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
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "../pico_int.h"
|
#include "../pico_int.h"
|
||||||
#include "../memory.h"
|
#include "../memory.h"
|
||||||
|
#include "eeprom_spi.h"
|
||||||
|
|
||||||
|
|
||||||
/* The SSFII mapper */
|
/* The SSFII mapper */
|
||||||
|
@ -270,6 +271,7 @@ static carthw_state_chunk carthw_pier_state[] =
|
||||||
{
|
{
|
||||||
{ CHUNK_CARTHW, sizeof(pier_regs), pier_regs },
|
{ CHUNK_CARTHW, sizeof(pier_regs), pier_regs },
|
||||||
{ CHUNK_CARTHW + 1, sizeof(pier_dump_prot), &pier_dump_prot },
|
{ CHUNK_CARTHW + 1, sizeof(pier_dump_prot), &pier_dump_prot },
|
||||||
|
{ CHUNK_CARTHW + 2, 0, NULL }, // filled later
|
||||||
{ 0, 0, NULL }
|
{ 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -308,7 +310,8 @@ static void carthw_pier_write8(u32 a, u32 d)
|
||||||
base = d << 19;
|
base = d << 19;
|
||||||
goto do_map;
|
goto do_map;
|
||||||
case 0x09:
|
case 0x09:
|
||||||
// TODO
|
SRam.changed = 1;
|
||||||
|
eeprom_spi_write(d);
|
||||||
break;
|
break;
|
||||||
case 0x0b:
|
case 0x0b:
|
||||||
// eeprom read
|
// eeprom read
|
||||||
|
@ -346,7 +349,7 @@ static u32 carthw_pier_read8(u32 a)
|
||||||
return PicoRead8_io(a);
|
return PicoRead8_io(a);
|
||||||
|
|
||||||
if (a == 0xa1300b)
|
if (a == 0xa1300b)
|
||||||
return 0; // TODO
|
return eeprom_spi_read(a);
|
||||||
|
|
||||||
elprintf(EL_UIO, "pier r8 [%06x] @%06x", a, SekPc);
|
elprintf(EL_UIO, "pier r8 [%06x] @%06x", a, SekPc);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -415,10 +418,13 @@ static void carthw_pier_reset(void)
|
||||||
pier_regs[1] = pier_regs[2] = pier_regs[3] = 0;
|
pier_regs[1] = pier_regs[2] = pier_regs[3] = 0;
|
||||||
pier_dump_prot = 3;
|
pier_dump_prot = 3;
|
||||||
carthw_pier_statef();
|
carthw_pier_statef();
|
||||||
|
eeprom_spi_init(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void carthw_pier_startup(void)
|
void carthw_pier_startup(void)
|
||||||
{
|
{
|
||||||
|
void *eeprom_state;
|
||||||
|
int eeprom_size = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
elprintf(EL_STATUS, "Pier Solar mapper startup");
|
elprintf(EL_STATUS, "Pier Solar mapper startup");
|
||||||
|
@ -434,6 +440,16 @@ void carthw_pier_startup(void)
|
||||||
for (i = 0; i < M68K_BANK_SIZE; i += 0x8000)
|
for (i = 0; i < M68K_BANK_SIZE; i += 0x8000)
|
||||||
memcpy(Pico.rom + Pico.romsize + i, Pico.rom, 0x8000);
|
memcpy(Pico.rom + Pico.romsize + i, Pico.rom, 0x8000);
|
||||||
|
|
||||||
|
// save EEPROM
|
||||||
|
eeprom_state = eeprom_spi_init(&eeprom_size);
|
||||||
|
SRam.flags = 0;
|
||||||
|
SRam.size = 0x10000;
|
||||||
|
SRam.data = calloc(1, SRam.size);
|
||||||
|
if (!SRam.data)
|
||||||
|
SRam.size = 0;
|
||||||
|
carthw_pier_state[2].ptr = eeprom_state;
|
||||||
|
carthw_pier_state[2].size = eeprom_size;
|
||||||
|
|
||||||
PicoCartMemSetup = carthw_pier_mem_setup;
|
PicoCartMemSetup = carthw_pier_mem_setup;
|
||||||
PicoResetHook = carthw_pier_reset;
|
PicoResetHook = carthw_pier_reset;
|
||||||
PicoLoadStateHook = carthw_pier_statef;
|
PicoLoadStateHook = carthw_pier_statef;
|
||||||
|
@ -679,3 +695,4 @@ void carthw_prot_lk3_startup(void)
|
||||||
PicoCartMemSetup = carthw_prot_lk3_mem_setup;
|
PicoCartMemSetup = carthw_prot_lk3_mem_setup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim:ts=2:sw=2:expandtab
|
||||||
|
|
|
@ -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) */
|
/* max supported size 64KB (25x512/95x512) */
|
||||||
#define SIZE_MASK 0xffff
|
#define SIZE_MASK 0xffff
|
||||||
|
@ -72,16 +74,16 @@ typedef struct
|
||||||
|
|
||||||
static T_EEPROM_SPI spi_eeprom;
|
static T_EEPROM_SPI spi_eeprom;
|
||||||
|
|
||||||
void eeprom_spi_init()
|
void *eeprom_spi_init(int *size)
|
||||||
{
|
{
|
||||||
/* reset eeprom state */
|
/* reset eeprom state */
|
||||||
memset(&spi_eeprom, 0, sizeof(T_EEPROM_SPI));
|
memset(&spi_eeprom, 0, sizeof(T_EEPROM_SPI));
|
||||||
spi_eeprom.out = 1;
|
spi_eeprom.out = 1;
|
||||||
spi_eeprom.state = GET_OPCODE;
|
spi_eeprom.state = GET_OPCODE;
|
||||||
|
|
||||||
/* enable backup RAM */
|
if (size)
|
||||||
sram.custom = 2;
|
*size = sizeof(T_EEPROM_SPI);
|
||||||
sram.on = 1;
|
return &spi_eeprom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eeprom_spi_write(unsigned char data)
|
void eeprom_spi_write(unsigned char data)
|
||||||
|
@ -208,7 +210,7 @@ void eeprom_spi_write(unsigned char data)
|
||||||
if (spi_eeprom.opcode & 0x01)
|
if (spi_eeprom.opcode & 0x01)
|
||||||
{
|
{
|
||||||
/* READ operation */
|
/* READ operation */
|
||||||
spi_eeprom.buffer = sram.sram[spi_eeprom.addr];
|
spi_eeprom.buffer = SRam.data[spi_eeprom.addr];
|
||||||
spi_eeprom.state = READ_BYTE;
|
spi_eeprom.state = READ_BYTE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -264,7 +266,7 @@ void eeprom_spi_write(unsigned char data)
|
||||||
/* $C000-$FFFF (sector #3) is protected */
|
/* $C000-$FFFF (sector #3) is protected */
|
||||||
if (spi_eeprom.addr < 0xC000)
|
if (spi_eeprom.addr < 0xC000)
|
||||||
{
|
{
|
||||||
sram.sram[spi_eeprom.addr] = spi_eeprom.buffer;
|
SRam.data[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +276,7 @@ void eeprom_spi_write(unsigned char data)
|
||||||
/* $8000-$FFFF (sectors #2 and #3) is protected */
|
/* $8000-$FFFF (sectors #2 and #3) is protected */
|
||||||
if (spi_eeprom.addr < 0x8000)
|
if (spi_eeprom.addr < 0x8000)
|
||||||
{
|
{
|
||||||
sram.sram[spi_eeprom.addr] = spi_eeprom.buffer;
|
SRam.data[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +290,7 @@ void eeprom_spi_write(unsigned char data)
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
/* no sectors protected */
|
/* no sectors protected */
|
||||||
sram.sram[spi_eeprom.addr] = spi_eeprom.buffer;
|
SRam.data[spi_eeprom.addr] = spi_eeprom.buffer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,7 +332,7 @@ void eeprom_spi_write(unsigned char data)
|
||||||
{
|
{
|
||||||
/* read next array byte */
|
/* read next array byte */
|
||||||
spi_eeprom.addr = (spi_eeprom.addr + 1) & SIZE_MASK;
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#define _EEPROM_SPI_H_
|
#define _EEPROM_SPI_H_
|
||||||
|
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
extern void eeprom_spi_init();
|
extern void *eeprom_spi_init(int *size);
|
||||||
extern void eeprom_spi_write(unsigned char data);
|
extern void eeprom_spi_write(unsigned char data);
|
||||||
extern unsigned int eeprom_spi_read(unsigned int address);
|
extern unsigned int eeprom_spi_read(unsigned int address);
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ endif
|
||||||
SRCS_COMMON += $(R)pico/pico/pico.c $(R)pico/pico/memory.c $(R)pico/pico/xpcm.c
|
SRCS_COMMON += $(R)pico/pico/pico.c $(R)pico/pico/memory.c $(R)pico/pico/xpcm.c
|
||||||
# carthw
|
# carthw
|
||||||
SRCS_COMMON += $(R)pico/carthw/carthw.c
|
SRCS_COMMON += $(R)pico/carthw/carthw.c
|
||||||
|
SRCS_COMMON += $(R)pico/carthw/eeprom_spi.c
|
||||||
# SVP
|
# SVP
|
||||||
SRCS_COMMON += $(R)pico/carthw/svp/svp.c $(R)pico/carthw/svp/memory.c \
|
SRCS_COMMON += $(R)pico/carthw/svp/svp.c $(R)pico/carthw/svp/memory.c \
|
||||||
$(R)pico/carthw/svp/ssp16.c
|
$(R)pico/carthw/svp/ssp16.c
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue