OSDN Git Service

[VM][WIP] Pre-process to apply new state framework.Still not buildable.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 17 Oct 2018 10:00:01 +0000 (19:00 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 17 Oct 2018 10:00:01 +0000 (19:00 +0900)
233 files changed:
source/src/vm/fm16beta/cmos.cpp
source/src/vm/fm16beta/fm16beta.cpp
source/src/vm/fm16beta/keyboard.cpp
source/src/vm/fm16beta/main.cpp [new file with mode: 0644]
source/src/vm/fm16beta/sub.cpp
source/src/vm/fm16pi/fm16pi.cpp
source/src/vm/fm16pi/sub.cpp
source/src/vm/fmr30/cmos.cpp
source/src/vm/fmr30/floppy.cpp
source/src/vm/fmr30/fmr30.cpp
source/src/vm/fmr30/memory.cpp
source/src/vm/fmr30/rtc.cpp
source/src/vm/fmr30/scsi.cpp
source/src/vm/fmr30/scsi.h
source/src/vm/fmr30/serial.cpp
source/src/vm/fmr30/system.cpp
source/src/vm/fmr30/timer.cpp
source/src/vm/fmr50/bios.cpp
source/src/vm/fmr50/cmos.cpp
source/src/vm/fmr50/floppy.cpp
source/src/vm/fmr50/fmr50.cpp
source/src/vm/fmr50/keyboard.cpp
source/src/vm/fmr50/memory.cpp
source/src/vm/fmr50/scsi.cpp
source/src/vm/fmr50/scsi.h
source/src/vm/fmr50/timer.cpp
source/src/vm/fp1100/fp1100.cpp
source/src/vm/fp1100/main.cpp
source/src/vm/fp1100/rampack.cpp
source/src/vm/fp1100/sub.cpp
source/src/vm/fp200/fp200.cpp
source/src/vm/fp200/io.cpp
source/src/vm/gamegear/gamegear.cpp
source/src/vm/gamegear/gamegear.h
source/src/vm/gamegear/mastersystem.cpp
source/src/vm/gamegear/mastersystem.h
source/src/vm/hc20/hc20.cpp
source/src/vm/hc20/memory.cpp
source/src/vm/hc40/hc40.cpp
source/src/vm/hc40/io.cpp
source/src/vm/hc40/memory.cpp
source/src/vm/hc80/hc80.cpp
source/src/vm/hc80/io.cpp
source/src/vm/hc80/memory.cpp
source/src/vm/j3100/j3100.cpp
source/src/vm/j3100/j3100.h
source/src/vm/jr100/jr100.cpp
source/src/vm/jr100/memory.cpp
source/src/vm/jr800/io.cpp
source/src/vm/jr800/jr800.cpp
source/src/vm/jx/display.cpp
source/src/vm/jx/display.h
source/src/vm/jx/floppy.cpp
source/src/vm/jx/floppy.h
source/src/vm/jx/i286.cpp
source/src/vm/jx/i286.h
source/src/vm/jx/jx.cpp
source/src/vm/jx/jx.h
source/src/vm/jx/keyboard.cpp
source/src/vm/jx/keyboard.h
source/src/vm/m5/cmt.cpp
source/src/vm/m5/m5.cpp
source/src/vm/msx/joystick.cpp
source/src/vm/msx/keyboard.cpp
source/src/vm/msx/memory.cpp
source/src/vm/msx/memory.h
source/src/vm/msx/memory_ex.cpp
source/src/vm/msx/msx.cpp
source/src/vm/msx/msx.h
source/src/vm/msx/msx_ex.cpp
source/src/vm/msx/rtcif.cpp
source/src/vm/msx/scc.cpp
source/src/vm/multi8/cmt.cpp
source/src/vm/multi8/display.cpp
source/src/vm/multi8/floppy.cpp
source/src/vm/multi8/kanji.cpp
source/src/vm/multi8/keyboard.cpp
source/src/vm/multi8/memory.cpp
source/src/vm/multi8/multi8.cpp
source/src/vm/mycomz80a/display.cpp
source/src/vm/mycomz80a/keyboard.cpp
source/src/vm/mycomz80a/memory.cpp
source/src/vm/mycomz80a/mycomz80a.cpp
source/src/vm/mz2500/cmt.cpp
source/src/vm/mz2500/crtc.cpp
source/src/vm/mz2500/floppy.cpp
source/src/vm/mz2500/interrupt.cpp
source/src/vm/mz2500/joystick.cpp
source/src/vm/mz2500/keyboard.cpp
source/src/vm/mz2500/memory.cpp
source/src/vm/mz2500/memory80b.cpp
source/src/vm/mz2500/mouse.cpp
source/src/vm/mz2500/mz1e30.cpp
source/src/vm/mz2500/mz1m01.cpp
source/src/vm/mz2500/mz1r12.cpp
source/src/vm/mz2500/mz1r13.cpp
source/src/vm/mz2500/mz1r37.cpp
source/src/vm/mz2500/mz2500.cpp
source/src/vm/mz2500/mz80b.cpp
source/src/vm/mz2500/serial.cpp
source/src/vm/mz2800/crtc.cpp
source/src/vm/mz2800/joystick.cpp
source/src/vm/mz2800/keyboard.cpp
source/src/vm/mz2800/memory.cpp
source/src/vm/mz2800/mouse.cpp
source/src/vm/mz2800/mz2800.cpp
source/src/vm/mz2800/reset.cpp
source/src/vm/mz2800/sasi.cpp
source/src/vm/mz2800/sasi.h
source/src/vm/mz2800/serial.cpp
source/src/vm/mz3500/keyboard.cpp
source/src/vm/mz3500/main.cpp
source/src/vm/mz3500/mz3500.cpp
source/src/vm/mz3500/sub.cpp
source/src/vm/mz5500/display.cpp
source/src/vm/mz5500/keyboard.cpp
source/src/vm/mz5500/memory.cpp
source/src/vm/mz5500/mz5500.cpp
source/src/vm/mz5500/sysport.cpp
source/src/vm/mz700/cmos.cpp
source/src/vm/mz700/emm.cpp
source/src/vm/mz700/floppy.cpp
source/src/vm/mz700/kanji.cpp
source/src/vm/mz700/keyboard.cpp
source/src/vm/mz700/memory.cpp
source/src/vm/mz700/mz700.cpp
source/src/vm/mz700/quickdisk.cpp
source/src/vm/mz700/ramfile.cpp
source/src/vm/mz80k/keyboard.cpp
source/src/vm/mz80k/memory.cpp
source/src/vm/mz80k/mz80k.cpp
source/src/vm/mz80k/printer.cpp
source/src/vm/n5200/n5200.cpp
source/src/vm/n5200/n5200.h
source/src/vm/pasopia/display.cpp
source/src/vm/pasopia/floppy.cpp
source/src/vm/pasopia/kanjipac2.cpp
source/src/vm/pasopia/keyboard.cpp
source/src/vm/pasopia/memory.cpp
source/src/vm/pasopia/pac2.cpp
source/src/vm/pasopia/pasopia.cpp
source/src/vm/pasopia/rampac2.cpp
source/src/vm/pasopia7/display.cpp
source/src/vm/pasopia7/floppy.cpp
source/src/vm/pasopia7/iobus.cpp
source/src/vm/pasopia7/iotrap.cpp
source/src/vm/pasopia7/kanjipac2.cpp
source/src/vm/pasopia7/keyboard.cpp
source/src/vm/pasopia7/memory.cpp
source/src/vm/pasopia7/pac2.cpp
source/src/vm/pasopia7/pasopia7.cpp
source/src/vm/pasopia7/rampac2.cpp
source/src/vm/pc100/crtc.cpp
source/src/vm/pc100/ioctrl.cpp
source/src/vm/pc100/kanji.cpp
source/src/vm/pc100/pc100.cpp
source/src/vm/pc2001/io.cpp
source/src/vm/pc2001/pc2001.cpp
source/src/vm/pc6001/display.cpp
source/src/vm/pc6001/floppy.cpp
source/src/vm/pc6001/memory.cpp
source/src/vm/pc6001/pc6001.cpp
source/src/vm/pc6001/psub.cpp
source/src/vm/pc6001/sub.cpp
source/src/vm/pc6001/timer.cpp
source/src/vm/pc8201/cmt.cpp
source/src/vm/pc8201/keyboard.cpp
source/src/vm/pc8201/lcd.cpp
source/src/vm/pc8201/memory.cpp
source/src/vm/pc8201/pc8201.cpp
source/src/vm/pc98ha/calendar.cpp
source/src/vm/pc98ha/floppy.cpp
source/src/vm/pc98ha/keyboard.cpp
source/src/vm/pc98ha/memory.cpp
source/src/vm/pc98ha/note.cpp
source/src/vm/pc98ha/pc98ha.cpp
source/src/vm/phc20/memory.cpp
source/src/vm/phc20/phc20.cpp
source/src/vm/phc25/keyboard.cpp
source/src/vm/phc25/memory.cpp
source/src/vm/phc25/phc25.cpp
source/src/vm/phc25/system.cpp
source/src/vm/pv1000/joystick.cpp
source/src/vm/pv1000/psg.cpp
source/src/vm/pv1000/pv1000.cpp
source/src/vm/pv1000/vdp.cpp
source/src/vm/pv2000/cmt.cpp
source/src/vm/pv2000/keyboard.cpp
source/src/vm/pv2000/printer.cpp
source/src/vm/pv2000/pv2000.cpp
source/src/vm/pyuta/memory.cpp
source/src/vm/pyuta/pyuta.cpp
source/src/vm/qc10/display.cpp
source/src/vm/qc10/keyboard.cpp
source/src/vm/qc10/memory.cpp
source/src/vm/qc10/mfont.cpp
source/src/vm/qc10/qc10.cpp
source/src/vm/rx78/cmt.cpp
source/src/vm/rx78/keyboard.cpp
source/src/vm/rx78/memory.cpp
source/src/vm/rx78/printer.cpp
source/src/vm/rx78/rx78.cpp
source/src/vm/rx78/vdp.cpp
source/src/vm/sc3000/keyboard.cpp
source/src/vm/sc3000/memory.cpp
source/src/vm/sc3000/sc3000.cpp
source/src/vm/scv/io.cpp
source/src/vm/scv/memory.cpp
source/src/vm/scv/scv.cpp
source/src/vm/scv/sound.cpp
source/src/vm/scv/vdp.cpp
source/src/vm/smb80te/memory.cpp
source/src/vm/smb80te/smb80te.cpp
source/src/vm/smc777/memory.cpp
source/src/vm/smc777/smc777.cpp
source/src/vm/tk80bs/cmt.cpp
source/src/vm/tk80bs/display.cpp
source/src/vm/tk80bs/keyboard.cpp
source/src/vm/tk80bs/membus.cpp
source/src/vm/tk80bs/memory.cpp
source/src/vm/tk80bs/tk80bs.cpp
source/src/vm/x07/io.cpp
source/src/vm/x07/x07.cpp
source/src/vm/yalky/io.cpp
source/src/vm/yalky/yalky.cpp
source/src/vm/yis/display.cpp
source/src/vm/yis/keyboard.cpp
source/src/vm/yis/mapper.cpp
source/src/vm/yis/yis.cpp
source/src/vm/ys6464a/display.cpp
source/src/vm/ys6464a/ys6464a.cpp
source/src/vm/z80tvgame/memory.cpp
source/src/vm/z80tvgame/z80tvgame.cpp

index 9d44ada..e972e07 100644 (file)
@@ -95,3 +95,15 @@ bool CMOS::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMOS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(cmos, sizeof(cmos), 1);
+       state_fio->StateBool(modified);
+       return true;
+}
index 08be4c0..d37e133 100644 (file)
@@ -440,3 +440,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index eedbdd9..cc74175 100644 (file)
@@ -272,3 +272,19 @@ static const int scan_code[] = {
 -1,    -1,     0x34,   -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,
 -1,    -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,
 };
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(kbstat);
+       state_fio->StateInt32(kbdata);
+       state_fio->StateBuffer(table, sizeof(table), 1);
+       return true;
+}
diff --git a/source/src/vm/fm16beta/main.cpp b/source/src/vm/fm16beta/main.cpp
new file mode 100644 (file)
index 0000000..ecbdf2f
--- /dev/null
@@ -0,0 +1,10 @@
+bool MAIN::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       return true;
+}
index 781600e..a2f040b 100644 (file)
@@ -978,3 +978,13 @@ bool SUB::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SUB::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       return MEMORY::process_state(state_fio, loading);
+}
index b51963f..c4eee47 100644 (file)
@@ -468,3 +468,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index b5eaaee..a47d8e9 100644 (file)
@@ -244,3 +244,21 @@ bool SUB::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SUB::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buffer->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint8(key_data);
+       state_fio->StateBool(key_irq);
+       state_fio->StateUint8(fdc_drive);
+       state_fio->StateUint8(fdc_side);
+       state_fio->StateUint8(rtc_data);
+       return true;
+}
index f92ec6a..ad82611 100644 (file)
@@ -96,3 +96,15 @@ bool CMOS::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMOS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(cmos, sizeof(cmos), 1);
+       state_fio->StateBool(modified);
+       return true;
+}
index beab6da..969e3eb 100644 (file)
@@ -154,3 +154,19 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(fdcr);
+       state_fio->StateUint8(fdsl);
+       state_fio->StateUint8(fdst);
+       state_fio->StateInt32(drvsel);
+       state_fio->StateBool(irq);
+       state_fio->StateBuffer(changed, sizeof(changed), 1);
+       return true;
+}
index d39b37a..d9da4e0 100644 (file)
@@ -471,3 +471,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index bd76731..8de5bc5 100644 (file)
@@ -609,3 +609,34 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(cvram, sizeof(cvram), 1);
+       state_fio->StateBuffer(kvram, sizeof(kvram), 1);
+       state_fio->StateUint8(mcr1);
+       state_fio->StateUint8(mcr2);
+       state_fio->StateUint8(a20);
+       state_fio->StateUint8(lcdadr);
+       state_fio->StateBuffer(lcdreg, sizeof(lcdreg), 1);
+       state_fio->StateUint16(dcr1);
+       state_fio->StateUint16(dcr2);
+       state_fio->StateInt32(kj_h);
+       state_fio->StateInt32(kj_l);
+       state_fio->StateInt32(kj_ofs);
+       state_fio->StateInt32(kj_row);
+       state_fio->StateInt32(blinkcnt);
+       
+       // post process
+       if(loading) {
+               update_bank();
+       }
+       return true;
+}
index 4824606..dcc1a19 100644 (file)
@@ -281,3 +281,23 @@ bool RTC::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RTC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(register_id);
+       state_fio->StateUint16(rtcmr);
+       state_fio->StateUint16(rtdsr);
+       state_fio->StateUint16(rtadr);
+       state_fio->StateUint16(rtobr);
+       state_fio->StateUint16(rtibr);
+       state_fio->StateBuffer(regs, sizeof(regs), 1);
+       return true;
+}
index 977cdd9..7423ed2 100644 (file)
@@ -216,3 +216,17 @@ bool SCSI::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SCSI::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(ctrl_reg);
+       state_fio->StateUint8(intm_reg);
+       state_fio->StateBool(phase_status);
+       state_fio->StateBool(eop_status);
+       return true;
+}
index f516206..7ff75b8 100644 (file)
@@ -37,6 +37,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_dma(DEVICE* device)
index bf7e5b0..46e2f17 100644 (file)
@@ -189,3 +189,14 @@ bool SERIAL::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SERIAL::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(sioctrl, sizeof(sioctrl), 1);
+       return true;
+}
index d1a845c..ede8ae2 100644 (file)
@@ -105,3 +105,16 @@ bool SYSTEM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SYSTEM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(arr);
+       state_fio->StateUint8(nmistat);
+       state_fio->StateUint8(nmimask);
+       return true;
+}
index 7770bc4..33b1d94 100644 (file)
@@ -107,3 +107,15 @@ bool TIMER::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool TIMER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(ctrl);
+       state_fio->StateUint8(status);
+       return true;
+}
index cfc16f7..da6f82a 100644 (file)
@@ -1210,3 +1210,23 @@ bool BIOS::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool BIOS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       for(int i = 0; i < MAX_DRIVE; i++) {
+               if(!disk[i]->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateInt32(secnum);
+       state_fio->StateInt32(timeout);
+       state_fio->StateBuffer(drive_mode1, sizeof(drive_mode1), 1);
+       state_fio->StateBuffer(drive_mode2, sizeof(drive_mode2), 1);
+       state_fio->StateBuffer(scsi_blocks, sizeof(scsi_blocks), 1);
+       return true;
+}
index f59359b..89fb2db 100644 (file)
@@ -121,3 +121,16 @@ bool CMOS::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMOS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(cmos, sizeof(cmos), 1);
+       state_fio->StateBool(modified);
+       state_fio->StateUint8(bank);
+       return true;
+}
index b4fe250..2c80c9b 100644 (file)
@@ -168,3 +168,18 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(drvreg);
+       state_fio->StateInt32(drvsel);
+       state_fio->StateBool(irq);
+       state_fio->StateBool(irqmsk);
+       state_fio->StateBuffer(changed, sizeof(changed), 1);
+       return true;
+}
index 315b3ab..cf6a1d1 100644 (file)
@@ -610,3 +610,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 22de29c..1c103ac 100644 (file)
@@ -161,3 +161,21 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint8(kbstat);
+       state_fio->StateUint8(kbdata);
+       state_fio->StateUint8(kbint);
+       state_fio->StateUint8(kbmsk);
+       state_fio->StateBuffer(table, sizeof(table), 1);
+       return true;
+}
index 863733d..a221eb9 100644 (file)
@@ -1406,3 +1406,68 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(cvram, sizeof(cvram), 1);
+#ifdef _FMR60
+       state_fio->StateBuffer(avram, sizeof(avram), 1);
+#else
+       state_fio->StateBuffer(kvram, sizeof(kvram), 1);
+#endif
+       state_fio->StateUint8(machine_id);
+       state_fio->StateUint8(protect);
+       state_fio->StateUint8(rst);
+       state_fio->StateUint8(mainmem);
+       state_fio->StateUint8(rplane);
+       state_fio->StateUint8(wplane);
+       state_fio->StateUint8(dma_addr_reg);
+       state_fio->StateUint8(dma_wrap_reg);
+       state_fio->StateUint32(dma_addr_mask);
+       state_fio->StateBool(disp);
+       state_fio->StateBool(vsync);
+       state_fio->StateInt32(blink);
+       state_fio->StateBuffer(apal, sizeof(apal), 1);
+       state_fio->StateUint8(apalsel);
+       state_fio->StateBuffer(dpal, sizeof(dpal), 1);
+       state_fio->StateUint8(outctrl);
+#ifndef _FMR60
+       state_fio->StateUint8(pagesel);
+       state_fio->StateUint8(ankcg);
+       state_fio->StateUint8(dispctrl);
+       state_fio->StateUint8(mix);
+       state_fio->StateUint16(accaddr);
+       state_fio->StateUint16(dispaddr);
+       state_fio->StateInt32(kj_h);
+       state_fio->StateInt32(kj_l);
+       state_fio->StateInt32(kj_ofs);
+       state_fio->StateInt32(kj_row);
+       state_fio->StateUint8(cmdreg);
+       state_fio->StateUint8(imgcol);
+       state_fio->StateUint8(maskreg);
+       state_fio->StateBuffer(compreg, sizeof(compreg), 1);
+       state_fio->StateUint8(compbit);
+       state_fio->StateUint8(bankdis);
+       state_fio->StateBuffer(tilereg, sizeof(tilereg), 1);
+       state_fio->StateUint16(lofs);
+       state_fio->StateUint16(lsty);
+       state_fio->StateUint16(lsx);
+       state_fio->StateUint16(lsy);
+       state_fio->StateUint16(lex);
+       state_fio->StateUint16(ley);
+#endif
+       state_fio->StateBuffer(palette_cg, sizeof(palette_cg), 1);
+       
+       // post process
+       if(loading) {
+               update_bank();
+       }
+       return true;
+}
index 79728ee..4d3b1af 100644 (file)
@@ -160,3 +160,15 @@ bool SCSI::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SCSI::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(ctrl_reg);
+       state_fio->StateBool(irq_status);
+       return true;
+}
index a33b15e..0e6b91e 100644 (file)
@@ -39,6 +39,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_dma(DEVICE* device)
index b61ab22..5932f80 100644 (file)
@@ -135,3 +135,18 @@ bool TIMER::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool TIMER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint16(free_run_counter);
+       state_fio->StateUint8(intr_reg);
+       state_fio->StateUint8(rtc_data);
+       state_fio->StateBool(tmout0);
+       state_fio->StateBool(tmout1);
+       return true;
+}
index 2dc22ca..3418429 100644 (file)
@@ -427,3 +427,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 1c78970..ba1ee08 100644 (file)
@@ -315,3 +315,26 @@ bool MAIN::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MAIN::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(comm_data);
+       state_fio->StateBool(rom_sel);
+       state_fio->StateUint8(slot_sel);
+       state_fio->StateBuffer(slot_exp, sizeof(slot_exp), 1);
+       state_fio->StateUint8(intr_mask);
+       state_fio->StateUint8(intr_request);
+       state_fio->StateUint8(intr_in_service);
+       
+       // post process
+       if(loading) {
+               update_memory_map();
+       }
+       return true;
+}
index 607bd31..fc0d2d6 100644 (file)
@@ -102,3 +102,15 @@ bool RAMPACK::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RAMPACK::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBool(modified);
+       return true;
+}
index b727df6..7947865 100644 (file)
@@ -688,3 +688,36 @@ bool SUB::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SUB::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram_b, sizeof(vram_b), 1);
+       state_fio->StateBuffer(vram_r, sizeof(vram_r), 1);
+       state_fio->StateBuffer(vram_g, sizeof(vram_g), 1);
+       state_fio->StateUint8(pa);
+       state_fio->StateUint8(pb);
+       state_fio->StateUint8(pc);
+       state_fio->StateUint8(comm_data);
+       state_fio->StateBool(so);
+       state_fio->StateUint8(clock);
+       state_fio->StateBuffer(&b16_1, sizeof(b16_1), 1);
+       state_fio->StateBuffer(&b16_2, sizeof(b16_2), 1);
+       state_fio->StateBuffer(&g21_1, sizeof(g21_1), 1);
+       state_fio->StateBuffer(&g21_2, sizeof(g21_2), 1);
+       state_fio->StateBuffer(&c15, sizeof(c15), 1);
+       state_fio->StateBuffer(&c16, sizeof(c16), 1);
+       state_fio->StateBuffer(&f21, sizeof(f21), 1);
+       state_fio->StateUint8(key_sel);
+       state_fio->StateUint8(key_data);
+       state_fio->StateUint8(color_reg);
+       state_fio->StateBool(hsync);
+       state_fio->StateBool(wait);
+       state_fio->StateUint8(cblink);
+       return true;
+}
index 7c62c22..0474c70 100644 (file)
@@ -373,3 +373,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index 9a36b6b..62371de 100644 (file)
@@ -517,11 +517,11 @@ void IO::close_tape()
 
                                __riff_chunk_size.d = length - 8;
                                __fmt_chunk_size.d = 16;
