[Coco] PIA keyboard input?

James Dessart james at skwirl.ca
Sun Dec 7 22:28:00 EST 2003


On 7-Dec-03, at 10:02 PM, Robert Gault wrote:

> 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.

Which is what I had tried.  However, it seems the store instruction 
isn't triggering the PIA in MESS.  The ROL does, so I'm guessing it's 
something related to emulation or timing or something of the like... 
from what I've heard, it's probably not the emulation... here's the 
code that reads the row:

	clra
	std	-21,u	;movhi: R:d -> -21,u
	ldd	#1	;movhi: #1 -> R:d
	ldx	-21,u	;movhi: -21,u -> R:x
			;ashlhi: d by x
	leax	-1,x	;decr shift count
	bmi .+6
	aslb
	rola
	bra .-6	;loop
	comb		;comqi: R:b
	stb	-254	;movqi: R:b -> -254
	ldb	-18,u	;zero_extendqihi: -18,u -> R:d
	clra
	leax	d,u	;addhi: R:x = R:u + R:d
	ldb	-256	;movqi: -256 -> R:b

It's taken directly from gcc's output, but should be pretty much the 
following in C:

       *((unsigned char *)0xFF02) = ~(1<<i);
       columns[i] = *((unsigned char *)0xFF00);

where i is my loop variable, columns is the array of columns.  However, 
if I do the following:

       asm( "rol 0xFF02" );
       columns[i] = *((unsigned char *)0xFF00);

and a ROL instruction is generated, it works... kinda stumped.  I 
haven't had a chance to test it with a real CoCo, though, only MESS.

I've found gcc does seem to generate a lot of code... my little app to 
scan the keyboard and print out the matrix of rows and columns takes up 
about 2-3k.  If I rewrote it in assembly, I could probably halve or 
even quarter that... but in gcc's defence, it does a lot to make sure 
it keeps variables in check with registers... if I rewrote the 
function, I'd probably skip a lot of that.

James




More information about the Coco mailing list