@ The probes for gba-python C12 (Hades-Tests dma-start-delay test 2). @ @ Every ARM probe is Hades' test 2 instruction for instruction (devkitARM @ -O0, as disassembled from Hades-Tests/roms/dma-start-delay.gba) from the @ timer start to the third sample, with ONE thing changed by a macro @ argument. Each probe takes a pointer to a 3-halfword record in r0 and @ returns, in it, the three timer samples Hades takes: @ [0] the value the DMA copied from TM0CNT_L (0xDEAD: the DMA never ran) @ [1] TM0CNT_L read right after the disable write ("t1") @ [2] TM0CNT_L read after one pass of while (DMAxCNT & enable) ("t2") @ The samples live on the stack (IWRAM), the DMA's destination, as in Hades. @ @ PROBE_ARM arguments: @ sad, dad, cnt the channel's registers @ enable the value written to cnt (Hades: 0x80000001, immediate) @ en_to, dis_to where the enable and the disable are written (normally @ cnt; SIO32, a harmless register, to leave a write out) @ gap extra MOV R0,R0 between the enable and the disable @ tight 1: enable and disable on consecutive instructions @ read what the wait loop reads (normally cnt) @ cut where t2 is taken: 0 right after t1's store, 1 after the @ loop's literal load, 2 after the loop's read, 3 Hades .syntax unified .equ TM0L, 0x04000100 .equ TM0H, 0x04000102 .equ SIO32, 0x04000120 .equ KEYS, 0x04000130 .equ D0SAD, 0x040000B0 .equ D0DAD, 0x040000B4 .equ D0CNT, 0x040000B8 .equ D1SAD, 0x040000BC .equ D1DAD, 0x040000C0 .equ D1CNT, 0x040000C4 .equ D2SAD, 0x040000C8 .equ D2DAD, 0x040000CC .equ D2CNT, 0x040000D0 .equ D3SAD, 0x040000D4 .equ D3DAD, 0x040000D8 .equ D3CNT, 0x040000DC .macro T2 reg ldr \reg, =TM0L ldrh \reg, [\reg] strh \reg, [sp, #4] .endm .macro PROBE_ARM name, sad=D0SAD, dad=D0DAD, cnt=D0CNT, enable=0x80000001, en_to=D0CNT, dis_to=D0CNT, gap=0, tight=0, read=D0CNT, cut=3 .arm .align 2 .global \name \name: push {r4-r11, lr} mov r11, r0 sub sp, sp, #8 ldr r3, =0xDEAD strh r3, [sp] strh r3, [sp, #2] strh r3, [sp, #4] @ ---- Hades test 2 from here ldr r3, =TM0H mov r2, #0 strh r2, [r3] ldr r3, =TM0L mov r2, #0 strh r2, [r3] ldr r3, =TM0H mov r2, #0x80 strh r2, [r3] @ timer 0 starts, 1 tick per cycle ldr r3, =\sad ldr r2, =TM0L str r2, [r3] ldr r2, =\dad mov r3, sp str r3, [r2] .if \tight ldr r3, =\en_to ldr r2, =\enable mov r1, #0 ldr r4, =\dis_to str r2, [r3] @ enable str r1, [r4] @ disable, the very next instruction .else ldr r3, =\en_to mov r2, #\enable @ Hades: MOV, not a literal load str r2, [r3] @ enable .rept \gap mov r0, r0 .endr ldr r3, =\dis_to mov r2, #0 str r2, [r3] @ disable .endif ldr r3, =TM0L ldrh r3, [r3] strh r3, [sp, #2] @ t1 .if \cut == 0 T2 r1 .else 1: ldr r3, =\read .if \cut == 1 T2 r1 .else ldr r3, [r3] .if \cut == 2 T2 r1 .else cmp r3, #0 blt 1b ldr r3, =TM0L ldrh r3, [r3] strh r3, [sp, #4] @ t2 .endif .endif .endif @ ---- end of the Hades sequence; stop as Hades does ldr r3, =TM0H mov r2, #0 strh r2, [r3] ldr r3, =\cnt mov r2, #0 str r2, [r3] ldrh r0, [sp] strh r0, [r11] ldrh r0, [sp, #2] strh r0, [r11, #2] ldrh r0, [sp, #4] strh r0, [r11, #4] add sp, sp, #8 pop {r4-r11, lr} bx lr .pool .endm @ The same sequence in Thumb (what -O0 Thumb code does: literal loads, a @ frame pointer for the stack samples since Thumb STRH has no SP form). .macro PROBE_THUMB name .thumb .align 2 .global \name .thumb_func \name: push {r4-r7, lr} movs r4, r0 sub sp, #8 mov r7, sp ldr r3, =0xDEAD strh r3, [r7] strh r3, [r7, #2] strh r3, [r7, #4] ldr r3, =TM0H movs r2, #0 strh r2, [r3] ldr r3, =TM0L movs r2, #0 strh r2, [r3] ldr r3, =TM0H movs r2, #0x80 strh r2, [r3] ldr r3, =D0SAD ldr r2, =TM0L str r2, [r3] ldr r2, =D0DAD mov r3, sp str r3, [r2] ldr r3, =D0CNT ldr r2, =0x80000001 str r2, [r3] @ enable ldr r3, =D0CNT movs r2, #0 str r2, [r3] @ disable ldr r3, =TM0L ldrh r3, [r3] strh r3, [r7, #2] @ t1 1: ldr r3, =D0CNT ldr r3, [r3] cmp r3, #0 blt 1b ldr r3, =TM0L ldrh r3, [r3] strh r3, [r7, #4] @ t2 ldr r3, =TM0H movs r2, #0 strh r2, [r3] ldr r3, =D0CNT movs r2, #0 str r2, [r3] ldrh r0, [r7] strh r0, [r4] ldrh r0, [r7, #2] strh r0, [r4, #2] ldrh r0, [r7, #4] strh r0, [r4, #4] add sp, #8 pop {r4-r7} pop {r0} bx r0 .align 2 .pool .endm @ ---- IWRAM .section .iwram.probes, "ax", %progbits PROBE_ARM p_hades_iw PROBE_ARM p_cut0_iw, cut=0 PROBE_ARM p_cut1_iw, cut=1 PROBE_ARM p_cut2_iw, cut=2 PROBE_ARM p_readkey_iw, read=KEYS PROBE_ARM p_readd1_iw, read=D1CNT PROBE_ARM p_nowrite_iw, en_to=SIO32, dis_to=SIO32 PROBE_ARM p_enonly_iw, dis_to=SIO32 PROBE_ARM p_tight_iw, tight=1 PROBE_ARM p_gap1_iw, gap=1 PROBE_ARM p_gap2_iw, gap=2 PROBE_ARM p_gap4_iw, gap=4 PROBE_ARM p_gap8_iw, gap=8 PROBE_ARM p_gap32_iw, gap=32 PROBE_ARM p_vblank_iw, enable=0x90000001 PROBE_ARM p_ch1_iw, sad=D1SAD, dad=D1DAD, cnt=D1CNT, en_to=D1CNT, dis_to=D1CNT, read=D1CNT PROBE_ARM p_ch2_iw, sad=D2SAD, dad=D2DAD, cnt=D2CNT, en_to=D2CNT, dis_to=D2CNT, read=D2CNT PROBE_ARM p_ch3_iw, sad=D3SAD, dad=D3DAD, cnt=D3CNT, en_to=D3CNT, dis_to=D3CNT, read=D3CNT PROBE_THUMB p_thumb_iw @ ---- EWRAM .section .ewram.probes, "ax", %progbits PROBE_ARM p_hades_ew @ ---- ROM (WAITCNT, prefetch included, is set by the caller) .text PROBE_ARM p_hades_rom PROBE_ARM p_cut0_rom, cut=0 PROBE_ARM p_cut1_rom, cut=1 PROBE_ARM p_cut2_rom, cut=2 PROBE_ARM p_readkey_rom, read=KEYS PROBE_ARM p_nowrite_rom, en_to=SIO32, dis_to=SIO32 PROBE_THUMB p_thumb_rom