![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-31 19:55 |
47,815 topics / 349,930 posts / today 0 new / 48,290 members |
| DOS开发编程 & 发展交流 (开发室) » [Original] A keyboard program I wrote, hehe, still very immature! |
| Printable Version 1,220 / 6 |
| Floor1 xy_god | Posted 2003-10-26 00:00 |
| 中级用户 Posts 56 Credits 276 | |
|
/************************************************/
/* 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; } } } |
|
| Floor2 xy_god | Posted 2003-10-26 00:00 |
| 中级用户 Posts 56 Credits 276 | |
|
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! |
|
| Floor3 lemonhall | Posted 2003-10-27 00:00 |
| 高级用户 Posts 183 Credits 639 | |
| Floor4 xy_god | Posted 2003-10-27 00:00 |
| 中级用户 Posts 56 Credits 276 | |
|
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! |
|
| Floor5 lemonhall | Posted 2003-10-27 00:00 |
| 高级用户 Posts 183 Credits 639 | |
| Floor6 xy_god | Posted 2003-10-27 00:00 |
| 中级用户 Posts 56 Credits 276 | |
|
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! |
|
| Floor7 alhan | Posted 2004-05-12 00:00 |
| 初级用户 Posts 11 Credits 125 | |
|
>I once used this structure to write a DOS graphical system
Post it and let us have a look. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |