OSDN Git Service

[WIP] Update to upstream 2018-10-05.This still not finish.May cause FTBFS.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 8 Oct 2018 05:25:28 +0000 (14:25 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 8 Oct 2018 05:25:28 +0000 (14:25 +0900)
47 files changed:
source/src/CMakeLists.txt
source/src/common.cpp
source/src/common.h
source/src/config.cpp
source/src/config.h
source/src/emu.cpp
source/src/fifo.cpp
source/src/fifo.h
source/src/fileio.cpp
source/src/fileio.h
source/src/qt/emuutils/CMakeLists.txt
source/src/vm/am9511.cpp
source/src/vm/am9511.h
source/src/vm/and.cpp
source/src/vm/and.h
source/src/vm/ay_3_891x.cpp
source/src/vm/ay_3_891x.h
source/src/vm/beep.cpp
source/src/vm/beep.h
source/src/vm/datarec.cpp
source/src/vm/datarec.h
source/src/vm/device.h
source/src/vm/fm7/bubblecasette.h
source/src/vm/fm7/display.cpp
source/src/vm/fm7/dummydevice.cpp
source/src/vm/fm7/dummydevice.h
source/src/vm/fm7/fm7.cpp
source/src/vm/fm7/fm7_display.h
source/src/vm/fm7/fm_bubblecasette.cpp
source/src/vm/fmgen/fmgen.cpp
source/src/vm/fmgen/fmgen.h
source/src/vm/fmgen/fmtimer.cpp
source/src/vm/fmgen/fmtimer.h
source/src/vm/fmgen/opm.cpp
source/src/vm/fmgen/opm.h
source/src/vm/fmgen/opna.cpp
source/src/vm/fmgen/opna.h
source/src/vm/fmgen/psg.cpp
source/src/vm/fmgen/psg.h
source/src/vm/fmgen/readme_takeda.txt
source/src/vm/harddisk.cpp
source/src/vm/harddisk.h
source/src/vm/i386.cpp
source/src/vm/i386.h
source/src/vm/libcpu_newdev/device.cpp
source/src/vm/libcpu_newdev/device.h
source/src/vm/scsi_hdd.h

index 63cd0a5..d490826 100644 (file)
@@ -9,7 +9,6 @@ if(USE_DEVICES_SHARED_LIB)
   add_library(common_common
        config.cpp
        debugger.cpp
-#      statesub.cpp
        )
 else()
   add_library(common_common
@@ -18,6 +17,5 @@ else()
        debugger.cpp
        fileio.cpp
        fifo.cpp
-       statesub.cpp
        )
 endif()
index 00f6937..148885a 100644 (file)
@@ -1463,105 +1463,22 @@ void DLL_PREFIX cur_time_t::update_day_of_week()
 
 #define STATE_VERSION  1
 
-#include "./state_data.h"
 
-void DLL_PREFIX cur_time_t::save_state_helper(void *f, uint32_t *sumseed, bool *__stat)
-{
-       csp_state_data_saver *state_saver = (csp_state_data_saver *)f;
-       const _TCHAR *_ns = "cur_time_t::BEGIN";
-       const _TCHAR *_ne = "cur_time_t::END";
-       
-       if(f == NULL) return;
-       
-       state_saver->save_string_data(_ns, sumseed, strlen(_ns) + 1, __stat);
-       state_saver->put_dword(STATE_VERSION, sumseed, __stat);
-
-       state_saver->put_int32(year, sumseed, __stat);
-       state_saver->put_int8((int8_t)month, sumseed, __stat);
-       state_saver->put_int8((int8_t)day, sumseed, __stat);
-       state_saver->put_int8((int8_t)day_of_week, sumseed, __stat);
-       state_saver->put_int8((int8_t)hour, sumseed, __stat);
-       state_saver->put_int8((int8_t)minute, sumseed, __stat);
-       state_saver->put_int16((int16_t)second, sumseed, __stat);
-       state_saver->put_bool(initialized, sumseed, __stat);
-       
-       state_saver->save_string_data(_ne, sumseed, strlen(_ne) + 1, __stat);
-}
-
-bool DLL_PREFIX cur_time_t::load_state_helper(void *f, uint32_t *sumseed, bool *__stat)
-{
-       csp_state_data_saver *state_saver = (csp_state_data_saver *)f;
-       const _TCHAR *_ns = "cur_time_t::BEGIN";
-       const _TCHAR *_ne = "cur_time_t::END";
-       _TCHAR sbuf[128];
-       uint32_t tmpvar;
-
-       if(f == NULL) return false;
-       memset(sbuf, 0x00, sizeof(sbuf));
-       state_saver->load_string_data(sbuf, sumseed, strlen(_ns) + 1, __stat);
-       tmpvar = state_saver->get_dword(sumseed, __stat);
-       if(strncmp(sbuf, _ns, strlen(_ns) + 1) != 0) {
-               if(__stat != NULL) *__stat = false;
-               return false;
-       }
-       if(tmpvar != STATE_VERSION) {
-               if(__stat != NULL) *__stat = false;
-               return false;
-       }
-       year =              state_saver->get_int32(sumseed, __stat);
-       month =       (int)(state_saver->get_int8(sumseed, __stat));
-       day =         (int)(state_saver->get_int8(sumseed, __stat));
-       day_of_week = (int)(state_saver->get_int8(sumseed, __stat));
-       hour =        (int)(state_saver->get_int8(sumseed, __stat));
-       minute =      (int)(state_saver->get_int8(sumseed, __stat));
-       second =      (int)(state_saver->get_int16(sumseed, __stat));
-       initialized = state_saver->get_bool(sumseed, __stat);
-       
-       memset(sbuf, 0x00, sizeof(sbuf));
-       state_saver->load_string_data(sbuf, sumseed, strlen(_ne) + 1, __stat);
-       if(strncmp(_ne, sbuf, strlen(_ne) + 1) != 0) {
-               if(__stat != NULL) *__stat = false;
-               return false;
-       }
-       
-       if(__stat != NULL) {
-               if(*__stat == false) return false;
-               //*__stat = true;
-       }
-       return true;
-}
-
-void DLL_PREFIX cur_time_t::save_state(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       state_fio->FputUint32(STATE_VERSION);
-       
-       state_fio->FputInt32(year);
-       state_fio->FputInt32(month);
-       state_fio->FputInt32(day);
-       state_fio->FputInt32(day_of_week);
-       state_fio->FputInt32(hour);
-       state_fio->FputInt32(minute);
-       state_fio->FputInt32(second);
-       state_fio->FputBool(initialized);
-}
-
-bool DLL_PREFIX cur_time_t::load_state(void *f)
+bool DLL_PREFIX cur_time_t::process_state(void *f, bool loading)
 {
        FILEIO *state_fio = (FILEIO *)f;
        
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       year = state_fio->FgetInt32();
-       month = state_fio->FgetInt32();
-       day = state_fio->FgetInt32();
-       day_of_week = state_fio->FgetInt32();
-       hour = state_fio->FgetInt32();
-       minute = state_fio->FgetInt32();
-       second = state_fio->FgetInt32();
-       initialized = state_fio->FgetBool();
+       state_fio->StateInt32(year);
+       state_fio->StateInt32(month);
+       state_fio->StateInt32(day);
+       state_fio->StateInt32(day_of_week);
+       state_fio->StateInt32(hour);
+       state_fio->StateInt32(minute);
+       state_fio->StateInt32(second);
+       state_fio->StateBool(initialized);
        return true;
 }
 
index 74f77f4..5b1122e 100644 (file)
@@ -1163,10 +1163,7 @@ typedef DLL_PREFIX struct cur_time_s {
        void increment();
        void update_year();
        void update_day_of_week();
-       void save_state(void *f);
-       bool load_state(void *f);
-       void save_state_helper(void *f, uint32_t *sumseed, bool *__stat);
-       bool load_state_helper(void *f, uint32_t *sumseed, bool *__stat);
+       bool process_state(void *f, bool loading);
 } cur_time_t;
 
 void DLL_PREFIX get_host_time(cur_time_t* cur_time);
index 2a8accf..bc260b2 100644 (file)
@@ -864,103 +864,54 @@ void save_config(const _TCHAR *config_path)
 
 #define STATE_VERSION  6
 
-void save_config_state(void *f)
+bool process_config_state(void *f, bool loading)
 {
        FILEIO *state_fio = (FILEIO *)f;
        
-       state_fio->FputUint32(STATE_VERSION);
-       
-       #ifdef USE_BOOT_MODE
-               state_fio->FputInt32(config.boot_mode);
-       #endif
-       #ifdef USE_CPU_TYPE
-               state_fio->FputInt32(config.cpu_type);
-       #endif
-       #ifdef USE_DIPSWITCH
-               state_fio->FputUint32(config.dipswitch);
-       #endif
-       #ifdef USE_DEVICE_TYPE
-               state_fio->FputInt32(config.device_type);
-       #endif
-       #ifdef USE_DRIVE_TYPE
-               state_fio->FputInt32(config.drive_type);
-       #endif
-       #ifdef USE_KEYBOARD_TYPE
-               state_fio->FputInt32(config.keyboard_type);
-       #endif
-       #ifdef USE_MOUSE_TYPE
-               state_fio->FputInt32(config.mouse_type);
-       #endif
-       #ifdef USE_JOYSTICK_TYPE
-               state_fio->FputInt32(config.joystick_type);
-       #endif
-       #ifdef USE_SOUND_TYPE
-               state_fio->FputInt32(config.sound_type);
-       #endif
-       #ifdef USE_MONITOR_TYPE
-               state_fio->FputInt32(config.monitor_type);
-       #endif
-       #ifdef USE_PRINTER_TYPE
-               state_fio->FputInt32(config.printer_type);
-       #endif
-       #ifdef USE_FLOPPY_DISK
-               for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
-                       state_fio->FputBool(config.correct_disk_timing[drv]);
-                       state_fio->FputBool(config.ignore_disk_crc[drv]);
-               }
-       #endif
-       state_fio->FputInt32(config.sound_frequency);
-       state_fio->FputInt32(config.sound_latency);
-}
-
-bool load_config_state(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
        #ifdef USE_BOOT_MODE
-               config.boot_mode = state_fio->FgetInt32();
+               state_fio->StateInt32(config.boot_mode);
        #endif
        #ifdef USE_CPU_TYPE
-               config.cpu_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.cpu_type);
        #endif
        #ifdef USE_DIPSWITCH
-               config.dipswitch = state_fio->FgetUint32();
+               state_fio->StateUint32(config.dipswitch);
        #endif
        #ifdef USE_DEVICE_TYPE
-               config.device_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.device_type);
        #endif
        #ifdef USE_DRIVE_TYPE
-               config.drive_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.drive_type);
        #endif
        #ifdef USE_KEYBOARD_TYPE
-               config.keyboard_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.keyboard_type);
        #endif
        #ifdef USE_MOUSE_TYPE
-               config.mouse_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.mouse_type);
        #endif
        #ifdef USE_JOYSTICK_TYPE
-               config.joystick_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.joystick_type);
        #endif
        #ifdef USE_SOUND_TYPE
-               config.sound_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.sound_type);
        #endif
        #ifdef USE_MONITOR_TYPE
-               config.monitor_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.monitor_type);
        #endif
        #ifdef USE_PRINTER_TYPE
-               config.printer_type = state_fio->FgetInt32();
+               state_fio->StateInt32(config.printer_type);
        #endif
        #ifdef USE_FLOPPY_DISK
                for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
-                       config.correct_disk_timing[drv] = state_fio->FgetBool();
-                       config.ignore_disk_crc[drv] = state_fio->FgetBool();
+                       state_fio->StateBool(config.correct_disk_timing[drv]);
+                       state_fio->StateBool(config.ignore_disk_crc[drv]);
                }
        #endif
-       config.sound_frequency = state_fio->FgetInt32();
-       config.sound_latency = state_fio->FgetInt32();
+       state_fio->StateInt32(config.sound_frequency);
+       state_fio->StateInt32(config.sound_latency);
        return true;
 }
 
