#define hex(x) (x < 10) ? x+'0' : x-10+'a' const char *apps_lst[] = { /*0*/ "", /*1*/ "reboot", /*2*/ "osver", /*3*/ "time", /*4*/ "place", /*5*/ "cls", /*6*/ "dump", /*7*/ "help", /*8*/ "cpuid", /*9*/ "memstat", /*A*/ "read", /*B*/ "mount", /*C*/ "write" }; int apps_count = 13; void apps_osver() { cprintf ("%#0BC%#0CT%#0AA %#0F32bit Operating System v0.1\n\r"); cprintf ("(c) CTA 2010\n\r"); } void apps_time() { TIME _internal_clock = ClockGetTime(); cprintf ("Today is %#0F%s%#07, %#0F%u %#07of %#0F%s%#07, %#0F%u%u%#07.\n\r", clock_weekday[_internal_clock.weekday], (unsigned) _internal_clock.day, clock_month[_internal_clock.month], (unsigned) _internal_clock.century, (unsigned) _internal_clock.year); cprintf ("%#07Now is %#0F%u%#87:%#0F%u%#87:%#0F%u%#07.\n\r", (unsigned) _internal_clock.hour, (unsigned) _internal_clock.minute, (unsigned) _internal_clock.second); } void apps_place() { cprintf ("%#0FOn your desk, %#07if you didn't notice... \n\r"); } void apps_clrscr() { clrscr(); } void apps_dump(const int pn, const char* param[]) { unsigned pause=0, i=0; if (pn<3) { cprintf ("%#0CCorrect syntax: %#07dump %#0F[start_address] %#0F[end_address] %#0C(in hex)\n\r"); return; } if (pn==4 && strcmp(param[3], "--p") == 0) pause=1; unsigned char *start, *end; start = (unsigned char *) atox (param[1]); end = (unsigned char *) atox (param[2]); unsigned char* count; while (start <= end) { cprintf("%#0D%x%#07: ", (unsigned int) start); for (count = start; count < start+16; count++) { if (*count == 0) cprintf ("%#0800 "); else cprintf ("%#0F%c%c ", hex(*count/16), hex(*count%16)); } cprintf(" "); for (count = start; count < start+16; count++) { if (*count < 32) cprintf("."); else cprintf("%#0A%c", *count); } cprintf("\n\r"); start+=16; i++; if ((i%22 == 0) && (pause==1)) { cprintf("\n\r%#08Press %#07any key %#08to continue scrolling, %#07Esc %#08to exit."); KeyboardKey t; t = GetKey(); if (t.Scancode == KeyboardKeyEscape) return; cprintf("\n\n\r"); } } } int apps_help_sort(const void* a, const void* b) { return strcmp(apps_lst[*(short *)a], apps_lst[*(short *)b]); } void apps_help(const int pn, const char* param[]) { short arr[apps_count]; int i; for (i = 0; i < apps_count; i++) arr[i] = i; qsort((void*)arr, apps_count, sizeof(short), apps_help_sort); if (pn==1) { cprintf("%#0BC%#0CT%#0AA %#0FShell %#07commands:\n\r"); for (i = 1; i < apps_count; i++) cprintf("%#0F\t%c %s\n\r", 0x7 ,apps_lst[arr[i]]); cprintf("\n\rUse help %#0E[command]%#07 for help on individual commands.\n\r"); return; } for (i = 0; strcmp(apps_lst[i], param[1])!=0 && i