30
* FIXME: the rom_*_loaded flag stuff is not clear enough.
38
#include "autostart.h"
34
#include "drive-snapshot.h"
42
#include "pet-snapshot.h"
45
#include "petmemsnapshot.h"
45
#include "resources.h"
46
48
#include "snapshot.h"
50
#include "tape-snapshot.h"
51
static log_t pet_snapshot_log = LOG_ERR;
54
* PET memory dump should be 4-32k or 128k, depending on the config, as RAM.
55
* Plus 64k expansion RAM (8096 or SuperPET) if necessary. Also there
56
* is the 1/2k video RAM as "VRAM".
57
* In this prototype we save the full ram......
60
static const char module_ram_name[] = "PETMEM";
61
#define PETMEM_DUMP_VER_MAJOR 1
62
#define PETMEM_DUMP_VER_MINOR 2
65
* UBYTE CONFIG Bits 0-3: 0 = 40 col PET without CRTC
66
* 1 = 40 col PET with CRTC
67
* 2 = 80 col PET (with CRTC)
71
* Bit 6: 1= RAM at $9***
72
* Bit 7: 1= RAM at $A***
74
* UBYTE KEYBOARD 0 = UK business
77
* UBYTE MEMSIZE memory size of low 32k in k (4,8,16,32)
79
* UBYTE CONF8X96 8x96 configuration register
80
* UBYTE SUPERPET SuperPET config:
81
* Bit 0: spet_ramen, 1= RAM enabled
82
* 1: spet_ramwp, 1= RAM write protected
83
* 2: spet_ctrlwp, 1= CTRL reg write prot.
84
* 3: spet_diag, 0= diag active
85
* 4-7: spet_bank, RAM block in use
87
* ARRAY RAM 4-32k RAM (not 8296, dep. on MEMSIZE)
88
* ARRAY VRAM 2/4k RAM (not 8296, dep in CONFIG)
89
* ARRAY EXTRAM 64k (SuperPET and 8096 only)
90
* ARRAY RAM 128k RAM (8296 only)
92
* Added in format V1.1, should be part of
93
* KEYBOARD in later versions.
95
* BYTE POSITIONAL bit 0=0 = symbolic keyboard mapping
96
* =1 = positional keyboard mapping
98
* Added in format V1.2
99
* BYTE EOIBLANK bit 0=0: EOI does not blank screen
100
* =1: EOI does blank screen
103
static int mem_write_ram_snapshot_module(snapshot_t *p)
105
snapshot_module_t *m;
106
BYTE config, rconf, memsize, conf8x96, superpet;
109
memsize = petres.ramSize;
117
config = petres.videoSize == 0x400 ? 1 : 2;
121
config = petres.map + 3;
127
rconf = (petres.mem9 ? 0x40 : 0)
128
| (petres.memA ? 0x80 : 0) ;
132
superpet = (spet_ramen ? 1 : 0)
133
| (spet_ramwp ? 2 : 0)
134
| (spet_ctrlwp ? 4 : 0)
135
| (spet_diag ? 8 : 0)
136
| ((spet_bank << 4) & 0xf0) ;
138
m = snapshot_module_create(p, module_ram_name,
139
PETMEM_DUMP_VER_MAJOR, PETMEM_DUMP_VER_MINOR);
142
snapshot_module_write_byte(m, (BYTE)(config | rconf));
144
resources_get_value("KeymapIndex", (resource_value_t*) &kbdindex);
145
snapshot_module_write_byte(m, (BYTE)(kbdindex >> 1));
147
snapshot_module_write_byte(m, memsize);
148
snapshot_module_write_byte(m, conf8x96);
149
snapshot_module_write_byte(m, superpet);
152
snapshot_module_write_byte_array(m, ram, memsize << 10);
154
snapshot_module_write_byte_array(m, ram + 0x8000,
155
(config < 2) ? 0x400 : 0x800);
157
if (config == 3 || config == 4) {
158
snapshot_module_write_byte_array(m, ram + 0x10000, 0x10000);
161
snapshot_module_write_byte_array(m, ram, 0x20000);
164
snapshot_module_write_byte(m, (BYTE)(kbdindex & 1));
165
snapshot_module_write_byte(m, (BYTE)(petres.eoiblank ? 1 : 0));
167
snapshot_module_close(m);
172
static int mem_read_ram_snapshot_module(snapshot_t *p)
175
snapshot_module_t *m;
176
BYTE config, rconf, byte, memsize, conf8x96, superpet;
177
petinfo_t peti = { 32, 0x0800, 1, 80, 0, 0, 0, 0, 0, 0, 0,
178
NULL, NULL, NULL, NULL, NULL, NULL };
180
m = snapshot_module_open(p, module_ram_name, &vmajor, &vminor);
184
if (vmajor != PETMEM_DUMP_VER_MAJOR) {
185
log_error(pet_snapshot_log,
186
"Cannot load PET RAM module with major version %d",
188
snapshot_module_close(m);
192
snapshot_module_read_byte(m, &config);
194
snapshot_module_read_byte(m, &byte);
195
peti.kbd_type = byte;
197
snapshot_module_read_byte(m, &memsize);
198
snapshot_module_read_byte(m, &conf8x96);
199
snapshot_module_read_byte(m, &superpet);
201
rconf = config & 0xc0;
204
peti.ramSize = memsize;
211
case 0: /* 40 cols w/o CRTC */
215
case 1: /* 40 cols w/ CRTC */
218
case 2: /* 80 cols (w/ CRTC) */
220
case 3: /* SuperPET */
221
spet_ramen = superpet & 1;
222
spet_ramwp = superpet & 2;
223
spet_ctrlwp= superpet & 4;
224
spet_diag = superpet & 8;
225
spet_bank = (superpet >> 4) & 0x0f;
236
peti.mem9 = (rconf & 0x40) ? 1 : 0;
237
peti.memA = (rconf & 0x80) ? 1 : 0;
239
pet_set_conf_info(&peti); /* set resources and config accordingly */
242
mem_initialize_memory();
244
pet_crtc_set_screen();
247
snapshot_module_read_byte_array(m, ram, memsize << 10);
249
snapshot_module_read_byte_array(m, ram + 0x8000,
250
(config < 2) ? 0x400 : 0x800);
252
if (config == 3 || config == 4) {
253
snapshot_module_read_byte_array(m, ram + 0x10000, 0x10000);
256
snapshot_module_read_byte_array(m, ram, 0x20000);
261
snapshot_module_read_byte(m, &byte);
262
resources_get_value("KeymapIndex",
263
(resource_value_t *)&kindex);
264
resources_set_value("KeymapIndex",
265
(resource_value_t)((kindex & ~1) | (byte & 1)));
268
snapshot_module_read_byte(m, &byte);
269
resources_set_value("EoiBlank",
270
(resource_value_t)(byte & 1));
273
snapshot_module_close(m);
278
static const char module_rom_name[] = "PETROM";
279
#define PETROM_DUMP_VER_MAJOR 1
280
#define PETROM_DUMP_VER_MINOR 0
283
* UBYTE CONFIG Bit 0: 1= $9*** ROM included
284
* 1: 1= $a*** ROM included
285
* 2: 1= $b*** ROM included
286
* 3: 1= $e900-$efff ROM included
288
* ARRAY KERNAL 4k KERNAL ROM image $f000-$ffff
289
* ARRAY EDITOR 2k EDITOR ROM image $e000-$e800
290
* ARRAY CHARGEN 2k CHARGEN ROM image
291
* ARRAY ROM9 4k $9*** ROM (if CONFIG & 1)
292
* ARRAY ROMA 4k $A*** ROM (if CONFIG & 2)
293
* ARRAY ROMB 4k $B*** ROM (if CONFIG & 4)
294
* ARRAY ROMC 4k $C*** ROM
295
* ARRAY ROMD 4k $D*** ROM
296
* ARRAY ROME9 7 blocks $e900-$efff ROM (if CONFIG & 8)
300
static int mem_write_rom_snapshot_module(snapshot_t *p, int save_roms)
302
snapshot_module_t *m;
309
m = snapshot_module_create(p, module_rom_name,
310
PETROM_DUMP_VER_MAJOR, PETROM_DUMP_VER_MINOR);
314
/* disable traps before saving the ROM */
315
resources_get_value("VirtualDevices", (resource_value_t*) &trapfl);
316
resources_set_value("VirtualDevices", (resource_value_t) 1);
317
petmem_unpatch_2001();
319
config = (rom_9_loaded ? 1 : 0)
320
| (rom_A_loaded ? 2 : 0)
321
| (rom_B_loaded ? 4 : 0)
322
| ((petres.ramSize == 128) ? 8 : 0);
324
snapshot_module_write_byte(m, config);
327
snapshot_module_write_byte_array(m, rom + 0x7000, 0x1000);
328
snapshot_module_write_byte_array(m, rom + 0x6000, 0x0800);
330
/* pick relevant data from chargen ROM */
331
for (i = 0; i < 128; i++) {
332
snapshot_module_write_byte_array(m, chargen_rom + i * 16, 8);
334
for (i = 0; i < 128; i++) {
335
snapshot_module_write_byte_array(m, chargen_rom + 0x1000 + i * 16,
340
snapshot_module_write_byte_array(m, rom + 0x1000, 0x1000);
343
snapshot_module_write_byte_array(m, rom + 0x2000, 0x1000);
346
snapshot_module_write_byte_array(m, rom + 0x3000, 0x1000);
349
snapshot_module_write_byte_array(m, rom + 0x4000, 0x2000);
352
snapshot_module_write_byte_array(m, rom + 0x6900, 0x0700);
356
/* enable traps again when necessary */
357
resources_set_value("VirtualDevices", (resource_value_t) trapfl);
360
snapshot_module_close(m);
365
static int mem_read_rom_snapshot_module(snapshot_t *p)
368
snapshot_module_t *m;
370
int trapfl, new_iosize;
372
m = snapshot_module_open(p, module_rom_name, &vmajor, &vminor);
374
return 0; /* optional */
376
if (vmajor != PETROM_DUMP_VER_MAJOR) {
377
log_error(pet_snapshot_log,
378
"Cannot load PET ROM module with major version %d",
380
snapshot_module_close(m);
384
/* disable traps before loading the ROM */
385
resources_get_value("VirtualDevices", (resource_value_t*)&trapfl);
386
resources_set_value("VirtualDevices", (resource_value_t)1);
387
petmem_unpatch_2001();
389
config = (rom_9_loaded ? 1 : 0)
390
| (rom_A_loaded ? 2 : 0)
391
| (rom_B_loaded ? 4 : 0)
392
| ((petres.pet2k || petres.ramSize == 128) ? 8 : 0);
394
snapshot_module_read_byte(m, &config);
396
/* De-initialize kbd-buf, autostart and tape stuff here before
397
loading the new ROMs. These depend on addresses defined in the
398
rom - they might be different in the loaded ROM. */
399
kbd_buf_init(0, 0, 0, 0);
400
autostart_init(0, 0, 0, 0, 0, 0);
403
rom_9_loaded = config & 1;
404
rom_A_loaded = config & 2;
405
rom_B_loaded = config & 4;
412
if (new_iosize != petres.IOSize) {
413
petres.IOSize = new_iosize;
414
mem_initialize_memory();
418
/* kernal $f000-$ffff */
419
snapshot_module_read_byte_array(m, rom + 0x7000, 0x1000);
420
/* editor $e000-$e7ff */
421
snapshot_module_read_byte_array(m, rom + 0x6000, 0x0800);
424
resources_set_value("Basic1Chars", (resource_value_t) 0);
425
snapshot_module_read_byte_array(m, chargen_rom, 0x0800);
426
petmem_convert_chargen(chargen_rom);
430
snapshot_module_read_byte_array(m, rom + 0x1000, 0x1000);
434
snapshot_module_read_byte_array(m, rom + 0x2000, 0x1000);
438
snapshot_module_read_byte_array(m, rom + 0x3000, 0x1000);
442
snapshot_module_read_byte_array(m, rom + 0x4000, 0x2000);
444
/* $e900-$efff editor extension */
446
snapshot_module_read_byte_array(m, rom + 0x6900, 0x0700);
450
log_warning(pet_snapshot_log,"Dumped Romset files and saved settings will "
451
"represent\nthe state before loading the snapshot!");
455
petmem_get_kernal_checksum();
456
petmem_get_editor_checksum();
461
/* enable traps again when necessary */
462
resources_set_value("VirtualDevices", (resource_value_t) trapfl);
464
snapshot_module_close(m);
469
int pet_snapshot_write_module(snapshot_t *m, int save_roms) {
470
if (mem_write_ram_snapshot_module(m) < 0
471
|| mem_write_rom_snapshot_module(m, save_roms) < 0 )
476
int pet_snapshot_read_module(snapshot_t *m) {
477
if (mem_read_ram_snapshot_module(m) < 0
478
|| mem_read_rom_snapshot_module(m) < 0 )
59
int pet_snapshot_write(const char *name, int save_roms, int save_disks,
65
s = snapshot_create(name, SNAP_MAJOR, SNAP_MINOR, machine_name);
70
sound_snapshot_prepare();
72
if (maincpu_snapshot_write_module(s) < 0
73
|| pet_snapshot_write_module(s, save_roms) < 0
74
|| crtc_snapshot_write_module(s) < 0
75
|| pia1_snapshot_write_module(s) < 0
76
|| pia2_snapshot_write_module(s) < 0
77
|| viacore_snapshot_write_module(machine_context.via, s) < 0
78
|| drive_snapshot_write_module(s, save_disks, save_roms) < 0
79
|| event_snapshot_write_module(s, event_mode) < 0
80
|| tape_snapshot_write_module(s, save_disks) < 0
81
|| keyboard_snapshot_write_module(s)
82
|| joystick_snapshot_write_module(s)) {
86
if ((!ef) && petres.superpet)
87
ef = acia1_snapshot_write_module(s);
97
int pet_snapshot_read(const char *name, int event_mode)
103
s = snapshot_open(name, &major, &minor, machine_name);
108
if (major != SNAP_MAJOR || minor != SNAP_MINOR) {
109
log_error(LOG_DEFAULT,
110
"Snapshot version (%d.%d) not valid: expecting %d.%d.",
111
major, minor, SNAP_MAJOR, SNAP_MINOR);
116
|| maincpu_snapshot_read_module(s) < 0
117
|| pet_snapshot_read_module(s) < 0
118
|| crtc_snapshot_read_module(s) < 0
119
|| pia1_snapshot_read_module(s) < 0
120
|| pia2_snapshot_read_module(s) < 0
121
|| viacore_snapshot_read_module(machine_context.via, s) < 0
122
|| drive_snapshot_read_module(s) < 0
123
|| event_snapshot_read_module(s, event_mode) < 0
124
|| tape_snapshot_read_module(s) < 0
125
|| keyboard_snapshot_read_module(s) < 0
126
|| joystick_snapshot_read_module(s) < 0) {
131
acia1_snapshot_read_module(s); /* optional, so no error check */
137
machine_trigger_reset(MACHINE_RESET_MODE_SOFT);
140
sound_snapshot_finish();