#166085 - headspin - Mon Jan 26, 2009 10:42 am
I am trying to convert the following code from this website
And here is my current "translation" to arm asm.
I am using the same SIN.bin and COS.bin from the old libnds (located in libnds\source\arm9) I ran a bin2s and included them in my project. I have no idea if the values are half word in size or not but thats what I've assumed in the code.
I also am also not sure how to make a value negative as in the C example, again I'm guessing it's setting the MSB.
All I'm getting is the sprite turns into the shape of a line and is really slowly moving. Obviously there is a bug in the code somewhere. Can you see it?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
Last edited by headspin on Mon Jan 26, 2009 12:59 pm; edited 4 times in total
Code: |
s16 s = -SIN[angle & 0x1FF] >> 4;
s16 c = COS[angle & 0x1FF] >> 4; spriteRotation[index].hdx = c; spriteRotation[index].hdy = -s; spriteRotation[index].vdx = s; spriteRotation[index].vdy = c; |
And here is my current "translation" to arm asm.
Code: |
ldr r0, =SIN_bin @ Load the address of our SIN table
ldr r1, =COS_bin @ Load the address of our COS table ldr r2, =angle @ Load the address of angle ldrh r3, [r2] @ Load r3 with the value of angle add r3, #1 @ Add one to angle cmp r3, #512 @ Compare our angle to 512 movpl r3, #0 @ If the angle is greater than 512 then set it to zero strh r3, [r2] @ Write it back to angle ldr r4, =0x1FF @ Load our mask to r4 and r3, r4 @ And our mask with our angle lsl r3, #1 @ Multiply by 2? (16 bit SIN data?) add r0, r3 @ Add our offset to our SIN table add r1, r3 @ Add our offset to our COS table ldrsh r2, [r0] @ Now read the SIN table ldrsh r3, [r1] @ Now read the COS table asr r2, #4 @ Right shift the SIN value 4 bits mov r6, r2 @ Make a copy of our SIN value (-SIN[angle & 0x1FF] >> 4) rsb r2, r2, #0 @ Reverse subtract to make it negative (r2=#0 - r2) asr r3, #4 @ Right shift the COS value 4 bits (c = COS[angle & 0x1FF] >> 4) ldr r4, =OBJ_ROTATION_HDX(0) @ This is the HDX address of the sprite ldr r5, =OBJ_ROTATION_HDY(0) @ This is the HDY address of the sprite strh r3, [r4] @ Write our COS value to HDX (hdx = c) strh r6, [r5] @ Write our SIN value to HDY (hdy = -s) ldr r4, =OBJ_ROTATION_VDX(0) @ This is the VDX address of the sprite ldr r5, =OBJ_ROTATION_VDY(0) @ This is the VDY address of the sprite strh r2, [r4] @ Write our SIN value to VDX (vdx = s) strh r3, [r5] @ Write our COS value to VDY (vdy = c) |
I am using the same SIN.bin and COS.bin from the old libnds (located in libnds\source\arm9) I ran a bin2s and included them in my project. I have no idea if the values are half word in size or not but thats what I've assumed in the code.
I also am also not sure how to make a value negative as in the C example, again I'm guessing it's setting the MSB.
All I'm getting is the sprite turns into the shape of a line and is really slowly moving. Obviously there is a bug in the code somewhere. Can you see it?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
Last edited by headspin on Mon Jan 26, 2009 12:59 pm; edited 4 times in total