China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 07:48
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » [Original] A keyboard program I wrote, hehe, still very immature! View 1,069 Replies 6
Original Poster Posted 2003-10-26 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
/************************************************/
/* Example program for communicating with the keyboard through the 8042 chip */
/* Author: xy_god */
/************************************************/
#include "dos.h"
#include "stdio.h"
#include "conio.h"

int iCode=0;
int blKey=0;
void interrupt ( *oldhandler)(void);/*interrupt handler function pointer*/

void interrupt handler(void);
int getbit(char c,int i);
void getkeystate();

int main(void)/***********************main function***********************/
{
int a;
oldhandler = getvect(0X09);/*get the original keyboard interrupt address*/
setvect(0X09, handler);/*install the new keyboard interrupt*/
getkeystate();
printf("*********************************************\n";
while (1)
{
if(blKey==1)
{
blKey=0;
printf("%X",iCode);
printf("****";
getkeystate();
}
}
setvect(0X09, oldhandler);/*restore the keyboard interrupt*/
return 0;
}/*****************************************************************/

void interrupt handler(void)/*keyboard interrupt handler*/
{
blKey=1;
iCode=inport(0x60);
oldhandler();
}
int getbit(char c,int i)/*get the value of bit i of the byte*/
{
int mi;
mi=c<127)
return 1;
else
return 0;
}

void getkeystate()/*get keyboard status*/
{
int i,ic=0,bitvalue;
for(ic=0;ic<8;ic++)
{
i=inport(0x64);
bitvalue=getbit(i,ic);
switch(ic)
{
case 0:
if(bitvalue) printf("OBF=TRUE\n"; else printf("OBF=FALSE\n";
break;
case 1:
if(bitvalue) printf("IBF=TRUE\n"; else printf("IBF=FALSE\n";
break;
case 2:
if(bitvalue) printf("SYS=TRUE\n"; else printf("SYS=FALSE\n";
break;
case 3:
if(bitvalue) printf("A2=TRUE\n"; else printf("A2=FALSE\n";
break;
case 4:
if(bitvalue) printf("INTH=TRUE\n"; else printf("INH=FALSE\n";
break;
case 5:
if(bitvalue) printf("TxTO=TRUE\n"; else printf("TxTO=FALSE\n";
break;
case 6:
if(bitvalue) printf("RxTO=TRUE\n"; else printf("RxTO=FALSE\n";
break;
case 7:
if(bitvalue) printf("PERR=TRUE\n"; else printf("PERR=FALSE\n";
break;
}
}
}
临河居士
http://www.xygod.pc5.org
Floor 2 Posted 2003-10-26 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
This program was written with TC2.0, and the development environment is Wu Jin's WIN-TC172, hehe!
Originally it was very readable, but for some reason after posting it to the forum it got messed up, so just make do with it!
Actually, if everyone looks carefully, this program's structure is very similar to developing WINDOWS programs with the SDK. Using it, you can implement multithreading in DOS programs. Note, I said multithreading, not multitasking, hehe!
This is a program for an 8042 PS2 keyboard. After I finish reading the material about the mouse, I'll write a mouse driver for everyone.
But right now I'm really busy and have no time to write it, so you'll have to wait a while. Really helpless! TMD!
临河居士
http://www.xygod.pc5.org
Floor 3 Posted 2003-10-27 00:00 ·  中国 陕西 西安 教育网
高级用户
★★
OS/2女孩
Credits 639
Posts 183
Joined 2003-06-14 00:00
23-year member
UID 5148
Gender Female
Status Offline
REM 喜欢DOS,因为它的简单
REM 喜欢OS/2,因为它不再矫饰
REM 喜欢BASIC,因为它并不幼稚
REM 喜欢GNU,因为它杂乱无章
Floor 4 Posted 2003-10-27 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
Come on, the poster above, I wrote it with TC20. What CONSOLE program? It's a pure DOS program, okay!
Did you even read it carefully? Good heavens!
I'm imitating the program structure of the WIN32 SDK!
临河居士
http://www.xygod.pc5.org
Floor 5 Posted 2003-10-27 00:00 ·  中国 陕西 西安 电信
高级用户
★★
OS/2女孩
Credits 639
Posts 183
Joined 2003-06-14 00:00
23-year member
UID 5148
Gender Female
Status Offline
REM 喜欢DOS,因为它的简单
REM 喜欢OS/2,因为它不再矫饰
REM 喜欢BASIC,因为它并不幼稚
REM 喜欢GNU,因为它杂乱无章
Floor 6 Posted 2003-10-27 00:00 ·  中国 河北 石家庄 电信
中级用户
★★
疯狂的流浪者
Credits 276
Posts 56
Joined 2003-09-25 00:00
22-year member
UID 10329
Gender Male
Status Offline
I once used this structure to write a DOS graphical system,
defined lots of message structures, pretty interesting too,
implemented multithreading, but you have to handle and initialize a lot of interrupts!
It's completely message-based. I hope someone gets inspired by this and develops a function library, so that later when developing DOS
programs there will be a graphical standard, and the program framework will be unified too!
临河居士
http://www.xygod.pc5.org
Floor 7 Posted 2004-05-12 00:00 ·  中国 新疆 喀什地区 电信
初级用户
Credits 125
Posts 11
Joined 2004-05-09 00:00
22-year member
UID 23971
Gender Male
Status Offline
>I once used this structure to write a DOS graphical system
Post it and let us have a look.
Forum Jump: