1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_vga.c,v 1.77 2005/07/15 07:34:06 debug Exp $ |
* $Id: dev_vga.c,v 1.99 2006/06/16 18:31:26 debug Exp $ |
29 |
* |
* |
30 |
* VGA charcell and graphics device. |
* VGA charcell and graphics device. |
31 |
* |
* |
52 |
#include "fonts/font8x16.c" |
#include "fonts/font8x16.c" |
53 |
|
|
54 |
|
|
55 |
/* For bintranslated videomem -> framebuffer updates: */ |
/* For videomem -> framebuffer updates: */ |
56 |
#define VGA_TICK_SHIFT 16 |
#define VGA_TICK_SHIFT 18 |
57 |
|
|
58 |
#define MAX_RETRACE_SCANLINES 420 |
#define MAX_RETRACE_SCANLINES 420 |
59 |
#define N_IS1_READ_THRESHOLD 50 |
#define N_IS1_READ_THRESHOLD 50 |
60 |
|
|
|
#define VGA_MEM_MAXY 60 |
|
|
#define VGA_MEM_ALLOCY 60 |
|
61 |
#define GFX_ADDR_WINDOW 0x18000 |
#define GFX_ADDR_WINDOW 0x18000 |
62 |
|
|
63 |
#define VGA_FB_ADDR 0x1c00000000ULL |
#define VGA_FB_ADDR 0x1c00000000ULL |
73 |
uint64_t control_base; |
uint64_t control_base; |
74 |
|
|
75 |
struct vfb_data *fb; |
struct vfb_data *fb; |
76 |
size_t fb_size; |
uint32_t fb_size; |
77 |
|
|
78 |
int fb_max_x; /* pixels */ |
int fb_max_x; /* pixels */ |
79 |
int fb_max_y; /* pixels */ |
int fb_max_y; /* pixels */ |
92 |
unsigned char *font; |
unsigned char *font; |
93 |
size_t charcells_size; |
size_t charcells_size; |
94 |
unsigned char *charcells; /* 2 bytes per char */ |
unsigned char *charcells; /* 2 bytes per char */ |
95 |
unsigned char *charcells_outputed; |
unsigned char *charcells_outputed; /* text */ |
96 |
|
unsigned char *charcells_drawn; /* framebuffer */ |
97 |
|
|
98 |
/* Graphics: */ |
/* Graphics: */ |
99 |
int graphics_mode; |
int graphics_mode; |
100 |
int bits_per_pixel; |
int bits_per_pixel; |
101 |
unsigned char *gfx_mem; |
unsigned char *gfx_mem; |
102 |
size_t gfx_mem_size; |
uint32_t gfx_mem_size; |
103 |
|
|
104 |
/* Registers: */ |
/* Registers: */ |
105 |
int attribute_state; /* 0 or 1 */ |
int attribute_state; /* 0 or 1 */ |
137 |
int cursor_y; |
int cursor_y; |
138 |
|
|
139 |
int modified; |
int modified; |
140 |
|
int palette_modified; |
141 |
int update_x1; |
int update_x1; |
142 |
int update_y1; |
int update_y1; |
143 |
int update_x2; |
int update_x2; |
146 |
|
|
147 |
|
|
148 |
/* |
/* |
149 |
|
* recalc_cursor_position(): |
150 |
|
* |
151 |
|
* Should be called whenever the cursor location _or_ the display |
152 |
|
* base has been changed. |
153 |
|
*/ |
154 |
|
static void recalc_cursor_position(struct vga_data *d) |
155 |
|
{ |
156 |
|
int base = (d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
157 |
|
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]; |
158 |
|
int ofs = d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] * 256 + |
159 |
|
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW]; |
160 |
|
ofs -= base; |
161 |
|
d->cursor_x = ofs % d->max_x; |
162 |
|
d->cursor_y = ofs / d->max_x; |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
/* |
167 |
* register_reset(): |
* register_reset(): |
168 |
* |
* |
169 |
* Resets many registers to sane values. |
* Resets many registers to sane values. |
170 |
*/ |
*/ |
171 |
static void register_reset(struct vga_data *d) |
static void register_reset(struct vga_data *d) |
172 |
{ |
{ |
173 |
/* Home cursor: */ |
/* Home cursor and start at the top: */ |
|
d->cursor_x = d->cursor_y = 0; |
|
174 |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] = |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] = |
175 |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW] = 0; |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW] = 0; |
|
|
|
176 |
d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] = |
d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] = |
177 |
d->crtc_reg[VGA_CRTC_START_ADDR_LOW] = 0; |
d->crtc_reg[VGA_CRTC_START_ADDR_LOW] = 0; |
178 |
|
|
179 |
|
recalc_cursor_position(d); |
180 |
|
|
181 |
/* Reset cursor scanline stuff: */ |
/* Reset cursor scanline stuff: */ |
182 |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_START] = d->font_height - 4; |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_START] = d->font_height - 2; |
183 |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_END] = d->font_height - 2; |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_END] = d->font_height - 1; |
184 |
|
|
185 |
d->sequencer_reg[VGA_SEQ_MAP_MASK] = 0x0f; |
d->sequencer_reg[VGA_SEQ_MAP_MASK] = 0x0f; |
186 |
d->graphcontr_reg[VGA_GRAPHCONTR_MASK] = 0xff; |
d->graphcontr_reg[VGA_GRAPHCONTR_MASK] = 0xff; |
208 |
for (i=16; i<256; i++) |
for (i=16; i<256; i++) |
209 |
d->fb->rgb_palette[i*3 + 0] = d->fb->rgb_palette[i*3 + 1] = |
d->fb->rgb_palette[i*3 + 0] = d->fb->rgb_palette[i*3 + 1] = |
210 |
d->fb->rgb_palette[i*3 + 2] = (i & 15) * 4; |
d->fb->rgb_palette[i*3 + 2] = (i & 15) * 4; |
211 |
|
d->palette_modified = 1; |
212 |
i = 0; |
i = 0; |
213 |
|
|
214 |
if (grayscale) { |
if (grayscale) { |
361 |
} |
} |
362 |
for (iy=y*ry; iy<(y+1)*ry; iy++) |
for (iy=y*ry; iy<(y+1)*ry; iy++) |
363 |
for (ix=x*rx; ix<(x+1)*rx; ix++) { |
for (ix=x*rx; ix<(x+1)*rx; ix++) { |
364 |
int addr2 = (d->fb_max_x * iy + ix) * 3; |
uint32_t addr2 = (d->fb_max_x * iy |
365 |
|
+ ix) * 3; |
366 |
if (addr2 < d->fb_size) |
if (addr2 < d->fb_size) |
367 |
dev_fb_access(machine->cpus[0], |
dev_fb_access(machine->cpus[0], |
368 |
machine->memory, addr2, |
machine->memory, addr2, |
383 |
static void vga_update_text(struct machine *machine, struct vga_data *d, |
static void vga_update_text(struct machine *machine, struct vga_data *d, |
384 |
int x1, int y1, int x2, int y2) |
int x1, int y1, int x2, int y2) |
385 |
{ |
{ |
386 |
int fg, bg, i, x,y, subx, line, start, end, base; |
int fg, bg, x,y, subx, line; |
387 |
|
size_t i, start, end, base; |
388 |
int font_size = d->font_height; |
int font_size = d->font_height; |
389 |
int font_width = d->font_width; |
int font_width = d->font_width; |
390 |
unsigned char *pal = d->fb->rgb_palette; |
unsigned char *pal = d->fb->rgb_palette; |
391 |
|
|
392 |
|
if (d->pixel_repx * font_width > 8*8) { |
393 |
|
fatal("[ too large font ]\n"); |
394 |
|
return; |
395 |
|
} |
396 |
|
|
397 |
/* Hm... I'm still using the old start..end code: */ |
/* Hm... I'm still using the old start..end code: */ |
398 |
start = (d->max_x * y1 + x1) * 2; |
start = (d->max_x * y1 + x1) * 2; |
399 |
end = (d->max_x * y2 + x2) * 2; |
end = (d->max_x * y2 + x2) * 2; |
412 |
|
|
413 |
for (i=start; i<=end; i+=2) { |
for (i=start; i<=end; i+=2) { |
414 |
unsigned char ch = d->charcells[i + base]; |
unsigned char ch = d->charcells[i + base]; |
415 |
|
|
416 |
|
if (!d->palette_modified && d->charcells_drawn[i] == ch && |
417 |
|
d->charcells_drawn[i+1] == d->charcells[i+base+1]) |
418 |
|
continue; |
419 |
|
|
420 |
|
d->charcells_drawn[i] = ch; |
421 |
|
d->charcells_drawn[i+1] = d->charcells[i + base + 1]; |
422 |
|
|
423 |
fg = d->charcells[i+base + 1] & 15; |
fg = d->charcells[i+base + 1] & 15; |
424 |
bg = (d->charcells[i+base + 1] >> 4) & 7; |
bg = (d->charcells[i+base + 1] >> 4) & 7; |
425 |
|
|
433 |
|
|
434 |
/* Draw the character: */ |
/* Draw the character: */ |
435 |
for (line = 0; line < font_size; line++) { |
for (line = 0; line < font_size; line++) { |
436 |
|
/* hardcoded for max 8 scaleup... :-) */ |
437 |
|
unsigned char rgb_line[3 * 8 * 8]; |
438 |
|
int iy; |
439 |
|
|
440 |
for (subx = 0; subx < font_width; subx++) { |
for (subx = 0; subx < font_width; subx++) { |
441 |
int ix, iy, color_index; |
int ix, color_index; |
442 |
|
|
443 |
if (d->use_palette_per_line) { |
if (d->use_palette_per_line) { |
444 |
int sline = d->pixel_repy * (line+y); |
int sline = d->pixel_repy * (line+y); |
455 |
else |
else |
456 |
color_index = bg; |
color_index = bg; |
457 |
|
|
458 |
for (iy=0; iy<d->pixel_repy; iy++) |
for (ix=0; ix<d->pixel_repx; ix++) |
459 |
for (ix=0; ix<d->pixel_repx; ix++) { |
memcpy(rgb_line + (subx*d->pixel_repx + |
460 |
int addr = (d->fb_max_x* (d->pixel_repy |
ix) * 3, &pal[color_index * 3], 3); |
461 |
* (line+y) + iy) + (x+subx) * |
} |
|
d->pixel_repx + ix) * 3; |
|
462 |
|
|
463 |
if (addr >= d->fb_size) |
for (iy=0; iy<d->pixel_repy; iy++) { |
464 |
continue; |
uint32_t addr = (d->fb_max_x * (d->pixel_repy * |
465 |
dev_fb_access(machine->cpus[0], |
(line+y) + iy) + x * d->pixel_repx) * 3; |
466 |
machine->memory, addr, |
if (addr >= d->fb_size) |
467 |
&pal[color_index * 3], 3, |
continue; |
468 |
MEM_WRITE, d->fb); |
dev_fb_access(machine->cpus[0], |
469 |
} |
machine->memory, addr, rgb_line, |
470 |
|
3 * machine->x11_scaleup * font_width, |
471 |
|
MEM_WRITE, d->fb); |
472 |
} |
} |
473 |
} |
} |
474 |
} |
} |
509 |
void dev_vga_tick(struct cpu *cpu, void *extra) |
void dev_vga_tick(struct cpu *cpu, void *extra) |
510 |
{ |
{ |
511 |
struct vga_data *d = extra; |
struct vga_data *d = extra; |
512 |
uint64_t low = (uint64_t)-1, high; |
int64_t low = -1, high; |
513 |
|
|
514 |
vga_update_cursor(cpu->machine, d); |
vga_update_cursor(cpu->machine, d); |
515 |
|
|
516 |
/* TODO: text vs graphics tick? */ |
/* TODO: text vs graphics tick? */ |
517 |
memory_device_dyntrans_access(cpu, cpu->mem, extra, &low, &high); |
memory_device_dyntrans_access(cpu, cpu->mem, extra, |
518 |
|
(uint64_t *) &low, (uint64_t *) &high); |
519 |
|
|
520 |
if ((int64_t)low != -1) { |
if (low != -1) { |
521 |
debug("[ dev_vga_tick: bintrans access, %llx .. %llx ]\n", |
int base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
522 |
(long long)low, (long long)high); |
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2; |
523 |
|
int new_u_y1, new_u_y2; |
524 |
|
debug("[ dev_vga_tick: dyntrans access, %"PRIx64" .. %" |
525 |
|
PRIx64" ]\n", (uint64_t) low, (uint64_t) high); |
526 |
|
low -= base; |
527 |
|
high -= base; |
528 |
d->update_x1 = 0; |
d->update_x1 = 0; |
529 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
530 |
d->update_y1 = (low/2) / d->max_x; |
new_u_y1 = (low/2) / d->max_x; |
531 |
d->update_y2 = ((high/2) / d->max_x) + 1; |
new_u_y2 = ((high/2) / d->max_x) + 1; |
532 |
|
if (new_u_y1 < d->update_y1) |
533 |
|
d->update_y1 = new_u_y1; |
534 |
|
if (new_u_y2 > d->update_y2) |
535 |
|
d->update_y2 = new_u_y2; |
536 |
|
if (d->update_y1 < 0) |
537 |
|
d->update_y1 = 0; |
538 |
if (d->update_y2 >= d->max_y) |
if (d->update_y2 >= d->max_y) |
539 |
d->update_y2 = d->max_y - 1; |
d->update_y2 = d->max_y - 1; |
540 |
d->modified = 1; |
d->modified = 1; |
573 |
vga_update_graphics(cpu->machine, d, d->update_x1, |
vga_update_graphics(cpu->machine, d, d->update_x1, |
574 |
d->update_y1, d->update_x2, d->update_y2); |
d->update_y1, d->update_x2, d->update_y2); |
575 |
|
|
576 |
|
d->palette_modified = 0; |
577 |
d->modified = 0; |
d->modified = 0; |
578 |
d->update_x1 = 999999; |
d->update_x1 = 999999; |
579 |
d->update_x2 = -1; |
d->update_x2 = -1; |
591 |
* |
* |
592 |
* Reads and writes to the VGA video memory (pixels). |
* Reads and writes to the VGA video memory (pixels). |
593 |
*/ |
*/ |
594 |
int dev_vga_graphics_access(struct cpu *cpu, struct memory *mem, |
DEVICE_ACCESS(vga_graphics) |
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
595 |
{ |
{ |
596 |
struct vga_data *d = extra; |
struct vga_data *d = extra; |
597 |
int i,j, x=0, y=0, x2=0, y2=0, modified = 0; |
int j, x=0, y=0, x2=0, y2=0, modified = 0; |
598 |
|
size_t i; |
599 |
|
|
600 |
if (relative_addr + len >= GFX_ADDR_WINDOW) |
if (relative_addr + len >= GFX_ADDR_WINDOW) |
601 |
return 0; |
return 0; |
632 |
int b = data[i] & pixelmask; |
int b = data[i] & pixelmask; |
633 |
int m = d->sequencer_reg[ |
int m = d->sequencer_reg[ |
634 |
VGA_SEQ_MAP_MASK] & 0x0f; |
VGA_SEQ_MAP_MASK] & 0x0f; |
635 |
int addr = (y * d->max_x + x + i*8 + j) |
uint32_t addr = (y * d->max_x + x + |
636 |
* d->bits_per_pixel / 8; |
i*8 + j) * d->bits_per_pixel / 8; |
637 |
unsigned char byte; |
unsigned char byte; |
638 |
if (!(d->graphcontr_reg[ |
if (!(d->graphcontr_reg[ |
639 |
VGA_GRAPHCONTR_MASK] & pixelmask)) |
VGA_GRAPHCONTR_MASK] & pixelmask)) |
688 |
* |
* |
689 |
* Reads and writes to the VGA video memory (charcells). |
* Reads and writes to the VGA video memory (charcells). |
690 |
*/ |
*/ |
691 |
int dev_vga_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr, |
DEVICE_ACCESS(vga) |
|
unsigned char *data, size_t len, int writeflag, void *extra) |
|
692 |
{ |
{ |
693 |
struct vga_data *d = extra; |
struct vga_data *d = extra; |
694 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
695 |
int i, x, y, x2, y2, r, base; |
int x, y, x2, y2, r, base; |
696 |
|
size_t i; |
697 |
|
|
698 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
699 |
|
idata = memory_readmax64(cpu, data, len); |
700 |
|
|
701 |
base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
702 |
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2; |
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2; |
706 |
y2 = (r+len-1) / (d->max_x * 2); |
y2 = (r+len-1) / (d->max_x * 2); |
707 |
x2 = ((r+len-1)/2) % d->max_x; |
x2 = ((r+len-1)/2) % d->max_x; |
708 |
|
|
709 |
if (relative_addr < d->charcells_size) { |
if (relative_addr + len - 1 < d->charcells_size) { |
710 |
if (writeflag == MEM_WRITE) { |
if (writeflag == MEM_WRITE) { |
711 |
for (i=0; i<len; i++) { |
for (i=0; i<len; i++) { |
712 |
int old = d->charcells[relative_addr + i]; |
int old = d->charcells[relative_addr + i]; |
763 |
static void vga_crtc_reg_write(struct machine *machine, struct vga_data *d, |
static void vga_crtc_reg_write(struct machine *machine, struct vga_data *d, |
764 |
int regnr, int idata) |
int regnr, int idata) |
765 |
{ |
{ |
766 |
int ofs, grayscale; |
int grayscale; |
767 |
|
|
768 |
switch (regnr) { |
switch (regnr) { |
769 |
case VGA_CRTC_CURSOR_SCANLINE_START: /* 0x0a */ |
case VGA_CRTC_CURSOR_SCANLINE_START: /* 0x0a */ |
776 |
d->update_y1 = 0; |
d->update_y1 = 0; |
777 |
d->update_y2 = d->max_y - 1; |
d->update_y2 = d->max_y - 1; |
778 |
d->modified = 1; |
d->modified = 1; |
779 |
|
recalc_cursor_position(d); |
780 |
break; |
break; |
781 |
case VGA_CRTC_CURSOR_LOCATION_HIGH: /* 0x0e */ |
case VGA_CRTC_CURSOR_LOCATION_HIGH: /* 0x0e */ |
782 |
case VGA_CRTC_CURSOR_LOCATION_LOW: /* 0x0f */ |
case VGA_CRTC_CURSOR_LOCATION_LOW: /* 0x0f */ |
783 |
ofs = d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] * 256 + |
recalc_cursor_position(d); |
|
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW]; |
|
|
d->cursor_x = ofs % d->max_x; |
|
|
d->cursor_y = ofs / d->max_x; |
|
784 |
break; |
break; |
785 |
case 0xff: |
case 0xff: |
786 |
grayscale = 0; |
grayscale = 0; |
790 |
case 0x01: |
case 0x01: |
791 |
d->cur_mode = MODE_CHARCELL; |
d->cur_mode = MODE_CHARCELL; |
792 |
d->max_x = 40; d->max_y = 25; |
d->max_x = 40; d->max_y = 25; |
793 |
d->pixel_repx = 2; d->pixel_repy = 1; |
d->pixel_repx = machine->x11_scaleup * 2; |
794 |
|
d->pixel_repy = machine->x11_scaleup; |
795 |
d->font_width = 8; |
d->font_width = 8; |
796 |
d->font_height = 16; |
d->font_height = 16; |
797 |
d->font = font8x16; |
d->font = font8x16; |
801 |
case 0x03: |
case 0x03: |
802 |
d->cur_mode = MODE_CHARCELL; |
d->cur_mode = MODE_CHARCELL; |
803 |
d->max_x = 80; d->max_y = 25; |
d->max_x = 80; d->max_y = 25; |
804 |
d->pixel_repx = d->pixel_repy = 1; |
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
805 |
d->font_width = 8; |
d->font_width = 8; |
806 |
d->font_height = 16; |
d->font_height = 16; |
807 |
d->font = font8x16; |
d->font = font8x16; |
811 |
d->max_x = 160; d->max_y = 200; |
d->max_x = 160; d->max_y = 200; |
812 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
813 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
814 |
d->pixel_repx = 4; |
d->pixel_repx = 4 * machine->x11_scaleup; |
815 |
d->pixel_repy = 2; |
d->pixel_repy = 2 * machine->x11_scaleup; |
816 |
break; |
break; |
817 |
case 0x09: |
case 0x09: |
818 |
case 0x0d: |
case 0x0d: |
820 |
d->max_x = 320; d->max_y = 200; |
d->max_x = 320; d->max_y = 200; |
821 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
822 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
823 |
d->pixel_repx = d->pixel_repy = 2; |
d->pixel_repx = d->pixel_repy = |
824 |
|
2 * machine->x11_scaleup; |
825 |
break; |
break; |
826 |
case 0x0e: |
case 0x0e: |
827 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
828 |
d->max_x = 640; d->max_y = 200; |
d->max_x = 640; d->max_y = 200; |
829 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
830 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
831 |
d->pixel_repx = 1; |
d->pixel_repx = machine->x11_scaleup; |
832 |
d->pixel_repy = 2; |
d->pixel_repy = machine->x11_scaleup * 2; |
833 |
break; |
break; |
834 |
case 0x10: |
case 0x10: |
835 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
836 |
d->max_x = 640; d->max_y = 350; |
d->max_x = 640; d->max_y = 350; |
837 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
838 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
839 |
d->pixel_repx = d->pixel_repy = 1; |
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
840 |
break; |
break; |
841 |
case 0x12: |
case 0x12: |
842 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
843 |
d->max_x = 640; d->max_y = 480; |
d->max_x = 640; d->max_y = 480; |
844 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
845 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
846 |
d->pixel_repx = d->pixel_repy = 1; |
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
847 |
break; |
break; |
848 |
case 0x13: |
case 0x13: |
849 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
850 |
d->max_x = 320; d->max_y = 200; |
d->max_x = 320; d->max_y = 200; |
851 |
d->graphics_mode = GRAPHICS_MODE_8BIT; |
d->graphics_mode = GRAPHICS_MODE_8BIT; |
852 |
d->bits_per_pixel = 8; |
d->bits_per_pixel = 8; |
853 |
d->pixel_repx = d->pixel_repy = 2; |
d->pixel_repx = d->pixel_repy = |
854 |
|
2 * machine->x11_scaleup; |
855 |
break; |
break; |
856 |
default: |
default: |
857 |
fatal("TODO! video mode change hack (mode 0x%02x)\n", |
fatal("TODO! video mode change hack (mode 0x%02x)\n", |
882 |
|
|
883 |
/* Clear screen and reset the palette: */ |
/* Clear screen and reset the palette: */ |
884 |
memset(d->charcells_outputed, 0, d->charcells_size); |
memset(d->charcells_outputed, 0, d->charcells_size); |
885 |
|
memset(d->charcells_drawn, 0, d->charcells_size); |
886 |
memset(d->gfx_mem, 0, d->gfx_mem_size); |
memset(d->gfx_mem, 0, d->gfx_mem_size); |
887 |
d->update_x1 = 0; |
d->update_x1 = 0; |
888 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
907 |
int regnr, int idata) |
int regnr, int idata) |
908 |
{ |
{ |
909 |
switch (regnr) { |
switch (regnr) { |
910 |
case VGA_SEQ_MAP_MASK: /* 0x02 */ |
case VGA_SEQ_RESET: |
911 |
|
case VGA_SEQ_MAP_MASK: |
912 |
|
case VGA_SEQ_SEQUENCER_MEMORY_MODE: |
913 |
|
debug("[ vga_sequencer_reg_write: select %i: TODO ]\n", regnr); |
914 |
break; |
break; |
915 |
default:fatal("[ vga_sequencer_reg_write: select %i ]\n", regnr); |
default:fatal("[ vga_sequencer_reg_write: select %i ]\n", regnr); |
916 |
/* cpu->running = 0; */ |
/* cpu->running = 0; */ |
927 |
struct vga_data *d, int regnr, int idata) |
struct vga_data *d, int regnr, int idata) |
928 |
{ |
{ |
929 |
switch (regnr) { |
switch (regnr) { |
930 |
case VGA_GRAPHCONTR_MASK: /* 0x08 */ |
case VGA_GRAPHCONTR_READMAPSELECT: |
931 |
|
case VGA_GRAPHCONTR_GRAPHICSMODE: |
932 |
|
case VGA_GRAPHCONTR_MISC: |
933 |
|
case VGA_GRAPHCONTR_MASK: |
934 |
|
debug("[ vga_graphcontr_reg_write: select %i: TODO ]\n", regnr); |
935 |
break; |
break; |
936 |
default:fatal("[ vga_graphcontr_reg_write: select %i ]\n", regnr); |
default:fatal("[ vga_graphcontr_reg_write: select %i ]\n", regnr); |
937 |
/* cpu->running = 0; */ |
/* cpu->running = 0; */ |
947 |
static void vga_attribute_reg_write(struct machine *machine, struct vga_data *d, |
static void vga_attribute_reg_write(struct machine *machine, struct vga_data *d, |
948 |
int regnr, int idata) |
int regnr, int idata) |
949 |
{ |
{ |
950 |
|
/* 0-15 are palette registers: TODO */ |
951 |
|
if (regnr >= 0 && regnr <= 0xf) |
952 |
|
return; |
953 |
|
|
954 |
switch (regnr) { |
switch (regnr) { |
955 |
default:fatal("[ vga_attribute_reg_write: select %i ]\n", regnr); |
default:fatal("[ vga_attribute_reg_write: select %i ]\n", regnr); |
956 |
/* cpu->running = 0; */ |
/* cpu->running = 0; */ |
963 |
* |
* |
964 |
* Reads and writes of the VGA control registers. |
* Reads and writes of the VGA control registers. |
965 |
*/ |
*/ |
966 |
int dev_vga_ctrl_access(struct cpu *cpu, struct memory *mem, |
DEVICE_ACCESS(vga_ctrl) |
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
967 |
{ |
{ |
968 |
struct vga_data *d = extra; |
struct vga_data *d = extra; |
969 |
int i; |
size_t i; |
970 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
971 |
|
|
972 |
for (i=0; i<len; i++) { |
for (i=0; i<len; i++) { |
1040 |
d->palette_read_index = idata; |
d->palette_read_index = idata; |
1041 |
d->palette_read_subindex = 0; |
d->palette_read_subindex = 0; |
1042 |
} else { |
} else { |
1043 |
fatal("[ dev_vga: WARNING: Read from " |
debug("[ dev_vga: WARNING: Read from " |
1044 |
"VGA_DAC_ADDR_READ? TODO ]\n"); |
"VGA_DAC_ADDR_READ? TODO ]\n"); |
1045 |
/* TODO */ |
/* TODO */ |
1046 |
} |
} |
1071 |
palette changed: */ |
palette changed: */ |
1072 |
if (new != old) { |
if (new != old) { |
1073 |
d->modified = 1; |
d->modified = 1; |
1074 |
|
d->palette_modified = 1; |
1075 |
d->update_x1 = d->update_y1 = 0; |
d->update_x1 = d->update_y1 = 0; |
1076 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
1077 |
d->update_y2 = d->max_y - 1; |
d->update_y2 = d->max_y - 1; |
1166 |
|
|
1167 |
default: |
default: |
1168 |
if (writeflag==MEM_READ) { |
if (writeflag==MEM_READ) { |
1169 |
fatal("[ vga_ctrl: read from 0x%08lx ]\n", |
debug("[ vga_ctrl: read from 0x%08lx ]\n", |
1170 |
(long)relative_addr); |
(long)relative_addr); |
1171 |
} else { |
} else { |
1172 |
fatal("[ vga_ctrl: write to 0x%08lx: 0x%08x" |
debug("[ vga_ctrl: write to 0x%08lx: 0x%08x" |
1173 |
" ]\n", (long)relative_addr, (int)idata); |
" ]\n", (long)relative_addr, (int)idata); |
1174 |
} |
} |
1175 |
} |
} |
1195 |
uint64_t videomem_base, uint64_t control_base, char *name) |
uint64_t videomem_base, uint64_t control_base, char *name) |
1196 |
{ |
{ |
1197 |
struct vga_data *d; |
struct vga_data *d; |
1198 |
int i, x,y, tmpi; |
size_t i; |
1199 |
size_t allocsize; |
size_t allocsize; |
1200 |
|
|
1201 |
d = malloc(sizeof(struct vga_data)); |
d = malloc(sizeof(struct vga_data)); |
1205 |
} |
} |
1206 |
memset(d, 0, sizeof(struct vga_data)); |
memset(d, 0, sizeof(struct vga_data)); |
1207 |
|
|
1208 |
d->console_handle = console_start_slave(machine, name); |
d->console_handle = console_start_slave(machine, "vga", |
1209 |
|
CONSOLE_OUTPUT_ONLY); |
1210 |
|
|
1211 |
d->videomem_base = videomem_base; |
d->videomem_base = videomem_base; |
1212 |
d->control_base = control_base; |
d->control_base = control_base; |
1213 |
d->max_x = 80; |
d->max_x = 80; |
1214 |
d->max_y = 25; |
d->max_y = 25; |
|
d->pixel_repx = 1; |
|
|
d->pixel_repy = 1; |
|
1215 |
d->cur_mode = MODE_CHARCELL; |
d->cur_mode = MODE_CHARCELL; |
1216 |
d->crtc_reg[0xff] = 0x03; |
d->crtc_reg[0xff] = 0x03; |
1217 |
d->charcells_size = d->max_x * VGA_MEM_MAXY * 2; |
d->charcells_size = 0x8000; |
1218 |
d->gfx_mem_size = 1; /* Nothing, as we start in text mode */ |
d->gfx_mem_size = 1; /* Nothing, as we start in text mode */ |
1219 |
|
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
1220 |
|
|
1221 |
/* Allocate in 4KB pages, to make it possible to use bintrans: */ |
/* Allocate in full pages, to make it possible to use dyntrans: */ |
1222 |
allocsize = ((d->charcells_size - 1) | 0xfff) + 1; |
allocsize = ((d->charcells_size-1) | (machine->arch_pagesize-1)) + 1; |
1223 |
d->charcells = malloc(d->charcells_size); |
d->charcells = malloc(d->charcells_size); |
1224 |
d->charcells_outputed = malloc(d->charcells_size); |
d->charcells_outputed = malloc(d->charcells_size); |
1225 |
|
d->charcells_drawn = malloc(d->charcells_size); |
1226 |
d->gfx_mem = malloc(d->gfx_mem_size); |
d->gfx_mem = malloc(d->gfx_mem_size); |
1227 |
if (d->charcells == NULL || d->charcells_outputed == NULL || |
if (d->charcells == NULL || d->charcells_outputed == NULL || |
1228 |
d->gfx_mem == NULL) { |
d->charcells_drawn == NULL || d->gfx_mem == NULL) { |
1229 |
fprintf(stderr, "out of memory in dev_vga_init()\n"); |
fprintf(stderr, "out of memory in dev_vga_init()\n"); |
1230 |
exit(1); |
exit(1); |
1231 |
} |
} |
1232 |
|
|
1233 |
for (y=0; y<VGA_MEM_MAXY; y++) { |
memset(d->charcells_drawn, 0, d->charcells_size); |
1234 |
for (x=0; x<d->max_x; x++) { |
|
1235 |
char ch = ' '; |
for (i=0; i<d->charcells_size; i+=2) { |
1236 |
i = (x + d->max_x * y) * 2; |
d->charcells[i] = ' '; |
1237 |
d->charcells[i] = ch; |
d->charcells[i+1] = 0x07; /* Default color */ |
1238 |
d->charcells[i+1] = 0x07; /* Default color */ |
d->charcells_drawn[i] = ' '; |
1239 |
} |
d->charcells_drawn[i+1] = 0x07; |
1240 |
} |
} |
1241 |
|
|
1242 |
memset(d->charcells_outputed, 0, d->charcells_size); |
memset(d->charcells_outputed, 0, d->charcells_size); |
1253 |
d->fb_max_y *= d->font_height; |
d->fb_max_y *= d->font_height; |
1254 |
} |
} |
1255 |
|
|
1256 |
|
memory_device_register(mem, "vga_charcells", videomem_base + 0x18000, |
1257 |
|
allocsize, dev_vga_access, d, DM_DYNTRANS_OK | |
1258 |
|
DM_DYNTRANS_WRITE_OK | DM_READS_HAVE_NO_SIDE_EFFECTS, |
1259 |
|
d->charcells); |
1260 |
|
memory_device_register(mem, "vga_gfx", videomem_base, GFX_ADDR_WINDOW, |
1261 |
|
dev_vga_graphics_access, d, DM_DEFAULT | |
1262 |
|
DM_READS_HAVE_NO_SIDE_EFFECTS, d->gfx_mem); |
1263 |
|
memory_device_register(mem, "vga_ctrl", control_base, |
1264 |
|
32, dev_vga_ctrl_access, d, DM_DEFAULT, NULL); |
1265 |
|
|
1266 |
d->fb = dev_fb_init(machine, mem, VGA_FB_ADDR, VFB_GENERIC, |
d->fb = dev_fb_init(machine, mem, VGA_FB_ADDR, VFB_GENERIC, |
1267 |
d->fb_max_x, d->fb_max_y, d->fb_max_x, d->fb_max_y, 24, "VGA"); |
d->fb_max_x, d->fb_max_y, d->fb_max_x, d->fb_max_y, 24, "VGA"); |
1268 |
d->fb_size = d->fb_max_x * d->fb_max_y * 3; |
d->fb_size = d->fb_max_x * d->fb_max_y * 3; |
1269 |
|
|
1270 |
reset_palette(d, 0); |
reset_palette(d, 0); |
1271 |
|
|
|
/* MEM_DYNTRANS_WRITE_OK <-- This works with OpenBSD/arc, but not |
|
|
with Windows NT yet. Why? */ |
|
|
memory_device_register(mem, "vga_charcells", videomem_base + 0x18000, |
|
|
allocsize, dev_vga_access, d, MEM_DYNTRANS_OK | |
|
|
MEM_READING_HAS_NO_SIDE_EFFECTS, d->charcells); |
|
|
memory_device_register(mem, "vga_gfx", videomem_base, GFX_ADDR_WINDOW, |
|
|
dev_vga_graphics_access, d, MEM_DEFAULT | |
|
|
MEM_READING_HAS_NO_SIDE_EFFECTS, d->gfx_mem); |
|
|
memory_device_register(mem, "vga_ctrl", control_base, |
|
|
32, dev_vga_ctrl_access, d, MEM_DEFAULT, NULL); |
|
|
|
|
1272 |
/* This will force an initial redraw/resynch: */ |
/* This will force an initial redraw/resynch: */ |
1273 |
d->update_x1 = 0; |
d->update_x1 = 0; |
1274 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
1276 |
d->update_y2 = d->max_y - 1; |
d->update_y2 = d->max_y - 1; |
1277 |
d->modified = 1; |
d->modified = 1; |
1278 |
|
|
1279 |
machine_add_tickfunction(machine, dev_vga_tick, d, VGA_TICK_SHIFT); |
machine_add_tickfunction(machine, dev_vga_tick, d, |
1280 |
|
VGA_TICK_SHIFT, 0.0); |
|
vga_update_cursor(machine, d); |
|
|
|
|
|
tmpi = d->cursor_y * d->max_x + d->cursor_x; |
|
1281 |
|
|
1282 |
register_reset(d); |
register_reset(d); |
1283 |
|
|
1284 |
|
vga_update_cursor(machine, d); |
1285 |
} |
} |
1286 |
|
|