KEYSCN

Reading the Color BASIC Unravelled book, the POLCAT/KEYIN routine seemed particularly not-good in the way it was written:

  • Thousands of cycles wasted in the keyboard debounce delay loop (countdown from 04e5 to 0 before return)
  • Only returns a single keystroke at a time (heavily processed) or a carry bit error indicator
  • Polls keys without shift, then again with shift, special break processing etc.

Could I do better? Probably not.

Could I come up with something that detected multiple simultaneous keypresses and didn't have a huge delay loop?

Probably. Well yes. Here it is in version 0.1 draft state.

Tested working in MAME and on my physical CoCo3.

THE JOY OF DEBUGGING

There are days when you want to pound your head on the desk to shake your eyeballs loose … since they've been staring through a stupid embarrassing bug.

Writing a naive CoCo3 keyboard scanner (keyscn.s attached) and nothing would work - and as you can see from the code this stuff should be drop dead simple.

All I wanted was to sample all of the columns of the PIA0 keyboard ports into RAM, then step through the sampled bytes bit by bit to decode all pressed keys at once, and flag them on the screen, like a keyboard diagnostic program.

Nope, no dice.

After hours and hours and different things, leaving it alone for a week and coming back the next weekend, I finally saw the problem.

In the attached code, all the CHK* labels are attached to an LDA ,X to load the scanned PIA data, then start checking.

That code block was copy and and pasted a lot.

And the original… well, the label was one line lower on the AND #%.

So yeah, that wasn't gonna work as intended - load A once, AND and CMP it over and over gets you no results.

BADNESS

This code is good for nothing.

It's a terrible example of extremely naive coding.

Rather than wasting cycles in debounce, I waste RAM using about 8x more code bytes than POLCAT/KEYIN.

Feel free to refer to it and learn from it but for pity's sake - write something better for yourself.

I've set the bar this low, so everyone can achieve higher.

You're probably better off sticking with POLCAT/KEYIN.

Or, check out the enum KeyboardBits and isKeyPressed() function in Pierre Sarrazin's fantastic CMOC compiler coco.h header file.

CODE

* KEYSCN.S
* V0.1 2020-02-09 ROBERT "ALLEN" MURPHEY
* FIXME NONASCII KEY PLACEHOLDERS
* Instructions:
* perl -e 'print chr(255) x (35*18*256)' > keyscn.dsk
* lwasm -9 -b --unicorns --list=keyscn.lst --symbols -o keyscn.bin keyscn.s
* writecocofile --verbose keyscn.dsk keyscn.bin
* Start CoCo
* LOADM"KEYSCN":EXEC
* PRESS KEYS
* Press RESET to quit
*
CURPOS	EQU	$88		* CURSOR POSITION HELD BY COLOR BASIC
VIDRAM	EQU	$0400		* START OF VIDEO RAM
INKEYB  EQU     $6400		* USE THE UNUSED BASIC SPACE
OUTKEY	EQU	$6600		* INPUT BUFFER
PIA0AD	EQU	$FF00		* PIA 0 PORT A DATA
PIA0AC	EQU	$FF01		* PIA 0 PORT A CONTROL
PIA0BD	EQU	$FF02		* PIA 0 PORT B DATA
PIA0BC	EQU	$FF03		* PIA 0 PORT B CONTROL

	ORG	$6000		* SOMEPLACE TO LIVE

NEWCLS	LDD	#$8080		* LOAD BLANK CHARACTER IN A AND B
	LDX	#VIDRAM		* START ADDRESS OF VIDEO TEXT RAM
	STX	CURPOS		* SET CURSOR POSITION BACK TO HOME
CLRTWO	STD	,X++		* CLEAR TWO BYTES AT X AND INCREMENT X+2
	CMPX	#VIDRAM+511	* HAVE WE REACHED THE LAST ADDRESSES?
	BLS	CLRTWO		* NOT DONE YET, GO TO NEXT

