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* 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));
85 // initialize all devices
86 #if defined(__GIT_REPO_VERSION)
87 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
89 for(DEVICE* device = first_device; device; device = device->next_device) {
97 for(DEVICE* device = first_device; device;) {
98 DEVICE *next_device = device->next_device;
101 device = next_device;
105 DEVICE* VM::get_device(int id)
107 for(DEVICE* device = first_device; device; device = device->next_device) {
108 if(device->this_device_id == id) {
115 // ----------------------------------------------------------------------------
116 // drive virtual machine
117 // ----------------------------------------------------------------------------
122 for(DEVICE* device = first_device; device; device = device->next_device) {
127 void VM::special_reset()
130 for(DEVICE* device = first_device; device; device = device->next_device) {
140 double VM::get_frame_rate()
142 return event->get_frame_rate();
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
150 DEVICE *VM::get_cpu(int index)
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 void VM::draw_screen()
165 memory->draw_screen();
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 void VM::initialize_sound(int rate, int samples)
174 // init sound manager
175 event->initialize_sound(rate, samples);
178 pcm->initialize_sound(rate, 5000);
181 uint16_t* VM::create_sound(int* extra_frames)
183 return event->create_sound(extra_frames);
186 int VM::get_sound_buffer_ptr()
188 return event->get_sound_buffer_ptr();
191 #ifdef USE_SOUND_VOLUME
192 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
195 pcm->set_volume(0, decibel_l, decibel_r);
197 drec->set_volume(0, decibel_l, decibel_r);
199 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
200 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
201 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 void VM::play_tape(int drv, const _TCHAR* file_path)
212 bool remote = drec->get_remote();
214 if(drec->play_tape(file_path) && remote) {
215 // if machine already sets remote on, start playing now
220 void VM::rec_tape(int drv, const _TCHAR* file_path)
222 bool remote = drec->get_remote();
224 if(drec->rec_tape(file_path) && remote) {
225 // if machine already sets remote on, start recording now
230 void VM::close_tape(int drv)
235 drec->set_remote(false);
238 bool VM::is_tape_inserted(int drv)
240 return drec->is_tape_inserted();
243 bool VM::is_tape_playing(int drv)
245 return drec->is_tape_playing();
248 bool VM::is_tape_recording(int drv)
250 return drec->is_tape_recording();
253 int VM::get_tape_position(int drv)
255 return drec->get_tape_position();
258 const _TCHAR* VM::get_tape_message(int drv)
260 return drec->get_message();
263 void VM::push_play(int drv)
265 drec->set_remote(false);
267 drec->set_remote(true);
270 void VM::push_stop(int drv)
272 drec->set_remote(false);
275 void VM::push_fast_forward(int drv)
277 drec->set_remote(false);
279 drec->set_remote(true);
282 void VM::push_fast_rewind(int drv)
284 drec->set_remote(false);
285 drec->set_ff_rew(-1);
286 drec->set_remote(true);
289 bool VM::is_frame_skippable()
291 return event->is_frame_skippable();
294 void VM::update_config()
296 for(DEVICE* device = first_device; device; device = device->next_device) {
297 device->update_config();
301 #define STATE_VERSION 3
303 bool VM::process_state(FILEIO* state_fio, bool loading)
305 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
308 for(DEVICE* device = first_device; device; device = device->next_device) {
309 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
310 // const char *name = typeid(*device).name();
311 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
312 const char *name = device->get_device_name();
313 int len = strlen(name);
315 if(!state_fio->StateCheckInt32(len)) {
317 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
321 if(!state_fio->StateCheckBuffer(name, len, 1)) {
323 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
327 if(!device->process_state(state_fio, loading)) {
329 printf("Data loading Error: DEVID=%d\n", device->this_device_id);