X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=ld45_start_nothing;a=blobdiff_plain;f=src%2Fkeyb.asm;h=0f1d498370410ad390d7e7990377e132a5991dc1;hp=5200f2acf562c565e5dcb58f75fb358db07bd9b1;hb=0216fd8105a2b94aab6eb1c013c97882cacaf0c1;hpb=72eec372bc82e28afee824b440fc76aad177d66b diff --git a/src/keyb.asm b/src/keyb.asm index 5200f2a..0f1d498 100644 --- a/src/keyb.asm +++ b/src/keyb.asm @@ -1,5 +1,107 @@ ; vi:filetype=nasm ts=8 sts=8 sw=8: +%include "intr.inc" +%include "kbregs.inc" global kb_init kb_init: - + push kbintr + push dword IRQ_TO_INTR(KB_IRQ) + call set_intr + add esp, 8 + + ; enable keyboard interrupt + mov eax, KB_CMD_GET_CMDBYTE + call send_cmd + call read_data + or eax, KB_CCB_KB_INTREN ; set the INTREN flag + push eax + mov eax, KB_CMD_SET_CMDBYTE + call send_cmd + pop eax + call send_data + + ; flush the read buffer + call wait_read + jz .skipread + call read_data +.skipread: + ret + + ; keyboard interrupt handler +kbintr: + pusha + in al, KB_DATA_PORT + cmp al, 0e0h + jnz .noext + mov byte [key_ext], 1 + jmp .eoi +.noext: + ; keystate[keycode] address in ebx + xor ebx, ebx + mov bl, al + add ebx, keystate + + ; determine if it's a press or release + test al, 80h + jz .press + ; key release + mov byte [ebx], 0 + jmp .eoi +.press: ; key press + mov byte [ebx], 1 + +.eoi: + cli + end_of_irq KB_IRQ + + popa + iret + +%macro iodelay 0 + xor al, al + times 7 out 80h, al +%endmacro + +wait_write: + push eax + push ecx + mov ecx, 32768 +.loop: in al, KB_STATUS_PORT + test al, KB_STAT_INBUF_FULL + jz .break + iodelay + dec ecx + jnz .loop +.break: pop ecx + pop eax + ret + +wait_read: + push eax + push ecx + mov ecx, 32768 +.loop: in al, KB_STATUS_PORT + test al, KB_STAT_OUTBUF_FULL + jnz .break + iodelay + dec ecx + jnz .loop +.break: pop ecx + pop eax + ret + + ; expects command in al +send_cmd: + call wait_write + out KB_CMD_PORT, al + ret + +read_data: +send_data: + + section .data + align 4 +key_ext: db 0 + + global keystate +keystate: times 256 db 0