OSDN Git Service

[VM][PCENGINE][X1] Enable to build.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 14 Oct 2018 10:27:59 +0000 (19:27 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 14 Oct 2018 10:27:59 +0000 (19:27 +0900)
24 files changed:
source/src/vm/pcengine/pce.cpp
source/src/vm/pcengine/pce.h
source/src/vm/pcengine/pcengine.cpp
source/src/vm/pcengine/pcengine.h
source/src/vm/x1/display.cpp
source/src/vm/x1/display.h
source/src/vm/x1/emm.cpp
source/src/vm/x1/emm.h
source/src/vm/x1/floppy.cpp
source/src/vm/x1/floppy.h
source/src/vm/x1/iobus.cpp
source/src/vm/x1/iobus.h
source/src/vm/x1/keyboard.cpp
source/src/vm/x1/keyboard.h
source/src/vm/x1/memory.cpp
source/src/vm/x1/memory.h
source/src/vm/x1/psub.cpp
source/src/vm/x1/psub.h
source/src/vm/x1/sasi.cpp
source/src/vm/x1/sasi.h
source/src/vm/x1/sub.cpp
source/src/vm/x1/sub.h
source/src/vm/x1/x1.cpp
source/src/vm/x1/x1.h

index 283f4e4..46b18fe 100644 (file)
@@ -2449,253 +2449,164 @@ void PCE::event_callback(int event_id, int err)
 
 #define STATE_VERSION  5
 
-#include "../../statesub.h"
-
-void PCE::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-
-       DECL_STATE_ENTRY_BOOL(support_6btn_pad);
-       DECL_STATE_ENTRY_BOOL(support_multi_tap);
+bool PCE::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(support_6btn_pad);
+       state_fio->StateBool(support_multi_tap);
 #ifdef SUPPORT_SUPER_GFX
-       DECL_STATE_ENTRY_BOOL(support_sgfx);
+       state_fio->StateBool(support_sgfx);
 #endif
 #ifdef SUPPORT_CDROM
-       DECL_STATE_ENTRY_BOOL(support_cdrom);
+       state_fio->StateBool(support_cdrom);
 #endif
-       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
-//     DECL_STATE_ENTRY_1D_ARRAY(cart + 0x80000, 0x80000);
-       DECL_STATE_ENTRY_1D_ARRAY(cart, sizeof(cart));  // Does correct this?
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateBuffer(cart + 0x80000, 0x80000, 1);
 #ifdef SUPPORT_BACKUP_RAM
-       DECL_STATE_ENTRY_1D_ARRAY(backup, sizeof(backup));
-       DECL_STATE_ENTRY_UINT32(backup_crc32);
+       state_fio->StateBuffer(backup, sizeof(backup), 1);
+       state_fio->StateUint32(backup_crc32);
 #endif
-       DECL_STATE_ENTRY_UINT32(bank);
-       DECL_STATE_ENTRY_UINT8(buffer);
-       DECL_STATE_ENTRY_INT32(prev_width);
-       DECL_STATE_ENTRY_BOOL(inserted);
+       state_fio->StateUint32(bank);
+       state_fio->StateUint8(buffer);
+       state_fio->StateInt32(prev_width);
+       state_fio->StateBool(inserted);
+
+       //state_fio->StateBuffer(vdc, sizeof(vdc), 1);
+       //state_fio->StateBuffer(&vce, sizeof(vce), 1);
+       //state_fio->StateBuffer(&vpc, sizeof(vpc), 1);
+       //state_fio->StateBuffer(psg, sizeof(psg), 1);
        // vdc
        for(int i = 0; i < 2; i++) {
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].dvssr_write), i);         /* Set when the DVSSR register has been written to */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].physical_width), i);              /* Width of the display */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].physical_height), i);             /* Height of the display */
-               DECL_STATE_ENTRY_1D_ARRAY_MEMBER((vdc[i].sprite_ram), 64*4, i); /* Sprite RAM */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].curline), i);                             /* the current scanline we're on */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].current_segment), i);             /* current segment of display */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].current_segment_line), i);        /* current line inside a segment of display */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].vblank_triggered), i);            /* to indicate whether vblank has been triggered */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].raster_count), i);                /* counter to compare RCR against */
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].satb_countdown), i);              /* scanlines to wait to trigger the SATB irq */
-               DECL_STATE_ENTRY_1D_ARRAY_MEMBER((vdc[i].vram), 0x10000, i);
-               DECL_STATE_ENTRY_UINT8_MEMBER((vdc[i].inc), i);
-               DECL_STATE_ENTRY_UINT8_MEMBER((vdc[i].vdc_register), i);
-               DECL_STATE_ENTRY_UINT8_MEMBER((vdc[i].vdc_latch), i);
-               DECL_STATE_ENTRY_PAIR_ARRAY((vdc[i].vdc_data), 32);
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].status), i);
-               DECL_STATE_ENTRY_INT32_MEMBER((vdc[i].y_scroll), i);
+               state_fio->StateInt32(vdc[i].dvssr_write);              /* Set when the DVSSR register has been written to */
+               state_fio->StateInt32(vdc[i].physical_width);           /* Width of the display */
+               state_fio->StateInt32(vdc[i].physical_height);          /* Height of the display */
+               for(int j = 0; j < (64 * 4); j++) {
+                       state_fio->StateUint16(vdc[i].sprite_ram[j]);   /* Sprite RAM */
+               }
+               state_fio->StateInt32(vdc[i].curline);                          /* the current scanline we're on */
+               state_fio->StateInt32(vdc[i].current_segment);          /* current segment of display */
+               state_fio->StateInt32(vdc[i].current_segment_line);     /* current line inside a segment of display */
+               state_fio->StateInt32(vdc[i].vblank_triggered);         /* to indicate whether vblank has been triggered */
+               state_fio->StateInt32(vdc[i].raster_count);             /* counter to compare RCR against */
+               state_fio->StateInt32(vdc[i].satb_countdown);           /* scanlines to wait to trigger the SATB irq */
+               state_fio->StateBuffer((vdc[i].vram), 0x10000, 1);
+               state_fio->StateUint8(vdc[i].inc);
+               state_fio->StateUint8(vdc[i].vdc_register);
+               state_fio->StateUint8(vdc[i].vdc_latch);
+               for(int j = 0; j < 32; j++) {
+                       state_fio->StateUint32(vdc[i].vdc_data[j].d);
+               }
+               state_fio->StateInt32(vdc[i].status);
+               state_fio->StateInt32(vdc[i].y_scroll);
        }
        // vce
        {
-               DECL_STATE_ENTRY_UINT8((vce.vce_control));              /* VCE control register */
-               DECL_STATE_ENTRY_PAIR((vce.vce_address));               /* Current address in the palette */
-               DECL_STATE_ENTRY_PAIR_ARRAY((vce.vce_data), 512);               /* Palette data */
-               DECL_STATE_ENTRY_INT32((vce.current_bitmap_line));      /* The current line in the display we are on */
+               state_fio->StateUint8(vce.vce_control);         /* VCE control register */
+               state_fio->StateUint32(vce.vce_address.d);              /* Current address in the palette */
+               for(int i = 0; i < 512; i++) {
+                       state_fio->StateUint32(vce.vce_data[i].d);              /* Palette data */
+               }
+               state_fio->StateInt32(vce.current_bitmap_line); /* The current line in the display we are on */
                //bitmap_ind16 *bmp;
-               DECL_STATE_ENTRY_SCRNTYPE_T_2D_ARRAY((vce.bmp), VDC_LPF, VDC_WPF);
-               DECL_STATE_ENTRY_SCRNTYPE_T_1D_ARRAY((vce.palette), 1024);
+               for(int i = 0; i < VDC_LPF; i++) {
+                       for(int j = 0; j < VDC_WPF; j++) {
+                               if(loading) {
+                                       uint8_t r, g, b;
+                                       r = state_fio->FgetUint8();
+                                       g = state_fio->FgetUint8();
+                                       b = state_fio->FgetUint8();
+                                       vce.bmp[i][j] = RGB_COLOR(r, g, b);
+                               } else {
+                                       uint8_t r, g, b;
+                                       r = R_OF_COLOR(vce.bmp[i][j]);
+                                       g = G_OF_COLOR(vce.bmp[i][j]);
+                                       b = B_OF_COLOR(vce.bmp[i][j]);
+                                       state_fio->FputUint8(r);
+                                       state_fio->FputUint8(g);
+                                       state_fio->FputUint8(b);
+                               }
+                       }
+               }
+               for(int i = 0; i < 1024; i++) {
+                       if(loading) {
+                               uint8_t r, g, b;
+                               r = state_fio->FgetUint8();
+                               g = state_fio->FgetUint8();
+                               b = state_fio->FgetUint8();
+                               vce.palette[i] = RGB_COLOR(r, g, b);
+                       } else {
+                               uint8_t r, g, b;
+                               r = R_OF_COLOR(vce.palette[i]);
+                               g = G_OF_COLOR(vce.palette[i]);
+                               b = B_OF_COLOR(vce.palette[i]);
+                               state_fio->FputUint8(r);
+                               state_fio->FputUint8(g);
+                               state_fio->FputUint8(b);
+                       }
+               }
        }
        // vpc
        {
                for(int i = 0; i < 4; i++) {
-                       DECL_STATE_ENTRY_UINT8_MEMBER((vpc.vpc_prio[i].prio), i);
-                       DECL_STATE_ENTRY_UINT8_MEMBER((vpc.vpc_prio[i].vdc0_enabled), i);
-                       DECL_STATE_ENTRY_UINT8_MEMBER((vpc.vpc_prio[i].vdc1_enabled), i);
+                       state_fio->StateUint8(vpc.vpc_prio[i].prio);
+                       state_fio->StateUint8(vpc.vpc_prio[i].vdc0_enabled);
+                       state_fio->StateUint8(vpc.vpc_prio[i].vdc1_enabled);
                }
-               DECL_STATE_ENTRY_1D_ARRAY((vpc.prio_map), 512);
-               DECL_STATE_ENTRY_PAIR((vpc.priority));
-               DECL_STATE_ENTRY_PAIR((vpc.window1));
-               DECL_STATE_ENTRY_PAIR((vpc.window2));
-               DECL_STATE_ENTRY_UINT8((vpc.vdc_select));
+               state_fio->StateBuffer(vpc.prio_map, 512, 1);
+               state_fio->StateUint32(vpc.priority.d);
+               state_fio->StateUint32(vpc.window1.d);
+               state_fio->StateUint32(vpc.window2.d);
+               state_fio->StateUint8(vpc.vdc_select);
        }
        // psg
        {
                for(int i = 0; i < 8; i++ ){
-                       DECL_STATE_ENTRY_1D_ARRAY_MEMBER((psg[i].regs), 8, i);
-                       DECL_STATE_ENTRY_1D_ARRAY_MEMBER((psg[i].wav), 32, i);
-                       DECL_STATE_ENTRY_UINT8_MEMBER((psg[i].wavptr), i);
-                       DECL_STATE_ENTRY_UINT32_MEMBER((psg[i].genptr), i);
-                       DECL_STATE_ENTRY_UINT32_MEMBER((psg[i].remain), i);
-                       DECL_STATE_ENTRY_BOOL_MEMBER((psg[i].noise), i);
-                       DECL_STATE_ENTRY_UINT32_MEMBER((psg[i].randval), i);
-               }
-       }
-       DECL_STATE_ENTRY_UINT8(psg_ch);
-       DECL_STATE_ENTRY_UINT8(psg_vol);
-       DECL_STATE_ENTRY_UINT8(psg_lfo_freq);
-       DECL_STATE_ENTRY_UINT8(psg_lfo_ctrl);
-       DECL_STATE_ENTRY_UINT8(joy_counter);
-       DECL_STATE_ENTRY_BOOL(joy_high_nibble);
-       DECL_STATE_ENTRY_BOOL(joy_second_byte);
+                   state_fio->StateBuffer(psg[i].regs, 8, 1);
+                       state_fio->StateBuffer(psg[i].wav, 32, 1);
+                       state_fio->StateUint8(psg[i].wavptr);
+                       state_fio->StateUint32(psg[i].genptr);
+                       state_fio->StateUint32(psg[i].remain);
+                       state_fio->StateBool(psg[i].noise);
+                       state_fio->StateUint32(psg[i].randval);
+               }
+       }
+
+       state_fio->StateUint8(psg_ch);
+       state_fio->StateUint8(psg_vol);
+       state_fio->StateUint8(psg_lfo_freq);
+       state_fio->StateUint8(psg_lfo_ctrl);
+       state_fio->StateUint8(joy_counter);
+       state_fio->StateBool(joy_high_nibble);
+       state_fio->StateBool(joy_second_byte);
 #ifdef SUPPORT_CDROM
