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) : 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
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) {
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) {
125 cpu->write_signal(SIG_MC6801_PORT_1, 0x00, 0xff);
126 cpu->write_signal(SIG_MC6801_PORT_2, 0x00, 0xff);
127 cpu->write_signal(SIG_MC6801_PORT_3, 0x00, 0xff);
128 cpu->write_signal(SIG_MC6801_PORT_4, 0x00, 0xff);
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
141 DEVICE *VM::get_cpu(int index)
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void VM::draw_screen()
156 for(int y = 0; y < 2; y++) {
157 for(int x = 0; x < 4; x++) {
158 lcd[x + 4 * y]->screen_update(50 * x - 4, 32 * y, y == 0);
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 void VM::initialize_sound(int rate, int samples)
169 // init sound manager
170 event->initialize_sound(rate, samples);
173 pcm->initialize_sound(rate, 8000);
176 uint16_t* VM::create_sound(int* extra_frames)
178 return event->create_sound(extra_frames);
181 int VM::get_sound_buffer_ptr()
183 return event->get_sound_buffer_ptr();
186 #ifdef USE_SOUND_VOLUME
187 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
190 pcm->set_volume(0, decibel_l, decibel_r);
192 drec->set_volume(0, decibel_l, decibel_r);
194 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
195 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
196 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void VM::play_tape(int drv, const _TCHAR* file_path)
207 drec->play_tape(file_path);
208 // drec->set_remote(true);
211 void VM::rec_tape(int drv, const _TCHAR* file_path)
213 drec->rec_tape(file_path);
214 // drec->set_remote(true);
217 void VM::close_tape(int drv)
222 // drec->set_remote(false);
225 bool VM::is_tape_inserted(int drv)
227 return drec->is_tape_inserted();
230 bool VM::is_tape_playing(int drv)
232 return drec->is_tape_playing();
235 bool VM::is_tape_recording(int drv)
237 return drec->is_tape_recording();
240 int VM::get_tape_position(int drv)
242 return drec->get_tape_position();
245 const _TCHAR* VM::get_tape_message(int drv)
247 return drec->get_message();
250 void VM::push_play(int drv)
253 drec->set_remote(true);
256 void VM::push_stop(int drv)
258 drec->set_remote(false);
261 void VM::push_fast_forward(int drv)
264 drec->set_remote(true);
267 void VM::push_fast_rewind(int drv)
269 drec->set_ff_rew(-1);
270 drec->set_remote(true);
273 bool VM::is_frame_skippable()
275 return event->is_frame_skippable();
278 void VM::update_config()
280 for(DEVICE* device = first_device; device; device = device->next_device) {
281 device->update_config();
285 #define STATE_VERSION 3
287 #include "../../statesub.h"
288 #include "../../qt/gui/csp_logger.h"
289 extern CSP_Logger DLL_PREFIX_I *csp_logger;
291 void VM::decl_state(void)
293 state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::JR_800_HEAD")), csp_logger);
294 DECL_STATE_ENTRY_MULTI(void, ram, sizeof(ram));
295 for(DEVICE* device = first_device; device; device = device->next_device) {
296 device->decl_state();
300 void VM::save_state(FILEIO* state_fio)
302 //state_fio->FputUint32(STATE_VERSION);
303 if(state_entry != NULL) {
304 state_entry->save_state(state_fio);
307 for(DEVICE* device = first_device; device; device = device->next_device) {
308 device->save_state(state_fio);
310 //state_fio->Fwrite(ram, sizeof(ram), 1);
313 bool VM::load_state(FILEIO* state_fio)
315 //if(state_fio->FgetUint32() != STATE_VERSION) {
319 if(state_entry != NULL) {
320 mb = state_entry->load_state(state_fio);
323 emu->out_debug_log("INFO: HEADER DATA ERROR");
326 for(DEVICE* device = first_device; device; device = device->next_device) {
327 if(!device->load_state(state_fio)) {
331 //state_fio->Fread(ram, sizeof(ram), 1);