KEYSCN	LDX	#INKEYB		* SETUP X TO POINT TO 8-BYTE KEY BUFFER
	LDA	#%11111111	* SET ALL BITS TO...
	STA	PIA0BD		* ... DISABLE ALL KEYBOARD COLUMN STROBES

	LDA	#%11111110	* SETUP TO STROBE COLUMN 0
	STA	PIA0BD		* STROBE COLUMN 0
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 0
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%11111101	* SETUP TO STROBE COLUMN 1
	STA	PIA0BD		* STROBE COLUMN 1
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 1
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%11111011	* SETUP TO STROBE COLUMN 2
	STA	PIA0BD		* STROBE COLUMN 2
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 2
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%11110111	* SETUP TO STROBE COLUMN 3
	STA	PIA0BD		* STROBE COLUMN 3
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 3
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%11101111	* SETUP TO STROBE COLUMN 4
	STA	PIA0BD		* STROBE COLUMN 4
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 4
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%11011111	* SETUP TO STROBE COLUMN 5
	STA	PIA0BD		* STROBE COLUMN 5
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 5
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%10111111	* SETUP TO STROBE COLUMN 6
	STA	PIA0BD		* STROBE COLUMN 6
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 6
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%01111111	* SETUP TO STROBE COLUMN 7
	STA	PIA0BD		* STROBE COLUMN 7
	LDA	PIA0AD		* READ ALL KEYBOARD ROWS FOR COLUMN 7
	COMA			* COMPLEMENT ALL BITS SO 1 = KEY PRESSED
	STA	,X+		* STORE IN INKEYB AND INCREMENT X

	LDA	#%11111111	* SET ALL BITS TO...
	STA	PIA0BD		* ... DISABLE ALL KEYBOARD COLUMN STROBES

KEYINX	LDX	#INKEYB		* GET TO TOP OF KEY SAMPLE BUFFER
	LDY	#OUTKEY		* GET START OF DECODED KEY BUFFER

				* ROW 0
CHKAT	LDA	,X		* LOAD FIRST ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKH		* NOPE, CHECK NEXT ROW
	LDA	#'@		* @ KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0478		* DRAW THE AT KEY

CHKH	LDA	,X		* LOAD FIRST ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKP		* NOPE, CHECK NEXT ROW
	LDA	#'H		* H KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04AF		* DRAW THE H KEY
	
CHKP	LDA	,X		* LOAD FIRST ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKX		* NOPE, CHECK NEXT ROW
	LDA	#'P		* P KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0476		* DRAW THE P KEY
	
CHKX	LDA	,X		* LOAD FIRST ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK0		* NOPE, CHECK NEXT ROW
	LDA	#'X		* X KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04E8		* DRAW THE X KEY
	
CHK0	LDA	,X		* LOAD FIRST ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHK8		* NOPE, CHECK NEXT ROW
	LDA	#'0		* 0 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0435		* DRAW THE 0 KEY
	
CHK8	LDA	,X		* LOAD FIRST ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKENT		* NOPE, CHECK NEXT ROW
	LDA	#'8		* 8 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0431		* DRAW THE 8 KEY
	
CHKENT	LDA	,X+		* LOAD FIRST ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKA		* NOPE, CHECK NEXT ROW
	LDA	#$13		* ENTER KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04B9		* DRAW THE ENTER KEY

				* ROW 1
CHKA	LDA	,X		* LOAD SECOND ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKI		* NOPE, CHECK NEXT ROW
	LDA	#'A		* A KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04A5		* DRAW THE A KEY

CHKI	LDA	,X		* LOAD SECOND ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKQ		* NOPE, CHECK NEXT ROW
	LDA	#'I		* I KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0472		* DRAW THE I KEY
	
CHKQ	LDA	,X		* LOAD SECOND ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKY		* NOPE, CHECK NEXT ROW
	LDA	#'Q		* Q KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0464		* DRAW THE Q KEY
	
CHKY	LDA	,X		* LOAD SECOND ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK1		* NOPE, CHECK NEXT ROW
	LDA	#'Y		* Y KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$046E		* DRAW THE Y KEY
	
CHK1	LDA	,X		* LOAD SECOND ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHK9		* NOPE, CHECK NEXT ROW
	LDA	#'1		* 1 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0423		* DRAW THE 1 KEY
	
CHK9	LDA	,X		* LOAD SECOND ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKCLR		* NOPE, CHECK NEXT ROW
	LDA	#'9		* 9 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0433		* DRAW THE 9 KEY
	
CHKCLR	LDA	,X+		* LOAD SECOND ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKB		* NOPE, CHECK NEXT ROW
	LDA	#$12		* CLEAR KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$047A		* DRAW THE CLEAR KEY

				* ROW 2
CHKB	LDA	,X		* LOAD THIRD ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKJ		* NOPE, CHECK NEXT ROW
	LDA	#'B		* B KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04EE		* DRAW THE B KEY

CHKJ	LDA	,X		* LOAD THIRD ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKR		* NOPE, CHECK NEXT ROW
	LDA	#'J		* J KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04B1		* DRAW THE J KEY
	
