]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/eeprom.cpp
Removed some cruft and nonstandard int/uint types, added M series BIOS.
[virtualjaguar] / src / eeprom.cpp
index 35e0d4d63ce575690407b5e0642bbfd97619a842..485a2a1f20985f88d548904e7862693bab329a4c 100644 (file)
@@ -3,7 +3,14 @@
 //
 // by Cal2
 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
-// Cleanups/enhancements by James L. Hammons
+// Cleanups/enhancements by James Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  01/16/2010  Created this log ;-)
 //
 
 #include "eeprom.h"
 
 #define eeprom_LOG
 
-static uint16 eeprom_ram[64];
+static uint16_t eeprom_ram[64];
 
 //
 // Private function prototypes
 //
 
 static void EEPROMSave(void);
-static void eeprom_set_di(uint32 state);
-static void eeprom_set_cs(uint32 state);
-static uint32 eeprom_get_do(void);
+static void eeprom_set_di(uint32_t state);
+static void eeprom_set_cs(uint32_t state);
+static uint32_t eeprom_get_do(void);
 
 enum { EE_STATE_START = 1, EE_STATE_OP_A, EE_STATE_OP_B, EE_STATE_0, EE_STATE_1,
        EE_STATE_2, EE_STATE_3, EE_STATE_0_0, EE_READ_ADDRESS, EE_STATE_0_0_0,
@@ -34,21 +41,21 @@ enum { EE_STATE_START = 1, EE_STATE_OP_A, EE_STATE_OP_B, EE_STATE_0, EE_STATE_1,
 
 // Local global variables
 
-static uint16 jerry_ee_state = EE_STATE_START;
-static uint16 jerry_ee_op = 0;
-static uint16 jerry_ee_rstate = 0;
-static uint16 jerry_ee_address_data = 0;
-static uint16 jerry_ee_address_cnt = 6;
-static uint16 jerry_ee_data = 0;
-static uint16 jerry_ee_data_cnt = 16;
-static uint16 jerry_writes_enabled = 0;
-static uint16 jerry_ee_direct_jump = 0;
+static uint16_t jerry_ee_state = EE_STATE_START;
+static uint16_t jerry_ee_op = 0;
+static uint16_t jerry_ee_rstate = 0;
+static uint16_t jerry_ee_address_data = 0;
+static uint16_t jerry_ee_address_cnt = 6;
+static uint16_t jerry_ee_data = 0;
+static uint16_t jerry_ee_data_cnt = 16;
+static uint16_t jerry_writes_enabled = 0;
+static uint16_t jerry_ee_direct_jump = 0;
 static char eeprom_filename[MAX_PATH];
 static bool foundEEPROM = false;
 
 void EepromInit(void)
 {
-       sprintf(eeprom_filename, "%s%08X.eep", vjs.EEPROMPath, (unsigned int)jaguarMainRomCRC32);
+       sprintf(eeprom_filename, "%s%08X.eep", vjs.EEPROMPath, (unsigned int)jaguarMainROMCRC32);
        FILE * fp = fopen(eeprom_filename, "rb");
 
        if (fp)
@@ -65,7 +72,7 @@ void EepromInit(void)
 void EepromReset(void)
 {
        if (!foundEEPROM)
-               memset(eeprom_ram, 0xFF, 64 * sizeof(uint16));
+               memset(eeprom_ram, 0xFF, 64 * sizeof(uint16_t));
 }
 
 void EepromDone(void)
@@ -87,7 +94,7 @@ static void EEPROMSave(void)
        fclose(fp);
 }
 
-uint8 EepromReadByte(uint32 offset)
+uint8_t EepromReadByte(uint32_t offset)
 {
        switch (offset)
        {
@@ -104,12 +111,12 @@ uint8 EepromReadByte(uint32 offset)
        return 0x00;
 }
 
-uint16 EepromReadWord(uint32 offset)
+uint16_t EepromReadWord(uint32_t offset)
 {
-       return ((uint16)EepromReadByte(offset + 0) << 8) | EepromReadByte(offset + 1);
+       return ((uint16_t)EepromReadByte(offset + 0) << 8) | EepromReadByte(offset + 1);
 }
 
-void EepromWriteByte(uint32 offset, uint8 data)
+void EepromWriteByte(uint32_t offset, uint8_t data)
 {
        switch (offset)
        {
@@ -125,13 +132,13 @@ void EepromWriteByte(uint32 offset, uint8 data)
        }
 }
 
-void EepromWriteWord(uint32 offset, uint16 data)
+void EepromWriteWord(uint32_t offset, uint16_t data)
 {
        EepromWriteByte(offset + 0, (data >> 8) & 0xFF);
        EepromWriteByte(offset + 1, data & 0xFF);
 }
 
-static void eeprom_set_di(uint32 data)
+static void eeprom_set_di(uint32_t data)
 {
 //     WriteLog("eeprom: di=%i\n",data);
 //     WriteLog("eeprom: state %i\n",jerry_ee_state);
@@ -193,6 +200,7 @@ static void eeprom_set_di(uint32 data)
                if (jerry_writes_enabled)
                        for(int i=0; i<64; i++)
                                eeprom_ram[i] = jerry_ee_data;
+
                EEPROMSave();                                                           // Save it NOW!
                //else
                //      WriteLog("eeprom: not writing because read only\n");
@@ -231,6 +239,7 @@ static void eeprom_set_di(uint32 data)
                //WriteLog("eeprom: writing 0x%.4x at 0x%.2x\n",jerry_ee_data,jerry_ee_address_data);
                if (jerry_writes_enabled)
                        eeprom_ram[jerry_ee_address_data] = jerry_ee_data;
+
                EEPROMSave();                                                           // Save it NOW!
                jerry_ee_state = EE_STATE_BUSY;
                break;
@@ -253,6 +262,7 @@ static void eeprom_set_di(uint32 data)
                //WriteLog("eeprom: erasing 0x%.2x\n",jerry_ee_address_data);
                if (jerry_writes_enabled)
                        eeprom_ram[jerry_ee_address_data] = 0xFFFF;
+
                jerry_ee_state = EE_STATE_BUSY;
                break;
        case EE_READ_DATA:
@@ -260,9 +270,11 @@ static void eeprom_set_di(uint32 data)
                jerry_ee_data <<= 1;
                jerry_ee_data |= data;
                jerry_ee_data_cnt--;
+
                if (!jerry_ee_data_cnt)
                {
                        jerry_ee_state = jerry_ee_rstate;
+
                        if (jerry_ee_direct_jump)
                                eeprom_set_di(data);
                }
@@ -272,10 +284,12 @@ static void eeprom_set_di(uint32 data)
                jerry_ee_address_data |= data;
                jerry_ee_address_cnt--;
 //             WriteLog("eeprom:\t%i bits remaining\n",jerry_ee_address_cnt);
+
                if (!jerry_ee_address_cnt)
                {
                        jerry_ee_state = jerry_ee_rstate;
                        //WriteLog("eeprom:\t\tread address 0x%.2x\n",jerry_ee_address_data);
+
                        if (jerry_ee_direct_jump)
                                eeprom_set_di(data);
                }
@@ -285,7 +299,7 @@ static void eeprom_set_di(uint32 data)
        }
 }
 
-static void eeprom_set_cs(uint32 state)
+static void eeprom_set_cs(uint32_t state)
 {
 //     WriteLog("eeprom: cs=%i\n",state);
        jerry_ee_state = EE_STATE_START;
@@ -298,9 +312,9 @@ static void eeprom_set_cs(uint32 state)
        jerry_writes_enabled = 1;
 }
 
-static uint32 eeprom_get_do(void)
+static uint32_t eeprom_get_do(void)
 {
-       uint16 data = 1;
+       uint16_t data = 1;
 
        switch (jerry_ee_state)
        {
@@ -314,6 +328,7 @@ static uint32 eeprom_get_do(void)
        case EE_STATE_2_0:
                jerry_ee_data_cnt--;
                data = (eeprom_ram[jerry_ee_address_data] & (1 << jerry_ee_data_cnt)) >> jerry_ee_data_cnt;
+
                if (!jerry_ee_data_cnt)
                {
                        //WriteLog("eeprom: read 0x%.4x at 0x%.2x cpu %i pc=0x%.8x\n",eeprom_ram[jerry_ee_address_data],jerry_ee_address_data,jaguar_cpu_in_exec,s68000readPC());