PS/2 -> PCjr keyboard conversion

Hardware questions and modifications

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed May 14, 2014 12:40 pm

Well, I did take a look at the existing AT->XT code yesterday, but I honestly don't think I'd be able to figure out what it's doing well enough to modify it for use with the PCjr in any shorter amount of time than it would take me to do the whole thing from scratch anyway. It also seems to be written for a different assembler than the one I'm using. I think someone more experienced than I am with PIC chips should probably be doing that, and I should probably continue my from-scratch approach in an effort to really learn how to use the chips.

I did restart my own coding last night as well. I was definitely trying to bite off more than I could chew by writing so much of the code before I had any of the hardware hooked up. Now I have it successfully recording scancodes one at a time and sending them out to the serial port, but I've discovered my approach at buffering the scancodes (which I want to do so I don't miss anything when keys send multiple bytes) was nonfunctional, and I'll have to spend some time figuring out why.
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed May 14, 2014 5:35 pm

I'm definitely learning a lot trying to do this, haha. First the UART turned out to be set up in the wrong order, so it was spitting out garbage every time I wrote to it. Then my method of recording the scan codes turned out to be bad (I was getting all sorts of results, some close, some not, depending on how I changed my code around) and I had to change do a different method of doing the bit shift into my scan code storage location. Now I'm getting perfect reads every time and I'm seeing the correct matching scan codes for each key I press showing up on the serial terminal. Next I'll try to implement my delay routine again, I guess (which, implemented without a buffer, should just show me the last code for each key pressed on the terminal), then I'll go after the buffer.

EDIT: Tried for a while this evening to get the delay function working. I don't think I'm gonna be able to get my head around that one; there's just too much going on with the interrupts. Instead, I think the 'state machine' approach might work better (for example, it receives an E0, an E1, or an F0 and it waits for another byte before transmitting anything).
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby Trixter » Thu May 15, 2014 12:36 pm

Consider me another guy hiding in the wings quietly cheering you on :-)
You're all insane and trying to steal my magic bag!
Trixter
 
Posts: 522
Joined: Mon Sep 01, 2008 12:00 am
Location: Illinois, USA

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Fri May 16, 2014 11:09 am

Okay, it's now properly interpreting what I would consider the two difficult multi-byte keys, Pause and Print Screen. For every other key, it simply ignores E0 or E1 and for F0 it SETs the MSB of the next translated code before sending it. Next up is building the rest of the translation table, and after that trying to get it to output in the PCjr's format.

Now, unfortunately, my code is getting ridiculously hairy at this point, and I've had a few random crashes where it stops giving me any output until I reset it, but I can't figure out how to intentionally reproduce the crashes, so I have no idea what's going on to cause them. The first couple of times, it happened when I hit an arrow key after hitting another extended key, but after the reset each time it handled the same situation without a problem.
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Fri May 16, 2014 1:53 pm

Okay, no random crashes today, so far, so I don't know what that was all about yesterday. I just finished writing the translation table, and it has become clear that the E0 Extended keys need some special handling. Specifically, most of the E0 keys exist in the little block of they keyboard that contains the arrow keys. As the program sits now, it cannot distinguish between these keys and the equivalent keys in the number pad. This means, with Num Lock on, you'd be getting numbers out of the arrow keys, Home, Page Up, etc. instead of their labeled functions. So I think what I need to do next is implement Num Lock handling (and this would be a great time to figure out how to turn the LEDs on or off) so that, if an E0 scan code is received and Num Lock is on, Num Lock gets turned off until after the next scan code has been sent. This one seems a little tricky, to me, and I'll likely have to spend some time thinking about it before I can implement it.
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jharre » Sat May 17, 2014 10:25 am

It looks like you're making progress. I'm over here on the sidelines cheering! 8-)
jharre
 
Posts: 64
Joined: Tue Jun 18, 2013 9:48 pm
Location: Placitas, New Mexico

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Sat May 17, 2014 11:19 am

Alright, basically at this point the code is getting too complex for me to make any progress with adding things in, so I'm gonna spend some time re-writing some or all of it to make the routines I'm using operate more consistently (and I'm hoping it'll end up in them being smaller and more efficient, as well). I'm also noticing that with PICs, mixing interrupts and polling doesn't turn out well (I tried to use polling in the middle of an interrupt routine on the same line that's controlling the interrupt, which I tried to disable after entering the interrupt routine, to service the write back to the keyboard for turning on the LEDs and it ended up screwing with my RAM contents somehow, which made the entire routine useless).

EDIT: Okay, I significantly shortened the interrupt handler by offloading a lot of the work for keeping track of where we are during a read sequence to the scancode reading subroutine. There is also now a register for flagging which operation I want the interrupt handler to jump to (though right now, it's either 'read' or 'write', so I may be better off using the main flags register I had already set up).
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Sun May 18, 2014 12:28 am

I'm not making any progress with turning on the keyboard LEDs. At the moment, in fact, I've settled for trying to get the keyboard to respond to an 'Echo' request, but I'm not having any luck there, either. I've somehow been able to get the keyboard to reset from time to time, but it's never when I actually send it a reset code. I've determined that some of the odd behavior is due to a lack of context saving on certain jumps between subroutines (pages are getting flipped and banks are being switched out and they aren't getting set back the way they were on return). After attempting to add in the context saving, the routines are operating properly, at least as far as what my debugging outputs over the UART are showing, but the keyboard refuses to respond to what I'm sending (I don't know if I'm starting early and stopping short or what). I might have to try tapping into the circuit so I can look at the waveforms again, 'cause I think I really need to see what's happening on a bit-by-bit level before I can figure out what's going wrong.
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby Hargle » Mon May 19, 2014 7:21 am

As mentioned earlier, my logic analyzer is here for you if you need to get some serious signal tracking done.
https://www.saleae.com/logic
I'll happily send it to you for whatever time you need.

We may also be at the point where it makes sense for a few other people to build up one of these devices to help you with code and debugging. If you can post your setup/schematics/BOM I could go build one too.
Hargle
 
Posts: 119
Joined: Wed Apr 27, 2011 3:53 pm

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Mon May 19, 2014 9:37 am

Hargle wrote:As mentioned earlier, my logic analyzer is here for you if you need to get some serious signal tracking done.
https://www.saleae.com/logic
I'll happily send it to you for whatever time you need.

We may also be at the point where it makes sense for a few other people to build up one of these devices to help you with code and debugging. If you can post your setup/schematics/BOM I could go build one too.


Well, I'd rather have the code in a more readable state before I have anyone else test it out (so far the routine to read scancodes is the only one that I think would make sense to someone else looking at it). And I have a couple more ideas I'd like to implement before I hand it over to other people, haha. That logic analyzer would probably be pretty helpful at this point, though.

The circuit (so far, anyway) isn't that bad to construct. It's based on the first two schematics listed here (except without the OSC pins hooked up, as I'm using the internal oscillator): http://picpgm.picprojects.net/hardware. ... PROGRAMMER

The chip is a PIC16F88, simply because I already had one and I didn't have to spend any money to get this setup working. The PS/2 clock line is connected to RB0 and the data line is connected to RB1. Then I have a MAX232 circuit set up with the TX line coming from RB5 and the RX line going to RB2 for debugging purposes. I haven't tried implementing communication to the PCjr yet since I'd rather finish figuring out communication with the keyboard itself first.
jmetal88
 
Posts: 794
Joined: Sun Jul 25, 2010 10:22 am

PreviousNext

Return to PCjr Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

cron