Operating System

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Post by 8bitwizard » Tue Mar 27, 2007 5:39 pm

A PS/2 keyboard interface would be nice, but the main problem is that the keyboard can send data at ANY time and is in control of the data clocking. (Curse you, IBM!) So you need a co-processor like a PIC.

The Z80 would be good as a co-processor for watching the keyboard (if you don't care about PCM audio), but apparently the controller ports are not accessible except through the 68K bank area. That makes it a bit more limiting (more bank switches when you want to read sound data from the 68K), but not impossible.

Of course you could always make an RS-232 interface with a MAX232 chip and talk at up to 4800 baud. I wouldn't be surprised if the "official" keyboard was going to work that way.

evildragon
Very interested
Posts: 326
Joined: Mon Mar 12, 2007 1:53 am
Contact:

Post by evildragon » Tue Mar 27, 2007 6:07 pm

i once made a PS/2 to Genesis circuit, but I have long lost those schematics (HD failure on my domain controller)... I believe I used a PIC for it, as it was easy to make...

If you guys want a simpler route, how about an old Macintosh "ADB" keyboard? Those run on a serial bus I believe...

commodorejohn
Very interested
Posts: 70
Joined: Tue Mar 06, 2007 6:30 pm

Post by commodorejohn » Tue Mar 27, 2007 7:06 pm

They're easy to get, too, at least in the States - just drop by any public school and ask if you can take some old Mac stuff off their hands. They'll thank you for it.

evildragon
Very interested
Posts: 326
Joined: Mon Mar 12, 2007 1:53 am
Contact:

Post by evildragon » Tue Mar 27, 2007 7:13 pm

commodorejohn wrote:They're easy to get, too, at least in the States - just drop by any public school and ask if you can take some old Mac stuff off their hands. They'll thank you for it.
heh, i loooove my Macs... :P

however, I think a flaw in ADB that may cause problems with interfacing it on the genesis, is that ADB devices can be daisy chained...

TascoDLX
Very interested
Posts: 262
Joined: Tue Feb 06, 2007 8:18 pm

Post by TascoDLX » Tue Mar 27, 2007 7:45 pm

8bitwizard wrote:The Z80 would be good as a co-processor for watching the keyboard (if you don't care about PCM audio), but apparently the controller ports are not accessible except through the 68K bank area. That makes it a bit more limiting (more bank switches when you want to read sound data from the 68K), but not impossible.
It would be much better to trigger a level 2 interrupt on a key event. That way the 68K can handle the input so it doesn't screw with the sound.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Mar 27, 2007 8:17 pm

TascoDLX wrote:
8bitwizard wrote:The Z80 would be good as a co-processor for watching the keyboard (if you don't care about PCM audio), but apparently the controller ports are not accessible except through the 68K bank area. That makes it a bit more limiting (more bank switches when you want to read sound data from the 68K), but not impossible.
It would be much better to trigger a level 2 interrupt on a key event. That way the 68K can handle the input so it doesn't screw with the sound.
smart guy :)

8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Post by 8bitwizard » Wed Mar 28, 2007 12:01 am

TascoDLX wrote:
8bitwizard wrote:The Z80 would be good as a co-processor for watching the keyboard (if you don't care about PCM audio), but apparently the controller ports are not accessible except through the 68K bank area. That makes it a bit more limiting (more bank switches when you want to read sound data from the 68K), but not impossible.
It would be much better to trigger a level 2 interrupt on a key event. That way the 68K can handle the input so it doesn't screw with the sound.
You really need to look at how the PS/2 interface works. All an interrupt will get you is the start of a PS/2 keyboard byte.

The problem is that the Z80 has to sit there and watch the input because (as I said), all timing comes from the PS/2 keyboard itself (a horrible design decision from before 1982), which means that the Z80 has to count cycles. One byte (IIRC) takes tens of scan lines. That's why you normally need some sort of controller in between. The advantage to my way is that all you need is an adapter cable and no electronics, at the cost of losing PCM sound. (PSG/FM sound can operate on a vsync interrupt)

evildragon
Very interested
Posts: 326
Joined: Mon Mar 12, 2007 1:53 am
Contact:

Post by evildragon » Wed Mar 28, 2007 12:09 am

8bitwizard wrote:
TascoDLX wrote:
8bitwizard wrote:The Z80 would be good as a co-processor for watching the keyboard (if you don't care about PCM audio), but apparently the controller ports are not accessible except through the 68K bank area. That makes it a bit more limiting (more bank switches when you want to read sound data from the 68K), but not impossible.
It would be much better to trigger a level 2 interrupt on a key event. That way the 68K can handle the input so it doesn't screw with the sound.
You really need to look at how the PS/2 interface works. All an interrupt will get you is the start of a PS/2 keyboard byte.

The problem is that the Z80 has to sit there and watch the input because (as I said), all timing comes from the PS/2 keyboard itself (a horrible design decision from before 1982), which means that the Z80 has to count cycles. One byte (IIRC) takes tens of scan lines. That's why you normally need some sort of controller in between. The advantage to my way is that all you need is an adapter cable and no electronics, at the cost of losing PCM sound. (PSG/FM sound can operate on a vsync interrupt)
ironically, PS/2 keyboards came out in 87.. I have the first computer that had the PS/2 port, right on my desk..

However, the command set we should look for, for this keyboard, is the AT keyboard (it's what the PS/2 boards use.) also, what would be required is a way to emulate how the i8042 works..

TascoDLX
Very interested
Posts: 262
Joined: Tue Feb 06, 2007 8:18 pm

Post by TascoDLX » Wed Mar 28, 2007 4:45 am

8bitwizard wrote:
TascoDLX wrote:
8bitwizard wrote:The Z80 would be good as a co-processor for watching the keyboard (if you don't care about PCM audio), but apparently the controller ports are not accessible except through the 68K bank area. That makes it a bit more limiting (more bank switches when you want to read sound data from the 68K), but not impossible.
It would be much better to trigger a level 2 interrupt on a key event. That way the 68K can handle the input so it doesn't screw with the sound.
You really need to look at how the PS/2 interface works. All an interrupt will get you is the start of a PS/2 keyboard byte.

The problem is that the Z80 has to sit there and watch the input because (as I said), all timing comes from the PS/2 keyboard itself (a horrible design decision from before 1982), which means that the Z80 has to count cycles. One byte (IIRC) takes tens of scan lines. That's why you normally need some sort of controller in between. The advantage to my way is that all you need is an adapter cable and no electronics, at the cost of losing PCM sound. (PSG/FM sound can operate on a vsync interrupt)
So, you want to use the Z80 as a microcontroller emulator? Seems like a waste but I've seen bigger atrocities.

commodorejohn
Very interested
Posts: 70
Joined: Tue Mar 06, 2007 6:30 pm

Post by commodorejohn » Wed Mar 28, 2007 12:36 pm

Actually, it sounds like he's proposing using a microcontroller and having the Z80 watch it.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Wed Mar 28, 2007 3:06 pm

I guess, external HW is better idea, since you have to make a small adaptor, so why not build something into it.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Post by 8bitwizard » Wed Mar 28, 2007 4:27 pm

evildragon wrote:The ironically, PS/2 keyboards came out in 87.. I have the first computer that had the PS/2 port, right on my desk..
The PS/2 port is a re-wiring (and speed upgrade?) of the old AT keyboard interface... which is a protocol upgrade from the old XT interface... which is where the "keyboard in control" behavior started.
However, the command set we should look for, for this keyboard, is the AT keyboard (it's what the PS/2 boards use.) also, what would be required is a way to emulate how the i8042 works..
You don't need to emulate the whole 8042, just the bit-banger serial input.

I just took my own advice and checked the specs of the PS/2 keyboard interface. While the baud rate is 10000-16000 baud, there is a separate clock line, which removes the work of timing the bits during decoding. It might even be possible to interleave checking the port with doing PCM audio, except for the one tiny problem of having to use the 32K bank area to read both the controller ports AND the PCM data, along with Sega's silly one-bit-at-a-time bank switching control. (Why they couldn't have simply mapped two latches at 0x6000/0x6001 makes no sense to me.)

As for using interrupts, the Z80 only gets the vsync interrupt. But I think you can tie the clock line to TH and use the 68K EXT interrupt. This may even be better than using the Z80!

evildragon
Very interested
Posts: 326
Joined: Mon Mar 12, 2007 1:53 am
Contact:

Post by evildragon » Wed Mar 28, 2007 5:22 pm

8bitwizard wrote:
evildragon wrote:The ironically, PS/2 keyboards came out in 87.. I have the first computer that had the PS/2 port, right on my desk..
The PS/2 port is a re-wiring (and speed upgrade?) of the old AT keyboard interface... which is a protocol upgrade from the old XT interface... which is where the "keyboard in control" behavior started.
However, the command set we should look for, for this keyboard, is the AT keyboard (it's what the PS/2 boards use.) also, what would be required is a way to emulate how the i8042 works..
You don't need to emulate the whole 8042, just the bit-banger serial input.

I just took my own advice and checked the specs of the PS/2 keyboard interface. While the baud rate is 10000-16000 baud, there is a separate clock line, which removes the work of timing the bits during decoding. It might even be possible to interleave checking the port with doing PCM audio, except for the one tiny problem of having to use the 32K bank area to read both the controller ports AND the PCM data, along with Sega's silly one-bit-at-a-time bank switching control. (Why they couldn't have simply mapped two latches at 0x6000/0x6001 makes no sense to me.)

As for using interrupts, the Z80 only gets the vsync interrupt. But I think you can tie the clock line to TH and use the 68K EXT interrupt. This may even be better than using the Z80!
I'm not talking about the XT interface.. The AT interface and XT interface look the same, but are not... The AT keyboard interface is the SAME as the PS/2 interface. They just use a different DIN connector... You can easily connect an old AT keyboard to a brand new PC with a PS/2 port, and you can also connect a brand new PS/2 keyboard to an old computer with an AT port.. I've done it, they even sell adaptors for that, because the communications link between them is the same..

Post Reply