From 2c4c76d1e735983989f72fe641ab30dc6f7ee896 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Tue, 7 Sep 2021 10:46:09 +0100 Subject: [PATCH] Added filename decoding to strings --- kernel32.c | 22 +++++++++++++++++++++- strings.c | 22 ++++++++++++++++++++++ strings.h | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/kernel32.c b/kernel32.c index 05fc4ed..8e0d6c7 100644 --- a/kernel32.c +++ b/kernel32.c @@ -56,8 +56,28 @@ int main() { set_curpos(0, 0); } else if (strcmp(buffer, "echo", 4)) { printf("%s\n", rest); + } else if (strcmp(buffer, "type", 4)) { + char filenamebuffer[12]; + uint8_t* filebuffer = 0x1006400; + + decode_filename(rest, filenamebuffer); + if (!file_exists(filenamebuffer)) { + printf("File %s not found!\n", filenamebuffer); + continue; + } + + for (int i=0; i<1024; i++) + hellotxt[i] = 0; + + load_file(filenamebuffer, filebuffer); + printf(filebuffer); } else { - printf("Bad Command or filename!\n"); + char filenamebuffer[12]; + decode_filename(buffer, filenamebuffer); + if (!file_exists(filenamebuffer)) { + printf("Bad Command or filename!\n"); + continue; + } } } } \ No newline at end of file diff --git a/strings.c b/strings.c index 4d23fc4..638405f 100644 --- a/strings.c +++ b/strings.c @@ -44,4 +44,26 @@ int string_split(char delimeter, char* string, char** pointer_array) { pointer_array[split_count] = (string+last_split_index); return split_count; +} + +void decode_filename(char* nice_name, char* filenamebuffer) { + // Clear filenamebuffer + for (int i=0; i<11; i++) + filenamebuffer[i] = ' '; + filenamebuffer[11] = 0; + + int fbIndex = 0; + for (int i=0; i<12; i++) { + if (nice_name[i] == 0) + return; + if (nice_name[i] == '.') { + fbIndex = 8; + continue; + } + + if (nice_name[i] >= 0x65 && nice_name[i] <= 0x65+26) + filenamebuffer[fbIndex++] = nice_name[i] & (0xff - 32); + else + filenamebuffer[fbIndex++] = nice_name[i]; + } } \ No newline at end of file diff --git a/strings.h b/strings.h index 8505e88..baf7c5c 100644 --- a/strings.h +++ b/strings.h @@ -6,5 +6,6 @@ bool strcmp(char* a, char* b, int max); char* split_on_first(char delimeter, char* string); int string_split(char delimeter, char* string, char** pointer_array); +void decode_filename(char* nice_name, char* filenamebuffer); #endif \ No newline at end of file