6502.org
http://forum.6502.org/

Another PS/2 keyboard driver ic.
http://forum.6502.org/viewtopic.php?f=10&t=7833
Page 1 of 1

Author:  gregorio [ Tue Nov 14, 2023 9:35 pm ]
Post subject:  Another PS/2 keyboard driver ic.

Code:
Name     KEYBOARD IC ;
PartNo   00 ;
Date     11/11/2023 ;
Revision 01 ;
Designer Gregor ;
Company  ;
Assembly ;
Location ;
Device   p22v10;


PIN  1 = CLK;
PIN  2 = RESET;
PIN  3 = DATA;
PIN  4 = RW;
PIN 13 = CS;

PIN 14 = Q7;
PIN 15 = Q6;
PIN 16 = Q5;
PIN 17 = Q4;
PIN 18 = Q3;
PIN 19 = Q2;
PIN 20 = Q1;
PIN 21 = Q0;
PIN 22 = START;
PIN 23 = IRQ;

[Q0..Q7].oe = !CS&RW;
[Q0..Q7].ar = !RESET;
[Q0..Q7].sp = 'b'0;
START.ar = !RESET;
START.sp = 'b'0;
IRQ.ar = !RESET;
IRQ.sp = 'b'0;

!Q7.d = (!DATA&START)#(!Q7&!START);
!Q6.d = (!Q7&START)#(!Q6&!START);
!Q5.d = (!Q6&START)#(!Q5&!START);
!Q4.d = (!Q5&START)#(!Q4&!START);
!Q3.d = (!Q4&START)#(!Q3&!START);
!Q2.d = (!Q3&START)#(!Q2&!START);
!Q1.d = (!Q2&START)#(!Q1&!START);
!Q0.d = (!Q1&START)#(!Q0&!START);
!START.d= !Q0;

!IRQ.d=!START;

I want to connect a PS/2 keyboard. For now, I have designed a simple controller using the GAL22V10 system. For operation, you need to add an AND gate summing the RESET signals and a signal that clears the keyboard controller after reading the character.
After receiving the code of the pressed key, the system should trigger an IRQ interrupt.
The IC is designed to connect directly to the 6502 bus, so the output is tri-state controlled using CS and R/W signals.
I wonder if this arrangement will work?

Attachments:
File comment: Signal CS not active
Screenshot (23).png
Screenshot (23).png [ 72.58 KiB | Viewed 15511 times ]
File comment: Signal CS active
Screenshot (26).png
Screenshot (26).png [ 68.16 KiB | Viewed 15511 times ]

