+#endif
+
+/* WriteLog("\nM68000 disassembly at $802288...\n");
+ jaguar_dasm(0x802288, 3);
+ WriteLog("\nM68000 disassembly at $802200...\n");
+ jaguar_dasm(0x802200, 500);
+ WriteLog("\nM68000 disassembly at $802518...\n");
+ jaguar_dasm(0x802518, 100);//*/
+
+/* WriteLog("\n\nM68000 disassembly at $803F00 (look @ $803F2A)...\n");
+ jaguar_dasm(0x803F00, 500);
+ WriteLog("\n");//*/
+
+/* WriteLog("\n\nM68000 disassembly at $802B00 (look @ $802B5E)...\n");
+ jaguar_dasm(0x802B00, 500);
+ WriteLog("\n");//*/
+
+/* WriteLog("\n\nM68000 disassembly at $809900 (look @ $8099F8)...\n");
+ jaguar_dasm(0x809900, 500);
+ WriteLog("\n");//*/
+//8099F8
+/* WriteLog("\n\nDump of $8093C8:\n\n");
+ for(int i=0x8093C8; i<0x809900; i+=4)
+ WriteLog("%06X: %08X\n", i, JaguarReadLong(i));//*/
+/* WriteLog("\n\nM68000 disassembly at $90006C...\n");
+ jaguar_dasm(0x90006C, 500);
+ WriteLog("\n");//*/
+/* WriteLog("\n\nM68000 disassembly at $1AC000...\n");
+ jaguar_dasm(0x1AC000, 6000);
+ WriteLog("\n");//*/
+
+// WriteLog("Jaguar: CD BIOS version %04X\n", JaguarReadWord(0x3004));
+ WriteLog("Jaguar: Interrupt enable = $%02X\n", TOMReadByte(0xF000E1, JAGUAR) & 0x1F);
+ WriteLog("Jaguar: Video interrupt is %s (line=%u)\n", ((TOMIRQEnabled(IRQ_VIDEO))
+ && (JaguarInterruptHandlerIsValid(64))) ? "enabled" : "disabled", TOMReadWord(0xF0004E, JAGUAR));
+ M68K_show_context();
+//#endif
+
+ CDROMDone();
+ GPUDone();
+ DSPDone();
+ TOMDone();
+ JERRYDone();
+
+ // temp, until debugger is in place
+//00802016: jsr $836F1A.l
+//0080201C: jsr $836B30.l
+//00802022: jsr $836B18.l
+//00802028: jsr $8135F0.l
+//00813C1E: jsr $813F76.l
+//00802038: jsr $836D00.l
+//00802098: jsr $8373A4.l
+//008020A2: jsr $83E24A.l
+//008020BA: jsr $83E156.l
+//008020C6: jsr $83E19C.l
+//008020E6: jsr $8445E8.l
+//008020EC: jsr $838C20.l
+//0080211A: jsr $838ED6.l
+//00802124: jsr $89CA56.l
+//0080212A: jsr $802B48.l
+#if 0
+ WriteLog("-------------------------------------------\n");
+ JaguarDasm(0x8445E8, 0x200);
+ WriteLog("-------------------------------------------\n");
+ JaguarDasm(0x838C20, 0x200);
+ WriteLog("-------------------------------------------\n");
+ JaguarDasm(0x838ED6, 0x200);
+ WriteLog("-------------------------------------------\n");
+ JaguarDasm(0x89CA56, 0x200);
+ WriteLog("-------------------------------------------\n");
+ JaguarDasm(0x802B48, 0x200);
+ WriteLog("\n\nM68000 disassembly at $802000...\n");
+ JaguarDasm(0x802000, 6000);
+ WriteLog("\n");//*/
+#endif
+/* WriteLog("\n\nM68000 disassembly at $6004...\n");
+ JaguarDasm(0x6004, 10000);
+ WriteLog("\n");//*/
+// WriteLog("\n\nM68000 disassembly at $802000...\n");
+// JaguarDasm(0x802000, 0x1000);
+// WriteLog("\n\nM68000 disassembly at $4100...\n");
+// JaguarDasm(0x4100, 200);
+// WriteLog("\n\nM68000 disassembly at $800800...\n");
+// JaguarDasm(0x800800, 0x1000);
+}
+
+
+// Temp debugging stuff
+
+void DumpMainMemory(void)
+{
+ FILE * fp = fopen("./memdump.bin", "wb");
+
+ if (fp == NULL)
+ return;
+
+ fwrite(jaguarMainRAM, 1, 0x200000, fp);
+ fclose(fp);
+}
+
+
+uint8_t * GetRamPtr(void)
+{
+ return jaguarMainRAM;
+}
+
+
+//
+// New Jaguar execution stack
+// This executes 1 frame's worth of code.
+//
+bool frameDone;
+void JaguarExecuteNew(void)
+{
+ frameDone = false;
+
+ do
+ {
+ double timeToNextEvent = GetTimeToNextEvent();
+//WriteLog("JEN: Time to next event (%u) is %f usec (%u RISC cycles)...\n", nextEvent, timeToNextEvent, USEC_TO_RISC_CYCLES(timeToNextEvent));
+
+ m68k_execute(USEC_TO_M68K_CYCLES(timeToNextEvent));
+
+ if (vjs.GPUEnabled)
+ GPUExec(USEC_TO_RISC_CYCLES(timeToNextEvent));
+
+ HandleNextEvent();
+ }
+ while (!frameDone);
+}
+
+
+#define USE_CORRECT_PAL_TIMINGS
+// A lot of confusion comes from here...
+// The thing to keep in mind is that the VC is advanced every HALF line, regardless
+// of whether the display is interlaced or not. The only difference with an
+// interlaced display is that the high bit of VC will be set when the lower
+// field is being rendered. (NB: The high bit of VC is ALWAYS set on the lower field,
+// regardless of whether it's in interlace mode or not.
+// NB2: Seems it doens't always, not sure what the constraint is...)
+//
+// Normally, TVs will render a full frame in 1/30s (NTSC) or 1/25s (PAL) by
+// rendering two fields that are slighty vertically offset from each other.
+// Each field is created in 1/60s (NTSC) or 1/50s (PAL), and every other line
+// is rendered in this mode so that each field, when overlaid on each other,
+// will yield the final picture at the full resolution for the full frame.
+//
+// We execute a half frame in each timeslice (1/60s NTSC, 1/50s PAL).
+// Since the number of lines in a FULL frame is 525 for NTSC, 625 for PAL,
+// it will be half this number for a half frame. BUT, since we're counting
+// HALF lines, we double this number and we're back at 525 for NTSC, 625 for PAL.
+//
+// Scanline times are 63.5555... μs in NTSC and 64 μs in PAL
+// Half line times are, naturally, half of this. :-P
+void HalflineCallback(void)
+{
+//OK, this is hardwired to run in NTSC, and for who knows how long.
+//Need to fix this so that it does a half-line in the correct amount of time
+//and number of lines, depending on which mode we're in. [FIXED]
+ uint16_t vc = TOMReadWord(0xF00006, JAGUAR);
+ uint16_t vp = TOMReadWord(0xF0003E, JAGUAR) + 1;
+ uint16_t vi = TOMReadWord(0xF0004E, JAGUAR);
+// uint16_t vbb = TOMReadWord(0xF00040, JAGUAR);
+ vc++;
+
+#ifdef USE_CORRECT_PAL_TIMINGS
+ // Each # of lines is for a full frame == 1/30s (NTSC), 1/25s (PAL).
+ // So we cut the number of half-lines in a frame in half. :-P
+ uint16_t numHalfLines = ((vjs.hardwareTypeNTSC ? 525 : 625) * 2) / 2;
+
+ if ((vc & 0x7FF) >= numHalfLines)
+#else
+ if ((vc & 0x7FF) >= vp)
+#endif