2 SONY SMC-70 Emulator 'eSMC-70'
3 SONY SMC-777 Emulator 'eSMC-777'
5 Author : Takeda.Toshiya
12 #include "../../emu.h"
13 #include "../device.h"
16 #include "../datarec.h"
18 #include "../hd46505.h"
19 #include "../mb8877.h"
21 #include "../msm58321.h"
24 #include "../pcm1bit.h"
26 #include "../sn76489an.h"
31 #include "../debugger.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
45 first_device = last_device = NULL;
46 dummy = new DEVICE(this, emu); // must be 1st device
47 event = new EVENT(this, emu); // must be 2nd device
48 dummy->set_device_name(_T("1st Dummy"));
50 drec = new DATAREC(this, emu);
51 drec->set_context_noise_play(new NOISE(this, emu));
52 drec->set_context_noise_stop(new NOISE(this, emu));
53 drec->set_context_noise_fast(new NOISE(this, emu));
54 crtc = new HD46505(this, emu);
55 fdc = new MB8877(this, emu);
56 fdc->set_context_noise_seek(new NOISE(this, emu));
57 fdc->set_context_noise_head_down(new NOISE(this, emu));
58 fdc->set_context_noise_head_up(new NOISE(this, emu));
60 fdc->set_context_debugger(new DEBUGGER(this, emu));
63 rtc = new MSM58321(this, emu);
65 pcm = new PCM1BIT(this, emu);
67 pcm->set_context_debugger(new DEBUGGER(this, emu));
70 psg = new SN76489AN(this, emu);
72 psg->set_context_debugger(new DEBUGGER(this, emu));
75 cpu = new Z80(this, emu);
77 memory = new MEMORY(this, emu);
80 event->set_context_cpu(cpu);
81 event->set_context_sound(pcm);
83 event->set_context_sound(psg);
85 event->set_context_sound(drec);
86 event->set_context_sound(fdc->get_context_noise_seek());
87 event->set_context_sound(fdc->get_context_noise_head_down());
88 event->set_context_sound(fdc->get_context_noise_head_up());
89 event->set_context_sound(drec->get_context_noise_play());
90 event->set_context_sound(drec->get_context_noise_stop());
91 event->set_context_sound(drec->get_context_noise_fast());
93 // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
94 //pcm->set_realtime_render(true);
96 drec->set_context_ear(memory, SIG_MEMORY_DATAREC_IN, 1);
97 crtc->set_context_disp(memory, SIG_MEMORY_CRTC_DISP, 1);
98 crtc->set_context_vsync(memory, SIG_MEMORY_CRTC_VSYNC, 1);
99 fdc->set_context_drq(memory, SIG_MEMORY_FDC_DRQ, 1);
100 fdc->set_context_irq(memory, SIG_MEMORY_FDC_IRQ, 1);
102 rtc->set_context_data(memory, SIG_MEMORY_RTC_DATA, 0x0f, 0);
103 rtc->set_context_busy(memory, SIG_MEMORY_RTC_BUSY, 1);
106 memory->set_context_cpu(cpu);
107 memory->set_context_crtc(crtc, crtc->get_regs());
108 memory->set_context_drec(drec);
109 memory->set_context_fdc(fdc);
110 memory->set_context_pcm(pcm);
112 memory->set_context_rtc(rtc);
113 #elif defined(_SMC777)
114 memory->set_context_psg(psg);
118 cpu->set_context_mem(memory);
119 cpu->set_context_io(memory);
120 cpu->set_context_intr(dummy);
122 cpu->set_context_debugger(new DEBUGGER(this, emu));
125 // initialize all devices
126 #if defined(__GIT_REPO_VERSION)
127 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
129 for(DEVICE* device = first_device; device; device = device->next_device) {
130 device->initialize();
132 for(int i = 0; i < MAX_DRIVE; i++) {
133 fdc->set_drive_type(i, DRIVE_TYPE_2DD); // 1DD
134 fdc->set_drive_rpm(i, 600);
136 fdc->write_signal(SIG_MB8877_MOTOR, 1, 1);
141 // delete all devices
142 for(DEVICE* device = first_device; device;) {
143 DEVICE *next_device = device->next_device;
146 device = next_device;
150 DEVICE* VM::get_device(int id)
152 for(DEVICE* device = first_device; device; device = device->next_device) {
153 if(device->this_device_id == id) {
160 // ----------------------------------------------------------------------------
161 // drive virtual machine
162 // ----------------------------------------------------------------------------
167 for(DEVICE* device = first_device; device; device = device->next_device) {
170 memory->warm_start = false;
173 void VM::special_reset()
176 for(DEVICE* device = first_device; device; device = device->next_device) {
179 memory->warm_start = true;
187 double VM::get_frame_rate()
189 return event->get_frame_rate();
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
197 DEVICE *VM::get_cpu(int index)
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 void VM::draw_screen()
212 memory->draw_screen();
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
219 void VM::initialize_sound(int rate, int samples)
221 // init sound manager
222 event->initialize_sound(rate, samples);
225 pcm->initialize_sound(rate, 5000);
227 psg->initialize_sound(rate, CPU_CLOCKS, 5000);
231 uint16_t* VM::create_sound(int* extra_frames)
233 return event->create_sound(extra_frames);
236 int VM::get_sound_buffer_ptr()
238 return event->get_sound_buffer_ptr();
241 #ifdef USE_SOUND_VOLUME
242 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
246 psg->set_volume(0, decibel_l, decibel_r);
250 pcm->set_volume(0, decibel_l, decibel_r);
251 } else if(ch-- == 0) {
252 drec->set_volume(0, decibel_l, decibel_r);
253 } else if(ch-- == 0) {
254 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
255 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
256 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
257 } else if(ch-- == 0) {
258 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
259 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
260 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
265 // ----------------------------------------------------------------------------
267 // ----------------------------------------------------------------------------
269 void VM::key_down(int code, bool repeat)
272 memory->key_down_up(code, true);
276 void VM::key_up(int code)
278 memory->key_down_up(code, false);
281 bool VM::get_caps_locked()
283 return memory->get_caps_locked();
286 bool VM::get_kana_locked()
288 return memory->get_kana_locked();
291 // ----------------------------------------------------------------------------
293 // ----------------------------------------------------------------------------
295 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
297 fdc->open_disk(drv, file_path, bank);
300 void VM::close_floppy_disk(int drv)
302 fdc->close_disk(drv);
305 bool VM::is_floppy_disk_inserted(int drv)
307 return fdc->is_disk_inserted(drv);
310 void VM::is_floppy_disk_protected(int drv, bool value)
312 fdc->is_disk_protected(drv, value);
315 bool VM::is_floppy_disk_protected(int drv)
317 return fdc->is_disk_protected(drv);
320 uint32_t VM::is_floppy_disk_accessed()
322 return fdc->read_signal(0);
325 void VM::play_tape(int drv, const _TCHAR* file_path)
327 bool remote = drec->get_remote();
329 if(drec->play_tape(file_path) && remote) {
330 // if machine already sets remote on, start playing now
335 void VM::rec_tape(int drv, const _TCHAR* file_path)
337 bool remote = drec->get_remote();
339 if(drec->rec_tape(file_path) && remote) {
340 // if machine already sets remote on, start recording now
345 void VM::close_tape(int drv)
350 drec->set_remote(false);
353 bool VM::is_tape_inserted(int drv)
355 return drec->is_tape_inserted();
358 bool VM::is_tape_playing(int drv)
360 return drec->is_tape_playing();
363 bool VM::is_tape_recording(int drv)
365 return drec->is_tape_recording();
368 int VM::get_tape_position(int drv)
370 return drec->get_tape_position();
373 const _TCHAR* VM::get_tape_message(int drv)
375 return drec->get_message();
378 void VM::push_play(int drv)
380 drec->set_remote(false);
382 drec->set_remote(true);
385 void VM::push_stop(int drv)
387 drec->set_remote(false);
390 void VM::push_fast_forward(int drv)
392 drec->set_remote(false);
394 drec->set_remote(true);
397 void VM::push_fast_rewind(int drv)
399 drec->set_remote(false);
400 drec->set_ff_rew(-1);
401 drec->set_remote(true);
404 bool VM::is_frame_skippable()
406 return event->is_frame_skippable();
409 void VM::update_config()
411 for(DEVICE* device = first_device; device; device = device->next_device) {
412 device->update_config();
416 #define STATE_VERSION 4
418 bool VM::process_state(FILEIO* state_fio, bool loading)
420 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
423 for(DEVICE* device = first_device; device; device = device->next_device) {
424 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
425 // const char *name = typeid(*device).name();
426 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
427 const char *name = device->get_device_name();
428 int len = strlen(name);
430 if(!state_fio->StateCheckInt32(len)) {
432 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
436 if(!state_fio->StateCheckBuffer(name, len, 1)) {
438 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
442 if(!device->process_state(state_fio, loading)) {
444 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
449 // Machine specified.