Files
86Box/src/tandy_eeprom.c
OBattler f6ef1f833c Vastly overhauled the UI, there's now a completely new Settings dialog as well as a status bar with disk activity icons and removable drive menus;
Thoroughly clean up the code to vastly reduce the number of compiler warnings and found and fixed several bugs in the process;
Applied all mainline PCem commits;
Added SCSI hard disk emulation;
Commented out all unfinished machines and graphics cards;
Added the AOpen AP53 and ASUS P/I-P55T2 machines as well as another Tyan 440FX machine, all three with AMI WinBIOS (patch from TheCollector1995);
Added the Diamond Stealth 3D 3000 (S3 ViRGE/VX) graphics card (patch from TheCollector1995);
Added the PS/2 XT IDE (AccuLogic) HDD Controller (patch from TheCollector1995);
Added Microsoft/Logitech Bus Mouse emulation (patch from waltje);
Overhauled the makefiles (patch from waltje);
Added the Adaptec AHA-1542CF SCSI controller (patch from waltje);
Added preliminary (but still unfinished) Adaptec AHA-154x SCSI controller BIOS support (patch from waltje);
Added an ISABugger debugging device (patch from waltje);
Added sanity checks to the Direct3D code.
2017-05-05 01:49:42 +02:00

178 lines
5.3 KiB
C

/* Copyright holders: Sarah Walker
see COPYING for more details
*/
#include <stdlib.h>
#include "ibm.h"
#include "device.h"
#include "io.h"
#include "tandy_eeprom.h"
typedef struct
{
int state;
int count;
int addr;
int clock;
uint16_t data;
uint16_t store[64];
int romset;
} tandy_eeprom_t;
enum
{
EEPROM_IDLE,
EEPROM_GET_OPERATION,
EEPROM_READ,
EEPROM_WRITE
};
static int eeprom_data_out;
void tandy_eeprom_write(uint16_t addr, uint8_t val, void *p)
{
tandy_eeprom_t *eeprom = (tandy_eeprom_t *)p;
if ((val & 4) && !eeprom->clock)
{
switch (eeprom->state)
{
case EEPROM_IDLE:
switch (eeprom->count)
{
case 0:
if (!(val & 3))
eeprom->count = 1;
else
eeprom->count = 0;
break;
case 1:
if ((val & 3) == 2)
eeprom->count = 2;
else
eeprom->count = 0;
break;
case 2:
if ((val & 3) == 3)
eeprom->state = EEPROM_GET_OPERATION;
eeprom->count = 0;
break;
}
break;
case EEPROM_GET_OPERATION:
eeprom->data = (eeprom->data << 1) | (val & 1);
eeprom->count++;
if (eeprom->count == 8)
{
eeprom->count = 0;
eeprom->addr = eeprom->data & 0x3f;
switch (eeprom->data & 0xc0)
{
case 0x40:
eeprom->state = EEPROM_WRITE;
break;
case 0x80:
eeprom->state = EEPROM_READ;
eeprom->data = eeprom->store[eeprom->addr];
break;
default:
eeprom->state = EEPROM_IDLE;
break;
}
}
break;
case EEPROM_READ:
eeprom_data_out = eeprom->data & 0x8000;
eeprom->data <<= 1;
eeprom->count++;
if (eeprom->count == 16)
{
eeprom->count = 0;
eeprom->state = EEPROM_IDLE;
}
break;
case EEPROM_WRITE:
eeprom->data = (eeprom->data << 1) | (val & 1);
eeprom->count++;
if (eeprom->count == 16)
{
eeprom->count = 0;
eeprom->state = EEPROM_IDLE;
eeprom->store[eeprom->addr] = eeprom->data;
}
break;
}
}
eeprom->clock = val & 4;
}
int tandy_eeprom_read()
{
return eeprom_data_out;
}
void *tandy_eeprom_init()
{
tandy_eeprom_t *eeprom = malloc(sizeof(tandy_eeprom_t));
FILE *f;
memset(eeprom, 0, sizeof(tandy_eeprom_t));
eeprom->romset = romset;
switch (romset)
{
case ROM_TANDY1000HX:
f = romfopen(nvr_concat("tandy1000hx.bin"), "rb");
break;
case ROM_TANDY1000SL2:
f = romfopen(nvr_concat("tandy1000sl2.bin"), "rb");
break;
}
if (f)
{
fread(eeprom->store, 128, 1, f);
fclose(f);
}
else
memset(eeprom->store, 0, 128);
io_sethandler(0x037c, 0x0001, NULL, NULL, NULL, tandy_eeprom_write, NULL, NULL, eeprom);
return eeprom;
}
void tandy_eeprom_close(void *p)
{
tandy_eeprom_t *eeprom = (tandy_eeprom_t *)p;
FILE *f;
switch (eeprom->romset)
{
case ROM_TANDY1000HX:
f = romfopen(nvr_concat("tandy1000hx.bin"), "wb");
break;
case ROM_TANDY1000SL2:
f = romfopen(nvr_concat("tandy1000sl2.bin"), "wb");
break;
}
fwrite(eeprom->store, 128, 1, f);
fclose(f);
free(eeprom);
}
device_t tandy_eeprom_device =
{
"Tandy EEPROM",
0,
tandy_eeprom_init,
tandy_eeprom_close,
NULL,
NULL,
NULL,
NULL,
NULL
};