OSDN Git Service

[VM][SN76489AN][YM2151][YM2203] Add write_debug_reg() and get_debug_regs().
[csp-qt/common_source_project-fm7.git] / source / src / vm / yis / yis.cpp
index e73f7d3..ceaa751 100644 (file)
 #include "mapper.h"
 #include "sound.h"
 
+using YIS::CALENDAR;
+using YIS::DISPLAY;
+using YIS::FLOPPY;
+using YIS::KEYBOARD;
+using YIS::MAPPER;
+using YIS::SOUND;
 // ----------------------------------------------------------------------------
 // initialize
 // ----------------------------------------------------------------------------
 
-VM::VM(EMU* parent_emu) : emu(parent_emu)
+VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
 {
        // create devices
        first_device = last_device = NULL;
@@ -52,7 +58,13 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        memory = new MEMORY(this, emu);
        apu = new AM9511(this, emu);
        beep = new BEEP(this, emu);
+#ifdef USE_DEBUGGER
+       beep->set_context_debugger(new DEBUGGER(this, emu));
+#endif
        fdc = new MB8877(this, emu);
+#ifdef USE_DEBUGGER
+       fdc->set_context_debugger(new DEBUGGER(this, emu));
+#endif
        fdc->set_context_noise_seek(new NOISE(this, emu));
        fdc->set_context_noise_head_down(new NOISE(this, emu));
        fdc->set_context_noise_head_up(new NOISE(this, emu));
@@ -116,6 +128,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
 //     io->set_iomap_range_rw(0xf060, 0xf06f, keyboard);
        
        // initialize all devices
+#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();
        }
@@ -237,6 +252,16 @@ void VM::key_up(int code)
 {
 }
 
+bool VM::get_caps_locked()
+{
+       return keyboard->get_caps_locked();
+}
+
+bool VM::get_kana_locked()
+{
+       return keyboard->get_kana_locked();
+}
+
 // ----------------------------------------------------------------------------
 // user interface
 // ----------------------------------------------------------------------------
@@ -283,27 +308,39 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  1
-
-void VM::save_state(FILEIO* state_fio)
-{
-       state_fio->FputUint32(STATE_VERSION);
-       
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->save_state(state_fio);
-       }
-}
+#define STATE_VERSION  2
 
-bool VM::load_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
                return false;
        }
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               if(!device->load_state(state_fio)) {
+       for(DEVICE* device = first_device; device; device = device->next_device) {
+               // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
+               // const char *name = typeid(*device).name();
+               //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
+               const char *name = device->get_device_name();
+               int len = strlen(name);
+               
+               if(!state_fio->StateCheckInt32(len)) {
+                       if(loading) {
+                               printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
                        return false;
                }
-       }
+               if(!state_fio->StateCheckBuffer(name, len, 1)) {
+                       if(loading) {
+                               printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
+                       }
+                       return false;
+               }
+               if(!device->process_state(state_fio, loading)) {
+                       if(loading) {
+                               printf("Data loading Error: DEVID=%d\n", device->this_device_id);
+                       }
+                       return false;
+               }
+       }
+       // Machine specified.
        return true;
 }
-