-       DECL_STATE_ENTRY_1D_ARRAY(cdrom_ram, sizeof(cdrom_ram));
-       DECL_STATE_ENTRY_1D_ARRAY(cdrom_regs, sizeof(cdrom_regs));
-       DECL_STATE_ENTRY_BOOL(backup_locked);
-       DECL_STATE_ENTRY_BOOL(irq_status);
-       DECL_STATE_ENTRY_BOOL(drq_status);
-       DECL_STATE_ENTRY_1D_ARRAY(adpcm_ram, sizeof(adpcm_ram));
-       DECL_STATE_ENTRY_INT32(adpcm_read_ptr);
-       DECL_STATE_ENTRY_INT32(adpcm_write_ptr);
-       DECL_STATE_ENTRY_INT32(adpcm_written);
-       DECL_STATE_ENTRY_INT32(adpcm_length);
-       DECL_STATE_ENTRY_INT32(adpcm_clock_divider);
-       DECL_STATE_ENTRY_UINT8(adpcm_read_buf);
-       DECL_STATE_ENTRY_UINT8(adpcm_write_buf);
-       DECL_STATE_ENTRY_BOOL(adpcm_dma_enabled);
-       DECL_STATE_ENTRY_INT32(msm_start_addr);
-       DECL_STATE_ENTRY_INT32(msm_end_addr);
-       DECL_STATE_ENTRY_INT32(msm_half_addr);
-       DECL_STATE_ENTRY_UINT8(msm_nibble);
-       DECL_STATE_ENTRY_UINT8(msm_idle);
-       DECL_STATE_ENTRY_DOUBLE(cdda_volume);
-       DECL_STATE_ENTRY_DOUBLE(adpcm_volume);
-       DECL_STATE_ENTRY_INT32(event_cdda_fader);
-       DECL_STATE_ENTRY_INT32(event_adpcm_fader);
+       state_fio->StateBuffer(cdrom_ram, sizeof(cdrom_ram), 1);
+       state_fio->StateBuffer(cdrom_regs, sizeof(cdrom_regs), 1);
+       state_fio->StateBool(backup_locked);
+       state_fio->StateBool(irq_status);
+       state_fio->StateBool(drq_status);
+       state_fio->StateBuffer(adpcm_ram, sizeof(adpcm_ram), 1);
+       state_fio->StateInt32(adpcm_read_ptr);
+       state_fio->StateInt32(adpcm_write_ptr);
+       state_fio->StateInt32(adpcm_written);
+       state_fio->StateInt32(adpcm_length);
+       state_fio->StateInt32(adpcm_clock_divider);
+       state_fio->StateUint8(adpcm_read_buf);
+       state_fio->StateUint8(adpcm_write_buf);
+       state_fio->StateBool(adpcm_dma_enabled);
+       state_fio->StateInt32(msm_start_addr);
+       state_fio->StateInt32(msm_end_addr);
+       state_fio->StateInt32(msm_half_addr);
+       state_fio->StateUint8(msm_nibble);
+       state_fio->StateUint8(msm_idle);
+       state_fio->StateDouble(cdda_volume);
+       state_fio->StateDouble(adpcm_volume);
+       state_fio->StateInt32(event_cdda_fader);
+       state_fio->StateInt32(event_adpcm_fader);
 #endif
-       leave_decl_state();
+       return true;
 }
