File Selector uses a very simple double buffer

This commit is contained in:
Lucia Ceionia 2023-02-10 04:45:47 -06:00
parent 168816cb1e
commit cec3b93c83
5 changed files with 20 additions and 16 deletions

View File

@ -1,8 +1,8 @@
#include "helper.h" #include "helper.h"
uint16_t *nextLine(uint16_t *p) { uint16_t *nextLine(uint16_t *p, uint16_t *b) {
uintptr_t v = (uintptr_t)p; 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) { void V8086Int(uint8_t interrupt, union V86Regs_t *regs) {

View File

@ -11,7 +11,7 @@ void SetVideo25Lines();
void SetVideo50Lines(); void SetVideo50Lines();
void SetCursorDisabled(); void SetCursorDisabled();
uint16_t *nextLine(uint16_t *p); uint16_t *nextLine(uint16_t *p, uint16_t *b);
uint32_t OpenVol(VOLINFO *vi); uint32_t OpenVol(VOLINFO *vi);
uint32_t OpenDir(uint8_t *path, VOLINFO *vi, DIRINFO *di); uint32_t OpenDir(uint8_t *path, VOLINFO *vi, DIRINFO *di);

View File

@ -283,7 +283,7 @@ void HexEditor(uint8_t *path, VOLINFO *vi) {
else vga_text += printChar(' ', vga_text); else vga_text += printChar(' ', vga_text);
} }
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 // Clear remainder of screen
for (;vga_text < &((uint16_t*)0xb8000)[screenSize]; vga_text++) for (;vga_text < &((uint16_t*)0xb8000)[screenSize]; vga_text++)

View File

@ -202,8 +202,8 @@ Protected Only (1MB+)
400000 - 700000 Usermode Code (3mB) 400000 - 700000 Usermode Code (3mB)
700000 - 800000 Usermode Stack (1mB) 700000 - 800000 Usermode Stack (1mB)
*/ */
void DrawScreen() { void DrawScreen(uint16_t *vga) {
uint16_t *vga_text = (uint16_t *)0xB8000; uint16_t *vga_text = vga;
// clear screen // clear screen
for (int i = 0; i < 80*25; i++) for (int i = 0; i < 80*25; i++)
vga_text[i] = 0x1f00; vga_text[i] = 0x1f00;
@ -255,8 +255,8 @@ void RestoreVGA() {
int32_t fileCount; int32_t fileCount;
DIRENT *entries = (DIRENT*)0x400000; DIRENT *entries = (DIRENT*)0x400000;
void PrintFileList() { void PrintFileList(uint16_t *vga) {
uint16_t *vga_text = &((uint16_t *)0xb8000)[80*6+3]; uint16_t *vga_text = &((uint16_t *)vga)[80*6+3];
for (int i = 0; i < fileCount; i++) { for (int i = 0; i < fileCount; i++) {
DIRENT *de = &entries[i]; DIRENT *de = &entries[i];
for (int i = 0; i < 11 && de->name[i]; 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_2 << 16) +
((uint32_t)de->filesize_3 << 24), vga_text); ((uint32_t)de->filesize_3 << 24), vga_text);
*(uint8_t*)vga_text++ = 'B'; *(uint8_t*)vga_text++ = 'B';
vga_text = nextLine(vga_text) + 3; vga_text = nextLine(vga_text, vga) + 3;
} }
} }
char IsDir(DIRENT *de) { char IsDir(DIRENT *de) {
@ -287,6 +287,7 @@ void ScancodeTest() {
} }
} }
extern void create_child(uint32_t esp, uint32_t eip, uint32_t argc, ...); extern void create_child(uint32_t esp, uint32_t eip, uint32_t argc, ...);
uint16_t FileSelectScreen[80*25];
void FileSelect() { void FileSelect() {
uint8_t current_path[80]; uint8_t current_path[80];
uintptr_t current_path_end; uintptr_t current_path_end;
@ -295,10 +296,10 @@ void FileSelect() {
current_path[0] = '/'; current_path[0] = '/';
current_path_end = 1; current_path_end = 1;
fileCount = 5; fileCount = 5;
uint16_t *vga_text = (uint16_t *)0xb8000; uint16_t *vga_text = (uint16_t *)FileSelectScreen;
int32_t fileHovered = 0, lastFileHovered = 0; int32_t fileHovered = 0, lastFileHovered = 0;
for (char reload = 1;;) { for (char reload = 1;;) {
DrawScreen(); DrawScreen(vga_text);
// Info line (4) // Info line (4)
{ {
uint16_t *vga = &vga_text[80*4 + 79 - 24]; uint16_t *vga = &vga_text[80*4 + 79 - 24];
@ -323,12 +324,15 @@ void FileSelect() {
GetFileList(entries, &fileCount, &vi, &di); GetFileList(entries, &fileCount, &vi, &di);
reload = 0; reload = 0;
} }
PrintFileList(); PrintFileList(vga_text);
if (lastFileHovered != fileHovered) { if (lastFileHovered != fileHovered) {
*(uint8_t*)&vga_text[80*(6+lastFileHovered)+2] = ' '; *(uint8_t*)&vga_text[80*(6+lastFileHovered)+2] = ' ';
lastFileHovered = fileHovered; lastFileHovered = fileHovered;
} }
*(uint8_t*)&vga_text[80*(6+fileHovered)+2] = '>'; *(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(); uint16_t key = get_scancode();
uint8_t path[13]; uint8_t path[13];
switch (key & 0xff) { // scancode component switch (key & 0xff) { // scancode component
@ -476,7 +480,7 @@ void start() {
//if (key == 't' || key == 'T') //if (key == 't' || key == 'T')
// create_child(GetFreeStack(), (uintptr_t)RunTests, 0); // create_child(GetFreeStack(), (uintptr_t)RunTests, 0);
RestoreVGA(); RestoreVGA();
DrawScreen(); DrawScreen((uint16_t*)0xb8000);
uint32_t stack; uint32_t stack;
asm volatile("mov %%esp,%%eax":"=a"(stack)); asm volatile("mov %%esp,%%eax":"=a"(stack));
stack = ((stack - 0x4000) / 0x1000) * 0x1000; stack = ((stack - 0x4000) / 0x1000) * 0x1000;
@ -490,7 +494,7 @@ void start() {
enter_v86(0x8000, 0xFF00, FP_SEG(v86_entry), FP_OFF(v86_entry), &regs); enter_v86(0x8000, 0xFF00, FP_SEG(v86_entry), FP_OFF(v86_entry), &regs);
} }
RestoreVGA(); RestoreVGA();
DrawScreen(); DrawScreen((uint16_t*)0xb8000);
vga_text = &((word*)0xb8000)[80*4 + 2]; 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 += printStr("Error loading file select. Ensure the disk has a valid MBR and FAT partition.", vga_text);
vga_text = &((word*)0xb8000)[80*5 + 2]; vga_text = &((word*)0xb8000)[80*5 + 2];

View File

@ -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]) { for (; o < (int32_t)fileLen && vga_text < &((uint16_t*)0xb8000)[screenSize]; c = diskReadBuf[++o]) {
// newline // newline
if (c == 0x0A) { if (c == 0x0A) {
vga_text = nextLine(vga_text); vga_text = nextLine(vga_text,(uint16_t*)0xb8000);
line++; line++;
{ {
uint16_t *vga_tmp = vga_text; uint16_t *vga_tmp = vga_text;
@ -225,7 +225,7 @@ void ProgramLoadTest(uint8_t *path, VOLINFO *vi) {
vga_text += printStr("\", ", vga_text); vga_text += printStr("\", ", vga_text);
vga_text += printDec(successcount, vga_text); vga_text += printDec(successcount, vga_text);
vga_text += printStr(" Bytes.", 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); vga_text += printStr("Press any key to run.", vga_text);
kbd_wait(); kbd_wait();
uint32_t res = create_user_child(0x800000, 0x400000, 0); uint32_t res = create_user_child(0x800000, 0x400000, 0);