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 pio1->set_device_name(_T("Z80 PIO (LEDs)"));
41 pio2 = new Z80PIO(this, emu);
42 pio2->set_device_name(_T("Z80 PIO (7-Seg/Keyboard)"));
44 display = new DISPLAY(this, emu);
45 keyboard = new KEYBOARD(this, emu);
49 dummy->set_device_name(_T("1st Dummy"));
50 event->set_device_name(_T("EVENT"));
51 cpu->set_device_name(_T("CPU(Z80)"));
52 ctc->set_device_name(_T("Z80 CTC"));
53 pio1->set_device_name(_T("Z80 PIO(LEDs)"));
54 pio2->set_device_name(_T("Z80 PIO(7SEG/KEYBOARD)"));
55 display->set_device_name(_T("7SEG/LEDs"));
56 keyboard->set_device_name(_T("KEYBOARD"));
59 event->set_context_cpu(cpu);
61 pio2->set_context_port_b(display, SIG_DISPLAY_7SEG_LED, 0xff, 0);
62 keyboard->set_context_pio(pio2);
64 ctc->set_context_zc2(ctc, SIG_Z80CTC_TRIG_1, 1);
65 ctc->set_context_zc1(ctc, SIG_Z80CTC_TRIG_0, 1);
67 pio1->set_context_port_b(display, SIG_DISPLAY_8BIT_LED, 0xff, 0);
68 //pio1->set_context_port_b(pio1, SIG_Z80PIO_PORT_A, 0xff, 0);
71 cpu->set_context_mem(memory);
72 cpu->set_context_io(io);
73 cpu->set_context_intr(ctc);
75 // z80 family daisy chain
76 ctc->set_context_intr(cpu, 0);
77 ctc->set_context_child(pio1);
78 pio1->set_context_intr(cpu, 1);
79 pio1->set_context_child(pio2);
80 pio2->set_context_intr(cpu, 2);
83 memset(ram, 0, sizeof(ram));
84 memset(rom, 0xff, sizeof(rom));
86 memory->read_bios(_T("MON.ROM"), rom, sizeof(rom));
88 memory->set_memory_r(0x0000, 0x07ff, rom);
89 memory->set_memory_rw(0x1000, 0x17ff, ram);
92 io->set_iomap_range_rw(0x00, 0x03, ctc);
93 io->set_iomap_range_rw(0x10, 0x13, pio1);
94 io->set_iomap_range_rw(0x20, 0x23, pio2);
96 // initialize all devices
97 for(DEVICE* device = first_device; device; device = device->next_device) {
104 // delete all devices
105 for(DEVICE* device = first_device; device;) {
106 DEVICE *next_device = device->next_device;
109 device = next_device;
113 DEVICE* VM::get_device(int id)
115 for(DEVICE* device = first_device; device; device = device->next_device) {
116 if(device->this_device_id == id) {
123 // ----------------------------------------------------------------------------
124 // drive virtual machine
125 // ----------------------------------------------------------------------------
130 for(DEVICE* device = first_device; device; device = device->next_device) {
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 void VM::draw_screen()
146 display->draw_screen();
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 void VM::initialize_sound(int rate, int samples)
155 // init sound manager
156 event->initialize_sound(rate, samples);
159 uint16_t* VM::create_sound(int* extra_frames)
161 return event->create_sound(extra_frames);
164 int VM::get_sound_buffer_ptr()
166 return event->get_sound_buffer_ptr();
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
173 void VM::key_down(int code, bool repeat)
175 keyboard->key_down(code);
178 void VM::key_up(int code)
180 //keyboard->key_up(code);
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 void VM::load_binary(int drv, const _TCHAR* file_path)
190 memory->read_image(file_path, ram, sizeof(ram));
194 void VM::save_binary(int drv, const _TCHAR* file_path)
197 memory->write_image(file_path, ram, sizeof(ram));
201 bool VM::is_frame_skippable()
203 return event->is_frame_skippable();
206 void VM::update_config()
208 for(DEVICE* device = first_device; device; device = device->next_device) {
209 device->update_config();