+//Try a simple example...
+// Let's say we have a 8 BPP scanline with an hscale of $80 (4). Our xpos is -10,
+// non-flipped. Pixels in the bitmap are XYZXYZXYZXYZXYZ.
+// Scaled up, they would be XXXXYYYYZZZZXXXXYYYYZZZZXXXXYYYYZZZZ...
+//
+// Normally, we would expect this in the line buffer:
+// ZZXXXXYYYYZZZZXXXXYYYYZZZZ...
+//
+// But instead we're getting:
+// XXXXYYYYZZZZXXXXYYYYZZZZ...
+//
+// or are we??? It would seem so, simply by virtue of the fact that we're NOT starting
+// on negative boundary--or are we? Hmm...
+// cw = 10, dcw = pcw = 10 / ([8 * 4 = 32] 32) = 0, sp = -10
+//
+// Let's try a real world example:
+//
+//OP: Scaled bitmap (70, 8 BPP, spp=28) sp (-400) < 0... [new sp=-8, cw=400, dcw=pcw=14]
+//OP: Scaled bitmap (6F, 8 BPP, spp=27) sp (-395) < 0... [new sp=-17, cw=395, dcw=pcw=14]
+//
+// Really, spp is 27.75 in the second case...
+// So... If we do 395 / 27.75, we get 14. Ok so far... If we scale that against the
+// start position (14 * 27.75), we get -6.5... NOT -17!
+
+//Now it seems we're working OK, at least for the first case...
+uint32 scaledPhrasePixelsUS = phraseWidthToPixels[depth] * hscale;
+
+ if (startPos < 0) // Case #1: Begin out, end in, L to R
+{
+extern int start_logging;
+if (start_logging)
+ WriteLog("OP: Scaled bitmap (%02X, %u BPP, spp=%u) start pos (%i) < 0...", hscale, op_bitmap_bit_depth[depth], scaledPhrasePixels, startPos);
+// clippedWidth = 0 - startPos,
+ clippedWidth = (0 - startPos) << 5,
+// dataClippedWidth = phraseClippedWidth = clippedWidth / scaledPhrasePixels,
+ dataClippedWidth = phraseClippedWidth = (clippedWidth / scaledPhrasePixelsUS) >> 5,
+// startPos = 0 - (clippedWidth % scaledPhrasePixels);
+ startPos += (dataClippedWidth * scaledPhrasePixelsUS) >> 5;
+if (start_logging)
+ WriteLog(" [new sp=%i, cw=%i, dcw=pcw=%i]\n", startPos, clippedWidth, dataClippedWidth);
+}
+
+ if (endPos < 0) // Case #2: Begin in, end out, R to L
+ clippedWidth = 0 - endPos,
+ phraseClippedWidth = clippedWidth / scaledPhrasePixels;
+
+ if (endPos > lbufWidth) // Case #3: Begin in, end out, L to R
+ clippedWidth = endPos - lbufWidth,
+ phraseClippedWidth = clippedWidth / scaledPhrasePixels;
+
+ if (startPos > lbufWidth) // Case #4: Begin out, end in, R to L
+ clippedWidth = startPos - lbufWidth,
+ dataClippedWidth = phraseClippedWidth = clippedWidth / scaledPhrasePixels,
+ startPos = lbufWidth + (clippedWidth % scaledPhrasePixels);
+
+extern int op_start_log;
+if (op_start_log && clippedWidth != 0)
+ WriteLog("OP: Clipped line. SP=%i, EP=%i, clip=%u, iwidth=%u, hscale=%02X\n", startPos, endPos, clippedWidth, iwidth, hscale);
+if (op_start_log && startPos == 13)
+{
+ WriteLog("OP: Scaled line. SP=%i, EP=%i, clip=%u, iwidth=%u, hscale=%02X, depth=%u, firstPix=%u\n", startPos, endPos, clippedWidth, iwidth, hscale, depth, firstPix);
+ DumpScaledObject(p0, p1, p2);
+ if (iwidth == 7)
+ {
+ WriteLog(" %08X: ", data);
+ for(int i=0; i<7*8; i++)
+ WriteLog("%02X ", JaguarReadByte(data+i));
+ WriteLog("\n");