index 9aef1fc..10cfea0 100644 (file)
@@ -101,8 +101,7 @@ enum {
 void DLL_PREFIX initialize_config();
 void DLL_PREFIX load_config(const _TCHAR* config_path);
 void DLL_PREFIX save_config(const _TCHAR* config_path);
-void DLL_PREFIX save_config_state(void *f);
-bool DLL_PREFIX load_config_state(void *f);
+bool DLL_PREFIX process_config_state(void *f, bool loading);
 
 /*
  * 20160407 Ohta:
index c925418..64d6f1e 100644 (file)
@@ -2847,7 +2847,7 @@ void EMU::save_state(const _TCHAR* file_path)
                // save state file version
                fio->FputUint32(STATE_VERSION);
                // save config
-               save_config_state((void *)fio);
+               process_config_state((void *)fio, false);
                // save inserted medias
 #ifdef USE_CART
                fio->Fwrite(&cart_status, sizeof(cart_status), 1);
@@ -2875,9 +2875,9 @@ void EMU::save_state(const _TCHAR* file_path)
                fio->Fwrite(&bubble_casette_status, sizeof(bubble_casette_status), 1);
 #endif
                // save vm state
-               vm->save_state(fio);
+               vm->process_state(fio, false);
                // end of state file
-               fio->FputInt32(-1);
+               fio->FputInt32_LE(-1);
                fio->Fclose();
        }
        osd->unlock_vm();
@@ -2918,7 +2918,7 @@ bool EMU::load_state_tmp(const _TCHAR* file_path)
                // check state file version
                if(fio->FgetUint32() == STATE_VERSION) {
                        // load config
-                       if(load_config_state((void *)fio)) {
+                       if(process_config_state((void *)fio, true)) {
                                // load inserted medias
 #ifdef USE_CART
                                fio->Fread(&cart_status, sizeof(cart_status), 1);
@@ -2994,9 +2994,9 @@ bool EMU::load_state_tmp(const _TCHAR* file_path)
                                        restore_media();
                                }
                                // load vm state
-                               if(vm->load_state(fio)) {
+                               if(vm->process_state(fio, true)) {
                                        // check end of state
-                                       result = (fio->FgetInt32() == -1);
+                                       result = (fio->FgetInt32_LE() == -1);
                                }
                        }
                }
index 20b694f..06c95d2 100644 (file)
@@ -93,97 +93,18 @@ bool FIFO::empty()
 
 #define STATE_VERSION  1
 
-#include "./state_data.h"
-
-void FIFO::save_state_helper(csp_state_data_saver *state_saver, uint32_t *sumseed, bool *__stat)
-{
-       if(state_saver == NULL) return;
-
-       state_saver->save_string_data(_ns, sumseed, strlen(_ns) + 1, __stat);
-       state_saver->put_dword(STATE_VERSION, sumseed, __stat);
-       
-       state_saver->put_int32(size, sumseed, __stat);
-       for(int i = 0; i < size; i++) {
-               state_saver->put_int32(buf[i], sumseed, __stat);
-       }
-       state_saver->put_int32(cnt, sumseed, __stat);
-       state_saver->put_int32(rpt, sumseed, __stat);
-       state_saver->put_int32(wpt, sumseed, __stat);
-       
-       state_saver->save_string_data(_ne, sumseed, strlen(_ne) + 1, __stat);
-       
-}
-
-bool FIFO::load_state_helper(csp_state_data_saver *state_saver, uint32_t *sumseed, bool *__stat)
-{
-
-       _TCHAR sbuf[128];
-       uint32_t tmpvar;
-       if(state_saver == NULL) return false;
-       
-       memset(sbuf, 0x00, sizeof(sbuf));
-       state_saver->load_string_data(sbuf, sumseed, strlen(_ns) + 1, __stat);
-       tmpvar = state_saver->get_dword(sumseed, __stat);
-
-       if(strncmp(sbuf, _ns, strlen(_ns) + 1) != 0) {
-               if(__stat != NULL) *__stat = false;
-               return false;
-       }
-       if(tmpvar != STATE_VERSION) {
-               if(__stat != NULL) *__stat = false;
-               return false;
-       }
-       
-       size = state_saver->get_int32(sumseed, __stat);
-       for(int i = 0; i < size; i++) {
-               buf[i] = state_saver->get_int32(sumseed, __stat);
-       }
-       cnt = state_saver->get_int32(sumseed, __stat);
-       rpt = state_saver->get_int32(sumseed, __stat);
-       wpt = state_saver->get_int32(sumseed, __stat);
-       
-       memset(sbuf, 0x00, sizeof(sbuf));
-       state_saver->load_string_data(sbuf, sumseed, strlen(_ne) + 1, __stat);
-       if(strncmp(_ne, sbuf, strlen(_ne) + 1) != 0) {
-               if(__stat != NULL) *__stat = false;
-               return false;
-       }
-       
-       if(__stat != NULL) {
-               if(*__stat == false) return false;
-               //*__stat = true;
-       }
-       return true;
-}
-
-
-void FIFO::save_state(void *f)
+bool FIFO::process_state(void *f, bool loading)
 {
        FILEIO *state_fio = (FILEIO *)f;
        
-       state_fio->FputUint32(STATE_VERSION);
-       
-       state_fio->FputInt32(size);
-       state_fio->Fwrite(buf, size * sizeof(int), 1);
-       state_fio->FputInt32(cnt);
-       state_fio->FputInt32(rpt);
-       state_fio->FputInt32(wpt);
-}
-
-bool FIFO::load_state(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != size) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       state_fio->Fread(buf, size * sizeof(int), 1);
-       cnt = state_fio->FgetInt32();
-       rpt = state_fio->FgetInt32();
-       wpt = state_fio->FgetInt32();
+       state_fio->StateInt32(size);
+       state_fio->StateBuffer(buf, size * sizeof(int), 1);
+       state_fio->StateInt32(cnt);
+       state_fio->StateInt32(rpt);
+       state_fio->StateInt32(wpt);
        return true;
 }
 
index 6477cf3..e810ef9 100644 (file)
@@ -20,8 +20,6 @@ private:
        int* buf;
        int cnt, rpt, wpt;
 
-       const _TCHAR *_ns = "FIFO::BEGIN";
-       const _TCHAR *_ne = "FIFO::END";
 public:
        FIFO(int s);
        void release();
@@ -33,12 +31,7 @@ public:
        int count();
        bool full();
        bool empty();
-       void save_state(void *f);
-       bool load_state(void *f);
-
-       void save_state_helper(csp_state_data_saver *state_saver, uint32_t *sumseed, bool *__stat);
-       bool load_state_helper(csp_state_data_saver *state_saver, uint32_t *sumseed, bool *__stat);
-       
+       bool process_state(void *f, bool loading);
 };
 
 #endif
index dddaf8c..fe34673 100644 (file)
        #include <windows.h>
 #endif
 #include "fileio.h"
-#if !defined(_MSC_VER)
-#include <stdarg.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <iostream>
-#include <fstream>
-#include <cstdio>
-#endif
 
 #ifdef USE_ZLIB
        #if defined(USE_QT)
@@ -73,7 +65,8 @@
                        return i + 1;
                }
        #endif
-#endif                 
+#endif
+
 FILEIO::FILEIO()
 {
 #ifdef USE_ZLIB
@@ -91,41 +84,33 @@ FILEIO::~FILEIO(void)
 bool FILEIO::IsFileExisting(const _TCHAR *file_path)
 {
 #if defined(_USE_QT) || defined(_USE_SDL)
-       FILE *f;
-       f = fopen(file_path, "r");
-       if(f != NULL)  {
-               fclose(f);         
+       FILE *f = fopen(file_path, "r");
+       if(f != NULL) {
+               fclose(f);
                return true;
        }
        return false;
 #elif defined(_WIN32)
        DWORD attr = GetFileAttributes(file_path);
-       if(attr == -1) {
-               return false;
-       }
-       return ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0);
+       if(attr == -1) {
+               return false;
+       }
+       return ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0);
 #else
        return (_taccess(file_path, 0) == 0);
 #endif
 }
 
-#if defined(_USE_QT)
-# include <sys/types.h>
-# include <sys/stat.h>
-# if !defined(Q_OS_WIN)
-#   include <unistd.h>
-# endif
-#endif
 bool FILEIO::IsFileProtected(const _TCHAR *file_path)
 {
 #if defined(_USE_QT) || defined(_USE_SDL)
        struct stat st;
        if(stat(file_path, &st) == 0) {
-# if defined(_WIN32)
+#if defined(_WIN32)
                if((st.st_mode & S_IWUSR) == 0) {
-# else
+#else
                if((st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0) {
-# endif
+#endif
                        return true;
                }
        }
@@ -144,7 +129,7 @@ bool FILEIO::RemoveFile(const _TCHAR *file_path)
 #elif defined(_WIN32)
        return (DeleteFile(file_path) != 0);
 #else
-       return (_tremove(file_path) == 0);      // not supported on wince ???
+       return (_tremove(file_path) == 0);
 #endif
 }
 
@@ -156,7 +141,7 @@ bool FILEIO::RenameFile(const _TCHAR *existing_file_path, const _TCHAR *new_file
        return (MoveFile(existing_file_path, new_file_path) != 0);
 #else
        return (_trename(existing_file_path, new_file_path) == 0);
-#endif                 
+#endif
 }
 
 bool FILEIO::Fopen(const _TCHAR *file_path, int mode)
@@ -165,6 +150,7 @@ bool FILEIO::Fopen(const _TCHAR *file_path, int mode)
        
        // store file path
        my_tcscpy_s(path, _MAX_PATH, file_path);
+       open_mode = mode;
        
 #ifdef USE_ZLIB
        if(check_file_extension(file_path, _T(".gz"))) {
@@ -201,6 +187,10 @@ bool FILEIO::Gzopen(const _TCHAR *file_path, int mode)
 {
        gz_size = 0;
        
+       // store file path
+       my_tcscpy_s(path, _MAX_PATH, file_path);
+       open_mode = mode;
+       
        switch(mode) {
        case FILEIO_READ_BINARY:
 //     case FILEIO_READ_WRITE_BINARY:
@@ -245,21 +235,21 @@ bool FILEIO::Gzopen(const _TCHAR *file_path, int mode)
        case FILEIO_WRITE_BINARY:
                return ((gz = gzopen(tchar_to_char(file_path), "wb")) != NULL);
 //     case FILEIO_READ_WRITE_BINARY:
-//             return ((fp = _tfopen(file_path, _T("r+b"))) != NULL);
+//             return ((gz = gzopen(tchar_to_char(file_path), "r+b")) != NULL);
 //     case FILEIO_READ_WRITE_NEW_BINARY:
-//             return ((fp = _tfopen(file_path, _T("w+b"))) != NULL);
+//             return ((gz = gzopen(tchar_to_char(file_path), "w+b")) != NULL);
        case FILEIO_READ_ASCII:
                return ((gz = gzopen(tchar_to_char(file_path), "r")) != NULL);
        case FILEIO_WRITE_ASCII:
                return ((gz = gzopen(tchar_to_char(file_path), "w")) != NULL);
 //     case FILEIO_WRITE_APPEND_ASCII:
-//             return ((fp = _tfopen(file_path, _T("a"))) != NULL);
+//             return ((gz = gzopen(tchar_to_char(file_path), "a")) != NULL);
 //     case FILEIO_READ_WRITE_ASCII:
-//             return ((fp = _tfopen(file_path, _T("r+"))) != NULL);
+//             return ((gz = gzopen(tchar_to_char(file_path), "r+")) != NULL);
 //     case FILEIO_READ_WRITE_NEW_ASCII:
-//             return ((fp = _tfopen(file_path, _T("w+"))) != NULL);
+//             return ((gz = gzopen(tchar_to_char(file_path), "w+")) != NULL);
 //     case FILEIO_READ_WRITE_APPEND_ASCII:
-//             return ((fp = _tfopen(file_path, _T("a+"))) != NULL);
+//             return ((gz = gzopen(tchar_to_char(file_path), "a+")) != NULL);
        }
        return false;
 }
@@ -274,9 +264,9 @@ void FILEIO::Fclose()
        }
 #endif
        if(fp != NULL) {
-               fclose(fp);
+               fclose(fp);
                fp = NULL;
-       }
+       }
        path[0] = _T('\0');
 }
 
@@ -290,9 +280,9 @@ long FILEIO::FileLength()
 }
 
 #define GET_VALUE(type) \
-       uint8_t buffer[sizeof(type)] = {0};             \
-       Fread(buffer, sizeof(buffer), 1);               \
-       return *(type *)buffer;                                         
+       uint8_t buffer[sizeof(type)] = {0}; \
+       Fread(buffer, sizeof(buffer), 1); \
+       return *(type *)buffer
 
 #define PUT_VALUE(type, v) \
        Fwrite(&v, sizeof(type), 1)
@@ -407,6 +397,17 @@ void FILEIO::FputDouble(double val)
        PUT_VALUE(double, val);
 }
 
+typedef union {
+       struct {
+#ifdef __BIG_ENDIAN__
+               uint8_t h, l;
+#else
+               uint8_t l, h;
+#endif
+       } b;
+       uint16_t u16;
+       int16_t s16;
+} pair16_t;
 
 typedef union {
        struct {
@@ -418,21 +419,34 @@ typedef union {
        } b;
        uint32_t u32;
        int32_t s32;
+       float f32;
 } pair32_t;
 
+typedef union {
+       struct {
+#ifdef __BIG_ENDIAN__
+               uint8_t h7, h6, h5, h4, h3, h2, h, l;
+#else
+               uint8_t l, h, h2, h3, h4, h5, h6, h7;
+#endif
+       } b;
+       uint64_t u64;
+       int64_t s64;
+       double d64;
+} pair64_t;
 
 uint16_t FILEIO::FgetUint16_LE()
 {
        pair16_t tmp;
        tmp.b.l = FgetUint8();
        tmp.b.h = FgetUint8();
-       return tmp.w;
+       return tmp.u16;
 }
 
 void FILEIO::FputUint16_LE(uint16_t val)
 {
        pair16_t tmp;
-       tmp.w = val;
+       tmp.u16 = val;
        FputUint8(tmp.b.l);
        FputUint8(tmp.b.h);
 }
@@ -468,13 +482,13 @@ uint64_t FILEIO::FgetUint64_LE()
        tmp.b.h5 = FgetUint8();
        tmp.b.h6 = FgetUint8();
        tmp.b.h7 = FgetUint8();
-       return tmp.q;
+       return tmp.u64;
 }
 
 void FILEIO::FputUint64_LE(uint64_t val)
 {
        pair64_t tmp;
-       tmp.q = val;
+       tmp.u64 = val;
        FputUint8(tmp.b.l);
        FputUint8(tmp.b.h);
        FputUint8(tmp.b.h2);
@@ -490,13 +504,13 @@ int16_t FILEIO::FgetInt16_LE()
        pair16_t tmp;
        tmp.b.l = FgetUint8();
        tmp.b.h = FgetUint8();
-       return tmp.sw;
+       return tmp.s16;
 }
 
 void FILEIO::FputInt16_LE(int16_t val)
 {
        pair16_t tmp;
-       tmp.sw = val;
+       tmp.s16 = val;
        FputUint8(tmp.b.l);
        FputUint8(tmp.b.h);
 }
@@ -532,13 +546,61 @@ int64_t FILEIO::FgetInt64_LE()
        tmp.b.h5 = FgetUint8();
        tmp.b.h6 = FgetUint8();
        tmp.b.h7 = FgetUint8();
-       return tmp.sq;
+       return tmp.s64;
 }
 
 void FILEIO::FputInt64_LE(int64_t val)
 {
        pair64_t tmp;
-       tmp.sq = val;
+       tmp.s64 = val;
+       FputUint8(tmp.b.l);
+       FputUint8(tmp.b.h);
+       FputUint8(tmp.b.h2);
+       FputUint8(tmp.b.h3);
+       FputUint8(tmp.b.h4);
+       FputUint8(tmp.b.h5);
+       FputUint8(tmp.b.h6);
+       FputUint8(tmp.b.h7);
+}
+
+float FILEIO::FgetFloat_LE()
+{
+       pair32_t tmp;
+       tmp.b.l  = FgetUint8();
+       tmp.b.h  = FgetUint8();
+       tmp.b.h2 = FgetUint8();
+       tmp.b.h3 = FgetUint8();
+       return tmp.f32;
+}
+
+void FILEIO::FputFloat_LE(float val)
+{
+       pair32_t tmp;
+       tmp.f32 = val;
+       FputUint8(tmp.b.l);
+       FputUint8(tmp.b.h);
+       FputUint8(tmp.b.h2);
+       FputUint8(tmp.b.h3);
+}
+
+double FILEIO::FgetDouble_LE()
+{
+       pair64_t tmp;
+       tmp.b.l  = FgetUint8();
+       tmp.b.h  = FgetUint8();
+       tmp.b.h2 = FgetUint8();
+       tmp.b.h3 = FgetUint8();
+       tmp.b.h4 = FgetUint8();
+       tmp.b.h5 = FgetUint8();
+       tmp.b.h6 = FgetUint8();
+       tmp.b.h7 = FgetUint8();
+       return tmp.d64;
+}
+
+void FILEIO::FputDouble_LE(double val)
+{
+       pair64_t tmp;
+       tmp.d64 = val;
        FputUint8(tmp.b.l);
        FputUint8(tmp.b.h);
        FputUint8(tmp.b.h2);
@@ -554,13 +616,13 @@ uint16_t FILEIO::FgetUint16_BE()
        pair16_t tmp;
        tmp.b.h = FgetUint8();
        tmp.b.l = FgetUint8();
-       return tmp.w;
+       return tmp.u16;
 }
 
 void FILEIO::FputUint16_BE(uint16_t val)
 {
        pair16_t tmp;
-       tmp.w = val;
+       tmp.u16 = val;
        FputUint8(tmp.b.h);
        FputUint8(tmp.b.l);
 }
@@ -596,13 +658,13 @@ uint64_t FILEIO::FgetUint64_BE()
        tmp.b.h2 = FgetUint8();
        tmp.b.h  = FgetUint8();
        tmp.b.l  = FgetUint8();
-       return tmp.q;
+       return tmp.u64;
 }
 
 void FILEIO::FputUint64_BE(uint64_t val)
 {
        pair64_t tmp;
-       tmp.q = val;
+       tmp.u64 = val;
        FputUint8(tmp.b.h7);
        FputUint8(tmp.b.h6);
        FputUint8(tmp.b.h5);
@@ -618,13 +680,13 @@ int16_t FILEIO::FgetInt16_BE()
        pair16_t tmp;
        tmp.b.h = FgetUint8();
        tmp.b.l = FgetUint8();
-       return tmp.sw;
+       return tmp.s16;
 }
 
 void FILEIO::FputInt16_BE(int16_t val)
 {
        pair16_t tmp;
-       tmp.sw = val;
+       tmp.s16 = val;
        FputUint8(tmp.b.h);
        FputUint8(tmp.b.l);
 }
@@ -660,13 +722,61 @@ int64_t FILEIO::FgetInt64_BE()
        tmp.b.h2 = FgetUint8();
        tmp.b.h  = FgetUint8();
        tmp.b.l  = FgetUint8();
-       return tmp.sq;
+       return tmp.s64;
 }
 
 void FILEIO::FputInt64_BE(int64_t val)
 {
        pair64_t tmp;
-       tmp.sq = val;
+       tmp.s64 = val;
+       FputUint8(tmp.b.h7);
+       FputUint8(tmp.b.h6);
+       FputUint8(tmp.b.h5);
+       FputUint8(tmp.b.h4);
+       FputUint8(tmp.b.h3);
+       FputUint8(tmp.b.h2);
+       FputUint8(tmp.b.h);
+       FputUint8(tmp.b.l);
+}
+
+float FILEIO::FgetFloat_BE()
+{
+       pair32_t tmp;
+       tmp.b.h3 = FgetUint8();
+       tmp.b.h2 = FgetUint8();
+       tmp.b.h  = FgetUint8();
+       tmp.b.l  = FgetUint8();
+       return tmp.f32;
+}
+
+void FILEIO::FputFloat_BE(float val)
+{
+       pair32_t tmp;
+       tmp.f32 = val;
+       FputUint8(tmp.b.h3);
+       FputUint8(tmp.b.h2);
+       FputUint8(tmp.b.h);
+       FputUint8(tmp.b.l);
+}
+
+double FILEIO::FgetDouble_BE()
+{
+       pair64_t tmp;
+       tmp.b.h7 = FgetUint8();
+       tmp.b.h6 = FgetUint8();
+       tmp.b.h5 = FgetUint8();
+       tmp.b.h4 = FgetUint8();
+       tmp.b.h3 = FgetUint8();
+       tmp.b.h2 = FgetUint8();
+       tmp.b.h  = FgetUint8();
+       tmp.b.l  = FgetUint8();
+       return tmp.d64;
+}
+
+void FILEIO::FputDouble_BE(double val)
+{
+       pair64_t tmp;
+       tmp.d64 = val;
        FputUint8(tmp.b.h7);
        FputUint8(tmp.b.h6);
        FputUint8(tmp.b.h5);
@@ -684,10 +794,8 @@ int FILEIO::Fgetc()
                return gzgetc(gz);
        } else
 #endif
-       {
-               if(fp != NULL) {
-                       return getc(fp);
-               }
+       if(fp != NULL) {
+               return fgetc(fp);
        }
        return 0;
 }
@@ -699,13 +807,11 @@ int FILEIO::Fputc(int c)
                return gzputc(gz, c);
        } else
 #endif
-       {
-               if(fp != NULL) {
-                       return fputc(c, fp);
-               }
+       if(fp != NULL) {
+               return fputc(c, fp);
        }
        return 0;
- }
+}
 
 char *FILEIO::Fgets(char *str, int n)
 {
@@ -714,10 +820,8 @@ char *FILEIO::Fgets(char *str, int n)
                return gzgets(gz, str, n);
        } else
 #endif
-       {
-               if(fp != NULL) {
-                       return fgets(str, n, fp);
-               }
+       if(fp != NULL) {
+               return fgets(str, n, fp);
        }
        return 0;
 }
@@ -737,7 +841,10 @@ _TCHAR *FILEIO::Fgetts(_TCHAR *str, int n)
 #endif
        } else
 #endif
-       return _fgetts(str, n, fp);
+       if(fp != NULL) {
+               return _fgetts(str, n, fp);
+       }
+       return 0;
 }
 
 int FILEIO::Fprintf(const char* format, ...)
@@ -793,18 +900,6 @@ size_t FILEIO::Fread(void* buffer, size_t size, size_t count)
        return 0;
 }
 
-bool FILEIO::Fflush()
-{
-#ifdef USE_ZLIB
-       if(gz != NULL) {
-               return (gzflush(gz, Z_SYNC_FLUSH) == Z_OK) ? true : false;
-       } else
-#endif
-       {
-               return (fflush(fp) == 0) ? true : false;
-       }
-}
-
 size_t FILEIO::Fwrite(const void* buffer, size_t size, size_t count)
 {
 #ifdef USE_ZLIB
@@ -856,17 +951,166 @@ long FILEIO::Ftell()
                return ftell(fp);
        }
        return 0;
- }
-
+}
 
 bool FILEIO::Fcompare(const void* buffer, size_t size)
 {
-       bool result = false;
+       return Fcompare(buffer, size, 1);
+}
+
+bool FILEIO::Fcompare(const void* buffer, size_t size, size_t count)
+{
+       bool result = true;
        void *tmp = malloc(size);
        
-       if(Fread(tmp, size, 1) == 1) {
-               result = (memcmp(buffer, tmp, size) == 0);
+       for(size_t i = 0; i < count; i++) {
+               if(Fread(tmp, size, 1) != 1) {
+                       result = false;
+                       break;
+               }
+               if(memcmp(buffer, tmp, size) != 0) {
+                       result = false;
+                       break;
+               }
        }
        free(tmp);
        return result;
 }
+
+bool FILEIO::StateCheckUint32(uint32_t val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               return (val == FgetUint32_LE());
+       } else {
+               FputUint32_LE(val);
+               return true;
+       }
+}
+
+bool FILEIO::StateCheckInt32(int32_t val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               return (val == FgetInt32_LE());
+       } else {
+               FputInt32_LE(val);
+               return true;
+       }
+}
+
+bool FILEIO::StateCheckBuffer(const void *buffer, size_t size, size_t count)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               return Fcompare(buffer, size, count);
+       } else {
+               Fwrite(buffer, size, count);
+               return true;
+       }
+}
+
+void FILEIO::StateBool(bool &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetBool();
+       } else {
+               FputBool(val);
+       }
+}
+
+void FILEIO::StateUint8(uint8_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetUint8();
+       } else {
+               FputUint8(val);
+       }
+}
+
+void FILEIO::StateUint16(uint16_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetUint16_LE();
+       } else {
+               FputUint16_LE(val);
+       }
+}
+
+void FILEIO::StateUint32(uint32_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetUint32_LE();
+       } else {
+               FputUint32_LE(val);
+       }
+}
+
+void FILEIO::StateUint64(uint64_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetUint64_LE();
+       } else {
+               FputUint64_LE(val);
+       }
+}
+
+void FILEIO::StateInt8(int8_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetInt8();
+       } else {
+               FputInt8(val);
+       }
+}
+
+void FILEIO::StateInt16(int16_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetInt16_LE();
+       } else {
+               FputInt16_LE(val);
+       }
+}
+
+void FILEIO::StateInt32(int32_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetInt32_LE();
+       } else {
+               FputInt32_LE(val);
+       }
+}
+
+void FILEIO::StateInt64(int64_t &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetInt64_LE();
+       } else {
+               FputInt64_LE(val);
+       }
+}
+
+void FILEIO::StateFloat(float &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetFloat_LE();
+       } else {
+               FputFloat_LE(val);
+       }
+}
+
+void FILEIO::StateDouble(double &val)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               val = FgetDouble_LE();
+       } else {
+               FputDouble_LE(val);
+       }
+}
+
+void FILEIO::StateBuffer(void *buffer, size_t size, size_t count)
+{
+       if(open_mode == FILEIO_READ_BINARY) {
+               Fread(buffer, size, count);
+       } else {
+               Fwrite(buffer, size, count);
+       }
+}
index 1f0a83c..78a6619 100644 (file)
@@ -41,6 +41,7 @@ private:
 #endif
        FILE* fp;
        _TCHAR path[_MAX_PATH];
+       int open_mode;
        
 public:
        FILEIO();
@@ -50,7 +51,7 @@ public:
        static bool IsFileProtected(const _TCHAR *file_path);
        static bool RemoveFile(const _TCHAR *file_path);
        static bool RenameFile(const _TCHAR *existing_file_path, const _TCHAR *new_file_path);
-
+       
        bool Fopen(const _TCHAR *file_path, int mode);
 #ifdef USE_ZLIB
        bool Gzopen(const _TCHAR *file_path, int mode);
@@ -106,6 +107,10 @@ public:
        void FputInt32_LE(int32_t val);
        int64_t FgetInt64_LE();
        void FputInt64_LE(int64_t val);
+       float FgetFloat_LE();
+       void FputFloat_LE(float val);
+       double FgetDouble_LE();
+       void FputDouble_LE(double val);
        
        uint16_t FgetUint16_BE();
        void FputUint16_BE(uint16_t val);
@@ -119,6 +124,10 @@ public:
        void FputInt32_BE(int32_t val);
        int64_t FgetInt64_BE();
        void FputInt64_BE(int64_t val);
+       float FgetFloat_BE();
+       void FputFloat_BE(float val);
+       double FgetDouble_BE();
+       void FputDouble_BE(double val);
        
        int Fgetc();
        int Fputc(int c);
@@ -126,13 +135,30 @@ public:
        _TCHAR *Fgetts(_TCHAR *str, int n);
        int Fprintf(const char* format, ...);
        int Ftprintf(const _TCHAR* format, ...);
-
+       
        size_t Fread(void* buffer, size_t size, size_t count);
        size_t Fwrite(const void* buffer, size_t size, size_t count);
-       bool Fflush();
        int Fseek(long offset, int origin);
        long Ftell();
        bool Fcompare(const void* buffer, size_t size);
+       bool Fcompare(const void* buffer, size_t size, size_t count);
+       
+       bool StateCheckUint32(uint32_t val);
+       bool StateCheckInt32(int32_t val);
+       bool StateCheckBuffer(const void *buffer, size_t size, size_t count);
+       
+       void StateBool(bool &val);
+       void StateUint8(uint8_t &val);
+       void StateUint16(uint16_t &val);
+       void StateUint32(uint32_t &val);
+       void StateUint64(uint64_t &val);
+       void StateInt8(int8_t &val);
+       void StateInt16(int16_t &val);
+       void StateInt32(int32_t &val);
+       void StateInt64(int64_t &val);
+       void StateFloat(float &val);
+       void StateDouble(double &val);
+       void StateBuffer(void *buffer, size_t size, size_t count);
 };
 
 #endif
index e6502e0..68df872 100644 (file)
@@ -2,20 +2,18 @@ message("* qt/emuutils")
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
-         ../../statesub.h
        )
        
 set(s_qt_emuutils_srcs
          ../../common.cpp
          ../../fifo.cpp
          ../../fileio.cpp
-         ../../statesub.cpp
          ../gui/csp_logger.cpp
          )
 
 QT5_WRAP_CPP(s_qt_emuutils_headers_MOC ${s_qt_emuutils_headers})
        
-SET(THIS_LIB_VERSION 2.12.3
+SET(THIS_LIB_VERSION 2.13.0
 
 add_definitions(-D__LIBEMU_UTIL_VERSION=\"libCSPemu_utils.${THIS_LIB_VERSION}\")
 
index 9fb1426..dd6c4a8 100644 (file)
@@ -669,50 +669,18 @@ void AM9511::event_callback(int event_id, int err)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void AM9511::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-
-       DECL_STATE_ENTRY_1D_ARRAY(_apu_stack, sizeof(_apu_stack));
-       DECL_STATE_ENTRY_INT32(_apu_tos);
-       DECL_STATE_ENTRY_UINT8(_apu_status);
-       DECL_STATE_ENTRY_INT32(register_id);
-
-       leave_decl_state();
-}
-void AM9511::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(_apu_stack, sizeof(_apu_stack), 1);
-       //state_fio->FputInt32(_apu_tos);
-       //state_fio->FputUint8(_apu_status);
-       //state_fio->FputInt32(register_id);
-}
-
-bool AM9511::load_state(FILEIO* state_fio)
+bool AM9511::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(_apu_stack, sizeof(_apu_stack), 1);
-       //_apu_tos = state_fio->FgetInt32();
-       //_apu_status = state_fio->FgetUint8();
-       //register_id = state_fio->FgetInt32();
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(_apu_stack, sizeof(_apu_stack), 1);
+       state_fio->StateInt32(_apu_tos);
+       state_fio->StateUint8(_apu_status);
+       state_fio->StateInt32(register_id);
        return true;
 }
+
index c20080c..5a2428f 100644 (file)
@@ -61,9 +61,7 @@ public:
        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
index a379660..4873e05 100644 (file)
@@ -26,52 +26,18 @@ void AND::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void AND::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-
-       DECL_STATE_ENTRY_UINT32(bits_mask);
-       DECL_STATE_ENTRY_UINT32(bits_in);
-       DECL_STATE_ENTRY_BOOL(prev);
-       DECL_STATE_ENTRY_BOOL(first);
-
-       leave_decl_state();
-}
-
-void AND::save_state(FILEIO* state_fio)
+bool AND::process_state(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->FputUint32(bits_mask);
-       //state_fio->FputUint32(bits_in);
-       //state_fio->FputBool(prev);
-       //state_fio->FputBool(first);
-}
-
-bool AND::load_state(FILEIO* state_fio)
-{
-       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;
-       //}
-       //bits_mask = state_fio->FgetUint32();
-       //bits_in = state_fio->FgetUint32();
-       //prev = state_fio->FgetBool();
-       //first = state_fio->FgetBool();
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint32(bits_mask);
+       state_fio->StateUint32(bits_in);
+       state_fio->StateBool(prev);
+       state_fio->StateBool(first);
        return true;
 }
 
index 0125cff..dc01ef0 100644 (file)
@@ -44,9 +44,7 @@ public:
        
        // common functions
        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 set_context_out(DEVICE* device, int id, uint32_t mask)
        {
index a430e5c..0f0f10d 100644 (file)
@@ -214,104 +214,37 @@ void AY_3_891X::update_timing(int new_clocks, double new_frames_per_sec, int new
        clock_const = (uint32_t)((double)chip_clock * 1024.0 * 1024.0 / (double)new_clocks + 0.5);
 }
 
-#define STATE_VERSION  4
-
-#include "../statesub.h"
-
-void AY_3_891X::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_UINT8(ch);
-       DECL_STATE_ENTRY_UINT8(fnum2);
-#ifdef SUPPORT_AY_3_891X_PORT
-       for(int i = 0; i < 2; i++) {
-               DECL_STATE_ENTRY_UINT8_MEMBER((port[i].wreg), i);
-               DECL_STATE_ENTRY_UINT8_MEMBER((port[i].rreg), i);
-               DECL_STATE_ENTRY_BOOL_MEMBER((port[i].first), i);
-       }
-       DECL_STATE_ENTRY_UINT8(mode);
-#endif
-       DECL_STATE_ENTRY_INT32(chip_clock);
-       DECL_STATE_ENTRY_BOOL(irq_prev);
-       DECL_STATE_ENTRY_BOOL(mute);
-       DECL_STATE_ENTRY_UINT32(clock_prev);
-       DECL_STATE_ENTRY_UINT32(clock_accum);
-       DECL_STATE_ENTRY_UINT32(clock_const);
-       DECL_STATE_ENTRY_UINT32(clock_busy);
-       DECL_STATE_ENTRY_INT32(timer_event_id);
-       DECL_STATE_ENTRY_BOOL(busy);
-
-       leave_decl_state();
-
-       opn->DeclState((void *)p_logger);
-}
-
-void AY_3_891X::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);
-       }
-       
-       opn->SaveState((void *)state_fio);
-       //state_fio->FputUint8(ch);
-       //state_fio->FputUint8(fnum2);
+#define STATE_VERSION  3
+
+bool AY_3_891X::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!opn->ProcessState((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint8(ch);
+       state_fio->StateUint8(fnum2);
 #ifdef SUPPORT_AY_3_891X_PORT
-       //for(int i = 0; i < 2; i++) {
-       //      state_fio->FputUint8(port[i].wreg);
-       //      state_fio->FputUint8(port[i].rreg);
-       //      state_fio->FputBool(port[i].first);
-       //}
-       //state_fio->FputUint8(mode);
+       for(int i = 0; i < 2; i++) {
+               state_fio->StateUint8(port[i].wreg);
+               state_fio->StateUint8(port[i].rreg);
+               state_fio->StateBool(port[i].first);
+       }
+       state_fio->StateUint8(mode);
 #endif
-       //state_fio->FputInt32(chip_clock);
-       //state_fio->FputBool(irq_prev);
-       //state_fio->FputBool(mute);
-       //state_fio->FputUint32(clock_prev);
-       //state_fio->FputUint32(clock_accum);
-       //state_fio->FputUint32(clock_const);
-       //state_fio->FputUint32(clock_busy);
-       //state_fio->FputInt32(timer_event_id);
-       //state_fio->FputBool(busy);
+       state_fio->StateInt32(chip_clock);
+       state_fio->StateBool(irq_prev);
+       state_fio->StateBool(mute);
+       state_fio->StateUint32(clock_prev);
+       state_fio->StateUint32(clock_accum);
+       state_fio->StateUint32(clock_const);
+       state_fio->StateUint32(clock_busy);
+       state_fio->StateInt32(timer_event_id);
+       state_fio->StateBool(busy);
+       return true;
 }
-
-bool AY_3_891X::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(!mb) return false;
-       if(!opn->LoadState((void *)state_fio)) {
-               return false;
-       }
-       //ch = state_fio->FgetUint8();
-       //fnum2 = state_fio->FgetUint8();
-#ifdef SUPPORT_AY_3_891X_PORT
-       //for(int i = 0; i < 2; i++) {
-       //      port[i].wreg = state_fio->FgetUint8();
-       //      port[i].rreg = state_fio->FgetUint8();
-       //      port[i].first = state_fio->FgetBool();
-       //}
-       //mode = state_fio->FgetUint8();
-#endif
-       //chip_clock = state_fio->FgetInt32();
-       //irq_prev = state_fio->FgetBool();
-       //mute = state_fio->FgetBool();
-       //clock_prev = state_fio->FgetUint32();
-       //clock_accum = state_fio->FgetUint32();
-       //clock_const = state_fio->FgetUint32();
-       //clock_busy = state_fio->FgetUint32();
-       //timer_event_id = state_fio->FgetInt32();
-       //busy = state_fio->FgetBool();
-       return true;
-}
-
index c977617..ef78c13 100644 (file)
@@ -105,9 +105,7 @@ public:
        void mix(int32_t* buffer, int cnt);
        void set_volume(int ch, int decibel_l, int decibel_r);
        void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_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 functions
 #ifdef SUPPORT_AY_3_891X_PORT_A
index 5d9d1f6..7bdfbd7 100644 (file)
@@ -65,52 +65,17 @@ void BEEP::set_frequency(double frequency)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void BEEP::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_BOOL(signal);
-       DECL_STATE_ENTRY_INT32(count);
-       DECL_STATE_ENTRY_BOOL(on);
-       DECL_STATE_ENTRY_BOOL(mute);
-
-       leave_decl_state();
-}
-
-void BEEP::save_state(FILEIO* state_fio)
+bool BEEP::process_state(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->FputBool(signal);
-//     state_fio->FputInt32(count);
-//     state_fio->FputBool(on);
-//     state_fio->FputBool(mute);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(signal);
+       state_fio->StateInt32(count);
+       state_fio->StateBool(on);
+       state_fio->StateBool(mute);
+       return true;
 }
-
-bool BEEP::load_state(FILEIO* state_fio)
-{
-       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;
-       //}
-       //signal = state_fio->FgetBool();
-       //count = state_fio->FgetInt32();
-       //on = state_fio->FgetBool();
-       //mute = state_fio->FgetBool();
-       //touch_sound();
-       return true;
-}
-
index e80a775..2a558cb 100644 (file)
@@ -46,9 +46,7 @@ public:
        void write_signal(int id, uint32_t data, uint32_t mask);
        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 function
        void initialize_sound(int rate, double frequency, int volume);
        void set_frequency(double frequency);
index e6ce399..df42a69 100644 (file)
@@ -1857,218 +1857,138 @@ void DATAREC::update_config()
 
 #define STATE_VERSION  12
 
-#include "../statesub.h"
-
-void DATAREC::decl_state()
+bool DATAREC::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_BOOL(play);
-       DECL_STATE_ENTRY_BOOL(rec);
-       DECL_STATE_ENTRY_BOOL(remote);
-       DECL_STATE_ENTRY_BOOL(trigger);
-       DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path) / sizeof(_TCHAR));
-       DECL_STATE_ENTRY_CMT_RECORDING(rec_fio, rec, rec_file_path);
-       
-       DECL_STATE_ENTRY_INT32(ff_rew);
-       DECL_STATE_ENTRY_BOOL(in_signal);
-       DECL_STATE_ENTRY_BOOL(out_signal);
-       DECL_STATE_ENTRY_UINT32(prev_clock);
-       DECL_STATE_ENTRY_INT32(positive_clocks);
-       DECL_STATE_ENTRY_INT32(negative_clocks);
-       DECL_STATE_ENTRY_INT32(signal_changed);
-       DECL_STATE_ENTRY_INT32(register_id);
-       DECL_STATE_ENTRY_BOOL(realtime);
-       DECL_STATE_ENTRY_INT32(sample_rate);
-       DECL_STATE_ENTRY_DOUBLE(sample_usec);
-       DECL_STATE_ENTRY_INT32(buffer_ptr);
-
-       DECL_STATE_ENTRY_INT32(buffer_length);
-       DECL_STATE_ENTRY_INT32(_tmp_buffer_length);
-       DECL_STATE_ENTRY_VARARRAY_VAR(buffer, _tmp_buffer_length);
-       
-       DECL_STATE_ENTRY_INT32(_tmp_buffer_bak_length);
-       DECL_STATE_ENTRY_VARARRAY_VAR(buffer_bak, _tmp_buffer_bak_length);
-       
+       int length_tmp;
+
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       // pre process
+       if(loading) {
+               close_file();
+       }
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(remote);
+       state_fio->StateBool(trigger);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               length_tmp = state_fio->FgetInt32_LE();
+               if(rec) {
+                       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(rec_fio->IsOpened()) {
+                                       rec_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(rec && rec_fio->IsOpened()) {
+                       length_tmp = (int)rec_fio->Ftell();
+                       rec_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));
+                               rec_fio->Fread(buffer_tmp, length_rw, 1);
+                               state_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               length_tmp -= length_rw;
+                       }
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+       }
+       state_fio->StateInt32(ff_rew);
+       state_fio->StateBool(in_signal);
+       state_fio->StateBool(out_signal);
+       state_fio->StateUint32(prev_clock);
+       state_fio->StateInt32(positive_clocks);
+       state_fio->StateInt32(negative_clocks);
+       state_fio->StateInt32(signal_changed);
+       state_fio->StateInt32(register_id);
+       state_fio->StateBool(realtime);
+       state_fio->StateInt32(sample_rate);
+       state_fio->StateDouble(sample_usec);
+       state_fio->StateInt32(buffer_ptr);
+       if(loading) {
+               if((buffer_length = state_fio->FgetInt32_LE()) != 0) {
+                       buffer = (uint8_t *)malloc(buffer_length);
+                       state_fio->Fread(buffer, buffer_length, 1);
+               }
+               if((length_tmp = state_fio->FgetInt32_LE()) != 0) {
+                       buffer_bak = (uint8_t *)malloc(length_tmp);
+                       state_fio->Fread(buffer_bak, length_tmp, 1);
+               }
+               if(__DATAREC_SOUND) {
+                       if((sound_buffer_length = state_fio->FgetInt32_LE()) != 0) {
+                               sound_buffer = (int16_t *)malloc(sound_buffer_length);
+                               state_fio->Fread(sound_buffer, sound_buffer_length, 1);
+                       }
+               }
+       } else {
+               if(buffer) {
+                       state_fio->FputInt32_LE(buffer_length);
+                       state_fio->Fwrite(buffer, buffer_length, 1);
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+               if(buffer_bak) {
+                       state_fio->FputInt32_LE(buffer_length);
+                       state_fio->Fwrite(buffer_bak, buffer_length, 1);
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
+               if(__DATAREC_SOUND) {
+                       if(sound_buffer) {
+                               state_fio->FputInt32_LE(sound_buffer_length);
+                               state_fio->Fwrite(sound_buffer, sound_buffer_length, 1);
+                       } else {
+                               state_fio->FputInt32_LE(0);
+                       }
+               }
+       }
        if(__DATAREC_SOUND) {
-               DECL_STATE_ENTRY_INT32(sound_buffer_length);
-               DECL_STATE_ENTRY_VARARRAY_BYTES(sound_buffer, sound_buffer_length);
-               DECL_STATE_ENTRY_INT16(sound_sample);
+               state_fio->StateInt16(sound_sample);
+       }
+       state_fio->StateBool(is_wav);
+       state_fio->StateBool(is_tap);
+       state_fio->StateBool(is_t77);
+       if(loading) {
+               if((apss_buffer_length = state_fio->FgetInt32_LE()) != 0) {
+                       apss_buffer = (bool *)malloc(apss_buffer_length);
+                       state_fio->Fread(apss_buffer, apss_buffer_length, 1);
+               }
+       } else {
+               if(apss_buffer) {
+                       state_fio->FputInt32_LE(apss_buffer_length);
+                       state_fio->Fwrite(apss_buffer, apss_buffer_length, 1);
+               } else {
+                       state_fio->FputInt32_LE(0);
+               }
        }
-
-       DECL_STATE_ENTRY_BOOL(is_wav);
-       DECL_STATE_ENTRY_BOOL(is_tap);
-       DECL_STATE_ENTRY_BOOL(is_t77);
-
-       DECL_STATE_ENTRY_INT32(apss_buffer_length);
-       DECL_STATE_ENTRY_VARARRAY_BYTES(apss_buffer, apss_buffer_length);
-       //DECL_STATE_ENTRY_INT32(_tmp_apss_buffer_length);
-       //DECL_STATE_ENTRY_VARARRAY_VAR(apss_buffer, _tmp_apss_buffer_length);
-
-       
-       DECL_STATE_ENTRY_INT32(apss_ptr);
-       DECL_STATE_ENTRY_INT32(apss_count);
-       DECL_STATE_ENTRY_INT32(apss_remain);
-       DECL_STATE_ENTRY_BOOL(apss_signals);
-       DECL_STATE_ENTRY_INT32(pcm_changed);
-       DECL_STATE_ENTRY_UINT32(pcm_prev_clock);
-       DECL_STATE_ENTRY_INT32(pcm_positive_clocks);
-       DECL_STATE_ENTRY_INT32(pcm_negative_clocks);
-
-       leave_decl_state();
-}
-void DATAREC::save_state(FILEIO* state_fio)
-{
-       uint32_t crc_value = 0xffffffff;
-
-       _tmp_buffer_length = buffer_length;
-       _tmp_buffer_bak_length = buffer_length;
-       //_tmp_sound_buffer_length = sound_buffer_length / sizeof(int16_t);
-       //_tmp_apss_buffer_length = apss_buffer_length / sizeof(bool);
-//     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->FputBool(trigger);
-//     state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio, &crc_value);
-       }
-       //state_fio->FputInt32(ff_rew);
-       //state_fio->FputBool(in_signal);
-       //state_fio->FputBool(out_signal);
-       //state_fio->FputUint32(prev_clock);
-       //state_fio->FputInt32(positive_clocks);
-       //state_fio->FputInt32(negative_clocks);
-       //state_fio->FputInt32(signal_changed);
-       //state_fio->FputInt32(register_id);
-       //state_fio->FputBool(realtime);
-       //state_fio->FputInt32(sample_rate);
-       //state_fio->FputDouble(sample_usec);
-       //state_fio->FputInt32(buffer_ptr);
-       //if(buffer) {
-       //      state_fio->FputInt32(buffer_length);
-       //      state_fio->Fwrite(buffer, buffer_length, 1);
-       //} else {
-       //      state_fio->FputInt32(0);
-       //}
-       //if(buffer_bak) {
-       //      state_fio->FputInt32(buffer_length);
-       //      state_fio->Fwrite(buffer_bak, buffer_length, 1);
-       //} else {
-       //      state_fio->FputInt32(0);
-       //}
-//#ifdef DATAREC_SOUND
-       //if(__DATAREC_SOUND) {
-       //      if(sound_buffer) {
-       //              state_fio->FputInt32(sound_buffer_length);
-       //              state_fio->Fwrite(sound_buffer, sound_buffer_length, 1);
-       //      } else {
-       //              state_fio->FputInt32(0);
-       //      }
-       //      state_fio->FputInt16(sound_sample);
-       //}
-//#endif
-       //state_fio->FputBool(is_wav);
-       //state_fio->FputBool(is_tap);
-       //state_fio->FputBool(is_t77);
-       //if(apss_buffer) {
-       //      state_fio->FputInt32(apss_buffer_length);
-       //      state_fio->Fwrite(apss_buffer, apss_buffer_length, 1);
-       //} else {
-       //      state_fio->FputInt32(0);
-       //}
-       //state_fio->FputInt32(apss_ptr);
-       //state_fio->FputInt32(apss_count);
-       //state_fio->FputInt32(apss_remain);
-       //state_fio->FputBool(apss_signals);
-       //state_fio->FputInt32(pcm_changed);
-       //state_fio->FputUint32(pcm_prev_clock);
-       //state_fio->FputInt32(pcm_positive_clocks);
-       //state_fio->FputInt32(pcm_negative_clocks);
-}
-
-bool DATAREC::load_state(FILEIO* state_fio)
-{
-       close_file();
-       
-//     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();
-//     trigger = state_fio->FgetBool();
-//     state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
-       bool mb = false;
-       bool stat;
-       uint32_t crc_value = 0xffffffff;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio, &crc_value);
-       }
-       if(!mb) return false;
-//     if(__DATAREC_SOUND) {
-//             if(sound_buffer_length > 0) {
-//                     sound_buffer = (int16_t *)malloc(sound_buffer_length);
-//                     memset(sound_buffer, 0x00, sound_buffer_length);
-//             }
-//     }
-//     ff_rew = state_fio->FgetInt32();
-//     in_signal = state_fio->FgetBool();
-//     out_signal = state_fio->FgetBool();
-//     prev_clock = state_fio->FgetUint32();
-//     positive_clocks = state_fio->FgetInt32();
-//     negative_clocks = state_fio->FgetInt32();
-//     signal_changed = state_fio->FgetInt32();
-//     register_id = state_fio->FgetInt32();
-//     realtime = state_fio->FgetBool();
-//     sample_rate = state_fio->FgetInt32();
-//     sample_usec = state_fio->FgetDouble();
-//     buffer_ptr = state_fio->FgetInt32();
-       //if((buffer_length = state_fio->FgetInt32()) != 0) {
-       //      buffer = (uint8_t *)malloc(buffer_length);
-       //      state_fio->Fread(buffer, buffer_length, 1);
-       //}
-       //if((length_tmp = state_fio->FgetInt32()) != 0) {
-       //      buffer_bak = (uint8_t *)malloc(length_tmp);
-       //      state_fio->Fread(buffer_bak, length_tmp, 1);
-       //}
-//#ifdef DATAREC_SOUND
-//     if(__DATAREC_SOUND) {
-//             if((sound_buffer_length = state_fio->FgetInt32()) != 0) {
-//                     sound_buffer = (int16_t *)malloc(sound_buffer_length);
-//                     state_fio->Fread(sound_buffer, sound_buffer_length, 1);
-//             }
-//             sound_sample = state_fio->FgetInt16();
-//     }
-//#endif
-//     is_wav = state_fio->FgetBool();
-//     is_tap = state_fio->FgetBool();
-//     is_t77 = state_fio->FgetBool();
-//     if((apss_buffer_length = state_fio->FgetInt32()) != 0) {
-//             apss_buffer = (bool *)malloc(apss_buffer_length);
-//             state_fio->Fread(apss_buffer, apss_buffer_length, 1);
-//     }
-//     apss_ptr = state_fio->FgetInt32();
-//     apss_count = state_fio->FgetInt32();
-//     apss_remain = state_fio->FgetInt32();
-//     apss_signals = state_fio->FgetBool();
-//     pcm_changed = state_fio->FgetInt32();
-//     pcm_prev_clock = state_fio->FgetUint32();
-//     pcm_positive_clocks = state_fio->FgetInt32();
-//     pcm_negative_clocks = state_fio->FgetInt32();
-       
-       // post process
-       pcm_last_vol_l = pcm_last_vol_r = 0;
-//#ifdef DATAREC_SOUND
-       sound_last_vol_l = sound_last_vol_r = 0;
-//#endif
-       return true;
+       state_fio->StateInt32(apss_ptr);
+       state_fio->StateInt32(apss_count);
+       state_fio->StateInt32(apss_remain);
+       state_fio->StateBool(apss_signals);
+       state_fio->StateInt32(pcm_changed);
+       state_fio->StateUint32(pcm_prev_clock);
+       state_fio->StateInt32(pcm_positive_clocks);
+       state_fio->StateInt32(pcm_negative_clocks);
+       
+       // post process
+       if(loading) {
+               pcm_last_vol_l = pcm_last_vol_r = 0;
+               if(__DATAREC_SOUND) {
+                       sound_last_vol_l = sound_last_vol_r = 0;
+               }
+       }
+       return true;
 }
-
index ea1f139..751adfa 100644 (file)
@@ -148,9 +148,7 @@ public:
        void mix(int32_t* buffer, int cnt);
        void set_volume(int ch, int decibel_l, int decibel_r);
        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);
        
        // unique functions
        void initialize_sound(int rate, int volume)
index 61a3511..dd8d755 100644 (file)
@@ -142,6 +142,15 @@ public:
        {
                reset();
        }
+       virtual bool process_state(FILEIO* state_fio, bool loading)
+       {
+               if(loading) {
+                       return load_state(state_fio);
+               } else {
+                       save_state(state_fio);
+                       return true;
+               }
+       }
        
        // NOTE: the virtual bus interface functions for 16/32bit access invite the cpu is little endian.
        // if the cpu is big endian, you need to implement them in the virtual machine memory/io classes.
index 44c9670..8289a70 100644 (file)
@@ -116,9 +116,7 @@ public:
        bool open(_TCHAR* file_path, int bank);
        void close();
        void event_callback(int event_id, int err);
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
-       void decl_state(void);
+       bool process_state(FILEIO *state_fio, bool loading);
        
        bool is_bubble_inserted()
        {
index 803a9f1..a692063 100644 (file)
@@ -3508,186 +3508,158 @@ void DISPLAY::release()
 }
 
 #define STATE_VERSION 12
-void DISPLAY::decl_state(void)
-{
-       enter_decl_state(STATE_VERSION);
-       DECL_STATE_ENTRY_INT(this_device_id);
-       {
-               int i;
-               DECL_STATE_ENTRY_BOOL(delay_busy);
-               DECL_STATE_ENTRY_BOOL(halt_flag);
-               DECL_STATE_ENTRY_INT32(active_page);
-               DECL_STATE_ENTRY_BOOL(sub_busy);
-               DECL_STATE_ENTRY_BOOL(crt_flag);
-               DECL_STATE_ENTRY_BOOL(vram_wrote);
-               DECL_STATE_ENTRY_BOOL(is_cyclesteal);
-               
-               DECL_STATE_ENTRY_BOOL(clock_fast);
-               
+
+bool DISPLAY::process_state(FILEIO *state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       {
+               int i;
+               state_fio->StateBool(delay_busy);
+               state_fio->StateBool(halt_flag);
+               state_fio->StateInt32(active_page);
+               state_fio->StateBool(sub_busy);
+               state_fio->StateBool(crt_flag);
+               state_fio->StateBool(vram_wrote);
+               state_fio->StateBool(is_cyclesteal);
+               
+               state_fio->StateBool(clock_fast);
+               
 #if defined(_FM77AV_VARIANTS)
-               DECL_STATE_ENTRY_BOOL(subcpu_resetreq);
-               DECL_STATE_ENTRY_BOOL(power_on_reset);
+               state_fio->StateBool(subcpu_resetreq);
+               state_fio->StateBool(power_on_reset);
 #endif 
-               DECL_STATE_ENTRY_BOOL(cancel_request);
-               DECL_STATE_ENTRY_BOOL(key_firq_req);
-
-               DECL_STATE_ENTRY_INT32(display_mode);
-               DECL_STATE_ENTRY_UINT32(prev_clock);
-
+               state_fio->StateBool(cancel_request);
+               state_fio->StateBool(key_firq_req);
+               state_fio->StateInt32(display_mode);
+               state_fio->StateUint32(prev_clock);
 #if !defined(_FM8)     
-               DECL_STATE_ENTRY_MULTI(void, dpalette_data, sizeof(dpalette_data));
-               DECL_STATE_ENTRY_UINT8(multimode_accessmask);
-               DECL_STATE_ENTRY_UINT8(multimode_dispmask);
+               state_fio->StateBuffer(dpalette_data, sizeof(dpalette_data), 1);
+               state_fio->StateUint8(multimode_accessmask);
+               state_fio->StateUint8(multimode_dispmask);
 #endif         
-               DECL_STATE_ENTRY_UINT32(offset_point);
+               state_fio->StateUint32(offset_point);
 #if defined(_FM77AV_VARIANTS)
-               DECL_STATE_ENTRY_UINT32(offset_point_bank1);
+               state_fio->StateUint32(offset_point_bank1);
 #endif         
                //for(i = 0; i < 2; i++) {
-               DECL_STATE_ENTRY_PAIR_ARRAY(tmp_offset_point, 2);
-               DECL_STATE_ENTRY_BOOL_ARRAY(offset_changed, 2);
-                       //}
-               DECL_STATE_ENTRY_BOOL(offset_77av);
-               DECL_STATE_ENTRY_BOOL(diag_load_subrom_c);
-               
-       
-               DECL_STATE_ENTRY_MULTI(void, io_w_latch, sizeof(io_w_latch));
-               DECL_STATE_ENTRY_MULTI(void, console_ram, sizeof(console_ram));
-               DECL_STATE_ENTRY_MULTI(void, work_ram, sizeof(work_ram));
-               DECL_STATE_ENTRY_MULTI(void, shared_ram, sizeof(shared_ram));
-               DECL_STATE_ENTRY_MULTI(void, subsys_c, sizeof(subsys_c));
-               DECL_STATE_ENTRY_MULTI(void, gvram, sizeof(gvram));
-               DECL_STATE_ENTRY_MULTI(void, gvram_shadow, sizeof(gvram_shadow));
-       
+               state_fio->StateBuffer(tmp_offset_point, sizeof(tmp_offset_point), 1);
+               state_fio->StateBuffer(offset_changed, sizeof(offset_changed), 1);
+               //}
+               state_fio->StateBool(offset_77av);
+               state_fio->StateBool(diag_load_subrom_c);
+               state_fio->StateBuffer(io_w_latch, sizeof(io_w_latch), 1);
+               state_fio->StateBuffer(console_ram, sizeof(console_ram), 1);
+               state_fio->StateBuffer(work_ram, sizeof(work_ram), 1);
+               state_fio->StateBuffer(shared_ram, sizeof(shared_ram), 1);
+               state_fio->StateBuffer(subsys_c, sizeof(subsys_c), 1);
+               state_fio->StateBuffer(gvram, sizeof(gvram), 1);
+               state_fio->StateBuffer(gvram_shadow, sizeof(gvram_shadow), 1);
 #if defined(_FM77_VARIANTS)
-               DECL_STATE_ENTRY_BOOL(kanjisub);
-               DECL_STATE_ENTRY_PAIR(kanjiaddr);
+               state_fio->StateBool(kanjisub);
+               state_fio->StateUint32(kanjiaddr.d);
 # if defined(_FM77L4)
-               DECL_STATE_ENTRY_BOOL(mode400line);
-               DECL_STATE_ENTRY_BOOL(stat_400linecard);
+               state_fio->StateBool(mode400line);
+               state_fio->StateBool(stat_400linecard);
 # endif
 #elif defined(_FM77AV_VARIANTS)
-               DECL_STATE_ENTRY_BOOL(kanjisub);
-               DECL_STATE_ENTRY_PAIR(kanjiaddr);
-
-               DECL_STATE_ENTRY_BOOL(mode320);
-               DECL_STATE_ENTRY_INT32(cgrom_bank);
+               state_fio->StateBool(kanjisub);
+               state_fio->StateUint32(kanjiaddr.d);
+               state_fio->StateBool(mode320);
+               state_fio->StateInt32(cgrom_bank);
 #if defined(_FM77AV40) || defined(_FM77AV40SX)|| defined(_FM77AV40SX) || \
-    defined(_FM77AV20) || defined(_FM77AV20EX) || defined(_FM77AV20SX)
-               DECL_STATE_ENTRY_INT32(vram_bank);
+       defined(_FM77AV20) || defined(_FM77AV20EX) || defined(_FM77AV20SX)
+               state_fio->StateInt32(vram_bank);
 #endif 
+               state_fio->StateUint32(displine);
+               state_fio->StateUint8(subrom_bank);
+               state_fio->StateUint8(subrom_bank_using);
+               state_fio->StateBool(nmi_enable);
+               state_fio->StateBool(use_alu);
+               state_fio->StateUint32(apalette_index.d);
+               state_fio->StateBuffer(analog_palette_r, sizeof(analog_palette_r), 1);
+               state_fio->StateBuffer(analog_palette_g, sizeof(analog_palette_g), 1);
+               state_fio->StateBuffer(analog_palette_b, sizeof(analog_palette_b), 1);
+               state_fio->StateBool(diag_load_subrom_a);
+               state_fio->StateBool(diag_load_subrom_b);
+               state_fio->StateBool(diag_load_subrom_cg);
        
-               DECL_STATE_ENTRY_UINT32(displine);
-               DECL_STATE_ENTRY_UINT8(subrom_bank);
-               DECL_STATE_ENTRY_UINT8(subrom_bank_using);
-       
-               DECL_STATE_ENTRY_BOOL(nmi_enable);
-               DECL_STATE_ENTRY_BOOL(use_alu);
-               
-               DECL_STATE_ENTRY_PAIR(apalette_index);
-               DECL_STATE_ENTRY_MULTI(void, analog_palette_r, sizeof(analog_palette_r));
-               DECL_STATE_ENTRY_MULTI(void, analog_palette_g, sizeof(analog_palette_g));
-               DECL_STATE_ENTRY_MULTI(void, analog_palette_b, sizeof(analog_palette_b));
-               
-
-               DECL_STATE_ENTRY_BOOL(diag_load_subrom_a);
-               DECL_STATE_ENTRY_BOOL(diag_load_subrom_b);
-               DECL_STATE_ENTRY_BOOL(diag_load_subrom_cg);
-       
-               DECL_STATE_ENTRY_MULTI(void, subsys_a, sizeof(subsys_a));
-               DECL_STATE_ENTRY_MULTI(void, subsys_b, sizeof(subsys_b));
-               DECL_STATE_ENTRY_MULTI(void, subsys_cg, sizeof(subsys_cg));
-               DECL_STATE_ENTRY_MULTI(void, submem_hidden, sizeof(submem_hidden));
+               state_fio->StateBuffer(subsys_a, sizeof(subsys_a), 1);
+               state_fio->StateBuffer(subsys_b, sizeof(subsys_b), 1);
+               state_fio->StateBuffer(subsys_cg, sizeof(subsys_cg), 1);
+               state_fio->StateBuffer(submem_hidden, sizeof(submem_hidden), 1);
 # if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
-               DECL_STATE_ENTRY_BOOL(mode400line);
-               DECL_STATE_ENTRY_BOOL(mode256k);
-               
-               DECL_STATE_ENTRY_BOOL(monitor_ram);
+               state_fio->StateBool(mode400line);
+               state_fio->StateBool(mode256k);
+               state_fio->StateBool(monitor_ram);
 #  if defined(_FM77AV40EX) || defined(_FM77AV40SX)
-               DECL_STATE_ENTRY_UINT16(window_low);
-               DECL_STATE_ENTRY_UINT16(window_high);
-               DECL_STATE_ENTRY_UINT16(window_xbegin);
-               DECL_STATE_ENTRY_UINT16(window_xend);
-               DECL_STATE_ENTRY_BOOL(window_opened);
+               state_fio->StateUint16(window_low);
+               state_fio->StateUint16(window_high);
+               state_fio->StateUint16(window_xbegin);
+               state_fio->StateUint16(window_xend);
+               state_fio->StateBool(window_opened);
 #  endif       
-               DECL_STATE_ENTRY_BOOL(kanji_level2);
-
-               DECL_STATE_ENTRY_UINT8(vram_active_block);
-               DECL_STATE_ENTRY_UINT8(vram_display_block);
-               DECL_STATE_ENTRY_UINT8(console_ram_bank);
-               DECL_STATE_ENTRY_BOOL(ram_protect);
-               
-               DECL_STATE_ENTRY_UINT8(cgram_bank);
-               DECL_STATE_ENTRY_MULTI(void, subsys_ram, sizeof(subsys_ram));
-               DECL_STATE_ENTRY_MULTI(void, submem_cgram, sizeof(submem_cgram));
-               DECL_STATE_ENTRY_MULTI(void, submem_console_av40, sizeof(submem_console_av40));
+               state_fio->StateBool(kanji_level2);
+               state_fio->StateUint8(vram_active_block);
+               state_fio->StateUint8(vram_display_block);
+               state_fio->StateUint8(console_ram_bank);
+               state_fio->StateBool(ram_protect);
+               state_fio->StateUint8(cgram_bank);
+               state_fio->StateBuffer(subsys_ram, sizeof(subsys_ram), 1);
+               state_fio->StateBuffer(submem_cgram, sizeof(submem_cgram), 1);
+               state_fio->StateBuffer(submem_console_av40, sizeof(submem_console_av40), 1);
 # endif
 #endif
-       }
-       // V2
-       {
-               DECL_STATE_ENTRY_INT32(nmi_event_id);
+       }
+       // V2
+       {
+               state_fio->StateInt32(nmi_event_id);
 //#if defined(_FM77AV_VARIANTS)
-               DECL_STATE_ENTRY_INT32(hblank_event_id);
-               DECL_STATE_ENTRY_INT32(hdisp_event_id);
-               DECL_STATE_ENTRY_INT32(vsync_event_id);
-               DECL_STATE_ENTRY_INT32(vstart_event_id);
+               state_fio->StateInt32(hblank_event_id);
+               state_fio->StateInt32(hdisp_event_id);
+               state_fio->StateInt32(vsync_event_id);
+               state_fio->StateInt32(vstart_event_id);
 //#endif
-               DECL_STATE_ENTRY_BOOL(firq_mask);
-               DECL_STATE_ENTRY_BOOL(vram_accessflag);
-               
-               DECL_STATE_ENTRY_INT8(display_page);
-               DECL_STATE_ENTRY_INT8(display_page_bak);
-               
-               DECL_STATE_ENTRY_BOOL(vblank);
-               DECL_STATE_ENTRY_BOOL(vsync);
-               DECL_STATE_ENTRY_BOOL(hblank);
-               DECL_STATE_ENTRY_INT32(vblank_count);
-       }                       
+               state_fio->StateBool(firq_mask);
+               state_fio->StateBool(vram_accessflag);
+               state_fio->StateInt8(display_page);
+               state_fio->StateInt8(display_page_bak);
+               state_fio->StateBool(vblank);
+               state_fio->StateBool(vsync);
+               state_fio->StateBool(hblank);
+               state_fio->StateInt32(vblank_count);
+       }                       
 #if defined(_FM77L4)
-       DECL_STATE_ENTRY_MULTI(void, subsys_cg_l4, sizeof(subsys_cg_l4));
-       DECL_STATE_ENTRY_MULTI(void, subsys_l4, sizeof(subsys_l4));
-       DECL_STATE_ENTRY_MULTI(void, text_vram, sizeof(text_vram));
-       //state_fio->Fwrite(crtc_regs, sizeof(crtc_regs), 1);
+       state_fio->StateBuffer(subsys_cg_l4, sizeof(subsys_cg_l4), 1);
+       state_fio->StateBuffer(subsys_l4, sizeof(subsys_l4), 1);
+       state_fio->StateBuffer(text_vram, sizeof(text_vram), 1);
+       //state_fio->Fwrite(crtc_regs, sizeof(crtc_regs), 1);
+       state_fio->StateBool(workram_l4);
+       state_fio->StateBool(cursor_lsb);
+       state_fio->StateBool(text_width40);
        
-       DECL_STATE_ENTRY_BOOL(workram_l4);
-       DECL_STATE_ENTRY_BOOL(cursor_lsb);
-    DECL_STATE_ENTRY_BOOL(text_width40);
+       state_fio->StateBool(text_blink);
+       state_fio->StateBool(cursor_blink);
        
-       DECL_STATE_ENTRY_BOOL(text_blink);
-       DECL_STATE_ENTRY_BOOL(cursor_blink);
+       state_fio->StateUint32(text_start_addr.d);
+       state_fio->StateUint32(text_lines);
+       state_fio->StateUint32(text_xmax);
        
-       DECL_STATE_ENTRY_PAIR(text_start_addr);
-       DECL_STATE_ENTRY_UINT32(text_lines);
-       DECL_STATE_ENTRY_UINT32(text_xmax);
-       
-       DECL_STATE_ENTRY_PAIR(cursor_addr);
-       DECL_STATE_ENTRY_INT32(cursor_start);
-       DECL_STATE_ENTRY_INT32(cursor_end);
-       DECL_STATE_ENTRY_UINT8(cursor_type);
-       DECL_STATE_ENTRY_UINT8(text_scroll_count);
-
-       DECL_STATE_ENTRY_INT32(event_id_l4_cursor_blink);
-       DECL_STATE_ENTRY_INT32(event_id_l4_text_blink);
+       state_fio->StateUint32(cursor_addr.d);
+       state_fio->StateInt32(cursor_start);
+       state_fio->StateInt32(cursor_end);
+       state_fio->StateUint8(cursor_type);
+       state_fio->StateUint8(text_scroll_count);
+       state_fio->StateInt32(event_id_l4_cursor_blink);
+       state_fio->StateInt32(event_id_l4_text_blink);
 #endif
-       leave_decl_state();
-}      
-
-void DISPLAY::save_state(FILEIO *state_fio)
-{
-       if(state_entry != NULL) state_entry->save_state(state_fio);
-}
 
-bool DISPLAY::load_state(FILEIO *state_fio)
-{
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       this->out_debug_log(_T("Load State: DISPLAY : id=%d stat=%s"), this_device_id, (mb) ? _T("OK") : _T("NG"));
-       if(!mb) return false;
-       
-       {
+       if(loading) {   
                int addr;
                int i;
                crt_flag_bak = true;
@@ -3700,7 +3672,7 @@ bool DISPLAY::load_state(FILEIO *state_fio)
                memcpy(dpalette_pixel_green, dpalette_green_tmp, sizeof(dpalette_pixel_green));
   #endif
 #else
-
+       
                for(addr = 0; addr < 8; addr++) set_dpalette(addr, dpalette_data[addr]);
                memcpy(dpalette_pixel, dpalette_pixel_tmp, sizeof(dpalette_pixel));
 #if defined(USE_GREEN_DISPLAY)
@@ -3726,27 +3698,28 @@ bool DISPLAY::load_state(FILEIO *state_fio)
                palette_changed = true;
                vram_wrote_shadow = true; // Force Draw
                this->draw_screen();
-       }
+               
                frame_skip_count_draw = 3;
                frame_skip_count_transfer = 3;
                need_transfer_line = true;
 #if defined(USE_GREEN_DISPLAY) && defined(USE_MONITOR_TYPE)
-       memcpy(dpalette_pixel_green, dpalette_green_tmp, sizeof(dpalette_pixel_green));
-       switch(config.monitor_type) {
-       case FM7_MONITOR_GREEN:
-               use_green_monitor = true;
-               break;
-       case FM7_MONITOR_STANDARD:
-       default:
-               use_green_monitor = false;
-               break;
-       }
+               memcpy(dpalette_pixel_green, dpalette_green_tmp, sizeof(dpalette_pixel_green));
+               switch(config.monitor_type) {
+               case FM7_MONITOR_GREEN:
+                       use_green_monitor = true;
+                       break;
+               case FM7_MONITOR_STANDARD:
+               default:
+                       use_green_monitor = false;
+                       break;
+               }
 #else
-       //use_green_monitor = false;
+               //use_green_monitor = false;
 #endif
-       force_update = true;
-       setup_display_mode();
-       return mb;
-}
+               force_update = true;
+               setup_display_mode();
+       }
+       return true;
+}      
 
        
index 41ed78a..fbb3a58 100644 (file)
@@ -60,32 +60,22 @@ void DUMMYDEVICE::reset()
        }
 }
 
-#define STATE_VERSION 1
-void DUMMYDEVICE::save_state(FILEIO *state_fio)
-{
-       state_fio->FputUint32_BE(STATE_VERSION);
-       state_fio->FputInt32_BE(this_device_id);
-       this->out_debug_log(_T("Save State: id=%d ver=%d\n"), this_device_id, STATE_VERSION);
-       // Version 1
-       {
-               state_fio->FputUint32_BE(status);
-               state_fio->FputBool(clear_on_reset);
-               state_fio->FputBool(clear_with_zero);
-       }
-}
+#define STATE_VERSION 2
 
-bool DUMMYDEVICE::load_state(FILEIO *state_fio)
+bool DUMMYDEVICE::process_state(FILEIO* state_fio, bool loading)
 {
-       uint32_t version;
-       version = state_fio->FgetUint32_BE();
-       this->out_debug_log(_T("Load State: id=%d ver=%d\n"), this_device_id, version);
-       if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
        // Version 1
        {
-               status = state_fio->FgetUint32_BE();
-               clear_on_reset = state_fio->FgetBool();
-               clear_with_zero = state_fio->FgetBool();
+               state_fio->StateUint32(status);
+               state_fio->StateBool(clear_on_reset);
+               state_fio->StateBool(clear_with_zero);
        }
-       if(version != STATE_VERSION) return false;
        return true;
 }
+
index 4682b66..28167ab 100644 (file)
@@ -70,8 +70,7 @@ public:
        void write_signal(int id, uint32_t data, uint32_t mask);
 
        void reset();
-       void save_state(FILEIO *state_fio);
-       bool load_state(FILEIO *state_fio);
+       bool process_state(FILEIO *state_fio, bool loading);
 };
 
 #endif //_VM_DUMMYDEVICE_H_
index 6a25ac9..621755f 100644 (file)
 #if defined(_FM8)
 #include "./bubblecasette.h"
 #endif
+
+#if defined(HAS_DMA)
+       dmac = new HD6844(this, emu);
+#endif   
 #if defined(_FM8)
 #include "./fm8_mainio.h"
 #else
@@ -233,6 +237,17 @@ VM::VM(EMU* parent_emu): VM_TEMPLATE(parent_emu)
        display = new DISPLAY(this, emu);
 
 
+       keyboard = new KEYBOARD(this, emu);
+       //display = new DISPLAY(this, emu);
+#if defined(_FM8)
+       mainio  = new FM8_MAINIO(this, emu);
+#else
+       mainio  = new FM7_MAINIO(this, emu);
+#endif
+       mainmem = new FM7_MAINMEM(this, emu);
+       display = new DISPLAY(this, emu);
+
+
 # if defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
        g_rs232c_dtr = new AND(this, emu);
        g_rs232c_dtr->set_mask(SIG_AND_BIT_0);
@@ -661,6 +676,10 @@ void VM::connect_bus(void)
 #if defined(__GIT_REPO_VERSION)
        strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
 #endif
+
+#if defined(__GIT_REPO_VERSION)
+       strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
+#endif
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->initialize();
        }
@@ -963,6 +982,7 @@ void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
                fdc->open_disk(drv, file_path, bank);
        }
 #endif
+       //display->reset(); // 20180618 K.O for RELICS
 }
 
 void VM::close_floppy_disk(int drv)
@@ -1226,76 +1246,50 @@ void VM::set_vm_frame_rate(double fps)
    if(event != NULL) event->set_frames_per_sec(fps);
 }
 
-#define STATE_VERSION  10
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
+#define STATE_VERSION  11
 
-void VM::decl_state(void)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-#if defined(_FM8)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM8_HEAD")), csp_logger);
-#elif defined(_FM7) || defined(_FMNEW7)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM7_HEAD")), csp_logger);
-#elif defined(_FM77) || defined(_FM77L2)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77_HEAD")), csp_logger);
-#elif defined(_FM77L4)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77L4_HEAD")), csp_logger);
-#elif defined(_FM77AV)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV_HEAD")), csp_logger);
-#elif defined(_FM77AV20)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV20_HEAD")), csp_logger);
-#elif defined(_FM77AV40)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV40_HEAD")), csp_logger);
-#elif defined(_FM77AV20EX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV20EX_HEAD")), csp_logger);
-#elif defined(_FM77AV40EX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV40EX_HEAD")), csp_logger);
-#elif defined(_FM77AV40SX)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM77AV40SX_HEAD")), csp_logger);
-#else
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FM7_SERIES_HEAD")), csp_logger);
-#endif
-       DECL_STATE_ENTRY_BOOL(connect_320kfdc);
-       DECL_STATE_ENTRY_BOOL(connect_1Mfdc);
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->decl_state();
-       }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               emu->out_debug_log("SAVE State: DEVID=%d", device->this_device_id);
-               device->save_state(state_fio);
-       }
-}
-
-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)) {
-                       printf("Load Error: DEVID=%d\n", device->this_device_id);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateBool(connect_320kfdc);
+       state_fio->StateBool(connect_1Mfdc);
+       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;
+               }
+       }
+       if(loading) {
+               update_config();
        }
-       update_config();
        //mainio->restore_opn();
-       
-       return true;
+       return true;
 }
 
+
+
 #ifdef USE_DIG_RESOLUTION
 void VM::get_screen_resolution(int *w, int *h)
 {
index 137963b..38e17c2 100644 (file)
@@ -437,9 +437,7 @@ public:
        void draw_screen();
        void event_frame();
        void event_vline(int v, int clock);
-       void save_state(FILEIO *state_fio);
-       bool load_state(FILEIO *state_fio);
-       void decl_state(void);
+       bool process_state(FILEIO *state_fio, bool loading);
        
        int get_screen_mode(void) {
                return display_mode;
index bbbf65f..b19a7c9 100644 (file)
@@ -681,147 +681,129 @@ void BUBBLECASETTE::event_callback(int event_id, int err)
 }
 
 
-#define STATE_VERSION 4
-#include "../../statesub.h"
+#define STATE_VERSION 5
 
-void BUBBLECASETTE::decl_state(void)
+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;
+       }
        
-       DECL_STATE_ENTRY_BOOL(is_wrote);
-       DECL_STATE_ENTRY_BOOL(is_b77);
-       DECL_STATE_ENTRY_BOOL(header_changed);
-       DECL_STATE_ENTRY_BOOL(read_access);
-       DECL_STATE_ENTRY_BOOL(write_access);
-
-       DECL_STATE_ENTRY_UINT8(offset_reg);
-       DECL_STATE_ENTRY_UINT8(data_reg);
-       DECL_STATE_ENTRY_UINT8(cmd_reg);
-
-       DECL_STATE_ENTRY_BOOL(cmd_error);  
-       DECL_STATE_ENTRY_BOOL(stat_tdra);  
-       DECL_STATE_ENTRY_BOOL(stat_rda);   
-       DECL_STATE_ENTRY_BOOL(not_ready);  
-       DECL_STATE_ENTRY_BOOL(write_protect); 
-       DECL_STATE_ENTRY_BOOL(stat_error); 
-       DECL_STATE_ENTRY_BOOL(stat_busy);  
-
-       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(is_wrote);
+       state_fio->StateBool(is_b77);
+       state_fio->StateBool(header_changed);
+       state_fio->StateBool(read_access);
+       state_fio->StateBool(write_access);
+
+       state_fio->StateUint8(offset_reg);
+       state_fio->StateUint8(data_reg);
+       state_fio->StateUint8(cmd_reg);
+
+       state_fio->StateBool(cmd_error);  
+       state_fio->StateBool(stat_tdra);  
+       state_fio->StateBool(stat_rda);   
+       state_fio->StateBool(not_ready);  
+       state_fio->StateBool(write_protect); 
+       state_fio->StateBool(stat_error); 
+       state_fio->StateBool(stat_busy);  
+
+       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); 
        
-       DECL_STATE_ENTRY_PAIR(page_address);
-       DECL_STATE_ENTRY_PAIR(page_count);
-       DECL_STATE_ENTRY_BOOL(bubble_inserted);
-       DECL_STATE_ENTRY_INT(bubble_type);
-       DECL_STATE_ENTRY_INT(media_num);
+       state_fio->StateUint32(page_address.d);
+       state_fio->StateUint32(page_count.d);
+       state_fio->StateBool(bubble_inserted);
+       state_fio->StateInt32(bubble_type);
+       state_fio->StateInt32(media_num);
        // Header
-       DECL_STATE_ENTRY_STRING(image_path, sizeof(image_path));
-       DECL_STATE_ENTRY_1D_ARRAY((bbl_header.filename), sizeof(bbl_header.filename));
-       DECL_STATE_ENTRY_PAIR((bbl_header.size));
-       DECL_STATE_ENTRY_PAIR((bbl_header.offset));
-       DECL_STATE_ENTRY_1D_ARRAY((bbl_header.misc), sizeof(bbl_header.misc));
-
-
-       DECL_STATE_ENTRY_UINT32(media_offset);
-       DECL_STATE_ENTRY_UINT32(media_offset_new);
-       DECL_STATE_ENTRY_UINT32(media_size);
-       DECL_STATE_ENTRY_UINT32(file_length);
-       DECL_STATE_ENTRY_1D_ARRAY(bubble_data, sizeof(bubble_data));
-
-       leave_decl_state();
-}
-void BUBBLECASETTE::save_state(FILEIO *state_fio)
-{
-       int i, j;
-       if(state_entry != NULL) state_entry->save_state(state_fio);
-       
+       state_fio->StateBuffer(image_path, sizeof(image_path), 1);
+       state_fio->StateBuffer((bbl_header.filename), sizeof(bbl_header.filename), 1);
+       state_fio->StateUint32((bbl_header.size.d));
+       state_fio->StateUint32((bbl_header.offset.d));
+       state_fio->StateBuffer((bbl_header.misc), sizeof(bbl_header.misc), 1);
+
+
+       state_fio->StateUint32(media_offset);
+       state_fio->StateUint32(media_offset_new);
+       state_fio->StateUint32(media_size);
+       state_fio->StateUint32(file_length);
+       state_fio->StateBuffer(bubble_data, sizeof(bubble_data), 1);
 #if 0
-       if(fio != NULL) {
-               if(fio->IsOpened()) {
-                       if(is_wrote) write_one_page();
-                       if(is_b77) {
-                               if(header_changed) {
-                                       write_header();
-                                       header_changed = false;
-                               }
+       if(loading) {
+               is_wrote = false;
+               header_changed = false;
+               if(_tcslen(image_path) > 0) {
+                       bool is_wrote_bak = is_wrote;
+                       bool header_changed_bak = header_changed;
+                       bool is_b77_bak = is_b77;
+                       uint32_t media_offset_bak = media_offset;
+                       uint32_t media_offset_new_bak = media_offset_new;
+                       uint32_t file_length_bak = file_length;
+                       bool bubble_inserted_bak = bubble_inserted;
+                       bool not_ready_bak = not_ready;
+                       bool cmd_error_bak = cmd_error;
+                       bool stat_tdra_bak = stat_tdra;
+                       bool stat_rda_bak = stat_rda;
+                       bool stat_error_bak = stat_error; // OK?
+                       bool stat_busy_bak = stat_busy;
+                       int bubble_type_bak = bubble_type;
+                       uint32_t media_size_bak = media_size;
+                       bool write_protect_bak = write_protect;
+                       bool not_ready_bak = not_ready;
+                       uint32_t media_num_bak = media_num;
+                       
+                       bbl_header_t bbl_header_bak;
+                       uint8_t bubble_data_bak[0x20000];
+                       _TCHAR image_path_bak[_MAX_PATH];
+                       memcpy(&bbl_header_bak, &bbl_header, sizeof(bbl_header_t));
+                       memcpy(bubble_data_bak, bubble_data, 0x20000);
+                       memcpy(image_path_bak, image_path, _MAXPATH * sizeof(_TCHAR));
+                       if(!open(image_path, (int)media_num)) {
+                               // Revert loaded status
+                               is_wrote = is_wrote_bak;
+                               header_changed = header_changed_bak;
+                               is_b77 = is_b77_bak;
+                               media_offset = media_offset_bak;
+                               media_offset_new = media_offset_new_bak;
+                               file_length = file_length_bak;
+                               bubble_inserted = bubble_inserted_bak;
+                               not_ready = not_ready_bak;
+                               cmd_error = cmd_error_bak;
+                               stat_tdra = stat_tdra_bak;
+                               stat_rda = stat_rda_bak;
+                               stat_error = stat_error_bak; // OK?
+                               stat_busy = stat_busy_bak;
+                               bubble_type = bubble_type_bak;
+                               media_size = media_size_bak;
+                               write_protect = write_protect_bak;
+                               not_ready = not_ready_bak;
+                               media_num = media_num_bak;
+                               memcpy(&bbl_header, &bbl_header_bak, sizeof(bbl_header_t));
+                               memcpy(bubble_data, bubble_data_bak, 0x20000);
+                               memcpy(image_path, image_path_bak, _MAXPATH * sizeof(_TCHAR));
+                               return true;
                        }
                }
-       }
-#endif
-}
-
-bool BUBBLECASETTE::load_state(FILEIO *state_fio)
-{
-       //int i, j;
-       //if(state_fio->FgetUint32_BE() != STATE_VERSION) return false;
-       //if(state_fio->FgetInt32_BE() != this_device_id) return false;
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       out_debug_log(_T("Load State: BUBBLE: id=%d status=%s"), this_device_id, (mb) ? _T("OK") : _T("NG"));
-       if(!mb) return false;
-       
-#if 0
-       is_wrote = false;
-       header_changed = false;
-
-
-       if(_tcslen(image_path) > 0) {
-               bool is_wrote_bak = is_wrote;
-               bool header_changed_bak = header_changed;
-               bool is_b77_bak = is_b77;
-               uint32_t media_offset_bak = media_offset;
-               uint32_t media_offset_new_bak = media_offset_new;
-               uint32_t file_length_bak = file_length;
-               bool bubble_inserted_bak = bubble_inserted;
-               bool not_ready_bak = not_ready;
-               bool cmd_error_bak = cmd_error;
-               bool stat_tdra_bak = stat_tdra;
-               bool stat_rda_bak = stat_rda;
-               bool stat_error_bak = stat_error; // OK?
-               bool stat_busy_bak = stat_busy;
-               int bubble_type_bak = bubble_type;
-               uint32_t media_size_bak = media_size;
-               bool write_protect_bak = write_protect;
-               bool not_ready_bak = not_ready;
-               uint32_t media_num_bak = media_num;
-               
-               bbl_header_t bbl_header_bak;
-               uint8_t bubble_data_bak[0x20000];
-               _TCHAR image_path_bak[_MAX_PATH];
-               memcpy(&bbl_header_bak, &bbl_header, sizeof(bbl_header_t));
-               memcpy(bubble_data_bak, bubble_data, 0x20000);
-               memcpy(image_path_bak, image_path, _MAXPATH * sizeof(_TCHAR));
-               if(!open(image_path, (int)media_num)) {
-                       // Revert loaded status
-                       is_wrote = is_wrote_bak;
-                       header_changed = header_changed_bak;
-                       is_b77 = is_b77_bak;
-                       media_offset = media_offset_bak;
-                       media_offset_new = media_offset_new_bak;
-                       file_length = file_length_bak;
-                       bubble_inserted = bubble_inserted_bak;
-                       not_ready = not_ready_bak;
-                       cmd_error = cmd_error_bak;
-                       stat_tdra = stat_tdra_bak;
-                       stat_rda = stat_rda_bak;
-                       stat_error = stat_error_bak; // OK?
-                       stat_busy = stat_busy_bak;
-                       bubble_type = bubble_type_bak;
-                       media_size = media_size_bak;
-                       write_protect = write_protect_bak;
-                       not_ready = not_ready_bak;
-                       media_num = media_num_bak;
-                       memcpy(&bbl_header, &bbl_header_bak, sizeof(bbl_header_t));
-                       memcpy(bubble_data, bubble_data_bak, 0x20000);
-                       memcpy(image_path, image_path_bak, _MAXPATH * sizeof(_TCHAR));
-                       return true;
+       } else {
+               if(state_fio != NULL) {
+                       if(state_fio->IsOpened()) {
+                               if(is_wrote) write_one_page();
+                               if(is_b77) {
+                                       if(header_changed) {
+                                               write_header();
+                                               header_changed = false;
+                                       }
+                               }
+                       }
                }
        }
 #endif
index a28f73b..15604b2 100644 (file)
@@ -28,9 +28,6 @@
 
 #include "../../fileio.h"
 
-
-#include "../../statesub.h"
-
 #define LOGNAME "fmgen"
 
 // ---------------------------------------------------------------------------
@@ -289,51 +286,20 @@ void Chip::MakeTable()
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define CHIP_STATE_VERSION     2
-
-void Chip::DeclState(void *f)
-{
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(CHIP_STATE_VERSION, chip_num, _T("FMGEN::Chip::"), p_logger);
-
-       DECL_STATE_ENTRY_UINT32(ratio_);
-       DECL_STATE_ENTRY_UINT32(aml_);
-       DECL_STATE_ENTRY_UINT32(pml_);
-       DECL_STATE_ENTRY_INT32(pmv_);
-}
+#define CHIP_STATE_VERSION     1
 
-void Chip::SaveState(void *f)
+bool Chip::ProcessState(void *f, bool loading)
 {
-       FILEIO *state_fio = (FILEIO *)f;
-
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32_BE(CHIP_STATE_VERSION);
-       
-//     state_fio->FputUint32_BE(ratio_);
-//     state_fio->FputUint32_BE(aml_);
-//     state_fio->FputUint32_BE(pml_);
-//     state_fio->FputInt32_BE(pmv_);
-}
-
-bool Chip::LoadState(void *f)
-{
-
-       FILEIO *state_fio = (FILEIO *)f;
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != CHIP_STATE_VERSION) {
-//             return false;
-//     }
-//     ratio_ = state_fio->FgetUint32_BE();
-//     aml_ = state_fio->FgetUint32_BE();
-//     pml_ = state_fio->FgetUint32_BE();
-//     pmv_ = state_fio->FgetInt32_BE();
-       return true;
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(CHIP_STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateUint32(ratio_);
+       state_fio->StateUint32(aml_);
+       state_fio->StateUint32(pml_);
+       state_fio->StateInt32(pmv_);
+       return true;
 }
 
 
@@ -768,166 +734,63 @@ inline FM::ISample FM::Operator::CalcFBL(uint fb)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define OPERATOR_STATE_VERSION 2
+#define OPERATOR_STATE_VERSION 1
 
-void Operator::DeclState(void *f)
+bool Operator::ProcessState(void *f, bool loading)
 {
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(OPERATOR_STATE_VERSION, operators_num, _T("FMGEN::Operator::"), p_logger);
-
-       DECL_STATE_ENTRY_INT32(out_);
-       DECL_STATE_ENTRY_INT32(out2_);
-       DECL_STATE_ENTRY_INT32(in2_);
-       DECL_STATE_ENTRY_UINT32(dp_);
-       DECL_STATE_ENTRY_UINT32(detune_);
-       DECL_STATE_ENTRY_UINT32(detune2_);
-       DECL_STATE_ENTRY_UINT32(multiple_);
-       DECL_STATE_ENTRY_UINT32(pg_count_);
-       DECL_STATE_ENTRY_UINT32(pg_diff_);
-       DECL_STATE_ENTRY_INT32(pg_diff_lfo_);
-       DECL_STATE_ENTRY_UINT32(bn_);
-       DECL_STATE_ENTRY_INT32(eg_level_);
-       DECL_STATE_ENTRY_INT32(eg_level_on_next_phase_);
-       DECL_STATE_ENTRY_INT32(eg_count_);
-       DECL_STATE_ENTRY_INT32(eg_count_diff_);
-       DECL_STATE_ENTRY_INT32(eg_out_);
-       DECL_STATE_ENTRY_INT32(tl_out_);
-       DECL_STATE_ENTRY_INT32(eg_rate_);
-       DECL_STATE_ENTRY_INT32(eg_curve_count_);
-       DECL_STATE_ENTRY_INT32(ssg_offset_);
-       DECL_STATE_ENTRY_INT32(ssg_vector_);
-       DECL_STATE_ENTRY_INT32(ssg_phase_);
-       DECL_STATE_ENTRY_UINT32(key_scale_rate_);
-       DECL_STATE_ENTRY_INT32(tmp_eg_phase);
-       DECL_STATE_ENTRY_INT32(tmp_ams);
-       DECL_STATE_ENTRY_UINT32(ms_);
-       DECL_STATE_ENTRY_UINT32(tl_);
-       DECL_STATE_ENTRY_UINT32(tl_latch_);
-       DECL_STATE_ENTRY_UINT32(ar_);
-       DECL_STATE_ENTRY_UINT32(dr_);
-       DECL_STATE_ENTRY_UINT32(sr_);
-       DECL_STATE_ENTRY_UINT32(sl_);
-       DECL_STATE_ENTRY_UINT32(rr_);
-       DECL_STATE_ENTRY_UINT32(ks_);
-       DECL_STATE_ENTRY_UINT32(ssg_type_);
-       DECL_STATE_ENTRY_BOOL(keyon_);
-       DECL_STATE_ENTRY_BOOL(amon_);
-       DECL_STATE_ENTRY_BOOL(param_changed_);
-       DECL_STATE_ENTRY_BOOL(mute_);
-       DECL_STATE_ENTRY_INT32(dbgopout_);
-       DECL_STATE_ENTRY_INT32(dbgpgout_);
-}
-
-void Operator::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-
-       tmp_eg_phase = static_cast<int>(eg_phase_);
-       tmp_ams = (int)(ams_ - &amtable[0][0][0]);
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(OPERATOR_STATE_VERSION)) {
+               return false;
        }
-//     state_fio->FputUint32_BE(OPERATOR_STATE_VERSION);
        
-//     state_fio->FputInt32_BE(out_);
-//     state_fio->FputInt32_BE(out2_);
-//     state_fio->FputInt32_BE(in2_);
-//     state_fio->FputUint32_BE(dp_);
-//     state_fio->FputUint32_BE(detune_);
-//     state_fio->FputUint32_BE(detune2_);
-//     state_fio->FputUint32_BE(multiple_);
-//     state_fio->FputUint32_BE(pg_count_);
-//     state_fio->FputUint32_BE(pg_diff_);
-//     state_fio->FputInt32_BE(pg_diff_lfo_);
-//     state_fio->FputUint32_BE(bn_);
-//     state_fio->FputInt32_BE(eg_level_);
-//     state_fio->FputInt32_BE(eg_level_on_next_phase_);
-//     state_fio->FputInt32_BE(eg_count_);
-//     state_fio->FputInt32_BE(eg_count_diff_);
-//     state_fio->FputInt32_BE(eg_out_);
-//     state_fio->FputInt32_BE(tl_out_);
-//     state_fio->FputInt32_BE(eg_rate_);
-//     state_fio->FputInt32_BE(eg_curve_count_);
-//     state_fio->FputInt32_BE(ssg_offset_);
-//     state_fio->FputInt32_BE(ssg_vector_);
-//     state_fio->FputInt32_BE(ssg_phase_);
-//     state_fio->FputUint32_BE(key_scale_rate_);
-//     state_fio->FputInt32_BE(static_cast<int>(eg_phase_));
-//     state_fio->FputInt32_BE((int)(ams_ - &amtable[0][0][0]));
-//     state_fio->FputUint32_BE(ms_);
-//     state_fio->FputUint32_BE(tl_);
-//     state_fio->FputUint32_BE(tl_latch_);
-//     state_fio->FputUint32_BE(ar_);
-//     state_fio->FputUint32_BE(dr_);
-//     state_fio->FputUint32_BE(sr_);
-//     state_fio->FputUint32_BE(sl_);
-//     state_fio->FputUint32_BE(rr_);
-//     state_fio->FputUint32_BE(ks_);
-//     state_fio->FputUint32_BE(ssg_type_);
-//     state_fio->FputBool(keyon_);
-//     state_fio->FputBool(amon_);
-//     state_fio->FputBool(param_changed_);
-//     state_fio->FputBool(mute_);
-//     state_fio->FputInt32_BE(dbgopout_);
-//     state_fio->FputInt32_BE(dbgpgout_);
-}
-
-bool Operator::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
+       state_fio->StateInt32(out_);
+       state_fio->StateInt32(out2_);
+       state_fio->StateInt32(in2_);
+       state_fio->StateUint32(dp_);
+       state_fio->StateUint32(detune_);
+       state_fio->StateUint32(detune2_);
+       state_fio->StateUint32(multiple_);
+       state_fio->StateUint32(pg_count_);
+       state_fio->StateUint32(pg_diff_);
+       state_fio->StateInt32(pg_diff_lfo_);
+       state_fio->StateUint32(bn_);
+       state_fio->StateInt32(eg_level_);
+       state_fio->StateInt32(eg_level_on_next_phase_);
+       state_fio->StateInt32(eg_count_);
+       state_fio->StateInt32(eg_count_diff_);
+       state_fio->StateInt32(eg_out_);
+       state_fio->StateInt32(tl_out_);
+       state_fio->StateInt32(eg_rate_);
+       state_fio->StateInt32(eg_curve_count_);
+       state_fio->StateInt32(ssg_offset_);
+       state_fio->StateInt32(ssg_vector_);
+       state_fio->StateInt32(ssg_phase_);
+       state_fio->StateUint32(key_scale_rate_);
+       if(loading) {
+               eg_phase_ = static_cast<EGPhase>(state_fio->FgetInt32_LE());
+               ams_ = &amtable[0][0][0] + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE(static_cast<int>(eg_phase_));
+               state_fio->FputInt32_LE((int)(ams_ - &amtable[0][0][0]));
        }
-       if(!mb) return false;
-       eg_phase_ = static_cast<EGPhase>(tmp_eg_phase);
-       ams_ = &amtable[0][0][0] + tmp_ams;
-       
-//     if(state_fio->FgetUint32_BE() != OPERATOR_STATE_VERSION) {
-//             return false;
-//     }
-//     out_ = state_fio->FgetInt32_BE();
-//     out2_ = state_fio->FgetInt32_BE();
-//     in2_ = state_fio->FgetInt32_BE();
-//     dp_ = state_fio->FgetUint32_BE();
-//     detune_ = state_fio->FgetUint32_BE();
-//     detune2_ = state_fio->FgetUint32_BE();
-//     multiple_ = state_fio->FgetUint32_BE();
-//     pg_count_ = state_fio->FgetUint32_BE();
-//     pg_diff_ = state_fio->FgetUint32_BE();
-//     pg_diff_lfo_ = state_fio->FgetInt32_BE();
-//     bn_ = state_fio->FgetUint32_BE();
-//     eg_level_ = state_fio->FgetInt32_BE();
-//     eg_level_on_next_phase_ = state_fio->FgetInt32_BE();
-//     eg_count_ = state_fio->FgetInt32_BE();
-//     eg_count_diff_ = state_fio->FgetInt32_BE();
-//     eg_out_ = state_fio->FgetInt32_BE();
-//     tl_out_ = state_fio->FgetInt32_BE();
-//     eg_rate_ = state_fio->FgetInt32_BE();
-//     eg_curve_count_ = state_fio->FgetInt32_BE();
-//     ssg_offset_ = state_fio->FgetInt32_BE();
-//     ssg_vector_ = state_fio->FgetInt32_BE();
-//     ssg_phase_ = state_fio->FgetInt32_BE();
-//     key_scale_rate_ = state_fio->FgetUint32_BE();
-//     eg_phase_ = static_cast<EGPhase>(state_fio->FgetInt32_BE());
-//     ams_ = &amtable[0][0][0] + state_fio->FgetInt32_BE();
-//     ms_ = state_fio->FgetUint32_BE();
-//     tl_ = state_fio->FgetUint32_BE();
-//     tl_latch_ = state_fio->FgetUint32_BE();
-//     ar_ = state_fio->FgetUint32_BE();
-//     dr_ = state_fio->FgetUint32_BE();
-//     sr_ = state_fio->FgetUint32_BE();
-//     sl_ = state_fio->FgetUint32_BE();
-//     rr_ = state_fio->FgetUint32_BE();
-//     ks_ = state_fio->FgetUint32_BE();
-//     ssg_type_ = state_fio->FgetUint32_BE();
-//     keyon_ = state_fio->FgetBool();
-//     amon_ = state_fio->FgetBool();
-//     param_changed_ = state_fio->FgetBool();
-//     mute_ = state_fio->FgetBool();
-//     dbgopout_ = state_fio->FgetInt32_BE();
-//     dbgpgout_ = state_fio->FgetInt32_BE();
-       return true;
+       state_fio->StateUint32(ms_);
+       state_fio->StateUint32(tl_);
+       state_fio->StateUint32(tl_latch_);
+       state_fio->StateUint32(ar_);
+       state_fio->StateUint32(dr_);
+       state_fio->StateUint32(sr_);
+       state_fio->StateUint32(sl_);
+       state_fio->StateUint32(rr_);
+       state_fio->StateUint32(ks_);
+       state_fio->StateUint32(ssg_type_);
+       state_fio->StateBool(keyon_);
+       state_fio->StateBool(amon_);
+       state_fio->StateBool(param_changed_);
+       state_fio->StateBool(mute_);
+       state_fio->StateInt32(dbgopout_);
+       state_fio->StateInt32(dbgpgout_);
+       return true;
 }
 
 #undef Sine
@@ -1199,83 +1062,33 @@ ISample Channel4::CalcLN(uint noise)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define CHANNEL4_STATE_VERSION 2
-void Channel4::DeclState(void *f)
-{
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(CHIP_STATE_VERSION, channel4s_num, _T("FMGEN::Channel4::"), p_logger);
-
-       DECL_STATE_ENTRY_UINT32(fb);
-       DECL_STATE_ENTRY_1D_ARRAY(buf, sizeof(buf) / sizeof(int));
-       for(int i = 0; i < 3; i++) {
-               DECL_STATE_ENTRY_INT32_MEMBER((tmp_in_bufptr[i]), i);
-               DECL_STATE_ENTRY_INT32_MEMBER((tmp_out_bufptr[i]), i);
-       }
-       DECL_STATE_ENTRY_INT32(tmp_pms);
-       DECL_STATE_ENTRY_INT32(algo_);
-       for(int i = 0; i < 4; i++) {
-               op[i].DeclState(f);
-       }
-       
-}
-void Channel4::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       for(int i = 0; i < 3; i++) {
-               tmp_in_bufptr[i] = (int)(in[i] - &buf[0]);
-               tmp_out_bufptr[i] = (int)(out[i] - &buf[0]);
-       }
-       tmp_pms = (int)(pms - &pmtable[0][0][0]);
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32_BE(CHANNEL4_STATE_VERSION);
-       
-//     state_fio->FputUint32_BE(fb);
-//     state_fio->Fwrite(buf, sizeof(buf), 1);
-//     for(int i = 0; i < 3; i++) {
-//             tmp_in_buffer[i] = (int)(in[i] - &buf[0])
-//             tmp_out_buffer[i] = (int)(out[i] - &buf[0])
-//             state_fio->FputInt32_BE((int)(in [i] - &buf[0]));
-//             state_fio->FputInt32_BE((int)(out[i] - &buf[0]));
-//     }
-//     tmp_pms = (int)(pms - &pmtable[0][0][0]);
-//     state_fio->FputInt32_BE((int)(pms - &pmtable[0][0][0]));
-//     state_fio->FputInt32_BE(algo_);
-       for(int i = 0; i < 4; i++) {
-               op[i].SaveState(f);
-       }
-}
+#define CHANNEL4_STATE_VERSION 1
 
-bool Channel4::LoadState(void *f)
+bool Channel4::ProcessState(void *f, bool loading)
 {
        FILEIO *state_fio = (FILEIO *)f;
        
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
+       if(!state_fio->StateCheckUint32(CHANNEL4_STATE_VERSION)) {
+               return false;
        }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != CHANNEL4_STATE_VERSION) {
-//             return false;
-//     }
-       //fb = state_fio->FgetUint32_BE();
-       //state_fio->Fread(buf, sizeof(buf), 1);
-       //for(int i = 0; i < 3; i++) {
-       //      in [i] = &buf[0] + state_fio->FgetInt32_BE();
-       //      out[i] = &buf[0] + state_fio->FgetInt32_BE();
-       //}
-       //pms = &pmtable[0][0][0] + state_fio->FgetInt32_BE();
-       //algo_ = state_fio->FgetInt32_BE();
-       
-       for(int i = 0; i < 3; i++) {
-               in[i] = &buf[0] + tmp_in_bufptr[i];
-               out[i] = &buf[0] + tmp_in_bufptr[i];
+       state_fio->StateUint32(fb);
+       state_fio->StateBuffer(buf, sizeof(buf), 1);
+       if(loading) {
+               for(int i = 0; i < 3; i++) {
+                       in [i] = &buf[0] + state_fio->FgetInt32_LE();
+                       out[i] = &buf[0] + state_fio->FgetInt32_LE();
+               }
+               pms = &pmtable[0][0][0] + state_fio->FgetInt32_LE();
+       } else {
+               for(int i = 0; i < 3; i++) {
+                       state_fio->FputInt32_LE((int)(in [i] - &buf[0]));
+                       state_fio->FputInt32_LE((int)(out[i] - &buf[0]));
+               }
+               state_fio->FputInt32_LE((int)(pms - &pmtable[0][0][0]));
        }
-       pms =&pmtable[0][0][0] + tmp_pms;
+       state_fio->StateInt32(algo_);
        for(int i = 0; i < 4; i++) {
-               if(!op[i].LoadState(f)) {
+               if(!op[i].ProcessState(f, loading)) {
                        return false;
                }
        }
index 4a2e8bd..5383e57 100644 (file)
@@ -33,7 +33,6 @@
 
 // ---------------------------------------------------------------------------
 
-class csp_state_utils;
 class CSP_Logger;
 namespace FM
 {      
@@ -50,7 +49,6 @@ namespace FM
        class Operator
        {
        protected:
-               csp_state_utils *state_entry;
                class CSP_Logger *p_logger;
                int tmp_eg_phase;
                int tmp_ams;
@@ -100,9 +98,7 @@ namespace FM
                void    dbgStopPG() { pg_diff_ = 0; pg_diff_lfo_ = 0; }
                
        protected:
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
                
        private:
                typedef uint32 Counter;
@@ -211,7 +207,6 @@ namespace FM
                int tmp_out_bufptr[3];
                int tmp_pms;
                int channel4s_num;
-               csp_state_utils *state_entry;
                class CSP_Logger *p_logger;
        public:
                Channel4();
@@ -235,9 +230,7 @@ namespace FM
 
                void dbgStopPG() { for (int i=0; i<4; i++) op[i].dbgStopPG(); }
                
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
                
        private:
                static const uint8 fbtable[8];
@@ -264,7 +257,6 @@ namespace FM
        {
        protected:
                class CSP_Logger *p_logger;
-               csp_state_utils *state_entry;
                int chip_num;
        public:
                Chip();
@@ -279,9 +271,7 @@ namespace FM
                int             GetPMV() { return pmv_; }
                uint    GetRatio() { return ratio_; }
 
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
                
        private:
                void    MakeTable();
index 23ade72..2533348 100644 (file)
@@ -9,8 +9,6 @@
 
 #include "../../fileio.h"
 
-#include "../../statesub.h"
-
 using namespace FM;
 
 // ---------------------------------------------------------------------------
@@ -115,60 +113,22 @@ void Timer::SetTimerPrescaler(int32 p)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define TIMER_STATE_VERSION    2
-
-void Timer::DeclState(void *f)
-{
-
-       DECL_STATE_ENTRY_UINT8(status);
-       DECL_STATE_ENTRY_UINT8(regtc);
-       DECL_STATE_ENTRY_1D_ARRAY(regta, sizeof(regta));
-       DECL_STATE_ENTRY_INT32(timera);
-       DECL_STATE_ENTRY_INT32(timera_count);
-       DECL_STATE_ENTRY_INT32(timerb);
-       DECL_STATE_ENTRY_INT32(timerb_count);
-       DECL_STATE_ENTRY_INT32(prescaler);
-}
-
-void Timer::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32_BE(TIMER_STATE_VERSION);
-       
-//     state_fio->FputUint8(status);
-//     state_fio->FputUint8(regtc);
-//     state_fio->Fwrite(regta, sizeof(regta), 1);
-//     state_fio->FputInt32_BE(timera);
-//     state_fio->FputInt32_BE(timera_count);
-//     state_fio->FputInt32_BE(timerb);
-//     state_fio->FputInt32_BE(timerb_count);
-//     state_fio->FputInt32_BE(prescaler);
-}
-
-bool Timer::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != TIMER_STATE_VERSION) {
-//             return false;
-//     }
-//     status = state_fio->FgetUint8();
-//     regtc = state_fio->FgetUint8();
-//     state_fio->Fread(regta, sizeof(regta), 1);
-//     timera = state_fio->FgetInt32_BE();
-//     timera_count = state_fio->FgetInt32_BE();
-//     timerb = state_fio->FgetInt32_BE();
-//     timerb_count = state_fio->FgetInt32_BE();
-//     prescaler = state_fio->FgetInt32_BE();
-       return true;
+#define TIMER_STATE_VERSION    1
+
+bool Timer::ProcessState(void *f, bool loading)
+ {
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(TIMER_STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateUint8(status);
+       state_fio->StateUint8(regtc);
+       state_fio->StateBuffer(regta, sizeof(regta), 1);
+       state_fio->StateInt32(timera);
+       state_fio->StateInt32(timera_count);
+       state_fio->StateInt32(timerb);
+       state_fio->StateInt32(timerb_count);
+       state_fio->StateInt32(prescaler);
+       return true;
 }
-
index ff6997f..3b7e38f 100644 (file)
@@ -10,7 +10,6 @@
 #include "types.h"
 #include "common.h"
 
-class csp_state_utils;
 class CSP_Logger;
 // ---------------------------------------------------------------------------
 
@@ -19,7 +18,6 @@ namespace FM
        class DLL_PREFIX Timer
        {
        protected:
-               csp_state_utils *state_entry;
                CSP_Logger *p_logger;
        public:
                void    Reset();
@@ -35,9 +33,7 @@ namespace FM
                void    SetTimerB(uint data);
                void    SetTimerControl(uint data);
 
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
                
                uint8   status;
                uint8   regtc;
index 74d434d..d4b951a 100644 (file)
@@ -11,8 +11,6 @@
 
 #include "../../fileio.h"
 
-#include "../../statesub.h"
-
 //#define LOGNAME "opm"
 
 namespace FM
@@ -531,139 +529,53 @@ void OPM::Mix(Sample* buffer, int nsamples)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define OPM_STATE_VERSION      4
-
-void OPM::DeclState(void *f)
-{
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(OPM_STATE_VERSION, chip_num, _T("FMGEN::OPM::"), p_logger);
-
-       Timer::DeclState(f);
-
-       DECL_STATE_ENTRY_INT32(fmvolume_l);
-       DECL_STATE_ENTRY_INT32(fmvolume_r);
-       DECL_STATE_ENTRY_UINT32(clock);
-       DECL_STATE_ENTRY_UINT32(rate);
-       DECL_STATE_ENTRY_UINT32(pcmrate);
-       DECL_STATE_ENTRY_UINT32(pmd);
-       DECL_STATE_ENTRY_UINT32(amd);
-       DECL_STATE_ENTRY_UINT32(lfocount);
-       DECL_STATE_ENTRY_UINT32(lfodcount);
-       DECL_STATE_ENTRY_UINT32(lfo_count_);
-       DECL_STATE_ENTRY_UINT32(lfo_count_diff_);
-       DECL_STATE_ENTRY_UINT32(lfo_step_);
-       DECL_STATE_ENTRY_UINT32(lfo_count_prev_);
-       DECL_STATE_ENTRY_UINT32(lfowaveform);
-       DECL_STATE_ENTRY_UINT32(rateratio);
-       DECL_STATE_ENTRY_UINT32(noise);
-       DECL_STATE_ENTRY_INT32(noisecount);
-       DECL_STATE_ENTRY_UINT32(noisedelta);
-       DECL_STATE_ENTRY_BOOL(interpolation);
-       DECL_STATE_ENTRY_UINT8(lfofreq);
-       DECL_STATE_ENTRY_UINT8(status);
-       DECL_STATE_ENTRY_BOOL(interrupt);
-       DECL_STATE_ENTRY_UINT8(reg01);
-       DECL_STATE_ENTRY_1D_ARRAY(kc, sizeof(kc));
-       DECL_STATE_ENTRY_1D_ARRAY(kf, sizeof(kf));
-       DECL_STATE_ENTRY_1D_ARRAY(pan, sizeof(pan));
-       for(int i = 0; i < 8; i++) {
-               ch[i].DeclState(f);
-       }
-       chip.DeclState(f);
-}
-
-void OPM::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32_BE(OPM_STATE_VERSION);
-//     
-//     Timer::SaveState(f);
-//     state_fio->FputInt32_BE(fmvolume_l);
-//     state_fio->FputInt32_BE(fmvolume_r);
-//     state_fio->FputUint32_BE(clock);
-//     state_fio->FputUint32_BE(rate);
-//     state_fio->FputUint32_BE(pcmrate);
-//     state_fio->FputUint32_BE(pmd);
-//     state_fio->FputUint32_BE(amd);
-//     state_fio->FputUint32_BE(lfocount);
-//     state_fio->FputUint32_BE(lfodcount);
-//     state_fio->FputUint32_BE(lfo_count_);
-//     state_fio->FputUint32_BE(lfo_count_diff_);
-//     state_fio->FputUint32_BE(lfo_step_);
-//     state_fio->FputUint32_BE(lfo_count_prev_);
-//     state_fio->FputUint32_BE(lfowaveform);
-//     state_fio->FputUint32_BE(rateratio);
-//     state_fio->FputUint32_BE(noise);
-//     state_fio->FputInt32_BE(noisecount);
-//     state_fio->FputUint32_BE(noisedelta);
-//     state_fio->FputBool(interpolation);
-//     state_fio->FputUint8(lfofreq);
-//     state_fio->FputUint8(status);
-//     state_fio->FputBool(interrupt);
-//     state_fio->FputUint8(reg01);
-//     state_fio->Fwrite(kc, sizeof(kc), 1);
-//     state_fio->Fwrite(kf, sizeof(kf), 1);
-//     state_fio->Fwrite(pan, sizeof(pan), 1);
-       for(int i = 0; i < 8; i++) {
-               ch[i].SaveState(f);
-       }
-       chip.SaveState(f);
-}
+#define OPM_STATE_VERSION      3
 
-bool OPM::LoadState(void *f)
+bool OPM::ProcessState(void *f, bool loading)
 {
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != OPM_STATE_VERSION) {
-//             return false;
-//     }
-//     if(!Timer::LoadState(f)) {
-//             return false;
-//     }
-//     fmvolume_l = state_fio->FgetInt32_BE();
-//     fmvolume_r = state_fio->FgetInt32_BE();
-//     clock = state_fio->FgetUint32_BE();
-//     rate = state_fio->FgetUint32_BE();
-//     pcmrate = state_fio->FgetUint32_BE();
-//     pmd = state_fio->FgetUint32_BE();
-//     amd = state_fio->FgetUint32_BE();
-//     lfocount = state_fio->FgetUint32_BE();
-//     lfodcount = state_fio->FgetUint32_BE();
-//     lfo_count_ = state_fio->FgetUint32_BE();
-//     lfo_count_diff_ = state_fio->FgetUint32_BE();
-//     lfo_step_ = state_fio->FgetUint32_BE();
-//     lfo_count_prev_ = state_fio->FgetUint32_BE();
-//     lfowaveform = state_fio->FgetUint32_BE();
-//     rateratio = state_fio->FgetUint32_BE();
-//     noise = state_fio->FgetUint32_BE();
-//     noisecount = state_fio->FgetInt32_BE();
-//     noisedelta = state_fio->FgetUint32_BE();
-//     interpolation = state_fio->FgetBool();
-//     lfofreq = state_fio->FgetUint8();
-//     status = state_fio->FgetUint8();
-//     interrupt = state_fio->FgetBool();
-//     reg01 = state_fio->FgetUint8();
-//     state_fio->Fread(kc, sizeof(kc), 1);
-//     state_fio->Fread(kf, sizeof(kf), 1);
-//     state_fio->Fread(pan, sizeof(pan), 1);
-       for(int i = 0; i < 8; i++) {
-               if(!ch[i].LoadState(f)) {
-                       return false;
-               }
-       }
-       if(!chip.LoadState(f)) {
-               return false;
-       }
-       return true;
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(OPM_STATE_VERSION)) {
+               return false;
+       }
+       if(!Timer::ProcessState(f, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(fmvolume_l);
+       state_fio->StateInt32(fmvolume_r);
+       state_fio->StateUint32(clock);
+       state_fio->StateUint32(rate);
+       state_fio->StateUint32(pcmrate);
+       state_fio->StateUint32(pmd);
+       state_fio->StateUint32(amd);
+       state_fio->StateUint32(lfocount);
+       state_fio->StateUint32(lfodcount);
+       state_fio->StateUint32(lfo_count_);
+       state_fio->StateUint32(lfo_count_diff_);
+       state_fio->StateUint32(lfo_step_);
+       state_fio->StateUint32(lfo_count_prev_);
+       state_fio->StateUint32(lfowaveform);
+       state_fio->StateUint32(rateratio);
+       state_fio->StateUint32(noise);
+       state_fio->StateInt32(noisecount);
+       state_fio->StateUint32(noisedelta);
+       state_fio->StateBool(interpolation);
+       state_fio->StateUint8(lfofreq);
+       state_fio->StateUint8(status);
+       state_fio->StateBool(interrupt);
+       state_fio->StateUint8(reg01);
+       state_fio->StateBuffer(kc, sizeof(kc), 1);
+       state_fio->StateBuffer(kf, sizeof(kf), 1);
+       state_fio->StateBuffer(pan, sizeof(pan), 1);
+       for(int i = 0; i < 8; i++) {
+               if(!ch[i].ProcessState(f, loading)) {
+                       return false;
+               }
+       }
+       if(!chip.ProcessState(f, loading)) {
+               return false;
+       }
+       return true;
 }
 
 }      // namespace FM
index 7339693..d747d90 100644 (file)
@@ -11,7 +11,6 @@
 #include "fmtimer.h"
 #include "psg.h"
 
-class csp_state_utils;
 class CSP_Logger;
 // ---------------------------------------------------------------------------
 //     class OPM
@@ -96,9 +95,7 @@ namespace FM
                void    SetVolume(int db_l, int db_r);
                void    SetChannelMask(uint mask);
 
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool    ProcessState(void *f, bool loading);
                
        private:
                void    Intr(bool value);
index c3d885f..59130f2 100644 (file)
@@ -197,80 +197,40 @@ void OPNBase::Intr(bool value)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define OPN_BASE_STATE_VERSION 4
+#define OPN_BASE_STATE_VERSION 2
 
-void OPNBase::DeclState(void *f)
+bool OPNBase::ProcessState(void *f, bool loading)
 {
-       Timer::DeclState(f);
-       DECL_STATE_ENTRY_INT32(fmvolume_l);
-       DECL_STATE_ENTRY_INT32(fmvolume_r);
-       DECL_STATE_ENTRY_UINT32(clock);
-       DECL_STATE_ENTRY_UINT32(rate);
-       DECL_STATE_ENTRY_UINT32(psgrate);
-       DECL_STATE_ENTRY_UINT32(status);
-       DECL_STATE_ENTRY_BOOL(interrupt);
-       DECL_STATE_ENTRY_UINT8(prescale);
-       chip.DeclState(f);
-       psg.DeclState(f);
-}
-
-void OPNBase::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       chip.SaveState(f);
-       psg.SaveState(f);
-//     state_fio->FputUint32_BE(OPN_BASE_STATE_VERSION);
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(OPN_BASE_STATE_VERSION)) {
+               return false;
+       }
        
-//     Timer::SaveState(f);
-//     state_fio->FputInt32_BE(fmvolume_l);
-//     state_fio->FputInt32_BE(fmvolume_r);
-//     state_fio->FputUint32_BE(clock);
-//     state_fio->FputUint32_BE(rate);
-//     state_fio->FputUint32_BE(psgrate);
-//     state_fio->FputUint32_BE(status);
-//     state_fio->FputBool(interrupt);
-//     state_fio->FputUint8(prescale);
-}
-
-bool OPNBase::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != OPN_BASE_STATE_VERSION) {
-//             return false;
-//     }
-//     if(!Timer::LoadState(f)) {
-//             return false;
-//     }
-//     fmvolume_l = state_fio->FgetInt32_BE();
-//     fmvolume_r = state_fio->FgetInt32_BE();
-//     clock = state_fio->FgetUint32_BE();
-//     rate = state_fio->FgetUint32_BE();
-//     psgrate = state_fio->FgetUint32_BE();
-//     status = state_fio->FgetUint32_BE();
-//     interrupt = state_fio->FgetBool();
-//     prescale = state_fio->FgetUint8();
-       {
+       if(!Timer::ProcessState(f, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(fmvolume_l);
+       state_fio->StateInt32(fmvolume_r);
+       state_fio->StateUint32(clock);
+       state_fio->StateUint32(rate);
+       state_fio->StateUint32(psgrate);
+       state_fio->StateUint32(status);
+       state_fio->StateBool(interrupt);
+       state_fio->StateUint8(prescale);
+       if(loading){
                // Make force-restore around prescaler and timers. 20180625 K.O
                uint bak = prescale;
                prescale = 10;
                SetPrescaler(bak);
        }
-       if(!chip.LoadState(f)) {
-               return false;
-       }
-       if(!psg.LoadState(f)) {
-               return false;
-       }
-       return true;
+       if(!chip.ProcessState(f, loading)) {
+               return false;
+       }
+       if(!psg.ProcessState(f, loading)) {
+               return false;
+       }
+       return true;
 }
 
 #endif // defined(BUILD_OPN) || defined(BUILD_OPNA) || defined (BUILD_OPNB) || defined(BUILD_OPN2)
@@ -480,74 +440,34 @@ void OPN::Mix(Sample* buffer, int nsamples)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define OPN_STATE_VERSION      2
+#define OPN_STATE_VERSION      1
 
-void OPN::DeclState(void *f)
+bool OPN::ProcessState(void *f, bool loading)
 {
-
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(OPN_STATE_VERSION, chip_num, _T("FMGEN::OPN::"), p_logger);
-
-       OPNBase::DeclState(f);
+       FILEIO *state_fio = (FILEIO *)f;
        
-       for(int i = 0; i < 3; i++) {
-               DECL_STATE_ENTRY_UINT32_MEMBER((fnum[i]), i);
-               DECL_STATE_ENTRY_UINT32_MEMBER((fnum3[i]), i);
-       }               
-       DECL_STATE_ENTRY_1D_ARRAY(fnum2, sizeof(fnum2));
-       for(int i = 0; i < 3; i++) {
-               ch[i].DeclState(f);
-       }
-}
-
-void OPN::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       OPNBase::SaveState(f);
-//     state_fio->FputUint32_BE(OPN_STATE_VERSION);
-//     
-//     OPNBase::SaveState(f);
-//     for(int i = 0; i < 3; i++) {
-//             state_fio->FputUint32_BE(fnum[i]);
-//     }               
-//     for(int i = 0; i < 3; i++) {
-//             state_fio->FputUint32_BE(fnum3[i]);
-//     }               
-//     //state_fio->Fwrite(fnum, sizeof(fnum), 1);
-//     //state_fio->Fwrite(fnum3, sizeof(fnum3), 1);
-//     state_fio->Fwrite(fnum2, sizeof(fnum2), 1);
-       for(int i = 0; i < 3; i++) {
-               ch[i].SaveState(f);
-       }
-}
-
-bool OPN::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       bool mb = false;
-       mb = OPNBase::LoadState(f);
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != OPN_STATE_VERSION) {
-//             return false;
-//     }
-//     if(!OPNBase::LoadState(f)) {
-//             return false;
-//     }
-//     for(int i = 0; i < 3; i++) {
-//             fnum[i] = state_fio->FgetUint32_BE();
-//     }               
-//     for(int i = 0; i < 3; i++) {
-//             fnum3[i] = state_fio->FgetUint32_BE();
-//     }               
-//     //state_fio->Fread(fnum, sizeof(fnum), 1);
-//     //state_fio->Fread(fnum3, sizeof(fnum3), 1);
-//     state_fio->Fread(fnum2, sizeof(fnum2), 1);
-       for(int i = 0; i < 3; i++) {
-               if(!ch[i].LoadState(f)) {
-                       return false;
-               }
-       }
+       if(!state_fio->StateCheckUint32(OPN_STATE_VERSION)) {
+               return false;
+       }
+       if(!OPNBase::ProcessState(f, loading)) {
+               return false;
+       }
+       
+       if(!state_fio->StateCheckUint32(OPN_STATE_VERSION)) {
+               return false;
+       }
+       if(!OPNBase::ProcessState(f, loading)) {
+               return false;
+       }
+
+       state_fio->StateBuffer(fnum, sizeof(fnum), 1);
+       state_fio->StateBuffer(fnum3, sizeof(fnum3), 1);
+       state_fio->StateBuffer(fnum2, sizeof(fnum2), 1);
+       for(int i = 0; i < 3; i++) {
+               if(!ch[i].ProcessState(f, loading)) {
+                       return false;
+               }
+       }
        return true;
 }
 
@@ -1375,212 +1295,68 @@ void OPNABase::Mix6(Sample* buffer, int nsamples, int activech)
 //
 #define OPNA_BASE_STATE_VERSION        2
 
-void OPNABase::DeclState(void *f)
+bool OPNABase::ProcessState(void *f, bool loading)
 {
-
-       OPNBase::DeclState(f);
+       FILEIO *state_fio = (FILEIO *)f;
        
-       DECL_STATE_ENTRY_1D_ARRAY(pan, sizeof(pan));
-       DECL_STATE_ENTRY_1D_ARRAY(fnum2, sizeof(fnum2));
-       DECL_STATE_ENTRY_UINT8(reg22);
-       DECL_STATE_ENTRY_UINT32(reg29);
-       DECL_STATE_ENTRY_UINT32(stmask);
-       DECL_STATE_ENTRY_UINT32(statusnext);
-       DECL_STATE_ENTRY_UINT32(lfocount);
-       DECL_STATE_ENTRY_UINT32(lfodcount);
-       //state_fio->Fwrite(fnum, sizeof(fnum), 1);
-       //state_fio->Fwrite(fnum3, sizeof(fnum3), 1);
+       if(!state_fio->StateCheckUint32(OPNA_BASE_STATE_VERSION)) {
+               return false;
+       }
+       if(!OPNBase::ProcessState(f, loading)) {
+               return false;
+       }
+       state_fio->StateBuffer(pan, sizeof(pan), 1);
+       state_fio->StateBuffer(fnum2, sizeof(fnum2), 1);
+       state_fio->StateUint8(reg22);
+       state_fio->StateUint32(reg29);
+       state_fio->StateUint32(stmask);
+       state_fio->StateUint32(statusnext);
+       state_fio->StateUint32(lfocount);
+       state_fio->StateUint32(lfodcount);
+       state_fio->StateBuffer(fnum, sizeof(fnum), 1);
+       state_fio->StateBuffer(fnum3, sizeof(fnum3), 1);
+       state_fio->StateBuffer(adpcmbuf, 0x40000, 1);
+       state_fio->StateUint32(adpcmmask);
+       state_fio->StateUint32(adpcmnotice);
+       state_fio->StateUint32(startaddr);
+       state_fio->StateUint32(stopaddr);
+       state_fio->StateUint32(memaddr);
+       state_fio->StateUint32(limitaddr);
+       state_fio->StateInt32(adpcmlevel);
+       state_fio->StateInt32(adpcmvolume_l);
+       state_fio->StateInt32(adpcmvolume_r);
+       state_fio->StateInt32(adpcmvol_l);
+       state_fio->StateInt32(adpcmvol_r);
+       state_fio->StateUint32(deltan);
+       state_fio->StateInt32(adplc);
+       state_fio->StateInt32(adpld);
+       state_fio->StateUint32(adplbase);
+       state_fio->StateInt32(adpcmx);
+       state_fio->StateInt32(adpcmd);
+       state_fio->StateInt32(adpcmout_l);
+       state_fio->StateInt32(adpcmout_r);
+       state_fio->StateInt32(apout0_l);
+       state_fio->StateInt32(apout0_r);
+       state_fio->StateInt32(apout1_l);
+       state_fio->StateInt32(apout1_r);
+       state_fio->StateUint32(adpcmreadbuf);
+       state_fio->StateBool(adpcmplay);
+       state_fio->StateInt8(granuality);
+       state_fio->StateBool(adpcmmask_);
+       state_fio->StateUint8(control1);
+       state_fio->StateUint8(control2);
+       state_fio->StateBuffer(adpcmreg, sizeof(adpcmreg), 1);
+       state_fio->StateInt32(rhythmmask_);
        for(int i = 0; i < 6; i++) {
-               DECL_STATE_ENTRY_UINT32_MEMBER((fnum[i]), i);
-       }               
-       for(int i = 0; i < 3; i++) {
-               DECL_STATE_ENTRY_UINT32_MEMBER((fnum3[i]), i);
-       }               
-       DECL_STATE_ENTRY_1D_ARRAY(adpcmbuf, 0x40000);
-       DECL_STATE_ENTRY_UINT32(adpcmmask);
-       DECL_STATE_ENTRY_UINT32(adpcmnotice);
-       DECL_STATE_ENTRY_UINT32(startaddr);
-       DECL_STATE_ENTRY_UINT32(stopaddr);
-       DECL_STATE_ENTRY_UINT32(memaddr);
-       DECL_STATE_ENTRY_UINT32(limitaddr);
-       DECL_STATE_ENTRY_INT32(adpcmlevel);
-       DECL_STATE_ENTRY_INT32(adpcmvolume_l);
-       DECL_STATE_ENTRY_INT32(adpcmvolume_r);
-       DECL_STATE_ENTRY_INT32(adpcmvol_l);
-       DECL_STATE_ENTRY_INT32(adpcmvol_r);
-       DECL_STATE_ENTRY_UINT32(deltan);
-       DECL_STATE_ENTRY_INT32(adplc);
-       DECL_STATE_ENTRY_INT32(adpld);
-       DECL_STATE_ENTRY_UINT32(adplbase);
-       DECL_STATE_ENTRY_INT32(adpcmx);
-       DECL_STATE_ENTRY_INT32(adpcmd);
-       DECL_STATE_ENTRY_INT32(adpcmout_l);
-       DECL_STATE_ENTRY_INT32(adpcmout_r);
-       DECL_STATE_ENTRY_INT32(apout0_l);
-       DECL_STATE_ENTRY_INT32(apout0_r);
-       DECL_STATE_ENTRY_INT32(apout1_l);
-       DECL_STATE_ENTRY_INT32(apout1_r);
-       DECL_STATE_ENTRY_UINT32(adpcmreadbuf);
-       DECL_STATE_ENTRY_BOOL(adpcmplay);
-       DECL_STATE_ENTRY_INT8(granuality);
-       DECL_STATE_ENTRY_BOOL(adpcmmask_);
-       DECL_STATE_ENTRY_UINT8(control1);
-       DECL_STATE_ENTRY_UINT8(control2);
-       DECL_STATE_ENTRY_1D_ARRAY(adpcmreg, sizeof(adpcmreg));
-       DECL_STATE_ENTRY_INT32(rhythmmask_);
-
-       for(int i = 0; i < 6; i++) {
-               ch[i].DeclState(f);
-       }
-}
-void OPNABase::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       chip.SaveState(f);
-       psg.SaveState(f);
-       
-//     state_fio->FputUint32_BE(OPNA_BASE_STATE_VERSION);
-       
-//     OPNBase::SaveState(f);
-//     state_fio->Fwrite(pan, sizeof(pan), 1);
-//     state_fio->Fwrite(fnum2, sizeof(fnum2), 1);
-//     state_fio->FputUint8(reg22);
-//     state_fio->FputUint32_BE(reg29);
-//     state_fio->FputUint32_BE(stmask);
-//     state_fio->FputUint32_BE(statusnext);
-//     state_fio->FputUint32_BE(lfocount);
-//     state_fio->FputUint32_BE(lfodcount);
-//     //state_fio->Fwrite(fnum, sizeof(fnum), 1);
-//     //state_fio->Fwrite(fnum3, sizeof(fnum3), 1);
-//     for(int i = 0; i < 6; i++) {
-//             state_fio->FputUint32_BE(fnum[i]);
-//     }               
-//     for(int i = 0; i < 3; i++) {
-//             state_fio->FputUint32_BE(fnum3[i]);
-//     }               
-//     state_fio->Fwrite(adpcmbuf, 0x40000, 1);
-//     state_fio->FputUint32_BE(adpcmmask);
-//     state_fio->FputUint32_BE(adpcmnotice);
-//     state_fio->FputUint32_BE(startaddr);
-//     state_fio->FputUint32_BE(stopaddr);
-//     state_fio->FputUint32_BE(memaddr);
-//     state_fio->FputUint32_BE(limitaddr);
-//     state_fio->FputInt32_BE(adpcmlevel);
-//     state_fio->FputInt32_BE(adpcmvolume_l);
-//     state_fio->FputInt32_BE(adpcmvolume_r);
-//     state_fio->FputInt32_BE(adpcmvol_l);
-//     state_fio->FputInt32_BE(adpcmvol_r);
-//     state_fio->FputUint32_BE(deltan);
-//     state_fio->FputInt32_BE(adplc);
-//     state_fio->FputInt32_BE(adpld);
-//     state_fio->FputUint32_BE(adplbase);
-//     state_fio->FputInt32_BE(adpcmx);
-//     state_fio->FputInt32_BE(adpcmd);
-//     state_fio->FputInt32_BE(adpcmout_l);
-//     state_fio->FputInt32_BE(adpcmout_r);
-//     state_fio->FputInt32_BE(apout0_l);
-//     state_fio->FputInt32_BE(apout0_r);
-//     state_fio->FputInt32_BE(apout1_l);
-//     state_fio->FputInt32_BE(apout1_r);
-//     state_fio->FputUint32_BE(adpcmreadbuf);
-//     state_fio->FputBool(adpcmplay);
-//     state_fio->FputInt8(granuality);
-//     state_fio->FputBool(adpcmmask_);
-//     state_fio->FputUint8(control1);
-//     state_fio->FputUint8(control2);
-//     state_fio->Fwrite(adpcmreg, sizeof(adpcmreg), 1);
-//     state_fio->FputInt32_BE(rhythmmask_);
-       for(int i = 0; i < 6; i++) {
-               ch[i].SaveState(f);
-       }
-}
-
-bool OPNABase::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) return false;
-       {
-               // Make force-restore around prescaler and timers. 20180625 K.O
-               uint bak = prescale;
-               prescale = 10;
-               SetPrescaler(bak);
-       }
-       if(!chip.LoadState(f)) {
-               return false;
-       }
-       if(!psg.LoadState(f)) {
-               return false;
-       }
-//     if(state_fio->FgetUint32_BE() != OPNA_BASE_STATE_VERSION) {
-//             return false;
-//     }
-//     if(!OPNBase::LoadState(f)) {
-//             return false;
-//     }
-//     state_fio->Fread(pan, sizeof(pan), 1);
-//     state_fio->Fread(fnum2, sizeof(fnum2), 1);
-//     reg22 = state_fio->FgetUint8();
-//     reg29 = state_fio->FgetUint32_BE();
-//     stmask = state_fio->FgetUint32_BE();
-//     statusnext = state_fio->FgetUint32_BE();
-//     lfocount = state_fio->FgetUint32_BE();
-//     lfodcount = state_fio->FgetUint32_BE();
-//     //state_fio->Fread(fnum, sizeof(fnum), 1);
-//     //state_fio->Fread(fnum3, sizeof(fnum3), 1);
-//     for(int i = 0; i < 6; i++) {
-//             fnum[i] = state_fio->FgetUint32_BE();
-//     }               
-//     for(int i = 0; i < 3; i++) {
-//             fnum3[i] = state_fio->FgetUint32_BE();
-//     }               
-//     state_fio->Fread(adpcmbuf, 0x40000, 1);
-//     adpcmmask = state_fio->FgetUint32_BE();
-//     adpcmnotice = state_fio->FgetUint32_BE();
-//     startaddr = state_fio->FgetUint32_BE();
-//     stopaddr = state_fio->FgetUint32_BE();
-//     memaddr = state_fio->FgetUint32_BE();
-//     limitaddr = state_fio->FgetUint32_BE();
-//     adpcmlevel = state_fio->FgetInt32_BE();
-//     adpcmvolume_l = state_fio->FgetInt32_BE();
-//     adpcmvolume_r = state_fio->FgetInt32_BE();
-//     adpcmvol_l = state_fio->FgetInt32_BE();
-//     adpcmvol_r = state_fio->FgetInt32_BE();
-//     deltan = state_fio->FgetUint32_BE();
-//     adplc = state_fio->FgetInt32_BE();
-//     adpld = state_fio->FgetInt32_BE();
-//     adplbase = state_fio->FgetUint32_BE();
-//     adpcmx = state_fio->FgetInt32_BE();
-//     adpcmd = state_fio->FgetInt32_BE();
-//     adpcmout_l = state_fio->FgetInt32_BE();
-//     adpcmout_r = state_fio->FgetInt32_BE();
-//     apout0_l = state_fio->FgetInt32_BE();
-//     apout0_r = state_fio->FgetInt32_BE();
-//     apout1_l = state_fio->FgetInt32_BE();
-//     apout1_r = state_fio->FgetInt32_BE();
-//     adpcmreadbuf = state_fio->FgetUint32_BE();
-//     adpcmplay = state_fio->FgetBool();
-//     granuality = state_fio->FgetInt8();
-//     adpcmmask_ = state_fio->FgetBool();
-//     control1 = state_fio->FgetUint8();
-//     control2 = state_fio->FgetUint8();
-///    state_fio->Fread(adpcmreg, sizeof(adpcmreg), 1);
-//     rhythmmask_ = state_fio->FgetInt32_BE();
-       for(int i = 0; i < 6; i++) {
-               if(!ch[i].LoadState(f)) {
-                       return false;
-               }
-       }
+               if(!ch[i].ProcessState(f, loading)) {
+                       return false;
+               }
+       }
        return true;
 }
 
+
+
 #endif // defined(BUILD_OPNA) || defined(BUILD_OPNB)
 
 // ---------------------------------------------------------------------------
@@ -1954,68 +1730,30 @@ void OPNA::Mix(Sample* buffer, int nsamples)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define OPNA_STATE_VERSION     4
-
-void OPNA::DeclState(void *f)
-{
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(OPNA_STATE_VERSION, chip_num, _T("FMGEN::OPNA::"), p_logger);
-
-       OPNABase::DeclState(f);
-       
-       for(int i = 0; i < 6; i++) {
-               DECL_STATE_ENTRY_UINT8_MEMBER((rhythm[i].pan), i);
-               DECL_STATE_ENTRY_INT8_MEMBER((rhythm[i].level), i);
-               DECL_STATE_ENTRY_UINT32_MEMBER((rhythm[i].pos), i);
-       }
-       DECL_STATE_ENTRY_INT8(rhythmtl);
-       DECL_STATE_ENTRY_INT32(rhythmtvol_l);
-       DECL_STATE_ENTRY_INT32(rhythmtvol_r);
-       DECL_STATE_ENTRY_UINT8(rhythmkey);
-}
-void OPNA::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       OPNABase::SaveState(f);
-//     state_fio->FputUint32_BE(OPNA_STATE_VERSION);
-       
-//     OPNABase::SaveState(f);
-//     for(int i = 0; i < 6; i++) {
-//             state_fio->FputUint8(rhythm[i].pan);
-//             state_fio->FputInt8(rhythm[i].level);
-//             state_fio->FputUint32_BE(rhythm[i].pos);
-//     }
-//     state_fio->FputInt8(rhythmtl);
-//     state_fio->FputInt32_BE(rhythmtvol_l);
-//     state_fio->FputInt32_BE(rhythmtvol_r);
-//     state_fio->FputUint8(rhythmkey);
-}
+#define OPNA_STATE_VERSION     2
 
-bool OPNA::LoadState(void *f)
+bool OPNA::ProcessState(void *f, bool loading)
 {
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       bool mb = false;
-       mb = OPNABase::LoadState(f);
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != OPNA_STATE_VERSION) {
-//             return false;
-//     }
-//     if(!OPNABase::LoadState(f)) {
-//             return false;
-//     }
-//     for(int i = 0; i < 6; i++) {
-//             rhythm[i].pan = state_fio->FgetUint8();
-//             rhythm[i].level = state_fio->FgetInt8();
-//             rhythm[i].pos = state_fio->FgetUint32_BE();
-//     }
-//     rhythmtl = state_fio->FgetInt8();
-//     rhythmtvol_l = state_fio->FgetInt32_BE();
-//     rhythmtvol_r = state_fio->FgetInt32_BE();
-//     rhythmkey = state_fio->FgetUint8();
-       return true;
-}
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(OPNA_STATE_VERSION)) {
+               return false;
+       }
+       if(!OPNABase::ProcessState(f, loading)) {
+               return false;
+       }
+       for(int i = 0; i < 6; i++) {
+               state_fio->StateUint8(rhythm[i].pan);
+               state_fio->StateInt8(rhythm[i].level);
+               state_fio->StateUint32(rhythm[i].pos);
+       }
+       state_fio->StateInt8(rhythmtl);
+       state_fio->StateInt32(rhythmtvol_l);
+       state_fio->StateInt32(rhythmtvol_r);
+       state_fio->StateUint8(rhythmkey);
+       return true;
+}
 
 #endif // BUILD_OPNA
 
@@ -2800,67 +2538,38 @@ void OPN2Base::Mix6(Sample* buffer, int nsamples, int activech)
 //
 #define OPN2_BASE_STATE_VERSION        1
 
-void OPN2Base::DeclState(void *f)
+bool OPN2Base::ProcessState(void *f, bool loading)
 {
-
-       OPNBase::DeclState(f);
+       FILEIO *state_fio = (FILEIO *)f;
        
-       DECL_STATE_ENTRY_1D_ARRAY(pan, sizeof(pan));
-       DECL_STATE_ENTRY_1D_ARRAY(fnum2, sizeof(fnum2));
-       DECL_STATE_ENTRY_UINT8(reg22);
-       DECL_STATE_ENTRY_UINT32(reg29);
-       DECL_STATE_ENTRY_UINT32(stmask);
-       DECL_STATE_ENTRY_UINT32(statusnext);
-       DECL_STATE_ENTRY_UINT32(lfocount);
-       DECL_STATE_ENTRY_UINT32(lfodcount);
-       //state_fio->Fwrite(fnum, sizeof(fnum), 1);
-       //state_fio->Fwrite(fnum3, sizeof(fnum3), 1);
-       for(int i = 0; i < 6; i++) {
-               DECL_STATE_ENTRY_UINT32_MEMBER((fnum[i]), i);
-       }               
-       for(int i = 0; i < 3; i++) {
-               DECL_STATE_ENTRY_UINT32_MEMBER((fnum3[i]), i);
-       }               
-       for(int i = 0; i < 6; i++) {
-               ch[i].DeclState(f);
-       }
-}
-
-void OPN2Base::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       chip.SaveState(f);
-       for(int i = 0; i < 6; i++) {
-               ch[i].SaveState(f);
-       }
-}
-
-bool OPN2Base::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
+       if(!state_fio->StateCheckUint32(OPN2_BASE_STATE_VERSION)) {
+               return false;
+       }
+       if(!OPNBase::ProcessState(f, loading)) {
+               return false;
+       }
+       state_fio->StateBuffer(pan, sizeof(pan), 1);
+       state_fio->StateBuffer(fnum2, sizeof(fnum2), 1);
+       state_fio->StateUint8(reg22);
+       state_fio->StateUint32(reg29);
+       state_fio->StateUint32(stmask);
+       state_fio->StateUint32(statusnext);
+       state_fio->StateUint32(lfocount);
+       state_fio->StateUint32(lfodcount);
+       state_fio->StateBuffer(fnum, sizeof(fnum), 1);
+       state_fio->StateBuffer(fnum3, sizeof(fnum3), 1);
        
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) return false;
-       {
+       if(loading) {
                // Make force-restore around prescaler and timers. 20180625 K.O
                uint bak = prescale;
                prescale = 10;
                SetPrescaler(bak);
        }
-       if(!chip.LoadState(f)) {
-               return false;
-       }
        for(int i = 0; i < 6; i++) {
-               if(!ch[i].LoadState(f)) {
-                       return false;
-               }
-       }
+               if(!ch[i].ProcessState(f, loading)) {
+                       return false;
+               }
+       }
        return true;
 }
 #endif // defined(BUILD_OPN2)
@@ -2962,29 +2671,9 @@ void OPN2::Mix(Sample* buffer, int nsamples)
 //
 #define OPN2_STATE_VERSION     1
 
-void OPN2::DeclState(void *f)
-{
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(OPN2_STATE_VERSION, chip_num, _T("FMGEN::OPN2::"), p_logger);
-
-       OPN2Base::DeclState(f);
-}
-
-void OPN2::SaveState(void *f)
+bool OPN2::ProcessState(void *f, bool loading)
 {
-       FILEIO *state_fio = (FILEIO *)f;
-       OPN2Base::SaveState(f);
-}
-
-bool OPN2::LoadState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       bool mb = false;
-       mb = OPN2Base::LoadState(f);
-       if(!mb) return false;
-
-       return true;
+       return OPN2Base::ProcessState(f, loading);
 }
 
 #endif // BUILD_OPN2
index 35413a9..4265b57 100644 (file)
@@ -111,9 +111,7 @@ namespace FM
                void    RebuildTimeTable();
                void    Intr(bool value);
                
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
                
                int             fmvolume_l;
                int             fmvolume_r;
@@ -160,9 +158,7 @@ namespace FM
                void    SetADPCMBReg(uint reg, uint data);
                uint    GetReg(uint addr);      
                
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
        
        protected:
                void    FMMix(Sample* buffer, int nsamples);
@@ -268,9 +264,7 @@ namespace FM
                void    SetReg(uint addr, uint data);
                uint    GetReg(uint addr);      
                
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
        
        protected:
                void    FMMix(Sample* buffer, int nsamples);
@@ -331,9 +325,7 @@ namespace FM
                int             dbgGetPGOut(int c, int s) { return ch[c].op[s].dbgpgout_; }
                Channel4* dbgGetCh(int c) { return &ch[c]; }
                
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
        
        private:
                void    SetStatus(uint bit);
@@ -373,9 +365,7 @@ namespace FM
                int             dbgGetPGOut(int c, int s) { return ch[c].op[s].dbgpgout_; }
                Channel4* dbgGetCh(int c) { return &ch[c]; }
 
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+               bool ProcessState(void *f, bool loading);
                
        private:
                struct Rhythm
@@ -479,9 +469,8 @@ namespace FM
                uint    GetReg(uint addr);
                uint    ReadStatus() { return status & 0x03; }
                uint    ReadStatusEx() { return 0xff; }
-               void DeclState(void *f);
-               void SaveState(void *f);
-               bool LoadState(void *f);
+
+               bool ProcessState(void *f, bool loading);
 
        private:
                //void  SetStatus(uint bit);
index 7b91c74..a2c3d77 100644 (file)
@@ -9,9 +9,6 @@
 #include "psg.h"
 
 #include "../../fileio.h"
-
-#include "../../statesub.h"
-
 // ---------------------------------------------------------------------------
 //     \83R\83\93\83X\83g\83\89\83N\83^\81E\83f\83X\83g\83\89\83N\83^
 //
@@ -437,100 +434,33 @@ void PSG::Mix(Sample* dest, int nsamples)
 // ---------------------------------------------------------------------------
 //     \83X\83e\81[\83g\83Z\81[\83u
 //
-#define PSG_STATE_VERSION      3
-void PSG::DeclState(void *f)
-{
-       p_logger = (CSP_Logger *)f;
-       state_entry = new csp_state_utils(PSG_STATE_VERSION, chip_num, _T("FMGEN::PSG::"), p_logger);
-
-       DECL_STATE_ENTRY_1D_ARRAY(reg, sizeof(reg));
-       DECL_STATE_ENTRY_INT32(tmp_envelop_l);
-       //state_fio->Fwrite(olevel_l, sizeof(olevel_l), 1);
-       //state_fio->Fwrite(olevel_r, sizeof(olevel_r), 1);
-       //state_fio->Fwrite(scount, sizeof(scount), 1);
-       //state_fio->Fwrite(speriod, sizeof(speriod), 1);
-       for(int i = 0; i < 3; i++) {
-               DECL_STATE_ENTRY_UINT32(olevel_l[i]);
-               DECL_STATE_ENTRY_UINT32(olevel_r[i]);
-               DECL_STATE_ENTRY_UINT32(scount[i]);
-               DECL_STATE_ENTRY_UINT32(speriod[i]);
-       }
-       DECL_STATE_ENTRY_UINT32(ecount);
-       DECL_STATE_ENTRY_UINT32(eperiod);
-       DECL_STATE_ENTRY_UINT32(ncount);
-       DECL_STATE_ENTRY_UINT32(nperiod);
-       DECL_STATE_ENTRY_UINT32(tperiodbase);
-       DECL_STATE_ENTRY_UINT32(eperiodbase);
-       DECL_STATE_ENTRY_UINT32(nperiodbase);
-       DECL_STATE_ENTRY_INT32(mask);
-}
-
-void PSG::SaveState(void *f)
-{
-       FILEIO *state_fio = (FILEIO *)f;
-       
-       tmp_envelop_l = (int)(envelop_l - &enveloptable_l[0][0]);
-
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32_BE(PSG_STATE_VERSION);
-       
-//     state_fio->Fwrite(reg, sizeof(reg), 1);
-//     state_fio->FputInt32_BE((int)(envelop_l - &enveloptable_l[0][0]));
-       //state_fio->Fwrite(olevel_l, sizeof(olevel_l), 1);
-       //state_fio->Fwrite(olevel_r, sizeof(olevel_r), 1);
-       //state_fio->Fwrite(scount, sizeof(scount), 1);
-       //state_fio->Fwrite(speriod, sizeof(speriod), 1);
-//     for(int i = 0; i < 3; i++) {
-//             state_fio->FputUint32_BE(olevel_l[i]);
-//             state_fio->FputUint32_BE(olevel_r[i]);
-//             state_fio->FputUint32_BE(scount[i]);
-//             state_fio->FputUint32_BE(speriod[i]);
-//     }
-//     state_fio->FputUint32_BE(ecount);
-//     state_fio->FputUint32_BE(eperiod);
-//     state_fio->FputUint32_BE(ncount);
-//     state_fio->FputUint32_BE(nperiod);
-//     state_fio->FputUint32_BE(tperiodbase);
-//     state_fio->FputUint32_BE(eperiodbase);
-//     state_fio->FputUint32_BE(nperiodbase);
-//     state_fio->FputInt32_BE(mask);
-}
+#define PSG_STATE_VERSION      2
 
-bool PSG::LoadState(void *f)
+bool PSG::ProcessState(void *f, bool loading)
 {
-       FILEIO *state_fio = (FILEIO *)f;
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
+       FILEIO *state_fio = (FILEIO *)f;
+       
+       if(!state_fio->StateCheckUint32(PSG_STATE_VERSION)) {
+               return false;
+       }
+       state_fio->StateBuffer(reg, sizeof(reg), 1);
+       if(loading) {
+               int offset = state_fio->FgetInt32_LE();
+               envelop_l = &enveloptable_l[0][0] + offset;
+       } else {
+               state_fio->FputInt32_LE((int)(envelop_l - &enveloptable_l[0][0]));
        }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32_BE() != PSG_STATE_VERSION) {
-//             return false;
-//     }
-//     state_fio->Fread(reg, sizeof(reg), 1);
-//     int offset = state_fio->FgetInt32_BE();
-       int offset = tmp_envelop_l;
-       envelop_l = &enveloptable_l[0][0] + offset;
-       envelop_r = &enveloptable_r[0][0] + offset;
-       //state_fio->Fread(olevel_l, sizeof(olevel_l), 1);
-       //state_fio->Fread(olevel_r, sizeof(olevel_r), 1);
-       //state_fio->Fread(scount, sizeof(scount), 1);
-       //state_fio->Fread(speriod, sizeof(speriod), 1);
-//     for(int i = 0; i < 3; i++) {
-//             olevel_l[i] = state_fio->FgetUint32_BE();
-//             olevel_r[i] = state_fio->FgetUint32_BE();
-//             scount[i]   = state_fio->FgetUint32_BE();
-//             speriod[i]  = state_fio->FgetUint32_BE();
-//     }
-//     ecount = state_fio->FgetUint32_BE();
-//     eperiod = state_fio->FgetUint32_BE();
-//     ncount = state_fio->FgetUint32_BE();
-//     nperiod = state_fio->FgetUint32_BE();
-//     tperiodbase = state_fio->FgetUint32_BE();
-//     eperiodbase = state_fio->FgetUint32_BE();
-//     nperiodbase = state_fio->FgetUint32_BE();
-//     mask = state_fio->FgetInt32_BE();
-       return true;
+       state_fio->StateBuffer(olevel_l, sizeof(olevel_l), 1);
+       state_fio->StateBuffer(olevel_r, sizeof(olevel_r), 1);
+       state_fio->StateBuffer(scount, sizeof(scount), 1);
+       state_fio->StateBuffer(speriod, sizeof(speriod), 1);
+       state_fio->StateUint32(ecount);
+       state_fio->StateUint32(eperiod);
+       state_fio->StateUint32(ncount);
+       state_fio->StateUint32(nperiod);
+       state_fio->StateUint32(tperiodbase);
+       state_fio->StateUint32(eperiodbase);
+       state_fio->StateUint32(nperiodbase);
+       state_fio->StateInt32(mask);
+       return true;
 }
index 250d63e..f08ace6 100644 (file)
@@ -77,9 +77,8 @@ public:
        void SetReg(uint regnum, uint8 data);
        uint GetReg(uint regnum) { return reg[regnum & 0x0f]; }
 
-       void DeclState(void *f);
-       void SaveState(void *f);
-       bool LoadState(void *f);
+       bool ProcessState(void *f, bool loading);
+
        
 protected:
        void MakeNoiseTable();
index 7ee160c..648dd63 100644 (file)
@@ -3,6 +3,6 @@ common source code project
 - fmtimer\93à\82Å\81ATimer A\82Ì\92l\82ª\95\89\82É\82È\82ç\82È\82¢\82æ\82¤\82É\83V\83t\83g\97Ê\82ð\92²\90®
 - ReadIRQ()\82ð\92Ç\89Á
 - \83\8a\83Y\83\80\89¹\8c¹\82Ì\83t\83@\83C\83\8b\83p\83X\82Ì\8c^\82ð*_TCHAR\82É\95Ï\8dX
-- \8ae\83N\83\89\83X\82ÉSaveState(),LoadState()\82ð\92Ç\89Á
+- \8ae\83N\83\89\83X\82ÉProcessState()\82ð\92Ç\89Á
 - FileIO\83N\83\89\83X\82Ì\91Ö\82è\82É\81AFILEIO\83N\83\89\83X\82ð\8eg\97p\82·\82é\82æ\82¤\82É\95Ï\8dX
 - \8ae\83{\83\8a\83\85\81[\83\80\82ð\8d\89E\95Ê\82É\90Ý\92è\82Å\82«\82é\82æ\82¤\82É\95Ï\8dX
index 75f827e..c35606c 100644 (file)
@@ -178,80 +178,3 @@ bool HARDDISK::write_buffer(long position, int length, uint8_t *buffer)
        return false;
 }
 
-/*
-#define STATE_VERSION  1
-
-void HARDDISK::save_state(FILEIO* state_fio)
-{
-       state_fio->FputUint32(STATE_VERSION);
-       
-       state_fio->Fwrite(image_path, sizeof(image_path), 1);
-       if(mounted()) {
-               uint8_t *buffer = (uint8_t *)malloc(0x100000); // 1MB
-               long remain = fio->FileLength();
-               state_fio->FputInt32(remain);
-               fio->Fseek(0, FILEIO_SEEK_SET);
-               while(remain > 0) {
-                       long size = min(remain, 0x100000);
-                       fio->Fread(buffer, size, 1);
-                       state_fio->Fwrite(buffer, size, 1);
-                       remain -= size;
-               }
-               free(buffer);
-       } else {
-               state_fio->FputInt32(0);
-       }
-       state_fio->FputInt32(header_size);
-//     state_fio->FputInt32(cylinders);
-       state_fio->FputInt32(surfaces);
-//     state_fio->FputInt32(sectors);
-       state_fio->FputInt32(sector_size);
-       state_fio->FputInt32(sector_num);
-}
-
-bool HARDDISK::load_state(FILEIO* state_fio)
-{
-       close();
-       
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       state_fio->Fread(image_path, sizeof(image_path), 1);
-       long remain = state_fio->FgetInt32();
-       if(remain > 0) {
-               fio = new FILEIO();
-               if(!fio->Fopen(image_path, FILEIO_READ_WRITE_NEW_BINARY)) {
-                       if(check_file_extension(image_path, _T(".thd"))) {
-                               create_local_path(image_path, _MAX_PATH, _T("temporary_saved_hard_disk_#%d.thd"), drive_num);
-                       } else if(check_file_extension(image_path, _T(".nhd"))) {
-                               create_local_path(image_path, _MAX_PATH, _T("temporary_saved_hard_disk_#%d.nhd"), drive_num);
-                       } else if(check_file_extension(image_path, _T(".hdi"))) {
-                               create_local_path(image_path, _MAX_PATH, _T("temporary_saved_hard_disk_#%d.hdi"), drive_num);
-                       } else {
-                               create_local_path(image_path, _MAX_PATH, _T("temporary_saved_hard_disk_#%d.dat"), drive_num);
-                       }
-                       fio->Fopen(image_path, FILEIO_READ_WRITE_NEW_BINARY);
-               }
-               if(fio->IsOpened()) {
-                       uint8_t *buffer = (uint8_t *)malloc(0x100000); // 1MB
-                       fio->Fseek(0, FILEIO_SEEK_SET);
-                       while(remain > 0) {
-                               long size = min(remain, 0x100000);
-                               state_fio->Fread(buffer, size, 1);
-                               fio->Fwrite(buffer, size, 1);
-                               remain -= size;
-                       }
-                       free(buffer);
-               } else {
-                       state_fio->Fseek(remain, FILEIO_SEEK_CUR);
-               }
-       }
-       header_size = state_fio->FgetInt32();
-//     cylinders = state_fio->FgetInt32();
-       surfaces = state_fio->FgetInt32();
-//     sectors = state_fio->FgetInt32();
-       sector_size = state_fio->FgetInt32();
-       sector_num = state_fio->FgetInt32();
-       return true;
-}
-*/
index 7f89b1d..8b40dab 100644 (file)
@@ -54,10 +54,6 @@ public:
        int drive_num;
        bool access;
        
-       // state
-//     void save_state(FILEIO* state_fio);
-//     bool load_state(FILEIO* state_fio);
-       
        // device name
        void set_device_name(const _TCHAR* format, ...)
        {
index 7972d02..b3ad522 100644 (file)
 #define CPU_INIT(name)                         void* CPU_INIT_NAME(name)()
 #define CPU_INIT_CALL(name)                    CPU_INIT_NAME(name)()
 
+#define CPU_TABLE_NAME(name)                   cpu_table_##name
+#define CPU_TABLE(name)                                void CPU_TABLE_NAME(name)(i386_state *cpustate)
+#define CPU_TABLE_CALL(name)                   CPU_TABLE_NAME(name)(cpustate)
+
 #define CPU_RESET_NAME(name)                   cpu_reset_##name
 #define CPU_RESET(name)                                void CPU_RESET_NAME(name)(i386_state *cpustate)
 #define CPU_RESET_CALL(name)                   CPU_RESET_NAME(name)(cpustate)
@@ -537,43 +541,83 @@ int I386::get_shutdown_flag()
        return cpustate->shutdown;
 }
 
-#define STATE_VERSION  2
-
-void I386::save_state(FILEIO* state_fio)
-{
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->Fwrite(opaque, sizeof(i386_state), 1);
-}
+#define STATE_VERSION  3
 
-bool I386::load_state(FILEIO* state_fio)
+bool I386::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       i386_state *cpustate = (i386_state *)opaque;
+       vtlb_state *vtlb = cpustate->vtlb;
+       void *cpudevice = NULL;
+       offs_t *live = NULL;
+       int live_size = 0;
+       int *fixedpages = NULL;
+       int fixedpages_size = 0;
+       vtlb_entry *table = NULL;
+       int table_size = 0;
+//     vtlb_entry *save = NULL;
+//     int save_size = 0;
+       if(vtlb != NULL) {
+               cpudevice = vtlb->cpudevice;
+               live = vtlb->live;
+               live_size = vtlb->live_size;
+               fixedpages = vtlb->fixedpages;
+               fixedpages_size = vtlb->fixedpages_size;
+               table = vtlb->table;
+               table_size = vtlb->table_size;
+//             save = vtlb->save;
+//             save_size = vtlb->save_size;
+       }
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!state_fio->StateCheckInt32(this_device_id)) {
                return false;
        }
