X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fobjectp.cpp;h=ea54a5bdf1c915863c425877cdd54f4e2357dfa8;hb=f3a7d2b1f420e63525039b776a1d9ffb2a86af85;hp=43b575eb57297371f5dc6b79801c63574f76c20e;hpb=135a0c52a2bcbcc37192c61801de6e9c80aeebff;p=virtualjaguar diff --git a/src/objectp.cpp b/src/objectp.cpp index 43b575e..ea54a5b 100644 --- a/src/objectp.cpp +++ b/src/objectp.cpp @@ -131,7 +131,7 @@ void op_done(void) WriteLog("OP: Phrase dump\n ----------\n"); for(uint32 i=0; i<0x100; i+=8) { - uint32 hi = jaguar_long_read(olp + i), lo = jaguar_long_read(olp + i + 4); + uint32 hi = JaguarReadLong(olp + i, OP), lo = JaguarReadLong(olp + i + 4, OP); WriteLog("\t%08X: %08X %08X %s", olp + i, hi, lo, opType[lo & 0x07]); if ((lo & 0x07) == 3) { @@ -153,41 +153,38 @@ void op_done(void) // Object Processor memory access // Memory range: F00010 - F00027 // -void op_byte_write(uint32 offset, uint8 data) +uint8 OPReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; - objectp_ram[offset] = data; + return objectp_ram[offset]; } -void op_word_write(uint32 offset, uint16 data) +uint16 OPReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; -// objectp_ram[offset] = (data >> 8) & 0xFF; -// objectp_ram[offset+1] = data & 0xFF; - SET16(objectp_ram, offset, data); - -/*if (offset == 0x20) -WriteLog("OP: Setting lo list pointer: %04X\n", data); -if (offset == 0x22) -WriteLog("OP: Setting hi list pointer: %04X\n", data);//*/ + return GET16(objectp_ram, offset); } -uint8 op_byte_read(uint32 offset) +// F00010-F00017 R xxxxxxxx xxxxxxxx OB - current object code from the graphics processor +// F00020-F00023 W xxxxxxxx xxxxxxxx OLP - start of the object list +// F00026 W -------- -------x OBF - object processor flag + +void OPWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; - return objectp_ram[offset]; + objectp_ram[offset] = data; } -uint16 op_word_read(uint32 offset) +void OPWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/) { -// return (objectp_ram[offset & 0x3F] << 8) | objectp_ram[(offset+1) & 0x3F]; offset &= 0x3F; - return GET16(objectp_ram, offset); -} + SET16(objectp_ram, offset, data); -// F00010-F00017 R xxxxxxxx xxxxxxxx OB - current object code from the graphics processor -// F00020-F00023 W xxxxxxxx xxxxxxxx OLP - start of the object list -// F00026 W -------- -------x OBF - object processor flag +/*if (offset == 0x20) +WriteLog("OP: Setting lo list pointer: %04X\n", data); +if (offset == 0x22) +WriteLog("OP: Setting hi list pointer: %04X\n", data);//*/ +} uint32 op_get_list_pointer(void) { @@ -245,14 +242,14 @@ void op_set_current_object(uint64 object) uint64 op_load_phrase(uint32 offset) { offset &= ~0x07; // 8 byte alignment - return ((uint64)jaguar_long_read(offset) << 32) | (uint64)jaguar_long_read(offset+4); + return ((uint64)JaguarReadLong(offset, OP) << 32) | (uint64)JaguarReadLong(offset+4, OP); } void OPStorePhrase(uint32 offset, uint64 p) { offset &= ~0x07; // 8 byte alignment - jaguar_long_write(offset, p >> 32); - jaguar_long_write(offset + 4, p & 0xFFFFFFFF); + JaguarWriteLong(offset, p >> 32, OP); + JaguarWriteLong(offset + 4, p & 0xFFFFFFFF, OP); } // @@ -314,14 +311,6 @@ extern int op_start_log; // char * condition_to_str[8] = // { "==", "<", ">", "(opflag set)", "(second half line)", "?", "?", "?" }; -// If jaguar_exec() is working right, we should *never* have to check for this -// condition... -/* if (scanline < tom_get_vdb()) - return; - - if (scanline >= 525)//tom_getVideoModeHeight()+tom_get_vdb()) - return;//*/ - op_pointer = op_get_list_pointer(); objectp_stop_reading_list = false; @@ -431,7 +420,7 @@ WriteLog(" --> List end\n"); //No, the reason this was needed is that the OP code before was wrong. Any value //less than VDB will get written to the top line of the display! // if (ypos == 0) -// ypos = tom_word_read(0xF00046) / 2; // Get the VDB value +// ypos = TOMReadWord(0xF00046, OP) / 2; // Get the VDB value uint32 height = (p0 & 0xFFC000) >> 14; uint32 oldOPP = op_pointer - 8; // *** BEGIN OP PROCESSOR TESTING ONLY *** @@ -488,7 +477,7 @@ if (!inhibit) // For OP testing only! //No, the reason this was needed is that the OP code before was wrong. Any value //less than VDB will get written to the top line of the display! // if (ypos == 0) -// ypos = tom_word_read(0xF00046) / 2; // Get the VDB value +// ypos = TOMReadWord(0xF00046, OP) / 2; // Get the VDB value uint32 height = (p0 & 0xFFC000) >> 14; uint32 oldOPP = op_pointer - 8; // *** BEGIN OP PROCESSOR TESTING ONLY *** @@ -593,17 +582,17 @@ if (!inhibit) // For OP testing only! // ypos ^= 0x01; // if ((2 * tom_get_scanline()) == ypos || ypos == 0x7FF) //Here we're using VC instead of the bogus tom_get_scanline() value... - if (tom_word_read(0xF00006) == ypos || ypos == 0x7FF) + if (TOMReadWord(0xF00006, OP) == ypos || ypos == 0x7FF) op_pointer = link; break; case CONDITION_LESS_THAN: // if ((2 * tom_get_scanline()) < ypos) - if (tom_word_read(0xF00006) < ypos) + if (TOMReadWord(0xF00006, OP) < ypos) op_pointer = link; break; case CONDITION_GREATER_THAN: // if ((2 * tom_get_scanline()) > ypos) - if (tom_word_read(0xF00006) > ypos) + if (TOMReadWord(0xF00006, OP) > ypos) op_pointer = link; break; case CONDITION_OP_FLAG_SET: @@ -680,6 +669,7 @@ void OPProcessFixedBitmap(int scanline, uint64 p0, uint64 p1, bool render) // provide the most significant bits of the palette address." uint8 index = (p1 >> 37) & 0xFE; // CLUT index offset (upper pix, 1-4 bpp) uint32 pitch = (p1 >> 15) & 0x07; // Phrase pitch + pitch <<= 3; // Optimization: Multiply pitch by 8 // int16 scanlineWidth = tom_getVideoModeWidth(); uint8 * tom_ram_8 = tom_get_ram_pointer(); @@ -694,9 +684,9 @@ void OPProcessFixedBitmap(int scanline, uint64 p0, uint64 p1, bool render) // Is it OK to have a 0 for the data width??? (i.e., undocumented?) // Seems to be... Seems that dwidth *can* be zero (i.e., reuse same line) as well. // Pitch == 0 is OK too... -// if (!render || op_pointer == 0 || dwidth == 0 || ptr == 0 || pitch == 0) +// if (!render || op_pointer == 0 || ptr == 0 || pitch == 0) //I'm not convinced that we need to concern ourselves with data & op_pointer here either! - if (!render || iwidth == 0) // || data == 0 || op_pointer == 0) + if (!render || iwidth == 0) return; //#define OP_DEBUG_BMP @@ -774,6 +764,7 @@ if (depth > 5) WriteLog("We're about to encounter a divide by zero error!\n"); // NOTE: We're just using endPos to figure out how much, if any, to clip by. // ALSO: There may be another case where we start out of bounds and end out of bounds...! + // !!! FIX !!! if (startPos < 0) // Case #1: Begin out, end in, L to R clippedWidth = 0 - startPos, dataClippedWidth = phraseClippedWidth = clippedWidth / phraseWidthToPixels[depth], @@ -799,12 +790,14 @@ if (depth > 5) // Also, if we're clipping the phrase we need to make sure we're in the correct part of // the pixel data. // data += phraseClippedWidth * (pitch << 3); - data += dataClippedWidth * (pitch << 3); + data += dataClippedWidth * pitch; // NOTE: When the bitmap is in REFLECT mode, the XPOS marks the *right* side of the // bitmap! This makes clipping & etc. MUCH, much easier...! // uint32 lbufAddress = 0x1800 + (!in24BPPMode ? leftMargin * 2 : leftMargin * 4); - uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 4); +//Why does this work right when multiplying startPos by 2 (instead of 4) for 24 BPP mode? +//Is this a bug in the OP? + uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 2); uint8 * currentLineBuffer = &tom_ram_8[lbufAddress]; // Render. @@ -813,6 +806,7 @@ if (depth > 5) // If we *were* in 24 BPP mode, how would you convert CRY to RGB24? Seems to me // that if you're in CRY mode then you wouldn't be able to use 24 BPP bitmaps // anyway. +// This seems to be the case (at least according to the Midsummer docs)...! if (depth == 0) // 1 BPP { @@ -820,9 +814,9 @@ if (depth > 5) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; // Fetch 1st phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); //Note that firstPix should only be honored *if* we start with the 1st phrase of the bitmap -//i.e., we didn't clip on the margin... +//i.e., we didn't clip on the margin... !!! FIX !!! pixels <<= firstPix; // Skip first N pixels (N=firstPix)... int i = firstPix; // Start counter at right spot... @@ -853,8 +847,8 @@ if (depth > 5) } i = 0; // Fetch next phrase... - data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + data += pitch; + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); } } else if (depth == 1) // 2 BPP @@ -868,8 +862,8 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); - data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); + data += pitch; for(int i=0; i<32; i++) { @@ -908,8 +902,8 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); - data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); + data += pitch; for(int i=0; i<16; i++) { @@ -947,8 +941,8 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); - data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); + data += pitch; for(int i=0; i<8; i++) { @@ -986,8 +980,8 @@ if (firstPix) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); - data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); + data += pitch; for(int i=0; i<4; i++) { @@ -1024,24 +1018,21 @@ if (firstPix) if (firstPix) WriteLog("OP: Fixed bitmap @ 24 BPP requesting FIRSTPIX! (fp=%u)\n", firstPix); // Not sure, but I think RMW only works with 16 BPP and below, and only in CRY mode... - // The LSB is OPFLAG_REFLECT, so sign extend it and or 4 into it. + // The LSB of flags is OPFLAG_REFLECT, so sign extend it and OR 4 into it. int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 4) | 0x04; while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); - data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); + data += pitch; for(int i=0; i<2; i++) { + // We don't use a 32-bit var here because of endian issues...! uint8 bits3 = pixels >> 56, bits2 = pixels >> 48, bits1 = pixels >> 40, bits0 = pixels >> 32; -// Seems to me that both of these are in the same endian, so we could cast it as -// uint16 * and do straight across copies (what about 24 bpp? Treat it differently...) -// This only works for the palettized modes (1 - 8 BPP), since we actually have to -// copy data from memory in 16 BPP mode (or does it? Isn't this the same as the CLUT case?) -// No, it isn't because we read the memory in an endian safe way--it *won't* work... + if (flagTRANS && (bits3 | bits2 | bits1 | bits0) == 0) ; // Do nothing... else @@ -1074,7 +1065,7 @@ void OPProcessScaledBitmap(int scanline, uint64 p0, uint64 p1, uint64 p2, bool r uint32 firstPix = (p1 >> 49) & 0x3F; //This is WEIRD! I'm sure I saw Atari Karts request 8 BPP FIRSTPIX! What happened??? if (firstPix) - WriteLog("OP: FIRSTPIX != 0!\n"); + WriteLog("OP: FIRSTPIX != 0! (Scaled BM)\n"); //#endif // We can ignore the RELEASE (high order) bit for now--probably forever...! // uint8 flags = (p1 >> 45) & 0x0F; // REFLECT, RMW, TRANS, RELEASE @@ -1165,6 +1156,7 @@ if (firstPix) // NOTE: We're just using endPos to figure out how much, if any, to clip by. // ALSO: There may be another case where we start out of bounds and end out of bounds...! + // !!! FIX !!! //There's a problem here with scaledPhrasePixels in that it can be forced to zero when //the scaling factor is small. So fix it already! !!! FIX !!! @@ -1222,7 +1214,8 @@ if (op_start_log && startPos == 13) // NOTE: When the bitmap is in REFLECT mode, the XPOS marks the *right* side of the // bitmap! This makes clipping & etc. MUCH, much easier...! // uint32 lbufAddress = 0x1800 + (!in24BPPMode ? leftMargin * 2 : leftMargin * 4); - uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 4); +// uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 4); + uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 2); uint8 * currentLineBuffer = &tom_ram_8[lbufAddress]; // Render. @@ -1231,6 +1224,7 @@ if (op_start_log && startPos == 13) // If we *were* in 24 BPP mode, how would you convert CRY to RGB24? Seems to me // that if you're in CRY mode then you wouldn't be able to use 24 BPP bitmaps // anyway. +// This seems to be the case (at least according to the Midsummer docs)...! if (depth == 0) // 1 BPP { @@ -1240,7 +1234,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1276,7 +1270,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 64, pixelShift = pixCount % 64; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 1 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1292,7 +1286,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1328,7 +1322,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 32, pixelShift = pixCount % 32; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 2 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1344,7 +1338,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1380,7 +1374,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 16, pixelShift = pixCount % 16; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 4 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1395,7 +1389,7 @@ if (firstPix) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1431,7 +1425,7 @@ if (firstPix) int phrasesToSkip = pixCount / 8, pixelShift = pixCount % 8; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 8 * pixelShift; iwidth -= phrasesToSkip; pixCount = pixelShift; @@ -1446,7 +1440,7 @@ if (firstPix != 0) int32 lbufDelta = ((int8)((flags << 7) & 0xFF) >> 5) | 0x02; int pixCount = 0; - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); while ((int32)iwidth > 0) { @@ -1481,7 +1475,7 @@ if (firstPix != 0) int phrasesToSkip = pixCount / 4, pixelShift = pixCount % 4; data += (pitch << 3) * phrasesToSkip; - pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); pixels <<= 16 * pixelShift; iwidth -= phrasesToSkip; @@ -1503,18 +1497,14 @@ if (firstPix != 0) while (iwidth--) { // Fetch phrase... - uint64 pixels = ((uint64)jaguar_long_read(data) << 32) | jaguar_long_read(data + 4); + uint64 pixels = ((uint64)JaguarReadLong(data, OP) << 32) | JaguarReadLong(data + 4, OP); data += pitch << 3; // Multiply pitch * 8 (optimize: precompute this value) for(int i=0; i<2; i++) { uint8 bits3 = pixels >> 56, bits2 = pixels >> 48, bits1 = pixels >> 40, bits0 = pixels >> 32; -// Seems to me that both of these are in the same endian, so we could cast it as -// uint16 * and do straight across copies (what about 24 bpp? Treat it differently...) -// This only works for the palettized modes (1 - 8 BPP), since we actually have to -// copy data from memory in 16 BPP mode (or does it? Isn't this the same as the CLUT case?) -// No, it isn't because we read the memory in an endian safe way--it *won't* work... + if (flagTRANS && (bits3 | bits2 | bits1 | bits0) == 0) ; // Do nothing... else