]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/jaguar.cpp
Fixed limits on cartridge space from 4MB to 6MB.
[virtualjaguar] / src / jaguar.cpp
index de5b5a888f8714e74effa72a11fad457844aaad0..9365b01672c2a8afa82fd8f3781743e4cf4fc28d 100644 (file)
@@ -28,7 +28,7 @@
 #include "jerry.h"
 #include "joystick.h"
 #include "log.h"
-#include "m68k.h"
+#include "m68000/m68kinterface.h"
 //#include "memory.h"
 #include "mmu.h"
 #include "settings.h"
 //Do this in makefile??? Yes! Could, but it's easier to define here...
 //#define LOG_UNMAPPED_MEMORY_ACCESSES
 //#define ABORT_ON_UNMAPPED_MEMORY_ACCESS
-#define ABORT_ON_ILLEGAL_INSTRUCTIONS
+//#define ABORT_ON_ILLEGAL_INSTRUCTIONS
 //#define ABORT_ON_OFFICIAL_ILLEGAL_INSTRUCTION
 #define CPU_DEBUG_MEMORY
 //#define LOG_CD_BIOS_CALLS
+#define CPU_DEBUG_TRACING
 
 // Private function prototypes
 
@@ -78,6 +79,7 @@ uint32 returnAddr[4000], raPtr = 0xFFFFFFFF;
 
 uint32 pcQueue[0x400];
 uint32 pcQPtr = 0;
+bool startM68KTracing = false;
 
 //
 // Callback function to detect illegal instructions
@@ -121,6 +123,17 @@ if (inRoutine)
        instSeen++;
 #endif
 
+// For code tracing...
+#ifdef CPU_DEBUG_TRACING
+       if (startM68KTracing)
+       {
+               static char buffer[2048];
+
+               m68k_disassemble(buffer, m68kPC, 0);
+               WriteLog("%06X: %s\n", m68kPC, buffer);
+       }
+#endif
+
 // For tracebacks...
 // Ideally, we'd save all the registers as well...
        pcQueue[pcQPtr++] = m68kPC;
@@ -133,7 +146,7 @@ if (inRoutine)
                static char buffer[2048];
                for(int i=0; i<0x400; i++)
                {
-                       m68k_disassemble(buffer, pcQueue[(pcQPtr + i) & 0x3FF], M68K_CPU_TYPE_68000);
+                       m68k_disassemble(buffer, pcQueue[(pcQPtr + i) & 0x3FF], 0);//M68K_CPU_TYPE_68000);
                        WriteLog("\t%08X: %s\n", pcQueue[(pcQPtr + i) & 0x3FF], buffer);
                }
                WriteLog("\n");
@@ -270,16 +283,16 @@ if (m68kPC == 0x802058) start = true;
                        m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
                        m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
        }//*/
-       if (m68kPC == 0x82E1A)
+/*     if (m68kPC == 0x82E1A)
        {
                static char buffer[2048];
-               m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
+               m68k_disassemble(buffer, m68kPC, 0);//M68K_CPU_TYPE_68000);
                WriteLog("--> [Routine start] %08X: %s", m68kPC, buffer);
                WriteLog("\t\tA0=%08X, A1=%08X, D0=%08X(cmd), D1=%08X(# bytes), D2=%08X\n",
                        m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1),
                        m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2));
        }//*/
-       if (m68kPC == 0x82E58)
+/*     if (m68kPC == 0x82E58)
                WriteLog("--> [Routine end]\n");
        if (m68kPC == 0x80004)
        {
@@ -356,7 +369,7 @@ CD_switch:: -> $306C
 #endif
 
 #ifdef ABORT_ON_ILLEGAL_INSTRUCTIONS
-       if (!m68k_is_valid_instruction(m68k_read_memory_16(m68kPC), M68K_CPU_TYPE_68000))
+       if (!m68k_is_valid_instruction(m68k_read_memory_16(m68kPC), 0))//M68K_CPU_TYPE_68000))
        {
 #ifndef ABORT_ON_OFFICIAL_ILLEGAL_INSTRUCTION
                if (m68k_read_memory_16(m68kPC) == 0x4AFC)
@@ -376,8 +389,21 @@ CD_switch::        -> $306C
                WriteLog("\nM68K encountered an 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", JaguarReadLong(topOfStack));
+               uint32 address = topOfStack - (4 * 4 * 3);
+
                for(int i=0; i<10; i++)
-                       WriteLog("%06X: %08X\n", topOfStack - (i * 4), JaguarReadLong(topOfStack - (i * 4)));
+               {
+                       WriteLog("%06X:", address);
+
+                       for(int j=0; j<4; j++)
+                       {
+                               WriteLog(" %08X", JaguarReadLong(address));
+                               address += 4;
+                       }
+
+                       WriteLog("\n");
+               }
+
                WriteLog("Jaguar: VBL interrupt is %s\n", ((TOMIRQEnabled(IRQ_VIDEO)) && (JaguarInterruptHandlerIsValid(64))) ? "enabled" : "disabled");
                M68K_show_context();
 
@@ -916,6 +942,13 @@ handler:
 #endif
 int irq_ack_handler(int level)
 {
+#ifdef CPU_DEBUG_TRACING
+       if (startM68KTracing)
+       {
+               WriteLog("irq_ack_handler: M68K PC=%06X\n", m68k_get_reg(NULL, M68K_REG_PC));
+       }
+#endif
+
        // Tracing the IPL lines on the Jaguar schematic yields the following:
        // IPL1 is connected to INTL on TOM (OUT to 68K)
        // IPL0-2 are also tied to Vcc via 4.7K resistors!
@@ -1454,7 +1487,7 @@ void JaguarDasm(uint32 offset, uint32 qt)
                pc += Dasm68000((char *)mem, buffer, 0);
                WriteLog("%08X: %s\n", oldpc, buffer);//*/
                oldpc = pc;
-               pc += m68k_disassemble(buffer, pc, M68K_CPU_TYPE_68000);
+               pc += m68k_disassemble(buffer, pc, 0);//M68K_CPU_TYPE_68000);
                WriteLog("%08X: %s\n", oldpc, buffer);//*/
        }
 #endif
@@ -1463,11 +1496,12 @@ void JaguarDasm(uint32 offset, uint32 qt)
 uint8 JaguarReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
        uint8 data = 0x00;
-
        offset &= 0xFFFFFF;
-       if (offset < 0x200000)
-               data = jaguarMainRAM[offset & 0x3FFFFF];
-       else if ((offset >= 0x800000) && (offset < 0xC00000))
+
+       // First 2M is mirrored in the $0 - $7FFFFF range
+       if (offset < 0x800000)
+               data = jaguarMainRAM[offset & 0x1FFFFF];
+       else if ((offset >= 0x800000) && (offset < 0xDFFF00))
                data = jaguarMainROM[offset - 0x800000];
        else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF))
                data = CDROMReadByte(offset, who);
@@ -1488,11 +1522,13 @@ uint8 JaguarReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
 uint16 JaguarReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
        offset &= 0xFFFFFF;
-       if (offset <= 0x1FFFFE)
+
+       // First 2M is mirrored in the $0 - $7FFFFF range
+       if (offset < 0x800000)
        {
                return (jaguarMainRAM[(offset+0) & 0x1FFFFF] << 8) | jaguarMainRAM[(offset+1) & 0x1FFFFF];
        }
-       else if ((offset >= 0x800000) && (offset <= 0xBFFFFE))
+       else if ((offset >= 0x800000) && (offset < 0xDFFF00))
        {
                offset -= 0x800000;
                return (jaguarMainROM[offset+0] << 8) | jaguarMainROM[offset+1];
@@ -1522,7 +1558,9 @@ void JaguarWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
                WriteLog("JWB: Byte %02X written at %08X by %s\n", data, offset, whoName[who]);//*/
 
        offset &= 0xFFFFFF;
-       if (offset < 0x200000)
+
+       // First 2M is mirrored in the $0 - $7FFFFF range
+       if (offset < 0x800000)
        {
                jaguarMainRAM[offset & 0x1FFFFF] = data;
                return;
@@ -1566,7 +1604,8 @@ if (offset == 0x0102)//64*4)
 
        offset &= 0xFFFFFF;
 
-       if (offset <= 0x1FFFFE)
+       // First 2M is mirrored in the $0 - $7FFFFF range
+       if (offset <= 0x7FFFFE)
        {
 /*
 GPU Table (CD BIOS)
@@ -1736,7 +1775,7 @@ void JaguarInit(void)
 //temp, for crappy crap that sux
 memset(jaguarMainRAM + 0x804, 0xFF, 4);
 
-       m68k_set_cpu_type(M68K_CPU_TYPE_68000);
+//     m68k_set_cpu_type(M68K_CPU_TYPE_68000);
        m68k_pulse_reset();                                                     // Need to do this so UAE disasm doesn't segfault on exit
        GPUInit();
        DSPInit();
@@ -1817,9 +1856,26 @@ void JaguarDone(void)
 //     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", JaguarReadLong(topOfStack));
+       WriteLog("M68K: Top of stack: %08X -> (%08X). Stack trace:\n", topOfStack, JaguarReadLong(topOfStack));
+#if 0
        for(int i=-2; i<9; i++)
                WriteLog("%06X: %08X\n", topOfStack + (i * 4), JaguarReadLong(topOfStack + (i * 4)));
+#else
+       uint32 address = topOfStack - (4 * 4 * 3);
+
+       for(int i=0; i<10; i++)
+       {
+               WriteLog("%06X:", address);
+
+               for(int j=0; j<4; j++)
+               {
+                       WriteLog(" %08X", JaguarReadLong(address));
+                       address += 4;
+               }
+
+               WriteLog("\n");
+       }
+#endif
 
 /*     WriteLog("\nM68000 disassembly at $802288...\n");
        jaguar_dasm(0x802288, 3);
@@ -1977,7 +2033,7 @@ void JaguarExecuteNew(void)
 // it will be half this number for a half frame. BUT, since we're counting
 // HALF lines, we double this number and we're back at 525 for NTSC, 625 for PAL.
 //
-// Scanline times are 63.5555... µs in NTSC and 64 µs in PAL
+// Scanline times are 63.5555... μs in NTSC and 64 μs in PAL
 // Half line times are, naturally, half of this. :-P
 void HalflineCallback(void)
 {