Skip to content

Commit

Permalink
snapshot support for c128 cartridge system
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45179 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
mrdudz committed Jun 1, 2024
1 parent 51c7b1a commit 8391660
Show file tree
Hide file tree
Showing 17 changed files with 1,426 additions and 1,029 deletions.
41 changes: 41 additions & 0 deletions vice/src/c128/cart/c128cart.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,45 @@ static void c128cartridge_powerup(void)
}
}

static int c128cartridge_snapshot_read(int type, snapshot_t *s)
{
switch (type) {
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GENERIC):
return c128generic_snapshot_read_module(s, type);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_COMAL80):
return c128comal80_snapshot_read_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_MAGICDESK128):
return magicdesk128_snapshot_read_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_PARTNER128):
return partner128_snapshot_read_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_WARPSPEED128):
return warpspeed128_snapshot_read_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GMOD2C128):
return c128gmod2_snapshot_read_module(s);
}
return -1;
}

static int c128cartridge_snapshot_write(int type, snapshot_t *s)
{
DBG(("c128cartridge_snapshot_write\n"));
switch (type) {
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GENERIC):
return c128generic_snapshot_write_module(s, type);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_COMAL80):
return c128comal80_snapshot_write_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_MAGICDESK128):
return magicdesk128_snapshot_write_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_PARTNER128):
return partner128_snapshot_write_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_WARPSPEED128):
return warpspeed128_snapshot_write_module(s);
case CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GMOD2C128):
return c128gmod2_snapshot_write_module(s);
}
return -1;
}

void c128cartridge_setup_interface(void)
{
DBG(("c128cartridge_setup_interface\n"));
Expand All @@ -570,6 +609,8 @@ void c128cartridge_setup_interface(void)
c128interface.can_save_image = c128cartridge_can_save_image;
c128interface.can_flush_secondary_image = c128cartridge_can_flush_secondary_image;
c128interface.can_save_secondary_image = c128cartridge_can_save_secondary_image;
c128interface.snapshot_read = c128cartridge_snapshot_read;
c128interface.snapshot_write = c128cartridge_snapshot_write;
c128cartridge = &c128interface;
}

Expand Down
70 changes: 67 additions & 3 deletions vice/src/c128/cart/comal80.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static io_source_t c128comal80_io1_device = {
c128comal80_io1_read, /* read function */
c128comal80_io1_peek, /* peek function */
c128comal80_dump, /* device state information dump function */
CARTRIDGE_C128_COMAL80, /* cartridge ID */
CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_COMAL80), /* cartridge ID */
IO_PRIO_NORMAL, /* normal priority, device read needs to be checked for collisions */
0, /* insertion order, gets filled in by the registration function */
IO_MIRROR_NONE /* NO mirroring */
Expand All @@ -103,7 +103,7 @@ static io_source_t c128comal80_io2_device = {
c128comal80_io2_read, /* read function */
c128comal80_io2_peek, /* peek function */
c128comal80_dump, /* device state information dump function */
CARTRIDGE_C128_COMAL80, /* cartridge ID */
CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_COMAL80), /* cartridge ID */
IO_PRIO_NORMAL, /* normal priority, device read needs to be checked for collisions */
0, /* insertion order, gets filled in by the registration function */
IO_MIRROR_NONE /* NO mirroring */
Expand All @@ -113,7 +113,7 @@ static io_source_list_t *c128comal80_io1_list_item = NULL;
static io_source_list_t *c128comal80_io2_list_item = NULL;

static const export_resource_t export_res = {
CARTRIDGE_C128_NAME_COMAL80, 1, 1, &c128comal80_io1_device, &c128comal80_io2_device, CARTRIDGE_C128_COMAL80
CARTRIDGE_C128_NAME_COMAL80, 1, 1, &c128comal80_io1_device, &c128comal80_io2_device, CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_COMAL80)
};

/* ---------------------------------------------------------------------*/
Expand Down Expand Up @@ -264,3 +264,67 @@ void c128comal80_reset(void)
DBG(("c128comal80_reset\n"));
external_function_rom_set_bank(0);
}

/* ---------------------------------------------------------------------*/

/* COMAL80C128 snapshot module format:
FIXME
*/

static char snap_module_name[] = "COMAL80C128";
#define SNAP_MAJOR 0
#define SNAP_MINOR 1

