]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/op.cpp
Fixed DSP/audio options to be unambiguous and consistent.
[virtualjaguar] / src / op.cpp
index 38322d8e432a0fd9e6d8678d10b48024bc1d6296..8708d9b34418c81a28ca6f279f5a81e65a51d953 100644 (file)
@@ -3,10 +3,10 @@
 //
 // 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
+// Extensive cleanups/fixes/rewrites by James Hammons
 // (C) 2010 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
@@ -20,7 +20,7 @@
 #include "gpu.h"
 #include "jaguar.h"
 #include "log.h"
-#include "m68k.h"
+#include "m68000/m68kinterface.h"
 #include "memory.h"
 #include "tom.h"
 
@@ -36,9 +36,9 @@
 #define OBJECT_TYPE_BRANCH     3                                       // 011
 #define OBJECT_TYPE_STOP       4                                       // 100
 
-#define CONDITION_EQUAL                                0
-#define CONDITION_LESS_THAN                    1
-#define CONDITION_GREATER_THAN         2
+#define CONDITION_EQUAL                                0                       // VC == YPOS
+#define CONDITION_LESS_THAN                    1                       // VC < YPOS
+#define CONDITION_GREATER_THAN         2                       // VC > YPOS
 #define CONDITION_OP_FLAG_SET          3
 #define CONDITION_SECOND_HALF_LINE     4
 
@@ -51,7 +51,8 @@
 
 void OPProcessFixedBitmap(uint64 p0, uint64 p1, bool render);
 void OPProcessScaledBitmap(uint64 p0, uint64 p1, uint64 p2, bool render);
-void OPDumpObjectList(uint32 address);
+void OPDiscoverObjects(uint32 address);
+void OPDumpObjectList(void);
 void DumpScaledObject(uint64 p0, uint64 p1, uint64 p2);
 void DumpFixedObject(uint64 p0, uint64 p1);
 void DumpBitmapCore(uint64 p0, uint64 p1);
@@ -137,8 +138,10 @@ static const char * opType[8] =
 { "(BITMAP)", "(SCALED BITMAP)", "(GPU INT)", "(BRANCH)", "(STOP)", "???", "???", "???" };
 static const char * ccType[8] =
        { "\"==\"", "\"<\"", "\">\"", "(opflag set)", "(second half line)", "?", "?", "?" };
-static uint32 objectLink[8192];
-static uint32 numberOfLinks;
+static uint32 object[8192];
+static uint32 numberOfObjects;
+//static uint32 objectLink[8192];
+//static uint32 numberOfLinks;
 
 void OPDone(void)
 {
@@ -177,24 +180,27 @@ void OPDone(void)
 
        WriteLog("\n");
 #else
-       numberOfLinks = 0;
+#warning "!!! Fix lockup in OPDiscoverObjects() !!!"
+//temp, to keep the following function from locking up on bad/weird OLs
+return;
 
-       OPDumpObjectList(olp);
+       numberOfObjects = 0;
+       OPDiscoverObjects(olp);
+       OPDumpObjectList();
 #endif
 }
 
