kern

annotate src/vid.c @ 2:86781ef20689

added hardware scrolling, memset16 and temporary keyboard input for testing
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 04 Dec 2010 08:04:43 +0200
parents ebe5e0e44a9d
children 0489a34ab348
rev   line source
nuclear@2 1 #if 0
nuclear@2 2
nuclear@0 3 #include <string.h>
nuclear@0 4 #include "vid.h"
nuclear@2 5 #include "asmops.h"
nuclear@2 6
nuclear@2 7 /* height of our virtual console text buffer */
nuclear@2 8 #define VIRT_HEIGHT 1024
nuclear@2 9
nuclear@2 10 /* CRTC ports */
nuclear@2 11 #define CRTC_ADDR 0x3d4
nuclear@2 12 #define CRTC_DATA 0x3d5
nuclear@2 13
nuclear@2 14 /* CRTC registers */
nuclear@2 15 #define CRTC_START_HIGH 0xc
nuclear@2 16 #define CRTC_START_LOW 0xd
nuclear@2 17 #define CRTC_CURSOR_HIGH 0xe
nuclear@2 18 #define CRTC_CURSOR_LOW 0xf
nuclear@2 19
nuclear@2 20 /* construct a character with its attributes */
nuclear@2 21 #define VMEM_CHAR(c, fg, bg) \
nuclear@2 22 ((uint16_t)(c) | (((uint16_t)(fg) & 0xf) << 8) | (((uint16_t)(bg) & 0xf) << 12))
nuclear@2 23
nuclear@2 24 static void set_start_line(int line);
nuclear@0 25
nuclear@0 26 static uint16_t *vmem = (uint16_t*)0xb8000;
nuclear@2 27 static int start_line;
nuclear@0 28
nuclear@2 29
nuclear@2 30 void clear_scr(void)
nuclear@0 31 {
nuclear@2 32 memset16(vmem, VMEM_CHAR(' ', LTGRAY, BLACK), WIDTH * HEIGHT);
nuclear@2 33 start_line = 0;
nuclear@2 34 set_start_line(0);
nuclear@2 35 set_cursor(0, 0);
nuclear@0 36 }
nuclear@0 37
nuclear@1 38 void set_char(char c, int x, int y, int fg, int bg)
nuclear@0 39 {
nuclear@2 40 vmem[(y + start_line) * WIDTH + x] = VMEM_CHAR(c, fg, bg);
nuclear@2 41 }
nuclear@2 42
nuclear@2 43 void set_cursor(int x, int y)
nuclear@2 44 {
nuclear@2 45 int loc;
nuclear@2 46
nuclear@2 47 if(x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
nuclear@2 48 loc = 0xffff;
nuclear@2 49 } else {
nuclear@2 50 loc = (y + start_line) * WIDTH + x;
nuclear@2 51 }
nuclear@2 52
nuclear@2 53 outb(CRTC_CURSOR_LOW, CRTC_ADDR);
nuclear@2 54 outb(loc, CRTC_DATA);
nuclear@2 55 outb(CRTC_CURSOR_HIGH, CRTC_ADDR);
nuclear@2 56 outb(loc >> 8, CRTC_DATA);
nuclear@0 57 }
nuclear@0 58
nuclear@1 59 void scroll_scr(void)
nuclear@0 60 {
nuclear@2 61 if(++start_line > VIRT_HEIGHT - HEIGHT) {
nuclear@2 62 /* The bottom of the visible range reached the end of our text buffer.
nuclear@2 63 * Copy the rest of the lines to the top and reset start_line.
nuclear@2 64 */
nuclear@2 65 memcpy(vmem, vmem + start_line * WIDTH, (HEIGHT - 1) * WIDTH);
nuclear@2 66 start_line = 0;
nuclear@2 67 }
nuclear@2 68
nuclear@2 69 /* clear the next line that will be revealed by scrolling */
nuclear@2 70 int new_line = start_line + HEIGHT - 1;
nuclear@2 71 memset16(vmem + new_line * WIDTH, VMEM_CHAR(' ', LTGRAY, BLACK), WIDTH);
nuclear@2 72
nuclear@2 73 set_start_line(start_line);
nuclear@0 74 }
nuclear@2 75
nuclear@2 76 static void set_start_line(int line)
nuclear@2 77 {
nuclear@2 78 int start_addr = line * WIDTH;
nuclear@2 79
nuclear@2 80 outb(CRTC_START_LOW, CRTC_ADDR);
nuclear@2 81 outb(start_addr & 0xff, CRTC_DATA);
nuclear@2 82 outb(CRTC_START_HIGH, CRTC_ADDR);
nuclear@2 83 outb((start_addr >> 8) & 0xff, CRTC_DATA);
nuclear@2 84 }
nuclear@2 85 #endif /* 0 */
nuclear@2 86
nuclear@2 87 #include <string.h>
nuclear@2 88 #include "vid.h"
nuclear@2 89 #include "asmops.h"
nuclear@2 90
nuclear@2 91 #define WIDTH 80
nuclear@2 92 #define HEIGHT 25
nuclear@2 93
nuclear@2 94 /* CRTC ports */
nuclear@2 95 #define CRTC_ADDR 0x3d4
nuclear@2 96 #define CRTC_DATA 0x3d5
nuclear@2 97
nuclear@2 98 /* CRTC registers */
nuclear@2 99 #define CRTC_CURSOR_HIGH 0xe
nuclear@2 100 #define CRTC_CURSOR_LOW 0xf
nuclear@2 101
nuclear@2 102 /* construct a character with its attributes */
nuclear@2 103 #define VMEM_CHAR(c, fg, bg) \
nuclear@2 104 ((uint16_t)(c) | (((uint16_t)(fg) & 0xf) << 8) | \
nuclear@2 105 (((uint16_t)(bg) & 0xf) << 12))
nuclear@2 106
nuclear@2 107 #define CLEAR_CHAR VMEM_CHAR(' ', LTGRAY, BLACK)
nuclear@2 108
nuclear@2 109 /* pointer to the text mode video memory */
nuclear@2 110 static uint16_t *vmem = (uint16_t*)0xb8000;
nuclear@2 111
nuclear@2 112 void clear_scr(void)
nuclear@2 113 {
nuclear@2 114 memset16(vmem, CLEAR_CHAR, WIDTH * HEIGHT);
nuclear@2 115 }
nuclear@2 116
nuclear@2 117 void set_char(char c, int x, int y, int fg, int bg)
nuclear@2 118 {
nuclear@2 119 vmem[y * WIDTH + x] = VMEM_CHAR(c, fg, bg);
nuclear@2 120 }
nuclear@2 121
nuclear@2 122 void set_cursor(int x, int y)
nuclear@2 123 {
nuclear@2 124 int loc;
nuclear@2 125 if(x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
nuclear@2 126 loc = 0xffff;
nuclear@2 127 } else {
nuclear@2 128 loc = y * WIDTH + x;
nuclear@2 129 }
nuclear@2 130
nuclear@2 131 /* tell the vga where we want the cursor by writing
nuclear@2 132 * to the "cursor address" register of the CRTC */
nuclear@2 133 outb(CRTC_CURSOR_LOW, CRTC_ADDR);
nuclear@2 134 outb(loc, CRTC_DATA);
nuclear@2 135 outb(CRTC_CURSOR_HIGH, CRTC_ADDR);
nuclear@2 136 outb(loc >> 8, CRTC_DATA);
nuclear@2 137 }
nuclear@2 138
nuclear@2 139 void scroll_scr(void)
nuclear@2 140 {
nuclear@2 141 /* simple scrolling by manually copying memory */
nuclear@2 142 memmove(vmem, vmem + WIDTH, WIDTH * (HEIGHT - 1) * 2);
nuclear@2 143 memset16(vmem + WIDTH * (HEIGHT - 1), CLEAR_CHAR, WIDTH);
nuclear@2 144 }
nuclear@2 145