From cec3b93c83f5d8def087c93615d18b68332237f4 Mon Sep 17 00:00:00 2001 From: Lucia Ceionia Date: Fri, 10 Feb 2023 04:45:47 -0600 Subject: [PATCH] File Selector uses a very simple double buffer --- helper.c | 4 ++-- helper.h | 2 +- hexedit.c | 2 +- kernel.c | 24 ++++++++++++++---------- progs.c | 4 ++-- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/helper.c b/helper.c index f53cec7..bfa6961 100644 --- a/helper.c +++ b/helper.c @@ -1,8 +1,8 @@ #include "helper.h" -uint16_t *nextLine(uint16_t *p) { +uint16_t *nextLine(uint16_t *p, uint16_t *b) { uintptr_t v = (uintptr_t)p; - return (uint16_t *)(v + (160 - ((v - 0xb8000) % 160))); + return (uint16_t *)(v + (160 - ((v - (uintptr_t)b) % 160))); } void V8086Int(uint8_t interrupt, union V86Regs_t *regs) { diff --git a/helper.h b/helper.h index 6d37664..b0b830f 100644 --- a/helper.h +++ b/helper.h @@ -11,7 +11,7 @@ void SetVideo25Lines(); void SetVideo50Lines(); void SetCursorDisabled(); -uint16_t *nextLine(uint16_t *p); +uint16_t *nextLine(uint16_t *p, uint16_t *b); uint32_t OpenVol(VOLINFO *vi); uint32_t OpenDir(uint8_t *path, VOLINFO *vi, DIRINFO *di); diff --git a/hexedit.c b/hexedit.c index 6fc46b9..2a7c34d 100644 --- a/hexedit.c +++ b/hexedit.c @@ -283,7 +283,7 @@ void HexEditor(uint8_t *path, VOLINFO *vi) { else vga_text += printChar(' ', vga_text); } vga_text += printChar('|', vga_text); - vga_text = nextLine(vga_text); + vga_text = nextLine(vga_text,(uint16_t*)0xb8000); } // Clear remainder of screen for (;vga_text < &((uint16_t*)0xb8000)[screenSize]; vga_text++) diff --git a/kernel.c b/kernel.c index 82dbb9e..d688995 100644 --- a/kernel.c +++ b/kernel.c @@ -202,8 +202,8 @@ Protected Only (1MB+) 400000 - 700000 Usermode Code (3mB) 700000 - 800000 Usermode Stack (1mB) */ -void DrawScreen() { - uint16_t *vga_text = (uint16_t *)0xB8000; +void DrawScreen(uint16_t *vga) { + uint16_t *vga_text = vga; // clear screen for (int i = 0; i < 80*25; i++) vga_text[i] = 0x1f00; @@ -255,8 +255,8 @@ void RestoreVGA() { int32_t fileCount; DIRENT *entries = (DIRENT*)0x400000; -void PrintFileList() { - uint16_t *vga_text = &((uint16_t *)0xb8000)[80*6+3]; +void PrintFileList(uint16_t *vga) { + uint16_t *vga_text = &((uint16_t *)vga)[80*6+3]; for (int i = 0; i < fileCount; i++) { DIRENT *de = &entries[i]; for (int i = 0; i < 11 && de->name[i]; i++) { @@ -270,7 +270,7 @@ void PrintFileList() { ((uint32_t)de->filesize_2 << 16) + ((uint32_t)de->filesize_3 << 24), vga_text); *(uint8_t*)vga_text++ = 'B'; - vga_text = nextLine(vga_text) + 3; + vga_text = nextLine(vga_text, vga) + 3; } } char IsDir(DIRENT *de) { @@ -287,6 +287,7 @@ void ScancodeTest() { } } extern void create_child(uint32_t esp, uint32_t eip, uint32_t argc, ...); +uint16_t FileSelectScreen[80*25]; void FileSelect() { uint8_t current_path[80]; uintptr_t current_path_end; @@ -295,10 +296,10 @@ void FileSelect() { current_path[0] = '/'; current_path_end = 1; fileCount = 5; - uint16_t *vga_text = (uint16_t *)0xb8000; + uint16_t *vga_text = (uint16_t *)FileSelectScreen; int32_t fileHovered = 0, lastFileHovered = 0; for (char reload = 1;;) { - DrawScreen(); + DrawScreen(vga_text); // Info line (4) { uint16_t *vga = &vga_text[80*4 + 79 - 24]; @@ -323,12 +324,15 @@ void FileSelect() { GetFileList(entries, &fileCount, &vi, &di); reload = 0; } - PrintFileList(); + PrintFileList(vga_text); if (lastFileHovered != fileHovered) { *(uint8_t*)&vga_text[80*(6+lastFileHovered)+2] = ' '; lastFileHovered = fileHovered; } *(uint8_t*)&vga_text[80*(6+fileHovered)+2] = '>'; + // Copy to real VGA + for (int i = 0; i < 80*25; i++) + ((uint16_t*)0xb8000)[i] = vga_text[i]; uint16_t key = get_scancode(); uint8_t path[13]; switch (key & 0xff) { // scancode component @@ -476,7 +480,7 @@ void start() { //if (key == 't' || key == 'T') // create_child(GetFreeStack(), (uintptr_t)RunTests, 0); RestoreVGA(); - DrawScreen(); + DrawScreen((uint16_t*)0xb8000); uint32_t stack; asm volatile("mov %%esp,%%eax":"=a"(stack)); stack = ((stack - 0x4000) / 0x1000) * 0x1000; @@ -490,7 +494,7 @@ void start() { enter_v86(0x8000, 0xFF00, FP_SEG(v86_entry), FP_OFF(v86_entry), ®s); } RestoreVGA(); - DrawScreen(); + DrawScreen((uint16_t*)0xb8000); vga_text = &((word*)0xb8000)[80*4 + 2]; vga_text += printStr("Error loading file select. Ensure the disk has a valid MBR and FAT partition.", vga_text); vga_text = &((word*)0xb8000)[80*5 + 2]; diff --git a/progs.c b/progs.c index fbbff33..ca54182 100644 --- a/progs.c +++ b/progs.c @@ -87,7 +87,7 @@ void TextViewTest(uint8_t *path, VOLINFO *vi) { for (; o < (int32_t)fileLen && vga_text < &((uint16_t*)0xb8000)[screenSize]; c = diskReadBuf[++o]) { // newline if (c == 0x0A) { - vga_text = nextLine(vga_text); + vga_text = nextLine(vga_text,(uint16_t*)0xb8000); line++; { uint16_t *vga_tmp = vga_text; @@ -225,7 +225,7 @@ void ProgramLoadTest(uint8_t *path, VOLINFO *vi) { vga_text += printStr("\", ", vga_text); vga_text += printDec(successcount, vga_text); vga_text += printStr(" Bytes.", vga_text); - vga_text = nextLine(vga_text); + vga_text = nextLine(vga_text,(uint16_t*)0xb8000); vga_text += printStr("Press any key to run.", vga_text); kbd_wait(); uint32_t res = create_user_child(0x800000, 0x400000, 0);