CHKR	LDA	,X		* LOAD THIRD ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKZ		* NOPE, CHECK NEXT ROW
	LDA	#'R		* R KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$046A		* DRAW THE R KEY
	
CHKZ	LDA	,X		* LOAD THIRD ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK2		* NOPE, CHECK NEXT ROW
	LDA	#'Z		* Z KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04E6		* DRAW THE Z KEY
	
CHK2	LDA	,X		* LOAD THIRD ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHKCOL		* NOPE, CHECK NEXT ROW
	LDA	#'2		* 2 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0425		* DRAW THE 2 KEY
	
CHKCOL	LDA	,X		* LOAD THIRD ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKBRK		* NOPE, CHECK NEXT ROW
	LDA	#':		* : KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0437		* DRAW THE : KEY
	
CHKBRK	LDA	,X+		* LOAD THIRD ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKC		* NOPE, CHECK NEXT ROW
	LDA	#$03		* BREAK KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$043D		* DRAW THE BRK KEY

				* ROW 3
CHKC	LDA	,X		* LOAD FOURTH ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKK		* NOPE, CHECK NEXT ROW
	LDA	#'C		* C KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04EA		* DRAW THE C KEY

CHKK	LDA	,X		* LOAD FOURTH ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKS		* NOPE, CHECK NEXT ROW
	LDA	#'K		* K KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04B3		* DRAW THE K KEY
	
CHKS	LDA	,X		* LOAD FOURTH ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKUP		* NOPE, CHECK NEXT ROW
	LDA	#'S		* S KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04A7		* DRAW THE S KEY
	
CHKUP	LDA	,X		* LOAD FOURTH ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK3		* NOPE, CHECK NEXT ROW
	LDA	#'_		* UP KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$047C		* DRAW THE UP KEY
	
CHK3	LDA	,X		* LOAD FOURTH ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHKSEM		* NOPE, CHECK NEXT ROW
	LDA	#'3		* 3 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0427		* DRAW THE 3 KEY
	
CHKSEM	LDA	,X		* LOAD FOURTH ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKALT		* NOPE, CHECK NEXT ROW
	LDA	#';		* ; KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04B7		* DRAW THE ; KEY
	
CHKALT	LDA	,X+		* LOAD FOURTH ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKD		* NOPE, CHECK NEXT ROW
	LDA	#'_		* ALT KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0462		* DRAW THE ALT KEY

				* ROW 4
CHKD	LDA	,X		* LOAD FIFTH ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKL		* NOPE, CHECK NEXT ROW
	LDA	#'D		* D KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04A9		* DRAW THE D KEY

CHKL	LDA	,X		* LOAD FIFTH ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKT		* NOPE, CHECK NEXT ROW
	LDA	#'L		* L KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04B5		* DRAW THE L KEY
	
CHKT	LDA	,X		* LOAD FIFTH ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKDN		* NOPE, CHECK NEXT ROW
	LDA	#'T		* T KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$046C		* DRAW THE T KEY
	
CHKDN	LDA	,X		* LOAD FIFTH ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK4		* NOPE, CHECK NEXT ROW
	LDA	#'_		* DOWN KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04FC		* DRAW THE DOWN KEY
	
CHK4	LDA	,X		* LOAD FIFTH ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHKCOM		* NOPE, CHECK NEXT ROW
	LDA	#'4		* 4 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0429		* DRAW THE 4 KEY

CHKCOM	LDA	,X		* LOAD FIFTH ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKCTL		* NOPE, CHECK NEXT ROW
	LDA	#',		* , KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04F4		* DRAW THE , KEY
	
CHKCTL	LDA	,X+		* LOAD FIFTH ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKE		* NOPE, CHECK NEXT ROW
	LDA	#'_		* CONTROL KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04A3		* DRAW THE CTRL KEY

				* ROW 5
CHKE	LDA	,X		* LOAD SIXTH ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKM		* NOPE, CHECK NEXT ROW
	LDA	#'E		* E KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0468		* DRAW THE E KEY

CHKM	LDA	,X		* LOAD SIXTH ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKU		* NOPE, CHECK NEXT ROW
	LDA	#'M		* M KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04F2		* DRAW THE M KEY
	
CHKU	LDA	,X		* LOAD SIXTH ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKLFT		* NOPE, CHECK NEXT ROW
	LDA	#'U		* U KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0470		* DRAW THE U KEY
	
CHKLFT	LDA	,X		* LOAD SIXTH ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK5		* NOPE, CHECK NEXT ROW
	LDA	#'_		* LEFT KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04BB		* DRAW THE LEFT KEY
	
