Skip to content

Commit

Permalink
Hack to improve timers used as counter
Browse files Browse the repository at this point in the history
Fixes smashing drive running too fast
Improves Bibi und Tina a bit, but still has problems (uses cascade)
  • Loading branch information
Gericom committed Apr 12, 2020
1 parent 08ec54a commit bb15d71
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
6 changes: 6 additions & 0 deletions arm9/source/dtcm_data.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 41 additions & 7 deletions arm9/source/emu/timer.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,60 @@

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

.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
Expand Down
10 changes: 10 additions & 0 deletions arm9/source/gamePatches.vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit bb15d71

Please sign in to comment.