int c128comal80_snapshot_write_module(snapshot_t *s)
{
snapshot_module_t *m;

m = snapshot_module_create(s, snap_module_name, SNAP_MAJOR, SNAP_MINOR);

if (m == NULL) {
return -1;
}

if (0
|| (SMW_B(m, (uint8_t)comal80_register) < 0)
|| (SMW_BA(m, &ext_function_rom[0x4000], (0x8000 * 5) + 0x4000) < 0)) {
snapshot_module_close(m);
return -1;
}

return snapshot_module_close(m);
}

int c128comal80_snapshot_read_module(snapshot_t *s)
{
uint8_t vmajor, vminor;
snapshot_module_t *m;

m = snapshot_module_open(s, snap_module_name, &vmajor, &vminor);

if (m == NULL) {
return -1;
}

/* Do not accept versions higher than current */
if (snapshot_version_is_bigger(vmajor, vminor, SNAP_MAJOR, SNAP_MINOR)) {
snapshot_set_error(SNAPSHOT_MODULE_HIGHER_VERSION);
goto fail;
}

if (0
|| (SMR_B_INT(m, &comal80_register) < 0)
|| (SMR_BA(m, &ext_function_rom[0x4000], (0x8000 * 5) + 0x4000) < 0)) {
goto fail;
}

snapshot_module_close(m);

return c128comal80_common_attach();

fail:
snapshot_module_close(m);
return -1;
}

5 changes: 5 additions & 0 deletions vice/src/c128/cart/comal80.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ void c128comal80_reset(void);

void c128comal80_config_setup(uint8_t *rawcart);

struct snapshot_s;

int c128comal80_snapshot_write_module(struct snapshot_s *s);
int c128comal80_snapshot_read_module(struct snapshot_s *s);

#endif
63 changes: 62 additions & 1 deletion vice/src/c128/cart/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#endif

static const export_resource_t export_res = {
CARTRIDGE_C128_NAME_GENERIC, 1, 1, NULL, NULL, CARTRIDGE_C128_GENERIC
CARTRIDGE_C128_NAME_GENERIC, 1, 1, NULL, NULL, CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GENERIC)
};

void c128generic_config_setup(uint8_t *rawcart)
Expand Down Expand Up @@ -176,3 +176,64 @@ void c128generic_reset(void)
{
DBG(("c128generic_reset\n"));
}

/* ---------------------------------------------------------------------*/

/* CART128GENERIC snapshot module format:
FIXME
*/

static char snap_module_name[] = "CART128GENERIC";
#define SNAP_MAJOR 0
#define SNAP_MINOR 1

int c128generic_snapshot_write_module(snapshot_t *s, int type)
{
snapshot_module_t *m;

m = snapshot_module_create(s, snap_module_name, SNAP_MAJOR, SNAP_MINOR);

if (m == NULL) {
return -1;
}

if (0
|| (SMW_BA(m, ext_function_rom, EXTERNAL_FUNCTION_ROM_SIZE) < 0)) {
snapshot_module_close(m);
return -1;
}

return snapshot_module_close(m);
}

int c128generic_snapshot_read_module(snapshot_t *s, int type)
{
uint8_t vmajor, vminor;
snapshot_module_t *m;

m = snapshot_module_open(s, snap_module_name, &vmajor, &vminor);

if (m == NULL) {
return -1;
}

/* Do not accept versions higher than current */
if (snapshot_version_is_bigger(vmajor, vminor, SNAP_MAJOR, SNAP_MINOR)) {
snapshot_set_error(SNAPSHOT_MODULE_HIGHER_VERSION);
goto fail;
}

if (0
|| (SMR_BA(m, ext_function_rom, EXTERNAL_FUNCTION_ROM_SIZE) < 0)) {
goto fail;
}

snapshot_module_close(m);

return c128generic_common_attach();

fail:
snapshot_module_close(m);
return -1;
}
5 changes: 5 additions & 0 deletions vice/src/c128/cart/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ void c128generic_reset(void);

void c128generic_config_setup(uint8_t *rawcart);

struct snapshot_s;

int c128generic_snapshot_write_module(struct snapshot_s *s, int type);
int c128generic_snapshot_read_module(struct snapshot_s *s, int type);

