Problems in Hello The World's code HELP!

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
yohayo
Posts: 3
Joined: Sat Jun 25, 2005 12:53 am

Problems in Hello The World's code HELP!

Post by yohayo »

I have read Hello The World's src.In pg.c I still have some problems that I could not understand,please help me!
1) 0x04000000 is PgVramAddr,then,what is 0x40000000?
so I could not understand the code:

Code: Select all

char *pgGetVramAddr(unsigned long x,unsigned long y)
{
    return pg_vramtop+(pg_drawframe?FRAMESIZE:0)+x*PIXELSIZE*2+y*LINESIZE*2+0x40000000;
}
2)

Code: Select all

#define     PIXELSIZE   1          
#define     LINESIZE    512         
#define     FRAMESIZE   0x44000
I could not understand the meaning of this three nembers:1 512 0x44000

THANX A LOTS!
trollied
Posts: 5
Joined: Sat Apr 02, 2005 5:26 am

Re: Problems in Hello The World's code HELP!

Post by trollied »

I don't think it was ever meant to be.....
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Re: Problems in Hello The World's code HELP!

Post by Agoln »

2)

Code: Select all

#define     PIXELSIZE   1
Probably just the size of a pixel... in case you want a pixel to be bigger or something.

Code: Select all

#define     LINESIZE    512         
Either how long a line is (how many pixel's wide) or how many lines are on the screen

Code: Select all

#define     FRAMESIZE   0x44000
Probably just how big to make the screen (440)




I don't know the PSP specs off the top of my head so I'm unsure if that is correct, but it sounds about right. I have not looked at the source code, but at least this should give you a head start.

If you don't know what 0x44000 is, it's a hex number. That is that it's Base 16, which uses 0-9, a-f. You can google around for hex numbers if you are unsure of what it means.
yohayo
Posts: 3
Joined: Sat Jun 25, 2005 12:53 am

Post by yohayo »

THANX A LOTS!
I know 0x4400 is a Hex_nember,but how could the Hello World's maker get this number?
PSP's screen is 480*272,so I think the longest line have 480 pixels,why they difine LINESIZE 512? Why not 480?
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

yohayo wrote:difine LINESIZE 512? Why not 480?
Now that I think of it more... maybe line size is more along the lines of a string type of format? Where do they use it in the code?
User avatar
cwbowron
Posts: 76
Joined: Fri May 06, 2005 4:22 am
Location: East Lansing, MI
Contact:

Post by cwbowron »

yohayo wrote:THANX A LOTS!
I know 0x4400 is a Hex_nember,but how could the Hello World's maker get this number?
PSP's screen is 480*272,so I think the longest line have 480 pixels,why they difine LINESIZE 512? Why not 480?
This is just a guess from reading the code, but the video ram is probably mapped out that way so that you find the actual offset of a pixel its 512*y+x rather than 480*y+x (the actual screen length) because its much faster to multiply by 512 than it is to multiply by 480.

(multiply by 512 == shift left 9)
0xdeadface
Posts: 62
Joined: Tue May 31, 2005 5:11 am

Post by 0xdeadface »

"I know 0x4400 is a Hex_nember,but how could the Hello World's maker get this number? "

If one screen = 272 scanlines with 512 pixels per scanline with 2 bytes per pixel, one screen = 272*512*2=278528.

278528 in hex equals 0x44000.

So if you have double buffering (drawing to a nonvisible screen) your second screen would be at 0x44000

0xdf
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

wow, thanks a ton man!
yohayo
Posts: 3
Joined: Sat Jun 25, 2005 12:53 am

Post by yohayo »

HA! Thanks all of you!
Last,could you tell me the meaning of 0x40000000?Some forums said it is cache of Vram,use it can quickly load the data in Vram.Is it right?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

In a simplistic way on the PSP's CPU if you access memory from 0x00000000 -> 0x3FFFFFFF the read and writes are cached. That same memory is also mapped to 0x40000000 -> 0x7FFFFFFF but in this case it is uncached and all read and writes go directly to memory. VRAM access should be made to the address 0x44000000 otherwise some of the pixels could get cached and you see artifacts such as missing pixels.

Now if the GE is ever properly utilised this will be totally irrelevant ;P
royonimusha
Posts: 2
Joined: Sun Jun 26, 2005 9:06 pm

Post by royonimusha »

yeah
I read the source code of hello psp these day and I still could not understand the principle of the function "pgPutChar" .Who'd like to explain it for me ?
thanks!

Code: Select all

void pgPutChar(unsigned long x,unsigned long y,unsigned long color,unsigned long bgcolor,unsigned char ch,char drawfg,char drawbg,char mag)
{
    unsigned char *vptr0;       //pointer to vram
    unsigned char *vptr;        //pointer to vram
    const unsigned char *cfont;     //pointer to font
    unsigned long cx,cy;
    unsigned long b;
    char mx,my;

    if (ch>255) return;
    cfont=font+ch*8;
    vptr0=pgGetVramAddr(x,y);
    for &#40;cy=0; cy<8; cy++&#41; &#123;
        for &#40;my=0; my<mag; my++&#41; &#123;
            vptr=vptr0;
            b=0x80;
            for &#40;cx=0; cx<8; cx++&#41; &#123;
                for &#40;mx=0; mx<mag; mx++&#41; &#123;
                    if &#40;&#40;*cfont&b&#41;!=0&#41; &#123;
                        if &#40;drawfg&#41; *&#40;unsigned short *&#41;vptr=color;
                	&#125; else &#123;
                        if &#40;drawbg&#41; *&#40;unsigned short *&#41;vptr=bgcolor;
        			&#125;
                    vptr+=PIXELSIZE*2;
        		&#125;
            	b=b>>1;
    		&#125;
            vptr0+=LINESIZE*2;
    	&#125;
        cfont++;
    &#125;
&#125;
soulctcher
Posts: 2
Joined: Mon Jun 27, 2005 9:43 am

Post by soulctcher »

Hello all, new here, so I'd appreciate your help. I've only coded a little bit, and am truly an amateur.

Currently I'm looking at the Hello World source and disecting it so I can understand the functions. In pgScreenFrame, there's a couple of lines like:

Code: Select all

frame=&#40;frame?1&#58;0&#41;;
and

Code: Select all

pg_drawframe=&#40;frame?0&#58;1&#41;;
What do these mean? I am sorry if it's a simple answer, and I thank anyone in advance for taking the time to help me out.


Also, does anyone have any recommendations as to sites they use as reference for C/C++?
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

This isn't an introductory c form, but anyway..

soulctcher:
the line myVar = xxx?yyy:bbb;
will evauate xxx as a boolean expression, ie down to true or false, 1 or 0, whatever. If xxx is non zero, then the expression becomes yyy, otherwise bbb is is asigned to myVar.
it's just shorthand for:

Code: Select all

if&#40;xxx&#41;
    myVar = yyy;
else
    myvar = bbb;
royonimusha:
looks like it uses x and yto find an offset in vram corresponding to the coordinates, used the supplied char to lookup a font file then copies pixel by pixel the letter from the font file to the screen with the supplied fore and background colours, magnifiying if necessary. easy.


But i (and most people here) would strongly advise getting a better grip on C before taking on something like the psp...
Damn, I need a decent signature!
soulctcher
Posts: 2
Joined: Mon Jun 27, 2005 9:43 am

Post by soulctcher »

Thanks for the help.
Post Reply