X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftom.cpp;h=44617b3daca40497901b2ba7fe70855e44ce748f;hb=731669ecc1eb876e42104a8a4ba49ac00572c020;hp=c01ddecc032201b9b3d35ce0bc46c295269a1dce;hpb=a71ef511af0a3680237ad91e7f80b2f77a10dcc4;p=virtualjaguar diff --git a/src/tom.cpp b/src/tom.cpp index c01ddec..44617b3 100644 --- a/src/tom.cpp +++ b/src/tom.cpp @@ -1,7 +1,7 @@ // // TOM Processing // -// by cal2 +// Originally by David Raingeard (cal2) // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) // Cleanups and endian wrongness amelioration by James L. Hammons // Note: Endian wrongness probably stems from the MAME origins of this emu and @@ -244,13 +244,22 @@ // F02298 W xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx B_Z0 - Z0 // ------------------------------------------------------------ -//#include #include "tom.h" + +#include // For memset() +#include // For rand() #include "video.h" #include "gpu.h" #include "objectp.h" #include "cry2rgb.h" #include "settings.h" +#include "clock.h" +#include "jaguar.h" +#include "log.h" +#include "blitter.h" +#include "m68k.h" + +#define NEW_TIMER_SYSTEM // TOM registers (offset from $F00000) @@ -268,7 +277,7 @@ #define HP 0x2E // Values range from 1 - 1024 (value written + 1) #define HBB 0x30 #define HBE 0x32 -#define HDB1 0x38 +#define HDB1 0x38 // Horizontal display begin 1 #define HDB2 0x3A #define HDE 0x3C #define VP 0x3E // Value ranges from 1 - 2048 (value written + 1) @@ -307,8 +316,8 @@ extern uint8 objectp_running; -static uint8 * tom_ram_8; -uint32 tom_width, tom_height, tom_real_internal_width; +uint8 tom_ram_8[0x4000]; +uint32 tom_width, tom_height; static uint32 tom_timer_prescaler; static uint32 tom_timer_divider; static int32 tom_timer_counter; @@ -316,30 +325,31 @@ static int32 tom_timer_counter; //uint32 hblankWidthInPixels = 0; uint16 tom_jerry_int_pending, tom_timer_int_pending, tom_object_int_pending, tom_gpu_int_pending, tom_video_int_pending; -uint16 * tom_cry_rgb_mix_lut; -int16 * TOMBackbuffer; +//uint16 * tom_cry_rgb_mix_lut; +//int16 * TOMBackbuffer; +uint32 * TOMBackbuffer; -static char * videoMode_to_str[8] = +static const char * videoMode_to_str[8] = { "16 BPP CRY", "24 BPP RGB", "16 BPP DIRECT", "16 BPP RGB", "Mixed mode", "24 BPP RGB", "16 BPP DIRECT", "16 BPP RGB" }; -typedef void (render_xxx_scanline_fn)(int16 *); +typedef void (render_xxx_scanline_fn)(uint32 *); // Private function prototypes -void tom_render_16bpp_cry_scanline(int16 * backbuffer); -void tom_render_24bpp_scanline(int16 * backbuffer); -void tom_render_16bpp_direct_scanline(int16 * backbuffer); -void tom_render_16bpp_rgb_scanline(int16 * backbuffer); -void tom_render_16bpp_cry_rgb_mix_scanline(int16 * backbuffer); +void tom_render_16bpp_cry_scanline(uint32 * backbuffer); +void tom_render_24bpp_scanline(uint32 * backbuffer); +void tom_render_16bpp_direct_scanline(uint32 * backbuffer); +void tom_render_16bpp_rgb_scanline(uint32 * backbuffer); +void tom_render_16bpp_cry_rgb_mix_scanline(uint32 * backbuffer); -void tom_render_16bpp_cry_stretch_scanline(int16 * backbuffer); -void tom_render_24bpp_stretch_scanline(int16 * backbuffer); -void tom_render_16bpp_direct_stretch_scanline(int16 * backbuffer); -void tom_render_16bpp_rgb_stretch_scanline(int16 * backbuffer); -void tom_render_16bpp_cry_rgb_mix_stretch_scanline(int16 * backbuffer); +void tom_render_16bpp_cry_stretch_scanline(uint32 * backbuffer); +void tom_render_24bpp_stretch_scanline(uint32 * backbuffer); +void tom_render_16bpp_direct_stretch_scanline(uint32 * backbuffer); +void tom_render_16bpp_rgb_stretch_scanline(uint32 * backbuffer); +void tom_render_16bpp_cry_rgb_mix_stretch_scanline(uint32 * backbuffer); -render_xxx_scanline_fn * scanline_render_normal[]= +render_xxx_scanline_fn * scanline_render_normal[] = { tom_render_16bpp_cry_scanline, tom_render_24bpp_scanline, @@ -351,7 +361,7 @@ render_xxx_scanline_fn * scanline_render_normal[]= tom_render_16bpp_rgb_scanline }; -render_xxx_scanline_fn * scanline_render_stretch[]= +render_xxx_scanline_fn * scanline_render_stretch[] = { tom_render_16bpp_cry_stretch_scanline, tom_render_24bpp_stretch_scanline, @@ -536,31 +546,36 @@ Trevor McFur Vertical resolution: 238 lines */ +uint32 RGB16ToRGB32[0x10000]; +uint32 CRY16ToRGB32[0x10000]; +uint32 MIX16ToRGB32[0x10000]; -void tom_calc_cry_rgb_mix_lut(void) +void TOMFillLookupTables(void) { - for (uint32 i=0; i<0x10000; i++) - { - uint16 color = i; + for(uint32 i=0; i<0x10000; i++) + RGB16ToRGB32[i] = 0xFF000000 + | ((i & 0xF100) >> 8) | ((i & 0xE000) >> 13) + | ((i & 0x07C0) << 13) | ((i & 0x0700) << 8) + | ((i & 0x003F) << 10) | ((i & 0x0030) << 4); - if (color & 0x01) - { - color >>= 1; - color = (color & 0x007C00) | ((color & 0x00003E0) >> 5) | ((color & 0x0000001F) << 5); - } - else - { - uint32 chrm = (color & 0xF000) >> 12, - chrl = (color & 0x0F00) >> 8, - y = color & 0x00FF; - uint16 red = (((uint32)redcv[chrm][chrl]) * y) >> 11, - green = (((uint32)greencv[chrm][chrl]) * y) >> 11, - blue = (((uint32)bluecv[chrm][chrl]) * y) >> 11; - color = (red << 10) | (green << 5) | blue; - } - tom_cry_rgb_mix_lut[i] = color; + for(uint32 i=0; i<0x10000; i++) + { + uint32 chrm = (i & 0xF000) >> 12, + chrl = (i & 0x0F00) >> 8, + y = (i & 0x00FF); + + uint32 r = (((uint32)redcv[chrm][chrl]) * y) >> 8, + g = (((uint32)greencv[chrm][chrl]) * y) >> 8, + b = (((uint32)bluecv[chrm][chrl]) * y) >> 8; + + CRY16ToRGB32[i] = 0xFF000000 | (b << 16) | (g << 8) | r; + MIX16ToRGB32[i] = CRY16ToRGB32[i]; } + + for(uint32 i=0; i<0x10000; i++) + if (i & 0x01) + MIX16ToRGB32[i] = RGB16ToRGB32[i]; } void tom_set_pending_jerry_int(void) @@ -610,8 +625,9 @@ uint16 tom_get_vdb(void) // // 16 BPP CRY/RGB mixed mode rendering // -void tom_render_16bpp_cry_rgb_mix_scanline(int16 * backbuffer) +void tom_render_16bpp_cry_rgb_mix_scanline(uint32 * backbuffer) { +//CHANGED TO 32BPP RENDERING uint16 width = tom_width; uint8 * current_line_buffer = (uint8 *)&tom_ram_8[0x1800]; @@ -627,13 +643,14 @@ void tom_render_16bpp_cry_rgb_mix_scanline(int16 * backbuffer) //This case doesn't properly handle the "start on the right side of virtual screen" case //Dunno why--looks Ok... //What *is* for sure wrong is that it doesn't copy the linebuffer's BG pixels... +//This should likely be 4 instead of 2 (?--not sure) backbuffer += 2 * startPos, width -= startPos; while (width) { uint16 color = (*current_line_buffer++) << 8; color |= *current_line_buffer++; - *backbuffer++ = tom_cry_rgb_mix_lut[color]; + *backbuffer++ = MIX16ToRGB32[color]; width--; } } @@ -641,8 +658,9 @@ void tom_render_16bpp_cry_rgb_mix_scanline(int16 * backbuffer) // // 16 BPP CRY mode rendering // -void tom_render_16bpp_cry_scanline(int16 * backbuffer) +void tom_render_16bpp_cry_scanline(uint32 * backbuffer) { +//CHANGED TO 32BPP RENDERING uint16 width = tom_width; uint8 * current_line_buffer = (uint8 *)&tom_ram_8[0x1800]; @@ -654,22 +672,14 @@ void tom_render_16bpp_cry_scanline(int16 * backbuffer) if (startPos < 0) current_line_buffer += 2 * -startPos; else +//This should likely be 4 instead of 2 (?--not sure) backbuffer += 2 * startPos, width -= startPos; while (width) { uint16 color = (*current_line_buffer++) << 8; color |= *current_line_buffer++; - - uint32 chrm = (color & 0xF000) >> 12, - chrl = (color & 0x0F00) >> 8, - y = (color & 0x00FF); - - uint16 red = (((uint32)redcv[chrm][chrl]) * y) >> 11, - green = (((uint32)greencv[chrm][chrl]) * y) >> 11, - blue = (((uint32)bluecv[chrm][chrl]) * y) >> 11; - - *backbuffer++ = (red << 10) | (green << 5) | blue; + *backbuffer++ = CRY16ToRGB32[color]; width--; } } @@ -677,8 +687,9 @@ void tom_render_16bpp_cry_scanline(int16 * backbuffer) // // 24 BPP mode rendering // -void tom_render_24bpp_scanline(int16 * backbuffer) +void tom_render_24bpp_scanline(uint32 * backbuffer) { +//CHANGED TO 32BPP RENDERING uint16 width = tom_width; uint8 * current_line_buffer = (uint8 *)&tom_ram_8[0x1800]; @@ -690,17 +701,16 @@ void tom_render_24bpp_scanline(int16 * backbuffer) if (startPos < 0) current_line_buffer += 4 * -startPos; else +//This should likely be 4 instead of 2 (?--not sure) backbuffer += 2 * startPos, width -= startPos; while (width) { - // This is NOT a good 8 -> 5 bit RGB conversion! (It saturates values below 8 - // to zero and throws away almost *half* the color resolution!) - uint16 green = (*current_line_buffer++) >> 3; - uint16 red = (*current_line_buffer++) >> 3; + uint32 g = *current_line_buffer++; + uint32 r = *current_line_buffer++; current_line_buffer++; - uint16 blue = (*current_line_buffer++) >> 3; - *backbuffer++ = (red << 10) | (green << 5) | blue; + uint32 b = *current_line_buffer++; + *backbuffer++ = 0xFF000000 | (b << 16) | (g << 8) | r; width--; } } @@ -710,7 +720,7 @@ void tom_render_24bpp_scanline(int16 * backbuffer) // // 16 BPP direct mode rendering // -void tom_render_16bpp_direct_scanline(int16 * backbuffer) +void tom_render_16bpp_direct_scanline(uint32 * backbuffer) { uint16 width = tom_width; uint8 * current_line_buffer = (uint8 *)&tom_ram_8[0x1800]; @@ -727,8 +737,11 @@ void tom_render_16bpp_direct_scanline(int16 * backbuffer) // // 16 BPP RGB mode rendering // -void tom_render_16bpp_rgb_scanline(int16 * backbuffer) +void tom_render_16bpp_rgb_scanline(uint32 * backbuffer) { +//CHANGED TO 32BPP RENDERING + // 16 BPP RGB: 0-5 green, 6-10 blue, 11-15 red + uint16 width = tom_width; uint8 * current_line_buffer = (uint8 *)&tom_ram_8[0x1800]; @@ -737,42 +750,44 @@ void tom_render_16bpp_rgb_scanline(int16 * backbuffer) //NOTE: May have to check HDB2 as well! int16 startPos = GET16(tom_ram_8, HDB1) - (vjs.hardwareTypeNTSC ? LEFT_VISIBLE_HC : LEFT_VISIBLE_HC_PAL); // Get start position in HC ticks startPos /= pwidth; + if (startPos < 0) current_line_buffer += 2 * -startPos; else +//This should likely be 4 instead of 2 (?--not sure) backbuffer += 2 * startPos, width -= startPos; while (width) { - uint16 color = (*current_line_buffer++) << 8; - color = (color | *current_line_buffer++) >> 1; - color = (color&0x7C00) | ((color&0x03E0) >> 5) | ((color&0x001F) << 5); - *backbuffer++ = color; + uint32 color = (*current_line_buffer++) << 8; + color |= *current_line_buffer++; + *backbuffer++ = RGB16ToRGB32[color]; width--; } } -// This stuff may just go away by itself, especially if we do some -// good old OpenGL goodness... +///////////////////////////////////////////////////////////////////// +// This stuff may just go away by itself, especially if we do some // +// good old OpenGL goodness... // +///////////////////////////////////////////////////////////////////// -void tom_render_16bpp_cry_rgb_mix_stretch_scanline(int16 *backbuffer) +void tom_render_16bpp_cry_rgb_mix_stretch_scanline(uint32 *backbuffer) { uint16 width=tom_width; uint8 *current_line_buffer=(uint8*)&tom_ram_8[0x1800]; while (width) { - uint16 color; - color=*current_line_buffer++; - color<<=8; - color|=*current_line_buffer++; - *backbuffer++=tom_cry_rgb_mix_lut[color]; - current_line_buffer+=2; + uint16 color = *current_line_buffer++; + color <<= 8; + color |= *current_line_buffer++; + *backbuffer++ = MIX16ToRGB32[color]; + current_line_buffer += 2; width--; } } -void tom_render_16bpp_cry_stretch_scanline(int16 *backbuffer) +void tom_render_16bpp_cry_stretch_scanline(uint32 *backbuffer) { uint32 chrm, chrl, y; @@ -816,7 +831,7 @@ void tom_render_16bpp_cry_stretch_scanline(int16 *backbuffer) } } -void tom_render_24bpp_stretch_scanline(int16 *backbuffer) +void tom_render_24bpp_stretch_scanline(uint32 *backbuffer) { uint16 width=tom_width; uint8 *current_line_buffer=(uint8*)&tom_ram_8[0x1800]; @@ -836,7 +851,7 @@ void tom_render_24bpp_stretch_scanline(int16 *backbuffer) } } -void tom_render_16bpp_direct_stretch_scanline(int16 *backbuffer) +void tom_render_16bpp_direct_stretch_scanline(uint32 *backbuffer) { uint16 width=tom_width; uint8 *current_line_buffer=(uint8*)&tom_ram_8[0x1800]; @@ -853,7 +868,7 @@ void tom_render_16bpp_direct_stretch_scanline(int16 *backbuffer) } } -void tom_render_16bpp_rgb_stretch_scanline(int16 *backbuffer) +void tom_render_16bpp_rgb_stretch_scanline(uint32 *backbuffer) { uint16 width=tom_width; uint8 *current_line_buffer=(uint8*)&tom_ram_8[0x1800]; @@ -878,7 +893,7 @@ void tom_render_16bpp_rgb_stretch_scanline(int16 *backbuffer) } } -void TOMResetBackbuffer(int16 * backbuffer) +void TOMResetBackbuffer(uint32 * backbuffer) { TOMBackbuffer = backbuffer; } @@ -912,26 +927,63 @@ void TOMExecScanline(uint16 scanline, bool render) else inActiveDisplayArea = false; -//Try to take PAL into account... -uint16 topVisible = (vjs.hardwareTypeNTSC ? TOP_VISIBLE_VC : TOP_VISIBLE_VC_PAL), - bottomVisible = (vjs.hardwareTypeNTSC ? BOTTOM_VISIBLE_VC : BOTTOM_VISIBLE_VC_PAL); + // Try to take PAL into account... + + uint16 topVisible = (vjs.hardwareTypeNTSC ? TOP_VISIBLE_VC : TOP_VISIBLE_VC_PAL), + bottomVisible = (vjs.hardwareTypeNTSC ? BOTTOM_VISIBLE_VC : BOTTOM_VISIBLE_VC_PAL); + // Here's our virtualized scanline code... + if (scanline >= topVisible && scanline < bottomVisible) { if (inActiveDisplayArea) - scanline_render[tom_getVideoMode()](TOMBackbuffer); + { +//NOTE: The following doesn't put BORDER color on the sides... !!! FIX !!! + if (vjs.renderType == RT_NORMAL) + scanline_render[tom_getVideoMode()](TOMBackbuffer); + else//TV type render + { +/* + tom_render_16bpp_cry_scanline, + tom_render_24bpp_scanline, + tom_render_16bpp_direct_scanline, + tom_render_16bpp_rgb_scanline, + tom_render_16bpp_cry_rgb_mix_scanline, + tom_render_24bpp_scanline, + tom_render_16bpp_direct_scanline, + tom_render_16bpp_rgb_scanline +#define VMODE 0x28 +#define MODE 0x0006 // Line buffer to video generator mode +#define VARMOD 0x0100 // Mixed CRY/RGB16 mode (only works in MODE 0!) +*/ + uint8 pwidth = ((GET16(tom_ram_8, VMODE) & PWIDTH) >> 9) + 1; + uint8 mode = ((GET16(tom_ram_8, VMODE) & MODE) >> 1); + bool varmod = GET16(tom_ram_8, VMODE) & VARMOD; +//The video texture line buffer ranges from 0 to 1279, with its left edge starting at LEFT_VISIBLE_HC. +//So, we need to start writing into the backbuffer at HDB1, using pwidth as our scaling factor. The +//way it generates its image on a real TV! + +//So, for example, if HDB1 is less than LEFT_VISIBLE_HC, then we have to figure out where in the VTLB +//that we start writing pixels from the Jaguar line buffer (VTLB start=0, JLB=something). + + } + } else { // If outside of VDB & VDE, then display the border color - int16 * currentLineBuffer = TOMBackbuffer; +/* int16 * currentLineBuffer = TOMBackbuffer; uint8 g = tom_ram_8[BORD1], r = tom_ram_8[BORD1 + 1], b = tom_ram_8[BORD2 + 1]; - uint16 pixel = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3); + uint16 pixel = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3);//*/ + uint32 * currentLineBuffer = TOMBackbuffer; + uint8 g = tom_ram_8[BORD1], r = tom_ram_8[BORD1 + 1], b = tom_ram_8[BORD2 + 1]; + uint32 pixel = 0xFF000000 | (b << 16) | (g << 8) | r; for(uint32 i=0; i= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) return GPUReadByte(offset, who); - else if ((offset >= 0xF00010) && (offset < 0xF00028)) - return OPReadByte(offset, who); +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) + return OPReadByte(offset, who);*/ else if ((offset >= 0xF02200) && (offset < 0xF022A0)) return BlitterReadByte(offset, who); else if (offset == 0xF00050) @@ -1192,12 +1243,22 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) //But it's causing Rayman to be fucked up... Why??? //Because VC is even in NI mode when calling the OP! That's why! return (tom_scanline << 1) + 1;//*/ - else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20)) +/* +// F00004 R/W -----xxx xxxxxxxx HC - horizontal count +// -----x-- -------- (which half of the display) +// ------xx xxxxxxxx (10-bit counter) +*/ +// This is a kludge to get the HC working somewhat... What we really should do here +// is check what the global time is at the time of the read and calculate the correct HC... +// !!! FIX !!! + else if (offset == 0xF00004) + return rand() & 0x03FF; + else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE + 0x20)) return GPUReadWord(offset, who); - else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) + else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000)) return GPUReadWord(offset, who); - else if ((offset >= 0xF00010) && (offset < 0xF00028)) - return OPReadWord(offset, who); +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) + return OPReadWord(offset, who);*/ else if ((offset >= 0xF02200) && (offset < 0xF022A0)) return BlitterReadWord(offset, who); else if (offset == 0xF00050) @@ -1232,11 +1293,11 @@ void TOMWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) GPUWriteByte(offset, data, who); return; } - else if ((offset >= 0xF00010) && (offset < 0xF00028)) +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) { OPWriteByte(offset, data, who); return; - } + }*/ else if ((offset >= 0xF02200) && (offset < 0xF022A0)) { BlitterWriteByte(offset, data, who); @@ -1310,11 +1371,11 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) TOMWriteByte(offset, data >> 8); TOMWriteByte(offset+1, data & 0xFF); }*/ - else if ((offset >= 0xF00010) && (offset < 0xF00028)) +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) { OPWriteWord(offset, data, who); return; - } + }*/ else if (offset == 0xF00050) { tom_timer_prescaler = data; @@ -1351,11 +1412,14 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) // Writing to one CLUT writes to the other offset &= 0x5FF; // Mask out $F00600 (restrict to $F00400-5FF) // Watch out for unaligned writes here! (Not fixed yet) - SET16(tom_ram_8, offset, data), SET16(tom_ram_8, offset + 0x200, data); + SET16(tom_ram_8, offset, data); + SET16(tom_ram_8, offset + 0x200, data); } offset &= 0x3FFF; if (offset == 0x28) // VMODE (Why? Why not OBF?) +//Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!! +#warning Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!! objectp_running = 1; if (offset >= 0x30 && offset <= 0x4E) @@ -1399,12 +1463,13 @@ if (offset == VMODE) if ((offset >= 0x28) && (offset <= 0x4F)) { uint32 width = tom_getVideoModeWidth(), height = tom_getVideoModeHeight(); - tom_real_internal_width = width; if ((width != tom_width) || (height != tom_height)) { tom_width = width, tom_height = height; - ResizeScreen(tom_width, tom_height); + + if (vjs.renderType == RT_NORMAL) + ResizeScreen(tom_width, tom_height); } } } @@ -1428,8 +1493,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 @@ -1437,12 +1510,24 @@ 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 } // // TOM Programmable Interrupt Timer handler // NOTE: TOM's PIT is only enabled if the prescaler is != 0 // +//NOTE: This is only used by the old execution code... Safe to remove +// once the timer system is stable. void TOMExecPIT(uint32 cycles) { if (tom_timer_prescaler) @@ -1453,10 +1538,25 @@ void TOMExecPIT(uint32 cycles) { tom_set_pending_timer_int(); GPUSetIRQLine(GPUIRQ_TIMER, ASSERT_LINE); // GPUSetIRQLine does the 'IRQ enabled' checking - if (tom_irq_enabled(IRQ_TIMER))//get rid of this crap -> && jaguar_interrupt_handler_is_valid(64)) - m68k_set_irq(7); // Cause a 68000 NMI... + + if (tom_irq_enabled(IRQ_TIMER)) + m68k_set_irq(7); // Cause a 68000 NMI... TOMResetPIT(); } } } + + +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(); +}