377 lines
8.8 KiB
C
377 lines
8.8 KiB
C
#include <debugio.h>
|
|
#include <time.h>
|
|
#include <stdio.h>
|
|
#include <memory-add.h>
|
|
#include "../hal/mouse/mouse.h"
|
|
#include "../drivers/floppy/floppy.h"
|
|
#include <fileio.h>
|
|
|
|
string ConsoleCommands[] =
|
|
{
|
|
"osver",
|
|
"time",
|
|
"cls",
|
|
"help",
|
|
"dump",
|
|
"mem",
|
|
"crash",
|
|
"mouse",
|
|
"read",
|
|
"reboot",
|
|
"restart",
|
|
"dir",
|
|
"cat",
|
|
"fork"
|
|
};
|
|
|
|
int32 ConsoleCommandsCount = 14;
|
|
|
|
/*****************************************
|
|
* osver - get os info *
|
|
*****************************************/
|
|
void CommandOsver()
|
|
{
|
|
ConsoleWrite ("%#%s%# 32bit operating system\n", Color(0,ColorYellow), OS_STRING, Color(0,ColorLightGray));
|
|
|
|
int32 i = 0;
|
|
for (i = 0; i < 30; i++)
|
|
ConsoleWrite ("%#%c", ColorDarkGray, 205);
|
|
|
|
ConsoleWrite ("\n%#OS version: %#%s\n", ColorDarkGray, ColorLightGray, OS_VERSION);
|
|
ConsoleWrite ("%#Build: %#%s ", ColorDarkGray, ColorLightGray, OS_BUILD);
|
|
ConsoleWrite ("%#built on %#%s %#at %#%s\n", ColorDarkGray, ColorLightGray, OS_BUILD_DATE, ColorDarkGray, ColorLightGray, OS_BUILD_TIME);
|
|
ConsoleWrite ("%#(c) Copyright %#CTA Systems Inc.\n", ColorDarkGray ,ColorLightGray);
|
|
}
|
|
|
|
|
|
/*****************************************
|
|
* time - get date and time *
|
|
*****************************************/
|
|
void CommandTime()
|
|
{
|
|
const char* Months[] = {
|
|
"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
|
|
};
|
|
|
|
const char* Weekdays[] = {
|
|
"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
|
|
};
|
|
|
|
|
|
Time time = ConvertTimeSystemToTime(TimeGetInternalTime());
|
|
|
|
ConsoleWrite ("Current time: ");
|
|
ConsoleWrite ("%#%d:%d%d:%d%d.%d%d%d\n", Color(0,ColorLightGreen) ,(int)time.Hour,
|
|
time.Minute/10, time.Minute%10, time.Second/10, time.Second%10, time.Milisecond/100, (time.Milisecond/10)%10, time.Milisecond%10);
|
|
|
|
ConsoleWrite ("Date: %#%s, %s %d, %d\n", Color(0,ColorLightGreen), Weekdays[time.WeekDay],
|
|
Months[time.Month], time.Day, time.Year);
|
|
|
|
}
|
|
|
|
|
|
/*****************************************
|
|
* help - help provider *
|
|
*****************************************/
|
|
void CommandHelp(string params[], int32 count)
|
|
{
|
|
if (count <= 1)
|
|
{
|
|
ConsoleWrite ("Available commands:\n");
|
|
|
|
int i;
|
|
for (i = 0; i < ConsoleCommandsCount; i++)
|
|
ConsoleWrite(" > %#%s\n", Color(0,ColorWhite), ConsoleCommands[i]);
|
|
|
|
return;
|
|
}
|
|
|
|
ConsoleWrite("%#! Help for %s command is not implemented yet.\n", Color(0,ColorLightRed), params[1]);
|
|
}
|
|
|
|
|
|
/*****************************************
|
|
* dump - dumps memory content *
|
|
*****************************************/
|
|
inline char hex (int32 digit)
|
|
{
|
|
return (digit < 10) ? (digit + '0') : (digit - 10 + 'A');
|
|
}
|
|
|
|
void CommandDump (string argv[], int32 argc)
|
|
{
|
|
unsigned pause = 1, i = 0;
|
|
|
|
// Verify correct number of arguments
|
|
if (argc < 3) {
|
|
ConsoleWrite("%#! Correct syntax: %#dump %#[start_address] [end_address]\n",
|
|
ColorLightRed, ColorWhite, ColorLightGray);
|
|
ConsoleWrite("%#Start %#and %#end %#addresses are in hex.\n",
|
|
ColorLightGray, ColorDarkGray, ColorLightGray, ColorDarkGray);
|
|
return;
|
|
}
|
|
|
|
// Disable pause
|
|
if (argc==4 && strcmp(argv[3], "!p") == 0)
|
|
pause = 0;
|
|
|
|
// Dump memory
|
|
unsigned char *start, *end;
|
|
start = (unsigned char *) ConvertStringToIntHex(argv[1]);
|
|
end = (unsigned char *) ConvertStringToIntHex(argv[2]);
|
|
unsigned char* count;
|
|
|
|
while (start <= end) {
|
|
// Write address
|
|
ConsoleWrite("%#%x%#: ", Color(0,ColorLightMagenta), (unsigned int)start, Color(0,ColorLightGray));
|
|
|
|
// Write hex data
|
|
for (count = start; count < start+16; count++) {
|
|
if (*count == 0) ConsoleWrite ("%#00 ", Color(0,ColorDarkGray));
|
|
else ConsoleWrite ("%#%c%c ", Color(0,ColorWhite), hex(*count/16), hex(*count%16));
|
|
}
|
|
|
|
// Write ASCII data
|
|
ConsoleWrite(" ");
|
|
for (count = start; count < start+16; count++) {
|
|
if (*count < 32) ConsoleWrite(".");
|
|
else ConsoleWrite("%#%c", Color(0,ColorLightGreen), *count);
|
|
}
|
|
|
|
// New line
|
|
ConsoleWrite("\n\r");
|
|
start+=16; i++;
|
|
|
|
// Pause
|
|
if ((i%22 == 0) && (pause==1)) {
|
|
ConsoleWrite("\n\r%#Press %#any key %#to continue scrolling, %#Esc %#to exit.",
|
|
0x8, 0x7, 0x8, 0x7, 0x8);
|
|
Key k = ReadKey();
|
|
if (k.Scancode == KeyboardKeyEscape) return;
|
|
ConsoleWrite("\n\n\r");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#define _CommandMemTotalRows 10
|
|
void _CommandMemPrintMemmap()
|
|
{
|
|
uint8 color = Color(ColorGreen, ColorRed);
|
|
uint32 total = MemoryGetFramesTotal();
|
|
|
|
char c = ' ';
|
|
|
|
// Print memory map
|
|
int32 i, old = 0, n = 0, blocks, used;
|
|
for (i = 0; i < 80; i++)
|
|
ConsoleWrite("%#%c", ColorLightGray, 220);
|
|
|
|
for (i = 1; i <= 80*_CommandMemTotalRows; i++, old++)
|
|
{
|
|
n = (total * i) / (80 * _CommandMemTotalRows);
|
|
|
|
blocks = n - old;
|
|
used = 0;
|
|
for (; old < n; old++)
|
|
used += (MemPhGetFrame(old) != 0);
|
|
|
|
if (used <= blocks / 5) c = ' ';
|
|
else if (used > 4 * blocks / 5) c = 219;
|
|
else if (used <= 2 * blocks / 5) c = 176;
|
|
else if (used <= 3 * blocks / 5) c = 177;
|
|
else c = 178;
|
|
|
|
ConsoleWrite("%#%c", color, c);
|
|
}
|
|
|
|
for (i = 0; i < 80; i++)
|
|
ConsoleWrite("%#%c", ColorDarkGray, 223);
|
|
}
|
|
|
|
void CommandMem (string argv[], int32 argc)
|
|
{
|
|
if (argc < 2)
|
|
{
|
|
ConsoleWrite ("Physical memory map:\n");
|
|
|
|
_CommandMemPrintMemmap();
|
|
|
|
ConsoleWrite ("Free space: %#%ukb (%u frames)\n", ColorLightMagenta, MemoryGetFree(), MemoryGetFramesFree());
|
|
ConsoleWrite ("Used space: %#%ukb (%u frames)\n\n", ColorLightMagenta, MemoryGetUsed(), MemoryGetFramesUsed());
|
|
ConsoleWrite ("Total space: %#%ukb (%u frames)\n", ColorLightMagenta, MemoryGetTotal(), MemoryGetFramesTotal());
|
|
|
|
return;
|
|
}
|
|
|
|
if (strcmp(argv[1], "alloc") == 0)
|
|
{
|
|
uint32 addr = 0;
|
|
if (argc < 3) addr = (uint32)kmalloc(0x4);
|
|
else addr = (uint32)kmalloc(ConvertStringToUInt(argv[2]));
|
|
|
|
ConsoleWrite("Returned address: %#0x%x\n", ColorWhite, addr);
|
|
}
|
|
|
|
else if (strcmp(argv[1], "free") == 0)
|
|
{
|
|
if (argc < 3) {
|
|
ConsoleWrite ("%#! Missing parameter: address to free.", ColorRed);
|
|
return;
|
|
}
|
|
|
|
kfree((void*)ConvertStringToIntHex(argv[2]));
|
|
ConsoleWrite("Done.\n");
|
|
}
|
|
|
|
else ConsoleWrite("%#! Invalid command. Available commands are: alloc, free.", ColorLightRed);
|
|
}
|
|
|
|
void CommandCrash()
|
|
{
|
|
int a = 10, b = 0;
|
|
ConsoleWrite ("%d", a/b);
|
|
}
|
|
|
|
void CommandMouse()
|
|
{
|
|
MouseState s = MouseGetState();
|
|
ConsoleWrite("X=%d Y=%d Buttons=", s.Position.X, s.Position.Y);
|
|
|
|
if (!s.Buttons) ConsoleWrite("<none>");
|
|
if (s.Buttons & 1) ConsoleWrite("<left>");
|
|
if (s.Buttons & 2) ConsoleWrite("<right>");
|
|
if (s.Buttons & 4) ConsoleWrite("<mid>");
|
|
|
|
ConsoleWrite("\n");
|
|
}
|
|
|
|
void CommandRead(string argv[], int32 argc)
|
|
{
|
|
if (argc < 2)
|
|
{
|
|
ConsoleWrite("%#! Missing parameter - sector!\n", ColorLightRed);
|
|
return;
|
|
}
|
|
|
|
uint32 sector = ConvertStringToUInt(argv[1]);
|
|
ConsoleWrite("Returned value: 0x%x\n", FloppyRead(0, sector));
|
|
}
|
|
|
|
|
|
void CommandDir (string argv[], int32 argc)
|
|
{
|
|
// No parameters? Display root content
|
|
if (argc < 2) {
|
|
ConsoleWrite ("Content of root: \n\n");
|
|
uint32 i = 0;
|
|
MountPoint* mp = VfsGetMountPoint(0);
|
|
|
|
for (i = 1; mp != NULL; i++)
|
|
{
|
|
ConsoleWrite ("\t[DEV] %s\n", mp->Name);
|
|
mp = VfsGetMountPoint(i);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// Make sure directory exists
|
|
DirectoryEntry* temp = VfsTest(argv[1]);
|
|
|
|
if (temp == NULL) {
|
|
ConsoleWrite("%#! Invalid path!\n", ColorLightRed); return;
|
|
}
|
|
|
|
if ((temp->Flags & 0x7) == 0x1) {
|
|
ConsoleWrite("%#! Not a directory!\n", ColorLightRed); return;
|
|
}
|
|
|
|
// Write contents
|
|
ConsoleWrite ("Content of directory %#%s:\n\n", ColorWhite, argv[1]);
|
|
|
|
FILE dir; VfsOpen(&dir, argv[1]);
|
|
uint32 i;
|
|
|
|
temp = VfsReadDirectory(&dir,0);
|
|
for (i = 1; temp != NULL; i++)
|
|
{
|
|
ConsoleWrite ("\t[%s] ", (temp->Flags & 0x1) ? "FIL" : "DIR" );
|
|
ConsoleWrite ("%s", temp->Name);
|
|
Point p = {60, -1}; ConsoleCursorGoto(p);
|
|
ConsoleWrite ("%u bytes\n", temp->Size);
|
|
|
|
temp = VfsReadDirectory(&dir, i);
|
|
}
|
|
|
|
VfsClose(&dir);
|
|
}
|
|
|
|
void CommandCat (string argv[], int32 argc)
|
|
{
|
|
if (argc < 2) {
|
|
ConsoleWrite("%#! Missing parameter - complete file path.\n", ColorLightRed);
|
|
return;
|
|
}
|
|
|
|
FILE f;
|
|
|
|
// Try to open
|
|
if (!VfsOpen(&f, argv[1])) {
|
|
ConsoleWrite ("%#! Invalid file: %s\n.", ColorLightRed, argv[1]);
|
|
return;
|
|
}
|
|
|
|
uint8* buffer = kmalloc(0x100);
|
|
uint32 sz, i;
|
|
|
|
ConsoleWrite("----[%s]------\n", argv[1]);
|
|
|
|
while ((sz = VfsRead(&f, 1, 0x100, buffer)))
|
|
{
|
|
for (i = 0; i < sz; i++) ConsoleWrite("%#%c", ColorLightGray, buffer[i]);
|
|
}
|
|
|
|
ConsoleWrite("\n------------[EOF]------------\n");
|
|
kfree(buffer);
|
|
VfsClose(&f);
|
|
}
|
|
|
|
#include <tasking.h>
|
|
void CommandFork()
|
|
{
|
|
ConsoleClear();
|
|
|
|
Point a = {5,1};
|
|
Point b = {5,2};
|
|
|
|
// Child?
|
|
if (Fork() == 0)
|
|
{
|
|
uint32 i;
|
|
for (i = 0; i < 0x7fffffff; i++)
|
|
{
|
|
ConsoleCursorGoto(a);
|
|
ConsoleWrite ("[c] Hello %u", i);
|
|
|
|
if (i > 0x7ffffff0) i = 0;
|
|
}
|
|
|
|
for (;;);
|
|
}
|
|
|
|
// Not child?
|
|
else {
|
|
uint32 i;
|
|
for (i = 0; i < 0x7fffffff; i++)
|
|
{
|
|
ConsoleCursorGoto(b);
|
|
ConsoleWrite ("[p] world %u", i);
|
|
|
|
if (i > 0x7ffffff0) i = 0;
|
|
}
|
|
|
|
for (;;);
|
|
}
|
|
}
|