#include "../i8080.h"
#include "../i8155.h"
#include "../io.h"
+#include "../noise.h"
#include "../pcm1bit.h"
#include "../upd1990a.h"
#include "cmt.h"
#include "keyboard.h"
#include "lcd.h"
-#include "memory.h"
-
-#include "../../fileio.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;
event = new EVENT(this, emu); // must be 2nd device
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 I8080(this, emu);
pio = new I8155(this, emu);
io = new IO(this, 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);
event->set_context_sound(pcm);
event->set_context_sound(drec);
+ 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(cpu, SIG_I8085_SID, 1);
+ drec->set_context_ear(cpu, SIG_I8085_SID, 1);
cpu->set_context_sod(cmt, SIG_CMT_SOD, 1);
pio->set_context_port_a(rtc, SIG_UPD1990A_C0, 1, 0);
pio->set_context_port_a(rtc, SIG_UPD1990A_C1, 2, 0);
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();
}
event->initialize_sound(rate, samples);
// init sound gen
- pcm->init(rate, 8000);
+ pcm->initialize_sound(rate, 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) {
+ pcm->set_volume(0, decibel_l, decibel_r);
+ } else if(ch == 1) {
+ drec->set_volume(0, decibel_l, decibel_r);
+ } else if(ch == 2) {
+ 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
+
// ----------------------------------------------------------------------------
// notify key
// ----------------------------------------------------------------------------
{
}
+bool VM::get_caps_locked()
+{
+ return keyboard->get_caps_locked();
+}
+
+bool VM::get_kana_locked()
+{
+ return keyboard->get_kana_locked();
+}
+
// ----------------------------------------------------------------------------
// user interface
// ----------------------------------------------------------------------------
-void VM::play_tape(_TCHAR* file_path)
+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(_TCHAR* file_path)
+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);
}
-void VM::close_tape()
+void VM::close_tape(int drv)
{
+ emu->lock_vm();
drec->close_tape();
+ emu->unlock_vm();
+// drec->set_remote(false);
cmt->close_tape();
}
-bool VM::tape_inserted()
+bool VM::is_tape_inserted(int drv)
{
- return drec->tape_inserted() || cmt->tape_inserted();
+ return drec->is_tape_inserted() || cmt->is_tape_inserted();
}
-bool VM::now_skip()
+bool VM::is_tape_playing(int drv)
{
- return event->now_skip();
+ if(drec->is_tape_inserted()) {
+ return drec->is_tape_playing();
+ } else {
+ return cmt->is_tape_playing();
+ }
}
-void VM::update_config()
+bool VM::is_tape_recording(int drv)
{
- for(DEVICE* device = first_device; device; device = device->next_device) {
- device->update_config();
+ if(drec->is_tape_inserted()) {
+ return drec->is_tape_recording();
+ } else {
+ return cmt->is_tape_recording();
+ }
+}
+
+int VM::get_tape_position(int drv)
+{
+ if(drec->is_tape_inserted()) {
+ return drec->get_tape_position();
+ } else {
+ return cmt->get_tape_position();
}
}
-#define STATE_VERSION 1
+const _TCHAR* VM::get_tape_message(int drv)
+{
+ if(drec->is_tape_inserted()) {
+ return drec->get_message();
+ } else {
+ return NULL;
+ }
+}
-void VM::save_state(FILEIO* state_fio)
+void VM::push_play(int drv)
+{
+ if(drec->is_tape_inserted()) {
+ drec->set_ff_rew(0);
+ drec->set_remote(true);
+ }
+}
+
+void VM::push_stop(int drv)
+{
+ 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);
+ }
+}
+
+void VM::push_fast_rewind(int drv)
+{
+ if(drec->is_tape_inserted()) {
+ drec->set_ff_rew(-1);
+ drec->set_remote(true);
+ }
+}
+
+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;
}
-