Mother2GbaTranslation/m2-subC87D0.txt

519 lines
18 KiB
Plaintext

m2_drawwindow:
// r0: window pointer
080C87D0 (T) push {r4-r7,r14}
080C87D2 (T) mov r7,r10
080C87D4 (T) mov r6,r9
080C87D6 (T) mov r5,r8
080C87D8 (T) push {r5-r7}
080C87DA (T) mov r6,r0
// Compute tilemap pointer
080C87DC (T) ldr r4,=#0x3005270
080C87DE (T) mov r1,#0x24
080C87E0 (T) ldsh r0,[r6,r1] // r0 = window_y
080C87E2 (T) lsl r0,r0,#0x6
080C87E4 (T) ldr r1,[r4] // r1 = tilemap pointer
080C87E6 (T) add r1,r1,r0
080C87E8 (T) mov r2,#0x22
080C87EA (T) ldsh r0,[r6,r2] // r0 = window_x
080C87EC (T) lsl r0,r0,#0x1
080C87EE (T) add r5,r1,r0 // r5 = tilemap + (window_y * 64) + (window_x * 2)
// Prepare tile 0x1FF: r0 = r8 = 0xE000 | (0x1FF + 0x100) = 0xE2FF
080C87F0 (T) mov r3,#0x0
080C87F2 (T) mov r12,r3
080C87F4 (T) mov r9,r3
080C87F6 (T) ldr r3,=#0x30051EC
080C87F8 (T) ldr r1,=#0x1FF
080C87FA (T) mov r0,r1
080C87FC (T) ldrh r2,[r3]
080C87FE (T) add r0,r0,r2
080C8800 (T) ldr r2,=#0x3005228
080C8802 (T) ldrh r1,[r2]
080C8804 (T) orr r0,r1
080C8806 (T) lsl r0,r0,#0x10
080C8808 (T) lsr r0,r0,#0x10
080C880A (T) mov r8,r0
int current_x = 0;
int current_y = 0;
int tilemap = ldr[0x3005270];
u16 *ptr = tilemap + (window_y * 64) + (window_x * 2);
for (int current_area = 0; current_area < window_area; current_area++)
{
if (current_x >= window_width || window_x + current_x > 0x1F)
{
if (current_y >= window_height || window_y + current_y > 0x1F)
break;
// 80C884A
current_x = 0;
current_y++;
int y = current_y + window_y;
*ptr = tilemap + (y * 64) + (window_x * 2);
}
*ptr = 0xE2FF;
current_x++;
ptr += 2;
}
080C880C (T) mov r7,#0x0
080C880E (T) mov r1,#0x20
080C8810 (T) ldsh r0,[r6,r1] // window area
080C8812 (T) mov r10,r4 // 0x3005270
080C8814 (T) cmp r7,r0
080C8816 (T) bge #0x80C888C
080C8818 (T) mov r2,r10
080C881A (T) mov r3,r12 // x counter
080C881C (T) lsl r0,r3,#0x10
080C881E (T) asr r1,r0,#0x10
080C8820 (T) mov r4,#0x26
080C8822 (T) ldsh r0,[r6,r4] // window width
080C8824 (T) cmp r1,r0
080C8826 (T) bge #0x80C8832
080C8828 (T) mov r3,#0x22
080C882A (T) ldsh r0,[r6,r3] // window x
080C882C (T) add r0,r0,r1
080C882E (T) cmp r0,#0x1F
080C8830 (T) ble #0x80C8868
080C8832 (T) mov r4,r9 // y counter
080C8834 (T) lsl r0,r4,#0x10
080C8836 (T) asr r1,r0,#0x10
080C8838 (T) mov r5,#0x28
080C883A (T) ldsh r0,[r6,r5] // window height
080C883C (T) cmp r1,r0
080C883E (T) bge #0x80C888C
080C8840 (T) mov r0,#0x24
080C8842 (T) ldsh r5,[r6,r0] // window y
080C8844 (T) add r0,r5,r1
080C8846 (T) cmp r0,#0x1F
080C8848 (T) bgt #0x80C888C
080C884A (T) mov r3,#0x0
080C884C (T) mov r12,r3
080C884E (T) add r0,r1,1
080C8850 (T) lsl r0,r0,#0x10
080C8852 (T) lsr r4,r0,#0x10
080C8854 (T) mov r9,r4
080C8856 (T) asr r0,r0,#0x10
080C8858 (T) add r0,r5,r0
080C885A (T) lsl r0,r0,#0x6
080C885C (T) ldr r1,[r2] // 0x3005270
080C885E (T) add r1,r1,r0
080C8860 (T) mov r5,#0x22
080C8862 (T) ldsh r0,[r6,r5] // window x
080C8864 (T) lsl r0,r0,#0x1
080C8866 (T) add r5,r1,r0
080C8868 (T) mov r0,r8
080C886A (T) strh r0,[r5]
080C886C (T) mov r1,r12
080C886E (T) lsl r0,r1,#0x10
080C8870 (T) mov r3,#0x80
080C8872 (T) lsl r3,r3,#0x9
080C8874 (T) add r0,r0,r3
080C8876 (T) lsr r0,r0,#0x10
080C8878 (T) mov r12,r0
080C887A (T) lsl r1,r7,#0x10
080C887C (T) add r1,r1,r3
080C887E (T) add r5,#0x2
080C8880 (T) lsr r7,r1,#0x10
080C8882 (T) asr r1,r1,#0x10
080C8884 (T) mov r4,#0x20
080C8886 (T) ldsh r0,[r6,r4]
080C8888 (T) cmp r1,r0
080C888A (T) blt #0x80C881A
080C888C (T) mov r0,#0x0
080C888E (T) strh r0,[r6,#0x32] // ?
// It seems the remaining code draws the window borders
080C8890 (T) ldr r5,=#0x30051EC
080C8892 (T) ldrh r5,[r5] // tile offset
080C8894 (T) mov r12,r5
080C8896 (T) ldr r0,=#0x1DF
080C8898 (T) add r0,r12
080C889A (T) ldr r1,=#0x3005228
080C889C (T) ldrh r4,[r1]
080C889E (T) orr r0,r4
080C88A0 (T) lsl r0,r0,#0x10
080C88A2 (T) lsr r0,r0,#0x10
080C88A4 (T) mov r8,r0
080C88A6 (T) mov r2,#0x22
080C88A8 (T) ldsh r3,[r6,r2]
080C88AA (T) sub r0,r3,1
080C88AC (T) cmp r0,#0x0
080C88AE (T) blt #0x80C88CE
080C88B0 (T) mov r5,#0x26
080C88B2 (T) ldsh r0,[r6,r5]
080C88B4 (T) add r0,r3,r0
080C88B6 (T) cmp r0,#0x1F
080C88B8 (T) bgt #0x80C88CE
080C88BA (T) mov r0,#0x24
080C88BC (T) ldsh r5,[r6,r0]
080C88BE (T) sub r1,r5,1
080C88C0 (T) cmp r1,#0x0
080C88C2 (T) blt #0x80C88CE
080C88C4 (T) mov r2,#0x28
080C88C6 (T) ldsh r0,[r6,r2]
080C88C8 (T) add r0,r5,r0
080C88CA (T) cmp r0,#0x1F
080C88CC (T) ble #0x80C88E8
080C88CE (T) mov r0,#0x1
080C88D0 (T) neg r0,r0
080C88D2 (T) b #0x80C8B8A
080C88D4 (T) strh r0,[r6,r1]
080C88D6 (T) lsl r0,r0,#0xC
080C88D8 (T) str r4,[r5,r7]
080C88DA (T) lsl r0,r0,#0xC
080C88DC (T) lsl r7,r7,#0x7
080C88DE (T) lsl r0,r0,#0x0
080C88E0 (T) strh r0,[r5,r0]
080C88E2 (T) lsl r0,r0,#0xC
080C88E4 (T) lsl r7,r3,#0x7
080C88E6 (T) lsl r0,r0,#0x0
080C88E8 (T) mov r2,r12
080C88EA (T) add r2,#0x93
080C88EC (T) orr r2,r4
080C88EE (T) mov r5,#0xC0
080C88F0 (T) lsl r5,r5,#0x4
080C88F2 (T) mov r9,r5
080C88F4 (T) mov r0,r9
080C88F6 (T) orr r2,r0
080C88F8 (T) lsl r0,r2,#0x10
080C88FA (T) lsr r7,r0,#0x10
080C88FC (T) lsl r1,r1,#0x6
080C88FE (T) mov r5,r10
080C8900 (T) ldr r0,[r5]
080C8902 (T) add r0,r0,r1
080C8904 (T) lsl r1,r3,#0x1
080C8906 (T) add r0,r0,r1
080C8908 (T) sub r5,r0,2
080C890A (T) ldrh r0,[r5]
080C890C (T) cmp r0,r8
080C890E (T) beq #0x80C8914
080C8910 (T) cmp r0,r7
080C8912 (T) bne #0x80C8918
080C8914 (T) strh r2,[r5]
080C8916 (T) b #0x80C8924
080C8918 (T) mov r0,r12
080C891A (T) add r0,#0x94
080C891C (T) orr r0,r4
080C891E (T) mov r1,r9
080C8920 (T) orr r0,r1
080C8922 (T) strh r0,[r5]
080C8924 (T) ldr r2,=#0x30051EC
080C8926 (T) ldrh r4,[r2]
080C8928 (T) mov r2,r4
080C892A (T) add r2,#0x93
080C892C (T) ldr r5,=#0x3005228
080C892E (T) ldrh r3,[r5]
080C8930 (T) orr r2,r3
080C8932 (T) mov r0,#0x80
080C8934 (T) lsl r0,r0,#0x4
080C8936 (T) mov r9,r0
080C8938 (T) mov r1,r9
080C893A (T) orr r2,r1
080C893C (T) lsl r0,r2,#0x10
080C893E (T) lsr r7,r0,#0x10
080C8940 (T) mov r5,#0x24
080C8942 (T) ldsh r0,[r6,r5]
080C8944 (T) sub r0,#0x1
080C8946 (T) lsl r0,r0,#0x6
080C8948 (T) mov r5,r10
080C894A (T) ldr r1,[r5]
080C894C (T) add r1,r1,r0
080C894E (T) mov r5,#0x22
080C8950 (T) ldsh r0,[r6,r5]
080C8952 (T) lsl r0,r0,#0x1
080C8954 (T) add r1,r1,r0
080C8956 (T) mov r5,#0x26
080C8958 (T) ldsh r0,[r6,r5]
080C895A (T) lsl r0,r0,#0x1
080C895C (T) add r5,r1,r0
080C895E (T) ldrh r0,[r5]
080C8960 (T) cmp r0,r8
080C8962 (T) beq #0x80C8968
080C8964 (T) cmp r0,r7
080C8966 (T) bne #0x80C8974
080C8968 (T) strh r2,[r5]
080C896A (T) b #0x80C8980
080C896C (T) str r4,[r5,r7]
080C896E (T) lsl r0,r0,#0xC
080C8970 (T) strh r0,[r5,r0]
080C8972 (T) lsl r0,r0,#0xC
080C8974 (T) mov r0,r4
080C8976 (T) add r0,#0x94
080C8978 (T) orr r0,r3
080C897A (T) mov r1,r9
080C897C (T) orr r0,r1
080C897E (T) strh r0,[r5]
080C8980 (T) ldr r2,=#0x30051EC
080C8982 (T) ldrh r4,[r2]
080C8984 (T) mov r2,r4
080C8986 (T) add r2,#0x93
080C8988 (T) ldr r5,=#0x3005228
080C898A (T) ldrh r3,[r5]
080C898C (T) orr r2,r3
080C898E (T) mov r0,#0x80
080C8990 (T) lsl r0,r0,#0x3
080C8992 (T) mov r9,r0
080C8994 (T) mov r1,r9
080C8996 (T) orr r2,r1
080C8998 (T) lsl r0,r2,#0x10
080C899A (T) lsr r7,r0,#0x10
080C899C (T) mov r5,#0x24
080C899E (T) ldsh r0,[r6,r5]
080C89A0 (T) mov r5,#0x28
080C89A2 (T) ldsh r1,[r6,r5]
080C89A4 (T) add r0,r0,r1
080C89A6 (T) lsl r0,r0,#0x6
080C89A8 (T) mov r5,r10
080C89AA (T) ldr r1,[r5]
080C89AC (T) add r1,r1,r0
080C89AE (T) mov r5,#0x22
080C89B0 (T) ldsh r0,[r6,r5]
080C89B2 (T) lsl r0,r0,#0x1
080C89B4 (T) add r1,r1,r0
080C89B6 (T) sub r5,r1,2
080C89B8 (T) ldrh r0,[r5]
080C89BA (T) cmp r0,r8
080C89BC (T) beq #0x80C89C2
080C89BE (T) cmp r0,r7
080C89C0 (T) bne #0x80C89D0
080C89C2 (T) strh r2,[r5]
080C89C4 (T) b #0x80C89DC
080C89C6 (T) lsl r0,r0,#0x0
080C89C8 (T) str r4,[r5,r7]
080C89CA (T) lsl r0,r0,#0xC
080C89CC (T) strh r0,[r5,r0]
080C89CE (T) lsl r0,r0,#0xC
080C89D0 (T) mov r0,r4
080C89D2 (T) add r0,#0x94
080C89D4 (T) orr r0,r3
080C89D6 (T) mov r1,r9
080C89D8 (T) orr r0,r1
080C89DA (T) strh r0,[r5]
080C89DC (T) ldr r2,=#0x30051EC
080C89DE (T) ldrh r4,[r2]
080C89E0 (T) mov r2,r4
080C89E2 (T) add r2,#0x93
080C89E4 (T) ldr r5,=#0x3005228
080C89E6 (T) ldrh r3,[r5]
080C89E8 (T) orr r2,r3
080C89EA (T) lsl r0,r2,#0x10
080C89EC (T) lsr r7,r0,#0x10
080C89EE (T) mov r1,#0x24
080C89F0 (T) ldsh r0,[r6,r1]
080C89F2 (T) mov r5,#0x28
080C89F4 (T) ldsh r1,[r6,r5]
080C89F6 (T) add r0,r0,r1
080C89F8 (T) lsl r0,r0,#0x6
080C89FA (T) mov r5,r10
080C89FC (T) ldr r1,[r5]
080C89FE (T) add r1,r1,r0
080C8A00 (T) mov r5,#0x22
080C8A02 (T) ldsh r0,[r6,r5]
080C8A04 (T) lsl r0,r0,#0x1
080C8A06 (T) add r1,r1,r0
080C8A08 (T) mov r5,#0x26
080C8A0A (T) ldsh r0,[r6,r5]
080C8A0C (T) lsl r0,r0,#0x1
080C8A0E (T) add r5,r1,r0
080C8A10 (T) ldrh r0,[r5]
080C8A12 (T) cmp r0,r8
080C8A14 (T) beq #0x80C8A1A
080C8A16 (T) cmp r0,r7
080C8A18 (T) bne #0x80C8A28
080C8A1A (T) strh r2,[r5]
080C8A1C (T) b #0x80C8A30
080C8A1E (T) lsl r0,r0,#0x0
080C8A20 (T) str r4,[r5,r7]
080C8A22 (T) lsl r0,r0,#0xC
080C8A24 (T) strh r0,[r5,r0]
080C8A26 (T) lsl r0,r0,#0xC
080C8A28 (T) mov r0,r4
080C8A2A (T) add r0,#0x94
080C8A2C (T) orr r0,r3
080C8A2E (T) strh r0,[r5]
080C8A30 (T) mov r1,#0x24
080C8A32 (T) ldsh r0,[r6,r1]
080C8A34 (T) sub r0,#0x1
080C8A36 (T) lsl r0,r0,#0x6
080C8A38 (T) mov r2,r10
080C8A3A (T) ldr r1,[r2]
080C8A3C (T) add r1,r1,r0
080C8A3E (T) mov r3,#0x22
080C8A40 (T) ldsh r0,[r6,r3]
080C8A42 (T) lsl r0,r0,#0x1
080C8A44 (T) add r5,r1,r0
080C8A46 (T) mov r7,#0x0
080C8A48 (T) mov r4,#0x26
080C8A4A (T) ldsh r0,[r6,r4]
080C8A4C (T) ldr r2,[r6]
080C8A4E (T) ldr r1,=#0x3000A0E
080C8A50 (T) mov r9,r1
080C8A52 (T) cmp r7,r0
080C8A54 (T) bge #0x80C8A8A
080C8A56 (T) ldr r3,=#0x30051EC
080C8A58 (T) mov r8,r3
080C8A5A (T) ldr r4,=#0x3005228
080C8A5C (T) mov r12,r4
080C8A5E (T) mov r0,#0x80
080C8A60 (T) lsl r0,r0,#0x4
080C8A62 (T) mov r3,r0
080C8A64 (T) mov r1,r8
080C8A66 (T) ldrh r0,[r1]
080C8A68 (T) add r0,#0x96
080C8A6A (T) mov r4,r12
080C8A6C (T) ldrh r1,[r4]
080C8A6E (T) orr r0,r1
080C8A70 (T) orr r0,r3
080C8A72 (T) strh r0,[r5]
080C8A74 (T) lsl r1,r7,#0x10
080C8A76 (T) mov r0,#0x80
080C8A78 (T) lsl r0,r0,#0x9
080C8A7A (T) add r1,r1,r0
080C8A7C (T) add r5,#0x2
080C8A7E (T) lsr r7,r1,#0x10
080C8A80 (T) asr r1,r1,#0x10
080C8A82 (T) mov r4,#0x26
080C8A84 (T) ldsh r0,[r6,r4]
080C8A86 (T) cmp r1,r0
080C8A88 (T) blt #0x80C8A64
080C8A8A (T) mov r5,#0x24
080C8A8C (T) ldsh r0,[r6,r5]
080C8A8E (T) mov r3,#0x28
080C8A90 (T) ldsh r1,[r6,r3]
080C8A92 (T) add r0,r0,r1
080C8A94 (T) lsl r0,r0,#0x6
080C8A96 (T) mov r4,r10
080C8A98 (T) ldr r1,[r4]
080C8A9A (T) add r1,r1,r0
080C8A9C (T) mov r5,#0x22
080C8A9E (T) ldsh r0,[r6,r5]
080C8AA0 (T) lsl r0,r0,#0x1
080C8AA2 (T) add r5,r1,r0
080C8AA4 (T) mov r7,#0x0
080C8AA6 (T) mov r1,#0x26
080C8AA8 (T) ldsh r0,[r6,r1]
080C8AAA (T) cmp r7,r0
080C8AAC (T) bge #0x80C8AD6
080C8AAE (T) ldr r3,=#0x30051EC
080C8AB0 (T) mov r8,r3
080C8AB2 (T) ldr r3,=#0x3005228
080C8AB4 (T) mov r4,r8
080C8AB6 (T) ldrh r0,[r4]
080C8AB8 (T) add r0,#0x96
080C8ABA (T) ldrh r1,[r3]
080C8ABC (T) orr r0,r1
080C8ABE (T) strh r0,[r5]
080C8AC0 (T) lsl r1,r7,#0x10
080C8AC2 (T) mov r0,#0x80
080C8AC4 (T) lsl r0,r0,#0x9
080C8AC6 (T) add r1,r1,r0
080C8AC8 (T) add r5,#0x2
080C8ACA (T) lsr r7,r1,#0x10
080C8ACC (T) asr r1,r1,#0x10
080C8ACE (T) mov r4,#0x26
080C8AD0 (T) ldsh r0,[r6,r4]
080C8AD2 (T) cmp r1,r0
080C8AD4 (T) blt #0x80C8AB4
080C8AD6 (T) mov r5,#0x24
080C8AD8 (T) ldsh r0,[r6,r5]
080C8ADA (T) lsl r0,r0,#0x6
080C8ADC (T) mov r3,r10
080C8ADE (T) ldr r1,[r3]
080C8AE0 (T) add r1,r1,r0
080C8AE2 (T) mov r4,#0x22
080C8AE4 (T) ldsh r0,[r6,r4]
080C8AE6 (T) lsl r0,r0,#0x1
080C8AE8 (T) add r1,r1,r0
080C8AEA (T) sub r5,r1,2
080C8AEC (T) mov r7,#0x0
080C8AEE (T) mov r1,#0x28
080C8AF0 (T) ldsh r0,[r6,r1]
080C8AF2 (T) cmp r7,r0
080C8AF4 (T) bge #0x80C8B2A
080C8AF6 (T) ldr r3,=#0x30051EC
080C8AF8 (T) mov r8,r3
080C8AFA (T) ldr r4,=#0x3005228
080C8AFC (T) mov r12,r4
080C8AFE (T) mov r0,#0x80
080C8B00 (T) lsl r0,r0,#0x3
080C8B02 (T) mov r3,r0
080C8B04 (T) mov r1,r8
080C8B06 (T) ldrh r0,[r1]
080C8B08 (T) add r0,#0x95
080C8B0A (T) mov r4,r12
080C8B0C (T) ldrh r1,[r4]
080C8B0E (T) orr r0,r1
080C8B10 (T) orr r0,r3
080C8B12 (T) strh r0,[r5]
080C8B14 (T) lsl r1,r7,#0x10
080C8B16 (T) mov r0,#0x80
080C8B18 (T) lsl r0,r0,#0x9
080C8B1A (T) add r1,r1,r0
080C8B1C (T) add r5,#0x40
080C8B1E (T) lsr r7,r1,#0x10
080C8B20 (T) asr r1,r1,#0x10
080C8B22 (T) mov r4,#0x28
080C8B24 (T) ldsh r0,[r6,r4]
080C8B26 (T) cmp r1,r0
080C8B28 (T) blt #0x80C8B04
080C8B2A (T) mov r5,#0x24
080C8B2C (T) ldsh r0,[r6,r5]
080C8B2E (T) lsl r0,r0,#0x6
080C8B30 (T) mov r3,r10
080C8B32 (T) ldr r1,[r3]
080C8B34 (T) add r1,r1,r0
080C8B36 (T) mov r4,#0x22
080C8B38 (T) ldsh r0,[r6,r4]
080C8B3A (T) lsl r0,r0,#0x1
080C8B3C (T) add r1,r1,r0
080C8B3E (T) mov r5,#0x26
080C8B40 (T) ldsh r0,[r6,r5]
080C8B42 (T) lsl r0,r0,#0x1
080C8B44 (T) add r5,r1,r0
080C8B46 (T) mov r7,#0x0
080C8B48 (T) mov r1,#0x28
080C8B4A (T) ldsh r0,[r6,r1]
080C8B4C (T) cmp r7,r0
080C8B4E (T) bge #0x80C8B78
080C8B50 (T) ldr r3,=#0x30051EC
080C8B52 (T) mov r8,r3
080C8B54 (T) ldr r3,=#0x3005228
080C8B56 (T) mov r4,r8
080C8B58 (T) ldrh r0,[r4]
080C8B5A (T) add r0,#0x95
080C8B5C (T) ldrh r1,[r3]
080C8B5E (T) orr r0,r1
080C8B60 (T) strh r0,[r5]
080C8B62 (T) lsl r1,r7,#0x10
080C8B64 (T) mov r0,#0x80
080C8B66 (T) lsl r0,r0,#0x9
080C8B68 (T) add r1,r1,r0
080C8B6A (T) add r5,#0x40
080C8B6C (T) lsr r7,r1,#0x10
080C8B6E (T) asr r1,r1,#0x10
080C8B70 (T) mov r4,#0x28
080C8B72 (T) ldsh r0,[r6,r4]
080C8B74 (T) cmp r1,r0
080C8B76 (T) blt #0x80C8B56
080C8B78 (T) mov r0,#0x21
080C8B7A (T) neg r0,r0
080C8B7C (T) and r2,r0
080C8B7E (T) mov r0,#0x1
080C8B80 (T) orr r2,r0
080C8B82 (T) str r2,[r6]
080C8B84 (T) mov r5,r9
080C8B86 (T) strh r0,[r5]
080C8B88 (T) mov r0,#0x0
080C8B8A (T) pop {r3-r5}
080C8B8C (T) mov r8,r3
080C8B8E (T) mov r9,r4
080C8B90 (T) mov r10,r5
080C8B92 (T) pop {r4-r7}
080C8B94 (T) pop {r1}
080C8B96 (T) bx r1