-                               __fmt_id.w = 1;
-                               __channels.w = 1;
+                               __fmt_id.u16 = 1;
+                               __channels.u16 = 1;
                                __sample_rate.d = CMT_SAMPLE_RATE;
-                               __block_size.w = 1;
-                               __sample_bits.w = 8;
+                               __block_size.u16 = 1;
+                               __sample_bits.u16 = 8;
        
                                memcpy(wav_header.riff_chunk.id, "RIFF", 4);
                                wav_header.riff_chunk.size = __riff_chunk_size.get_4bytes_le_to();
@@ -827,3 +827,70 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       // pre process
+       if(loading) {
+               close_tape();
+       }
+       state_fio->StateBuffer(lcd, sizeof(lcd), 1);
+       state_fio->StateInt32(lcd_status);
+       state_fio->StateInt32(lcd_addr);
+       state_fio->StateBool(lcd_text);
+       state_fio->StateBool(cmt_selected);
+       state_fio->StateUint8(cmt_mode);
+       state_fio->StateBool(cmt_play_ready);
+       state_fio->StateBool(cmt_play_signal);
+       state_fio->StateBool(cmt_rec_ready);
+       state_fio->StateBool(cmt_rec);
+       state_fio->StateBool(cmt_is_wav);
+       state_fio->StateBuffer(cmt_rec_file_path, sizeof(cmt_rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(cmt_rec) {
+                       cmt_fio->Fopen(cmt_rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(cmt_fio->IsOpened()) {
+                                       cmt_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(cmt_rec && cmt_fio->IsOpened()) {
+                       int length_tmp = (int)cmt_fio->Ftell();
+                       cmt_fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               cmt_fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(cmt_bufcnt);
+       state_fio->StateBuffer(cmt_buffer, cmt_bufcnt, 1);
+       state_fio->StateUint8(cmt_clock);
+       state_fio->StateBuffer(&b16_1, sizeof(b16_1), 1);
+       state_fio->StateBuffer(&b16_2, sizeof(b16_2), 1);
+       state_fio->StateBuffer(&g21_1, sizeof(g21_1), 1);
+       state_fio->StateBuffer(&g21_2, sizeof(g21_2), 1);
+       state_fio->StateBuffer(&c15, sizeof(c15), 1);
+       state_fio->StateBuffer(&c16, sizeof(c16), 1);
+       state_fio->StateBuffer(&f21, sizeof(f21), 1);
+       state_fio->StateUint8(key_column);
+       return true;
+}
index d515096..d5dca39 100644 (file)
@@ -384,3 +384,48 @@ void VM::update_config()
        }
 }
 
+#define STATE_VERSION  1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 179be18..fbb641a 100644 (file)
@@ -145,6 +145,7 @@ public:
        bool is_frame_skippable();
        
        void update_config();
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index b6edbaa..99ac53f 100644 (file)
@@ -389,3 +389,49 @@ void VM::update_config()
                device->update_config();
        }
 }
+
+#define STATE_VERSION  1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 0863637..49c3b2f 100644 (file)
@@ -149,6 +149,7 @@ public:
        bool is_frame_skippable();
        
        void update_config();
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index 14daf69..3194ab4 100644 (file)
@@ -390,3 +390,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 6089bf6..18fcaf1 100644 (file)
@@ -977,3 +977,87 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       bool wr = false;
+       bool rd = false;
+       
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(loading) {
+               wr = state_fio->FgetBool();
+               rd = state_fio->FgetBool();
+       } else {
+               state_fio->FputBool(wbank[0x8000 >> 13] == ext);
+               state_fio->FputBool(rbank[0x8000 >> 13] == ext);
+       }
+       state_fio->StateBuffer(rom, sizeof(rom), 1);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       if(!cmd_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBool(sio_select);
+       state_fio->StateBool(special_cmd_masked);
+       state_fio->StateBuffer(slave_mem, sizeof(slave_mem), 1);
+       state_fio->StateBuffer(sound, sizeof(sound), 1);
+       state_fio->StateInt32(sound_ptr);
+       state_fio->StateInt32(sound_count);
+       state_fio->StateUint8(sound_reply);
+       state_fio->StateDouble(sound_freq);
+       state_fio->StateBuffer(key_stat, sizeof(key_stat), 1);
+       state_fio->StateBuffer(key_flag, sizeof(key_flag), 1);
+       state_fio->StateInt32(key_data);
+       state_fio->StateInt32(key_strobe);
+       state_fio->StateInt32(key_intmask);
+       state_fio->StateBool(cmt_play);
+       state_fio->StateBool(cmt_rec);
+       state_fio->StateBuffer(cmt_file_path, sizeof(cmt_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(cmt_rec) {
+                       cmt_fio->Fopen(cmt_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(cmt_fio->IsOpened()) {
+                                       cmt_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(cmt_rec && cmt_fio->IsOpened()) {
+                       int length_tmp = (int)cmt_fio->Ftell();
+                       cmt_fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               cmt_fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(cmt_count);
+       state_fio->StateBuffer(cmt_buffer, sizeof(cmt_buffer), 1);
+       state_fio->StateBuffer(lcd, sizeof(lcd), 1);
+       state_fio->StateUint8(lcd_select);
+       state_fio->StateUint8(lcd_data);
+       state_fio->StateInt32(lcd_clock);
+       state_fio->StateInt32(int_status);
+       state_fio->StateInt32(int_mask);
+       
+       // post process
+       if(loading) {
+               SET_BANK(0x8000, 0xbfff, wr ? ext : wdmy, rd ? ext : rom);
+       }
+       return true;
+}
index ba28276..8c95401 100644 (file)
@@ -365,3 +365,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 19da5a2..aeaca83 100644 (file)
@@ -897,3 +897,63 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(cur_clock);
+       state_fio->StateUint8(bcr);
+       state_fio->StateUint8(slbcr);
+       state_fio->StateUint8(isr);
+       state_fio->StateUint8(ier);
+       state_fio->StateUint8(bankr);
+       state_fio->StateUint8(ioctlr);
+       state_fio->StateUint32(icrc);
+       state_fio->StateUint32(icrb);
+       state_fio->StateBool(ear);
+       state_fio->StateUint8(vadr);
+       state_fio->StateUint8(yoff);
+       if(!cmd_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!rsp_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(register_id_1sec);
+       state_fio->StateBool(onesec_intr);
+       state_fio->StateBool(onesec_intr_enb);
+       state_fio->StateBool(alarm_intr);
+       state_fio->StateBool(alarm_intr_enb);
+       state_fio->StateBuffer(alarm, sizeof(alarm), 1);
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBool(kb_intr_enb);
+       state_fio->StateBool(kb_rep_enb);
+       state_fio->StateBool(kb_caps);
+       state_fio->StateUint8(kb_rep_spd1);
+       state_fio->StateUint8(kb_rep_spd2);
+       if(!art_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint8(artsr);
+       state_fio->StateUint8(artdir);
+       state_fio->StateBool(txen);
+       state_fio->StateBool(rxen);
+       state_fio->StateBool(dsr);
+       state_fio->StateInt32(register_id_art);
+       state_fio->StateBool(beep);
+       state_fio->StateBool(res_z80);
+       state_fio->StateBool(res_7508);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       state_fio->StateUint32(extar);
+       state_fio->StateUint8(extcr);
+       return true;
+}
index d04711b..681e635 100644 (file)
@@ -177,3 +177,20 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(bank);
+       
+       // post process
+       if(loading) {
+               set_bank(bank);
+       }
+       return true;
+}
index 42a5810..e62a495 100644 (file)
@@ -282,3 +282,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 42ca1e8..1d45033 100644 (file)
@@ -2153,3 +2153,97 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(cur_clock);
+       state_fio->StateUint8(bcr);
+       state_fio->StateUint8(slbcr);
+       state_fio->StateUint8(isr);
+       state_fio->StateUint8(ier);
+       state_fio->StateUint8(ioctlr);
+       state_fio->StateUint32(icrc);
+       state_fio->StateUint32(icrb);
+       state_fio->StateBool(ear);
+       state_fio->StateUint8(vadr);
+       state_fio->StateUint8(yoff);
+       if(!cmd7508_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!rsp7508_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(register_id);
+       state_fio->StateBool(onesec_intr);
+       state_fio->StateBool(onesec_intr_enb);
+       state_fio->StateBool(alarm_intr);
+       state_fio->StateBool(alarm_intr_enb);
+       state_fio->StateBuffer(alarm, sizeof(alarm), 1);
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBool(kb_intr_enb);
+       state_fio->StateBool(kb_rep_enb);
+       state_fio->StateBool(kb_caps);
+       state_fio->StateUint8(kb_rep_spd1);
+       state_fio->StateUint8(kb_rep_spd2);
+       state_fio->StateBool(beep);
+       state_fio->StateBool(res_z80);
+       state_fio->StateBool(res_7508);
+       state_fio->StateUint8(cmd6303);
+       state_fio->StateUint8(psr);
+       if(!cmd6303_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!rsp6303_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint16(cs_addr);
+       state_fio->StateUint16(gs_addr);
+       state_fio->StateUint8(lcd_on);
+       state_fio->StateUint8(scr_mode);
+       state_fio->StateUint16(scr_ptr);
+       state_fio->StateUint8(num_lines);
+       state_fio->StateUint8(curs_mode);
+       state_fio->StateUint8(curs_x);
+       state_fio->StateUint8(curs_y);
+       state_fio->StateUint8(wnd_ptr_x);
+       state_fio->StateUint8(wnd_ptr_y);
+       state_fio->StateUint8(flash_block);
+       state_fio->StateUint8(cs_blocks);
+       state_fio->StateBuffer(cs_block, sizeof(cs_block), 1);
+       state_fio->StateUint8(gs_blocks);
+       state_fio->StateBuffer(gs_block, sizeof(gs_block), 1);
+       state_fio->StateBuffer(font, sizeof(font), 1);
+       state_fio->StateBuffer(udgc, sizeof(udgc), 1);
+       state_fio->StateBuffer(mov, sizeof(mov), 1);
+       state_fio->StateBuffer(lcd, sizeof(lcd), 1);
+       state_fio->StateInt32(blink);
+       if(!tf20_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(device_type);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       state_fio->StateUint32(extar);
+       state_fio->StateUint8(extcr);
+       state_fio->StateBuffer(iramdisk_sectors, sizeof(iramdisk_sectors), 1);
+       state_fio->StateUint8(iramdisk_cmd);
+       state_fio->StateInt32(iramdisk_count);
+       state_fio->StateInt32(iramdisk_dest);
+       state_fio->StateBuffer(iramdisk_buf, sizeof(iramdisk_buf), 1);
+       if(loading) {
+               iramdisk_ptr = iramdisk_buf + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(iramdisk_ptr - iramdisk_buf));
+       }
+       return true;
+}
index 00d6b5a..2493cf9 100644 (file)
@@ -138,3 +138,20 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(bank);
+       
+       // post process
+       if(loading) {
+               set_bank(bank);
+       }
+       return true;
+}
index bd0978b..facfb11 100644 (file)
@@ -418,3 +418,48 @@ void VM::update_config()
        }
 }
 
+#define STATE_VERSION  1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 525b072..a9895ba 100644 (file)
@@ -183,6 +183,7 @@ public:
        bool is_frame_skippable();
        
        void update_config();
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index ad9ba23..ecbab75 100644 (file)
@@ -334,3 +334,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 93088ea..be6761c 100644 (file)
@@ -216,3 +216,17 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateInt32(key_column);
+       state_fio->StateBool(cmode);
+       return true;
+}
index 37b0e98..1751d86 100644 (file)
@@ -200,3 +200,13 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       return true;
+}
index 35a2b1f..fcc6b1d 100644 (file)
@@ -335,3 +335,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index 44b81cf..720086d 100644 (file)
@@ -525,3 +525,48 @@ void DISPLAY::draw_graph_360x512_4col()
        // TODO
 }
 
+#define STATE_VERSION  1
+
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(extvram, sizeof(extvram), 1);
+       state_fio->StateBuffer(vgarray, sizeof(vgarray), 1);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+       state_fio->StateInt32(vgarray_num);
+       state_fio->StateBuffer(bankreg, sizeof(bankreg), 1);
+       state_fio->StateInt32(bankreg_num);
+       state_fio->StateUint8(hires_mode);
+       state_fio->StateUint8(page);
+       state_fio->StateUint8(status);
+       state_fio->StateInt32(cblink);
+       return true;
+}
+
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(extvram, sizeof(extvram), 1);
+       state_fio->StateBuffer(vgarray, sizeof(vgarray), 1);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+       state_fio->StateInt32(vgarray_num);
+       state_fio->StateBuffer(bankreg, sizeof(bankreg), 1);
+       state_fio->StateInt32(bankreg_num);
+       state_fio->StateUint8(hires_mode);
+       state_fio->StateUint8(page);
+       state_fio->StateUint8(status);
+       state_fio->StateInt32(cblink);
+       return true;
+}
index f20a0f6..8bebd28 100644 (file)
@@ -70,6 +70,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
        void event_frame();
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_mem(MEMORY* device)
index 4b50936..5a87bb6 100644 (file)
@@ -52,3 +52,30 @@ void FLOPPY::event_callback(int event_id, int err)
        register_id = -1;
 }
 
+#define STATE_VERSION  1
+
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(prev);
+       state_fio->StateInt32(register_id);
+       return true;
+}
+
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(prev);
+       state_fio->StateInt32(register_id);
+       return true;
+}
index cd6d3a5..d1e6bed 100644 (file)
@@ -32,6 +32,7 @@ public:
        void reset();
        void write_io8(uint32_t addr, uint32_t data);
        void event_callback(int event_id, int err);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_fdc(DEVICE* device)
index bae0440..d668eb5 100644 (file)
@@ -417,41 +417,68 @@ int I286::get_shutdown_flag()
 
 #define STATE_VERSION  4
 
-void I286::save_state(FILEIO* state_fio)
+bool I286::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(opaque, sizeof(cpu_state), 1);
        
-       state_fio->Fwrite(opaque, sizeof(cpu_state), 1);
+       // post process
+       if(loading) {
+               cpu_state *cpustate = (cpu_state *)opaque;
+               cpustate->pic = d_pic;
+               cpustate->program = d_mem;
+               cpustate->io = d_io;
+#ifdef I86_PSEUDO_BIOS
+               cpustate->bios = d_bios;
+#endif
+#ifdef SINGLE_MODE_DMA
+               cpustate->dma = d_dma;
+#endif
+#ifdef USE_DEBUGGER
+               cpustate->emu = emu;
+               cpustate->debugger = d_debugger;
+               cpustate->program_stored = d_mem;
+               cpustate->io_stored = d_io;
+               cpustate->prev_total_icount = cpustate->total_icount;
+#endif
+       }
+       return true;
 }
 
-bool I286::load_state(FILEIO* state_fio)
+bool I286::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       state_fio->Fread(opaque, sizeof(cpu_state), 1);
+       state_fio->StateBuffer(opaque, sizeof(cpu_state), 1);
        
        // post process
-       cpu_state *cpustate = (cpu_state *)opaque;
-       cpustate->pic = d_pic;
-       cpustate->program = d_mem;
-       cpustate->io = d_io;
+       if(loading) {
+               cpu_state *cpustate = (cpu_state *)opaque;
+               cpustate->pic = d_pic;
+               cpustate->program = d_mem;
+               cpustate->io = d_io;
 #ifdef I86_PSEUDO_BIOS
-       cpustate->bios = d_bios;
+               cpustate->bios = d_bios;
 #endif
 #ifdef SINGLE_MODE_DMA
-       cpustate->dma = d_dma;
+               cpustate->dma = d_dma;
 #endif
 #ifdef USE_DEBUGGER
-       cpustate->emu = emu;
-       cpustate->debugger = d_debugger;
-       cpustate->program_stored = d_mem;
-       cpustate->io_stored = d_io;
+               cpustate->emu = emu;
+               cpustate->debugger = d_debugger;
+               cpustate->program_stored = d_mem;
+               cpustate->io_stored = d_io;
+               cpustate->prev_total_icount = cpustate->total_icount;
 #endif
+       }
        return true;
 }
-
index 963ffcb..28dca4e 100644 (file)
@@ -103,8 +103,7 @@ public:
        void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
        int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
 #endif
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique function
        void set_context_mem(DEVICE* device)
index 08b599a..9667c4e 100644 (file)
@@ -348,3 +348,50 @@ void VM::update_config()
        }
 }
 
+#define STATE_VERSION  1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index 961f3d7..2d18c40 100644 (file)
@@ -157,6 +157,7 @@ public:
        bool is_frame_skippable();
        
        void update_config();
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index 706b63f..8c325d1 100644 (file)
@@ -192,3 +192,44 @@ void KEYBOARD::key_up(int code)
        }
 }
 
+#define STATE_VERSION  1
+
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state(state_fio, loading)) {
+               return false;
+       }
+#ifndef KEYBOARD_HACK
+       state_fio->StateUint64(send_data);
+       state_fio->StateInt32(send_count);
+#endif
+       state_fio->StateBool(key_latched);
+       state_fio->StateUint8(nmi_reg);
+       return true;
+}
+
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state(state_fio, loading)) {
+               return false;
+       }
+#ifndef KEYBOARD_HACK
+       state_fio->StateUint64(send_data);
+       state_fio->StateInt32(send_count);
+#endif
+       state_fio->StateBool(key_latched);
+       state_fio->StateUint8(nmi_reg);
+       return true;
+}
index 98c81be..77004ce 100644 (file)
@@ -47,6 +47,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        void event_callback(int event_id, int err);
        void write_signal(int id, uint32_t data, uint32_t mask);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_cpu(DEVICE* device)
index f4f1ecd..5e8839a 100644 (file)
@@ -129,3 +129,20 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(in);
+       state_fio->StateBool(out);
+       state_fio->StateBool(remote);
+       state_fio->StateBool(eot);
+       state_fio->StateUint8(pout);
+       state_fio->StateBool(strobe);
+       state_fio->StateBool(busy);
+       return true;
+}
index 7518343..37bfc6d 100644 (file)
@@ -384,3 +384,27 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       state_fio->StateBool(inserted);
+       return true;
+}
index 5b1066f..7b8b84a 100644 (file)
@@ -88,3 +88,14 @@ bool JOYSTICK::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool JOYSTICK::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(select);
+       return true;
+}
index 970ba28..4fec3b3 100644 (file)
@@ -116,3 +116,15 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+//     state_fio->StateBool(break_pressed);
+       return true;
+}
index d9f9292..4295819 100644 (file)
@@ -171,26 +171,16 @@ uint32_t SLOT0::read_data8(uint32_t addr)
 
 #define SLOT0_STATE_VERSION    1
 
-void SLOT0::save_state(FILEIO* state_fio)
+bool SLOT0::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(SLOT0_STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-#if defined(_PX7)
-       state_fio->Fwrite(ram, sizeof(ram), 1);
-#endif
-}
-
-bool SLOT0::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != SLOT0_STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(SLOT0_STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
 #if defined(_PX7)
-       state_fio->Fread(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
 #endif
        return true;
 }
@@ -257,42 +247,33 @@ void SLOT1::close_cart()
 
 #define SLOT1_STATE_VERSION    1
 
-void SLOT1::save_state(FILEIO* state_fio)
-{
-       state_fio->FputUint32(SLOT1_STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputBool(inserted);
-#if defined(_MSX2)
-       state_fio->Fwrite(mapper, sizeof(mapper), 1);
-#endif
-}
-
-bool SLOT1::load_state(FILEIO* state_fio)
+bool SLOT1::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != SLOT1_STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(SLOT1_STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       inserted = state_fio->FgetBool();
+       state_fio->StateBool(inserted);
 #if defined(_MSX2)
-       state_fio->Fread(mapper, sizeof(mapper), 1);
+       state_fio->StateBuffer(mapper, sizeof(mapper), 1);
 #endif
        
        // post process
-       if(inserted) {
-               SET_BANK(0x0000, 0xffff, wdmy, rom);
+       if(loading) {
+               if(inserted) {
+                       SET_BANK(0x0000, 0xffff, wdmy, rom);
 #if defined(_MSX2)
-       } else if(mapper[0] < 4) {
-                       SET_BANK(0x0000, 0x3fff, wdmy, rdmy);
-                       SET_BANK(0x4000, 0x7fff, wdmy, rom + mapper[0] * 0x4000);
-                       SET_BANK(0x8000, 0xbfff, wdmy, rom + mapper[1] * 0x4000);
-                       SET_BANK(0xc000, 0xffff, wdmy, rdmy);
+               } else if(mapper[0] < 4) {
+                               SET_BANK(0x0000, 0x3fff, wdmy, rdmy);
+                               SET_BANK(0x4000, 0x7fff, wdmy, rom + mapper[0] * 0x4000);
+                               SET_BANK(0x8000, 0xbfff, wdmy, rom + mapper[1] * 0x4000);
+                               SET_BANK(0xc000, 0xffff, wdmy, rdmy);
 #endif
-       } else {
-               SET_BANK(0x0000, 0xffff, wdmy, rdmy);
+               } else {
+                       SET_BANK(0x0000, 0xffff, wdmy, rdmy);
+               }
        }
        return true;
 }
@@ -405,37 +386,22 @@ void SLOT2::event_callback(int event_id, int err)
 
 #define SLOT2_STATE_VERSION    1
 
-void SLOT2::save_state(FILEIO* state_fio)
+bool SLOT2::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(SLOT2_STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputBool(clock);
-       state_fio->FputBool(exv);
-       state_fio->FputBool(ack);
-       state_fio->FputBool(super_impose);
-       state_fio->FputBool(req_intr);
-       state_fio->FputBool(pc4);
-       state_fio->FputBool(mute_l);
-       state_fio->FputBool(mute_r);
-}
-
-bool SLOT2::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != SLOT2_STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(SLOT2_STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       clock = state_fio->FgetBool();
-       exv = state_fio->FgetBool();
-       ack = state_fio->FgetBool();
-       super_impose = state_fio->FgetBool();
-       req_intr = state_fio->FgetBool();
-       pc4 = state_fio->FgetBool();
-       mute_l = state_fio->FgetBool();
-       mute_r = state_fio->FgetBool();
+       state_fio->StateBool(clock);
+       state_fio->StateBool(exv);
+       state_fio->StateBool(ack);
+       state_fio->StateBool(super_impose);
+       state_fio->StateBool(req_intr);
+       state_fio->StateBool(pc4);
+       state_fio->StateBool(mute_l);
+       state_fio->StateBool(mute_r);
        return true;
 }
 #else
@@ -546,36 +512,28 @@ void SLOT3::close_cart()
 
 #define SLOT3_STATE_VERSION    1
 
-void SLOT3::save_state(FILEIO* state_fio)
+bool SLOT3::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(SLOT3_STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->Fwrite(ram, sizeof(ram), 1);
-       state_fio->FputBool(inserted);
-       state_fio->Fwrite(mapper, sizeof(mapper), 1);
-}
-
-bool SLOT3::load_state(FILEIO* state_fio)
-{
-       if(state_fio->FgetUint32() != SLOT3_STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(SLOT3_STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       state_fio->Fread(ram, sizeof(ram), 1);
-       inserted = state_fio->FgetBool();
-       state_fio->Fread(mapper, sizeof(mapper), 1);
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBool(inserted);
+       state_fio->StateBuffer(mapper, sizeof(mapper), 1);
        
        // post process
-       if(inserted) {
-               SET_BANK(0x0000, 0xffff, wdmy, rom);
-       } else {
-               SET_BANK(0x0000, 0x3fff, ram + mapper[0] * 0x4000, ram + mapper[0] * 0x4000);
-               SET_BANK(0x4000, 0x7fff, ram + mapper[1] * 0x4000, ram + mapper[1] * 0x4000);
-               SET_BANK(0x8000, 0xbfff, ram + mapper[2] * 0x4000, ram + mapper[2] * 0x4000);
-               SET_BANK(0xc000, 0xffff, ram + mapper[3] * 0x4000, ram + mapper[3] * 0x4000);
+       if(loading) {
+               if(inserted) {
+                       SET_BANK(0x0000, 0xffff, wdmy, rom);
+               } else {
+                       SET_BANK(0x0000, 0x3fff, ram + mapper[0] * 0x4000, ram + mapper[0] * 0x4000);
+                       SET_BANK(0x4000, 0x7fff, ram + mapper[1] * 0x4000, ram + mapper[1] * 0x4000);
+                       SET_BANK(0x8000, 0xbfff, ram + mapper[2] * 0x4000, ram + mapper[2] * 0x4000);
+                       SET_BANK(0xc000, 0xffff, ram + mapper[3] * 0x4000, ram + mapper[3] * 0x4000);
+               }
        }
        return true;
 }
@@ -975,38 +933,136 @@ bool MEMORY::is_disk_protected(int drv)
 
 #define STATE_VERSION  1
 
-void MEMORY::save_state(FILEIO* state_fio)
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
 #if !defined(_PX7)
        for(int i = 0; i < MAX_DRIVE; i++) {
-               disk[i]->save_state(state_fio);
+               if(!disk[i]->process_state(state_fio, loading)) {
+                       return false;
+               }
        }
 #endif
-       state_fio->FputUint32(slot_select);
+       state_fio->StateUint32(slot_select);
+       
+       // post process
+       if(loading) {
+               update_map(slot_select);
+       }
+       return true;
 }
 
-bool MEMORY::load_state(FILEIO* state_fio)
+bool SLOT0::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(SLOT0_STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(_PX7)
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+#endif
+       return true;
+}
+bool SLOT1::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT1_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(inserted);
+#if defined(_MSX2)
+       state_fio->StateBuffer(mapper, sizeof(mapper), 1);
+#endif
+       
+       // post process
+       if(loading) {
+               if(inserted) {
+                       SET_BANK(0x0000, 0xffff, wdmy, rom);
+#if defined(_MSX2)
+               } else if(mapper[0] < 4) {
+                               SET_BANK(0x0000, 0x3fff, wdmy, rdmy);
+                               SET_BANK(0x4000, 0x7fff, wdmy, rom + mapper[0] * 0x4000);
+                               SET_BANK(0x8000, 0xbfff, wdmy, rom + mapper[1] * 0x4000);
+                               SET_BANK(0xc000, 0xffff, wdmy, rdmy);
+#endif
+               } else {
+                       SET_BANK(0x0000, 0xffff, wdmy, rdmy);
+               }
+       }
+       return true;
+}
+bool SLOT2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT2_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(clock);
+       state_fio->StateBool(exv);
+       state_fio->StateBool(ack);
+       state_fio->StateBool(super_impose);
+       state_fio->StateBool(req_intr);
+       state_fio->StateBool(pc4);
+       state_fio->StateBool(mute_l);
+       state_fio->StateBool(mute_r);
+       return true;
+}
+bool SLOT3::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT3_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBool(inserted);
+       state_fio->StateBuffer(mapper, sizeof(mapper), 1);
+       
+       // post process
+       if(loading) {
+               if(inserted) {
+                       SET_BANK(0x0000, 0xffff, wdmy, rom);
+               } else {
+                       SET_BANK(0x0000, 0x3fff, ram + mapper[0] * 0x4000, ram + mapper[0] * 0x4000);
+                       SET_BANK(0x4000, 0x7fff, ram + mapper[1] * 0x4000, ram + mapper[1] * 0x4000);
+                       SET_BANK(0x8000, 0xbfff, ram + mapper[2] * 0x4000, ram + mapper[2] * 0x4000);
+                       SET_BANK(0xc000, 0xffff, ram + mapper[3] * 0x4000, ram + mapper[3] * 0x4000);
+               }
+       }
+       return true;
+}
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
 #if !defined(_PX7)
        for(int i = 0; i < MAX_DRIVE; i++) {
-               if(!disk[i]->load_state(state_fio)) {
+               if(!disk[i]->process_state(state_fio, loading)) {
                        return false;
                }
        }
 #endif
-       slot_select = state_fio->FgetUint32();
+       state_fio->StateUint32(slot_select);
        
        // post process
-       update_map(slot_select);
+       if(loading) {
+               update_map(slot_select);
+       }
        return true;
 }
-
index ccf2f92..c5ba414 100644 (file)
@@ -53,8 +53,7 @@ public:
        void initialize();
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(uint32_t addr);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
 };
 
 // slot #1
@@ -83,8 +82,7 @@ public:
        void initialize();
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(uint32_t addr);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void open_cart(const _TCHAR *file_path);
@@ -129,8 +127,7 @@ public:
        uint32_t read_data8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
        void event_callback(int event_id, int err);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_cpu(DEVICE* device)
@@ -196,8 +193,7 @@ public:
        void write_data8(uint32_t addr, uint32_t data);
        uint32_t read_data8(uint32_t addr);
        void write_io8(uint32_t addr, uint32_t data);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void open_cart(const _TCHAR *file_path);
@@ -244,8 +240,7 @@ public:
        uint32_t read_signal(int id);
        bool bios_ret_z80(uint16_t PC, pair_t* af, pair_t* bc, pair_t* de, pair_t* hl, pair_t* ix, pair_t* iy, uint8_t* iff1);
 #endif
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_slot(int drv, DEVICE *device)
index 160c919..304069d 100644 (file)
@@ -1667,3 +1667,168 @@ bool MEMORY_EX::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SLOT_MAINROM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT_MAINROM_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#ifdef MAINROM_PLUS_RAM_32K
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+#endif
+       return true;
+}
+bool SLOT_CART::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT_CART_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(inserted);
+#ifdef USE_MEGAROM
+       state_fio->StateInt32(type);
+       state_fio->StateBool(bank_scc);
+       /* Todo: MEGA ROM bank select */
+       /* is this OK? */
+       if(loading) {
+               if(inserted) {
+                       SET_BANK(0x0000, 0xffff, wdmy, rom);
+                       int i32;
+                       i32 = state_fio->FgetInt32_LE() ; rbank[0] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[1] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[2] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[3] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[4] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[5] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[6] = ((i32 == -1) ? rdmy : rom + i32);
+                       i32 = state_fio->FgetInt32_LE() ; rbank[7] = ((i32 == -1) ? rdmy : rom + i32);
+               } else {
+                       SET_BANK(0x0000, 0xffff, wdmy, rdmy);
+               }
+       } else {
+               if(inserted) {
+                       state_fio->FputInt32_LE(rbank[0]==rdmy ? (-1) : rbank[0] - rom);
+                       state_fio->FputInt32_LE(rbank[1]==rdmy ? (-1) : rbank[1] - rom);
+                       state_fio->FputInt32_LE(rbank[2]==rdmy ? (-1) : rbank[2] - rom);
+                       state_fio->FputInt32_LE(rbank[3]==rdmy ? (-1) : rbank[3] - rom);
+                       state_fio->FputInt32_LE(rbank[4]==rdmy ? (-1) : rbank[4] - rom);
+                       state_fio->FputInt32_LE(rbank[5]==rdmy ? (-1) : rbank[5] - rom);
+                       state_fio->FputInt32_LE(rbank[6]==rdmy ? (-1) : rbank[6] - rom);
+                       state_fio->FputInt32_LE(rbank[7]==rdmy ? (-1) : rbank[7] - rom);
+               }
+       }
+#else
+       // post process
+       if(loading) {
+               if(inserted) {
+                       SET_BANK(0x0000, 0xffff, wdmy, rom);
+               } else {
+                       SET_BANK(0x0000, 0xffff, wdmy, rdmy);
+               }
+       }
+#endif
+       return true;
+}
+bool SLOT_MSXDOS2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT_MSXDOS2_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(mapper, sizeof(mapper), 1);
+       
+       // post process
+       if(loading) {
+               if(mapper[0] < 4) {
+                               SET_BANK(0x0000, 0x3fff, wdmy, rdmy);
+                               SET_BANK(0x4000, 0x7fff, wdmy, rom + mapper[0] * 0x4000);
+                               SET_BANK(0x8000, 0xbfff, wdmy, rom + mapper[1] * 0x4000);
+                               SET_BANK(0xc000, 0xffff, wdmy, rdmy);
+               } else {
+                       SET_BANK(0x0000, 0xffff, wdmy, rdmy);
+               }
+       }
+       return true;
+}
+bool SLOT_LDC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT_LDC_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(clock);
+       state_fio->StateBool(exv);
+       state_fio->StateBool(ack);
+       state_fio->StateBool(super_impose);
+       state_fio->StateBool(req_intr);
+       state_fio->StateBool(pc4);
+       state_fio->StateBool(mute_l);
+       state_fio->StateBool(mute_r);
+       return true;
+}
+bool SLOT_MAPPERRAM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT_MAPPERRAM_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(mapper, sizeof(mapper), 1);
+       
+       // post process
+       if(loading) {
+               SET_BANK(0x0000, 0x3fff, ram + mapper[0] * 0x4000, ram + mapper[0] * 0x4000);
+               SET_BANK(0x4000, 0x7fff, ram + mapper[1] * 0x4000, ram + mapper[1] * 0x4000);
+               SET_BANK(0x8000, 0xbfff, ram + mapper[2] * 0x4000, ram + mapper[2] * 0x4000);
+               SET_BANK(0xc000, 0xffff, ram + mapper[3] * 0x4000, ram + mapper[3] * 0x4000);
+       }
+       return true;
+}
+bool SLOT_RAM64K::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(SLOT_RAM64K_STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
+bool MEMORY_EX::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(FDD_PATCH_SLOT)
+       for(int i = 0; i < MAX_DRIVE; i++) {
+               if(!disk[i]->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+#endif
+       state_fio->StateUint8(psl);
+       state_fio->StateUint8(ssl[0]);
+       state_fio->StateUint8(ssl[1]);
+       state_fio->StateUint8(ssl[2]);
+       state_fio->StateUint8(ssl[3]);
+       
+       // post process
+       if(loading) {
+               update_map(psl);
+       }
+       return true;
+}
index e504736..cbcc069 100644 (file)
@@ -487,3 +487,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index e0f22d8..88e48ad 100644 (file)
@@ -228,8 +228,7 @@ public:
        bool is_frame_skippable();
        
        void update_config();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index e85bad8..0b6ce12 100644 (file)
@@ -688,3 +688,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 4212ea5..43c193f 100644 (file)
@@ -71,3 +71,14 @@ bool RTCIF::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RTCIF::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(adrs);
+       return true;
+}
index ef9be3f..c5947dc 100644 (file)
@@ -665,3 +665,14 @@ void SCC::save_load_state(FILEIO* state_fio, bool is_save)
        return;
 }
 
+bool SCC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       save_load_state(state_fio, !loading);
+       return true;
+}
index b3030a3..f988c88 100644 (file)
@@ -185,3 +185,49 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(remote);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(rec) {
+                       fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(fio->IsOpened()) {
+                                       fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(rec && fio->IsOpened()) {
+                       int length_tmp = (int)fio->Ftell();
+                       fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(bufcnt);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+       return true;
+}
index 6741ae9..12402a5 100644 (file)
@@ -382,3 +382,24 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(pal, sizeof(pal), 1);
+       state_fio->StateBool(text_wide);
+       state_fio->StateBool(text_color);
+       state_fio->StateUint8(graph_color);
+       state_fio->StateUint8(graph_page);
+       state_fio->StateUint16(cursor);
+       state_fio->StateUint16(cblink);
+       state_fio->StateBool(hsync);
+       state_fio->StateBool(vsync);
+       state_fio->StateBool(display);
+       state_fio->StateBool(blink);
+       return true;
+}
index 448a8dd..c68c898 100644 (file)
@@ -87,3 +87,14 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(drq);
+       return true;
+}
index 5ff66e5..329dc55 100644 (file)
@@ -94,3 +94,14 @@ bool KANJI::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KANJI::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(ptr);
+       return true;
+}
index 7012101..9f800eb 100644 (file)
@@ -312,3 +312,23 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(init);
+       state_fio->StateUint8(code);
+       state_fio->StateUint8(code_prev);
+       state_fio->StateUint8(stat);
+       state_fio->StateBool(caps);
+       state_fio->StateBool(caps_prev);
+       state_fio->StateBool(graph);
+       state_fio->StateBool(graph_prev);
+       state_fio->StateBool(kana);
+       state_fio->StateBool(kana_prev);
+       return true;
+}
index d3fea19..9771724 100644 (file)
@@ -195,3 +195,23 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram0, sizeof(ram0), 1);
+       state_fio->StateBuffer(ram1, sizeof(ram1), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateUint8(map1);
+       state_fio->StateUint8(map2);
+       
+       // post process
+       if(loading) {
+               update_map();
+       }
+       return true;
+}
index 98ff6c7..1dc54ec 100644 (file)
@@ -371,3 +371,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index ade1294..8511420 100644 (file)
@@ -267,3 +267,19 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(chr);
+       state_fio->StateBool(wide);
+       state_fio->StateUint16(cursor);
+       state_fio->StateUint16(cblink);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateUint16(vram_addr);
+       return true;
+}
index d85acda..219b848 100644 (file)
@@ -271,3 +271,19 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(key_code);
+       state_fio->StateBool(kana);
+       state_fio->StateInt32(event_cnt);
+       return true;
+}
index 68b777a..ea56830 100644 (file)
@@ -156,3 +156,21 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint32(addr_mask);
+       state_fio->StateBool(rom_sel);
+       
+       // post process
+       if(loading) {
+               update_memory_map();
+       }
+       return true;
+}
index ab71f33..fe2f236 100644 (file)
@@ -414,3 +414,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 72b34b2..1f70578 100644 (file)
@@ -406,3 +406,30 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(pa);
+       state_fio->StateUint8(pc);
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(now_play);
+       state_fio->StateBool(now_rewind);
+       state_fio->StateInt32(register_id_frew);
+       state_fio->StateInt32(register_id_ffwd);
+       state_fio->StateInt32(register_id_fwd);
+       state_fio->StateInt32(register_id_stop);
+       state_fio->StateInt32(register_id_eject);
+#ifndef _MZ80B
+       state_fio->StateInt32(register_id_apss);
+       state_fio->StateBool(now_apss);
+       state_fio->StateBool(now_apss_tmp);
+#endif
+       state_fio->StateInt32(register_id_ipl);
+       return true;
+}
index 64ce95f..ab0cb61 100644 (file)
@@ -1892,3 +1892,67 @@ bool CRTC::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CRTC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(scan_line);
+       state_fio->StateBool(scan_tmp);
+       state_fio->StateBool(monitor_200line);
+       state_fio->StateBool(monitor_digital);
+       state_fio->StateBool(monitor_tmp);
+       state_fio->StateUint8(textreg_num);
+       state_fio->StateBuffer(textreg, sizeof(textreg), 1);
+       state_fio->StateUint8(cgreg_num);
+       state_fio->StateBuffer(cgreg, sizeof(cgreg), 1);
+       state_fio->StateUint8(scrn_size);
+       state_fio->StateUint8(cg_mask);
+       state_fio->StateUint8(cg_mask256);
+       state_fio->StateBool(cg_mask256_init);
+       state_fio->StateBool(font_size);
+       state_fio->StateBool(column_size);
+       state_fio->StateBuffer(latch, sizeof(latch), 1);
+       state_fio->StateUint16(GDEVS);
+       state_fio->StateUint16(GDEVE);
+       state_fio->StateUint8(GDEHS);
+       state_fio->StateUint8(GDEHE);
+       state_fio->StateInt32(GDEHSC);
+       state_fio->StateInt32(GDEHEC);
+       state_fio->StateBool(hblank);
+       state_fio->StateBool(vblank);
+       state_fio->StateBool(blink);
+       state_fio->StateUint8(clear_flag);
+       state_fio->StateBuffer(palette_reg, sizeof(palette_reg), 1);
+       state_fio->StateBool(pal_select);
+       state_fio->StateBool(screen_mask);
+       state_fio->StateBuffer(priority16, sizeof(priority16), 1);
+       state_fio->StateBuffer(palette16, sizeof(palette16), 1);
+       state_fio->StateBuffer(palette4096, sizeof(palette4096), 1);
+       state_fio->StateBuffer(palette4096r, sizeof(palette4096r), 1);
+       state_fio->StateBuffer(palette4096g, sizeof(palette4096g), 1);
+       state_fio->StateBuffer(palette4096b, sizeof(palette4096b), 1);
+       state_fio->StateBuffer(palette16txt, sizeof(palette16txt), 1);
+       state_fio->StateBuffer(palette4096txt, sizeof(palette4096txt), 1);
+       state_fio->StateBuffer(palette16pri, sizeof(palette16pri), 1);
+       state_fio->StateBuffer(palette4096pri, sizeof(palette4096pri), 1);
+       state_fio->StateUint8(prev16);
+       state_fio->StateBool(update16);
+       state_fio->StateBuffer(priority256, sizeof(priority256), 1);
+       state_fio->StateBuffer(palette256, sizeof(palette256), 1);
+       state_fio->StateBuffer(palette256txt, sizeof(palette256txt), 1);
+       state_fio->StateBuffer(palette256pri, sizeof(palette256pri), 1);
+       state_fio->StateUint32((uint32_t)prev256);
+       state_fio->StateBool(update256);
+       state_fio->StateBuffer(map_addr, sizeof(map_addr), 1);
+       state_fio->StateBuffer(map_hdsc, sizeof(map_hdsc), 1);
+       state_fio->StateBuffer(text_matrix, sizeof(text_matrix), 1);
+       state_fio->StateBuffer(text_matrixw, sizeof(text_matrixw), 1);
+       state_fio->StateUint8(trans_color);
+       state_fio->StateBool(map_init);
+       state_fio->StateBool(trans_init);
+       return true;
+}
index f995a0c..a89eac8 100644 (file)
@@ -91,3 +91,14 @@ bool FLOPPY::load_state(FILEIO* state_fio)
 }
 #endif
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(reversed);
+       return true;
+}
index 3c89657..438c10d 100644 (file)
@@ -234,3 +234,19 @@ bool INTERRUPT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool INTERRUPT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(select);
+       state_fio->StateBuffer(irq, sizeof(irq), 1);
+       state_fio->StateInt32(req_intr_ch);
+       state_fio->StateBool(iei);
+       state_fio->StateBool(oei);
+       state_fio->StateUint32(intr_bit);
+       return true;
+}
index f794c6c..4e84cf8 100644 (file)
@@ -94,3 +94,14 @@ bool JOYSTICK::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool JOYSTICK::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(mode);
+       return true;
+}
index 110b2d1..e793e45 100644 (file)
@@ -116,3 +116,14 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       return true;
+}
index 708543a..4d486a7 100644 (file)
@@ -412,3 +412,35 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(tvram, sizeof(tvram), 1);
+       state_fio->StateBuffer(pcg, sizeof(pcg), 1);
+       state_fio->StateUint8(bank);
+       state_fio->StateBuffer(page, sizeof(page), 1);
+       state_fio->StateUint8(dic_bank);
+       state_fio->StateUint8(kanji_bank);
+       state_fio->StateBool(blank);
+       state_fio->StateBool(hblank);
+       state_fio->StateBool(vblank);
+       state_fio->StateBool(busreq);
+       
+       // post process
+       if(loading) {
+               uint8_t bank_tmp = bank;
+               bank = 0;
+               for(int i = 0; i < 8; i++) {
+                       set_map(page[i]);
+               }
+               bank = bank_tmp;
+       }
+       return true;
+}
index 9449705..4b88c8e 100644 (file)
@@ -728,3 +728,46 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(tvram, sizeof(tvram), 1);
+       state_fio->StateBool(ipl_selected);
+       state_fio->StateUint8(vram_sel);
+       state_fio->StateUint8(vram_page);
+       state_fio->StateUint8(back_color);
+       state_fio->StateUint8(text_color);
+       state_fio->StateUint8(vram_mask);
+       state_fio->StateBool(width80);
+       state_fio->StateBool(reverse);
+       state_fio->StateBool(vgate);
+       state_fio->StateBool(hblank);
+#ifdef _MZ80B
+       state_fio->StateBuffer(pio3039_palette, sizeof(pio3039_palette), 1);
+       state_fio->StateBool(pio3039_txt_sw);
+       state_fio->StateUint8(pio3039_data);
+#endif
+       
+       // post process
+       if(loading) {
+               if(ipl_selected) {
+                       SET_BANK(0x0000, 0x07ff, wdmy, ipl, false);
+                       SET_BANK(0x0800, 0x7fff, wdmy, rdmy, false);
+                       SET_BANK(0x8000, 0xffff, ram, ram, false);
+               } else {
+                       SET_BANK(0x0000, 0xffff, ram, ram, false);
+               }
+               update_vram_map();
+#ifndef _MZ80B
+               update_green_palette();
+#endif
+       }
+       return true;
+}
index dfe4492..43ecfae 100644 (file)
@@ -80,3 +80,14 @@ bool MOUSE::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MOUSE::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(select);
+       return true;
+}
index 7f62b93..9e02d9e 100644 (file)
@@ -189,3 +189,16 @@ bool MZ1E30::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MZ1E30::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(rom_address);
+       state_fio->StateBool(irq_status);
+       state_fio->StateBool(drq_status);
+       return true;
+}
index ad42269..c408a7c 100644 (file)
@@ -157,3 +157,15 @@ bool MZ1M01::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MZ1M01::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(port, sizeof(port), 1);
+       return true;
+}
index c269c5c..15d7a35 100644 (file)
@@ -127,3 +127,17 @@ bool MZ1R12::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MZ1R12::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(sram, sizeof(sram), 1);
+       state_fio->StateBool(read_only);
+       state_fio->StateUint16(address);
+       state_fio->StateUint32(crc32);
+       return true;
+}
index 311a0f6..33e9821 100644 (file)
@@ -116,3 +116,15 @@ bool MZ1R13::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MZ1R13::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint16(address);
+       state_fio->StateBool(select_kanji);
+       return true;
+}
index a919448..974091c 100644 (file)
@@ -100,3 +100,15 @@ bool MZ1R37::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MZ1R37::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(buffer, EMM_SIZE, 1);
+       state_fio->StateUint32(address);
+       return true;
+}
index 11f5c30..7c0657f 100644 (file)
@@ -632,3 +632,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateInt32(monitor_type);
+       return true;
+}
index e1a5a2a..7ab781f 100644 (file)
@@ -600,3 +600,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 9d4a842..c03eff3 100644 (file)
@@ -110,3 +110,14 @@ bool SERIAL::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SERIAL::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(addr_a0);
+       return true;
+}
index b74ee90..c8c57a8 100644 (file)
@@ -1487,3 +1487,57 @@ bool CRTC::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CRTC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(textreg_num);
+       state_fio->StateBuffer(textreg, sizeof(textreg), 1);
+       state_fio->StateBuffer(rmwreg_num, sizeof(rmwreg_num), 1);
+       state_fio->StateBuffer(rmwreg, sizeof(rmwreg), 1);
+       state_fio->StateUint8(cgreg_num);
+       state_fio->StateBuffer(cgreg, sizeof(cgreg), 1);
+       state_fio->StateUint8(scrn_size);
+       state_fio->StateUint8(cg_mask);
+       state_fio->StateBool(font_size);
+       state_fio->StateBool(column_size);
+       state_fio->StateBuffer(latch, sizeof(latch), 1);
+       state_fio->StateUint16(GDEVS);
+       state_fio->StateUint16(GDEVE);
+       state_fio->StateUint8(GDEHS);
+       state_fio->StateUint8(GDEHE);
+       state_fio->StateInt32(GDEHSC);
+       state_fio->StateInt32(GDEHEC);
+       state_fio->StateBool(blank);
+       state_fio->StateBool(hblank);
+       state_fio->StateBool(vblank);
+       state_fio->StateBool(blink);
+       state_fio->StateUint8(clear_flag);
+       state_fio->StateBuffer(palette_reg, sizeof(palette_reg), 1);
+       state_fio->StateBool(pal_select);
+       state_fio->StateBool(screen_mask);
+       state_fio->StateBuffer(priority16, sizeof(priority16), 1);
+       state_fio->StateBuffer(palette16, sizeof(palette16), 1);
+       state_fio->StateBuffer(palette4096, sizeof(palette4096), 1);
+       state_fio->StateBuffer(palette4096r, sizeof(palette4096r), 1);
+       state_fio->StateBuffer(palette4096g, sizeof(palette4096g), 1);
+       state_fio->StateBuffer(palette4096b, sizeof(palette4096b), 1);
+       state_fio->StateBuffer(palette16txt, sizeof(palette16txt), 1);
+       state_fio->StateBuffer(palette4096txt, sizeof(palette4096txt), 1);
+       state_fio->StateBuffer(palette16pri, sizeof(palette16pri), 1);
+       state_fio->StateBuffer(palette4096pri, sizeof(palette4096pri), 1);
+       state_fio->StateUint8(prev16);
+       state_fio->StateBool(update16);
+       state_fio->StateBuffer(map_addr, sizeof(map_addr), 1);
+       state_fio->StateBuffer(map_hdsc, sizeof(map_hdsc), 1);
+       state_fio->StateBuffer(text_matrix, sizeof(text_matrix), 1);
+       state_fio->StateBuffer(text_matrixw, sizeof(text_matrixw), 1);
+       state_fio->StateUint8(trans_color);
+       state_fio->StateBool(map_init);
+       state_fio->StateBool(trans_init);
+       return true;
+}
index d8b9912..ba05564 100644 (file)
@@ -94,3 +94,14 @@ bool JOYSTICK::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool JOYSTICK::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(mode);
+       return true;
+}
index 13d49b2..6a2fd09 100644 (file)
@@ -128,3 +128,14 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       return true;
+}
index d520cd3..e4e87b4 100644 (file)
@@ -264,3 +264,46 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(tvram, sizeof(tvram), 1);
+       state_fio->StateBuffer(pcg, sizeof(pcg), 1);
+       state_fio->StateUint32(mem_window);
+       state_fio->StateUint8(vram_bank);
+       state_fio->StateUint8(dic_bank);
+       state_fio->StateUint8(kanji_bank);
+       
+       // post process
+       if(loading) {
+               if(vram_bank == 4) {
+                       SET_BANK(0x0c0000, 0x0dffff, vram + 0x00000, vram + 0x00000);
+               } else if(vram_bank == 5) {
+                       SET_BANK(0x0c0000, 0x0dffff, vram + 0x20000, vram + 0x20000);
+               } else if(vram_bank == 6) {
+                       SET_BANK(0x0c0000, 0x0dffff, vram + 0x40000, vram + 0x40000);
+               } else if(vram_bank == 7) {
+                       SET_BANK(0x0c0000, 0x0dffff, vram + 0x60000, vram + 0x60000);
+               } else {
+                       SET_BANK(0x0c0000, 0x0dffff, vram + 0x00000, vram + 0x00000);
+               }
+               SET_BANK(0x0e0000, 0x0effff, wdmy, dic + ((dic_bank & 0x18) >> 3) * 0x10000);
+               if(kanji_bank & 0x80) {
+                       SET_BANK(0x0f0000, 0x0f0fff, wdmy, kanji + 0x1000 * (kanji_bank & 0x7f));
+               } else {
+                       SET_BANK(0x0f0000, 0x0f0fff, pcg, pcg);
+               }
+               SET_BANK(0x0f1000, 0x0f3fff, pcg + 0x1000, pcg + 0x1000);
+               SET_BANK(0x0f4000, 0x0f5fff, tvram, tvram);
+               SET_BANK(0x0f6000, 0x0f7fff, tvram, tvram);
+       }
+       return true;
+}
index 6ad09f6..0309f5e 100644 (file)
@@ -82,3 +82,14 @@ bool MOUSE::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MOUSE::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(select);
+       return true;
+}
index a37023c..2f8b54f 100644 (file)
@@ -496,3 +496,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 36ca2ec..65ad7e0 100644 (file)
@@ -69,3 +69,14 @@ bool RESET::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RESET::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(prev);
+       return true;
+}
index e501636..46e0828 100644 (file)
@@ -123,27 +123,30 @@ void SASI::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  2
 
-void SASI::save_state(FILEIO* state_fio)
+bool SASI::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->FputUint8(control);
-       state_fio->FputBool(irq_status);
-       state_fio->FputBool(drq_status);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(control);
+       state_fio->StateBool(irq_status);
+       state_fio->StateBool(drq_status);
+       return true;
 }
 
-bool SASI::load_state(FILEIO* state_fio)
+bool SASI::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       control = state_fio->FgetUint8();
-       irq_status = state_fio->FgetBool();
-       drq_status = state_fio->FgetBool();
+       state_fio->StateUint8(control);
+       state_fio->StateBool(irq_status);
+       state_fio->StateBool(drq_status);
        return true;
 }
-
index c2461f6..93e8cc8 100644 (file)
@@ -42,8 +42,7 @@ public:
        void write_dma_io8(uint32_t addr, uint32_t data);
        uint32_t read_dma_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique function
        void set_context_host(DEVICE* device)
