From bb15d71dbb703b23ee47f8f55244569405894aa8 Mon Sep 17 00:00:00 2001 From: Gericom Date: Sun, 12 Apr 2020 23:17:59 +0200 Subject: [PATCH] Hack to improve timers used as counter Fixes smashing drive running too fast Improves Bibi und Tina a bit, but still has problems (uses cascade) --- arm9/source/dtcm_data.s | 6 ++++ arm9/source/emu/timer.s | 48 +++++++++++++++++++++++++++----- arm9/source/gamePatches.vram.cpp | 10 +++++++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/arm9/source/dtcm_data.s b/arm9/source/dtcm_data.s index 6263dad..82ef0f9 100644 --- a/arm9/source/dtcm_data.s +++ b/arm9/source/dtcm_data.s @@ -309,6 +309,12 @@ timer_shadow_regs_dtcm: .short 0 //reload value .endr +.global timer_shadow_regs_count_dtcm +timer_shadow_regs_count_dtcm: +.rept 4 + .short 0 //counter value +.endr + //the current bios opcode that is returned if you do a protected read //[00DCh+8] = 0xE129F000, after startup and softreset //before this address 0x27C is read //[0134h+8] = 0xE25EF004, during irq execution diff --git a/arm9/source/emu/timer.s b/arm9/source/emu/timer.s index 5e42852..ecf6d60 100644 --- a/arm9/source/emu/timer.s +++ b/arm9/source/emu/timer.s @@ -8,18 +8,41 @@ ADDRESS_TIMER_BASE = 0x04000100 -.macro fix_timer_counter_read regb, rega - mov \regb, \rega, lsl #16 +// .macro fix_timer_counter_read regb, rega +// mov \regb, \rega, lsl #16 +// tst \rega, #(4 << 16) +// movne \regb, \regb, lsr #16 //if slave mode, don't divide by 2 +// moveq \regb, \regb, lsr #17 //if normal mode, fix timer value +// orreq \regb, \regb, #0x8000 //set top bit as we assume this bit was 1 (we don't really have a proper way of fixing that) +// .endm + +.macro fix_timer_counter_read regb, rega, regc tst \rega, #(4 << 16) - movne \regb, \regb, lsr #16 //if slave mode, don't divide by 2 - moveq \regb, \regb, lsr #17 //if normal mode, fix timer value - orreq \regb, \regb, #0x8000 //set top bit as we assume this bit was 1 (we don't really have a proper way of fixing that) + mov \regb, \rega, lsl #16 + movne \regb, \regb, lsr #16 //if slave mode, don't divide by 2 + bne 1f + mov \regb, \regb, lsr #17 //if normal mode, fix timer value + tst \regc, #0x8000 + orrne \regb, #0x8000 + cmp \regb, \regc + eorlt \regb, #0x8000 +1: .endm .global read_address_timer_counter read_address_timer_counter: ldr r10, [r9] //read full info - fix_timer_counter_read r10, r10 + + ldr r12,= ADDRESS_TIMER_BASE + ldr r13,= timer_shadow_regs_count_dtcm + sub r12, r9, r12 + add r13, r12, lsr #1 + ldrh r11, [r13] + + fix_timer_counter_read r10, r10, r11 + + strh r10, [r13] + //ldrh r10, [r9] //mov r10, r10, lsr #1 bx lr @@ -27,7 +50,18 @@ read_address_timer_counter: .global read_address_timer read_address_timer: ldr r10, [r9] - fix_timer_counter_read r12, r10 + + + ldr r12,= ADDRESS_TIMER_BASE + ldr r13,= timer_shadow_regs_count_dtcm + sub r12, r9, r12 + add r13, r12, lsr #1 + ldrh r11, [r13] + + fix_timer_counter_read r12, r10, r11 + + strh r12, [r13] + mov r10, r10, lsr #16 orr r10, r12, r10, lsl #16 //mov r12, r10, lsr #16 diff --git a/arm9/source/gamePatches.vram.cpp b/arm9/source/gamePatches.vram.cpp index 1916d00..acf4959 100644 --- a/arm9/source/gamePatches.vram.cpp +++ b/arm9/source/gamePatches.vram.cpp @@ -173,6 +173,16 @@ void gptc_patchRom() *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x3D73C0) = 0xE3A0001B; *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x3D73FC) = 0xE3A0009B; } + else if(gameCode == 0x50565342) + { + //Smashing Drive (Europe) (En,Fr,De,Es,It) + *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x7F4C2C) = 0xE8990E00; + } + else if(gameCode == 0x45565342) + { + //Smashing Drive (USA) + *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x7F62B8) = 0xE8990E00; + } #endif /*else if(gameCode == 0x45573241 || gameCode == 0x50573241) {