Skip to content

Commit

Permalink
MEGA65: cleanup, remove snapshot related stuff
Browse files Browse the repository at this point in the history
Emulator snapshots for the MEGA65 emulators are disabled since years for
now, and wouldn't even work for multiple reasons in this very form. So
it's fine to remove the "considered as dead" code. Even if I want this
to work some day, a serious total rewrite would be needed.
  • Loading branch information
lgblgblgb committed Jun 18, 2024
1 parent ab2290e commit 6558f72
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 423 deletions.
6 changes: 3 additions & 3 deletions targets/mega65/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
## Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
## Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
## Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -20,8 +20,8 @@ TARGET = mega65
PRG_TARGET = xmega65
EMU_DESCRIPTION = MEGA65

SRCS_TARGET_xmega65 = configdb.c mega65.c sdcard.c uart_monitor.c hypervisor.c m65_snapshot.c memory_mapper.c io_mapper.c vic4.c vic4_palette.c ethernet65.c input_devices.c memcontent.c ui.c fat32.c sdcontent.c audio65.c inject.c dma65.c rom.c hdos.c matrix_mode.c cart.c
SRCS_COMMON_xmega65 = emutools.c cpu65.c cia6526.c emutools_hid.c sid.c f011_core.c c64_kbd_mapping.c emutools_config.c emutools_snapshot.c emutools_files.c emutools_umon.c emutools_socketapi.c ethertap.c d81access.c emutools_gui.c basic_text.c opl3.c lodepng.c compressed_disk_image.c cpu65_disasm.c
SRCS_TARGET_xmega65 = configdb.c mega65.c sdcard.c uart_monitor.c hypervisor.c memory_mapper.c io_mapper.c vic4.c vic4_palette.c ethernet65.c input_devices.c memcontent.c ui.c fat32.c sdcontent.c audio65.c inject.c dma65.c rom.c hdos.c matrix_mode.c cart.c
SRCS_COMMON_xmega65 = emutools.c cpu65.c cia6526.c emutools_hid.c sid.c f011_core.c c64_kbd_mapping.c emutools_config.c emutools_files.c emutools_umon.c emutools_socketapi.c ethertap.c d81access.c emutools_gui.c basic_text.c opl3.c lodepng.c compressed_disk_image.c cpu65_disasm.c
CFLAGS_TARGET_xmega65 = $(SDL2_CFLAGS) $(MATH_CFLAGS) $(SOCKET_CFLAGS) $(XEMUGUI_CFLAGS)
LDFLAGS_TARGET_xmega65 = $(SDL2_LIBS) $(MATH_LIBS) $(SOCKET_LIBS) $(XEMUGUI_LIBS)
LDFLAGS_TARGET_xmega65_ON_html = -s STACK_SIZE=655360 --preload-file=$$HOME/.local/share/xemu-lgb/mega65/mega65.img.compressed3@/files/mega65.img --preload-file=$$HOME/mega65/megapoly.d81@/files/files/hdos/mega65.d81
Expand Down
4 changes: 0 additions & 4 deletions targets/mega65/configdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ static const struct xemutools_configdef_str_st str_options[] = {
{ "dumpmem", NULL, "Save memory content on exit", &configdb.dumpmem },
{ "dumpscreen", NULL, "Save screen content (ASCII) on exit", &configdb.dumpscreen },
{ "screenshot", NULL, "Save screenshot (PNG) on exit and vice-versa (for testing!)", &configdb.screenshot_and_exit },
#ifdef XEMU_SNAPSHOT_SUPPORT
{ "snapload", NULL, "Load a snapshot from the given file", &configdb.snapload },
{ "snapsave", NULL, "Save a snapshot into the given file before Xemu would exit", &configdb.snapsave },
#endif
#ifdef HAS_UARTMON_SUPPORT
{ "uartmon", NULL, "Sets the name for named unix-domain socket for uartmon, otherwise disabled", &configdb.uartmon },
#endif
Expand Down
4 changes: 0 additions & 4 deletions targets/mega65/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ struct configdb_st {
char *dumpmem;
char *dumpscreen;
char *screenshot_and_exit;
#ifdef XEMU_SNAPSHOT_SUPPORT
char *snapload;
char *snapsave;
#endif
#ifdef HAS_UARTMON_SUPPORT
char *uartmon;
#endif
Expand Down
55 changes: 0 additions & 55 deletions targets/mega65/dma65.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,58 +665,3 @@ void dma_set_list_addr_from_bytes ( const Uint8 *p )
list_addr = p[0] + (p[1] << 8) + (p[2] << 16) + ((p[3] & 0x0F) << 24);
DEBUGDMA("DMA: list address is set 'externally' to $%X" NL, list_addr);
}

/* --- SNAPSHOT RELATED --- */

#ifdef XEMU_SNAPSHOT_SUPPORT

// Note: currently state is not saved "within" a DMA operation. It's only a problem, if a DMA
// operation is not handled fully here, but implemented as an iterating update method from the
// emulator code. FIXME.

#include <string.h>

#define SNAPSHOT_DMA_BLOCK_VERSION 2
#define SNAPSHOT_DMA_BLOCK_SIZE 0x100


int dma_snapshot_load_state ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block )
{
Uint8 buffer[SNAPSHOT_DMA_BLOCK_SIZE];
int a;
if (block->block_version != SNAPSHOT_DMA_BLOCK_VERSION || block->sub_counter || block->sub_size != sizeof buffer)
RETURN_XSNAPERR_USER("Bad C65 block syntax");
a = xemusnap_read_file(buffer, sizeof buffer);
if (a) return a;
/* loading state ... */
memcpy(dma_registers, buffer, sizeof dma_registers);
dma_chip_revision = buffer[0x80];
dma_chip_initial_revision = buffer[0x81];
//dma_chip_revision_is_dynamic = buffer[0x82];
modulo.enabled = buffer[0x83];
dma_status = buffer[0x84];
in_dma_update = buffer[0x85];
return 0;
}


int dma_snapshot_save_state ( const struct xemu_snapshot_definition_st *def )
{
Uint8 buffer[SNAPSHOT_DMA_BLOCK_SIZE];
int a = xemusnap_write_block_header(def->idstr, SNAPSHOT_DMA_BLOCK_VERSION);
if (a) return a;
memset(buffer, 0xFF, sizeof buffer);
/* saving state ... */
memcpy(buffer, dma_registers, sizeof dma_registers);
buffer[0x80] = dma_chip_revision;
buffer[0x81] = dma_chip_initial_revision;
//buffer[0x82] = dma_chip_revision_is_dynamic ? 1 : 0;
buffer[0x83] = modulo.enabled ? 1 : 0;
buffer[0x84] = dma_status; // bit useless to store (see below, actually it's a problem), but to think about the future ...
buffer[0x85] = in_dma_update ? 1 : 0; // -- "" --
if (dma_status)
WARNING_WINDOW("f018_core DMA snapshot save: snapshot with DMA pending! Snapshot WILL BE incorrect on loading! FIXME!"); // FIXME!
return xemusnap_write_sub_block(buffer, sizeof buffer);
}

#endif
6 changes: 0 additions & 6 deletions targets/mega65/dma65.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,4 @@ extern int dma_get_revision ( void );
extern void dma_get_list_addr_as_bytes ( Uint8 *p );
extern void dma_set_list_addr_from_bytes ( const Uint8 *p );

#ifdef XEMU_SNAPSHOT_SUPPORT
#include "xemu/emutools_snapshot.h"
extern int dma_snapshot_load_state ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block );
extern int dma_snapshot_save_state ( const struct xemu_snapshot_definition_st *def );
#endif

