25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_vga.c,v 1.74 2005/05/29 16:04:28 debug Exp $ |
* $Id: dev_vga.c,v 1.90 2005/11/13 00:14:10 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 |
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; |
145 |
|
|
146 |
|
|
147 |
/* |
/* |
148 |
|
* recalc_cursor_position(): |
149 |
|
* |
150 |
|
* Should be called whenever the cursor location _or_ the display |
151 |
|
* base has been changed. |
152 |
|
*/ |
153 |
|
static void recalc_cursor_position(struct vga_data *d) |
154 |
|
{ |
155 |
|
int base = (d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
156 |
|
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]; |
157 |
|
int ofs = d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] * 256 + |
158 |
|
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW]; |
159 |
|
ofs -= base; |
160 |
|
d->cursor_x = ofs % d->max_x; |
161 |
|
d->cursor_y = ofs / d->max_x; |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
/* |
166 |
* register_reset(): |
* register_reset(): |
167 |
* |
* |
168 |
* Resets many registers to sane values. |
* Resets many registers to sane values. |
169 |
*/ |
*/ |
170 |
static void register_reset(struct vga_data *d) |
static void register_reset(struct vga_data *d) |
171 |
{ |
{ |
172 |
/* Home cursor: */ |
/* Home cursor and start at the top: */ |
|
d->cursor_x = d->cursor_y = 0; |
|
173 |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] = |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_HIGH] = |
174 |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW] = 0; |
d->crtc_reg[VGA_CRTC_CURSOR_LOCATION_LOW] = 0; |
|
|
|
175 |
d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] = |
d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] = |
176 |
d->crtc_reg[VGA_CRTC_START_ADDR_LOW] = 0; |
d->crtc_reg[VGA_CRTC_START_ADDR_LOW] = 0; |
177 |
|
|
178 |
|
recalc_cursor_position(d); |
179 |
|
|
180 |
/* Reset cursor scanline stuff: */ |
/* Reset cursor scanline stuff: */ |
181 |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_START] = d->font_height - 4; |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_START] = d->font_height - 2; |
182 |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_END] = d->font_height - 2; |
d->crtc_reg[VGA_CRTC_CURSOR_SCANLINE_END] = d->font_height - 1; |
183 |
|
|
184 |
d->sequencer_reg[VGA_SEQ_MAP_MASK] = 0x0f; |
d->sequencer_reg[VGA_SEQ_MAP_MASK] = 0x0f; |
185 |
d->graphcontr_reg[VGA_GRAPHCONTR_MASK] = 0xff; |
d->graphcontr_reg[VGA_GRAPHCONTR_MASK] = 0xff; |
277 |
d->charcells_outputed[i+1] = d->charcells[base+i+1]; |
d->charcells_outputed[i+1] = d->charcells[base+i+1]; |
278 |
|
|
279 |
if (!printed_last || x == 0) { |
if (!printed_last || x == 0) { |
280 |
sprintf(s, "\033[%i;%iH", y + 1, x + 1); |
snprintf(s, sizeof(s), "\033[%i;%iH", y + 1, x + 1); |
281 |
c_putstr(d, s); |
c_putstr(d, s); |
282 |
} |
} |
283 |
if (oldcolor < 0 || (bg<<4)+fg != oldcolor || !printed_last) { |
if (oldcolor < 0 || (bg<<4)+fg != oldcolor || !printed_last) { |
284 |
sprintf(s, "\033[0;"); c_putstr(d, s); |
snprintf(s, sizeof(s), "\033[0;"); c_putstr(d, s); |
285 |
|
|
286 |
switch (fg & 7) { |
switch (fg & 7) { |
287 |
case 0: c_putstr(d, "30"); break; |
case 0: c_putstr(d, "30"); break; |
318 |
} |
} |
319 |
|
|
320 |
/* Restore the terminal's cursor position: */ |
/* Restore the terminal's cursor position: */ |
321 |
sprintf(s, "\033[%i;%iH", d->cursor_y + 1, d->cursor_x + 1); |
snprintf(s, sizeof(s), "\033[%i;%iH", d->cursor_y + 1, d->cursor_x + 1); |
322 |
c_putstr(d, s); |
c_putstr(d, s); |
323 |
} |
} |
324 |
|
|
404 |
|
|
405 |
for (i=start; i<=end; i+=2) { |
for (i=start; i<=end; i+=2) { |
406 |
unsigned char ch = d->charcells[i + base]; |
unsigned char ch = d->charcells[i + base]; |
407 |
|
|
408 |
|
if (d->charcells_drawn[i] == ch && |
409 |
|
d->charcells_drawn[i+1] == d->charcells[i+base+1]) |
410 |
|
continue; |
411 |
|
|
412 |
|
d->charcells_drawn[i] = ch; |
413 |
|
d->charcells_drawn[i+1] = d->charcells[i + base + 1]; |
414 |
|
|
415 |
fg = d->charcells[i+base + 1] & 15; |
fg = d->charcells[i+base + 1] & 15; |
416 |
bg = (d->charcells[i+base + 1] >> 4) & 7; |
bg = (d->charcells[i+base + 1] >> 4) & 7; |
417 |
|
|
496 |
void dev_vga_tick(struct cpu *cpu, void *extra) |
void dev_vga_tick(struct cpu *cpu, void *extra) |
497 |
{ |
{ |
498 |
struct vga_data *d = extra; |
struct vga_data *d = extra; |
499 |
uint64_t low = (uint64_t)-1, high; |
int64_t low = -1, high; |
500 |
|
|
501 |
vga_update_cursor(cpu->machine, d); |
vga_update_cursor(cpu->machine, d); |
502 |
|
|
503 |
/* TODO: text vs graphics tick? */ |
/* TODO: text vs graphics tick? */ |
504 |
memory_device_bintrans_access(cpu, cpu->mem, extra, &low, &high); |
memory_device_dyntrans_access(cpu, cpu->mem, extra, |
505 |
|
(uint64_t *) &low, (uint64_t *) &high); |
506 |
|
|
507 |
if ((int64_t)low != -1) { |
if (low != -1) { |
508 |
debug("[ dev_vga_tick: bintrans access, %llx .. %llx ]\n", |
int base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
509 |
|
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2; |
510 |
|
int new_u_y1, new_u_y2; |
511 |
|
debug("[ dev_vga_tick: dyntrans access, %llx .. %llx ]\n", |
512 |
(long long)low, (long long)high); |
(long long)low, (long long)high); |
513 |
|
low -= base; |
514 |
|
high -= base; |
515 |
d->update_x1 = 0; |
d->update_x1 = 0; |
516 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
517 |
d->update_y1 = (low/2) / d->max_x; |
new_u_y1 = (low/2) / d->max_x; |
518 |
d->update_y2 = ((high/2) / d->max_x) + 1; |
new_u_y2 = ((high/2) / d->max_x) + 1; |
519 |
|
if (new_u_y1 < d->update_y1) |
520 |
|
d->update_y1 = new_u_y1; |
521 |
|
if (new_u_y2 > d->update_y2) |
522 |
|
d->update_y2 = new_u_y2; |
523 |
|
if (d->update_y1 < 0) |
524 |
|
d->update_y1 = 0; |
525 |
if (d->update_y2 >= d->max_y) |
if (d->update_y2 >= d->max_y) |
526 |
d->update_y2 = d->max_y - 1; |
d->update_y2 = d->max_y - 1; |
527 |
d->modified = 1; |
d->modified = 1; |
682 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
683 |
int i, x, y, x2, y2, r, base; |
int i, x, y, x2, y2, r, base; |
684 |
|
|
685 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
686 |
|
idata = memory_readmax64(cpu, data, len); |
687 |
|
|
688 |
base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
base = ((d->crtc_reg[VGA_CRTC_START_ADDR_HIGH] << 8) |
689 |
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2; |
+ d->crtc_reg[VGA_CRTC_START_ADDR_LOW]) * 2; |
693 |
y2 = (r+len-1) / (d->max_x * 2); |
y2 = (r+len-1) / (d->max_x * 2); |
694 |
x2 = ((r+len-1)/2) % d->max_x; |
x2 = ((r+len-1)/2) % d->max_x; |
695 |
|
|
696 |
if (relative_addr < d->charcells_size) { |
if (relative_addr + len - 1 < d->charcells_size) { |
697 |
if (writeflag == MEM_WRITE) { |
if (writeflag == MEM_WRITE) { |
698 |
for (i=0; i<len; i++) { |
for (i=0; i<len; i++) { |
699 |
int old = d->charcells[relative_addr + i]; |
int old = d->charcells[relative_addr + i]; |
750 |
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, |
751 |
int regnr, int idata) |
int regnr, int idata) |
752 |
{ |
{ |
753 |
int ofs, grayscale; |
int grayscale; |
754 |
|
|
755 |
switch (regnr) { |
switch (regnr) { |
756 |
case VGA_CRTC_CURSOR_SCANLINE_START: /* 0x0a */ |
case VGA_CRTC_CURSOR_SCANLINE_START: /* 0x0a */ |
763 |
d->update_y1 = 0; |
d->update_y1 = 0; |
764 |
d->update_y2 = d->max_y - 1; |
d->update_y2 = d->max_y - 1; |
765 |
d->modified = 1; |
d->modified = 1; |
766 |
|
recalc_cursor_position(d); |
767 |
break; |
break; |
768 |
case VGA_CRTC_CURSOR_LOCATION_HIGH: /* 0x0e */ |
case VGA_CRTC_CURSOR_LOCATION_HIGH: /* 0x0e */ |
769 |
case VGA_CRTC_CURSOR_LOCATION_LOW: /* 0x0f */ |
case VGA_CRTC_CURSOR_LOCATION_LOW: /* 0x0f */ |
770 |
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; |
|
771 |
break; |
break; |
772 |
case 0xff: |
case 0xff: |
773 |
grayscale = 0; |
grayscale = 0; |
777 |
case 0x01: |
case 0x01: |
778 |
d->cur_mode = MODE_CHARCELL; |
d->cur_mode = MODE_CHARCELL; |
779 |
d->max_x = 40; d->max_y = 25; |
d->max_x = 40; d->max_y = 25; |
780 |
d->pixel_repx = 2; d->pixel_repy = 1; |
d->pixel_repx = machine->x11_scaleup * 2; |
781 |
|
d->pixel_repy = machine->x11_scaleup; |
782 |
d->font_width = 8; |
d->font_width = 8; |
783 |
d->font_height = 16; |
d->font_height = 16; |
784 |
d->font = font8x16; |
d->font = font8x16; |
788 |
case 0x03: |
case 0x03: |
789 |
d->cur_mode = MODE_CHARCELL; |
d->cur_mode = MODE_CHARCELL; |
790 |
d->max_x = 80; d->max_y = 25; |
d->max_x = 80; d->max_y = 25; |
791 |
d->pixel_repx = d->pixel_repy = 1; |
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
792 |
d->font_width = 8; |
d->font_width = 8; |
793 |
d->font_height = 16; |
d->font_height = 16; |
794 |
d->font = font8x16; |
d->font = font8x16; |
798 |
d->max_x = 160; d->max_y = 200; |
d->max_x = 160; d->max_y = 200; |
799 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
800 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
801 |
d->pixel_repx = 4; |
d->pixel_repx = 4 * machine->x11_scaleup; |
802 |
d->pixel_repy = 2; |
d->pixel_repy = 2 * machine->x11_scaleup; |
803 |
break; |
break; |
804 |
case 0x09: |
case 0x09: |
805 |
case 0x0d: |
case 0x0d: |
807 |
d->max_x = 320; d->max_y = 200; |
d->max_x = 320; d->max_y = 200; |
808 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
809 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
810 |
d->pixel_repx = d->pixel_repy = 2; |
d->pixel_repx = d->pixel_repy = |
811 |
|
2 * machine->x11_scaleup; |
812 |
break; |
break; |
813 |
case 0x0e: |
case 0x0e: |
814 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
815 |
d->max_x = 640; d->max_y = 200; |
d->max_x = 640; d->max_y = 200; |
816 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
817 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
818 |
d->pixel_repx = 1; |
d->pixel_repx = machine->x11_scaleup; |
819 |
d->pixel_repy = 2; |
d->pixel_repy = machine->x11_scaleup * 2; |
820 |
break; |
break; |
821 |
case 0x10: |
case 0x10: |
822 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
823 |
d->max_x = 640; d->max_y = 350; |
d->max_x = 640; d->max_y = 350; |
824 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
825 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
826 |
d->pixel_repx = d->pixel_repy = 1; |
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
827 |
break; |
break; |
828 |
case 0x12: |
case 0x12: |
829 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
830 |
d->max_x = 640; d->max_y = 480; |
d->max_x = 640; d->max_y = 480; |
831 |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
d->graphics_mode = GRAPHICS_MODE_4BIT; |
832 |
d->bits_per_pixel = 4; |
d->bits_per_pixel = 4; |
833 |
d->pixel_repx = d->pixel_repy = 1; |
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
834 |
break; |
break; |
835 |
case 0x13: |
case 0x13: |
836 |
d->cur_mode = MODE_GRAPHICS; |
d->cur_mode = MODE_GRAPHICS; |
837 |
d->max_x = 320; d->max_y = 200; |
d->max_x = 320; d->max_y = 200; |
838 |
d->graphics_mode = GRAPHICS_MODE_8BIT; |
d->graphics_mode = GRAPHICS_MODE_8BIT; |
839 |
d->bits_per_pixel = 8; |
d->bits_per_pixel = 8; |
840 |
d->pixel_repx = d->pixel_repy = 2; |
d->pixel_repx = d->pixel_repy = |
841 |
|
2 * machine->x11_scaleup; |
842 |
break; |
break; |
843 |
default: |
default: |
844 |
fatal("TODO! video mode change hack (mode 0x%02x)\n", |
fatal("TODO! video mode change hack (mode 0x%02x)\n", |
869 |
|
|
870 |
/* Clear screen and reset the palette: */ |
/* Clear screen and reset the palette: */ |
871 |
memset(d->charcells_outputed, 0, d->charcells_size); |
memset(d->charcells_outputed, 0, d->charcells_size); |
872 |
|
memset(d->charcells_drawn, 0, d->charcells_size); |
873 |
memset(d->gfx_mem, 0, d->gfx_mem_size); |
memset(d->gfx_mem, 0, d->gfx_mem_size); |
874 |
d->update_x1 = 0; |
d->update_x1 = 0; |
875 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
894 |
int regnr, int idata) |
int regnr, int idata) |
895 |
{ |
{ |
896 |
switch (regnr) { |
switch (regnr) { |
897 |
case VGA_SEQ_MAP_MASK: /* 0x02 */ |
case VGA_SEQ_RESET: |
898 |
|
case VGA_SEQ_MAP_MASK: |
899 |
|
case VGA_SEQ_SEQUENCER_MEMORY_MODE: |
900 |
|
debug("[ vga_sequencer_reg_write: select %i: TODO ]\n", regnr); |
901 |
break; |
break; |
902 |
default:fatal("[ vga_sequencer_reg_write: select %i ]\n", regnr); |
default:fatal("[ vga_sequencer_reg_write: select %i ]\n", regnr); |
903 |
/* cpu->running = 0; */ |
/* cpu->running = 0; */ |
914 |
struct vga_data *d, int regnr, int idata) |
struct vga_data *d, int regnr, int idata) |
915 |
{ |
{ |
916 |
switch (regnr) { |
switch (regnr) { |
917 |
case VGA_GRAPHCONTR_MASK: /* 0x08 */ |
case VGA_GRAPHCONTR_READMAPSELECT: |
918 |
|
case VGA_GRAPHCONTR_GRAPHICSMODE: |
919 |
|
case VGA_GRAPHCONTR_MISC: |
920 |
|
case VGA_GRAPHCONTR_MASK: |
921 |
|
debug("[ vga_graphcontr_reg_write: select %i: TODO ]\n", regnr); |
922 |
break; |
break; |
923 |
default:fatal("[ vga_graphcontr_reg_write: select %i ]\n", regnr); |
default:fatal("[ vga_graphcontr_reg_write: select %i ]\n", regnr); |
924 |
/* cpu->running = 0; */ |
/* cpu->running = 0; */ |
934 |
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, |
935 |
int regnr, int idata) |
int regnr, int idata) |
936 |
{ |
{ |
937 |
|
/* 0-15 are palette registers: TODO */ |
938 |
|
if (regnr >= 0 && regnr <= 0xf) |
939 |
|
return; |
940 |
|
|
941 |
switch (regnr) { |
switch (regnr) { |
942 |
default:fatal("[ vga_attribute_reg_write: select %i ]\n", regnr); |
default:fatal("[ vga_attribute_reg_write: select %i ]\n", regnr); |
943 |
/* cpu->running = 0; */ |
/* cpu->running = 0; */ |
1029 |
d->palette_read_index = idata; |
d->palette_read_index = idata; |
1030 |
d->palette_read_subindex = 0; |
d->palette_read_subindex = 0; |
1031 |
} else { |
} else { |
1032 |
fatal("[ dev_vga: WARNING: Read from " |
debug("[ dev_vga: WARNING: Read from " |
1033 |
"VGA_DAC_ADDR_READ? TODO ]\n"); |
"VGA_DAC_ADDR_READ? TODO ]\n"); |
1034 |
/* TODO */ |
/* TODO */ |
1035 |
} |
} |
1154 |
|
|
1155 |
default: |
default: |
1156 |
if (writeflag==MEM_READ) { |
if (writeflag==MEM_READ) { |
1157 |
fatal("[ vga_ctrl: read from 0x%08lx ]\n", |
debug("[ vga_ctrl: read from 0x%08lx ]\n", |
1158 |
(long)relative_addr); |
(long)relative_addr); |
1159 |
} else { |
} else { |
1160 |
fatal("[ vga_ctrl: write to 0x%08lx: 0x%08x" |
debug("[ vga_ctrl: write to 0x%08lx: 0x%08x" |
1161 |
" ]\n", (long)relative_addr, (int)idata); |
" ]\n", (long)relative_addr, (int)idata); |
1162 |
} |
} |
1163 |
} |
} |
1183 |
uint64_t videomem_base, uint64_t control_base, char *name) |
uint64_t videomem_base, uint64_t control_base, char *name) |
1184 |
{ |
{ |
1185 |
struct vga_data *d; |
struct vga_data *d; |
1186 |
int i, x,y, tmpi; |
int i; |
1187 |
size_t allocsize; |
size_t allocsize; |
1188 |
|
|
1189 |
d = malloc(sizeof(struct vga_data)); |
d = malloc(sizeof(struct vga_data)); |
1199 |
d->control_base = control_base; |
d->control_base = control_base; |
1200 |
d->max_x = 80; |
d->max_x = 80; |
1201 |
d->max_y = 25; |
d->max_y = 25; |
|
d->pixel_repx = 1; |
|
|
d->pixel_repy = 1; |
|
1202 |
d->cur_mode = MODE_CHARCELL; |
d->cur_mode = MODE_CHARCELL; |
1203 |
d->crtc_reg[0xff] = 0x03; |
d->crtc_reg[0xff] = 0x03; |
1204 |
d->charcells_size = d->max_x * VGA_MEM_MAXY * 2; |
d->charcells_size = 0x8000; |
1205 |
d->gfx_mem_size = 1; /* Nothing, as we start in text mode */ |
d->gfx_mem_size = 1; /* Nothing, as we start in text mode */ |
1206 |
|
d->pixel_repx = d->pixel_repy = machine->x11_scaleup; |
1207 |
|
|
1208 |
/* Allocate in 4KB pages, to make it possible to use bintrans: */ |
/* Allocate in full pages, to make it possible to use bintrans: */ |
1209 |
allocsize = ((d->charcells_size - 1) | 0xfff) + 1; |
allocsize = ((d->charcells_size-1) | (machine->arch_pagesize-1)) + 1; |
1210 |
d->charcells = malloc(d->charcells_size); |
d->charcells = malloc(d->charcells_size); |
1211 |
d->charcells_outputed = malloc(d->charcells_size); |
d->charcells_outputed = malloc(d->charcells_size); |
1212 |
|
d->charcells_drawn = malloc(d->charcells_size); |
1213 |
d->gfx_mem = malloc(d->gfx_mem_size); |
d->gfx_mem = malloc(d->gfx_mem_size); |
1214 |
if (d->charcells == NULL || d->charcells_outputed == NULL || |
if (d->charcells == NULL || d->charcells_outputed == NULL || |
1215 |
d->gfx_mem == NULL) { |
d->charcells_drawn == NULL || d->gfx_mem == NULL) { |
1216 |
fprintf(stderr, "out of memory in dev_vga_init()\n"); |
fprintf(stderr, "out of memory in dev_vga_init()\n"); |
1217 |
exit(1); |
exit(1); |
1218 |
} |
} |
1219 |
|
|
1220 |
for (y=0; y<VGA_MEM_MAXY; y++) { |
memset(d->charcells_drawn, 0, d->charcells_size); |
1221 |
for (x=0; x<d->max_x; x++) { |
|
1222 |
char ch = ' '; |
for (i=0; i<d->charcells_size; i+=2) { |
1223 |
i = (x + d->max_x * y) * 2; |
d->charcells[i] = ' '; |
1224 |
d->charcells[i] = ch; |
d->charcells[i+1] = 0x07; /* Default color */ |
1225 |
d->charcells[i+1] = 0x07; /* Default color */ |
d->charcells_drawn[i] = ' '; |
1226 |
} |
d->charcells_drawn[i+1] = 0x07; |
1227 |
} |
} |
1228 |
|
|
1229 |
memset(d->charcells_outputed, 0, d->charcells_size); |
memset(d->charcells_outputed, 0, d->charcells_size); |
1240 |
d->fb_max_y *= d->font_height; |
d->fb_max_y *= d->font_height; |
1241 |
} |
} |
1242 |
|
|
1243 |
|
memory_device_register(mem, "vga_charcells", videomem_base + 0x18000, |
1244 |
|
allocsize, dev_vga_access, d, DM_DYNTRANS_OK | |
1245 |
|
DM_DYNTRANS_WRITE_OK | DM_READS_HAVE_NO_SIDE_EFFECTS, |
1246 |
|
d->charcells); |
1247 |
|
memory_device_register(mem, "vga_gfx", videomem_base, GFX_ADDR_WINDOW, |
1248 |
|
dev_vga_graphics_access, d, DM_DEFAULT | |
1249 |
|
DM_READS_HAVE_NO_SIDE_EFFECTS, d->gfx_mem); |
1250 |
|
memory_device_register(mem, "vga_ctrl", control_base, |
1251 |
|
32, dev_vga_ctrl_access, d, DM_DEFAULT, NULL); |
1252 |
|
|
1253 |
d->fb = dev_fb_init(machine, mem, VGA_FB_ADDR, VFB_GENERIC, |
d->fb = dev_fb_init(machine, mem, VGA_FB_ADDR, VFB_GENERIC, |
1254 |
d->fb_max_x, d->fb_max_y, d->fb_max_x, d->fb_max_y, 24, "VGA", 0); |
d->fb_max_x, d->fb_max_y, d->fb_max_x, d->fb_max_y, 24, "VGA"); |
1255 |
d->fb_size = d->fb_max_x * d->fb_max_y * 3; |
d->fb_size = d->fb_max_x * d->fb_max_y * 3; |
1256 |
|
|
1257 |
reset_palette(d, 0); |
reset_palette(d, 0); |
1258 |
|
|
|
/* MEM_BINTRANS_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_BINTRANS_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); |
|
|
|
|
1259 |
/* This will force an initial redraw/resynch: */ |
/* This will force an initial redraw/resynch: */ |
1260 |
d->update_x1 = 0; |
d->update_x1 = 0; |
1261 |
d->update_x2 = d->max_x - 1; |
d->update_x2 = d->max_x - 1; |
1265 |
|
|
1266 |
machine_add_tickfunction(machine, dev_vga_tick, d, VGA_TICK_SHIFT); |
machine_add_tickfunction(machine, dev_vga_tick, d, VGA_TICK_SHIFT); |
1267 |
|
|
|
vga_update_cursor(machine, d); |
|
|
|
|
|
tmpi = d->cursor_y * d->max_x + d->cursor_x; |
|
|
|
|
1268 |
register_reset(d); |
register_reset(d); |
1269 |
|
|
1270 |
|
vga_update_cursor(machine, d); |
1271 |
} |
} |
1272 |
|
|