4 // Originally by David Raingeard (Cal2)
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Carwin Jones (BeOS)
6 // Cleanups and endian wrongness amelioration by James L. Hammons
7 // Note: Endian wrongness probably stems from the MAME origins of this emu and
8 // the braindead way in which MAME handles memory. :-)
15 //#include "m68kdasmAG.h"
18 #include "SDL_opengl.h"
30 //Do this in makefile??? Yes! Could, but it's easier to define here...
31 //#define LOG_UNMAPPED_MEMORY_ACCESSES
32 //#define ABORT_ON_UNMAPPED_MEMORY_ACCESS
33 #define ABORT_ON_ILLEGAL_INSTRUCTIONS
34 //#define ABORT_ON_OFFICIAL_ILLEGAL_INSTRUCTION
35 #define CPU_DEBUG_MEMORY
37 // Private function prototypes
39 unsigned jaguar_unknown_readbyte(unsigned address, uint32 who = UNKNOWN);
40 unsigned jaguar_unknown_readword(unsigned address, uint32 who = UNKNOWN);
41 void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who = UNKNOWN);
42 void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who = UNKNOWN);
43 void M68K_show_context(void);
47 //extern bool hardwareTypeNTSC; // Set to false for PAL
48 #ifdef CPU_DEBUG_MEMORY
49 extern bool startMemLog; // Set by "e" key
50 extern int effect_start;
51 extern int effect_start2, effect_start3, effect_start4, effect_start5, effect_start6;
54 // Memory debugging identifiers
56 const char * whoName[9] =
57 { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" };
59 uint32 jaguar_active_memory_dumps = 0;
61 uint32 jaguar_mainRom_crc32, jaguarRomSize, jaguarRunAddress;
63 /*static*/ uint8 * jaguar_mainRam = NULL;
64 /*static*/ uint8 * jaguar_mainRom = NULL;
65 /*static*/ uint8 * jaguar_bootRom = NULL;
66 /*static*/ uint8 * jaguar_CDBootROM = NULL;
68 #ifdef CPU_DEBUG_MEMORY
69 uint8 writeMemMax[0x400000], writeMemMin[0x400000];
70 uint8 readMem[0x400000];
71 uint32 returnAddr[4000], raPtr = 0xFFFFFFFF;
74 uint32 pcQueue[0x400];
78 // Callback function to detect illegal instructions
80 void GPUDumpDisassembly(void);
81 void GPUDumpRegisters(void);
82 static bool start = false;
83 void M68KInstructionHook(void)
85 uint32 m68kPC = m68k_get_reg(NULL, M68K_REG_PC);
88 // Ideally, we'd save all the registers as well...
89 pcQueue[pcQPtr++] = m68kPC;
92 if (m68kPC & 0x01) // Oops! We're fetching an odd address!
94 WriteLog("M68K: Attempted to execute from an odd adress!\n\nBacktrace:\n\n");
96 static char buffer[2048];
97 for(int i=0; i<0x400; i++)
99 m68k_disassemble(buffer, pcQueue[(pcQPtr + i) & 0x3FF], M68K_CPU_TYPE_68000);
100 WriteLog("\t%08X: %s\n", pcQueue[(pcQPtr + i) & 0x3FF], buffer);
104 uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
105 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
106 for(int i=0; i<10; i++)
107 WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4)));
108 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
114 /* if (m68kPC >= 0x807EC4 && m68kPC <= 0x807EDB)
116 static char buffer[2048];
117 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
118 WriteLog("%08X: %s", m68kPC, buffer);
119 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X, D1=%08X\n",
120 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
121 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1));
123 /* if (m68kPC == 0x8D0E48 && effect_start5)
125 WriteLog("\nM68K: At collision detection code. Exiting!\n\n");
127 GPUDumpDisassembly();
131 /* uint16 opcode = JaguarReadWord(m68kPC);
132 if (opcode == 0x4E75) // RTS
135 // WriteLog("Jaguar: Returning from subroutine to %08X\n", JaguarReadLong(m68k_get_reg(NULL, M68K_REG_A7)));
137 uint32 addr = JaguarReadLong(m68k_get_reg(NULL, M68K_REG_A7));
139 if (raPtr != 0xFFFFFFFF)
141 for(uint32 i=0; i<=raPtr; i++)
143 if (returnAddr[i] == addr)
152 returnAddr[++raPtr] = addr;
156 //Flip Out! debugging...
159 00805FDC: movea.l #$9c6f8, A0 D0=00100010, A0=00100000
160 00805FE2: move.w #$10, (A0)+ D0=00100010, A0=0009C6F8
161 00805FE6: cmpa.l #$c96f8, A0 D0=00100010, A0=0009C6FA
162 00805FEC: bne 805fe2 D0=00100010, A0=0009C6FA
164 0080603A: move.l #$11ed7c, $100.w D0=61700080, A0=000C96F8, D1=00000000, A1=000040D8
166 0012314C: move.l (A0)+, (A1)+ D0=61700080, A0=00124174, D1=00000000, A1=00F03FFC
167 0012314E: cmpa.l #$f04000, A1 D0=61700080, A0=00124178, D1=00000000, A1=00F04000
168 00123154: blt 12314c D0=61700080, A0=00124178, D1=00000000, A1=00F04000
169 00123156: move.l #$0, $f035d0.l D0=61700080, A0=00124178, D1=00000000, A1=00F04000
170 00123160: move.l #$f03000, $f02110.l D0=61700080, A0=00124178, D1=00000000, A1=00F04000
171 0012316A: move.l #$1, $f02114.l D0=61700080, A0=00124178, D1=00000000, A1=00F04000
172 00123174: rts D0=61700080, A0=00124178, D1=00000000, A1=00F04000
174 /* static char buffer[2048];
175 //if (m68kPC > 0x805F48) start = true;
176 //if (m68kPC > 0x806486) start = true;
177 //if (m68kPC == 0x805FEE) start = true;
178 //if (m68kPC == 0x80600C)// start = true;
179 if (m68kPC == 0x802058) start = true;
181 // GPUDumpRegisters();
182 // GPUDumpDisassembly();
184 // M68K_show_context();
190 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
191 WriteLog("%08X: %s \t\tD0=%08X, A0=%08X, D1=%08X, A1=%08X\n", m68kPC, buffer, m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_A1));
194 /* if (m68kPC == 0x803F16)
196 WriteLog("M68K: Registers found at $803F16:\n");
197 WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
198 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
199 WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
201 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
202 WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
204 //Looks like the DSP is supposed to return $12345678 when it finishes its validation routine...
205 // !!! Investigate !!!
206 /*extern bool doDSPDis;
207 static bool disgo = false;
208 if (m68kPC == 0x50222)
211 // WriteLog("M68K: About to stuff $12345678 into $F1B000 (=%08X)...\n", DSPReadLong(0xF1B000, M68K));
212 // DSPWriteLong(0xF1B000, 0x12345678, M68K);
215 if (m68kPC == 0x5000)
220 static char buffer[2048];
221 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
222 WriteLog("%08X: %s", m68kPC, buffer);
223 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X, D1=%08X, D2=%08X\n",
224 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
225 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
227 if (m68kPC == 0x82E1A)
229 static char buffer[2048];
230 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
231 WriteLog("--> [Routine start] %08X: %s", m68kPC, buffer);
232 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X(cmd), D1=%08X(# bytes), D2=%08X\n",
233 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
234 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
236 if (m68kPC == 0x82E58)
237 WriteLog("--> [Routine end]\n");
238 if (m68kPC == 0x80004)
240 WriteLog("--> [Calling BusWrite2] D2: %08X\n", m68k_get_reg(NULL, M68K_REG_D2));
241 // m68k_set_reg(M68K_REG_D2, 0x12345678);
265 if (m68kPC == 0x3000)
266 WriteLog("M68K: CD_init\n");
267 else if (m68kPC == 0x3006 + (6 * 0))
268 WriteLog("M68K: CD_mode\n");
269 else if (m68kPC == 0x3006 + (6 * 1))
270 WriteLog("M68K: CD_ack\n");
271 else if (m68kPC == 0x3006 + (6 * 2))
272 WriteLog("M68K: CD_jeri\n");
273 else if (m68kPC == 0x3006 + (6 * 3))
274 WriteLog("M68K: CD_spin\n");
275 else if (m68kPC == 0x3006 + (6 * 4))
276 WriteLog("M68K: CD_stop\n");
277 else if (m68kPC == 0x3006 + (6 * 5))
278 WriteLog("M68K: CD_mute\n");
279 else if (m68kPC == 0x3006 + (6 * 6))
280 WriteLog("M68K: CD_umute\n");
281 else if (m68kPC == 0x3006 + (6 * 7))
282 WriteLog("M68K: CD_paus\n");
283 else if (m68kPC == 0x3006 + (6 * 8))
284 WriteLog("M68K: CD_upaus\n");
285 else if (m68kPC == 0x3006 + (6 * 9))
286 WriteLog("M68K: CD_read\n");
287 else if (m68kPC == 0x3006 + (6 * 10))
288 WriteLog("M68K: CD_uread\n");
289 else if (m68kPC == 0x3006 + (6 * 11))
290 WriteLog("M68K: CD_setup\n");
291 else if (m68kPC == 0x3006 + (6 * 12))
292 WriteLog("M68K: CD_ptr\n");
293 else if (m68kPC == 0x3006 + (6 * 13))
294 WriteLog("M68K: CD_osamp\n");
295 else if (m68kPC == 0x3006 + (6 * 14))
296 WriteLog("M68K: CD_getoc\n");
297 else if (m68kPC == 0x3006 + (6 * 15))
298 WriteLog("M68K: CD_initm\n");
299 else if (m68kPC == 0x3006 + (6 * 16))
300 WriteLog("M68K: CD_initf\n");
301 else if (m68kPC == 0x3006 + (6 * 17))
302 WriteLog("M68K: CD_switch\n");
304 if (m68kPC >= 0x3000 && m68kPC <= 0x306C)
305 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X, D1=%08X, D2=%08X\n",
306 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
307 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
309 #ifdef ABORT_ON_ILLEGAL_INSTRUCTIONS
310 if (!m68k_is_valid_instruction(m68k_read_memory_16(m68kPC), M68K_CPU_TYPE_68000))
312 #ifndef ABORT_ON_OFFICIAL_ILLEGAL_INSTRUCTION
313 if (m68k_read_memory_16(m68kPC) == 0x4AFC)
315 // This is a kludge to let homebrew programs work properly (i.e., let the other processors
316 // keep going even when the 68K dumped back to the debugger or what have you).
318 // m68k_set_reg(M68K_REG_PC, m68kPC - 2);
319 // Try setting the vector to the illegal instruction...
320 //This doesn't work right either! Do something else! Quick!
321 // SET32(jaguar_mainRam, 0x10, m68kPC);
327 WriteLog("\nM68K encountered an illegal instruction at %08X!!!\n\nAborting!\n", m68kPC);
328 uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
329 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
330 for(int i=0; i<10; i++)
331 WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4)));
332 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
336 // WriteLog("\n\n68K disasm\n\n");
337 // jaguar_dasm(0x802000, 0x50C);
348 // Musashi 68000 read/write/IRQ functions
351 int irq_ack_handler(int level)
353 int vector = M68K_INT_ACK_AUTOVECTOR;
355 // The GPU/DSP/etc are probably *not* issuing an NMI, but it seems to work OK...
359 m68k_set_irq(0); // Clear the IRQ...
360 vector = 64; // Set user interrupt #0
366 unsigned int m68k_read_memory_8(unsigned int address)
368 #ifdef CPU_DEBUG_MEMORY
369 if ((address >= 0x000000) && (address <= 0x3FFFFF))
372 readMem[address] = 1;
375 //WriteLog("[RM8] Addr: %08X\n", address);
376 //; So, it seems that it stores the returned DWORD at $51136 and $FB074.
377 /* if (address == 0x51136 || address == 0x51138 || address == 0xFB074 || address == 0xFB076
378 || address == 0x1AF05E)
379 WriteLog("[RM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, jaguar_mainRam[address]);//*/
380 unsigned int retVal = 0;
382 if ((address >= 0x000000) && (address <= 0x3FFFFF))
383 retVal = jaguar_mainRam[address];
384 // else if ((address >= 0x800000) && (address <= 0xDFFFFF))
385 else if ((address >= 0x800000) && (address <= 0xDFFEFF))
386 retVal = jaguar_mainRom[address - 0x800000];
387 else if ((address >= 0xE00000) && (address <= 0xE3FFFF))
388 retVal = jaguar_bootRom[address - 0xE00000];
389 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
390 retVal = CDROMReadByte(address);
391 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
392 retVal = TOMReadByte(address, M68K);
393 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
394 retVal = JERRYReadByte(address, M68K);
396 retVal = jaguar_unknown_readbyte(address, M68K);
398 //if (address >= 0x2800 && address <= 0x281F)
399 // WriteLog("M68K: Read byte $%02X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
400 //if (address >= 0x8B5E4 && address <= 0x8B5E4 + 16)
401 // WriteLog("M68K: Read byte $%02X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
405 void gpu_dump_disassembly(void);
406 void gpu_dump_registers(void);
408 unsigned int m68k_read_memory_16(unsigned int address)
410 #ifdef CPU_DEBUG_MEMORY
411 /* if ((address >= 0x000000) && (address <= 0x3FFFFE))
414 readMem[address] = 1, readMem[address + 1] = 1;
416 /* if (effect_start && (address >= 0x8064FC && address <= 0x806501))
418 return 0x4E71; // NOP
420 if (effect_start2 && (address >= 0x806502 && address <= 0x806507))
422 return 0x4E71; // NOP
424 if (effect_start3 && (address >= 0x806512 && address <= 0x806517))
426 return 0x4E71; // NOP
428 if (effect_start4 && (address >= 0x806524 && address <= 0x806527))
430 return 0x4E71; // NOP
432 if (effect_start5 && (address >= 0x80653E && address <= 0x806543)) //Collision detection!
434 return 0x4E71; // NOP
436 if (effect_start6 && (address >= 0x806544 && address <= 0x806547))
438 return 0x4E71; // NOP
441 //WriteLog("[RM16] Addr: %08X\n", address);
442 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005FBA)
443 // for(int i=0; i<10000; i++)
444 WriteLog("[M68K] In routine #6!\n");//*/
445 //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00006696) // GPU Program #4
446 //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005B3C) // GPU Program #2
447 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005BA8) // GPU Program #3
449 WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address));
450 gpu_dump_registers();
451 gpu_dump_disassembly();
452 // for(int i=0; i<10000; i++)
453 // WriteLog("[M68K] About to run GPU!\n");
455 //WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
456 /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x00006696 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x000066A8)
458 if (address == 0x000066A0)
460 gpu_dump_registers();
461 gpu_dump_disassembly();
463 for(int i=0; i<10000; i++)
464 WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address));
466 //; So, it seems that it stores the returned DWORD at $51136 and $FB074.
467 /* if (address == 0x51136 || address == 0x51138 || address == 0xFB074 || address == 0xFB076
468 || address == 0x1AF05E)
469 WriteLog("[RM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, GET16(jaguar_mainRam, address));//*/
470 unsigned int retVal = 0;
472 if ((address >= 0x000000) && (address <= 0x3FFFFE))
473 // retVal = (jaguar_mainRam[address] << 8) | jaguar_mainRam[address+1];
474 retVal = GET16(jaguar_mainRam, address);
475 // else if ((address >= 0x800000) && (address <= 0xDFFFFE))
476 else if ((address >= 0x800000) && (address <= 0xDFFEFE))
477 retVal = (jaguar_mainRom[address - 0x800000] << 8) | jaguar_mainRom[address - 0x800000 + 1];
478 else if ((address >= 0xE00000) && (address <= 0xE3FFFE))
479 retVal = (jaguar_bootRom[address - 0xE00000] << 8) | jaguar_bootRom[address - 0xE00000 + 1];
480 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
481 retVal = CDROMReadWord(address, M68K);
482 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
483 retVal = TOMReadWord(address, M68K);
484 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
485 retVal = JERRYReadWord(address, M68K);
487 retVal = jaguar_unknown_readword(address, M68K);
489 //if (address >= 0xF1B000 && address <= 0xF1CFFF)
490 // WriteLog("M68K: Read word $%04X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
491 //if (address >= 0x2800 && address <= 0x281F)
492 // WriteLog("M68K: Read word $%04X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
493 //$8B3AE -> Transferred from $F1C010
494 //$8B5E4 -> Only +1 read at $808AA
495 //if (address >= 0x8B5E4 && address <= 0x8B5E4 + 16)
496 // WriteLog("M68K: Read word $%04X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
500 unsigned int m68k_read_memory_32(unsigned int address)
502 //; So, it seems that it stores the returned DWORD at $51136 and $FB074.
503 /* if (address == 0x51136 || address == 0xFB074 || address == 0x1AF05E)
504 WriteLog("[RM32 PC=%08X] Addr: %08X, val: %08X\n", m68k_get_reg(NULL, M68K_REG_PC), address, (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2));//*/
506 //WriteLog("--> [RM32]\n");
507 return (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2);
510 void m68k_write_memory_8(unsigned int address, unsigned int value)
512 #ifdef CPU_DEBUG_MEMORY
513 if ((address >= 0x000000) && (address <= 0x3FFFFF))
517 if (value > writeMemMax[address])
518 writeMemMax[address] = value;
519 if (value < writeMemMin[address])
520 writeMemMin[address] = value;
524 //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F))
525 // WriteLog("M68K: Writing %02X at %08X\n", value, address);
526 //WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
528 if (address >= 0x18FA70 && address < (0x18FA70 + 8000))
529 WriteLog("M68K: Byte %02X written at %08X by 68K\n", value, address);//*/
531 if ((address >= 0x000000) && (address <= 0x3FFFFF))
532 jaguar_mainRam[address] = value;
533 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
534 CDROMWriteByte(address, value, M68K);
535 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
536 TOMWriteByte(address, value, M68K);
537 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
538 JERRYWriteByte(address, value, M68K);
540 jaguar_unknown_writebyte(address, value, M68K);
543 void m68k_write_memory_16(unsigned int address, unsigned int value)
545 #ifdef CPU_DEBUG_MEMORY
546 if ((address >= 0x000000) && (address <= 0x3FFFFE))
550 uint8 hi = value >> 8, lo = value & 0xFF;
552 if (hi > writeMemMax[address])
553 writeMemMax[address] = hi;
554 if (hi < writeMemMin[address])
555 writeMemMin[address] = hi;
557 if (lo > writeMemMax[address+1])
558 writeMemMax[address+1] = lo;
559 if (lo < writeMemMin[address+1])
560 writeMemMin[address+1] = lo;
564 //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F))
565 // WriteLog("M68K: Writing %04X at %08X\n", value, address);
566 //WriteLog("[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
567 //if (address >= 0xF02200 && address <= 0xF0229F)
568 // WriteLog("M68K: Writing to blitter --> %04X at %08X\n", value, address);
569 //if (address >= 0x0E75D0 && address <= 0x0E75E7)
570 // WriteLog("M68K: Writing %04X at %08X, M68K PC=%08X\n", value, address, m68k_get_reg(NULL, M68K_REG_PC));
571 /*extern uint32 totalFrames;
572 if (address == 0xF02114)
573 WriteLog("M68K: Writing to GPU_CTRL (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));
574 if (address == 0xF02110)
575 WriteLog("M68K: Writing to GPU_PC (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));//*/
576 //if (address >= 0xF03B00 && address <= 0xF03DFF)
577 // WriteLog("M68K: Writing %04X to %08X...\n", value, address);
579 /*if (address == 0x0100)//64*4)
580 WriteLog("M68K: Wrote word to VI vector value %04X...\n", value);//*/
582 if (address >= 0x18FA70 && address < (0x18FA70 + 8000))
583 WriteLog("M68K: Word %04X written at %08X by 68K\n", value, address);//*/
584 /* if (address == 0x51136 || address == 0x51138 || address == 0xFB074 || address == 0xFB076
585 || address == 0x1AF05E)
586 WriteLog("[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);//*/
588 if ((address >= 0x000000) && (address <= 0x3FFFFE))
590 /* jaguar_mainRam[address] = value >> 8;
591 jaguar_mainRam[address + 1] = value & 0xFF;*/
592 SET16(jaguar_mainRam, address, value);
594 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
595 CDROMWriteWord(address, value, M68K);
596 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
597 TOMWriteWord(address, value, M68K);
598 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
599 JERRYWriteWord(address, value, M68K);
602 jaguar_unknown_writeword(address, value, M68K);
603 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
604 WriteLog("\tA0=%08X, A1=%08X, D0=%08X, D1=%08X\n",
605 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
606 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1));
611 void m68k_write_memory_32(unsigned int address, unsigned int value)
613 //WriteLog("--> [WM32]\n");
614 /*if (address == 0x0100)//64*4)
615 WriteLog("M68K: Wrote dword to VI vector value %08X...\n", value);//*/
616 /*if (address >= 0xF03214 && address < 0xF0321F)
617 WriteLog("M68K: Writing DWORD (%08X) to GPU RAM (%08X)...\n", value, address);//*/
618 //M68K: Writing DWORD (88E30047) to GPU RAM (00F03214)...
619 /*extern bool doGPUDis;
620 if (address == 0xF03214 && value == 0x88E30047)
623 /* if (address == 0x51136 || address == 0xFB074)
624 WriteLog("[WM32 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);//*/
626 m68k_write_memory_16(address, value >> 16);
627 m68k_write_memory_16(address + 2, value & 0xFFFF);
631 uint32 jaguar_get_handler(uint32 i)
633 return JaguarReadLong(i * 4);
636 uint32 jaguar_interrupt_handler_is_valid(uint32 i) // Debug use only...
638 uint32 handler = jaguar_get_handler(i);
639 if (handler && (handler != 0xFFFFFFFF))
645 void M68K_show_context(void)
647 WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
648 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
649 WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
651 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
652 WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
654 WriteLog("68K disasm\n");
655 // jaguar_dasm(s68000readPC()-0x1000,0x20000);
656 jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x80, 0x200);
657 // jaguar_dasm(0x5000, 0x14414);
659 // WriteLog("\n.......[Cart start]...........\n\n");
660 // jaguar_dasm(0x192000, 0x1000);//0x200);
662 WriteLog("..................\n");
664 if (tom_irq_enabled(IRQ_VBLANK))
666 WriteLog("vblank int: enabled\n");
667 jaguar_dasm(jaguar_get_handler(64), 0x200);
670 WriteLog("vblank int: disabled\n");
672 WriteLog("..................\n");
674 for(int i=0; i<256; i++)
675 WriteLog("handler %03i at $%08X\n", i, (unsigned int)jaguar_get_handler(i));
679 // Unknown read/write byte/word routines
682 // It's hard to believe that developers would be sloppy with their memory writes, yet in
683 // some cases the developers screwed up royal. E.g., Club Drive has the following code:
685 // 807EC4: movea.l #$f1b000, A1
686 // 807ECA: movea.l #$8129e0, A0
687 // 807ED0: move.l A0, D0
688 // 807ED2: move.l #$f1bb94, D1
689 // 807ED8: sub.l D0, D1
690 // 807EDA: lsr.l #2, D1
691 // 807EDC: move.l (A0)+, (A1)+
692 // 807EDE: dbra D1, 807edc
694 // The problem is at $807ED0--instead of putting A0 into D0, they really meant to put A1
695 // in. This mistake causes it to try and overwrite approximately $700000 worth of address
696 // space! (That is, unless the 68K causes a bus error...)
698 void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/)
700 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
701 WriteLog("Jaguar: Unknown byte %02X written at %08X by %s (M68K PC=%06X)\n", data, address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
703 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
704 extern bool finished;
706 extern bool doDSPDis;
712 void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/)
714 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
715 WriteLog("Jaguar: Unknown word %04X written at %08X by %s (M68K PC=%06X)\n", data, address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
717 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
718 extern bool finished;
720 extern bool doDSPDis;
726 unsigned jaguar_unknown_readbyte(unsigned address, uint32 who/*=UNKNOWN*/)
728 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
729 WriteLog("Jaguar: Unknown byte read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
731 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
732 extern bool finished;
734 extern bool doDSPDis;
741 unsigned jaguar_unknown_readword(unsigned address, uint32 who/*=UNKNOWN*/)
743 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
744 WriteLog("Jaguar: Unknown word read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
746 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
747 extern bool finished;
749 extern bool doDSPDis;
757 // Disassemble M68K instructions at the given offset
760 unsigned int m68k_read_disassembler_8(unsigned int address)
762 return m68k_read_memory_8(address);
765 unsigned int m68k_read_disassembler_16(unsigned int address)
767 return m68k_read_memory_16(address);
770 unsigned int m68k_read_disassembler_32(unsigned int address)
772 return m68k_read_memory_32(address);
775 void jaguar_dasm(uint32 offset, uint32 qt)
778 static char buffer[2048];//, mem[64];
779 int pc = offset, oldpc;
781 for(uint32 i=0; i<qt; i++)
784 for(int j=0; j<64; j++)
785 mem[j^0x01] = jaguar_byte_read(pc + j);
787 pc += Dasm68000((char *)mem, buffer, 0);
788 WriteLog("%08X: %s\n", oldpc, buffer);//*/
790 pc += m68k_disassemble(buffer, pc, M68K_CPU_TYPE_68000);
791 WriteLog("%08X: %s\n", oldpc, buffer);//*/
796 uint8 JaguarReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
801 if (offset < 0x400000)
802 data = jaguar_mainRam[offset & 0x3FFFFF];
803 else if ((offset >= 0x800000) && (offset < 0xC00000))
804 data = jaguar_mainRom[offset - 0x800000];
805 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
806 data = CDROMReadByte(offset, who);
807 else if ((offset >= 0xE00000) && (offset < 0xE40000))
808 data = jaguar_bootRom[offset & 0x3FFFF];
809 else if ((offset >= 0xF00000) && (offset < 0xF10000))
810 data = TOMReadByte(offset, who);
811 else if ((offset >= 0xF10000) && (offset < 0xF20000))
812 data = JERRYReadByte(offset, who);
814 data = jaguar_unknown_readbyte(offset, who);
819 uint16 JaguarReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
822 if (offset <= 0x3FFFFE)
824 return (jaguar_mainRam[(offset+0) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+1) & 0x3FFFFF];
826 else if ((offset >= 0x800000) && (offset <= 0xBFFFFE))
829 return (jaguar_mainRom[offset+0] << 8) | jaguar_mainRom[offset+1];
831 // else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00))
832 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE))
833 return CDROMReadWord(offset, who);
834 else if ((offset >= 0xE00000) && (offset <= 0xE3FFFE))
835 return (jaguar_bootRom[(offset+0) & 0x3FFFF] << 8) | jaguar_bootRom[(offset+1) & 0x3FFFF];
836 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE))
837 return TOMReadWord(offset, who);
838 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE))
839 return JERRYReadWord(offset, who);
841 return jaguar_unknown_readword(offset, who);
844 void JaguarWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
846 //Need to check for writes in the range of $18FA70 + 8000...
848 if (offset >= 0x18FA70 && offset < (0x18FA70 + 8000))
849 WriteLog("JWB: Byte %02X written at %08X by %s\n", data, offset, whoName[who]);//*/
852 if (offset < 0x400000)
854 jaguar_mainRam[offset & 0x3FFFFF] = data;
857 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
859 CDROMWriteByte(offset, data, who);
862 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFF))
864 TOMWriteByte(offset, data, who);
867 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFF))
869 JERRYWriteByte(offset, data, who);
873 jaguar_unknown_writebyte(offset, data, who);
877 void JaguarWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
879 /*if (offset == 0x0100)//64*4)
880 WriteLog("M68K: %s wrote word to VI vector value %04X...\n", whoName[who], data);
881 if (offset == 0x0102)//64*4)
882 WriteLog("M68K: %s wrote word to VI vector+2 value %04X...\n", whoName[who], data);//*/
883 //TEMP--Mirror of F03000? Yes, but only 32-bit CPUs can do it (i.e., NOT the 68K!)
884 // PLUS, you would handle this in the GPU/DSP WriteLong code! Not here!
885 //Need to check for writes in the range of $18FA70 + 8000...
887 if (offset >= 0x18FA70 && offset < (0x18FA70 + 8000))
888 WriteLog("JWW: Word %04X written at %08X by %s\n", data, offset, whoName[who]);//*/
889 /*if (offset >= 0x2C00 && offset <= 0x2CFF)
890 WriteLog("Jaguar: Word %04X written to TOC+%02X by %s\n", data, offset-0x2C00, whoName[who]);//*/
894 if (offset <= 0x3FFFFE)
899 1A 69 F0 ($0000) -> Starfield
900 1A 73 C8 ($0001) -> Final clearing blit & bitmap blit?
903 1A 8F E8 ($0004) -> "Jaguar" small color logo?
912 //This MUST be done by the 68K!
913 /*if (offset == 0x670C)
914 WriteLog("Jaguar: %s writing to location $670C...\n", whoName[who]);*/
916 /*extern bool doGPUDis;
917 //if ((offset == 0x100000 + 75522) && who == GPU) // 76,226 -> 75522
918 if ((offset == 0x100000 + 128470) && who == GPU) // 107,167 -> 128470 (384 x 250 screen size 16BPP)
919 //if ((offset >= 0x100000 && offset <= 0x12C087) && who == GPU)
921 /*if (offset == 0x100000 + 128470) // 107,167 -> 128470 (384 x 250 screen size 16BPP)
922 WriteLog("JWW: Writing value %04X at %08X by %s...\n", data, offset, whoName[who]);
923 if ((data & 0xFF00) != 0x7700)
924 WriteLog("JWW: Writing value %04X at %08X by %s...\n", data, offset, whoName[who]);//*/
925 /*if ((offset >= 0x100000 && offset <= 0x147FFF) && who == GPU)
927 /*if ((data & 0xFF00) != 0x7700 && who == GPU)
928 WriteLog("JWW: Writing value %04X at %08X by %s...\n", data, offset, whoName[who]);//*/
929 /*if ((offset >= 0x100000 + 0x48000 && offset <= 0x12C087 + 0x48000) && who == GPU)
931 /*extern bool doGPUDis;
932 if (offset == 0x120216 && who == GPU)
934 /*extern uint32 gpu_pc;
935 if (who == GPU && (gpu_pc == 0xF03604 || gpu_pc == 0xF03638))
937 uint32 base = offset - (offset > 0x148000 ? 0x148000 : 0x100000);
938 uint32 y = base / 0x300;
939 uint32 x = (base - (y * 0x300)) / 2;
940 WriteLog("JWW: Writing starfield star %04X at %08X (%u/%u) [%s]\n", data, offset, x, y, (gpu_pc == 0xF03604 ? "s" : "L"));
943 JWW: Writing starfield star 775E at 0011F650 (555984/1447)
945 //if (offset == (0x001E17F8 + 0x34))
946 /*if (who == GPU && offset == (0x001E17F8 + 0x34))
948 // WriteLog("JWW: Write at %08X written to by %s.\n", 0x001E17F8 + 0x34, whoName[who]);//*/
949 /*extern uint32 gpu_pc;
950 if (who == GPU && (gpu_pc == 0xF03604 || gpu_pc == 0xF03638))
952 extern int objectPtr;
953 // if (offset > 0x148000)
956 if (starCount > objectPtr)
959 // if (starCount == 1)
960 // WriteLog("--> Drawing 1st star...\n");
962 // uint32 base = offset - (offset > 0x148000 ? 0x148000 : 0x100000);
963 // uint32 y = base / 0x300;
964 // uint32 x = (base - (y * 0x300)) / 2;
965 // WriteLog("JWW: Writing starfield star %04X at %08X (%u/%u) [%s]\n", data, offset, x, y, (gpu_pc == 0xF03604 ? "s" : "L"));
967 //A star of interest...
968 //-->JWW: Writing starfield star 77C9 at 0011D31A (269/155) [s]
969 //1st trail +3(x), -1(y) -> 272, 154 -> 0011D020
970 //JWW: Blitter writing echo 77B3 at 0011D022...
972 //extern bool doGPUDis;
973 /*if (offset == 0x11D022 + 0x48000 || offset == 0x11D022)// && who == GPU)
976 WriteLog("JWW: %s writing echo %04X at %08X...\n", whoName[who], data, offset);
979 if (offset == 0x11D31A + 0x48000 || offset == 0x11D31A)
980 WriteLog("JWW: %s writing star %04X at %08X...\n", whoName[who], data, offset);//*/
982 jaguar_mainRam[(offset+0) & 0x3FFFFF] = data >> 8;
983 jaguar_mainRam[(offset+1) & 0x3FFFFF] = data & 0xFF;
986 else if (offset >= 0xDFFF00 && offset <= 0xDFFFFE)
988 CDROMWriteWord(offset, data, who);
991 else if (offset >= 0xF00000 && offset <= 0xF0FFFE)
993 TOMWriteWord(offset, data, who);
996 else if (offset >= 0xF10000 && offset <= 0xF1FFFE)
998 JERRYWriteWord(offset, data, who);
1001 // Don't bomb on attempts to write to ROM
1002 else if (offset >= 0x800000 && offset <= 0xEFFFFF)
1005 jaguar_unknown_writeword(offset, data, who);
1008 // We really should re-do this so that it does *real* 32-bit access... !!! FIX !!!
1009 uint32 JaguarReadLong(uint32 offset, uint32 who/*=UNKNOWN*/)
1011 return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset+2, who);
1014 // We really should re-do this so that it does *real* 32-bit access... !!! FIX !!!
1015 void JaguarWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
1017 /* extern bool doDSPDis;
1018 if (offset < 0x400 && !doDSPDis)
1020 WriteLog("JLW: Write to %08X by %s... Starting DSP log!\n\n", offset, whoName[who]);
1023 /*if (offset == 0x0100)//64*4)
1024 WriteLog("M68K: %s wrote dword to VI vector value %08X...\n", whoName[who], data);//*/
1026 JaguarWriteWord(offset, data >> 16, who);
1027 JaguarWriteWord(offset+2, data & 0xFFFF, who);
1031 // Jaguar console initialization
1033 void jaguar_init(void)
1035 #ifdef CPU_DEBUG_MEMORY
1036 memset(readMem, 0x00, 0x400000);
1037 memset(writeMemMin, 0xFF, 0x400000);
1038 memset(writeMemMax, 0x00, 0x400000);
1040 memory_malloc_secure((void **)&jaguar_mainRam, 0x400000, "Jaguar 68K CPU RAM");
1041 memory_malloc_secure((void **)&jaguar_mainRom, 0x600000, "Jaguar 68K CPU ROM");
1042 memory_malloc_secure((void **)&jaguar_bootRom, 0x040000, "Jaguar 68K CPU BIOS ROM"); // Only uses half of this!
1043 memory_malloc_secure((void **)&jaguar_CDBootROM, 0x040000, "Jaguar 68K CPU CD BIOS ROM");
1044 memset(jaguar_mainRam, 0x00, 0x400000);
1045 // memset(jaguar_mainRom, 0xFF, 0x200000); // & set it to all Fs...
1046 // memset(jaguar_mainRom, 0x00, 0x200000); // & set it to all 0s...
1047 //NOTE: This *doesn't* fix FlipOut...
1048 //Or does it? Hmm...
1049 //Seems to want $01010101... Dunno why. Investigate!
1050 memset(jaguar_mainRom, 0x01, 0x600000); // & set it to all 01s...
1051 // memset(jaguar_mainRom, 0xFF, 0x600000); // & set it to all Fs...
1053 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
1061 //New timer based code stuffola...
1062 void ScanlineCallback(void);
1063 void RenderCallback(void);
1064 extern uint32 * backbuffer;
1065 void jaguar_reset(void)
1067 //NOTE: This causes a (virtual) crash if this is set in the config but not found... !!! FIX !!!
1068 if (vjs.useJaguarBIOS)
1069 memcpy(jaguar_mainRam, jaguar_bootRom, 8);
1071 SET32(jaguar_mainRam, 4, jaguarRunAddress);
1073 // WriteLog("jaguar_reset():\n");
1079 m68k_pulse_reset(); // Reset the 68000
1080 WriteLog("Jaguar: 68K reset. PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7));
1082 // New timer base code stuffola...
1083 InitializeEventList();
1084 TOMResetBackbuffer(backbuffer);
1085 // SetCallbackTime(ScanlineCallback, 63.5555);
1086 SetCallbackTime(ScanlineCallback, 31.77775);
1087 // SetCallbackTime(RenderCallback, 33303.082); // # Scanlines * scanline time
1088 // SetCallbackTime(RenderCallback, 16651.541); // # Scanlines * scanline time
1091 void jaguar_done(void)
1093 #ifdef CPU_DEBUG_MEMORY
1094 /* WriteLog("\nJaguar: Memory Usage Stats (return addresses)\n\n");
1096 for(uint32 i=0; i<=raPtr; i++)
1098 WriteLog("\t%08X\n", returnAddr[i]);
1099 WriteLog("M68000 disassembly at $%08X...\n", returnAddr[i] - 16);
1100 jaguar_dasm(returnAddr[i] - 16, 16);
1105 /* int start = 0, end = 0;
1106 bool endTriggered = false, startTriggered = false;
1107 for(int i=0; i<0x400000; i++)
1109 if (readMem[i] && writeMemMin[i] != 0xFF && writeMemMax != 0x00)
1111 if (!startTriggered)
1112 startTriggered = true, endTriggered = false, start = i;
1114 WriteLog("\t\tMin/Max @ %06X: %u/%u\n", i, writeMemMin[i], writeMemMax[i]);
1120 end = i - 1, endTriggered = true, startTriggered = false;
1121 WriteLog("\tMemory range accessed: %06X - %06X\n", start, end);
1128 // for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
1129 // WriteLog("\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
1130 int32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
1131 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
1132 for(int i=-2; i<9; i++)
1133 WriteLog("%06X: %08X\n", topOfStack + (i * 4), JaguarReadLong(topOfStack + (i * 4)));
1135 /* WriteLog("\nM68000 disassembly at $802288...\n");
1136 jaguar_dasm(0x802288, 3);
1137 WriteLog("\nM68000 disassembly at $802200...\n");
1138 jaguar_dasm(0x802200, 500);
1139 WriteLog("\nM68000 disassembly at $802518...\n");
1140 jaguar_dasm(0x802518, 100);//*/
1142 /* WriteLog("\n\nM68000 disassembly at $803F00 (look @ $803F2A)...\n");
1143 jaguar_dasm(0x803F00, 500);
1146 /* WriteLog("\n\nM68000 disassembly at $802B00 (look @ $802B5E)...\n");
1147 jaguar_dasm(0x802B00, 500);
1150 /* WriteLog("\n\nM68000 disassembly at $809900 (look @ $8099F8)...\n");
1151 jaguar_dasm(0x809900, 500);
1154 /* WriteLog("\n\nDump of $8093C8:\n\n");
1155 for(int i=0x8093C8; i<0x809900; i+=4)
1156 WriteLog("%06X: %08X\n", i, JaguarReadLong(i));//*/
1157 /* WriteLog("\n\nM68000 disassembly at $90006C...\n");
1158 jaguar_dasm(0x90006C, 500);
1160 /* WriteLog("\n\nM68000 disassembly at $1AC000...\n");
1161 jaguar_dasm(0x1AC000, 6000);
1164 // WriteLog("Jaguar: CD BIOS version %04X\n", JaguarReadWord(0x3004));
1165 WriteLog("Jaguar: Interrupt enable = %02X\n", TOMReadByte(0xF000E1) & 0x1F);
1166 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
1167 M68K_show_context();
1176 memory_free(jaguar_mainRom);
1177 memory_free(jaguar_mainRam);
1178 memory_free(jaguar_bootRom);
1179 memory_free(jaguar_CDBootROM);
1183 // Main Jaguar execution loop (1 frame)
1185 void JaguarExecute(uint32 * backbuffer, bool render)
1187 uint16 vp = TOMReadWord(0xF0003E) + 1;
1188 uint16 vi = TOMReadWord(0xF0004E);
1189 //Using WO registers is OK, since we're the ones controlling access--there's nothing wrong here! ;-)
1190 //Though we shouldn't be able to do it using TOMReadWord... !!! FIX !!!
1192 // uint16 vdb = TOMReadWord(0xF00046);
1193 //Note: This is the *definite* end of the display, though VDE *might* be less than this...
1194 // uint16 vbb = TOMReadWord(0xF00040);
1195 //It seems that they mean it when they say that VDE is the end of object processing.
1196 //However, we need to be able to tell the OP (or TOM) that we've reached the end of the
1197 //buffer and not to write any more pixels... !!! FIX !!!
1198 // uint16 vde = TOMReadWord(0xF00048);
1200 uint16 refreshRate = (vjs.hardwareTypeNTSC ? 60 : 50);
1201 //Not sure the above is correct, since the number of lines and timings given in the JTRM
1202 //seem to indicate the refresh rate is *half* the above...
1203 // uint16 refreshRate = (vjs.hardwareTypeNTSC ? 30 : 25);
1204 // Should these be hardwired or read from VP? Yes, from VP!
1205 uint32 M68KCyclesPerScanline
1206 = (vjs.hardwareTypeNTSC ? M68K_CLOCK_RATE_NTSC : M68K_CLOCK_RATE_PAL) / (vp * refreshRate);
1207 uint32 RISCCyclesPerScanline
1208 = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL) / (vp * refreshRate);
1210 TOMResetBackbuffer(backbuffer);
1211 /*extern int effect_start;
1213 WriteLog("JagExe: VP=%u, VI=%u, CPU CPS=%u, GPU CPS=%u\n", vp, vi, M68KCyclesPerScanline, RISCCyclesPerScanline);//*/
1215 //extern int start_logging;
1216 for(uint16 i=0; i<vp; i++)
1218 // Increment the horizontal count (why? RNG? Besides which, this is *NOT* cycle accurate!)
1219 TOMWriteWord(0xF00004, (TOMReadWord(0xF00004) + 1) & 0x7FF);
1221 TOMWriteWord(0xF00006, i); // Write the VC
1223 // if (i == vi) // Time for Vertical Interrupt?
1224 //Not sure if this is correct...
1225 //Seems to be, kinda. According to the JTRM, this should only fire on odd lines in non-interlace mode...
1226 //Which means that it normally wouldn't go when it's zero.
1227 if (i == vi && i > 0 && tom_irq_enabled(IRQ_VBLANK)) // Time for Vertical Interrupt?
1229 // We don't have to worry about autovectors & whatnot because the Jaguar
1230 // tells you through its HW registers who sent the interrupt...
1231 tom_set_pending_video_int();
1235 //if (start_logging)
1236 // WriteLog("About to execute M68K (%u)...\n", i);
1237 m68k_execute(M68KCyclesPerScanline);
1238 //if (start_logging)
1239 // WriteLog("About to execute TOM's PIT (%u)...\n", i);
1240 TOMExecPIT(RISCCyclesPerScanline);
1241 //if (start_logging)
1242 // WriteLog("About to execute JERRY's PIT (%u)...\n", i);
1243 JERRYExecPIT(RISCCyclesPerScanline);
1244 //if (start_logging)
1245 // WriteLog("About to execute JERRY's SSI (%u)...\n", i);
1246 jerry_i2s_exec(RISCCyclesPerScanline);
1247 BUTCHExec(RISCCyclesPerScanline);
1248 //if (start_logging)
1249 // WriteLog("About to execute GPU (%u)...\n", i);
1250 gpu_exec(RISCCyclesPerScanline);
1254 if (vjs.usePipelinedDSP)
1255 DSPExecP2(RISCCyclesPerScanline); // Pipelined DSP execution (3 stage)...
1257 DSPExec(RISCCyclesPerScanline); // Ordinary non-pipelined DSP
1258 // DSPExecComp(RISCCyclesPerScanline); // Comparison core
1261 //if (start_logging)
1262 // WriteLog("About to execute OP (%u)...\n", i);
1263 TOMExecScanline(i, render);
1267 // Temp debugging stuff
1269 void DumpMainMemory(void)
1271 FILE * fp = fopen("./memdump.bin", "wb");
1276 fwrite(jaguar_mainRam, 1, 0x400000, fp);
1280 uint8 * GetRamPtr(void)
1282 return jaguar_mainRam;
1286 // New Jaguar execution stack
1291 void JaguarExecuteNew(void)
1293 extern bool finished, showGUI;
1294 extern bool debounceRunKey;
1295 // Pass a message to the "joystick" code to debounce the ESC key...
1296 debounceRunKey = true;
1298 /* InitializeEventList();
1299 TOMResetBackbuffer(backbuffer);
1300 // SetCallbackTime(ScanlineCallback, 63.5555);
1301 SetCallbackTime(ScanlineCallback, 31.77775);
1302 // SetCallbackTime(RenderCallback, 33303.082); // # Scanlines * scanline time
1303 // SetCallbackTime(RenderCallback, 16651.541); // # Scanlines * scanline time//*/
1304 // uint8 * keystate = SDL_GetKeyState(NULL);
1308 double timeToNextEvent = GetTimeToNextEvent();
1309 //WriteLog("JEN: Time to next event (%u) is %f usec (%u RISC cycles)...\n", nextEvent, timeToNextEvent, USEC_TO_RISC_CYCLES(timeToNextEvent));
1311 m68k_execute(USEC_TO_M68K_CYCLES(timeToNextEvent));
1312 gpu_exec(USEC_TO_RISC_CYCLES(timeToNextEvent));
1316 if (vjs.usePipelinedDSP)
1317 DSPExecP2(USEC_TO_RISC_CYCLES(timeToNextEvent)); // Pipelined DSP execution (3 stage)...
1319 DSPExec(USEC_TO_RISC_CYCLES(timeToNextEvent)); // Ordinary non-pipelined DSP
1324 // if (keystate[SDLK_ESCAPE])
1327 // SDL_PumpEvents(); // Needed to keep the keystate current...
1332 void ScanlineCallback(void)
1334 uint16 vc = TOMReadWord(0xF00006);
1335 uint16 vp = TOMReadWord(0xF0003E) + 1;
1336 uint16 vi = TOMReadWord(0xF0004E);
1337 // uint16 vbb = TOMReadWord(0xF00040);
1343 //WriteLog("SLC: Currently on line %u (VP=%u)...\n", vc, vp);
1344 TOMWriteWord(0xF00006, vc);
1346 //This is a crappy kludge, but maybe it'll work for now...
1347 //Maybe it's not so bad, since the IRQ happens on a scanline boundary...
1348 if (vc == vi && vc > 0 && tom_irq_enabled(IRQ_VBLANK)) // Time for Vertical Interrupt?
1350 // We don't have to worry about autovectors & whatnot because the Jaguar
1351 // tells you through its HW registers who sent the interrupt...
1352 tom_set_pending_video_int();
1356 TOMExecScanline(vc, true);
1358 //Change this to VBB???
1359 //Doesn't seem to matter (at least for Flip Out & I-War)
1366 TOMResetBackbuffer(backbuffer);
1370 // TOMResetBackbuffer(backbuffer);
1372 // SetCallbackTime(ScanlineCallback, 63.5555);
1373 SetCallbackTime(ScanlineCallback, 31.77775);
1379 void JaguarExecuteNew(void)
1381 // extern bool finished, showGUI;
1382 // extern bool debounceRunKey;
1383 // Pass a message to the "joystick" code to debounce the ESC key...
1384 // debounceRunKey = true;
1385 // finished = false;
1386 /* InitializeEventList();
1387 TOMResetBackbuffer(backbuffer);
1388 // SetCallbackTime(ScanlineCallback, 63.5555);
1389 SetCallbackTime(ScanlineCallback, 31.77775);
1390 // SetCallbackTime(RenderCallback, 33303.082); // # Scanlines * scanline time
1391 // SetCallbackTime(RenderCallback, 16651.541); // # Scanlines * scanline time//*/
1392 // uint8 * keystate = SDL_GetKeyState(NULL);
1397 double timeToNextEvent = GetTimeToNextEvent();
1398 //WriteLog("JEN: Time to next event (%u) is %f usec (%u RISC cycles)...\n", nextEvent, timeToNextEvent, USEC_TO_RISC_CYCLES(timeToNextEvent));
1400 m68k_execute(USEC_TO_M68K_CYCLES(timeToNextEvent));
1401 gpu_exec(USEC_TO_RISC_CYCLES(timeToNextEvent));
1405 if (vjs.usePipelinedDSP)
1406 DSPExecP2(USEC_TO_RISC_CYCLES(timeToNextEvent)); // Pipelined DSP execution (3 stage)...
1408 DSPExec(USEC_TO_RISC_CYCLES(timeToNextEvent)); // Ordinary non-pipelined DSP
1413 // if (keystate[SDLK_ESCAPE])
1416 // SDL_PumpEvents(); // Needed to keep the keystate current...
1421 void ScanlineCallback(void)
1423 uint16 vc = TOMReadWord(0xF00006);
1424 uint16 vp = TOMReadWord(0xF0003E) + 1;
1425 uint16 vi = TOMReadWord(0xF0004E);
1426 // uint16 vbb = TOMReadWord(0xF00040);
1432 //WriteLog("SLC: Currently on line %u (VP=%u)...\n", vc, vp);
1433 TOMWriteWord(0xF00006, vc);
1435 //This is a crappy kludge, but maybe it'll work for now...
1436 //Maybe it's not so bad, since the IRQ happens on a scanline boundary...
1437 if (vc == vi && vc > 0 && tom_irq_enabled(IRQ_VBLANK)) // Time for Vertical Interrupt?
1439 // We don't have to worry about autovectors & whatnot because the Jaguar
1440 // tells you through its HW registers who sent the interrupt...
1441 tom_set_pending_video_int();
1445 TOMExecScanline(vc, true);
1447 //Change this to VBB???
1448 //Doesn't seem to matter (at least for Flip Out & I-War)
1454 TOMResetBackbuffer(backbuffer);
1459 // TOMResetBackbuffer(backbuffer);
1461 // SetCallbackTime(ScanlineCallback, 63.5555);
1462 SetCallbackTime(ScanlineCallback, 31.77775);
1467 // This isn't currently used, but maybe it should be...
1468 void RenderCallback(void)
1471 TOMResetBackbuffer(backbuffer);
1472 // SetCallbackTime(RenderCallback, 33303.082); // # Scanlines * scanline time
1473 SetCallbackTime(RenderCallback, 16651.541); // # Scanlines * scanline time