#endif
1 change: 0 additions & 1 deletion targets/mega65/ethernet65.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
would result in quite slow emulation :(
* FIXME: it uses thread, and it's horrible code!! there are tons of race conditions, etc ...
It's not so nice work to use threads, but it would be hard to do otherwise, sadly.
* FIXME FIXME FIXME: No support for snapshotting ...
* Maybe allow TUN devices to be supported. It does not handle ethernet level stuffs, no source and
target MAC for example :-O But TUN devices are supported by wider range of OSes (eg: OSX) and we
probably can emulate the missing ethernet level stuffs somehow in this source on RX (and chop
Expand Down
2 changes: 1 addition & 1 deletion targets/mega65/io_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

int fpga_switches = 0; // State of FPGA board switches (bits 0 - 15), set switch 12 (hypervisor serial output)
Uint8 D6XX_registers[0x100]; // mega65 specific D6XX range, excluding the UART part (not used here!)
Uint8 D7XX[0x100]; // FIXME: hack for future M65 stuffs like ALU! FIXME: no snapshot on these!
Uint8 D7XX[0x100]; // FIXME: hack for future M65 stuffs like ALU!
struct Cia6526 cia1, cia2; // CIA emulation structures for the two CIAs
int cpu_mega65_opcodes = 0; // used by the CPU emu as well!
static int bigmult_valid_result = 0;
Expand Down
98 changes: 0 additions & 98 deletions targets/mega65/m65_snapshot.c

This file was deleted.

34 changes: 0 additions & 34 deletions targets/mega65/m65_snapshot.h

This file was deleted.

98 changes: 0 additions & 98 deletions targets/mega65/mega65.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "xemu/c64_kbd_mapping.h"
#include "xemu/emutools_config.h"
#include "xemu/emutools_umon.h"
#include "m65_snapshot.h"
#include "memory_mapper.h"
#include "io_mapper.h"
#include "ethernet65.h"
Expand Down Expand Up @@ -253,19 +252,6 @@ static Uint8 cia2_in_b ( void )
}


#ifdef XEMU_SNAPSHOT_SUPPORT
static void m65_snapshot_saver_on_exit_callback ( void )
{
if (!configdb.snapsave)
return;
if (xemusnap_save(configdb.snapsave))
ERROR_WINDOW("Could not save snapshot \"%s\": %s", configdb.snapsave, xemusnap_error_buffer);
else
INFO_WINDOW("Snapshot has been saved to \"%s\".", configdb.snapsave);
}
#endif


static int preinit_memory_item ( const char *name, const char *desc, Uint8 *target_ptr, const Uint8 *source_ptr, const int source_size, const int min_size, const int max_size, const char *fn )
{
if (source_size < min_size || source_size > max_size || min_size > max_size)
Expand Down Expand Up @@ -443,14 +429,6 @@ static void mega65_init ( void )
if (configdb.useutilmenu)
hwa_kbd_set_fake_key(0x20);
DEBUG("INIT: end of initialization!" NL);
#ifdef XEMU_SNAPSHOT_SUPPORT
xemusnap_init(m65_snapshot_definition);
if (configdb.snapload) {
if (xemusnap_load(configdb.snapload))
FATAL("Couldn't load snapshot \"%s\": %s", configdb.snapload, xemusnap_error_buffer);
}
atexit(m65_snapshot_saver_on_exit_callback);
#endif
}


Expand Down Expand Up @@ -908,79 +886,3 @@ int main ( int argc, char **argv )
XEMU_MAIN_LOOP(emulation_loop, 25, 1);
return 0;
}

/* --- SNAPSHOT RELATED --- */

#ifdef XEMU_SNAPSHOT_SUPPORT

#include <string.h>

#define SNAPSHOT_M65_BLOCK_VERSION 2
#define SNAPSHOT_M65_BLOCK_SIZE (0x100 + sizeof(D6XX_registers) + sizeof(D7XX))


