void kmain(void)
{
+ int i, row;
+ int line, scroll;
char buf[64];
+ char twirl[] = "-\\|/";
vga_reset();
- vga_setcolor(VGA_YELLOW | VGA_BRIGHT, VGA_BLACK);
- sprintf(buf, "kmain addr: %p", (void*)kmain);
- drawtext(10, 5, buf);
+ line = 0;
+ for(;;) {
+ scroll = line <= 24 ? 0 : line - 24;
+ row = line <= 24 ? line : 24;
+ sprintf(buf, "line %d (scroll %d [%d])", line, scroll, scroll % 25);
+ vga_scroll(scroll);
+ if(scroll) {
+ vga_clearline(24);
+ }
+ vga_setcolor(VGA_YELLOW | VGA_BRIGHT, VGA_BLACK);
+ drawtext(line & 7, row, buf);
+
+ for(i=0; i<65536 * 4; i++) {
+ buf[0] = twirl[(i >> 18) & 3];
+ buf[1] = 0;
+ vga_setcolor(VGA_WHITE, VGA_BLACK);
+ drawtext(50, row, buf);
+ }
+ line++;
+ }
}
crtc_write(CRTC_CURPOS_L, loc);
}
-void vga_setstart(int start)
+void vga_scroll(int s)
{
- yoffs = start;
- crtc_write(CRTC_START_H, start >> 8);
- crtc_write(CRTC_START_L, start);
+ yoffs = s % 25;
+ s = yoffs * 80;
+ crtc_write(CRTC_START_H, s >> 8);
+ crtc_write(CRTC_START_L, s);
}
void vga_reset(void)
{
vga_setcolor(VGA_WHITE, VGA_BLACK);
- vga_setstart(0);
+ vga_scroll(0);
vga_setcursor(0, 0);
memset((void*)0xb8000, 0, 80 * 25 * 2);
}
+void vga_clearline(int row)
+{
+ uint16_t *ptr;
+
+ row += yoffs;
+
+ ptr = (uint16_t*)0xb8000 + row * 80;
+ memset16(ptr, attr, 80);
+
+ if(row - 25 >= 0) {
+ /* write a copy to wrap-around future scrolling */
+ ptr -= 80 * 25;
+ memset16(ptr, attr, 80);
+ }
+}
+
void vga_drawchar(int x, int y, int c)
{
- uint16_t *ptr = (uint16_t*)0xb8000 + (y + yoffs) * 80 + x;
- *ptr = (c & 0xff) | attr;
+ uint16_t *ptr, val = (c & 0xff) | attr;
+
+ y += yoffs;
+
+ ptr = (uint16_t*)0xb8000 + y * 80 + x;
+ *ptr = val;
+
+ if(y - 25 >= 0) {
+ /* write a copy to wrap-around future scrolling */
+ ptr -= 80 * 25;
+ *ptr = val;
+ }
}
static void crtc_write(int reg, unsigned char val)
void vga_setcolor(int fg, int bg);
void vga_setcursor(int x, int y);
-void vga_setstart(int start);
+void vga_scroll(int s);
void vga_reset(void);
+void vga_clearline(int row);
void vga_drawchar(int x, int y, int c);
#endif /* VGA_H_ */