#endif
4 changes: 2 additions & 2 deletions vice/src/c128/cart/gmod2c128.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static io_source_t c128gmod2_io1_device = {
c128gmod2_io1_read, /* read function */
c128gmod2_io1_peek, /* peek function */
c128gmod2_dump, /* device state information dump function */
CARTRIDGE_C128_GMOD2C128, /* cartridge ID */
CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GMOD2C128), /* cartridge ID */
IO_PRIO_NORMAL, /* normal priority, device read needs to be checked for collisions */
0, /* insertion order, gets filled in by the registration function */
IO_MIRROR_NONE /* NO mirroring */
Expand All @@ -126,7 +126,7 @@ static io_source_t c128gmod2_io1_device = {
static io_source_list_t *c128gmod2_io1_list_item = NULL;

static const export_resource_t export_res = {
CARTRIDGE_C128_NAME_GMOD2C128, 0, 0, &c128gmod2_io1_device, NULL, CARTRIDGE_C128_GMOD2C128
CARTRIDGE_C128_NAME_GMOD2C128, 0, 0, &c128gmod2_io1_device, NULL, CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_GMOD2C128)
};

/* ---------------------------------------------------------------------*/
Expand Down
1 change: 0 additions & 1 deletion vice/src/c128/cart/gmod2c128.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ int c128gmod2_cmdline_options_init(void);
int c128gmod2_resources_init(void);
void c128gmod2_resources_shutdown(void);

/* FIXME: snapshot stuff is not implemented yet */
int c128gmod2_snapshot_write_module(struct snapshot_s *s);
int c128gmod2_snapshot_read_module(struct snapshot_s *s);

Expand Down
58 changes: 56 additions & 2 deletions vice/src/c128/cart/magicdesk128.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static io_source_t magicdesk128_io1_device = {
magicdesk128_io1_read, /* read function */
magicdesk128_io1_peek, /* peek function */
magicdesk128_dump, /* device state information dump function */
CARTRIDGE_C128_MAGICDESK128, /* cartridge ID */
CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_MAGICDESK128), /* cartridge ID */
IO_PRIO_NORMAL, /* normal priority, device read needs to be checked for collisions */
0, /* insertion order, gets filled in by the registration function */
IO_MIRROR_NONE /* NO mirroring */
Expand All @@ -107,7 +107,7 @@ static io_source_t magicdesk128_io1_device = {
static io_source_list_t *magicdesk128_io1_list_item = NULL;

static const export_resource_t export_res = {
CARTRIDGE_C128_NAME_MAGICDESK128, 1, 1, &magicdesk128_io1_device, NULL, CARTRIDGE_C128_MAGICDESK128
CARTRIDGE_C128_NAME_MAGICDESK128, 1, 1, &magicdesk128_io1_device, NULL, CARTRIDGE_C128_MAKEID(CARTRIDGE_C128_MAGICDESK128)
};

/* ---------------------------------------------------------------------*/
Expand Down Expand Up @@ -252,3 +252,57 @@ void magicdesk128_reset(void)
rombank = 0;
external_function_rom_set_bank(0);
}

/* ---------------------------------------------------------------------*/

/* MAGICDESK128 snapshot module format:
FIXME
*/

static char snap_module_name[] = "MAGICDESK128";
#define SNAP_MAJOR 0
#define SNAP_MINOR 0

int magicdesk128_snapshot_write_module(snapshot_t *s)
{
snapshot_module_t *m;

m = snapshot_module_create(s, snap_module_name, SNAP_MAJOR, SNAP_MINOR);

if (m == NULL) {
return -1;
}

/* FIXME */

return snapshot_module_close(m);
}

int magicdesk128_snapshot_read_module(snapshot_t *s)
{
uint8_t vmajor, vminor;
snapshot_module_t *m;

m = snapshot_module_open(s, snap_module_name, &vmajor, &vminor);

if (m == NULL) {
return -1;
}

/* Do not accept versions higher than current */
if (snapshot_version_is_bigger(vmajor, vminor, SNAP_MAJOR, SNAP_MINOR)) {
snapshot_set_error(SNAPSHOT_MODULE_HIGHER_VERSION);
goto fail;
}

/* FIXME */

snapshot_module_close(m);

return magicdesk128_common_attach();

fail:
snapshot_module_close(m);
return -1;
}
5 changes: 5 additions & 0 deletions vice/src/c128/cart/magicdesk128.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ void magicdesk128_reset(void);

void magicdesk128_config_setup(uint8_t *rawcart);

struct snapshot_s;

int magicdesk128_snapshot_write_module(struct snapshot_s *s);
int magicdesk128_snapshot_read_module(struct snapshot_s *s);

#endif
Loading

0 comments on commit 8391660

Please sign in to comment.