for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
- decl_state();
}
VM::~VM()
#define STATE_VERSION 2
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
+bool VM::process_state(FILEIO* state_fio, bool loading)
{
- state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::BABBAGE2ND_HEAD")), csp_logger);
- DECL_STATE_ENTRY_MULTI(void, ram, sizeof(ram));
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->decl_state();
- }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
- //state_fio->FputUint32(STATE_VERSION);
-
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->save_state(state_fio);
- }
- //state_fio->Fwrite(ram, sizeof(ram), 1);
-}
-
-bool VM::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
- }
- if(!mb) {
- emu->out_debug_log("INFO: HEADER DATA ERROR");
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- if(!device->load_state(state_fio)) {
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ for(DEVICE* device = first_device; device; device = device->next_device) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
return false;
}
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ if(loading) {
+ update_config();
}
- return true;
+ return true;
}
-
bool is_frame_skippable();
void update_config();
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// for each device
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void DISPLAY::decl_state()
-{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_2D_ARRAY(seg, 6, 7);
- DECL_STATE_ENTRY_UINT8(ls373);
- DECL_STATE_ENTRY_UINT8(pio_7seg);
- DECL_STATE_ENTRY_UINT8(pio_8bit);
-
- leave_decl_state();
-}
-
-void DISPLAY::save_state(FILEIO* state_fio)
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
- //state_fio->FputUint32(STATE_VERSION);
- //state_fio->FputInt32(this_device_id);
-
- //state_fio->Fwrite(seg, sizeof(seg), 1);
- //state_fio->FputUint8(ls373);
- //state_fio->FputUint8(pio_7seg);
- //state_fio->FputUint8(pio_8bit);
-}
-
-bool DISPLAY::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
- //if(state_fio->FgetUint32() != STATE_VERSION) {
- // return false;
- //}
- //if(state_fio->FgetInt32() != this_device_id) {
- // return false;
- //}
- //state_fio->Fread(seg, sizeof(seg), 1);
- //ls373 = state_fio->FgetUint8();
- //pio_7seg = state_fio->FgetUint8();
- //pio_8bit = state_fio->FgetUint8();
+ state_fio->StateBuffer(seg, sizeof(seg), 1);
+ state_fio->StateUint8(ls373);
+ state_fio->StateUint8(pio_7seg);
+ state_fio->StateUint8(pio_8bit);
return true;
}
-
void initialize();
void write_signal(int id, uint32_t data, uint32_t mask);
void event_vline(int v, int clock);
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// unique function
void draw_screen();
for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
- decl_state();
}
VM::~VM()
#define STATE_VERSION 3
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-void VM::decl_state(void)
+bool VM::process_state(FILEIO* state_fio, bool loading)
{
- state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::BASIC_MASTER_HEAD")), csp_logger);
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->decl_state();
- }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
- //state_fio->FputUint32(STATE_VERSION);
-
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->save_state(state_fio);
- }
-}
-
-bool VM::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(!mb) {
- emu->out_debug_log("INFO: HEADER DATA ERROR");
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- if(!device->load_state(state_fio)) {
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ for(DEVICE* device = first_device; device; device = device->next_device) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
return false;
}
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+ if(loading) {
+ update_config();
}
- return true;
+ return true;
}
-
bool is_frame_skippable();
void update_config();
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// for each device
#define STATE_VERSION 2
-#include "../../statesub.h"
-
-void MEMORY::decl_state()
-{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
- DECL_STATE_ENTRY_UINT8(memory_bank);
-
- DECL_STATE_ENTRY_1D_ARRAY(color_table, sizeof(color_table));
- DECL_STATE_ENTRY_UINT8(char_color);
- DECL_STATE_ENTRY_UINT8(back_color);
- DECL_STATE_ENTRY_UINT8(mp1710_enb);
- DECL_STATE_ENTRY_UINT8(screen_mode);
- DECL_STATE_ENTRY_BOOL(screen_reversed);
- DECL_STATE_ENTRY_BOOL(drec_bit);
- DECL_STATE_ENTRY_BOOL(drec_in);
- DECL_STATE_ENTRY_UINT32(drec_clock);
- DECL_STATE_ENTRY_UINT8(key_column);
- DECL_STATE_ENTRY_UINT8(key_data);
- DECL_STATE_ENTRY_BOOL(nmi_enb);
- DECL_STATE_ENTRY_BOOL(break_pressed);
- DECL_STATE_ENTRY_UINT8(sound_sample);
- DECL_STATE_ENTRY_DOUBLE(sound_accum);
- DECL_STATE_ENTRY_UINT32(sound_clock);
- DECL_STATE_ENTRY_UINT32(sound_mix_clock);
-
- leave_decl_state();
-}
-
-void MEMORY::save_state(FILEIO* state_fio)
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
- //state_fio->FputUint32(STATE_VERSION);
- //state_fio->FputInt32(this_device_id);
-
- //state_fio->Fwrite(ram, sizeof(ram), 1);
- //state_fio->FputUint8(memory_bank);
- //state_fio->Fwrite(color_table, sizeof(color_table), 1);
- //state_fio->FputUint8(char_color);
- //state_fio->FputUint8(back_color);
- //state_fio->FputUint8(mp1710_enb);
- //state_fio->FputUint8(screen_mode);
- //state_fio->FputBool(screen_reversed);
- //state_fio->FputBool(drec_bit);
- //state_fio->FputBool(drec_in);
- //state_fio->FputUint32(drec_clock);
- //state_fio->FputUint8(key_column);
- //state_fio->FputUint8(key_data);
- //state_fio->FputBool(nmi_enb);
- //state_fio->FputBool(break_pressed);
- //state_fio->FputUint8(sound_sample);
- //state_fio->FputDouble(sound_accum);
- //state_fio->FputUint32(sound_clock);
- //state_fio->FputUint32(sound_mix_clock);
-}
-
-bool MEMORY::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
- //if(state_fio->FgetUint32() != STATE_VERSION) {
- // return false;
- //}
- //if(state_fio->FgetInt32() != this_device_id) {
- // return false;
- //}
- //state_fio->Fread(ram, sizeof(ram), 1);
- //memory_bank = state_fio->FgetUint8();
- //state_fio->Fread(color_table, sizeof(color_table), 1);
- //char_color = state_fio->FgetUint8();
- //back_color = state_fio->FgetUint8();
- //mp1710_enb = state_fio->FgetUint8();
- //screen_mode = state_fio->FgetUint8();
- //screen_reversed = state_fio->FgetBool();
- //drec_bit = state_fio->FgetBool();
- //drec_in = state_fio->FgetBool();
- //drec_clock = state_fio->FgetUint32();
- //key_column = state_fio->FgetUint8();
- //key_data = state_fio->FgetUint8();
- //nmi_enb = state_fio->FgetBool();
- //break_pressed = state_fio->FgetBool();
- //sound_sample = state_fio->FgetUint8();
- //sound_accum = state_fio->FgetDouble();
- //sound_clock = state_fio->FgetUint32();
- //sound_mix_clock = state_fio->FgetUint32();
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ state_fio->StateUint8(memory_bank);
+ state_fio->StateBuffer(color_table, sizeof(color_table), 1);
+ state_fio->StateUint8(char_color);
+ state_fio->StateUint8(back_color);
+ state_fio->StateUint8(mp1710_enb);
+ state_fio->StateUint8(screen_mode);
+ state_fio->StateBool(screen_reversed);
+ state_fio->StateBool(drec_bit);
+ state_fio->StateBool(drec_in);
+ state_fio->StateUint32(drec_clock);
+ state_fio->StateUint8(key_column);
+ state_fio->StateUint8(key_data);
+ state_fio->StateBool(nmi_enb);
+ state_fio->StateBool(break_pressed);
+ state_fio->StateUint8(sound_sample);
+ state_fio->StateDouble(sound_accum);
+ state_fio->StateUint32(sound_clock);
+ state_fio->StateUint32(sound_mix_clock);
// post process
- update_bank();
+ if(loading) {
+ update_bank();
+ }
return true;
}
-
void event_frame();
void mix(int32_t* buffer, int cnt);
void set_volume(int ch, int decibel_l, int decibel_r);
- void decl_state();
- 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_drec(DEVICE* device)
#define STATE_VERSION 2
-#include "../../statesub.h"
-
-void BUBBLECASETTE::decl_state()
+bool BUBBLECASETTE::process_state(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
-
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
// Attributes
- DECL_STATE_ENTRY_UINT32(file_length);
- DECL_STATE_ENTRY_BOOL(bubble_inserted);
- DECL_STATE_ENTRY_INT32(bubble_type);
- DECL_STATE_ENTRY_INT32(media_num);
- DECL_STATE_ENTRY_UINT32(media_offset);
- DECL_STATE_ENTRY_UINT32(media_offset_new);
- DECL_STATE_ENTRY_UINT32(media_size);
+ state_fio->StateUint32(file_length);
+ state_fio->StateBool(bubble_inserted);
+ state_fio->StateInt32(bubble_type);
+ state_fio->StateInt32(media_num);
+ state_fio->StateUint32(media_offset);
+ state_fio->StateUint32(media_offset_new);
+ state_fio->StateUint32(media_size);
// Data reg
- DECL_STATE_ENTRY_UINT8(data_reg);
+ state_fio->StateUint8(data_reg);
// Command reg
- DECL_STATE_ENTRY_UINT8(cmd_reg);
+ state_fio->StateUint8(cmd_reg);
// Status reg
- DECL_STATE_ENTRY_BOOL(stat_busy);
- DECL_STATE_ENTRY_BOOL(stat_tdra);
- DECL_STATE_ENTRY_BOOL(stat_rda);
- DECL_STATE_ENTRY_BOOL(cmd_error);
- DECL_STATE_ENTRY_BOOL(stat_error);
- DECL_STATE_ENTRY_BOOL(not_ready);
+ state_fio->StateBool(stat_busy);
+ state_fio->StateBool(stat_tdra);
+ state_fio->StateBool(stat_rda);
+ state_fio->StateBool(cmd_error);
+ state_fio->StateBool(stat_error);
+ state_fio->StateBool(not_ready);
// Error reg
- DECL_STATE_ENTRY_BOOL(eject_error);
- DECL_STATE_ENTRY_BOOL(povr_error);
- DECL_STATE_ENTRY_BOOL(crc_error);
- DECL_STATE_ENTRY_BOOL(transfer_error);
- DECL_STATE_ENTRY_BOOL(bad_loop_over_error);
- DECL_STATE_ENTRY_BOOL(no_marker_error);
- DECL_STATE_ENTRY_BOOL(undefined_cmd_error);
+ state_fio->StateBool(eject_error);
+ state_fio->StateBool(povr_error);
+ state_fio->StateBool(crc_error);
+ state_fio->StateBool(transfer_error);
+ state_fio->StateBool(bad_loop_over_error);
+ state_fio->StateBool(no_marker_error);
+ state_fio->StateBool(undefined_cmd_error);
// Page address
- DECL_STATE_ENTRY_UINT32(page_address.d);
+ state_fio->StateUint32(page_address.d);
//Page Count
- DECL_STATE_ENTRY_UINT32(page_count.d);
+ state_fio->StateUint32(page_count.d);
// Misc flags
- DECL_STATE_ENTRY_BOOL(is_b77);
- DECL_STATE_ENTRY_BOOL(read_access);
- DECL_STATE_ENTRY_BOOL(write_access);
- DECL_STATE_ENTRY_BOOL(write_protect);
- DECL_STATE_ENTRY_UINT8(offset_reg);
- DECL_STATE_ENTRY_STRING(image_path, _MAX_PATH);
+ state_fio->StateBool(is_b77);
+ state_fio->StateBool(read_access);
+ state_fio->StateBool(write_access);
+ state_fio->StateBool(write_protect);
+ state_fio->StateUint8(offset_reg);
- leave_decl_state();
-}
-void BUBBLECASETTE::save_state(FILEIO *state_fio)
-{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
-
-// int i, j;
-// state_fio->FputUint32_BE(STATE_VERSION);
-// state_fio->FputInt32_BE(this_device_id);
-// this->out_debug_log(_T("Save State: BUBBLE: id=%d ver=%d\n"), this_device_id, STATE_VERSION);
-
- // Attributes
-// state_fio->FputUint32_BE(file_length);
-// state_fio->FputBool(bubble_inserted);
-// state_fio->FputInt32_BE(bubble_type);
-// state_fio->FputInt32_BE(media_num);
-// state_fio->FputUint32_BE(media_offset);
-// state_fio->FputUint32_BE(media_offset_new);
-// state_fio->FputUint32_BE(media_size);
- // Data reg
-// state_fio->FputUint8(data_reg);
-// // Command reg
-// state_fio->FputUint8(cmd_reg);
- // Status reg
-// state_fio->FputBool(stat_busy);
-// state_fio->FputBool(stat_tdra);
-// state_fio->FputBool(stat_rda);
-// state_fio->FputBool(cmd_error);
-// state_fio->FputBool(stat_error);
-// state_fio->FputBool(not_ready);
- // Error reg
-// state_fio->FputBool(eject_error);
-// state_fio->FputBool(povr_error);
-// state_fio->FputBool(crc_error);
-// state_fio->FputBool(transfer_error);
-// state_fio->FputBool(bad_loop_over_error);
-// state_fio->FputBool(no_marker_error);
-// state_fio->FputBool(undefined_cmd_error);
- // Page address
-// state_fio->FputUint32_BE(page_address.d);
- //Page Count
-// state_fio->FputUint32_BE(page_count.d);
- // Misc flags
-// state_fio->FputBool(is_b77);
-// state_fio->FputBool(read_access);
-// state_fio->FputBool(write_access);
-// state_fio->FputBool(write_protect);
-// state_fio->FputUint8(offset_reg);
-
+ state_fio->StateBuffer(image_path, _MAX_PATH * sizeof(_TCHAR), 1);
-// state_fio->Fwrite(image_path, _MAX_PATH * sizeof(_TCHAR), 1);
- if(fio != NULL) {
- if(fio->IsOpened()) {
+ // post process
+ if(loading) {
+ if(_tcslen(image_path) > 0) {
+ this->open(image_path, (int)media_num);
+ }
+ } else {
+ if(fio != NULL && fio->IsOpened()) {
if(is_wrote) write_one_page();
if(is_b77) {
if(header_changed) {
}
}
}
-}
-
-bool BUBBLECASETTE::load_state(FILEIO *state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
- }
- if(!mb) return false;
-// int i, j;
-// if(state_fio->FgetUint32_BE() != STATE_VERSION) return false;
-// if(state_fio->FgetInt32_BE() != this_device_id) return false;
-// this->out_debug_log(_T("Load State: BUBBLE: id=%d ver=%d\n"), this_device_id, STATE_VERSION);
-
- // Attributes
-// file_length = state_fio->FgetUint32_BE();
-// bubble_inserted = state_fio->FgetBool();
-// bubble_type = state_fio->FgetInt32_BE();
-// media_num = state_fio->FgetInt32_BE();
-// media_offset = state_fio->FgetInt32_BE();
-// media_offset_new = state_fio->FgetInt32_BE();
-// media_size = state_fio->FgetInt32_BE();
- // Data reg
-// data_reg = state_fio->FgetUint8();
- // Command reg
-// cmd_reg = state_fio->FgetUint8();
- // Status reg
-// stat_busy = state_fio->FgetBool();
-// stat_tdra = state_fio->FgetBool();
-// stat_rda = state_fio->FgetBool();
-// cmd_error = state_fio->FgetBool();
-// stat_error = state_fio->FgetBool();
-// not_ready = state_fio->FgetBool();
- // Error reg
-// eject_error = state_fio->FgetBool();
-// povr_error = state_fio->FgetBool();
-// crc_error = state_fio->FgetBool();
-// transfer_error = state_fio->FgetBool();
-// bad_loop_over_error = state_fio->FgetBool();
-// no_marker_error = state_fio->FgetBool();
-// undefined_cmd_error = state_fio->FgetBool();
- // Page address
-// page_address.d = state_fio->FgetUint32_BE();
- //Page Count
-// page_count.d = state_fio->FgetUint32_BE();
- // Misc flags
-// is_b77 = state_fio->FgetBool();
-// read_access = state_fio->FgetBool();
-// write_access = state_fio->FgetBool();
-// write_protect = state_fio->FgetBool();
-// offset_reg = state_fio->FgetUint8();
- is_wrote = false;
- header_changed = false;
-
- //if(state_fio->Fread(image_path, _MAX_PATH * sizeof(_TCHAR), 1) != (_MAX_PATH * sizeof(_TCHAR))) return false;
- if(_tcslen(image_path) > 0) {
- this->open(image_path, (int)media_num);
- }
return true;
}
-
uint32_t read_signal(int id);
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);
+ bool process_state(FILEIO* state_fio, bool loading);
// unique functions
void open(_TCHAR* file_path, int bank);
for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
- decl_state(); // You should put this line after this to every VMs.20180601 K.O
for(int i = 0; i < MAX_DRIVE; i++) {
fdc->set_drive_type(i, DRIVE_TYPE_2HD); // 8inch 2D
#define STATE_VERSION 1
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
- state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::BUBCOM_80_HEAD")), csp_logger);
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->decl_state();
- }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
- //state_fio->FputUint32(STATE_VERSION);
-
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- // Suggestion:
- // Will stop to decl. class-name at VM::save_state(),
- // will decl. at FOO_DEVICE::decl_state(). 20180601 K.Ohta
- //const char *name = typeid(*device).name() + 6; // skip "class "
- //state_fio->FputInt32(strlen(name));
- //state_fio->Fwrite(name, strlen(name), 1);
- device->save_state(state_fio);
- }
-}
-
-bool VM::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(!mb) {
- emu->out_debug_log("INFO: HEADER DATA ERROR");
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- ///const char *name = typeid(*device).name() + 6; // skip "class "
+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) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
- //if(!(state_fio->FgetInt32() == strlen(name) && state_fio->Fcompare(name, strlen(name)))) {
- // return false;
- //}
- if(!device->load_state(state_fio)) {
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
return false;
}
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+ if(loading) {
+ update_config();
}
- return true;
+ //mainio->restore_opn();
+ return true;
}
-
bool is_frame_skippable();
void update_config();
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// for each device
#define STATE_VERSION 3
-#include "../../statesub.h"
-
-void CMT::decl_state()
-{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_BOOL(play);
- DECL_STATE_ENTRY_BOOL(rec);
- DECL_STATE_ENTRY_BOOL(remote);
- DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path));
- DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
-
- DECL_STATE_ENTRY_INT32(bufcnt);
- DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
-
- leave_decl_state();
-}
-void CMT::save_state(FILEIO* state_fio)
+bool CMT::process_state(FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->FputBool(play);
-// state_fio->FputBool(rec);
-// state_fio->FputBool(remote);
-// state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
-#if 0
- if(rec && fio->IsOpened()) {
- int length_tmp = (int)fio->Ftell();
- 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));
- fio->Fread(buffer_tmp, length_rw, 1);
- state_fio->Fwrite(buffer_tmp, length_rw, 1);
- length_tmp -= length_rw;
+ 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 {
- state_fio->FputInt32(0);
- }
-#endif
-// state_fio->FputInt32(bufcnt);
-// state_fio->Fwrite(buffer, sizeof(buffer), 1);
-}
-
-bool CMT::load_state(FILEIO* state_fio)
-{
- release_tape();
-
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->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;
-// }
-// play = state_fio->FgetBool();
-// rec = state_fio->FgetBool();
-// remote = state_fio->FgetBool();
-// state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
-#if 0
- int length_tmp = state_fio->FgetInt32();
- 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);
+ 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;
}
- length_tmp -= length_rw;
+ } else {
+ state_fio->FputInt32_LE(0);
}
}
-#endif
-// bufcnt = state_fio->FgetInt32();
-// state_fio->Fread(buffer, sizeof(buffer), 1);
+ state_fio->StateInt32(bufcnt);
+ state_fio->StateBuffer(buffer, sizeof(buffer), 1);
return true;
}
-
void release();
void reset();
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);
+ bool process_state(FILEIO* state_fio, bool loading);
// unique functions
void play_tape(const _TCHAR* file_path);
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void DISPLAY::decl_state()
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
{
-
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_1D_ARRAY(font, sizeof(font));
- DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
- DECL_STATE_ENTRY_INT32(busreq_clocks);
- DECL_STATE_ENTRY_BOOL(color);
- DECL_STATE_ENTRY_BOOL(width40);
- DECL_STATE_ENTRY_UINT8(mode);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
+ state_fio->StateBuffer(font, sizeof(font), 1);
+ state_fio->StateBuffer(vram, sizeof(vram), 1);
+ state_fio->StateInt32(busreq_clocks);
+ state_fio->StateBool(color);
+ state_fio->StateBool(width40);
+ state_fio->StateUint8(mode);
+ //state_fio->StateBuffer(&crtc, sizeof(crtc), 1);
{
// crtc
/* struct */{
- DECL_STATE_ENTRY_INT32((crtc.blink.rate));
- DECL_STATE_ENTRY_INT32((crtc.blink.counter));
- DECL_STATE_ENTRY_UINT8((crtc.blink.cursor));
- DECL_STATE_ENTRY_UINT8((crtc.blink.attrib));
+ state_fio->StateInt32(crtc.blink.rate);
+ state_fio->StateInt32(crtc.blink.counter);
+ state_fio->StateUint8(crtc.blink.cursor);
+ state_fio->StateUint8(crtc.blink.attrib);
} /* blink */;
/*struct */{
- DECL_STATE_ENTRY_INT32((crtc.cursor.type));
- DECL_STATE_ENTRY_INT32((crtc.cursor.mode));
- DECL_STATE_ENTRY_INT32((crtc.cursor.x));
- DECL_STATE_ENTRY_INT32((crtc.cursor.y));
+ state_fio->StateInt32(crtc.cursor.type);
+ state_fio->StateInt32(crtc.cursor.mode);
+ state_fio->StateInt32(crtc.cursor.x);
+ state_fio->StateInt32(crtc.cursor.y);
} /* cursor */;
/*struct */{
- DECL_STATE_ENTRY_UINT8((crtc.attrib.data));
- DECL_STATE_ENTRY_INT32((crtc.attrib.num));
- DECL_STATE_ENTRY_2D_ARRAY((crtc.attrib.expand), 200, 80);
+ state_fio->StateUint8(crtc.attrib.data);
+ state_fio->StateInt32(crtc.attrib.num);
+ state_fio->StateBuffer(crtc.attrib.expand, sizeof(crtc.attrib.expand), 1);
} /* attrib */;
/* struct */{
- DECL_STATE_ENTRY_2D_ARRAY((crtc.text.expand), 200, 80);
+ state_fio->StateBuffer(crtc.text.expand, sizeof(crtc.text.expand), 1);
} /*text; */
- DECL_STATE_ENTRY_INT32((crtc.width));
- DECL_STATE_ENTRY_INT32((crtc.height));
- DECL_STATE_ENTRY_INT32((crtc.char_height));
- DECL_STATE_ENTRY_BOOL((crtc.skip_line));
- DECL_STATE_ENTRY_INT32((crtc.vretrace));
- DECL_STATE_ENTRY_BOOL((crtc.timing_changed));
- DECL_STATE_ENTRY_1D_ARRAY((crtc.buffer), 120 * 200);
- DECL_STATE_ENTRY_INT32((crtc.buffer_ptr));
- DECL_STATE_ENTRY_UINT8((crtc.cmd));
- DECL_STATE_ENTRY_INT32((crtc.cmd_ptr));
- DECL_STATE_ENTRY_UINT8((crtc.mode));
- DECL_STATE_ENTRY_UINT8((crtc.reverse));
- DECL_STATE_ENTRY_UINT8((crtc.intr_mask));
- DECL_STATE_ENTRY_UINT8((crtc.status));
- DECL_STATE_ENTRY_BOOL((crtc.vblank));
+ state_fio->StateInt32(crtc.width);
+ state_fio->StateInt32(crtc.height);
+ state_fio->StateInt32(crtc.char_height);
+ state_fio->StateBool(crtc.skip_line);
+ state_fio->StateInt32(crtc.vretrace);
+ state_fio->StateBool(crtc.timing_changed);
+ state_fio->StateBuffer(crtc.buffer, sizeof(crtc.buffer), 1);
+ state_fio->StateInt32(crtc.buffer_ptr);
+ state_fio->StateUint8(crtc.cmd);
+ state_fio->StateInt32(crtc.cmd_ptr);
+ state_fio->StateUint8(crtc.mode);
+ state_fio->StateUint8(crtc.reverse);
+ state_fio->StateUint8(crtc.intr_mask);
+ state_fio->StateUint8(crtc.status);
+ state_fio->StateBool(crtc.vblank);
}
+ STORE_DMAC_CONTEXTS();
+ //state_fio->StateBuffer(&dmac, sizeof(dmac), 1);
{ // dmac
for(int i = 0; i < 4; i++) {
- DECL_STATE_ENTRY_PAIR_MEMBER((dmac.ch[i].addr), i);
- DECL_STATE_ENTRY_PAIR_MEMBER((dmac.ch[i].count), i);
- DECL_STATE_ENTRY_UINT8_MEMBER((dmac.ch[i].mode), i);
- DECL_STATE_ENTRY_INT32_MEMBER((dmac.ch[i].nbytes), i);
- DECL_STATE_ENTRY_BOOL_MEMBER((dmac.ch[i].running), i);
+ state_fio->StateUint32(dmac.ch[i].addr.d);
+ state_fio->StateUint32(dmac.ch[i].count.d);
+ state_fio->StateUint8(dmac.ch[i].mode);
+ state_fio->StateInt32(dmac.ch[i].nbytes);
+ state_fio->StateBool(dmac.ch[i].running);
} /* ch[4] */
- DECL_STATE_ENTRY_UINT8((dmac.mode));
- DECL_STATE_ENTRY_UINT8((dmac.status));
- DECL_STATE_ENTRY_BOOL((dmac.high_low))
+ state_fio->StateUint8(dmac.mode);
+ state_fio->StateUint8(dmac.status);
+ state_fio->StateBool(dmac.high_low);
}
- leave_decl_state();
-}
-
-void DISPLAY::save_state(FILEIO* state_fio)
-{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
-
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->Fwrite(font, sizeof(font), 1);
-// state_fio->Fwrite(vram, sizeof(vram), 1);
-// state_fio->FputInt32(busreq_clocks);
-// state_fio->FputBool(color);
-// state_fio->FputBool(width40);
-// state_fio->FputUint8(mode);
-// state_fio->Fwrite(&crtc, sizeof(crtc), 1);
-// state_fio->Fwrite(&dmac, sizeof(dmac), 1);
-}
-
-bool DISPLAY::load_state(FILEIO* state_fio)
-{
- STORE_DMAC_CONTEXTS();
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
- }
- if(!mb) {
- RESTORE_DMAC_CONTEXTS();
- return false;
- }
RESTORE_DMAC_CONTEXTS();
-
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// state_fio->Fread(font, sizeof(font), 1);
-// state_fio->Fread(vram, sizeof(vram), 1);
-// busreq_clocks = state_fio->FgetInt32();
-// color = state_fio->FgetBool();
-// width40 = state_fio->FgetBool();
-// mode = state_fio->FgetUint8();
-// state_fio->Fread(&crtc, sizeof(crtc), 1);
-// STORE_DMAC_CONTEXTS();
-// state_fio->Fread(&dmac, sizeof(dmac), 1);
-// RESTORE_DMAC_CONTEXTS();
return true;
}
void event_callback(int event_id, int err);
void event_frame();
void event_vline(int v, int clock);
- void decl_state();
- 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(Z80* device)
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void MEMBUS::decl_state()
-{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
- DECL_STATE_ENTRY_PAIR(basic_addr);
- DECL_STATE_ENTRY_BOOL(ram_selected);
-
- leave_decl_state();
-
-// MEMORY::decl_state(); // ??
-}
-void MEMBUS::save_state(FILEIO* state_fio)
-{
- 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->FputUint32(basic_addr.d);
-// state_fio->FputBool(ram_selected);
-
- MEMORY::save_state(state_fio); // OK?
-}
-
-bool MEMBUS::load_state(FILEIO* state_fio)
+bool MEMBUS::process_state(FILEIO* state_fio, bool loading)
{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
- if(!mb) {
+ if(!state_fio->StateCheckInt32(this_device_id)) {
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)) { // OK?
+ if(!MEMORY::process_state(state_fio, loading)) {
return false;
}
-
-// state_fio->Fread(ram, sizeof(ram), 1);
-// basic_addr.d = state_fio->FgetUint32();
-// ram_selected = state_fio->FgetBool();
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ state_fio->StateUint32(basic_addr.d);
+ state_fio->StateBool(ram_selected);
// post process
- update_bank();
+ if(loading) {
+ update_bank();
+ }
return true;
}
uint32_t read_io8(uint32_t addr);
void write_dma_data8(uint32_t addr, uint32_t data);
uint32_t read_dma_data8(uint32_t addr);
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
};
#endif
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void RTC::decl_state()
+bool RTC::process_state(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_CUR_TIME_T(cur_time);
- DECL_STATE_ENTRY_CUR_TIME_T(tmp_time);
- DECL_STATE_ENTRY_UINT8(ctrl);
-
- leave_decl_state();
-}
-
-void RTC::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);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
- //cur_time.save_state((void *)state_fio);
- //tmp_time.save_state((void *)state_fio);
- //state_fio->FputUint8(ctrl);
-}
-
-bool RTC::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
- //if(state_fio->FgetUint32() != STATE_VERSION) {
- // return false;
- //}
- //if(state_fio->FgetInt32() != this_device_id) {
- // return false;
- //}
- //if(!cur_time.load_state((void *)state_fio)) {
- // return false;
- //}
- //if(!tmp_time.load_state((void *)state_fio)) {
- // return false;
- //}
- //ctrl = state_fio->FgetUint8();
+ if(!cur_time.process_state((void *)state_fio, loading)) {
+ return false;
+ }
+ if(!tmp_time.process_state((void *)state_fio, loading)) {
+ return false;
+ }
+ state_fio->StateUint8(ctrl);
return true;
}
-
void write_io8(uint32_t addr, uint32_t data);
uint32_t read_io8(uint32_t addr);
void event_callback(int event_id, int err);
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
};
#endif
for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
- decl_state();
}
VM::~VM()
#define STATE_VERSION 2
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
- state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::COLECO_VISION_HEAD")), csp_logger);
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->decl_state();
- }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
- //state_fio->FputUint32(STATE_VERSION);
-
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->save_state(state_fio);
- }
-}
-
-bool VM::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(!mb) {
- emu->out_debug_log("INFO: HEADER DATA ERROR");
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- if(!device->load_state(state_fio)) {
+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) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
return false;
}
- }
- return true;
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+// if(loading) {
+// update_config();
+// }
+ return true;
}
bool is_frame_skippable();
void update_config();
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// for each device
#define STATE_VERSION 2
-#include "../../statesub.h"
-
-void KEYBOARD::decl_state(void)
-{
- enter_decl_state(STATE_VERSION);
- DECL_STATE_ENTRY_BOOL(tenkey);
- leave_decl_state();
-}
-
-void KEYBOARD::save_state(FILEIO* state_fio)
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->FputBool(tenkey);
-}
-
-bool KEYBOARD::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// tenkey = state_fio->FgetBool();
+ state_fio->StateBool(tenkey);
return true;
}
void event_frame();
uint32_t read_io8(uint32_t addr);
void write_io8(uint32_t addr, uint32_t data);
- void decl_state();
- 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)
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void MEMORY::decl_state(void)
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
- DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
- DECL_STATE_ENTRY_BOOL(inserted);
- leave_decl_state();
-}
-
-void MEMORY::save_state(FILEIO* state_fio)
-{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->Fwrite(ram, sizeof(ram), 1);
-// state_fio->FputBool(inserted);
-}
-
-bool MEMORY::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// state_fio->Fread(ram, sizeof(ram), 1);
-// inserted = state_fio->FgetBool();
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ state_fio->StateBool(inserted);
// post process
- if(inserted) {
- SET_BANK(0x8000, 0xffff, wdmy, cart);
- } else {
- SET_BANK(0x0000, 0x1fff, wdmy, ipl);
- SET_BANK(0x2000, 0x5fff, wdmy, rdmy);
- SET_BANK(0x6000, 0x7fff, ram, ram);
- SET_BANK(0x8000, 0xffff, wdmy, cart);
+ if(loading) {
+ if(inserted) {
+ SET_BANK(0x8000, 0xffff, wdmy, cart);
+ } else {
+ SET_BANK(0x0000, 0x1fff, wdmy, ipl);
+ SET_BANK(0x2000, 0x5fff, wdmy, rdmy);
+ SET_BANK(0x6000, 0x7fff, ram, ram);
+ SET_BANK(0x8000, 0xffff, wdmy, cart);
+ }
}
return true;
}
void initialize();
void write_data8(uint32_t addr, uint32_t data);
uint32_t read_data8(uint32_t addr);
- void decl_state();
- 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);
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void CMT::decl_state()
-{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_BOOL(play);
- DECL_STATE_ENTRY_BOOL(rec);
- DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path));
- DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
-
- DECL_STATE_ENTRY_INT32(bufcnt);
- DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
-
- leave_decl_state();
-}
-void CMT::save_state(FILEIO* state_fio)
+bool CMT::process_state(FILEIO* state_fio, bool loading)
{
- uint32_t crc_value = 0xffffffff;
- if(state_entry != NULL) {
- state_entry->save_state(state_fio, &crc_value);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->FputBool(play);
-// state_fio->FputBool(rec);
-// state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
-// state_fio->FputInt32(bufcnt);
-// state_fio->Fwrite(buffer, sizeof(buffer), 1);
-}
-
-bool CMT::load_state(FILEIO* state_fio)
-{
- release_tape();
-
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// play = state_fio->FgetBool();
-// rec = state_fio->FgetBool();
-// state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
-// int length_tmp = state_fio->FgetInt32();
- bool mb = false;
- bool stat;
- uint32_t crc_value = 0xffffffff;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio, &crc_value);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
+ 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);
+ }
}
- if(!mb) return false;
-// bufcnt = state_fio->FgetInt32();
-// state_fio->Fread(buffer, sizeof(buffer), 1);
+ state_fio->StateInt32(bufcnt);
+ state_fio->StateBuffer(buffer, sizeof(buffer), 1);
return true;
}
void release();
void reset();
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);
+ bool process_state(FILEIO* state_fio, bool loading);
// unique functions
void play_tape(const _TCHAR* file_path);
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void DISPLAY::decl_state()
-{
- enter_decl_state(STATE_VERSION);
- DECL_STATE_ENTRY_INT32(odd_even);
- DECL_STATE_ENTRY_BOOL(dma);
- leave_decl_state();
-}
-
-void DISPLAY::save_state(FILEIO* state_fio)
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->FputInt32(odd_even);
-// state_fio->FputBool(dma);
-}
-
-bool DISPLAY::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// odd_even = state_fio->FgetInt32();
-// dma = state_fio->FgetBool();
+ state_fio->StateInt32(odd_even);
+ state_fio->StateBool(dma);
return true;
}
void event_frame();
void event_vline(int v, int clock);
void event_callback(int event_id, int err);
- void decl_state();
- 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)
for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
- decl_state();
}
VM::~VM()
#define STATE_VERSION 2
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
+bool VM::process_state(FILEIO* state_fio, bool loading)
{
- state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::EX80_HEAD")), csp_logger);
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->decl_state();
- }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
- //state_fio->FputUint32(STATE_VERSION);
-
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->save_state(state_fio);
- }
-}
-
-bool VM::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(!mb) {
- emu->out_debug_log("INFO: HEADER DATA ERROR");
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- if(!device->load_state(state_fio)) {
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ for(DEVICE* device = first_device; device; device = device->next_device) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
return false;
}
- }
- return true;
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+ return true;
}
bool is_frame_skippable();
void update_config();
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// for each device
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void KEYBOARD::decl_state(void)
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
- DECL_STATE_ENTRY_UINT32(column);
- leave_decl_state();
-}
-
-void KEYBOARD::save_state(FILEIO* state_fio)
-{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->FputUint32(column);
-}
-
-bool KEYBOARD::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// column = state_fio->FgetUint32();
+ state_fio->StateUint32(column);
return true;
}
-
void initialize();
void write_signal(int id, uint32_t data, uint32_t mask);
void event_frame();
- void decl_state();
- 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_pio(DEVICE* device)
#define STATE_VERSION 1
-#include "../../statesub.h"
-
-void MEMORY::decl_state(void)
-{
- enter_decl_state(STATE_VERSION);
- DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
- leave_decl_state();
-}
-
-void MEMORY::save_state(FILEIO* state_fio)
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-//
-// state_fio->Fwrite(ram, sizeof(ram), 1);
-}
-
-bool MEMORY::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// 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->StateBuffer(ram, sizeof(ram), 1);
return true;
}
-
// RST 7
return 0xff;
}
- void decl_state();
- 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)
volume_r = decibel_to_volume(decibel_r);
}
-#define STATE_VERSION 1
+#define STATE_VERSION 2
-#include "../../statesub.h"
-
-void APU::decl_state_rectangle(int num)
+void APU::process_state_rectangle(int num, FILEIO* state_fio, bool loading)
{
- DECL_STATE_ENTRY_1D_ARRAY_MEMBER((rectangle[num].regs), 4, num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].enabled), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].phaseacc), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].freq), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].output_vol), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].fixed_envelope), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].holdnote), num);
- DECL_STATE_ENTRY_UINT8_MEMBER((rectangle[num].volume), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].sweep_phase), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].sweep_delay), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].sweep_on), num);
- DECL_STATE_ENTRY_UINT8_MEMBER((rectangle[num].sweep_shifts), num);
- DECL_STATE_ENTRY_UINT8_MEMBER((rectangle[num].sweep_length), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].sweep_inc), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].freq_limit), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].sweep_complement), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].env_phase), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].env_delay), num);
- DECL_STATE_ENTRY_UINT8_MEMBER((rectangle[num].env_vol), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].vbl_length), num);
- DECL_STATE_ENTRY_UINT8_MEMBER((rectangle[num].adder), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].duty_flip), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].enabled_cur), num);
- DECL_STATE_ENTRY_BOOL_MEMBER((rectangle[num].holdnote_cur), num);
- DECL_STATE_ENTRY_INT32_MEMBER((rectangle[num].vbl_length_cur), num);
+ state_fio->StateBuffer(rectangle[num].regs, sizeof(rectangle[0].regs), 1);
+ state_fio->StateBool(rectangle[num].enabled);
+ state_fio->StateInt32(rectangle[num].phaseacc);
+ state_fio->StateInt32(rectangle[num].freq);
+ state_fio->StateInt32(rectangle[num].output_vol);
+ state_fio->StateBool(rectangle[num].fixed_envelope);
+ state_fio->StateBool(rectangle[num].holdnote);
+ state_fio->StateUint8(rectangle[num].volume);
+ state_fio->StateInt32(rectangle[num].sweep_phase);
+ state_fio->StateInt32(rectangle[num].sweep_delay);
+ state_fio->StateBool(rectangle[num].sweep_on);
+ state_fio->StateUint8(rectangle[num].sweep_shifts);
+ state_fio->StateUint8(rectangle[num].sweep_length);
+ state_fio->StateBool(rectangle[num].sweep_inc);
+ state_fio->StateInt32(rectangle[num].freq_limit);
+ state_fio->StateBool(rectangle[num].sweep_complement);
+ state_fio->StateInt32(rectangle[num].env_phase);
+ state_fio->StateInt32(rectangle[num].env_delay);
+ state_fio->StateUint8(rectangle[num].env_vol);
+ state_fio->StateInt32(rectangle[num].vbl_length);
+ state_fio->StateUint8(rectangle[num].adder);
+ state_fio->StateInt32(rectangle[num].duty_flip);
+ state_fio->StateBool(rectangle[num].enabled_cur);
+ state_fio->StateBool(rectangle[num].holdnote_cur);
+ state_fio->StateInt32(rectangle[num].vbl_length_cur);
}
-void APU::decl_state_triangle()
+
+void APU::process_state_triangle(FILEIO* state_fio, bool loading)
{
- DECL_STATE_ENTRY_1D_ARRAY((triangle.regs), 3);
- DECL_STATE_ENTRY_BOOL((triangle.enabled));
- DECL_STATE_ENTRY_INT32((triangle.freq));
- DECL_STATE_ENTRY_INT32((triangle.phaseacc));
- DECL_STATE_ENTRY_INT32((triangle.output_vol));
- DECL_STATE_ENTRY_UINT8((triangle.adder));
- DECL_STATE_ENTRY_BOOL((triangle.holdnote));
- DECL_STATE_ENTRY_BOOL((triangle.counter_started));
- DECL_STATE_ENTRY_INT((triangle.write_latency));
- DECL_STATE_ENTRY_INT((triangle.vbl_length));
- DECL_STATE_ENTRY_INT((triangle.linear_length));
- DECL_STATE_ENTRY_BOOL((triangle.enabled_cur));
- DECL_STATE_ENTRY_BOOL((triangle.holdnote_cur));
- DECL_STATE_ENTRY_BOOL((triangle.counter_started_cur));
- DECL_STATE_ENTRY_INT((triangle.vbl_length_cur));
+ state_fio->StateBuffer(triangle.regs, sizeof(triangle.regs), 1);
+ state_fio->StateBool(triangle.enabled);
+ state_fio->StateInt32(triangle.freq);
+ state_fio->StateInt32(triangle.phaseacc);
+ state_fio->StateInt32(triangle.output_vol);
+ state_fio->StateUint8(triangle.adder);
+ state_fio->StateBool(triangle.holdnote);
+ state_fio->StateBool(triangle.counter_started);
+ state_fio->StateInt32(triangle.write_latency);
+ state_fio->StateInt32(triangle.vbl_length);
+ state_fio->StateInt32(triangle.linear_length);
+ state_fio->StateBool(triangle.enabled_cur);
+ state_fio->StateBool(triangle.holdnote_cur);
+ state_fio->StateBool(triangle.counter_started_cur);
+ state_fio->StateInt32(triangle.vbl_length_cur);
}
-void APU::decl_state_noise()
+void APU::process_state_noise(FILEIO* state_fio, bool loading)
{
- DECL_STATE_ENTRY_1D_ARRAY((noise.regs), 3);
- DECL_STATE_ENTRY_BOOL((noise.enabled));
- DECL_STATE_ENTRY_INT32((noise.freq));
- DECL_STATE_ENTRY_INT32((noise.phaseacc));
- DECL_STATE_ENTRY_INT32((noise.output_vol));
- DECL_STATE_ENTRY_INT32((noise.env_phase));
- DECL_STATE_ENTRY_INT32((noise.env_delay));
- DECL_STATE_ENTRY_UINT8((noise.env_vol));
- DECL_STATE_ENTRY_BOOL((noise.fixed_envelope));
- DECL_STATE_ENTRY_BOOL((noise.holdnote));
- DECL_STATE_ENTRY_UINT8((noise.volume));
- DECL_STATE_ENTRY_INT((noise.vbl_length));
- DECL_STATE_ENTRY_UINT8((noise.xor_tap));
- DECL_STATE_ENTRY_BOOL((noise.enabled_cur));
- DECL_STATE_ENTRY_BOOL((noise.holdnote_cur));
- DECL_STATE_ENTRY_INT((noise.vbl_length_cur));
+ state_fio->StateBuffer(noise.regs, sizeof(noise.regs), 1);
+ state_fio->StateBool(noise.enabled);
+ state_fio->StateInt32(noise.freq);
+ state_fio->StateInt32(noise.phaseacc);
+ state_fio->StateInt32(noise.output_vol);
+ state_fio->StateInt32(noise.env_phase);
+ state_fio->StateInt32(noise.env_delay);
+ state_fio->StateUint8(noise.env_vol);
+ state_fio->StateBool(noise.fixed_envelope);
+ state_fio->StateBool(noise.holdnote);
+ state_fio->StateUint8(noise.volume);
+ state_fio->StateInt32(noise.vbl_length);
+ state_fio->StateUint8(noise.xor_tap);
+ state_fio->StateBool(noise.enabled_cur);
+ state_fio->StateBool(noise.holdnote_cur);
+ state_fio->StateInt32(noise.vbl_length_cur);
- DECL_STATE_ENTRY_INT((noise.shift_reg));
- DECL_STATE_ENTRY_INT((noise.noise_bit));
-}
-
-void APU::decl_state_dmc()
-{
- DECL_STATE_ENTRY_1D_ARRAY((dmc.regs), 4);
- DECL_STATE_ENTRY_BOOL((dmc.enabled));
- DECL_STATE_ENTRY_INT32((dmc.freq));
- DECL_STATE_ENTRY_INT32((dmc.phaseacc));
- DECL_STATE_ENTRY_INT32((dmc.output_vol));
- DECL_STATE_ENTRY_UINT32((dmc.address));
- DECL_STATE_ENTRY_UINT32((dmc.cached_addr));
- DECL_STATE_ENTRY_INT((dmc.dma_length));
- DECL_STATE_ENTRY_INT((dmc.cached_dmalength));
- DECL_STATE_ENTRY_UINT8((dmc.cur_byte));
- DECL_STATE_ENTRY_BOOL((dmc.looping));
- DECL_STATE_ENTRY_BOOL((dmc.irq_gen));
- DECL_STATE_ENTRY_BOOL((dmc.irq_occurred));
- DECL_STATE_ENTRY_INT32((dmc.freq_cur));
- DECL_STATE_ENTRY_INT32((dmc.phaseacc_cur));
- DECL_STATE_ENTRY_INT((dmc.dma_length_cur));
- DECL_STATE_ENTRY_INT((dmc.cached_dmalength_cur));
- DECL_STATE_ENTRY_BOOL((dmc.enabled_cur));
- DECL_STATE_ENTRY_BOOL((dmc.looping_cur));
- DECL_STATE_ENTRY_BOOL((dmc.irq_gen_cur));
- DECL_STATE_ENTRY_BOOL((dmc.irq_occurred_cur));
-}
-
-void APU::decl_state_queue(int __size)
-{
-// DECL_STATE_ENTRY_UINT32_MEMBER((queue[num].timestamp), num);
-// DECL_STATE_ENTRY_UINT32_MEMBER((queue[num].addr), num);
-// DECL_STATE_ENTRY_UINT32_MEMBER((queue[num].data), num);
- DECL_STATE_ENTRY_UINT32_STRIDE((queue[0].timestamp), __size, sizeof(queue_t));
- DECL_STATE_ENTRY_UINT32_STRIDE((queue[0].addr), __size, sizeof(queue_t));
- DECL_STATE_ENTRY_UINT32_STRIDE((queue[0].data), __size, sizeof(queue_t));
+ state_fio->StateInt32(noise.shift_reg);
+ state_fio->StateInt32(noise.noise_bit);
}
-void APU::decl_state()
+void APU::process_state_dmc(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
-
- for(int i = 0; i < 2; i++) decl_state_rectangle(i);
- decl_state_triangle();
- decl_state_noise();
- decl_state_dmc();
-
- DECL_STATE_ENTRY_UINT32(enable_reg);
- DECL_STATE_ENTRY_UINT32(enable_reg_cur);
- DECL_STATE_ENTRY_INT32(count_rate);
-
- decl_state_queue(APUQUEUE_SIZE);
-
- DECL_STATE_ENTRY_INT32(q_head);
- DECL_STATE_ENTRY_INT32(q_tail);
- DECL_STATE_ENTRY_UINT32(elapsed_cycles);
- DECL_STATE_ENTRY_DOUBLE(ave);
- DECL_STATE_ENTRY_DOUBLE(max);
- DECL_STATE_ENTRY_DOUBLE(min);
-
- leave_decl_state();
+ state_fio->StateBuffer(dmc.regs, sizeof(dmc.regs), 1);
+ state_fio->StateBool(dmc.enabled);
+ state_fio->StateInt32(dmc.freq);
+ state_fio->StateInt32(dmc.phaseacc);
+ state_fio->StateInt32(dmc.output_vol);
+ state_fio->StateUint32(dmc.address);
+ state_fio->StateUint32(dmc.cached_addr);
+ state_fio->StateInt32(dmc.dma_length);
+ state_fio->StateInt32(dmc.cached_dmalength);
+ state_fio->StateUint8(dmc.cur_byte);
+ state_fio->StateBool(dmc.looping);
+ state_fio->StateBool(dmc.irq_gen);
+ state_fio->StateBool(dmc.irq_occurred);
+ state_fio->StateInt32(dmc.freq_cur);
+ state_fio->StateInt32(dmc.phaseacc_cur);
+ state_fio->StateInt32(dmc.dma_length_cur);
+ state_fio->StateInt32(dmc.cached_dmalength_cur);
+ state_fio->StateBool(dmc.enabled_cur);
+ state_fio->StateBool(dmc.looping_cur);
+ state_fio->StateBool(dmc.irq_gen_cur);
+ state_fio->StateBool(dmc.irq_occurred_cur);
}
-void APU::save_state(FILEIO* state_fio)
+void APU::process_state_queue(int num, FILEIO* state_fio, bool loading)
{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->Fwrite(rectangle, sizeof(rectangle), 1);
-// state_fio->Fwrite(&triangle, sizeof(triangle), 1);
-// state_fio->Fwrite(&noise, sizeof(noise), 1);
-// state_fio->Fwrite(&dmc, sizeof(dmc), 1);
-// state_fio->FputUint32(enable_reg);
-// state_fio->FputUint32(enable_reg_cur);
-// state_fio->FputInt32(count_rate);
-// state_fio->Fwrite(queue, sizeof(queue), 1);
-// state_fio->FputInt32(q_head);
-// state_fio->FputInt32(q_tail);
-// state_fio->FputUint32(elapsed_cycles);
-// state_fio->FputDouble(ave);
-// state_fio->FputDouble(max);
-// state_fio->FputDouble(min);
+ state_fio->StateUint32(queue[num].timestamp);
+ state_fio->StateUint32(queue[num].addr);
+ state_fio->StateUint32(queue[num].data);
}
-bool APU::load_state(FILEIO* state_fio)
+bool APU::process_state(FILEIO* state_fio, bool loading)
{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->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;
-// }
-// state_fio->Fread(rectangle, sizeof(rectangle), 1);
-// state_fio->Fread(&triangle, sizeof(triangle), 1);
-// state_fio->Fread(&noise, sizeof(noise), 1);
-// state_fio->Fread(&dmc, sizeof(dmc), 1);
-// enable_reg = state_fio->FgetUint32();
-// enable_reg_cur = state_fio->FgetUint32();
-// count_rate = state_fio->FgetInt32();
-// state_fio->Fread(queue, sizeof(queue), 1);
-// q_head = state_fio->FgetInt32();
-// q_tail = state_fio->FgetInt32();
-// elapsed_cycles = state_fio->FgetUint32();
-// ave = state_fio->FgetDouble();
-// max = state_fio->FgetDouble();
-// min = state_fio->FgetDouble();
- //touch_sound();
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
+ //state_fio->StateBuffer(rectangle, sizeof(rectangle), 1);
+ //state_fio->StateBuffer(&triangle, sizeof(triangle), 1);
+ //state_fio->StateBuffer(&noise, sizeof(noise), 1);
+ //state_fio->StateBuffer(&dmc, sizeof(dmc), 1);
+ for(int i = 0; i < 2; i++) {
+ process_state_rectangle(i, state_fio, loading);
+ }
+ process_state_triangle(state_fio, loading);
+ process_state_noise(state_fio, loading);
+ process_state_dmc(state_fio, loading);
+
+ state_fio->StateUint32(enable_reg);
+ state_fio->StateUint32(enable_reg_cur);
+ state_fio->StateInt32(count_rate);
+ //state_fio->StateBuffer(queue, sizeof(queue), 1);
+ for(int i = 0; i < APUQUEUE_SIZE; i++) {
+ process_state_queue(i, state_fio, loading);
+ }
+ state_fio->StateInt32(q_head);
+ state_fio->StateInt32(q_tail);
+ state_fio->StateUint32(elapsed_cycles);
+ state_fio->StateDouble(ave);
+ state_fio->StateDouble(max);
+ state_fio->StateDouble(min);
return true;
}
int volume_l, volume_r;
- void decl_state_rectangle(int num);
- void decl_state_triangle();
- void decl_state_noise();
- void decl_state_dmc();
- void decl_state_queue(int num);
+ void process_state_rectangle(int num, FILEIO* state_fio, bool loading);
+ void process_state_triangle(FILEIO* state_fio, bool loading);
+ void process_state_noise(FILEIO* state_fio, bool loading);
+ void process_state_dmc(FILEIO* state_fio, bool loading);
+ void process_state_queue(int num, FILEIO* state_fio, bool loading);
public:
APU(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
void event_vline(int v, int clock);
void mix(int32_t* buffer, int cnt);
void set_volume(int ch, int decibel_l, int decibel_r);
- void decl_state();
- 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)
for(DEVICE* device = first_device; device; device = device->next_device) {
device->initialize();
}
- decl_state();
}
VM::~VM()
}
}
-#define STATE_VERSION 5
+#define STATE_VERSION 6
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
- state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FAMILY_BASIC_HEAD")), csp_logger);
- DECL_STATE_ENTRY_INT32(boot_mode);
-
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->decl_state();
- }
-}
-void VM::save_state(FILEIO* state_fio)
-{
- //state_fio->FputUint32(STATE_VERSION);
-
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->save_state(state_fio);
- }
- //state_fio->FputInt32(boot_mode); // Move to decl_state().
-}
-
-bool VM::load_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
{
- //if(state_fio->FgetUint32() != STATE_VERSION) {
- // return false;
- //}
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
- }
- if(!mb) {
- emu->out_debug_log("INFO: HEADER DATA ERROR");
- return false;
- }
- for(DEVICE* device = first_device; device; device = device->next_device) {
- if(!device->load_state(state_fio)) {
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ for(DEVICE* device = first_device; device; device = device->next_device) {
+ // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+ // const char *name = typeid(*device).name();
+ // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+ const char *name = device->get_device_name();
+ int len = strlen(name);
+
+ if(!state_fio->StateCheckInt32(len)) {
+ if(loading) {
+ printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
return false;
}
+ if(!state_fio->StateCheckBuffer(name, len, 1)) {
+ if(loading) {
+ printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+ }
+ return false;
+ }
+ if(!device->process_state(state_fio, loading)) {
+ if(loading) {
+ printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+ }
+ return false;
+ }
+ }
+ // Machine specified.
+ state_fio->StateInt32(boot_mode);
+ if(loading) {
+ update_config();
}
- //boot_mode = state_fio->FgetInt32();
- return true;
+ return true;
}
bool is_frame_skippable();
void update_config();
- void decl_state();
- void save_state(FILEIO* state_fio);
- bool load_state(FILEIO* state_fio);
+ bool process_state(FILEIO* state_fio, bool loading);
// ----------------------------------------
// for each device
#define STATE_VERSION 2
-#include "../../statesub.h"
-
-void MEMORY::decl_state_header(header_t *p)
-{
- DECL_STATE_ENTRY_1D_ARRAY((p->id), 3); // 'NES'
- DECL_STATE_ENTRY_UINT8((p->ctrl_z)); // control-z
- DECL_STATE_ENTRY_UINT8((p->dummy));
- DECL_STATE_ENTRY_UINT8((p->num_8k_vrom_banks));
- DECL_STATE_ENTRY_UINT8((p->flags_1));
- DECL_STATE_ENTRY_UINT8((p->flags_2));
- DECL_STATE_ENTRY_1D_ARRAY((p->reserved), 1);
-}
-
-void MEMORY::decl_state()
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
-
- DECL_STATE_ENTRY_STRING(save_file_name, sizeof(save_file_name) / sizeof(_TCHAR));
- decl_state_header(&header);
-
- DECL_STATE_ENTRY_UINT32(rom_size);
-// DECL_STATE_ENTRY_UINT32(rom_mask);
- DECL_STATE_ENTRY_VARARRAY_VAR(rom, rom_size);
- DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
- DECL_STATE_ENTRY_1D_ARRAY(save_ram, sizeof(save_ram));
- DECL_STATE_ENTRY_UINT32(save_ram_crc32);
- DECL_STATE_ENTRY_1D_ARRAY(banks, sizeof(banks) / sizeof(uint32_t));
- DECL_STATE_ENTRY_UINT16(dma_addr);
- DECL_STATE_ENTRY_UINT8(frame_irq_enabled);
- DECL_STATE_ENTRY_1D_ARRAY(mmc5_wram_bank, sizeof(mmc5_wram_bank)/ sizeof(uint32_t));
- DECL_STATE_ENTRY_2D_ARRAY(mmc5_chr_reg, 8, 2);
- DECL_STATE_ENTRY_UINT32(mmc5_value0);
- DECL_STATE_ENTRY_UINT32(mmc5_value0);
- DECL_STATE_ENTRY_UINT8(mmc5_wram_protect0);
- DECL_STATE_ENTRY_UINT8(mmc5_wram_protect1);
- DECL_STATE_ENTRY_UINT8(mmc5_prg_size);
- DECL_STATE_ENTRY_UINT8(mmc5_chr_size);
- DECL_STATE_ENTRY_UINT8(mmc5_gfx_mode);
-// DECL_STATE_ENTRY_UINT8(mmc5_split_control);
-// DECL_STATE_ENTRY_UINT8(mmc5_split_bank);
- DECL_STATE_ENTRY_UINT8(mmc5_irq_enabled);
- DECL_STATE_ENTRY_UINT8(mmc5_irq_status);
- DECL_STATE_ENTRY_UINT32(mmc5_irq_line);
- DECL_STATE_ENTRY_UINT8(vrc7_irq_enabled);
- DECL_STATE_ENTRY_UINT8(vrc7_irq_counter);
- DECL_STATE_ENTRY_UINT8(vrc7_irq_latch);
- DECL_STATE_ENTRY_BOOL(pad_strobe);
- DECL_STATE_ENTRY_UINT8(pad1_bits);
- DECL_STATE_ENTRY_UINT8(pad2_bits);
- DECL_STATE_ENTRY_BOOL(kb_out);
- DECL_STATE_ENTRY_UINT8(kb_scan);
-
- leave_decl_state();
-}
-void MEMORY::save_state(FILEIO* state_fio)
-{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->Fwrite(save_file_name, sizeof(save_file_name), 1);
-// state_fio->Fwrite(&header, sizeof(header), 1);
-// state_fio->FputUint32(rom_size);
-//// state_fio->FputUint32(rom_mask);
-// state_fio->Fwrite(rom, rom_size, 1);
-// state_fio->Fwrite(ram, sizeof(ram), 1);
-// state_fio->Fwrite(save_ram, sizeof(save_ram), 1);
-// state_fio->FputUint32(save_ram_crc32);
-// state_fio->Fwrite(banks, sizeof(banks), 1);
-// state_fio->FputUint16(dma_addr);
-// state_fio->FputUint8(frame_irq_enabled);
-// state_fio->Fwrite(mmc5_wram_bank, sizeof(mmc5_wram_bank), 1);
-// state_fio->Fwrite(mmc5_chr_reg, sizeof(mmc5_chr_reg), 1);
-// state_fio->FputUint32(mmc5_value0);
-// state_fio->FputUint32(mmc5_value0);
-// state_fio->FputUint8(mmc5_wram_protect0);
-// state_fio->FputUint8(mmc5_wram_protect1);
-// state_fio->FputUint8(mmc5_prg_size);
-// state_fio->FputUint8(mmc5_chr_size);
-// state_fio->FputUint8(mmc5_gfx_mode);
-// state_fio->FputUint8(mmc5_split_control);
-// state_fio->FputUint8(mmc5_split_bank);
-// state_fio->FputUint8(mmc5_irq_enabled);
-// state_fio->FputUint8(mmc5_irq_status);
-// state_fio->FputUint32(mmc5_irq_line);
-// state_fio->FputUint8(vrc7_irq_enabled);
-// state_fio->FputUint8(vrc7_irq_counter);
-// state_fio->FputUint8(vrc7_irq_latch);
-// state_fio->FputBool(pad_strobe);
-// state_fio->FputUint8(pad1_bits);
-// state_fio->FputUint8(pad2_bits);
-// state_fio->FputBool(kb_out);
-// state_fio->FputUint8(kb_scan);
-}
-
-bool MEMORY::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// state_fio->Fread(save_file_name, sizeof(save_file_name), 1);
-// state_fio->Fread(&header, sizeof(header), 1);
-// rom_size = state_fio->FgetUint32();
-//// rom_mask = state_fio->FgetUint32();
- rom_mask = (rom_size / 0x2000) - 1;
-// if(rom != NULL) {
-// free(rom);
-// }
-// rom = (uint8_t *)malloc(rom_size);
-// state_fio->Fread(rom, rom_size, 1);
-// state_fio->Fread(ram, sizeof(ram), 1);
-// state_fio->Fread(save_ram, sizeof(save_ram), 1);
-// save_ram_crc32 = state_fio->FgetUint32();
-// state_fio->Fread(banks, sizeof(banks), 1);
-// dma_addr = state_fio->FgetUint16();
-// frame_irq_enabled = state_fio->FgetUint8();
-// state_fio->Fread(mmc5_wram_bank, sizeof(mmc5_wram_bank), 1);
-// state_fio->Fread(mmc5_chr_reg, sizeof(mmc5_chr_reg), 1);
-// mmc5_value0 = state_fio->FgetUint32();
-// mmc5_value0 = state_fio->FgetUint32();
-// mmc5_wram_protect0 = state_fio->FgetUint8();
-// mmc5_wram_protect1 = state_fio->FgetUint8();
-// mmc5_prg_size = state_fio->FgetUint8();
-// mmc5_chr_size = state_fio->FgetUint8();
-// mmc5_gfx_mode = state_fio->FgetUint8();
-// mmc5_split_control = state_fio->FgetUint8();
-// mmc5_split_bank = state_fio->FgetUint8();
-// mmc5_irq_enabled = state_fio->FgetUint8();
-// mmc5_irq_status = state_fio->FgetUint8();
-// mmc5_irq_line = state_fio->FgetUint32();
-// vrc7_irq_enabled = state_fio->FgetUint8();
-// vrc7_irq_counter = state_fio->FgetUint8();
-// vrc7_irq_latch = state_fio->FgetUint8();
-// pad_strobe = state_fio->FgetBool();
-// pad1_bits = state_fio->FgetUint8();
-// pad2_bits = state_fio->FgetUint8();
-// kb_out = state_fio->FgetBool();
-// kb_scan = state_fio->FgetUint8();
+ state_fio->StateBuffer(save_file_name, sizeof(save_file_name), 1);
+ state_fio->StateBuffer(&header, sizeof(header), 1); // OK?
+ state_fio->StateUint32(rom_size);
+// state_fio->StateUint32(rom_mask);
+ if(loading) {
+ rom_mask = (rom_size / 0x2000) - 1;
+ if(rom != NULL) {
+ free(rom);
+ }
+ rom = (uint8_t *)malloc(rom_size);
+ }
+ state_fio->StateBuffer(rom, rom_size, 1);
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ state_fio->StateBuffer(save_ram, sizeof(save_ram), 1);
+ state_fio->StateUint32(save_ram_crc32);
+ //state_fio->StateBuffer(banks, sizeof(banks), 1);
+ for(int i = 0; i < (sizeof(banks) / sizeof(uint32_t)); i++) {
+ state_fio->StateUint32(banks[i]);
+ }
+ state_fio->StateUint16(dma_addr);
+ state_fio->StateUint8(frame_irq_enabled);
+ //state_fio->StateBuffer(mmc5_wram_bank, sizeof(mmc5_wram_bank), 1);
+ for(int i = 0; i < (sizeof(mmc5_wram_bank) / sizeof(uint32_t)); i++) {
+ state_fio->StateUint32(mmc5_wram_bank[i]);
+ }
+ state_fio->StateBuffer(mmc5_chr_reg, sizeof(mmc5_chr_reg), 1);
+ state_fio->StateUint32(mmc5_value0);
+ state_fio->StateUint32(mmc5_value0);
+ state_fio->StateUint8(mmc5_wram_protect0);
+ state_fio->StateUint8(mmc5_wram_protect1);
+ state_fio->StateUint8(mmc5_prg_size);
+ state_fio->StateUint8(mmc5_chr_size);
+ state_fio->StateUint8(mmc5_gfx_mode);
+// state_fio->StateUint8(mmc5_split_control);
+// state_fio->StateUint8(mmc5_split_bank);
+ state_fio->StateUint8(mmc5_irq_enabled);
+ state_fio->StateUint8(mmc5_irq_status);
+ state_fio->StateUint32(mmc5_irq_line);
+ state_fio->StateUint8(vrc7_irq_enabled);
+ state_fio->StateUint8(vrc7_irq_counter);
+ state_fio->StateUint8(vrc7_irq_latch);
+ state_fio->StateBool(pad_strobe);
+ state_fio->StateUint8(pad1_bits);
+ state_fio->StateUint8(pad2_bits);
+ state_fio->StateBool(kb_out);
+ state_fio->StateUint8(kb_scan);
// post process
- if(header.mapper() == 5) {
- for(int i = 3; i < 8; i++) {
- mmc5_set_wram_bank(i, mmc5_wram_bank[i]);
- }
- } else {
- for(int i = 4; i < 8; i++) {
- set_rom_bank(i, banks[i]);
+ if(loading) {
+ if(header.mapper() == 5) {
+ for(int i = 3; i < 8; i++) {
+ mmc5_set_wram_bank(i, mmc5_wram_bank[i]);
+ }
+ } else {
+ for(int i = 4; i < 8; i++) {
+ set_rom_bank(i, banks[i]);
+ }
+ bank_ptr[3] = save_ram;
}
- bank_ptr[3] = save_ram;
}
return true;
}
+
void vrc7_hi_write(uint32_t addr, uint32_t data);
void vrc7_hsync(int v);
- void decl_state_header(header_t *p);
public:
MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
{
uint32_t read_data8(uint32_t addr);
void event_vline(int v, int clock);
void event_callback(int event_id, int err);
- void decl_state();
- 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)
set_ppu_bank(11, nt3);
}
-#define STATE_VERSION 2
+#define STATE_VERSION 3
-#include "../../statesub.h"
-
-void PPU::decl_state_header(header_t *p)
-{
- DECL_STATE_ENTRY_1D_ARRAY((p->id), 3); // 'NES'
- DECL_STATE_ENTRY_UINT8((p->ctrl_z)); // control-z
- DECL_STATE_ENTRY_UINT8((p->dummy));
- DECL_STATE_ENTRY_UINT8((p->num_8k_vrom_banks));
- DECL_STATE_ENTRY_UINT8((p->flags_1));
- DECL_STATE_ENTRY_UINT8((p->flags_2));
- DECL_STATE_ENTRY_1D_ARRAY((p->reserved), 1);
-}
-
-void PPU::decl_state()
+bool PPU::process_state(FILEIO* state_fio, bool loading)
{
- enter_decl_state(STATE_VERSION);
- // ToDo: Read register value, then calculate display values.
- DECL_STATE_ENTRY_SCRNTYPE_T_1D_ARRAY(palette_pc, sizeof(palette_pc) / sizeof(scrntype_t));
- DECL_STATE_ENTRY_1D_ARRAY(solid_buf, sizeof(solid_buf));
- decl_state_header(&header);
-
- DECL_STATE_ENTRY_1D_ARRAY(banks, sizeof(banks) / sizeof(uint32_t));
- DECL_STATE_ENTRY_INT32(chr_rom_size);
-// DECL_STATE_ENTRY_INT32(chr_rom_mask);
- DECL_STATE_ENTRY_VARARRAY_VAR(chr_rom, chr_rom_size);
- DECL_STATE_ENTRY_1D_ARRAY(name_tables, sizeof(name_tables));
- DECL_STATE_ENTRY_1D_ARRAY(spr_ram, sizeof(spr_ram));
- DECL_STATE_ENTRY_1D_ARRAY(bg_pal, sizeof(bg_pal));
- DECL_STATE_ENTRY_1D_ARRAY(spr_pal, sizeof(spr_pal));
- DECL_STATE_ENTRY_UINT8(spr_ram_rw_ptr);
- DECL_STATE_ENTRY_1D_ARRAY(regs, sizeof(regs));
- DECL_STATE_ENTRY_UINT16(bg_pattern_table_addr);
- DECL_STATE_ENTRY_UINT16(spr_pattern_table_addr);
- DECL_STATE_ENTRY_UINT16(ppu_addr_inc);
- DECL_STATE_ENTRY_UINT8(rgb_bak);
- DECL_STATE_ENTRY_BOOL(toggle_2005_2006);
- DECL_STATE_ENTRY_UINT8(read_2007_buffer);
- DECL_STATE_ENTRY_UINT16(loopy_v);
- DECL_STATE_ENTRY_UINT16(loopy_t);
- DECL_STATE_ENTRY_UINT8(loopy_x);
-
- leave_decl_state();
-}
-void PPU::save_state(FILEIO* state_fio)
-{
- if(state_entry != NULL) {
- state_entry->save_state(state_fio);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
}
-// state_fio->FputUint32(STATE_VERSION);
-// state_fio->FputInt32(this_device_id);
-
-// state_fio->Fwrite(palette_pc, sizeof(palette_pc), 1);
-// state_fio->Fwrite(solid_buf, sizeof(solid_buf), 1);
-// state_fio->Fwrite(&header, sizeof(header), 1);
-// state_fio->Fwrite(banks, sizeof(banks), 1);
-// state_fio->FputInt32(chr_rom_size);
-//// state_fio->FputInt32(chr_rom_mask);
-// state_fio->Fwrite(chr_rom, chr_rom_size, 1);
-// state_fio->Fwrite(name_tables, sizeof(name_tables), 1);
-// state_fio->Fwrite(spr_ram, sizeof(spr_ram), 1);
-// state_fio->Fwrite(bg_pal, sizeof(bg_pal), 1);
-// state_fio->Fwrite(spr_pal, sizeof(spr_pal), 1);
-// state_fio->FputUint8(spr_ram_rw_ptr);
-// state_fio->Fwrite(regs, sizeof(regs), 1);
-// state_fio->FputUint16(bg_pattern_table_addr);
-// state_fio->FputUint16(spr_pattern_table_addr);
-// state_fio->FputUint16(ppu_addr_inc);
-// state_fio->FputUint8(rgb_bak);
-// state_fio->FputBool(toggle_2005_2006);
-// state_fio->FputUint8(read_2007_buffer);
-// state_fio->FputUint16(loopy_v);
-// state_fio->FputUint16(loopy_t);
-// state_fio->FputUint8(loopy_x);
-}
-
-bool PPU::load_state(FILEIO* state_fio)
-{
- bool mb = false;
- if(state_entry != NULL) {
- mb = state_entry->load_state(state_fio);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
}
- if(!mb) return false;
-// if(state_fio->FgetUint32() != STATE_VERSION) {
-// return false;
-// }
-// if(state_fio->FgetInt32() != this_device_id) {
-// return false;
-// }
-// state_fio->Fread(palette_pc, sizeof(palette_pc), 1);
-// state_fio->Fread(solid_buf, sizeof(solid_buf), 1);
-// state_fio->Fread(&header, sizeof(header), 1);
-// state_fio->Fread(banks, sizeof(banks), 1);
-// chr_rom_size = state_fio->FgetUint32();
-// chr_rom_mask = state_fio->FgetUint32();
- chr_rom_mask = (chr_rom_size / 0x400) - 1;
-// if(chr_rom != NULL) {
-// free(chr_rom);
-// }
-// chr_rom = (uint8_t *)malloc(chr_rom_size);
-// state_fio->Fread(chr_rom, chr_rom_size, 1);
-// state_fio->Fread(name_tables, sizeof(name_tables), 1);
-// state_fio->Fread(spr_ram, sizeof(spr_ram), 1);
-// state_fio->Fread(bg_pal, sizeof(bg_pal), 1);
-// state_fio->Fread(spr_pal, sizeof(spr_pal), 1);
-// spr_ram_rw_ptr = state_fio->FgetUint8();
-// state_fio->Fread(regs, sizeof(regs), 1);
-// bg_pattern_table_addr = state_fio->FgetUint16();
-// spr_pattern_table_addr = state_fio->FgetUint16();
-// ppu_addr_inc = state_fio->FgetUint16();
-// rgb_bak = state_fio->FgetUint8();
-// toggle_2005_2006 = state_fio->FgetBool();
-// read_2007_buffer = state_fio->FgetUint8();
-// loopy_v = state_fio->FgetUint16();
-// loopy_t = state_fio->FgetUint16();
-// loopy_x = state_fio->FgetUint8();
+ //state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+ if(loading) {
+ for(int i = 0; i < (sizeof(palette_pc) / sizeof(scrntype_t)); i++) {
+ uint8_t r, g, b;
+ r = state_fio->FgetUint8();
+ g = state_fio->FgetUint8();
+ b = state_fio->FgetUint8();
+ palette_pc[i] = RGB_COLOR(r, g, b);
+ }
+ } else {
+ for(int i = 0; i < (sizeof(palette_pc) / sizeof(scrntype_t)); i++) {
+ uint8_t r, g, b;
+ r = R_OF_COLOR(palette_pc[i]);
+ g = G_OF_COLOR(palette_pc[i]);
+ b = B_OF_COLOR(palette_pc[i]);
+ state_fio->FputUint8(r);
+ state_fio->FputUint8(g);
+ state_fio->FputUint8(b);
+ }
+ }
+ state_fio->StateBuffer(solid_buf, sizeof(solid_buf), 1);
+ state_fio->StateBuffer(&header, sizeof(header), 1); // OK?
+// state_fio->StateBuffer(banks, sizeof(banks), 1);
+ for(int i = 0; i < (sizeof(banks) / sizeof(uint32_t)); i++) {
+ state_fio->StateUint32(banks[i]);
+ }
+ state_fio->StateUint32(chr_rom_size);
+// state_fio->StateInt32(chr_rom_mask);
+ if(loading) {
+ chr_rom_mask = (chr_rom_size / 0x400) - 1;
+ if(chr_rom != NULL) {
+ free(chr_rom);
+ }
+ chr_rom = (uint8_t *)malloc(chr_rom_size);
+ }
+ state_fio->StateBuffer(chr_rom, chr_rom_size, 1);
+ state_fio->StateBuffer(name_tables, sizeof(name_tables), 1);
+ state_fio->StateBuffer(spr_ram, sizeof(spr_ram), 1);
+ state_fio->StateBuffer(bg_pal, sizeof(bg_pal), 1);
+ state_fio->StateBuffer(spr_pal, sizeof(spr_pal), 1);
+ state_fio->StateUint8(spr_ram_rw_ptr);
+ state_fio->StateBuffer(regs, sizeof(regs), 1);
+ state_fio->StateUint16(bg_pattern_table_addr);
+ state_fio->StateUint16(spr_pattern_table_addr);
+ state_fio->StateUint16(ppu_addr_inc);
+ state_fio->StateUint8(rgb_bak);
+ state_fio->StateBool(toggle_2005_2006);
+ state_fio->StateUint8(read_2007_buffer);
+ state_fio->StateUint16(loopy_v);
+ state_fio->StateUint16(loopy_t);
+ state_fio->StateUint8(loopy_x);
// post process
- for(int i = 0; i < 12; i++) {
- set_ppu_bank(i, banks[i]);
+ if(loading) {
+ for(int i = 0; i < 12; i++) {
+ set_ppu_bank(i, banks[i]);
+ }
}
return true;
}
-
void render_bg(int v);
void render_spr(int v);
void update_palette();
- void decl_state_header(header_t *p);
public:
PPU(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
void write_data8(uint32_t addr, uint32_t data);
uint32_t read_data8(uint32_t addr);
void event_vline(int v, int clock);
- void decl_state();
- 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)