flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Reading keyboard fast to much?

Author
Thread Post new topic Reply to topic
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash
Hello!
I borrow some subroutines, from DexOS and early Linux, to read keyboard. It works fine over DOS, but when I use it as part of "stand alone" code (boot code). The keys are readed twice.
As you can see, the routines have filtered de key-up signal. Can anybody help me to solve taht problem.... some advice maybe... Thanks:

Code:
;All vars are well defined
;This subroutine reads the scan code
KeyPress: cli
             xor     CX,CX
           @@: in  AL,64h
              test    AL,1
                loopz   @b
          in      AL,60h
              sti
         ret

;This subroutine maps ASCII chars
       ReadKey: call        KeyPress
            cmp     AL,42                   ;Left Shift pressed
         jne     @f
          mov     [shiftstatus],0FFh
          jmp     ReadKey
         @@: cmp AL,42+128               ;Left Shift released
                jne     @f
          mov     [shiftstatus],0
             jmp     ReadKey
         @@: cmp AL,54                   ;Right Shift pressed
                jne     @f
          mov     [shiftstatus],0FFh
          jmp     ReadKey
         @@: cmp AL,54+128               ;Right Shift released
               jne     @f
          mov     [shiftstatus],0
             jmp     ReadKey
         @@: cmp AL,58+128               ;CapsLock activated
         jne     @f
          not     [capsstatus]
                jmp     ReadKey
         @@: cmp AL,56                   ;Avoid Alt "echo"
         jne     @f
          jmp     ReadKey
         @@: cmp AL,58                   ;Avoid CapsLock "echo"
            jne     @f
          jmp     ReadKey
         @@: cmp AL,29                   ;Avoid Left Ctrl "echo"
           jne     @f
          jmp     ReadKey
         @@: cmp AL,128                  ;Avoid all "echoes"
               jb      @f
          jmp     ReadKey

     @@: xor AH,AH
               mov     DI,AX
               cmp     [shiftstatus],0FFh
          jne     @f
          mov     AL,[DI+shiftkeymap]
         ret
     @@: cmp [capsstatus],0FFh
           jne     @f
          mov     AL,[DI+capskeymap]
          ret
     @@: mov AL,[DI+normalkeymap]
                ret

;This subroutine puts chars at screen
       PutChar: push    0B800h
              pop     ES
          mov     SI,[textfbpos]
              cmp     AL,8                    ;Ejecutar BackSpace
         jne     @f
          cmp     SI,0
                jne     PutCharBackSpc
              ret
PutCharBackSpc: mov  [ES:SI],byte 32     ;Erase cursor
               sub     SI,2
                mov     [ES:SI],byte 32     ;Erase previous char
                mov     [textfbpos],SI
              ret
     @@: cmp AL,9                    ;Do Tab
             jne     @f
          mov     CX,6
    PutCharTab: mov [ES:SI],byte 32     ;Fill with space
            add     SI,2
                loop    PutCharTab
          mov     [textfbpos],SI
              ret
     @@: cmp AL,10                   ;Do Enter
           jne     @f
          mov     [ES:SI],byte 0              ;Mark line jmp
              call    NextFrameBufferLine
         mov     [textfbpos],SI
              ret
     @@: mov [ES:SI],AL
              add     SI,2
                mov     [textfbpos],SI
              ret
      textfbpos dw 0
    shiftstatus DB 0
     capsstatus DB 0
  normalkeymap: DB 0
             DB 27,'1234567890-=',8
            DB 9,'qwertyuiop[]',10
            DB 0,'asdfghjkl;',39,96,0,'\'
          DB 'zxcvbnm,./',0,'*',0,' '
           DB 0,'2345678901',0,'3789-456+1230.'

   shiftkeymap: DB 0
            DB 27,'!@#$%^&*()_+',8
                DB 9,'QWERTYUIOP{}',10
          DB 0,'ASDFGHJKL:"~',0,'|'
              DB 'ZXCVBNM<>?',0,'*',0,' '
             DB 0,'2345678901',0,'3789-456+1230.'

    capskeymap: DB 0
            DB 27,'1234567890-=',8
            DB 9,'QWERTYUIOP[]',10
            DB 0,'ASDFGHJKL;',39,96,0,'\'
          DB 'ZXCVBNM,./',0,'*',0,' '
           DB 0,'2345678901',0,'3789-456+1230.'
    

_________________
i don't hate goto
Post 16 Mar 2011, 22:50
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
isr ends with iret!!!!
and don't forget to disable/enable the keyboard at the end of the isr, with io port 61h. very important, if you don't do that, the keyboard will not send the next scan code.

and don't forget too to free the PIC with EOI to io port 20h.



not ret

and no need of cli, sti, because... no irq handler should block irqs.

there is a reason for the priority.

less priority interrupts cannot occurs during isr, but high priority interrupt should be supported during lesser isr.
Post 16 Mar 2011, 23:01
View user's profile Send private message Visit poster's website Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash
Mmmm... thanks!! A lot. Very interesting things. I am sure i will need that. But, the code I post is not intended to be used as interrupt service routine. The program simply calls ReadKey and it waits for any key to be pressed... As the code shows, the ASCII results in AL and it can be used for PutChar in order to be printed on screen. Te problem is that chars are printed on screen more than one time, really really fast!!!! I have no idea what can be happen... Sad
Post 17 Mar 2011, 01:36
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
in user code, you don't need to test the flag in port 64h.
the isr still do it.

if you don't want to read 2 times the same key, just add a simple routine:

Code:
in al,60h
cmp al,[oldcode]
je @f
mov al,[oldcode]
call keyprocessing
@@:
ret
oldcode db ?
    


oldcode will contain the last entered scancode, and just by compare it with the fresh scancode, you will know if it is a typematic repetition, or a new key.

it is very simple.
Post 17 Mar 2011, 15:49
View user's profile Send private message Visit poster's website Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash
Oh!! so simple!!! Smile I am wondering how we can keep "some other ideas" in code. After read your post i found the real problem... loopz instruction!!!.
I change KeyPress to:
Code:
      KeyPress: cli
        @@: in  AL,64h
              test    AL,1
                jz      @b
          in      AL,60h
              sti
         ret
    

And It works fine!!!! Beautiful. But now the use is more important. Since i am disabling interrupts its a clear signal to make the code interrupt driven. Which send me back to your first post Wink Thank's!!!
Post 19 Mar 2011, 16:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

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.