📄 monitor.c
字号:
rgStatLine[11] = '0' + ((time >> 16) & 0x0f);
rgStatLine[13] = '0' + ((time >> 12) & 0x0f);
rgStatLine[14] = '0' + ((time >> 8) & 0x0f);
rgStatLine[16] = '0' + ((time >> 4) & 0x0f); /* seconds */
rgStatLine[17] = '0' + (time & 0x0f);
GetCMOSDate(&date);
rgStatLine[0] = '0' + ((date >> 20) & 0x0f); /* month */
rgStatLine[1] = '0' + ((date >> 16) & 0x0f);
rgStatLine[3] = '0' + ((date >> 12) & 0x0f); /* Day */
rgStatLine[4] = '0' + ((date >> 8) & 0x0f);
rgStatLine[6] = '0' + ((date >> 28) & 0x0f); /* year */
rgStatLine[7] = '0' + ((date >> 24) & 0x0f);
GetTimerTick(&tick);
xsprintf(&rgStatLine[70], "%d", tick);
PutVidChars(0,0, rgStatLine, 80, WHITE|BGBLUE);
Sleep(50); /* sleep 0.5 second */
GetTimerTick(&tick);
xsprintf(&rgStatLine[70], "%d", tick);
PutVidChars(0,0, rgStatLine, 80, WHITE|BGBLUE);
Sleep(50); /* sleep 0.5 second */
/* Now we check for tasks that are Jobs that are killing
themselves (either due to fatal errors or no exitjob).
The message has Error, TSSExch in it.
*/
erc = CheckMsg(KillExch, KillMsg);
if (!erc) { /* someones there wanting to terminate...*/
/* Get and save the error (KillMsg[0]) */
KillError = KillMsg[0];
/* Call GetExchOwner which gives us pJCB */
erc = GetExchOwner(KillMsg[1], &pKillJCB);
if (!erc) {
KillJob = pKillJCB->JobNum;
Tone(440,50);
xprintf("\r\nJob number %d terminated. Error: %d\r\n",
KillJob, KillError);
pPD = pKillJCB->pJcbPD;
pVid = pKillJCB->pVirtVid;
/* Must change video to monitor if this guy owned it */
GetVidOwner(&i);
if (i == KillJob) {
GetTSSExch(&Exch); /* Use our TSS exchange for Request */
SetVidOwner(1);
erc = Request("KEYBOARD", 4, Exch, &i, 0,
0, 0, 0, 0, 1, 0, 0);
erc = WaitMsg(Exch, Msg);
}
/* Now we deallocate the JCB and the TSSExch
which will free the TSS automatically!
*/
DeAllocExch(KillMsg[1]);
DeAllocJCB(pKillJCB); /* No error returnd */
/* When the JCB was created, the PD and it's 1st
PDE (PT) were allocated as two pages next to each other
in linear memory. SO we can just deallocate both
pages in one shot. Then we deallocate the single
page for virtual video.
*/
DeAllocPage(pPD, 2);
DeAllocPage(pVid, 1);
fKilled = 1;
/* We're done (and so is he...) */
}
}
} /* for EVER */
}
/*********************************************************
This is the Manager task for the Monitor.
It allows us to switch jobs with the
CTRL-ALT-PLUS and CTRL-ALT-MINUS keys.
We don't actually switch jobs, we just
ressign video and keyboard to the next
active job (except the Debugger).
*********************************************************/
void MngrTask(void)
{
long erc, i, j, fDone;
char *pJCB;
/* Leave a Global Key Request outstanding with KBD service
for the status task
*/
erc = Request("KEYBOARD", 2, MngrExch, &MngrHndl, 0, &gcode,
4, 0, 0, 0, 0, 0);
for(;;) {
erc = WaitMsg(MngrExch, MngrMsg);
if (!erc) {
if ((gcode & 0xff) == 0x0C) {
/* Find next valid Job that is NOT the
debugger and assign Vid and Keyboard to
it.
*/
erc = GetVidOwner(&j);
fDone = 0;
i = j;
while (!fDone) {
i++;
if (i==2) i = 3;
else if (i>34) i = 1;
erc = GetpJCB(i, &pJCB); /* erc = 0 if valid JCB */
if ((!erc) || (i==j)) fDone = 1;
}
if (i != j) {
SetVidOwner(i);
erc = Request("KEYBOARD", 4, MngrExch, &MngrHndl, 0,
0, 0, 0, 0, i, 0, 0);
erc = WaitMsg(MngrExch, MngrMsg);
}
}
/* leave another global key request */
erc = Request("KEYBOARD", 2, MngrExch, &MngrHndl, 0, &gcode,
4, 0, 0, 0, 0, 0);
}
} /* for EVER */
}
/*********************************************************
This simply does a software interrupt 03 (Debugger).
*********************************************************/
void GoDebug(void)
{
;
#asm
INT 03
#endasm
return;
}
/*********************************************************
This strobes keyboard data port 60h with 00 after
sending 0D1 command to Command port. We have to loop
reading the status bit of the command port to make
sure it's OK to send the command.
*********************************************************/
void Reboot(void)
{
;
#asm
CLI ;first we clear interrupts
MOV ECX, 0FFFFh ;check port up to 64K times
Reboot0:
IN AL,64h ;Read Status Byte into AL
TEST AL,02h ;Test The Input Buffer Full Bit
LOOPNZ Reboot0
MOV AL,0FEh ;Strobe bit 0 of keyboard crtlr output
OUT 64h,AL
STI
#endasm
return;
}
/*********************************************************
This Loads the MMURTL Command Line Interpreter
and switches video and keyboard to give the
user access to it.
*********************************************************/
long LoadCLI(void)
{
long erc, job;
erc = LoadNewJob("C:\\MMURTL\\CLI.RUN", 17, &job);
if (!erc) {
xprintf("New CLI Job Number is: %d\r\n", job);
Sleep(100);
SetVidOwner(job);
erc = Request("KEYBOARD", 4, GP1Exch, &GP1Hndl, 0,
0, 0, 0, 0, job, 0, 0);
if (!erc)
erc = WaitMsg(GP1Exch, GP1Msg);
}
return erc;
}
/*********************************************************
This is the main procedure called from the OS after
all OS structures and memory are initialized.
*********************************************************/
void Monitor(void)
{
long erc, i, j, k, l, iCol, iLine, fh, dret;
unsigned long ccode, ccode1;
unsigned char c, c1;
char text[70];
char *pNewMem;
InitScreen();
Tone(250,15); /* 250 Hz for 150ms */
Tone(1000,33); /* 250 Hz for 330ms */
/* Allocate an exchange for the Manager task global keycode */
erc = AllocExch(&MngrExch);
if (erc)
xprintf("AllocExch (Status task) Error: %d\r\n", erc);
SpawnTask( &StatTask, 24, 0, &StatStack[255], 1 ); /* Task 4 */
erc = AllocExch(&KillExch);
if (erc)
xprintf("AllocExch (Kill Exch) Error: %d\r\n", erc);
Color = YELLOW|BGBLACK;
xprintf("MMURTL (tm) - Message based, MUltitasking, Real-Time kerneL\r\n");
xprintf(" Copyright (c) R.A. Burgess, 1991, 1992, 1993\r\n\r\n");
Color = WHITE|BGBLACK;
erc = InitKBDService(); /* He does Task 4 */
xprintf("Init KBD Service Error: %d\r\n", erc);
erc = coms_setup(); /* He does Task 4 */
xprintf("Init Serial Comms Device Driver Error: %d\r\n", erc);
/* Allocate a General Purpose exchange to use in the monitor */
erc = AllocExch(&GPExch);
if (erc)
xprintf("AllocExch Error: %d\r\n", erc);
erc = AllocExch(&GP1Exch);
if (erc)
xprintf("AllocExch GP1 Error: %d\r\n", erc);
i = (oMemMax+1)/1024;
xprintf("Physical memory (Kb): %d\r\n", i);
erc = QueryPages(&nMemPages);
i = (nMemPages*4096)/1024;
xprintf("Free memory (Kb): %d\r\n", i);
xprintf("Init floppy device driver... Error: ");
erc = fdisk_setup();
xprintf("%d\r\n", erc);
xprintf("Init hard disk device driver... Error: ");
erc = hdisk_setup();
xprintf("%d\r\n", erc);
xprintf("Initializing file system...\r\n");
erc = InitFS();
/* Spawn manager task */
SpawnTask( &MngrTask, 10, 0, &MngrStack[255], 1 );
for (;;) {
/* Make a ReadKbd Key Request with KBD service. Tell it
to wait for a key. */
erc = Request("KEYBOARD", 1, GPExch, &GPHndl, 0, &ccode,
4, 0, 0, 1, 0, 0);
if (erc)
xprintf("Kbd Svc Request KERNEL ERROR: %d\r\n", erc);
/* wait for the keycode to come back */
erc = WaitMsg(GPExch, GPMsg);
if (erc)
xprintf("KERNEL Error from Wait msg: %d\r\n", erc);
c = ccode & 0xff;
switch (c) {
case 0x0F: /* F1 Run */
erc = LoadCLI();
if (erc)
xprintf("Error from LoadCLI: %d\r\n", erc);
break;
case 0x10: /* F2 Jobs */
break;
case 0x11: /* F3 Stats */
InitScreen();
while (erc = ReadKbd(&ccode1, 0)) { /* ReadKbd no wait until no error */
SetXY(0,1);
erc = QueryPages(&nMemPages);
xprintf("Any key to dismiss status... \r\n");
xprintf("Free 4K memory pages: %d\r\n", nMemPages);
xprintf("Task Switches since boot: %d\r\n", nSwitches);
xprintf("Free Task State Segments: %d\r\n", nTSSLeft);
xprintf("Free Job Control Blocks: %d\r\n", nJCBLeft);
xprintf("Free Request Blocks: %d\r\n", nRQBLeft);
xprintf("Free Link Blocks: %d\r\n", nLBLeft);
xprintf("Free Exchanges: %d\r\n", nEXCHLeft);
SetXY(0,1);
PutVidChars(29, 1, "|", 1, GREEN|BGBLACK); Sleep(9);
PutVidChars(29, 1, "/", 1, GREEN|BGBLACK); Sleep(9);
PutVidChars(29, 1, "-", 1, GREEN|BGBLACK); Sleep(12);
PutVidChars(29, 1, "\\", 1, GREEN|BGBLACK); Sleep(9);
PutVidChars(29, 1, "|", 1, GREEN|BGBLACK); Sleep(9);
PutVidChars(29, 1, "/", 1, GREEN|BGBLACK); Sleep(9);
PutVidChars(29, 1, "-", 1, GREEN|BGBLACK); Sleep(12);
PutVidChars(29, 1, "\\", 1, GREEN|BGBLACK); Sleep(9);
PutVidChars(29, 1, " ", 1, GREEN|BGBLACK);
}
SetXY(0,9);
xprintf ("\r\n");
break;
case 0x13:
break;
case 0x14: /* F6 */
break;
case 0x16: /* F8 Reboot */
xprintf("\r\nF8 again to reboot, any other key to cancel");
erc = ReadKbd(&ccode1, 1);
if ((ccode1 & 0xff) == 0x16)
Reboot();
xprintf("...Cancelled\r\n");
break;
case 0x18: /* F10 Debug */
GoDebug();
break;
case 0x19: /* F11 */
case 0x1A: /* F12 TestDeAllocMem */
break;
case 0x00: /* No Key */
Sleep(3); /* Sleep for 30 ms */
break;
default:
if (((c > 0x1F) && (c < 0x80)) ||
(c==0x0D) || (c==8)) {
if (c==0x0D)
TTYOut (CRLF, 2, WHITE|BGBLACK);
else
TTYOut (&c, 1, WHITE|BGBLACK);
}
}
GetXY(&iCol, &iLine);
if (iLine >= 23) {
ScrollVid(0,1,80,23,1);
SetXY(0,22);
}
} /* for EVER */
}
/*=========== THE END =========================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -