Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
m65_snapshot.c
Go to the documentation of this file.
1 /* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
2  Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
3  Copyright (C)2016,2017,2021 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18 
19 #ifdef XEMU_SNAPSHOT_SUPPORT
20 
21 #define NEED_SID_H
22 
23 #include "xemu/emutools.h"
24 #include "xemu/emutools_snapshot.h"
25 #include "xemu/emutools_config.h"
26 #include "mega65.h"
27 #include "xemu/cpu65.h"
28 #include "xemu/cia6526.h"
29 #include "vic4.h"
30 #include "dma65.h"
31 #include "hypervisor.h"
32 #include "sdcard.h"
33 #include "xemu/f011_core.h"
34 #include "m65_snapshot.h"
35 #include "memory_mapper.h"
36 #include "audio65.h"
37 #include "io_mapper.h"
38 #include <string.h>
39 
40 #define M65_MEMORY_BLOCK_VERSION 1
41 
42 struct memblock_st {
43  Uint8 *data;
44  int size;
45 };
46 
47 
48 static int snapcallback_memory_loader ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block )
49 {
50  const struct memblock_st *mem = (const struct memblock_st *)def->user_data;
51  if (block->block_version != M65_MEMORY_BLOCK_VERSION || block->sub_counter != 0 || block->sub_size > mem->size)
52  RETURN_XSNAPERR_USER("Bad memory block syntax @ %s", def->idstr);
53  memset(mem->data, 0xFF, mem->size);
54  return xemusnap_read_file(mem->data, block->sub_size); // read that damn memory dump
55 }
56 
57 
58 static int snapcallback_memory_saver ( const struct xemu_snapshot_definition_st *def )
59 {
60  const struct memblock_st *mem = (const struct memblock_st *)def->user_data;
61  int ret = xemusnap_write_block_header(def->idstr, M65_MEMORY_BLOCK_VERSION);
62  if (ret) return ret;
63  ret = mem->size - 1;
64  while (ret && mem->data[ret] == 0xFF)
65  ret--;
66  return xemusnap_write_sub_block(mem->data, ret + 1);
67 }
68 
69 
70 #define DEFINE_SNAPSHOT_MEMORY_BLOCK(name, structure) { "MemoryRegion:" name, (void*)&structure, snapcallback_memory_loader, snapcallback_memory_saver }
71 
72 
73 static const struct memblock_st memblock_main_ram = { main_ram, sizeof main_ram };
74 static const struct memblock_st memblock_colour_ram = { colour_ram, sizeof colour_ram };
75 static const struct memblock_st memblock_char_wom = { char_wom, sizeof char_wom };
76 static const struct memblock_st memblock_hypervisor = { hypervisor_ram, 0x4000 };
77 
78 const struct xemu_snapshot_definition_st m65_snapshot_definition[] = {
79  { "CPU", NULL, cpu65_snapshot_load_state, cpu65_snapshot_save_state },
80  { "CIA#1", &cia1, cia_snapshot_load_state, cia_snapshot_save_state },
81  { "CIA#2", &cia2, cia_snapshot_load_state, cia_snapshot_save_state },
82  { "VIC-4", NULL, vic4_snapshot_load_state, vic4_snapshot_save_state },
83  { "M65", NULL, m65emu_snapshot_load_state, m65emu_snapshot_save_state },
84  { "SID#1", &sid[0], sid_snapshot_load_state, sid_snapshot_save_state },
85  { "SID#2", &sid[1], sid_snapshot_load_state, sid_snapshot_save_state },
86  { "SID#3", &sid[3], sid_snapshot_load_state, sid_snapshot_save_state },
87  { "SID#4", &sid[4], sid_snapshot_load_state, sid_snapshot_save_state },
88  { "DMAgic", NULL, dma_snapshot_load_state, dma_snapshot_save_state },
89  { "SDcard", NULL, sdcard_snapshot_load_state, sdcard_snapshot_save_state },
90  { "FDC-F011", NULL, fdc_snapshot_load_state, fdc_snapshot_save_state },
91  DEFINE_SNAPSHOT_MEMORY_BLOCK("RAM:Main", memblock_main_ram),
92  DEFINE_SNAPSHOT_MEMORY_BLOCK("RAM:Colour", memblock_colour_ram),
93  DEFINE_SNAPSHOT_MEMORY_BLOCK("WOM:Char", memblock_char_wom),
94  DEFINE_SNAPSHOT_MEMORY_BLOCK("RAM:Hyppo", memblock_hypervisor),
95  { NULL, NULL, m65emu_snapshot_loading_finalize, NULL }
96 };
97 
98 #endif
cia6526.h
vic4.h
emutools.h
char_wom
Uint8 char_wom[0x2000]
Definition: memory_mapper.c:67
f011_core.h
hypervisor_ram
Uint8 hypervisor_ram[0x4000]
Definition: memory_mapper.c:69
colour_ram
Uint8 colour_ram[0x8000]
Definition: memory_mapper.c:65
io_mapper.h
m65-memcontent-generator.data
data
Definition: m65-memcontent-generator.py:119
mega65.h
cia2
struct Cia6526 cia1 cia2
Definition: commodore_65.c:44
Uint8
uint8_t Uint8
Definition: fat32.c:51
main_ram
Uint8 main_ram[512<< 10]
Definition: memory_mapper.c:47
block
Uint32 block
Definition: fat32.c:156
sid
struct SidEmulation sid[NUMBER_OF_SIDS]
Definition: audio65.c:37
memory_mapper.h
emutools_config.h
hypervisor.h
cpu65.h
size
int size
Definition: inject.c:37
emutools_snapshot.h
m65_snapshot.h
audio65.h