X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftom.cpp;h=b3882a09f3fbe645e4b1b17ba6d6c2aaf21f9483;hb=4beff2f35f649bb0befa58c8a89fdd702b3c9b4f;hp=03523bfafbb28bab75849f5d03fd2002b16c5a69;hpb=d239de704f276a75d927900e3d413a44cc87116c;p=virtualjaguar diff --git a/src/tom.cpp b/src/tom.cpp index 03523bf..b3882a0 100644 --- a/src/tom.cpp +++ b/src/tom.cpp @@ -4,6 +4,14 @@ // 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 +// (C) 2010 Underground Software +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ------------------------------------------------------------- +// JLH 01/16/2010 Created this log ;-) +// // Note: Endian wrongness probably stems from the MAME origins of this emu and // the braindead way in which MAME handles memory. :-) // @@ -255,6 +263,7 @@ #include "jaguar.h" #include "log.h" #include "m68k.h" +//#include "memory.h" #include "objectp.h" #include "settings.h" #include "video.h" @@ -314,13 +323,11 @@ //(It's easier to do it here, though...) //#define TOM_DEBUG -extern uint8 objectp_running; - uint8 tomRam8[0x4000]; uint32 tomWidth, tomHeight; -static uint32 tom_timer_prescaler; -static uint32 tom_timer_divider; -static int32 tom_timer_counter; +uint32 tomTimerPrescaler; +uint32 tomTimerDivider; +int32 tomTimerCounter; //uint32 tom_scanline; //uint32 hblankWidthInPixels = 0; uint16 tom_jerry_int_pending, tom_timer_int_pending, tom_object_int_pending, @@ -550,6 +557,7 @@ uint32 RGB16ToRGB32[0x10000]; uint32 CRY16ToRGB32[0x10000]; uint32 MIX16ToRGB32[0x10000]; +#warning "This is not endian-safe. !!! FIX !!!" void TOMFillLookupTables(void) { for(uint32 i=0; i<0x10000; i++) @@ -570,12 +578,12 @@ void TOMFillLookupTables(void) b = (((uint32)bluecv[chrm][chrl]) * y) >> 8; CRY16ToRGB32[i] = 0xFF000000 | (b << 16) | (g << 8) | r; - MIX16ToRGB32[i] = CRY16ToRGB32[i]; + MIX16ToRGB32[i] = (i & 0x01 ? RGB16ToRGB32[i] : CRY16ToRGB32[i]); } - for(uint32 i=0; i<0x10000; i++) - if (i & 0x01) - MIX16ToRGB32[i] = RGB16ToRGB32[i]; +// for(uint32 i=0; i<0x10000; i++) +// if (i & 0x01) +// MIX16ToRGB32[i] = RGB16ToRGB32[i]; } void TOMSetPendingJERRYInt(void) @@ -615,10 +623,9 @@ uint8 TOMGetVideoMode(void) } //Used in only one place (and for debug purposes): OBJECTP.CPP +#warning "Used in only one place (and for debug purposes): OBJECTP.CPP !!! FIX !!!" uint16 TOMGetVDB(void) { -// This in NOT VDB!!! -// return GET16(tomRam8, VBE); return GET16(tomRam8, VDB); } @@ -939,6 +946,7 @@ void TOMExecScanline(uint16 scanline, bool render) if (inActiveDisplayArea) { //NOTE: The following doesn't put BORDER color on the sides... !!! FIX !!! +#warning "The following doesn't put BORDER color on the sides... !!! FIX !!!" if (vjs.renderType == RT_NORMAL) scanline_render[TOMGetVideoMode()](TOMBackbuffer); else//TV type render @@ -959,21 +967,51 @@ void TOMExecScanline(uint16 scanline, bool render) uint8 pwidth = ((GET16(tomRam8, VMODE) & PWIDTH) >> 9) + 1; uint8 mode = ((GET16(tomRam8, VMODE) & MODE) >> 1); bool varmod = GET16(tomRam8, 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! +//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). +#if 0 +// +// 24 BPP mode rendering +// +void tom_render_24bpp_scanline(uint32 * backbuffer) +{ +//CHANGED TO 32BPP RENDERING + uint16 width = tomWidth; + uint8 * current_line_buffer = (uint8 *)&tomRam8[0x1800]; + + //New stuff--restrict our drawing... + uint8 pwidth = ((GET16(tomRam8, VMODE) & PWIDTH) >> 9) + 1; + //NOTE: May have to check HDB2 as well! + int16 startPos = GET16(tomRam8, HDB1) - (vjs.hardwareTypeNTSC ? LEFT_VISIBLE_HC : LEFT_VISIBLE_HC_PAL); // Get start position in HC ticks + startPos /= pwidth; + if (startPos < 0) + current_line_buffer += 4 * -startPos; + else +//This should likely be 4 instead of 2 (?--not sure) + backbuffer += 2 * startPos, width -= startPos; -//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). + while (width) + { + uint32 g = *current_line_buffer++; + uint32 r = *current_line_buffer++; + current_line_buffer++; + uint32 b = *current_line_buffer++; + *backbuffer++ = 0xFF000000 | (b << 16) | (g << 8) | r; + width--; + } +} +#endif } } else { // If outside of VDB & VDE, then display the border color -/* int16 * currentLineBuffer = TOMBackbuffer; - uint8 g = tomRam8[BORD1], r = tomRam8[BORD1 + 1], b = tomRam8[BORD2 + 1]; - uint16 pixel = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3);//*/ uint32 * currentLineBuffer = TOMBackbuffer; uint8 g = tomRam8[BORD1], r = tomRam8[BORD1 + 1], b = tomRam8[BORD2 + 1]; uint32 pixel = 0xFF000000 | (b << 16) | (g << 8) | r; @@ -982,7 +1020,6 @@ void TOMExecScanline(uint16 scanline, bool render) *currentLineBuffer++ = pixel; } -// TOMBackbuffer += GetSDLScreenPitch() / 2; // Returns bytes, but we need words TOMBackbuffer += GetSDLScreenWidthInPixels(); } } @@ -1167,9 +1204,9 @@ void TOMReset(void) tom_gpu_int_pending = 0; tom_video_int_pending = 0; - tom_timer_prescaler = 0; // TOM PIT is disabled - tom_timer_divider = 0; - tom_timer_counter = 0; + tomTimerPrescaler = 0; // TOM PIT is disabled + tomTimerDivider = 0; + tomTimerCounter = 0; memcpy(scanline_render, scanline_render_normal, sizeof(scanline_render)); } @@ -1197,13 +1234,13 @@ uint8 TOMReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) else if ((offset >= 0xF02200) && (offset < 0xF022A0)) return BlitterReadByte(offset, who); else if (offset == 0xF00050) - return tom_timer_prescaler >> 8; + return tomTimerPrescaler >> 8; else if (offset == 0xF00051) - return tom_timer_prescaler & 0xFF; + return tomTimerPrescaler & 0xFF; else if (offset == 0xF00052) - return tom_timer_divider >> 8; + return tomTimerDivider >> 8; else if (offset == 0xF00053) - return tom_timer_divider & 0xFF; + return tomTimerDivider & 0xFF; return tomRam8[offset & 0x3FFF]; } @@ -1256,9 +1293,9 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) else if ((offset >= 0xF02200) && (offset < 0xF022A0)) return BlitterReadWord(offset, who); else if (offset == 0xF00050) - return tom_timer_prescaler; + return tomTimerPrescaler; else if (offset == 0xF00052) - return tom_timer_divider; + return tomTimerDivider; offset &= 0x3FFF; return (TOMReadByte(offset, who) << 8) | TOMReadByte(offset + 1, who); @@ -1299,25 +1336,25 @@ void TOMWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) } else if (offset == 0xF00050) { - tom_timer_prescaler = (tom_timer_prescaler & 0x00FF) | (data << 8); + tomTimerPrescaler = (tomTimerPrescaler & 0x00FF) | (data << 8); TOMResetPIT(); return; } else if (offset == 0xF00051) { - tom_timer_prescaler = (tom_timer_prescaler & 0xFF00) | data; + tomTimerPrescaler = (tomTimerPrescaler & 0xFF00) | data; TOMResetPIT(); return; } else if (offset == 0xF00052) { - tom_timer_divider = (tom_timer_divider & 0x00FF) | (data << 8); + tomTimerDivider = (tomTimerDivider & 0x00FF) | (data << 8); TOMResetPIT(); return; } else if (offset == 0xF00053) { - tom_timer_divider = (tom_timer_divider & 0xFF00) | data; + tomTimerDivider = (tomTimerDivider & 0xFF00) | data; TOMResetPIT(); return; } @@ -1372,13 +1409,13 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) }*/ else if (offset == 0xF00050) { - tom_timer_prescaler = data; + tomTimerPrescaler = data; TOMResetPIT(); return; } else if (offset == 0xF00052) { - tom_timer_divider = data; + tomTimerDivider = data; TOMResetPIT(); return; } @@ -1413,7 +1450,7 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) 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 !!! +#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) @@ -1508,9 +1545,9 @@ void TOMResetPIT(void) // Need to remove previous timer from the queue, if it exists... RemoveCallback(TOMPITCallback); - if (tom_timer_prescaler) + if (tomTimerPrescaler) { - double usecs = (float)(tom_timer_prescaler + 1) * (float)(tom_timer_divider + 1) * RISC_CYCLE_IN_USEC; + double usecs = (float)(tomTimerPrescaler + 1) * (float)(tomTimerDivider + 1) * RISC_CYCLE_IN_USEC; SetCallbackTime(TOMPITCallback, usecs); } #endif @@ -1524,11 +1561,11 @@ void TOMResetPIT(void) // once the timer system is stable. void TOMExecPIT(uint32 cycles) { - if (tom_timer_prescaler) + if (tomTimerPrescaler) { - tom_timer_counter -= cycles; + tomTimerCounter -= cycles; - if (tom_timer_counter <= 0) + if (tomTimerCounter <= 0) { TOMSetPendingTimerInt(); GPUSetIRQLine(GPUIRQ_TIMER, ASSERT_LINE); // GPUSetIRQLine does the 'IRQ enabled' checking