OSDN Git Service

[VM][FM7] Fix state save/load.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 27 Apr 2016 13:16:32 +0000 (22:16 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 27 Apr 2016 13:16:32 +0000 (22:16 +0900)
[VM][General] Fix state save/load.

15 files changed:
source/src/emu.cpp
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_mainio.cpp
source/src/vm/fm7/fm7_mainmem.cpp
source/src/vm/fm7/fm_bubblecasette.cpp
source/src/vm/fm7/hd6844.cpp
source/src/vm/fm7/joystick.cpp
source/src/vm/fm7/joystick.h
source/src/vm/fm7/kanjirom.cpp
source/src/vm/fm7/kanjirom.h
source/src/vm/fm7/keyboard.cpp
source/src/vm/fm7/mb61vh010.cpp

index adef6c6..4b6e1ae 100644 (file)
@@ -1677,10 +1677,6 @@ void EMU::save_state_tmp(const _TCHAR* file_path)
 #ifdef USE_LASER_DISC
                fio->Fwrite(&laser_disc_status, sizeof(laser_disc_status), 1);
 #endif
-#ifdef USE_FD1
-               fio->Fwrite(floppy_disk_status, sizeof(floppy_disk_status), 1);
-               fio->Fwrite(d88_file, sizeof(d88_file), 1);
-#endif
                // save vm state
                vm->save_state(fio);
                // end of state file
index efd05bf..5d44f69 100644 (file)
@@ -2424,6 +2424,7 @@ void DISPLAY::save_state(FILEIO *state_fio)
 {
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: DISPLAY : id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        {
                int i;
@@ -2570,6 +2571,7 @@ bool DISPLAY::load_state(FILEIO *state_fio)
        if(this_device_id != state_fio->FgetInt32_BE()) {
                return false;
        }
+       p_emu->out_debug_log("Load State: DISPLAY : id=%d ver=%d\n", this_device_id, version);
    
        if(version >= 1) {
                int addr;
index f9159da..68d0326 100644 (file)
@@ -8,14 +8,15 @@
  *
  */
 
+#include "emu.h"
 #include "dummydevice.h"
 
-
 DUMMYDEVICE::DUMMYDEVICE(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
 {
        status = 0x00000000;
        clear_on_reset = true;
        clear_with_zero = true;
+       p_emu = parent_emu;
 }
 
 DUMMYDEVICE::~DUMMYDEVICE()
@@ -76,6 +77,7 @@ void DUMMYDEVICE::save_state(FILEIO *state_fio)
 {
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: DUMMYDEVICE: id=%d ver=%d\n", this_device_id, STATE_VERSION);
        // Version 1
        {
                state_fio->FputUint32_BE(status);
@@ -88,13 +90,14 @@ bool DUMMYDEVICE::load_state(FILEIO *state_fio)
 {
        uint32_t version;
        version = state_fio->FgetUint32_BE();
+       p_emu->out_debug_log("Load State: DUMMYDEVICE: id=%d ver=%d\n", this_device_id, version);
        if(this_device_id != state_fio->FgetInt32_BE()) return false;
        // Version 1
-       if((version < 1) || (version > STATE_VERSION)) return false;
        {
                status = state_fio->FgetUint32_BE();
                clear_on_reset = state_fio->FgetBool();
                clear_with_zero = state_fio->FgetBool();
        }
+       if(version != STATE_VERSION) return false;
        return true;
 }
index 9803f5e..02ddc9b 100644 (file)
@@ -50,9 +50,11 @@ enum {
        SIG_DUMMYDEVICE_CLEAR_ON_RESET,
        SIG_DUMMYDEVICE_CLEAR_WITH_ZERO,
 };
+class EMU;
 
 class DUMMYDEVICE : public DEVICE {
 private:
+       EMU *p_emu;
        uint32_t status;
        bool clear_on_reset;
        bool clear_with_zero;
index 753f275..fcb1639 100644 (file)
@@ -708,7 +708,6 @@ void VM::is_bubble_casette_protected(int drv, bool flag)
 void VM::save_state(FILEIO* state_fio)
 {
        state_fio->FputUint32_BE(STATE_VERSION);
-       
        for(DEVICE* device = first_device; device; device = device->next_device) {
                device->save_state(state_fio);
        }
@@ -718,7 +717,7 @@ bool VM::load_state(FILEIO* state_fio)
 {
        uint32_t version = state_fio->FgetUint32_BE();
        int i = 1;
-       if(version > STATE_VERSION) {
+       if(version != STATE_VERSION) {
                return false;
        }
        for(DEVICE* device = first_device; device; device = device->next_device) {
@@ -727,10 +726,7 @@ bool VM::load_state(FILEIO* state_fio)
                        return false;
                }
        }
-       if(version >= 1) {// V1 
-               if(version == 3) return true;
-       }
-       return false;
+       return true;
 }
 
 #ifdef USE_DIG_RESOLUTION
index 6ced85b..56c1b33 100644 (file)
@@ -1631,6 +1631,7 @@ void FM7_MAINIO::save_state(FILEIO *state_fio)
        int addr;
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: MAINIO: id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        // Version 1
        {
@@ -1791,6 +1792,7 @@ bool FM7_MAINIO::load_state(FILEIO *state_fio)
        
        version = state_fio->FgetUint32_BE();
        if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       p_emu->out_debug_log("Load State: MAINIO: id=%d ver=%d\n", this_device_id, version);
 
        if(version >= 1) {
                for(addr = 0; addr < 0x100; addr++) io_w_latch[addr] = state_fio->FgetUint8();
index df3a28b..2118ed5 100644 (file)
@@ -1224,6 +1224,7 @@ void FM7_MAINMEM::save_state(FILEIO *state_fio)
 {
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: MAINMEM: id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        // V1
        state_fio->FputBool(ioaccess_wait);
@@ -1328,6 +1329,7 @@ bool FM7_MAINMEM::load_state(FILEIO *state_fio)
        uint32_t version;
        version = state_fio->FgetUint32_BE();
        if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       p_emu->out_debug_log("Load State: MAINMEM: id=%d ver=%d\n", this_device_id, version);
        if(version >= 1) {
                // V1
                ioaccess_wait = state_fio->FgetBool();
@@ -1399,7 +1401,7 @@ bool FM7_MAINMEM::load_state(FILEIO *state_fio)
 #endif
                if(version == 1) return true;
        }
-       if(version >= 2) { // V2;
+       { // V2;
                is_basicrom = state_fio->FgetBool();
                clockmode = state_fio->FgetBool();
                basicrom_fd0f = state_fio->FgetBool();
@@ -1427,5 +1429,6 @@ bool FM7_MAINMEM::load_state(FILEIO *state_fio)
                state_fio->Fread(mmr_map_data, sizeof(mmr_map_data), 1);
 #endif
        }
+       if(version != STATE_VERSION) return false;
        return true;
 }
index d70b571..1c56c9f 100644 (file)
@@ -20,6 +20,7 @@ BUBBLECASETTE::BUBBLECASETTE(VM *parent_vm, EMU *parent_emu) : DEVICE(parent_vm,
        memset(bubble_data, 0x00, 0x20000);
        bubble_inserted = false;
        read_access = write_access = false;
+       p_emu = parent_emu;
 }
 
 BUBBLECASETTE::~BUBBLECASETTE()
@@ -638,6 +639,7 @@ void BUBBLECASETTE::save_state(FILEIO *state_fio)
        int i, j;
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: BUBBLE: id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        // Attributes
        state_fio->FputUint32_BE(file_length);
@@ -696,6 +698,7 @@ 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;
+       p_emu->out_debug_log("Load State: BUBBLE: id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        // Attributes
        file_length = state_fio->FgetUint32_BE();
index 79e1cea..e90e4ae 100644 (file)
@@ -418,6 +418,7 @@ void HD6844::save_state(FILEIO *state_fio)
        int i;
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: HD6844: id=%d ver=%d\n", this_device_id, STATE_VERSION);
        { // V1
                for(i = 0; i < 4; i++) {
                        state_fio->FputUint32_BE(addr_reg[i]);
@@ -447,6 +448,7 @@ bool HD6844::load_state(FILEIO *state_fio)
        int i;
        version = state_fio->FgetUint32_BE();
        if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       p_emu->out_debug_log("Load State: HD6844: id=%d ver=%d\n", this_device_id, version);
        if(version >= 1) {
                for(i = 0; i < 4; i++) {
                        addr_reg[i] = state_fio->FgetUint32_BE();
index 361eed5..991e120 100644 (file)
@@ -39,10 +39,9 @@ void JOYSTICK::initialize()
        lx = ly = -1;
        mouse_button = 0x00;
        mouse_timeout_event = -1;
-       port_a_val = 0;
-       port_b_val = 0;
        lpmask = 0x00;
        lpt_type = config.printer_device_type;
+       port_b_val = 0;
 }
 
 void JOYSTICK::reset()
@@ -81,6 +80,7 @@ void JOYSTICK::event_frame()
        uint32_t retval = 0xff;
        uint32_t val;
 #if !defined(_FM8)
+       mouse_state = p_emu->get_mouse_buffer();
        if(mouse_state != NULL) {
                dx += (mouse_state[0] / 2);
                dy += (mouse_state[1] / 2);
@@ -194,7 +194,7 @@ uint32_t JOYSTICK::read_data8(uint32_t addr)
        case 0: // OPN
                        //opn->write_io8(0, 0x0f);
                        //opnval = opn->read_io8(1);
-                       opnval = port_b_val;
+                       opnval = (uint32_t)port_b_val;
                        if(emulate_mouse[0]) {
                                if((opnval & 0xc0) == 0x00) {
                                        return update_mouse((opnval & 0x03) << 4);
@@ -255,7 +255,7 @@ void JOYSTICK::write_signal(int id, uint32_t data, uint32_t mask)
                        emulate_mouse[1] = val_b;
                        break;
                case FM7_JOYSTICK_MOUSE_STROBE:
-                       port_b_val = data;
+                       port_b_val = (uint8_t)data;
                        if(emulate_mouse[0]) {
                                update_strobe(((data & 0x10) != 0));
                        } else  if(emulate_mouse[1]) {
@@ -290,12 +290,13 @@ void JOYSTICK::update_config(void)
        }
 #endif 
 }
-#define STATE_VERSION 3
+#define STATE_VERSION 4
 void JOYSTICK::save_state(FILEIO *state_fio)
 {
        int ch;
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: JOYSTICK: id=%d ver=%d\n", this_device_id, STATE_VERSION);
        // Version 1
        for(ch = 0; ch < 2; ch++) {
 #if !defined(_FM8)
@@ -317,6 +318,8 @@ void JOYSTICK::save_state(FILEIO *state_fio)
 #endif 
        // Version 3
        state_fio->FputUint8(lpmask);
+       // Version 4
+       state_fio->FputUint8(port_b_val);
 }
 
 bool JOYSTICK::load_state(FILEIO *state_fio)
@@ -325,6 +328,7 @@ bool JOYSTICK::load_state(FILEIO *state_fio)
        uint32_t devid = state_fio->FgetInt32_BE();
        bool stat = false;
        int ch;
+       p_emu->out_debug_log("Load State: JOYSTICK: id=%d ver=%d\n", devid, version);
        if(devid != this_device_id) return stat;
        if(version >= 1) {
                for(ch = 0; ch < 2; ch++) {
@@ -333,7 +337,7 @@ bool JOYSTICK::load_state(FILEIO *state_fio)
 #endif                 
                        joydata[ch] = state_fio->FgetUint32_BE();
                }
-               if(version == 1) stat = true;
+               //if(version == 1) stat = true;
        }
 #if !defined(_FM8)
        // After version 2.
@@ -347,8 +351,12 @@ bool JOYSTICK::load_state(FILEIO *state_fio)
        mouse_data = state_fio->FgetUint32_BE();
        //mouse_timeout_event = state_fio->FgetInt32();
 #endif 
+       // V3
        lpmask = state_fio->FgetUint8();
-       if(version == 3) stat = true; 
+       lpt_type = config.printer_device_type;
+       // V4
+       port_b_val = state_fio->FgetUint8();
+       if(version == STATE_VERSION) stat = true; 
        return stat;
 }
                
index 43ab64f..55e5037 100644 (file)
@@ -28,8 +28,7 @@ class JOYSTICK : public DEVICE {
        uint32_t mouse_data;
        int mouse_phase;
        int mouse_timeout_event;
-       uint32_t port_a_val;
-       uint32_t port_b_val;
+       uint8_t port_b_val;
        uint8_t lpmask;
        int lpt_type;
  protected:
index d425a93..660ce88 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include "../../fileio.h"
+#include "emu.h"
 #include "fm7_common.h"
 #include "kanjirom.h"
 
@@ -18,7 +19,7 @@ KANJIROM::KANJIROM(VM *parent_vm, EMU* parent_emu, bool type_2std): DEVICE(paren
        fio = new FILEIO();
        memset(data_table, 0xff, 0x20000); 
        //      read_table[0].memory = data_table;
-       
+       p_emu = parent_emu;
        if(type_2std) {
                class2 = true;
                if(fio->Fopen(create_local_path(_T("KANJI2.ROM")), FILEIO_READ_BINARY)) {
@@ -89,6 +90,7 @@ void KANJIROM::save_state(FILEIO *state_fio)
 {
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: KANJIROM: id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        state_fio->FputBool(class2);
        state_fio->FputBool(read_ok);
@@ -101,6 +103,7 @@ bool KANJIROM::load_state(FILEIO *state_fio)
        uint32_t version;
        version = state_fio->FgetUint32_BE();
        if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       p_emu->out_debug_log("Load State: KANJIROM: id=%d ver=%d\n", this_device_id, version);
 
        if(version >= 1) {
                class2 = state_fio->FgetBool();
index 7156b16..11a7b9e 100644 (file)
@@ -9,8 +9,11 @@
 #include "../device.h"
 #include "../mc6809.h"
 
+class EMU;
+
 class KANJIROM: public DEVICE {
 private:
+       EMU *p_emu;
        uint8_t data_table[0x20000];
        bool read_ok;
        bool class2;
index a7087bc..f020953 100644 (file)
@@ -1064,6 +1064,7 @@ void KEYBOARD::save_state(FILEIO *state_fio)
 {
        state_fio->FputUint32_BE(STATE_VERSION);
        state_fio->FputInt32_BE(this_device_id);
+       p_emu->out_debug_log("Save State: KEYBOARD: id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        // Version 1
        {
@@ -1134,6 +1135,7 @@ bool KEYBOARD::load_state(FILEIO *state_fio)
        
        version = state_fio->FgetUint32_BE();
        if(this_device_id != state_fio->FgetInt32_BE()) return false;
+       p_emu->out_debug_log("Load State: KEYBOARD: id=%d ver=%d\n", this_device_id, version);
 
        if(version >= 1) {
                keycode_7 = state_fio->FgetUint32_BE();
@@ -1195,7 +1197,7 @@ bool KEYBOARD::load_state(FILEIO *state_fio)
                did_hidden_message_av_1 = state_fio->FgetBool();
 #endif
        }
-       if(version == 2) {
+       if(version == STATE_VERSION) {
                return true;
        }
        return false;
index 9ef87b5..744e8e4 100644 (file)
@@ -321,7 +321,7 @@ void MB61VH010::do_alucmds_dmyread(uint32_t addr)
                        do_compare(addr);
                        break;
        }
-       //printf("ALU DMYREAD ADDR=%04x, CMD=%02x CMP STATUS=%02x\n", addr, command_reg, cmp_status_reg);
+       //p_emu->out_debug_log("ALU DMYREAD ADDR=%04x, CMD=%02x CMP STATUS=%02x\n", addr, command_reg, cmp_status_reg);
        //if(eventid_busy >= 0) cancel_event(this, eventid_busy) ;
        //register_event(this, EVENT_MB61VH010_BUSY_OFF, 1.0 / 16.0, false, &eventid_busy) ;
 }  
@@ -406,7 +406,7 @@ void MB61VH010::do_line(void)
    
        xcount = abs(ax);
        ycount = abs(ay);
-       //printf("LINE: (%d,%d)-(%d,%d)\n", x_begin, y_begin, x_end , y_end); 
+       //p_emu->out_debug_log("LINE: (%d,%d)-(%d,%d)\n", x_begin, y_begin, x_end , y_end); 
        if(ycount == 0) {
                if(ax > 0) {
                        if((cpx_t & 0x07) != 7) total_bytes = 1;
@@ -504,13 +504,13 @@ void MB61VH010::do_line(void)
        //if(!lastflag) total_bytes++;
        if(alu_addr < 0x8000) do_alucmds(alu_addr);
    
-       if(total_bytes > 16) { // Over 1.0us
-               usec = (double)total_bytes / 16.0;
-               if(eventid_busy >= 0) cancel_event(this, eventid_busy) ;
-               register_event(this, EVENT_MB61VH010_BUSY_OFF, usec, false, &eventid_busy) ;
-       } else {
-               busy_flag = false;
-       }
+       //if(total_bytes > 16) { // Over 1.0us
+       usec = (double)total_bytes / 16.0;
+       if(eventid_busy >= 0) cancel_event(this, eventid_busy) ;
+       register_event(this, EVENT_MB61VH010_BUSY_OFF, usec, false, &eventid_busy) ;
+       //} else {
+       //      busy_flag = false;
+       //}
 }
 
 bool MB61VH010::put_dot(int x, int y)
@@ -546,7 +546,7 @@ bool MB61VH010::put_dot(int x, int y)
 
 void MB61VH010::write_data8(uint32_t id, uint32_t data)
 {
-       //printf("ALU: ADDR=%02x DATA=%02x\n", id, data);
+       //p_emu->out_debug_log("ALU: ADDR=%02x DATA=%02x\n", id, data);
        if(id == ALU_CMDREG) {
                command_reg = data;
                return;
@@ -781,6 +781,7 @@ void MB61VH010::save_state(FILEIO *state_fio)
        int i;
        state_fio->FputUint32(STATE_VERSION);
        state_fio->FputInt32(this_device_id);
+       p_emu->out_debug_log("Save State: MB61VH010 : id=%d ver=%d\n", this_device_id, STATE_VERSION);
 
        { // V1
                state_fio->FputUint8(command_reg);
@@ -820,7 +821,7 @@ bool MB61VH010::load_state(FILEIO *state_fio)
 {
        uint32_t version = state_fio->FgetUint32();
        int i;
-   
+       p_emu->out_debug_log("Load State: MB61VH010 : id=%d ver=%d\n", this_device_id, version);
        if(this_device_id != state_fio->FgetInt32()) return false;
        if(version >= 1) {
                command_reg = state_fio->FgetUint8();
@@ -860,5 +861,6 @@ bool MB61VH010::load_state(FILEIO *state_fio)
                line_style.d = 0;
                line_style.w.l = state_fio->FgetUint16_BE();
        }
+       if(version != STATE_VERSION) return false;
        return true;
 }