OSDN Git Service

[General] Merge Updtream 2020-08-10.
[csp-qt/common_source_project-fm7.git] / source / src / vm / pasopia / pasopia.cpp
index b3edcfb..2254bf1 100644 (file)
 #include "./memory.h"
 #include "pac2.h"
 
+using PASOPIA::DISPLAY;
+using PASOPIA::FLOPPY;
+using PASOPIA::KEYBOARD;
+using PASOPIA::MEMORY;
+using PASOPIA::PAC2;
+
+
 // ----------------------------------------------------------------------------
 // initialize
 // ----------------------------------------------------------------------------
 
-VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
+VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
 {
        boot_mode = config.boot_mode;
        
@@ -65,7 +72,13 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
        flipflop = new LS393(this, emu); // LS74
        not_remote = new NOT(this, emu);
        pcm = new PCM1BIT(this, emu);
+#ifdef USE_DEBUGGER
+//     pcm->set_context_debugger(new DEBUGGER(this, emu));
+#endif
        fdc = new UPD765A(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));
@@ -76,7 +89,7 @@ VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
        floppy = new FLOPPY(this, emu);
        display = new DISPLAY(this, emu);
        key = new KEYBOARD(this, emu);
-       memory = new PASOPIA_MEMORY(this, emu);
+       memory = new MEMORY(this, emu);
        pac2 = new PAC2(this, emu);
        // set contexts
        event->set_context_cpu(cpu);
@@ -346,14 +359,22 @@ uint32_t VM::is_floppy_disk_accessed()
 
 void VM::play_tape(int drv, const _TCHAR* file_path)
 {
-       drec->play_tape(file_path);
-//     drec->set_remote(true);
+       bool remote = drec->get_remote();
+       
+       if(drec->play_tape(file_path) && remote) {
+               // if machine already sets remote on, start playing now
+               push_play(drv);
+       }
 }
 
 void VM::rec_tape(int drv, const _TCHAR* file_path)
 {
-       drec->rec_tape(file_path);
-//     drec->set_remote(true);
+       bool remote = drec->get_remote();
+       
+       if(drec->rec_tape(file_path) && remote) {
+               // if machine already sets remote on, start recording now
+               push_play(drv);
+       }
 }
 
 void VM::close_tape(int drv)
@@ -361,7 +382,7 @@ void VM::close_tape(int drv)
        emu->lock_vm();
        drec->close_tape();
        emu->unlock_vm();
-//     drec->set_remote(false);
+       drec->set_remote(false);
 }
 
 bool VM::is_tape_inserted(int drv)
@@ -391,6 +412,7 @@ const _TCHAR* VM::get_tape_message(int drv)
 
 void VM::push_play(int drv)
 {
+       drec->set_remote(false);
        drec->set_ff_rew(0);
        drec->set_remote(true);
 }
@@ -402,12 +424,14 @@ void VM::push_stop(int drv)
 
 void VM::push_fast_forward(int drv)
 {
+       drec->set_remote(false);
        drec->set_ff_rew(1);
        drec->set_remote(true);
 }
 
 void VM::push_fast_rewind(int drv)
 {
+       drec->set_remote(false);
        drec->set_ff_rew(-1);
        drec->set_remote(true);
 }
@@ -440,6 +464,18 @@ void VM::update_config()
        }
 }
 
+double VM::get_current_usec()
+{
+       if(event == NULL) return 0.0;
+       return event->get_current_usec();
+}
+
+uint64_t VM::get_current_clock_uint64()
+{
+               if(event == NULL) return (uint64_t)0;
+               return event->get_current_clock_uint64();
+}
+
 #define STATE_VERSION  3
 
 bool VM::process_state(FILEIO* state_fio, bool loading)
@@ -452,7 +488,7 @@ bool VM::process_state(FILEIO* state_fio, bool loading)
                // 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);
+               int len = (int)strlen(name);
                
                if(!state_fio->StateCheckInt32(len)) {
                        if(loading) {
@@ -474,6 +510,6 @@ bool VM::process_state(FILEIO* state_fio, bool loading)
                }
        }
        // Machine specified.
-       state_fio->StateInt32(boot_mode);
+       state_fio->StateValue(boot_mode);
        return true;
 }