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"
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
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 for(int i = 0; i < 8; i++) {
46 lcd[i] = new HD44102(this, emu);
48 // cpu = new MC6800(this, emu);
49 cpu = new HD6301(this, emu);
50 memory = new MEMORY(this, emu);
51 pcm = new PCM1BIT(this, emu);
53 io = new IO(this, emu);
56 event->set_context_cpu(cpu);
57 event->set_context_sound(drec);
58 event->set_context_sound(pcm);
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 // cpu->set_context_port1(drec, SIG_DATAREC_MIC, 0x01, 0);
64 cpu->set_context_port1(pcm, SIG_PCM1BIT_ON, 0x08, 0);
65 cpu->set_context_port1(pcm, SIG_PCM1BIT_SIGNAL, 0x10, 0);
67 for(int i = 0; i < 8; i++) {
68 io->set_context_lcd(i, lcd[i]);
72 cpu->set_context_mem(memory);
74 cpu->set_context_debugger(new DEBUGGER(this, emu));
78 memset(ram, 0x00, sizeof(ram));
79 memset(rom, 0xff, sizeof(rom));
81 memory->read_bios(_T("BASIC.ROM"), rom, sizeof(rom));
83 memory->set_memory_rw(0x2000, 0x7fff, ram);
84 memory->set_memory_r(0x8000, 0xffff, rom);
85 memory->set_memory_mapped_io_rw(0x0a00, 0x0bff, io);
86 memory->set_memory_mapped_io_rw(0x0d00, 0x0fff, io);
88 // initialize all devices
89 #if defined(__GIT_REPO_VERSION)
90 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
92 for(DEVICE* device = first_device; device; device = device->next_device) {
100 for(DEVICE* device = first_device; device;) {
101 DEVICE *next_device = device->next_device;
104 device = next_device;
108 DEVICE* VM::get_device(int id)
110 for(DEVICE* device = first_device; device; device = device->next_device) {
111 if(device->this_device_id == id) {
118 // ----------------------------------------------------------------------------
119 // drive virtual machine
120 // ----------------------------------------------------------------------------
125 for(DEVICE* device = first_device; device; device = device->next_device) {
128 cpu->write_signal(SIG_MC6801_PORT_1, 0x00, 0xff);
129 cpu->write_signal(SIG_MC6801_PORT_2, 0x00, 0xff);
130 cpu->write_signal(SIG_MC6801_PORT_3, 0x00, 0xff);
131 cpu->write_signal(SIG_MC6801_PORT_4, 0x00, 0xff);
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
144 DEVICE *VM::get_cpu(int index)
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 void VM::draw_screen()
159 for(int y = 0; y < 2; y++) {
160 for(int x = 0; x < 4; x++) {
161 lcd[x + 4 * y]->screen_update(50 * x - 4, 32 * y, y == 0);
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 void VM::initialize_sound(int rate, int samples)
172 // init sound manager
173 event->initialize_sound(rate, samples);
176 pcm->initialize_sound(rate, 8000);
179 uint16_t* VM::create_sound(int* extra_frames)
181 return event->create_sound(extra_frames);
184 int VM::get_sound_buffer_ptr()
186 return event->get_sound_buffer_ptr();
189 #ifdef USE_SOUND_VOLUME
190 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
193 pcm->set_volume(0, decibel_l, decibel_r);
195 drec->set_volume(0, decibel_l, decibel_r);
197 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
198 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
199 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 void VM::play_tape(int drv, const _TCHAR* file_path)
210 drec->play_tape(file_path);
211 // drec->set_remote(true);
214 void VM::rec_tape(int drv, const _TCHAR* file_path)
216 drec->rec_tape(file_path);
217 // drec->set_remote(true);
220 void VM::close_tape(int drv)
225 // drec->set_remote(false);
228 bool VM::is_tape_inserted(int drv)
230 return drec->is_tape_inserted();
233 bool VM::is_tape_playing(int drv)
235 return drec->is_tape_playing();
238 bool VM::is_tape_recording(int drv)
240 return drec->is_tape_recording();
243 int VM::get_tape_position(int drv)
245 return drec->get_tape_position();
248 const _TCHAR* VM::get_tape_message(int drv)
250 return drec->get_message();
253 void VM::push_play(int drv)
256 drec->set_remote(true);
259 void VM::push_stop(int drv)
261 drec->set_remote(false);
264 void VM::push_fast_forward(int drv)
267 drec->set_remote(true);
270 void VM::push_fast_rewind(int drv)
272 drec->set_ff_rew(-1);
273 drec->set_remote(true);
276 bool VM::is_frame_skippable()
278 return event->is_frame_skippable();
281 void VM::update_config()
283 for(DEVICE* device = first_device; device; device = device->next_device) {
284 device->update_config();
288 #define STATE_VERSION 3
290 bool VM::process_state(FILEIO* state_fio, bool loading)
292 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
295 for(DEVICE* device = first_device; device; device = device->next_device) {
296 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
297 // const char *name = typeid(*device).name();
298 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
299 const char *name = device->get_device_name();
300 int len = strlen(name);
302 if(!state_fio->StateCheckInt32(len)) {
304 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
308 if(!state_fio->StateCheckBuffer(name, len, 1)) {
310 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
314 if(!device->process_state(state_fio, loading)) {
316 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
321 state_fio->StateBuffer(ram, sizeof(ram), 1);