;********************************************************************* ;* Title CODE-KEYSCN-V01.ASM ;********************************************************************* ;* Author: ;* R. Allen Murphey ;* ;* License: ;* Copyright (c) 2022 R. Allen Murphey. All Rights Reserved. ;* ;* Description: ;* Color Computer and Dragon keyboard driver ;* ;* Documentation ;* MC6821 Peripheral Interface Adapter (PIA) Data Sheet ;* Color Computer Technical Reference Manual ;* Color Computer 2 Service Manual ;* Color Computer 3 Service Manual ;* Inside the Dragon ;* v00 https://exileinparadise.com/tandy_color_computer:keyscn ;* v01 https://exileinparadise.com/tandy_color_computer:keyscn2 ;* ;* Include Files: ;* PIA0 ;* ;* Assembler: ;* lwasm from LWtools 4.19+ ;* ;* Revision History: ;* Rev # Date Who Comments ;* ----- ----------- ------ --------------------------------------- ;* 01 2022 RAM Rebuilt as ROL loop, and decode stepped loops ;* 00 2020 RAM Created initial keyscn fully unrolled ;********************************************************************* ; KEYPRESS ; last key pressed, defined in NOSTROMO.ASM ; JOYBUF equ $00F3 ; store buffers in 1 of 13 unused zero page bytes ; KEYBUF equ $00F4 ; store keybuff in 8 of 13 unused zero page bytes KEY_UP: equ 27 KEY_DOWN: equ 28 KEY_LEFT: equ 29 KEY_RIGHT: equ 30 KEY_ENTER: equ 48 ; $0D CR Carriage Return KEY_CLEAR: equ 49 ; $0C FF Form Feed KEY_BREAK: equ 50 ; $03 ETX End of Text KEY_ALT: equ 51 ; Modifier Key 3 KEY_CTRL: equ 52 ; Modifier Key 2 KEY_F1: equ 53 KEY_F2: equ 54 KEY_SHIFT: equ 55 ; Modifier Key 1 ;********************************************************************* ;* KEYSCN - strobe PIA0 port B all 8 columns and save to DP buffer ;* Entry Values ;* None ;* Globals Used ;* JOYBUF, KEYBUF, KEYPRESS ;* Control Register Modifications ;* A,X,CC (preserved and restored) ;* PIA0AD, PIA0BD (destroyed) ;* Subroutines Called ;* None ;* Exit Values ;* None ;* Notes ;* Thanks to Simon Jonassen, William Astle, and Dave Phillipsen ;* for patiently explaining where I was going wrong with PIC on ;* I/O addresses and thanks Simon for the CLC replacement ;********************************************************************* KEYSCN: pshs A,X,CC ; save our registers leax JOYBUF,PCR ; point to place to save polled data lda #$FF ; all bits high sta PIA0BD ; disable all keyboard column strobes clra ; clears carry too which is what we want here KEY010: lda PIA0AD ; read the keyboard rows, first joy, then keys sta ,X+ ; store to pointer and advance to next save ptr rol PIA0BD ; move the zero bit left to strobe next bcs KEY010 ; keep reading until we hit our original CLC puls A,X,CC,PC ; restore registers and bail ;********************************************************************* ;* DECODE - decode a bit from the saved key buffer into an ASCII value ;* Entry Values ;* None ;* Globals Used ;* KEYBUF,COCOKEYS,DRGNKEYS,KEYPRESS ;* Control Register Modifications ;* A,B,X,Y,CC (preserved and restored) ;* Subroutines Called ;* None ;* Exit Values ;* None ;********************************************************************* DECODE: pshs A,B,X,Y,CC ; save our registers leax KEYBUF,PCR ; pointer to where we saved PIA data ; FIXME Config switch for CoCo or Dragon leay COCOKEYS,PCR ; load Y with ptr to keys read in clrb ; start with b empty as bit cursor DECD000: lda ,X+ ; get read key bits into A to process DECD010: rora ; move low bit into carry to test bcs DECD020 ; bit high, key not processed, skip lookup leax KEYPRESS,PCR ; get pointer to keypress output lda B,Y ; get the key sta ,X ; save just the KEY_* out bra DECD030 ; head for the exit DECD020: addb #8 ; move bit cursor to next column cmpb #56 ; have we read past bit 6 of keybuf? blt DECD010 ; no go get next key bit from current buffer subb #55 ; yes, go back to row 0 of next column cmpb #8 ; is bit cursor past end of column data? blt DECD000 ; no go get next key buffer and decode it DECD030: puls A,B,X,Y,CC,PC ; restore registers and bail ;********************************************************************* ; Color Computer 1,2,3 Key Matrix Decoding Table ;********************************************************************* COCOKEYS: fcb '@','A','B','C','D','E','F','G' fcb 'H','I','J','K','L','M','N','O' fcb 'P','Q','R','S','T','U','V','W' fcb 'X','Y','Z',KEY_UP,KEY_DOWN,KEY_LEFT,KEY_RIGHT,' ' fcb '0','1','2','3','4','5','6','7' fcb '8','9',':',';',',','-','.','/' fcb KEY_ENTER,KEY_CLEAR,KEY_BREAK,KEY_ALT,KEY_CTRL,KEY_F1,KEY_F2,KEY_SHIFT ;********************************************************************* ; Dragon 32,64 Key Matrix Decoding Table ;********************************************************************* DRGNKEYS: fcb '0','1','2','3','4','5','6','7' fcb '8','9',':',';',',','-','.','/' fcb '@','A','B','C','D','E','F','G' fcb 'H','I','J','K','L','M','N','O' fcb 'P','Q','R','S','T','U','V','W' fcb 'X','Y','Z',KEY_UP,KEY_DOWN,KEY_LEFT,KEY_RIGHT,' ' fcb KEY_ENTER,KEY_CLEAR,KEY_BREAK,KEY_ALT,KEY_CTRL,KEY_F1,KEY_F2,KEY_SHIFT ;********************************************************************* ;* End of code-keyscn-v01.asm ;*********************************************************************