?? pc.c
字號(hào):
/*
*********************************************************************************************************
* PC SUPPORT FUNCTIONS
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* File : PC.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include "includes.h"
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define DISP_BASE 0xB800 /* Base segment of display (0xB800=VGA, 0xB000=Mono) */
#define DISP_MAX_X 80 /* Maximum number of columns */
#define DISP_MAX_Y 25 /* Maximum number of rows */
#define TICK_T0_8254_CWR 0x43 /* 8254 PIT Control Word Register address. */
#define TICK_T0_8254_CTR0 0x40 /* 8254 PIT Timer 0 Register address. */
#define TICK_T0_8254_CTR1 0x41 /* 8254 PIT Timer 1 Register address. */
#define TICK_T0_8254_CTR2 0x42 /* 8254 PIT Timer 2 Register address. */
#define TICK_T0_8254_CTR0_MODE3 0x36 /* 8254 PIT Binary Mode 3 for Counter 0 control word. */
#define TICK_T0_8254_CTR2_MODE0 0xB0 /* 8254 PIT Binary Mode 0 for Counter 2 control word. */
#define TICK_T0_8254_CTR2_LATCH 0x80 /* 8254 PIT Latch command control word */
#define VECT_TICK 0x08 /* Vector number for 82C54 timer tick */
#define VECT_DOS_CHAIN 0x81 /* Vector number used to chain DOS */
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static INT16U PC_ElapsedOverhead;
static jmp_buf PC_JumpBuf;
static BOOLEAN PC_ExitFlag;
void (*PC_TickISR)(void);
/*$PAGE*/
/*
*********************************************************************************************************
* DISPLAY A SINGLE CHARACTER AT 'X' & 'Y' COORDINATE
*
* Description : This function writes a single character anywhere on the PC's screen. This function
* writes directly to video RAM instead of using the BIOS for speed reasons. It assumed
* that the video adapter is VGA compatible. Video RAM starts at absolute address
* 0x000B8000. Each character on the screen is composed of two bytes: the ASCII character
* to appear on the screen followed by a video attribute. An attribute of 0x07 displays
* the character in WHITE with a black background.
這個(gè)函數(shù)允許在顯示器的任何位置顯示單個(gè)ASCII碼字符或其他特殊字符。
*
* Arguments : x corresponds to the desired column on the screen. Valid columns numbers are from
* 0 to 79. Column 0 corresponds to the leftmost column.
* y corresponds to the desired row on the screen. Valid row numbers are from 0 to 24.
* Line 0 corresponds to the topmost row.x和y指定所顯示字符的坐標(biāo)(列和行)。行的值為0~DISP_MAX_Y-1,而
列的值為0~DISP_MAX_X-1
* c Is the ASCII character to display. You can also specify a character with a
* numeric value higher than 128. In this case, special character based graphics
* will be displayed.需要顯示的字符。可以指定任何ASCII碼字符,若C的值大一128,則可以指定任何其他特殊
字符。
* color specifies the foreground/background color to use (see PC.H for available choices)
* and whether the character will blink or not.指定所顯示字符的屬性,即字符的色彩組合。可添加一個(gè)
DISP_FGND_???常數(shù)和一個(gè)DISP_BGND_???常數(shù),以得到所需要的色彩組合。這2個(gè)常數(shù)的定義見PC.H
*
* Returns : None
*********************************************************************************************************
*/
void PC_DispChar (INT8U x, INT8U y, INT8U c, INT8U color)
{
INT8U far *pscr;
INT16U offset;
offset = (INT16U)y * DISP_MAX_X * 2 + (INT16U)x * 2; /* Calculate position on the screen */
pscr = (INT8U far *)MK_FP(DISP_BASE, offset);
*pscr++ = c; /* Put character in video RAM */
*pscr = color; /* Put video attribute in video RAM */
}
/*$PAGE*/
/*
*********************************************************************************************************
* CLEAR A COLUMN
*
* Description : This function clears one of the 80 columns on the PC's screen by directly accessing video
* RAM instead of using the BIOS. It assumed that the video adapter is VGA compatible.
* Video RAM starts at absolute address 0x000B8000. Each character on the screen is
* composed of two bytes: the ASCII character to appear on the screen followed by a video
* attribute. An attribute of 0x07 displays the character in WHITE with a black background
這個(gè)函數(shù)允許清除一列的內(nèi)容(一共25個(gè)字符)。.
*
* Arguments : x corresponds to the desired column to clear. Valid column numbers are from
* 0 to 79. Column 0 corresponds to the leftmost column.
指定清除哪一列,列值為0~DISP_MAX_X-1(見PC.C文件)的數(shù)。
*
* color specifies the foreground/background color combination to use
* (see PC.H for available choices)
指定字符屬性字節(jié)的內(nèi)容。因?yàn)橛脕砬宄幌盗械淖址强崭?quot;''",它只顯示背景色,也可以通過定義DISP_BGND_???來指定任意一種顏色
*
* Returns : None
*********************************************************************************************************
*/
void PC_DispClrCol (INT8U x, INT8U color)
{
INT8U far *pscr;
INT8U i;
pscr = (INT8U far *)MK_FP(DISP_BASE, (INT16U)x * 2);
for (i = 0; i < DISP_MAX_Y; i++) {
*pscr++ = ' '; /* Put ' ' character in video RAM */
*pscr-- = color; /* Put video attribute in video RAM */
pscr = pscr + DISP_MAX_X * 2; /* Position on next row */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CLEAR A ROW
*
* Description : This function clears one of the 25 lines on the PC's screen by directly accessing video
* RAM instead of using the BIOS. It assumed that the video adapter is VGA compatible.
* Video RAM starts at absolute address 0x000B8000. Each character on the screen is
* composed of two bytes: the ASCII character to appear on the screen followed by a video
* attribute. An attribute of 0x07 displays the character in WHITE with a black background.
這個(gè)函數(shù)允許清除一行的內(nèi)容(共80個(gè)字符)
*
* Arguments : y corresponds to the desired row to clear. Valid row numbers are from
* 0 to 24. Row 0 corresponds to the topmost line.
指定清除哪一行,行值為0~DISP_MAX_Y-1(見PC.C)的數(shù)。
*
* color specifies the foreground/background color combination to use
* (see PC.H for available choices)
指定字符屬性字節(jié)的內(nèi)容。因?yàn)橛脕砬宄恍械淖址强兆址?quot;''",它只顯示背景色,也可以通過定義DISP_BGND_???來指定任意一種顏色
*
* Returns : None
*********************************************************************************************************
*/
void PC_DispClrRow (INT8U y, INT8U color)
{
INT8U far *pscr;
INT8U i;
pscr = (INT8U far *)MK_FP(DISP_BASE, (INT16U)y * DISP_MAX_X * 2);
for (i = 0; i < DISP_MAX_X; i++) {
*pscr++ = ' '; /* Put ' ' character in video RAM */
*pscr++ = color; /* Put video attribute in video RAM */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CLEAR SCREEN
*
* Description : This function clears the PC's screen by directly accessing video RAM instead of using
* the BIOS. It assumed that the video adapter is VGA compatible. Video RAM starts at
* absolute address 0x000B8000. Each character on the screen is composed of two bytes:
* the ASCII character to appear on the screen followed by a video attribute. An attribute
* of 0x07 displays the character in WHITE with a black background.
允許清空所有顯示內(nèi)容
*
* Arguments : color specifies the foreground/background color combination to use
* (see PC.H for available choices)指定字符屬性字節(jié)的內(nèi)容。因?yàn)橛脕砬迤恋淖址强崭褡址?quot;''",它只顯示
背景色,也可以通過定義DISP_BGND_???來指定任意一種顏色。
*
* Returns : None
注意:應(yīng)當(dāng)使用DISP_FGND_WHITE常數(shù),而不要使用DISP_BGND_BLACK常數(shù),因?yàn)檫@樣前景色和背景色都為黑色,不是我們想要的
*********************************************************************************************************
*/
void PC_DispClrScr (INT8U color)
{
INT8U far *pscr;
INT16U i;
pscr = (INT8U far *)MK_FP(DISP_BASE, 0x0000);
for (i = 0; i < (DISP_MAX_X * DISP_MAX_Y); i++) { /* PC display has 80 columns and 25 lines */
*pscr++ = ' '; /* Put ' ' character in video RAM */
*pscr++ = color; /* Put video attribute in video RAM */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* DISPLAY A STRING AT 'X' & 'Y' COORDINATE
*
* Description : This function writes an ASCII string anywhere on the PC's screen. This function writes
* directly to video RAM instead of using the BIOS for speed reasons. It assumed that the
* video adapter is VGA compatible. Video RAM starts at absolute address 0x000B8000. Each
* character on the screen is composed of two bytes: the ASCII character to appear on the
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -