OSDN Git Service

[BUILD] Set SOVERSION and GIT hash automatically.
[csp-qt/common_source_project-fm7.git] / source / src / vm / msx / msx.cpp
index 61fe2f3..e504736 100644 (file)
 #if defined(_PX7)
 #include "../ld700.h"
 #endif
+#include "../noise.h"
 #include "../not.h"
-#include "../ym2203.h"
+//#include "../ym2203.h"
+#include "../ay_3_891x.h"
 #include "../pcm1bit.h"
 #if defined(_MSX2)
 #include "../rp5c01.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"));
+       event->set_device_name(_T("EVENT"));
        
        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));
        pio = new I8255(this, emu);
        io = new IO(this, emu);
 #if defined(_PX7)
        ldp = new LD700(this, emu);
 #endif
-       d_not = new NOT(this, emu);
-       psg = new YM2203(this, emu);
+       not_remote = new NOT(this, emu);
+//     psg = new YM2203(this, emu);
+       psg = new AY_3_891X(this, emu);
        pcm = new PCM1BIT(this, emu);
+       not_remote->set_device_name(_T("NOT Gate (REMOTE)"));
+
 #if defined(_MSX2)
        rtc = new RP5C01(this, emu);
        vdp = new V99X8(this, emu);
@@ -72,7 +82,6 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        vdp = new TMS9918A(this, emu);
 #endif
        cpu = new Z80(this, emu);
-       
        joystick = new JOYSTICK(this, emu);
        keyboard = new KEYBOARD(this, emu);
        memory = new MEMORY(this, emu);
@@ -83,7 +92,12 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        slot1 = new SLOT1(this, emu);   // #1: rom-cartridge or msx-dos
        slot2 = new SLOT2(this, emu);   // #2: fdd-cartridge or p-basic
        slot3 = new SLOT3(this, emu);   // #3: rom-cartridge or ram-cartridge
-       
+
+       slot0->set_device_name(_T("SLOT#0 MAIN MEMORY"));
+       slot1->set_device_name(_T("SLOT#1 ROM CARTRIDGE"));
+       slot2->set_device_name(_T("SLOT#2 FDD CARTRIDGE"));
+       slot3->set_device_name(_T("SLOT#3 ROM CARTRIDGE"));
+
        // set contexts
        event->set_context_cpu(cpu);
        event->set_context_sound(psg);
@@ -92,23 +106,26 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
 #if defined(_PX7)
        event->set_context_sound(ldp);
 #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());
        
-       drec->set_context_out(psg, SIG_YM2203_PORT_A, 0x80);
+       drec->set_context_ear(psg, SIG_AY_3_891X_PORT_A, 0x80);
        pio->set_context_port_a(memory, SIG_MEMORY_SEL, 0xff, 0);
        pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x0f, 0);
-       pio->set_context_port_c(d_not, SIG_NOT_INPUT, 0x10, 0);
-       d_not->set_context_out(drec, SIG_DATAREC_REMOTE, 1);
-       pio->set_context_port_c(drec, SIG_DATAREC_OUT, 0x20, 0);
+       pio->set_context_port_c(not_remote, SIG_NOT_INPUT, 0x10, 0);
+       not_remote->set_context_out(drec, SIG_DATAREC_REMOTE, 1);
+       pio->set_context_port_c(drec, SIG_DATAREC_MIC, 0x20, 0);
        pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0);
        psg->set_context_port_b(joystick, SIG_JOYSTICK_SEL, 0x40, 0);
        vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
+
 #if defined(_PX7)
        pio->set_context_port_c(slot2, SIG_SLOT2_MUTE, 0x10, 0);
        ldp->set_context_exv(slot2, SIG_SLOT2_EXV, 1);
        ldp->set_context_ack(slot2, SIG_SLOT2_ACK, 1);
-       ldp->set_context_sound(psg, SIG_YM2203_PORT_A, 0x80);
+       ldp->set_context_sound(psg, SIG_AY_3_891X_PORT_A, 0x80);
 #endif
-       
        joystick->set_context_psg(psg);
 //     keyboard->set_context_cpu(cpu);
        keyboard->set_context_pio(pio);
@@ -150,6 +167,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        io->set_iomap_range_rw(0xfc, 0xff, memory);
        
        // 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();
        }
@@ -226,35 +246,56 @@ void VM::initialize_sound(int rate, int samples)
        event->initialize_sound(rate, samples);
        
        // init sound gen
-       psg->init(rate, 3579545, samples, 0, 0);
-       pcm->init(rate, 8000);
+       psg->initialize_sound(rate, 3579545, samples, 0, 0);
+       pcm->initialize_sound(rate, 8000);
 #if defined(_PX7)
        ldp->initialize_sound(rate, samples);
 #endif
 }
 
-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();
 }
 
 #if defined(_PX7)
-void VM::movie_sound_callback(uint8 *buffer, long size)
+void VM::movie_sound_callback(uint8_t *buffer, long size)
 {
        ldp->movie_sound_callback(buffer, size);
 }
 #endif
 