-
-// To do this properly, we have to use recursion...
-void OPDumpObjectList(uint32 address)
+void OPDiscoverObjects(uint32 address)
 {
-       // Sanity checking: If we've already visited this link, bail out!
-       for(uint32 i=0; i<numberOfLinks; i++)
+       // Check to see if we've already seen this object
+       for(uint32 i=0; i<numberOfObjects; i++)
        {
-               if (address == objectLink[i])
+               if (address == object[i])
                        return;
        }
 
-       objectLink[numberOfLinks++] = address;
+       // Store the object...
+       object[numberOfObjects++] = address;
        uint8 objectType = 0;
 
        do
@@ -203,26 +209,59 @@ void OPDumpObjectList(uint32 address)
                uint32 lo = JaguarReadLong(address + 4, OP);
                objectType = lo & 0x07;
                uint32 link = ((hi << 11) | (lo >> 21)) & 0x3FFFF8;
-               WriteLog("%08X: %08X %08X %s", address, hi, lo, opType[objectType]);
 
                if (objectType == 3)
                {
                        uint16 ypos = (lo >> 3) & 0x7FF;
                        uint8  cc   = (lo >> 14) & 0x07;        // Proper # of bits == 3
-                       WriteLog(" YPOS=%u, CC=%s, link=$%08X", ypos, ccType[cc], link);
 
                        // Recursion needed to follow all links!
-                       WriteLog("\n");
-                       OPDumpObjectList(address + 8);
-
-                       // Do the sanity check after recursive call: We may have already seen this...
-                       // Sanity checking: If we've already visited this link, bail out!
-//disnowok: we added ourself above
-//                     for(uint32 i=0; i<numberOfLinks; i++)
-//                     {
-//                             if (address == objectLink[i])
-//                                     return;
-//                     }
+                       OPDiscoverObjects(address + 8);
+               }
+
+               if (address == link)    // Ruh roh...
+               {
+                       // Runaway recursive link is bad!
+                       return;
+               }
+
+               address = link;
+
+               // Check to see if we've already seen this object, and add it if not
+               bool seenObject = false;
+
+               for(uint32 i=0; i<numberOfObjects; i++)
+               {
+                       if (address == object[i])
+                       {
+                               seenObject = true;
+                               break;
+                       }
+               }
+
+               if (!seenObject)
+                       object[numberOfObjects++] = address;
+       }
+       while (objectType != 4);
+}
+
+void OPDumpObjectList(void)
+{
+       for(uint32 i=0; i<numberOfObjects; i++)
+       {
+               uint32 address = object[i];
+
+               uint32 hi = JaguarReadLong(address + 0, OP);
+               uint32 lo = JaguarReadLong(address + 4, OP);
+               uint8 objectType = lo & 0x07;
+               uint32 link = ((hi << 11) | (lo >> 21)) & 0x3FFFF8;
+               WriteLog("%08X: %08X %08X %s", address, hi, lo, opType[objectType]);
+
+               if (objectType == 3)
+               {
+                       uint16 ypos = (lo >> 3) & 0x7FF;
+                       uint8  cc   = (lo >> 14) & 0x07;        // Proper # of bits == 3
+                       WriteLog(" YPOS=%u, CC=%s, link=$%08X", ypos, ccType[cc], link);
                }
 
                WriteLog("\n");
@@ -238,19 +277,12 @@ void OPDumpObjectList(uint32 address)
                {
                        // Runaway recursive link is bad!
                        WriteLog("***** SELF REFERENTIAL LINK *****\n\n");
-                       return;
                }
-
-               address = link;
-               objectLink[numberOfLinks++] = address;
        }
-       while (objectType != 4);
 
        WriteLog("\n");
 }
 
-
-
 //
 // Object Processor memory access
 // Memory range: F00010 - F00027
