Jump to content
  • entries
    9
  • comments
    8
  • views
    748

6502 computer: The Keyboard


bluejay

386 views

Remember how I made that PS/2 keyboard interface? Yeah, I decided to get rid of it. Too complex on the software side. Now I have this 8x8 keyboard matrix. It has every key I thought I might need for the computer. 

keyboard.thumb.JPG.eedb85afddf03b947621ac35d87e7490.JPG

I know the drawing of the matrix is messy, but who cares. This is how the matrix works: the computer outputs a 1 to all 8 PA bits upon initialization. The other side of the switch matrix is ORed to CB1. If any key is pressed, CB1 will go high and trigger an interrupt. The computer then outputs a 1 to each of the PA bits, and reads from PB to figure out which column the pressed key is on. Then, the computer jumps to a bit of code that figures out exactly which key was pressed. Then it outputs a value into video RAM that the MC6847 can process. (at least, this is what the computer will do. I haven't written the entire keyboard routine yet because I don't know what kind of ASCII the MC6847 wants. Once I've figured that bit out I'll write the rest of the routine.)

 

Drawing the keyboard layout was surprisingly difficult. I wanted it to be easy to convert into an 8x8 matrix and still be easy to use. Also, I didn't want to deal with having a SHIFT key, so each symbol has its own dedicated key. I don't imagine this would be terribly easy to use, but whatever. You may have noticed the lack of a space bar; I didn't notice it until writing this blog entry. I'll get rid of the CLS key and replace it with a space bar later. The keyboard is 4 rows by 16 columns, which is easily split in half to fit into an 8x8 matrix. The character matrix is shown to the left of the switch matrix. It's gonna be a pain in the ass to decode that.

 

So, here's the entire BIOS code so far. It's obviously incomplete, and I'll continue to work on it in the future.

Spoiler

    .org $c000

 

VIDEO = $B000
JOYSTICK = $B001
DDRB1 = $B002
DDRA1 = $B003
PCR1 = $B00C
IFR1 = $B00D
IER1 = $B00E
KBIN = $B010
KBOUT = $B011
DDRB2 = $B012
DDRA2 = $B013
PCR2 = $B01C
IFR2 = $B01D
IER2 = $B01E

 

sysinit:

    JSR viainit
    JSR videoinit
    JSR kbinit
    JSR videotest

 

system:

    JSR kbinput

 

viainit:

    LDA #$FF
    STA DDRB1    ; Output to MC6847
    LDA #$00
    STA DDRA1    ; Input from joystick
    LDA #$00
    STA DDRB2    ; Input from keyboard
    LDA #$FF
    STA DDRA2    ; Output to keyboard
    RTS

 

videoinit:

    LDA #$00
    STA VIDEO    ; set all control bits of MC6847 to low
    LDA #$00
    STA $9FFF    ; set video counter to zero
    RTS

 

kbinit:
    
    LDA #%10010000
    STA IER2
    LDA #%00010000
    STA PCR2
    LDA #$FF
    STA KBOUT
    RTS

 

videotest:

    LDA #$13
    STA $8000    ; print T
    jsr videocount
    LDA #$04
    STA $8001    ; print E
    jsr videocount
    LDA #$12
    STA $8002    ; print S
    jsr videocount
    LDA #$13
    STA $8003    ; print T
    jsr videocount
    RTS

 

videocount:
    LDX $9FFF    ; load value of video counter to X
    INX        ; increment video counter
    STX $9FFF     ; store X to video counter
    RTS

 

kbinput:
    LDA #%00000001
    JSR keysub
    BNE kb1
    LDA #%00000010
    JSR keysub
    BNE kb2
    LDA #%00000100
    JSR keysub
    BNE kb3
    LDA #%00001000
    JSR keysub
    BNE kb4
    LDA #%00010000
    JSR keysub
    BNE kb5
    LDA #%00100000
    JSR keysub
    BNE kb6
    LDA #%01000000
    JSR keysub
    BNE kb7
    LDA #%10000000
    JSR keysub
    BNE kb8
    PLA
    RTI

 

kb1:
kb2:
kb3:
kb4:
kb5:
kb6:
kb7:
kb8:

 

keysub:

    STA KBOUT
    LDA KBIN
    RTS

 

joystick:

    PLA
    RTI

 

nmi:

    RTI

 

irq:

    PHA
    LDA IFR1
    ASL
    BCS joystick
    LDA IFR2
    ASL
    BCS kbinput
    PLA
    RTI

 

    .org $fffa
    .word nmi
    .word sysinit
    .word irq

 

That's it for this blog entry. Expect to see floppy controller circuitry in the next one, or perhaps even hard disk! See ya :) 

  • Like 1

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   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...