2 National JR-100 Emulator 'eJR-100'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
16 //#include "../mc6800.h"
17 #include "../mb8861.h"
20 #include "../pcm1bit.h"
21 #include "../sy6522.h"
24 #include "../debugger.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
37 first_device = last_device = NULL;
38 dummy = new DEVICE(this, emu); // must be 1st device
39 event = new EVENT(this, emu); // must be 2nd device
40 dummy->set_device_name(_T("1st Dummy"));
42 drec = new DATAREC(this, emu);
43 drec->set_context_noise_play(new NOISE(this, emu));
44 drec->set_context_noise_stop(new NOISE(this, emu));
45 drec->set_context_noise_fast(new NOISE(this, emu));
46 //cpu = new MC6800(this, emu); // MB8861N
47 cpu = new MB8861(this, emu); // MB8861N
48 not_mic = new NOT(this, emu);
49 not_mic->set_device_name(_T("NOT Gate (Mic)"));
50 not_ear = new NOT(this, emu);
51 not_ear->set_device_name(_T("NOT Gate (Ear)"));
52 pcm = new PCM1BIT(this, emu);
53 via = new SY6522(this, emu);
55 memory = new MEMORY(this, emu);
57 event->set_context_cpu(cpu);
58 event->set_context_sound(pcm);
59 event->set_context_sound(drec);
60 event->set_context_sound(drec->get_context_noise_play());
61 event->set_context_sound(drec->get_context_noise_stop());
62 event->set_context_sound(drec->get_context_noise_fast());
64 via->set_context_port_a(memory, SIG_MEMORY_VIA_PORT_A, 0xff, 0);
65 via->set_context_port_b(memory, SIG_MEMORY_VIA_PORT_B, 0xff, 0);
66 via->set_context_port_b(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0); // PB7 -> Speaker
67 via->set_context_port_b(via, SIG_MEMORY_VIA_PORT_B, 0x80, -1); // PB7 -> PB6
68 via->set_context_cb2(not_mic, SIG_NOT_INPUT, 1); // CB2 -> NOT -> MIC
69 via->set_constant_clock(CPU_CLOCKS >> 2);
70 not_mic->set_context_out(drec, SIG_DATAREC_MIC, 1);
71 drec->set_context_ear(not_ear, SIG_NOT_INPUT, 1); // EAR -> NOT -> CA1,CB1
72 not_ear->set_context_out(via, SIG_SY6522_PORT_CA1, 1);
73 not_ear->set_context_out(via, SIG_SY6522_PORT_CB1, 1);
74 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
75 //pcm->set_realtime_render(true);
77 memory->set_context_via(via);
80 cpu->set_context_mem(memory);
82 cpu->set_context_debugger(new DEBUGGER(this, emu));
83 // pcm->set_context_debugger(new DEBUGGER(this, emu));
86 // initialize all devices
87 #if defined(__GIT_REPO_VERSION)
88 set_git_repo_version(__GIT_REPO_VERSION);
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) {
126 void VM::special_reset(int num)
129 for(DEVICE* device = first_device; device; device = device->next_device) {
139 double VM::get_frame_rate()
141 return event->get_frame_rate();
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
149 DEVICE *VM::get_cpu(int index)
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 void VM::draw_screen()
164 memory->draw_screen();
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 void VM::initialize_sound(int rate, int samples)
173 // init sound manager
174 event->initialize_sound(rate, samples);
177 pcm->initialize_sound(rate, 5000);
180 uint16_t* VM::create_sound(int* extra_frames)
182 return event->create_sound(extra_frames);
185 int VM::get_sound_buffer_ptr()
187 return event->get_sound_buffer_ptr();
190 #ifdef USE_SOUND_VOLUME
191 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
194 pcm->set_volume(0, decibel_l, decibel_r);
196 drec->set_volume(0, decibel_l, decibel_r);
198 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
199 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
200 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 void VM::play_tape(int drv, const _TCHAR* file_path)
211 bool remote = drec->get_remote();
213 if(drec->play_tape(file_path) && remote) {
214 // if machine already sets remote on, start playing now
219 void VM::rec_tape(int drv, const _TCHAR* file_path)
221 bool remote = drec->get_remote();
223 if(drec->rec_tape(file_path) && remote) {
224 // if machine already sets remote on, start recording now
229 void VM::close_tape(int drv)
234 drec->set_remote(false);
237 bool VM::is_tape_inserted(int drv)
239 return drec->is_tape_inserted();
242 bool VM::is_tape_playing(int drv)
244 return drec->is_tape_playing();
247 bool VM::is_tape_recording(int drv)
249 return drec->is_tape_recording();
252 int VM::get_tape_position(int drv)
254 return drec->get_tape_position();
257 const _TCHAR* VM::get_tape_message(int drv)
259 return drec->get_message();
262 void VM::push_play(int drv)
264 drec->set_remote(false);
266 drec->set_remote(true);
269 void VM::push_stop(int drv)
271 drec->set_remote(false);
274 void VM::push_fast_forward(int drv)
276 drec->set_remote(false);
278 drec->set_remote(true);
281 void VM::push_fast_rewind(int drv)
283 drec->set_remote(false);
284 drec->set_ff_rew(-1);
285 drec->set_remote(true);
288 bool VM::is_frame_skippable()
290 return event->is_frame_skippable();
293 void VM::update_config()
295 for(DEVICE* device = first_device; device; device = device->next_device) {
296 device->update_config();
300 double VM::get_current_usec()
302 if(event == NULL) return 0.0;
303 return event->get_current_usec();
306 uint64_t VM::get_current_clock_uint64()
308 if(event == NULL) return (uint64_t)0;
309 return event->get_current_clock_uint64();
312 #define STATE_VERSION 3
314 bool VM::process_state(FILEIO* state_fio, bool loading)
316 if(!(VM_TEMPLATE::process_state_core(state_fio, loading, STATE_VERSION))) {