-void PCE::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->FputBool(support_6btn_pad);
-//     state_fio->FputBool(support_multi_tap);
-#ifdef SUPPORT_SUPER_GFX
-//     state_fio->FputBool(support_sgfx);
-#endif
-#ifdef SUPPORT_CDROM
-//     state_fio->FputBool(support_cdrom);
-#endif
-//     state_fio->Fwrite(ram, sizeof(ram), 1);
-//     state_fio->Fwrite(cart + 0x80000, 0x80000, 1);
-#ifdef SUPPORT_BACKUP_RAM
-//     state_fio->Fwrite(backup, sizeof(backup), 1);
-//     state_fio->FputUint32(backup_crc32);
-#endif
-//     state_fio->FputUint32(bank);
-//     state_fio->FputUint8(buffer);
-//     state_fio->FputInt32(prev_width);
-//     state_fio->FputBool(inserted);
-//     state_fio->Fwrite(vdc, sizeof(vdc), 1);
-//     state_fio->Fwrite(&vce, sizeof(vce), 1);
-//     state_fio->Fwrite(&vpc, sizeof(vpc), 1);
-//     state_fio->Fwrite(psg, sizeof(psg), 1);
-//     state_fio->FputUint8(psg_ch);
-//     state_fio->FputUint8(psg_vol);
-//     state_fio->FputUint8(psg_lfo_freq);
-//     state_fio->FputUint8(psg_lfo_ctrl);
-//     state_fio->FputUint8(joy_counter);
-//     state_fio->FputBool(joy_high_nibble);
-//     state_fio->FputBool(joy_second_byte);
-#ifdef SUPPORT_CDROM
-//     state_fio->Fwrite(cdrom_ram, sizeof(cdrom_ram), 1);
-//     state_fio->Fwrite(cdrom_regs, sizeof(cdrom_regs), 1);
-//     state_fio->FputBool(backup_locked);
-//     state_fio->FputBool(irq_status);
-//     state_fio->FputBool(drq_status);
-//     state_fio->Fwrite(adpcm_ram, sizeof(adpcm_ram), 1);
-//     state_fio->FputInt32(adpcm_read_ptr);
-//     state_fio->FputInt32(adpcm_write_ptr);
-//     state_fio->FputInt32(adpcm_written);
-//     state_fio->FputInt32(adpcm_length);
-//     state_fio->FputInt32(adpcm_clock_divider);
-//     state_fio->FputUint8(adpcm_read_buf);
-//     state_fio->FputUint8(adpcm_write_buf);
-//     state_fio->FputBool(adpcm_dma_enabled);
-//     state_fio->FputInt32(msm_start_addr);
-//     state_fio->FputInt32(msm_end_addr);
-//     state_fio->FputInt32(msm_half_addr);
-//     state_fio->FputUint8(msm_nibble);
-//     state_fio->FputUint8(msm_idle);
-//     state_fio->FputDouble(cdda_volume);
-//     state_fio->FputDouble(adpcm_volume);
-//     state_fio->FputInt32(event_cdda_fader);
-//     state_fio->FputInt32(event_adpcm_fader);
-#endif
-}
-
-bool PCE::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;
-//     }
-//     support_6btn_pad = state_fio->FgetBool();
-//     support_multi_tap = state_fio->FgetBool();
-#ifdef SUPPORT_SUPER_GFX
-//     support_sgfx = state_fio->FgetBool();
-#endif
-#ifdef SUPPORT_CDROM
-//     support_cdrom = state_fio->FgetBool();
-#endif
-//     state_fio->Fread(ram, sizeof(ram), 1);
-//     state_fio->Fread(cart + 0x80000, 0x80000, 1);
-#ifdef SUPPORT_BACKUP_RAM
-//     state_fio->Fread(backup, sizeof(backup), 1);
-//     backup_crc32 = state_fio->FgetUint32();
-#endif
-//     bank = state_fio->FgetUint32();
-//     buffer = state_fio->FgetUint8();
-//     prev_width = state_fio->FgetInt32();
-//     inserted = state_fio->FgetBool();
-//     state_fio->Fread(vdc, sizeof(vdc), 1);
-//     state_fio->Fread(&vce, sizeof(vce), 1);
-//     state_fio->Fread(&vpc, sizeof(vpc), 1);
-//     state_fio->Fread(psg, sizeof(psg), 1);
-//     psg_ch = state_fio->FgetUint8();
-//     psg_vol = state_fio->FgetUint8();
-//     psg_lfo_freq = state_fio->FgetUint8();
-//     psg_lfo_ctrl = state_fio->FgetUint8();
-//     joy_counter = state_fio->FgetUint8();
-//     joy_high_nibble = state_fio->FgetBool();
-//     joy_second_byte = state_fio->FgetBool();
-#ifdef SUPPORT_CDROM
-//     state_fio->Fread(cdrom_ram, sizeof(cdrom_ram), 1);
-//     state_fio->Fread(cdrom_regs, sizeof(cdrom_regs), 1);
-//     backup_locked = state_fio->FgetBool();
-//     irq_status = state_fio->FgetBool();
-//     drq_status = state_fio->FgetBool();
-//     state_fio->Fread(adpcm_ram, sizeof(adpcm_ram), 1);
-//     adpcm_read_ptr = state_fio->FgetInt32();
-//     adpcm_write_ptr = state_fio->FgetInt32();
-//     adpcm_written = state_fio->FgetInt32();
-//     adpcm_length = state_fio->FgetInt32();
-//     adpcm_clock_divider = state_fio->FgetInt32();
-//     adpcm_read_buf = state_fio->FgetUint8();
-//     adpcm_write_buf = state_fio->FgetUint8();
-//     adpcm_dma_enabled = state_fio->FgetBool();
-//     msm_start_addr = state_fio->FgetInt32();
-//     msm_end_addr = state_fio->FgetInt32();
-//     msm_half_addr = state_fio->FgetInt32();
-//     msm_nibble = state_fio->FgetUint8();
-//     msm_idle = state_fio->FgetUint8();
-//     cdda_volume = state_fio->FgetDouble();
-//     adpcm_volume = state_fio->FgetDouble();
-//     event_cdda_fader = state_fio->FgetInt32();
-//     event_adpcm_fader = state_fio->FgetInt32();
-#endif
-       return true;
-}
-
index 77c108e..e071010 100644 (file)
@@ -244,9 +244,7 @@ public:
 #endif
        void mix(int32_t* buffer, int cnt);
        void set_volume(int ch, int decibel_l, int decibel_r);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_cpu(HUC6280* device)
index c9d18eb..f821e4c 100644 (file)
@@ -88,7 +88,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->initialize();
        }
-       decl_state();
 }
 
 VM::~VM()
@@ -246,48 +245,36 @@ void VM::update_config()
 
 #define STATE_VERSION  2
 
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
-       state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::PC_ENGINE_HEAD")), csp_logger);
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->decl_state();
-       }
-}
-
-void VM::save_state(FILEIO* state_fio)
-{
-       //state_fio->FputUint32(STATE_VERSION);
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->save_state(state_fio);
-       }
-}
-
-bool VM::load_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       //if(state_fio->FgetUint32() != STATE_VERSION) {
-       //      return false;
-       //}
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
-       }
-       if(!mb) {
-               emu->out_debug_log("INFO: HEADER DATA ERROR");
-               return false;
-       }
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               if(!device->load_state(state_fio)) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+               // const char *name = typeid(*device).name();
+               //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+               const char *name = device->get_device_name();
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       if(loading) {
+                               printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
                        return false;
                }
-       }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       if(loading) {
+                               printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       if(loading) {
+                               printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+                       }
+                       return false;
+               }
+       }
        return true;
 }
-
index 5b0a7ea..8b11fd9 100644 (file)
@@ -139,9 +139,7 @@ public:
                return false;
        }
        void update_config();
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device
index dfcbc51..f50f3a8 100644 (file)
@@ -1513,224 +1513,131 @@ uint16_t DISPLAY::jis2sjis(uint16_t jis)
 
 #define STATE_VERSION  4
 
-#include "../statesub.h"
-
-void DISPLAY::decl_state()
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_1D_ARRAY(vram_t, sizeof(vram_t));
-       DECL_STATE_ENTRY_1D_ARRAY(vram_a, sizeof(vram_a));
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(vram_t, sizeof(vram_t), 1);
+       state_fio->StateBuffer(vram_a, sizeof(vram_a), 1);
 #ifdef _X1TURBO_FEATURE
-       DECL_STATE_ENTRY_1D_ARRAY(vram_k, sizeof(vram_k));
+       state_fio->StateBuffer(vram_k, sizeof(vram_k), 1);
 #endif
-       DECL_STATE_ENTRY_2D_ARRAY(pcg_b, 256, 8);
-       DECL_STATE_ENTRY_2D_ARRAY(pcg_r, 256, 8);
-       DECL_STATE_ENTRY_2D_ARRAY(pcg_g, 256, 8);
+       state_fio->StateBuffer(pcg_b, sizeof(pcg_b), 1);
+       state_fio->StateBuffer(pcg_r, sizeof(pcg_r), 1);
+       state_fio->StateBuffer(pcg_g, sizeof(pcg_g), 1);
 #ifdef _X1TURBO_FEATURE
