From a9ac2db02f009e086df85d25dc9b32452f259538 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 8 Jun 2021 23:02:03 +0300 Subject: [PATCH] infinite hardware scrolling --- sys1/kern/src/main.c | 26 +++++++++++++++++++++++--- sys1/kern/src/vga.c | 41 ++++++++++++++++++++++++++++++++++------- sys1/kern/src/vga.h | 3 ++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/sys1/kern/src/main.c b/sys1/kern/src/main.c index f0441e5..00d3882 100644 --- a/sys1/kern/src/main.c +++ b/sys1/kern/src/main.c @@ -12,11 +12,31 @@ void drawtext(int x, int y, const char *s) 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++; + } } diff --git a/sys1/kern/src/vga.c b/sys1/kern/src/vga.c index 2967299..ae7c049 100644 --- a/sys1/kern/src/vga.c +++ b/sys1/kern/src/vga.c @@ -28,25 +28,52 @@ void vga_setcursor(int x, int y) 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) diff --git a/sys1/kern/src/vga.h b/sys1/kern/src/vga.h index e8be27a..14a91ff 100644 --- a/sys1/kern/src/vga.h +++ b/sys1/kern/src/vga.h @@ -15,10 +15,11 @@ enum { 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_ */ -- 1.7.10.4