[Coco] PIA keyboard input?

jdaggett at gate.net jdaggett at gate.net
Sun Dec 7 23:12:00 EST 2003


James 

the ROL instruction brings in thestate of the carry bit to bit zero. To do the walking 
zero through the column register of the PIA you must first set the carry bit and 
preserve the carry bit state between any other steps and and restore it before the 
rotate. Otherwise you can rotate in an unexpectant zero. That way a simple BCS 
instruction can be used to test if the carry is zero. That way you have rotated 8 
times and are done. 

The cary bit is set by"
ORCC #$01.

the ccr can be stored in a ram location or on the stack. One could even use the DP 
register as a temp. Just don't do any direct instructins though. 
james

On 7 Dec 2003 at 22:26, James Dessart wrote:

> 
> 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
> 
> 
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco





More information about the Coco mailing list