Mother2GbaTranslation/m2-customcodes.asm

89 lines
1.7 KiB
NASM
Raw Normal View History

2015-03-13 23:03:48 +00:00
//==============================================================================
// void parse(int code, char* parserAddress, WINDOW* window)
// In:
// r0: code
// r1: parser address
// r2: window
// Out:
// r0: control code length (0 if not matched)
//==============================================================================
2017-03-29 05:19:51 +01:00
customcodes_parse:
2015-03-13 23:03:48 +00:00
push {r1-r5,lr}
2017-03-29 05:19:51 +01:00
mov r3,0
2015-03-13 23:03:48 +00:00
mov r4,r0
//--------------------------------
// 60 FF XX: Add XX pixels to the renderer
2017-03-29 05:19:51 +01:00
cmp r4,0x60
bne @@next
mov r3,3
2015-03-13 23:03:48 +00:00
// Get the current X offset
2017-03-29 05:19:51 +01:00
ldrh r4,[r2,2]
2015-03-13 23:03:48 +00:00
// Get the current X tile
2017-03-29 05:19:51 +01:00
ldrh r5,[r2,0x2A]
2015-03-13 23:03:48 +00:00
2017-03-29 05:19:51 +01:00
lsl r5,r5,3
2015-03-13 23:03:48 +00:00
add r4,r4,r5 // Current X location (in pixels)
// Get the value to add
2017-03-29 05:19:51 +01:00
ldrb r5,[r1,2] // Control code parameter
2015-03-13 23:03:48 +00:00
add r4,r4,r5 // New X location
// Store the pixel offset of the new location
2017-03-29 05:19:51 +01:00
@@store_x:
lsl r5,r4,29
lsr r5,r5,29
strh r5,[r2,2]
2015-03-13 23:03:48 +00:00
// Store the X tile of the new location
2017-03-29 05:19:51 +01:00
lsr r4,r4,3
strh r4,[r2,0x2A]
b @@end
2015-03-13 23:03:48 +00:00
2017-03-29 05:19:51 +01:00
@@next:
2015-03-13 23:03:48 +00:00
//--------------------------------
// 5F FF XX: Set the X value of the renderer
2017-03-29 05:19:51 +01:00
cmp r4,0x5F
bne @@next2
mov r3,3
2015-03-13 23:03:48 +00:00
// Get the new X value
2017-03-29 05:19:51 +01:00
ldrb r4,[r1,2]
b @@store_x
2015-03-13 23:03:48 +00:00
2017-03-29 05:19:51 +01:00
@@next2:
2015-03-13 23:03:48 +00:00
//--------------------------------
// 5E FF XX: Load value into memory
2017-03-29 05:19:51 +01:00
cmp r4,0x5E
bne @@end
mov r3,3
// Get the argument
2017-03-29 05:19:51 +01:00
ldrb r4,[r1,2]
cmp r4,1
bne @@end
// 01: load enemy plurality
2017-03-29 05:19:51 +01:00
ldr r1,=0x2025038
2017-04-03 03:12:18 +01:00
ldrb r1,[r1] // number of enemies at start of battle
2017-03-29 05:19:51 +01:00
cmp r1,4
blt @@small
mov r1,3
@@small:
mov r0,r1 // the jump table is 1-indexed
mov r4,r3
2017-03-29 05:19:51 +01:00
bl 0x80A334C // store to window memory
mov r3,r4
2015-03-13 23:03:48 +00:00
//--------------------------------
2017-03-29 05:19:51 +01:00
@@end:
mov r0,r3
pop {r1-r5,pc}
2017-03-29 05:19:51 +01:00
.pool