add useful macros
This commit is contained in:
parent
b778b4dcd1
commit
23e5e3cd35
@ -29,9 +29,9 @@ INCLUDE_PS2_KEYBOARD = 1
|
|||||||
.include "system.h65"
|
.include "system.h65"
|
||||||
|
|
||||||
.scope ps2kb
|
.scope ps2kb
|
||||||
Import ps2kb,init,begin_receive,send_command,scancode,status,scancode_handler
|
Import ps2kb, init, begin_receive, scancode, status, scancode_handler
|
||||||
Import ps2kb, _receive_irq_shift_reg_handler, _receive_irq_timer_handler, _send_byte, _send_irq_shift_reg_handler, _send_irq_timer_handler,
|
Import ps2kb, _receive_irq_shift_reg_handler, _receive_irq_timer_handler, _send_byte, _send_irq_shift_reg_handler, _send_irq_timer_handler,
|
||||||
Import ps2kb, send_last_bits, send_cmd, send_data, key_read, prev_status
|
Import ps2kb, send_command, send_cmd, send_data, cmd_response, response_length, FMT_CMD_FAIL
|
||||||
|
|
||||||
VIA = IO1
|
VIA = IO1
|
||||||
; Enough time must pass for 3 bits to be shifted in.
|
; Enough time must pass for 3 bits to be shifted in.
|
||||||
@ -41,22 +41,152 @@ TIMER_RECV = 230 ; 230 ms (@1MHz)
|
|||||||
; After that, the interrupt must have happened because the keyboard will pull data low.
|
; After that, the interrupt must have happened because the keyboard will pull data low.
|
||||||
; At that point, the SR needs to be set to input again
|
; At that point, the SR needs to be set to input again
|
||||||
TIMER_SEND = 230 ; 180 ms (@1MHz)
|
TIMER_SEND = 230 ; 180 ms (@1MHz)
|
||||||
; use RA4 to pull the clock low
|
|
||||||
PULL_REG = IO::RANH
|
PULL_REG = IO::RANH
|
||||||
PULL_DDR = IO::DDRA
|
PULL_DDR = IO::DDRA
|
||||||
|
; use RA4 to pull the clock low
|
||||||
PULL_MASK_CLK = %00010000
|
PULL_MASK_CLK = %00010000
|
||||||
; PULL_MASK_DAT = %00001000
|
|
||||||
NO_DATA = $ff ; indicates that no data byte should be send
|
; using ff because 0 is a possible data byte (set led)
|
||||||
|
NO_DATA = $ff ; indicates that no data byte should be send
|
||||||
|
NO_RESPONSE = $ff ; indicates a command did not receive a response (yet)
|
||||||
|
ACK = $fa ; successful transmission
|
||||||
|
RESEND = $fe ; unsuccessful transmission
|
||||||
|
|
||||||
|
|
||||||
.enum STATUS
|
.enum STATUS
|
||||||
RECEIVE_KEYS = %10000000
|
RECEIVE_KEYS = %10000000 ; keyboard sends scancodes
|
||||||
RECEIVE_ANSWER = %01000000
|
RECEIVE_ANSWER = %01000000 ; keyboard replies to a command
|
||||||
SEND_CMD = %00100000
|
SEND_CMD = %00100000 ; host sends/sent the command byte
|
||||||
SEND_DATA = %00010000
|
SEND_DATA = %00010000 ; host sends/sent the data byte
|
||||||
SEND_CMD_WAIT = %00001000
|
SEND_RECV = %00001000 ; keyboard sends additional data byte
|
||||||
|
SEND = SEND_CMD | SEND_DATA | SEND_RECV ; host is sending something, only used for checking status
|
||||||
NONE = %00000000
|
NONE = %00000000
|
||||||
.endenum
|
.endenum
|
||||||
|
|
||||||
|
.enum TYPEMATIC
|
||||||
|
REPEAT_MASK = %00011111 ; 00000 = 30Hz, ..., 11111 = 2Hz
|
||||||
|
DELAY250 = %00000000
|
||||||
|
DELAY500 = %00100000
|
||||||
|
DELAY750 = %01000000
|
||||||
|
DELAY1000 = %01100000
|
||||||
|
.endenum
|
||||||
.endscope
|
.endscope
|
||||||
|
|
||||||
|
; see https://wiki.osdev.org/PS/2_Keyboard
|
||||||
|
.macro ps2kb_CmdEcho
|
||||||
|
lda #$ee
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
ldy #0
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdSetLeds mask
|
||||||
|
lda #$ed
|
||||||
|
.ifnblank mask
|
||||||
|
ldx #mask
|
||||||
|
.endif
|
||||||
|
ldy #0
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdGetScancodeSet
|
||||||
|
lda #$f0
|
||||||
|
ldx #0
|
||||||
|
ldy #1
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdSetScancodeSet set
|
||||||
|
.assert set = 1 .or set = 2 .or set = 3, warning, "ps2kb_CmdSetScancodeSet: invalid scancode set"
|
||||||
|
lda #$f0
|
||||||
|
ldx #set
|
||||||
|
ldy #0
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdIdentify
|
||||||
|
lda #$f2
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
ldy #2
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdTypematicSettings settings
|
||||||
|
lda #$f3
|
||||||
|
ldx #settings
|
||||||
|
ldy #0
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdEnable
|
||||||
|
lda #$f4
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
ldy #0
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdDisable
|
||||||
|
lda #$f5
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
ldy #0
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdSetTypematic scancode
|
||||||
|
ldy #0
|
||||||
|
.ifblank scancode
|
||||||
|
lda #$f7
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
.else
|
||||||
|
lda #$fb
|
||||||
|
ldx #scancode
|
||||||
|
.endif
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdSetMakeRelease scancode
|
||||||
|
ldy #0
|
||||||
|
.ifblank scancode
|
||||||
|
lda #$f8
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
.else
|
||||||
|
lda #$fc
|
||||||
|
ldx #scancode
|
||||||
|
.endif
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdSetMake scancode
|
||||||
|
ldy #0
|
||||||
|
.ifblank scancode
|
||||||
|
lda #$f9
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
.else
|
||||||
|
lda #$fd
|
||||||
|
ldx #scancode
|
||||||
|
.endif
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_CmdSelfTest
|
||||||
|
lda #$ff
|
||||||
|
ldx #ps2kb::NO_DATA
|
||||||
|
ldy #1
|
||||||
|
jsr ps2kb::send_command
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_WaitFinishCmd
|
||||||
|
:
|
||||||
|
wai
|
||||||
|
lda ps2kb::status
|
||||||
|
and #ps2kb::STATUS::SEND
|
||||||
|
bne :-
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.macro ps2kb_PrintCmdFailed
|
||||||
|
Printf ps2kb::FMT_CMD_FAIL,ps2kb::send_cmd,ps2kb::send_data,ps2kb::cmd_response,ps2kb::cmd_response+1,ps2kb::cmd_response+2
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
|
||||||
.endif ; guard
|
.endif ; guard
|
||||||
|
Loading…
Reference in New Issue
Block a user