2 Gijutsu-Hyoron-Sha Babbage-2nd Emulator 'eBabbage-2nd'
4 Author : Takeda.Toshiya
10 #include "babbage2nd.h"
11 #include "../../emu.h"
12 #include "../device.h"
16 #include "../memory.h"
18 #include "../z80ctc.h"
19 #include "../z80pio.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 VM::VM(EMU* parent_emu) : emu(parent_emu)
31 first_device = last_device = NULL;
32 dummy = new DEVICE(this, emu); // must be 1st device
33 event = new EVENT(this, emu); // must be 2nd device
35 io = new IO(this, emu);
36 memory = new MEMORY(this, emu);
37 cpu = new Z80(this, emu);
38 ctc = new Z80CTC(this, emu);
39 pio1 = new Z80PIO(this, emu);
40 pio2 = new Z80PIO(this, emu);
42 display = new DISPLAY(this, emu);
43 keyboard = new KEYBOARD(this, emu);
47 dummy->set_device_name(_T("1st Dummy"));
48 event->set_device_name(_T("EVENT"));
49 cpu->set_device_name(_T("CPU(Z80)"));
50 ctc->set_device_name(_T("Z80 CTC"));
51 pio1->set_device_name(_T("Z80 PIO(LEDs)"));
52 pio2->set_device_name(_T("Z80 PIO(7SEG/KEYBOARD)"));
53 display->set_device_name(_T("7SEG/LEDs"));
54 keyboard->set_device_name(_T("KEYBOARD"));
57 event->set_context_cpu(cpu);
59 pio2->set_context_port_b(display, SIG_DISPLAY_7SEG_LED, 0xff, 0);
60 keyboard->set_context_pio(pio2);
62 ctc->set_context_zc2(ctc, SIG_Z80CTC_TRIG_1, 1);
63 ctc->set_context_zc1(ctc, SIG_Z80CTC_TRIG_0, 1);
65 pio1->set_context_port_b(display, SIG_DISPLAY_8BIT_LED, 0xff, 0);
66 //pio1->set_context_port_b(pio1, SIG_Z80PIO_PORT_A, 0xff, 0);
69 cpu->set_context_mem(memory);
70 cpu->set_context_io(io);
71 cpu->set_context_intr(ctc);
73 // z80 family daisy chain
74 ctc->set_context_intr(cpu, 0);
75 ctc->set_context_child(pio1);
76 pio1->set_context_intr(cpu, 1);
77 pio1->set_context_child(pio2);
78 pio2->set_context_intr(cpu, 2);
81 memset(ram, 0, sizeof(ram));
82 memset(rom, 0xff, sizeof(rom));
84 memory->read_bios(_T("MON.ROM"), rom, sizeof(rom));
86 memory->set_memory_r(0x0000, 0x07ff, rom);
87 memory->set_memory_rw(0x1000, 0x17ff, ram);
90 io->set_iomap_range_rw(0x00, 0x03, ctc);
91 io->set_iomap_range_rw(0x10, 0x13, pio1);
92 io->set_iomap_range_rw(0x20, 0x23, pio2);
94 // initialize all devices
95 for(DEVICE* device = first_device; device; device = device->next_device) {
102 // delete all devices
103 for(DEVICE* device = first_device; device;) {
104 DEVICE *next_device = device->next_device;
107 device = next_device;
111 DEVICE* VM::get_device(int id)
113 for(DEVICE* device = first_device; device; device = device->next_device) {
114 if(device->this_device_id == id) {
121 // ----------------------------------------------------------------------------
122 // drive virtual machine
123 // ----------------------------------------------------------------------------
128 for(DEVICE* device = first_device; device; device = device->next_device) {
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 void VM::draw_screen()
144 display->draw_screen();
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 void VM::initialize_sound(int rate, int samples)
153 // init sound manager
154 event->initialize_sound(rate, samples);
157 uint16_t* VM::create_sound(int* extra_frames)
159 return event->create_sound(extra_frames);
162 int VM::get_sound_buffer_ptr()
164 return event->get_sound_buffer_ptr();
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 void VM::key_down(int code, bool repeat)
173 keyboard->key_down(code);
176 void VM::key_up(int code)
178 //keyboard->key_up(code);
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 void VM::load_binary(int drv, const _TCHAR* file_path)
188 memory->read_image(file_path, ram, sizeof(ram));
192 void VM::save_binary(int drv, const _TCHAR* file_path)
195 memory->write_image(file_path, ram, sizeof(ram));
199 bool VM::is_frame_skippable()
201 return event->is_frame_skippable();
204 void VM::update_config()
206 for(DEVICE* device = first_device; device; device = device->next_device) {
207 device->update_config();