luxos/SysCore/shell/apps.h

145 lines
4.3 KiB
C
Raw Normal View History

2021-09-14 15:34:14 +00:00
const char *apps_lst[] = {
"",
"reboot",
"osver",
"time",
"place",
"cls",
"memory",
"help",
"cpu_info",
2021-09-14 15:35:13 +00:00
"memstat"
2021-09-14 15:34:14 +00:00
};
2021-09-14 15:35:13 +00:00
int apps_count = 10;
2021-09-14 15:34:14 +00:00
unsigned int atox(const char* str)
{
unsigned int temp = 0;
int i; unsigned int digit = 0;
for (i = 0; str[i]!=0; i++) {
if (str[i] >= '0' && str[i] <= '9') digit = str[i] - '0';
else if (str[i] >= 'A' && str[i] <= 'F') digit = str[i] - 'A' + 10;
else if (str[i] >= 'a' && str[i] <= 'f') digit = str[i] - 'a' + 10;
else break;
temp = temp*16 + digit;
}
return temp;
}
unsigned int atoui(const char* str)
{
unsigned int temp = 0;
int i;
for (i = 0; str[i] >= '0' && str[i] <= '9' ; i++)
temp = temp*10 + (str[i] - '0');
return temp;
}
void apps_osver()
{
printf ("CTA 32bit Operating System v0.1");
printf ("\n(c) CTA 2010\n");
}
void apps_time()
{
printf ("Today is %s, %u of %s, %u%u.\n", clock_weekdays[_internal_clock.weekday],
(unsigned int) _internal_clock.day, clock_months[_internal_clock.month],
(unsigned int) _internal_clock.century, (unsigned int) _internal_clock.year);
printf ("Now is %u:%u:%u.\n", (unsigned int) _internal_clock.hours,
(unsigned int) _internal_clock.minutes, (unsigned int) _internal_clock.seconds);
}
void apps_place()
{
printf ("On your desk, if you didn't notice... \n");
}
void apps_clrscr()
{
clrscr();
}
void apps_memory(const int pn, const char* param[])
{
if (pn<3) {
printf ("Correct syntax: memory [start_address] [end_address] (in hex)\n");
return;
}
byte *start, *end;
start = (byte *) atox (param[1]);
end = (byte *) atox (param[2]);
byte* count;
while (start <= end) {
put_hex ((unsigned int) start); puts(": ");
for (count = start; count < start+16; count++) {
putc(hex[*count/16]); putc(hex[*count%16]);
putc(' ');
}
puts(" ");
for (count = start; count < start+16; count++) {
if (*count < 32) putc('.');
else putc(*count);
}
putc('\n');
start+=16;
}
}
void apps_help(const int pn, const char* param[])
{
int i;
puts ("\n");
if (pn==1) {
puts("[BeTA]\n");
puts("Available commands:");
for (i = 1; i < apps_count; i++) {
puts("\n \t "); puts((char*)apps_lst[i]);
}
puts("\n\nUse help [command] for help on individual commands.\n");
return;
}
for (i = 0; strcmp(apps_lst[i], param[1])!=0 && i<apps_count; i++);
puts("[BeTA]\nShowing help for command: "); puts((char*)apps_lst[i]);
switch (i) {
case 0: break;
case 1: puts("\n\nReboots the system.\nUsage: reboot"); break;
case 2: puts("\n\nShows information about the current operating system.\nUsage: osver"); break;
case 3: puts("\n\nDisplays the current date.\nUsage: date"); break;
case 5: puts("\n\nClears the screen.\nUsage: cls");break;
case 6: puts("\n\nShows the content of memory in the interval specified.\nUsage: memory [start_address] [end_address]");break;
case 7: puts("\n\nShows a list of commands, or help for a specified command.\nUsage: help [opt:command]"); break;
default: puts("Invalid function: "); puts((char*)param[1]);
break;
}
puts("\n\n");
}
extern void detect_cpu();
void apps_memory_status()
{
printf ("Memory available: %u KB \n", pmmngr_get_memory_size ());
printf ("Total blocks: %u Used: %u Free: %u\n", pmmngr_get_block_count (), pmmngr_get_use_block_count (), pmmngr_get_free_block_count ());
printf ("Block size: %u bytes\nPaging is ", pmmngr_get_block_size());
printf ( pmmngr_is_paging() ? "enabled.\n" : "disabled.\n");
}