-       state_fio->Fread(opaque, sizeof(i386_state), 1);
+       state_fio->StateBuffer(opaque, sizeof(i386_state), 1);
+       if(vtlb != NULL) {
+               state_fio->StateBuffer(vtlb, sizeof(vtlb_state), 1);
+       }
+       if(live != NULL && live_size > 0) {
+               state_fio->StateBuffer(live, live_size, 1);
+       }
+       if(fixedpages != NULL && fixedpages_size > 0) {
+               state_fio->StateBuffer(fixedpages, fixedpages_size, 1);
+       }
+       if(table != NULL && table_size > 0) {
+               state_fio->StateBuffer(table, table_size, 1);
+       }
+//     if(save != NULL && save_size > 0) {
+//             state_fio->StateBuffer(save, save_size, 1);
+//     }
        
        // post process
-       i386_state *cpustate = (i386_state *)opaque;
-       cpustate->pic = d_pic;
-       cpustate->program = d_mem;
-       cpustate->io = d_io;
+       if(loading) {
+               cpustate->vtlb = vtlb;
+               if(vtlb != NULL) {
+                       vtlb->cpudevice = cpudevice;
+                       vtlb->live = live;
+                       vtlb->fixedpages = fixedpages;
+                       vtlb->table = table;
+//                     vtlb->save = save;
+               }
+               cpustate->pic = d_pic;
+               cpustate->program = d_mem;
+               cpustate->io = d_io;
 #ifdef I86_PSEUDO_BIOS
-       cpustate->bios = d_bios;
+               cpustate->bios = d_bios;
 #endif
 #ifdef SINGLE_MODE_DMA
-       cpustate->dma = d_dma;
+               cpustate->dma = d_dma;
 #endif
 #ifdef USE_DEBUGGER
-       cpustate->emu = emu;
-       cpustate->debugger = d_debugger;
-       cpustate->program_stored = d_mem;
-       cpustate->io_stored = d_io;
+               cpustate->emu = emu;
+               cpustate->debugger = d_debugger;
+               cpustate->program_stored = d_mem;
+               cpustate->io_stored = d_io;
+               cpustate->prev_total_cycles = cpustate->total_cycles;
 #endif
+               CPU_TABLE_CALL(CPU_MODEL);
+       }
        return true;
 }
 
index a443070..5cb1b50 100644 (file)
@@ -130,8 +130,7 @@ public:
        void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
        int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
 #endif
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique function
        void set_context_mem(DEVICE* device)
index 3a5ed95..04e34f2 100644 (file)
@@ -221,26 +221,6 @@ int DEVICE::get_lines_per_frame()
        return event_manager->get_lines_per_frame();
 }
 
-#include "../../statesub.h"
-
-void DEVICE::decl_state()
-{
-       state_entry = new csp_state_utils(1, this_device_id, (const _TCHAR *)this_device_name, p_logger);
-}
-
-void DEVICE::enter_decl_state(int version)
-{
-       state_entry = new csp_state_utils(version, this_device_id, (const _TCHAR *)this_device_name, p_logger);
-}
-
-void DEVICE::enter_decl_state(int version, _TCHAR *name)
-{
-       state_entry = new csp_state_utils(version, this_device_id, (const _TCHAR *)name, p_logger);
-}
-
-void DEVICE::leave_decl_state()
-{
-}
 // Force render sound immediately when device's status has changed.
 // You must call this after you changing registers (or anything).
 // If has problems, try set_realtime_render.
index a0c4e88..3a659b2 100644 (file)
@@ -49,7 +49,6 @@
 #include "vm_template.h"
 
 class CSP_Logger;
