2 National JR-800 Emulator 'eJR-800'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
16 #include "../hd44102.h"
17 //#include "../mc6800.h"
18 #include "../hd6301.h"
19 #include "../memory.h"
21 #include "../pcm1bit.h"
24 #include "../debugger.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 VM::VM(EMU* parent_emu) : emu(parent_emu)
36 first_device = last_device = NULL;
37 dummy = new DEVICE(this, emu); // must be 1st device
38 event = new EVENT(this, emu); // must be 2nd device
40 drec = new DATAREC(this, emu);
41 drec->set_context_noise_play(new NOISE(this, emu));
42 drec->set_context_noise_stop(new NOISE(this, emu));
43 drec->set_context_noise_fast(new NOISE(this, emu));
44 for(int i = 0; i < 8; i++) {
45 lcd[i] = new HD44102(this, emu);
47 // cpu = new MC6800(this, emu);
48 cpu = new HD6301(this, emu);
49 memory = new MEMORY(this, emu);
50 pcm = new PCM1BIT(this, emu);
52 io = new IO(this, emu);
55 event->set_context_cpu(cpu);
56 event->set_context_sound(drec);
57 event->set_context_sound(pcm);
58 event->set_context_sound(drec->get_context_noise_play());
59 event->set_context_sound(drec->get_context_noise_stop());
60 event->set_context_sound(drec->get_context_noise_fast());
62 // cpu->set_context_port1(drec, SIG_DATAREC_MIC, 0x01, 0);
63 cpu->set_context_port1(pcm, SIG_PCM1BIT_ON, 0x08, 0);
64 cpu->set_context_port1(pcm, SIG_PCM1BIT_SIGNAL, 0x10, 0);
66 for(int i = 0; i < 8; i++) {
67 io->set_context_lcd(i, lcd[i]);
71 cpu->set_context_mem(memory);
73 cpu->set_context_debugger(new DEBUGGER(this, emu));
77 memset(ram, 0x00, sizeof(ram));
78 memset(rom, 0xff, sizeof(rom));
80 memory->read_bios(_T("BASIC.ROM"), rom, sizeof(rom));
82 memory->set_memory_rw(0x2000, 0x7fff, ram);
83 memory->set_memory_r(0x8000, 0xffff, rom);
84 memory->set_memory_mapped_io_rw(0x0a00, 0x0bff, io);
85 memory->set_memory_mapped_io_rw(0x0d00, 0x0fff, io);
87 // initialize all devices
88 for(DEVICE* device = first_device; device; device = device->next_device) {
96 for(DEVICE* device = first_device; device;) {
97 DEVICE *next_device = device->next_device;
100 device = next_device;
104 DEVICE* VM::get_device(int id)
106 for(DEVICE* device = first_device; device; device = device->next_device) {
107 if(device->this_device_id == id) {
114 // ----------------------------------------------------------------------------
115 // drive virtual machine
116 // ----------------------------------------------------------------------------
121 for(DEVICE* device = first_device; device; device = device->next_device) {
124 cpu->write_signal(SIG_MC6801_PORT_1, 0x00, 0xff);
125 cpu->write_signal(SIG_MC6801_PORT_2, 0x00, 0xff);
126 cpu->write_signal(SIG_MC6801_PORT_3, 0x00, 0xff);
127 cpu->write_signal(SIG_MC6801_PORT_4, 0x00, 0xff);
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
140 DEVICE *VM::get_cpu(int index)
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 void VM::draw_screen()
155 for(int y = 0; y < 2; y++) {
156 for(int x = 0; x < 4; x++) {
157 lcd[x + 4 * y]->screen_update(50 * x - 4, 32 * y, y == 0);
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 void VM::initialize_sound(int rate, int samples)
168 // init sound manager
169 event->initialize_sound(rate, samples);
172 pcm->initialize_sound(rate, 8000);
175 uint16_t* VM::create_sound(int* extra_frames)
177 return event->create_sound(extra_frames);
180 int VM::get_sound_buffer_ptr()
182 return event->get_sound_buffer_ptr();
185 #ifdef USE_SOUND_VOLUME
186 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
189 pcm->set_volume(0, decibel_l, decibel_r);
191 drec->set_volume(0, decibel_l, decibel_r);
193 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
194 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
195 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void VM::play_tape(int drv, const _TCHAR* file_path)
206 drec->play_tape(file_path);
209 void VM::rec_tape(int drv, const _TCHAR* file_path)
211 drec->rec_tape(file_path);
214 void VM::close_tape(int drv)
221 bool VM::is_tape_inserted(int drv)
223 return drec->is_tape_inserted();
226 bool VM::is_tape_playing(int drv)
228 return drec->is_tape_playing();
231 bool VM::is_tape_recording(int drv)
233 return drec->is_tape_recording();
236 int VM::get_tape_position(int drv)
238 return drec->get_tape_position();
241 const _TCHAR* VM::get_tape_message(int drv)
243 return drec->get_message();
246 bool VM::is_frame_skippable()
248 return event->is_frame_skippable();
251 void VM::update_config()
253 for(DEVICE* device = first_device; device; device = device->next_device) {
254 device->update_config();
258 #define STATE_VERSION 3
260 void VM::save_state(FILEIO* state_fio)
262 state_fio->FputUint32(STATE_VERSION);
264 for(DEVICE* device = first_device; device; device = device->next_device) {
265 device->save_state(state_fio);
267 state_fio->Fwrite(ram, sizeof(ram), 1);
270 bool VM::load_state(FILEIO* state_fio)
272 if(state_fio->FgetUint32() != STATE_VERSION) {
275 for(DEVICE* device = first_device; device; device = device->next_device) {
276 if(!device->load_state(state_fio)) {
280 state_fio->Fread(ram, sizeof(ram), 1);