OSDN Git Service

[VM][I286] Save cpustate without StateBuffer().
[csp-qt/common_source_project-fm7.git] / source / src / vm / hc20 / hc20.cpp
index 6dd43be..72953ca 100644 (file)
 #include "../event.h"
 
 #include "../beep.h"
+#include "../disk.h"
 #include "../hd146818p.h"
 #include "../i8255.h"
-#include "../mc6800.h"
+//#include "../mc6800.h"
+#include "../hd6301.h"
+#include "../noise.h"
 #include "../tf20.h"
 #include "../upd765a.h"
 #include "../z80.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
+       dummy->set_device_name(_T("1st Dummy"));
        
        beep = new BEEP(this, emu);
        rtc = new HD146818P(this, emu);
-       cpu = new MC6800(this, emu);
-       
+       //cpu = new MC6800(this, emu);
+       cpu = new HD6301(this, emu);
        tf20 = new TF20(this, emu);
        pio_tf20 = new I8255(this, emu);
        fdc_tf20 = new UPD765A(this, emu);
+       fdc_tf20->set_context_noise_seek(new NOISE(this, emu));
+       fdc_tf20->set_context_noise_head_down(new NOISE(this, emu));
+       fdc_tf20->set_context_noise_head_up(new NOISE(this, emu));
        cpu_tf20 = new Z80(this, emu);
        sio_tf20 = new Z80SIO(this, emu);
-       
-       memory = new MEMORY(this, emu);
-       
+       pio_tf20->set_device_name(_T("TF20 PIO(i8255)"));
+       cpu_tf20->set_device_name(_T("TF20 CPU(Z80)"));
+       sio_tf20->set_device_name(_T("TF20 SIO(Z80 SIO)"));
+       fdc_tf20->set_device_name(_T("TF20 FDC(uPD765A)"));
+       memory = new HC20_MEMORY(this, emu);
        // set contexts
        event->set_context_cpu(cpu);
        event->set_context_cpu(cpu_tf20, 4000000);
        event->set_context_sound(beep);
+       event->set_context_sound(fdc_tf20->get_context_noise_seek());
+       event->set_context_sound(fdc_tf20->get_context_noise_head_down());
+       event->set_context_sound(fdc_tf20->get_context_noise_head_up());
        
 /*
        memory:
@@ -132,9 +144,15 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        sio_tf20->set_rx_clock(1, 4915200 / 8);
        
        // 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();
        }
+       for(int i = 0; i < MAX_DRIVE; i++) {
+               fdc_tf20->set_drive_type(i, DRIVE_TYPE_2D);
+       }
 }
 
 VM::~VM()
@@ -174,7 +192,7 @@ void VM::reset()
 
 void VM::notify_power_off()
 {
-//     emu->out_debug_log("--- POWER OFF ---\n");
+//     this->out_debug_log(T("--- POWER OFF ---\n"));
        memory->notify_power_off();
 }
 
@@ -192,6 +210,8 @@ DEVICE *VM::get_cpu(int index)
 {
        if(index == 0) {
                return cpu;
+       } else if(index == 1) {
+               return cpu_tf20;
        }
        return NULL;
 }
@@ -206,12 +226,6 @@ void VM::draw_screen()
        memory->draw_screen();
 }
 
-int VM::access_lamp()
-{
-       uint32 status = fdc_tf20->read_signal(0);
-       return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
-}
-
 // ----------------------------------------------------------------------------
 // soud manager
 // ----------------------------------------------------------------------------
@@ -222,19 +236,32 @@ void VM::initialize_sound(int rate, int samples)
        event->initialize_sound(rate, samples);
        
        // init sound gen
-       beep->init(rate, 1000, 8000);
+       beep->initialize_sound(rate, 1000, 8000);
 }
 
-uint16* VM::create_sound(int* extra_frames)
+uint16_t* VM::create_sound(int* extra_frames)
 {
        return event->create_sound(extra_frames);
 }
 
-int VM::sound_buffer_ptr()
+int VM::get_sound_buffer_ptr()
 {
-       return event->sound_buffer_ptr();
+       return event->get_sound_buffer_ptr();
 }
 
+#ifdef USE_SOUND_VOLUME
+void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
+{
+       if(ch == 0) {
+               beep->set_volume(0, decibel_l, decibel_r);
+       } else if(ch == 1) {
+               fdc_tf20->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
+               fdc_tf20->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
+               fdc_tf20->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
+       }
+}
+#endif
+
 // ----------------------------------------------------------------------------
 // notify key
 // ----------------------------------------------------------------------------
@@ -253,63 +280,59 @@ void VM::key_up(int code)
 // user interface
 // ----------------------------------------------------------------------------
 
-void VM::open_disk(int drv, _TCHAR* file_path, int bank)
+void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
 {
        fdc_tf20->open_disk(drv, file_path, bank);
 }
 
-void VM::close_disk(int drv)
+void VM::close_floppy_disk(int drv)
 {
        fdc_tf20->close_disk(drv);
 }
 
-bool VM::disk_inserted(int drv)
+bool VM::is_floppy_disk_inserted(int drv)
 {
-       return fdc_tf20->disk_inserted(drv);
+       return fdc_tf20->is_disk_inserted(drv);
 }
 
-#if defined(USE_DISK_WRITE_PROTECT)
-bool VM::is_write_protect_fd(int drv)
+void VM::is_floppy_disk_protected(int drv, bool value)
 {
-       return fdc_tf20->is_write_protect_fd(drv);
+       fdc_tf20->is_disk_protected(drv, value);
 }
 
-void VM::write_protect_fd(int drv, bool flag)
+bool VM::is_floppy_disk_protected(int drv)
 {
-       fdc_tf20->write_protect_fd(drv, flag);
+       return fdc_tf20->is_disk_protected(drv);
 }
-#endif
 
-void VM::play_tape(_TCHAR* file_path)
+uint32_t VM::is_floppy_disk_accessed()
 {
-       memory->play_tape(file_path);
+       return fdc_tf20->read_signal(0);
 }
 
-void VM::rec_tape(_TCHAR* file_path)
+void VM::play_tape(int drv, const _TCHAR* file_path)
 {
-       memory->rec_tape(file_path);
+       memory->play_tape(file_path);
 }
 
-void VM::close_tape()
+void VM::rec_tape(int drv, const _TCHAR* file_path)
 {
-       memory->close_tape();
+       memory->rec_tape(file_path);
 }
 
-bool VM::tape_inserted()
+void VM::close_tape(int drv)
 {
-       return memory->tape_inserted();
+       memory->close_tape();
 }
 
-#if defined(USE_TAPE_PTR)
-int VM::get_tape_ptr(void)
+bool VM::is_tape_inserted(int drv)
 {
-        return memory->get_tape_ptr();
+       return memory->is_tape_inserted();
 }
-#endif
 
-bool VM::now_skip()
+bool VM::is_frame_skippable()
 {
-       return event->now_skip();
+       return event->is_frame_skippable();
 }
 
 void VM::update_config()
@@ -319,27 +342,38 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  1
+#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;
 }
-