OSDN Git Service

[VM][STATE] Apply new framework to some VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc8201 / pc8201.cpp
index b6c5157..e2055ec 100644 (file)
 #include "cmt.h"
 #include "keyboard.h"
 #include "lcd.h"
-#include "memory.h"
+#include "./memory.h"
 
 // ----------------------------------------------------------------------------
 // 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;
@@ -53,7 +53,7 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        cmt = new CMT(this, emu);
        keyboard = new KEYBOARD(this, emu);
        lcd = new LCD(this, emu);
-       memory = new MEMORY(this, emu);
+       memory = new PC8201_MEMORY(this, emu);
        
        // set contexts
        event->set_context_cpu(cpu);
@@ -100,6 +100,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        io->set_iomap_range_rw(0xf0, 0xff, lcd);
        
        // 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();
        }
@@ -218,6 +221,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
 // ----------------------------------------------------------------------------
@@ -226,6 +239,7 @@ void VM::play_tape(int drv, const _TCHAR* file_path)
 {
        cmt->close_tape();
        drec->play_tape(file_path);
+//     drec->set_remote(true);
 }
 
 void VM::rec_tape(int drv, const _TCHAR* file_path)
@@ -233,6 +247,7 @@ void VM::rec_tape(int drv, const _TCHAR* file_path)
        emu->lock_vm();
        drec->close_tape();
        emu->unlock_vm();
+//     drec->set_remote(false);
        cmt->rec_tape(file_path);
 }
 
@@ -241,6 +256,7 @@ void VM::close_tape(int drv)
        emu->lock_vm();
        drec->close_tape();
        emu->unlock_vm();
+//     drec->set_remote(false);
        cmt->close_tape();
 }
 
@@ -251,57 +267,116 @@ bool VM::is_tape_inserted(int drv)
 
 bool VM::is_tape_playing(int drv)
 {
-       return drec->is_tape_playing();
+       if(drec->is_tape_inserted()) {
+               return drec->is_tape_playing();
+       } else {
+               return cmt->is_tape_playing();
+       }
 }
 
 bool VM::is_tape_recording(int drv)
 {
-       return drec->is_tape_recording();
+       if(drec->is_tape_inserted()) {
+               return drec->is_tape_recording();
+       } else {
+               return cmt->is_tape_recording();
+       }
 }
 
 int VM::get_tape_position(int drv)
 {
-       return drec->get_tape_position();
+       if(drec->is_tape_inserted()) {
+               return drec->get_tape_position();
+       } else {
+               return cmt->get_tape_position();
+       }
 }
 
 const _TCHAR* VM::get_tape_message(int drv)
 {
-       return drec->get_message();
+       if(drec->is_tape_inserted()) {
+               return drec->get_message();
+       } else {
+               return NULL;
+       }
 }
 
-bool VM::is_frame_skippable()
+void VM::push_play(int drv)
 {
-       return event->is_frame_skippable();
+       if(drec->is_tape_inserted()) {
+               drec->set_ff_rew(0);
+               drec->set_remote(true);
+       }
 }
 
-void VM::update_config()
+void VM::push_stop(int drv)
 {
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->update_config();
+       if(drec->is_tape_inserted()) {
+               drec->set_remote(false);
+       }
+}
+
+void VM::push_fast_forward(int drv)
+{
+       if(drec->is_tape_inserted()) {
+               drec->set_ff_rew(1);
+               drec->set_remote(true);
        }
 }
 
-#define STATE_VERSION  2
+void VM::push_fast_rewind(int drv)
+{
+       if(drec->is_tape_inserted()) {
+               drec->set_ff_rew(-1);
+               drec->set_remote(true);
+       }
+}
 
-void VM::save_state(FILEIO* state_fio)
+bool VM::is_frame_skippable()
+{
+       return event->is_frame_skippable();
+}
+
+void VM::update_config()
 {
-       state_fio->FputUint32(STATE_VERSION);
-       
        for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->save_state(state_fio);
+               device->update_config();
        }
 }
 
-bool VM::load_state(FILEIO* state_fio)
+#define STATE_VERSION  3
+
+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;
 }
-