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 > predefining variables doesnt work ...

#8911 - wasiliy - Wed Jul 23, 2003 6:43 pm

hi
i'm using armsdt and i'm trying to predefine a variable

color DCB 1

when i try to load the value via

ldr r2,=color
ldrb r1,[r2]

it doesnt work. r1 seems still to be zero. here is the whole code:

Code:

   AREA  new, CODE, READONLY
   ENTRY
main
   mov r0,#0x4000000
   ldr r1,=0x404
   str r1,[r0]                  ; set gfx mode 4

   ldr r0,=0x05000002   ; set color 1 to white
   ldr r1,=0x0FFFF
   strh r1,[r0]
   
   ldr r0,=0x6000000    ; set a white pixel on screen
   ldr r2,=color
   ldrb r1,[r2]
   strb r1,[r0,#10]

infinit
   b infinit
   
   AREA  Block, DATA, READWRITE
color DCB 1
   END


when i just load 1 into the r1 register by using

mov r1,#1

it works but when i try to load a 1 from memory it doesnt.

#8977 - funkeejeffou - Fri Jul 25, 2003 11:30 am

Really weird if it works when you move r1 manually...
Try doing strh r1, [r0, #10] as the video bus is 16 bits wide (strb souldn't work). It will store the white color in the pixel 11. If you wanna store the white color in pixel 10, mov r1, r1 lsl#8 so that 1 will be in the 8 upper bits; then store it like above : strh r1, [r0, #10].

Also, white color is not 0xFFFF as each RVB value is 5bit coded.
so white is 31 + 32*31 + 1024*31 = 0x7FFF. Same for the other colors.

When you store the video mode at 0x4000000, you should also use strh as the VIDEO_REG is 16 bit wide. Register from 0x4000002 to 0x4000004 is undocumented, but better not write to it.

Hope this helps.

#9025 - wasiliy - Sat Jul 26, 2003 5:46 pm

thank you for your reply,
but i've already solved the problem. it was a memory issue. i cant write to rom thats why the assembler wont predefine the variable when i'm in readwrite mode. i have to define my data to readonly and copy it to ram manually, it works then.
it was my fault, that i didnt tell you where i stored my data, sorry.
but again, thanks for your effort.