-       DECL_STATE_ENTRY_2D_ARRAY(gaiji_b, 128, 16);
-       DECL_STATE_ENTRY_2D_ARRAY(gaiji_r, 128, 16);
-       DECL_STATE_ENTRY_2D_ARRAY(gaiji_g, 128, 16);
-#endif
-       DECL_STATE_ENTRY_UINT8(cur_code);
-       DECL_STATE_ENTRY_UINT8(cur_line);
-       DECL_STATE_ENTRY_INT32(kaddr);
-       DECL_STATE_ENTRY_INT32(kofs);
-       DECL_STATE_ENTRY_INT32(kflag);
-       DECL_STATE_ENTRY_INT32(tmp_kanji_ptr); // (int)(kanji_ptr - &kanji[0]);
-       DECL_STATE_ENTRY_1D_ARRAY(pal, sizeof(pal));
-       DECL_STATE_ENTRY_UINT8(priority);
-       DECL_STATE_ENTRY_2D_ARRAY(pri, 8, 8);
-       DECL_STATE_ENTRY_BOOL(column40);
+       state_fio->StateBuffer(gaiji_b, sizeof(gaiji_b), 1);
+       state_fio->StateBuffer(gaiji_r, sizeof(gaiji_r), 1);
+       state_fio->StateBuffer(gaiji_g, sizeof(gaiji_g), 1);
+#endif
+       state_fio->StateUint8(cur_code);
+       state_fio->StateUint8(cur_line);
+       state_fio->StateInt32(kaddr);
+       state_fio->StateInt32(kofs);
+       state_fio->StateInt32(kflag);
+       if(loading) {
+               kanji_ptr = &kanji[0] + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(kanji_ptr - &kanji[0]));
+       }
+       state_fio->StateBuffer(pal, sizeof(pal), 1);
+       state_fio->StateUint8(priority);
+       state_fio->StateBuffer(pri, sizeof(pri), 1);
+       state_fio->StateBool(column40);
 #ifdef _X1TURBO_FEATURE
-       DECL_STATE_ENTRY_UINT8(mode1);
-       DECL_STATE_ENTRY_UINT8(mode2);
-       DECL_STATE_ENTRY_BOOL(hireso);
+       state_fio->StateUint8(mode1);
+       state_fio->StateUint8(mode2);
+       state_fio->StateBool(hireso);
 #endif
 #ifdef _X1TURBOZ
-       DECL_STATE_ENTRY_UINT8(zmode1);
-       DECL_STATE_ENTRY_UINT8(zpriority);
-       DECL_STATE_ENTRY_UINT8(zadjust);
-       DECL_STATE_ENTRY_UINT8(zmosaic);
-       DECL_STATE_ENTRY_UINT8(zchromakey);
-       DECL_STATE_ENTRY_UINT8(zscroll);
-       DECL_STATE_ENTRY_UINT8(zmode2);
-       DECL_STATE_ENTRY_1D_ARRAY(ztpal, sizeof(ztpal));
-
-       DECL_STATE_ENTRY_UINT8_STRIDE((zpal[0].b), sizeof(zpal) / sizeof(zpal[0]) ,sizeof(zpal[0]));
-       DECL_STATE_ENTRY_UINT8_STRIDE((zpal[0].r), sizeof(zpal) / sizeof(zpal[0]) ,sizeof(zpal[0]));
-       DECL_STATE_ENTRY_UINT8_STRIDE((zpal[0].g), sizeof(zpal) / sizeof(zpal[0]) ,sizeof(zpal[0]));
-       DECL_STATE_ENTRY_INT32(zpal_num);
-       
-       DECL_STATE_ENTRY_1D_ARRAY(zpalette_pc, sizeof(zpalette_pc) / sizeof(scrntype_t)); // ToDo: Generic value.
-#endif
-       DECL_STATE_ENTRY_BOOL(prev_vert_double);
-       DECL_STATE_ENTRY_INT32(raster);
-       DECL_STATE_ENTRY_INT32(cblink);
-       DECL_STATE_ENTRY_INT32(ch_height);
-       DECL_STATE_ENTRY_INT32(hz_total);
-       DECL_STATE_ENTRY_INT32(hz_disp);
-       DECL_STATE_ENTRY_INT32(vt_disp);
-       DECL_STATE_ENTRY_INT32(st_addr);
-       DECL_STATE_ENTRY_UINT32(vblank_clock);
-       DECL_STATE_ENTRY_BOOL(cur_blank);
-       
-       leave_decl_state();
-}
-void DISPLAY::save_state(FILEIO* state_fio)
-{
-       tmp_kanji_ptr = (int)(kanji_ptr - &kanji[0]);
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
+       state_fio->StateUint8(zmode1);
+       state_fio->StateUint8(zpriority);
+       state_fio->StateUint8(zadjust);
+       state_fio->StateUint8(zmosaic);
+       state_fio->StateUint8(zchromakey);
+       state_fio->StateUint8(zscroll);
+       state_fio->StateUint8(zmode2);
+       state_fio->StateBuffer(ztpal, sizeof(ztpal), 1);
+       //state_fio->StateBuffer(zpal, sizeof(zpal), 1);
+       for(int i = 0; i < 4096; i++) {
+               state_fio->StateUint8(zpal[i].b);
+               state_fio->StateUint8(zpal[i].r);
+               state_fio->StateUint8(zpal[i].g);
+       }                                                         
+       state_fio->StateInt32(zpal_num);
+       //state_fio->StateBuffer(zpalette_pc, sizeof(zpalette_pc), 1);
+       if(loading) {
+               for(int i = 0; i < (sizeof(zpalette_pc) / sizeof(scrntype_t)); i++) {
+                       uint8_t r, g, b;
+                       r = state_fio->FgetUint8();
+                       g = state_fio->FgetUint8();
+                       b = state_fio->FgetUint8();
+                       zpalette_pc[i] = RGB_COLOR(r, g, b);
+               }
+       } else {
+               for(int i = 0; i < (sizeof(zpalette_pc) / sizeof(scrntype_t)); i++) {
+                       uint8_t r, g, b;
+                       r = R_OF_COLOR(zpalette_pc[i]);
+                       g = G_OF_COLOR(zpalette_pc[i]);
+                       b = B_OF_COLOR(zpalette_pc[i]);
+                       state_fio->FputUint8(r);
+                       state_fio->FputUint8(g);
+                       state_fio->FputUint8(b);
+               }
        }
-//     state_fio->FputUint32(STATE_VERSION);
-//     state_fio->FputInt32(this_device_id);
-       
-//     state_fio->Fwrite(vram_t, sizeof(vram_t), 1);
-//     state_fio->Fwrite(vram_a, sizeof(vram_a), 1);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fwrite(vram_k, sizeof(vram_k), 1);
-//#endif
-//     state_fio->Fwrite(pcg_b, sizeof(pcg_b), 1);
-//     state_fio->Fwrite(pcg_r, sizeof(pcg_r), 1);
-//     state_fio->Fwrite(pcg_g, sizeof(pcg_g), 1);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fwrite(gaiji_b, sizeof(gaiji_b), 1);
-//     state_fio->Fwrite(gaiji_r, sizeof(gaiji_r), 1);
-//     state_fio->Fwrite(gaiji_g, sizeof(gaiji_g), 1);
-//#endif
-//     state_fio->FputUint8(cur_code);
-//     state_fio->FputUint8(cur_line);
-//     state_fio->FputInt32(kaddr);
-//     state_fio->FputInt32(kofs);
-//     state_fio->FputInt32(kflag);
-
-//     state_fio->FputInt32((int)(kanji_ptr - &kanji[0]));
-//     state_fio->Fwrite(pal, sizeof(pal), 1);
-//     state_fio->FputUint8(priority);
-//     state_fio->Fwrite(pri, sizeof(pri), 1);
-//     state_fio->FputBool(column40);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->FputUint8(mode1);
-//     state_fio->FputUint8(mode2);
-//     state_fio->FputBool(hireso);
-//#endif
-//#ifdef _X1TURBOZ
-//     state_fio->FputUint8(zmode1);
-//     state_fio->FputUint8(zpriority);
-//     state_fio->FputUint8(zadjust);
-//     state_fio->FputUint8(zmosaic);
-//     state_fio->FputUint8(zchromakey);
-//     state_fio->FputUint8(zscroll);
-//     state_fio->FputUint8(zmode2);
-//     state_fio->Fwrite(ztpal, sizeof(ztpal), 1);
-//     state_fio->Fwrite(zpal, sizeof(zpal), 1);
-//     state_fio->FputInt32(zpal_num);
-//     state_fio->Fwrite(zpalette_pc, sizeof(zpalette_pc), 1);
-//#endif
-//     state_fio->FputBool(prev_vert_double);
-//     state_fio->FputInt32(raster);
-//     state_fio->FputInt32(cblink);
-//     state_fio->FputInt32(ch_height);
-//     state_fio->FputInt32(hz_total);
-//     state_fio->FputInt32(hz_disp);
-//     state_fio->FputInt32(vt_disp);
-//     state_fio->FputInt32(st_addr);
-//     state_fio->FputUint32(vblank_clock);
-//     state_fio->FputBool(cur_blank);
-}
 
