]> Shamusworld >> Repos - virtualjaguar/commitdiff
More changes for upcoming 1.0.5 release
authorShamus Hammons <jlhamm@acm.org>
Thu, 28 Aug 2003 05:16:00 +0000 (05:16 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 28 Aug 2003 05:16:00 +0000 (05:16 +0000)
INSTALL
src/dsp.cpp
src/gpu.cpp
src/include/jaguar.h
src/jaguar.cpp
src/joystick.cpp

diff --git a/INSTALL b/INSTALL
index ab1456b8dff11f654ee4b064bcfb244e461ae14d..620ae1fcfc78ae0518a3834112c48d7cfae47d57 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -31,8 +31,9 @@ compile Virtual Jaguar v1.0.4 GCC/SDL release by doing the following:
 
 2) Optionally you can manually strip vj[.exe] to downsize the binary.
 
-If you don't have upx in your path somewhere, you can ignore the error
-message that make throws at you about not being able to find upx.
+If you have upx in your path somewhere, you can uncomment the line in the
+makefile that executes upx so that you'll end up with a somewhat smaller
+binary.
  
 That's it! You're done! You can now start the emulator with ./vj.
 See the output for more details or consult the docs/README for more info.
index 710b90a169ad33fa05c478a84b2362e9543aacef..b9a042e5670a68a89b425a7901d941af3978e9cf 100644 (file)
@@ -403,6 +403,8 @@ void dsp_build_branch_condition_table(void)
 
 uint8 DSPReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF1A000 && offset <= 0xF1A0FF)
+               WriteLog("DSP: ReadByte--Attempt to read from DSP register file by %s!\n", whoName[who]);
 // battlemorph
 //     if ((offset==0xF1CFE0)||(offset==0xF1CFE2))
 //             return(0xffff);
@@ -437,6 +439,8 @@ uint8 DSPReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
 
 uint16 DSPReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF1A000 && offset <= 0xF1A0FF)
+               WriteLog("DSP: ReadWord--Attempt to read from DSP register file by %s!\n", whoName[who]);
        //???
        offset &= 0xFFFFFFFE;
        // jaguar cd bios
@@ -504,6 +508,9 @@ uint16 DSPReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
 
 uint32 DSPReadLong(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF1A000 && offset <= 0xF1A0FF)
+               WriteLog("DSP: ReadLong--Attempt to read from DSP register file by %s!\n", whoName[who]);
+
        // ??? WHY ???
        offset &= 0xFFFFFFFC;
 /*if (offset == 0xF1BCF4)
@@ -548,6 +555,9 @@ uint32 DSPReadLong(uint32 offset, uint32 who/*=UNKNOWN*/)
 
 void DSPWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF1A000 && offset <= 0xF1A0FF)
+               WriteLog("DSP: WriteByte--Attempt to write to DSP register file by %s!\n", whoName[who]);
+
        if ((offset >= DSP_WORK_RAM_BASE) && (offset < DSP_WORK_RAM_BASE+0x2000))
        {
                offset -= DSP_WORK_RAM_BASE;
@@ -584,6 +594,8 @@ void DSPWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
 
 void DSPWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF1A000 && offset <= 0xF1A0FF)
