X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fjaguar.cpp;h=6ac2d2929ffc01403e3457fa5bcd67f1b006d38e;hb=986beba059356c432d020ef0aeff106b716217f2;hp=74c1de425f969453220b4cd3715a9ddcb106425d;hpb=0031c06df2f7f099ca5ecf1632f46b92f6b0dd79;p=virtualjaguar diff --git a/src/jaguar.cpp b/src/jaguar.cpp index 74c1de4..6ac2d29 100644 --- a/src/jaguar.cpp +++ b/src/jaguar.cpp @@ -9,45 +9,32 @@ // #include "jaguar.h" -#include "m68kdasmAG.h" -#include "crc32.h" +//#include "m68kdasmAG.h" //#define LOG_UNMAPPED_MEMORY_ACCESSES //#define SOUND_OUTPUT +#define CPU_DEBUG +#define JAGUAR_WIP_RELEASE +//Do this in makefile??? Yes! Could, but it's easier to define here... +//#define LOG_UNMAPPED_MEMORY_ACCESSES -// Some handy macros to help converting native endian to big endian (jaguar native) - -#define SET32(r, a, v) r[a] = ((v) & 0xFF000000) >> 24, r[a+1] = ((v) & 0x00FF0000) >> 16, \ - r[a+2] = ((v) & 0x0000FF00) >> 8, r[a+3] = (v) & 0x000000FF - -// -// Function Prototypes -// +// Private function prototypes unsigned jaguar_unknown_readbyte(unsigned address); unsigned jaguar_unknown_readword(unsigned address); void jaguar_unknown_writebyte(unsigned address, unsigned data); void jaguar_unknown_writeword(unsigned address, unsigned data); +void M68K_show_context(void); +// External variables -#ifdef SOUND_OUTPUT -int dsp_enabled = 1; -#else -int dsp_enabled = 0; -#endif -uint32 jaguar_active_memory_dumps = 0; -uint32 jaguar_use_bios = 0; -#define JAGUAR_WIP_RELEASE -#define JAGUAR_REAL_SPEED +extern bool hardwareTypeNTSC; // Set to false for PAL -// -// Bios path -// +// These values are overridden by command line switches... -//static char *jaguar_bootRom_path="c:/jaguarEmu/newload.img"; -static char * jaguar_bootRom_path = "./bios/jagboot.rom"; -//static char *jaguar_bootRom_path="./bios/JagOS.bin"; -char * jaguar_eeproms_path = "./eeproms/"; +bool dsp_enabled = false; +bool jaguar_use_bios = true; // Default is now to USE the BIOS +uint32 jaguar_active_memory_dumps = 0; uint32 jaguar_mainRom_crc32; @@ -56,11 +43,47 @@ static uint32 gpu_cycles_per_scanline; static uint32 dsp_cycles_per_scanline; static uint32 jaguar_screen_scanlines; -static uint8 * jaguar_mainRam = NULL; -static uint8 * jaguar_bootRom = NULL; -static uint8 * jaguar_mainRom = NULL; +/*static*/ uint8 * jaguar_mainRam = NULL; +/*static*/ uint8 * jaguar_bootRom = NULL; +/*static*/ uint8 * jaguar_mainRom = NULL; +// +// Callback function to detect illegal instructions +// +void M68KInstructionHook(void) +{ + uint32 m68kPC = m68k_get_reg(NULL, M68K_REG_PC); + +/* static char buffer[2048]; + m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000); + 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));//*/ + +/* if (m68kPC == 0x803F16) + { + WriteLog("M68K: Registers found at $803F16:\n"); + WriteLog( "\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC)); + for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++) + WriteLog( "\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog( "\n"); + for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++) + WriteLog( "\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); + }*/ + + if (!m68k_is_valid_instruction(jaguar_word_read(m68kPC), M68K_CPU_TYPE_68000)) + { + WriteLog("\nEncountered illegal instruction at %08X!!!\n\nAborting!\n", m68kPC); + uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7); + WriteLog("M68K: Top of stack: %08X. Stack trace:\n", jaguar_long_read(topOfStack)); + for(int i=0; i<10; i++) + WriteLog("%06X: %08X\n", topOfStack - (i * 4), jaguar_long_read(topOfStack - (i * 4))); + WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled"); + M68K_show_context(); + log_done(); + exit(0); + } +} + // // Musashi 68000 read/write/IRQ functions // @@ -69,7 +92,9 @@ int irq_ack_handler(int level) { int vector = M68K_INT_ACK_AUTOVECTOR; - if (level = 7) + // The GPU/DSP/etc are probably *not* issuing an NMI, but it seems to work OK... + + if (level == 7) { m68k_set_irq(0); // Clear the IRQ... vector = 64; // Set user interrupt #0 @@ -78,12 +103,9 @@ int irq_ack_handler(int level) return vector; } -//Do this in makefile??? Yes! -//#define LOG_UNMAPPED_MEMORY_ACCESSES 1 - unsigned int m68k_read_memory_8(unsigned int address) { -//fprintf(log_get(), "[RM8] Addr: %08X\n", address); +//WriteLog( "[RM8] Addr: %08X\n", address); unsigned int retVal = 0; if ((address >= 0x000000) && (address <= 0x3FFFFF)) @@ -104,9 +126,36 @@ unsigned int m68k_read_memory_8(unsigned int address) return retVal; } +void gpu_dump_disassembly(void); +void gpu_dump_registers(void); + unsigned int m68k_read_memory_16(unsigned int address) { -//fprintf(log_get(), "[RM16] Addr: %08X\n", address); +//WriteLog( "[RM16] Addr: %08X\n", address); +/*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005FBA) +// for(int i=0; i<10000; i++) + WriteLog("[M68K] In routine #6!\n");//*/ +//if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00006696) // GPU Program #4 +//if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005B3C) // GPU Program #2 +/*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005BA8) // GPU Program #3 +{ + WriteLog("[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, tom_word_read(address)); + gpu_dump_registers(); + gpu_dump_disassembly(); +// for(int i=0; i<10000; i++) +// WriteLog( "[M68K] About to run GPU!\n"); +}//*/ +//WriteLog( "[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +/*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x00006696 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x000066A8) +{ + if (address == 0x000066A0) + { + gpu_dump_registers(); + gpu_dump_disassembly(); + } + for(int i=0; i<10000; i++) + WriteLog( "[M68K] About to run GPU! (Addr:%08X, data:%04X)\n", address, tom_word_read(address)); +}//*/ unsigned int retVal = 0; if ((address >= 0x000000) && (address <= 0x3FFFFE)) @@ -123,7 +172,7 @@ unsigned int m68k_read_memory_16(unsigned int address) retVal = jerry_word_read(address); else //{ -//fprintf(log_get(), "[RM16] Unknown address: %08X\n", address); +//WriteLog( "[RM16] Unknown address: %08X\n", address); retVal = jaguar_unknown_readword(address); //} @@ -132,13 +181,15 @@ unsigned int m68k_read_memory_16(unsigned int address) unsigned int m68k_read_memory_32(unsigned int address) { -//fprintf(log_get(), "--> [RM32]\n"); +//WriteLog( "--> [RM32]\n"); return (m68k_read_memory_16(address) << 16) | m68k_read_memory_16(address + 2); } void m68k_write_memory_8(unsigned int address, unsigned int value) { -//fprintf(log_get(), "[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +//if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F)) +// WriteLog("M68K: Writing %02X at %08X\n", value, address); +//WriteLog( "[WM8 PC=%08X] Addr: %08X, val: %02X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); if ((address >= 0x000000) && (address <= 0x3FFFFF)) jaguar_mainRam[address] = value; else if ((address >= 0xDFFF00) && (address <= 0xDFFFFF)) @@ -153,7 +204,42 @@ void m68k_write_memory_8(unsigned int address, unsigned int value) void m68k_write_memory_16(unsigned int address, unsigned int value) { -//fprintf(log_get(), "[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +extern int dsp_pc;//, dsp_control; +if (address == 0xF1A116 && (value & 0x01)) +{ + WriteLog(" M68K(16): DSP is GO! (DSP_PC: %08X)\n\n", dsp_pc); + +/* static char buffer[512]; + uint32 j = 0xF1B000; + while (j <= 0xF1BFFF) + { + uint32 oldj = j; + j += dasmjag(JAGUAR_DSP, buffer, j); + WriteLog( "\t%08X: %s\n", oldj, buffer); + } + WriteLog( "\n");//*/ +} +//else +// WriteLog("M68K(16): DSP halted... (Old value: %08X)\n", dsp_control); + +//if ((address >= 0x1FF020 && address <= 0x1FF03F) || (address >= 0x1FF820 && address <= 0x1FF83F)) +// WriteLog("M68K: Writing %04X at %08X\n", value, address); +//WriteLog( "[WM16 PC=%08X] Addr: %08X, val: %04X\n", m68k_get_reg(NULL, M68K_REG_PC), address, value); +//if (address >= 0xF02200 && address <= 0xF0229F) +// WriteLog("M68K: Writing to blitter --> %04X at %08X\n", value, address); +//if (address >= 0x0E75D0 && address <= 0x0E75E7) +// WriteLog("M68K: Writing %04X at %08X, M68K PC=%08X\n", value, address, m68k_get_reg(NULL, M68K_REG_PC)); +/*extern uint32 totalFrames; +extern bool suppressOutput; +if (totalFrames >= 59) + suppressOutput = false;//*/ +/*if (address == 0xF02114) + WriteLog("M68K: Writing to GPU_CTRL (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC)); +if (address == 0xF02110) + WriteLog("M68K: Writing to GPU_PC (frame:%u)... [M68K PC:%08X]\n", totalFrames, m68k_get_reg(NULL, M68K_REG_PC));//*/ +//if (address >= 0xF03B00 && address <= 0xF03DFF) +// WriteLog("M68K: Writing %04X to %08X...\n", value, address); + if ((address >= 0x000000) && (address <= 0x3FFFFE)) { jaguar_mainRam[address] = value >> 8; @@ -171,19 +257,19 @@ void m68k_write_memory_16(unsigned int address, unsigned int value) void m68k_write_memory_32(unsigned int address, unsigned int value) { -//fprintf(log_get(), "--> [WM32]\n"); +extern int dsp_pc;//, dsp_control; +if (address == 0xF1A114 && (value & 0x01)) + WriteLog("M68K(32): DSP is GO! (DSP_PC: %08X)\n", dsp_pc); +//else +// WriteLog("M68K(32): DSP halted... (Old value: %08X)\n", dsp_control); + +//WriteLog( "--> [WM32]\n"); m68k_write_memory_16(address, value >> 16); m68k_write_memory_16(address + 2, value & 0xFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint32 jaguar_get_handler(uint32 i) { // return (jaguar_word_read(i<<2) << 16) | jaguar_word_read((i<<2) + 2); @@ -191,57 +277,6 @@ uint32 jaguar_get_handler(uint32 i) return jaguar_long_read(i * 4); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -static char romLoadDialog_filePath[1024]; -#ifndef __PORT__ -static char romLoadDialog_initialDirectory[1024]; - -int jaguar_open_rom(HWND hWnd, char * title, char * filterString) -{ - OPENFILENAME ofn; - romLoadDialog_initialDirectory[0] = 0; - romLoadDialog_filePath[0] = 0; - - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = hWnd; - ofn.lpstrFile = romLoadDialog_filePath; - ofn.nMaxFile = sizeof(romLoadDialog_filePath); - ofn.lpstrFilter = filterString; - ofn.nFilterIndex = 0; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = (const char *)romLoadDialog_initialDirectory; - ofn.lpstrTitle = title; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - - if(GetOpenFileName(&ofn) == FALSE) - { - DWORD res = CommDlgExtendedError(); - SendMessage(hWnd, WM_MOVE, 0,0); - return 0; - } - - - SendMessage(hWnd, WM_MOVE, 0,0); - return 1; -} -#endif -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// uint32 jaguar_interrupt_handler_is_valid(uint32 i) { uint32 handler = jaguar_get_handler(i); @@ -250,49 +285,37 @@ uint32 jaguar_interrupt_handler_is_valid(uint32 i) else return 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void s68000show_context(void) + +void M68K_show_context(void) { -// fprintf(log_get(),"\t68k PC=0x%.6x\n",s68000readPC()); - fprintf(log_get(),"\t68k PC=0x%.6x\n", m68k_get_reg(NULL, M68K_REG_PC)); -// for (int i=0;i<8;i++) -// fprintf(log_get(),"\tD%i = 0x%.8x\n",i,s68000context.dreg[i]); + WriteLog( "\t68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC)); for(int i=M68K_REG_D0; i<=M68K_REG_D7; i++) - fprintf(log_get(), "\tD%i = 0x%.8x\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); - fprintf(log_get(), "\n"); -// for (i=0;i<8;i++) -// fprintf(log_get(),"\tA%i = 0x%.8x\n",i,s68000context.areg[i]); + WriteLog( "\tD%i = %08X\n", i-M68K_REG_D0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog( "\n"); for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++) - fprintf(log_get(), "\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); + WriteLog( "\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); - fprintf(log_get(), "68k dasm\n"); + WriteLog( "68K disasm\n"); // jaguar_dasm(s68000readPC()-0x1000,0x20000); -// jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x1000, 0x20000); jaguar_dasm(m68k_get_reg(NULL, M68K_REG_PC) - 0x80, 0x200); - fprintf(log_get(), "..................\n"); +// jaguar_dasm(0x5000, 0x14414); + WriteLog( "..................\n"); if (tom_irq_enabled(IRQ_VBLANK)) { - fprintf(log_get(), "vblank int: enabled\n"); + WriteLog( "vblank int: enabled\n"); jaguar_dasm(jaguar_get_handler(64), 0x200); } else - fprintf(log_get(), "vblank int: disabled\n"); - fprintf(log_get(), "..................\n"); + WriteLog( "vblank int: disabled\n"); + + WriteLog( "..................\n"); for(int i=0; i<256; i++) - fprintf(log_get(), "handler %03i at $%08X\n", i, jaguar_get_handler(i)); + WriteLog( "handler %03i at $%08X\n", i, (unsigned int)jaguar_get_handler(i)); } -// Starscream crap ripped out... - // // Unknown read/write byte/word routines // @@ -300,21 +323,21 @@ void s68000show_context(void) void jaguar_unknown_writebyte(unsigned address, unsigned data) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - fprintf(log_get(), "jaguar: unknown byte %02X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog( "jaguar: unknown byte %02X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC)); #endif } void jaguar_unknown_writeword(unsigned address, unsigned data) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - fprintf(log_get(), "jaguar: unknown word %04X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog( "jaguar: unknown word %04X write at %08X (PC=%06X)\n", data, address, m68k_get_reg(NULL, M68K_REG_PC)); #endif } unsigned jaguar_unknown_readbyte(unsigned address) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - fprintf(log_get(), "jaguar: unknown byte read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog( "jaguar: unknown byte read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC)); #endif return 0xFF; } @@ -322,450 +345,49 @@ unsigned jaguar_unknown_readbyte(unsigned address) unsigned jaguar_unknown_readword(unsigned address) { #ifdef LOG_UNMAPPED_MEMORY_ACCESSES - fprintf(log_get(), "jaguar: unknown word read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC)); + WriteLog( "Jaguar: Unknown word read at %08X (PC=%06X)\n", address, m68k_get_reg(NULL, M68K_REG_PC)); #endif return 0xFFFF; } // -// Jaguar ROM loading +// Disassemble M68K instructions at the given offset // -uint8 * jaguar_rom_load(char * path, uint32 * romSize) +unsigned int m68k_read_disassembler_8(unsigned int address) { - __int64 filepos; - - fprintf(log_get(), "jaguar: loading %s...", path); - FILE * fp = fopen(path, "rb"); - if (fp == NULL) - { - fprintf(log_get(), "failed\n"); - log_done(); - exit(0); - return NULL; - } - fseek(fp, 0, SEEK_END); - - /* Added by SDLEMU (http://sdlemu.ngemu.com) */ - /* Added for GCC UNIX compatibility */ -#ifdef __GCCUNIX__ - fgetpos(fp, (fpos_t *)&filepos); -#else - fgetpos(fp, &filepos); -#endif - - *romSize = (int)filepos; - fseek(fp, 0, SEEK_SET); - uint8 * rom = (uint8 *)malloc(*romSize); - fread(rom, 1, *romSize, fp); - fclose(fp); - fprintf(log_get(), "ok (%i bytes)\n", *romSize); -// jaguar_mainRom_crc32=crc32_calcCheckSum(jaguar_mainRom,*romSize); -// fprintf(log_get(),"crc: 0x%.8x\n",jaguar_mainRom_crc32); - return rom; + return m68k_read_memory_8(address); } -// -// Load a ROM at a specific address -// - -void jaguar_rom_load_to(uint8 * rom, char * path, uint32 * romSize) +unsigned int m68k_read_disassembler_16(unsigned int address) { - __int64 filepos; - - fprintf(log_get(), "jaguar: loading %s...", path); - FILE * fp = fopen(path, "rb"); - if (fp == NULL) - { - fprintf(log_get(), "failed\n"); - log_done(); - exit(0); - return; - } - fseek(fp, 0, SEEK_END); - - /* Added by SDLEMU (http://sdlemu.ngemu.com) */ - /* Added for GCC UNIX compatibility */ -#ifdef __GCCUNIX__ - fgetpos(fp, (fpos_t *)&filepos); -#else - fgetpos(fp, &filepos); -#endif - - *romSize = (int)filepos; - fseek(fp, 0, SEEK_SET); - fread(rom, 1, *romSize, fp); - fclose(fp); - fprintf(log_get(), "ok (%i bytes)\n", *romSize); + return m68k_read_memory_16(address); } -// -// Byte swap a region of memory -// - -/*void jaguar_byte_swap(uint8 * rom, uint32 size) +unsigned int m68k_read_disassembler_32(unsigned int address) { - while (size > 0) - { - uint8 tmp = rom[0]; - rom[0] = rom[1]; - rom[1] = tmp; - rom += 2; - size -= 2; - } -}*/ - -// -// Disassemble instructions at the given offset -// + return m68k_read_memory_32(address); +} void jaguar_dasm(uint32 offset, uint32 qt) { #ifdef CPU_DEBUG - static char buffer[2048], mem[64]; + static char buffer[2048];//, mem[64]; int pc = offset, oldpc; - for(int i=0; i>16) | (boot<<16), 32*4); - jaguar_dasm(boot, 32*4); -} - -// -// Jaguar initialization -// - -#ifdef __PORT__ -void jaguar_init(const char * filename) -#else -void jaguar_init(void) -#endif -{ - uint32 romsize; - - jaguar_screen_scanlines = 525; // PAL screen size - m68k_cycles_per_scanline = 13300000 / (jaguar_screen_scanlines * 60); - gpu_cycles_per_scanline = (26591000 / 4) / (jaguar_screen_scanlines * 60); - dsp_cycles_per_scanline = (26591000 / 4) / (jaguar_screen_scanlines * 60); - - memory_malloc_secure((void **)&jaguar_mainRam, 0x400000, "Jaguar 68k cpu ram"); - memory_malloc_secure((void **)&jaguar_bootRom, 0x040000, "Jaguar 68k cpu boot rom"); - memory_malloc_secure((void **)&jaguar_mainRom, 0x600000, "Jaguar 68k cpu rom"); - memset(jaguar_mainRam, 0x00, 0x400000); - - jaguar_rom_load_to(jaguar_bootRom, jaguar_bootRom_path, &romsize); -// No need to do this anymore, since Starcrap is gone! -// jaguar_byte_swap(jaguar_bootRom, romsize); - memcpy(jaguar_mainRam, jaguar_bootRom, 8); -// More braindead endian dependent crap -//WAS: *((uint32 *)&jaguar_mainRam[0]) = 0x00000020; - SET32(jaguar_mainRam, 0, 0x00200000); - -#ifdef JAGUAR_WIP_RELEASE -#ifdef __PORT__ - strcpy(romLoadDialog_filePath, filename); -#else - jaguar_open_rom(GetForegroundWindow(), "Load", "Jaguar roms (*.JAG)\0*.JAG\0\0"); -#endif -//WAS: jaguar_load_cart(romLoadDialog_filePath, jaguar_mainRom, 0x0000, 0x20000080, 0); - jaguar_load_cart(romLoadDialog_filePath, jaguar_mainRom, 0x0000, 0x00802000, 0); - -//JLH: -/* if (jaguar_mainRom_crc32 == 0xA9F8A00E) - { - dsp_enabled = 1; - fprintf(log_get(), "--> Rayman detected, DSP enabled...\n"); - }//*/ - - - if ((jaguar_mainRom_crc32 == 0x3966698f) || (jaguar_mainRom_crc32 == 0x5e705756) - || (jaguar_mainRom_crc32 == 0x2630cbc4) || (jaguar_mainRom_crc32 == 0xd46437e8) - || (jaguar_mainRom_crc32 == 0x2630cbc4)) - dsp_enabled = 1; - - if ((jaguar_mainRom_crc32 == 0x6e90989f) || (jaguar_mainRom_crc32 == 0xfc8f0dcd) - || (jaguar_mainRom_crc32 == 0x2a512a83) || (jaguar_mainRom_crc32 == 0x41307601) - || (jaguar_mainRom_crc32 == 0x3c7bfda8) || (jaguar_mainRom_crc32 == 0x5e705756)) - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - - if (jaguar_mainRom_crc32 == 0x7ae20823) - { - dsp_enabled = 1; - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - } - if (jaguar_mainRom_crc32 == 0xe21d0e2f) - { - dsp_enabled = 1; - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - } - if (jaguar_mainRom_crc32 == 0x66f8914c) - { - gpu_cycles_per_scanline = (26591000 / 1) /(jaguar_screen_scanlines * 60); - } - if (jaguar_mainRom_crc32 == 0x5a5b9c68) - { - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - } - if (jaguar_mainRom_crc32 == 0xdcb0197a) - { - dsp_enabled = 0; // dsp not needed - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - //dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } - if ((jaguar_mainRom_crc32 == 0x3966698f) || (jaguar_mainRom_crc32 == 0xe21d0e2f)) - dsp_enabled = 1; - if (jaguar_mainRom_crc32 == 0x5e705756) - { - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_enabled = 1; - } - if (jaguar_mainRom_crc32 == 0x2630cbc4) - { - // ultra vortek - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_enabled = 1; - } - if ((jaguar_mainRom_crc32 == 0xd46437e8) || (jaguar_mainRom_crc32 == 0xba74c3ed)) - { - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_enabled = 1; - } - if (jaguar_mainRom_crc32 == 0x6e90989f) - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - - if (jaguar_mainRom_crc32 == 0x41307601) - { - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - } - - if (jaguar_mainRom_crc32 == 0x8483392b) - { - dsp_enabled = 1; - } - -#else // #ifdef JAGUAR_WIP_RELEASE -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/flashback.jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Pinball Fantasies.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/alien vs predator (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/cannon fodder (1995) (computer west).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/double dragon v (1995) (williams).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Dragon - The Bruce Lee Story.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Syndicate.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Theme Park.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Brutal Sports Football.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/International Sensible Soccer.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Defender 2000.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Fever Pitch Soccer.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Rayman.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Tempest 2000.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/zool 2 (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Bubsy - Fractured Furry Tails.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Raiden.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Dino Olympics.jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/I-War.jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Attack of the Mutant Penguins.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Cybermorph.jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Troy Aikman NFL Football (1995) (Williams).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Power Drive Rally (1995) (TWI).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Zoop! (1996).jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Missile Command 3D.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Hover Strike.jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/worms.bin",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Atari Kart.JAG",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/native.bin",jaguar_mainRam,0x5000, 0x50000000,0x00); - - if (jaguar_mainRom_crc32==0xe21d0e2f) - { - dsp_enabled=1; - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } - if (jaguar_mainRom_crc32==0x66f8914c) - { - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } - if (jaguar_mainRom_crc32==0x5a5b9c68) - { - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Super Cross 3D.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0xdcb0197a) - { - dsp_enabled=0; // dsp not needed - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - //dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/wolfenstein 3d (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0); - if ((jaguar_mainRom_crc32==0x3966698f)||(jaguar_mainRom_crc32==0xe21d0e2f)) - dsp_enabled=1; -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/NBA JAM.jag",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Doom - Evil Unleashed.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x5e705756) - { - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_enabled=1; - } -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Ultra Vortek.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x2630cbc4) - { - // ultra vortek - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_enabled=1; - } -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/fflbeta.rom",jaguar_mainRom,0x0000, 0x20000080,0); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Fight for Your Life.jag",jaguar_mainRom,0x0000, 0x20000080,0); - if ((jaguar_mainRom_crc32==0xd46437e8)||(jaguar_mainRom_crc32==0xba74c3ed)) - { - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); -// dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_enabled=1; - } -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Pitfall - The Mayan Adventure.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x6e90989f) - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - -// missing some sprites -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Crescent Galaxy.jag",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x41307601) - { - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } - -// missing vertical bar shades -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Phase Zero (2000) (PD).rom",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x8483392b) - { - dsp_enabled=1; - } -// cpu/dsp/gpu synchronization problems - - -// locks up during the game -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Club Drive.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - -// no parallax floor, locks up at the start of the game -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Kasumi Ninja.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - -// displaying the sound control dialog. no way to exit from it -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Checkered Flag.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - -// no 3d -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Iron Soldier.jag",jaguar_mainRom,0x0000, 0x20000080,0); - -// locks up at the start of the game -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Super Burnout.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x20ae75f4) - { - dsp_enabled=1; - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } -// locks up at the start of the game -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Val D'Isere Skiing & Snowboarding (1994).jag",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x4664ebd1) - { - dsp_enabled=1; - } - -// fonctionne avec le gpu et le dsp activés et gpu à frequence nominale, et dsp à 1/4 de la frequence nominale -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/white men can't jump (1995).jag",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x7ae20823) - { - dsp_enabled=1; - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - } -// not working at all -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/Flip Out.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x6f57dcd2) - { - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - dsp_enabled=0; - - } - - jaguar_load_cart("C:/ftp/jaguar/roms/roms/Ruiner.JAG",jaguar_mainRom,0x0000, 0x20000080,0); - if (jaguar_mainRom_crc32==0x6a7c7430) - { - dsp_enabled=1; - } - - if (jaguar_mainRom_crc32==0x2f032271) - { - dsp_enabled=1; - dsp_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); - gpu_cycles_per_scanline=(26591000/1) /((jaguar_screen_scanlines)*60); + WriteLog("%08X: %s\n", oldpc, buffer);//*/ + oldpc = pc; + pc += m68k_disassemble(buffer, pc, M68K_CPU_TYPE_68000); + WriteLog("%08X: %s\n", oldpc, buffer);//*/ } -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/tetris.bin",jaguar_mainRam,0x4fe4, 0x50000000,0x00); -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/painter.bin",jaguar_mainRam,0xffe4, 0x00000001,0x00); -// jaguar_load_cart("./roms/jagcd.rom",jaguar_mainRom,0x0000, 0x20000080,0); - -// jaguar_load_cart("cart.jag",jaguar_mainRom,0x0000, 0x20000080,0); - - -// cd_bios_boot("C:\\ftp\\jaguar\\cd\\Brain Dead 13.cdi"); -// cd_bios_boot("C:\\ftp\\jaguar\\cd\\baldies.cdi"); -// cd_bios_boot("C:\\ftp\\jaguar\\cd\\mystdemo.cdi"); -// cd_bios_boot("C:\\ftp\\jaguar\\cd\\battlemorph.cdi"); -// cd_bios_boot("C:\\ftp\\jaguar\\cd\\primalrage.cdi"); -// cd_bios_boot("C:\\ftp\\jaguar\\cd\\Dragons Lair.cdi"); - -// jaguar_load_cart("C:/ftp/jaguar/roms/roms/raw.jag",jaguar_mainRam,0x4000, 0x40000000,0x00); -#endif // #ifdef JAGUAR_WIP_RELEASE - -#ifdef JAGUAR_REAL_SPEED - gpu_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); - dsp_cycles_per_scanline = (26591000 / 1) / (jaguar_screen_scanlines * 60); #endif -#ifdef SOUND_OUTPUT - ws_audio_init(); -#endif - if (jaguar_use_bios) - { - memcpy(jaguar_mainRam, jaguar_bootRom, 8); -// *((uint32 *)&jaguar_mainRam[0]) = 0x00000020; -// SET32(jaguar_mainRam, 0, 0x00200000); - } - -// s68000init(); - m68k_set_cpu_type(M68K_CPU_TYPE_68000); - gpu_init(); - dsp_init(); - tom_init(); - jerry_init(); - cdrom_init(); } unsigned jaguar_byte_read(unsigned int offset) @@ -797,6 +419,10 @@ unsigned jaguar_byte_read(unsigned int offset) unsigned jaguar_word_read(unsigned int offset) { +//TEMP--Mirror of F03000? +/*if (offset >= 0xF0B000 && offset <= 0xF0BFFF) +WriteLog( "[JWR16] --> Possible GPU RAM mirror access! [%08X]\n", offset);//*/ + offset &= 0xFFFFFF; if (offset <= 0x3FFFFE) { @@ -818,7 +444,10 @@ unsigned jaguar_word_read(unsigned int offset) else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE)) return tom_word_read(offset); else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE)) +//{ +//WriteLog("Reading from JERRY offset %08X...\n", offset); return jerry_word_read(offset); +//} return jaguar_unknown_readword(offset); } @@ -854,6 +483,23 @@ void jaguar_byte_write(unsigned offset, unsigned data) void jaguar_word_write(unsigned offset, unsigned data) { +extern int dsp_pc;//, dsp_control; +if (offset == 0xF1A116 && (data & 0x01)) + WriteLog(" JagWW: DSP is GO! (DSP_PC: %08X)\n", dsp_pc); +//else +// WriteLog("JagWW: DSP halted... (Old value: %08X)\n", dsp_control); + +//extern int blit_start_log; +//if (blit_start_log) +/*{ + if (offset == 0x0674DE) + WriteLog( "[JWW16] Bad write starting @ 0674DE! [%04X]\n", data); +}//*/ +//TEMP--Mirror of F03000? +//if (offset >= 0xF0B000 && offset <= 0xF0BFFF) +//WriteLog( "[JWW16] --> Possible GPU RAM mirror access! [%08X]", offset); +//if ((offset >= 0x1FF020 && offset <= 0x1FF03F) || (offset >= 0x1FF820 && offset <= 0x1FF83F)) +// WriteLog("JagWW: Writing %04X at %08X\n", data, offset); offset &= 0xFFFFFF; if (offset <= 0x3FFFFE) @@ -885,27 +531,94 @@ void jaguar_word_write(unsigned offset, unsigned data) unsigned jaguar_long_read(unsigned int offset) { -/* uint32 data = jaguar_word_read(offset); - data = (data<<16) | jaguar_word_read(offset+2); - return data;*/ return (jaguar_word_read(offset) << 16) | jaguar_word_read(offset+2); } void jaguar_long_write(unsigned offset, unsigned data) { +extern int dsp_pc;//, dsp_control; +if (offset == 0xF1A114 && (data & 0x01)) + WriteLog("JagLW: DSP is GO! (DSP_PC: %08X)\n", dsp_pc); +//else +// WriteLog("JagLW: DSP halted... (Old value: %08X)\n", dsp_control); + jaguar_word_write(offset, data >> 16); jaguar_word_write(offset+2, data & 0xFFFF); } -void jaguar_done(void) +// +// Jaguar console initialization +// +void jaguar_init(void) { - fprintf(log_get(), "jaguar_done() ...START\n"); -#ifdef CPU_DEBUG - fprintf(log_get(), "jaguar: top of stack: %08X\n", jaguar_long_read(0x001FFFF8)); -// fprintf(log_get(),"jaguar: cd bios version 0x%.4x\n",jaguar_word_read(0x3004)); -// fprintf(log_get(),"jaguar: vbl interrupt is %s\n",((tom_irq_enabled(IRQ_VBLANK))&&(jaguar_interrupt_handler_is_valid(64)))?"enabled":"disabled"); - s68000show_context(); + memory_malloc_secure((void **)&jaguar_mainRam, 0x400000, "Jaguar 68K CPU RAM"); + memory_malloc_secure((void **)&jaguar_bootRom, 0x040000, "Jaguar 68K CPU BIOS ROM"); + memory_malloc_secure((void **)&jaguar_mainRom, 0x600000, "Jaguar 68K CPU ROM"); + memset(jaguar_mainRam, 0x00, 0x400000); +// memset(jaguar_mainRom, 0xFF, 0x200000); // & set it to all Fs... + memset(jaguar_mainRom, 0x00, 0x200000); // & set it to all 0s... + +// cd_bios_boot("C:\\ftp\\jaguar\\cd\\Brain Dead 13.cdi"); +// cd_bios_boot("C:\\ftp\\jaguar\\cd\\baldies.cdi"); +// cd_bios_boot("C:\\ftp\\jaguar\\cd\\mystdemo.cdi"); +// cd_bios_boot("C:\\ftp\\jaguar\\cd\\battlemorph.cdi"); +// cd_bios_boot("C:\\ftp\\jaguar\\cd\\primalrage.cdi"); +// cd_bios_boot("C:\\ftp\\jaguar\\cd\\Dragons Lair.cdi"); + +// NTSC PAL +// GPU/DSP/video clock rate 26.590906 26.593900 +// 68000 clock rate 13.295453 13.296950 +// (clock rates in MHz) + + // Should these be hardwired or read from VP? + jaguar_screen_scanlines = (hardwareTypeNTSC ? 524 : 624); +//Should the divisor be 50 for PAL??? Let's try it! + m68k_cycles_per_scanline = (hardwareTypeNTSC ? 13295453 : 13296950) / (jaguar_screen_scanlines * (hardwareTypeNTSC ? 60 : 50)); + gpu_cycles_per_scanline = dsp_cycles_per_scanline + = (hardwareTypeNTSC ? 26590906 : 26593900) / (jaguar_screen_scanlines * (hardwareTypeNTSC ? 60 : 50)); + +#ifdef SOUND_OUTPUT + ws_audio_init(); #endif + + m68k_set_cpu_type(M68K_CPU_TYPE_68000); + gpu_init(); + dsp_init(); + tom_init(); + jerry_init(); + cdrom_init(); +} + +void jaguar_done(void) +{ +//#ifdef CPU_DEBUG +// for(int i=M68K_REG_A0; i<=M68K_REG_A7; i++) +// WriteLog("\tA%i = 0x%.8x\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i)); + int32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7); + WriteLog("M68K: Top of stack: %08X. Stack trace:\n", jaguar_long_read(topOfStack)); + for(int i=-2; i<9; i++) + WriteLog("%06X: %08X\n", topOfStack + (i * 4), jaguar_long_read(topOfStack + (i * 4))); + +/* WriteLog("\nM68000 disassembly at $802288...\n"); + jaguar_dasm(0x802288, 3); + WriteLog("\nM68000 disassembly at $802200...\n"); + jaguar_dasm(0x802200, 500); + WriteLog("\nM68000 disassembly at $802518...\n"); + jaguar_dasm(0x802518, 100);//*/ + +/* WriteLog("\n\nM68000 disassembly at $803F00 (look @ $803F2A)...\n"); + jaguar_dasm(0x803F00, 500); + WriteLog("\n");//*/ + +/* WriteLog("\n\nM68000 disassembly at $802B00 (look @ $802B5E)...\n"); + jaguar_dasm(0x802B00, 500); + WriteLog("\n");//*/ + +// WriteLog("Jaguar: CD BIOS version %04X\n", jaguar_word_read(0x3004)); + WriteLog("Jaguar: Interrupt enable = %02X\n", tom_byte_read(0xF000E1) & 0x1F); + WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled"); + M68K_show_context(); +//#endif #ifdef SOUND_OUTPUT ws_audio_done(); #endif @@ -913,16 +626,31 @@ void jaguar_done(void) cdrom_done(); tom_done(); jerry_done(); -// jaguar_regionsDone(); memory_free(jaguar_mainRom); memory_free(jaguar_bootRom); memory_free(jaguar_mainRam); - fprintf(log_get(), "jaguar_done() ...END\n"); } void jaguar_reset(void) { -// fprintf(log_get(),"jaguar_reset():\n"); + if (jaguar_use_bios) + memcpy(jaguar_mainRam, jaguar_bootRom, 8); + else + { + SET32(jaguar_mainRam, 4, 0x00802000); + // Handle PD stuff... + // This should definitely go elsewhere (like in the cart load section)! + if (jaguar_mainRom[0] == 0x60 && jaguar_mainRom[1] == 0x1A) + { + uint32 runAddress = GET32(jaguar_mainRom, 0x2A); + uint32 progLength = GET32(jaguar_mainRom, 0x02); + WriteLog("Setting up PD ROM... Run address: %08X, length: %08X\n", runAddress, progLength); + memcpy(jaguar_mainRam + runAddress, jaguar_mainRom + 0x2E, progLength); + SET32(jaguar_mainRam, 4, runAddress); + } + } + +// WriteLog("jaguar_reset():\n"); #ifdef SOUND_OUTPUT ws_audio_reset(); #endif @@ -932,23 +660,22 @@ void jaguar_reset(void) gpu_reset(); dsp_reset(); cdrom_reset(); -// s68000reset(); m68k_pulse_reset(); // Reset the 68000 - fprintf(log_get(), "\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7)); + WriteLog( "\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7)); } void jaguar_reset_handler(void) { } -void jaguar_exec(int16 * backbuffer, uint8 render) +void jaguar_exec(int16 * backbuffer, bool render) { uint32 i, vblank_duration = tom_get_vdb(); // vblank if ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) { - if (jaguar_word_read(0xF0004E) != 0xFFFF) + if (jaguar_word_read(0xF0004E) != 0x07FF) // VI (11 bits wide!) { tom_set_pending_video_int(); // s68000interrupt(7, IRQ_VBLANK+64); @@ -965,11 +692,11 @@ void jaguar_exec(int16 * backbuffer, uint8 render) if (invalid_instruction_address != 0x80000000) cd_bios_process(invalid_instruction_address);*/ m68k_execute(m68k_cycles_per_scanline); - // No CD handling... Hmm... + // No CD handling... !!! FIX !!! cd_bios_exec(i); tom_pit_exec(m68k_cycles_per_scanline); - tom_exec_scanline(backbuffer, i, 0); + tom_exec_scanline(backbuffer, i, false); jerry_pit_exec(m68k_cycles_per_scanline); jerry_i2s_exec(m68k_cycles_per_scanline); gpu_exec(gpu_cycles_per_scanline); @@ -983,7 +710,7 @@ void jaguar_exec(int16 * backbuffer, uint8 render) if (invalid_instruction_address != 0x80000000) cd_bios_process(invalid_instruction_address);*/ m68k_execute(m68k_cycles_per_scanline); - // No CD handling... Hmm... + // No CD handling... !!! FIX !!! cd_bios_exec(i); tom_pit_exec(m68k_cycles_per_scanline); jerry_pit_exec(m68k_cycles_per_scanline); @@ -999,6 +726,76 @@ void jaguar_exec(int16 * backbuffer, uint8 render) #endif } +// +// Main Jaguar execution loop (1 frame) +// +void JaguarExecute(int16 * backbuffer, bool render) +{ + uint16 vp = tom_word_read(0xF0003E);//Hmm. This is a WO register. Will work? Looks like. But wrong behavior! + uint16 vi = tom_word_read(0xF0004E);//Another WO register... + uint16 vdb = tom_word_read(0xF00046); +// uint16 endingLine = +//Note: This is the *definite* end of the display, though VDE *might* be less than this... +// uint16 vbb = tom_word_read(0xF00040); +//It seems that they mean it when they say that VDE is the end of object processing. +//However, we need to be able to tell the OP (or TOM) that we've reached the end of the +//buffer and not to write any more pixels... + uint16 vde = tom_word_read(0xF00048); + +/*extern int effect_start; +if (effect_start) +{ + WriteLog("JagExe: VP=%u, VI=%u, VDB=%u, VBB=%u CPU CPS=%u, GPU CPS=%u\n", vp, vi, vdb, vbb, m68k_cycles_per_scanline, gpu_cycles_per_scanline); +}//*/ + + for(uint16 i=0; i= vdb && i < vde)//vbb) + { + if (!(i & 0x01)) // Execute OP only on even lines (non-interlaced only!) + { + tom_exec_scanline(backbuffer, i/2, render); // i/2 is a kludge... + backbuffer += TOMGetSDLScreenPitch() / 2; // Convert bytes to words... + } + } + } + +#ifdef SOUND_OUTPUT + system_sound_update(); +#endif +} + // Temp debugging stuff void DumpMainMemory(void) @@ -1009,10 +806,6 @@ void DumpMainMemory(void) return; fwrite(jaguar_mainRam, 1, 0x400000, fp); -// for(int i=0; i<0x400000; i++) -// fprintf(fp, "%c", jaguar_mainRam[i]); -// fputc(jaguar_mainRam[i], fp); - fclose(fp); }