]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gpu.cpp
Added HOSTCC to m68000 Makefile, improvements to M68K disassembler.
[virtualjaguar] / src / gpu.cpp
index 1d7afa79a3bfb46f0e75d553d98ab7d96dbf8e5b..e5855fea7eda560f68fcdc186f74b781febaf36d 100644 (file)
@@ -32,7 +32,7 @@
 #include "jagdasm.h"
 #include "jaguar.h"
 #include "log.h"
-#include "m68k.h"
+#include "m68000/m68kinterface.h"
 //#include "memory.h"
 #include "tom.h"
 
@@ -323,8 +323,8 @@ static uint32 gpu_div_control;
 // a bit before writing a result. I.e., if the result of an operation leaves a zero in
 // the carry flag, you don't have to zero gpu_flag_c before you can write that zero!
 static uint8 gpu_flag_z, gpu_flag_n, gpu_flag_c;
-static uint32 gpu_reg_bank_0[32];
-static uint32 gpu_reg_bank_1[32];
+uint32 gpu_reg_bank_0[32];
+uint32 gpu_reg_bank_1[32];
 static uint32 * gpu_reg;
 static uint32 * gpu_alternate_reg;
 
@@ -501,7 +501,11 @@ uint16 GPUReadWord(uint32 offset, uint32 who/*=UNKNOWN*/)
 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]);
+       {
+               WriteLog("GPU: ReadLong--Attempt to read from GPU register file (%X) by %s!\n", offset, whoName[who]);
+               uint32 reg = (offset & 0xFC) >> 2;
+               return (reg < 32 ? gpu_reg_bank_0[reg] : gpu_reg_bank_1[reg - 32]); 
+       }
 
 //     if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000))
        if ((offset >= GPU_WORK_RAM_BASE) && (offset <= GPU_WORK_RAM_BASE + 0x0FFC))
@@ -647,12 +651,15 @@ void GPUWriteWord(uint32 offset, uint16 data, uint32 who/*=UNKNOWN*/)
                {
 //WriteLog("[GPU W16:%08X,%04X]", offset, data);
                        uint32 old_data = GPUReadLong(offset & 0xFFFFFFC, who);
+
                        if (offset & 0x02)
                                old_data = (old_data & 0xFFFF0000) | (data & 0xFFFF);
                        else
                                old_data = (old_data & 0x0000FFFF) | ((data & 0xFFFF) << 16);
+
                        GPUWriteLong(offset & 0xFFFFFFC, old_data, who);
                }
+
                return;
        }
        else if ((offset == GPU_WORK_RAM_BASE + 0x0FFF) || (GPU_CONTROL_RAM_BASE + 0x1F))
@@ -700,7 +707,9 @@ void GPUWriteLong(uint32 offset, uint32 data, uint32 who/*=UNKNOWN*/)
                case 0x00:
                {
                        bool IMASKCleared = (gpu_flags & IMASK) && !(data & IMASK);
-                       gpu_flags = data;
+                       // NOTE: According to the JTRM, writing a 1 to IMASK has no effect; only the
+                       //       IRQ logic can set it. So we mask it out here to prevent problems...
+                       gpu_flags = data & (~IMASK);
                        gpu_flag_z = gpu_flags & ZERO_FLAG;
                        gpu_flag_c = (gpu_flags & CARRY_FLAG) >> 1;
                        gpu_flag_n = (gpu_flags & NEGA_FLAG) >> 2;
@@ -771,6 +780,7 @@ 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 & 0xF7C0) | (data & (~0xF7C0));
 
                        // if gpu wasn't running but is now running, execute a few cycles