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"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 VM::VM(EMU* parent_emu) : VM_TEMPLATE(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
39 dummy->set_device_name(_T("1st Dummy"));
41 drec = new DATAREC(this, emu);
42 drec->set_context_noise_play(new NOISE(this, emu));
43 drec->set_context_noise_stop(new NOISE(this, emu));
44 drec->set_context_noise_fast(new NOISE(this, emu));
45 //cpu = new MC6800(this, emu); // MB8861N
46 cpu = new MB8861(this, emu); // MB8861N
47 not_mic = new NOT(this, emu);
48 not_mic->set_device_name(_T("NOT Gate (Mic)"));
49 not_ear = new NOT(this, emu);
50 not_ear->set_device_name(_T("NOT Gate (Ear)"));
51 pcm = new PCM1BIT(this, emu);
52 via = new SY6522(this, emu);
54 memory = new MEMORY(this, emu);
56 event->set_context_cpu(cpu);
57 event->set_context_sound(pcm);
58 event->set_context_sound(drec);
59 event->set_context_sound(drec->get_context_noise_play());
60 event->set_context_sound(drec->get_context_noise_stop());
61 event->set_context_sound(drec->get_context_noise_fast());
63 via->set_context_port_a(memory, SIG_MEMORY_VIA_PORT_A, 0xff, 0);
64 via->set_context_port_b(memory, SIG_MEMORY_VIA_PORT_B, 0xff, 0);
65 via->set_context_port_b(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0); // PB7 -> Speaker
66 via->set_context_port_b(via, SIG_MEMORY_VIA_PORT_B, 0x80, -1); // PB7 -> PB6
67 via->set_context_cb2(not_mic, SIG_NOT_INPUT, 1); // CB2 -> NOT -> MIC
68 via->set_constant_clock(CPU_CLOCKS >> 2);
69 not_mic->set_context_out(drec, SIG_DATAREC_MIC, 1);
70 drec->set_context_ear(not_ear, SIG_NOT_INPUT, 1); // EAR -> NOT -> CA1,CB1
71 not_ear->set_context_out(via, SIG_SY6522_PORT_CA1, 1);
72 not_ear->set_context_out(via, SIG_SY6522_PORT_CB1, 1);
73 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
74 //pcm->set_realtime_render(true);
76 memory->set_context_via(via);
79 cpu->set_context_mem(memory);
81 cpu->set_context_debugger(new DEBUGGER(this, emu));
84 // initialize all devices
85 #if defined(__GIT_REPO_VERSION)
86 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
88 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 drec->play_tape(file_path);
213 // drec->set_remote(true);
216 void VM::rec_tape(int drv, const _TCHAR* file_path)
218 drec->rec_tape(file_path);
219 // drec->set_remote(true);
222 void VM::close_tape(int drv)
227 // drec->set_remote(false);
230 bool VM::is_tape_inserted(int drv)
232 return drec->is_tape_inserted();
235 bool VM::is_tape_playing(int drv)
237 return drec->is_tape_playing();
240 bool VM::is_tape_recording(int drv)
242 return drec->is_tape_recording();
245 int VM::get_tape_position(int drv)
247 return drec->get_tape_position();
250 const _TCHAR* VM::get_tape_message(int drv)
252 return drec->get_message();
255 void VM::push_play(int drv)
258 drec->set_remote(true);
261 void VM::push_stop(int drv)
263 drec->set_remote(false);
266 void VM::push_fast_forward(int drv)
269 drec->set_remote(true);
272 void VM::push_fast_rewind(int drv)
274 drec->set_ff_rew(-1);
275 drec->set_remote(true);
278 bool VM::is_frame_skippable()
280 return event->is_frame_skippable();
283 void VM::update_config()
285 for(DEVICE* device = first_device; device; device = device->next_device) {
286 device->update_config();
290 #define STATE_VERSION 3
292 #include "../../statesub.h"
293 #include "../../qt/gui/csp_logger.h"
294 extern CSP_Logger DLL_PREFIX_I *csp_logger;
296 void VM::decl_state(void)
298 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::JR_100_HEAD")), csp_logger);
299 for(DEVICE* device = first_device; device; device = device->next_device) {
300 device->decl_state();
304 void VM::save_state(FILEIO* state_fio)
306 //state_fio->FputUint32(STATE_VERSION);
308 if(state_entry != NULL) {
309 state_entry->save_state(state_fio);
311 for(DEVICE* device = first_device; device; device = device->next_device) {
312 device->save_state(state_fio);
316 bool VM::load_state(FILEIO* state_fio)
318 //if(state_fio->FgetUint32() != STATE_VERSION) {
322 if(state_entry != NULL) {
323 mb = state_entry->load_state(state_fio);
326 emu->out_debug_log("INFO: HEADER DATA ERROR");
329 for(DEVICE* device = first_device; device; device = device->next_device) {
330 if(!device->load_state(state_fio)) {