• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revisionb52e7c90d3f29db8cefd83a6ff936952b6b7decd (tree)
Time2018-07-07 01:51:19
AuthorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[VM][PASOPIA][PASOPIA7] Apply new state framework to VMs.

Change Summary

Incremental Difference

--- a/source/src/vm/pasopia/display.cpp
+++ b/source/src/vm/pasopia/display.cpp
@@ -631,27 +631,50 @@ void DISPLAY::draw_screen15_wide(uint16_t src)
631631
632632 #define STATE_VERSION 1
633633
634+#include "../../statesub.h"
635+
636+void DISPLAY::decl_state()
637+{
638+ enter_decl_state(STATE_VERSION);
639+
640+ DECL_STATE_ENTRY_UINT8(mode);
641+ DECL_STATE_ENTRY_UINT16(cursor);
642+ DECL_STATE_ENTRY_UINT16(cblink);
643+
644+ leave_decl_state();
645+}
646+
634647 void DISPLAY::save_state(FILEIO* state_fio)
635648 {
636- state_fio->FputUint32(STATE_VERSION);
637- state_fio->FputInt32(this_device_id);
649+ if(state_entry != NULL) {
650+ state_entry->save_state(state_fio);
651+ }
652+// state_fio->FputUint32(STATE_VERSION);
653+// state_fio->FputInt32(this_device_id);
638654
639- state_fio->FputUint8(mode);
640- state_fio->FputUint16(cursor);
641- state_fio->FputUint16(cblink);
655+// state_fio->FputUint8(mode);
656+// state_fio->FputUint16(cursor);
657+// state_fio->FputUint16(cblink);
642658 }
643659
644660 bool DISPLAY::load_state(FILEIO* state_fio)
645661 {
646- if(state_fio->FgetUint32() != STATE_VERSION) {
647- return false;
662+ bool mb = false;
663+ if(state_entry != NULL) {
664+ mb = state_entry->load_state(state_fio);
648665 }
649- if(state_fio->FgetInt32() != this_device_id) {
666+ if(!mb) {
650667 return false;
651668 }
652- mode = state_fio->FgetUint8();
653- cursor = state_fio->FgetUint16();
654- cblink = state_fio->FgetUint16();
669+// if(state_fio->FgetUint32() != STATE_VERSION) {
670+// return false;
671+// }
672+// if(state_fio->FgetInt32() != this_device_id) {
673+// return false;
674+// }
675+// mode = state_fio->FgetUint8();
676+// cursor = state_fio->FgetUint16();
677+// cblink = state_fio->FgetUint16();
655678 return true;
656679 }
657680
--- a/source/src/vm/pasopia/display.h
+++ b/source/src/vm/pasopia/display.h
@@ -52,6 +52,7 @@ public:
5252 void write_io8(uint32_t addr, uint32_t data);
5353 void write_signal(int id, uint32_t data, uint32_t mask);
5454 void event_frame();
55+ void decl_state();
5556 void save_state(FILEIO* state_fio);
5657 bool load_state(FILEIO* state_fio);
5758
--- a/source/src/vm/pasopia/floppy.cpp
+++ b/source/src/vm/pasopia/floppy.cpp
@@ -73,25 +73,47 @@ void FLOPPY::write_signal(int id, uint32_t data, uint32_t mask)
7373
7474 #define STATE_VERSION 1
7575
76+#include "../../statesub.h"
77+
78+void FLOPPY::decl_state()
79+{
80+ enter_decl_state(STATE_VERSION);
81+
82+ DECL_STATE_ENTRY_BOOL(intr);
83+ DECL_STATE_ENTRY_BOOL(supported);
84+
85+ leave_decl_state();
86+}
87+
7688 void FLOPPY::save_state(FILEIO* state_fio)
7789 {
78- state_fio->FputUint32(STATE_VERSION);
79- state_fio->FputInt32(this_device_id);
90+ if(state_entry != NULL) {
91+ state_entry->save_state(state_fio);
92+ }
93+// state_fio->FputUint32(STATE_VERSION);
94+// state_fio->FputInt32(this_device_id);
8095
81- state_fio->FputBool(intr);
82- state_fio->FputBool(supported);
96+// state_fio->FputBool(intr);
97+// state_fio->FputBool(supported);
8398 }
8499
85100 bool FLOPPY::load_state(FILEIO* state_fio)
86101 {
87- if(state_fio->FgetUint32() != STATE_VERSION) {
88- return false;
102+ bool mb = false;
103+ if(state_entry != NULL) {
104+ mb = state_entry->load_state(state_fio);
89105 }
90- if(state_fio->FgetInt32() != this_device_id) {
106+ if(!mb) {
91107 return false;
92108 }
93- intr = state_fio->FgetBool();
94- supported = state_fio->FgetBool();
109+// if(state_fio->FgetUint32() != STATE_VERSION) {
110+// return false;
111+// }
112+// if(state_fio->FgetInt32() != this_device_id) {
113+// return false;
114+// }
115+// intr = state_fio->FgetBool();
116+// supported = state_fio->FgetBool();
95117 return true;
96118 }
97119
--- a/source/src/vm/pasopia/floppy.h
+++ b/source/src/vm/pasopia/floppy.h
@@ -34,6 +34,7 @@ public:
3434 void write_io8(uint32_t addr, uint32_t data);
3535 uint32_t read_io8(uint32_t addr);
3636 void write_signal(int id, uint32_t data, uint32_t mask);
37+ void decl_state();
3738 void save_state(FILEIO* state_fio);
3839 bool load_state(FILEIO* state_fio);
3940
--- a/source/src/vm/pasopia/kanjipac2.cpp
+++ b/source/src/vm/pasopia/kanjipac2.cpp
@@ -44,19 +44,38 @@ uint32_t KANJIPAC2::read_io8(uint32_t addr)
4444
4545 #define STATE_VERSION 1
4646
47+#include "../../statesub.h"
48+
49+void KANJIPAC2::decl_state()
50+{
51+ state_entry = new csp_state_utils(STATE_VERSION, 0, (const _TCHAR *)_T("PAC2SLOT::KANJIPAC2"), NULL);
52+
53+ DECL_STATE_ENTRY_UINT32(ptr);
54+
55+ //leave_decl_state();
56+}
57+
4758 void KANJIPAC2::save_state(FILEIO* state_fio)
4859 {
49- state_fio->FputUint32(STATE_VERSION);
60+ if(state_entry != NULL) {
61+ state_entry->save_state(state_fio);
62+ }
63+// state_fio->FputUint32(STATE_VERSION);
5064
51- state_fio->FputUint32(ptr);
65+// state_fio->FputUint32(ptr);
5266 }
5367
5468 bool KANJIPAC2::load_state(FILEIO* state_fio)
5569 {
56- if(state_fio->FgetUint32() != STATE_VERSION) {
57- return false;
70+ bool mb = false;
71+ if(state_entry != NULL) {
72+ mb = state_entry->load_state(state_fio);
5873 }
59- ptr = state_fio->FgetUint32();
74+ if(!mb) return false;
75+// if(state_fio->FgetUint32() != STATE_VERSION) {
76+// return false;
77+// }
78+// ptr = state_fio->FgetUint32();
6079 return true;
6180 }
6281
--- a/source/src/vm/pasopia/kanjipac2.h
+++ b/source/src/vm/pasopia/kanjipac2.h
@@ -31,6 +31,7 @@ public:
3131 void initialize(int id);
3232 void write_io8(uint32_t addr, uint32_t data);
3333 uint32_t read_io8(uint32_t addr);
34+ void decl_state();
3435 void save_state(FILEIO* state_fio);
3536 bool load_state(FILEIO* state_fio);
3637 };
--- a/source/src/vm/pasopia/keyboard.cpp
+++ b/source/src/vm/pasopia/keyboard.cpp
@@ -74,23 +74,42 @@ void KEYBOARD::create_key()
7474
7575 #define STATE_VERSION 1
7676
77+#include "../../statesub.h"
78+
79+void KEYBOARD::decl_state()
80+{
81+ enter_decl_state(STATE_VERSION);
82+
83+ DECL_STATE_ENTRY_UINT8(sel);
84+
85+ leave_decl_state();
86+}
87+
7788 void KEYBOARD::save_state(FILEIO* state_fio)
7889 {
79- state_fio->FputUint32(STATE_VERSION);
80- state_fio->FputInt32(this_device_id);
90+ if(state_entry != NULL) {
91+ state_entry->save_state(state_fio);
92+ }
93+// state_fio->FputUint32(STATE_VERSION);
94+// state_fio->FputInt32(this_device_id);
8195
82- state_fio->FputUint8(sel);
96+// state_fio->FputUint8(sel);
8397 }
8498
8599 bool KEYBOARD::load_state(FILEIO* state_fio)
86100 {
87- if(state_fio->FgetUint32() != STATE_VERSION) {
88- return false;
89- }
90- if(state_fio->FgetInt32() != this_device_id) {
91- return false;
101+ bool mb = false;
102+ if(state_entry != NULL) {
103+ mb = state_entry->load_state(state_fio);
92104 }
93- sel = state_fio->FgetUint8();
105+ if(!mb) return false;
106+// if(state_fio->FgetUint32() != STATE_VERSION) {
107+// return false;
108+// }
109+// if(state_fio->FgetInt32() != this_device_id) {
110+// return false;
111+// }
112+// sel = state_fio->FgetUint8();
94113 return true;
95114 }
96115
--- a/source/src/vm/pasopia/keyboard.h
+++ b/source/src/vm/pasopia/keyboard.h
@@ -36,6 +36,7 @@ public:
3636 void initialize();
3737 void write_signal(int id, uint32_t data, uint32_t mask);
3838 void event_frame();
39+ void decl_state();
3940 void save_state(FILEIO* state_fio);
4041 bool load_state(FILEIO* state_fio);
4142
--- a/source/src/vm/pasopia/memory.cpp
+++ b/source/src/vm/pasopia/memory.cpp
@@ -141,33 +141,57 @@ void MEMORY::write_signal(int id, uint32_t data, uint32_t mask)
141141
142142 #define STATE_VERSION 1
143143
144+#include "../../statesub.h"
145+
146+void MEMORY::decl_state()
147+{
148+ enter_decl_state(STATE_VERSION);
149+
150+ DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
151+ DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
152+ DECL_STATE_ENTRY_1D_ARRAY(attr, sizeof(attr));
153+ DECL_STATE_ENTRY_UINT16(vram_ptr);
154+ DECL_STATE_ENTRY_UINT8(vram_data);
155+ DECL_STATE_ENTRY_UINT8(mem_map);
156+
157+ leave_decl_state();
158+}
159+
144160 void MEMORY::save_state(FILEIO* state_fio)
145161 {
146- state_fio->FputUint32(STATE_VERSION);
147- state_fio->FputInt32(this_device_id);
162+ if(state_entry != NULL) {
163+ state_entry->save_state(state_fio);
164+ }
165+// state_fio->FputUint32(STATE_VERSION);
166+// state_fio->FputInt32(this_device_id);
148167
149- state_fio->Fwrite(ram, sizeof(ram), 1);
150- state_fio->Fwrite(vram, sizeof(vram), 1);
151- state_fio->Fwrite(attr, sizeof(attr), 1);
152- state_fio->FputUint16(vram_ptr);
153- state_fio->FputUint8(vram_data);
154- state_fio->FputUint8(mem_map);
168+// state_fio->Fwrite(ram, sizeof(ram), 1);
169+// state_fio->Fwrite(vram, sizeof(vram), 1);
170+// state_fio->Fwrite(attr, sizeof(attr), 1);
171+// state_fio->FputUint16(vram_ptr);
172+// state_fio->FputUint8(vram_data);
173+// state_fio->FputUint8(mem_map);
155174 }
156175
157176 bool MEMORY::load_state(FILEIO* state_fio)
158177 {
159- if(state_fio->FgetUint32() != STATE_VERSION) {
160- return false;
161- }
162- if(state_fio->FgetInt32() != this_device_id) {
163- return false;
178+ bool mb = false;
179+ if(state_entry != NULL) {
180+ mb = state_entry->load_state(state_fio);
164181 }
165- state_fio->Fread(ram, sizeof(ram), 1);
166- state_fio->Fread(vram, sizeof(vram), 1);
167- state_fio->Fread(attr, sizeof(attr), 1);
168- vram_ptr = state_fio->FgetUint16();
169- vram_data = state_fio->FgetUint8();
170- mem_map = state_fio->FgetUint8();
182+ if(!mb) return false;
183+// if(state_fio->FgetUint32() != STATE_VERSION) {
184+// return false;
185+// }
186+// if(state_fio->FgetInt32() != this_device_id) {
187+// return false;
188+// }
189+// state_fio->Fread(ram, sizeof(ram), 1);
190+// state_fio->Fread(vram, sizeof(vram), 1);
191+// state_fio->Fread(attr, sizeof(attr), 1);
192+// vram_ptr = state_fio->FgetUint16();
193+// vram_data = state_fio->FgetUint8();
194+// mem_map = state_fio->FgetUint8();
171195
172196 // post process
173197 if(mem_map & 2) {
--- a/source/src/vm/pasopia/memory.h
+++ b/source/src/vm/pasopia/memory.h
@@ -48,6 +48,7 @@ public:
4848 uint32_t read_data8(uint32_t addr);
4949 void write_io8(uint32_t addr, uint32_t data);
5050 void write_signal(int id, uint32_t data, uint32_t mask);
51+ void decl_state();
5152 void save_state(FILEIO* state_fio);
5253 bool load_state(FILEIO* state_fio);
5354
--- a/source/src/vm/pasopia/pac2.cpp
+++ b/source/src/vm/pasopia/pac2.cpp
@@ -77,24 +77,57 @@ void PAC2::open_rampac2(const _TCHAR* file_path)
7777
7878 #define STATE_VERSION 1
7979
80-void PAC2::save_state(FILEIO* state_fio)
80+#include "../../statesub.h"
81+
82+void PAC2::decl_state()
8183 {
82- state_fio->FputUint32(STATE_VERSION);
83- state_fio->FputInt32(this_device_id);
84+ enter_decl_state(STATE_VERSION);
85+
86+ DECL_STATE_ENTRY_INT32(device_type);
87+
88+ if(rampac2 != NULL) {
89+ rampac2->decl_state();
90+ }
91+ if(kanji != NULL) {
92+ kanji->decl_state();
93+ }
94+ if(joy != NULL) {
95+ joy->decl_state();
96+ }
97+ if(dummy != NULL) {
98+ dummy->decl_state();
99+ }
100+
84101
85- state_fio->FputInt32(device_type);
102+ leave_decl_state();
103+}
104+
105+void PAC2::save_state(FILEIO* state_fio)
106+{
107+ if(state_entry != NULL) {
108+ state_entry->save_state(state_fio);
109+ }
110+// state_fio->FputUint32(STATE_VERSION);
111+// state_fio->FputInt32(this_device_id);
112+//
113+// state_fio->FputInt32(device_type);
86114 get_device()->save_state(state_fio);
87115 }
88116
89117 bool PAC2::load_state(FILEIO* state_fio)
90118 {
91- if(state_fio->FgetUint32() != STATE_VERSION) {
92- return false;
93- }
94- if(state_fio->FgetInt32() != this_device_id) {
95- return false;
119+ bool mb = false;
120+ if(state_entry != NULL) {
121+ mb = state_entry->load_state(state_fio);
96122 }
97- device_type = state_fio->FgetInt32();
123+ if(!mb) return false;
124+// if(state_fio->FgetUint32() != STATE_VERSION) {
125+// return false;
126+// }
127+// if(state_fio->FgetInt32() != this_device_id) {
128+// return false;
129+// }
130+// device_type = state_fio->FgetInt32();
98131 if(!get_device()->load_state(state_fio)) {
99132 return false;
100133 }
--- a/source/src/vm/pasopia/pac2.h
+++ b/source/src/vm/pasopia/pac2.h
@@ -44,6 +44,7 @@ public:
4444 void reset();
4545 void write_io8(uint32_t addr, uint32_t data);
4646 uint32_t read_io8(uint32_t addr);
47+ void decl_state();
4748 void save_state(FILEIO* state_fio);
4849 bool load_state(FILEIO* state_fio);
4950
--- a/source/src/vm/pasopia/pac2dev.h
+++ b/source/src/vm/pasopia/pac2dev.h
@@ -14,11 +14,14 @@
1414 #include "../vm.h"
1515 #include "../../emu.h"
1616
17+class csp_state_utils;
1718 class PAC2DEV
1819 {
1920 protected:
2021 VM* vm;
2122 EMU* emu;
23+ csp_state_utils *state_entry;
24+
2225 public:
2326 PAC2DEV(VM* parent_vm, EMU* parent_emu) : vm(parent_vm), emu(parent_emu)
2427 {
@@ -31,7 +34,8 @@ public:
3134 virtual void reset() {}
3235 virtual void write_io8(uint32_t addr, uint32_t data) {}
3336 virtual uint32_t read_io8(uint32_t addr) { return 0xff; }
34- virtual void save_state(FILEIO* state_fio) {}
37+ virtual void decl_state() { state_entry = NULL; }
38+ virtual void save_state(FILEIO* state_fio) { }
3539 virtual bool load_state(FILEIO* state_fio) { return true; }
3640
3741 virtual void set_device_name(const _TCHAR* format, ...)
--- a/source/src/vm/pasopia/pasopia.cpp
+++ b/source/src/vm/pasopia/pasopia.cpp
@@ -485,10 +485,12 @@ bool VM::load_state(FILEIO* state_fio)
485485 }
486486 for(DEVICE* device = first_device; device; device = device->next_device) {
487487 if(!device->load_state(state_fio)) {
488+ //printf("LOAD ERROR at DEVID#%d\n", device->this_device_id);
488489 return false;
489490 }
490491 }
491492 //boot_mode = state_fio->FgetInt32();
493+ //printf("LOAD STATE OK\n");
492494 return true;
493495 }
494496
--- a/source/src/vm/pasopia/rampac2.cpp
+++ b/source/src/vm/pasopia/rampac2.cpp
@@ -96,25 +96,48 @@ void RAMPAC2::open_file(const _TCHAR* file_path)
9696
9797 #define STATE_VERSION 1
9898
99+#include "../../statesub.h"
100+
101+void RAMPAC2::decl_state()
102+{
103+ state_entry = new csp_state_utils(STATE_VERSION, 1, (const _TCHAR *)_T("PAC2SLOT::RAMPAC2"), NULL);
104+
105+ DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
106+ DECL_STATE_ENTRY_UINT32(ptr);
107+
108+ DECL_STATE_ENTRY_BOOL(opened);
109+ DECL_STATE_ENTRY_BOOL(modified);
110+ //leave_decl_state();
111+}
112+
113+
99114 void RAMPAC2::save_state(FILEIO* state_fio)
100115 {
101- state_fio->FputUint32(STATE_VERSION);
116+ if(state_entry != NULL) {
117+ state_entry->save_state(state_fio);
118+ }
119+// state_fio->FputUint32(STATE_VERSION);
102120
103- state_fio->Fwrite(ram, sizeof(ram), 1);
104- state_fio->FputUint32(ptr);
105- state_fio->FputBool(opened);
106- state_fio->FputBool(modified);
121+// state_fio->Fwrite(ram, sizeof(ram), 1);
122+// state_fio->FputUint32(ptr);
123+// state_fio->FputBool(opened);
124+// state_fio->FputBool(modified);
107125 }
108126
109127 bool RAMPAC2::load_state(FILEIO* state_fio)
110128 {
111- if(state_fio->FgetUint32() != STATE_VERSION) {
112- return false;
129+ bool mb = false;
130+ if(state_entry != NULL) {
131+ mb = state_entry->load_state(state_fio);
113132 }
114- state_fio->Fread(ram, sizeof(ram), 1);
115- ptr = state_fio->FgetUint32();
116- opened = state_fio->FgetBool();
117- modified = state_fio->FgetBool();
133+ if(!mb) return false;
134+// if(state_fio->FgetUint32() != STATE_VERSION) {
135+// return false;
136+// }
137+// state_fio->Fread(ram, sizeof(ram), 1);
138+// ptr = state_fio->FgetUint32();
139+// opened = state_fio->FgetBool();
140+// modified = state_fio->FgetBool();
118141 return true;
119142 }
120143
--- a/source/src/vm/pasopia/rampac2.h
+++ b/source/src/vm/pasopia/rampac2.h
@@ -37,6 +37,7 @@ public:
3737 void write_io8(uint32_t addr, uint32_t data);
3838 uint32_t read_io8(uint32_t addr);
3939 void open_file(const _TCHAR* file_path);
40+ void decl_state();
4041 void save_state(FILEIO* state_fio);
4142 bool load_state(FILEIO* state_fio);
4243 };
--- a/source/src/vm/pasopia7/display.cpp
+++ b/source/src/vm/pasopia7/display.cpp
@@ -757,35 +757,60 @@ void DISPLAY::draw_fine_lcd(uint16_t src)
757757
758758 #define STATE_VERSION 1
759759
760+#include "../../statesub.h"
761+
762+void DISPLAY::decl_state()
763+{
764+ enter_decl_state(STATE_VERSION);
765+
766+ DECL_STATE_ENTRY_UINT8(mode);
767+ DECL_STATE_ENTRY_UINT8(text_page);
768+ DECL_STATE_ENTRY_UINT16(cursor);
769+ DECL_STATE_ENTRY_UINT16(cblink);
770+ DECL_STATE_ENTRY_UINT16(flash_cnt);
771+ DECL_STATE_ENTRY_BOOL(blink);
772+ DECL_STATE_ENTRY_BOOL(pal_dis);
773+
774+ leave_decl_state();
775+}
776+
760777 void DISPLAY::save_state(FILEIO* state_fio)
761778 {
762- state_fio->FputUint32(STATE_VERSION);
763- state_fio->FputInt32(this_device_id);
779+ if(state_entry != NULL) {
780+ state_entry->save_state(state_fio);
781+ }
782+// state_fio->FputUint32(STATE_VERSION);
783+// state_fio->FputInt32(this_device_id);
764784
765- state_fio->FputUint8(mode);
766- state_fio->FputUint8(text_page);
767- state_fio->FputUint16(cursor);
768- state_fio->FputUint16(cblink);
769- state_fio->FputUint16(flash_cnt);
770- state_fio->FputBool(blink);
771- state_fio->FputBool(pal_dis);
785+// state_fio->FputUint8(mode);
786+// state_fio->FputUint8(text_page);
787+// state_fio->FputUint16(cursor);
788+// state_fio->FputUint16(cblink);
789+// state_fio->FputUint16(flash_cnt);
790+// state_fio->FputBool(blink);
791+// state_fio->FputBool(pal_dis);
772792 }
773793
774794 bool DISPLAY::load_state(FILEIO* state_fio)
775795 {
776- if(state_fio->FgetUint32() != STATE_VERSION) {
777- return false;
778- }
779- if(state_fio->FgetInt32() != this_device_id) {
780- return false;
796+ bool mb = false;
797+ if(state_entry != NULL) {
798+ mb = state_entry->load_state(state_fio);
781799 }
782- mode = state_fio->FgetUint8();
783- text_page = state_fio->FgetUint8();
784- cursor = state_fio->FgetUint16();
785- cblink = state_fio->FgetUint16();
786- flash_cnt = state_fio->FgetUint16();
787- blink = state_fio->FgetBool();
788- pal_dis = state_fio->FgetBool();
800+ if(!mb) return false;
801+// if(state_fio->FgetUint32() != STATE_VERSION) {
802+// return false;
803+// }
804+// if(state_fio->FgetInt32() != this_device_id) {
805+// return false;
806+// }
807+// mode = state_fio->FgetUint8();
808+// text_page = state_fio->FgetUint8();
809+// cursor = state_fio->FgetUint16();
810+// cblink = state_fio->FgetUint16();
811+// flash_cnt = state_fio->FgetUint16();
812+// blink = state_fio->FgetBool();
813+// pal_dis = state_fio->FgetBool();
789814 return true;
790815 }
791816
--- a/source/src/vm/pasopia7/display.h
+++ b/source/src/vm/pasopia7/display.h
@@ -53,6 +53,7 @@ public:
5353 void initialize();
5454 void write_signal(int id, uint32_t data, uint32_t mask);
5555 void event_frame();
56+ void decl_state();
5657 void save_state(FILEIO* state_fio);
5758 bool load_state(FILEIO* state_fio);
5859
--- a/source/src/vm/pasopia7/floppy.cpp
+++ b/source/src/vm/pasopia7/floppy.cpp
@@ -56,23 +56,42 @@ void FLOPPY::write_signal(int id, uint32_t data, uint32_t mask)
5656
5757 #define STATE_VERSION 1
5858
59+#include "../../statesub.h"
60+
61+void FLOPPY::decl_state()
62+{
63+ enter_decl_state(STATE_VERSION);
64+
65+ DECL_STATE_ENTRY_BOOL(intr);
66+
67+ leave_decl_state();
68+}
69+
5970 void FLOPPY::save_state(FILEIO* state_fio)
6071 {
61- state_fio->FputUint32(STATE_VERSION);
62- state_fio->FputInt32(this_device_id);
72+ if(state_entry != NULL) {
73+ state_entry->save_state(state_fio);
74+ }
75+// state_fio->FputUint32(STATE_VERSION);
76+// state_fio->FputInt32(this_device_id);
6377
64- state_fio->FputBool(intr);
78+// state_fio->FputBool(intr);
6579 }
6680
6781 bool FLOPPY::load_state(FILEIO* state_fio)
6882 {
69- if(state_fio->FgetUint32() != STATE_VERSION) {
70- return false;
71- }
72- if(state_fio->FgetInt32() != this_device_id) {
73- return false;
83+ bool mb = false;
84+ if(state_entry != NULL) {
85+ mb = state_entry->load_state(state_fio);
7486 }
75- intr = state_fio->FgetBool();
87+ if(!mb) return false;
88+// if(state_fio->FgetUint32() != STATE_VERSION) {
89+// return false;
90+// }
91+// if(state_fio->FgetInt32() != this_device_id) {
92+// return false;
93+// }
94+// intr = state_fio->FgetBool();
7695 return true;
7796 }
7897
--- a/source/src/vm/pasopia7/floppy.h
+++ b/source/src/vm/pasopia7/floppy.h
@@ -34,6 +34,7 @@ public:
3434 void write_io8(uint32_t addr, uint32_t data);
3535 uint32_t read_io8(uint32_t addr);
3636 void write_signal(int id, uint32_t data, uint32_t mask);
37+ void decl_state();
3738 void save_state(FILEIO* state_fio);
3839 bool load_state(FILEIO* state_fio);
3940
--- a/source/src/vm/pasopia7/iobus.cpp
+++ b/source/src/vm/pasopia7/iobus.cpp
@@ -43,23 +43,42 @@ void IOBUS::write_signal(int id, uint32_t data, uint32_t mask)
4343
4444 #define STATE_VERSION 1
4545
46+#include "../../statesub.h"
47+
48+void IOBUS::decl_state()
49+{
50+ enter_decl_state(STATE_VERSION);
51+
52+ DECL_STATE_ENTRY_BOOL(mio);
53+
54+ leave_decl_state();
55+}
56+
4657 void IOBUS::save_state(FILEIO* state_fio)
4758 {
48- state_fio->FputUint32(STATE_VERSION);
49- state_fio->FputInt32(this_device_id);
59+ if(state_entry != NULL) {
60+ state_entry->save_state(state_fio);
61+ }
62+// state_fio->FputUint32(STATE_VERSION);
63+// state_fio->FputInt32(this_device_id);
5064
51- state_fio->FputBool(mio);
65+// state_fio->FputBool(mio);
5266 }
5367
5468 bool IOBUS::load_state(FILEIO* state_fio)
5569 {
56- if(state_fio->FgetUint32() != STATE_VERSION) {
57- return false;
58- }
59- if(state_fio->FgetInt32() != this_device_id) {
60- return false;
70+ bool mb = false;
71+ if(state_entry != NULL) {
72+ mb = state_entry->load_state(state_fio);
6173 }
62- mio = state_fio->FgetBool();
74+ if(!mb) return false;
75+// if(state_fio->FgetUint32() != STATE_VERSION) {
76+// return false;
77+// }
78+// if(state_fio->FgetInt32() != this_device_id) {
79+// return false;
80+// }
81+// mio = state_fio->FgetBool();
6382 return true;
6483 }
6584
--- a/source/src/vm/pasopia7/iobus.h
+++ b/source/src/vm/pasopia7/iobus.h
@@ -35,6 +35,7 @@ public:
3535 void write_io8(uint32_t addr, uint32_t data);
3636 uint32_t read_io8(uint32_t addr);
3737 void write_signal(int id, uint32_t data, uint32_t mask);
38+ void decl_state();
3839 void save_state(FILEIO* state_fio);
3940 bool load_state(FILEIO* state_fio);
4041
--- a/source/src/vm/pasopia7/iotrap.cpp
+++ b/source/src/vm/pasopia7/iotrap.cpp
@@ -79,25 +79,45 @@ void IOTRAP::do_reset()
7979
8080 #define STATE_VERSION 1
8181
82+#include "../../statesub.h"
83+
84+void IOTRAP::decl_state()
85+{
86+ enter_decl_state(STATE_VERSION);
87+
88+ DECL_STATE_ENTRY_BOOL(nmi_mask);
89+ DECL_STATE_ENTRY_BOOL(pasopia);
90+
91+ leave_decl_state();
92+}
93+
8294 void IOTRAP::save_state(FILEIO* state_fio)
8395 {
84- state_fio->FputUint32(STATE_VERSION);
85- state_fio->FputInt32(this_device_id);
96+ if(state_entry != NULL) {
97+ state_entry->save_state(state_fio);
98+ }
99+// state_fio->FputUint32(STATE_VERSION);
100+// state_fio->FputInt32(this_device_id);
86101
87- state_fio->FputBool(nmi_mask);
88- state_fio->FputBool(pasopia);
102+// state_fio->FputBool(nmi_mask);
103+// state_fio->FputBool(pasopia);
89104 }
90105
91106 bool IOTRAP::load_state(FILEIO* state_fio)
92107 {
93- if(state_fio->FgetUint32() != STATE_VERSION) {
94- return false;
95- }
96- if(state_fio->FgetInt32() != this_device_id) {
97- return false;
108+ bool mb = false;
109+ if(state_entry != NULL) {
110+ mb = state_entry->load_state(state_fio);
98111 }
99- nmi_mask = state_fio->FgetBool();
100- pasopia = state_fio->FgetBool();
112+ if(!mb) return false;
113+// if(state_fio->FgetUint32() != STATE_VERSION) {
114+// return false;
115+// }
116+// if(state_fio->FgetInt32() != this_device_id) {
117+// return false;
118+// }
119+// nmi_mask = state_fio->FgetBool();
120+// pasopia = state_fio->FgetBool();
101121 return true;
102122 }
103123
--- a/source/src/vm/pasopia7/iotrap.h
+++ b/source/src/vm/pasopia7/iotrap.h
@@ -35,6 +35,7 @@ public:
3535 void write_io8(uint32_t addr, uint32_t data);
3636 uint32_t read_io8(uint32_t addr);
3737 void write_signal(int id, uint32_t data, uint32_t mask);
38+ void decl_state();
3839 void save_state(FILEIO* state_fio);
3940 bool load_state(FILEIO* state_fio);
4041
--- a/source/src/vm/pasopia7/kanjipac2.cpp
+++ b/source/src/vm/pasopia7/kanjipac2.cpp
@@ -47,19 +47,38 @@ uint32_t KANJIPAC2::read_io8(uint32_t addr)
4747
4848 #define STATE_VERSION 1
4949
50+#include "../../statesub.h"
51+
52+void KANJIPAC2::decl_state()
53+{
54+ state_entry = new csp_state_utils(STATE_VERSION, 0, (const _TCHAR *)_T("PAC2SLOT::KANJIPAC2"), NULL);
55+
56+ DECL_STATE_ENTRY_UINT32(ptr);
57+
58+ //leave_decl_state();
59+}
60+
5061 void KANJIPAC2::save_state(FILEIO* state_fio)
5162 {
52- state_fio->FputUint32(STATE_VERSION);
63+ if(state_entry != NULL) {
64+ state_entry->save_state(state_fio);
65+ }
66+// state_fio->FputUint32(STATE_VERSION);
5367
54- state_fio->FputUint32(ptr);
68+// state_fio->FputUint32(ptr);
5569 }
5670
5771 bool KANJIPAC2::load_state(FILEIO* state_fio)
5872 {
59- if(state_fio->FgetUint32() != STATE_VERSION) {
60- return false;
73+ bool mb = false;
74+ if(state_entry != NULL) {
75+ mb = state_entry->load_state(state_fio);
6176 }
62- ptr = state_fio->FgetUint32();
77+ if(!mb) return false;
78+// if(state_fio->FgetUint32() != STATE_VERSION) {
79+// return false;
80+// }
81+// ptr = state_fio->FgetUint32();
6382 return true;
6483 }
6584
--- a/source/src/vm/pasopia7/kanjipac2.h
+++ b/source/src/vm/pasopia7/kanjipac2.h
@@ -32,6 +32,7 @@ public:
3232 void reset();
3333 void write_io8(uint32_t addr, uint32_t data);
3434 uint32_t read_io8(uint32_t addr);
35+ void decl_state();
3536 void save_state(FILEIO* state_fio);
3637 bool load_state(FILEIO* state_fio);
3738 };
--- a/source/src/vm/pasopia7/keyboard.cpp
+++ b/source/src/vm/pasopia7/keyboard.cpp
@@ -79,23 +79,42 @@ void KEYBOARD::create_key()
7979
8080 #define STATE_VERSION 1
8181
82+#include "../../statesub.h"
83+
84+void KEYBOARD::decl_state()
85+{
86+ enter_decl_state(STATE_VERSION);
87+
88+ DECL_STATE_ENTRY_UINT8(sel);
89+
90+ leave_decl_state();
91+}
92+
8293 void KEYBOARD::save_state(FILEIO* state_fio)
8394 {
84- state_fio->FputUint32(STATE_VERSION);
85- state_fio->FputInt32(this_device_id);
95+ if(state_entry != NULL) {
96+ state_entry->save_state(state_fio);
97+ }
98+ //state_fio->FputUint32(STATE_VERSION);
99+ //state_fio->FputInt32(this_device_id);
86100
87- state_fio->FputUint8(sel);
101+ //state_fio->FputUint8(sel);
88102 }
89103
90104 bool KEYBOARD::load_state(FILEIO* state_fio)
91105 {
92- if(state_fio->FgetUint32() != STATE_VERSION) {
93- return false;
94- }
95- if(state_fio->FgetInt32() != this_device_id) {
96- return false;
106+ bool mb = false;
107+ if(state_entry != NULL) {
108+ mb = state_entry->load_state(state_fio);
97109 }
98- sel = state_fio->FgetUint8();
110+ if(!mb) return false;
111+ //if(state_fio->FgetUint32() != STATE_VERSION) {
112+ // return false;
113+ //}
114+ //if(state_fio->FgetInt32() != this_device_id) {
115+ // return false;
116+ //}
117+ //sel = state_fio->FgetUint8();
99118 return true;
100119 }
101120
--- a/source/src/vm/pasopia7/keyboard.h
+++ b/source/src/vm/pasopia7/keyboard.h
@@ -36,6 +36,7 @@ public:
3636 void initialize();
3737 void write_signal(int id, uint32_t data, uint32_t mask);
3838 void event_frame();
39+ void decl_state();
3940 void save_state(FILEIO* state_fio);
4041 bool load_state(FILEIO* state_fio);
4142
--- a/source/src/vm/pasopia7/memory.cpp
+++ b/source/src/vm/pasopia7/memory.cpp
@@ -167,41 +167,69 @@ void MEMORY::update_memory_map()
167167
168168 #define STATE_VERSION 1
169169
170+#include "../../statesub.h"
171+
172+void MEMORY::decl_state()
173+{
174+ enter_decl_state(STATE_VERSION);
175+
176+ DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
177+ DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
178+ DECL_STATE_ENTRY_1D_ARRAY(pal, sizeof(pal));
179+ DECL_STATE_ENTRY_UINT8(mem_map);
180+ DECL_STATE_ENTRY_UINT8(plane);
181+ DECL_STATE_ENTRY_UINT8(attr_data);
182+ DECL_STATE_ENTRY_UINT8(attr_latch);
183+ DECL_STATE_ENTRY_BOOL(vram_sel);
184+ DECL_STATE_ENTRY_BOOL(pal_sel);
185+ DECL_STATE_ENTRY_BOOL(attr_wrap);
186+
187+ leave_decl_state();
188+}
189+
170190 void MEMORY::save_state(FILEIO* state_fio)
171191 {
172- state_fio->FputUint32(STATE_VERSION);
173- state_fio->FputInt32(this_device_id);
192+ if(state_entry != NULL) {
193+ state_entry->save_state(state_fio);
194+ }
195+// state_fio->FputUint32(STATE_VERSION);
196+// state_fio->FputInt32(this_device_id);
174197
175- state_fio->Fwrite(ram, sizeof(ram), 1);
176- state_fio->Fwrite(vram, sizeof(vram), 1);
177- state_fio->Fwrite(pal, sizeof(pal), 1);
178- state_fio->FputUint8(mem_map);
179- state_fio->FputUint8(plane);
180- state_fio->FputUint8(attr_data);
181- state_fio->FputUint8(attr_latch);
182- state_fio->FputBool(vram_sel);
183- state_fio->FputBool(pal_sel);
184- state_fio->FputBool(attr_wrap);
198+// state_fio->Fwrite(ram, sizeof(ram), 1);
199+// state_fio->Fwrite(vram, sizeof(vram), 1);
200+// state_fio->Fwrite(pal, sizeof(pal), 1);
201+// state_fio->FputUint8(mem_map);
202+// state_fio->FputUint8(plane);
203+// state_fio->FputUint8(attr_data);
204+// state_fio->FputUint8(attr_latch);
205+// state_fio->FputBool(vram_sel);
206+// state_fio->FputBool(pal_sel);
207+// state_fio->FputBool(attr_wrap);
185208 }
186209
187210 bool MEMORY::load_state(FILEIO* state_fio)
188211 {
189- if(state_fio->FgetUint32() != STATE_VERSION) {
190- return false;
191- }
192- if(state_fio->FgetInt32() != this_device_id) {
193- return false;
212+ bool mb = false;
213+ if(state_entry != NULL) {
214+ mb = state_entry->load_state(state_fio);
194215 }
195- state_fio->Fread(ram, sizeof(ram), 1);
196- state_fio->Fread(vram, sizeof(vram), 1);
197- state_fio->Fread(pal, sizeof(pal), 1);
198- mem_map = state_fio->FgetUint8();
199- plane = state_fio->FgetUint8();
200- attr_data = state_fio->FgetUint8();
201- attr_latch = state_fio->FgetUint8();
202- vram_sel = state_fio->FgetBool();
203- pal_sel = state_fio->FgetBool();
204- attr_wrap = state_fio->FgetBool();
216+ if(!mb) return false;
217+// if(state_fio->FgetUint32() != STATE_VERSION) {
218+// return false;
219+// }
220+// if(state_fio->FgetInt32() != this_device_id) {
221+// return false;
222+// }
223+// state_fio->Fread(ram, sizeof(ram), 1);
224+// state_fio->Fread(vram, sizeof(vram), 1);
225+// state_fio->Fread(pal, sizeof(pal), 1);
226+// mem_map = state_fio->FgetUint8();
227+// plane = state_fio->FgetUint8();
228+// attr_data = state_fio->FgetUint8();
229+// attr_latch = state_fio->FgetUint8();
230+// vram_sel = state_fio->FgetBool();
231+// pal_sel = state_fio->FgetBool();
232+// attr_wrap = state_fio->FgetBool();
205233
206234 // post process
207235 update_memory_map();
--- a/source/src/vm/pasopia7/memory.h
+++ b/source/src/vm/pasopia7/memory.h
@@ -52,6 +52,7 @@ public:
5252 uint32_t read_data8(uint32_t addr);
5353 void write_io8(uint32_t addr, uint32_t data);
5454 void write_signal(int id, uint32_t data, uint32_t mask);
55+ void decl_state();
5556 void save_state(FILEIO* state_fio);
5657 bool load_state(FILEIO* state_fio);
5758
--- a/source/src/vm/pasopia7/pac2.cpp
+++ b/source/src/vm/pasopia7/pac2.cpp
@@ -90,12 +90,40 @@ void PAC2::open_rampac2(int drv, const _TCHAR* file_path)
9090
9191 #define STATE_VERSION 1
9292
93+#include "../../statesub.h"
94+
95+void PAC2::decl_state()
96+{
97+ enter_decl_state(STATE_VERSION);
98+
99+ DECL_STATE_ENTRY_INT32(sel);
100+
101+ if(dummy != NULL) {
102+ dummy->decl_state();
103+ }
104+ if(kanji != NULL) {
105+ kanji->decl_state();
106+ }
107+ if(joy != NULL) {
108+ joy->decl_state();
109+ }
110+ for(int i = 0; i < 2; i++) {
111+ if(rampac2[i] != NULL) {
112+ rampac2[i]->decl_state();
113+ }
114+ }
115+ leave_decl_state();
116+}
117+
93118 void PAC2::save_state(FILEIO* state_fio)
94119 {
95- state_fio->FputUint32(STATE_VERSION);
96- state_fio->FputInt32(this_device_id);
120+ if(state_entry != NULL) {
121+ state_entry->save_state(state_fio);
122+ }
123+// state_fio->FputUint32(STATE_VERSION);
124+// state_fio->FputInt32(this_device_id);
97125
98- state_fio->FputInt32(sel);
126+// state_fio->FputInt32(sel);
99127 rampac2[0]->save_state(state_fio);
100128 rampac2[1]->save_state(state_fio);
101129 kanji->save_state(state_fio);
@@ -103,13 +131,18 @@ void PAC2::save_state(FILEIO* state_fio)
103131
104132 bool PAC2::load_state(FILEIO* state_fio)
105133 {
106- if(state_fio->FgetUint32() != STATE_VERSION) {
107- return false;
108- }
109- if(state_fio->FgetInt32() != this_device_id) {
110- return false;
134+ bool mb = false;
135+ if(state_entry != NULL) {
136+ mb = state_entry->load_state(state_fio);
111137 }
112- sel = state_fio->FgetInt32();
138+ if(!mb) return false;
139+// if(state_fio->FgetUint32() != STATE_VERSION) {
140+// return false;
141+// }
142+// if(state_fio->FgetInt32() != this_device_id) {
143+// return false;
144+// }
145+// sel = state_fio->FgetInt32();
113146 if(!rampac2[0]->load_state(state_fio)) {
114147 return false;
115148 }
--- a/source/src/vm/pasopia7/pac2.h
+++ b/source/src/vm/pasopia7/pac2.h
@@ -43,6 +43,7 @@ public:
4343 void reset();
4444 void write_io8(uint32_t addr, uint32_t data);
4545 uint32_t read_io8(uint32_t addr);
46+ void decl_state();
4647 void save_state(FILEIO* state_fio);
4748 bool load_state(FILEIO* state_fio);
4849
--- a/source/src/vm/pasopia7/pac2dev.h
+++ b/source/src/vm/pasopia7/pac2dev.h
@@ -14,11 +14,13 @@
1414 #include "../vm.h"
1515 #include "../../emu.h"
1616
17+class csp_state_utils;
1718 class PAC2DEV
1819 {
1920 protected:
2021 VM* vm;
2122 EMU* emu;
23+ csp_state_utils *state_entry;
2224 public:
2325 PAC2DEV(VM* parent_vm, EMU* parent_emu) : vm(parent_vm), emu(parent_emu)
2426 {
@@ -31,6 +33,7 @@ public:
3133 virtual void reset() {}
3234 virtual void write_io8(uint32_t addr, uint32_t data) {}
3335 virtual uint32_t read_io8(uint32_t addr) { return 0xff; }
36+ virtual void decl_state() { state_entry = NULL; }
3437 virtual void save_state(FILEIO* state_fio) {}
3538 virtual bool load_state(FILEIO* state_fio) { return true; }
3639
--- a/source/src/vm/pasopia7/rampac2.cpp
+++ b/source/src/vm/pasopia7/rampac2.cpp
@@ -96,25 +96,47 @@ void RAMPAC2::open_file(const _TCHAR* file_path)
9696
9797 #define STATE_VERSION 1
9898
99-void RAMPAC2::save_state(FILEIO* state_fio)
99+#include "../../statesub.h"
100+
101+void RAMPAC2::decl_state()
100102 {
101- state_fio->FputUint32(STATE_VERSION);
103+ state_entry = new csp_state_utils(STATE_VERSION, this_device_id, (const _TCHAR *)_T("PAC2SLOT::RAMPAC2"), NULL);
104+
105+ DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
106+ DECL_STATE_ENTRY_UINT32(ptr);
102107
103- state_fio->Fwrite(ram, sizeof(ram), 1);
104- state_fio->FputUint32(ptr);
105- state_fio->FputBool(opened);
106- state_fio->FputBool(modified);
108+ DECL_STATE_ENTRY_BOOL(opened);
109+ DECL_STATE_ENTRY_BOOL(modified);
110+ //leave_decl_state();
111+}
112+
113+void RAMPAC2::save_state(FILEIO* state_fio)
114+{
115+ if(state_entry != NULL) {
116+ state_entry->save_state(state_fio);
117+ }
118+// state_fio->FputUint32(STATE_VERSION);
119+//
120+// state_fio->Fwrite(ram, sizeof(ram), 1);
121+// state_fio->FputUint32(ptr);
122+// state_fio->FputBool(opened);
123+// state_fio->FputBool(modified);
107124 }
108125
109126 bool RAMPAC2::load_state(FILEIO* state_fio)
110127 {
111- if(state_fio->FgetUint32() != STATE_VERSION) {
112- return false;
128+ bool mb = false;
129+ if(state_entry != NULL) {
130+ mb = state_entry->load_state(state_fio);
113131 }
114- state_fio->Fread(ram, sizeof(ram), 1);
115- ptr = state_fio->FgetUint32();
116- opened = state_fio->FgetBool();
117- modified = state_fio->FgetBool();
132+ if(!mb) return false;
133+// if(state_fio->FgetUint32() != STATE_VERSION) {
134+// return false;
135+// }
136+// state_fio->Fread(ram, sizeof(ram), 1);
137+// ptr = state_fio->FgetUint32();
138+// opened = state_fio->FgetBool();
139+// modified = state_fio->FgetBool();
118140 return true;
119141 }
120142
--- a/source/src/vm/pasopia7/rampac2.h
+++ b/source/src/vm/pasopia7/rampac2.h
@@ -22,10 +22,12 @@ private:
2222 uint8_t ram[32*1024];
2323 uint32_t ptr;
2424 bool opened, modified;
25-
25+ int this_device_id;
2626 public:
2727 RAMPAC2(VM* parent_vm, EMU* parent_emu) : PAC2DEV(parent_vm, parent_emu)
2828 {
29+ static int num = 1;
30+ this_device_id = num++;
2931 set_device_name(_T("RAM PAC2"));
3032 }
3133 ~RAMPAC2() {}
@@ -37,6 +39,7 @@ public:
3739 void write_io8(uint32_t addr, uint32_t data);
3840 uint32_t read_io8(uint32_t addr);
3941 void open_file(const _TCHAR* file_path);
42+ void decl_state();
4043 void save_state(FILEIO* state_fio);
4144 bool load_state(FILEIO* state_fio);
4245 };
Show on old repository browser