Skip to content

Commit 379ee16

Browse files
JoeMattclaude
andcommitted
Add CD EEPROM to SRAM buffer and save states
- Add cdrom_eeprom_ram[64] array in eeprom.c for Jaguar CD saves - Include CD EEPROM in save state serialization - Extend SRAM buffer to 256 bytes (128 cart + 128 CD EEPROM) - Pack/unpack both arrays for RETRO_MEMORY_SAVE_RAM The CD EEPROM I/O hookup (BUTCH register $DFFF2C) is not yet implemented — this provides the data infrastructure for when it is. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent c381208 commit 379ee16

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

libretro.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int game_width = 0;
4141
int game_height = 0;
4242

4343
extern uint16_t eeprom_ram[64];
44+
extern uint16_t cdrom_eeprom_ram[64];
4445
extern uint8_t mtMem[0x20000];
4546
extern uint32_t jaguarMainROMCRC32;
4647
extern void (*eeprom_dirty_cb)(void);
@@ -51,9 +52,10 @@ extern void (*eeprom_dirty_cb)(void);
5152
*
5253
* The save buffer is kept in sync on every EEPROM write via eeprom_dirty_cb,
5354
* so frontends that cache the pointer always see current data. */
54-
#define EEPROM_SAVE_SIZE 128 /* 64 x 16-bit words, big-endian */
55-
#define MT_SAVE_SIZE 0x20000 /* 128K Memory Track */
56-
static uint8_t eeprom_save_buf[EEPROM_SAVE_SIZE];
55+
#define EEPROM_SAVE_SIZE 128 /* 64 x 16-bit words, big-endian */
56+
#define CD_EEPROM_SAVE_SIZE 128 /* CD EEPROM: 64 x 16-bit words */
57+
#define MT_SAVE_SIZE 0x20000 /* 128K Memory Track */
58+
static uint8_t eeprom_save_buf[EEPROM_SAVE_SIZE + CD_EEPROM_SAVE_SIZE];
5759
static void eeprom_pack_save_buf(void);
5860
static void eeprom_unpack_save_buf(void);
5961

@@ -1195,16 +1197,25 @@ static void eeprom_pack_save_buf(void)
11951197
eeprom_save_buf[(i * 2) + 0] = eeprom_ram[i] >> 8;
11961198
eeprom_save_buf[(i * 2) + 1] = eeprom_ram[i] & 0xFF;
11971199
}
1200+
/* CD EEPROM follows cart EEPROM in the save buffer */
1201+
for (i = 0; i < 64; i++)
1202+
{
1203+
eeprom_save_buf[EEPROM_SAVE_SIZE + (i * 2) + 0] = cdrom_eeprom_ram[i] >> 8;
1204+
eeprom_save_buf[EEPROM_SAVE_SIZE + (i * 2) + 1] = cdrom_eeprom_ram[i] & 0xFF;
1205+
}
11981206
}
11991207

1200-
/* Unpack the save buffer back into eeprom_ram[].
1208+
/* Unpack the save buffer back into eeprom_ram[] and cdrom_eeprom_ram[].
12011209
* Called once after the frontend loads .srm data. */
12021210
static void eeprom_unpack_save_buf(void)
12031211
{
12041212
unsigned i;
12051213
for (i = 0; i < 64; i++)
12061214
eeprom_ram[i] = ((uint16_t)eeprom_save_buf[(i * 2) + 0] << 8)
12071215
| eeprom_save_buf[(i * 2) + 1];
1216+
for (i = 0; i < 64; i++)
1217+
cdrom_eeprom_ram[i] = ((uint16_t)eeprom_save_buf[EEPROM_SAVE_SIZE + (i * 2) + 0] << 8)
1218+
| eeprom_save_buf[EEPROM_SAVE_SIZE + (i * 2) + 1];
12081219
}
12091220

12101221
void *retro_get_memory_data(unsigned type)
@@ -1230,7 +1241,7 @@ size_t retro_get_memory_size(unsigned type)
12301241
{
12311242
if (jaguarMainROMCRC32 == 0xFDF37F47)
12321243
return MT_SAVE_SIZE;
1233-
return EEPROM_SAVE_SIZE;
1244+
return EEPROM_SAVE_SIZE + CD_EEPROM_SAVE_SIZE;
12341245
}
12351246
return 0;
12361247
}

src/eeprom.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string.h> // For memset
2121

2222
uint16_t eeprom_ram[64];
23+
uint16_t cdrom_eeprom_ram[64];
2324

2425
/* Callback to sync the save buffer when EEPROM is modified.
2526
* Set by libretro.c to keep RETRO_MEMORY_SAVE_RAM up to date. */
@@ -59,6 +60,7 @@ void EepromInit(void)
5960
if (!eeprom_initialized)
6061
{
6162
memset(eeprom_ram, 0xFF, 64 * sizeof(uint16_t));
63+
memset(cdrom_eeprom_ram, 0xFF, 64 * sizeof(uint16_t));
6264
eeprom_initialized = true;
6365
}
6466
}
@@ -381,6 +383,7 @@ size_t EepromStateSave(uint8_t *buf)
381383

382384
/* EEPROM data arrays */
383385
STATE_SAVE_BUF(buf, eeprom_ram, sizeof(eeprom_ram));
386+
STATE_SAVE_BUF(buf, cdrom_eeprom_ram, sizeof(cdrom_eeprom_ram));
384387

385388
return (size_t)(buf - start);
386389
}
@@ -401,6 +404,7 @@ size_t EepromStateLoad(const uint8_t *buf)
401404

402405
/* EEPROM data arrays */
403406
STATE_LOAD_BUF(buf, eeprom_ram, sizeof(eeprom_ram));
407+
STATE_LOAD_BUF(buf, cdrom_eeprom_ram, sizeof(cdrom_eeprom_ram));
404408

405409
return (size_t)(buf - start);
406410
}

src/eeprom.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ void EepromInit(void);
1515
void EepromReset(void);
1616
void EepromDone(void);
1717

18+
extern uint16_t cdrom_eeprom_ram[64];
19+
1820
uint8_t EepromReadByte(uint32_t offset);
1921
uint16_t EepromReadWord(uint32_t offset);
2022
void EepromWriteByte(uint32_t offset, uint8_t data);

0 commit comments

Comments
 (0)