2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
27 void MC6847_BASE::initialize()
32 void MC6847_BASE::reset()
34 vsync = hsync = disp = true;
37 void MC6847_BASE::write_signal(int id, uint32_t data, uint32_t mask)
41 ag = ((data & mask) != 0);
44 as = ((data & mask) != 0);
46 case SIG_MC6847_INTEXT:
47 intext = ((data & mask) != 0);
50 gm = (gm & ~mask) | (data & mask);
53 css = ((data & mask) != 0);
56 inv = ((data & mask) != 0);
58 case SIG_MC6847_ENABLE:
59 disabled = ((data & mask) == 0);
61 case SIG_MC6847_DISABLE:
62 disabled = ((data & mask) != 0);
67 void MC6847_BASE::update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame)
69 // this should be called before vline event
70 tWHS = (int)((double)new_clocks / new_frames_per_sec / (double)new_lines_per_frame * 16.5 / 227.5 + 0.5);
73 void MC6847_BASE::event_vline(int v, int clock)
76 set_vsync(v > 32); // 32/262
80 register_event_by_clock(this, 0, tWHS, false, NULL);
83 void MC6847_BASE::event_callback(int event_id, int err)
88 void MC6847_BASE::set_vsync(bool val)
91 write_signals(&outputs_vsync, val ? 0xffffffff : 0);
93 set_disp(vsync && hsync);
97 void MC6847_BASE::set_hsync(bool val)
100 write_signals(&outputs_hsync, val ? 0xffffffff : 0);
102 set_disp(vsync && hsync);
106 void MC6847_BASE::set_disp(bool val)
109 if(d_cpu != NULL && !disabled) {
110 d_cpu->write_signal(SIG_CPU_BUSREQ, val ? 1 : 0, 1);
116 void MC6847_BASE::load_font_image(const _TCHAR *file_path)
119 FILEIO* fio = new FILEIO();
120 if(fio->Fopen(file_path, FILEIO_READ_BINARY)) {
121 fio->Fread(extfont, sizeof(extfont), 1);
127 void MC6847_BASE::draw_screen()
131 memset(screen, 0, sizeof(screen));
135 case 0: draw_cg(4, 3); break; // 64x 64
136 case 1: draw_rg(2, 3); break; // 128x 64
137 case 2: draw_cg(2, 3); break; // 128x 64
138 case 3: draw_rg(2, 2); break; // 128x 96
139 case 4: draw_cg(2, 2); break; // 128x 96
140 case 5: draw_rg(2, 1); break; // 128x192
141 case 6: draw_cg(2, 1); break; // 128x192
142 case 7: draw_rg(1, 1); break; // 256x192
145 // alphanumerics / semigraphics
150 for(int y = 0; y < 192; y++) {
151 scrntype_t* dest = osd->get_vm_screen_buffer(y);
152 for(int x = 0; x < 256; x++) {
153 dest[x] = palette_pc[screen[y][x]];
158 void MC6847_BASE::draw_cg(int xofs, int yofs)
160 uint8_t color = css ? 4 : 0;
163 for(int y = 0; y < 192; y += yofs) {
164 for(int x = 0; x < 256; x += xofs * 4) {
165 uint8_t data = vram_ptr[ofs];
166 if(++ofs >= vram_size) {
169 uint8_t* dest = &screen[y][x];
172 dest[ 0] = dest[ 1] = dest[ 2] = dest[ 3] = color | ((data >> 6) & 3);
173 dest[ 4] = dest[ 5] = dest[ 6] = dest[ 7] = color | ((data >> 4) & 3);
174 dest[ 8] = dest[ 9] = dest[10] = dest[11] = color | ((data >> 2) & 3);
175 dest[12] = dest[13] = dest[14] = dest[15] = color | ((data >> 0) & 3);
177 dest[0] = dest[1] = color | ((data >> 6) & 3);
178 dest[2] = dest[3] = color | ((data >> 4) & 3);
179 dest[4] = dest[5] = color | ((data >> 2) & 3);
180 dest[6] = dest[7] = color | ((data >> 0) & 3);
184 my_memcpy(screen[y + 1], screen[y], 256);
186 my_memcpy(screen[y + 2], screen[y], 256);
192 void MC6847_BASE::draw_rg(int xofs, int yofs)
194 static const uint8_t color_table[4] = {
195 GREEN, LIGHTGREEN, BLACK, WHITE
197 static const uint8_t color_table2[4] = {
198 BLACK, BLACK, CYAN, WHITE
200 static const uint8_t color_table3[4] = {
201 BLACK, ORANGE, BLACK, WHITE
203 uint8_t color = css ? 2 : 0;
206 for(int y = 0; y < 192; y += yofs) {
207 for(int x = 0; x < 256; x += xofs * 8) {
208 uint8_t data = vram_ptr[ofs];
209 if(++ofs >= vram_size) {
212 uint8_t* dest = &screen[y][x];
215 dest[ 0] = dest[ 1] = color_table[color | ((data >> 7) & 1)];
216 dest[ 2] = dest[ 3] = color_table[color | ((data >> 6) & 1)];
217 dest[ 4] = dest[ 5] = color_table[color | ((data >> 5) & 1)];
218 dest[ 6] = dest[ 7] = color_table[color | ((data >> 4) & 1)];
219 dest[ 8] = dest[ 9] = color_table[color | ((data >> 3) & 1)];
220 dest[10] = dest[11] = color_table[color | ((data >> 2) & 1)];
221 dest[12] = dest[13] = color_table[color | ((data >> 1) & 1)];
222 dest[14] = dest[15] = color_table[color | ((data >> 0) & 1)];
224 // color bleed in black/white pattern
225 dest[0] = color_table2[(data >> 6) & 3];
226 dest[1] = color_table3[(data >> 6) & 3];
227 dest[2] = color_table2[(data >> 4) & 3];
228 dest[3] = color_table3[(data >> 4) & 3];
229 dest[4] = color_table2[(data >> 2) & 3];
230 dest[5] = color_table3[(data >> 2) & 3];
231 dest[6] = color_table2[(data >> 0) & 3];
232 dest[7] = color_table3[(data >> 0) & 3];
234 dest[0] = color_table[(data >> 7) & 1];
235 dest[1] = color_table[(data >> 6) & 1];
236 dest[2] = color_table[(data >> 5) & 1];
237 dest[3] = color_table[(data >> 4) & 1];
238 dest[4] = color_table[(data >> 3) & 1];
239 dest[5] = color_table[(data >> 2) & 1];
240 dest[6] = color_table[(data >> 1) & 1];
241 dest[7] = color_table[(data >> 0) & 1];
245 my_memcpy(screen[y + 1], screen[y], 256);
247 my_memcpy(screen[y + 2], screen[y], 256);
253 void MC6847_BASE::draw_alpha()
257 #define STATE_VERSION 1
259 void MC6847_BASE::save_state(FILEIO* state_fio)
261 state_fio->FputUint32(STATE_VERSION);
262 state_fio->FputInt32(this_device_id);
264 state_fio->Fwrite(sg4, sizeof(sg4), 1);
265 state_fio->Fwrite(sg6, sizeof(sg6), 1);
266 state_fio->FputBool(ag);
267 state_fio->FputBool(as);
268 state_fio->FputBool(intext);
269 state_fio->FputUint8(gm);
270 state_fio->FputBool(css);
271 state_fio->FputBool(inv);
272 state_fio->FputBool(vsync);
273 state_fio->FputBool(hsync);
274 state_fio->FputBool(disp);
275 state_fio->FputInt32(tWHS);
276 state_fio->FputBool(disabled);
279 bool MC6847_BASE::load_state(FILEIO* state_fio)
281 if(state_fio->FgetUint32() != STATE_VERSION) {
284 if(state_fio->FgetInt32() != this_device_id) {
287 state_fio->Fread(sg4, sizeof(sg4), 1);
288 state_fio->Fread(sg6, sizeof(sg6), 1);
289 ag = state_fio->FgetBool();
290 as = state_fio->FgetBool();
291 intext = state_fio->FgetBool();
292 gm = state_fio->FgetUint8();
293 css = state_fio->FgetBool();
294 inv = state_fio->FgetBool();
295 vsync = state_fio->FgetBool();
296 hsync = state_fio->FgetBool();
297 disp = state_fio->FgetBool();
298 tWHS = state_fio->FgetInt32();
299 disabled = state_fio->FgetBool();