1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

beep and commands

This commit is contained in:
Julian Barathieu 2019-05-18 19:09:46 +02:00
parent 1213055aff
commit df479e6336
4 changed files with 53 additions and 33 deletions

View File

@ -25,6 +25,8 @@
#include <ex/argv.h> #include <ex/argv.h>
#include <ex/malloc.h> #include <ex/malloc.h>
#include <kernel.h>
// //
// Computes argument count, the least N such // Computes argument count, the least N such
// that argv[N] == NULL // that argv[N] == NULL
@ -75,7 +77,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
char **argv, char **argv,
bool doEscaping) bool doEscaping)
{ {
int argc; int argc = 0;
char quotes = 0; char quotes = 0;
bool started = false; bool started = false;
bool escaping = false; bool escaping = false;
@ -92,7 +94,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
// Macro'd to avoid copypasting code // Macro'd to avoid copypasting code
#define NULLTERM_AND_SAVE \ #define NULLTERM_AND_SAVE \
*buffer = 0; \ *buffer = 0; \
argv[++argc] = buffer++ + 1; \ argv[++argc] = ++buffer; \
written += sizeof(char *) + 1; \ written += sizeof(char *) + 1; \
// Is character a blank character? // Is character a blank character?
@ -106,7 +108,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
// Go through the command line // Go through the command line
for (argc = 0; *cmdLine; cmdLine++) { for (; *cmdLine; cmdLine++) {
// Make sure we don't go beyond ARG_MAX bytes // Make sure we don't go beyond ARG_MAX bytes
if (written >= ARG_MAX - (1 + sizeof(char *))) { if (written >= ARG_MAX - (1 + sizeof(char *))) {

View File

@ -27,13 +27,13 @@
void IoStartSpeaker(int freq) void IoStartSpeaker(int freq)
{ {
char temp; uchar temp;
int pitf = 1193180 / freq; uint pitf = 1193180 / freq;
ulong flags = KePauseIRQs(); ulong flags = KePauseIRQs();
IoWriteByteOnPort(0x43, 0xB6); IoWriteByteOnPort(0x43, 0xB6);
IoWriteByteOnPort(0x42, (char)pitf); IoWriteByteOnPort(0x42, (uchar)pitf);
IoWriteByteOnPort(0x42, (char)(pitf >> 8)); IoWriteByteOnPort(0x42, (uchar)(pitf >> 8));
temp = IoReadByteFromPort(0x61); temp = IoReadByteFromPort(0x61);
if (temp != (temp | 3)) { if (temp != (temp | 3)) {
@ -44,14 +44,9 @@ void IoStartSpeaker(int freq)
void IoQuietSpeaker(void) void IoQuietSpeaker(void)
{ {
ulong flags = KePauseIRQs();
IoWriteByteOnPort(0x61, IoReadByteFromPort(0x61) & 0xFC); IoWriteByteOnPort(0x61, IoReadByteFromPort(0x61) & 0xFC);
} KeRestoreIRQs(flags);
void IoDoBeep(void)
{
IoStartSpeaker(1000);
KeDelayExecution(100);
IoQuietSpeaker();
} }
void IoDoTone(uint tone, uint time) void IoDoTone(uint tone, uint time)
@ -61,28 +56,34 @@ void IoDoTone(uint tone, uint time)
IoQuietSpeaker(); IoQuietSpeaker();
} }
void IoDoBeep(void)
{
IoDoTone(1000, 100);
}
void IoDoStarWars(void) void IoDoStarWars(void)
{ {
size_t i;
struct Note { struct Note {
uint tone; uint tone;
uint time; uint time;
}; };
struct Note Score[40] = { {440, 200}, {110, 200}, {440, 200}, {110, 200}, struct Note score[] = { {440, 200}, {110, 200}, {440, 200}, {110, 200},
{440, 200}, {110, 200}, {349, 140}, {87, 100}, {440, 200}, {110, 200}, {349, 140}, {87, 100},
{523, 60}, {87, 100}, {440, 200}, {110, 200}, {523, 60}, {87, 100}, {440, 200}, {110, 200},
{349, 140}, {87, 100}, {523, 60}, {87, 100}, {349, 140}, {87, 100}, {523, 60}, {87, 100},
{440, 200}, {110, 200}, {440, 200}, {110, 200}, {440, 200}, {110, 200}, {440, 200}, {110, 200},
{659, 200}, {110, 200}, {659, 200}, {110, 200}, {659, 200}, {110, 200}, {659, 200}, {110, 200},
{659, 200}, {87, 200}, {698, 140}, {87, 100}, {659, 200}, {87, 200}, {698, 140}, {87, 100},
{523, 60}, {87, 100}, {415, 200}, {87, 200}, {523, 60}, {87, 100}, {415, 200}, {87, 200},
{349, 140}, {87, 100}, {523, 60}, {87, 100}, {349, 140}, {87, 100}, {523, 60}, {87, 100},
{440, 200}, {110, 200}, {110, 200}, {110, 200} {440, 200}, {110, 200}, {110, 200}, {110, 200}
} ; };
for (int i=0; i<40 ; i++) { for (i = 0; i < sizeof(score)/sizeof(struct Note); i++) {
IoDoTone(Score[i].tone, Score[i].time); IoDoTone(score[i].tone, score[i].time);
KePauseCPU();
} }
} }

View File

@ -26,12 +26,7 @@
error_t CmdBeep(int argc, char **argv, char *cmdline) error_t CmdBeep(int argc, char **argv, char *cmdline)
{ {
if (rand() % 64 == 0 || (argc > 1 && !strcmp(argv[1], "starwars"))) { IoDoBeep();
IoDoStarWars();
}
else IoDoBeep();
return EOK; return EOK;
} }
@ -240,6 +235,19 @@ error_t CmdPF(int argc, char **argv, char *cmdline)
return EOK; return EOK;
} }
error_t CmdArgs(int argc, char **argv, char *cmdline)
{
int i;
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
for (i = 0; i < argc; i++) {
KernLog("argv[%d]: '%s'\n", i, argv[i]);
}
return EOK;
}
void MmInitPaging(void); void MmInitPaging(void);
error_t CmdReloadPage(int argc, char **argv, char *cmdline) error_t CmdReloadPage(int argc, char **argv, char *cmdline)
@ -249,6 +257,13 @@ error_t CmdReloadPage(int argc, char **argv, char *cmdline)
} }
extern void KeStartShell(void); extern void KeStartShell(void);
error_t CmdShell(int argc, char **argv, char *cmdline)
{
KeStartShell();
return EOK;
}
error_t CmdStackOverflow(int argc, char **argv, char *cmdline) error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
{ {
CmdStackOverflow(0, 0, 0); CmdStackOverflow(0, 0, 0);
@ -259,20 +274,22 @@ error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
Command_t cmdtable[] = Command_t cmdtable[] =
{ {
{ "args", CmdArgs, "Print command line" },
{ "beep", CmdBeep, "Make a beep" }, { "beep", CmdBeep, "Make a beep" },
{ "cls", CmdClear, "Clears standard output" }, { "cls", CmdClear, "Clears standard output" },
{ "date", CmdDate, "Print date" }, { "date", CmdDate, "Print date" },
{ "die", CmdDie, "Die painfully" }, { "die", CmdDie, "Die painfully" },
{ "exit", CmdQuit, "Initiate shutdown" }, { "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" }, { "help", CmdHelp, "Show this message" },
{ "rpag", CmdReloadPage, "Reload the pages directory" }, { "rpag", CmdReloadPage, "Reload the pages directory" },
{ "march", CmdStarWars, "Play the Imperial March"}, { "march", CmdStarWars, "Play the Imperial March"},
{ "mmap", CmdMemMap, "Show memory map" }, { "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" }, { "musage", CmdMemUsage, "Show memory statistics" },
{ "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" }, { "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" },
{ "pstest", CmdPsTest, "Scheduler test routine" }, { "pstest", CmdPsTest, "Scheduler test routine" },
{ "quit", CmdQuit, "Alias for 'exit'" }, { "quit", CmdQuit, "Alias for 'exit'" },
{ "so", CmdStackOverflow, "Provoke a stack overflow" }, { "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
{ "time", CmdTime, "Print time" }, { "time", CmdTime, "Print time" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };

View File

@ -96,7 +96,7 @@ void KeStartShell(void)
break; break;
case KEY_BEL: case KEY_BEL:
if (rand() % 64 == 0) { if (rand() % 16 == 0) {
IoDoStarWars(); IoDoStarWars();
} }
else IoDoBeep(); else IoDoBeep();