Tiberiu Chibici
caa7718af9
==================================================== Mainly changed: HAL.FSs + Updated 'mount' call in floppy driver, now done after controller is initialized + Added 'detect' function for FAT file systems + Implemented 'initdr' driver, however still bugged + Improved logger
96 lines
2.2 KiB
C
96 lines
2.2 KiB
C
#include <debugio.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include "commands.c"
|
|
|
|
void _process_command (string params[16], int32 count);
|
|
void _command_does_not_exist(string command);
|
|
|
|
void ConsoleMain()
|
|
{
|
|
char buffer[512];
|
|
string params[CONSOLE_MAX_PARAMS];
|
|
|
|
CommandOsver();
|
|
|
|
for (;;)
|
|
{
|
|
// Read a string
|
|
ConsoleWrite("\n%#] ", Color(ColorBlack, ColorYellow));
|
|
ConsoleReadString(buffer, 512, '\n');
|
|
|
|
// Split buffer in params
|
|
params[0] = buffer;
|
|
|
|
int32 i=0, len = strlen(buffer), param_count = 0;
|
|
|
|
while (i < len && param_count < CONSOLE_MAX_PARAMS)
|
|
{
|
|
// Skip spaces before
|
|
while (i < len && isspace(buffer[i])) buffer[i++] = 0;
|
|
if (i == len) break;
|
|
|
|
params[param_count++] = &buffer[i];
|
|
|
|
// Skip non-spaces
|
|
while (i < len && !isspace(buffer[i])) i++;
|
|
}
|
|
|
|
// Send command to processing
|
|
_process_command(params, param_count);
|
|
}
|
|
|
|
}
|
|
|
|
void _process_command (string params[CONSOLE_MAX_PARAMS], int32 count)
|
|
{
|
|
int32 Cmd = -1;
|
|
|
|
if (count == 0)
|
|
{
|
|
ConsoleWrite ("%#! You must enter a command!\n", Color(0, ColorLightRed));
|
|
return;
|
|
}
|
|
|
|
// Lookup command in list
|
|
int32 i;
|
|
for (i = 0; i < ConsoleCommandsCount && Cmd == -1; i++)
|
|
if (strcmp(params[0], ConsoleCommands[i]) == 0) Cmd = i;
|
|
|
|
switch (Cmd)
|
|
{
|
|
case -1: _command_does_not_exist(params[0]); break;
|
|
case 0: CommandOsver(); break;
|
|
case 1: CommandTime(); break;
|
|
case 2: ConsoleClear(); break;
|
|
case 3: CommandHelp(params, count); break;
|
|
case 4: CommandDump (params, count); break;
|
|
case 5: CommandMem(params, count); break;
|
|
case 6: CommandCrash(); break;
|
|
case 7: CommandMouse(); break;
|
|
case 8: CommandRead(params, count); break;
|
|
case 9:
|
|
case 10: SystemReboot(); break;
|
|
case 11: CommandDir(params, count); break;
|
|
case 12: CommandCat(params, count); break;
|
|
|
|
default: ConsoleWrite ("%#! Command %#%s%# was not implemented (yet)!\n",
|
|
Color(0,ColorLightRed), Color(0,ColorWhite), params[0], Color(0,ColorLightRed)); break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void _command_does_not_exist(string command)
|
|
{
|
|
if (strlen(command) > 20)
|
|
{
|
|
command[18] = command[19] = command[20] = '.';
|
|
command[21] = null;
|
|
}
|
|
|
|
ConsoleWrite ("%#! Command %#%s%# does not exist!\n",
|
|
Color(0,ColorLightRed), Color(0,ColorWhite), command, Color(0,ColorLightRed));
|
|
|
|
}
|