X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftom.cpp;h=ca38c13c54fb879b52ac6d78b29f177d458c9d25;hb=3580a9ef98432ed54f065f2d537d588fdc083592;hp=604f2cce1e5d96fa1cf85a20eab159edf2c97800;hpb=5e091ddd7723a0a7b4c86df576b3c6331316d4ff;p=virtualjaguar diff --git a/src/tom.cpp b/src/tom.cpp index 604f2cc..ca38c13 100644 --- a/src/tom.cpp +++ b/src/tom.cpp @@ -251,6 +251,9 @@ #include "objectp.h" #include "cry2rgb.h" #include "settings.h" +#include "clock.h" + +#define NEW_TIMER_SYSTEM // TOM registers (offset from $F00000) @@ -969,7 +972,7 @@ uint16 topVisible = (vjs.hardwareTypeNTSC ? TOP_VISIBLE_VC : TOP_VISIBLE_VC_PAL) } // TOMBackbuffer += GetSDLScreenPitch() / 2; // Returns bytes, but we need words - TOMBackbuffer += GetSDLScreenPitch() / 4; // Returns bytes, but we need dwords + TOMBackbuffer += GetSDLScreenWidthInPixels(); } } @@ -1467,8 +1470,16 @@ int tom_irq_enabled(int irq) return (tom_ram_8[0xE0] << 8) | tom_ram_8[0xE1]; }*/ +// NEW: +// TOM Programmable Interrupt Timer handler +// NOTE: TOM's PIT is only enabled if the prescaler is != 0 +// The PIT only generates an interrupt when it counts down to zero, not when loaded! + +void TOMPITCallback(void); + void TOMResetPIT(void) { +#ifndef NEW_TIMER_SYSTEM //Probably should *add* this amount to the counter to retain cycle accuracy! !!! FIX !!! [DONE] //Also, why +1??? 'Cause that's what it says in the JTRM...! //There is a small problem with this approach: If both the prescaler and the divider are equal @@ -1476,6 +1487,16 @@ void TOMResetPIT(void) if (tom_timer_prescaler) tom_timer_counter += (1 + tom_timer_prescaler) * (1 + tom_timer_divider); // WriteLog("tom: reseting timer to 0x%.8x (%i)\n",tom_timer_counter,tom_timer_counter); +#else + // Need to remove previous timer from the queue, if it exists... + RemoveCallback(TOMPITCallback); + + if (tom_timer_prescaler) + { + double usecs = (float)(tom_timer_prescaler + 1) * (float)(tom_timer_divider + 1) * RISC_CYCLE_IN_USEC; + SetCallbackTime(TOMPITCallback, usecs); + } +#endif } // @@ -1499,3 +1520,17 @@ void TOMExecPIT(uint32 cycles) } } } + + +void TOMPITCallback(void) +{ +// INT1_RREG |= 0x08; // Set TOM PIT interrupt pending + tom_set_pending_timer_int(); + GPUSetIRQLine(GPUIRQ_TIMER, ASSERT_LINE); // It does the 'IRQ enabled' checking + +// if (INT1_WREG & 0x08) + if (tom_irq_enabled(IRQ_TIMER)) + m68k_set_irq(7); // Generate 68K NMI + + TOMResetPIT(); +}