6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 2:35 pm

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Tue Nov 14, 2023 9:35 pm 
Offline

Joined: Tue Feb 07, 2023 12:27 pm
Posts: 19
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 15454 times ]
File comment: Signal CS active
Screenshot (26).png
Screenshot (26).png [ 68.16 KiB | Viewed 15454 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 23, 2023 5:17 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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.

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Last edited by and3rson on Thu Nov 23, 2023 10:45 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 23, 2023 10:44 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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!

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 23, 2023 11:06 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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 15192 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.

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 24, 2023 2:21 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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 15139 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

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 24, 2023 6:21 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 24, 2023 6:45 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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.

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 25, 2023 9:53 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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. :)

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 25, 2023 11:01 pm 
Offline

Joined: Tue Feb 07, 2023 12:27 pm
Posts: 19
Sorry for not replying for a long time, but I was very busy.
Here's my .jed file


Attachments:
testKEY.zip [713 Bytes]
Downloaded 150 times
Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 27, 2023 1:06 pm 
Offline

Joined: Tue Feb 07, 2023 12:27 pm
Posts: 19
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 14880 times ]
File comment: Source code + .jed
keyps2.zip [1.17 KiB]
Downloaded 139 times
Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 30, 2023 10:27 am 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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.

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 30, 2023 10:56 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1398
Location: Scotland
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

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 30, 2023 2:02 pm 
Offline
User avatar

Joined: Fri Feb 17, 2023 11:59 pm
Posts: 163
Location: Lviv, Ukraine
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!

_________________
/Andrew

deck65 - 6502 slab with screen and keyboard | ПК-88 - SBC based on KM1810VM88 (Ukrainian i8088 clone) | leo80 - simple Z80 SBC
nice65 - 6502 assembly linter | My parts, footprints & 3D models for KiCad/FreeCAD


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 30, 2023 6:06 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
I don’t recall seeing a schematic to go with this keyboard-interface GAL.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 01, 2023 9:51 pm 
Offline

Joined: Tue Feb 07, 2023 12:27 pm
Posts: 19
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 14651 times ]
File comment: Schematic for GAL22v10 programmed by
testKEY.jed file is located in the file (keyps2.zip).

PS2keyICdriver.pdf [16.33 KiB]
Downloaded 147 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: