diff --git a/m12-symbols.sym b/m12-symbols.sym index 26ca99d..1f850dc 100644 --- a/m12-symbols.sym +++ b/m12-symbols.sym @@ -6,5 +6,6 @@ 03001F30 m2_food 03001F3A m2_rockin 03001F50 m2_player1 +080C87D0 m2_drawwindow 080C980C m2_printnextch 080CA4BC m2_scrolltext \ No newline at end of file diff --git a/m2-notes.txt b/m2-notes.txt index 4b36b48..341a204 100644 --- a/m2-notes.txt +++ b/m2-notes.txt @@ -26,6 +26,7 @@ Custom WRAM: 2027FC0 Subroutines ----------- +80C87D0: draw blank window and border (r0: window pointer) 80C980C: print next character (r0: window pointer) 80CA4BC: scroll text upwards (r0: window pointer) diff --git a/m2-subC87D0.txt b/m2-subC87D0.txt index e114ad4..ef4ab4d 100644 --- a/m2-subC87D0.txt +++ b/m2-subC87D0.txt @@ -1,3 +1,5 @@ +m2_drawwindow: + // r0: window pointer 080C87D0 (T) push {r4-r7,r14} 080C87D2 (T) mov r7,r10 @@ -34,35 +36,58 @@ 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 + 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 + 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] + 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] + 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 + 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] + 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] + 080C8842 (T) ldsh r5,[r6,r0] // window y 080C8844 (T) add r0,r5,r1 080C8846 (T) cmp r0,#0x1F 080C8848 (T) bgt #0x80C888C @@ -75,10 +100,10 @@ 080C8856 (T) asr r0,r0,#0x10 080C8858 (T) add r0,r5,r0 080C885A (T) lsl r0,r0,#0x6 - 080C885C (T) ldr r1,[r2] + 080C885C (T) ldr r1,[r2] // 0x3005270 080C885E (T) add r1,r1,r0 080C8860 (T) mov r5,#0x22 - 080C8862 (T) ldsh r0,[r6,r5] + 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 @@ -99,10 +124,13 @@ 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] + 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] + 080C8892 (T) ldrh r5,[r5] // tile offset 080C8894 (T) mov r12,r5 080C8896 (T) ldr r0,=#0x1DF 080C8898 (T) add r0,r12