From c5cc2f1e50c96c9baed1f2b3e90d71e35f988449 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Tue, 6 Jan 2015 14:10:48 +0200 Subject: [PATCH] Document sh4_shced, fix tmu a bit --- core/hw/sh4/interpr/sh4_interpreter.cpp | 5 +- core/hw/sh4/modules/tmu.cpp | 74 ++++++++++++------------- core/hw/sh4/sh4_sched.cpp | 8 +++ core/hw/sh4/sh4_sched.h | 33 +++++++++++ 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/core/hw/sh4/interpr/sh4_interpreter.cpp b/core/hw/sh4/interpr/sh4_interpreter.cpp index 16ee6f82b..f5640af6c 100644 --- a/core/hw/sh4/interpr/sh4_interpreter.cpp +++ b/core/hw/sh4/interpr/sh4_interpreter.cpp @@ -170,6 +170,8 @@ int AicaUpdate(int tag, int c, int j) return AICA_TICK; } + + int DreamcastSecond(int tag, int c, int j) { settings.dreamcast.RTC++; @@ -183,7 +185,8 @@ int DreamcastSecond(int tag, int c, int j) #endif //printf("%d ticks\n",sh4_sched_intr); - sh4_sched_intr=0; return SH4_MAIN_CLOCK; + sh4_sched_intr=0; + return SH4_MAIN_CLOCK; } int UpdateSystem_rec() diff --git a/core/hw/sh4/modules/tmu.cpp b/core/hw/sh4/modules/tmu.cpp index f207babd0..28d500330 100644 --- a/core/hw/sh4/modules/tmu.cpp +++ b/core/hw/sh4/modules/tmu.cpp @@ -100,29 +100,28 @@ void write_TMU_TCNT(u32 addr, u32 data) write_TMU_TCNTch(ch,data); } +void sched_chan_tick(int ch) +{ + //schedule next interrupt + //return TMU_TCOR(ch) << tmu_shift[ch]; + + u32 tcor = TMU_TCOR(ch); + u32 cycles = tcor << tmu_shift[ch]; + + if (tmu_mask[ch]) + sh4_sched_request(tmu_sched[ch], cycles); + else + sh4_sched_request(tmu_sched[ch], -1); + //sched_tmu_cb +} + void turn_on_off_ch(u32 ch, bool on) { u32 TCNT=read_TMU_TCNTch(ch); tmu_mask[ch]=on?0xFFFFFFFF:0x00000000; write_TMU_TCNTch(ch,TCNT); -} -void sched_chan_tick(int ch) -{ - //max ticks - u32 tcnt = read_TMU_TCNTch(ch); - - u64 togo=tcnt; - - togo<<=tmu_shift[ch]; - - if (togo>SH4_MAIN_CLOCK) - togo=SH4_MAIN_CLOCK; - - if (togo>-sh4_sched_now()) - togo=-sh4_sched_now(); - - sh4_sched_request(tmu_sched[ch],togo); + sched_chan_tick(ch); } //Update internal counter registers @@ -173,6 +172,7 @@ void UpdateTMUCounts(u32 reg) } tmu_shift[reg]+=2; write_TMU_TCNTch(reg,TCNT); + sched_chan_tick(reg); } //Write to status registers @@ -204,25 +204,24 @@ void write_TMU_TSTR(u32 addr, u32 data) turn_on_off_ch(i,data&(1<