-class csp_state_utils;
 class VM_TEMPLATE;
 class EMU;
 class OSD;
@@ -59,7 +58,6 @@ protected:
        VM_TEMPLATE* vm;
        EMU* emu;
        OSD* osd;
-       csp_state_utils *state_entry;
        CSP_Logger *p_logger;
 public:
        DEVICE(VM_TEMPLATE* parent_vm, EMU* parent_emu);
@@ -75,17 +73,21 @@ public:
                return true;
        }
        
-       virtual void decl_state(void);
-       virtual void enter_decl_state(int version);
-       virtual void enter_decl_state(int version,  _TCHAR *name); 
-       virtual void leave_decl_state(void);
-       
        // control
        virtual void reset() {}
        virtual void special_reset()
        {
                reset();
        }
+       virtual bool process_state(FILEIO* state_fio, bool loading)
+       {
+               if(loading) {
+                       return load_state(state_fio);
+               } else {
+                       save_state(state_fio);
+                       return true;
+               }
+       }
        
        // NOTE: the virtual bus interface functions for 16/32bit access invite the cpu is little endian.
        // if the cpu is big endian, you need to implement them in the virtual machine memory/io classes.
index 6a46095..7c6f7a9 100644 (file)
@@ -91,7 +91,6 @@ public:
        ~SASI_HDD() {}
        
        // virtual scsi functions
-       int get_command_length(int value);
        void start_command();
 };