5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (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. :-)
12 //#include "m68kdasmAG.h"
15 //Do this in makefile??? Yes! Could, but it's easier to define here...
16 //#define LOG_UNMAPPED_MEMORY_ACCESSES
18 // Private function prototypes
20 unsigned jaguar_unknown_readbyte(unsigned address, uint32 who = UNKNOWN);
21 unsigned jaguar_unknown_readword(unsigned address, uint32 who = UNKNOWN);
22 void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who = UNKNOWN);
23 void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who = UNKNOWN);
24 void M68K_show_context(void);
28 extern bool hardwareTypeNTSC; // Set to false for PAL
30 // Memory debugging identifiers
33 { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" };
35 // These values are overridden by command line switches...
37 bool dsp_enabled = false;
38 bool jaguar_use_bios = true; // Default is now to USE the BIOS
39 uint32 jaguar_active_memory_dumps = 0;
41 uint32 jaguar_mainRom_crc32;
43 /*static*/ uint8 * jaguar_mainRam = NULL;
44 /*static*/ uint8 * jaguar_bootRom = NULL;
45 /*static*/ uint8 * jaguar_mainRom = NULL;
49 // Callback function to detect illegal instructions
51 void M68KInstructionHook(void)
53 uint32 m68kPC = m68k_get_reg(NULL, M68K_REG_PC);
55 /* static char buffer[2048];
56 m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
57 WriteLog("%08X: %s \t\tD0=%08X, A0=%08X\n", m68kPC, buffer, m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_A0));//*/
59 /* if (m68kPC == 0x803F16)
61 WriteLog("M68K: Registers found at $803F16:\n");
62 WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
63 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
64 WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
66 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
67 WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
70 if (!m68k_is_valid_instruction(JaguarReadWord(m68kPC), M68K_CPU_TYPE_68000))
72 WriteLog("\nM68K encountered an illegal instruction at %08X!!!\n\nAborting!\n", m68kPC);
73 uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
74 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
75 for(int i=0; i<10; i++)
76 WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4)));
77 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
85 // Musashi 68000 read/write/IRQ functions
88 int irq_ack_handler(int level)
90 int vector = M68K_INT_ACK_AUTOVECTOR;
92 // The GPU/DSP/etc are probably *not* issuing an NMI, but it seems to work OK...
96 m68k_set_irq(0); // Clear the IRQ...
97 vector = 64; // Set user interrupt #0
103 unsigned int m68k_read_memory_8(unsigned int address)
105 //WriteLog("[RM8] Addr: %08X\n", address);
106 unsigned int retVal = 0;
108 if ((address >= 0x000000) && (address <= 0x3FFFFF))
109 retVal = jaguar_mainRam[address];
110 else if ((address >= 0x800000) && (address <= 0xDFFFFF))
111 retVal = jaguar_mainRom[address - 0x800000];
112 else if ((address >= 0xE00000) && (address <= 0xE3FFFF))
113 retVal = jaguar_bootRom[address - 0xE00000];
114 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
115 retVal = CDROMReadByte(address);
116 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
117 retVal = TOMReadByte(address, M68K);
118 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
119 retVal = JERRYReadByte(address, M68K);
121 retVal = jaguar_unknown_readbyte(address, M68K);
126 void gpu_dump_disassembly(void);
127 void gpu_dump_registers(void);
129 unsigned int m68k_read_memory_16(unsigned int address)
131 //WriteLog("[RM16] Addr: %08X\n", address);
132 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005FBA)
133 // for(int i=0; i<10000; i++)
134 WriteLog("[M68K] In routine #6!\n");//*/
135 //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00006696) // GPU Program #4
136 //if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005B3C) // GPU Program #2
137 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005BA8) // GPU Program #3
139 WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address));
140 gpu_dump_registers();
141 gpu_dump_disassembly();
142 // for(int i=0; i<10000; i++)
143 // WriteLog("[M68K] About to run GPU!\n");
145 //WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
146 /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x00006696 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x000066A8)
148 if (address == 0x000066A0)
150 gpu_dump_registers();
151 gpu_dump_disassembly();
153 for(int i=0; i<10000; i++)
154 WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, TOMReadWord(address));
156 unsigned int retVal = 0;
158 if ((address >= 0x000000) && (address <= 0x3FFFFE))
159 retVal = (jaguar_mainRam[address] << 8) | jaguar_mainRam[address+1];
160 else if ((address >= 0x800000) && (address <= 0xDFFFFE))
161 retVal = (jaguar_mainRom[address - 0x800000] << 8) | jaguar_mainRom[address - 0x800000 + 1];
162 else if ((address >= 0xE00000) && (address <= 0xE3FFFE))
163 retVal = (jaguar_bootRom[address - 0xE00000] << 8) | jaguar_bootRom[address - 0xE00000 + 1];
164 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
165 retVal = CDROMReadWord(address, M68K);
166 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
167 retVal = TOMReadWord(address, M68K);
168 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
169 retVal = JERRYReadWord(address, M68K);
171 retVal = jaguar_unknown_readword(address, M68K);
176 unsigned int m68k_read_memory_32(unsigned int address)
178 //WriteLog("--> [RM32]\n");
179 return (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2);
182 void m68k_write_memory_8(unsigned int address, unsigned int value)
184 //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F))
185 // WriteLog("M68K: Writing %02X at %08X\n", value, address);
186 //WriteLog("[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
187 if ((address >= 0x000000) && (address <= 0x3FFFFF))
188 jaguar_mainRam[address] = value;
189 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
190 CDROMWriteByte(address, value, M68K);
191 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
192 TOMWriteByte(address, value, M68K);
193 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
194 JERRYWriteByte(address, value, M68K);
196 jaguar_unknown_writebyte(address, value, M68K);
199 void m68k_write_memory_16(unsigned int address, unsigned int value)
201 //if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F))
202 // WriteLog("M68K: Writing %04X at %08X\n", value, address);
203 //WriteLog("[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
204 //if (address >= 0xF02200 && address <= 0xF0229F)
205 // WriteLog("M68K: Writing to blitter --> %04X at %08X\n", value, address);
206 //if (address >= 0x0E75D0 && address <= 0x0E75E7)
207 // WriteLog("M68K: Writing %04X at %08X, M68K PC=%08X\n", value, address, m68k_get_reg(NULL, M68K_REG_PC));
208 /*extern uint32 totalFrames;
209 /*if (address == 0xF02114)
210 WriteLog("M68K: Writing to GPU_CTRL (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));
211 if (address == 0xF02110)
212 WriteLog("M68K: Writing to GPU_PC (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));//*/
213 //if (address >= 0xF03B00 && address <= 0xF03DFF)
214 // WriteLog("M68K: Writing %04X to %08X...\n", value, address);
216 if ((address >= 0x000000) && (address <= 0x3FFFFE))
218 /* jaguar_mainRam[address] = value >> 8;
219 jaguar_mainRam[address + 1] = value & 0xFF;*/
220 SET16(jaguar_mainRam, address, value);
222 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
223 CDROMWriteWord(address, value, M68K);
224 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
225 TOMWriteWord(address, value, M68K);
226 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
227 JERRYWriteWord(address, value, M68K);
229 jaguar_unknown_writeword(address, value, M68K);
232 void m68k_write_memory_32(unsigned int address, unsigned int value)
234 //WriteLog("--> [WM32]\n");
235 m68k_write_memory_16(address, value >> 16);
236 m68k_write_memory_16(address + 2, value & 0xFFFF);
240 uint32 jaguar_get_handler(uint32 i)
242 return JaguarReadLong(i * 4);
245 uint32 jaguar_interrupt_handler_is_valid(uint32 i)
247 uint32 handler = jaguar_get_handler(i);
248 if (handler && (handler != 0xFFFFFFFF))
254 void M68K_show_context(void)
256 WriteLog("\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
257 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
258 WriteLog("\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
260 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
261 WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
263 WriteLog("68K disasm\n");
264 // jaguar_dasm(s68000readPC()-0x1000,0x20000);
265 jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x80, 0x200);
266 // jaguar_dasm(0x5000, 0x14414);
268 WriteLog("..................\n");
270 if (tom_irq_enabled(IRQ_VBLANK))
272 WriteLog("vblank int: enabled\n");
273 jaguar_dasm(jaguar_get_handler(64), 0x200);
276 WriteLog("vblank int: disabled\n");
278 WriteLog("..................\n");
280 for(int i=0; i<256; i++)
281 WriteLog("handler %03i at $%08X\n", i, (unsigned int)jaguar_get_handler(i));
285 // Unknown read/write byte/word routines
288 void jaguar_unknown_writebyte(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/)
290 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
291 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));
292 extern bool finished;
294 extern bool doDSPDis;
300 void jaguar_unknown_writeword(unsigned address, unsigned data, uint32 who/*=UNKNOWN*/)
302 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
303 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));
304 extern bool finished;
306 extern bool doDSPDis;
312 unsigned jaguar_unknown_readbyte(unsigned address, uint32 who/*=UNKNOWN*/)
314 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
315 WriteLog("Jaguar: Unknown byte read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
316 extern bool finished;
318 extern bool doDSPDis;
325 unsigned jaguar_unknown_readword(unsigned address, uint32 who/*=UNKNOWN*/)
327 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
328 WriteLog("Jaguar: Unknown word read at %08X by %s (M68K PC=%06X)\n", address, whoName[who], m68k_get_reg(NULL, M68K_REG_PC));
329 extern bool finished;
331 extern bool doDSPDis;
339 // Disassemble M68K instructions at the given offset
342 unsigned int m68k_read_disassembler_8(unsigned int address)
344 return m68k_read_memory_8(address);
347 unsigned int m68k_read_disassembler_16(unsigned int address)
349 return m68k_read_memory_16(address);
352 unsigned int m68k_read_disassembler_32(unsigned int address)
354 return m68k_read_memory_32(address);
357 void jaguar_dasm(uint32 offset, uint32 qt)
360 static char buffer[2048];//, mem[64];
361 int pc = offset, oldpc;
363 for(uint32 i=0; i<qt; i++)
366 for(int j=0; j<64; j++)
367 mem[j^0x01] = jaguar_byte_read(pc + j);
369 pc += Dasm68000((char *)mem, buffer, 0);
370 WriteLog("%08X: %s\n", oldpc, buffer);//*/
372 pc += m68k_disassemble(buffer, pc, M68K_CPU_TYPE_68000);
373 WriteLog("%08X: %s\n", oldpc, buffer);//*/
378 uint8 JaguarReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
383 if (offset < 0x400000)
384 data = jaguar_mainRam[offset & 0x3FFFFF];
385 else if ((offset >= 0x800000) && (offset < 0xC00000))
386 data = jaguar_mainRom[offset - 0x800000];
387 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
388 data = CDROMReadByte(offset, who);
389 else if ((offset >= 0xE00000) && (offset < 0xE40000))
390 data = jaguar_bootRom[offset & 0x3FFFF];
391 else if ((offset >= 0xF00000) && (offset < 0xF10000))
392 data = TOMReadByte(offset, who);
393 else if ((offset >= 0xF10000) && (offset < 0xF20000))
394 data = JERRYReadByte(offset, who);
396 data = jaguar_unknown_readbyte(offset, who);
401 uint16 JaguarReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
404 if (offset <= 0x3FFFFE)
406 return (jaguar_mainRam[(offset+0) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+1) & 0x3FFFFF];
408 else if ((offset >= 0x800000) && (offset <= 0xBFFFFE))
411 return (jaguar_mainRom[offset+0] << 8) | jaguar_mainRom[offset+1];
413 // else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00))
414 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE))
415 return CDROMReadWord(offset, who);
416 else if ((offset >= 0xE00000) && (offset <= 0xE3FFFE))
417 return (jaguar_bootRom[(offset+0) & 0x3FFFF] << 8) | jaguar_bootRom[(offset+1) & 0x3FFFF];
418 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE))
419 return TOMReadWord(offset, who);
420 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE))
421 return JERRYReadWord(offset, who);
423 return jaguar_unknown_readword(offset, who);
426 void JaguarWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
429 if (offset < 0x400000)
431 jaguar_mainRam[offset & 0x3FFFFF] = data;
434 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
436 CDROMWriteByte(offset, data, who);
439 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFF))
441 TOMWriteByte(offset, data, who);
444 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFF))
446 JERRYWriteByte(offset, data, who);
450 jaguar_unknown_writebyte(offset, data, who);
453 void JaguarWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
455 //TEMP--Mirror of F03000? Yes, but only 32-bit CPUs can do it (i.e., NOT the 68K!)
456 //if (offset >= 0xF0B000 && offset <= 0xF0BFFF)
457 //WriteLog("[JWW16] --> Possible GPU RAM mirror access! [%08X]", offset);
458 //if ((offset >= 0x1FF020 && offset <= 0x1FF03F) || (offset >= 0x1FF820 && offset <= 0x1FF83F))
459 // WriteLog("JagWW: Writing %04X at %08X\n", data, offset);
462 if (offset <= 0x3FFFFE)
464 jaguar_mainRam[(offset+0) & 0x3FFFFF] = (data>>8) & 0xFF;
465 jaguar_mainRam[(offset+1) & 0x3FFFFF] = data & 0xFF;
468 else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE))
470 CDROMWriteWord(offset, data, who);
473 else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE))
475 TOMWriteWord(offset, data, who);
478 else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE))
480 JERRYWriteWord(offset, data, who);
484 jaguar_unknown_writeword(offset, data, who);
487 // We really should re-do this so that it does *real* 32-bit access... !!! FIX !!!
488 uint32 JaguarReadLong(uint32 offset, uint32 who/*=UNKNOWN*/)
490 return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset+2, who);
493 // We really should re-do this so that it does *real* 32-bit access... !!! FIX !!!
494 void JaguarWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
496 JaguarWriteWord(offset, data >> 16, who);
497 JaguarWriteWord(offset+2, data & 0xFFFF, who);
501 // Jaguar console initialization
503 void jaguar_init(void)
505 memory_malloc_secure((void **)&jaguar_mainRam, 0x400000, "Jaguar 68K CPU RAM");
506 memory_malloc_secure((void **)&jaguar_bootRom, 0x040000, "Jaguar 68K CPU BIOS ROM");
507 memory_malloc_secure((void **)&jaguar_mainRom, 0x600000, "Jaguar 68K CPU ROM");
508 memset(jaguar_mainRam, 0x00, 0x400000);
509 // memset(jaguar_mainRom, 0xFF, 0x200000); // & set it to all Fs...
510 memset(jaguar_mainRom, 0x00, 0x200000); // & set it to all 0s...
512 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\Brain Dead 13.cdi");
513 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\baldies.cdi");
514 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\mystdemo.cdi");
515 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\battlemorph.cdi");
516 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\primalrage.cdi");
517 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\Dragons Lair.cdi");
519 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
527 void jaguar_done(void)
530 // for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
531 // WriteLog("\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
532 int32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
533 WriteLog("M68K: Top of stack: %08X. Stack trace:\n", JaguarReadLong(topOfStack));
534 for(int i=-2; i<9; i++)
535 WriteLog("%06X: %08X\n", topOfStack + (i * 4), JaguarReadLong(topOfStack + (i * 4)));
537 /* WriteLog("\nM68000 disassembly at $802288...\n");
538 jaguar_dasm(0x802288, 3);
539 WriteLog("\nM68000 disassembly at $802200...\n");
540 jaguar_dasm(0x802200, 500);
541 WriteLog("\nM68000 disassembly at $802518...\n");
542 jaguar_dasm(0x802518, 100);//*/
544 /* WriteLog("\n\nM68000 disassembly at $803F00 (look @ $803F2A)...\n");
545 jaguar_dasm(0x803F00, 500);
548 /* WriteLog("\n\nM68000 disassembly at $802B00 (look @ $802B5E)...\n");
549 jaguar_dasm(0x802B00, 500);
552 // WriteLog("Jaguar: CD BIOS version %04X\n", JaguarReadWord(0x3004));
553 WriteLog("Jaguar: Interrupt enable = %02X\n", TOMReadByte(0xF000E1) & 0x1F);
554 WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
565 memory_free(jaguar_mainRom);
566 memory_free(jaguar_bootRom);
567 memory_free(jaguar_mainRam);
570 void jaguar_reset(void)
573 memcpy(jaguar_mainRam, jaguar_bootRom, 8);
576 SET32(jaguar_mainRam, 4, 0x00802000);
577 // Handle PD stuff...
578 // This should definitely go elsewhere (like in the cart load section)!
579 if (jaguar_mainRom[0] == 0x60 && jaguar_mainRom[1] == 0x1A)
581 uint32 runAddress = GET32(jaguar_mainRom, 0x2A);
582 uint32 progLength = GET32(jaguar_mainRom, 0x02);
583 WriteLog("Setting up PD ROM... Run address: %08X, length: %08X\n", runAddress, progLength);
584 memcpy(jaguar_mainRam + runAddress, jaguar_mainRom + 0x2E, progLength);
585 SET32(jaguar_mainRam, 4, runAddress);
589 // WriteLog("jaguar_reset():\n");
590 //#ifdef SOUND_OUTPUT
599 m68k_pulse_reset(); // Reset the 68000
600 WriteLog("\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7));
604 void jaguar_reset_handler(void)
609 // Main Jaguar execution loop (1 frame)
611 void JaguarExecute(int16 * backbuffer, bool render)
613 uint16 vp = TOMReadWord(0xF0003E) + 1;//Hmm. This is a WO register. Will work? Looks like. But wrong behavior!
614 uint16 vi = TOMReadWord(0xF0004E);//Another WO register...
615 uint16 vdb = TOMReadWord(0xF00046);
616 //Note: This is the *definite* end of the display, though VDE *might* be less than this...
617 // uint16 vbb = TOMReadWord(0xF00040);
618 //It seems that they mean it when they say that VDE is the end of object processing.
619 //However, we need to be able to tell the OP (or TOM) that we've reached the end of the
620 //buffer and not to write any more pixels... !!! FIX !!!
621 uint16 vde = TOMReadWord(0xF00048);
623 uint16 refreshRate = (hardwareTypeNTSC ? 60 : 50);
624 // Should these be hardwired or read from VP? Yes, from VP!
625 uint32 M68KCyclesPerScanline
626 = (hardwareTypeNTSC ? M68K_CLOCK_RATE_NTSC : M68K_CLOCK_RATE_PAL) / (vp * refreshRate);
627 uint32 RISCCyclesPerScanline
628 = (hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL) / (vp * refreshRate);
630 /*extern int effect_start;
633 WriteLog("JagExe: VP=%u, VI=%u, VDB=%u, VBB=%u CPU CPS=%u, GPU CPS=%u\n", vp, vi, vdb, vbb, M68KCyclesPerScanline, RISCCyclesPerScanline);
636 for(uint16 i=0; i<vp; i++)
638 // Increment the horizontal count (why? RNG?)
639 TOMWriteWord(0xF00004, (TOMReadWord(0xF00004) + 1) & 0x7FF);
641 TOMWriteWord(0xF00006, i); // Write the VC
643 if (i == vi) // Time for Vertical Interrupt?
645 if (tom_irq_enabled(IRQ_VBLANK))// && jaguar_interrupt_handler_is_valid(64))
647 // We don't have to worry about autovectors & whatnot because the Jaguar
648 // tells you through its HW registers who sent the interrupt...
649 tom_set_pending_video_int();
654 // uint32 invalid_instruction_address = s68000exec(M68KCyclesPerScanline);
655 // if (invalid_instruction_address != 0x80000000)
656 // cd_bios_process(invalid_instruction_address);
657 // These are divided by 2 because we're executing *half* lines...!
658 // Err, this is *already* accounted for in jaguar_init...!
659 m68k_execute(M68KCyclesPerScanline);
660 // No CD handling... !!! FIX !!!
661 cd_bios_exec(i); // NOTE: Ignores parameter...
662 tom_pit_exec(RISCCyclesPerScanline);
663 jerry_pit_exec(RISCCyclesPerScanline);
664 jerry_i2s_exec(RISCCyclesPerScanline);
665 gpu_exec(RISCCyclesPerScanline);
667 DSPExec(RISCCyclesPerScanline);
669 //Interlacing is still not handled correctly here... !!! FIX !!!
670 if (i >= vdb && i < vde)//vbb)
672 if (!(i & 0x01)) // Execute OP only on even lines (non-interlaced only!)
674 tom_exec_scanline(backbuffer, i/2, render); // i/2 is a kludge...
675 backbuffer += TOMGetSDLScreenPitch() / 2; // Convert bytes to words...
681 // Temp debugging stuff
683 void DumpMainMemory(void)
685 FILE * fp = fopen("./memdump.bin", "wb");
690 fwrite(jaguar_mainRam, 1, 0x400000, fp);
694 uint8 * GetRamPtr(void)
696 return jaguar_mainRam;