OSDN Git Service

[VM][I286] Save cpustate without StateBuffer().
[csp-qt/common_source_project-fm7.git] / source / src / vm / jr100 / jr100.cpp
index 1bb3a61..f766202 100644 (file)
@@ -13,7 +13,8 @@
 #include "../event.h"
 
 #include "../datarec.h"
-#include "../mc6800.h"
+//#include "../mc6800.h"
+#include "../mb8861.h"
 #include "../noise.h"
 #include "../not.h"
 #include "../pcm1bit.h"
 #include "../debugger.h"
 #endif
 
-#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;
        dummy = new DEVICE(this, emu);  // must be 1st device
        event = new EVENT(this, emu);   // must be 2nd device
-#if defined(_USE_QT)
        dummy->set_device_name(_T("1st Dummy"));
-       event->set_device_name(_T("EVENT"));
-#endif 
        
        drec = new DATAREC(this, emu);
        drec->set_context_noise_play(new NOISE(this, emu));
        drec->set_context_noise_stop(new NOISE(this, emu));
        drec->set_context_noise_fast(new NOISE(this, emu));
-       cpu = new MC6800(this, emu);    // MB8861N
+       //cpu = new MC6800(this, emu);  // MB8861N
+       cpu = new MB8861(this, emu);    // MB8861N
        not_mic = new NOT(this, emu);
        not_mic->set_device_name(_T("NOT Gate (Mic)"));
        not_ear = new NOT(this, emu);
        not_ear->set_device_name(_T("NOT Gate (Ear)"));
        pcm = new PCM1BIT(this, emu);
        via = new SY6522(this, emu);
-#if defined(_USE_QT)
-       cpu->set_device_name(_T("CPU(MC6800)"));
-       not_mic->set_device_name(_T("NOT GATE(MIC)"));
-       not_ear->set_device_name(_T("NOT GATE(EAR PHONE)"));
-       pcm->set_device_name(_T("SOUND DEVICE"));
-       via->set_device_name(_T("SY6522 VIA"));
-#endif 
        
-       memory = new MEMORY(this, emu);
-#if defined(_USE_QT)
-       memory->set_device_name(_T("MEMORY"));
-#endif 
+       memory = new JR100_MEMORY(this, emu);
        // set contexts
        event->set_context_cpu(cpu);
        event->set_context_sound(pcm);
        event->set_context_sound(drec);
-#if defined(USE_SOUND_FILES)
-       drec->load_sound_data(DATAREC_SNDFILE_RELAY_ON, _T("RELAY_ON.WAV"));
-       drec->load_sound_data(DATAREC_SNDFILE_RELAY_OFF, _T("RELAYOFF.WAV"));
-#endif
+       event->set_context_sound(drec->get_context_noise_play());
+       event->set_context_sound(drec->get_context_noise_stop());
+       event->set_context_sound(drec->get_context_noise_fast());
+       
        via->set_context_port_a(memory, SIG_MEMORY_VIA_PORT_A, 0xff, 0);
        via->set_context_port_b(memory, SIG_MEMORY_VIA_PORT_B, 0xff, 0);
        via->set_context_port_b(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0);      // PB7 -> Speaker
@@ -82,7 +71,7 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        not_ear->set_context_out(via, SIG_SY6522_PORT_CA1, 1);
        not_ear->set_context_out(via, SIG_SY6522_PORT_CB1, 1);
        // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
-       pcm->set_realtime_render(true);
+       //pcm->set_realtime_render(true);
        
        memory->set_context_via(via);
        
@@ -93,6 +82,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
 #endif
        
        // 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();
        }
@@ -207,12 +199,6 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
                drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
                drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
        }
-#if defined(USE_SOUND_FILES)
-       else if(ch == 2) {
-               drec->set_volume(2 + DATAREC_SNDFILE_RELAY_ON,  decibel_l, decibel_r);
-               drec->set_volume(2 + DATAREC_SNDFILE_RELAY_OFF, decibel_l, decibel_r);
-       }
-#endif
 }
 #endif
 
@@ -220,64 +206,69 @@ void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
 // user interface
 // ----------------------------------------------------------------------------
 
-void VM::play_tape(const _TCHAR* file_path)
+void VM::play_tape(int drv, const _TCHAR* file_path)
 {
        drec->play_tape(file_path);
-       push_play();
+//     drec->set_remote(true);
 }
 
-void VM::rec_tape(const _TCHAR* file_path)
+void VM::rec_tape(int drv, const _TCHAR* file_path)
 {
        drec->rec_tape(file_path);
-       push_play();
+//     drec->set_remote(true);
 }
 
-void VM::close_tape()
+void VM::close_tape(int drv)
 {
-       push_stop();
        emu->lock_vm();
        drec->close_tape();
        emu->unlock_vm();
+//     drec->set_remote(false);
 }
 
-bool VM::is_tape_inserted()
+bool VM::is_tape_inserted(int drv)
 {
        return drec->is_tape_inserted();
 }
 
-bool VM::is_tape_playing()
+bool VM::is_tape_playing(int drv)
 {
        return drec->is_tape_playing();
 }
 
-bool VM::is_tape_recording()
+bool VM::is_tape_recording(int drv)
 {
        return drec->is_tape_recording();
 }
 
-int VM::get_tape_position()
+int VM::get_tape_position(int drv)
 {
        return drec->get_tape_position();
 }
 
-void VM::push_play()
+const _TCHAR* VM::get_tape_message(int drv)
+{
+       return drec->get_message();
+}
+
+void VM::push_play(int drv)
 {
        drec->set_ff_rew(0);
        drec->set_remote(true);
 }
 
-void VM::push_stop()
+void VM::push_stop(int drv)
 {
        drec->set_remote(false);
 }
 
-void VM::push_fast_forward()
+void VM::push_fast_forward(int drv)
 {
        drec->set_ff_rew(1);
        drec->set_remote(true);
 }
 
-void VM::push_fast_rewind()
+void VM::push_fast_rewind(int drv)
 {
        drec->set_ff_rew(-1);
        drec->set_remote(true);
@@ -295,27 +286,38 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  2
+#define STATE_VERSION  3
 
-void VM::save_state(FILEIO* state_fio)
+bool VM::process_state(FILEIO* state_fio, bool loading)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       
-       for(DEVICE* device = first_device; device; device = device->next_device) {
-               device->save_state(state_fio);
-       }
-}
-
-bool VM::load_state(FILEIO* state_fio)
-{
-       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;
+               }
+       }
        return true;
 }
-