diff --git a/helper.c b/helper.c index bfa6961..38ef099 100644 --- a/helper.c +++ b/helper.c @@ -5,6 +5,22 @@ uint16_t *nextLine(uint16_t *p, uint16_t *b) { return (uint16_t *)(v + (160 - ((v - (uintptr_t)b) % 160))); } +void trimPath(char *path, char *buff, uint32_t maxLen) { + int pathLen = 0; + for (;path[pathLen];pathLen++); + pathLen++; + if (pathLen < maxLen) { + for(int i = 0; i < pathLen; i++) + buff[i] = path[i]; + return; + } + for (int i = 0; i < 3; i++) + buff[i] = '.'; + for (int i = 3; i < maxLen; i++) { + buff[i] = path[pathLen-maxLen+i]; + } +} + void V8086Int(uint8_t interrupt, union V86Regs_t *regs) { // Edit the v8086 code with the interrupt // Writing 4 bytes to ensure proper code @@ -65,7 +81,7 @@ void File83ToPath(char *src, char *path) { path[tmp] = 0; } -void GetFileList(DIRENT *entries, int32_t *entCount, VOLINFO *vi, DIRINFO *di) { +void GetFileList(DIRENT *entries, int32_t *entCount, int32_t maxEntries, VOLINFO *vi, DIRINFO *di) { uint8_t *diskReadBuf = (uint8_t *)0x20000; DIRENT de; int32_t fileCount = 0; @@ -77,6 +93,7 @@ void GetFileList(DIRENT *entries, int32_t *entCount, VOLINFO *vi, DIRINFO *di) { d[i] = s[i]; fileCount++; } + if (fileCount >= maxEntries) break; } *entCount = fileCount; } diff --git a/helper.h b/helper.h index b0b830f..31e4851 100644 --- a/helper.h +++ b/helper.h @@ -12,8 +12,9 @@ void SetVideo50Lines(); void SetCursorDisabled(); uint16_t *nextLine(uint16_t *p, uint16_t *b); +void trimPath(char *path, char *buff, uint32_t maxLen); uint32_t OpenVol(VOLINFO *vi); uint32_t OpenDir(uint8_t *path, VOLINFO *vi, DIRINFO *di); void File83ToPath(char *src, char *path); -void GetFileList(DIRENT *entries, int32_t *entCount, VOLINFO *vi, DIRINFO *di); +void GetFileList(DIRENT *entries, int32_t *entCount, int32_t maxEntries, VOLINFO *vi, DIRINFO *di); diff --git a/hexedit.c b/hexedit.c index 4acab45..b649e14 100644 --- a/hexedit.c +++ b/hexedit.c @@ -244,11 +244,15 @@ void HexEditor(uint8_t *path, VOLINFO *vi) { } if (redraw) { vga_text = (uint16_t *)0xb8000; - vga_text += printStr((char*)path, vga_text); - vga_text += printChar(fileChanged ? '*' : ' ', vga_text); { const char prnt[] = "Scroll: Up/Down PgUp/PgDown Home/End Exit: F1"; - vga_text = &((uint16_t*)0xb8000)[80-sizeof(prnt)]; + vga_text = &((uint16_t*)0xb8000)[0]; + char pathBuff[22]; + trimPath((char*)path, pathBuff, sizeof(pathBuff)); + vga_text += printStr(pathBuff, vga_text); + vga_text += printChar(fileChanged ? '*' : ' ', vga_text); + for (;vga_text < &((uint16_t*)0xb8000)[80-sizeof(prnt)];) + vga_text += printChar(' ', vga_text); vga_text += printStr((char*)prnt, vga_text); } vga_text = &((uint16_t*)0xb8000)[80]; @@ -407,8 +411,12 @@ void HexEditor(uint8_t *path, VOLINFO *vi) { } if (!fileChanged) return; vga_text = (uint16_t*)0xb8000; - vga_text += printStr((char*)path, vga_text); - vga_text += printChar(fileChanged ? '*' : ' ', vga_text); + { + char pathBuff[23]; + trimPath((char*)path, pathBuff, sizeof(pathBuff)); + vga_text += printStr(pathBuff, vga_text); + vga_text += printChar(fileChanged ? '*' : ' ', vga_text); + } vga_text += printChar(' ', vga_text); vga_text += printStr("Save changes to file? (Y/N)", vga_text); for (;vga_text < &((uint16_t*)0xb8000)[80];vga_text++) diff --git a/kernel.c b/kernel.c index 5358bca..5b2e3a5 100644 --- a/kernel.c +++ b/kernel.c @@ -253,12 +253,13 @@ void RestoreVGA() { SetPalette(); } -int32_t fileCount; +int32_t fileCount, fileOffset; DIRENT *entries = (DIRENT*)0x400000; +#define MAXDISPFILES 16 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 + fileOffset) < fileCount && i < MAXDISPFILES; i++) { + DIRENT *de = &entries[i + fileOffset]; for (int i = 0; i < 11 && de->name[i]; i++) { if (i == 8) { *(uint8_t*)vga_text = ' '; vga_text++; } // space for 8.3 *(uint8_t *)vga_text = de->name[i]; @@ -297,7 +298,8 @@ void FileSelect() { current_path_end = 1; fileCount = 5; uint16_t *vga_text = (uint16_t *)FileSelectScreen; - int32_t fileHovered = 0, lastFileHovered = 0; + int32_t fileHovered = 0; + fileOffset = 0; for (char reload = 1;;) { DrawScreen(vga_text); // Info line (4) @@ -321,15 +323,22 @@ void FileSelect() { OpenVol(&vi); current_path[current_path_end] = 0; OpenDir(current_path, &vi, &di); - GetFileList(entries, &fileCount, &vi, &di); + GetFileList(entries, &fileCount, INT32_MAX, &vi, &di); reload = 0; } - PrintFileList(vga_text); - if (lastFileHovered != fileHovered) { - *(uint8_t*)&vga_text[80*(6+lastFileHovered)+2] = ' '; - lastFileHovered = fileHovered; + if (fileHovered >= fileCount) { + fileOffset = fileCount - MAXDISPFILES; + fileHovered = fileCount - 1; } - *(uint8_t*)&vga_text[80*(6+fileHovered)+2] = '>'; + if ((fileHovered - fileOffset) >= MAXDISPFILES) + fileOffset = fileHovered - MAXDISPFILES + 1; + else if ((fileHovered - fileOffset) < 0) + fileOffset = fileHovered; + PrintFileList(vga_text); + for (int i = 6; i < 24; i++) { + *(uint8_t*)&vga_text[80*i+2] = ' '; + } + *(uint8_t*)&vga_text[80*(6+(fileHovered-fileOffset))+2] = '>'; // Copy to real VGA for (int i = 0; i < 80*25; i++) ((uint16_t*)0xb8000)[i] = vga_text[i]; @@ -338,7 +347,7 @@ void FileSelect() { switch (key & 0xff) { // scancode component case KEY_DOWN: // down fileHovered++; - if (fileHovered >= fileCount) fileHovered = 0; + if (fileHovered >= fileCount) { fileHovered = 0; fileOffset = 0; } break; case KEY_UP: // up fileHovered--; @@ -392,6 +401,7 @@ void FileSelect() { current_path[current_path_end] = 0; reload = 1; fileHovered = 0; + fileOffset = 0; break; } for (int i = 0; (i + current_path_end) < sizeof(current_path); i++) @@ -402,6 +412,7 @@ void FileSelect() { current_path[current_path_end] = 0; reload = 1; fileHovered = 0; + fileOffset = 0; } break; case KEY_F6: diff --git a/progs.c b/progs.c index 3e50d47..d14cec5 100644 --- a/progs.c +++ b/progs.c @@ -62,16 +62,17 @@ void TextViewTest(uint8_t *path, VOLINFO *vi) { vga_text = (uint16_t *)0xb8000; for (int i = 0; i < screenSize; i++) vga_text[i] = 0x0f00; - vga_text += printStr((char*)path, vga_text); + char pathBuff[22]; + trimPath((char*)path, pathBuff, sizeof(pathBuff)); + vga_text += printStr(pathBuff, vga_text); vga_text += 2; - vga_text += printStr("Line: ", vga_text); vga_text += printDec(currLine, vga_text); vga_text += printChar('/', vga_text); vga_text += printDec(lastLine, vga_text); vga_text += printStr(" Scroll: Up/Down PgUp/PgDown Home/End", vga_text); { - const char prnt[] = "Exit: E "; - vga_text = &((uint16_t*)0xb8000)[80-sizeof(prnt)]; + const char prnt[] = "Exit: E"; + vga_text = &((uint16_t*)0xb8000)[80-sizeof(prnt)+1]; vga_text += printStr((char*)prnt, vga_text); } for (vga_text = &((uint16_t*)0xb8000)[84]; vga_text < &((uint16_t*)0xb8000)[screenSize]; vga_text += 80)