adolf01

Untitled

Jan 31st, 2021
1,315
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; KBSCAN will scan the keyboard for incoming data for about
  2. ; 105uS and returns with A=0 if no data was received.
  3. ; It does not decode anything, the non-zero value in A if data
  4. ; is ready is ambiguous.  You must call KBGET or KBINPUT to
  5. ; get the keyboard data.
  6. ;
  7. kbscan:         ldx   #$05              ; timer: x = (cycles - 40)/13   (105-40)/13=5
  8.                lda   kbportddr         ;
  9.                and   #$CF              ; set clk to input (change if port bits change)
  10.                sta   kbportddr         ;
  11. kbscan1:        lda   #clk              ;
  12.                bit   kbportreg         ;
  13.                beq   kbscan2           ; if clk goes low, data ready
  14.                dex                     ; reduce timer
  15.                bne   kbscan1           ; wait while clk is high
  16.                jsr   kbdis             ; timed out, no data, disable receiver
  17.                lda   #$00              ; set data not ready flag
  18.                rts                     ; return
  19. kbscan2:        jsr   kbdis             ; disable the receiver so other routines get it
  20. ; Three alternative exits if data is ready to be received: Either return or jmp to handler
  21. ;               rts                     ; return (A<>0, A=clk bit mask value from kbdis)
  22.                jmp   kbinput           ; if key pressed, decode it with KBINPUT
  23. ;               jmp   KBGET             ; if key pressed, decode it with KBGET
  24. ;
  25. ;
RAW Paste Data