[Coco] PIA keyboard input?

jdaggett at gate.net jdaggett at gate.net
Sun Dec 7 22:52:00 EST 2003


how about this


	orcc	#$01	set carry bit
	lda	#$fe 	load col mask
	ldy	#$ff00	point to row PIA
	ldx	#$ff02	point ot col PIA
loop	pshs	cc	save a copy of the ccr on the stack
	sta	,x
	jsr 	cmpre	test for push
	puls	cc	get the ccr from the stack
	rola		rotate one bit
	bcs	loop	branch if carry set


james

This sets the carry bit so that rotates will always shift in a one until 8 rotates. The 
the carry is zero and we are done. The key is to push and pull the CCR on and off 
the stack to preserve the carry bit state before the rotate. figure even with a good 
lengthy compare that one will still need a delay loop for debounce. Figure the whole 
scan can be done in about 1mS to 2mS. Should aslo scan all columns to insure two 
keys down at the same time. shift U as an example. 

james


Routine take 196 machine cycles plus what ever the compare routine takes. Figure 
On 7 Dec 2003 at 22:02, Robert Gault wrote:

> James Dessart wrote:
> > 
> > On 7-Dec-03, at 5:09 PM, Robert Gault wrote:
> > 
> >> Whether you ROL/ROR or ST depends on whether you want to detect one
> >> specific key or any possible key press combination. Clearly if you
> >> want any key you must test all possible column/row combinations.
> > 
> > 
> > Well, what I wanted to do was to store a value into the PIA
> > register, through a loop.  I'm doing this in C, and to do a ROL you
> > need to write inline assembly.  So I was trying to store a
> > constantly changing value into the register through a C assignment. 
> > That didn't work for me, for some reason... I never got key
> > presses... I'll retry it, though, maybe I was doing it wrong the
> > first time and didn't realize it.
> > 
> > James
> > 
> > 
> That's easy to do if you use the correct algorithm. What is equivalent
> to rolling a bit? A power of 2 change is the same thing. So, if you
> want a zero bit, the loop would be (in Basic)
>   for i =1 to 8
>    poke pia, 255-2^(i-1)
>   next i
> The above is going to give you 255-1=254=%11111110,
> 255-2=253=%11111101, 255-4=251=%11111011, 255-8=247=%11110111, etc.
> 
> 
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco





More information about the Coco mailing list