2 // opbrowser.cpp - Jaguar Object Processor browser
5 // (C) 2012 Underground Software
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 12/01/2012 Created this file
17 #include "opbrowser.h"
23 OPBrowserWindow::OPBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
24 layout(new QVBoxLayout), text(new QLabel),
25 refresh(new QPushButton(tr("Refresh")))
27 setWindowTitle(tr("OP Browser"));
29 // Need to set the size as well...
32 // QFont fixedFont("Lucida Console", 8, QFont::Normal);
33 QFont fixedFont("", 8, QFont::Normal);
34 fixedFont.setStyleHint(QFont::TypeWriter);
35 text->setFont(fixedFont);
36 //// layout->setSizeConstraint(QLayout::SetFixedSize);
39 QScrollArea * scrollArea = new QScrollArea;
40 scrollArea->setWidgetResizable(true);
41 scrollArea->setWidget(text);
42 layout->addWidget(scrollArea);
43 layout->addWidget(refresh);
45 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
49 void OPBrowserWindow::RefreshContents(void)
51 char string[1024];//, buf[64];
54 uint32_t olp = OPGetListPointer();
55 sprintf(string, "OLP = $%X<br>", olp);
56 opDump += QString(string);
60 DumpObjectList(opDump);
63 text->setText(opDump);
67 void OPBrowserWindow::keyPressEvent(QKeyEvent * e)
69 if (e->key() == Qt::Key_Escape)
71 else if (e->key() == Qt::Key_Enter)
76 bool OPBrowserWindow::ObjectExists(uint32_t address)
78 // Yes, we really do a linear search, every time. :-/
79 for(uint32_t i=0; i<numberOfObjects; i++)
81 if (address == object[i])
89 void OPBrowserWindow::DiscoverObjects(uint32_t address)
91 uint8_t objectType = 0;
95 // If we've seen this object already, bail out!
96 // Otherwise, add it to the list
97 if (ObjectExists(address))
100 object[numberOfObjects++] = address;
102 // Get the object & decode its type, link address
103 uint32_t hi = JaguarReadLong(address + 0, OP);
104 uint32_t lo = JaguarReadLong(address + 4, OP);
105 objectType = lo & 0x07;
106 uint32_t link = ((hi << 11) | (lo >> 21)) & 0x3FFFF8;
110 // Recursion needed to follow all links! This does depth-first recursion
111 // on the not-taken objects
112 DiscoverObjects(address + 8);
115 // Get the next object...
118 while (objectType != 4);
122 void OPBrowserWindow::DumpObjectList(QString & list)
124 const char * opType[8] = {
125 "(BITMAP)", "(SCALED BITMAP)", "(GPU INT)", "(BRANCH)",
126 "(STOP)", "???", "???", "???"
128 const char * ccType[8] = {
129 "==", "<", ">", "(opflag set)",
130 "(second half line)", "?", "?", "?"
134 for(uint32_t i=0; i<numberOfObjects; i++)
136 uint32_t address = object[i];
138 uint32_t hi = JaguarReadLong(address + 0, OP);
139 uint32_t lo = JaguarReadLong(address + 4, OP);
140 uint8_t objectType = lo & 0x07;
141 uint32_t link = ((hi << 11) | (lo >> 21)) & 0x3FFFF8;
142 sprintf(buf, "<br>%06X: %08X %08X %s -> %06X", address, hi, lo, opType[objectType], link);
143 list += QString(buf);
147 uint16_t ypos = (lo >> 3) & 0x7FF;
148 uint8_t cc = (lo >> 14) & 0x07; // Proper # of bits == 3
149 sprintf(buf, " YPOS %s %u", ccType[cc], ypos);
150 list += QString(buf);
156 DumpFixedObject(list, OPLoadPhrase(address + 0), OPLoadPhrase(address + 8));
159 DumpScaledObject(list, OPLoadPhrase(address + 0), OPLoadPhrase(address + 8),
160 OPLoadPhrase(address + 16));
162 if (address == link) // Ruh roh...
164 // Runaway recursive link is bad!
165 sprintf(buf, "***** SELF REFERENTIAL LINK *****<br>");
166 list += QString(buf);
174 void OPBrowserWindow::DumpScaledObject(QString & list, uint64_t p0, uint64_t p1, uint64_t p2)
178 sprintf(buf, " %08X %08X<br>", (uint32_t)(p1 >> 32), (uint32_t)(p1 & 0xFFFFFFFF));
179 list += QString(buf);
180 sprintf(buf, " %08X %08X<br>", (uint32_t)(p2 >> 32), (uint32_t)(p2 & 0xFFFFFFFF));
181 list += QString(buf);
182 DumpBitmapCore(list, p0, p1);
183 uint32_t hscale = p2 & 0xFF;
184 uint32_t vscale = (p2 >> 8) & 0xFF;
185 uint32_t remainder = (p2 >> 16) & 0xFF;
186 sprintf(buf, " [hsc: %02X, vsc: %02X, rem: %02X]<br>", hscale, vscale, remainder);
187 list += QString(buf);
191 void OPBrowserWindow::DumpFixedObject(QString & list, uint64_t p0, uint64_t p1)
195 sprintf(buf, " %08X %08X<br>", (uint32_t)(p1 >> 32), (uint32_t)(p1 & 0xFFFFFFFF));
196 list += QString(buf);
197 DumpBitmapCore(list, p0, p1);
201 void OPBrowserWindow::DumpBitmapCore(QString & list, uint64_t p0, uint64_t p1)
204 uint8_t op_bitmap_bit_depth[8] = { 1, 2, 4, 8, 16, 24, 32, 0 };
206 uint32_t bdMultiplier[8] = { 64, 32, 16, 8, 4, 2, 1, 1 };
207 uint8_t bitdepth = (p1 >> 12) & 0x07;
208 //WAS: int16 ypos = ((p0 >> 3) & 0x3FF); // ??? What if not interlaced (/2)?
209 int16_t ypos = ((p0 >> 3) & 0x7FF); // ??? What if not interlaced (/2)?
210 int32_t xpos = p1 & 0xFFF;
211 xpos = (xpos & 0x800 ? xpos | 0xFFFFF000 : xpos); // Sign extend that mutha!
212 uint32_t iwidth = ((p1 >> 28) & 0x3FF);
213 uint32_t dwidth = ((p1 >> 18) & 0x3FF); // Unsigned!
214 uint16_t height = ((p0 >> 14) & 0x3FF);
215 uint32_t link = ((p0 >> 24) & 0x7FFFF) << 3;
216 uint32_t ptr = ((p0 >> 43) & 0x1FFFFF) << 3;
217 uint32_t firstPix = (p1 >> 49) & 0x3F;
218 uint8_t flags = (p1 >> 45) & 0x0F;
219 uint8_t idx = (p1 >> 38) & 0x7F;
220 uint32_t pitch = (p1 >> 15) & 0x07;
222 sprintf(buf, " [%u x %u @ (%i, %u) (iw:%u, dw:%u) (%u bpp), p:%06X fp:%02X, fl:%s%s%s%s, idx:%02X, pt:%02X]<br>",
223 iwidth * bdMultiplier[bitdepth],
224 height, xpos, ypos, iwidth, dwidth, op_bitmap_bit_depth[bitdepth],
225 ptr, firstPix, (flags & OPFLAG_REFLECT ? "REFLECT " : ""),
226 (flags & OPFLAG_RMW ? "RMW " : ""), (flags & OPFLAG_TRANS ? "TRANS " : ""),
227 (flags & OPFLAG_RELEASE ? "RELEASE" : ""), idx, pitch);
228 list += QString(buf);