+               WriteLog("DSP: WriteWord--Attempt to write to DSP register file by %s!\n", whoName[who]);
        offset &= 0xFFFFFFFE;
 /*if (offset == 0xF1BCF4)
 {
@@ -628,8 +640,11 @@ void DSPWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
        JaguarWriteWord(offset, data, who);
 }
 
+//bool badWrite = false;
 void DSPWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF1A000 && offset <= 0xF1A0FF)
+               WriteLog("DSP: WriteLong--Attempt to write to DSP register file by %s!\n", whoName[who]);
        // ??? WHY ???
        offset &= 0xFFFFFFFC;
 /*if (offset == 0xF1BCF4)
@@ -677,7 +692,9 @@ void DSPWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
                        dsp_matrix_control = data;
                        break;
                case 0x08:
-                       dsp_pointer_to_matrix = data;
+                       // According to JTRM, only lines 2-11 are adressable, the rest being
+                       // hardwired to $F1Bxxx.
+                       dsp_pointer_to_matrix = 0xF1B000 | (data & 0x000FFC);
                        break;
                case 0x0C:
                        dsp_data_organization = data;
@@ -708,7 +725,7 @@ void DSPWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
                        // Check for CPU -> DSP interrupt
                        if (data & DSPINT0)
                        {
-//                             WriteLog("DSP: CPU -> DSP interrupt\n");
+                               WriteLog("DSP: CPU -> DSP interrupt\n");
                                m68k_end_timeslice();
                                gpu_releaseTimeslice();
                                DSPSetIRQLine(DSPIRQ_CPU, ASSERT_LINE);
@@ -766,6 +783,8 @@ WriteLog("\n");
 //We don't have to break this up like this! We CAN do 32 bit writes!
 //     JaguarWriteWord(offset, (data>>16) & 0xFFFF, DSP);
 //     JaguarWriteWord(offset+2, data & 0xFFFF, DSP);
+//if (offset > 0xF1FFFF)
+//     badWrite = true;
        JaguarWriteLong(offset, data, who);
 }
 
@@ -1001,10 +1020,17 @@ void DSPExec(int32 cycles)
 
        while (cycles > 0 && DSP_RUNNING)
        {
-if (dsp_pc == 0xF1B5D8)
+/*if (badWrite)
 {
-       WriteLog("DSP: At $F1B4D8--R15 = %08X at %u ms%s...\n", dsp_reg[15], SDL_GetTicks(), (dsp_flags & IMASK ? " (inside interrupt)" : ""));
-}
+       WriteLog("\nDSP: Encountered bad write in Atari Synth module. PC=%08X, R15=%08X\n", dsp_pc, dsp_reg[15]);
+       for(int i=0; i<80; i+=4)
+               WriteLog("     %08X: %08X\n", dsp_reg[15]+i, JaguarReadLong(dsp_reg[15]+i));
+       WriteLog("\n");
+}//*/
+/*if (dsp_pc == 0xF1B55E)
+{
+       WriteLog("DSP: At $F1B55E--R15 = %08X at %u ms%s...\n", dsp_reg[15], SDL_GetTicks(), (dsp_flags & IMASK ? " (inside interrupt)" : ""));
+}//*/
 /*if (dsp_pc == 0xF1B7D2)      // Start here???
        doDSPDis = true;
 pcQueue[ptrPCQ++] = dsp_pc;
@@ -1320,7 +1346,7 @@ static void dsp_opcode_store_r14_indexed(void)
        if (doDSPDis)
                WriteLog("%06X: STORE  R%02u, (R14+$%02X) [NCZ:%u%u%u, R%02u=%08X, R14+$%02X=%08X]\n", dsp_pc-2, IMM_2, dsp_convert_zero[IMM_1] << 2, dsp_flag_n, dsp_flag_c, dsp_flag_z, IMM_2, RN, dsp_convert_zero[IMM_1] << 2, dsp_reg[14]+(dsp_convert_zero[IMM_1] << 2));
 #endif
-       DSPWriteLong(dsp_reg[15] + (dsp_convert_zero[IMM_1] << 2), RN, DSP);
+       DSPWriteLong(dsp_reg[14] + (dsp_convert_zero[IMM_1] << 2), RN, DSP);
 }
 
 static void dsp_opcode_store_r15_indexed(void)
index f7951ccc7d932332510ca3d4c868de253669f4f5..464350cf9fbb7453e6da89be7a1563658ffeaad0 100644 (file)
@@ -1,7 +1,7 @@
 //
 // GPU Core
 //
-// by cal2
+// by Cal2
 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
 // Cleanups, endian wrongness, and bad ASM amelioration by James L. Hammons
 // Note: Endian wrongness probably stems from the MAME origins of this emu and
@@ -17,7 +17,7 @@
 //#define GPU_DEBUG
 
 // For GPU dissasembly...
-/*
+
 #define GPU_DIS_ABS
 #define GPU_DIS_ADD
 #define GPU_DIS_ADDC
@@ -145,6 +145,11 @@ GPU opcodes use (BIOS flying ATARI logo):
 #define REGPAGE                        0x4000
 #define DMAEN                  0x8000
 
+// External global variables
+
+extern int start_logging;
+extern int gpu_start_log;
+
 // Private function prototypes
 
 void GPUUpdateRegisterBanks(void);
@@ -153,11 +158,6 @@ void GPUDumpDisassembly(void);
 void GPUDumpRegisters(void);
 void GPUDumpMemory(void);
 
-// External global variables
-
-extern int start_logging;
-extern int gpu_start_log;
-
 static void gpu_opcode_add(void);
 static void gpu_opcode_addc(void);
 static void gpu_opcode_addq(void);
@@ -384,6 +384,9 @@ void build_branch_condition_table(void)
 //
 uint8 GPUReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF02000 && offset <= 0xF020FF)
+               WriteLog("GPU: ReadByte--Attempt to read from GPU register file by %s!\n", whoName[who]);
+
        if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000))
                return gpu_ram_8[offset & 0xFFF];
        else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20))
@@ -408,6 +411,9 @@ uint8 GPUReadByte(uint32 offset, uint32 who/*=UNKNOWN*/)
 //
 uint16 GPUReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF02000 && offset <= 0xF020FF)
