gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Doubled width on screensize?

#553 - YogiJogg - Wed Jan 08, 2003 7:54 pm

When I run this code (copied from GBAguy?s tutor) the pixel is put on line 0, column 479 and not on line 1, column 239 where I thought it should be put. I use the emulator "VirtalBoy Advance". It appears that the screen mode is 480*(unknown height), instead of 240*160.

Does anyone know why I have this problem?

@include screen.h
@textarea

ldr r1,=REG_DISPCNT

ldr r2,=(BG2_ENABLE|MODE_3)

str r2,[r1]

ldr r1,=0x0FF

ldr r2,=vram+479

str r1,[r2]

label1

B label1

@pool
@endarea

#555 - YogiJogg - Wed Jan 08, 2003 8:07 pm

I mean the emulator is visualboy and the compiler is goldroad.

#559 - Burre - Wed Jan 08, 2003 8:25 pm

I also tried that tutorial some months ago and I believe that the formula "y * 240 + x" wich he uses is faulty. I used some trial end error method and came up with a formula that worked: (y * 240 + x) * 2. Why this workes (wich I learned later) is that the pixel format is 32bit and when writing you have skip 16bit write 16 bit and so fourth. I'm not sure about the explanation since it's only what I've heard, but I know that the formula workes. Does anyone know why it is this way?
_________________
"The best optimizer is between your ears..."

#562 - YogiJogg - Wed Jan 08, 2003 8:50 pm

That doesn?t work perfeclty either because the pixel is put on the same spot (0,0) for this combinations:

ldr r2,=vram+0
ldr r2,=vram+1
ldr r2,=vram+2
ldr r2,=vram+3

So the formula might be (y * 240 + x) * 4. But then I cant address all pixels because

ldr r2,=vram+4

puts the pixel two steps to the left and leaves a black pixel between.

Guess I have to read more tutorials and maybe change to another mode.

Thanks anyway!

#564 - Touchstone - Wed Jan 08, 2003 8:56 pm

The forumla (y * 240 + x) * 2 is valid when the width of the screen is 240 pixels, every pixel is two bytes and the VRAM is a linear buffer. The forumla y * 240 + x is valid then the size of each pixel is one byte.
_________________
You can't beat our meat