//
// 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,
// 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 EepromReset(void)
{
if (!foundEEPROM)
- memset(eeprom_ram, 0xFF, 64 * sizeof(uint16));
+ memset(eeprom_ram, 0xFF, 64 * sizeof(uint16_t));
}
void EepromDone(void)
fclose(fp);
}
-uint8 EepromReadByte(uint32 offset)
+uint8_t EepromReadByte(uint32_t offset)
{
switch (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)
{
}
}
-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);
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");
//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;
//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:
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);
}
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);
}
}
}
-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;
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)
{
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());