OSDN Git Service

[VM][General][WIP] Apply new (Upstream 2016-02-21) APIs to VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / ys6464a / ys6464a.cpp
1 /*
2         SHINKO SANGYO YS-6464A Emulator 'eYS-6464A'
3
4         Author : Takeda.Toshiya
5         Date   : 2009.12.30 -
6
7         [ virtual machine ]
8 */
9
10 #include "ys6464a.h"
11 #include "../../emu.h"
12 #include "../device.h"
13 #include "../event.h"
14
15 #include "../io.h"
16 #include "../i8255.h"
17 #include "../memory.h"
18 #include "../pcm1bit.h"
19 #include "../z80.h"
20
21 #include "display.h"
22 #include "keyboard.h"
23
24 // ----------------------------------------------------------------------------
25 // initialize
26 // ----------------------------------------------------------------------------
27
28 VM::VM(EMU* parent_emu) : emu(parent_emu)
29 {
30         // create devices
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
34         
35         io = new IO(this, emu);
36         pio = new I8255(this, emu);
37         memory = new MEMORY(this, emu);
38 //      pcm = new PCM1BIT(this, emu);
39         cpu = new Z80(this, emu);
40         
41         display = new DISPLAY(this, emu);
42         keyboard = new KEYBOARD(this, emu);
43         
44         // set contexts
45         event->set_context_cpu(cpu);
46 //      event->set_context_sound(pcm);
47         
48 //      pio->set_context_port_b(pcm, SIG_PCM1BIT_SIGNAL, 0x01, 0);
49         pio->set_context_port_b(display, SIG_DISPLAY_PORT_B, 0xf0, 0);
50         pio->set_context_port_c(display, SIG_DISPLAY_PORT_C, 0xf0, 0);
51         pio->set_context_port_c(keyboard, SIG_KEYBOARD_PORT_C, 0xf0, 0);
52         keyboard->set_context_pio(pio);
53         
54         // cpu bus
55         cpu->set_context_mem(memory);
56         cpu->set_context_io(io);
57         cpu->set_context_intr(dummy);
58         
59         // memory bus
60         memset(ram, 0, sizeof(ram));
61         memset(rom, 0xff, sizeof(rom));
62         
63         memory->read_bios(_T("MON.ROM"), rom, sizeof(rom));
64         
65         memory->set_memory_r(0x0000, 0x1fff, rom);
66         memory->set_memory_r(0x2000, 0x3fff, rom);
67         memory->set_memory_r(0x4000, 0x5fff, rom);
68         memory->set_memory_r(0x6000, 0x7fff, rom);
69         memory->set_memory_rw(0x8000, 0x9fff, ram);
70         memory->set_memory_rw(0xa000, 0xbfff, ram);
71         memory->set_memory_rw(0xc000, 0xdfff, ram);
72         memory->set_memory_rw(0xe000, 0xffff, ram);
73         
74         // i/o bus
75         io->set_iomap_range_w(0xf8, 0xfb, pio);
76         io->set_iomap_range_r(0xf8, 0xfb, pio);
77         
78         // initialize all devices
79         for(DEVICE* device = first_device; device; device = device->next_device) {
80                 device->initialize();
81         }
82 }
83
84 VM::~VM()
85 {
86         // delete all devices
87         for(DEVICE* device = first_device; device;) {
88                 DEVICE *next_device = device->next_device;
89                 device->release();
90                 delete device;
91                 device = next_device;
92         }
93 }
94
95 DEVICE* VM::get_device(int id)
96 {
97         for(DEVICE* device = first_device; device; device = device->next_device) {
98                 if(device->this_device_id == id) {
99                         return device;
100                 }
101         }
102         return NULL;
103 }
104
105 // ----------------------------------------------------------------------------
106 // drive virtual machine
107 // ----------------------------------------------------------------------------
108
109 void VM::reset()
110 {
111         // reset all devices
112         for(DEVICE* device = first_device; device; device = device->next_device) {
113                 device->reset();
114         }
115 }
116
117 void VM::run()
118 {
119         event->drive();
120 }
121
122 // ----------------------------------------------------------------------------
123 // draw screen
124 // ----------------------------------------------------------------------------
125
126 void VM::draw_screen()
127 {
128         display->draw_screen();
129 }
130
131 // ----------------------------------------------------------------------------
132 // soud manager
133 // ----------------------------------------------------------------------------
134
135 void VM::initialize_sound(int rate, int samples)
136 {
137         // init sound manager
138         event->initialize_sound(rate, samples);
139         
140         // init sound gen
141 //      pcm->initialize_sound(rate, 8000);
142 }
143
144 uint16* VM::create_sound(int* extra_frames)
145 {
146         return event->create_sound(extra_frames);
147 }
148
149 int VM::get_sound_buffer_ptr()
150 {
151         return event->get_sound_buffer_ptr();
152 }
153
154 // ----------------------------------------------------------------------------
155 // user interface
156 // ----------------------------------------------------------------------------
157
158 void VM::load_binary(int drv, const _TCHAR* file_path)
159 {
160         if(drv == 0) {
161                 memory->read_image(file_path, ram, sizeof(ram));
162         }
163 }
164
165 void VM::save_binary(int drv, const _TCHAR* file_path)
166 {
167         if(drv == 0) {
168                 memory->write_image(file_path, ram, sizeof(ram));
169         }
170 }
171
172 bool VM::is_frame_skippable()
173 {
174         return event->is_frame_skippable();
175 }
176
177 void VM::update_config()
178 {
179         for(DEVICE* device = first_device; device; device = device->next_device) {
180                 device->update_config();
181         }
182 }
183