mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
integrate SPI EEPROM
This commit is contained in:
parent
8c2137f11f
commit
6a47c2d4fb
4 changed files with 33 additions and 13 deletions
|
@ -36,7 +36,9 @@
|
|||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#include "shared.h"
|
||||
#include "../pico_int.h"
|
||||
#include "../cd/genplus_macros.h"
|
||||
#include "eeprom_spi.h"
|
||||
|
||||
/* max supported size 64KB (25x512/95x512) */
|
||||
#define SIZE_MASK 0xffff
|
||||
|
@ -72,16 +74,16 @@ typedef struct
|
|||
|
||||
static T_EEPROM_SPI spi_eeprom;
|
||||
|
||||
void eeprom_spi_init()
|
||||
void *eeprom_spi_init(int *size)
|
||||
{
|
||||
/* reset eeprom state */
|
||||
memset(&spi_eeprom, 0, sizeof(T_EEPROM_SPI));
|
||||
spi_eeprom.out = 1;
|
||||
spi_eeprom.state = GET_OPCODE;
|
||||
|
||||
/* enable backup RAM */
|
||||
sram.custom = 2;
|
||||
sram.on = 1;
|
||||
if (size)
|
||||
*size = sizeof(T_EEPROM_SPI);
|
||||
return &spi_eeprom;
|
||||
}
|
||||
|
||||
void eeprom_spi_write(unsigned char data)
|
||||
|
@ -208,7 +210,7 @@ void eeprom_spi_write(unsigned char data)
|
|||
if (spi_eeprom.opcode & 0x01)
|
||||
{
|
||||
/* READ operation */
|
||||
spi_eeprom.buffer = sram.sram[spi_eeprom.addr];
|
||||
spi_eeprom.buffer = SRam.data[spi_eeprom.addr];
|
||||
spi_eeprom.state = READ_BYTE;
|
||||
}
|
||||
else
|
||||
|
@ -264,7 +266,7 @@ void eeprom_spi_write(unsigned char data)
|
|||
/* $C000-$FFFF (sector #3) is protected */
|
||||
if (spi_eeprom.addr < 0xC000)
|
||||
{
|
||||
sram.sram[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||
SRam.data[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -274,7 +276,7 @@ void eeprom_spi_write(unsigned char data)
|
|||
/* $8000-$FFFF (sectors #2 and #3) is protected */
|
||||
if (spi_eeprom.addr < 0x8000)
|
||||
{
|
||||
sram.sram[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||
SRam.data[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -288,7 +290,7 @@ void eeprom_spi_write(unsigned char data)
|
|||
default:
|
||||
{
|
||||
/* no sectors protected */
|
||||
sram.sram[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||
SRam.data[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +332,7 @@ void eeprom_spi_write(unsigned char data)
|
|||
{
|
||||
/* read next array byte */
|
||||
spi_eeprom.addr = (spi_eeprom.addr + 1) & SIZE_MASK;
|
||||
spi_eeprom.buffer = sram.sram[spi_eeprom.addr];
|
||||
spi_eeprom.buffer = SRam.data[spi_eeprom.addr];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue