From: K.Ohta Date: Sat, 30 Jun 2018 13:17:06 +0000 (+0900) Subject: [VM][FM16BETA][FM16PI][FP1100][FP200][STATE] Apply new state framework to these. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=991d7b6bcbcadb00f443fb2d6794ad585b08c0e0;p=csp-qt%2Fcommon_source_project-fm7.git [VM][FM16BETA][FM16PI][FP1100][FP200][STATE] Apply new state framework to these. --- diff --git a/source/src/vm/fm16beta/cmos.cpp b/source/src/vm/fm16beta/cmos.cpp index 544ac3135..9d44ada10 100644 --- a/source/src/vm/fm16beta/cmos.cpp +++ b/source/src/vm/fm16beta/cmos.cpp @@ -50,25 +50,48 @@ uint32_t CMOS::read_io8(uint32_t addr) #define STATE_VERSION 1 +#include "../../statesub.h" + +void CMOS::decl_state() +{ + enter_decl_state(STATE_VERSION); + + DECL_STATE_ENTRY_1D_ARRAY(cmos, sizeof(cmos)); + DECL_STATE_ENTRY_BOOL(modified); + + leave_decl_state(); +} void CMOS::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); - state_fio->Fwrite(cmos, sizeof(cmos), 1); - state_fio->FputBool(modified); +// state_fio->Fwrite(cmos, sizeof(cmos), 1); +// state_fio->FputBool(modified); } bool CMOS::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } - state_fio->Fread(cmos, sizeof(cmos), 1); - modified = state_fio->FgetBool(); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// state_fio->Fread(cmos, sizeof(cmos), 1); +// modified = state_fio->FgetBool(); return true; } diff --git a/source/src/vm/fm16beta/cmos.h b/source/src/vm/fm16beta/cmos.h index 2e5736b34..c09f3560d 100644 --- a/source/src/vm/fm16beta/cmos.h +++ b/source/src/vm/fm16beta/cmos.h @@ -32,6 +32,7 @@ public: void release(); void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); }; diff --git a/source/src/vm/fm16beta/keyboard.cpp b/source/src/vm/fm16beta/keyboard.cpp index fe7049676..eedbdd99b 100644 --- a/source/src/vm/fm16beta/keyboard.cpp +++ b/source/src/vm/fm16beta/keyboard.cpp @@ -75,31 +75,56 @@ void KEYBOARD::key_up(int code) #define STATE_VERSION 1 +#include "../../statesub.h" + +void KEYBOARD::decl_state() +{ + enter_decl_state(STATE_VERSION); + + DECL_STATE_ENTRY_FIFO(key_buf); + DECL_STATE_ENTRY_INT32(kbstat); + DECL_STATE_ENTRY_INT32(kbdata); + DECL_STATE_ENTRY_1D_ARRAY(table, sizeof(table)); + + leave_decl_state(); +} void KEYBOARD::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); - key_buf->save_state((void *)state_fio); - state_fio->FputInt32(kbstat); - state_fio->FputInt32(kbdata); - state_fio->Fwrite(table, sizeof(table), 1); +// key_buf->save_state((void *)state_fio); +// state_fio->FputInt32(kbstat); +// state_fio->FputInt32(kbdata); +// state_fio->Fwrite(table, sizeof(table), 1); } bool KEYBOARD::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; - } - if(state_fio->FgetInt32() != this_device_id) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(!key_buf->load_state((void *)state_fio)) { + if(!mb) { return false; } - kbstat = state_fio->FgetInt32(); - kbdata = state_fio->FgetInt32(); - state_fio->Fread(table, sizeof(table), 1); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// if(!key_buf->load_state((void *)state_fio)) { +// return false; +// } +// kbstat = state_fio->FgetInt32(); +// kbdata = state_fio->FgetInt32(); +// state_fio->Fread(table, sizeof(table), 1); return true; } diff --git a/source/src/vm/fm16beta/keyboard.h b/source/src/vm/fm16beta/keyboard.h index ca67d9b19..a0794f83e 100644 --- a/source/src/vm/fm16beta/keyboard.h +++ b/source/src/vm/fm16beta/keyboard.h @@ -73,6 +73,7 @@ public: void reset(); uint32_t read_io8(uint32_t addr); void event_frame(); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fm16beta/mainbus.cpp b/source/src/vm/fm16beta/mainbus.cpp index c6391d36d..f5ff57cab 100644 --- a/source/src/vm/fm16beta/mainbus.cpp +++ b/source/src/vm/fm16beta/mainbus.cpp @@ -424,21 +424,43 @@ void MAINBUS::update_int7() #define STATE_VERSION 1 +#include "../../statesub.h" + +void MAINBUS::decl_state() +{ + enter_decl_state(STATE_VERSION); + + + leave_decl_state(); +} + void MAINBUS::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); } bool MAINBUS::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } return true; } diff --git a/source/src/vm/fm16beta/mainbus.h b/source/src/vm/fm16beta/mainbus.h index 0d5127234..c6117d288 100644 --- a/source/src/vm/fm16beta/mainbus.h +++ b/source/src/vm/fm16beta/mainbus.h @@ -107,6 +107,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); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fm16beta/sub.cpp b/source/src/vm/fm16beta/sub.cpp index f6278facc..33ea2ee20 100644 --- a/source/src/vm/fm16beta/sub.cpp +++ b/source/src/vm/fm16beta/sub.cpp @@ -933,25 +933,48 @@ void SUB::draw_cg() #define STATE_VERSION 1 +#include "../../statesub.h" + +void SUB::decl_state() +{ + enter_decl_state(STATE_VERSION); + + MEMORY::decl_state(); // + + leave_decl_state(); +} + void SUB::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); - MEMORY::save_state(state_fio); +// MEMORY::save_state(state_fio); } bool SUB::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { - return false; - } - if(!MEMORY::load_state(state_fio)) { + if(!mb) { return false; } + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// if(!MEMORY::load_state(state_fio)) { +// return false; +// } return true; } diff --git a/source/src/vm/fm16beta/sub.h b/source/src/vm/fm16beta/sub.h index aa0465b6e..c43fe130e 100644 --- a/source/src/vm/fm16beta/sub.h +++ b/source/src/vm/fm16beta/sub.h @@ -104,6 +104,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); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fm16pi/sub.cpp b/source/src/vm/fm16pi/sub.cpp index 74c5ebbcd..b5eaaeef0 100644 --- a/source/src/vm/fm16pi/sub.cpp +++ b/source/src/vm/fm16pi/sub.cpp @@ -184,35 +184,63 @@ void SUB::draw_screen() #define STATE_VERSION 1 +#include "../../statesub.h" + +void SUB::decl_state() +{ + enter_decl_state(STATE_VERSION); + + DECL_STATE_ENTRY_FIFO(key_buffer); + DECL_STATE_ENTRY_UINT8(key_data); + DECL_STATE_ENTRY_BOOL(key_irq); + DECL_STATE_ENTRY_UINT8(fdc_drive); + DECL_STATE_ENTRY_UINT8(fdc_side); + DECL_STATE_ENTRY_UINT8(rtc_data); + + leave_decl_state(); +} + void SUB::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); - - key_buffer->save_state((void *)state_fio); - state_fio->FputUint8(key_data); - state_fio->FputBool(key_irq); - state_fio->FputUint8(fdc_drive); - state_fio->FputUint8(fdc_side); - state_fio->FputUint8(rtc_data); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); +// +// key_buffer->save_state((void *)state_fio); +// state_fio->FputUint8(key_data); +// state_fio->FputBool(key_irq); +// state_fio->FputUint8(fdc_drive); +// state_fio->FputUint8(fdc_side); +// state_fio->FputUint8(rtc_data); } bool SUB::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } - if(!key_buffer->load_state((void *)state_fio)) { - return false; - } - key_data = state_fio->FgetUint8(); - key_irq = state_fio->FgetBool(); - fdc_drive = state_fio->FgetUint8(); - fdc_side = state_fio->FgetUint8(); - rtc_data = state_fio->FgetUint8(); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// if(!key_buffer->load_state((void *)state_fio)) { +// return false; +// } +// key_data = state_fio->FgetUint8(); +// key_irq = state_fio->FgetBool(); +// fdc_drive = state_fio->FgetUint8(); +// fdc_side = state_fio->FgetUint8(); +// rtc_data = state_fio->FgetUint8(); return true; } diff --git a/source/src/vm/fm16pi/sub.h b/source/src/vm/fm16pi/sub.h index fda93944e..e5b31e894 100644 --- a/source/src/vm/fm16pi/sub.h +++ b/source/src/vm/fm16pi/sub.h @@ -45,6 +45,7 @@ public: uint32_t read_io8(uint32_t addr); void write_signal(int id, uint32_t data, uint32_t mask); void event_callback(int event_id, int err); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fp1100/main.cpp b/source/src/vm/fp1100/main.cpp index 8ae1d8c7a..1c7897016 100644 --- a/source/src/vm/fp1100/main.cpp +++ b/source/src/vm/fp1100/main.cpp @@ -248,37 +248,67 @@ void MAIN::notify_intr_ei() #define STATE_VERSION 3 +#include "../../statesub.h" + +void MAIN::decl_state() +{ + enter_decl_state(STATE_VERSION); + + DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); + DECL_STATE_ENTRY_UINT8(comm_data); + DECL_STATE_ENTRY_BOOL(rom_sel); + DECL_STATE_ENTRY_UINT8(slot_sel); + DECL_STATE_ENTRY_1D_ARRAY(slot_exp, sizeof(slot_exp)); + DECL_STATE_ENTRY_UINT8(intr_mask); + DECL_STATE_ENTRY_UINT8(intr_request); + DECL_STATE_ENTRY_UINT8(intr_in_service); + + leave_decl_state(); +} + void MAIN::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); - state_fio->Fwrite(ram, sizeof(ram), 1); - state_fio->FputUint8(comm_data); - state_fio->FputBool(rom_sel); - state_fio->FputUint8(slot_sel); - state_fio->Fwrite(slot_exp, sizeof(slot_exp), 1); - state_fio->FputUint8(intr_mask); - state_fio->FputUint8(intr_request); - state_fio->FputUint8(intr_in_service); +// state_fio->Fwrite(ram, sizeof(ram), 1); +// state_fio->FputUint8(comm_data); +// state_fio->FputBool(rom_sel); +// state_fio->FputUint8(slot_sel); +// state_fio->Fwrite(slot_exp, sizeof(slot_exp), 1); +// state_fio->FputUint8(intr_mask); +// state_fio->FputUint8(intr_request); +// state_fio->FputUint8(intr_in_service); } bool MAIN::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } - state_fio->Fread(ram, sizeof(ram), 1); - comm_data = state_fio->FgetUint8(); - rom_sel = state_fio->FgetBool(); - slot_sel = state_fio->FgetUint8(); - state_fio->Fread(slot_exp, sizeof(slot_exp), 1); - intr_mask = state_fio->FgetUint8(); - intr_request = state_fio->FgetUint8(); - intr_in_service = state_fio->FgetUint8(); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// state_fio->Fread(ram, sizeof(ram), 1); +// comm_data = state_fio->FgetUint8(); +// rom_sel = state_fio->FgetBool(); +// slot_sel = state_fio->FgetUint8(); +// state_fio->Fread(slot_exp, sizeof(slot_exp), 1); +// intr_mask = state_fio->FgetUint8(); +// intr_request = state_fio->FgetUint8(); +// intr_in_service = state_fio->FgetUint8(); // post process update_memory_map(); diff --git a/source/src/vm/fp1100/main.h b/source/src/vm/fp1100/main.h index 16acfdf88..0d32a8298 100644 --- a/source/src/vm/fp1100/main.h +++ b/source/src/vm/fp1100/main.h @@ -78,6 +78,7 @@ public: uint32_t get_intr_ack(); void notify_intr_reti(); void notify_intr_ei(); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fp1100/rampack.cpp b/source/src/vm/fp1100/rampack.cpp index c21654f0e..607bd31bf 100644 --- a/source/src/vm/fp1100/rampack.cpp +++ b/source/src/vm/fp1100/rampack.cpp @@ -56,25 +56,49 @@ uint32_t RAMPACK::read_io8(uint32_t addr) #define STATE_VERSION 1 +#include "../../statesub.h" + +void RAMPACK::decl_state() +{ + enter_decl_state(STATE_VERSION); + + DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); + DECL_STATE_ENTRY_BOOL(modified); + + leave_decl_state(); +} + void RAMPACK::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); - state_fio->Fwrite(ram, sizeof(ram), 1); - state_fio->FputBool(modified); +// state_fio->Fwrite(ram, sizeof(ram), 1); +// state_fio->FputBool(modified); } bool RAMPACK::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } - state_fio->Fread(ram, sizeof(ram), 1); - modified = state_fio->FgetBool(); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// state_fio->Fread(ram, sizeof(ram), 1); +// modified = state_fio->FgetBool(); return true; } diff --git a/source/src/vm/fp1100/rampack.h b/source/src/vm/fp1100/rampack.h index e40233f22..31830c36d 100644 --- a/source/src/vm/fp1100/rampack.h +++ b/source/src/vm/fp1100/rampack.h @@ -32,6 +32,7 @@ public: void release(); void write_io8(uint32_t addr, uint32_t data); uint32_t read_io8(uint32_t addr); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fp1100/sub.cpp b/source/src/vm/fp1100/sub.cpp index 866a5e4eb..b727df6bb 100644 --- a/source/src/vm/fp1100/sub.cpp +++ b/source/src/vm/fp1100/sub.cpp @@ -526,67 +526,165 @@ void SUB::draw_screen() #define STATE_VERSION 2 +#include "../../statesub.h" + +#define DECL_STATE_ENTRY_74LS74(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_d)); \ + DECL_STATE_ENTRY_BOOL((foo.in_ck)); \ + DECL_STATE_ENTRY_BOOL((foo.in_s)); \ + DECL_STATE_ENTRY_BOOL((foo.in_r)); \ + DECL_STATE_ENTRY_BOOL((foo.out_q)); \ + DECL_STATE_ENTRY_BOOL((foo.out_nq)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_ck)); \ + } + +#define DECL_STATE_ENTRY_74LS151(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_d0)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d1)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d2)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d3)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d4)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d5)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d6)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d7)); \ + DECL_STATE_ENTRY_BOOL((foo.in_a)); \ + DECL_STATE_ENTRY_BOOL((foo.in_b)); \ + DECL_STATE_ENTRY_BOOL((foo.in_c)); \ + DECL_STATE_ENTRY_BOOL((foo.in_s)); \ + DECL_STATE_ENTRY_BOOL((foo.out_y)); \ + DECL_STATE_ENTRY_BOOL((foo.out_ny)); \ + } + +#define DECL_STATE_ENTRY_74LS93(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_a)); \ + DECL_STATE_ENTRY_BOOL((foo.in_b)); \ + DECL_STATE_ENTRY_BOOL((foo.in_rc1)); \ + DECL_STATE_ENTRY_BOOL((foo.in_rc2)); \ + DECL_STATE_ENTRY_BOOL((foo.out_qa)); \ + DECL_STATE_ENTRY_BOOL((foo.out_qb)); \ + DECL_STATE_ENTRY_BOOL((foo.out_qc)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_a)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_b)); \ + DECL_STATE_ENTRY_UINT8((foo.counter_a)); \ + DECL_STATE_ENTRY_UINT8((foo.counter_b)); \ + } + +#define DECL_STATE_ENTRY_TC4024BP(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_ck)); \ + DECL_STATE_ENTRY_BOOL((foo.in_clr)); \ + DECL_STATE_ENTRY_BOOL((foo.out_q5)); \ + DECL_STATE_ENTRY_BOOL((foo.out_q6)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_ck)); \ + DECL_STATE_ENTRY_UINT8((foo.counter)); \ + } + +void SUB::decl_state() +{ + enter_decl_state(STATE_VERSION); + + DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram)); + DECL_STATE_ENTRY_1D_ARRAY(vram_b, sizeof(vram_b)); + DECL_STATE_ENTRY_1D_ARRAY(vram_r, sizeof(vram_r)); + DECL_STATE_ENTRY_1D_ARRAY(vram_g, sizeof(vram_g)); + DECL_STATE_ENTRY_UINT8(pa); + DECL_STATE_ENTRY_UINT8(pb); + DECL_STATE_ENTRY_UINT8(pc); + DECL_STATE_ENTRY_UINT8(comm_data); + DECL_STATE_ENTRY_BOOL(so); + DECL_STATE_ENTRY_UINT8(clock); + DECL_STATE_ENTRY_74LS74(b16_1); + DECL_STATE_ENTRY_74LS74(b16_2); + DECL_STATE_ENTRY_74LS74(g21_1); + DECL_STATE_ENTRY_74LS74(g21_2); + + DECL_STATE_ENTRY_74LS151(c15); + DECL_STATE_ENTRY_74LS93(c16); + + DECL_STATE_ENTRY_TC4024BP(f21); + + DECL_STATE_ENTRY_UINT8(key_sel); + DECL_STATE_ENTRY_UINT8(key_data); + DECL_STATE_ENTRY_UINT8(color_reg); + DECL_STATE_ENTRY_BOOL(hsync); + DECL_STATE_ENTRY_BOOL(wait); + DECL_STATE_ENTRY_UINT8(cblink); + + leave_decl_state(); +} + void SUB::save_state(FILEIO* state_fio) { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + if(state_entry != NULL) { + state_entry->save_state(state_fio); + } + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); - state_fio->Fwrite(ram, sizeof(ram), 1); - state_fio->Fwrite(vram_b, sizeof(vram_b), 1); - state_fio->Fwrite(vram_r, sizeof(vram_r), 1); - state_fio->Fwrite(vram_g, sizeof(vram_g), 1); - state_fio->FputUint8(pa); - state_fio->FputUint8(pb); - state_fio->FputUint8(pc); - state_fio->FputUint8(comm_data); - state_fio->FputBool(so); - state_fio->FputUint8(clock); - state_fio->Fwrite(&b16_1, sizeof(b16_1), 1); - state_fio->Fwrite(&b16_2, sizeof(b16_2), 1); - state_fio->Fwrite(&g21_1, sizeof(g21_1), 1); - state_fio->Fwrite(&g21_2, sizeof(g21_2), 1); - state_fio->Fwrite(&c15, sizeof(c15), 1); - state_fio->Fwrite(&c16, sizeof(c16), 1); - state_fio->Fwrite(&f21, sizeof(f21), 1); - state_fio->FputUint8(key_sel); - state_fio->FputUint8(key_data); - state_fio->FputUint8(color_reg); - state_fio->FputBool(hsync); - state_fio->FputBool(wait); - state_fio->FputUint8(cblink); +// state_fio->Fwrite(ram, sizeof(ram), 1); +// state_fio->Fwrite(vram_b, sizeof(vram_b), 1); +// state_fio->Fwrite(vram_r, sizeof(vram_r), 1); +// state_fio->Fwrite(vram_g, sizeof(vram_g), 1); +// state_fio->FputUint8(pa); +// state_fio->FputUint8(pb); +// state_fio->FputUint8(pc); +// state_fio->FputUint8(comm_data); +// state_fio->FputBool(so); +// state_fio->FputUint8(clock); +// state_fio->Fwrite(&b16_1, sizeof(b16_1), 1); +// state_fio->Fwrite(&b16_2, sizeof(b16_2), 1); +// state_fio->Fwrite(&g21_1, sizeof(g21_1), 1); +// state_fio->Fwrite(&g21_2, sizeof(g21_2), 1); +// state_fio->Fwrite(&c15, sizeof(c15), 1); +// state_fio->Fwrite(&c16, sizeof(c16), 1); +// state_fio->Fwrite(&f21, sizeof(f21), 1); +// state_fio->FputUint8(key_sel); +// state_fio->FputUint8(key_data); +// state_fio->FputUint8(color_reg); +// state_fio->FputBool(hsync); +// state_fio->FputBool(wait); +// state_fio->FputUint8(cblink); } bool SUB::load_state(FILEIO* state_fio) { - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } - state_fio->Fread(ram, sizeof(ram), 1); - state_fio->Fread(vram_b, sizeof(vram_b), 1); - state_fio->Fread(vram_r, sizeof(vram_r), 1); - state_fio->Fread(vram_g, sizeof(vram_g), 1); - pa = state_fio->FgetUint8(); - pb = state_fio->FgetUint8(); - pc = state_fio->FgetUint8(); - comm_data = state_fio->FgetUint8(); - so = state_fio->FgetBool(); - clock = state_fio->FgetUint8(); - state_fio->Fread(&b16_1, sizeof(b16_1), 1); - state_fio->Fread(&b16_2, sizeof(b16_2), 1); - state_fio->Fread(&g21_1, sizeof(g21_1), 1); - state_fio->Fread(&g21_2, sizeof(g21_2), 1); - state_fio->Fread(&c15, sizeof(c15), 1); - state_fio->Fread(&c16, sizeof(c16), 1); - state_fio->Fread(&f21, sizeof(f21), 1); - key_sel = state_fio->FgetUint8(); - key_data = state_fio->FgetUint8(); - color_reg = state_fio->FgetUint8(); - hsync = state_fio->FgetBool(); - wait = state_fio->FgetBool(); - cblink = state_fio->FgetUint8(); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// state_fio->Fread(ram, sizeof(ram), 1); +// state_fio->Fread(vram_b, sizeof(vram_b), 1); +// state_fio->Fread(vram_r, sizeof(vram_r), 1); +// state_fio->Fread(vram_g, sizeof(vram_g), 1); +// pa = state_fio->FgetUint8(); +// pb = state_fio->FgetUint8(); +// pc = state_fio->FgetUint8(); +// comm_data = state_fio->FgetUint8(); +// so = state_fio->FgetBool(); +// clock = state_fio->FgetUint8(); +// state_fio->Fread(&b16_1, sizeof(b16_1), 1); +// state_fio->Fread(&b16_2, sizeof(b16_2), 1); +// state_fio->Fread(&g21_1, sizeof(g21_1), 1); +// state_fio->Fread(&g21_2, sizeof(g21_2), 1); +// state_fio->Fread(&c15, sizeof(c15), 1); +// state_fio->Fread(&c16, sizeof(c16), 1); +// state_fio->Fread(&f21, sizeof(f21), 1); +// key_sel = state_fio->FgetUint8(); +// key_data = state_fio->FgetUint8(); +// color_reg = state_fio->FgetUint8(); +// hsync = state_fio->FgetBool(); +// wait = state_fio->FgetBool(); +// cblink = state_fio->FgetUint8(); return true; } diff --git a/source/src/vm/fp1100/sub.h b/source/src/vm/fp1100/sub.h index 0130808ca..9c48964c2 100644 --- a/source/src/vm/fp1100/sub.h +++ b/source/src/vm/fp1100/sub.h @@ -184,6 +184,7 @@ public: void write_signal(int id, uint32_t data, uint32_t mask); void event_frame(); void event_callback(int event_id, int err); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio); diff --git a/source/src/vm/fp200/io.cpp b/source/src/vm/fp200/io.cpp index a3a57b4e0..9a36b6b6b 100644 --- a/source/src/vm/fp200/io.cpp +++ b/source/src/vm/fp200/io.cpp @@ -624,100 +624,206 @@ void IO::draw_screen() } } -#define STATE_VERSION 2 +#define STATE_VERSION 3 + +#include "../../statesub.h" + +#define DECL_STATE_ENTRY_74LS74(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_d)); \ + DECL_STATE_ENTRY_BOOL((foo.in_ck)); \ + DECL_STATE_ENTRY_BOOL((foo.in_s)); \ + DECL_STATE_ENTRY_BOOL((foo.in_r)); \ + DECL_STATE_ENTRY_BOOL((foo.out_q)); \ + DECL_STATE_ENTRY_BOOL((foo.out_nq)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_ck)); \ + } -void IO::save_state(FILEIO* state_fio) +#define DECL_STATE_ENTRY_74LS151(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_d0)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d1)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d2)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d3)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d4)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d5)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d6)); \ + DECL_STATE_ENTRY_BOOL((foo.in_d7)); \ + DECL_STATE_ENTRY_BOOL((foo.in_a)); \ + DECL_STATE_ENTRY_BOOL((foo.in_b)); \ + DECL_STATE_ENTRY_BOOL((foo.in_c)); \ + DECL_STATE_ENTRY_BOOL((foo.in_s)); \ + DECL_STATE_ENTRY_BOOL((foo.out_y)); \ + DECL_STATE_ENTRY_BOOL((foo.out_ny)); \ + } + +#define DECL_STATE_ENTRY_74LS93(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_a)); \ + DECL_STATE_ENTRY_BOOL((foo.in_b)); \ + DECL_STATE_ENTRY_BOOL((foo.in_rc1)); \ + DECL_STATE_ENTRY_BOOL((foo.in_rc2)); \ + DECL_STATE_ENTRY_BOOL((foo.out_qa)); \ + DECL_STATE_ENTRY_BOOL((foo.out_qb)); \ + DECL_STATE_ENTRY_BOOL((foo.out_qc)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_a)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_b)); \ + DECL_STATE_ENTRY_UINT8((foo.counter_a)); \ + DECL_STATE_ENTRY_UINT8((foo.counter_b)); \ + } + +#define DECL_STATE_ENTRY_TC4024BP(foo) { \ + DECL_STATE_ENTRY_BOOL((foo.in_ck)); \ + DECL_STATE_ENTRY_BOOL((foo.in_clr)); \ + DECL_STATE_ENTRY_BOOL((foo.out_q5)); \ + DECL_STATE_ENTRY_BOOL((foo.out_q6)); \ + DECL_STATE_ENTRY_BOOL((foo.tmp_ck)); \ + DECL_STATE_ENTRY_UINT8((foo.counter)); \ + } + +void IO::decl_state() { - state_fio->FputUint32(STATE_VERSION); - state_fio->FputInt32(this_device_id); + enter_decl_state(STATE_VERSION); + + for(int i = 0; i < 2; i++) { + DECL_STATE_ENTRY_1D_ARRAY_MEMBER(lcd[i].ram, sizeof(lcd[0].ram), i); + DECL_STATE_ENTRY_INT32_MEMBER((lcd[i].offset), i); + DECL_STATE_ENTRY_INT32_MEMBER((lcd[i].cursor), i); + } + DECL_STATE_ENTRY_INT32(lcd_status); + DECL_STATE_ENTRY_INT32(lcd_addr); + DECL_STATE_ENTRY_BOOL(lcd_text); + DECL_STATE_ENTRY_BOOL(cmt_selected); + DECL_STATE_ENTRY_UINT8(cmt_mode); + DECL_STATE_ENTRY_BOOL(cmt_play_ready); + DECL_STATE_ENTRY_BOOL(cmt_play_signal); + DECL_STATE_ENTRY_BOOL(cmt_rec_ready); + DECL_STATE_ENTRY_BOOL(cmt_rec); + DECL_STATE_ENTRY_BOOL(cmt_is_wav); + DECL_STATE_ENTRY_STRING(cmt_rec_file_path, sizeof(cmt_rec_file_path)); + DECL_STATE_ENTRY_CMT_RECORDING(cmt_fio, cmt_rec, cmt_rec_file_path); - state_fio->Fwrite(lcd, sizeof(lcd), 1); - state_fio->FputInt32(lcd_status); - state_fio->FputInt32(lcd_addr); - state_fio->FputBool(lcd_text); - state_fio->FputBool(cmt_selected); - state_fio->FputUint8(cmt_mode); - state_fio->FputBool(cmt_play_ready); - state_fio->FputBool(cmt_play_signal); - state_fio->FputBool(cmt_rec_ready); - state_fio->FputBool(cmt_rec); - state_fio->FputBool(cmt_is_wav); - state_fio->Fwrite(cmt_rec_file_path, sizeof(cmt_rec_file_path), 1); - if(cmt_rec && cmt_fio->IsOpened()) { - int length_tmp = (int)cmt_fio->Ftell(); - cmt_fio->Fseek(0, FILEIO_SEEK_SET); - state_fio->FputInt32(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(0); + DECL_STATE_ENTRY_INT32(cmt_bufcnt); + // ToDo: Write cmt_buffer only used (indicated by cmt_bufcnt). + DECL_STATE_ENTRY_1D_ARRAY(cmt_buffer, sizeof(cmt_buffer)); + + DECL_STATE_ENTRY_UINT8(cmt_clock); + DECL_STATE_ENTRY_74LS74(b16_1); + DECL_STATE_ENTRY_74LS74(b16_2); + DECL_STATE_ENTRY_74LS74(g21_1); + DECL_STATE_ENTRY_74LS74(g21_2); + + DECL_STATE_ENTRY_74LS151(c15); + + DECL_STATE_ENTRY_74LS93(c16); + + DECL_STATE_ENTRY_TC4024BP(f21); + DECL_STATE_ENTRY_UINT8(key_column); + + leave_decl_state(); +} + +void IO::save_state(FILEIO* state_fio) +{ + if(state_entry != NULL) { + state_entry->save_state(state_fio); } - state_fio->FputInt32(cmt_bufcnt); - state_fio->Fwrite(cmt_buffer, cmt_bufcnt, 1); - state_fio->FputUint8(cmt_clock); - state_fio->Fwrite(&b16_1, sizeof(b16_1), 1); - state_fio->Fwrite(&b16_2, sizeof(b16_2), 1); - state_fio->Fwrite(&g21_1, sizeof(g21_1), 1); - state_fio->Fwrite(&g21_2, sizeof(g21_2), 1); - state_fio->Fwrite(&c15, sizeof(c15), 1); - state_fio->Fwrite(&c16, sizeof(c16), 1); - state_fio->Fwrite(&f21, sizeof(f21), 1); - state_fio->FputUint8(key_column); + +// state_fio->FputUint32(STATE_VERSION); +// state_fio->FputInt32(this_device_id); + +// state_fio->Fwrite(lcd, sizeof(lcd), 1); +// state_fio->FputInt32(lcd_status); +// state_fio->FputInt32(lcd_addr); +// state_fio->FputBool(lcd_text); +// state_fio->FputBool(cmt_selected); +// state_fio->FputUint8(cmt_mode); +// state_fio->FputBool(cmt_play_ready); +// state_fio->FputBool(cmt_play_signal); +// state_fio->FputBool(cmt_rec_ready); +// state_fio->FputBool(cmt_rec); +// state_fio->FputBool(cmt_is_wav); +// state_fio->Fwrite(cmt_rec_file_path, sizeof(cmt_rec_file_path), 1); +// if(cmt_rec && cmt_fio->IsOpened()) { +// int length_tmp = (int)cmt_fio->Ftell(); +// cmt_fio->Fseek(0, FILEIO_SEEK_SET); +/// state_fio->FputInt32(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(0); +// } +// state_fio->FputInt32(cmt_bufcnt); +// state_fio->Fwrite(cmt_buffer, cmt_bufcnt, 1); +// state_fio->FputUint8(cmt_clock); +// state_fio->Fwrite(&b16_1, sizeof(b16_1), 1); +// state_fio->Fwrite(&b16_2, sizeof(b16_2), 1); +// state_fio->Fwrite(&g21_1, sizeof(g21_1), 1); +// state_fio->Fwrite(&g21_2, sizeof(g21_2), 1); +// state_fio->Fwrite(&c15, sizeof(c15), 1); +// state_fio->Fwrite(&c16, sizeof(c16), 1); +// state_fio->Fwrite(&f21, sizeof(f21), 1); +// state_fio->FputUint8(key_column); } bool IO::load_state(FILEIO* state_fio) { close_tape(); - if(state_fio->FgetUint32() != STATE_VERSION) { - return false; + bool mb = false; + if(state_entry != NULL) { + mb = state_entry->load_state(state_fio); } - if(state_fio->FgetInt32() != this_device_id) { + if(!mb) { return false; } - state_fio->Fread(lcd, sizeof(lcd), 1); - lcd_status = state_fio->FgetInt32(); - lcd_addr = state_fio->FgetInt32(); - lcd_text = state_fio->FgetBool(); - cmt_selected = state_fio->FgetBool(); - cmt_mode = state_fio->FgetUint8(); - cmt_play_ready = state_fio->FgetBool(); - cmt_play_signal = state_fio->FgetBool(); - cmt_rec_ready = state_fio->FgetBool(); - cmt_rec = state_fio->FgetBool(); - cmt_is_wav = state_fio->FgetBool(); - state_fio->Fread(cmt_rec_file_path, sizeof(cmt_rec_file_path), 1); - int length_tmp = state_fio->FgetInt32(); - 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; - } - } - cmt_bufcnt = state_fio->FgetInt32(); - if(cmt_bufcnt) { - state_fio->Fread(cmt_buffer, cmt_bufcnt, 1); - } - cmt_clock = state_fio->FgetUint8(); - state_fio->Fread(&b16_1, sizeof(b16_1), 1); - state_fio->Fread(&b16_2, sizeof(b16_2), 1); - state_fio->Fread(&g21_1, sizeof(g21_1), 1); - state_fio->Fread(&g21_2, sizeof(g21_2), 1); - state_fio->Fread(&c15, sizeof(c15), 1); - state_fio->Fread(&c16, sizeof(c16), 1); - state_fio->Fread(&f21, sizeof(f21), 1); - key_column = state_fio->FgetUint8(); + +// if(state_fio->FgetUint32() != STATE_VERSION) { +// return false; +// } +// if(state_fio->FgetInt32() != this_device_id) { +// return false; +// } +// state_fio->Fread(lcd, sizeof(lcd), 1); +// lcd_status = state_fio->FgetInt32(); +// lcd_addr = state_fio->FgetInt32(); +// lcd_text = state_fio->FgetBool(); +// cmt_selected = state_fio->FgetBool(); +// cmt_mode = state_fio->FgetUint8(); +// cmt_play_ready = state_fio->FgetBool(); +// cmt_play_signal = state_fio->FgetBool(); +// cmt_rec_ready = state_fio->FgetBool(); +// cmt_rec = state_fio->FgetBool(); +// cmt_is_wav = state_fio->FgetBool(); +// state_fio->Fread(cmt_rec_file_path, sizeof(cmt_rec_file_path), 1); +// int length_tmp = state_fio->FgetInt32(); +// 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; +// } +// } +// cmt_bufcnt = state_fio->FgetInt32(); +// if(cmt_bufcnt) { +// state_fio->Fread(cmt_buffer, cmt_bufcnt, 1); +// } +// cmt_clock = state_fio->FgetUint8(); +// state_fio->Fread(&b16_1, sizeof(b16_1), 1); +// state_fio->Fread(&b16_2, sizeof(b16_2), 1); +// state_fio->Fread(&g21_1, sizeof(g21_1), 1); +// state_fio->Fread(&g21_2, sizeof(g21_2), 1); +// state_fio->Fread(&c15, sizeof(c15), 1); +/// state_fio->Fread(&c16, sizeof(c16), 1); +// state_fio->Fread(&f21, sizeof(f21), 1); +// key_column = state_fio->FgetUint8(); return true; } diff --git a/source/src/vm/fp200/io.h b/source/src/vm/fp200/io.h index 0a6f7beba..b99c97ce9 100644 --- a/source/src/vm/fp200/io.h +++ b/source/src/vm/fp200/io.h @@ -166,6 +166,7 @@ public: uint32_t read_io8w(uint32_t addr, int* wait); void write_signal(int id, uint32_t data, uint32_t mask); void event_callback(int event_id, int err); + void decl_state(); void save_state(FILEIO* state_fio); bool load_state(FILEIO* state_fio);