+               WriteLog("GPU: ReadWord--Attempt to read from GPU register file by %s!\n", whoName[who]);
+
        if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000))
        {
                offset &= 0xFFF;
@@ -441,6 +447,9 @@ WriteLog("[GPUR16] --> Possible GPU RAM mirror access by %s!", whoName[who]);
 //
 uint32 GPUReadLong(uint32 offset, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF02000 && offset <= 0xF020FF)
+               WriteLog("GPU: ReadLong--Attempt to read from GPU register file by %s!\n", whoName[who]);
+
 //     if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000))
        if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFC))
        {
@@ -498,6 +507,9 @@ if (offset >= 0xF0B000 && offset <= 0xF0BFFF)
 //
 void GPUWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF02000 && offset <= 0xF020FF)
+               WriteLog("GPU: WriteByte--Attempt to write to GPU register file by %s!\n", whoName[who]);
+
        if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFF))
        {
                gpu_ram_8[offset & 0xFFF] = data;
@@ -536,6 +548,9 @@ void GPUWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/)
 //
 void GPUWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF02000 && offset <= 0xF020FF)
+               WriteLog("GPU: WriteWord--Attempt to write to GPU register file by %s!\n", whoName[who]);
+
        if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFE))
        {
                gpu_ram_8[offset & 0xFFF] = (data>>8) & 0xFF;
@@ -601,13 +616,16 @@ void GPUWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
 //
 void GPUWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
 {
+       if (offset >= 0xF02000 && offset <= 0xF020FF)
+               WriteLog("GPU: WriteLong--Attempt to write to GPU register file by %s!\n", whoName[who]);
+
 //     if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000))
        if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFC))
        {
 #ifdef GPU_DEBUG
                if (offset & 0x03)
                {
-                       WriteLog("GPU: Write32--unaligned write @ %08X [%08X]\n", offset, data);
+                       WriteLog("GPU: Write32--unaligned write @ %08X [%08X] by %s\n", offset, data, whoName[who]);
                        GPUDumpRegisters();
                }
 #endif // GPU_DEBUG
@@ -651,7 +669,7 @@ void GPUWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
                        gpu_matrix_control = data;
                        break;
                case 0x08:
-                       // Can only point to long aligned addresses
+                       // This can only point to long aligned addresses
                        gpu_pointer_to_matrix = data & 0xFFFFFFFC;
                        break;
                case 0x0C:
@@ -699,7 +717,6 @@ WriteLog("GPU: %s setting GPU PC to %08X %s\n", whoName[who], gpu_pc, (GPU_RUNNI
                        {
                                //WriteLog("asked to perform a single step (single step is %senabled)\n",(data&0x8)?"":"not ");
                        }
-//                     gpu_control = (gpu_control & 0x107C0) | (data & (~0x107C0));
                        gpu_control = (gpu_control & 0xF7C0) | (data & (~0xF7C0));
 
                        // if gpu wasn't running but is now running, execute a few cycles
@@ -727,6 +744,93 @@ WriteLog("\n");
 #endif // GPU_DEBUG
 //if (GPU_RUNNING)
 //     GPUDumpDisassembly();
+/*if (GPU_RUNNING)
+{
+       if (gpu_pc == 0xF035D8)
+       {
+//             GPUDumpDisassembly();
+//             log_done();
+//             exit(1);
+               gpu_control &= 0xFFFFFFFE;      // Don't run it and let's see what happens!
+//Hmm. Seems to lock up when going into the demo...
+//Try to disable the collision altogether!
+       }
+}//*/
+extern int effect_start5;
+static bool finished = false;
+//if (GPU_RUNNING && effect_start5 && !finished)
+if (GPU_RUNNING && effect_start5 && gpu_pc == 0xF035D8)
+{
+       // Let's do a dump of $6528!
+/*     uint32 numItems = JaguarReadWord(0x6BD6);
+       WriteLog("\nDump of $6528: %u items.\n\n", numItems);
+       for(int i=0; i<numItems*3*4; i+=3*4)
+       {
+               WriteLog("\t%04X: %08X %08X %08X -> ", 0x6528+i, JaguarReadLong(0x6528+i),
+                       JaguarReadLong(0x6528+i+4), JaguarReadLong(0x6528+i+8));
+               uint16 link = JaguarReadWord(0x6528+i+8+2);
+               for(int j=0; j<40; j+=4)
+                       WriteLog("%08X ", JaguarReadLong(link + j));
+               WriteLog("\n");
+       }
+       WriteLog("\n");//*/
+       // Let's try a manual blit here...
+//This isn't working the way it should! !!! FIX !!!
+//Err, actually, it is.
+// NOW, it works right! Problem solved!!! It's a blitter bug!
+/*     uint32 src = 0x4D54, dst = 0xF03000, width = 10 * 4;
+       for(int y=0; y<127; y++)
+       {
+               for(int x=0; x<2; x++)
+               {
+                       JaguarWriteLong(dst, JaguarReadLong(src));
+                       
+                       src += 4;
+                       dst += 4;
+               }
+               src += width - (2 * 4);
+       }//*/
+/*     finished = true;
+       doGPUDis = true;
+       WriteLog("\nGPU: About to execute collision detection code.\n\n");//*/
+
+/*     WriteLog("\nGPU: About to execute collision detection code. Data @ 4D54:\n\n");
+       int count = 0;
+       for(int i=0x004D54; i<0x004D54+2048; i++)
+       {
+               WriteLog("%02X ", JaguarReadByte(i));
+               count++;
+               if (count == 32)
+               {
+                       count = 0;
+                       WriteLog("\n");
+               }
+       }
+       WriteLog("\n\nData @ F03000:\n\n");
+       count = 0;
+       for(int i=0xF03000; i<0xF03200; i++)
+       {
+               WriteLog("%02X ", JaguarReadByte(i));
+               count++;
+               if (count == 32)
+               {
+                       count = 0;
+                       WriteLog("\n");
+               }
+       }
+       WriteLog("\n\n");
+       log_done();
+       exit(0);//*/
+}
+//if (!GPU_RUNNING)
+//     doGPUDis = false;
+/*if (!GPU_RUNNING && finished)
+{
+       WriteLog("\nGPU: Finished collision detection code. Exiting!\n\n");
+       GPUDumpRegisters();
+       log_done();
+       exit(0);
+}//*/
                        // (?) If we're set running by the M68K (or DSP?) then end its timeslice to
                        // allow the GPU a chance to run...
                        // Yes! This partially fixed Trevor McFur...
@@ -938,7 +1042,7 @@ void GPUDumpMemory(void)
 
 void gpu_done(void)
 { 
-       WriteLog("GPU: stopped at PC=%08X (GPU %s running)\n", (unsigned int)gpu_pc, GPU_RUNNING ? "was" : "wasn't");
+       WriteLog("GPU: Stopped at PC=%08X (GPU %s running)\n", (unsigned int)gpu_pc, GPU_RUNNING ? "was" : "wasn't");
 
        // Get the interrupt latch & enable bits 
        uint8 bits = (gpu_control >> 6) & 0x1F, mask = (gpu_flags >> 4) & 0x1F;
@@ -947,15 +1051,6 @@ void gpu_done(void)
        GPUDumpRegisters();
        GPUDumpDisassembly();
 
-/*     WriteLog("---[GPU code at %08X]---------------------------\n", gpu_pc);
-       j = gpu_pc - 64;
-       for(int i=0; i<4096; i++)
-       {
-               uint32 oldj = j;
-               j += dasmjag(JAGUAR_GPU, buffer, j);
-               WriteLog("\t%08X: %s\n", oldj, buffer);
-       }*/
-
        WriteLog("\nGPU opcodes use:\n");
        for(int i=0; i<64; i++)
        {
@@ -1132,7 +1227,7 @@ if (gpu_start_log)
        WriteLog("(RM=%08X, RN=%08X)\n", RM, RN);//*/
 if ((gpu_pc < 0xF03000 || gpu_pc > 0xF03FFF) && !tripwire)
 {
-       WriteLog("GPU: Executing outside local RAM!\n");
+       WriteLog("GPU: Executing outside local RAM! GPU_PC: %08X\n", gpu_pc);
        tripwire = true;
 }
        }
index 43184711ed2cba99a35c644819b4cbe0297e4112..d3d69047fc198fbd6e1967be1e628dfd0163f7cd 100644 (file)
@@ -31,7 +31,6 @@ extern char * whoName[9];
 
 void jaguar_init(void);
 void jaguar_reset(void);
-//void jaguar_reset_handler(void);
 void jaguar_done(void);
 
 uint8 JaguarReadByte(uint32 offset, uint32 who = UNKNOWN);
@@ -44,7 +43,6 @@ void JaguarWriteLong(uint32 offset, uint32 data, uint32 who = UNKNOWN);
 uint32 jaguar_interrupt_handler_is_valid(uint32 i);
 void jaguar_dasm(uint32 offset, uint32 qt);
 
-//New stuff...
 void JaguarExecute(int16 * backbuffer, bool render);
 
 // Some handy macros to help converting native endian to big endian (jaguar native)
index 35f53b953edec65424cda6cffbbc6af67a037b86..8e7ee328a5b03703d3ef4cea765d986b3394c51e 100644 (file)
@@ -13,7 +13,8 @@
 
 #define CPU_DEBUG
 //Do this in makefile??? Yes! Could, but it's easier to define here...
-//#define LOG_UNMAPPED_MEMORY_ACCESSES
+#define LOG_UNMAPPED_MEMORY_ACCESSES
+#define CPU_DEBUG_MEMORY
 
 // Private function prototypes
 
@@ -26,6 +27,11 @@ void M68K_show_context(void);
 // External variables
 
 extern bool hardwareTypeNTSC;                          // Set to false for PAL
+#ifdef CPU_DEBUG_MEMORY
+extern bool startMemLog;                                       // Set by "e" key
+extern int effect_start;
+extern int effect_start2, effect_start3, effect_start4, effect_start5, effect_start6;
+#endif
 
 // Memory debugging identifiers
 
@@ -43,14 +49,52 @@ uint32 jaguar_mainRom_crc32;
 /*static*/ uint8 * jaguar_mainRam = NULL;
 /*static*/ uint8 * jaguar_bootRom = NULL;
 /*static*/ uint8 * jaguar_mainRom = NULL;
-
+#ifdef CPU_DEBUG_MEMORY
+uint8 writeMemMax[0x400000], writeMemMin[0x400000];
+uint8 readMem[0x400000];
+uint32 returnAddr[4000], raPtr = 0xFFFFFFFF;
+#endif
 
 //
 // Callback function to detect illegal instructions
 //
+//void GPUDumpDisassembly(void);
+//void GPUDumpRegisters(void);
 void M68KInstructionHook(void)
 {
        uint32 m68kPC = m68k_get_reg(NULL, M68K_REG_PC);
+/*     if (m68kPC == 0x8D0E48 && effect_start5)
+       {
+               WriteLog("\nM68K: At collision detection code. Exiting!\n\n");
+               GPUDumpRegisters();
+               GPUDumpDisassembly();
+               log_done();
+               exit(0);
+       }//*/
+/*     uint16 opcode = JaguarReadWord(m68kPC);
+       if (opcode == 0x4E75)   // RTS
+       {
+               if (startMemLog)
+//                     WriteLog("Jaguar: Returning from subroutine to %08X\n", JaguarReadLong(m68k_get_reg(NULL, M68K_REG_A7)));
+               {
+                       uint32 addr = JaguarReadLong(m68k_get_reg(NULL, M68K_REG_A7));
+                       bool found = false;
+                       if (raPtr != 0xFFFFFFFF)
+                       {
+                               for(uint32 i=0; i<=raPtr; i++)
+                               {
+                                       if (returnAddr[i] == addr)
+                                       {
+                                               found = true;
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if (!found)
+                               returnAddr[++raPtr] = addr;
+               }
+       }//*/
 
 /*     static char buffer[2048];
        m68k_disassemble(buffer, m68kPC, M68K_CPU_TYPE_68000);
@@ -67,7 +111,7 @@ void M68KInstructionHook(void)
                        WriteLog("\tA%i = %08X\n", i-M68K_REG_A0, m68k_get_reg(NULL, (m68k_register_t)i));
        }*/
 
-       if (!m68k_is_valid_instruction(JaguarReadWord(m68kPC), M68K_CPU_TYPE_68000))
+       if (!m68k_is_valid_instruction(m68k_read_memory_16(m68kPC), M68K_CPU_TYPE_68000))
        {
                WriteLog("\nM68K encountered an illegal instruction at %08X!!!\n\nAborting!\n", m68kPC);
                uint32 topOfStack = m68k_get_reg(NULL, M68K_REG_A7);
@@ -102,6 +146,13 @@ int irq_ack_handler(int level)
 
 unsigned int m68k_read_memory_8(unsigned int address)
 {
+#ifdef CPU_DEBUG_MEMORY
+       if ((address >= 0x000000) && (address <= 0x3FFFFF))
+       {
+               if (startMemLog)
+                       readMem[address] = 1;
+       }
+#endif
 //WriteLog("[RM8] Addr: %08X\n", address);
        unsigned int retVal = 0;
 
@@ -128,6 +179,37 @@ void gpu_dump_registers(void);
 
 unsigned int m68k_read_memory_16(unsigned int address)
 {
+#ifdef CPU_DEBUG_MEMORY
+/*     if ((address >= 0x000000) && (address <= 0x3FFFFE))
+       {
+               if (startMemLog)
+                       readMem[address] = 1, readMem[address + 1] = 1;
+       }//*/
+/*     if (effect_start && (address >= 0x8064FC && address <= 0x806501))
+       {
+               return 0x4E71;  // NOP
+       }
+       if (effect_start2 && (address >= 0x806502 && address <= 0x806507))
+       {
+               return 0x4E71;  // NOP
+       }
+       if (effect_start3 && (address >= 0x806512 && address <= 0x806517))
+       {
+               return 0x4E71;  // NOP
+       }
+       if (effect_start4 && (address >= 0x806524 && address <= 0x806527))
+       {
+               return 0x4E71;  // NOP
+       }
+       if (effect_start5 && (address >= 0x80653E && address <= 0x806543)) //Collision detection!
+       {
+               return 0x4E71;  // NOP
+       }
+       if (effect_start6 && (address >= 0x806544 && address <= 0x806547))
+       {
+               return 0x4E71;  // NOP
+       }//*/
+#endif
 //WriteLog("[RM16] Addr: %08X\n", address);
 /*if (m68k_get_reg(NULL, M68K_REG_PC) == 0x00005FBA)
 //     for(int i=0; i<10000; i++)
@@ -181,6 +263,18 @@ unsigned int m68k_read_memory_32(unsigned int address)
 
 void m68k_write_memory_8(unsigned int address, unsigned int value)
 {
+#ifdef CPU_DEBUG_MEMORY
+       if ((address >= 0x000000) && (address <= 0x3FFFFF))
+       {
+               if (startMemLog)
+               {
+                       if (value > writeMemMax[address])
+                               writeMemMax[address] = value;
+                       if (value < writeMemMin[address])
+                               writeMemMin[address] = value;
+               }
+       }
+#endif
 //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);
@@ -198,6 +292,25 @@ void m68k_write_memory_8(unsigned int address, unsigned int value)
 
 void m68k_write_memory_16(unsigned int address, unsigned int value)
 {
+#ifdef CPU_DEBUG_MEMORY
+       if ((address >= 0x000000) && (address <= 0x3FFFFE))
+       {
+               if (startMemLog)
+               {
+                       uint8 hi = value >> 8, lo = value & 0xFF;
+
+                       if (hi > writeMemMax[address])
+                               writeMemMax[address] = hi;
+                       if (hi < writeMemMin[address])
+                               writeMemMin[address] = hi;
+
+                       if (lo > writeMemMax[address+1])
+                               writeMemMax[address+1] = lo;
+                       if (lo < writeMemMin[address+1])
+                               writeMemMin[address+1] = lo;
+               }
+       }
+#endif
 //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);
@@ -206,7 +319,7 @@ void m68k_write_memory_16(unsigned int address, unsigned int value)
 //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;
-/*if (address == 0xF02114)
+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));//*/
@@ -502,6 +615,11 @@ void JaguarWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
 //
 void jaguar_init(void)
 {
+#ifdef CPU_DEBUG_MEMORY
+       memset(readMem, 0x00, 0x400000);
+       memset(writeMemMin, 0xFF, 0x400000);
+       memset(writeMemMax, 0x00, 0x400000);
+#endif
        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");
@@ -526,6 +644,47 @@ void jaguar_init(void)
 
 void jaguar_done(void)
 {
+#ifdef CPU_DEBUG_MEMORY
+/*     WriteLog("\n\nM68000 disassembly at $8D0D44 (collision routine!)...\n");
+       jaguar_dasm(0x8D0D44, 5000);
+       WriteLog("\n");//*/
+/*     WriteLog("\n\nM68000 disassembly at $806300 (look @ $806410)...\n");
+       jaguar_dasm(0x806300, 5000);
+       WriteLog("\n");//*/
+
+/*     WriteLog("\nJaguar: Memory Usage Stats (return addresses)\n\n");
+
+       for(uint32 i=0; i<=raPtr; i++)
+       {
+               WriteLog("\t%08X\n", returnAddr[i]);
+               WriteLog("M68000 disassembly at $%08X...\n", returnAddr[i] - 16);
+               jaguar_dasm(returnAddr[i] - 16, 16);
+               WriteLog("\n");
+       }
+       WriteLog("\n");//*/
+
+/*     int start = 0, end = 0;
+       bool endTriggered = false, startTriggered = false;
+       for(int i=0; i<0x400000; i++)
+       {
+               if (readMem[i] && writeMemMin[i] != 0xFF && writeMemMax != 0x00)
+               {
+                       if (!startTriggered)
+                               startTriggered = true, endTriggered = false, start = i;
+
+                       WriteLog("\t\tMin/Max @ %06X: %u/%u\n", i, writeMemMin[i], writeMemMax[i]);
+               }
+               else
+               {
+                       if (!endTriggered)
+                       {
+                               end = i - 1, endTriggered = true, startTriggered = false;
+                               WriteLog("\tMemory range accessed: %06X - %06X\n", start, end);
+                       }
+               }
+       }
+       WriteLog("\n");//*/
+#endif
 //#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));
@@ -549,6 +708,11 @@ void jaguar_done(void)
        jaguar_dasm(0x802B00, 500);
        WriteLog("\n");//*/
 
+/*     WriteLog("\n\nM68000 disassembly at $8099F8...\n");
+       jaguar_dasm(0x809900, 500);
+       WriteLog("\n");//*/
+//8099F8
+
 //     WriteLog("Jaguar: CD BIOS version %04X\n", JaguarReadWord(0x3004));
        WriteLog("Jaguar: Interrupt enable = %02X\n", TOMReadByte(0xF000E1) & 0x1F);
        WriteLog("Jaguar: VBL interrupt is %s\n", ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) ? "enabled" : "disabled");
@@ -600,11 +764,6 @@ void jaguar_reset(void)
        WriteLog("\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7));
 }
 
-/*unused
-void jaguar_reset_handler(void)
-{
-}*/
-
 //
 // Main Jaguar execution loop (1 frame)
 //
@@ -654,8 +813,6 @@ if (effect_start)
 //             uint32 invalid_instruction_address = s68000exec(M68KCyclesPerScanline);
 //             if (invalid_instruction_address != 0x80000000)
 //                     cd_bios_process(invalid_instruction_address);
-               // These are divided by 2 because we're executing *half* lines...!
-               // Err, this is *already* accounted for in jaguar_init...!
                m68k_execute(M68KCyclesPerScanline);
                // No CD handling... !!! FIX !!!
                cd_bios_exec(i);        // NOTE: Ignores parameter...
index 6ed1fa12194989594a9e234d44884e57d2e8c15b..89a0098afe470d067c8669af3043e31ea653866d 100644 (file)
@@ -6,17 +6,10 @@
 // Cleanups/fixes by James L. Hammons
 //
 
-//#ifndef __PORT__
-//#include "include/stdafx.h"
-//#include <mmsystem.h>
-//#endif
 #include <time.h>
 #include <SDL.h>
-//#include "SDLptc.h"
 #include "jaguar.h"
 
-void main_screen_switch(void);
-
 #define BUTTON_U               0
 #define BUTTON_D               1
 #define BUTTON_L               2
@@ -40,6 +33,12 @@ void main_screen_switch(void);
 #define BUTTON_OPTION  19
 #define BUTTON_PAUSE   20
 
+// Private function prototypes
+
+void main_screen_switch(void);
+
+// Global vars
+
 static uint8 joystick_ram[4];
 static uint8 joypad_0_buttons[21];
 static uint8 joypad_1_buttons[21];
@@ -51,10 +50,12 @@ int gpu_start_log = 0;
 int op_start_log = 0;
 int blit_start_log = 0;
 int effect_start = 0;
+int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
 bool interactiveMode = false;
 bool iLeft, iRight, iToggle = false;
 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
 int objectPtr = 0;
+bool startMemLog = false;
 
 
 void main_screen_switch(void)
@@ -68,8 +69,6 @@ void main_screen_switch(void)
        if (fullscreen)
                mainSurfaceFlags |= SDL_FULLSCREEN;
 
-//???Should we do this???
-//     SDL_FreeSurface(mainSurface);
        mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
 
        if (mainSurface == NULL)
@@ -79,13 +78,6 @@ void main_screen_switch(void)
        }
 
        SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar");
-/*     if (fullscreen)
-               console.option("fullscreen output");
-       else
-               console.option("windowed output");*/
-
-//     console.close();
-//     console.open("Virtual Jaguar", tom_width, tom_height, format);
 }
 
 void joystick_init(void)
@@ -98,12 +90,12 @@ void joystick_exec(void)
        extern SDL_Joystick * joystick;
        extern bool useJoystick;
        uint8 * keystate = SDL_GetKeyState(NULL);
-//     extern Console console;
        
        memset(joypad_0_buttons, 0, 21);
        memset(joypad_1_buttons, 0, 21);
        gpu_start_log = 0;                                                      // Only log while key down!
        effect_start = 0;
+       effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
        blit_start_log = 0;
        iLeft = iRight = false;
 
@@ -145,8 +137,19 @@ void joystick_exec(void)
                op_start_log = 1;
        if (keystate[SDLK_b])
                blit_start_log = 1;
+
        if (keystate[SDLK_1])
                effect_start = 1;
+       if (keystate[SDLK_2])
+               effect_start2 = 1;
+       if (keystate[SDLK_3])
+               effect_start3 = 1;
+       if (keystate[SDLK_4])
+               effect_start4 = 1;
+       if (keystate[SDLK_5])
+               effect_start5 = 1;
+       if (keystate[SDLK_6])
+               effect_start6 = 1;
 
        if (keystate[SDLK_i])
                interactiveMode = true;
@@ -175,6 +178,11 @@ void joystick_exec(void)
        else
                keyHeld3 = false;
 
+       if (keystate[SDLK_e])
+               startMemLog = true;
+       if (keystate[SDLK_r])
+               WriteLog("\n--------> MARK!\n\n");
+
        if (keystate[SDLK_KP0])         joypad_0_buttons[BUTTON_0] = 0x01;
        if (keystate[SDLK_KP1])         joypad_0_buttons[BUTTON_1] = 0x01;
        if (keystate[SDLK_KP2])         joypad_0_buttons[BUTTON_2] = 0x01;
@@ -192,11 +200,8 @@ void joystick_exec(void)
     /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
     /* Joystick support                                 */
     
-//    if (console.JoyEnabled() == 1)
     if (useJoystick)
     {
-//             int16 x = SDL_JoystickGetAxis(console.joystick, 0),
-//                     y = SDL_JoystickGetAxis(console.joystick, 1);
                int16 x = SDL_JoystickGetAxis(joystick, 0),
                        y = SDL_JoystickGetAxis(joystick, 1);
        
@@ -209,13 +214,10 @@ void joystick_exec(void)
                if (y < -16384)
                        joypad_0_buttons[BUTTON_U] = 0x01;
        
-//             if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED)
                if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
                        joypad_0_buttons[BUTTON_A] = 0x01;
-//             if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED)
                if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
                        joypad_0_buttons[BUTTON_B] = 0x01;
-//             if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED)
                if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
                        joypad_0_buttons[BUTTON_C] = 0x01;
        }
@@ -236,18 +238,6 @@ void joystick_done(void)
 {
 }
 
-void joystick_byte_write(uint32 offset, uint8 data)
-{
-       joystick_ram[offset&0x03] = data;
-}
-
-void joystick_word_write(uint32 offset, uint16 data)
-{
-       offset &= 0x03;
-       joystick_ram[offset+0] = (data >> 8) & 0xFF;
-       joystick_ram[offset+1] = data & 0xFF;
-}
-
 uint8 joystick_byte_read(uint32 offset)
 {
        extern bool hardwareTypeNTSC;
@@ -259,7 +249,7 @@ uint8 joystick_byte_read(uint32 offset)
                int pad0Index = joystick_ram[1] & 0x0F;
                int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
                
-// This is bad--we're assuming that a bit is set in the last case
+// This is bad--we're assuming that a bit is set in the last case. Might not be so!
                if (!(pad0Index & 0x01)) 
                        pad0Index = 0;
                else if (!(pad0Index & 0x02)) 
@@ -291,7 +281,6 @@ uint8 joystick_byte_read(uint32 offset)
        }
        else if (offset == 3)
        {
-//             uint8 data = ((1 << 5) | (1 << 4) | 0x0F);
                uint8 data = 0x2F | (hardwareTypeNTSC ? 0x10 : 0x00);
                int pad0Index = joystick_ram[1] & 0x0F;
 //unused               int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
@@ -328,3 +317,15 @@ uint16 joystick_word_read(uint32 offset)
 {
        return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
 }
+
+void joystick_byte_write(uint32 offset, uint8 data)
+{
+       joystick_ram[offset&0x03] = data;
+}
+
+void joystick_word_write(uint32 offset, uint16 data)
+{
+       offset &= 0x03;
+       joystick_ram[offset+0] = (data >> 8) & 0xFF;
+       joystick_ram[offset+1] = data & 0xFF;
+}