mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Improved shell by adding disk command (currently read only)
This commit is contained in:
+34
-10
@@ -24,7 +24,7 @@ void main() {
|
||||
|
||||
clear(0x0f);
|
||||
print("kern.\n\n", 0x0f);
|
||||
|
||||
|
||||
// Run Interactive Shell Program
|
||||
// TODO: Make it in another file
|
||||
|
||||
@@ -39,11 +39,42 @@ void main() {
|
||||
args = strchr(input, '\n');
|
||||
}
|
||||
|
||||
*args = '\0';
|
||||
*args = '\0'; // Separate command from args
|
||||
args++;
|
||||
|
||||
if (strcmp(input, "clear") == 0) {
|
||||
clear(0x0f);
|
||||
} else if (strcmp(input, "disk") == 0) {
|
||||
static char buf[512];
|
||||
|
||||
if (*args == '\0') {
|
||||
print("test: ", 0x0f);
|
||||
print("No arguments given\n", 0x0c);
|
||||
print("Usage: test <sector>\n", 0x0f);
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: We only support reading right now
|
||||
//char mode = *args++;
|
||||
//if (mode != 'r' || mode != 'w') {
|
||||
// print("test: ", 0x0f);
|
||||
// print("Invalid access mode. Use r(ead) or w(rite)\n", 0x0c);
|
||||
// print("Usage: test <r/w> <sector> [data]\n", 0x0f);
|
||||
// continue;
|
||||
//}
|
||||
|
||||
uint32_t sector = atoi(args);
|
||||
print("Reading...\n", 0x0f);
|
||||
diskRead(sector, 1, buf);
|
||||
|
||||
print("Contents:\n", 0x0f);
|
||||
for (size_t i = 0; i < 512; i++) {
|
||||
if (buf[i] != '\0') {
|
||||
putc(buf[i], 0x0f);
|
||||
}
|
||||
}
|
||||
|
||||
putc('\n', 0x0f);
|
||||
} else if (strcmp(input, "echo") == 0) {
|
||||
print(args, 0x0f);
|
||||
} else if (strcmp(input, "exit") == 0) {
|
||||
@@ -51,6 +82,7 @@ void main() {
|
||||
} else if (strcmp(input, "help") == 0) {
|
||||
print("Available Commands:\n", 0x0f);
|
||||
print(" clear | Clears the screen\n", 0x0f);
|
||||
print(" disk | Reads/Writes data from/to the disk\n", 0x0f);
|
||||
print(" echo | Prints a message to stdout\n", 0x0f);
|
||||
print(" exit | Exits shell\n", 0x0f);
|
||||
print(" help | Prints this message\n", 0x0f);
|
||||
@@ -58,14 +90,6 @@ void main() {
|
||||
// TODO: print(" reboot | Reboots the system\n", 0x0f);
|
||||
print(" test | Tests the latest feature [DEBUG]\n", 0x0f);
|
||||
} else if (strcmp(input, "test") == 0) {
|
||||
char buf[512];
|
||||
print("Reading from drive 0x", 0x0f);
|
||||
print(itoa(driveNum, 16), 0x0f);
|
||||
print("...\n", 0x0f);
|
||||
diskRead(22, 1, driveNum, buf);
|
||||
|
||||
print(buf, 0x0f);
|
||||
putc('\n', 0x0f);
|
||||
} else {
|
||||
print("Command not found: ", 0x0c);
|
||||
print(input, 0x0c);
|
||||
|
||||
Reference in New Issue
Block a user