TI-H: Most don't deserve this
[Prev][Next][Index][Thread]
TI-H: Most don't deserve this
Most of you don't deserve this (there are tons of people who do). I have
been working on TI projects and you guys have been blaming me of, let me
say, blowing sh__? Yes. Well, I'm tired of it. I have limited time to
spend on projects. I've had this kbd driver for the 92 working for about 4
months, I just had no ambition to release it. Instead of selling chips,
I'm just giving out the source. This should be enough to keep ryan quiet
and all of the other doubtfull people.
Instructions: You have to do a little to make this work. I have not
included the TI communication routines because I didn't want to. If you
make this right, it will plug into the link port and with a tiny bit of
code, directly controll the TI92 without any drivers...
Grant
;*****************************************************
;* *
;* 101 Key, IBM Keyboard Decoder for guess what. *
;* *
;* Copyright 1998 - Grant Stockly *
;* 25th January 1998 *
;* *
;* Includes ALTDEC & CTRLHEX Routines *
;* *
;*****************************************************
.include "chipdef.inc"
.equ nreset =4
.equ datain =0
.equ clkin =1
.equ dataout =2
.equ clkout =3
.equ TxD =1 ;Transmit pin is PD1
; Equates for LED Byte
.equ pscrlck =7 ; If true, Scroll Lock Pressed
.equ pnumlck =6 ; If true, Num Lock Pressed
.equ caplock =2 ; If true, Caps Lock is On (Active)
.equ numlock =1 ; If true, Num Lock is On (Active)
.equ scrlock =0 ; If true, Num Lock is On (Active)
; Equates for Status Flag, Byte
.equ rctrl =7 ; If true, Right Ctrl Pressed
.equ lctrl =6 ; If true, Left Ctrl Pressed
.equ ralt =5 ; If true, Right Alt Pressed
.equ lalt =4 ; If true, Left Alt Pressed
.equ caploc =2 ; If true, Caps Lock Pressed
.equ rshift =1 ; If true, Right Shift Key Pressed
.equ lshift =0 ; If true, Left Shift Key Pressed
.def byte =r18 ; Used to hold byte, during Trans & Rec
.def status =r19 ; Status Flags
.def LED =r20 ; LED Flags
.def delay =r21 ; delay
.def count =r22 ; counter
.def bitcnt =R23 ;bit counter
.def temp =R24 ;temporary storage register
.def Txbyte =R25 ;Data to be transmitted
.def RXbyte =R26 ;Received data
Start:
cbi PORTB, dataout
cbi PORTB, clkout
rjmp rstflag ;No Attempt to Reset Keyboard made
;as keyboard would still be
in POST
;or BAT Tests, if power
applied at
;the same time than the HC705.
;*****************************************************
;* *
;* reset - Sends a Reset Command to the Keyboard. *
;* Not a very good effort to reset keyboard, *
;* as it doesn't check for ACK or BAT *
;* Completion Code. I.e. Reset may not of *
;* even Worked! *
;* *
;*****************************************************
reset:
ldi byte, $FF ;Reset Keyboard
rcall transmit
;*****************************************************
;* *
;* rstflag - Resets Status and LED Flags. Used when *
;* a successful Bat Completion code is *
;* sent to sync keyboard's LED's to 705's *
;* status register *
;* *
;*****************************************************
rstflag:
clr status
clr LED
;*****************************************************
;* *
;* main - Main Keyboard Decoding Routine. Once key *
;* been decoded, program should return here *
;* *
;*****************************************************
main:
rcall Receive ;Get's a Single Byte from the Keyboard.
cpi byte, $F0 ;A Key has been Released
brne main1
rjmp release
main1:
cpi byte, $AA ;Successful Completion of BAT
brne main2
rjmp rstflag
main2:
cpi byte, $E0 ;Extended Keys
brne main3
rjmp extend
main3:
cpi byte, $12 ;Left Shift Key Pressed
brne main4
sbr status, lshift
main4:
cpi byte, $59 ;Right Shift Key Pressed
brne main5
sbr status, rshift
main5:
cpi byte, $14 ;Left Ctrl
brne main6
sbr status, lctrl
main6:
cpi byte, $11 ;Left Alt
brne main7
sbr status, lalt
main7:
cpi byte, $58 ;Caps Lock Pressed
brne main8
sbrs status, caploc
rcall caps
sbr status, caploc
main8:
cpi byte, $7E ;Scroll Lock Pressed
brne main9
sbrs status, pscrlck
rcall scrl
sbr status, pscrlck
main9:
cpi byte, $77 ;Num Lock Pressed
brne main10
sbrs status, pnumlck
rcall nums
sbr status, pnumlck
main10:
cpi byte, $8F ;Last Value in Look-Up Table
brlo main11
rjmp main ;Out of Bounds
main11:
sbrc LED, caplock
rcall caps_on
sbrc status, rshift
rcall shifton
sbrc status, lshift
rcall shifton
cancel:
rcall noshift ;Load Lower Case Values
rjmp main12
caps_on:
sbrc status, rshift ;If ShiftLock & Shift, Cancel
rjmp cancel
sbrc status, lshift
rjmp cancel
shifton:
rcall shift ;Load Upper Case Values
main12:
andi status, $30 ;Either Alt Key Pressed
breq main13
main13:
andi status, $C0 ;Either CTRL Key Pressed
breq main14
main14:
rcall putchar ;Send to RS232
return:
rjmp main
;*****************************************************
;* *
;* caps - Toggle Status of Caps lock and Echo to *
;* Keyboard *
;* *
;*****************************************************
caps:
sbr status, caploc ; Set caploc flag to prevent
routine being
; called again
ori LED, $04 ; Toggle Shift Lock Flag
rjmp LEDshow
;*****************************************************
;* *
;* nums - Toggle Status of Nums lock and Echo to *
;* Keyboard *
;* *
;*****************************************************
nums:
sbr status, pnumlck
ori LED, $02
rjmp LEDshow
;*****************************************************
;* *
;* scrl - Toggle Status of Scroll lock and Echo to *
;* Keyboard *
;* *
;*****************************************************
scrl:
sbr status, pscrlck
ori LED, $01
rjmp LEDshow
;*****************************************************
;* *
;* extend - An Extended Key has been Pressed *
;* *
;*****************************************************
extend:
rcall Receive ;Get Next byte
cpi byte, $F0 ;An Extended Key Has been Released
brne extend1
rjmp rel_ext
extend1:
cpi byte, $11 ;Right Alt Pressed
brne extend2
sbr status, ralt
extend2:
cpi byte, $14 ;Right Ctrl Pressed
brne extend3
sbr status, rctrl
extend3:
cpi byte, $71 ;Delete
brne extend4
andi status, $C0 ;Either Alt Key Pressed?
breq extend4
andi status, $30 ;Either Ctrl Key Pressed?
breq extend4
sbi PORTB, nreset
ldi delay, $FF
rcall delay
cbi PORTB, nreset
rjmp reset
extend4:
cpi byte, $5A ;Enter Key on Num Keypad
brne extend5
ldi byte, $0D
rcall putchar
extend5:
cpi byte, $4A ; '/' Key on Num Keypad
brne extend6
ldi byte, $2F
rcall putchar
extend6:
rjmp main ;Return to main
;*****************************************************
;* *
;* release - A Key has been Released *
;* *
;*****************************************************
release:
rcall Receive ;Release - Next Byte Garbage in many cases
releas3:
cpi byte, $12 ;Left Shift Key Released
brne releas4
cbr status, lshift
releas4:
cpi byte, $59 ;Right Shift Key Released
brne releas5
sbr status, rshift
releas5:
cpi byte, $14 ;Left Ctrl Released
brne releas6
cbr status, lctrl
releas6:
cpi byte, $11 ;Left Alt Released
brne releas7
cbr status, lalt
releas7:
cpi byte, $58 ;Caps Lock Released
brne releas8
cbr status, caploc
releas8:
cpi byte, $7E ;Scroll Lock Released
brne releas9
cbr status, pscrlck
releas9:
cbr byte, $77 ;Num Lock Released
brne relea10
cbr status, pnumlck
relea10:
rjmp main ;Return to Main
;*****************************************************
;* *
;* rel_ext - An Extended Key has been Released *
;* *
;*****************************************************
rel_ext:
rcall Receive ;Get Next byte
rel_ex2:
rel_ex3:
rjmp main ;Return to main
;*****************************************************
;* *
;* LEDshow - Copies the 3 LSB of the LED register to *
;* keyboard for the keyboards Status LED's *
;* E.g. Num Lock, Caps Lock, Scroll Lock *
;* Also makes their status present on *
;* PORTA *
;* *
;*****************************************************
LEDshow:
andi LED, $07
out PORTA, LED ;Made Status Avalible at PORTA
ldi byte, $ED
rcall transmit
rcall Receive
andi LED, $07
mov byte, LED
rcall transmit
rjmp main
;*****************************************************
;* *
;* Transmit - Send Data stored at Byte to the *
;* Keyboard. Result *
;* *
;*****************************************************
transmit:
cbi PORTB, clkout
cbi PORTB, dataout ;Make sure outputs are low.
ldi count, $08
sbi PORTB, clkout ;Set Clock Low
ldi delay, $13 ;Delay 64uS
rcall delay
sbi PORTB, dataout ;Set Data Low
cbi PORTB, clkout ;Release Clock Line
rcall highlow
loop:
ror byte
brcs mark
space:
sbi PORTB, dataout ; Clear Bit
rjmp next
mark:
cbi PORTB, dataout ; Clear Bit
inc byte ; Parity Calculation
next:
rcall highlow ; Wait for high to low transition
dec count
brne loop
andi byte, $01
brne clr_par
set_par:
cbi PORTB, dataout
rjmp tr_ackn
clr_par:
sbi PORTB, dataout
tr_ackn:
rcall highlow
cbi PORTB, dataout ;Release Data Line
rcall highlow
sbic PORTB, datain
rcall error ;Check for Ack
amy:
sbis PORTB, clkin
rjmp amy ;Wait for idle line
sbi PORTB, clkout ;Prevent Keyboard from sending data
;(Clear to Send)
ret
error:
ldi byte, $FF ;Reset
rcall transmit
ret
delay:
dec count ; Delay = 6[A] + 6
brne delay
ret
;*****************************************************
;* *
;* Receive - Get a Byte from the Keyboard. Result *
;* stored in byte. *
;* *
;*****************************************************
Receive:
ldi count, 08 ;Number of Bits
cbi PORTB, clkout ;Clear to Send
gantt:
sbic PORTB, clkin
rjmp gantt ;wait for idle Clock
sbic PORTB, datain
rjmp Receive ;False Start Bit, Restart
Recdata:
ror byte
rcall highlow ;Wait for high to low Transision
sbic PORTB, datain
rcall Recset
sbr byte, 7
rjmp Recnext
Recset:
sbr byte, 7
inc byte
Recnext:
dec count
brne Recdata ;Loop until 8 bits been received
rcall highlow
andi byte, $01
breq r_error
rjmp highlow
sbis PORTB, datain
rcall r_error ;Stop Bit Detection
sbi PORTB, clkout ;Prevent Keyboard from sending data
;(Clear to Send)
ret
r_error:
ldi byte, $FE ;Resend
rcall Transmit
rjmp Receive ;Try again
;*****************************************************
;* *
;* highlow - Waits for next High to Low Transistion *
;* on the Clock Line *
;* *
;*****************************************************
highlow:
sbis PORTB, clkin
rjmp highlow ;Loop until Clk High
yma:
sbic PORTB, clkin
rjmp yma ;Loop until Clk Low
ret