BBS: Inland Empire Archive Date: 11-21-92 (19:35) Number: 362 From: BRENT ASHLEY Refer#: NONE To: RAYMOND PAQUIN Recvd: NO Subj: QB SIMULTANEOUS KEYS Conf: (2) Quik_Bas
; ; KeyPress.ASM by Brent Ashley ; maintains map of the "pressed" status of all keys ; allows you to detect multiple keys pressed ; .model medium, basic .code Old09 Label Dword ;Label for to old Int 09h handler Old09Offset dw ? ;Offset part Old09Segment dw ? ;Segment part Hooked db 0 ;Our installed flag KeyMap db 80h dup(0) ;map of kybd, one byte per scancode InstKeyPress proc uses ds ax dx ; From BASIC: CALL InstKeyPress ; REMEMBER to call UnhookKeyPress! cmp cs:Hooked,0 ;Are we already hooked? jnz InstallExit ;If so, exit mov ax,3509h ;Get current vector for int 09h int 21h mov cs:Old09Segment,es ;Remember it for later mov cs:Old09Offset,bx mov ax,2509h push ds push cs pop ds ;Point int 09h handler to our code mov dx, offset OurInt09 int 21h pop ds mov cs:Hooked,-1 ;Set our installed flag InstallExit: ret OurInt09: ;Our Int 09h handler push ax push bx push dx push si in al, 60h ;get scancode from keyboard port test al, 080h ;is "released" bit set? jnz Released ;yup - go to it mov dl, 0FFh ;nope - set key pressed flag jmp PutFlag Released: and al, 07Fh ;yes - clear bit for index mov dl, 0 ;and set flag for release PutFlag: xor ah, ah mov si, ax ;assign index mov cs:KeyMap[si], dl ;put flag in place pop si pop dx pop bx pop ax Continue: jmp dword ptr cs:[Old09] ;Transfer control to orig Int 09h InstKeyPress endp KeyPressed proc uses bx si, ScanCode:WORD ; from BASIC: TrueOrFalse% = KeyPressed(ScanCode%) mov bx, ScanCode ;get scan code addr mov si, [bx] ;load value as index mov al, cs:KeyMap[si] ;put flag in al and al, 07Fh ;make sure less than 80h cbw ;convert to word for integer value ret KeyPressed endp UnhookKeyPress proc ; from BASIC: CALL UnHookKeyPress cmp cs:Hooked,0 ; are we installed? jz UnHooked ; nope - exit push ax push ds mov ax,2509h ;Unhook ourself mov ds,Old09Segment mov dx,Old09Offset int 21h ;Point Int 09h back to original handler pop ds pop ax mov cs:Hooked,0 ;Set installed flag back to zero UnHooked: ret UnhookKeyPress endp END --- FidoPCB v1.3 [ff053/x] * Origin: Canada Remote Systems, Mississauga, Ontario (1:229/15)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET