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 "../memory.h"
20 #include "../pcm1bit.h"
23 #include "../debugger.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 VM::VM(EMU* parent_emu) : emu(parent_emu)
35 first_device = last_device = NULL;
36 dummy = new DEVICE(this, emu); // must be 1st device
37 event = new EVENT(this, emu); // must be 2nd device
39 drec = new DATAREC(this, emu);
40 drec->set_context_noise_play(new NOISE(this, emu));
41 drec->set_context_noise_stop(new NOISE(this, emu));
42 drec->set_context_noise_fast(new NOISE(this, emu));
43 for(int i = 0; i < 8; i++) {
44 lcd[i] = new HD44102(this, emu);
46 cpu = new MC6800(this, emu);
47 memory = new MEMORY(this, emu);
48 pcm = new PCM1BIT(this, emu);
50 io = new IO(this, emu);
53 event->set_context_cpu(cpu);
54 event->set_context_sound(drec);
55 event->set_context_sound(pcm);
56 event->set_context_sound(drec->get_context_noise_play());
57 event->set_context_sound(drec->get_context_noise_stop());
58 event->set_context_sound(drec->get_context_noise_fast());
60 // cpu->set_context_port1(drec, SIG_DATAREC_MIC, 0x01, 0);
61 cpu->set_context_port1(pcm, SIG_PCM1BIT_ON, 0x08, 0);
62 cpu->set_context_port1(pcm, SIG_PCM1BIT_SIGNAL, 0x10, 0);
64 for(int i = 0; i < 8; i++) {
65 io->set_context_lcd(i, lcd[i]);
69 cpu->set_context_mem(memory);
71 cpu->set_context_debugger(new DEBUGGER(this, emu));
75 memset(ram, 0x00, sizeof(ram));
76 memset(rom, 0xff, sizeof(rom));
78 memory->read_bios(_T("BASIC.ROM"), rom, sizeof(rom));
80 memory->set_memory_rw(0x2000, 0x7fff, ram);
81 memory->set_memory_r(0x8000, 0xffff, rom);
82 memory->set_memory_mapped_io_rw(0x0a00, 0x0bff, io);
83 memory->set_memory_mapped_io_rw(0x0d00, 0x0fff, io);
85 // initialize all devices
86 for(DEVICE* device = first_device; device; device = device->next_device) {
94 for(DEVICE* device = first_device; device;) {
95 DEVICE *next_device = device->next_device;
102 DEVICE* VM::get_device(int id)
104 for(DEVICE* device = first_device; device; device = device->next_device) {
105 if(device->this_device_id == id) {
112 // ----------------------------------------------------------------------------
113 // drive virtual machine
114 // ----------------------------------------------------------------------------
119 for(DEVICE* device = first_device; device; device = device->next_device) {
122 cpu->write_signal(SIG_MC6801_PORT_1, 0x00, 0xff);
123 cpu->write_signal(SIG_MC6801_PORT_2, 0x00, 0xff);
124 cpu->write_signal(SIG_MC6801_PORT_3, 0x00, 0xff);
125 cpu->write_signal(SIG_MC6801_PORT_4, 0x00, 0xff);
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
138 DEVICE *VM::get_cpu(int index)
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 void VM::draw_screen()
153 for(int y = 0; y < 2; y++) {
154 for(int x = 0; x < 4; x++) {
155 lcd[x + 4 * y]->screen_update(50 * x - 4, 32 * y, y == 0);
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 void VM::initialize_sound(int rate, int samples)
166 // init sound manager
167 event->initialize_sound(rate, samples);
170 pcm->initialize_sound(rate, 8000);
173 uint16_t* VM::create_sound(int* extra_frames)
175 return event->create_sound(extra_frames);
178 int VM::get_sound_buffer_ptr()
180 return event->get_sound_buffer_ptr();
183 #ifdef USE_SOUND_VOLUME
184 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
187 pcm->set_volume(0, decibel_l, decibel_r);
189 drec->set_volume(0, decibel_l, decibel_r);
191 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
192 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
193 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void VM::play_tape(const _TCHAR* file_path)
204 drec->play_tape(file_path);
207 void VM::rec_tape(const _TCHAR* file_path)
209 drec->rec_tape(file_path);
212 void VM::close_tape()
219 bool VM::is_tape_inserted()
221 return drec->is_tape_inserted();
224 bool VM::is_tape_playing()
226 return drec->is_tape_playing();
229 bool VM::is_tape_recording()
231 return drec->is_tape_recording();
234 int VM::get_tape_position()
236 return drec->get_tape_position();
239 const _TCHAR* VM::get_tape_message()
241 return drec->get_message();
244 bool VM::is_frame_skippable()
246 return event->is_frame_skippable();
249 void VM::update_config()
251 for(DEVICE* device = first_device; device; device = device->next_device) {
252 device->update_config();
256 #define STATE_VERSION 2
258 void VM::save_state(FILEIO* state_fio)
260 state_fio->FputUint32(STATE_VERSION);
262 for(DEVICE* device = first_device; device; device = device->next_device) {
263 device->save_state(state_fio);
265 state_fio->Fwrite(ram, sizeof(ram), 1);
268 bool VM::load_state(FILEIO* state_fio)
270 if(state_fio->FgetUint32() != STATE_VERSION) {
273 for(DEVICE* device = first_device; device; device = device->next_device) {
274 if(!device->load_state(state_fio)) {
278 state_fio->Fread(ram, sizeof(ram), 1);