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. :-)
14 //#include "m68kdasmAG.h"
17 //Do this in makefile??? Yes! Could, but it's easier to define here...
18 //#define LOG_UNMAPPED_MEMORY_ACCESSES
19 //#define ABORT_ON_UNMAPPED_MEMORY_ACCESS
20 #define ABORT_ON_ILLEGAL_INSTRUCTIONS
21 //#define ABORT_ON_OFFICIAL_ILLEGAL_INSTRUCTION
22 #define CPU_DEBUG_MEMORY
24 // Private function prototypes
26 unsigned jaguar_unknown_readbyte(unsigned address, uint32 who = UNKNOWN);
27 unsigned jaguar_unknown_readword(unsigned address, uint32 who = UNKNOWN);
28 void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who = UNKNOWN);
29 void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who = UNKNOWN);
30 void M68K_show_context(void);
34 //extern bool hardwareTypeNTSC; // Set to false for PAL
35 #ifdef CPU_DEBUG_MEMORY
36 extern bool startMemLog; // Set by "e" key
37 extern int effect_start;
38 extern int effect_start2, effect_start3, effect_start4, effect_start5, effect_start6;
41 // Memory debugging identifiers
44 { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" };
46 uint32 jaguar_active_memory_dumps = 0;
48 uint32 jaguar_mainRom_crc32, jaguarRomSize, jaguarRunAddress;
50 /*static*/ uint8 * jaguar_mainRam = NULL;
51 /*static*/ uint8 * jaguar_mainRom = NULL;
52 /*static*/ uint8 * jaguar_bootRom = NULL;
53 /*static*/ uint8 * jaguar_CDBootROM = NULL;
55 #ifdef CPU_DEBUG_MEMORY
56 uint8 writeMemMax[0x400000], writeMemMin[0x400000];
57 uint8 readMem[0x400000];
58 uint32 returnAddr[4000], raPtr = 0xFFFFFFFF;
61 uint32 pcQueue[0x400];
65 // Callback function to detect illegal instructions
67 void GPUDumpDisassembly(void);
68 void GPUDumpRegisters(void);
69 static bool start = false;
70 void M68KInstructionHook(void)
72 uint32 m68kPC = m68k_get_reg(NULL, M68K_REG_PC);
75 // Ideally, we'd save all the registers as well...
76 pcQueue[pcQPtr++] = m68kPC;
79 if (m68kPC & 0x01) // Oops! We're fetching an odd address!
81 WriteLog("M68K: Attempted to execute from an odd adress!\n\nBacktrace:\n\n");
83 static char buffer[2048];
84 for(int i=0; i<0x400; i++)
86 m68k_disassemble(buffer, pcQueue[(pcQPtr + i) & 0x3FF], M68K_CPU_TYPE_68000);
87 WriteLog("\t%08X: %s\n", pcQueue[(pcQPtr + i) & 0x3FF], buffer);
91 uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
92 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
93 for(int i=0; i<10; i++)
94 WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4)));
95 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
101 /* if (m68kPC >= 0x807EC4 && m68kPC <= 0x807EDB)
103 static char buffer[2048];
104 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
105 WriteLog("%08X: %s", m68kPC, buffer);
106 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X, D1=%08X\n",
107 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
108 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1));
110 /* if (m68kPC == 0x8D0E48 && effect_start5)
112 WriteLog("\nM68K: At collision detection code. Exiting!\n\n");
114 GPUDumpDisassembly();
118 /* uint16 opcode = JaguarReadWord(m68kPC);
119 if (opcode == 0x4E75) // RTS
122 // WriteLog("Jaguar: Returning from subroutine to %08X\n", JaguarReadLong(m68k_get_reg(NULL, M68K_REG_A7)));
124 uint32 addr = JaguarReadLong(m68k_get_reg(NULL, M68K_REG_A7));
126 if (raPtr != 0xFFFFFFFF)
128 for(uint32 i=0; i<=raPtr; i++)
130 if (returnAddr[i] == addr)
139 returnAddr[++raPtr] = addr;
143 //Flip Out! debugging...
146 00805FDC: movea.l #$9c6f8, A0 D0=00100010, A0=00100000
147 00805FE2: move.w #$10, (A0)+ D0=00100010, A0=0009C6F8
148 00805FE6: cmpa.l #$c96f8, A0 D0=00100010, A0=0009C6FA
149 00805FEC: bne 805fe2 D0=00100010, A0=0009C6FA
151 0080603A: move.l #$11ed7c, $100.w D0=61700080, A0=000C96F8, D1=00000000, A1=000040D8
153 0012314C: move.l (A0)+, (A1)+ D0=61700080, A0=00124174, D1=00000000, A1=00F03FFC
154 0012314E: cmpa.l #$f04000, A1 D0=61700080, A0=00124178, D1=00000000, A1=00F04000
155 00123154: blt 12314c D0=61700080, A0=00124178, D1=00000000, A1=00F04000
156 00123156: move.l #$0, $f035d0.l D0=61700080, A0=00124178, D1=00000000, A1=00F04000
157 00123160: move.l #$f03000, $f02110.l D0=61700080, A0=00124178, D1=00000000, A1=00F04000
158 0012316A: move.l #$1, $f02114.l D0=61700080, A0=00124178, D1=00000000, A1=00F04000
159 00123174: rts D0=61700080, A0=00124178, D1=00000000, A1=00F04000
161 /* static char buffer[2048];
162 //if (m68kPC > 0x805F48) start = true;
163 //if (m68kPC > 0x806486) start = true;
164 //if (m68kPC == 0x805FEE) start = true;
165 //if (m68kPC == 0x80600C)// start = true;
166 if (m68kPC == 0x802058) start = true;
168 // GPUDumpRegisters();
169 // GPUDumpDisassembly();
171 // M68K_show_context();
177 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
178 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));
181 /* if (m68kPC == 0x803F16)
183 WriteLog("M68K: Registers found at $803F16:\n");
184 WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
185 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
186 WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
188 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
189 WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
191 //Looks like the DSP is supposed to return $12345678 when it finishes its validation routine...
192 // !!! Investigate !!!
193 /*extern bool doDSPDis;
194 static bool disgo = false;
195 if (m68kPC == 0x50222)
198 // WriteLog("M68K: About to stuff $12345678 into $F1B000 (=%08X)...\n", DSPReadLong(0xF1B000, M68K));
199 // DSPWriteLong(0xF1B000, 0x12345678, M68K);
202 if (m68kPC == 0x5000)
207 static char buffer[2048];
208 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
209 WriteLog("%08X: %s", m68kPC, buffer);
210 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X, D1=%08X, D2=%08X\n",
211 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
212 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
214 if (m68kPC == 0x82E1A)
216 static char buffer[2048];
217 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
218 WriteLog("--> [Routine start] %08X: %s", m68kPC, buffer);
219 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X(cmd), D1=%08X(# bytes), D2=%08X\n",
220 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
221 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
223 if (m68kPC == 0x82E58)
224 WriteLog("--> [Routine end]\n");
225 if (m68kPC == 0x80004)
227 WriteLog("--> [Calling BusWrite2] D2: %08X\n", m68k_get_reg(NULL, M68K_REG_D2));
228 // m68k_set_reg(M68K_REG_D2, 0x12345678);
252 if (m68kPC == 0x3000)
253 WriteLog("M68K: CD_init\n");
254 else if (m68kPC == 0x3006 + (6 * 0))
255 WriteLog("M68K: CD_mode\n");
256 else if (m68kPC == 0x3006 + (6 * 1))
257 WriteLog("M68K: CD_ack\n");
258 else if (m68kPC == 0x3006 + (6 * 2))
259 WriteLog("M68K: CD_jeri\n");
260 else if (m68kPC == 0x3006 + (6 * 3))
261 WriteLog("M68K: CD_spin\n");
262 else if (m68kPC == 0x3006 + (6 * 4))
263 WriteLog("M68K: CD_stop\n");
264 else if (m68kPC == 0x3006 + (6 * 5))
265 WriteLog("M68K: CD_mute\n");
266 else if (m68kPC == 0x3006 + (6 * 6))
267 WriteLog("M68K: CD_umute\n");
268 else if (m68kPC == 0x3006 + (6 * 7))
269 WriteLog("M68K: CD_paus\n");
270 else if (m68kPC == 0x3006 + (6 * 8))
271 WriteLog("M68K: CD_upaus\n");
272 else if (m68kPC == 0x3006 + (6 * 9))
273 WriteLog("M68K: CD_read\n");
274 else if (m68kPC == 0x3006 + (6 * 10))
275 WriteLog("M68K: CD_uread\n");
276 else if (m68kPC == 0x3006 + (6 * 11))
277 WriteLog("M68K: CD_setup\n");
278 else if (m68kPC == 0x3006 + (6 * 12))
279 WriteLog("M68K: CD_ptr\n");
280 else if (m68kPC == 0x3006 + (6 * 13))
281 WriteLog("M68K: CD_osamp\n");
282 else if (m68kPC == 0x3006 + (6 * 14))
283 WriteLog("M68K: CD_getoc\n");
284 else if (m68kPC == 0x3006 + (6 * 15))
285 WriteLog("M68K: CD_initm\n");
286 else if (m68kPC == 0x3006 + (6 * 16))
287 WriteLog("M68K: CD_initf\n");
288 else if (m68kPC == 0x3006 + (6 * 17))
289 WriteLog("M68K: CD_switch\n");
291 if (m68kPC >= 0x3000 && m68kPC <= 0x306C)
292 WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X, D1=%08X, D2=%08X\n",
293 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
294 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
296 #ifdef ABORT_ON_ILLEGAL_INSTRUCTIONS
297 if (!m68k_is_valid_instruction(m68k_read_memory_16(m68kPC), M68K_CPU_TYPE_68000))
299 #ifndef ABORT_ON_OFFICIAL_ILLEGAL_INSTRUCTION
300 if (m68k_read_memory_16(m68kPC) == 0x4AFC)
302 // This is a kludge to let homebrew programs work properly (i.e., let the other processors
303 // keep going even when the 68K dumped back to the debugger or what have you).
305 // m68k_set_reg(M68K_REG_PC, m68kPC - 2);
306 // Try setting the vector to the illegal instruction...
307 //This doesn't work right either! Do something else! Quick!
308 // SET32(jaguar_mainRam, 0x10, m68kPC);
314 WriteLog("\nM68K encountered an illegal instruction at %08X!!!\n\nAborting!\n", m68kPC);
315 uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
316 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
317 for(int i=0; i<10; i++)
318 WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4)));
319 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
323 // WriteLog("\n\n68K disasm\n\n");
324 // jaguar_dasm(0x802000, 0x50C);
335 // Musashi 68000 read/write/IRQ functions
338 int irq_ack_handler(int level)
340 int vector = M68K_INT_ACK_AUTOVECTOR;
342 // The GPU/DSP/etc are probably *not* issuing an NMI, but it seems to work OK...
346 m68k_set_irq(0); // Clear the IRQ...
347 vector = 64; // Set user interrupt #0
353 unsigned int m68k_read_memory_8(unsigned int address)
355 #ifdef CPU_DEBUG_MEMORY
356 if ((address >= 0x000000) && (address <= 0x3FFFFF))
359 readMem[address] = 1;
362 //WriteLog("[RM8] Addr: %08X\n", address);
363 //; So, it seems that it stores the returned DWORD at $51136 and $FB074.
364 /* if (address == 0x51136 || address == 0x51138 || address == 0xFB074 || address == 0xFB076
365 || address == 0x1AF05E)
366 WriteLog("[RM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, jaguar_mainRam[address]);//*/
367 unsigned int retVal = 0;
369 if ((address >= 0x000000) && (address <= 0x3FFFFF))
370 retVal = jaguar_mainRam[address];
371 // else if ((address >= 0x800000) && (address <= 0xDFFFFF))
372 else if ((address >= 0x800000) && (address <= 0xDFFEFF))
373 retVal = jaguar_mainRom[address - 0x800000];
374 else if ((address >= 0xE00000) && (address <= 0xE3FFFF))
375 retVal = jaguar_bootRom[address - 0xE00000];
376 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
377 retVal = CDROMReadByte(address);
378 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
379 retVal = TOMReadByte(address, M68K);
380 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
381 retVal = JERRYReadByte(address, M68K);
383 retVal = jaguar_unknown_readbyte(address, M68K);
385 //if (address >= 0x2800 && address <= 0x281F)
386 // WriteLog("M68K: Read byte $%02X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
387 //if (address >= 0x8B5E4 && address <= 0x8B5E4 + 16)
388 // WriteLog("M68K: Read byte $%02X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
392 void gpu_dump_disassembly(void);
393 void gpu_dump_registers(void);
395 unsigned int m68k_read_memory_16(unsigned int address)
397 #ifdef CPU_DEBUG_MEMORY
398 /* if ((address >= 0x000000) && (address <= 0x3FFFFE))
401 readMem[address] = 1, readMem[address + 1] = 1;
403 /* if (effect_start && (address >= 0x8064FC && address <= 0x806501))
405 return 0x4E71; // NOP
407 if (effect_start2 && (address >= 0x806502 && address <= 0x806507))
409 return 0x4E71; // NOP
411 if (effect_start3 && (address >= 0x806512 && address <= 0x806517))
413 return 0x4E71; // NOP
415 if (effect_start4 && (address >= 0x806524 && address <= 0x806527))
417 return 0x4E71; // NOP
419 if (effect_start5 && (address >= 0x80653E && address <= 0x806543)) //Collision detection!
421 return 0x4E71; // NOP
423 if (effect_start6 && (address >= 0x806544 && address <= 0x806547))
425 return 0x4E71; // NOP
428 //WriteLog("[RM16] Addr: %08X\n", address);
429 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005FBA)
430 // for(int i=0; i<10000; i++)
431 WriteLog("[M68K] In routine #6!\n");//*/
432 //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00006696) // GPU Program #4
433 //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005B3C) // GPU Program #2
434 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005BA8) // GPU Program #3
436 WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address));
437 gpu_dump_registers();
438 gpu_dump_disassembly();
439 // for(int i=0; i<10000; i++)
440 // WriteLog("[M68K] About to run GPU!\n");
442 //WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
443 /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x00006696 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x000066A8)
445 if (address == 0x000066A0)
447 gpu_dump_registers();
448 gpu_dump_disassembly();
450 for(int i=0; i<10000; i++)
451 WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address));
453 //; So, it seems that it stores the returned DWORD at $51136 and $FB074.
454 /* if (address == 0x51136 || address == 0x51138 || address == 0xFB074 || address == 0xFB076
455 || address == 0x1AF05E)
456 WriteLog("[RM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, GET16(jaguar_mainRam, address));//*/
457 unsigned int retVal = 0;
459 if ((address >= 0x000000) && (address <= 0x3FFFFE))
460 // retVal = (jaguar_mainRam[address] << 8) | jaguar_mainRam[address+1];
461 retVal = GET16(jaguar_mainRam, address);
462 // else if ((address >= 0x800000) && (address <= 0xDFFFFE))
463 else if ((address >= 0x800000) && (address <= 0xDFFEFE))
464 retVal = (jaguar_mainRom[address - 0x800000] << 8) | jaguar_mainRom[address - 0x800000 + 1];
465 else if ((address >= 0xE00000) && (address <= 0xE3FFFE))
466 retVal = (jaguar_bootRom[address - 0xE00000] << 8) | jaguar_bootRom[address - 0xE00000 + 1];
467 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
468 retVal = CDROMReadWord(address, M68K);
469 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
470 retVal = TOMReadWord(address, M68K);
471 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
472 retVal = JERRYReadWord(address, M68K);
474 retVal = jaguar_unknown_readword(address, M68K);
476 //if (address >= 0xF1B000 && address <= 0xF1CFFF)
477 // WriteLog("M68K: Read word $%04X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
478 //if (address >= 0x2800 && address <= 0x281F)
479 // WriteLog("M68K: Read word $%04X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
480 //$8B3AE -> Transferred from $F1C010
481 //$8B5E4 -> Only +1 read at $808AA
482 //if (address >= 0x8B5E4 && address <= 0x8B5E4 + 16)
483 // WriteLog("M68K: Read word $%04X at $%08X [PC=%08X]\n", retVal, address, m68k_get_reg(NULL, M68K_REG_PC));
487 unsigned int m68k_read_memory_32(unsigned int address)
489 //; So, it seems that it stores the returned DWORD at $51136 and $FB074.
490 /* if (address == 0x51136 || address == 0xFB074 || address == 0x1AF05E)
491 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));//*/
493 //WriteLog("--> [RM32]\n");
494 return (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2);
497 void m68k_write_memory_8(unsigned int address, unsigned int value)
499 #ifdef CPU_DEBUG_MEMORY
500 if ((address >= 0x000000) && (address <= 0x3FFFFF))
504 if (value > writeMemMax[address])
505 writeMemMax[address] = value;
506 if (value < writeMemMin[address])
507 writeMemMin[address] = value;
511 //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F))
512 // WriteLog("M68K: Writing %02X at %08X\n", value, address);
513 //WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
515 if (address >= 0x18FA70 && address < (0x18FA70 + 8000))
516 WriteLog("M68K: Byte %02X written at %08X by 68K\n", value, address);//*/
518 if ((address >= 0x000000) && (address <= 0x3FFFFF))
519 jaguar_mainRam[address] = value;
520 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
521 CDROMWriteByte(address, value, M68K);
522 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
523 TOMWriteByte(address, value, M68K);
524 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
525 JERRYWriteByte(address, value, M68K);
527 jaguar_unknown_writebyte(address, value, M68K);
530 void m68k_write_memory_16(unsigned int address, unsigned int value)
532 #ifdef CPU_DEBUG_MEMORY
533 if ((address >= 0x000000) && (address <= 0x3FFFFE))
537 uint8 hi = value >> 8, lo = value & 0xFF;
539 if (hi > writeMemMax[address])
540 writeMemMax[address] = hi;
541 if (hi < writeMemMin[address])
542 writeMemMin[address] = hi;
544 if (lo > writeMemMax[address+1])
545 writeMemMax[address+1] = lo;
546 if (lo < writeMemMin[address+1])
547 writeMemMin[address+1] = lo;
551 //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F))
552 // WriteLog("M68K: Writing %04X at %08X\n", value, address);
553 //WriteLog("[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
554 //if (address >= 0xF02200 && address <= 0xF0229F)
555 // WriteLog("M68K: Writing to blitter --> %04X at %08X\n", value, address);
556 //if (address >= 0x0E75D0 && address <= 0x0E75E7)
557 // WriteLog("M68K: Writing %04X at %08X, M68K PC=%08X\n", value, address, m68k_get_reg(NULL, M68K_REG_PC));
558 /*extern uint32 totalFrames;
559 if (address == 0xF02114)
560 WriteLog("M68K: Writing to GPU_CTRL (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));
561 if (address == 0xF02110)
562 WriteLog("M68K: Writing to GPU_PC (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));//*/
563 //if (address >= 0xF03B00 && address <= 0xF03DFF)
564 // WriteLog("M68K: Writing %04X to %08X...\n", value, address);
566 /*if (address == 0x0100)//64*4)
567 WriteLog("M68K: Wrote word to VI vector value %04X...\n", value);//*/
569 if (address >= 0x18FA70 && address < (0x18FA70 + 8000))
570 WriteLog("M68K: Word %04X written at %08X by 68K\n", value, address);//*/
571 /* if (address == 0x51136 || address == 0x51138 || address == 0xFB074 || address == 0xFB076
572 || address == 0x1AF05E)
573 WriteLog("[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);//*/
575 if ((address >= 0x000000) && (address <= 0x3FFFFE))
577 /* jaguar_mainRam[address] = value >> 8;
578 jaguar_mainRam[address + 1] = value & 0xFF;*/
579 SET16(jaguar_mainRam, address, value);
581 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
582 CDROMWriteWord(address, value, M68K);
583 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
584 TOMWriteWord(address, value, M68K);
585 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
586 JERRYWriteWord(address, value, M68K);
589 jaguar_unknown_writeword(address, value, M68K);
590 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
591 WriteLog("\tA0=%08X, A1=%08X, D0=%08X, D1=%08X\n",
592 m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
593 m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1));
598 void m68k_write_memory_32(unsigned int address, unsigned int value)
600 //WriteLog("--> [WM32]\n");
601 /*if (address == 0x0100)//64*4)
602 WriteLog("M68K: Wrote dword to VI vector value %08X...\n", value);//*/
603 /*if (address >= 0xF03214 && address < 0xF0321F)
604 WriteLog("M68K: Writing DWORD (%08X) to GPU RAM (%08X)...\n", value, address);//*/
605 //M68K: Writing DWORD (88E30047) to GPU RAM (00F03214)...
606 /*extern bool doGPUDis;
607 if (address == 0xF03214 && value == 0x88E30047)
610 /* if (address == 0x51136 || address == 0xFB074)
611 WriteLog("[WM32 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);//*/
613 m68k_write_memory_16(address, value >> 16);
614 m68k_write_memory_16(address + 2, value & 0xFFFF);
618 uint32 jaguar_get_handler(uint32 i)
620 return JaguarReadLong(i * 4);
623 uint32 jaguar_interrupt_handler_is_valid(uint32 i)
625 uint32 handler = jaguar_get_handler(i);
626 if (handler && (handler != 0xFFFFFFFF))
632 void M68K_show_context(void)
634 WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
635 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
636 WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
638 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
639 WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
641 WriteLog("68K disasm\n");
642 // jaguar_dasm(s68000readPC()-0x1000,0x20000);
643 jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x80, 0x200);
644 // jaguar_dasm(0x5000, 0x14414);
646 // WriteLog("\n.......[Cart start]...........\n\n");
647 // jaguar_dasm(0x192000, 0x1000);//0x200);
649 WriteLog("..................\n");
651 if (tom_irq_enabled(IRQ_VBLANK))
653 WriteLog("vblank int: enabled\n");
654 jaguar_dasm(jaguar_get_handler(64), 0x200);
657 WriteLog("vblank int: disabled\n");
659 WriteLog("..................\n");
661 for(int i=0; i<256; i++)
662 WriteLog("handler %03i at $%08X\n", i, (unsigned int)jaguar_get_handler(i));
666 // Unknown read/write byte/word routines
669 // It's hard to believe that developers would be sloppy with their memory writes, yet in
670 // some cases the developers screwed up royal. E.g., Club Drive has the following code:
672 // 807EC4: movea.l #$f1b000, A1
673 // 807ECA: movea.l #$8129e0, A0
674 // 807ED0: move.l A0, D0
675 // 807ED2: move.l #$f1bb94, D1
676 // 807ED8: sub.l D0, D1
677 // 807EDA: lsr.l #2, D1
678 // 807EDC: move.l (A0)+, (A1)+
679 // 807EDE: dbra D1, 807edc
681 // The problem is at $807ED0--instead of putting A0 into D0, they really meant to put A1
682 // in. This mistake causes it to try and overwrite approximately $700000 worth of address
683 // space! (That is, unless the 68K causes a bus error...)
685 void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/)
687 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
688 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));
690 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
691 extern bool finished;
693 extern bool doDSPDis;
699 void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/)
701 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
702 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));
704 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
705 extern bool finished;
707 extern bool doDSPDis;
713 unsigned jaguar_unknown_readbyte(unsigned address, uint32 who/*=UNKNOWN*/)
715 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
716 WriteLog("Jaguar: Unknown byte read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
718 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
719 extern bool finished;
721 extern bool doDSPDis;
728 unsigned jaguar_unknown_readword(unsigned address, uint32 who/*=UNKNOWN*/)
730 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
731 WriteLog("Jaguar: Unknown word read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
733 #ifdef ABORT_ON_UNMAPPED_MEMORY_ACCESS
734 extern bool finished;
736 extern bool doDSPDis;
744 // Disassemble M68K instructions at the given offset
747 unsigned int m68k_read_disassembler_8(unsigned int address)
749 return m68k_read_memory_8(address);
752 unsigned int m68k_read_disassembler_16(unsigned int address)
754 return m68k_read_memory_16(address);
757 unsigned int m68k_read_disassembler_32(unsigned int address)
759 return m68k_read_memory_32(address);
762 void jaguar_dasm(uint32 offset, uint32 qt)
765 static char buffer[2048];//, mem[64];
766 int pc = offset, oldpc;
768 for(uint32 i=0; i<qt; i++)
771 for(int j=0; j<64; j++)
772 mem[j^0x01] = jaguar_byte_read(pc + j);
774 pc += Dasm68000((char *)mem, buffer, 0);
775 WriteLog("%08X: %s\n", oldpc, buffer);//*/
777 pc += m68k_disassemble(buffer, pc, M68K_CPU_TYPE_68000);
778 WriteLog("%08X: %s\n", oldpc, buffer);//*/
783 uint8 JaguarReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
788 if (offset < 0x400000)
789 data = jaguar_mainRam[offset & 0x3FFFFF];
790 else if ((offset >= 0x800000) && (offset < 0xC00000))
791 data = jaguar_mainRom[offset - 0x800000];
792 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
793 data = CDROMReadByte(offset, who);
794 else if ((offset >= 0xE00000) && (offset < 0xE40000))
795 data = jaguar_bootRom[offset & 0x3FFFF];
796 else if ((offset >= 0xF00000) && (offset < 0xF10000))
797 data = TOMReadByte(offset, who);
798 else if ((offset >= 0xF10000) && (offset < 0xF20000))
799 data = JERRYReadByte(offset, who);
801 data = jaguar_unknown_readbyte(offset, who);
806 uint16 JaguarReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
809 if (offset <= 0x3FFFFE)
811 return (jaguar_mainRam[(offset+0) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+1) & 0x3FFFFF];
813 else if ((offset >= 0x800000) && (offset <= 0xBFFFFE))
816 return (jaguar_mainRom[offset+0] << 8) | jaguar_mainRom[offset+1];
818 // else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00))
819 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE))
820 return CDROMReadWord(offset, who);
821 else if ((offset >= 0xE00000) && (offset <= 0xE3FFFE))
822 return (jaguar_bootRom[(offset+0) & 0x3FFFF] << 8) | jaguar_bootRom[(offset+1) & 0x3FFFF];
823 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE))
824 return TOMReadWord(offset, who);
825 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE))
826 return JERRYReadWord(offset, who);
828 return jaguar_unknown_readword(offset, who);
831 void JaguarWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
833 //Need to check for writes in the range of $18FA70 + 8000...
835 if (offset >= 0x18FA70 && offset < (0x18FA70 + 8000))
836 WriteLog("JWB: Byte %02X written at %08X by %s\n", data, offset, whoName[who]);//*/
839 if (offset < 0x400000)
841 jaguar_mainRam[offset & 0x3FFFFF] = data;
844 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
846 CDROMWriteByte(offset, data, who);
849 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFF))
851 TOMWriteByte(offset, data, who);
854 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFF))
856 JERRYWriteByte(offset, data, who);
860 jaguar_unknown_writebyte(offset, data, who);
864 void JaguarWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
866 /*if (offset == 0x0100)//64*4)
867 WriteLog("M68K: %s wrote word to VI vector value %04X...\n", whoName[who], data);
868 if (offset == 0x0102)//64*4)
869 WriteLog("M68K: %s wrote word to VI vector+2 value %04X...\n", whoName[who], data);//*/
870 //TEMP--Mirror of F03000? Yes, but only 32-bit CPUs can do it (i.e., NOT the 68K!)
871 // PLUS, you would handle this in the GPU/DSP WriteLong code! Not here!
872 //Need to check for writes in the range of $18FA70 + 8000...
874 if (offset >= 0x18FA70 && offset < (0x18FA70 + 8000))
875 WriteLog("JWW: Word %04X written at %08X by %s\n", data, offset, whoName[who]);//*/
876 /*if (offset >= 0x2C00 && offset <= 0x2CFF)
877 WriteLog("Jaguar: Word %04X written to TOC+%02X by %s\n", data, offset-0x2C00, whoName[who]);//*/
881 if (offset <= 0x3FFFFE)
886 1A 69 F0 ($0000) -> Starfield
887 1A 73 C8 ($0001) -> Final clearing blit & bitmap blit?
890 1A 8F E8 ($0004) -> "Jaguar" small color logo?
899 //This MUST be done by the 68K!
900 /*if (offset == 0x670C)
901 WriteLog("Jaguar: %s writing to location $670C...\n", whoName[who]);*/
903 /*extern bool doGPUDis;
904 //if ((offset == 0x100000 + 75522) && who == GPU) // 76,226 -> 75522
905 if ((offset == 0x100000 + 128470) && who == GPU) // 107,167 -> 128470 (384 x 250 screen size 16BPP)
906 //if ((offset >= 0x100000 && offset <= 0x12C087) && who == GPU)
908 /*if (offset == 0x100000 + 128470) // 107,167 -> 128470 (384 x 250 screen size 16BPP)
909 WriteLog("JWW: Writing value %04X at %08X by %s...\n", data, offset, whoName[who]);
910 if ((data & 0xFF00) != 0x7700)
911 WriteLog("JWW: Writing value %04X at %08X by %s...\n", data, offset, whoName[who]);//*/
912 /*if ((offset >= 0x100000 && offset <= 0x147FFF) && who == GPU)
914 /*if ((data & 0xFF00) != 0x7700 && who == GPU)
915 WriteLog("JWW: Writing value %04X at %08X by %s...\n", data, offset, whoName[who]);//*/
916 /*if ((offset >= 0x100000 + 0x48000 && offset <= 0x12C087 + 0x48000) && who == GPU)
918 /*extern bool doGPUDis;
919 if (offset == 0x120216 && who == GPU)
921 /*extern uint32 gpu_pc;
922 if (who == GPU && (gpu_pc == 0xF03604 || gpu_pc == 0xF03638))
924 uint32 base = offset - (offset > 0x148000 ? 0x148000 : 0x100000);
925 uint32 y = base / 0x300;
926 uint32 x = (base - (y * 0x300)) / 2;
927 WriteLog("JWW: Writing starfield star %04X at %08X (%u/%u) [%s]\n", data, offset, x, y, (gpu_pc == 0xF03604 ? "s" : "L"));
930 JWW: Writing starfield star 775E at 0011F650 (555984/1447)
932 //if (offset == (0x001E17F8 + 0x34))
933 /*if (who == GPU && offset == (0x001E17F8 + 0x34))
935 // WriteLog("JWW: Write at %08X written to by %s.\n", 0x001E17F8 + 0x34, whoName[who]);//*/
936 /*extern uint32 gpu_pc;
937 if (who == GPU && (gpu_pc == 0xF03604 || gpu_pc == 0xF03638))
939 extern int objectPtr;
940 // if (offset > 0x148000)
943 if (starCount > objectPtr)
946 // if (starCount == 1)
947 // WriteLog("--> Drawing 1st star...\n");
949 // uint32 base = offset - (offset > 0x148000 ? 0x148000 : 0x100000);
950 // uint32 y = base / 0x300;
951 // uint32 x = (base - (y * 0x300)) / 2;
952 // WriteLog("JWW: Writing starfield star %04X at %08X (%u/%u) [%s]\n", data, offset, x, y, (gpu_pc == 0xF03604 ? "s" : "L"));
954 //A star of interest...
955 //-->JWW: Writing starfield star 77C9 at 0011D31A (269/155) [s]
956 //1st trail +3(x), -1(y) -> 272, 154 -> 0011D020
957 //JWW: Blitter writing echo 77B3 at 0011D022...
959 //extern bool doGPUDis;
960 /*if (offset == 0x11D022 + 0x48000 || offset == 0x11D022)// && who == GPU)
963 WriteLog("JWW: %s writing echo %04X at %08X...\n", whoName[who], data, offset);
966 if (offset == 0x11D31A + 0x48000 || offset == 0x11D31A)
967 WriteLog("JWW: %s writing star %04X at %08X...\n", whoName[who], data, offset);//*/
969 jaguar_mainRam[(offset+0) & 0x3FFFFF] = data >> 8;
970 jaguar_mainRam[(offset+1) & 0x3FFFFF] = data & 0xFF;
973 else if (offset >= 0xDFFF00 && offset <= 0xDFFFFE)
975 CDROMWriteWord(offset, data, who);
978 else if (offset >= 0xF00000 && offset <= 0xF0FFFE)
980 TOMWriteWord(offset, data, who);
983 else if (offset >= 0xF10000 && offset <= 0xF1FFFE)
985 JERRYWriteWord(offset, data, who);
988 // Don't bomb on attempts to write to ROM
989 else if (offset >= 0x800000 && offset <= 0xEFFFFF)
992 jaguar_unknown_writeword(offset, data, who);
995 // We really should re-do this so that it does *real* 32-bit access... !!! FIX !!!
996 uint32 JaguarReadLong(uint32 offset, uint32 who/*=UNKNOWN*/)
998 return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset+2, who);
1001 // We really should re-do this so that it does *real* 32-bit access... !!! FIX !!!
1002 void JaguarWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
1004 /* extern bool doDSPDis;
1005 if (offset < 0x400 && !doDSPDis)
1007 WriteLog("JLW: Write to %08X by %s... Starting DSP log!\n\n", offset, whoName[who]);
1010 /*if (offset == 0x0100)//64*4)
1011 WriteLog("M68K: %s wrote dword to VI vector value %08X...\n", whoName[who], data);//*/
1013 JaguarWriteWord(offset, data >> 16, who);
1014 JaguarWriteWord(offset+2, data & 0xFFFF, who);
1018 // Jaguar console initialization
1020 void jaguar_init(void)
1022 #ifdef CPU_DEBUG_MEMORY
1023 memset(readMem, 0x00, 0x400000);
1024 memset(writeMemMin, 0xFF, 0x400000);
1025 memset(writeMemMax, 0x00, 0x400000);
1027 memory_malloc_secure((void **)&jaguar_mainRam, 0x400000, "Jaguar 68K CPU RAM");
1028 memory_malloc_secure((void **)&jaguar_mainRom, 0x600000, "Jaguar 68K CPU ROM");
1029 memory_malloc_secure((void **)&jaguar_bootRom, 0x040000, "Jaguar 68K CPU BIOS ROM"); // Only uses half of this!
1030 memory_malloc_secure((void **)&jaguar_CDBootROM, 0x040000, "Jaguar 68K CPU CD BIOS ROM");
1031 memset(jaguar_mainRam, 0x00, 0x400000);
1032 // memset(jaguar_mainRom, 0xFF, 0x200000); // & set it to all Fs...
1033 // memset(jaguar_mainRom, 0x00, 0x200000); // & set it to all 0s...
1034 //NOTE: This *doesn't* fix FlipOut...
1035 //Or does it? Hmm...
1036 //Seems to want $01010101... Dunno why. Investigate!
1037 memset(jaguar_mainRom, 0x01, 0x600000); // & set it to all 01s...
1038 // memset(jaguar_mainRom, 0xFF, 0x600000); // & set it to all Fs...
1040 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
1048 void jaguar_reset(void)
1050 if (vjs.useJaguarBIOS)
1051 memcpy(jaguar_mainRam, jaguar_bootRom, 8);
1053 SET32(jaguar_mainRam, 4, jaguarRunAddress);
1055 // WriteLog("jaguar_reset():\n");
1061 m68k_pulse_reset(); // Reset the 68000
1062 WriteLog("Jaguar: 68K reset. PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7));
1065 void jaguar_done(void)
1067 #ifdef CPU_DEBUG_MEMORY
1068 /* WriteLog("\nJaguar: Memory Usage Stats (return addresses)\n\n");
1070 for(uint32 i=0; i<=raPtr; i++)
1072 WriteLog("\t%08X\n", returnAddr[i]);
1073 WriteLog("M68000 disassembly at $%08X...\n", returnAddr[i] - 16);
1074 jaguar_dasm(returnAddr[i] - 16, 16);
1079 /* int start = 0, end = 0;
1080 bool endTriggered = false, startTriggered = false;
1081 for(int i=0; i<0x400000; i++)
1083 if (readMem[i] && writeMemMin[i] != 0xFF && writeMemMax != 0x00)
1085 if (!startTriggered)
1086 startTriggered = true, endTriggered = false, start = i;
1088 WriteLog("\t\tMin/Max @ %06X: %u/%u\n", i, writeMemMin[i], writeMemMax[i]);
1094 end = i - 1, endTriggered = true, startTriggered = false;
1095 WriteLog("\tMemory range accessed: %06X - %06X\n", start, end);
1102 // for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
1103 // WriteLog("\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
1104 int32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
1105 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
1106 for(int i=-2; i<9; i++)
1107 WriteLog("%06X: %08X\n", topOfStack + (i * 4), JaguarReadLong(topOfStack + (i * 4)));
1109 /* WriteLog("\nM68000 disassembly at $802288...\n");
1110 jaguar_dasm(0x802288, 3);
1111 WriteLog("\nM68000 disassembly at $802200...\n");
1112 jaguar_dasm(0x802200, 500);
1113 WriteLog("\nM68000 disassembly at $802518...\n");
1114 jaguar_dasm(0x802518, 100);//*/
1116 /* WriteLog("\n\nM68000 disassembly at $803F00 (look @ $803F2A)...\n");
1117 jaguar_dasm(0x803F00, 500);
1120 /* WriteLog("\n\nM68000 disassembly at $802B00 (look @ $802B5E)...\n");
1121 jaguar_dasm(0x802B00, 500);
1124 /* WriteLog("\n\nM68000 disassembly at $809900 (look @ $8099F8)...\n");
1125 jaguar_dasm(0x809900, 500);
1128 /* WriteLog("\n\nDump of $8093C8:\n\n");
1129 for(int i=0x8093C8; i<0x809900; i+=4)
1130 WriteLog("%06X: %08X\n", i, JaguarReadLong(i));//*/
1131 /* WriteLog("\n\nM68000 disassembly at $90006C...\n");
1132 jaguar_dasm(0x90006C, 500);
1134 /* WriteLog("\n\nM68000 disassembly at $1AC000...\n");
1135 jaguar_dasm(0x1AC000, 6000);
1138 // WriteLog("Jaguar: CD BIOS version %04X\n", JaguarReadWord(0x3004));
1139 WriteLog("Jaguar: Interrupt enable = %02X\n", TOMReadByte(0xF000E1) & 0x1F);
1140 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
1141 M68K_show_context();
1150 memory_free(jaguar_mainRom);
1151 memory_free(jaguar_mainRam);
1152 memory_free(jaguar_bootRom);
1153 memory_free(jaguar_CDBootROM);
1157 // Main Jaguar execution loop (1 frame)
1159 void JaguarExecute(uint32 * backbuffer, bool render)
1161 uint16 vp = TOMReadWord(0xF0003E) + 1;//Hmm. This is a WO register. Will work? Looks like. But wrong behavior!
1162 uint16 vi = TOMReadWord(0xF0004E);//Another WO register...
1163 //Using WO registers is OK, since we're the ones controlling access--there's nothing wrong here! ;-)
1165 // uint16 vdb = TOMReadWord(0xF00046);
1166 //Note: This is the *definite* end of the display, though VDE *might* be less than this...
1167 // uint16 vbb = TOMReadWord(0xF00040);
1168 //It seems that they mean it when they say that VDE is the end of object processing.
1169 //However, we need to be able to tell the OP (or TOM) that we've reached the end of the
1170 //buffer and not to write any more pixels... !!! FIX !!!
1171 // uint16 vde = TOMReadWord(0xF00048);
1173 uint16 refreshRate = (vjs.hardwareTypeNTSC ? 60 : 50);
1174 // Should these be hardwired or read from VP? Yes, from VP!
1175 uint32 M68KCyclesPerScanline
1176 = (vjs.hardwareTypeNTSC ? M68K_CLOCK_RATE_NTSC : M68K_CLOCK_RATE_PAL) / (vp * refreshRate);
1177 uint32 RISCCyclesPerScanline
1178 = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL) / (vp * refreshRate);
1180 TOMResetBackbuffer(backbuffer);
1181 /*extern int effect_start;
1183 WriteLog("JagExe: VP=%u, VI=%u, CPU CPS=%u, GPU CPS=%u\n", vp, vi, M68KCyclesPerScanline, RISCCyclesPerScanline);//*/
1185 //extern int start_logging;
1186 for(uint16 i=0; i<vp; i++)
1188 // Increment the horizontal count (why? RNG? Besides which, this is *NOT* cycle accurate!)
1189 TOMWriteWord(0xF00004, (TOMReadWord(0xF00004) + 1) & 0x7FF);
1191 TOMWriteWord(0xF00006, i); // Write the VC
1193 // if (i == vi) // Time for Vertical Interrupt?
1194 //Not sure if this is correct...
1195 //Seems to be, kinda. According to the JTRM, this should only fire on odd lines in non-interlace mode...
1196 //Which means that it normally wouldn't go when it's zero.
1197 if (i == vi && i > 0 && tom_irq_enabled(IRQ_VBLANK)) // Time for Vertical Interrupt?
1199 // We don't have to worry about autovectors & whatnot because the Jaguar
1200 // tells you through its HW registers who sent the interrupt...
1201 tom_set_pending_video_int();
1205 //if (start_logging)
1206 // WriteLog("About to execute M68K (%u)...\n", i);
1207 m68k_execute(M68KCyclesPerScanline);
1208 //if (start_logging)
1209 // WriteLog("About to execute TOM's PIT (%u)...\n", i);
1210 TOMExecPIT(RISCCyclesPerScanline);
1211 //if (start_logging)
1212 // WriteLog("About to execute JERRY's PIT (%u)...\n", i);
1213 JERRYExecPIT(RISCCyclesPerScanline);
1214 //if (start_logging)
1215 // WriteLog("About to execute JERRY's SSI (%u)...\n", i);
1216 jerry_i2s_exec(RISCCyclesPerScanline);
1217 BUTCHExec(RISCCyclesPerScanline);
1218 //if (start_logging)
1219 // WriteLog("About to execute GPU (%u)...\n", i);
1220 gpu_exec(RISCCyclesPerScanline);
1224 if (vjs.usePipelinedDSP)
1225 DSPExecP2(RISCCyclesPerScanline); // Pipelined DSP execution (3 stage)...
1227 DSPExec(RISCCyclesPerScanline); // Ordinary non-pipelined DSP
1228 // DSPExecComp(RISCCyclesPerScanline); // Comparison core
1231 //if (start_logging)
1232 // WriteLog("About to execute OP (%u)...\n", i);
1233 TOMExecScanline(i, render);
1237 // Temp debugging stuff
1239 void DumpMainMemory(void)
1241 FILE * fp = fopen("./memdump.bin", "wb");
1246 fwrite(jaguar_mainRam, 1, 0x400000, fp);
1250 uint8 * GetRamPtr(void)
1252 return jaguar_mainRam;