index 663df6a..d20566f 100644 (file)
@@ -110,3 +110,14 @@ bool SERIAL::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SERIAL::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(addr_a0);
+       return true;
+}
index 9db94a3..f75ec30 100644 (file)
@@ -535,3 +535,26 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(phase);
+       state_fio->StateUint16(send_data);
+       state_fio->StateUint32(stc_clock);
+       state_fio->StateUint8(recv_data);
+       state_fio->StateBool(recv_ok);
+       state_fio->StateBool(stc);
+       state_fio->StateBool(dc);
+       state_fio->StateBool(caps);
+       state_fio->StateBool(kana);
+       state_fio->StateBool(pro_mode);
+       return true;
+}
index b36fe99..23c610e 100644 (file)
@@ -504,3 +504,42 @@ bool MAIN::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MAIN::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(common, sizeof(common), 1);
+       state_fio->StateUint8(ma);
+       state_fio->StateUint8(ms);
+       state_fio->StateUint8(mo);
+       state_fio->StateBool(me1);
+       state_fio->StateBool(me2);
+       state_fio->StateUint8(srqb);
+       state_fio->StateUint8(sres);
+       state_fio->StateBool(sack);
+       state_fio->StateBool(srdy);
+       state_fio->StateBool(intfd);
+       state_fio->StateBool(int0);
+       state_fio->StateBool(int1);
+       state_fio->StateBool(int2);
+       state_fio->StateBool(int3);
+       state_fio->StateBool(int4);
+       state_fio->StateBool(me);
+       state_fio->StateBool(e1);
+       state_fio->StateUint8(inp);
+       state_fio->StateBool(motor);
+       state_fio->StateBool(drq);
+       state_fio->StateBool(index);
+       state_fio->StateBool(crt_400line);
+       
+       // post process
+       if(loading) {
+                update_bank();
+       }
+       return true;
+}
index f196e45..eab892d 100644 (file)
@@ -511,3 +511,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateUint8(halt);
+       return true;
+}
index b683301..cdc2745 100644 (file)
@@ -625,3 +625,19 @@ bool SUB::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SUB::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram_chr, sizeof(vram_chr), 1);
+       state_fio->StateBuffer(vram_gfx, sizeof(vram_gfx), 1);
+       state_fio->StateBuffer(disp, sizeof(disp), 1);
+       state_fio->StateInt32(cblink);
+       state_fio->StateBool(crt_400line);
+       return true;
+}
index 9437f2f..ca3bca1 100644 (file)
@@ -574,3 +574,25 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+       state_fio->StateBuffer(back, sizeof(back), 1);
+       state_fio->StateBuffer(reverse, sizeof(reverse), 1);
+       state_fio->StateUint8(rno);
+       state_fio->StateBuffer(wregs, sizeof(wregs), 1);
+       state_fio->StateBuffer(pri, sizeof(pri), 1);
+       state_fio->StateBuffer(vma, sizeof(vma), 1);
+       state_fio->StateBuffer(vds, sizeof(vds), 1);
+       state_fio->StateUint8(mode_r);
+       state_fio->StateUint8(mode_c);
+       state_fio->StateUint8(mode_p);
+       return true;
+}
index 1bdea6c..691d1c8 100644 (file)
@@ -547,3 +547,30 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!rsp_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBool(caps);
+       state_fio->StateBool(kana);
+       state_fio->StateBool(graph);
+       state_fio->StateInt32(dk);
+       state_fio->StateInt32(srk);
+       state_fio->StateInt32(dc);
+       state_fio->StateInt32(stc);
+       state_fio->StateInt32(send);
+       state_fio->StateInt32(recv);
+       state_fio->StateInt32(phase);
+       state_fio->StateInt32(timeout);
+       return true;
+}
index 3c5f22d..5741a53 100644 (file)
@@ -255,3 +255,26 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+#if defined(_MZ6500) || defined(_MZ6550)
+       state_fio->StateBuffer(mz1r32, sizeof(mz1r32), 1);
+#endif
+       state_fio->StateUint8(bank1);
+       state_fio->StateUint8(bank2);
+       state_fio->StateUint32(haddr);
+       
+       // post process
+       if(loading) {
+                update_bank();
+               }
+       return true;
+}
index 4192aae..19584b4 100644 (file)
@@ -485,3 +485,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 3cd872b..5aca551 100644 (file)
@@ -113,3 +113,15 @@ bool SYSPORT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SYSPORT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(rst);
+       state_fio->StateInt32(highden);
+       return true;
+}
index 2545bdd..441dc88 100644 (file)
@@ -131,3 +131,16 @@ bool CMOS::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMOS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(data_buffer, DATA_SIZE, 1);
+       state_fio->StateUint32(data_addr);
+       state_fio->StateBool(modified);
+       return true;
+}
index 0f0c396..7906e8a 100644 (file)
@@ -119,3 +119,15 @@ bool EMM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool EMM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(data_buffer, DATA_SIZE, 1);
+       state_fio->StateUint32(data_addr);
+       return true;
+}
index c3bcb92..93069ca 100644 (file)
@@ -146,3 +146,17 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(prev_dc);
+       state_fio->StateInt32(register_id);
+       state_fio->StateBool(motor_on);
+       state_fio->StateBool(irq_enabled);
+       return true;
+}
index cd87567..dea0a9a 100644 (file)
@@ -121,3 +121,16 @@ bool KANJI::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KANJI::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(control_reg);
+       state_fio->StateUint32(kanji_addr);
+       state_fio->StateUint32(dic_addr);
+       return true;
+}
index a83224a..6a1dc2c 100644 (file)
@@ -106,3 +106,14 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       return true;
+}
index 7e925f7..65b5031 100644 (file)
@@ -1267,3 +1267,70 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(_MZ700)
+       state_fio->StateBuffer(pcg + 0x400, 0x400, 1);
+       state_fio->StateBuffer(pcg + 0xc00, 0x400, 1);
+#elif defined(_MZ1500)
+       state_fio->StateBuffer(pcg, sizeof(pcg), 1);
+#endif
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateUint8(mem_bank);
+#if defined(_MZ700)
+       state_fio->StateUint8(pcg_data);
+       state_fio->StateUint8(pcg_addr);
+       state_fio->StateUint8(pcg_ctrl);
+#elif defined(_MZ800)
+       state_fio->StateUint8(wf);
+       state_fio->StateUint8(rf);
+       state_fio->StateUint8(dmd);
+       state_fio->StateUint32(vram_addr_top);
+       state_fio->StateBool(is_mz800);
+#elif defined(_MZ1500)
+       state_fio->StateUint8(pcg_bank);
+#endif
+#if defined(_MZ800)
+       state_fio->StateUint16(sof);
+       state_fio->StateUint8(sw);
+       state_fio->StateUint8(ssa);
+       state_fio->StateUint8(sea);
+       state_fio->StateUint8(palette_sw);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+       state_fio->StateBuffer(palette16, sizeof(palette16), 1);
+#elif defined(_MZ1500)
+       state_fio->StateUint8(priority);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+#endif
+       state_fio->StateBool(blink);
+       state_fio->StateBool(tempo);
+       state_fio->StateBool(hblank);
+       state_fio->StateBool(hsync);
+       state_fio->StateBool(vblank);
+       state_fio->StateBool(vsync);
+#if defined(_MZ700) || defined(_MZ1500)
+       state_fio->StateBool(hblank_vram);
+#endif
+#if defined(_MZ1500)
+       state_fio->StateBool(hblank_pcg);
+#endif
+#if defined(_MZ800)
+       state_fio->StateBuffer(palette_mz800_pc, sizeof(palette_mz800_pc), 1);
+#endif
+       state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+       
+       // post process
+       if(loading) {
+               update_map_low();
+               update_map_middle();
+               update_map_high();
+       }
+       return true;
+}
index d51aa04..7282f95 100644 (file)
@@ -743,3 +743,27 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+#if defined(_MZ800)
+       state_fio->StateInt32(boot_mode);
+#endif
+       return true;
+}
index 5a2e58f..282290d 100644 (file)
@@ -649,3 +649,30 @@ bool QUICKDISK::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool QUICKDISK::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(file_path, sizeof(file_path), 1);
+       state_fio->StateBool(insert);
+       state_fio->StateBool(protect);
+       state_fio->StateBool(home);
+       state_fio->StateBool(modified);
+       state_fio->StateBool(accessed);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+       state_fio->StateInt32(buffer_ptr);
+       state_fio->StateInt32(write_ptr);
+       state_fio->StateBool(first_data);
+       state_fio->StateBool(send_break);
+       state_fio->StateBool(wrga);
+       state_fio->StateBool(mton);
+       state_fio->StateBool(sync);
+       state_fio->StateBool(motor_on);
+       state_fio->StateInt32(restore_id);
+       state_fio->StateInt32(end_id);
+       return true;
+}
index b29ac00..ee3f5d7 100644 (file)
@@ -99,3 +99,15 @@ bool RAMFILE::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RAMFILE::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(data_buffer, DATA_SIZE, 1);
+       state_fio->StateUint32(data_addr);
+       return true;
+}
index f45a37e..4f10cf3 100644 (file)
@@ -166,3 +166,15 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       state_fio->StateBool(kana);
+       return true;
+}
index 36adb2f..2e2f3e9 100644 (file)
@@ -535,3 +535,49 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBool(tempo);
+       state_fio->StateBool(blink);
+#if defined(_MZ1200) || defined(_MZ80A)
+       state_fio->StateBool(hblank);
+       state_fio->StateBool(memory_swap);
+#endif
+#if defined(SUPPORT_MZ80AIF)
+       state_fio->StateBool(fdc_irq);
+       state_fio->StateBool(fdc_drq);
+#endif
+       state_fio->StateBool(vgate);
+#if defined(_MZ1200) || defined(_MZ80A)
+       state_fio->StateBool(reverse);
+#endif
+#if defined(_MZ80A)
+       state_fio->StateUint32(e200);
+#endif
+       state_fio->StateBuffer(pcg + 0x400, 0x400, 1);
+#if defined(_MZ1200)
+       state_fio->StateBuffer(pcg + 0xc00, 0x400, 1);
+#endif
+       state_fio->StateUint8(pcg_data);
+       state_fio->StateUint8(pcg_addr);
+       state_fio->StateUint8(pcg_ctrl);
+       
+       // post process
+       if(loading) {
+#if defined(_MZ1200) || defined(_MZ80A)
+               update_memory_swap();
+#endif
+#if defined(SUPPORT_MZ80AIF)
+               update_fdif_rom_bank();
+#endif
+       }
+       return true;
+}
index dfa4ed1..5a95c4e 100644 (file)
@@ -510,3 +510,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 544d5b4..2346ef4 100644 (file)
@@ -86,3 +86,14 @@ bool PRINTER::load_state(FILEIO* state_fio)
 }
 #endif
 
+bool PRINTER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(out_ch);
+       return true;
+}
index bf8088c..864cfe4 100644 (file)
@@ -424,3 +424,48 @@ void VM::update_config()
        }
 }
 
