| View previous topic :: View next topic |
| Author |
Message |
yohayo
Joined: 25 Jun 2005 Posts: 3
|
Posted: Sat Jun 25, 2005 1:20 am Post subject: Problems in Hello The World's code HELP! |
|
|
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: | char *pgGetVramAddr(unsigned long x,unsigned long y)
{
return pg_vramtop+(pg_drawframe?FRAMESIZE:0)+x*PIXELSIZE*2+y*LINESIZE*2+0x40000000;
} |
2) | Code: |
#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! |
|
| Back to top |
|
 |
trollied
Joined: 02 Apr 2005 Posts: 5
|
Posted: Sat Jun 25, 2005 1:26 am Post subject: Re: Problems in Hello The World's code HELP! |
|
|
| I don't think it was ever meant to be..... |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jun 25, 2005 2:57 am Post subject: Re: Problems in Hello The World's code HELP! |
|
|
2) | Code: |
#define PIXELSIZE 1
|
Probably just the size of a pixel... in case you want a pixel to be bigger or something.
| Code: |
#define LINESIZE 512
|
Either how long a line is (how many pixel's wide) or how many lines are on the screen
| Code: |
#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. |
|
| Back to top |
|
 |
yohayo
Joined: 25 Jun 2005 Posts: 3
|
Posted: Sat Jun 25, 2005 5:30 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jun 25, 2005 5:35 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
cwbowron

Joined: 06 May 2005 Posts: 76 Location: East Lansing, MI
|
Posted: Sat Jun 25, 2005 5:49 am Post subject: |
|
|
| 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) |
|
| Back to top |
|
 |
0xdeadface
Joined: 31 May 2005 Posts: 62
|
Posted: Sat Jun 25, 2005 7:38 am Post subject: |
|
|
"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 |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sun Jun 26, 2005 1:48 am Post subject: |
|
|
| wow, thanks a ton man! |
|
| Back to top |
|
 |
yohayo
Joined: 25 Jun 2005 Posts: 3
|
Posted: Sun Jun 26, 2005 2:36 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sun Jun 26, 2005 4:24 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
royonimusha
Joined: 26 Jun 2005 Posts: 2
|
Posted: Sun Jun 26, 2005 9:23 pm Post subject: |
|
|
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: |
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 (cy=0; cy<8; cy++) {
for (my=0; my<mag; my++) {
vptr=vptr0;
b=0x80;
for (cx=0; cx<8; cx++) {
for (mx=0; mx<mag; mx++) {
if ((*cfont&b)!=0) {
if (drawfg) *(unsigned short *)vptr=color;
} else {
if (drawbg) *(unsigned short *)vptr=bgcolor;
}
vptr+=PIXELSIZE*2;
}
b=b>>1;
}
vptr0+=LINESIZE*2;
}
cfont++;
}
}
|
|
|
| Back to top |
|
 |
soulctcher
Joined: 27 Jun 2005 Posts: 2
|
Posted: Mon Jun 27, 2005 9:53 am Post subject: |
|
|
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:
and
| Code: | | pg_drawframe=(frame?0:1); |
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++? |
|
| Back to top |
|
 |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Mon Jun 27, 2005 10:02 am Post subject: |
|
|
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: | if(xxx)
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! |
|
| Back to top |
|
 |
soulctcher
Joined: 27 Jun 2005 Posts: 2
|
Posted: Mon Jun 27, 2005 10:11 am Post subject: |
|
|
| Thanks for the help. |
|
| Back to top |
|
 |
|