vnIIc/client/mouse.inc

281 lines
8.0 KiB
PHP
Raw Normal View History

2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
;;;
;;; Mouse
;;;
;;;-------------------------------------------------------------------
2018-11-03 03:51:23 +00:00
;; .error "Mouse support not fully implemented"
2018-10-29 02:49:17 +00:00
.proc Mouse
;;;--------------------------------------------------
2018-11-03 03:51:23 +00:00
;;; Mouse Screen Holes
2018-10-29 02:49:17 +00:00
;;;--------------------------------------------------
2018-11-03 03:51:23 +00:00
;;; For ReadMouse and PosMouse
MOUSE_X_LSB := $0478 ; + slot Low byte of X coordinate
MOUSE_Y_LSB := $04F8 ; + slot Low byte of Y coordinate
MOUSE_X_MSB := $0578 ; + slot High byte of X coordinate
MOUSE_Y_MSB := $05F8 ; + slot High byte of Y coordinate
MOUSE_RSV1 := $0678 ; + slot Reserved
MOUSE_RSV2 := $06F8 ; + slot Reserved
MOUSE_STATUS := $0778 ; + slot Status byte
;; 7 Button down
;; 6 Button was down on last read and still down
;; 5 Movement since last read
;; 4 Reserved
;; 3 Interrupt from VBlInt
;; 2 Interrupt from button
;; 1 Interrupt from movement
;; 0 Reserved
2018-10-29 05:23:33 +00:00
MOUSE_MODE := $07F8 ; + slot Mode byte
2018-11-03 03:51:23 +00:00
;; 7-4 Reserved
;; 3 VBlInt active
;; 2 VBL interrupt on button
;; 1 VBL interrupt on movement
;; 0 Mouse active
;;; Scratch area for ClampMouse:
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
MOUSE_CMIN_LSB := $0478 ; Low byte of clamping minimum
MOUSE_CMAX_LSB := $04F8 ; Low byte of clamping maximum
MOUSE_CMIN_MSB := $0578 ; High byte of clamping minimum
MOUSE_CMAX_MSB := $05F8 ; High byte of clamping maximum
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
;;;--------------------------------------------------
;;; Mouse Constants
;;;--------------------------------------------------
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
MOUSE_CLAMP_X := 0 ; Value for A when setting X clamp with ClampMouse
MOUSE_CLAMP_Y := 1 ; Value for A when setting X clamp with ClampMouse
2018-10-29 02:49:17 +00:00
;;; Mouse ID bytes
2018-10-29 05:10:05 +00:00
MOUSEID_MAX := 4
2018-10-29 05:23:33 +00:00
MOUSEID_ADDR: .byte $05, $07, $0b, $0c, $fb
MOUSEID_VAL: .byte $38, $18, $01, $20, $d6
2018-10-29 02:49:17 +00:00
2018-10-29 05:23:33 +00:00
SLOT_BASE := $C000
2018-10-29 05:10:05 +00:00
2018-11-03 03:51:23 +00:00
;;;--------------------------------------------------
;;; Mouse firmware routine
;;;--------------------------------------------------
SetMouse := $12 ; A=mode; C=0 on success
ServeMouse := $13 ; C=0 mouse interrupt, C=1 other
ReadMouse := $14
ClearMouse := $15
PosMouse := $16
ClampMouse := $17
HomeMouse := $18
InitMouse := $19
.macro MOUSE_CALL routine
ldy routine
jmp CallMouse
.endmacro
2018-10-29 02:49:17 +00:00
;;;--------------------------------------------------
;;; Data
;;;--------------------------------------------------
;;; Mouse
2018-11-03 03:51:23 +00:00
mouse_slot: .byte 0 ; mouse slot, or 0 if none
mouse_fw_hi: .byte 0 ; mouse slot as $Cn
mouse_op: .byte 0 ; mouse slot as $n0
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
mouse_ptr := $EB ; Zero page location
2018-10-29 02:49:17 +00:00
;;;--------------------------------------------------
;;; Routines
;;;--------------------------------------------------
2018-11-03 03:51:23 +00:00
MOUSE_CLAMP_MIN := $10
MOUSE_CLAMP_MAX := $1F
MOUSE_CENTER := $17
MOUSE_POS_MASK := $0F
2018-10-29 02:49:17 +00:00
;;;--------------------------------------------------
;;; Macros for common mouse operations
;;;--------------------------------------------------
;;;----------------------------------------
2018-11-03 03:51:23 +00:00
.macro DoClampMouse axis, min, max
2018-10-29 02:49:17 +00:00
;;;----------------------------------------
;;; axis: MOUSE_CLAMP_X or MOUSE_CLAMP_Y
;;; min: minimum value (2 byte)
;;; max: maximum value (2 byte)
;;;----------------------------------------
2018-10-29 05:23:33 +00:00
lda #<min
sta MOUSE_CMIN_LSB
lda #>min
sta MOUSE_CMIN_MSB
lda #<max
sta MOUSE_CMAX_LSB
lda #>max
sta MOUSE_CMAX_MSB
lda #axis
2018-11-03 03:51:23 +00:00
MOUSE_CALL ClampMouse
2018-10-29 02:49:17 +00:00
.endmacro
;;;----------------------------------------
2018-11-03 03:51:23 +00:00
.macro DoPosMouse px, py
2018-10-29 02:49:17 +00:00
;;;----------------------------------------
2018-11-03 03:51:23 +00:00
ldx mouse_slot
2018-10-29 05:23:33 +00:00
lda #<px
2018-11-03 03:51:23 +00:00
sta MOUSE_X_LSB,x
2018-10-29 05:23:33 +00:00
lda #>px
2018-11-03 03:51:23 +00:00
sta MOUSE_X_MSB,x
2018-10-29 05:23:33 +00:00
lda #<py
2018-11-03 03:51:23 +00:00
sta MOUSE_Y_LSB,x
2018-10-29 05:23:33 +00:00
lda #>py
2018-11-03 03:51:23 +00:00
sta MOUSE_Y_MSB,x
MOUSE_CALL PosMouse
.endmacro
;;;----------------------------------------
.macro DoSetMouse mode
;;;----------------------------------------
lda #mode
MOUSE_CALL SetMouse
2018-10-29 02:49:17 +00:00
.endmacro
;;;---------------------------------------------------------
;;; Find and initialize the mouse port
2018-10-29 05:23:33 +00:00
.proc FindMouse
2018-10-29 02:49:17 +00:00
;;; Reference: http://home.swbell.net/rubywand/R034MOUSEPRG.TXT
2018-10-29 05:23:33 +00:00
sei ; No interrupts while we're getting set up
2018-11-03 03:51:23 +00:00
;; Find mouse card by scanning slots for ID bytes
2018-10-29 02:49:17 +00:00
2018-10-29 05:23:33 +00:00
ldy #MAX_SLOT ; Start search in slot 7
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
slot_loop:
sty mouse_slot ; Save for later
2018-10-29 05:23:33 +00:00
tya
clc
2018-11-03 03:51:23 +00:00
adc #>SLOT_BASE ; Firmware is $Cn
2018-10-29 05:23:33 +00:00
sta slot_addr + 1 ; Update msb of signature test
ldx #MOUSEID_MAX ; This many signature bytes
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
: lda MOUSEID_ADDR,x
sta slot_addr ; Update lsb of signature test
2018-10-29 05:23:33 +00:00
slot_addr := *+1
lda SLOT_BASE ; Self-modified
cmp MOUSEID_VAL,x ; Does it match the signature?
2018-11-03 03:51:23 +00:00
bne no_match ; Nope - try the next slot
2018-10-29 05:23:33 +00:00
dex ; Yes! Keep testing
2018-11-03 03:51:23 +00:00
bpl :- ; Fall through if all done
jmp found
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
no_match:
2018-10-29 05:23:33 +00:00
dey ; Didn't match
2018-11-03 03:51:23 +00:00
bne slot_loop ; Keep looking until slot 0
sty mouse_slot ; Oops, no mouse - make a note
2018-10-29 05:23:33 +00:00
rts ; and bail
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
;; Store results needed for call ($Cn and $n0)
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
found: tya ; Slot is in y
ora #>SLOT_BASE ; Compute $Cn - needed for calls
sta mouse_fw_hi
2018-10-29 02:49:17 +00:00
2018-10-29 05:23:33 +00:00
tya
2018-11-03 03:51:23 +00:00
asl ; Compute $n0 - needed for calls
2018-10-29 05:23:33 +00:00
asl
asl
asl
2018-11-03 03:51:23 +00:00
sta mouse_op
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
;; Initialize and configure mouse card
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
MOUSE_CALL InitMouse ; reset, clamp to 0-1023 x/y
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
DoSetMouse $01 ; mouse on, no interrupts
; TODO: test carry bit result (set = error)
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
;; Clamp for deltas
DoClampMouse MOUSE_CLAMP_X, MOUSE_CLAMP_MIN, MOUSE_CLAMP_MAX
DoClampMouse MOUSE_CLAMP_Y, MOUSE_CLAMP_MIN, MOUSE_CLAMP_MAX
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
DoPosMouse MOUSE_CENTER, MOUSE_CENTER
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
cli ; Enable interrupts so mouse can function
2018-10-29 05:23:33 +00:00
rts
2018-10-29 05:10:05 +00:00
.endproc
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
;;;--------------------------------------------------
;;; Call mouse firmware, param in A, routine in Y
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
.proc CallMouse
pha ; Save A (param)
ldx mouse_fw_hi ; $Cn
stx mouse_ptr+1
lda #0
sta mouse_ptr
lda (mouse_ptr),y ; Look up routine offset
sta mouse_ptr
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
pla ; param in A
ldy mouse_op ; $n0 in Y
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
php
sei
jsr call
plp
rts
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
call: jmp (mouse_ptr)
.endproc
2018-10-29 05:23:33 +00:00
2018-11-03 03:51:23 +00:00
;;;--------------------------------------------------
;;; Read mouse pos, send deltas, and recenter
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
.proc SendMouse
SaveRegisters
lda mouse_slot
beq done
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
MOUSE_CALL ReadMouse
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
lda Protocol::MouseX
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
ldx mouse_slot
2018-10-29 05:23:33 +00:00
lda MOUSE_X_LSB,x
2018-11-03 03:51:23 +00:00
ora MOUSE_POS_MASK
jsr SSC::Put
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
lda Protocol::MouseY
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
ldx mouse_slot
2018-10-29 05:23:33 +00:00
lda MOUSE_Y_LSB,x
2018-11-03 03:51:23 +00:00
ora MOUSE_POS_MASK
jsr SSC::Put
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
lda Protocol::MouseBtn
2018-10-29 05:23:33 +00:00
jsr SSC::Put
2018-11-03 03:51:23 +00:00
lda #1 ; Data size
jsr SSC::Put
ldx mouse_slot
lda MOUSE_STATUS,x
2018-10-29 05:23:33 +00:00
jsr SSC::Put
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
DoPosMouse MOUSE_CENTER, MOUSE_CENTER
2018-10-29 02:49:17 +00:00
2018-11-03 03:51:23 +00:00
done: RestoreRegisters
2018-10-29 05:23:33 +00:00
rts
2018-10-29 02:49:17 +00:00
.endproc
2018-10-29 05:10:05 +00:00
.endproc