+#define STATE_VERSION  1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 0ffb614..f53593b 100644 (file)
@@ -148,6 +148,7 @@ public:
        bool is_frame_skippable();
        
        void update_config();
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index e69057d..2f4dd47 100644 (file)
@@ -678,3 +678,16 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(mode);
+       state_fio->StateUint16(cursor);
+       state_fio->StateUint16(cblink);
+       return true;
+}
index 6912048..cf4bd54 100644 (file)
@@ -117,3 +117,15 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(intr);
+       state_fio->StateBool(supported);
+       return true;
+}
index 8bbfda0..119d33f 100644 (file)
@@ -79,3 +79,11 @@ bool KANJIPAC2::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KANJIPAC2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateUint32(ptr);
+       return true;
+}
index 0c22739..256a7c7 100644 (file)
@@ -113,3 +113,14 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(sel);
+       return true;
+}
index 375c644..af1c862 100644 (file)
@@ -202,3 +202,28 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(attr, sizeof(attr), 1);
+       state_fio->StateUint16(vram_ptr);
+       state_fio->StateUint8(vram_data);
+       state_fio->StateUint8(mem_map);
+       
+       // post process
+       if(loading) {
+               if(mem_map & 2) {
+                       SET_BANK(0x0000, 0x7fff, ram, ram);
+               } else {
+                       SET_BANK(0x0000, 0x7fff, ram, rom);
+               }
+       }
+       return true;
+}
index 7eccb06..78082d6 100644 (file)
@@ -134,3 +134,14 @@ bool PAC2::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool PAC2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(device_type);
+       return get_device()->process_state(state_fio, loading);
+}
index c253e4d..3b8e7b1 100644 (file)
@@ -497,3 +497,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateInt32(boot_mode);
+       return true;
+}
index 365a25a..a46ddbd 100644 (file)
@@ -141,3 +141,14 @@ bool RAMPAC2::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RAMPAC2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint32(ptr);
+       state_fio->StateBool(opened);
+       state_fio->StateBool(modified);
+       return true;
+}
index 7903ba5..03db5fc 100644 (file)
@@ -814,3 +814,20 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(mode);
+       state_fio->StateUint8(text_page);
+       state_fio->StateUint16(cursor);
+       state_fio->StateUint16(cblink);
+       state_fio->StateUint16(flash_cnt);
+       state_fio->StateBool(blink);
+       state_fio->StateBool(pal_dis);
+       return true;
+}
index 7072d49..4aafcb1 100644 (file)
@@ -95,3 +95,14 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(intr);
+       return true;
+}
index 89e56ac..27263d3 100644 (file)
@@ -82,3 +82,14 @@ bool IOBUS::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IOBUS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(mio);
+       return true;
+}
index db46bd0..8205fca 100644 (file)
@@ -121,3 +121,15 @@ bool IOTRAP::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IOTRAP::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(nmi_mask);
+       state_fio->StateBool(pasopia);
+       return true;
+}
index dcc4ef6..cc42759 100644 (file)
@@ -82,3 +82,11 @@ bool KANJIPAC2::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KANJIPAC2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateUint32(ptr);
+       return true;
+}
index 73a7dfe..361b69c 100644 (file)
@@ -118,3 +118,14 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(sel);
+       return true;
+}
index 56496c8..c0f2aa9 100644 (file)
@@ -236,3 +236,28 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(pal, sizeof(pal), 1);
+       state_fio->StateUint8(mem_map);
+       state_fio->StateUint8(plane);
+       state_fio->StateUint8(attr_data);
+       state_fio->StateUint8(attr_latch);
+       state_fio->StateBool(vram_sel);
+       state_fio->StateBool(pal_sel);
+       state_fio->StateBool(attr_wrap);
+       
+       // post process
+       if(loading) {
+               update_memory_map();
+       }
+       return true;
+}
index dbf3c87..d174081 100644 (file)
@@ -155,3 +155,23 @@ bool PAC2::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool PAC2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(sel);
+       if(!rampac2[0]->process_state(state_fio, loading)) {
+               return false;
+       }
+       if(!rampac2[1]->process_state(state_fio, loading)) {
+               return false;
+       }
+       if(!kanji->process_state(state_fio, loading)) {
+               return false;
+       }
+       return true;
+}
index 826a5bf..c824d51 100644 (file)
@@ -482,3 +482,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 3d7de9d..ca14437 100644 (file)
@@ -140,3 +140,14 @@ bool RAMPAC2::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool RAMPAC2::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint32(ptr);
+       state_fio->StateBool(opened);
+       state_fio->StateBool(modified);
+       return true;
+}
index 2f1b150..6aca8eb 100644 (file)
@@ -390,3 +390,27 @@ bool CRTC::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CRTC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+       state_fio->StateUint8(sel);
+       state_fio->StateBuffer(regs, sizeof(regs), 1);
+       state_fio->StateUint16(vs);
+       state_fio->StateUint16(cmd);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateUint32(shift);
+       state_fio->StateUint32(maskl);
+       state_fio->StateUint32(maskh);
+       state_fio->StateUint32(busl);
+       state_fio->StateUint32(bush);
+       state_fio->StateUint32(write_plane);
+       state_fio->StateUint32(read_plane);
+       return true;
+}
index 7039ee0..eb5c2d6 100644 (file)
@@ -290,3 +290,25 @@ bool IOCTRL::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IOCTRL::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(caps);
+       state_fio->StateBool(kana);
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint32(key_val);
+       state_fio->StateUint32(key_mouse);
+       state_fio->StateInt32(key_prev);
+       state_fio->StateBool(key_res);
+       state_fio->StateBool(key_done);
+       state_fio->StateInt32(register_id);
+       state_fio->StateUint8(ts);
+       return true;
+}
index a4d0823..2dca822 100644 (file)
@@ -101,3 +101,15 @@ bool KANJI::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KANJI::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint16(ptr);
+       state_fio->StateBool(strobe);
+       return true;
+}
index bcd2c50..ade2c38 100644 (file)
@@ -387,3 +387,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index a21f5d7..5bc182d 100644 (file)
@@ -331,3 +331,19 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(port_a);
+       state_fio->StateUint8(port_b);
+       state_fio->StateUint8(port_s);
+       state_fio->StateBool(drec_in);
+       state_fio->StateBool(rtc_in);
+       state_fio->StateUint16(key_strobe);
+       return true;
+}
index 4de712e..4c97260 100644 (file)
@@ -342,3 +342,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index c7a0c5c..2ae8b7b 100644 (file)
@@ -90,3 +90,18 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(loading) {
+               vram_ptr = ram_ptr + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(vram_ptr - ram_ptr));
+       }
+       return true;
+}
index f598d32..d68eff7 100644 (file)
@@ -703,3 +703,33 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(io_B1H);
+       for(int i = 0; i < 2; i++) {
+               if(!disk[i]->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(cur_trk, sizeof(cur_trk), 1);
+       state_fio->StateBuffer(cur_sct, sizeof(cur_sct), 1);
+       state_fio->StateBuffer(cur_pos, sizeof(cur_pos), 1);
+       state_fio->StateBuffer(access, sizeof(access), 1);
+       state_fio->StateBuffer(Data, sizeof(Data), 1);
+       state_fio->StateBuffer(Index, sizeof(Index), 1);
+       state_fio->StateBuffer(&CmdIn, sizeof(CmdBuffer), 1);
+       state_fio->StateBuffer(&CmdOut, sizeof(CmdBuffer), 1);
+       state_fio->StateUint8(SeekST0);
+       state_fio->StateUint8(LastCylinder);
+       state_fio->StateInt32(SeekEnd);
+       state_fio->StateUint8(SendSectors);
+       state_fio->StateInt32(DIO);
+       state_fio->StateUint8(Status);
+       return true;
+}
index 50a09fa..f78d49a 100644 (file)
@@ -898,3 +898,75 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(RAM, RAM_SIZE, 1);
+       if(loading) {
+               CGROM = MEMORY_BASE + state_fio->FgetInt32_LE();
+               EXTROM1 = MEMORY_BASE + state_fio->FgetInt32_LE();
+               EXTROM2 = MEMORY_BASE + state_fio->FgetInt32_LE();
+               for(int i = 0; i < 8; i++) {
+                       RdMem[i] = MEMORY_BASE + state_fio->FgetInt32_LE();
+                       WrMem[i] = MEMORY_BASE + state_fio->FgetInt32_LE();
+               }
+               VRAM = MEMORY_BASE + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(CGROM - MEMORY_BASE));
+               state_fio->FputInt32_LE((int)(EXTROM1 - MEMORY_BASE));
+               state_fio->FputInt32_LE((int)(EXTROM2 - MEMORY_BASE));
+               for(int i = 0; i < 8; i++) {
+                       state_fio->FputInt32_LE((int)(RdMem[i] - MEMORY_BASE));
+                       state_fio->FputInt32_LE((int)(WrMem[i] - MEMORY_BASE));
+               }
+               state_fio->FputInt32_LE((int)(VRAM - MEMORY_BASE));
+       }
+       state_fio->StateBuffer(EnWrite, sizeof(EnWrite), 1);
+       state_fio->StateUint8(CGSW93);
+       state_fio->StateBool(inserted);
+#ifndef _PC6001
+       state_fio->StateUint8(CRTKILL);
+       if(loading) {
+               CurKANJIROM = MEMORY_BASE + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(CurKANJIROM - MEMORY_BASE));
+       }
+       state_fio->StateUint8(CRTMode1);
+       state_fio->StateUint8(CRTMode2);
+       state_fio->StateUint8(CRTMode3);
+       state_fio->StateUint8(CSS1);
+       state_fio->StateUint8(CSS2);
+       state_fio->StateUint8(CSS3);
+       state_fio->StateUint8(portF0);
+       state_fio->StateUint8(portF1);
+#if defined(_PC6601SR) || defined(_PC6001MK2SR)
+       state_fio->StateInt32(bitmap);
+       state_fio->StateInt32(cols);
+       state_fio->StateInt32(rows);
+       state_fio->StateInt32(lines);
+       if(loading) {
+               TEXTVRAM = MEMORY_BASE + state_fio->FgetInt32_LE();
+               SYSROM2 = MEMORY_BASE + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(TEXTVRAM - MEMORY_BASE));
+               state_fio->FputInt32_LE((int)(SYSROM2 - MEMORY_BASE));
+       }
+       state_fio->StateBuffer(EXTRAM, EXTRAM_SIZE, 1);
+       state_fio->StateBuffer(port60, sizeof(port60), 1);
+       state_fio->StateUint8(portC1);
+       state_fio->StateUint8(portC8);
+       state_fio->StateUint8(portCA);
+       state_fio->StateUint8(portCB);
+       state_fio->StateUint8(portCC);
+       state_fio->StateUint8(portCE);
+       state_fio->StateUint8(portCF);
+       state_fio->StateBuffer(palet, sizeof(palet), 1);
+#endif
+#endif
+       return true;
+}
index 55b22aa..3ff8a0b 100644 (file)
@@ -760,3 +760,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateInt32(sr_mode);
+       return true;
+}
index 07a2d4b..ff46d2f 100644 (file)
@@ -1240,3 +1240,70 @@ bool PSUB::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool PSUB::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       // pre process
+       if(loading) {
+               close_tape();
+       }
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(is_wav);
+       state_fio->StateBool(is_p6t);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(rec) {
+                       fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(fio->IsOpened()) {
+                                       fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(rec && fio->IsOpened()) {
+                       int length_tmp = (int)fio->Ftell();
+                       fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(CasIntFlag);
+       state_fio->StateInt32(CasIndex);
+       state_fio->StateInt32(CasRecv);
+       state_fio->StateInt32(CasMode);
+       state_fio->StateInt32(CasBaud);
+       state_fio->StateInt32(FileBaud);
+       state_fio->StateBuffer(CasData, sizeof(CasData), 1);
+       state_fio->StateInt32(CasLength);
+       state_fio->StateInt32(CasSkipFlag);
+       state_fio->StateInt32(kbFlagFunc);
+       state_fio->StateInt32(kbFlagGraph);
+       state_fio->StateInt32(kbFlagCtrl);
+       state_fio->StateInt32(kanaMode);
+       state_fio->StateInt32(katakana);
+       state_fio->StateInt32(p6key);
+       state_fio->StateInt32(stick0);
+       state_fio->StateInt32(StrigIntFlag);
+       state_fio->StateInt32(StrigEventID);
+       return true;
+}
index 4fba9f2..4d6c425 100644 (file)
@@ -497,3 +497,57 @@ bool SUB::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SUB::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(p1_out);
+       state_fio->StateInt32(p2_in);
+       state_fio->StateBool(drec_in);
+       state_fio->StateBool(rxrdy_in);
+       state_fio->StateBool(update_key);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(is_wav);
+       state_fio->StateBool(is_p6t);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(rec) {
+                       fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(fio->IsOpened()) {
+                                       fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(rec && fio->IsOpened()) {
+                       int length_tmp = (int)fio->Ftell();
+                       fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(prev_command);
+       state_fio->StateInt32(baud);
+       state_fio->StateInt32(index);
+       state_fio->StateBool(skip);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+       return true;
+}
index dad8069..b562dcf 100644 (file)
@@ -363,3 +363,28 @@ bool TIMER::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool TIMER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(IRQ);
+       state_fio->StateUint8(NewIRQ);
+       state_fio->StateInt32(timer_id);
+#ifndef _PC6001
+#if defined(_PC6601SR) || defined(_PC6001MK2SR)
+       state_fio->StateBuffer(sr_vectors, sizeof(sr_vectors), 1);
+       state_fio->StateUint8(portFA);
+       state_fio->StateUint8(portFB);
+#endif
+       state_fio->StateUint8(portF3);
+       state_fio->StateUint8(portF4);
+       state_fio->StateUint8(portF5);
+       state_fio->StateUint8(portF6);
+       state_fio->StateUint8(portF7);
+#endif
+       return true;
+}
index 332ca26..455c548 100644 (file)
@@ -275,3 +275,51 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(is_wav);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(remote);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(rec) {
+                       fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(fio->IsOpened()) {
+                                       fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(rec && fio->IsOpened()) {
+                       int length_tmp = (int)fio->Ftell();
+                       fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(bufcnt);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+       state_fio->StateInt32(prev_signal);
+       state_fio->StateUint32(prev_clock);
+       return true;
+}
index c645d49..4fbe852 100644 (file)
@@ -130,3 +130,16 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint16(column);
+       state_fio->StateBool(caps);
+       state_fio->StateBool(kana);
+       return true;
+}
index 87b6346..b766c30 100644 (file)
@@ -215,3 +215,15 @@ bool LCD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool LCD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(seg, sizeof(seg), 1);
+       state_fio->StateUint16(sel);
+       return true;
+}
index e5635e9..92aecc2 100644 (file)
@@ -194,3 +194,21 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(sio);
+       state_fio->StateUint8(bank);
+       
+       // post process
+       if(loading) {
+               update_bank();
+       }
+       return true;
+}
index 0cb410a..e8ade1e 100644 (file)
@@ -399,3 +399,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 26a1875..40b5911 100644 (file)
@@ -97,3 +97,14 @@ bool CALENDAR::load_state(FILEIO* state_fio)
 }
 #endif
 
+bool CALENDAR::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(ch);
+       return true;
+}
index db86866..1f4fe34 100644 (file)
@@ -114,3 +114,15 @@ bool FLOPPY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool FLOPPY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(ctrlreg);
+       state_fio->StateUint8(modereg);
+       return true;
+}
index 976a5bb..942cb9b 100644 (file)
@@ -119,3 +119,16 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(kana);
+       state_fio->StateBool(caps);
+       state_fio->StateBuffer(flag, sizeof(flag), 1);
+       return true;
+}
index 8433223..f6b845e 100644 (file)
@@ -385,3 +385,40 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(learn, sizeof(learn), 1);
+#ifdef _PC98HA
+       state_fio->StateBuffer(ramdrv, sizeof(ramdrv), 1);
+       state_fio->StateBuffer(ems, sizeof(ems), 1);
+       state_fio->StateBuffer(memcard, sizeof(memcard), 1);
+#endif
+       state_fio->StateUint32(learn_crc32);
+#ifdef _PC98HA
+       state_fio->StateUint32(ramdrv_crc32);
+       state_fio->StateUint32(memcard_crc32);
+#endif
+       state_fio->StateUint8(learn_bank);
+       state_fio->StateUint8(dic_bank);
+       state_fio->StateUint8(kanji_bank);
+       state_fio->StateUint8(romdrv_bank);
+#ifdef _PC98HA
+       state_fio->StateUint8(ramdrv_bank);
+       state_fio->StateUint8(ramdrv_sel);
+       state_fio->StateBuffer(ems_bank, sizeof(ems_bank), 1);
+#endif
+       
+       // post process
+       if(loading) {
+               update_bank();
+       }
+       return true;
+}
index 666f56b..bb48ddf 100644 (file)
@@ -124,3 +124,15 @@ bool NOTE::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool NOTE::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(ch);
+       state_fio->StateBuffer(regs, sizeof(regs), 1);
+       return true;
+}
index 3ccbead..f01a7f8 100644 (file)
@@ -455,3 +455,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 8febde0..fec8e53 100644 (file)
@@ -208,3 +208,17 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(status, sizeof(status), 1);
+       state_fio->StateUint8(sysport);
+       return true;
+}
index 3858efe..d5f0131 100644 (file)
@@ -307,3 +307,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 2d4b321..c9547ca 100644 (file)
@@ -171,3 +171,18 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#ifdef _MAP1010
+       state_fio->StateInt32(kana_pressed);
+#else
+       state_fio->StateBuffer(status, sizeof(status), 1);
+#endif
+       return true;
+}
index 1c6c299..966f9d6 100644 (file)
@@ -131,3 +131,15 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       return true;
+}
index 538c8ea..9d33ded 100644 (file)
@@ -350,3 +350,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 3319098..79d2569 100644 (file)
@@ -86,3 +86,14 @@ bool SYSTEM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SYSTEM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(sysport);
+       return true;
+}
index dd2d9ab..fac275a 100644 (file)
@@ -130,3 +130,15 @@ bool JOYSTICK::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool JOYSTICK::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       state_fio->StateUint8(status);
+       return true;
+}
index a9b13c7..120880c 100644 (file)
@@ -107,3 +107,16 @@ bool PSG::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool PSG::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       for(int i = 0; i < 3; i++) {
+               state_fio->StateInt32(ch[i].period);
+       }
+       return true;
+}
index 4ec45a7..9c06951 100644 (file)
@@ -272,3 +272,26 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(mem, sizeof(mem), 1);
+       state_fio->StateBool(inserted);
+       return true;
+}
index 560d07b..64f0fcc 100644 (file)
@@ -187,3 +187,23 @@ bool VDP::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VDP::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(loading) {
+               vram = base + state_fio->FgetInt32_LE();
+               pcg = base + state_fio->FgetInt32_LE();
+               pattern = base + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(vram - base));
+               state_fio->FputInt32_LE((int)(pcg - base));
+               state_fio->FputInt32_LE((int)(pattern - base));
+       }
+       state_fio->StateBool(force_pattern);
+       return true;
+}
index 9c6d67f..054c60e 100644 (file)
@@ -187,3 +187,19 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(bufcnt);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateUint8(start);
+       state_fio->StateUint8(bit);
+       return true;
+}
index 4d74b70..bed36e7 100644 (file)
@@ -160,3 +160,16 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(key_stat, sizeof(key_stat), 1);
+       state_fio->StateInt32(key_no);
+       state_fio->StateBool(intr_enb);
+       return true;
+}
index a194e1c..a463c75 100644 (file)
@@ -90,3 +90,17 @@ bool PRINTER::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool PRINTER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(out);
+       state_fio->StateUint8(ctrl0);
+       state_fio->StateUint8(ctrl1);
+       state_fio->StateBool(busy);
+       return true;
+}
index 0639b8d..886e5d8 100644 (file)
@@ -325,3 +325,27 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       state_fio->StateBool(inserted);
+       return true;
+}
index b6beffb..5ceb6e4 100644 (file)
@@ -374,3 +374,27 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(cmt_signal);
+       state_fio->StateBool(cmt_remote);
+       state_fio->StateBool(has_extrom);
+       state_fio->StateBool(cart_enabled);
+       state_fio->StateInt32(ctype);
+       
+       // post process
+       if(loading) {
+               if(cart_enabled) {
+                       ENABLE_CART();
+               } else {
+                       DISABLE_CART();
+               }
+       }
+       return true;
+}
index 37f2a06..76535b4 100644 (file)
@@ -334,3 +334,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 9632bd2..3203148 100644 (file)
@@ -372,3 +372,22 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#ifdef _COLOR_MONITOR
+       state_fio->StateBuffer(vram_r, sizeof(vram_r), 1);
+       state_fio->StateBuffer(vram_g, sizeof(vram_g), 1);
+       state_fio->StateBuffer(vram_b, sizeof(vram_b), 1);
+#else
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+#endif
+       state_fio->StateUint8(bank);
+       state_fio->StateInt32(blink);
+       return true;
+}
index 0b04471..09797d1 100644 (file)
@@ -195,3 +195,16 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(led, sizeof(led), 1);
+       state_fio->StateBool(repeat);
+       state_fio->StateBool(enable);
+       return true;
+}
index 83b7177..5adab54 100644 (file)
@@ -256,3 +256,29 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(cmos, sizeof(cmos), 1);
+       state_fio->StateUint32(cmos_crc32);
+       state_fio->StateUint8(bank);
+       state_fio->StateUint8(psel);
+       state_fio->StateUint8(csel);
+       state_fio->StateBool(pcm_on);
+       state_fio->StateBool(pcm_cont);
+       state_fio->StateBool(pcm_pit);
+       state_fio->StateBool(fdc_irq);
+       state_fio->StateBool(motor);
+       
+       // post process
+       if(loading) {
+               update_map();
+       }
+       return true;
+}
index bf592bc..2477c8a 100644 (file)
@@ -145,3 +145,20 @@ bool MFONT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MFONT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(status);
+       if(!cmd->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!res->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       return true;
+}
index ead84e7..e5bfee6 100644 (file)
@@ -394,3 +394,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index e1e2d2f..89b7c31 100644 (file)
@@ -123,3 +123,18 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(in);
+       state_fio->StateBool(out);
+       state_fio->StateBool(remote);
+       state_fio->StateBool(now_acc);
+       state_fio->StateInt32(framecnt);
+       return true;
+}
index 3cb0140..a293730 100644 (file)
@@ -138,3 +138,15 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(status, sizeof(status), 1);
+       state_fio->StateUint8(column);
+       return true;
+}
index 6ce0fd0..e9a15ff 100644 (file)
@@ -193,3 +193,19 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(ext, sizeof(ext), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateInt32(rpage);
+       state_fio->StateInt32(wpage);
+       state_fio->StateBool(inserted);
+       return true;
+}
index 35020d9..e498102 100644 (file)
@@ -91,3 +91,16 @@ bool PRINTER::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool PRINTER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(strobe);
+       state_fio->StateBool(busy);
+       state_fio->StateUint8(out);
+       return true;
+}
index ade6aba..c59a19c 100644 (file)
@@ -349,3 +349,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index b822e32..30f5437 100644 (file)
@@ -211,3 +211,18 @@ bool VDP::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VDP::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+       state_fio->StateBuffer(reg, sizeof(reg), 1);
+       state_fio->StateUint8(bg);
+       state_fio->StateUint8(cmask);
+       state_fio->StateUint8(pmask);
+       return true;
+}
index 7fe256a..0c953c9 100644 (file)
@@ -124,3 +124,15 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       state_fio->StateBool(break_pressed);
+       return true;
+}
index 1b942bb..d88a21a 100644 (file)
@@ -192,3 +192,22 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBool(inserted);
+       state_fio->StateBool(ram_selected);
+       state_fio->StateBuffer(bank, sizeof(bank), 1);
+       
+       // post process
+       if(loading) {
+               update_bank();
+       }
+       return true;
+}
index 846847e..8180e4a 100644 (file)
@@ -406,3 +406,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 66c4ae7..0714c3d 100644 (file)
@@ -155,3 +155,16 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(pa);
+       state_fio->StateUint8(pb);
+       state_fio->StateUint8(pc);
+       return true;
+}
index 92f9b00..f679cc2 100644 (file)
@@ -284,3 +284,26 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(save_path, sizeof(save_path), 1);
+       state_fio->StateBuffer(&header, sizeof(header), 1);
+       state_fio->StateBool(inserted);
+       state_fio->StateUint32(sram_crc32);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBuffer(wreg, sizeof(wreg), 1);
+       state_fio->StateBuffer(sram, sizeof(sram), 1);
+       state_fio->StateUint8(cur_bank);
+       
+       // post process
+       if(loading) {
+               set_bank(cur_bank);
+       }
+       return true;
+}
index f734f5a..773dfaf 100644 (file)
@@ -249,3 +249,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 574ea12..90ca57d 100644 (file)
@@ -443,3 +443,44 @@ bool SOUND::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool SOUND::process_state(FILEIO* state_fio, bool loading)
+{
+       // pre process
+       int tone_diff = tone.diff;
+       int noise_diff = noise.diff;
+       int square1_diff = square1.diff;
+       int square2_diff = square2.diff;
+       int square3_diff = square3.diff;
+       int pcm_diff = pcm.diff;
+       
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(&tone, sizeof(tone), 1);
+       state_fio->StateBuffer(&noise, sizeof(noise), 1);
+       state_fio->StateBuffer(&square1, sizeof(square1), 1);
+       state_fio->StateBuffer(&square2, sizeof(square2), 1);
+       state_fio->StateBuffer(&square3, sizeof(square3), 1);
+       state_fio->StateBuffer(&pcm, sizeof(pcm), 1);
+       state_fio->StateBuffer(pcm_table, sizeof(pcm_table), 1);
+       state_fio->StateUint32(cmd_addr);
+       state_fio->StateInt32(pcm_len);
+       state_fio->StateInt32(param_cnt);
+       state_fio->StateInt32(param_ptr);
+       state_fio->StateInt32(register_id);
+       state_fio->StateBuffer(params, sizeof(params), 1);
+       
+       // post process
+       if(loading) {
+               tone.diff = tone_diff;
+               noise.diff = noise_diff;
+               square1.diff = square1_diff;
+               square2.diff = square2_diff;
+               square3.diff = square3_diff;
+               pcm.diff = pcm_diff;
+       }
+       return true;
+}
index 3bbd617..3c63315 100644 (file)
@@ -387,3 +387,17 @@ bool VDP::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VDP::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(vdc0);
+       state_fio->StateUint8(vdc1);
+       state_fio->StateUint8(vdc2);
+       state_fio->StateUint8(vdc3);
+       return true;
+}
index a699a99..82e2977 100644 (file)
@@ -334,3 +334,19 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(pio1_pa);
+       state_fio->StateUint8(pio1_pb);
+       state_fio->StateUint8(shift_reg);
+       state_fio->StateUint32(a15_mask);
+       state_fio->StateBool(led);
+       return true;
+}
index ae14bc2..d260a70 100644 (file)
@@ -359,3 +359,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index ceb693d..b1ebc4a 100644 (file)
@@ -1158,3 +1158,67 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(cram, sizeof(cram), 1);
+       state_fio->StateBuffer(aram, sizeof(aram), 1);
+       state_fio->StateBuffer(pcg, sizeof(pcg), 1);
+       state_fio->StateBuffer(gram, sizeof(gram), 1);
+       state_fio->StateBool(rom_selected);
+       state_fio->StateInt32(rom_switch_wait);
+       state_fio->StateInt32(ram_switch_wait);
+       state_fio->StateBuffer(keytable, sizeof(keytable), 1);
+       state_fio->StateBuffer(keytable_shift, sizeof(keytable_shift), 1);
+       state_fio->StateBuffer(keytable_ctrl, sizeof(keytable_ctrl), 1);
+       state_fio->StateBuffer(keytable_kana, sizeof(keytable_kana), 1);
+       state_fio->StateBuffer(keytable_kana_shift, sizeof(keytable_kana_shift), 1);
+       state_fio->StateUint8(key_code);
+       state_fio->StateUint8(key_status);
+       state_fio->StateUint8(key_cmd);
+       state_fio->StateInt32(key_repeat_start);
+       state_fio->StateInt32(key_repeat_interval);
+       state_fio->StateInt32(key_repeat_event);
+       state_fio->StateUint8(funckey_code);
+       state_fio->StateInt32(funckey_index);
+       state_fio->StateBool(caps);
+       state_fio->StateBool(kana);
+       state_fio->StateUint8(gcw);
+       state_fio->StateBool(vsup);
+       state_fio->StateBool(vsync);
+       state_fio->StateBool(disp);
+       state_fio->StateInt32(cblink);
+#if defined(_SMC777)
+       state_fio->StateBool(use_palette_text);
+       state_fio->StateBool(use_palette_graph);
+       state_fio->StateBuffer(pal, sizeof(pal), 1);
+       state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+#endif
+       state_fio->StateInt32(kanji_hi);
+       state_fio->StateInt32(kanji_lo);
+       state_fio->StateBool(ief_key);
+       state_fio->StateBool(ief_vsync);
+       state_fio->StateBool(fdc_irq);
+       state_fio->StateBool(fdc_drq);
+       state_fio->StateBool(drec_in);
+#if defined(_SMC70)
+       state_fio->StateUint8(rtc_data);
+       state_fio->StateBool(rtc_busy);
+#endif
+       
+       // post process
+       if(loading) {
+               if(rom_selected) {
+                       SET_BANK(0x0000, sizeof(rom) - 1, wdmy, rom);
+               } else {
+                       SET_BANK(0x0000, sizeof(rom) - 1, ram, ram);
+               }
+       }
+       return true;
+}
index 4ecfd19..98aacd7 100644 (file)
@@ -445,3 +445,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 4ea045f..8da4c86 100644 (file)
@@ -244,3 +244,54 @@ bool CMT::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(mic);
+       state_fio->StateBool(ear);
+       state_fio->StateBool(pulse);
+       state_fio->StateInt32(pulse_count);
+#if defined(_TK80BS)
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(rec) {
+                       fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(fio->IsOpened()) {
+                                       fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(rec && fio->IsOpened()) {
+                       int length_tmp = (int)fio->Ftell();
+                       fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(bufcnt);
+       state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+#endif
+       return true;
+}
index 1e5040c..c54379e 100644 (file)
@@ -260,3 +260,17 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(_TK80BS)
+       state_fio->StateInt32(mode);
+#endif
+       state_fio->StateBool(dma);
+       return true;
+}
index 646de09..69ae962 100644 (file)
@@ -345,3 +345,21 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(_TK80BS)
+       state_fio->StateUint8(prev_type);
+       state_fio->StateUint8(prev_brk);
+       state_fio->StateUint8(prev_kana);
+       state_fio->StateBool(kana_lock);
+       state_fio->StateUint32(kb_type);
+#endif
+       state_fio->StateUint32(column);
+       return true;
+}
index 3b46bd8..3aecc1b 100644 (file)
@@ -92,3 +92,17 @@ bool MEMBUS::load_state(FILEIO* state_fio)
 //#endif
        return MEMORY::load_state(state_fio);
 }
+bool MEMBUS::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+#if defined(_TK85)
+       state_fio->StateUint32(pc7);
+       state_fio->StateUint32(count);
+#endif
+       return MEMORY::process_state(state_fio, loading);
+}
index f837380..63c6c17 100644 (file)
@@ -202,3 +202,15 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       return true;
+}
index 18a98a1..5773ba0 100644 (file)
@@ -622,3 +622,36 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+#if defined(_TK80BS)
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateInt32(boot_mode);
+//     state_fio->StateInt32(draw_ranges);
+       
+       // post process
+       if(loading) {
+               emu->reload_bitmap();
+               draw_ranges = 8;
+       }
+#endif
+       return true;
+}
index 28d9bc7..4ee5ad7 100644 (file)
@@ -1441,3 +1441,91 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(rregs, sizeof(rregs), 1);
+       state_fio->StateBuffer(wregs, sizeof(wregs), 1);
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(register_id_1sec);
+       if(!cmd_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!rsp_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint8(sub_int);
+       state_fio->StateBuffer(wram, sizeof(wram), 1);
+       state_fio->StateBuffer(alarm, sizeof(alarm), 1);
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBool(ctrl);
+       state_fio->StateBool(shift);
+       state_fio->StateBool(kana);
+       state_fio->StateBool(graph);
+       state_fio->StateBool(brk);
+       state_fio->StateUint8(stick);
+       state_fio->StateUint8(strig);
+       state_fio->StateUint8(strig1);
+       state_fio->StateBool(cmt_play);
+       state_fio->StateBool(cmt_rec);
+       state_fio->StateBool(cmt_mode);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(cmt_rec) {
+                       cmt_fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               state_fio->Fread(buffer_tmp, length_rw, 1);
+                               if(cmt_fio->IsOpened()) {
+                                       cmt_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(cmt_rec && cmt_fio->IsOpened()) {
+                       int length_tmp = (int)cmt_fio->Ftell();
+                       cmt_fio->Fseek(0, FILEIO_SEEK_SET);
+                       state_fio->FputInt32_LE(length_tmp);
+                       while(length_tmp != 0) {
+                               uint8_t buffer_tmp[1024];
+                               int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+                               cmt_fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(cmt_len);
+       state_fio->StateInt32(cmt_ptr);
+       state_fio->StateBuffer(cmt_buf, sizeof(cmt_buf), 1);
+       state_fio->StateBool(vblank);
+       state_fio->StateUint8(font_code);
+       state_fio->StateBuffer(udc, sizeof(udc), 1);
+       state_fio->StateBuffer(lcd, sizeof(lcd), 1);
+       state_fio->StateBool(locate_on);
+       state_fio->StateBool(cursor_on);
+       state_fio->StateBool(udk_on);
+       state_fio->StateInt32(locate_x);
+       state_fio->StateInt32(locate_y);
+       state_fio->StateInt32(cursor_x);
+       state_fio->StateInt32(cursor_y);
+       state_fio->StateInt32(cursor_blink);
+       state_fio->StateInt32(scroll_min);
+       state_fio->StateInt32(scroll_max);
+       state_fio->StateInt32(register_id_beep);
+       return true;
+}
index fcfb2e9..74b89f0 100644 (file)
@@ -288,3 +288,26 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       return true;
+}
index 8d63804..23d54a3 100644 (file)
@@ -337,3 +337,23 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(pb);
+       state_fio->StateUint8(pc);
+       state_fio->StateUint8(div_counter);
+       state_fio->StateUint8(counter);
+       state_fio->StateInt32(posi_counter);
+       state_fio->StateInt32(nega_counter);
+       state_fio->StateBool(drec_in);
+       state_fio->StateBool(drec_toggle);
+       state_fio->StateUint32(prev_clock);
+       state_fio->StateInt32(register_id);
+       return true;
+}
index 30e5849..cc77390 100644 (file)
@@ -339,3 +339,26 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       return true;
+}
index ae3aa8e..cb1e204 100644 (file)
@@ -1765,3 +1765,56 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!cmd_buffer->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(active_cmd);
+       state_fio->StateUint8(dpp_data);
+       state_fio->StateUint8(dpp_ctrl);
+       state_fio->StateInt32(scroll_x0);
+       state_fio->StateInt32(scroll_y0);
+       state_fio->StateInt32(scroll_x1);
+       state_fio->StateInt32(scroll_y1);
+       state_fio->StateInt32(cursor_x);
+       state_fio->StateInt32(cursor_y);
+       state_fio->StateInt32(read_x);
+       state_fio->StateInt32(read_y);
+       state_fio->StateUint8(mode1);
+       state_fio->StateUint8(mode2);
+       state_fio->StateUint8(mode3);
+       state_fio->StateUint32(report);
+       state_fio->StateBool(write_cr);
+       state_fio->StateBuffer(cvram, sizeof(cvram), 1);
+       state_fio->StateBuffer(gvram, sizeof(gvram), 1);
+       state_fio->StateInt32(window_x0);
+       state_fio->StateInt32(window_y0);
+       state_fio->StateInt32(window_x1);
+       state_fio->StateInt32(window_y1);
+       state_fio->StateInt32(view_x0);
+       state_fio->StateInt32(view_y0);
+       state_fio->StateInt32(view_x1);
+       state_fio->StateInt32(view_y1);
+       state_fio->StateDouble(expand);
+       state_fio->StateInt32(rotate);
+       state_fio->StateInt32(translate_x);
+       state_fio->StateInt32(translate_y);
+       state_fio->StateInt32(point_x);
+       state_fio->StateInt32(point_y);
+       state_fio->StateInt32(fore_color);
+       state_fio->StateInt32(back_color);
+       state_fio->StateBool(erase);
+       state_fio->StateInt32(texture);
+       state_fio->StateInt32(texture_index);
+       state_fio->StateInt32(pattern);
+       state_fio->StateBuffer(palette_graph, sizeof(palette_graph), 1);
+       state_fio->StateInt32(blink);
+       return true;
+}
index 32416f5..479c7fb 100644 (file)
@@ -217,3 +217,16 @@ bool KEYBOARD::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(column);
+       state_fio->StateBool(caps_locked);
+       state_fio->StateBool(kana_locked);
+       return true;
+}
index 4458c3d..dec2eec 100644 (file)
@@ -157,3 +157,25 @@ bool MAPPER::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MAPPER::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(mapper_reg);
+       state_fio->StateBuffer(bank_reg, sizeof(bank_reg), 1);
+//     state_fio->StateBuffer(cur_bank, sizeof(cur_bank), 1);
+       
+       // post process
+       if(loading) {
+               for(int i = 0; i < 15; i++) {
+                       cur_bank[i] = -1;
+                       update_bank(i);
+               }
+       }
+       return true;
+}
index 313257f..ee7892e 100644 (file)
@@ -344,3 +344,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}
index 3a49486..b1c7ffd 100644 (file)
@@ -163,3 +163,16 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(seg, sizeof(seg), 1);
+       state_fio->StateUint8(pb);
+       state_fio->StateUint8(pc);
+       return true;
+}
index e25ce9f..78c6d3d 100644 (file)
@@ -257,3 +257,25 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       return true;
+}
index acf1e6d..87aa81a 100644 (file)
@@ -142,3 +142,15 @@ bool MEMORY::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBool(inserted);
+       return true;
+}
index 8173a29..f434987 100644 (file)
@@ -269,3 +269,24 @@ bool VM::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               const char *name = typeid(*device).name() + 6; // skip "class "
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       return false;
+               }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       return false;
+               }
+       }
+       return true;
+}