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 //#define LOG_UNMAPPED_MEMORY_ACCESSES
16 //#define SOUND_OUTPUT
18 // Some handy macros to help converting native endian to big endian (jaguar native)
20 #define SET32(r, a, v) r[a] = ((v) & 0xFF000000) >> 24, r[a+1] = ((v) & 0x00FF0000) >> 16, \
21 r[a+2] = ((v) & 0x0000FF00) >> 8, r[a+3] = (v) & 0x000000FF
24 // Function Prototypes
27 unsigned jaguar_unknown_readbyte(unsigned address);
28 unsigned jaguar_unknown_readword(unsigned address);
29 void jaguar_unknown_writebyte(unsigned address, unsigned data);
30 void jaguar_unknown_writeword(unsigned address, unsigned data);
38 uint32 jaguar_active_memory_dumps = 0;
39 uint32 jaguar_use_bios = 0;
40 #define JAGUAR_WIP_RELEASE
41 #define JAGUAR_REAL_SPEED
44 //////////////////////////////////////////////////////////////////////////////
46 //////////////////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////////////
51 //static char *jaguar_bootRom_path="c:/jaguarEmu/newload.img";
52 static char * jaguar_bootRom_path = "./bios/jagboot.rom";
53 //static char *jaguar_bootRom_path="./bios/JagOS.bin";
54 char * jaguar_eeproms_path = "./eeproms/";
56 //////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////
62 //////////////////////////////////////////////////////////////////////////////
63 uint32 jaguar_mainRom_crc32;
65 static uint32 m68k_cycles_per_scanline;
66 static uint32 gpu_cycles_per_scanline;
67 static uint32 dsp_cycles_per_scanline;
68 static uint32 jaguar_screen_scanlines;
70 static uint8 * jaguar_mainRam = NULL;
71 static uint8 * jaguar_bootRom = NULL;
72 static uint8 * jaguar_mainRom = NULL;
73 //////////////////////////////////////////////////////////////////////////////
77 // Musashi 68000 read/write/IRQ functions
80 int irq_ack_handler(int level)
82 int vector = M68K_INT_ACK_AUTOVECTOR;
86 m68k_set_irq(0); // Clear the IRQ...
87 vector = 64; // Set user interrupt #0
93 //Do this in makefile???
94 //#define LOG_UNMAPPED_MEMORY_ACCESSES 1
96 unsigned int m68k_read_memory_8(unsigned int address)
98 //fprintf(log_get(), "[RM8] Addr: %08X\n", address);
99 unsigned int retVal = 0;
101 if ((address >= 0x000000) && (address <= 0x3FFFFF))
102 retVal = jaguar_mainRam[address];
103 else if ((address >= 0x800000) && (address <= 0xDFFFFF))
104 retVal = jaguar_mainRom[address - 0x800000];
105 else if ((address >= 0xE00000) && (address <= 0xE3FFFF))
106 retVal = jaguar_bootRom[address - 0xE00000];
107 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
108 retVal = cdrom_byte_read(address);
109 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
110 retVal = tom_byte_read(address);
111 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
112 retVal = jerry_byte_read(address);
114 retVal = jaguar_unknown_readbyte(address);
119 unsigned int m68k_read_memory_16(unsigned int address)
121 //fprintf(log_get(), "[RM16] Addr: %08X\n", address);
122 unsigned int retVal = 0;
124 if ((address >= 0x000000) && (address <= 0x3FFFFE))
125 retVal = (jaguar_mainRam[address] << 8) | jaguar_mainRam[address+1];
126 else if ((address >= 0x800000) && (address <= 0xDFFFFE))
127 retVal = (jaguar_mainRom[address - 0x800000] << 8) | jaguar_mainRom[address - 0x800000 + 1];
128 else if ((address >= 0xE00000) && (address <= 0xE3FFFE))
129 retVal = (jaguar_bootRom[address - 0xE00000] << 8) | jaguar_bootRom[address - 0xE00000 + 1];
130 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
131 retVal = cdrom_word_read(address);
132 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
133 retVal = tom_word_read(address);
134 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
135 retVal = jerry_word_read(address);
138 //fprintf(log_get(), "[RM16] Unknown address: %08X\n", address);
139 retVal = jaguar_unknown_readword(address);
145 unsigned int m68k_read_memory_32(unsigned int address)
147 //fprintf(log_get(), "--> [RM32]\n");
148 return (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2);
151 void m68k_write_memory_8(unsigned int address, unsigned int value)
153 //fprintf(log_get(), "[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
154 if ((address >= 0x000000) && (address <= 0x3FFFFF))
155 jaguar_mainRam[address] = value;
156 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF))
157 cdrom_byte_write(address, value);
158 else if ((address >= 0xF00000) && (address <= 0xF0FFFF))
159 tom_byte_write(address, value);
160 else if ((address >= 0xF10000) && (address <= 0xF1FFFF))
161 jerry_byte_write(address, value);
163 jaguar_unknown_writebyte(address, value);
166 void m68k_write_memory_16(unsigned int address, unsigned int value)
168 //fprintf(log_get(), "[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value);
169 if ((address >= 0x000000) && (address <= 0x3FFFFE))
171 jaguar_mainRam[address] = value >> 8;
172 jaguar_mainRam[address + 1] = value & 0xFF;
174 else if ((address >= 0xDFFF00) && (address <= 0xDFFFFE))
175 cdrom_word_write(address, value);
176 else if ((address >= 0xF00000) && (address <= 0xF0FFFE))
177 tom_word_write(address, value);
178 else if ((address >= 0xF10000) && (address <= 0xF1FFFE))
179 jerry_word_write(address, value);
181 jaguar_unknown_writeword(address, value);
184 void m68k_write_memory_32(unsigned int address, unsigned int value)
186 //fprintf(log_get(), "--> [WM32]\n");
187 m68k_write_memory_16(address, value >> 16);
188 m68k_write_memory_16(address + 2, value & 0xFFFF);
191 //////////////////////////////////////////////////////////////////////////////
195 //////////////////////////////////////////////////////////////////////////////
196 /*struct STARSCREAM_PROGRAMREGION *jaguar_programfetch;
197 struct STARSCREAM_DATAREGION *jaguar_readbyte;
198 struct STARSCREAM_DATAREGION *jaguar_readword;
199 struct STARSCREAM_DATAREGION *jaguar_writebyte;
200 struct STARSCREAM_DATAREGION *jaguar_writeword;
201 UINT16 jaguar_regionsCount[6];*/
203 //////////////////////////////////////////////////////////////////////////////
205 //////////////////////////////////////////////////////////////////////////////
209 //////////////////////////////////////////////////////////////////////////////
210 uint32 jaguar_get_handler(uint32 i)
212 // return (jaguar_word_read(i<<2) << 16) | jaguar_word_read((i<<2) + 2);
213 return (jaguar_word_read(i*4) << 16) | jaguar_word_read((i*4) + 2);
216 //////////////////////////////////////////////////////////////////////////////
218 //////////////////////////////////////////////////////////////////////////////
224 //////////////////////////////////////////////////////////////////////////////
225 static char romLoadDialog_filePath[1024];
227 static char romLoadDialog_initialDirectory[1024];
229 int jaguar_open_rom(HWND hWnd,char *title,char *filterString)
234 romLoadDialog_initialDirectory[0] = 0;
237 romLoadDialog_filePath[0] = 0;
239 ZeroMemory(&ofn, sizeof(OPENFILENAME));
240 ofn.lStructSize = sizeof(OPENFILENAME);
241 ofn.hwndOwner = hWnd;
242 ofn.lpstrFile = romLoadDialog_filePath;
243 ofn.nMaxFile = sizeof(romLoadDialog_filePath);
244 ofn.lpstrFilter = filterString;
245 ofn.nFilterIndex = 0;
246 ofn.lpstrFileTitle = NULL;
247 ofn.nMaxFileTitle = 0;
248 ofn.lpstrInitialDir = (const char *)romLoadDialog_initialDirectory;
249 ofn.lpstrTitle = title;
250 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
252 if(GetOpenFileName(&ofn) == FALSE)
254 DWORD res = CommDlgExtendedError();
255 SendMessage(hWnd, WM_MOVE, 0,0);
260 SendMessage(hWnd, WM_MOVE, 0,0);
264 //////////////////////////////////////////////////////////////////////////////
266 //////////////////////////////////////////////////////////////////////////////
270 //////////////////////////////////////////////////////////////////////////////
271 uint32 jaguar_interrupt_handler_is_valid(uint32 i)
273 uint32 handler = jaguar_get_handler(i);
274 if (handler && (handler != 0xFFFFFFFF))
279 //////////////////////////////////////////////////////////////////////////////
281 //////////////////////////////////////////////////////////////////////////////
285 //////////////////////////////////////////////////////////////////////////////
286 void s68000show_context(void)
288 // fprintf(log_get(),"\t68k PC=0x%.6x\n",s68000readPC());
289 fprintf(log_get(),"\t68k PC=0x%.6x\n", m68k_get_reg(NULL, M68K_REG_PC));
290 // for (int i=0;i<8;i++)
291 // fprintf(log_get(),"\tD%i = 0x%.8x\n",i,s68000context.dreg[i]);
292 for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++)
293 fprintf(log_get(), "\tD%i = 0x%.8x\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i));
294 fprintf(log_get(), "\n");
296 // fprintf(log_get(),"\tA%i = 0x%.8x\n",i,s68000context.areg[i]);
297 for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++)
298 fprintf(log_get(), "\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
300 fprintf(log_get(), "68k dasm\n");
301 // jaguar_dasm(s68000readPC()-0x1000,0x20000);
302 // jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x1000, 0x20000);
303 jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x80, 0x200);
304 fprintf(log_get(), "..................\n");
307 if (tom_irq_enabled(IRQ_VBLANK))
309 fprintf(log_get(), "vblank int: enabled\n");
310 jaguar_dasm(jaguar_get_handler(64), 0x200);
313 fprintf(log_get(), "vblank int: disabled\n");
314 fprintf(log_get(), "..................\n");
316 for(int i=0; i<256; i++)
317 fprintf(log_get(), "handler %03i at $%08X\n", i, jaguar_get_handler(i));
320 // Starscream crap ripped out...
323 // Unknown read/write byte/word routines
326 void jaguar_unknown_writebyte(unsigned address, unsigned data)
328 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
329 fprintf(log_get(), "jaguar: unknown byte %02X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC));
333 void jaguar_unknown_writeword(unsigned address, unsigned data)
335 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
336 fprintf(log_get(), "jaguar: unknown word %04X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC));
340 unsigned jaguar_unknown_readbyte(unsigned address)
342 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
343 fprintf(log_get(), "jaguar: unknown byte read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC));
348 unsigned jaguar_unknown_readword(unsigned address)
350 #ifdef LOG_UNMAPPED_MEMORY_ACCESSES
351 fprintf(log_get(), "jaguar: unknown word read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC));
357 // Jaguar ROM loading
360 uint8 * jaguar_rom_load(char * path, uint32 * romSize)
367 fprintf(log_get(), "jaguar: loading %s...", path);
368 FILE * fp = fopen(path, "rb");
371 fprintf(log_get(), "failed\n");
376 fseek(fp, 0, SEEK_END);
378 /* Added by SDLEMU (http://sdlemu.ngemu.com) */
379 /* Added for GCC UNIX compatibility */
381 fgetpos(fp, (fpos_t *)&filepos);
383 fgetpos(fp, &filepos);
386 *romSize = (int)filepos;
387 fseek(fp, 0, SEEK_SET);
388 rom = (uint8 *)malloc(*romSize);
389 fread(rom, 1, *romSize, fp);
391 fprintf(log_get(), "ok (%i bytes)\n", *romSize);
392 // jaguar_mainRom_crc32=crc32_calcCheckSum(jaguar_mainRom,*romSize);
393 // fprintf(log_get(),"crc: 0x%.8x\n",jaguar_mainRom_crc32);
398 // Load a ROM at a specific address
401 void jaguar_rom_load_to(uint8 * rom, char * path, uint32 * romSize)
405 fprintf(log_get(), "jaguar: loading %s...", path);
406 FILE * fp = fopen(path, "rb");
409 fprintf(log_get(), "failed\n");
414 fseek(fp, 0, SEEK_END);
416 /* Added by SDLEMU (http://sdlemu.ngemu.com) */
417 /* Added for GCC UNIX compatibility */
419 fgetpos(fp, (fpos_t *)&filepos);
421 fgetpos(fp, &filepos);
424 *romSize = (int)filepos;
425 fseek(fp, 0, SEEK_SET);
426 fread(rom, 1, *romSize, fp);
428 fprintf(log_get(), "ok (%i bytes)\n", *romSize);
432 // Byte swap a region of memory
435 void jaguar_byte_swap(uint8 * rom, uint32 size)
448 // Disassemble instructions at the given offset
451 void jaguar_dasm(uint32 offset, uint32 qt)
453 static char buffer[2048], mem[64];
454 int pc = offset, oldpc;
456 for(int i=0; i<qt; i++)
459 for(int j=0; j<64; j++)
460 // mem[j^0x01] = jaguar_byte_read(pc + j);
461 mem[j^0x01] = jaguar_byte_read(pc + j);
463 pc += Dasm68000((char *)mem, buffer, 0);
465 fprintf(log_get(), "%08X: %s\n", oldpc, buffer);
471 // Jaguar cartridge ROM loading
474 void jaguar_load_cart(char * path, uint8 * mem, uint32 offs, uint32 boot, uint32 header)
478 jaguar_rom_load_to(mem+offs-header, path, &romsize);
479 // Is there a need for this? The answer is !!! NO !!!
480 // jaguar_byte_swap(mem+offs, romsize);
481 jaguar_mainRom_crc32 = crc32_calcCheckSum(jaguar_mainRom, romsize);
482 fprintf(log_get(), "crc: %08X\n", jaguar_mainRom_crc32);
484 // Brain dead endian dependent crap
485 // *((uint32 *)&jaguar_mainRam[4]) = boot;
486 // This is how it *should* have been done...
487 SET32(jaguar_mainRam, 4, boot);
489 // jaguar_dasm((boot>>16) | (boot<<16), 32*4);
490 jaguar_dasm(boot, 32*4);
494 // Jaguar initialization
498 void jaguar_init(const char * filename)
500 void jaguar_init(void)
505 jaguar_screen_scanlines = 525; // PAL screen size
506 m68k_cycles_per_scanline = 13300000 / (jaguar_screen_scanlines * 60);
507 gpu_cycles_per_scanline = (26591000 / 4) / (jaguar_screen_scanlines * 60);
508 dsp_cycles_per_scanline = (26591000 / 4) / (jaguar_screen_scanlines * 60);
510 memory_malloc_secure((void**)&jaguar_mainRam, 0x400000, "Jaguar 68k cpu ram");
511 memory_malloc_secure((void**)&jaguar_bootRom, 0x040000, "Jaguar 68k cpu boot rom");
512 memory_malloc_secure((void**)&jaguar_mainRom, 0x600000, "Jaguar 68k cpu rom");
513 memset(jaguar_mainRam, 0x00, 0x400000);
515 jaguar_rom_load_to(jaguar_bootRom, jaguar_bootRom_path, &romsize);
516 // No need to do this anymore, since Starcrap is gone!
517 // jaguar_byte_swap(jaguar_bootRom, romsize);
518 memcpy(jaguar_mainRam, jaguar_bootRom, 8);
519 // More braindead endian dependent crap
520 //WAS: *((uint32 *)&jaguar_mainRam[0]) = 0x00000020;
521 SET32(jaguar_mainRam, 0, 0x00200000);
523 #ifdef JAGUAR_WIP_RELEASE
525 strcpy(romLoadDialog_filePath, filename);
527 jaguar_open_rom(GetForegroundWindow(), "Load", "Jaguar roms (*.JAG)\0*.JAG\0\0");
529 //WAS: jaguar_load_cart(romLoadDialog_filePath, jaguar_mainRom, 0x0000, 0x20000080, 0);
530 jaguar_load_cart(romLoadDialog_filePath, jaguar_mainRom, 0x0000, 0x00802000, 0);
531 if ((jaguar_mainRom_crc32 == 0x3966698f) || (jaguar_mainRom_crc32 == 0x5e705756)
532 || (jaguar_mainRom_crc32 == 0x2630cbc4) || (jaguar_mainRom_crc32 == 0xd46437e8)
533 || (jaguar_mainRom_crc32 == 0x2630cbc4))
536 if ((jaguar_mainRom_crc32 == 0x6e90989f) || (jaguar_mainRom_crc32 == 0xfc8f0dcd)
537 || (jaguar_mainRom_crc32 == 0x2a512a83) || (jaguar_mainRom_crc32 == 0x41307601)
538 || (jaguar_mainRom_crc32 == 0x3c7bfda8) || (jaguar_mainRom_crc32 == 0x5e705756))
539 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
541 if (jaguar_mainRom_crc32 == 0x7ae20823)
544 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
545 dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
547 if (jaguar_mainRom_crc32 == 0xe21d0e2f)
550 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
551 dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
553 if (jaguar_mainRom_crc32 == 0x66f8914c)
555 gpu_cycles_per_scanline = (26591000 / 1) /(jaguar_screen_scanlines * 60);
557 if (jaguar_mainRom_crc32 == 0x5a5b9c68)
559 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
561 if (jaguar_mainRom_crc32 == 0xdcb0197a)
563 dsp_enabled = 0; // dsp not needed
564 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
565 //dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
567 if ((jaguar_mainRom_crc32 == 0x3966698f) || (jaguar_mainRom_crc32 == 0xe21d0e2f))
569 if (jaguar_mainRom_crc32 == 0x5e705756)
571 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
574 if (jaguar_mainRom_crc32 == 0x2630cbc4)
577 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
578 dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
581 if ((jaguar_mainRom_crc32 == 0xd46437e8) || (jaguar_mainRom_crc32 == 0xba74c3ed))
583 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
586 if (jaguar_mainRom_crc32 == 0x6e90989f)
587 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
589 if (jaguar_mainRom_crc32 == 0x41307601)
591 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
594 if (jaguar_mainRom_crc32 == 0x8483392b)
599 #else // #ifdef JAGUAR_WIP_RELEASE
600 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/flashback.jag",jaguar_mainRom,0x0000, 0x20000080,0);
601 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Pinball Fantasies.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
602 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/alien vs predator (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0);
603 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/cannon fodder (1995) (computer west).jag",jaguar_mainRom,0x0000, 0x20000080,0);
604 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/double dragon v (1995) (williams).jag",jaguar_mainRom,0x0000, 0x20000080,0);
605 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Dragon - The Bruce Lee Story.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
606 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Syndicate.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
607 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Theme Park.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
608 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Brutal Sports Football.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
609 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/International Sensible Soccer.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
610 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Defender 2000.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
611 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Fever Pitch Soccer.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
612 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Rayman.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
613 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Tempest 2000.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
614 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/zool 2 (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0);
615 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Bubsy - Fractured Furry Tails.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
616 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Raiden.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
617 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Dino Olympics.jag",jaguar_mainRom,0x0000, 0x20000080,0);
618 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/I-War.jag",jaguar_mainRom,0x0000, 0x20000080,0);
619 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Attack of the Mutant Penguins.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
620 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Cybermorph.jag",jaguar_mainRom,0x0000, 0x20000080,0);
621 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Troy Aikman NFL Football (1995) (Williams).jag",jaguar_mainRom,0x0000, 0x20000080,0);
622 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Power Drive Rally (1995) (TWI).jag",jaguar_mainRom,0x0000, 0x20000080,0);
623 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Zoop! (1996).jag",jaguar_mainRom,0x0000, 0x20000080,0);
624 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Missile Command 3D.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
625 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Hover Strike.jag",jaguar_mainRom,0x0000, 0x20000080,0);
626 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/worms.bin",jaguar_mainRom,0x0000, 0x20000080,0);
627 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Atari Kart.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
628 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/native.bin",jaguar_mainRam,0x5000, 0x50000000,0x00);
630 if (jaguar_mainRom_crc32==0xe21d0e2f)
633 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
634 dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
636 if (jaguar_mainRom_crc32==0x66f8914c)
638 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
640 if (jaguar_mainRom_crc32==0x5a5b9c68)
642 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
644 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Super Cross 3D.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
645 if (jaguar_mainRom_crc32==0xdcb0197a)
647 dsp_enabled=0; // dsp not needed
648 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
649 //dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
651 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/wolfenstein 3d (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0);
652 if ((jaguar_mainRom_crc32==0x3966698f)||(jaguar_mainRom_crc32==0xe21d0e2f))
654 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/NBA JAM.jag",jaguar_mainRom,0x0000, 0x20000080,0);
655 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Doom - Evil Unleashed.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
656 if (jaguar_mainRom_crc32==0x5e705756)
658 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
661 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Ultra Vortek.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
662 if (jaguar_mainRom_crc32==0x2630cbc4)
665 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
666 dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
669 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/fflbeta.rom",jaguar_mainRom,0x0000, 0x20000080,0);
670 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Fight for Your Life.jag",jaguar_mainRom,0x0000, 0x20000080,0);
671 if ((jaguar_mainRom_crc32==0xd46437e8)||(jaguar_mainRom_crc32==0xba74c3ed))
673 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
674 // dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
677 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Pitfall - The Mayan Adventure.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
678 if (jaguar_mainRom_crc32==0x6e90989f)
679 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
681 // missing some sprites
682 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Crescent Galaxy.jag",jaguar_mainRom,0x0000, 0x20000080,0);
683 if (jaguar_mainRom_crc32==0x41307601)
685 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
688 // missing vertical bar shades
689 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Phase Zero (2000) (PD).rom",jaguar_mainRom,0x0000, 0x20000080,0);
690 if (jaguar_mainRom_crc32==0x8483392b)
694 // cpu/dsp/gpu synchronization problems
697 // locks up during the game
698 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Club Drive.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
700 // no parallax floor, locks up at the start of the game
701 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Kasumi Ninja.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
703 // displaying the sound control dialog. no way to exit from it
704 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Checkered Flag.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
707 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Iron Soldier.jag",jaguar_mainRom,0x0000, 0x20000080,0);
709 // locks up at the start of the game
710 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Super Burnout.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
711 if (jaguar_mainRom_crc32==0x20ae75f4)
714 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
715 dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
717 // locks up at the start of the game
718 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Val D'Isere Skiing & Snowboarding (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0);
719 if (jaguar_mainRom_crc32==0x4664ebd1)
724 // fonctionne avec le gpu et le dsp activés et gpu à frequence nominale, et dsp à 1/4 de la frequence nominale
725 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/white men can't jump (1995).jag",jaguar_mainRom,0x0000, 0x20000080,0);
726 if (jaguar_mainRom_crc32==0x7ae20823)
729 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
731 // not working at all
732 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/Flip Out.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
733 if (jaguar_mainRom_crc32==0x6f57dcd2)
735 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
740 jaguar_load_cart("C:/ftp/jaguar/roms/roms/Ruiner.JAG",jaguar_mainRom,0x0000, 0x20000080,0);
741 if (jaguar_mainRom_crc32==0x6a7c7430)
746 if (jaguar_mainRom_crc32==0x2f032271)
749 dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
750 gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60);
752 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/tetris.bin",jaguar_mainRam,0x4fe4, 0x50000000,0x00);
753 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/painter.bin",jaguar_mainRam,0xffe4, 0x00000001,0x00);
754 // jaguar_load_cart("./roms/jagcd.rom",jaguar_mainRom,0x0000, 0x20000080,0);
756 // jaguar_load_cart("cart.jag",jaguar_mainRom,0x0000, 0x20000080,0);
759 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\Brain Dead 13.cdi");
760 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\baldies.cdi");
761 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\mystdemo.cdi");
762 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\battlemorph.cdi");
763 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\primalrage.cdi");
764 // cd_bios_boot("C:\\ftp\\jaguar\\cd\\Dragons Lair.cdi");
766 // jaguar_load_cart("C:/ftp/jaguar/roms/roms/raw.jag",jaguar_mainRam,0x4000, 0x40000000,0x00);
767 #endif // #ifdef JAGUAR_WIP_RELEASE
769 #ifdef JAGUAR_REAL_SPEED
770 gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
771 dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60);
778 memcpy(jaguar_mainRam, jaguar_bootRom, 8);
779 *((uint32 *)&jaguar_mainRam[0]) = 0x00000020;
783 m68k_set_cpu_type(M68K_CPU_TYPE_68000);
790 //////////////////////////////////////////////////////////////////////////////
792 //////////////////////////////////////////////////////////////////////////////
799 //////////////////////////////////////////////////////////////////////////////
800 unsigned jaguar_byte_read(unsigned int offset)
805 if (offset < 0x400000)
806 // data = (jaguar_mainRam[(offset^0x01) & 0x3FFFFF]);
807 data = (jaguar_mainRam[offset & 0x3FFFFF]);
808 else if ((offset >= 0x800000) && (offset < 0xC00000))
809 // data = (jaguar_mainRom[(offset^0x01)-0x800000]);
810 data = (jaguar_mainRom[offset - 0x800000]);
811 else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00))
812 data = cdrom_byte_read(offset);
813 else if ((offset >= 0xE00000) && (offset < 0xE40000))
814 // data = (jaguar_bootRom[(offset^0x01) & 0x3FFFF]);
815 data = (jaguar_bootRom[offset & 0x3FFFF]);
816 else if ((offset >= 0xF00000) && (offset < 0xF10000))
817 data = (tom_byte_read(offset));
818 else if ((offset >= 0xF10000) && (offset < 0xF20000))
819 data = (jerry_byte_read(offset));
821 data = jaguar_unknown_readbyte(offset);
825 //////////////////////////////////////////////////////////////////////////////
827 //////////////////////////////////////////////////////////////////////////////
834 //////////////////////////////////////////////////////////////////////////////
835 unsigned jaguar_word_read(unsigned int offset)
838 if (offset < 0x400000)
840 // return (jaguar_mainRam[(offset+1) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+0) & 0x3FFFFF];
841 return (jaguar_mainRam[(offset+0) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+1) & 0x3FFFFF];
843 else if ((offset >= 0x800000) && (offset < 0xC00000))
846 // return (jaguar_mainRom[offset+1] << 8) | jaguar_mainRom[offset+0];
847 return (jaguar_mainRom[offset+0] << 8) | jaguar_mainRom[offset+1];
849 else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00))
850 return cdrom_word_read(offset);
851 else if ((offset >= 0xE00000) && (offset < 0xE40000))
852 return *((uint16 *)&jaguar_bootRom[offset & 0x3FFFF]);
853 else if ((offset >= 0xF00000) && (offset < 0xF10000))
854 return tom_word_read(offset);
855 else if ((offset >= 0xF10000) && (offset < 0xF20000))
856 return jerry_word_read(offset);
858 return jaguar_unknown_readword(offset);
860 //////////////////////////////////////////////////////////////////////////////
862 //////////////////////////////////////////////////////////////////////////////
869 //////////////////////////////////////////////////////////////////////////////
870 void jaguar_byte_write(unsigned offset, unsigned data)
873 if (offset < 0x400000)
875 // jaguar_mainRam[(offset^0x01) & 0x3FFFFF] = data;
876 jaguar_mainRam[offset & 0x3FFFFF] = data;
879 else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00))
881 cdrom_byte_write(offset, data);
884 else if ((offset >= 0xF00000) && (offset < 0xF10000))
886 tom_byte_write(offset, data);
889 else if ((offset >= 0xF10000) && (offset < 0xF20000))
891 jerry_byte_write(offset, data);
895 jaguar_unknown_writebyte(offset, data);
897 //////////////////////////////////////////////////////////////////////////////
899 //////////////////////////////////////////////////////////////////////////////
906 //////////////////////////////////////////////////////////////////////////////
907 void jaguar_word_write(unsigned offset, unsigned data)
911 if (offset < 0x400000)
913 // jaguar_mainRam[(offset+0) & 0x3FFFFF] = data & 0xFF;
914 // jaguar_mainRam[(offset+1) & 0x3FFFFF] = (data>>8) & 0xFF;
915 jaguar_mainRam[(offset+0) & 0x3FFFFF] = (data>>8) & 0xFF;
916 jaguar_mainRam[(offset+1) & 0x3FFFFF] = data & 0xFF;
919 else if ((offset >= 0xDFFF00) && (offset < 0xDFFFFF))
921 cdrom_word_write(offset, data);
924 else if ((offset >= 0xF00000) && (offset < 0xF10000))
926 tom_word_write(offset, data);
929 else if ((offset >= 0xF10000) && (offset < 0xF20000))
931 jerry_word_write(offset, data);
935 jaguar_unknown_writeword(offset, data);
937 //////////////////////////////////////////////////////////////////////////////
939 //////////////////////////////////////////////////////////////////////////////
946 //////////////////////////////////////////////////////////////////////////////
947 unsigned jaguar_long_read(unsigned int offset)
949 /* uint32 data = jaguar_word_read(offset);
950 data = (data<<16) | jaguar_word_read(offset+2);
952 return (jaguar_word_read(offset) << 16) | jaguar_word_read(offset+2);
954 //////////////////////////////////////////////////////////////////////////////
956 //////////////////////////////////////////////////////////////////////////////
963 //////////////////////////////////////////////////////////////////////////////
964 void jaguar_long_write(unsigned offset, unsigned data)
966 jaguar_word_write(offset, data >> 16);
967 jaguar_word_write(offset+2, data & 0xFFFF);
969 //////////////////////////////////////////////////////////////////////////////
971 //////////////////////////////////////////////////////////////////////////////
978 //////////////////////////////////////////////////////////////////////////////
979 void jaguar_done(void)
981 fprintf(log_get(), "jaguar: top of stack: %08X\n", jaguar_long_read(0x001FFFF8));
982 // fprintf(log_get(),"jaguar: cd bios version 0x%.4x\n",jaguar_word_read(0x3004));
983 // fprintf(log_get(),"jaguar: vbl interrupt is %s\n",((tom_irq_enabled(IRQ_VBLANK))&&(jaguar_interrupt_handler_is_valid(64)))?"enabled":"disabled");
984 s68000show_context();
992 // jaguar_regionsDone();
993 memory_free(jaguar_mainRom);
994 memory_free(jaguar_bootRom);
995 memory_free(jaguar_mainRam);
996 // fprintf(log_get(),"jaguar_done()\n");
998 //////////////////////////////////////////////////////////////////////////////
1000 //////////////////////////////////////////////////////////////////////////////
1007 //////////////////////////////////////////////////////////////////////////////
1008 void jaguar_reset(void)
1010 // fprintf(log_get(),"jaguar_reset():\n");
1021 m68k_pulse_reset(); // Reset the 68000
1022 fprintf(log_get(), "\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7));
1024 //////////////////////////////////////////////////////////////////////////////
1026 //////////////////////////////////////////////////////////////////////////////
1030 //////////////////////////////////////////////////////////////////////////////
1031 void jaguar_reset_handler(void)
1034 //////////////////////////////////////////////////////////////////////////////
1036 //////////////////////////////////////////////////////////////////////////////
1040 //////////////////////////////////////////////////////////////////////////////
1041 void jaguar_exec(int16 * backbuffer, uint8 render)
1044 uint32 vblank_duration = tom_get_vdb();
1047 if ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64)))
1049 if (jaguar_word_read(0xF0004E) != 0xFFFF)
1051 tom_set_pending_video_int();
1052 // s68000interrupt(7, IRQ_VBLANK+64);
1053 // s68000flushInterrupts();
1054 m68k_set_irq(7); // IRQ_VBLANK+64??? Not autovectored??? No.
1055 // Could set a global variable here, to signal that this is a VBLANK interrupt...
1056 // Then again, since IRQ_VBLANK is set to zero, this would not be necessary in this case.
1059 for(i=0; i<vblank_duration; i++)
1061 /* uint32 invalid_instruction_address = s68000exec(m68k_cycles_per_scanline);
1062 if (invalid_instruction_address != 0x80000000)
1063 cd_bios_process(invalid_instruction_address);*/
1064 m68k_execute(m68k_cycles_per_scanline);
1065 // No CD handling... Hmm...
1068 tom_pit_exec(m68k_cycles_per_scanline);
1069 tom_exec_scanline(backbuffer, i, 0);
1070 jerry_pit_exec(m68k_cycles_per_scanline);
1071 jerry_i2s_exec(m68k_cycles_per_scanline);
1072 gpu_exec(gpu_cycles_per_scanline);
1074 dsp_exec(dsp_cycles_per_scanline);
1077 for (; i<jaguar_screen_scanlines; i++)
1079 /* uint32 invalid_instruction_address = s68000exec(m68k_cycles_per_scanline);
1080 if (invalid_instruction_address != 0x80000000)
1081 cd_bios_process(invalid_instruction_address);*/
1082 m68k_execute(m68k_cycles_per_scanline);
1083 // No CD handling... Hmm...
1085 tom_pit_exec(m68k_cycles_per_scanline);
1086 jerry_pit_exec(m68k_cycles_per_scanline);
1087 jerry_i2s_exec(m68k_cycles_per_scanline);
1088 tom_exec_scanline(backbuffer, i, render);
1089 gpu_exec(gpu_cycles_per_scanline);
1091 dsp_exec(dsp_cycles_per_scanline);
1092 backbuffer += tom_width;
1095 system_sound_update();