-bool DISPLAY::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;
-//     }
-//     state_fio->Fread(vram_t, sizeof(vram_t), 1);
-//     state_fio->Fread(vram_a, sizeof(vram_a), 1);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fread(vram_k, sizeof(vram_k), 1);
-//#endif
-//     state_fio->Fread(pcg_b, sizeof(pcg_b), 1);
-//     state_fio->Fread(pcg_r, sizeof(pcg_r), 1);
-//     state_fio->Fread(pcg_g, sizeof(pcg_g), 1);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fread(gaiji_b, sizeof(gaiji_b), 1);
-//     state_fio->Fread(gaiji_r, sizeof(gaiji_r), 1);
-//     state_fio->Fread(gaiji_g, sizeof(gaiji_g), 1);
-//#endif
-//     cur_code = state_fio->FgetUint8();
-//     cur_line = state_fio->FgetUint8();
-//     kaddr = state_fio->FgetInt32();
-//     kofs = state_fio->FgetInt32();
-//     kflag = state_fio->FgetInt32();
-//     kanji_ptr = &kanji[0] + state_fio->FgetInt32();
-//     state_fio->Fread(pal, sizeof(pal), 1);
-//     priority = state_fio->FgetUint8();
-//     state_fio->Fread(pri, sizeof(pri), 1);
-//     column40 = state_fio->FgetBool();
-//#ifdef _X1TURBO_FEATURE
-//     mode1 = state_fio->FgetUint8();
-//     mode2 = state_fio->FgetUint8();
-//     hireso = state_fio->FgetBool();
-//#endif
-//#ifdef _X1TURBOZ
-//     zmode1 = state_fio->FgetUint8();
-//     zpriority = state_fio->FgetUint8();
-//     zadjust = state_fio->FgetUint8();
-//     zmosaic = state_fio->FgetUint8();
-//     zchromakey = state_fio->FgetUint8();
-//     zscroll = state_fio->FgetUint8();
-//     zmode2 = state_fio->FgetUint8();
-//     state_fio->Fread(ztpal, sizeof(ztpal), 1);
-//     state_fio->Fread(zpal, sizeof(zpal), 1);
-//     zpal_num = state_fio->FgetInt32();
-//     state_fio->Fread(zpalette_pc, sizeof(zpalette_pc), 1);
-//#endif
-//     prev_vert_double = state_fio->FgetBool();
-//     raster = state_fio->FgetInt32();
-//     cblink = state_fio->FgetInt32();
-//     ch_height = state_fio->FgetInt32();
-//     hz_total = state_fio->FgetInt32();
-//     hz_disp = state_fio->FgetInt32();
-//     vt_disp = state_fio->FgetInt32();
-//     st_addr = state_fio->FgetInt32();
-//     vblank_clock = state_fio->FgetUint32();
-//     cur_blank = state_fio->FgetBool();
-       
-       kanji_ptr = &kanji[0] + tmp_kanji_ptr;
-       // post process
-       // Copy images to draw buffers.
-       my_memcpy(dr_text, text, sizeof(dr_text));
-       my_memcpy(dr_cg, cg, sizeof(dr_cg));
-       my_memcpy(dr_pri_line, pri_line, sizeof(dr_pri_line));
-       my_memcpy(dr_palette_pc, palette_pc, sizeof(dr_palette_pc));
-       dr_priority = priority;
+#endif
+       state_fio->StateBool(prev_vert_double);
+       state_fio->StateInt32(raster);
+       state_fio->StateInt32(cblink);
+       state_fio->StateInt32(ch_height);
+       state_fio->StateInt32(hz_total);
+       state_fio->StateInt32(hz_disp);
+       state_fio->StateInt32(vt_disp);
+       state_fio->StateInt32(st_addr);
+       state_fio->StateUint32(vblank_clock);
+       state_fio->StateBool(cur_blank);
+       
+       // post process
+       if(loading) {
+               for(int i = 0; i < 8; i++) {
+                       palette_pc[i    ] = RGB_COLOR((i & 2) ? 255 : 0, (i & 4) ? 255 : 0, (i & 1) ? 255 : 0); // text
+                       palette_pc[i + 8] = RGB_COLOR((i & 2) ? 255 : 0, (i & 4) ? 255 : 0, (i & 1) ? 255 : 0); // cg
+               }
+               // Copy images to draw buffers.
+               my_memcpy(dr_text, text, sizeof(dr_text));
+               my_memcpy(dr_cg, cg, sizeof(dr_cg));
+#ifdef _X1TURBO_FEATURE
+               for(int v = 0; v < 400; v++) {
+                       memcpy(&pri_line[v][0][0], &pri[0][0], sizeof(pri));
+               }
+#else
+               for(int v = 0; v < 200; v++) {
+                       memcpy(&pri_line[v][0][0], &pri[0][0], sizeof(pri));
+               }
+#endif
+               my_memcpy(dr_pri_line, pri_line, sizeof(dr_pri_line));
+               my_memcpy(dr_palette_pc, palette_pc, sizeof(dr_palette_pc));
+               dr_priority = priority;
 #ifdef _X1TURBOZ
-       dr_zpriority = zpriority;
-       my_memcpy(dr_zcg, zcg, sizeof(dr_zcg));
-       my_memcpy(dr_aen_line, aen_line, sizeof(dr_aen_line));
-       my_memcpy(dr_zpalette_pc, zpalette_pc, sizeof(zpalette_pc));
-       zpalette_pc[8 + 0] = zpalette_pc[16 + 0x000];
-       zpalette_pc[8 + 1] = zpalette_pc[16 + 0x00f];
-       zpalette_pc[8 + 2] = zpalette_pc[16 + 0x0f0];
-       zpalette_pc[8 + 3] = zpalette_pc[16 + 0x0ff];
-       zpalette_pc[8 + 4] = zpalette_pc[16 + 0xf00];
-       zpalette_pc[8 + 5] = zpalette_pc[16 + 0xf0f];
-       zpalette_pc[8 + 6] = zpalette_pc[16 + 0xff0];
-       zpalette_pc[8 + 7] = zpalette_pc[16 + 0xfff];
+               dr_zpriority = zpriority;
+               my_memcpy(dr_zcg, zcg, sizeof(dr_zcg));
+               my_memcpy(dr_aen_line, aen_line, sizeof(dr_aen_line));
+               my_memcpy(dr_zpalette_pc, zpalette_pc, sizeof(zpalette_pc));
+               zpalette_pc[8 + 0] = zpalette_pc[16 + 0x000];
+               zpalette_pc[8 + 1] = zpalette_pc[16 + 0x00f];
+               zpalette_pc[8 + 2] = zpalette_pc[16 + 0x0f0];
+               zpalette_pc[8 + 3] = zpalette_pc[16 + 0x0ff];
+               zpalette_pc[8 + 4] = zpalette_pc[16 + 0xf00];
+               zpalette_pc[8 + 5] = zpalette_pc[16 + 0xf0f];
+               zpalette_pc[8 + 6] = zpalette_pc[16 + 0xff0];
+               zpalette_pc[8 + 7] = zpalette_pc[16 + 0xfff];
 #endif 
-
-       update_crtc(); // force update timing
-       
-       return true;
+               update_crtc(); // force update timing
+       }
+       return true;
 }
-
index 0f27a8a..3e945f9 100644 (file)
@@ -165,9 +165,7 @@ public:
 #ifdef _X1TURBO_FEATURE
        void event_callback(int event_id, int err);
 #endif
-       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 _X1TURBO_FEATURE
index 0c38916..cb76413 100644 (file)
@@ -60,44 +60,15 @@ uint32_t EMM::read_io8(uint32_t addr)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void EMM::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_1D_ARRAY(data_buffer, sizeof(data_buffer));
-       DECL_STATE_ENTRY_UINT32(data_addr);
-
-       leave_decl_state();
-}
-
-void EMM::save_state(FILEIO* state_fio)
+bool EMM::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->Fwrite(data_buffer, sizeof(data_buffer), 1);
-//     state_fio->FputUint32(data_addr);
-}
-
-bool EMM::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;
-//     }
-//     state_fio->Fread(data_buffer, sizeof(data_buffer), 1);
-//     data_addr = state_fio->FgetUint32();
-       return true;
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(data_buffer, sizeof(data_buffer), 1);
+       state_fio->StateUint32(data_addr);
+       return true;
 }
index 46e3152..9307488 100644 (file)
@@ -37,9 +37,7 @@ public:
        void reset();
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
 };
 
 #endif
index 4c77b80..cddd6fa 100644 (file)
@@ -96,53 +96,16 @@ void FLOPPY::event_callback(int event_id, int err)
 
 #define STATE_VERSION  3
 
-#include "../statesub.h"
-
-void FLOPPY::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_INT32(prev);
-       DECL_STATE_ENTRY_BOOL(motor_on);
-       DECL_STATE_ENTRY_INT32(register_id);
-       leave_decl_state();
-}
-
-void FLOPPY::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->FputInt32(prev);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->FputBool(select_2dd);
-//#endif
-//     state_fio->FputBool(motor_on);
-//     state_fio->FputInt32(register_id);
-}
-
-bool FLOPPY::load_state(FILEIO* state_fio)
+bool FLOPPY::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;
-//     }
-//     prev = state_fio->FgetInt32();
-//#ifdef _X1TURBO_FEATURE
-//     select_2dd = state_fio->FgetBool();
-//#endif
-//     motor_on = state_fio->FgetBool();
-//     register_id = state_fio->FgetInt32();
-       return true;
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateInt32(prev);
+       state_fio->StateBool(motor_on);
+       state_fio->StateInt32(register_id);
+       return true;
 }
-
index b7f67cf..101ab03 100644 (file)
@@ -46,9 +46,7 @@ public:
        uint32_t read_io8(uint32_t addr);
 #endif
        void event_callback(int event_id, int err);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_fdc(MB8877* device)
index 7612657..4960d60 100644 (file)
@@ -235,103 +235,38 @@ int IOBUS::get_vram_wait()
 
 #define STATE_VERSION  3
 
-#include "../statesub.h"
-
-void IOBUS::decl_state()
+bool IOBUS::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-
-       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
-       DECL_STATE_ENTRY_BOOL(vram_mode);
-       DECL_STATE_ENTRY_BOOL(signal);
-       DECL_STATE_ENTRY_INT32(vramptr_b); //(int)(vram_b - vram);
-       DECL_STATE_ENTRY_INT32(vramptr_r); //(int)(vram_r - vram);
-       DECL_STATE_ENTRY_INT32(vramptr_g); //(int)(vram_g - vram);
-       DECL_STATE_ENTRY_UINT8(vdisp);
-       DECL_STATE_ENTRY_UINT32(prev_clock);
-       DECL_STATE_ENTRY_UINT32(vram_wait_index);
-       DECL_STATE_ENTRY_BOOL(column40);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateBool(vram_mode);
+       state_fio->StateBool(signal);
+       if(loading) {
+               vram_b = vram + state_fio->FgetInt32_LE();
+               vram_r = vram + state_fio->FgetInt32_LE();
+               vram_g = vram + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(vram_b - vram));
+               state_fio->FputInt32_LE((int)(vram_r - vram));
+               state_fio->FputInt32_LE((int)(vram_g - vram));
+       }
+       state_fio->StateUint8(vdisp);
+       state_fio->StateUint32(prev_clock);
+       state_fio->StateUint32(vram_wait_index);
+       state_fio->StateBool(column40);
 #ifdef _X1TURBO_FEATURE
-       DECL_STATE_ENTRY_1D_ARRAY(crtc_regs, sizeof(crtc_regs));
-       DECL_STATE_ENTRY_INT32(crtc_ch);
-       DECL_STATE_ENTRY_BOOL(hireso);
+       state_fio->StateBuffer(crtc_regs, sizeof(crtc_regs), 1);
+       state_fio->StateInt32(crtc_ch);
+       state_fio->StateBool(hireso);
 #ifdef _X1TURBOZ
-       DECL_STATE_ENTRY_UINT8(zmode1);
-       DECL_STATE_ENTRY_UINT8(zmode2);
+       state_fio->StateUint8(zmode1);
+       state_fio->StateUint8(zmode2);
 #endif
 #endif
-       leave_decl_state();
-}
-       
-void IOBUS::save_state(FILEIO* state_fio)
-{
-       vramptr_b = (int)(vram_b - vram);
-       vramptr_r = (int)(vram_r - vram);
-       vramptr_g = (int)(vram_g - vram);
-       
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32(STATE_VERSION);
-//     state_fio->FputInt32(this_device_id);
-       
-//     state_fio->Fwrite(vram, sizeof(vram), 1);
-//     state_fio->FputBool(vram_mode);
-//     state_fio->FputBool(signal);
-//     state_fio->FputInt32((int)(vram_b - vram));
-//     state_fio->FputInt32((int)(vram_r - vram));
-//     state_fio->FputInt32((int)(vram_g - vram));
-//     state_fio->FputUint8(vdisp);
-//     state_fio->FputUint32(prev_clock);
-//     state_fio->FputUint32(vram_wait_index);
-//     state_fio->FputBool(column40);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fwrite(crtc_regs, sizeof(crtc_regs), 1);
-//     state_fio->FputInt32(crtc_ch);
-//     state_fio->FputBool(hireso);
-//#ifdef _X1TURBOZ
-//     state_fio->FputUint8(zmode1);
-//     state_fio->FputUint8(zmode2);
-//#endif
-//#endif
+       return true;
 }
-
-bool IOBUS::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;
-//     }
-//     state_fio->Fread(vram, sizeof(vram), 1);
-//     vram_mode = state_fio->FgetBool();
-//     signal = state_fio->FgetBool();
-//     vram_b = vram + state_fio->FgetInt32();
-//     vram_r = vram + state_fio->FgetInt32();
-//     vram_g = vram + state_fio->FgetInt32();
-//     vdisp = state_fio->FgetUint8();
-//     prev_clock = state_fio->FgetUint32();
-//     vram_wait_index = state_fio->FgetUint32();
-//     column40 = state_fio->FgetBool();
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fread(crtc_regs, sizeof(crtc_regs), 1);
-//     crtc_ch = state_fio->FgetInt32();
-//     hireso = state_fio->FgetBool();
-//#ifdef _X1TURBOZ
-//     zmode1 = state_fio->FgetUint8();
-//     zmode2 = state_fio->FgetUint8();
-//#endif
-//#endif
-
-       vram_b = vram + vramptr_b;
-       vram_r = vram + vramptr_r;
-       vram_g = vram + vramptr_g;
-       return true;
-}
-
index 774d265..9716b6d 100644 (file)
@@ -71,9 +71,7 @@ public:
        uint32_t read_io8w(uint32_t addr, int* wait);
        void write_dma_io8w(uint32_t addr, uint32_t data, int* wait);
        uint32_t read_dma_io8w(uint32_t addr, int* wait);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_cpu(DEVICE* device)
index 562b781..7c4e037 100644 (file)
@@ -164,48 +164,17 @@ void KEYBOARD::key_down(int code, bool repeat)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void KEYBOARD::decl_state()
+bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_UINT8(caps_locked);
-       DECL_STATE_ENTRY_UINT8(kana_locked);
-       DECL_STATE_ENTRY_UINT16(column);
-       
-       leave_decl_state();
-}
-
-void KEYBOARD::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->FputUint8(caps_locked);
-//     state_fio->FputUint8(kana_locked);
-//     state_fio->FputUint16(column);
-}
-
-bool KEYBOARD::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;
-//     }
-//     caps_locked = state_fio->FgetUint8();
-//     kana_locked= state_fio->FgetUint8();
-//     column = state_fio->FgetUint16();
-       return true;
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(caps_locked);
+       state_fio->StateUint8(kana_locked);
+       state_fio->StateUint16(column);
+       return true;
 }
 
