Jump to content
IGNORED

7800 keyboard adapter, VERY ALPHA


Flipper

Recommended Posts

Well, last week a discussion got started on the relative difficulty of making a PS/2 to 7800 keyboard adapter, using a modern microcontroller to do it. Somehow, I got the impression that a challenge was put forth, and so I decided to do something about it, rather than just think about it as I have for several months. This necessitated finishing the EEPROM adapter that stacks onto the BIOS ROM socket, and installing Win98 on my machine so that my POS EEPROM programmer would work. It gets allergic to XP and shuts down half way through the write.

 

Anyhow, I managed to get as far as getting the 7800 to sync with my Atmel microcontroller and then obtain 'keypresses' via the Atmel's RS232 port. Thus, I have my laptop hooked to the developer's board of the Atmel, feeding it characters that the 7800 polls just as it should from the 'real' keyboard.

 

In the pictures you can see my EEPROM stack board with my keyboard test program loaded on it, the atmel plugged into joystick port 2 as the real keyboard would have been, a couple of pictures of the board to show where I plugged into it, and a screenshot of my laptop with a test message typed in, and a screenshot of the 7800's display of that same message.

 

Although the communication between the laptop and the Atmel is RS232, the communication between the Atmel and the 7800 is PROBABLY the same as the original keyboard. All I have to go on, of course, is the programming spec that got scanned and posted around. So, it could be totally wrong.

 

My next attempt is going to be to hook a PS/2 keyboard to it instead of the RS232. That would make it slightly more authentic feeling. After that, I see no reason why SIO shouldn't be doable. The 'brains' of the SIO system were all on the 7800 anyway. The microcontroller in the keyboard does little to nothing to process each command.

 

Anyway, to prove I'm not full of it, pictures are at:

http://www.phin.com/gallery/atari7800

 

And the source zips for both the 7800 code and the Atmel are at:

http://www.phin.com/atari7800

 

The current code has many limitations, such as, no punctuation, capital letters only, no return key. These limitations are all very cosmetic. The actual act of passing triplets and bytes over the joystick port is working perfectly to spec as far as I can tell. Of course, without an actual keyboard or actual software, I can't be sure. Right now, one big thing that I can see is that I don't support the keyboard status command, that the real games would probably have used rather than transferring the full keypress byte each time. But again, that's all quite cosmetic. Sorting out my electrical issues was a problem. :P I'm NOT a hardware guy, I just do it when I have to so that I can write software.

Link to comment
Share on other sites

Note, I just rather found a problem in my design. Or, at least I think it's there. According to the spec, there is a breif (few microseconds) period as the port changes direction from keyboard->7800 to 7800->keyboard where both devices are trying to output on the data lines. This is basically a 'wired-or' condition which would try and pull huge amounts of power from the I/O ports on each chip. Adding some lowish resistors to the lines should help. The original keyboard use 470ohm resistors, and in addition to their use in the low pass filter, they will prevent the 'wired-or' case from burning excessive amounts of current.

 

It hasn't caused me a problem during my testing, and I've REALLY electrically abused these chips with silly mistakes, so my guess is, they can take the overcurrent for the few microseconds it exists. But, the problem is still there.

 

BTW, since A2600 asked, my TV is a Panasonic 34" hi-def Tau. The old style with no HDCP port, so if they ever turn on HD copy protection, I can't watch. :P

Link to comment
Share on other sites

You need to get with Curt and see if you can get a copy of the original keyboard programs to see how compatible they are with your adapter. Full compatiblity with the original protos would be great. :)

 

Mitch

Link to comment
Share on other sites

You need to get with Curt and see if you can get a copy of the original keyboard programs to see how compatible they are with your adapter. Full compatiblity with the original protos would be great. :)

 

Mitch

844480[/snapback]

 

Full compatability is the only thing I would consider. :) Yes, at some point I need to have a real keyboard and or real software to test with. Having implemented more than one protocol 'by spec' at work, I know all to well the differences between specs and reality!

Link to comment
Share on other sites

  • 2 weeks later...

An update finally!

 

Sorry about that, I intended to have this done a week ago. But between moving out for 3 days for a fumigation, spending an evening driving 2 hours each way to see Cats, family emergency, and other volunteer commitments....ya.

 

Anyhow, the PS/2 keyboard now works. I actually had this going a week ago, just was waiting on some time to write the code to convert from PS/2 sequences to 7800 keycodes. I think I've found something I am happy with.

 

The keyboard still types in all Caps, but you can use some punctuation now. I need to type out the full data tables (shift, control, shift+control) so that you can get all the keys on the 7800 keyboard.

 

Key repeat is controlled by the 7800, just as it should be. The typematic stuff from the PS/2 keyboard is ignored.

 

I still haven't implemented the keyboard status command, which ticks me off. It's pretty simple to do, so I'll do it in a couple of days here if work doesn't snow me under. I have to get serious there till the weekend.

 

Anyway, if I can clean up this data table issue, and the keyboard status command, one of the three features of the original keyboard will be DONE. That would leave SIO, and casette.

 

And I've still not gotten to test with original software/hardware.

 

Anyhow, new code is up here:

http://www.phin.com/atari7800

Link to comment
Share on other sites

Cool stuff! Too bad my programmer doesn't handle an atmega32. :(

By the way, does this support AT style keyboards as well?

 

Mitch

853440[/snapback]

 

Yes, actually, I guess I should have mentioned that. It will do AT or PS/2. No XT support, tho. Not that I think most people will care. :)

 

And, I really doubt my code requires a Mega32. It SHOULD rebuild for any atmega with at least IRQ1. I barely use ANY SRAM at this point. You might have to change pin numbers if you use a chip with less than 32 I/Os

Edited by Flipper
Link to comment
Share on other sites

This is something I was thinking about to post in my blog, the work of some fans are amazing. Keep up the good work, if you ever start to sell these thing you'll have many besides me planning to buy one. I tried asking here once what does an original one Atari made costs. My only answer was that there are only 6 prototypes and their extremely rare. You could not buy one for love or money..so keep up the good work and please keep us informed as your progress goes.

Link to comment
Share on other sites

From the look of the schematics, it seems like the main cost in building the real thing would be the keyboard and shell. It really doesn't seem to use many other parts, aside from the microcontroller, the SIO port, a 4051 demux, an LM339 comparator, assorted capacitors and resistors, and a power supply.

 

And then of course you need a boot cartridge to make it work in computer mode. Preferably one with 48K or 64K of RAM inside.

 

But seriously, I don't think there's any real need for the SIO and cassette interfaces. Using a generic PS/2 keyboard removes the cost of making a custom keyboard, though you will get a lot of "dead keys" which don't map to anything, and some shift keys will be "wrong" because of Atari-specific keyboard layout choices. It also means you get this tiny little unit which can easily tap off of the 7800 for power.

 

It's just too bad you can't get the 7800 itself to interface directly to an AT keyboard. But it looks like the keyboard gets to transmit whenever it wants to, so the CPU has to be listening all the time. And the bit rate is as high as twice the horizontal sync rate, so you couldn't reliably read the keyboard with video DMA turned on.

 

I suppose it could be possible to use a couple of chips to FIFO buffer the AT keyboard data, but at that point you might as well use a microcontroller. Also, the Atari protocol lets you read 3 bits at a time, which will take up less of the 7800 CPU time than reading 1 bit at a time. On the other hand, you won't have to deal with that complicated Atari protocol.

 

I even thought about making a keyboard interface (to an unencoded matrix) with a 4017 and a 4021 (I have a dozen tubes of 4017 chips that I got at a thrift store, and the 4021 is what NES controllers use), but that would mean that the CPU would have to scan every key individually, and a 7800 with lots of video DMA really can't afford that much time just to scan a damn keyboard.

 

So this is pretty much the right way to go. But if there's no need for the SIO/cassette interface, or to run actual prototype code, I think a simpler protocol (possibly even a 4-bit protocol instead of 3 bits) sending standard AT key codes would be better. Being able to send data TO the keyboard would be a plus, but the AT keyboard interface is a bit more complicated if you're doing bi-directional.

 

Hmmm... I just thought of something... if you can somehow grab the AT interface like you're about to send a command, then release it when the 7800 is ready to clock in some bits during vertical retrace, maybe it might be possible to use a direct AT-to-joystick port connection. Primitive flow control. The downside is that it will still take 5-10 scan lines to read a key.

Link to comment
Share on other sites

Hmmm... I just thought of something... if you can somehow grab the AT interface like you're about to send a command, then release it when the 7800 is ready to clock in some bits during vertical retrace, maybe it might be possible to use a direct AT-to-joystick port connection.  Primitive flow control.  The downside is that it will still take 5-10 scan lines to read a key.

854068[/snapback]

 

Actually, that WOULD work if you can poll the joyport fast enough to read 10-16kbps. :) I'm mostly doing my project as a learning exercise, and because I love bit-banging funky protocols. And some FSK demod for the casette would be fun too. Of course, to be able to offer board layouts and code and everything, maybe even a kit, that would be great too.

 

But, here's what you would do to wire an AT or PS/2 keyboard directly to a joyport. Use an open collector inverter. It's a 74xx part, just don't remember the number. Wire two inputs to D0 and D1 on the joyport. Wire the outputs to D2 and D3, as well as keyboard clock and data. Connect power and ground.

 

Now, to send data to the keyboard, send it INVERTED on pins D0 and D1. To read it, read it NON-INVERTED on pins D2 and D3. People who have done fast loaders on the C64 will know EXACTLY what I am talking about here.

 

When the DMA starts on the 7800, write a 1 to the clock inverter. This will pull DOWN the clock line and stop the keyboard from transmitting data. Write a 0 at the conclusion of DMA to allow the keyboard to send bytes again.

 

The keyboard generates clock, thus if you cannot keep up with 16kbps, some keyboards will be iffy, and some will work.

Link to comment
Share on other sites

The problem isn't keeping up with the data rate, the problem is that the data rate is slow enough (at 1-2 clocks per scan line) that it will tie up the CPU for way too much of the precious vertical retrace interval. You really can't do anything else while waiting for the keyboard to clock out the rest of the data. And the slower the keyboard transmits data, the worse the problem.

 

And you can't do it outside of vertical retrace, because DMA can easily halt the CPU for half a scan line or more. You really need something to assist the 6502. It would be funny if it were easier to implement a direct keyboard interface to an NES just because it was free from the DMA penalty.

Link to comment
Share on other sites

The problem isn't keeping up with the data rate, the problem is that the data rate is slow enough (at 1-2 clocks per scan line) that it will tie up the CPU for way too much of the precious vertical retrace interval.  You really can't do anything else while waiting for the keyboard to clock out the rest of the data.  And the slower the keyboard transmits data, the worse the problem.

854412[/snapback]

 

Ya, I didn't even think of that. Unless you could predict when the keyboard would send data and do your processing.

 

I guess that's exactly why the official keyboard has a clock in each direction. Any time one side or the other gets busy, it just stops responding to the clock, and the protocol automatically halts.

Link to comment
Share on other sites

I honestly think an easier project would be to make a computer add-on to the 5200, use the front joystick ports to interpret keyboard input, its got an SIO port on it already and if someone is willing to take Atari Basic and change it to the memory map of the 5200, then it should'nt be nearly as difficult a task to manage.

 

 

 

Curt

 

 

 

The problem isn't keeping up with the data rate, the problem is that the data rate is slow enough (at 1-2 clocks per scan line) that it will tie up the CPU for way too much of the precious vertical retrace interval.  You really can't do anything else while waiting for the keyboard to clock out the rest of the data.  And the slower the keyboard transmits data, the worse the problem.

854412[/snapback]

 

Ya, I didn't even think of that. Unless you could predict when the keyboard would send data and do your processing.

 

I guess that's exactly why the official keyboard has a clock in each direction. Any time one side or the other gets busy, it just stops responding to the clock, and the protocol automatically halts.

854872[/snapback]

Link to comment
Share on other sites

Yes, great idea. It even has the XEGS keyboard that plugs into the 5200 joystick although I'm sure you'd have to modify the keyboards electronics to get it to work. The SIO port in the back is the same as the 5200 cartridge port so all you'd have to do is wire and SIO cord to the end of a cart port.

 

Then rewrite the software and you're all set. Now that we can have 512K carts on the 5200 will help also.

 

Allan

 

 

I honestly think an easier project would be to make a computer add-on to the 5200, use the front joystick ports to interpret keyboard input, its got an SIO port on it already and if someone is willing to take Atari Basic and change it to the memory map of the 5200, then it should'nt be nearly as difficult a task to manage.

 

 

 

Curt

 

 

 

The problem isn't keeping up with the data rate, the problem is that the data rate is slow enough (at 1-2 clocks per scan line) that it will tie up the CPU for way too much of the precious vertical retrace interval.  You really can't do anything else while waiting for the keyboard to clock out the rest of the data.  And the slower the keyboard transmits data, the worse the problem.

854412[/snapback]

 

Ya, I didn't even think of that. Unless you could predict when the keyboard would send data and do your processing.

 

I guess that's exactly why the official keyboard has a clock in each direction. Any time one side or the other gets busy, it just stops responding to the clock, and the protocol automatically halts.

854872[/snapback]

855983[/snapback]

Link to comment
Share on other sites

Although I'd still like to see Curt design and sell a 7800 keyboard using an 600XL keyboard and case! All those nice 7800 apps are just sitting there collecting dust. :(

 

Than we can start a new magazine called Maria (in the tradition of Antic magazine) and type in user submitted programs like in the old days! :)

 

Allan

Link to comment
Share on other sites

  • 3 years later...
  • 8 months later...

I see the atmel code but... and the schematics diagram?

 

I've got the links the to the 7800 side code that I wrote, as well as the Atmel code.

 

As to schematics, something blew out my 7800. I don't know if it was bad static handling or if it was a bad cabling job, but it was REALLY hacky. Just some soldered wires between at Atmel dev board and the 6532 pins.

 

If you're not a programmer and hardware guy, you're not going to be able to use what I got done before I fried my machine.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...