58,7 → 58,7 |
static uint32_t ega_cursor; |
static uint8_t *videoram; |
static uint8_t *backbuf; |
static ioport_t ega_base; |
static ioport8_t *ega_base; |
|
chardev_t ega_console; |
|
67,26 → 67,50 |
*/ |
static void ega_check_cursor(void) |
{ |
if (ega_cursor < SCREEN) |
if (ega_cursor < EGA_SCREEN) |
return; |
|
memmove((void *) videoram, (void *) (videoram + ROW * 2), |
(SCREEN - ROW) * 2); |
memmove((void *) backbuf, (void *) (backbuf + ROW * 2), |
(SCREEN - ROW) * 2); |
memsetw(videoram + (SCREEN - ROW) * 2, ROW, 0x0720); |
memsetw(backbuf + (SCREEN - ROW) * 2, ROW, 0x0720); |
ega_cursor = ega_cursor - ROW; |
memmove((void *) videoram, (void *) (videoram + EGA_COLS * 2), |
(EGA_SCREEN - EGA_COLS) * 2); |
memmove((void *) backbuf, (void *) (backbuf + EGA_COLS * 2), |
(EGA_SCREEN - EGA_COLS) * 2); |
memsetw(videoram + (EGA_SCREEN - EGA_COLS) * 2, EGA_COLS, 0x0720); |
memsetw(backbuf + (EGA_SCREEN - EGA_COLS) * 2, EGA_COLS, 0x0720); |
ega_cursor = ega_cursor - EGA_COLS; |
} |
|
static void ega_show_cursor(void) |
{ |
pio_write_8(ega_base + EGA_INDEX_REG, 0x0a); |
uint8_t stat = pio_read_8(ega_base + EGA_DATA_REG); |
pio_write_8(ega_base + EGA_INDEX_REG, 0x0a); |
pio_write_8(ega_base + EGA_DATA_REG, stat & (~(1 << 5))); |
} |
|
static void ega_move_cursor(void) |
{ |
pio_write_8(ega_base + EGA_INDEX_REG, 0xe); |
pio_write_8(ega_base + EGA_INDEX_REG, 0x0e); |
pio_write_8(ega_base + EGA_DATA_REG, (uint8_t) ((ega_cursor >> 8) & 0xff)); |
pio_write_8(ega_base + EGA_INDEX_REG, 0xf); |
pio_write_8(ega_base + EGA_INDEX_REG, 0x0f); |
pio_write_8(ega_base + EGA_DATA_REG, (uint8_t) (ega_cursor & 0xff)); |
} |
|
static void ega_sync_cursor(void) |
{ |
pio_write_8(ega_base + EGA_INDEX_REG, 0x0e); |
uint8_t hi = pio_read_8(ega_base + EGA_DATA_REG); |
pio_write_8(ega_base + EGA_INDEX_REG, 0x0f); |
uint8_t lo = pio_read_8(ega_base + EGA_DATA_REG); |
|
ega_cursor = (hi << 8) | lo; |
if ((ega_cursor % EGA_COLS) != 0) |
ega_cursor = (ega_cursor + EGA_COLS) - ega_cursor % EGA_COLS; |
|
ega_check_cursor(); |
ega_move_cursor(); |
ega_show_cursor(); |
} |
|
static void ega_display_char(char ch, bool silent) |
{ |
backbuf[ega_cursor * 2] = ch; |
104,13 → 128,13 |
|
switch (ch) { |
case '\n': |
ega_cursor = (ega_cursor + ROW) - ega_cursor % ROW; |
ega_cursor = (ega_cursor + EGA_COLS) - ega_cursor % EGA_COLS; |
break; |
case '\t': |
ega_cursor = (ega_cursor + 8) - ega_cursor % 8; |
break; |
case '\b': |
if (ega_cursor % ROW) |
if (ega_cursor % EGA_COLS) |
ega_cursor--; |
break; |
default: |
131,21 → 155,20 |
.write = ega_putchar |
}; |
|
void ega_init(ioport_t base, uintptr_t videoram_phys) |
void ega_init(ioport8_t *base, uintptr_t videoram_phys) |
{ |
/* Initialize the software structure. */ |
ega_base = base; |
|
backbuf = (uint8_t *) malloc(SCREEN * 2, 0); |
backbuf = (uint8_t *) malloc(EGA_VRAM_SIZE, 0); |
if (!backbuf) |
panic("Unable to allocate backbuffer."); |
|
videoram = (uint8_t *) hw_map(videoram_phys, SCREEN * 2); |
videoram = (uint8_t *) hw_map(videoram_phys, EGA_VRAM_SIZE); |
|
/* Clear the screen and set the cursor position. */ |
memsetw(videoram, SCREEN, 0x0720); |
memsetw(backbuf, SCREEN, 0x0720); |
ega_move_cursor(); |
/* Synchronize the back buffer and cursor position. */ |
memcpy(backbuf, videoram, EGA_VRAM_SIZE); |
ega_sync_cursor(); |
|
chardev_initialize("ega_out", &ega_console, &ega_ops); |
stdout = &ega_console; |
152,8 → 175,8 |
|
sysinfo_set_item_val("fb", NULL, true); |
sysinfo_set_item_val("fb.kind", NULL, 2); |
sysinfo_set_item_val("fb.width", NULL, ROW); |
sysinfo_set_item_val("fb.height", NULL, ROWS); |
sysinfo_set_item_val("fb.width", NULL, EGA_COLS); |
sysinfo_set_item_val("fb.height", NULL, EGA_ROWS); |
sysinfo_set_item_val("fb.blinking", NULL, true); |
sysinfo_set_item_val("fb.address.physical", NULL, videoram_phys); |
} |
160,8 → 183,9 |
|
void ega_redraw(void) |
{ |
memcpy(videoram, backbuf, SCREEN * 2); |
memcpy(videoram, backbuf, EGA_VRAM_SIZE); |
ega_move_cursor(); |
ega_show_cursor(); |
} |
|
/** @} |