同时获取两把钥匙——组装8086 [英] Get two keys at the same time - Assembly 8086

查看:29
本文介绍了同时获取两把钥匙——组装8086的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在组装一个游戏,有两个玩家.所以我使用下面的代码来按下当前的键:

I am building a game in assembly, with two players. So I'm using the following code to get the current key pressed:

mov ah, 01h
int 16h

此代码为我提供了所按下键的扫描码和 Ascii 码问题是两个玩家可能同时按下 2 个不同的键.如何同时收到两个密钥?

This code gives me the Scan code and the Ascii code of the pressed key The problem is that two players might press 2 different keys on the same time. How do I receive two keys at the same time?

我尝试了几种方法来实现这一目标.我尝试通过在 al,060h 中使用直接获取输入.我也试过 int 9h 但还是不行.

I have tried few ways to achieve that. I tried getting the input directly by using in al,060h. I also tried int 9h but still it didn't work.

推荐答案

如果没记错的话,用谷歌搜索一下让自己重新了解数字...

If memory serves, with a touch of Googling to refresh myself on the numbers...

BIOS 没有提供您想要的.它正在管理文本字符的输入流.这与捕获按键事件密切相关,但不会让您知道现在按下了哪些键,只能判断哪些键在某些时候没有按下,然后在过去变得按下.

The BIOS doesn't offer what you want. It's managing an input stream of text characters. Which is strongly related to catching key down events but will not allow you to tell which keys are depressed now, only which keys at some point weren't depressed and then became depressed in the past.

您需要使用int 21h,函数25h 来安装您自己的int 9h 处理程序.这样您就可以直接从硬件获取按键向上和按键向下事件.

You need to use int 21h, function 25h to install your own handler for int 9h. That way you'll get the key up and key down events directly from the hardware.

在您的处理程序中,读取端口 60h 以确定发生中断的原因.低七位是密钥代码.如果最高位清零,则该键已转换为已按下.如果设置了最高位,则该键已转换为未按下.

Within your handler, read port 60h to determine why the interrupt has occurred. The low seven bits are a key code. If the top bit is clear then the key has transitioned to pressed. If the top bit is set then the key has transitioned to unpressed.

然后您需要将 20h 输出到端口 20h 以确认中断.

You then need to out 20h to port 20h to acknowledge the interrupt.

所以你可能会保留一个 128 字节的表,初始化为所有 80h.在您的处理程序中,只需将 value 存储到 value&7h.

So you might keep a table of 128 bytes, initialised as all 80h. In your handler, just store value to value&7h.

在您的实际游戏代码中,如果您想知道当时是否按下了 n 键,请从您的表中读取第 n 个值并在符号上进行分支.正 = 按下,负 = 未按下.

In your actual game code, if you want to know whether key n is pressed at that moment, read the nth value from your table and branch on sign. Positive = pressed, negative = unpressed.

(附录:你还应该在启动时获取现有向量并在退出前恢复它,否则你只是不小心写了 TSR 的挂钩部分,可能没有做 SR 部分)

(Addendum: you should also get the existing vector when you launch and restore it before you exit, or else you've just accidentally written the hooking part of a TSR, probably without doing the SR part)

这篇关于同时获取两把钥匙——组装8086的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