]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/objectp.cpp
Fixed OP scaling bug for sizes of 7.0 and up.
[virtualjaguar] / src / objectp.cpp
index 856b233ca3e6e6563246ce65c6fd160b2189b166..de366eec31e906e8d2cf5392d8fc470aa1f9dbe5 100644 (file)
@@ -4,6 +4,13 @@
 // Original source by David Raingeard (Cal2)
 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
 // Extensive cleanups/fixes/rewrites by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  01/16/2010  Created this log ;-)
 //
 
 #include "objectp.h"
@@ -14,6 +21,7 @@
 #include "jaguar.h"
 #include "log.h"
 #include "m68k.h"
+#include "memory.h"
 #include "tom.h"
 
 //#define OP_DEBUG
@@ -312,7 +320,7 @@ void DumpFixedObject(uint64 p0, uint64 p1)
 //
 //Need to fix this so that when an GPU object IRQ happens, we can pick up OP processing
 //where we left off. !!! FIX !!!
-#warning Need to fix this so that when an GPU object IRQ happens, we can pick up OP processing where we left off. !!! FIX !!!
+#warning "Need to fix this so that when an GPU object IRQ happens, we can pick up OP processing where we left off. !!! FIX !!!"
 void OPProcessList(int scanline, bool render)
 {
 extern int op_start_log;
@@ -351,9 +359,12 @@ else
                uint64 p0 = OPLoadPhrase(op_pointer);
 //WriteLog("\t%08X type %i\n", op_pointer, (uint8)p0 & 0x07);
                op_pointer += 8;
+
+#if 1
 if (scanline == TOMGetVDB() && op_start_log)
 //if (scanline == 215 && op_start_log)
 //if (scanline == 28 && op_start_log)
+//if (scanline == 0)
 {
 WriteLog("%08X --> phrase %08X %08X", op_pointer - 8, (int)(p0>>32), (int)(p0&0xFFFFFFFF));
 if ((p0 & 0x07) == OBJECT_TYPE_BITMAP)
@@ -417,8 +428,9 @@ for(int k=0; k<8; k++)
 WriteLog("\n");
 }
 if ((p0 & 0x07) == OBJECT_TYPE_STOP)
-WriteLog("    --> List end\n");
-}//*/
+WriteLog("    --> List end\n\n");
+}
+#endif
 
                switch ((uint8)p0 & 0x07)
                {
@@ -435,8 +447,15 @@ 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 = TOMReadWord(0xF00046, OP) / 2;                   // Get the VDB value
+#if 0
+// Not so sure... Let's see what happens here...
+// No change...
+                       if (ypos == 0)
+                               ypos = TOMReadWord(0xF00046, OP) / 2;                   // Get the VDB value
+#endif
+// Actually, no. Any item less than VDB will get only the lines that hang over VDB displayed.
+// So we need to fix this somehow... (and it has... in tom.cpp :-P)
+
                        uint32 height = (p0 & 0xFFC000) >> 14;
                        uint32 oldOPP = op_pointer - 8;
 // *** BEGIN OP PROCESSOR TESTING ONLY ***
@@ -496,6 +515,7 @@ if (!inhibit)       // For OP testing only!
                        uint16 ypos = (p0 >> 3) & 0x7FF;
                        uint32 height = (p0 & 0xFFC000) >> 14;
                        uint32 oldOPP = op_pointer - 8;
+//WriteLog("OP: Scaled Object (ypos=%04X, height=%04X", ypos, height);
 // *** BEGIN OP PROCESSOR TESTING ONLY ***
 if (inhibit && op_start_log)
 {
@@ -516,7 +536,8 @@ if (!inhibit)       // For OP testing only!
 
                                // OP write-backs
 
-                               uint8 remainder = p2 >> 16, vscale = p2 >> 8;
+                               uint16 remainder = (p2 >> 16) & 0xFF;//, vscale = p2 >> 8;
+                               uint8 /*remainder = p2 >> 16,*/ vscale = p2 >> 8;
 //Actually, we should skip this object if it has a vscale of zero.
 //Or do we? Not sure... Atari Karts has a few lines that look like:
 // (SCALED BITMAP)
@@ -524,6 +545,7 @@ if (!inhibit)       // For OP testing only!
 //    [7 (0) x 1 @ (13, 0) (8 bpp), l: 000E82A0, p: 000E0FC0 fp: 00, fl:RELEASE, idx:00, pt:01]
 //    [hsc: 9A, vsc: 00, rem: 00]
 // Could it be the vscale is overridden if the DWIDTH is zero? Hmm...
+//WriteLog("OP: Scaled bitmap processing (rem=%02X, vscale=%02X)...\n", remainder, vscale);//*/
 
                                if (vscale == 0)
                                        vscale = 0x20;                                  // OP bug??? Nope, it isn't...! Or is it?
@@ -572,7 +594,9 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
 //                             if ((remainder - 1) >= 0xE0)            // I.e., it's <= 0
 //                             if ((remainder >= 0xE1) || remainder == 0)// I.e., it's <= 0
 //                             if ((remainder >= 0xE1 && remainder <= 0xFF) || remainder == 0)// I.e., it's <= 0
-                               if (remainder <= 0x20)                          // I.e., it's <= 0
+//                             if (remainder <= 0x20)                          // I.e., it's <= 1.0
+                               // I.e., it's < 1.0f -> means it'll go negative when we subtract 1.0f.
+                               if (remainder < 0x20)
                                {
                                        uint64 data = (p0 & 0xFFFFF80000000000LL) >> 40;
                                        uint64 dwidth = (p1 & 0xFFC0000) >> 15;
@@ -582,7 +606,8 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
 //                                     while ((remainder - 1) >= 0xE0)
 //                                     while ((remainder >= 0xE1) || remainder == 0)
 //                                     while ((remainder >= 0xE1 && remainder <= 0xFF) || remainder == 0)
-                                       while (remainder <= 0x20)
+//                                     while (remainder <= 0x20)
+                                       while (remainder < 0x20)
                                        {
                                                remainder += vscale;
 
@@ -607,16 +632,18 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
                                p2 &= ~0x0000000000FF0000LL;
                                p2 |= (uint64)remainder << 16;
 //WriteLog("%08X%08X]\n", (uint32)(p2>>32), (uint32)(p2&0xFFFFFFFF));
-                               OPStorePhrase(oldOPP+16, p2);
+                               OPStorePhrase(oldOPP + 16, p2);
 //remainder = (uint8)(p2 >> 16), vscale = (uint8)(p2 >> 8);
 //WriteLog(" [after]: rem=%02X, vscale=%02X\n", remainder, vscale);
                        }
+
                        op_pointer = (p0 & 0x000007FFFF000000LL) >> 21;
                        break;
                }
                case OBJECT_TYPE_GPU:
                {
 //WriteLog("OP: Asserting GPU IRQ #3...\n");
+#warning "Need to fix OP GPU IRQ handling! !!! FIX !!!"
                        OPSetCurrentObject(p0);
                        GPUSetIRQLine(3, ASSERT_LINE);
 //Also, OP processing is suspended from this point until OBF (F00026) is written to...
@@ -656,8 +683,8 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
                                break;
                        case CONDITION_SECOND_HALF_LINE:
                                // This basically means branch if bit 10 of HC is set
+#warning "Unhandled condition code causes emulator to crash... !!! FIX !!!"
                                WriteLog("OP: Unexpected CONDITION_SECOND_HALF_LINE in BRANCH object\nOP: shuting down\n");
-//                             fclose(log_get());
                                LogDone();
                                exit(0);
                                break;
@@ -693,6 +720,7 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
                // Here is a little sanity check to keep the OP from locking up the machine
                // when fed bad data. Better would be to count how many actual cycles it used
                // and bail out/reenter to properly simulate an overloaded OP... !!! FIX !!!
+#warning "Better would be to count how many actual cycles it used and bail out/reenter to properly simulate an overloaded OP... !!! FIX !!!"
                opCyclesToRun--;
                if (!opCyclesToRun)
                        return;
@@ -1147,10 +1175,10 @@ if (firstPix)
        // for use when using endian-corrected data (i.e., any of the *ReadWord functions!)
        uint16 * paletteRAM16 = (uint16 *)paletteRAM;
 
-       uint8 hscale = p2 & 0xFF;
+       uint16 hscale = p2 & 0xFF;
 // Hmm. It seems that fixing the horizontal scale necessitated re-fixing this. Not sure why,
 // but seems to be consistent with the vertical scaling now (and it may turn out to be wrong!)...
-       uint8 horizontalRemainder = hscale;                             // Not sure if it starts full, but seems reasonable [It's not!]
+       uint16 horizontalRemainder = hscale;                            // Not sure if it starts full, but seems reasonable [It's not!]
 //     uint8 horizontalRemainder = 0;                                  // Let's try zero! Seems to work! Yay! [No, it doesn't!]
        int32 scaledWidthInPixels = (iwidth * phraseWidthToPixels[depth] * hscale) >> 5;
        uint32 scaledPhrasePixels = (phraseWidthToPixels[depth] * hscale) >> 5;
@@ -1364,6 +1392,11 @@ if (firstPix != 0)
 
                        currentLineBuffer += lbufDelta;
 
+/*
+The reason we subtract the horizontalRemainder *after* the test is because we had too few
+bytes for horizontalRemainder to properly recognize a negative number. But now it's 16 bits
+wide, so we could probably go back to that (as long as we make it an int16 and not a uint16!)
+*/
 /*                     horizontalRemainder -= 0x20;            // Subtract 1.0f in [3.5] fixed point format
                        while (horizontalRemainder & 0x80)
                        {
@@ -1371,7 +1404,8 @@ if (firstPix != 0)
                                pixCount++;
                                pixels <<= 1;
                        }//*/
-                       while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+//                     while (horizontalRemainder <= 0x20)             // I.e., it's <= 1.0 (*before* subtraction)
+                       while (horizontalRemainder < 0x20)              // I.e., it's <= 1.0 (*before* subtraction)
                        {
                                horizontalRemainder += hscale;
                                pixCount++;
@@ -1430,7 +1464,8 @@ if (firstPix != 0)
                                pixCount++;
                                pixels <<= 2;
                        }//*/
-                       while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+//                     while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+                       while (horizontalRemainder < 0x20)              // I.e., it's <= 1.0 (*before* subtraction)
                        {
                                horizontalRemainder += hscale;
                                pixCount++;
@@ -1489,7 +1524,8 @@ if (firstPix != 0)
                                pixCount++;
                                pixels <<= 4;
                        }//*/
-                       while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+//                     while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+                       while (horizontalRemainder < 0x20)              // I.e., it's <= 0 (*before* subtraction)
                        {
                                horizontalRemainder += hscale;
                                pixCount++;
@@ -1544,7 +1580,8 @@ if (firstPix)
 
                        currentLineBuffer += lbufDelta;
 
-                       while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+//                     while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+                       while (horizontalRemainder < 0x20)              // I.e., it's <= 1.0 (*before* subtraction)
                        {
                                horizontalRemainder += hscale;
                                pixCount++;
@@ -1601,7 +1638,8 @@ if (firstPix != 0)
                                pixCount++;
                                pixels <<= 16;
                        }//*/
-                       while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+//                     while (horizontalRemainder <= 0x20)             // I.e., it's <= 0 (*before* subtraction)
+                       while (horizontalRemainder < 0x20)              // I.e., it's <= 1.0 (*before* subtraction)
                        {
                                horizontalRemainder += hscale;
                                pixCount++;