flat assembler
Message board for the users of flat assembler.

Index > DOS > Cant get keyboard handler to work

Author
Thread Post new topic This topic is locked: you cannot edit posts or make replies.
Karl20001



Joined: 10 Nov 2005
Posts: 11
Karl20001
Hi, im making little game in asm.
Problem is that is very slowed down by using int 16h or keyboard port check on every loop.
So i want to use keyboard interrupt handler, with some functions already found on this board.

Here is the code of my test program. It should print out current address for keyboard interrupt handler, change address, print new address and then do a loop to simulate a normal working program.

And when i hit a key, my keyboardhandler should be called automatically and print something out. The problem is it doesnt, the program just hangs after the first key pressed, why ? Crying or Very sad


Code:
use16
org 0x100


mov al, 9h
call getint     ; es = segment  bx = offset
mov ax, es
mov dx, bx
mov bx, 16
call putint
call newline
mov ax,dx
call putint
call newline
call newline

mov ah, 0   ; Key wait
int 16h


mov al, 9h
mov dx, handlekey
call setint


mov al, 9h
call getint     ; es = segment  bx = offset
mov ax, es
mov dx, bx
mov bx, 16
call putint
call newline
mov ax,dx
call putint
call newline
call newline

mov ah, 0   ; Key wait
int 16h

a:    ;simulate a real running program
 nop
 nop 
 mov ax,bx
 mov cx,bx
jmp a


exit:
int 20h  ;exit


handlekey:
 push ax
 push bx

 in al,60h       ; read scancode byte

 mov ah,0eh     ; print character from scancode
 mov bh,0
 int 10

 pop bx
 pop ax
iret



;----------------------------------------------------------------------------
; set interrupt vector
setint:
       ; al = interrrupt
       ; cs = segment
       ; dx = offset


       ; cmp al, 19h               ; do not allow to change int 19h (for rebooting)
       ; je near int21_error

        cli
        xor ah, ah
        shl ax, 2

        push si
        push bx
        push es

        mov si, ax
        xor bx, bx
        mov es, bx

        mov word [es:si], dx             ; offset
        mov bx, cs
        mov word [es:si+2], bx                ; segment

        pop es
        pop bx
        pop si
        sti

    retn

;----------------------------------------------------------------------------
; get interrupt vector
; al = interrupt
; es = segment
; bx = offset



getint:
        push ds
        push si

        xor ah, ah
        shl ax, 2
        mov si, ax

        xor bx, bx
        mov ds, bx             ; DS = 0

        mov bx, word [ds:si+2]  ; segment
        push bx
        mov bx, word [ds:si]    ; offset

        pop es                      ; get segment

        pop si
        pop ds

 retn 



newline:
  push ax dx
  mov ah,02h
  mov dl,0Dh
  int 21h    ; Output CR to screen
  mov dl,0Ah
  int 21h    ; Output LF to screen
  pop dx ax
ret


; bx = base (default = 10), ax = number
putint:
  push ax bx cx dx
  cmp bx,0
  jne .start    ; the same as in putsint... (if bx = 0 then bx = 10)
  mov bx,10
  .start:
  xor cx,cx     ; cx = 0
  .new:
  xor dx,dx     ; dx = 0
  div bx        ; number / base
  push dx       ; push the remainder
  inc cx        ; increase the "digit-count"
  cmp ax,0      ; if the quotient still is not 0, do it once more
  jnz .new
  .loop:
  pop dx        ; pop the remainder
  add dl,30h    ; convert the number to a character
  cmp dl,"9"
  jng .ok       ; if the charater is greater than "9" then we have
  add dl,7      ; to add 7 to get A as 10, B as 11, and so on...
  .ok:
  mov ah,02h    ; output the character
  int 21h
  loop .loop

  pop dx cx bx ax
ret                  
       
    
Post 17 Nov 2005, 23:58
View user's profile Send private message Reply with quote
Karl20001



Joined: 10 Nov 2005
Posts: 11
Karl20001
Well i solved it now, had to insert this into the handler code

Code:
 mov     al,20h          ; Send generic EOI to PIC
  out     20h,al          ; 001 00 000
                                        ;  |   |  |
                                        ;  |   |  +--- INT request level
                                        ;  |   +------ OCW2
                                        ;  +---------- non-specific EOI command          
Post 20 Nov 2005, 01:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic This topic is locked: you cannot edit posts or make replies.

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.