Author:  and3rson [ Thu Nov 23, 2023 5:17 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

This is awesome! I've got a bunch of 22V10 lying around, so I'm going to test this today.

I've converted your equations into GALasm format (since I find it more convenient than running WinCUPL on Linux):

Code:
GAL22V10
PS2

CLK  /RESET DATA  RW    NC    NC    NC    NC    NC    NC    NC    GND
/CS   Q7    Q6    Q5    Q4    Q3    Q2    Q1    Q0    START IRQ   VCC

AR = RESET
SP = GND

/Q7.R = /DATA * START + /Q7 * /START
/Q6.R = /Q7 * START + /Q6 * /START
/Q5.R = /Q6 * START + /Q5 * /START
/Q4.R = /Q5 * START + /Q4 * /START
/Q3.R = /Q4 * START + /Q3 * /START
/Q2.R = /Q3 * START + /Q2 * /START
/Q1.R = /Q2 * START + /Q1 * /START
/Q0.R = /Q1 * START + /Q0 * /START

Q0.E = CS * RW
Q1.E = CS * RW
Q2.E = CS * RW
Q3.E = CS * RW
Q4.E = CS * RW
Q5.E = CS * RW
Q6.E = CS * RW
Q7.E = CS * RW

/START.R = /Q0

/IRQ.R = /START

DESCRIPTION
Keyboard IC by Gregor
Converted from WinCUPL to GALasm by Andrew Dunai
Original thread: http://forum.6502.org/viewtopic.php?f=10&t=7833


Since you have a lot of spare inputs, why not add an `A0` input which, when high during /CS assertion, will clear the buffer? This way no external gate will be needed: buffer can then be read from even address and cleared by reading or writing its next odd address:

Code:
CLK  /RESET DATA  RW    A0    NC    NC    NC    NC    NC    NC    GND  ; <------- added A0
/CS   Q7    Q6    Q5    Q4    Q3    Q2    Q1    Q0    START IRQ   VCC

; ...

AR = RESET + A0 * CS  ; Reset if (/RESET is asserted) OR (A0 is high and chip is selected)

; ...


I'll try this later today and post if it works.

Author:  and3rson [ Thu Nov 23, 2023 10:44 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

Gregor - could you please post your .jed file? I want to verify if my galasm+minipro are working properly, since I seem to be running into some ATF weirdness here. Thanks in advance!

Author:  and3rson [ Thu Nov 23, 2023 11:06 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

Here's a working version:

Code:
GAL22V10
PS2

CLK  /RESET  DATA  RW    NC    NC    NC    NC    NC    NC     NC    GND
/CS  /Q7    /Q6   /Q5   /Q4   /Q3   /Q2   /Q1   /Q0   /START /IRQ   VCC

AR = RESET
SP = GND

/Q7.R = /DATA * START + /Q7 * /START
/Q6.R = /Q7 * START + /Q6 * /START
/Q5.R = /Q6 * START + /Q5 * /START
/Q4.R = /Q5 * START + /Q4 * /START
/Q3.R = /Q4 * START + /Q3 * /START
/Q2.R = /Q3 * START + /Q2 * /START
/Q1.R = /Q2 * START + /Q1 * /START
/Q0.R = /Q1 * START + /Q0 * /START

/Q0.E = CS * RW
/Q1.E = CS * RW
/Q2.E = CS * RW
/Q3.E = CS * RW
/Q4.E = CS * RW
/Q5.E = CS * RW
/Q6.E = CS * RW
/Q7.E = CS * RW

/START.R = /Q0

IRQ.R = /START

DESCRIPTION
Keyboard IC by Gregor
Converted from WinCUPL to GALasm by Andrew Dunai
Original thread: http://forum.6502.org/viewtopic.php?f=10&t=7833


For some unknown reason, if I invert D0..D7 in pin definitions, the entire thing breaks. I have no idea why this happens. Might be some ATF-specific weirdness. I've seen some threads on our forums mentioning some issues with TL866-II and ATF GALs...

Attachment:
galasm_ps2.png
galasm_ps2.png [ 38.8 KiB | Viewed 15249 times ]


The only downside with current equations is that the byte comes inverted.

I'd be happy if anyone could point why does inverting the outputs in pin definitions change the entire behavior of the GAL.

EDIT: I did some more testing and it might be a bug in GALasm. I've created an issue - https://github.com/daveho/GALasm/issues/16.

Author:  and3rson [ Fri Nov 24, 2023 2:21 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

It works. :)

Blasphemy alert: I've tested this on my i8088-based SBC.

Attachment:
File comment: BAT frame (0xAA) and 'A' make/break codes (0x1C, 0xF0+0x1C)
ps2working.jpg
ps2working.jpg [ 171.37 KiB | Viewed 15196 times ]


Note 1. I've changed the pinout a bit:

Code:


                                GAL22V10

                          -------\___/-------
                  PS2 CLK |  1           24 | VCC
                          |                 |
                 PS2 DATA |  2           23 | IRQ
                          |                 |
                       A0 |  3           22 |
                          |                 |
                      /RD |  4           21 | /D0
                          |                 |
                          |  5           20 | /D1
                          |                 |
                          |  6           19 | /D2
                          |                 |
                          |  7           18 | /D3
                          |                 |
                          |  8           17 | /D4
                          |                 |
                          |  9           16 | /D5
                          |                 |
                          | 10           15 | /D6
                          |                 |
                          | 11           14 | /D7
                          |                 |
                      GND | 12           13 | /CS
                          -------------------


Note 2. I've inverted IRQ, since x86 interrupt lines are active-high (I've been bit by that more times that I'm willing to admit.) You have to change IRQ to /IRQ in line 4 if you're using this in a system with proper active-low IRQ line, such as 6502. :D

Note 3. I eliminated the /RESET signal, so the registers needs to be reset by CPU by writing/reading A0=1. The reason is that we cannot have OR terms in asynchronous reset definition, so we cannot do `RESET + CS * A0`. I decided to drop /RESET whatsoever so that we can reset the controller ourselves.

Code:
GAL22V10
PS2

CLK   DATA  A0   /RD    NC    NC    NC    NC    NC    NC     NC    GND
/CS  /Q7   /Q6   /Q5   /Q4   /Q3   /Q2   /Q1   /Q0   /START  IRQ   VCC

AR = CS * A0  ; Reset by accessing the chip with A0 = 1
SP = GND

/Q7.R = /DATA * START + /Q7 * /START
/Q6.R =   /Q7 * START + /Q6 * /START
/Q5.R =   /Q6 * START + /Q5 * /START
/Q4.R =   /Q5 * START + /Q4 * /START
/Q3.R =   /Q4 * START + /Q3 * /START
/Q2.R =   /Q3 * START + /Q2 * /START
/Q1.R =   /Q2 * START + /Q1 * /START
/Q0.R =   /Q1 * START + /Q0 * /START

/Q0.E = CS * RD
/Q1.E = CS * RD
/Q2.E = CS * RD
/Q3.E = CS * RD
/Q4.E = CS * RD
/Q5.E = CS * RD
/Q6.E = CS * RD
/Q7.E = CS * RD

/START.R = /Q0

IRQ.R = /START

DESCRIPTION
Keyboard IC by Gregor
Converted from WinCUPL to GALasm by Andrew Dunai
Original thread: http://forum.6502.org/viewtopic.php?f=10&t=7833


GAL is initialized by reading/writing anything with A0=1:

Code:
init_kb:
        out     KB_PORT+1, al


Reading & resetting:
Code:
read_kb:
        in      al, KB_PORT     ; read byte
        xor     al, 0xFF        ; flip since it's inverted due to galasm bug
        out     KB_PORT, al     ; reset buffer

Author:  gfoot [ Fri Nov 24, 2023 6:21 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

You should be able to build the reset behaviour into the logic equations, e.g. maybe:

Code:
/Q7.R = /DATA * START * /RESET + /Q7 * /START * /RESET + RESET

This example would get set when RESET is asserted. Or remove the final term and it will get reset low instead. This will be a synchronous reset rather than an asynchronous reset, but so long as the clock is running during the reset that should be fine.

Edit: or do it the other way around - use RESET for AR, and add A0 into the logic equations for explicit synchronous resets.

Author:  and3rson [ Fri Nov 24, 2023 6:45 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

gfoot wrote:
You should be able to build the reset behaviour into the logic equations, e.g. maybe:

Code:
/Q7.R = /DATA * START * /RESET + /Q7 * /START * /RESET + RESET

This example would get set when RESET is asserted. Or remove the final term and it will get reset low instead. This will be a synchronous reset rather than an asynchronous reset, but so long as the clock is running during the reset that should be fine.

Edit: or do it the other way around - use RESET for AR, and add A0 into the logic equations for explicit synchronous resets.


Synchronous resets are a problem since the clock comes from PS/2. This means GAL can only reset itself when a new frame starts, at which point we have already lost the bit. I used AR same way as Gregor, but tied it to A0 * CS so that it can be reset by CPU.

EDIT: As for using RESET in addition to A0 - this is not possible since OR cannot be used in AR (asynchronous reset) definition - only AND... That's why I ditched RESET and used only A0 * CS.

Author:  and3rson [ Sat Nov 25, 2023 9:53 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

After spending a ridiculous amount of time debugging my GALasm equations, here's a final working GALasm version I finally came up with that does not flip the data byte anymore:

Code:
GAL22V10
PS2

CLK   DATA  A0   /RD    NC    NC    NC    NC    NC    NC     NC    GND
/CS   Q7    Q6    Q5    Q4    Q3    Q2    Q1    Q0    START  IRQ   VCC  ; Change IRQ to /IRQ (in this line only) for active-low interrupt signal (e. g. for 65xx)

AR = CS * A0
SP = GND

/Q7.R = /DATA * /START + Q7 * START
/Q6.R =    Q7 * /START + Q6 * START
/Q5.R =    Q6 * /START + Q5 * START
/Q4.R =    Q5 * /START + Q4 * START
/Q3.R =    Q4 * /START + Q3 * START
/Q2.R =    Q3 * /START + Q2 * START
/Q1.R =    Q2 * /START + Q1 * START
/Q0.R =    Q1 * /START + Q0 * START

Q0.E = CS * RD
Q1.E = CS * RD
Q2.E = CS * RD
Q3.E = CS * RD
Q4.E = CS * RD
Q5.E = CS * RD
Q6.E = CS * RD
Q7.E = CS * RD

/START.R = Q0

IRQ.R = START

DESCRIPTION
Keyboard IC by Gregor
Converted from WinCUPL to GALasm by Andrew Dunai
Original thread: http://forum.6502.org/viewtopic.php?f=10&t=7833


I had to resort to using an ancient tool called `JED2EQN` to reverse-engineer the fuses that GALasm generated. Turns out my understanding of how GALasm works was incorrect - notice how different the equations are from Gregor's WinCUPL version.

TL;DR: It seems that (in GALasm) when referring to a pin inside an equation, you are referring to an actual physical pin, not the assumed signal. For example:

Code:
/Q1.R = A * B
Q2.R = Q1

...will produce (when decompiled):
Code:
Q2 := /Q1
/Q1 := A * B


To me, this seems completely wrong. I would expect Q2 to be equal to Q1, but it's not. Please someone tell me I'm wrong - because I'm starting to lose my mind with all this stuff. :lol:

On the flipside, while doing this, I learned a lot about GAL's internals. :)

Author:  gregorio [ Sat Nov 25, 2023 11:01 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

Sorry for not replying for a long time, but I was very busy.
Here's my .jed file

Attachments:
testKEY.zip [713 Bytes]
Downloaded 152 times

Author:  gregorio [ Mon Nov 27, 2023 1:06 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

I made a correction so that now reseting is not necessary. :wink:
Code:
PIN  1 = CLK;
PIN  3 = DATA;
PIN  4 = RW;
PIN 13 = CS;

PIN 14 = Q7;
PIN 15 = Q6;
PIN 16 = Q5;
PIN 17 = Q4;
PIN 18 = Q3;
PIN 19 = Q2;
PIN 20 = Q1;
PIN 21 = Q0;
PIN 22 = NMI;
PIN 23 = TEMP;

[Q0..Q7].oe = !CS;
NMI.oe = !CS;
TEMP.oe = !CS;
[Q0..Q7].ar = NMI&!TEMP;
[Q0..Q7].sp = 'b'0;
NMI.ar = NMI&!TEMP;
NMI.sp = 'b'0;
TEMP.ar = NMI&!TEMP;
TEMP.sp = 'b'0;



!Q7.d = (!DATA&NMI)#(!Q7&!NMI);
!Q6.d = (!Q7&NMI)#(!Q6&!NMI);
!Q5.d = (!Q6&NMI)#(!Q5&!NMI);
!Q4.d = (!Q5&NMI)#(!Q4&!NMI);
!Q3.d = (!Q4&NMI)#(!Q3&!NMI);
!Q2.d = (!Q3&NMI)#(!Q2&!NMI);
!Q1.d = (!Q2&NMI)#(!Q1&!NMI);
!Q0.d = (!Q1&NMI)#(!Q0&!NMI);
!NMI.d= !Q0;

!TEMP.d=!NMI;


Attachments:
Screenshot (29).png
Screenshot (29).png [ 62.82 KiB | Viewed 14937 times ]
File comment: Source code + .jed
keyps2.zip [1.17 KiB]
Downloaded 143 times

Author:  and3rson [ Thu Nov 30, 2023 10:27 am ]
Post subject:  Re: Another PS/2 keyboard driver ic.

Great! Thanks for sharing!

Update on my GALasm issues: https://github.com/daveho/GALasm/issues/16 - turns out it was indeed a bug in GALasm, and my proposed solution fixes it.

Author:  drogon [ Thu Nov 30, 2023 10:56 am ]
Post subject:  Re: Another PS/2 keyboard driver ic.

and3rson wrote:
Great! Thanks for sharing!

Update on my GALasm issues: https://github.com/daveho/GALasm/issues/16 - turns out it was indeed a bug in GALasm, and my proposed solution fixes it.


Thanks for taking the time to find this. I'm having an issue with something similar myself (not a keyboard though!) and wonder if this is the issue - I'll apply your patch later today and see.

There is also another galasm spin-off that I wonder if you're aware about -

https://github.com/simon-frankau/galette

it's a re-write in rust and says he fixes some bugs in GALasm too..

I've not tried it though.

Cheers,

-Gordon

Author:  and3rson [ Thu Nov 30, 2023 2:02 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

drogon wrote:
Thanks for taking the time to find this. I'm having an issue with something similar myself (not a keyboard though!) and wonder if this is the issue - I'll apply your patch later today and see.


It's been merged, so you can just pull & build the latest version of GALasm from daveho's git repo.

drogon wrote:
There is also another galasm spin-off that I wonder if you're aware about -

https://github.com/simon-frankau/galette

it's a re-write in rust and says he fixes some bugs in GALasm too..

I've not tried it though.


Yeah, I've tested galette and it suffers from the same bug. I actually created the same ticket in their repo as well: https://github.com/simon-frankau/galette/issues/12

Once galette devs apply the fix, there will be equation parity between WinCUPL, GALasm, & galette. Currently only the first two are consistent. However, galette repo doesn't seem to get much attention over the past year, unfortunately...
Still, I'm happy that GALasm is now fixed: I can now get back to using a proper native Linux CLI assembler. No more WinCUPL shenanigans!

Author:  BigDumbDinosaur [ Thu Nov 30, 2023 6:06 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

I don’t recall seeing a schematic to go with this keyboard-interface GAL.

Author:  gregorio [ Fri Dec 01, 2023 9:51 pm ]
Post subject:  Re: Another PS/2 keyboard driver ic.

In fact, there was no schematic.
This is the simplest connection, the D0..D7 signals from the processor and the CE signal from the address decoder are enough to control it.
It is only possible to download data from the keyboard.
Lines D0..D7 can be connected directly to the processor bus or 8-bit input/output, e.g. 6520.
The NMI signal appears immediately when the data from the instruction is ready in the time between the 8th data bit and the parity bit. After this time, zeroing occurs and the controller waits for further data from the keyboard.

Attachments:
1701467582001-9a6d7da9-47f3-4932-ab6e-d0ad3d818bf5_1.jpg
1701467582001-9a6d7da9-47f3-4932-ab6e-d0ad3d818bf5_1.jpg [ 20.34 KiB | Viewed 14708 times ]
File comment: Schematic for GAL22v10 programmed by
testKEY.jed file is located in the file (keyps2.zip).

PS2keyICdriver.pdf [16.33 KiB]
Downloaded 150 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/