]> Shamusworld >> Repos - virtualjaguar/commitdiff
Attempting to add sanity to memory access: Added mmu.cpp/h
authorShamus Hammons <jlhamm@acm.org>
Thu, 26 Nov 2009 05:09:55 +0000 (05:09 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 26 Nov 2009 05:09:55 +0000 (05:09 +0000)
Makefile
src/cdintf.cpp
src/jaguar.cpp
src/jerry.cpp
src/joystick.cpp
src/mmu.cpp [new file with mode: 0644]
src/mmu.h [new file with mode: 0644]
src/tom.cpp

index af2d38328ca1f893a1d57cd36a72c4997ccd7831..e1467c9da2cc6bb1485f591f28d552b95c8afe14 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -102,6 +102,7 @@ OBJS = \
        obj/joystick.o      \
        obj/log.o           \
        obj/memory.o        \
+       obj/mmu.o           \
        obj/objectp.o       \
        obj/sdlemu_config.o \
        obj/sdlemu_opengl.o \
index 2f54be5f439d96445843bc374e9873c1fce46ccf..066f2cc2588e9cb7772d464e50b86e5721fc1f22 100644 (file)
@@ -81,7 +81,7 @@ void CDIntfDone(void)
 
 bool CDIntfReadBlock(uint32 sector, uint8 * buffer)
 {
-#warning !!! FIX !!! CDIntfReadBlock not implemented!
+#warning "!!! FIX !!! CDIntfReadBlock not implemented!"
        // !!! FIX !!!
        WriteLog("CDINTF: ReadBlock unimplemented!\n");
        return false;
@@ -89,7 +89,7 @@ bool CDIntfReadBlock(uint32 sector, uint8 * buffer)
 
 uint32 CDIntfGetNumSessions(void)
 {
-#warning !!! FIX !!! CDIntfGetNumSessions not implemented!
+#warning "!!! FIX !!! CDIntfGetNumSessions not implemented!"
        // !!! FIX !!!
        // Still need relevant code here... !!! FIX !!!
        return 2;
@@ -97,14 +97,14 @@ uint32 CDIntfGetNumSessions(void)
 
 void CDIntfSelectDrive(uint32 driveNum)
 {
-#warning !!! FIX !!! CDIntfSelectDrive not implemented!
+#warning "!!! FIX !!! CDIntfSelectDrive not implemented!"
        // !!! FIX !!!
        WriteLog("CDINTF: SelectDrive unimplemented!\n");
 }
 
 uint32 CDIntfGetCurrentDrive(void)
 {
-#warning !!! FIX !!! CDIntfGetCurrentDrive not implemented!
+#warning "!!! FIX !!! CDIntfGetCurrentDrive not implemented!"
        // !!! FIX !!!
        WriteLog("CDINTF: GetCurrentDrive unimplemented!\n");
        return 0;
@@ -112,7 +112,7 @@ uint32 CDIntfGetCurrentDrive(void)
 
 const uint8 * CDIntfGetDriveName(uint32 driveNum)
 {
-#warning !!! FIX !!! CDIntfGetDriveName driveNum is currently ignored!
+#warning "!!! FIX !!! CDIntfGetDriveName driveNum is currently ignored!"
        // driveNum is currently ignored... !!! FIX !!!
 
 #ifdef HAVE_LIB_CDIO
@@ -127,7 +127,7 @@ const uint8 * CDIntfGetDriveName(uint32 driveNum)
 
 uint8 CDIntfGetSessionInfo(uint32 session, uint32 offset)
 {
-#warning !!! FIX !!! CDIntfGetSessionInfo not implemented!
+#warning "!!! FIX !!! CDIntfGetSessionInfo not implemented!"
        // !!! FIX !!!
        WriteLog("CDINTF: GetSessionInfo unimplemented!\n");
        return 0xFF;
@@ -135,7 +135,7 @@ uint8 CDIntfGetSessionInfo(uint32 session, uint32 offset)
 
 uint8 CDIntfGetTrackInfo(uint32 track, uint32 offset)
 {
-#warning !!! FIX !!! CDIntfTrackInfo not implemented!
+#warning "!!! FIX !!! CDIntfTrackInfo not implemented!"
        // !!! FIX !!!
        WriteLog("CDINTF: GetTrackInfo unimplemented!\n");
        return 0xFF;
index f524242241769b5f0e3af7778c024fcc4763c28d..582ec85d1de2662f6325c9d2dadd8b9d717486b0 100644 (file)
@@ -70,7 +70,8 @@ uint8 jaguarCDBootROM[0x040000];                                      // 68K CPU CD BIOS ROM
 bool BIOSLoaded = false;
 bool CDBIOSLoaded = false;
 
-uint8 cdRAM[0x100];
+//uint8 cdRAM[0x100];
+uint8 * cdRAM = &jaguarMainROM[0x5FFF00];
 uint8 tomRAM[0x4000];
 uint8 jerryRAM[0x10000];
 
@@ -364,7 +365,7 @@ things that are entirely internal to those modules. This way we should be able t
 this crap which is currently scattered over Hell's Half Acre(tm).
 
 Also: We need to distinguish whether or not we need .b, .w, and .dw versions of everything, or if there
-is a good way to collapse that shit.
+is a good way to collapse that shit (look below for inspiration). Current method works, but is error prone.
 
 /*************************************
  *
@@ -443,6 +444,116 @@ ADDRESS_MAP_END
 #ifdef EXPERIMENTAL_MEMORY_HANDLING
 // Needed defines...
 #define NEW_TIMER_SYSTEM
+
+/*
+uint8 jaguarMainRAM[0x400000];                                         // 68K CPU RAM
+uint8 jaguarMainROM[0x600000];                                         // 68K CPU ROM
+uint8 jaguarBootROM[0x040000];                                         // 68K CPU BIOS ROM--uses only half of this!
+uint8 jaguarCDBootROM[0x040000];                                       // 68K CPU CD BIOS ROM
+bool BIOSLoaded = false;
+bool CDBIOSLoaded = false;
+
+uint8 cdRAM[0x100];
+uint8 tomRAM[0x4000];
+uint8 jerryRAM[0x10000];
+static uint16 eeprom_ram[64];
+
+// NOTE: CD BIOS ROM is read from cartridge space @ $802000 (it's a cartridge, after all)
+*/
+
+enum MemType { MM_NOP = 0, MM_RAM, MM_ROM, MM_IO };
+
+// M68K Memory map/handlers
+uint32         {
+       { 0x000000, 0x3FFFFF, MM_RAM, jaguarMainRAM },
+       { 0x800000, 0xDFFEFF, MM_ROM, jaguarMainROM },
+// Note that this is really memory mapped I/O region...
+//     { 0xDFFF00, 0xDFFFFF, MM_RAM, cdRAM },
+       { 0xDFFF00, 0xDFFF03, MM_IO,  cdBUTCH }, // base of Butch == interrupt control register, R/W
+       { 0xDFFF04, 0xDFFF07, MM_IO,  cdDSCNTRL }, // DSA control register, R/W
+       { 0xDFFF0A, 0xDFFF0B, MM_IO,  cdDS_DATA }, // DSA TX/RX data, R/W
+       { 0xDFFF10, 0xDFFF13, MM_IO,  cdI2CNTRL }, // i2s bus control register, R/W
+       { 0xDFFF14, 0xDFFF17, MM_IO,  cdSBCNTRL }, // CD subcode control register, R/W
+       { 0xDFFF18, 0xDFFF1B, MM_IO,  cdSUBDATA }, // Subcode data register A
+       { 0xDFFF1C, 0xDFFF1F, MM_IO,  cdSUBDATB }, // Subcode data register B
+       { 0xDFFF20, 0xDFFF23, MM_IO,  cdSB_TIME }, // Subcode time and compare enable (D24)
+       { 0xDFFF24, 0xDFFF27, MM_IO,  cdFIFO_DATA }, // i2s FIFO data
+       { 0xDFFF28, 0xDFFF2B, MM_IO,  cdI2SDAT2 }, // i2s FIFO data (old)
+       { 0xDFFF2C, 0xDFFF2F, MM_IO,  cdUNKNOWN }, // Seems to be some sort of I2S interface
+
+       { 0xE00000, 0xE3FFFF, MM_ROM, jaguarBootROM },
+
+//     { 0xF00000, 0xF0FFFF, MM_IO,  TOM_REGS_RW },
+       { 0xF00050, 0xF00051, MM_IO,  tomTimerPrescaler },
+       { 0xF00052, 0xF00053, MM_IO,  tomTimerDivider },
+       { 0xF00400, 0xF005FF, MM_RAM, tomRAM }, // CLUT A&B: How to link these? Write to one writes to the other...
+       { 0xF00600, 0xF007FF, MM_RAM, tomRAM }, // Actually, this is a good approach--just make the reads the same as well
+       //What about LBUF writes???
+       { 0xF02100, 0xF0211F, MM_IO,  GPUWriteByte }, // GPU CONTROL
+       { 0xF02200, 0xF0229F, MM_IO,  BlitterWriteByte }, // BLITTER
+       { 0xF03000, 0xF03FFF, MM_RAM, GPUWriteByte }, // GPU RAM
+
+       { 0xF10000, 0xF1FFFF, MM_IO,  JERRY_REGS_RW },
+
+/*
+       EEPROM:
+       { 0xF14001, 0xF14001, MM_IO_RO, eepromFOO }
+       { 0xF14801, 0xF14801, MM_IO_WO, eepromBAR }
+       { 0xF15001, 0xF15001, MM_IO_RW, eepromBAZ }
+
+       JOYSTICK:
+       { 0xF14000, 0xF14003, MM_IO,  joystickFoo }
+       0 = pad0/1 button values (4 bits each), RO(?)
+       1 = pad0/1 index value (4 bits each), WO
+       2 = unused, RO
+       3 = NTSC/PAL, certain button states, RO
+
+JOYSTICK    $F14000               Read/Write
+            15.....8  7......0
+Read        fedcba98  7654321q    f-1    Signals J15 to J1
+                                  q      Cartridge EEPROM  output data
+Write       exxxxxxm  76543210    e      1 = enable  J7-J0 outputs
+                                         0 = disable J7-J0 outputs
+                                  x      don't care
+                                  m      Audio mute
+                                         0 = Audio muted (reset state)
+                                         1 = Audio enabled
+                                  7-4    J7-J4 outputs (port 2)
+                                  3-0    J3-J0 outputs (port 1)
+JOYBUTS     $F14002               Read Only
+            15.....8  7......0
+Read        xxxxxxxx  rrdv3210    x      don't care
+                                  r      Reserved
+                                  d      Reserved
+                                  v      1 = NTSC Video hardware
+                                         0 = PAL  Video hardware
+                                  3-2    Button inputs B3 & B2 (port 2)
+                                  1-0    Button inputs B1 & B0 (port 1)
+
+J4 J5 J6 J7  Port 2    B2     B3    J12  J13   J14  J15
+J3 J2 J1 J0  Port 1    B0     B1    J8   J9    J10  J11
+ 0  0  0  0
+ 0  0  0  1
+ 0  0  1  0
+ 0  0  1  1
+ 0  1  0  0
+ 0  1  0  1
+ 0  1  1  0
+ 0  1  1  1  Row 3     C3   Option  #     9     6     3
+ 1  0  0  0
+ 1  0  0  1
+ 1  0  1  0
+ 1  0  1  1  Row 2     C2      C    0     8     5     2
+ 1  1  0  0
+ 1  1  0  1  Row 1     C1      B    *     7     4     1
+ 1  1  1  0  Row 0   Pause     A    Up  Down  Left  Right
+ 1  1  1  1
+
+0 bit read in any position means that button is pressed.
+C3 = C2 = 1 means std. Jag. cntrlr. or nothing attached.
+*/
+};
+
 void WriteByte(uint32 address, uint8 byte, uint32 who/*=UNKNOWN*/)
 {
        // Not sure, but I think the system only has 24 address bits...
@@ -1511,7 +1622,7 @@ void JaguarExecute(uint32 * backbuffer, bool render)
 //     uint16 vde = TOMReadWord(0xF00048);
 
        uint16 refreshRate = (vjs.hardwareTypeNTSC ? 60 : 50);
-       uint32 m68kCockRate = (vjs.hardwareTypeNTSC ? M68K_CLOCK_RATE_NTSC : M68K_CLOCK_RATE_PAL);
+       uint32 m68kClockRate = (vjs.hardwareTypeNTSC ? M68K_CLOCK_RATE_NTSC : M68K_CLOCK_RATE_PAL);
 //Not sure the above is correct, since the number of lines and timings given in the JTRM
 //seem to indicate the refresh rate is *half* the above...
 //     uint16 refreshRate = (vjs.hardwareTypeNTSC ? 30 : 25);
index c564d4306147a0aa836ac4b64e42843d04f9fbda..e7aee5801217489e8b2d3a8453d0ba846383a435 100644 (file)
@@ -63,7 +63,7 @@
 //                       W   x------- --------      (enable joystick outputs)
 //                       W   -------- xxxxxxxx      (joystick output data)
 //     F14002          R     xxxxxxxx xxxxxxxx   JOYBUTS - button register
-//     F14800-F14FFF   R/W   xxxxxxxx xxxxxxxx   GPI00 - reserved (CD-ROM?)
+//     F14800-F14FFF   R/W   xxxxxxxx xxxxxxxx   GPI00 - reserved (CD-ROM? no.)
 //     F15000-F15FFF   R/W   xxxxxxxx xxxxxxxx   GPI01 - reserved
 //     F16000-F16FFF   R/W   xxxxxxxx xxxxxxxx   GPI02 - reserved
 //     F17000-F177FF   R/W   xxxxxxxx xxxxxxxx   GPI03 - reserved
@@ -356,7 +356,7 @@ void JERRYI2SCallback(void)
 {
        // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP???
 //Yes, it should. !!! FIX !!!
-#warning Yes, it should. !!! FIX !!!
+#warning "Yes, it should. !!! FIX !!!"
        jerry_i2s_interrupt_divide &= 0xFF;
        // We don't have to divide the RISC clock rate by this--the reason is a bit
        // convoluted. Will put explanation here later...
index aa81c0ff3ebc107412ba38e365a80dd6735bd759..9fe2197a276dbf14e5caebc7ac03e44239bed4d8 100644 (file)
@@ -271,7 +271,7 @@ void JoystickDone(void)
 
 uint8 JoystickReadByte(uint32 offset)
 {
-#warning No bounds checking done in JoystickReadByte!
+#warning "No bounds checking done in JoystickReadByte!"
 //     extern bool hardwareTypeNTSC;
        offset &= 0x03;
 
@@ -282,6 +282,10 @@ uint8 JoystickReadByte(uint32 offset)
                int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
 
 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
+// NOTE: values $7, B, D, & E are only legal ones for pad 0, (rows 3 to 0, in both cases)
+//              $E, D, B, & 7 are only legal ones for pad 1
+//       So the following code is WRONG!
+
                if (!(pad0Index & 0x01))
                        pad0Index = 0;
                else if (!(pad0Index & 0x02))
@@ -318,6 +322,7 @@ uint8 JoystickReadByte(uint32 offset)
                int pad0Index = joystick_ram[1] & 0x0F;
 //unused               int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
 
+//WTF is this shit?
                if (!(pad0Index & 0x01))
                {
                        if (joypad_0_buttons[BUTTON_PAUSE])
@@ -340,6 +345,7 @@ uint8 JoystickReadByte(uint32 offset)
                        if (joypad_0_buttons[BUTTON_OPTION])
                                data ^= 0x02;
                }
+
                return data;
        }
 
@@ -358,7 +364,7 @@ void JoystickWriteByte(uint32 offset, uint8 data)
 
 void JoystickWriteWord(uint32 offset, uint16 data)
 {
-#warning No bounds checking done for JoystickWriteWord!
+#warning "No bounds checking done for JoystickWriteWord!"
        offset &= 0x03;
        joystick_ram[offset + 0] = (data >> 8) & 0xFF;
        joystick_ram[offset + 1] = data & 0xFF;
diff --git a/src/mmu.cpp b/src/mmu.cpp
new file mode 100644 (file)
index 0000000..3e746d2
--- /dev/null
@@ -0,0 +1,48 @@
+//
+// mmu.cpp
+//
+// Jaguar Memory Manager Unit
+//
+// by James L. Hammons
+//
+// JLH = James L. Hammons
+//
+// WHO  WHEN        WHAT
+// ---  ----------  -----------------------------------------------------------
+// JLH  11/25/2009  Created this file. :-)
+//
+
+#include "mmu.h"
+
+void MMUWrite8(uint32 address, uint8 data, uint32 who/*= UNKNOWN*/)
+{
+}
+
+void MMUWrite16(uint32 address, uint16 data, uint32 who/*= UNKNOWN*/)
+{
+}
+
+void MMUWrite32(uint32 address, uint32 data, uint32 who/*= UNKNOWN*/)
+{
+}
+
+void MMUWrite64(uint32 address, uint64 data, uint32 who/*= UNKNOWN*/)
+{
+}
+
+uint8 MMURead8(uint32 address, uint32 who/*= UNKNOWN*/)
+{
+}
+
+uint16 MMURead16(uint32 address, uint32 who/*= UNKNOWN*/)
+{
+}
+
+uint32 MMURead32(uint32 address, uint32 who/*= UNKNOWN*/)
+{
+}
+
+uint64 MMURead64(uint32 address, uint32 who/*= UNKNOWN*/)
+{
+}
+
diff --git a/src/mmu.h b/src/mmu.h
new file mode 100644 (file)
index 0000000..6a4cce9
--- /dev/null
+++ b/src/mmu.h
@@ -0,0 +1,19 @@
+//
+// mmu.h
+//
+// Jaguar Memory Manager Unit
+//
+// by James L. Hammons
+//
+
+#include "types.h"
+
+void MMUWrite8(uint32 address, uint8 data, uint32 who = UNKNOWN);
+void MMUWrite16(uint32 address, uint16 data, uint32 who = UNKNOWN);
+void MMUWrite32(uint32 address, uint32 data, uint32 who = UNKNOWN);
+void MMUWrite64(uint32 address, uint64 data, uint32 who = UNKNOWN);
+uint8 MMURead8(uint32 address, uint32 who = UNKNOWN);
+uint16 MMURead16(uint32 address, uint32 who = UNKNOWN);
+uint32 MMURead32(uint32 address, uint32 who = UNKNOWN);
+uint64 MMURead64(uint32 address, uint32 who = UNKNOWN);
+
index 36f3d8bbe6c3f1ec6767a60cf66e193e854b5d26..e33201ccd818e6fe9884adc79b62cecfa40fbd05 100644 (file)
@@ -1441,7 +1441,7 @@ if (offset >= 0xF02000 && offset <= 0xF020FF)
        offset &= 0x3FFF;
        if (offset == 0x28)                     // VMODE (Why? Why not OBF?)
 //Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!!
-#warning Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!!
+#warning "Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!!"
                objectp_running = 1;
 
        if (offset >= 0x30 && offset <= 0x4E)