📄 embedded.c
字号:
/* ============================================================ */
/* File: EMBEDDED.C */
/* */
/* Copyright (C) 1999, Daniel W. Lewis and Prentice-Hall */
/* */
/* Purpose: An example of an embedded application program that */
/* runs on an IBM-PC or equivalent with a 386 or better cpu. */
/* */
/* This program must be compiled and linked into an absolute */
/* binary image file called EMBEDDED.BIN and put on a floppy */
/* diskette whose boot sector has been replaced with a copy of */
/* BOOTLOAD.BIN using the utility COPYBOOT.EXE. To run this */
/* program, you must perform a cold boot using the floppy. */
/* */
/* Designed for use with the DJGPP port of the GNU C/C++ */
/* protected mode 386 compiler. */
/* */
/* Modification History: */
/* */
/* ============================================================ */
#include <dos.h>
#include <pc.h>
#include "libepc.h"
#include "mtc.h"
void KeyBoard(void)
{
static char keyboard[] = "Keyboard Scan Code: --" ;
int len, col, kcol ;
len = strlen(keyboard) ;
col = (80 - len) / 2 ;
SetCursorPosition(14, col) ;
PutString(keyboard) ;
kcol = GetCursorCol() - 2 ;
for (;;)
{
BYTE8 scan_code ;
while (!ScanCodeRdy()) MtCYield() ;
scan_code = GetScanCode() ;
SetCursorPosition(14, kcol) ;
PutUnsigned(scan_code, 16, 2) ;
}
}
void ElapsedTime(void)
{
static char elapsed[] = "Elapsed Time: " ;
int old, len, col, tcol ;
len = strlen(elapsed) ;
col = (80 - (len + 8)) / 2 ;
SetCursorPosition(15, col) ;
PutString(elapsed) ;
tcol = GetCursorCol() ;
old = -1 ;
for (;;)
{
unsigned long msec ;
unsigned hh, mm, ss, fs ;
while ((msec = Milliseconds()) == old)
{
MtCYield() ;
}
old = msec ;
hh = msec / (60 * 60 * 1000) ; msec %= (60 * 60 * 1000) ;
mm = msec / (60 * 1000) ; msec %= (60 * 1000) ;
ss = msec / 1000 ;
fs = msec % 1000 ;
SetCursorPosition(15, tcol) ;
PutUnsigned(hh, 10, 2) ;
PutChar(':') ;
PutUnsigned(mm, 10, 2) ;
PutChar(':') ;
PutUnsigned(ss, 10, 2) ;
PutChar('.') ;
PutUnsigned(fs, 10, 2) ;
}
}
int main(void)
{
static char welcome[] = " Welcome to Protected Mode! " ;
static char memory[] = "Physical Memory: " ;
DWORD32 kbytes ;
int col, len ;
enable() ; /* Enable interrupts. */
ClearScreen(0x07) ;
SetCursorVisible(FALSE) ;
len = strlen(welcome) ;
col = (80 - len) / 2 ;
SetCursorPosition(11, col) ;
PutAttb(0x70, len) ;
PutString(welcome) ;
kbytes = ((DWORD32) LastMemoryAddress() + 1) / 1024 ;
len = strlen(memory) ;
col = (80 - (len + 6)) / 2 ;
SetCursorPosition(12, col) ;
PutString(memory) ;
if (kbytes < 1024)
{
PutUnsigned(kbytes, 10, 0) ;
PutString(" KB") ;
}
else
{
PutUnsigned(kbytes / 1024, 10, 0) ;
PutString(" MB") ;
}
MtCCoroutine(ElapsedTime()) ;
MtCCoroutine(KeyBoard()) ;
return 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -