📄 keys.c
字号:
/* Keys.c
This file is part of the VGB-DOS project
Copyright (C) Marcel de Kogel (m.dekogel@student.utwente.nl), 1996
You may not use this file for commercial purposes
Please notify me if you make any changes to this file */
#include <stdio.h>
#include <sys/farptr.h>
#include <dpmi.h>
#include <go32.h>
#include <crt0.h>
#include <pc.h>
int _crt0_startup_flags = _CRT0_FLAG_NONMOVE_SBRK |
_CRT0_FLAG_LOCK_MEMORY |
_CRT0_FLAG_DROP_EXE_SUFFIX;
static __volatile__ int key=0;
static _go32_dpmi_seginfo newirqkeyb,oldirqkeyb;
void keyb_interrupt (void)
{
unsigned code;
static int extkey;
code=inportb (0x60); /* get scancode */
if (code<0xE0) /* ignore codes >0xE0 */
{
if (code & 0x80) /* key is released */
key=0;
else /* key is pressed */
{
if (extkey)
key=code+128;
else
key=code;
}
extkey=0;
}
else
if (code==0xE0)
extkey=1;
}
static int _getkey (char *s)
{
printf ("Press key for %s\n",s);
key=0;
while (!key);
_farpokew (_dos_ds,0x41A,_farpeekw(_dos_ds,0x41C)); /* clear buffer */
return key;
}
int main (int argc,char *argv[])
{
int left,right,up,down,firea,fireb,start,select;
_go32_dpmi_get_protected_mode_interrupt_vector (9,&oldirqkeyb);
newirqkeyb.pm_offset=(int)keyb_interrupt;
newirqkeyb.pm_selector=_go32_my_cs();
_go32_dpmi_chain_protected_mode_interrupt_vector (9,&newirqkeyb);
left=_getkey ("LEFT");
right=_getkey ("RIGHT");
up=_getkey ("UP");
down=_getkey ("DOWN");
firea=_getkey ("BUTTON A");
fireb=_getkey ("BUTTON B");
start=_getkey ("START");
select=_getkey ("SELECT");
printf ("\n-keys %02X%02X%02X%02X%02X%02X%02X%02X\n",
left,right,up,down,firea,fireb,start,select);
_go32_dpmi_set_protected_mode_interrupt_vector (9,&oldirqkeyb);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -