Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
c65_snapshot.c
Go to the documentation of this file.
1 /* Test-case for a very simple, inaccurate, work-in-progress Commodore 65 emulator.
2  Copyright (C)2016 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17 
18 #ifdef XEMU_SNAPSHOT_SUPPORT
19 
20 #include "xemu/emutools.h"
21 #include "xemu/emutools_snapshot.h"
22 #include "xemu/emutools_config.h"
23 #include "commodore_65.h"
24 #include "xemu/cpu65.h"
25 #include "xemu/cia6526.h"
26 #include "vic3.h"
27 #include "xemu/sid.h"
28 #include "dma65.h"
29 #include "xemu/f011_core.h"
30 #include "c65_snapshot.h"
31 #include <string.h>
32 
33 
34 #define C65_MEMORY_BLOCK_VERSION 0
35 
36 static int snapcallback_memory_loader ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block )
37 {
38  if (block->block_version != C65_MEMORY_BLOCK_VERSION || block->sub_counter != 0 || block->sub_size > sizeof(memory))
39  RETURN_XSNAPERR_USER("Bad memory block syntax ver=%d, subcount=%d, size=%d", block->block_version, block->sub_counter, block->sub_size);
40  memset(memory, 0xFF, sizeof memory);
41  return xemusnap_read_file(memory, block->sub_size); // read that damn memory dump
42 }
43 
44 static int snapcallback_memory_saver ( const struct xemu_snapshot_definition_st *def )
45 {
46  int ret = xemusnap_write_block_header(def->idstr, C65_MEMORY_BLOCK_VERSION);
47  if (ret) return ret;
48  ret = sizeof memory;
49  while (memory[--ret] == 0xFF) ;
50  return xemusnap_write_sub_block(memory, ret + 1);
51 }
52 
53 
54 /* The heart of the Snapshot handling. For the Xemu level snapshot support (both loading and saving)
55  A definition list like this must be created. Each entry defines a block type, a user parameter,
56  a load and save callback. Callbacks can be NULL to signal that no need to handle that for load or
57  save (that is: it's possible to support loading a block which is never written though on save).
58  The last entry MUST have a NULL entry in the place of block-identify string. This last entry can
59  specify callbacks too, if it's given it means, that Xemu snapshot handler will call those callbacks
60  at the end of loading or saving a snapshot. It's especially useful in case of "load finalization"
61  for example, when an emulator needs to execute some extra code to really use the loaded state. The
62  user parameter is accessible for the callbacks. Some of these callbacks are common code, ie
63  CIA/CPU/SID can be included this way without any emulator-specific snapshot code, and realized
64  in the shared/common code base. */
65 const struct xemu_snapshot_definition_st c65_snapshot_definition[] = {
66  { "CPU", NULL, cpu65_snapshot_load_state, cpu65_snapshot_save_state },
67  { "CIA#1", &cia1, cia_snapshot_load_state, cia_snapshot_save_state },
68  { "CIA#2", &cia2, cia_snapshot_load_state, cia_snapshot_save_state },
69  { "VIC-3", NULL, vic3_snapshot_load_state, vic3_snapshot_save_state },
70  { "C65", NULL, c65emu_snapshot_load_state, c65emu_snapshot_save_state },
71  { "SID#1", &sids[0], sid_snapshot_load_state, sid_snapshot_save_state },
72  { "SID#2", &sids[1], sid_snapshot_load_state, sid_snapshot_save_state },
73  { "DMA", NULL, dma_snapshot_load_state, dma_snapshot_save_state },
74  { "FDC-F011", NULL, fdc_snapshot_load_state, fdc_snapshot_save_state },
75  { "Memory", NULL, snapcallback_memory_loader, snapcallback_memory_saver },
76  { NULL, NULL, c65emu_snapshot_loading_finalize, NULL }
77 };
78 
79 #endif
cia6526.h
emutools.h
f011_core.h
vic3.h
cia2
struct Cia6526 cia1 cia2
Definition: commodore_65.c:44
block
Uint32 block
Definition: fat32.c:156
emutools_config.h
commodore_65.h
memory
Uint8 memory[0x100000]
Definition: commodore_65.c:43
cpu65.h
sid.h
emutools_snapshot.h
c65_snapshot.h
sids
struct SidEmulation sids[2]
Definition: commodore_65.c:45