How does the Keyboard Matrix and PIA really work?

A place to discuss everything Dragon related that doesn't fall into the other categories.
Post Reply
jedie
Posts: 630
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

How does the Keyboard Matrix and PIA really work?

Post by jedie » Thu Jul 31, 2014 9:51 pm

One missing part in my Dragon Emulator is the Input via emulated PIA and the Keyboard Matrix...

"Inside the Dragon" described on Page 198-204 all the basics. I have read it carefully, but didn't understand it completely :oops: I missed a complete, detailed example.
I have study the XRoar sources, but didn't help at all.

I would like to start to implement only the Keyboard stuff in my Emulation. So, i think only the following parts must be implemented:
  • $ff00 -> PIA 0 A side Data register
  • $ff02 -> PIA 0 B side Data register
There is the Dragon keyboard matrix:

Code: Select all

        | PB0   PB1   PB2   PB3   PB4   PB5   PB6   PB7
    ----|----------------------------------------------
    PA0 |   0     1     2     3     4     5     6     7
    PA1 |   8     9     *     ;     ,     -     .     /
    PA2 |   @     A     B     C     D     E     F     G
    PA3 |   H     I     J     K     L     M     N     O
    PA4 |   P     Q     R     S     T     U     V     W
    PA5 |   X     Y     Z    Up  Down  Left Right Space
    PA6 | ENT   CLR   BRK   N/C   N/C   N/C   N/C  SHFT
matrix columns PB0-PB7 are:
  • configured as outputs
  • connected to: $ff02 -> PIA 0 B side Data register
matrix rows PA0-PA6 are:
  • configured as inputs
  • connected to: $ff00 -> PIA 0 A side Data register
OK, what happens now, if the keyboard scan routine is executed?

I my current emulation i can see this:

bbff writes $ff (11111111) to $ff02
bbcd reads from $ff00

I send $ff (11111111) back.

Now i see the "next row" scan loop:

bc0e writes $fe (11111110) to $ff02
bbcd reads from $ff00

bc23 writes $fd (11111101) to $ff02
bbcd reads from $ff00

bc23 writes $fb (11111011) to $ff02
bbcd reads from $ff00

...snip...

bc23 writes $bf (10111111) to $ff02
bbcd reads from $ff00

bc23 writes $7f (01111111) to $ff02
bbcd reads from $ff00


So the complete loop writes $ff02 this sequence:

Code: Select all

11111110
11111101
11111011
11110111
11101111
11011111
10111111
01111111

So my first questions is, what should be send back, if key XY is pressed on $ff00 ?
e.g.:
"U" pressed: col = 5 - row = 4 => 0xfb => 11111011 or inverted: 00000100
or
"A" pressed: col = 1 - row = 2 => 0xbf => 10111111 or inverted: 01000000
or
Shift + K is pressed?

I think if "U" is pressed and on column PB5 is a 1 then row PA4 is 0 and if PB5 is 0, then PA4 is 0
In other words: If PB0-PB7 are all 1, then PA0-PA6 are: 11101011

Of is it the opposite? Result a key press a pull up or a pull down?

EDIT: I have try to fake a keypress by clear one bit it the output. e.g. i send in the "next row" loop this back on $ff00:

Code: Select all

11111010
11111001
11111011
11110011
11101011
11011011
10111011
01111011
So i think this simulate the "U" key pressed. But it will be ignored, because the memor locations $0152-$0159 are not changed :(
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809

sixxie
Posts: 1097
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by sixxie » Fri Aug 01, 2014 6:47 am

If "U" is pressed, then when PB5 of PIA0 is LOW, PA4 of PIA0 will read LOW, else it will read HIGH.

Similarly if "A" is pressed then when PB1 is LOW, PA2 will read LOW, else it will read HIGH.

Each key is just a switch bridging a row and a column - if the column is low, then the row will be pulled low when the key is pressed (the A side of the PIA has an internal pull-up, so in input mode it will read as high if not connected to anything - no key pressed).

jedie
Posts: 630
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by jedie » Fri Aug 01, 2014 3:02 pm

Thank you very mutch. Think i now understand it right :D
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809

jedie
Posts: 630
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by jedie » Sat Aug 02, 2014 7:59 pm

Seems that i'm on the right way:

Code: Select all

	New test input char: 'P'
bbf4| read $ff00 ($ff02 is $00 00000000) send $2f 00101111 back (char: P)	
bbcd| read $ff00 ($ff02 is $ff 11111111) send $ff 11111111 back (char: P)	
bc08|      Set keyboard matrix state $0151 to $af 10101111			
bbcd| read $ff00 ($ff02 is $fe 11111110) send $ef 11101111 back (char: P)	
bc1b|      Set keyboard matrix state $0152 to $ef 11101111			
bbcd| read $ff00 ($ff02 is $fe 11111110) send $ef 11101111 back (char: P)	
bbdf| read $ff00 ($ff02 is $7f 01111111) send $3f 00111111 back (char: P)	
b544| *** Display write $60 ***u' '*** NORMAL at $04a0
bcd9| *** Display write $50 ***u'P'*** NORMAL at $04a0
bbf4| read $ff00 ($ff02 is $00 00000000) send $7f 01111111 back (char: None)	
bbcd| read $ff00 ($ff02 is $ff 11111111) send $ff 11111111 back (char: None)	
bc08|      Set keyboard matrix state $0151 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $fe 11111110) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0152 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $fe 11111110) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0153 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $fd 11111101) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0154 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $f7 11110111) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0155 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $ef 11101111) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0156 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $ef 11101111) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0157 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $bf 10111111) send $ff 11111111 back (char: None)	
bc1b|      Set keyboard matrix state $0158 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $7f 01111111) send $7f 01111111 back (char: None)	
bc1b|      Set keyboard matrix state $0159 to $ff 11111111			
	New test input char: 'R'
