2 SONY SMC-777 Emulator 'eSMC-777'
4 Author : Takeda.Toshiya
11 #include "../../emu.h"
12 #include "../device.h"
15 #include "../datarec.h"
17 #include "../hd46505.h"
18 #include "../mb8877.h"
19 #include "../pcm1bit.h"
20 #include "../sn76489an.h"
24 #include "../debugger.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 VM::VM(EMU* parent_emu) : emu(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 crtc = new HD46505(this, emu);
42 fdc = new MB8877(this, emu);
43 pcm = new PCM1BIT(this, emu);
44 psg = new SN76489AN(this, emu);
45 cpu = new Z80(this, emu);
47 io = new IO(this, emu);
50 event->set_context_cpu(cpu);
51 event->set_context_sound(pcm);
52 event->set_context_sound(psg);
53 event->set_context_sound(drec);
55 drec->set_context_ear(io, SIG_IO_DATAREC_IN, 1);
56 crtc->set_context_disp(io, SIG_IO_CRTC_DISP, 1);
57 crtc->set_context_vsync(io, SIG_IO_CRTC_VSYNC, 1);
58 fdc->set_context_drq(io, SIG_IO_FDC_DRQ, 1);
59 fdc->set_context_irq(io, SIG_IO_FDC_IRQ, 1);
61 io->set_context_cpu(cpu);
62 io->set_context_crtc(crtc, crtc->get_regs());
63 io->set_context_drec(drec);
64 io->set_context_fdc(fdc);
65 io->set_context_pcm(pcm);
66 io->set_context_psg(psg);
69 cpu->set_context_mem(io);
70 cpu->set_context_io(io);
71 cpu->set_context_intr(dummy);
73 cpu->set_context_debugger(new DEBUGGER(this, emu));
76 // initialize all devices
77 for(DEVICE* device = first_device; device; device = device->next_device) {
80 for(int i = 0; i < MAX_DRIVE; i++) {
81 fdc->set_drive_type(i, DRIVE_TYPE_2DD); // 1DD
82 fdc->set_drive_rpm(i, 600);
84 fdc->write_signal(SIG_MB8877_MOTOR, 1, 1);
90 for(DEVICE* device = first_device; device;) {
91 DEVICE *next_device = device->next_device;
98 DEVICE* VM::get_device(int id)
100 for(DEVICE* device = first_device; device; device = device->next_device) {
101 if(device->this_device_id == id) {
108 // ----------------------------------------------------------------------------
109 // drive virtual machine
110 // ----------------------------------------------------------------------------
115 for(DEVICE* device = first_device; device; device = device->next_device) {
118 io->warm_start = false;
121 void VM::special_reset()
124 for(DEVICE* device = first_device; device; device = device->next_device) {
127 io->warm_start = true;
135 double VM::frame_rate()
137 return event->frame_rate();
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
145 DEVICE *VM::get_cpu(int index)
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void VM::draw_screen()
163 int VM::access_lamp()
165 uint32 status = fdc->read_signal(0);
166 return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
173 void VM::initialize_sound(int rate, int samples)
175 // init sound manager
176 event->initialize_sound(rate, samples);
179 pcm->init(rate, 5000);
180 psg->init(rate, CPU_CLOCKS, 5000);
183 uint16* VM::create_sound(int* extra_frames)
185 return event->create_sound(extra_frames);
188 int VM::sound_buffer_ptr()
190 return event->sound_buffer_ptr();
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 void VM::key_down(int code, bool repeat)
200 io->key_down_up(code, true);
204 void VM::key_up(int code)
206 io->key_down_up(code, false);
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 void VM::open_disk(int drv, const _TCHAR* file_path, int bank)
215 fdc->open_disk(drv, file_path, bank);
218 void VM::close_disk(int drv)
220 fdc->close_disk(drv);
223 bool VM::disk_inserted(int drv)
225 return fdc->disk_inserted(drv);
228 void VM::set_disk_protected(int drv, bool value)
230 fdc->set_disk_protected(drv, value);
233 bool VM::get_disk_protected(int drv)
235 return fdc->get_disk_protected(drv);
238 void VM::play_tape(const _TCHAR* file_path)
240 drec->play_tape(file_path);
243 void VM::rec_tape(const _TCHAR* file_path)
245 drec->rec_tape(file_path);
248 void VM::close_tape()
253 bool VM::tape_inserted()
255 return drec->tape_inserted();
258 bool VM::tape_playing()
260 return drec->tape_playing();
263 bool VM::tape_recording()
265 return drec->tape_recording();
268 int VM::tape_position()
270 return drec->tape_position();
276 drec->set_remote(true);
281 drec->set_remote(false);
284 void VM::push_fast_forward()
287 drec->set_remote(true);
290 void VM::push_fast_rewind()
292 drec->set_ff_rew(-1);
293 drec->set_remote(true);
298 return event->now_skip();
301 void VM::update_config()
303 for(DEVICE* device = first_device; device; device = device->next_device) {
304 device->update_config();
308 #define STATE_VERSION 1
310 void VM::save_state(FILEIO* state_fio)
312 state_fio->FputUint32(STATE_VERSION);
314 for(DEVICE* device = first_device; device; device = device->next_device) {
315 device->save_state(state_fio);
319 bool VM::load_state(FILEIO* state_fio)
321 if(state_fio->FgetUint32() != STATE_VERSION) {
324 for(DEVICE* device = first_device; device; device = device->next_device) {
325 if(!device->load_state(state_fio)) {