X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftom.cpp;h=44617b3daca40497901b2ba7fe70855e44ce748f;hb=731669ecc1eb876e42104a8a4ba49ac00572c020;hp=604f2cce1e5d96fa1cf85a20eab159edf2c97800;hpb=4b32affecce8cf8f557feb96daa76ba1692c3afe;p=virtualjaguar diff --git a/src/tom.cpp b/src/tom.cpp index 604f2cc..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,11 +325,11 @@ 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; +//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" }; @@ -340,7 +349,7 @@ 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, @@ -352,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, @@ -569,32 +578,6 @@ void TOMFillLookupTables(void) MIX16ToRGB32[i] = RGB16ToRGB32[i]; } -/*void tom_calc_cry_rgb_mix_lut(void) -{ - for (uint32 i=0; i<0x10000; i++) - { - uint16 color = i; - - 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; - } -}*/ - void tom_set_pending_jerry_int(void) { tom_jerry_int_pending = 1; @@ -667,7 +650,6 @@ void tom_render_16bpp_cry_rgb_mix_scanline(uint32 * backbuffer) { uint16 color = (*current_line_buffer++) << 8; color |= *current_line_buffer++; -// *backbuffer++ = tom_cry_rgb_mix_lut[color]; *backbuffer++ = MIX16ToRGB32[color]; width--; } @@ -796,12 +778,11 @@ void tom_render_16bpp_cry_rgb_mix_stretch_scanline(uint32 *backbuffer) 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--; } } @@ -946,14 +927,47 @@ 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 @@ -969,7 +983,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(); } } @@ -978,12 +992,12 @@ uint16 topVisible = (vjs.hardwareTypeNTSC ? TOP_VISIBLE_VC : TOP_VISIBLE_VC_PAL) // void tom_init(void) { - memory_malloc_secure((void **)&tom_cry_rgb_mix_lut, 2 * 0x10000, "CRY/RGB mixed mode LUT"); +// memory_malloc_secure((void **)&tom_cry_rgb_mix_lut, 2 * 0x10000, "CRY/RGB mixed mode LUT"); op_init(); blitter_init(); //This should be done by JERRY! pcm_init(); - memory_malloc_secure((void **)&tom_ram_8, 0x4000, "TOM RAM"); +// memory_malloc_secure((void **)&tom_ram_8, 0x4000, "TOM RAM"); tom_reset(); // Setup the non-stretchy scanline rendering... memcpy(scanline_render, scanline_render_normal, sizeof(scanline_render)); @@ -1003,8 +1017,8 @@ void tom_done(void) // WriteLog("tom: INT1=0x%.2x%.2x\n",TOMReadByte(0xf000e0),TOMReadByte(0xf000e1)); // gpu_done(); // dsp_done(); - memory_free(tom_ram_8); - memory_free(tom_cry_rgb_mix_lut); +// memory_free(tom_ram_8); +// memory_free(tom_cry_rgb_mix_lut); } /*uint32 tom_getHBlankWidthInPixels(void) @@ -1113,46 +1127,44 @@ void tom_reset(void) { op_reset(); blitter_reset(); -//This should be done by JERRY! pcm_reset(); - memset(tom_ram_8, 0x00, 0x4000); if (vjs.hardwareTypeNTSC) { SET16(tom_ram_8, MEMCON1, 0x1861); SET16(tom_ram_8, MEMCON2, 0x35CC); - SET16(tom_ram_8, HP, 844); // Horizontal Period (1-based; HP=845) - SET16(tom_ram_8, HBB, 1713); // Horizontal Blank Begin - SET16(tom_ram_8, HBE, 125); // Horizontal Blank End - SET16(tom_ram_8, HDE, 1665); // Horizontal Display End - SET16(tom_ram_8, HDB1, 203); // Horizontal Display Begin 1 - SET16(tom_ram_8, VP, 523); // Vertical Period (1-based; in this case VP = 524) - SET16(tom_ram_8, VBE, 24); // Vertical Blank End - SET16(tom_ram_8, VDB, 38); // Vertical Display Begin - SET16(tom_ram_8, VDE, 518); // Vertical Display End - SET16(tom_ram_8, VBB, 500); // Vertical Blank Begin - SET16(tom_ram_8, VS, 517); // Vertical Sync + SET16(tom_ram_8, HP, 844); // Horizontal Period (1-based; HP=845) + SET16(tom_ram_8, HBB, 1713); // Horizontal Blank Begin + SET16(tom_ram_8, HBE, 125); // Horizontal Blank End + SET16(tom_ram_8, HDE, 1665); // Horizontal Display End + SET16(tom_ram_8, HDB1, 203); // Horizontal Display Begin 1 + SET16(tom_ram_8, VP, 523); // Vertical Period (1-based; in this case VP = 524) + SET16(tom_ram_8, VBE, 24); // Vertical Blank End + SET16(tom_ram_8, VDB, 38); // Vertical Display Begin + SET16(tom_ram_8, VDE, 518); // Vertical Display End + SET16(tom_ram_8, VBB, 500); // Vertical Blank Begin + SET16(tom_ram_8, VS, 517); // Vertical Sync SET16(tom_ram_8, VMODE, 0x06C1); } else // PAL Jaguar { SET16(tom_ram_8, MEMCON1, 0x1861); SET16(tom_ram_8, MEMCON2, 0x35CC); - SET16(tom_ram_8, HP, 850); // Horizontal Period - SET16(tom_ram_8, HBB, 1711); // Horizontal Blank Begin - SET16(tom_ram_8, HBE, 158); // Horizontal Blank End - SET16(tom_ram_8, HDE, 1665); // Horizontal Display End - SET16(tom_ram_8, HDB1, 203); // Horizontal Display Begin 1 - SET16(tom_ram_8, VP, 623); // Vertical Period (1-based; in this case VP = 624) - SET16(tom_ram_8, VBE, 34); // Vertical Blank End - SET16(tom_ram_8, VDB, 38); // Vertical Display Begin - SET16(tom_ram_8, VDE, 518); // Vertical Display End - SET16(tom_ram_8, VBB, 600); // Vertical Blank Begin - SET16(tom_ram_8, VS, 618); // Vertical Sync + SET16(tom_ram_8, HP, 850); // Horizontal Period + SET16(tom_ram_8, HBB, 1711); // Horizontal Blank Begin + SET16(tom_ram_8, HBE, 158); // Horizontal Blank End + SET16(tom_ram_8, HDE, 1665); // Horizontal Display End + SET16(tom_ram_8, HDB1, 203); // Horizontal Display Begin 1 + SET16(tom_ram_8, VP, 623); // Vertical Period (1-based; in this case VP = 624) + SET16(tom_ram_8, VBE, 34); // Vertical Blank End + SET16(tom_ram_8, VDB, 38); // Vertical Display Begin + SET16(tom_ram_8, VDE, 518); // Vertical Display End + SET16(tom_ram_8, VBB, 600); // Vertical Blank Begin + SET16(tom_ram_8, VS, 618); // Vertical Sync SET16(tom_ram_8, VMODE, 0x06C1); } - tom_width = tom_real_internal_width = 0; + tom_width = 0; tom_height = 0; tom_jerry_int_pending = 0; @@ -1161,7 +1173,7 @@ void tom_reset(void) tom_gpu_int_pending = 0; tom_video_int_pending = 0; - tom_timer_prescaler = 0; // TOM PIT is disabled + tom_timer_prescaler = 0; // TOM PIT is disabled tom_timer_divider = 0; tom_timer_counter = 0; memcpy(scanline_render, scanline_render_normal, sizeof(scanline_render)); @@ -1186,8 +1198,8 @@ uint8 TOMReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) return GPUReadByte(offset, who); else if ((offset >= 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) @@ -1231,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) @@ -1271,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); @@ -1349,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; @@ -1390,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) @@ -1438,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); } } } @@ -1467,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 @@ -1476,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) @@ -1492,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(); +}