index 89e2665..17c532f 100644 (file)
@@ -36,9 +36,7 @@ public:
        void initialize();
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique functions
        void set_context_cpu(DEVICE *device)
index 754ce67..73e86c4 100644 (file)
@@ -162,65 +162,27 @@ void MEMORY::update_map()
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void MEMORY::decl_state()
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-
-       DECL_STATE_ENTRY_1D_ARRAY(ram, sizeof(ram));
-       DECL_STATE_ENTRY_UINT8(romsel);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(ram, sizeof(ram), 1);
+       state_fio->StateUint8(romsel);
 #ifdef _X1TURBO_FEATURE
-       DECL_STATE_ENTRY_1D_ARRAY(extram, sizeof(extram));
-       DECL_STATE_ENTRY_UINT8(bank);
+       state_fio->StateBuffer(extram, sizeof(extram), 1);
+       state_fio->StateUint8(bank);
 #else
-       DECL_STATE_ENTRY_INT32(m1_cycle);
+       state_fio->StateInt32(m1_cycle);
 #endif
-       leave_decl_state();
-}
-       
-void MEMORY::save_state(FILEIO* state_fio)
-{
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32(STATE_VERSION);
-//     state_fio->FputInt32(this_device_id);
-       
-//     state_fio->Fwrite(ram, sizeof(ram), 1);
-//     state_fio->FputUint8(romsel);
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fwrite(extram, sizeof(extram), 1);
-//     state_fio->FputUint8(bank);
-//#else
-//     state_fio->FputInt32(m1_cycle);
-//#endif
-}
-
-bool MEMORY::load_state(FILEIO* state_fio)
-{
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
+       
+       // post process
+       if(loading) {
+               update_map();
        }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32() != STATE_VERSION) {
-//             return false;
-//     }
-//     if(state_fio->FgetInt32() != this_device_id) {
-//             return false;
-//     }
-//     state_fio->Fread(ram, sizeof(ram), 1);
-//     romsel = state_fio->FgetUint8();
-//#ifdef _X1TURBO_FEATURE
-//     state_fio->Fread(extram, sizeof(extram), 1);
-//     bank = state_fio->FgetUint8();
-//#else
-//     m1_cycle = state_fio->FgetInt32();
-//#endif
-       
-       // post process
-       update_map();
-       return true;
+       return true;
 }
-
index 7bc03fa..767593e 100644 (file)
@@ -55,9 +55,7 @@ public:
 #endif
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // unique function
 #ifdef _X1TURBO_FEATURE
index 48258f8..1a56800 100644 (file)
@@ -827,125 +827,48 @@ uint16_t PSUB::get_key(int code, bool repeat)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void PSUB::decl_state()
-{
-       enter_decl_state(STATE_VERSION);
-
-       DECL_STATE_ENTRY_CUR_TIME_T(cur_time);
-       DECL_STATE_ENTRY_INT32(time_register_id);
-       DECL_STATE_ENTRY_2D_ARRAY(databuf, 32, 8);
-       DECL_STATE_ENTRY_INT32(tmp_datap); // (int)(datap - &databuf[0][0]);
-       DECL_STATE_ENTRY_UINT8(mode);
-       DECL_STATE_ENTRY_UINT8(inbuf);
-       DECL_STATE_ENTRY_UINT8(outbuf);
-       DECL_STATE_ENTRY_BOOL(ibf);
-       DECL_STATE_ENTRY_BOOL(obf);
-       DECL_STATE_ENTRY_INT32(cmdlen);
-       DECL_STATE_ENTRY_INT32(datalen);
-       DECL_STATE_ENTRY_FIFO(key_buf);
-       DECL_STATE_ENTRY_INT32(key_prev);
-       DECL_STATE_ENTRY_INT32(key_break);
-       DECL_STATE_ENTRY_BOOL(key_shift);
-       DECL_STATE_ENTRY_BOOL(key_ctrl);
-       DECL_STATE_ENTRY_BOOL(key_graph);
-       DECL_STATE_ENTRY_BOOL(key_caps_locked);
-       DECL_STATE_ENTRY_BOOL(key_kana_locked);
-       DECL_STATE_ENTRY_INT32(key_register_id);
-       DECL_STATE_ENTRY_BOOL(play);
-       DECL_STATE_ENTRY_BOOL(rec);
-       DECL_STATE_ENTRY_BOOL(eot);
-       DECL_STATE_ENTRY_BOOL(iei);
-       DECL_STATE_ENTRY_BOOL(intr);
-       DECL_STATE_ENTRY_UINT32(intr_bit);
-       
-       leave_decl_state();
-}
-
-void PSUB::save_state(FILEIO* state_fio)
+bool PSUB::process_state(FILEIO* state_fio, bool loading)
 {
-       tmp_datap = (int)(datap - &databuf[0][0]);
-       if(state_entry != NULL) {
-               state_entry->save_state(state_fio);
-       }
-//     state_fio->FputUint32(STATE_VERSION);
-//     state_fio->FputInt32(this_device_id);
-       
-//     cur_time.save_state((void *)state_fio);
-//     state_fio->FputInt32(time_register_id);
-//     state_fio->Fwrite(databuf, sizeof(databuf), 1);
-//     state_fio->FputInt32((int)(datap - &databuf[0][0]));
-//     state_fio->FputUint8(mode);
-//     state_fio->FputUint8(inbuf);
-//     state_fio->FputUint8(outbuf);
-//     state_fio->FputBool(ibf);
-//     state_fio->FputBool(obf);
-//     state_fio->FputInt32(cmdlen);
-//     state_fio->FputInt32(datalen);
-//     key_buf->save_state((void *)state_fio);
-//     state_fio->FputInt32(key_prev);
-//     state_fio->FputInt32(key_break);
-//     state_fio->FputBool(key_shift);
-//     state_fio->FputBool(key_ctrl);
-//     state_fio->FputBool(key_graph);
-//     state_fio->FputBool(key_caps_locked);
-//     state_fio->FputBool(key_kana_locked);
-//     state_fio->FputInt32(key_register_id);
-//     state_fio->FputBool(play);
-//     state_fio->FputBool(rec);
-//     state_fio->FputBool(eot);
-//     state_fio->FputBool(iei);
-//     state_fio->FputBool(intr);
-//     state_fio->FputUint32(intr_bit);
-}
-
-bool PSUB::load_state(FILEIO* state_fio)
-{
-       bool mb = false;
-       if(state_entry != NULL) {
-               mb = state_entry->load_state(state_fio);
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(time_register_id);
+       state_fio->StateBuffer(databuf, sizeof(databuf), 1);
+       if(loading) {
+               datap = &databuf[0][0] + state_fio->FgetInt32_LE();
+       } else {
+               state_fio->FputInt32_LE((int)(datap - &databuf[0][0]));
        }
-       if(!mb) return false;
-//     if(state_fio->FgetUint32() != STATE_VERSION) {
-//             return false;
-//     }
-//     if(state_fio->FgetInt32() != this_device_id) {
-//             return false;
-//     }
-//     if(!cur_time.load_state((void *)state_fio)) {
-//             return false;
-//     }
-//     time_register_id = state_fio->FgetInt32();
-//     state_fio->Fread(databuf, sizeof(databuf), 1);
-//     datap = &databuf[0][0] + state_fio->FgetInt32();
-//     mode = state_fio->FgetUint8();
-//     inbuf = state_fio->FgetUint8();
-//     outbuf = state_fio->FgetUint8();
-//     ibf = state_fio->FgetBool();
-//     obf = state_fio->FgetBool();
-//     cmdlen = state_fio->FgetInt32();
-//     datalen = state_fio->FgetInt32();
-//     if(!key_buf->load_state((void *)state_fio)) {
-//             return false;
-//     }
-//     key_prev = state_fio->FgetInt32();
-//     key_break = state_fio->FgetInt32();
-//     key_shift = state_fio->FgetBool();
-//     key_ctrl = state_fio->FgetBool();
-//     key_graph = state_fio->FgetBool();
-//     key_caps_locked = state_fio->FgetBool();
-//     key_kana_locked = state_fio->FgetBool();
-//     key_register_id = state_fio->FgetInt32();
-//     play = state_fio->FgetBool();
-//     rec = state_fio->FgetBool();
-//     eot = state_fio->FgetBool();
-//     iei = state_fio->FgetBool();
-//     intr = state_fio->FgetBool();
-//     intr_bit = state_fio->FgetUint32();
-
-       datap = tmp_datap + &databuf[0][0];
-
-       return true;
+       state_fio->StateUint8(mode);
+       state_fio->StateUint8(inbuf);
+       state_fio->StateUint8(outbuf);
+       state_fio->StateBool(ibf);
+       state_fio->StateBool(obf);
+       state_fio->StateInt32(cmdlen);
+       state_fio->StateInt32(datalen);
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(key_prev);
+       state_fio->StateInt32(key_break);
+       state_fio->StateBool(key_shift);
+       state_fio->StateBool(key_ctrl);
+       state_fio->StateBool(key_graph);
+       state_fio->StateBool(key_caps_locked);
+       state_fio->StateBool(key_kana_locked);
+       state_fio->StateInt32(key_register_id);
+       state_fio->StateBool(play);
+       state_fio->StateBool(rec);
+       state_fio->StateBool(eot);
+       state_fio->StateBool(iei);
+       state_fio->StateBool(intr);
+       state_fio->StateUint32(intr_bit);
+       return true;
 }
 
index 20898bc..93acabf 100644 (file)
@@ -71,9 +71,7 @@ public:
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
        void event_callback(int event_id, int err);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // interrupt common functions
        void set_context_intr(DEVICE* device, uint32_t bit)
index ab8639d..a3a096e 100644 (file)
@@ -123,45 +123,15 @@ void SASI::write_signal(int id, uint32_t data, uint32_t mask)
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void SASI::decl_state()
+bool SASI::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_BOOL(irq_status);
-       DECL_STATE_ENTRY_BOOL(drq_status);
-       
-       leave_decl_state();
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBool(irq_status);
+       state_fio->StateBool(drq_status);
+       return true;
 }