+#ifdef USE_SOUND_VOLUME
+void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
+{
+       if(ch-- == 0) {
+               psg->set_volume(1, decibel_l, decibel_r);
+       } else if(ch-- == 0) {
+               pcm->set_volume(0, decibel_l, decibel_r);
+       } else if(ch-- == 0) {
+               drec->set_volume(0, decibel_l, decibel_r);
+#if defined(_PX7)
+       } else if(ch-- == 0) {
+               ldp->set_volume(0, decibel_l, decibel_r);
+#endif
+       } else if(ch-- == 0) {
+               drec->get_context_noise_play()->set_volume(0, decibel_l, 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);
+       }
+}
+#endif
+
 // ----------------------------------------------------------------------------
 // user interface
 // ----------------------------------------------------------------------------
 
-void VM::open_cart(int drv, _TCHAR* file_path)
+void VM::open_cart(int drv, const _TCHAR* file_path)
 {
        if(drv == 0) {
                slot1->open_cart(file_path);
@@ -274,96 +315,145 @@ void VM::close_cart(int drv)
        reset();
 }
 
-bool VM::cart_inserted(int drv)
+bool VM::is_cart_inserted(int drv)
 {
        if(drv == 0) {
-               return slot1->cart_inserted();
+               return slot1->is_cart_inserted();
        } else {
-               return slot3->cart_inserted();
+               return slot3->is_cart_inserted();
        }
 }
 
-void VM::play_tape(_TCHAR* file_path)
+void VM::play_tape(int drv, const _TCHAR* file_path)
 {
        drec->play_tape(file_path);
+//     drec->set_remote(true);
 }
 
-void VM::rec_tape(_TCHAR* file_path)
+void VM::rec_tape(int drv, const _TCHAR* file_path)
 {
        drec->rec_tape(file_path);
+//     drec->set_remote(true);
 }
 
-void VM::close_tape()
+void VM::close_tape(int drv)
 {
+       emu->lock_vm();
        drec->close_tape();
+       emu->unlock_vm();
+//     drec->set_remote(false);
 }
 
-bool VM::tape_inserted()
+bool VM::is_tape_inserted(int drv)
 {
-       return drec->tape_inserted();
+       return drec->is_tape_inserted();
 }
 
-#if defined(USE_TAPE_PTR)
-int VM::get_tape_ptr(void)
+bool VM::is_tape_playing(int drv)
 {
-        return drec->get_tape_ptr();
+       return drec->is_tape_playing();
+}
+
+bool VM::is_tape_recording(int drv)
+{
+       return drec->is_tape_recording();
+}
+
+int VM::get_tape_position(int drv)
+{
+       return drec->get_tape_position();
+}
+
+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(int drv)
+{
+       drec->set_remote(false);
+}
+
+void VM::push_fast_forward(int drv)
+{
+       drec->set_ff_rew(1);
+       drec->set_remote(true);
+}
+
+void VM::push_fast_rewind(int drv)
+{
+       drec->set_ff_rew(-1);
+       drec->set_remote(true);
+}
+
+void VM::load_binary(int drv, const _TCHAR* file_path)
+{
+       if(drv == 0) {
+               pac2->open_rampac2(file_path);
+       }
 }
-#endif
 
 #if defined(_PX7)
-void VM::open_laser_disc(_TCHAR* file_path)
+void VM::open_laser_disc(int drv, const _TCHAR* file_path)
 {
        ldp->open_disc(file_path);
 }
 
-void VM::close_laser_disc()
+void VM::close_laser_disc(int drv)
 {
        ldp->close_disc();
 }
 
-bool VM::laser_disc_inserted()
+bool VM::is_laser_disc_inserted(int drv)
+{
+       return ldp->is_disc_inserted();
+}
+
+uint32_t VM::is_laser_disc_accessed()
 {
-       return ldp->disc_inserted();
+       return lpd->read_signal(0);
 }
 #else
-void VM::open_disk(int drv, _TCHAR* file_path, int bank)
+void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
 {
        memory->open_disk(drv, file_path, bank);
 }
 
-void VM::close_disk(int drv)
+void VM::close_floppy_disk(int drv)
 {
        memory->close_disk(drv);
 }
 
-bool VM::disk_inserted(int drv)
+bool VM::is_floppy_disk_inserted(int drv)
 {
-       return memory->disk_inserted(drv);
+       return memory->is_disk_inserted(drv);
 }
 
-#if defined(USE_DISK_WRITE_PROTECT)
-void VM::write_protect_fd(int drv, bool flag)
+void VM::is_floppy_disk_protected(int drv, bool value)
 {
-       //fdc->write_protect_fd(drv, flag);
+       memory->is_disk_protected(drv, value);
 }
- bool VM::is_write_protect_fd(int drv)
+
+bool VM::is_floppy_disk_protected(int drv)
 {
-        //return fdc->is_write_protect_fd(drv);
-       return false;
+       return memory->is_disk_protected(drv);
 }
-#endif
 
-//int VM::access_lamp()
-//{
-//     //uint32 status = fdc->read_signal(0);
-//     //return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
-//     return 0;
-//}
+uint32_t VM::is_floppy_disk_accessed()
+{
+       return memory->read_signal(0);
+}
 #endif
 
-bool VM::now_skip()
+bool VM::is_frame_skippable()
 {
-       return event->now_skip();
+       return event->is_frame_skippable();
 }
 
 void VM::update_config()
@@ -373,7 +463,7 @@ void VM::update_config()
        }
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  4
 
 void VM::save_state(FILEIO* state_fio)
 {