CHK5	LDA	,X		* LOAD SIXTH ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHKDSH		* NOPE, CHECK NEXT ROW
	LDA	#'5		* 5 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$042B		* DRAW THHE 5 KEY
	
CHKDSH	LDA	,X		* LOAD SIXTH ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKF1		* NOPE, CHECK NEXT ROW
	LDA	#'-		* - KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0439		* DRAW THE - KEY
	
CHKF1	LDA	,X+		* LOAD SIXTH ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKF		* NOPE, CHECK NEXT ROW
	LDA	#'_		* F1 KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$053B		* DRAW THE F1 KEY

				* ROW 6
CHKF	LDA	,X		* LOAD SEVENTH ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKN		* NOPE, CHECK NEXT ROW
	LDA	#'F		* F KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04AB		* DRAW THE F KEY

CHKN	LDA	,X		* LOAD SEVENTH ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKV		* NOPE, CHECK NEXT ROW
	LDA	#'N		* N KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04F0
	
CHKV	LDA	,X		* LOAD SEVENTH ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKRGT		* NOPE, CHECK NEXT ROW
	LDA	#'V		* V KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04EC
	
CHKRGT	LDA	,X		* LOAD SEVENTH ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK6		* NOPE, CHECK NEXT ROW
	LDA	#'_		* RIGHT KEY WAS DOWN FIXME NOT A SPACE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04BD
	
CHK6	LDA	,X		* LOAD SEVENTH ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHKPER		* NOPE, CHECK NEXT ROW
	LDA	#'6		* 6 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$042D		* DRAW THE 6 KEY
	
CHKPER	LDA	,X		* LOAD SEVENTH ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKF2		* NOPE, CHECK NEXT ROW
	LDA	#'.		* . KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04F6		* DRAW THE . KEY
	
CHKF2	LDA	,X+		* LOAD SEVENTH ROW DATA AND INCREMENT
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	CHKG		* NOPE, CHECK NEXT ROW
	LDA	#'_		* F2 KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$053D		* DRAW THE F2 KEY

				* ROW 7
CHKG	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%00000001	* TEST BIT 0
	CMPA	#%00000001	* WAS BIT 0 SET?
	BNE	CHKO		* NOPE, CHECK NEXT ROW
	LDA	#'G		* G KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04AD		* DRAW THE G KEY

CHKO	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%00000010	* TEST BIT 1
	CMPA	#%00000010	* WAS BIT 1 SET?
	BNE	CHKW		* NOPE, CHECK NEXT ROW
	LDA	#'O		* O KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0474		* DRAW THE O KEY
	
CHKW	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%00000100	* TEST BIT 2
	CMPA	#%00000100	* WAS BIT 2 SET?
	BNE	CHKSPC		* NOPE, CHECK NEXT ROW
	LDA	#'W		* W KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$0466		* DRAW THE W KEY
	
CHKSPC	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%00001000	* TEST BIT 3
	CMPA	#%00001000	* WAS BIT 3 SET?
	BNE	CHK7		* NOPE, CHECK NEXT ROW
	LDA	#'_		* SPACE KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$052F		* DRAW THE SPACE KEY
	
CHK7	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%00010000	* TEST BIT 4
	CMPA	#%00010000	* WAS BIT 4 SET?
	BNE	CHKSLS		* NOPE, CHECK NEXT ROW
	LDA	#'7		* 7 KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$042F		* DRAW THE 7 KEY
	
CHKSLS	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%00100000	* TEST BIT 5
	CMPA	#%00100000	* WAS BIT 5 SET?
	BNE	CHKSHF		* NOPE, CHECK NEXT ROW
	LDA	#'/		* / KEY WAS DOWN
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04F8		* DRAW THE / KEY
	
CHKSHF	LDA	,X		* LOAD EIGHTH ROW DATA FROM INKEYB
	ANDA	#%01000000	* TEST BIT 6
	CMPA	#%01000000	* WAS BIT 6 SET?
	BNE	DONE		* NOPE AND WE'RE DONE
	LDA	#'_		* SHIFT KEY WAS DOWN FIXME NOT UNDERSCORE
	STA	,Y+		* STORE KEY TO OUTKEY
	STA	$04E4		* DRAW LEFT SHIFT
	STA	$04FA		* DRAW RIGHT SHIFT

DONE	LBRA	NEWCLS		* DO IT ALL AGAIN
	END	NEWCLS		* END WHERE WE START

RTS

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies