#include "../i8255.h"
#include "../i8259.h"
#include "../io.h"
+#include "../noise.h"
#include "../upd1990a.h"
#include "../upd7220.h"
#include "../upd765a.h"
+#ifdef USE_DEBUGGER
+#include "../debugger.h"
+#endif
+
#include "display.h"
#include "floppy.h"
#include "keyboard.h"
-#include "memory.h"
+#include "./memory.h"
#include "system.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);
cpu = new I386(this, emu);
dma = new I8237(this, emu);
sio_r = new I8251(this, emu); // for rs232c
+ sio_r->set_device_name(_T("8251 SIO (RS-232C)"));
sio_k = new I8251(this, emu); // for keyboard
+ sio_k->set_device_name(_T("8251 SIO (Keyboard)"));
pit = new I8253(this, emu);
pio_s = new I8255(this, emu); // for system port
+ pio_s->set_device_name(_T("8255 PIO (System)"));
pio_p = new I8255(this, emu); // for printer
+ pio_p->set_device_name(_T("8255 PIO (Printer)"));
pic = new I8259(this, emu);
io = new IO(this, emu);
rtc = new UPD1990A(this, emu);
gdc_c = new UPD7220(this, emu);
+ gdc_c->set_device_name(_T("uPD7220 GDC (Character)"));
gdc_g = new UPD7220(this, emu);
+ gdc_g->set_device_name(_T("uPD7220 GDC (Graphics)"));
fdc = new UPD765A(this, emu);
+ 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));
display = new DISPLAY(this, emu);
floppy = new FLOPPY(this, emu);
keyboard = new KEYBOARD(this, emu);
- memory = new MEMORY(this, emu);
+ memory = new N5200_MEMORY(this, emu);
system = new SYSTEM(this, emu);
// set contexts
event->set_context_cpu(cpu);
event->set_context_sound(beep);
+ event->set_context_sound(fdc->get_context_noise_seek());
+ event->set_context_sound(fdc->get_context_noise_head_down());
+ event->set_context_sound(fdc->get_context_noise_head_up());
//??? sio_r->set_context_rxrdy(pic, SIG_I8259_CHIP0 | SIG_I8259_IR4, 1);
sio_k->set_context_rxrdy(pic, SIG_I8259_CHIP0 | SIG_I8259_IR1, 1);
cpu->set_context_mem(memory);
cpu->set_context_io(io);
cpu->set_context_intr(pic);
+#ifdef USE_DEBUGGER
+ cpu->set_context_debugger(new DEBUGGER(this, emu));
+#endif
// i/o bus
io->set_iomap_alias_w(0x00, pic, 0);
io->set_iomap_single_r(0xbe, floppy);
// 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();
}
}
// ----------------------------------------------------------------------------
-// draw screen
+// debugger
// ----------------------------------------------------------------------------
-void VM::draw_screen()
+#ifdef USE_DEBUGGER
+DEVICE *VM::get_cpu(int index)
{
- display->draw_screen();
+ if(index == 0) {
+ return cpu;
+ }
+ return NULL;
}
+#endif
+
+// ----------------------------------------------------------------------------
+// draw screen
+// ----------------------------------------------------------------------------
-int VM::access_lamp()
+void VM::draw_screen()
{
- uint32 status = fdc->read_signal(0);
- return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
+ display->draw_screen();
}
// ----------------------------------------------------------------------------
event->initialize_sound(rate, samples);
// init sound gen
- beep->init(rate, 2400, 8000);
+ beep->initialize_sound(rate, 2400, 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->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
+ fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
+ fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
+ }
}
+#endif
// ----------------------------------------------------------------------------
// notify key
void VM::key_up(int code)
{
keyboard->key_up(code);
-// emu->out_debug_log(_T("-----\n"));
+}
+
+bool VM::get_caps_locked()
+{
+ return keyboard->get_caps_locked();
+}
+
+bool VM::get_kana_locked()
+{
+ return keyboard->get_kana_locked();
}
// ----------------------------------------------------------------------------
// user interface
// ----------------------------------------------------------------------------
-void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
+void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
{
fdc->open_disk(drv, file_path, bank);
}
-void VM::close_disk(int drv)
+void VM::close_floppy_disk(int drv)
{
fdc->close_disk(drv);
}
-bool VM::disk_inserted(int drv)
+bool VM::is_floppy_disk_inserted(int drv)
{
- return fdc->disk_inserted(drv);
+ return fdc->is_disk_inserted(drv);
}
-void VM::set_disk_protected(int drv, bool value)
+void VM::is_floppy_disk_protected(int drv, bool value)
{
- fdc->set_disk_protected(drv, value);
+ fdc->is_disk_protected(drv, value);
}
-bool VM::get_disk_protected(int drv)
+bool VM::is_floppy_disk_protected(int drv)
{
- return fdc->get_disk_protected(drv);
+ return fdc->is_disk_protected(drv);
}
-bool VM::now_skip()
+uint32_t VM::is_floppy_disk_accessed()
{
- return event->now_skip();
+ return fdc->read_signal(0);
+}
+
+bool VM::is_frame_skippable()
+{
+ return event->is_frame_skippable();
}
void VM::update_config()
}
}
+#define STATE_VERSION 1
+
+bool VM::process_state(FILEIO* state_fio, bool loading)
+{
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ 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;
+}
+