Jim Rosemary (rosemary@eecis.udel.edu) This code was taken from a terminal emulator that I wrote a while back. The entire program was written in machine language and each revision was burned into an EPROM for the target system. Because of this, I did not try to make the code too 'pretty' - I just wanted to get it running. Read at your own risk. Also, be advised that not all keyboards work with my machine. The better of the two keyboards that I have tried works fine, whereas the cheap one will not work at all. It is advisable to obtain the keyboard docs from ftp.ee.ualberta.ca in the /pub/cookbook directory and read them. A 6522 is mapped at $fe30 PB0 goes to DATA PB1 goes to CLOCK Also, one of the control lines (CB1 or CB2, whichever corresponds to Interrupt enable $10) No interrupt code is provided here; only the actual transfer. $ff is used for passing data to/from the Get Byte and Write Byte routines. Reset has no parameters. Get Byte: lda $fe32 and #fc sta $fe32 jsr get_bit ldy #$09 loop: jsr get_bit ror $ff dey bne loop jsr get_bit lda $ff rts get_bit: lda #$02 wait_for_hi bit $fe30 bne wait_for_hi lda $fe30 pha lda #$02 wait_for_low bit $fe30 bne wait_for_low pla lsr rts Write Byte: lda $fe30 and #$fc sta $fe30 lda $fe32 ora #03 sta $fe32 ldx #$c0 wait: dex bne wait lda $fe32 // Write start bit and #$fd sta $fe32 lda #$02 wait_for_hi bit $fe30 // Wait for clock line beq wait_for_hi wait_for_lo bit $fe30 bne wait_for_lo ldx #$08 lda $fe32 ldy #$01 loop lsr $ff jsr write_bit // Write data bits dex bne loop tya lsr // Write parity jsr write_bit sec // Write stop bit jsr write_bit lda #$01 wait_lo bit $fe30 // Wait for handshake from kbd bne wait_lo rts write_bit lda $fe32 and #$fe bcs write_one ora #$01 iny write_one sta $fe32 lda #$02 wait_for_lo bit $fe30 bne wait_for_lo wait_for_hi bit $fe30 beq wait_for_hi rts Reset Keyboard: lda $fe30 and #$fc sta $fe30 lda $fe32 ora #$03 sta $fe32 ldx #$c0 wait dex bne wait lda $fe32 and #$fd sta $fe32 lda #$02 wait_for_hi bit $fe30 beq wait_for_hi wait_for_lo bit $fe30 bne wait_for_lo ldx #$08 lda $fe32 and #$fe sta $fe32 lda #$02 wait_for_hi1 bit $fe30 beq wait_for_hi1 wait_for_lo1 bit $fe30 bne wait_for_lo1 dex bne wait_for_hi1 lda #$02 wait_for_hi2 bit $fe30 beq wait_for_hi2 wait_for_lo2 bit $fe30 beq wait_for_lo2 lda #$01 wait_for_lo3 bit $fe30 bne wait_for_lo3 lda #$10 sta $fe3d rts