+ if (endPos < 0) // Case #2: Begin in, end out, R to L
+/* clippedWidth = 0 - endPos,
+ phraseClippedWidth = clippedWidth / phraseWidthToPixels[depth];*/
+ clippedWidth = 0 - endPos,
+ phraseClippedWidth = clippedWidth / scaledPhrasePixels;
+
+ if (endPos > lbufWidth) // Case #3: Begin in, end out, L to R
+/* clippedWidth = endPos - lbufWidth,
+ phraseClippedWidth = clippedWidth / phraseWidthToPixels[depth];*/
+ clippedWidth = endPos - lbufWidth,
+ phraseClippedWidth = clippedWidth / scaledPhrasePixels;
+
+ if (startPos > lbufWidth) // Case #4: Begin out, end in, R to L
+/* clippedWidth = startPos - lbufWidth,
+ dataClippedWidth = phraseClippedWidth = clippedWidth / phraseWidthToPixels[depth],
+ startPos = lbufWidth + (clippedWidth % phraseWidthToPixels[depth]);*/
+ 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 the image is sitting on the line buffer left or right edge, we need to compensate
+ // by decreasing the image phrase width accordingly.
+ iwidth -= phraseClippedWidth;
+
+ // Also, if we're clipping the phrase we need to make sure we're in the correct part of
+ // the pixel data.
+// data += phraseClippedWidth * (pitch << 3);
+ data += dataClippedWidth * (pitch << 3);
+
+ // NOTE: When the bitmap is in REFLECT mode, the XPOS marks the *right* side of the
+ // bitmap! This makes clipping & etc. MUCH, much easier...!
+// uint32 lbufAddress = 0x1800 + (!in24BPPMode ? leftMargin * 2 : leftMargin * 4);
+// uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 4);
+ uint32 lbufAddress = 0x1800 + (!in24BPPMode ? startPos * 2 : startPos * 2);
+ uint8 * currentLineBuffer = &tom_ram_8[lbufAddress];
+
+ // Render.