int m65emu_snapshot_load_state ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block )
{
Uint8 buffer[SNAPSHOT_M65_BLOCK_SIZE];
int a;
if (block->block_version != SNAPSHOT_M65_BLOCK_VERSION || block->sub_counter || block->sub_size != sizeof buffer)
RETURN_XSNAPERR_USER("Bad M65 block syntax");
a = xemusnap_read_file(buffer, sizeof buffer);
if (a) return a;
/* loading state ... */
memcpy(D6XX_registers, buffer + 0x100, sizeof D6XX_registers);
memcpy(D7XX, buffer + 0x200, sizeof D7XX);
in_hypervisor = 1; // simulate hypervisor mode, to allow to write some regs now instead of causing a TRAP now ...
io_write(0x367D, D6XX_registers[0x7D]); // write $(D)67D in VIC-IV I/O mode! (sets ROM protection, linear addressing mode enable ...)
// TODO FIXME: see if there is a need for other registers from D6XX_registers to write back to take effect on loading snapshot!
// end of spec, hypervisor-needed faked mode for loading snapshot ...
map_mask = (int)P_AS_BE32(buffer + 0);
map_offset_low = (int)P_AS_BE32(buffer + 4);
map_offset_high = (int)P_AS_BE32(buffer + 8);
cpu65.cpu_inhibit_interrupts = (int)P_AS_BE32(buffer + 12);
in_hypervisor = (int)P_AS_BE32(buffer + 16); // sets hypervisor state from snapshot (hypervisor/userspace)
map_megabyte_low = (int)P_AS_BE32(buffer + 20);
map_megabyte_high = (int)P_AS_BE32(buffer + 24);
//force_fast_loaded = (int)P_AS_BE32(buffer + 28); // activated in m65emu_snapshot_loading_finalize() as force_fast can be set at multiple places through loading snapshot!
// +32 is free for 4 bytes now ... can be used later
memory_set_cpu_io_port_ddr_and_data(buffer[36], buffer[37]);
return 0;
}


int m65emu_snapshot_save_state ( const struct xemu_snapshot_definition_st *def )
{
Uint8 buffer[SNAPSHOT_M65_BLOCK_SIZE];
int a = xemusnap_write_block_header(def->idstr, SNAPSHOT_M65_BLOCK_VERSION);
if (a) return a;
memset(buffer, 0xFF, sizeof buffer);
/* saving state ... */
U32_AS_BE(buffer + 0, map_mask);
U32_AS_BE(buffer + 4, map_offset_low);
U32_AS_BE(buffer + 8, map_offset_high);
U32_AS_BE(buffer + 12, cpu65.cpu_inhibit_interrupts);
U32_AS_BE(buffer + 16, in_hypervisor);
U32_AS_BE(buffer + 20, map_megabyte_low);
U32_AS_BE(buffer + 24, map_megabyte_high);
//U32_AS_BE(buffer + 28, force_fast); // see notes on this at load_state and finalize stuff!
// +32 is free for 4 bytes now ... can be used later
buffer[36] = memory_get_cpu_io_port(0);
buffer[37] = memory_get_cpu_io_port(1);
memcpy(buffer + 0x100, D6XX_registers, sizeof D6XX_registers);
memcpy(buffer + 0x200, D7XX, sizeof D7XX);
return xemusnap_write_sub_block(buffer, sizeof buffer);
}


int m65emu_snapshot_loading_finalize ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block )
{
DEBUGPRINT("SNAP: loaded (finalize-callback: begin)" NL);
memory_set_vic3_rom_mapping(vic_registers[0x30]);
memory_set_do_map();
//force_fast = force_fast_loaded; // force_fast is handled through different places, so we must have a "finalize" construct and saved separately to have the actual effect ...
machine_set_speed(1);
DEBUGPRINT("SNAP: loaded (finalize-callback: end)" NL);
OSD(-1, -1, "Snapshot has been loaded.");
return 0;
}
#endif
Loading

0 comments on commit 6558f72

Please sign in to comment.