@@ -372,6 +404,7 @@ void DumpFixedObject(uint64 p0, uint64 p1)
 
 void DumpBitmapCore(uint64 p0, uint64 p1)
 {
+       uint32 bdMultiplier[8] = { 64, 32, 16, 8, 4, 2, 1, 1 };
        uint8 bitdepth = (p1 >> 12) & 0x07;
 //WAS: int16 ypos = ((p0 >> 3) & 0x3FF);                       // ??? What if not interlaced (/2)?
        int16 ypos = ((p0 >> 3) & 0x7FF);                       // ??? What if not interlaced (/2)?
@@ -386,8 +419,9 @@ void DumpBitmapCore(uint64 p0, uint64 p1)
        uint8 flags = (p1 >> 45) & 0x0F;
        uint8 idx = (p1 >> 38) & 0x7F;
        uint32 pitch = (p1 >> 15) & 0x07;
-       WriteLog("    [%u (%u) x %u @ (%i, %u) (%u bpp), l: %08X, p: %08X fp: %02X, fl:%s%s%s%s, idx:%02X, pt:%02X]\n",
-               iwidth, dwidth, height, xpos, ypos, op_bitmap_bit_depth[bitdepth], link,
+       WriteLog("    [%u x %u @ (%i, %u) (iw:%u, dw:%u) (%u bpp), l:%08X, p:%08X fp:%02X, fl:%s%s%s%s, idx:%02X, pt:%02X]\n",
+               iwidth * bdMultiplier[bitdepth],
+               height, xpos, ypos, iwidth, dwidth, op_bitmap_bit_depth[bitdepth], link,
                ptr, firstPix, (flags&OPFLAG_REFLECT ? "REFLECT " : ""),
                (flags&OPFLAG_RMW ? "RMW " : ""), (flags&OPFLAG_TRANS ? "TRANS " : ""),
                (flags&OPFLAG_RELEASE ? "RELEASE" : ""), idx, pitch);
@@ -399,6 +433,10 @@ void DumpBitmapCore(uint64 p0, uint64 p1)
 #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 halfline, bool render)
 {
+#warning "!!! NEED TO HANDLE MULTIPLE FIELDS PROPERLY !!!
+// We ignore them, for now; not good
+       halfline &= 0x7FF;
+
 extern int op_start_log;
 //     char * condition_to_str[8] =
 //             { "==", "<", ">", "(opflag set)", "(second half line)", "?", "?", "?" };
@@ -582,8 +620,17 @@ if (!inhibit)      // For OP testing only!
 /*     if (op_pointer > ((p0 & 0x000007FFFF000000LL) >> 21))
                return;*/
 
-                       op_pointer = (p0 & 0x000007FFFF000000LL) >> 21;
+// NOTE: The link address only replaces bits 3-21 in the OLP, and this replaces
+//       EVERYTHING. !!! FIX !!! [DONE]
+#warning "!!! Link address is not linked properly for all object types !!!"
+#warning "!!! Only BITMAP is properly handled !!!"
+                       op_pointer &= 0xFFC00007;
+                       op_pointer |= (p0 & 0x000007FFFF000000LL) >> 21;
 //WriteLog("New OP: %08X\n", op_pointer);
+//kludge: Seems that memory access is mirrored in the first 8MB of memory...
+if (op_pointer > 0x1FFFFF && op_pointer < 0x800000)
+       op_pointer &= 0xFF1FFFFF;       // Knock out bits 21-23
+
                        break;
                }
                case OBJECT_TYPE_SCALE:
@@ -737,6 +784,7 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
                        uint16 ypos = (p0 >> 3) & 0x7FF;
 // NOTE: The JTRM sez there are only 2 bits used for the CC, but lists *five*
 //       conditions! Need at least one more bit for that! :-P
+// Also, the ASIC nets imply that it uses bits 14-16 (height in BM & SBM objects)
 #warning "!!! Possibly bad CC handling in OP (missing 1 bit) !!!"
                        uint8  cc   = (p0 >> 14) & 0x03;
                        uint32 link = (p0 >> 21) & 0x3FFFF8;
@@ -802,7 +850,7 @@ OP: Scaled bitmap 4x? 4bpp at 34,? hscale=80 fpix=0 data=000756E8 pitch 1 hflipp
 //                     break;
                }
                default:
-                       WriteLog("op: unknown object type %i\n", ((uint8)p0 & 0x07));
+//                     WriteLog("op: unknown object type %i\n", ((uint8)p0 & 0x07));
                        return;
                }
 
@@ -860,6 +908,13 @@ void OPProcessFixedBitmap(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...
+
+//kludge: Seems that the OP treats iwidth == 0 as iwidth == 1... Need to investigate
+//        on real hardware...
+#warning "!!! Need to investigate iwidth == 0 behavior on real hardware !!!"
+if (iwidth == 0)
+       iwidth = 1;
+
 //     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)