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 > ARM ASM problem.

#9610 - Lord Graga - Sun Aug 10, 2003 5:49 pm

Hey all, I just recently started to do some ARM ASM with ARM SDT, as I plan to release a 4K demo for the competition this year. However, I have a problem. The problem is, that I have made a palette for my entry, and it's 16 bits. However, when I use the method below, I can only get the first 8 bits of the palette. What am I doing wrong?
Code:
 AREA _mother, CODE, READONLY
    ENTRY
    b initmother
    DCD   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    DCD   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   DCD   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   
initmother
;SET MODE
   mov r0,#0x4000000
   ldr r1,=0x400|0x4
   str r1,[r0]
;PALETTE
   mov r0,#0x5000000
   ldr r1,=colours
palloop
   str r1,[r0]
   add r0,r0,#1
   ldr r1,=colurs|r2
   add r2,r2,#1
   cmp r2,#255
   bne palloop
looper   b looper

colours
   INCBIN c:\projects\mother4k\palette
 END

#9611 - DekuTree64 - Sun Aug 10, 2003 6:44 pm

Ok, ldr r1, =colours will get you a pointer to the array, then you have to load the colors from that, and I don't know what's up with that ldr r1, =colours|r2, I thought that would cause an error^^;
So for your inner loop, it should be more like
Code:

;PALETTE
   mov r0,#0x5000000
   ldr r1,=colours
   mov r2, #0
palloop
   ldrh r3, [r1, r2] @colors are 2 bytes, not 4
   strh r3,[r0, r2]
   add r2,r2,#2 @2 bytes each
   cmp r2,#512
   bne palloop


Or for a more optimized version...
Code:

;PALETTE
   mov r0,#0x5000000
   ldr r1,=colours
   add r2, r1, #512
palloop
   ldr r3, [r1], #4 @copy 2 at a time
   str r3, [r0], #4
   cmp r1, r2
   bne palloop

Good luck on your entry, learning ASM takes a while, so hopefully you'll have time to recode everything after you've got the hang of it, cause I know I would^_^
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku