-
- uint32 width = 640;
- switch (pwidth)
- {
-/* case 1: width = 640; break;
- case 2: width = 640; break;
- case 3: width = 448; break;
- case 4: width = 320; break;
- case 5: width = 256; break;
- case 6: width = 256; break;
- case 7: width = 256; break;
- case 8: width = 320; break;//*/
- case 1: width = 1330; break; // 0.25:1 pixels (X:Y ratio)
- case 2: width = 665; break; // 0.50:1 pixels
- case 3: width = 443; break; // 0.75:1 pixels
- case 4: width = 332; break; // 1.00:1 pixels
- case 5: width = 266; break; // 1.25:1 pixels
- case 6: width = 222; break; // 1.50:1 pixels
- case 7: width = 190; break; // 1.75:1 pixels
- case 8: width = 166; break; // 2.00:1 pixels
-//Temporary, for testing Doom...
-// case 8: width = 332; break; // 2.00:1 pixels
-//*/
- }
-
- if (hdb1 == 123)
- hblankWidthInPixels = 16;
- else
- hblankWidthInPixels = 0;
-
-// WriteLog("TOM: HDB1=%i HBE=%i\n", hdb1, hbe);
- return width;
+ // Also, I seriously doubt that you will see any games that use PWIDTH = 1!
+
+ // NOTE: Even though the PWIDTH value is + 1, here we're using a zero-based index and
+ // so we don't bother to add one...
+// return width[(GET16(tom_ram_8, VMODE) & PWIDTH) >> 9];
+
+ // Now, we just calculate it...
+ uint16 hdb1 = GET16(tom_ram_8, HDB1), hde = GET16(tom_ram_8, HDE),
+ hbb = GET16(tom_ram_8, HBB), pwidth = ((GET16(tom_ram_8, VMODE) & PWIDTH) >> 9) + 1;
+ return ((hbb < hde ? hbb : hde) - hdb1) / pwidth;
+
+// More speculating...
+// According to the JTRM, the number of potential pixels across is given by the
+// Horizontal Period (HP - in NTSC this is 845). The Horizontal Count counts from
+// zero to this value twice per scanline (the high bit is set on the second count).
+// HBE and HBB define the absolute "black" limits of the screen, while HDB1/2 and
+// HDE determine the extent of the OP "on" time. I.e., when the OP is turned on by
+// HDB1, it starts fetching the line from position 0 in LBUF.
+
+// The trick, it would seem, is to figure out how long the typical visible scanline
+// of a TV is in HP ticks and limit the visible area to that (divided by PWIDTH, of
+// course). Using that length, we can establish an "absolute left display limit" with
+// which to measure HBB & HDB1/2 against when rendering LBUF (i.e., if HDB1 is 20 ticks
+// to the right of the ALDL and PWIDTH is 4, then start writing the LBUF starting at
+// backbuffer + 5 pixels).