-
-void SASI::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->FputBool(irq_status);
-//     state_fio->FputBool(drq_status);
-}
-
-bool SASI::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;
-//     }
-//     irq_status = state_fio->FgetBool();
-//     drq_status = state_fio->FgetBool();
-       return true;
-}
-
index d27f374..bef1ca6 100644 (file)
@@ -45,9 +45,7 @@ public:
        void write_dma_io8(uint32_t addr, uint32_t data);
        uint32_t read_dma_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
-       void 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_host(DEVICE* device)
index 7abeee9..3b46c18 100644 (file)
@@ -266,78 +266,26 @@ void SUB::update_intr()
 
 #define STATE_VERSION  1
 
-#include "../statesub.h"
-
-void SUB::decl_state()
+bool SUB::process_state(FILEIO* state_fio, bool loading)
 {
-       enter_decl_state(STATE_VERSION);
-       
-       DECL_STATE_ENTRY_UINT8(p1_out);
-       DECL_STATE_ENTRY_UINT8(p1_in);
-       DECL_STATE_ENTRY_UINT8(p2_out);
-       DECL_STATE_ENTRY_UINT8(p2_in);
-       DECL_STATE_ENTRY_UINT8(portc);
-       DECL_STATE_ENTRY_BOOL(tape_play);
-       DECL_STATE_ENTRY_BOOL(tape_rec);
-       DECL_STATE_ENTRY_BOOL(tape_eot);
-       DECL_STATE_ENTRY_BOOL(tape_apss);
-       DECL_STATE_ENTRY_BOOL(intr);
-       DECL_STATE_ENTRY_BOOL(obf);
-       DECL_STATE_ENTRY_BOOL(iei);
-       DECL_STATE_ENTRY_UINT32(intr_bit);
-       
-       leave_decl_state();
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateUint8(p1_out);
+       state_fio->StateUint8(p1_in);
+       state_fio->StateUint8(p2_out);
+       state_fio->StateUint8(p2_in);
+       state_fio->StateUint8(portc);
+       state_fio->StateBool(tape_play);
+       state_fio->StateBool(tape_rec);
+       state_fio->StateBool(tape_eot);
+       state_fio->StateBool(tape_apss);
+       state_fio->StateBool(intr);
+       state_fio->StateBool(obf);
+       state_fio->StateBool(iei);
+       state_fio->StateUint32(intr_bit);
+       return true;
 }
-
-void SUB::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->FputUint8(p1_out);
-//     state_fio->FputUint8(p1_in);
-//     state_fio->FputUint8(p2_out);
-//     state_fio->FputUint8(p2_in);
-//     state_fio->FputUint8(portc);
-//     state_fio->FputBool(tape_play);
-//     state_fio->FputBool(tape_rec);
-//     state_fio->FputBool(tape_eot);
-//     state_fio->FputBool(tape_apss);
-//     state_fio->FputBool(intr);
-//     state_fio->FputBool(obf);
-//     state_fio->FputBool(iei);
-//     state_fio->FputUint32(intr_bit);
-}
-
-bool SUB::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;
-//     }
-//     p1_out = state_fio->FgetUint8();
-//     p1_in = state_fio->FgetUint8();
-//     p2_out = state_fio->FgetUint8();
-//     p2_in = state_fio->FgetUint8();
-//     portc = state_fio->FgetUint8();
-//     tape_play = state_fio->FgetBool();
-//     tape_rec = state_fio->FgetBool();
-//     tape_eot = state_fio->FgetBool();
-//     tape_apss = state_fio->FgetBool();
-//     intr = state_fio->FgetBool();
-//     obf = state_fio->FgetBool();
-//     iei = state_fio->FgetBool();
-//     intr_bit = state_fio->FgetUint32();
-       return true;
-}
-
index fa7eda2..953d18e 100644 (file)
@@ -55,9 +55,7 @@ public:
        void write_io8(uint32_t addr, uint32_t data);
        uint32_t read_io8(uint32_t addr);
        void write_signal(int id, uint32_t data, uint32_t mask);
-       void decl_state();
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // interrupt common functions
        void set_context_intr(DEVICE* device, uint32_t bit)
index 776a671..3080b1b 100644 (file)
@@ -471,7 +471,6 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
                        create_local_path(config.last_hard_disk_path[drv], _MAX_PATH, _T("SASI%d.DAT"), drv);
                }
        }
-       decl_state();
 }
 
 VM::~VM()
@@ -950,59 +949,39 @@ void VM::update_dipswitch()
 #endif
 
 #define STATE_VERSION  10
-#include "../../statesub.h"
-#include "../../qt/gui/csp_logger.h"
-extern CSP_Logger DLL_PREFIX_I *csp_logger;
-
-void VM::decl_state(void)
-{
-#if defined(_X1)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, _T("CSP::X1_HEAD"), csp_logger);
-#elif defined(_X1TURBO)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, _T("CSP::X1_TURBO_HEAD"), csp_logger);
-#elif defined(_X1TURBOZ)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, _T("CSP::X1_TURBO_Z_HEAD"), csp_logger);
-#elif defined(_X1TWIN)
-       state_entry = new csp_state_utils(STATE_VERSION, 0, _T("CSP::X1_TWIN_HEAD"), csp_logger);
-#else
-       state_entry = new csp_state_utils(STATE_VERSION, 0, _T("CSP::X1_SERIES_HEAD"), csp_logger);
-#endif
-       
-       DECL_STATE_ENTRY_BOOL(pseudo_sub_cpu);
-       DECL_STATE_ENTRY_INT32(sound_type);
-       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) {
-               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) return false;
-
-       int n = 1;
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               if(!device->load_state(state_fio)) {
-                       printf("STATE ERROR at device #%d\n", n);
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               // Note: typeid(foo).name is fixed by recent ABI.Not decr. 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)) {
                        return false;
                }
-               n++;
-       }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       if(loading) {
+                               printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+                       }
+                       return false;
+               }
+       }
+       state_fio->StateBool(pseudo_sub_cpu);
+       state_fio->StateInt32(sound_type);
+       
 #ifdef _X1TURBO_FEATURE
-       // post process
-       update_dipswitch();
+       // post process
+       if(loading) {
+               update_dipswitch();
+       }
 #endif
-       return true;
+       return true;
 }
-
index fc1804c..e438ab6 100644 (file)
@@ -425,9 +425,7 @@ public:
 #ifdef _X1TURBO_FEATURE
        void update_dipswitch();
 #endif
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
-       void decl_state(void);
+       bool process_state(FILEIO* state_fio, bool loading);
        
        // ----------------------------------------
        // for each device