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 > Repetitive code.

#11502 - jimmy-bucket - Wed Oct 08, 2003 10:01 pm

Hi all,

I'm currently playing around with some basics, and i have a routine that checks for keypresses and flips a sprite if one is pressed. It all works fine, but there are large chunks of irrelevant code repeated.

Eg:
Code:
ldr r1,=(SQUARE|COLOR_256|10)|((SIZE_32|10|HORIZONTAL_FLIP)<<16) 
ldrne r1,=(SQUARE|COLOR_256|10)|((SIZE_32|10)<<16)


The HORIZONTAL_FLIP (or lack of) is the only part i want, but the code doesnt work without the rest.

Ie:
Code:
ldr r1,=HORIZONTAL_FLIP
ldrne r1,=**Remove flip**


Any pointers?

Thanks in advance, Kieren

#11503 - Burton Radons - Wed Oct 08, 2003 10:16 pm

You forgot the left shift.

Code:
ldr r1, =(HORIZONTAL_FLIP << 16)

#11504 - jimmy-bucket - Wed Oct 08, 2003 10:24 pm

Yeah, but the code i posted was just to hint at what i wanted. I cant work that bit out, so im asking for help.

Whenever i leave the (SQUARE|COLOR_256|10) part off, the sprite is scrambled when a key is pressed.

#11509 - tepples - Thu Oct 09, 2003 1:03 am

The ORR instruction sets a bit in a word. The BIC instruction clears a bit in a word.

Instead of this:
Code:

ldr r1,=(SQUARE|COLOR_256|10)|((SIZE_32|10|HORIZONTAL_FLIP)<<16)
ldrne r1,=(SQUARE|COLOR_256|10)|((SIZE_32|10)<<16)

Try this:
Code:

ldr r1,=(SQUARE|COLOR_256|10)|((SIZE_32|10)<<16)
orreq r1,r1,#(HORIZONTAL_FLIP<<16)

Or this:
Code:

ldr r1,=(SQUARE|COLOR_256|10)|((SIZE_32|10|HORIZONTAL_FLIP)<<16)
bicne r1,r1,#(HORIZONTAL_FLIP<<16)

I haven't written any ARM asm from scratch, so there might be a syntax error or two.

Reference: ARM Instruction Formats and Timings

TRIVIA: There is an ARM instruction with mnemonic SWINE. What does this hog do?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#11510 - sajiimori - Thu Oct 09, 2003 1:51 am

SWINE: SoftWare Interrupt if Not Equal