bbf4| read $ff00 ($ff02 is $00 00000000) send $2f 00101111 back (char: R)	
bbcd| read $ff00 ($ff02 is $ff 11111111) send $ff 11111111 back (char: R)	
bc08|      Set keyboard matrix state $0151 to $af 10101111			
bbcd| read $ff00 ($ff02 is $fe 11111110) send $ff 11111111 back (char: R)	
bc1b|      Set keyboard matrix state $0152 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $fd 11111101) send $ff 11111111 back (char: R)	
bc1b|      Set keyboard matrix state $0153 to $ff 11111111			
bbcd| read $ff00 ($ff02 is $fb 11111011) send $ef 11101111 back (char: R)	
bc1b|      Set keyboard matrix state $0154 to $ef 11101111			
bbcd| read $ff00 ($ff02 is $fb 11111011) send $ef 11101111 back (char: R)	
bbdf| read $ff00 ($ff02 is $fb 11111011) send $ef 11101111 back (char: R)	
b544| *** Display write $60 ***u' '*** NORMAL at $04a1
bcd9| *** Display write $52 ***u'R'*** NORMAL at $04a1
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809

jedie
Posts: 630
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by jedie » Sun Aug 03, 2014 2:53 pm

jedie wrote: There is the Dragon keyboard matrix:

Code: Select all

        | PB0   PB1   PB2   PB3   PB4   PB5   PB6   PB7
    ----|----------------------------------------------
    PA0 |   0     1     2     3     4     5     6     7
    PA1 |   8     9     *     ;     ,     -     .     /
    PA2 |   @     A     B     C     D     E     F     G
    PA3 |   H     I     J     K     L     M     N     O
    PA4 |   P     Q     R     S     T     U     V     W
    PA5 |   X     Y     Z    Up  Down  Left Right Space
    PA6 | ENT   CLR   BRK   N/C   N/C   N/C   N/C  SHFT
btw. this table (used in many documentarys) is wrong: The "*" in PB2/PA1 must be a ":", because ":" is not shifted and "*" is Shift+":" :D


EDIT: btw. i created the Wiki Page -> http://archive.worldofdragon.org/index. ... e=Keyboard
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809

jedie
Posts: 630
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by jedie » Wed Aug 06, 2014 11:03 am

Does anyone spontaneously knowns what's the different between the Dragon and the CoCo around the PIA/Keyboard and the related ROM code it?

I know only that the keyboard matrix is wired differently a little bit.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809

sixxie
Posts: 1097
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by sixxie » Wed Aug 06, 2014 1:24 pm

Hardware-wise, that's pretty much the only difference (details here: http://www.grempc.demon.co.uk/dragon/info/memmap.html). Later CoCos did use a variant of the PIA for the keyboard that had different electrical characteristics, but I couldn't tell you how it differed.

The ROM routine differs a little - it's generally accepted that it's a little easier to type on the CoCo for this reason.

And then obviously the CoCo 3 adds a few keys (F1, F2, Alt, Ctrl) in the the otherwise-unfilled matrix positions.

jedie
Posts: 630
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the Keyboard Matrix and PIA really work?

Post by jedie » Wed Aug 06, 2014 8:12 pm

The CoCo ROM routine works a little bit other than the Dragon ones...

They doesn't scan only the first row. It always scans all rows:

Code: Select all

a23a| read $ff00 ($ff02 is $fe 11111110) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $fd 11111101) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $fb 11111011) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $f7 11110111) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $ef 11101111) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $df 11011111) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $bf 10111111) send $ff 11111111 back	|$a23a: UNKNOWN
a23a| read $ff00 ($ff02 is $7f 01111111) send $ff 11111111 back	|$a23a: UNKNOWN
I see this with "Color Basic v1.3" and "Color Basic v1.2"

So i think there is not the problem with the "not detected keypress" if the first row is the same.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809

Post Reply