X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=3sys;a=blobdiff_plain;f=sys1%2Fkern%2Fsrc%2Fvga.c;fp=sys1%2Fkern%2Fsrc%2Fvga.c;h=29672990a36528127b8ccdd949ee82e4e040599d;hp=0000000000000000000000000000000000000000;hb=d49aa763f9b7c4ae66cf80f0cbfc3456789fc0ac;hpb=3e2e8a9156d288d230bbcd722bc91c4b3e4b21e1 diff --git a/sys1/kern/src/vga.c b/sys1/kern/src/vga.c new file mode 100644 index 0000000..2967299 --- /dev/null +++ b/sys1/kern/src/vga.c @@ -0,0 +1,56 @@ +#include +#include "vga.h" +#include "asmutil.h" + +#define CRTC_ADDR_PORT 0x3d4 +#define CRTC_DATA_PORT 0x3d5 + +/* CRTC registers */ +#define CRTC_START_H 0x0c +#define CRTC_START_L 0x0d +#define CRTC_CURPOS_H 0x0e +#define CRTC_CURPOS_L 0x0f + +static void crtc_write(int reg, unsigned char val); + +static uint16_t attr = 0x0700; +static int yoffs; + +void vga_setcolor(int fg, int bg) +{ + attr = ((bg & 7) << 12) | ((fg & 0xf) << 8); +} + +void vga_setcursor(int x, int y) +{ + int loc = (y + yoffs) * 80 + x; + crtc_write(CRTC_CURPOS_H, loc >> 8); + crtc_write(CRTC_CURPOS_L, loc); +} + +void vga_setstart(int start) +{ + yoffs = start; + crtc_write(CRTC_START_H, start >> 8); + crtc_write(CRTC_START_L, start); +} + +void vga_reset(void) +{ + vga_setcolor(VGA_WHITE, VGA_BLACK); + vga_setstart(0); + vga_setcursor(0, 0); + memset((void*)0xb8000, 0, 80 * 25 * 2); +} + +void vga_drawchar(int x, int y, int c) +{ + uint16_t *ptr = (uint16_t*)0xb8000 + (y + yoffs) * 80 + x; + *ptr = (c & 0xff) | attr; +} + +static void crtc_write(int reg, unsigned char val) +{ + outp(CRTC_ADDR_PORT, reg); + outp(CRTC_DATA_PORT, val); +}