?? dispdrv.c.bak
字號:
/*********************************************************************************\
* 顯示驅動 *
* *
* Description : 本文件中程序為顯示驅動函數,主要包括INT 10H中斷和一些顯示子程序。 *
* INT 10H型中斷包括:1. VGA寄存器初始化 *
* 2. 清顯存 *
* 3. 硬件光標初始化 *
* 4. 重設模式(重新設置VGA寄存器,切換顯示模式) *
* *
* 顯示子程序包括: 1. 在指定位置顯示一字符 *
* 2. 在指定位置顯示一字符串 *
* 3. 計算光標位置(硬件光標) *
* *
\*********************************************************************************/
#include "includes.h"
#include "vga/dispdrv.h"
#include "mouse/ps2mouse.h"
#include "modules/display/disp.h"
#include "modules/display/graphics.h"
INT32U linetab[32];
extern WINDOW win;
extern XWINDOW xwin;
extern MOUSE_STRUC mouse;
extern far INT8 ArrorCur;
/*************本地函數聲明************************************/
void interrupt int10(INT16U bp, INT16U di, INT16U si,
INT16U ds, INT16U es, INT16U dx,
INT16U cx, INT16U bx, INT16U ax);
static void setmode(INT8U mode);
static void clearvram(void);
static void setcursortype(INT8U mode);
static void setlinetab(void);
//static void resetmode(INT8U mode);
/**************外部變量聲明****************************/
extern OS_EVENT *KtAccessSem;
extern INT16U far crt24[37];
extern INT16U far crt16132[37];
extern INT16U far seq24[15];
extern INT16U far crt1680[37];
extern INT16U far seq16132[15];
extern INT16U far seq1680[15];
extern INT8U far att[21];
extern INT16U far gra[9];
extern INT16U far recrt24[28];
extern INT16U far reseq24[2];
extern INT16U far recrt16132[28];
extern INT16U far reseq16132[2];
extern INT16U far recrt1680[28];
extern INT16U far reseq1680[2];
void InitLCD(void)
{
outport(SEQREG, (INT16U)(0x3e<<8)+0x1d);
outport(SEQREG, (INT16U)(0xb8<<8)+0x1e);
outport(SEQREG, (INT16U)(0xF0<<8)+0x1f);
outport(SEQREG, (INT16U)(0x4f<<8)+0x20);
}
#pragma argsused
void interrupt int10(INT16U bp, INT16U di, INT16U si,
INT16U ds, INT16U es, INT16U dx,
INT16U cx, INT16U bx, INT16U ax)
{
INT8U type, mode;
type = highbyte(ax);
mode = lowbyte(ax);
switch(type)
{
case 0:
setmode(mode);
clearvram();
setlinetab();
window(1, 1, 80, 26);
clrscr();
window(1, 1, 80, 25);
Cursor();
xwindow();
break;
case 1:
setcursortype(mode);
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
}
/***********************************************************************\
* setmode *
* Description : set display mode *
* input : mode = 0-------------24點陣80列 *
* mode = 1-------------16點陣132列 *
* mode = 2-------------16點陣80列 *
* *
\***********************************************************************/
static void setmode(INT8U mode)
{
INT16U *p,*p1;
INT16U cnt, cnt1, i;
INT8U *p3;
outportb(MBSREG, 1); // 允許訪問VGA寄存器
outportb(ADSREG, 8);
switch(mode)
{
case 0:
outportb(MOPREG, 0xA3); // 垂直同步極性為負,水平同步極性為正, 允許CPU訪問顯存, CRT I/O地址空間為2DX(用于VGA彩色)
p = (INT16U *)crt24;
p1= (INT16U *)seq24;
cnt = sizeof(crt24)/sizeof(crt24[0]);
cnt1= sizeof(seq24)/sizeof(seq24[0]);
break;
case 1:
outportb(MOPREG, 0xa3); // 垂直/水平同步極性都為負
p = (INT16U *)crt16132;
p1 = (INT16U *)seq16132;
cnt = sizeof(crt16132)/sizeof(crt16132[0]);
cnt1= sizeof(seq16132)/sizeof(seq16132[0]);
break;
case 2:
outportb(MOPREG, 0xa3);
p = (INT16U *)crt1680;
p1 = (INT16U *)seq1680;
cnt = sizeof(crt1680)/sizeof(crt1680[0]);
cnt1= sizeof(seq1680)/sizeof(crt1680[0]);
break;
default: // 入口參數錯誤,直接返回
return;
}
for(i=0;i<cnt;i++) // 初始化CRT寄存器
{
outport(CRTREG,*p++);
}
for(i=0;i<cnt1;i++) // 初始化定序器
{
outport(SEQREG, *p1++);
}
p = (INT16U *)gra; // 初始化圖形控制器
cnt = sizeof(gra)/2;
for(i=0;i<cnt;i++)
{
outport(GRAREG, *p++);
}
p3 = (INT8U *)att;
cnt = sizeof(att);
inportb(RESREG);
for(i=0;i<cnt;i++)
{
outportb(ATTREG, i);
outportb(ATTREG, *p3++);
}
outportb(VPMREG, 0xff);
outportb(PMWREG, 0);
outport(GRAREG, 0x0001);
outport(SEQREG, 0);
outport(SEQREG,0x1b00);
outport(SEQREG, 0xe105);
inportb(RESREG);
outportb(ATTREG, 0x20);
}
/***************************************************************\
* clearvram *
* *
* Description : clear 512K vram space, 256K for graphics, 256K *
* for text *
* *
\***************************************************************/
static void clearvram(void)
{
cleartext();
setbkcolor(BLACK);
}
/***************************************************************\
* setcursortype *
* *
* Description : set cursor type *
* *
* *
\***************************************************************/
static void setcursortype(INT8U type)
{
INT8 x, line, pixel;
outportb(CRTREG, 0x0a); // 選擇光標寄存器
x = 0;
if((type&4)==4) // 是否禁止光標
{
x = inport(CRTREG+1); // 讀出當前光標寄存器值
x |= 0x20;
outportb(CRTREG, 0xa);
outportb(CRTREG+1, x);
return;
}
if((type&1)==1)
x |= 0x80; // 固定光標
else
x |= 0x40; // 光標每32場閃爍一次
outportb(SEQREG, 0x9);
pixel = inportb(SEQREG+1);
if((type&2)==2) // 塊壯光標還是線性光標
{
line = 0x15; // 24點陣
if((pixel&2)==0)
line = 0xd; // 16點陣
x |= line;
outportb(CRTREG+1, x); // 寫光標開始寄存器
outportb(CRTREG, 0xb); // 光標結束寄存器
outportb(CRTREG+1, x+3);
}
else
{
outportb(CRTREG+1, x);
x |= 0x11;
if(pixel&2)
x |= 8;
outportb(CRTREG, 0xb);
outportb(CRTREG+1, x);
}
}
#pragma option -w.
/***************************************************************\
* cleartext *
* description : 以圖形方式快速清文本屏 *
* *
* *
\***************************************************************/
#pragma inline
void cleartext(void)
{
INT32 *p;
outport(SEQREG, 0x0f0e);
p = MK_FP(0xa000, 0);
*p = 0x00800f20UL;
outport(SEQREG, 0x0404); // 位平面方式
outport(SEQREG, 0x010e); // 圖形方式共兩段,4個文本段對應圖形第一段
outport(GRAREG, 0x0105); // 鎖存器寫
outport(GRAREG, 0x0008);
outport(GRAREG, 0x0f02);
outport(GRAREG, 0x0001);
asm{
push ds es
mov ax, 0xa000
mov es, ax
mov ds, ax
mov si, 0xc000
mov di, 0xc001
mov cx, 4000h
cld
rep movsb
pop es ds
}
outport(SEQREG, 0x0804);
outport(GRAREG, 0x0005);
outport(GRAREG, 0xff08);
}
/***************************************************************\
* cleartext *
* description : 清圖形屏 *
* *
* *
\***************************************************************/
void cleargraph(INT8 color)
{
outport(SEQREG, 0x010e); // 圖形第1段
outport(SEQREG, 0x0404); // 位平面方式
outport(GRAREG, (color<<8)+0);// 將指定顏色裝入設置/重置寄存器
outport(GRAREG, 0x0f01); // 允許設置/重置4個位面
outport(GRAREG, 0xff08); // 不用鎖存器值
asm{
mov ax, 0xa000
mov es, ax
mov cx, 0xc000
mov al, 0
mov di, 0
rep stosb
}
outport(GRAREG, 0x0f00);
outport(GRAREG, 0x0001);
outport(SEQREG, 0x0804);
}
/*
static void resetmode(INT8U mode)
{
INT16U *p, *p1;
INT16U cnt, cnt1, i, val;
disable(); // 關中斷
switch(mode)
{
case 0: // 24點陣,80列
p = (INT16U *)recrt24;
p1 = (INT16U *)reseq24;
cnt = sizeof(recrt24);
cnt1 = sizeof(reseq24);
break;
case 1: // 16點陣,132列
p = (INT16U *)recrt16132;
p1 = (INT16U *)reseq16132;
cnt = sizeof(recrt16132);
cnt1= sizeof(reseq16132);
break;
case 2: // 16點陣, 80列
p = (INT16U *)recrt1680;
p1 = (INT16U *)reseq1680;
cnt = sizeof(recrt1680);
cnt1= sizeof(reseq1680);
break;
default: // 其他為非法模式
return;
}
for(i=0;i<cnt;i++) // 初始化CRT寄存器
{
val = *p++;
outport(CRTREG, val);
}
for(i=0;i<cnt1;i++) // 初始化定序器
{
val = *p1++;
outport(SEQREG, val);
}
enable(); // 開中斷
}
*/
/*******************************************************\
* RefreshWindow *
* description : refresh line table *
* argument : lta---------行表結構訪問指針 *
* *
\*******************************************************/
void RefreshWindow(INT8U firstrow, INT8U endrow)
{
INT16U i;
INT32U *ltp;
ltp = MK_FP(0xa000, 0xfe00+4*(firstrow-1));
for(i=firstrow-1;i<=endrow;i++){
*ltp++ = linetab[i];
}
}
/***************************************************************\
* openscreen *
* Description : open screen such as text screen, graphics screen*
* and text and graphics screen *
* *
* Arguments : screen *
* 0(CLOSESCREEN)------------close screen *
* 1(OPENSCREEN)------------open screens *
* 2(OPENTEXTSCR)------------open text screen *
* 3(OPENGRASCR)------------open graph screen *
* 4(CLOSETEXTSCR)------------close text screen *
* 5(CLOSEGRASCR)------------close graph screen *
* *
\***************************************************************/
void openscreen(int screen)
{
{
case CLOSESCREEN:
case CLOSETEXTSCR:
closetextscr();
if(screen==CLOSETEXTSCR)
break;
case CLOSEGRASCR:
closegrascr();
break;
case OPENSCREEN:
case OPENTEXTSCR:
opentextscr();
if(screen==OPENTEXTSCR)
break;
case OPENGRASCR:
opengrascr();
break;
default:
break;
}
}
void opentextscr(void)
{
char val;
outportb(SEQREG, 5);
val = inportb(SEQREG+1);
val |= 0x10;
outport(SEQREG, (val<<8)+5);
}
void opengrascr(void)
{
char val;
val = inportb(SEQREG+1);
val &= 0xdf;
outport(SEQREG, (val<<8)+1);
}
void closetextscr(void)
{
char val;
outportb(SEQREG, 5);
val = inportb(SEQREG+1);
val &= 0xef;
outport(SEQREG, (val<<8)+5);
}
void closegrascr(void)
{
char val;
outportb(SEQREG, 1);
val = inportb(SEQREG+1);
val |= 0x20;
outport(SEQREG, (val<<8)+1);
}
/***********************************************************************\
* HwCursor *
* *
\***********************************************************************/
void Cursor(void)
{
INT16U pos, x, y;
x = win.wincurx + win.winleft - 1;
y = win.wincury + win.wintop - 1;
pos = (INT16U)linetab[y-1] + x-1;
outport(CRTREG, (pos&0xff00)+0x0e);
outport(CRTREG, (pos<<8)+0x0f);
}
void setlinetab(void)
{
int i;
INT16U pos;
pos = (TEXTSEG-12)<<14;
pos += 8;
for(i=0;i<32;i++){
linetab[i] = pos;
pos += MAXROWBYTES;
}
RefreshWindow(1, 32);
}
void OpenCursor(INT8U crs)
{
INT8U v;
outportb(CRTREG, 0xa);
v = inportb(CRTREG+1);
if(crs)
v &= 0xdf;
else
v |= 0x20;
outport(CRTREG, (v<<8)+0xa);
}
void xwindow(void)
{
xwin.left = 0;
xwin.top = 0;
xwin.right = 639;
xwin.bottom = 467;
xwin.mcurx = 320;
xwin.mcury = 220;
xwin.oldmcurx = 320;
xwin.oldmcury = 220;
xwin.crsp = &ArrorCur;
xwin.oldcrsp = &ArrorCur;
GraCursor(xwin.mcurx, xwin.mcury, xwin.crsp);
mouse.visible = 1; // 光標使能
}
void InitVGA(void)
{
union REGS reg;
reg.x.ax = 0x0002; // 初始化VGA寄存器,顯示模式16點陣80列
int86(0x10, ®, ®);
reg.h.ah = 1; // 光標初始化
int86(0x10, ®, ®);
OpenCursor(1);
openscreen(OPENSCREEN);
graphup(1); // 圖形優先
textbackground(BLACK);
textcolor(LIGHTGREEN);
gotoxy(1, 1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -