So now I'm going to describe a bit of the workings of Mattel VS the PIC chip interface that I'm working on now, in a general way
The Mattel keyboard was being constantly scanned. It was an unusual system whereby I had to send out a signal to TURN ON a section of the keyboard (I think 8 keys at a time) and then READ back if one of those keys were PRESSED. Meanwhile , my effects and sequencer were interrupting every 1/240 of a second.
With the PIC chip, I'm using Serial on the MIDI side of the chip and parallel to send to the C64 UserPort. But this is tricky. If I don't clear the USART buffer on the PIC chip quick enough, it locks up. So now instead of updating 240 times a second I must POLL the UserPort 6000 or more times, per second, so that I can keep the buffer clear.So I have 2 more options left. I may add a hardware interrupt line or I may try (against my gut feeling) to insert the Userport read in the keyscan routine, (as it was setup for the Mattel)
Oh and the other level of complexity , is that I must also program the PIC chip, which has its' own unusual instruction set. That computer calls the accumulator the WORKING register. So movement is from and to W .....This is a cool 40 pin device only slightly larger than a SID chip....and here is an example of pic16f887 code
getmidi btfss PIR1,RCIF ; test for incoming data goto getmidi movf RCREG,W movwf RawMidi
movf RawMidi,W andlw 0xF0 ;filter sysex sublw 0xF0 bz start
movf RawMidi,W andlw 0xE0 ;filter pitch bend 1110 0000 sublw 0xE0 bz start
movf RawMidi,W andlw 0xD0 ;filter channel pressure aftertouch sublw 0xD0 bz start
movf RawMidi,W andlw 0xC0 ;filter program change sublw 0xC0 bz PrgmChng
movf RawMidi,W andlw 0xB0 ;filter control change sublw 0xB0 bz start
movf RawMidi,W andlw 0xA0 ;filter polyphonic aftertouch sublw 0xA0 bz start
YesMidi movf RawMidi,W andlw 0x90 sublw 0x90 bz GetNote movf RawMidi,W andlw 0x80 ;don't display status sublw 0x80 ;don't display status and disccard channel info bz NoteOff goto start
.and I have a 20mhz clock crystal on this board so this thing is 20X as fast as a C64