
;this routine is used for selecting the keys for left/right flipper
;it reads the keyboard, and when one specific key is pressed, it rts's
;column-data is in temp, rowdata in temp2

huntforkeypress
	;check all columns
huntloop
	lda #$fe
	sta temp

	lda temp       ;set column to check
huntloop2
	sta $dc00
	lda $dc01           ;read key
	eor #$ff
	bne checkwhichkey   ;branch if a key is pressed
	lda temp            ;check next column  (last column was #$7f!,restart when $7f)
	bpl huntloop
	sec                 ;rol in a bit 1
	rol                 ;and get value for next column
	sta temp
	bne huntloop2
checkwhichkey
	sta temp2

	lda #$01            ;make sure only 1 key is pressed, only 1,2,4,8,10,20,40,80 are valid
validloop
	cmp temp2
	beq validkey
	asl
	bne validloop
	jmp huntloop        ;>1 key was pressed!
validkey
	rts

;------------------------------------------------------------------------------------------

