+#else
+//#warning "!!! Fix lockup in OPDiscoverObjects() !!!"
+//temp, to keep the following function from locking up on bad/weird OLs
+//return;
+
+ numberOfObjects = 0;
+ OPDiscoverObjects(olp);
+ OPDumpObjectList();
+#endif
+}
+
+
+bool OPObjectExists(uint32_t address)
+{
+ // Yes, we really do a linear search, every time. :-/
+ for(uint32_t i=0; i<numberOfObjects; i++)
+ {
+ if (address == object[i])
+ return true;
+ }
+
+ return false;
+}
+
+
+void OPDiscoverObjects(uint32_t address)
+{
+ uint8_t objectType = 0;
+
+ do
+ {
+ // If we've seen this object already, bail out!
+ // Otherwise, add it to the list
+ if (OPObjectExists(address))
+ return;
+
+ object[numberOfObjects++] = address;
+
+ // Get the object & decode its type, link address
+ uint32_t hi = JaguarReadLong(address + 0, OP);
+ uint32_t lo = JaguarReadLong(address + 4, OP);
+ objectType = lo & 0x07;
+ uint32_t link = ((hi << 11) | (lo >> 21)) & 0x3FFFF8;
+
+ if (objectType == 3)
+ {
+ // Branch if YPOS < 2047 (or YPOS > 0) can be treated as a GOTO, so
+ // don't do any discovery in that case. Otherwise, have at it:
+ if (((lo & 0xFFFF) != 0x7FFB) && ((lo & 0xFFFF) != 0x8003))
+ // Recursion needed to follow all links! This does depth-first
+ // recursion on the not-taken objects
+ OPDiscoverObjects(address + 8);
+ }
+
+ // Get the next object...
+ address = link;
+ }
+ while (objectType != 4);
+}
+
+
+void OPDumpObjectList(void)
+{
+ for(uint32_t i=0; i<numberOfObjects; i++)
+ {
+ uint32_t address = object[i];
+
+ uint32_t hi = JaguarReadLong(address + 0, OP);
+ uint32_t lo = JaguarReadLong(address + 4, OP);
+ uint8_t objectType = lo & 0x07;
+ uint32_t link = ((hi << 11) | (lo >> 21)) & 0x3FFFF8;
+ WriteLog("%08X: %08X %08X %s -> $%08X", address, hi, lo, opType[objectType], link);
+
+ if (objectType == 3)
+ {
+ uint16_t ypos = (lo >> 3) & 0x7FF;
+ uint8_t cc = (lo >> 14) & 0x07; // Proper # of bits == 3
+ WriteLog(" YPOS %s %u", ccType[cc], ypos);
+ }
+
+ WriteLog("\n");
+
+ // Yes, this is how the OP finds follow-on phrases for bitmap/scaled
+ // bitmap objects...!
+ if (objectType == 0)
+ DumpFixedObject(OPLoadPhrase(address + 0),
+ OPLoadPhrase(address | 0x08));
+
+ if (objectType == 1)
+ DumpScaledObject(OPLoadPhrase(address + 0),
+ OPLoadPhrase(address | 0x08), OPLoadPhrase(address | 0x10));
+
+ if (address == link) // Ruh roh...
+ {
+ // Runaway recursive link is bad!
+ WriteLog("***** SELF REFERENTIAL LINK *****\n\n");
+ }
+ }