client rewrite

This commit is contained in:
Joshua Bell 2018-11-02 20:51:23 -07:00
parent a094909c8c
commit 6df3ef7096
4 changed files with 769 additions and 473 deletions

Binary file not shown.

View File

@ -9,7 +9,7 @@ Current file: client.s
000000r 1 ;;;------------------------------------------------------------------- 000000r 1 ;;;-------------------------------------------------------------------
000000r 1 000000r 1
000000r 1 PADDLE_SUPPORT = 1 000000r 1 PADDLE_SUPPORT = 1
000000r 1 ;;; MOUSE_SUPPORT = 1 000000r 1 MOUSE_SUPPORT = 1
000000r 1 000000r 1
000000r 1 .include "apple2.inc" 000000r 1 .include "apple2.inc"
000000r 2 000000r 2
@ -127,8 +127,6 @@ Current file: client.s
000000r 1 000000r 1
000000r 1 MAX_SLOT := 7 ; Maximum slot # on an Apple II 000000r 1 MAX_SLOT := 7 ; Maximum slot # on an Apple II
000000r 1 000000r 1
000000r 1 ZP_PTR := $FA ; Write cursor location on zero page
000000r 1
000000r 1 ;;;------------------------------------------------------------------- 000000r 1 ;;;-------------------------------------------------------------------
000000r 1 ;;; Protocol: 000000r 1 ;;; Protocol:
000000r 1 ;;;------------------------------------------------------------------- 000000r 1 ;;;-------------------------------------------------------------------
@ -157,7 +155,7 @@ Current file: client.s
000000r 1 ;;;------------------------------------------------------------------- 000000r 1 ;;;-------------------------------------------------------------------
000000r 1 000000r 1
000000r 1 .org $6000 000000r 1 .org $6000
006000 1 4C 5B 60 jmp AppEntry 006000 1 4C 8A 61 jmp AppEntry
006003 1 006003 1
006003 1 .include "ssc.inc" 006003 1 .include "ssc.inc"
006003 2 ;;;------------------------------------------------------------------- 006003 2 ;;;-------------------------------------------------------------------
@ -205,7 +203,7 @@ Current file: client.s
00600D 2 AA tax 00600D 2 AA tax
00600E 2 A9 0B lda #CMND_NRDI ; Command register: no parity, RTS on, DTR on, no interrupts 00600E 2 A9 0B lda #CMND_NRDI ; Command register: no parity, RTS on, DTR on, no interrupts
006010 2 9D 02 C0 sta $C002,X 006010 2 9D 02 C0 sta $C002,X
006013 2 AC 58 60 ldy PSPEED ; Control register: look up by baud rate (8 data bits, 1 stop bit) 006013 2 AC 87 61 ldy PSPEED ; Control register: look up by baud rate (8 data bits, 1 stop bit)
006016 2 B9 03 60 lda BPSCTRL,Y 006016 2 B9 03 60 lda BPSCTRL,Y
006019 2 9D 03 C0 sta $C003,X 006019 2 9D 03 C0 sta $C003,X
00601C 2 8E 3C 60 stx MOD_UADATA_1 ; Modify references to 00601C 2 8E 3C 60 stx MOD_UADATA_1 ; Modify references to
@ -281,292 +279,604 @@ Current file: client.s
006058 1 006058 1
006058 1 .ifdef MOUSE_SUPPORT 006058 1 .ifdef MOUSE_SUPPORT
006058 1 .include "mouse.inc" 006058 1 .include "mouse.inc"
006058 1 .endif 006058 2 ;;;-------------------------------------------------------------------
006058 1 006058 2 ;;;
006058 1 006058 2 ;;; Mouse
006058 1 ;;;------------------------------------------------------------------- 006058 2 ;;;
006058 1 ;;; Variables 006058 2 ;;;-------------------------------------------------------------------
006058 1 ;;;------------------------------------------------------------------- 006058 2 ;; .error "Mouse support not fully implemented"
006058 1 006058 2
006058 1 ;;; Application configuration 006058 2 .proc Mouse
006058 1 03 PSPEED: .byte SSC::BPS_115k ; Hardcoded for Apple IIc (TODO: Allow configuration) 006058 2
006059 1 02 PSLOT: .byte 2 ; Hardcoded for Apple IIc (TODO: Allow configuration) 006058 2 ;;;--------------------------------------------------
00605A 1 00 PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemented) 006058 2 ;;; Mouse Screen Holes
00605B 1 006058 2 ;;;--------------------------------------------------
00605B 1 006058 2
00605B 1 ;;;--------------------------------------------------------- 006058 2 ;;; For ReadMouse and PosMouse
00605B 1 ;;; Initialize the application, and enter the main loop 006058 2
00605B 1 006058 2 MOUSE_X_LSB := $0478 ; + slot Low byte of X coordinate
00605B 1 .proc AppEntry 006058 2 MOUSE_Y_LSB := $04F8 ; + slot Low byte of Y coordinate
00605B 1 AD 59 60 lda PSLOT ; Use slot 2 006058 2 MOUSE_X_MSB := $0578 ; + slot High byte of X coordinate
00605E 1 20 07 60 jsr SSC::Init ; Initialize Super Serial Card 006058 2 MOUSE_Y_MSB := $05F8 ; + slot High byte of Y coordinate
006061 1 20 2B 61 jsr InitHires ; Initialize Hi-Res graphics 006058 2 MOUSE_RSV1 := $0678 ; + slot Reserved
006064 1 20 A5 60 jsr InitInput ; Initialize input devices 006058 2 MOUSE_RSV2 := $06F8 ; + slot Reserved
006067 1 20 74 60 jsr MainLoop 006058 2 MOUSE_STATUS := $0778 ; + slot Status byte
00606A 1 ;; fall through 006058 2 ;; 7 Button down
00606A 1 .endproc 006058 2 ;; 6 Button was down on last read and still down
00606A 1 006058 2 ;; 5 Movement since last read
00606A 1 ;;;--------------------------------------------------------- 006058 2 ;; 4 Reserved
00606A 1 ;;; Clean up and exit app 006058 2 ;; 3 Interrupt from VBlInt
00606A 1 006058 2 ;; 2 Interrupt from button
00606A 1 .proc AppExit 006058 2 ;; 1 Interrupt from movement
00606A 1 20 54 60 jsr SSC::Reset 006058 2 ;; 0 Reserved
00606D 1 8D 54 C0 sta LOWSCR 006058 2 MOUSE_MODE := $07F8 ; + slot Mode byte
006070 1 8D 51 C0 sta TXTSET 006058 2 ;; 7-4 Reserved
006073 1 60 rts 006058 2 ;; 3 VBlInt active
006074 1 .endproc 006058 2 ;; 2 VBL interrupt on button
006074 1 006058 2 ;; 1 VBL interrupt on movement
006074 1 ;;;------------------------------------------------------------------- 006058 2 ;; 0 Mouse active
006074 1 ;;; 006058 2
006074 1 ;;; Main loop functionality 006058 2 ;;; Scratch area for ClampMouse:
006074 1 ;;; 006058 2
006074 1 ;;;------------------------------------------------------------------- 006058 2 MOUSE_CMIN_LSB := $0478 ; Low byte of clamping minimum
006074 1 006058 2 MOUSE_CMAX_LSB := $04F8 ; Low byte of clamping maximum
006074 1 006058 2 MOUSE_CMIN_MSB := $0578 ; High byte of clamping minimum
006074 1 ;;;--------------------------------------------------------- 006058 2 MOUSE_CMAX_MSB := $05F8 ; High byte of clamping maximum
006074 1 .proc MainLoop 006058 2
006074 1 006058 2 ;;;--------------------------------------------------
006074 1 ;;; TODO: Sort out the protocol - should be able to send 006058 2 ;;; Mouse Constants
006074 1 ;;; input state without receiving data 006058 2 ;;;--------------------------------------------------
006074 1 ;;; jsr SSC::HasData ; Anything to read? 006058 2
006074 1 ;;; bne :+ ; Nope 006058 2 MOUSE_CLAMP_X := 0 ; Value for A when setting X clamp with ClampMouse
006074 1 006058 2 MOUSE_CLAMP_Y := 1 ; Value for A when setting X clamp with ClampMouse
006074 1 20 7E 60 : jsr ReceivePage 006058 2
006077 1 ;; Input is sent every 256 bytes (32 times per page) 006058 2 ;;; Mouse ID bytes
006077 1 20 42 61 jsr FlipHires 006058 2 MOUSEID_MAX := 4
00607A 1 006058 2 05 07 0B 0C MOUSEID_ADDR: .byte $05, $07, $0b, $0c, $fb
00607A 1 4C 74 60 jmp :- ; TODO: define an exit trigger 00605C 2 FB
00607D 1 60 rts 00605D 2 38 18 01 20 MOUSEID_VAL: .byte $38, $18, $01, $20, $d6
00607E 1 .endproc 006061 2 D6
00607E 1 006062 2
00607E 1 006062 2 SLOT_BASE := $C000
00607E 1 ;;;--------------------------------------------------------- 006062 2
00607E 1 ;;; Pull a hi-res page down over serial 006062 2 ;;;--------------------------------------------------
00607E 1 ;;; 006062 2 ;;; Mouse firmware routine
00607E 1 ;;; Protocol is: 006062 2 ;;;--------------------------------------------------
00607E 1 ;;; * Recieve 256 bytes (graphic data) 006062 2
00607E 1 ;;; * Send 1 byte (input state) 006062 2 SetMouse := $12 ; A=mode; C=0 on success
00607E 1 006062 2 ServeMouse := $13 ; C=0 mouse interrupt, C=1 other
00607E 1 .proc ReceivePage 006062 2 ReadMouse := $14
00607E 1 A9 80 lda #Protocol::Screen 006062 2 ClearMouse := $15
006080 1 20 30 60 jsr SSC::Put 006062 2 PosMouse := $16
006083 1 A9 00 lda #0 ; data size 006062 2 ClampMouse := $17
006085 1 20 30 60 jsr SSC::Put 006062 2 HomeMouse := $18
006088 1 006062 2 InitMouse := $19
006088 1 006062 2
006088 1 A9 00 lda #0 ; set up write pointer 006062 2 .macro MOUSE_CALL routine
00608A 1 85 FA sta ZP_PTR 006062 2 ldy routine
00608C 1 A5 E6 lda PAGE 006062 2 jmp CallMouse
00608E 1 85 FB sta ZP_PTR+1 006062 2 .endmacro
006090 1 A2 20 ldx #PAGESIZE ; plan to receive this many pages 006062 2
006092 1 A0 00 ldy #0 006062 2 ;;;--------------------------------------------------
006094 1 006062 2 ;;; Data
006094 1 20 3F 60 : jsr SSC::Get 006062 2 ;;;--------------------------------------------------
006097 1 91 FA sta (ZP_PTR),Y 006062 2
006099 1 C8 iny 006062 2 ;;; Mouse
00609A 1 D0 F8 bne :- ; Do a full page... 006062 2 00 mouse_slot: .byte 0 ; mouse slot, or 0 if none
00609C 1 006063 2 00 mouse_fw_hi: .byte 0 ; mouse slot as $Cn
00609C 1 ;; Interleave to maintain responsiveness 006064 2 00 mouse_op: .byte 0 ; mouse slot as $n0
00609C 1 20 A6 60 jsr SendInputState 006065 2
00609F 1 006065 2 mouse_ptr := $EB ; Zero page location
00609F 1 E6 FB inc ZP_PTR+1 006065 2
0060A1 1 CA dex 006065 2 ;;;--------------------------------------------------
0060A2 1 D0 F0 bne :- ; ...as many pages as we need 006065 2 ;;; Routines
0060A4 1 60 rts 006065 2 ;;;--------------------------------------------------
0060A5 1 .endproc 006065 2
0060A5 1 006065 2
0060A5 1 006065 2 MOUSE_CLAMP_MIN := $10
0060A5 1 ;;;------------------------------------------------------------------- 006065 2 MOUSE_CLAMP_MAX := $1F
0060A5 1 ;;; 006065 2 MOUSE_CENTER := $17
0060A5 1 ;;; Input device routines 006065 2 MOUSE_POS_MASK := $0F
0060A5 1 ;;; 006065 2
0060A5 1 ;;;------------------------------------------------------------------- 006065 2
0060A5 1 006065 2 ;;;--------------------------------------------------
0060A5 1 ;;;--------------------------------------------------------- 006065 2 ;;; Macros for common mouse operations
0060A5 1 ;;; Initialize input devices and storage for detecting 006065 2 ;;;--------------------------------------------------
0060A5 1 ;;; state transitions 006065 2
0060A5 1 006065 2 ;;;----------------------------------------
0060A5 1 .proc InitInput 006065 2 .macro DoClampMouse axis, min, max
0060A5 1 006065 2 ;;;----------------------------------------
0060A5 1 .ifdef MOUSE_SUPPORT 006065 2 ;;; axis: MOUSE_CLAMP_X or MOUSE_CLAMP_Y
0060A5 1 jsr Mouse::FindMouse 006065 2 ;;; min: minimum value (2 byte)
0060A5 1 .endif 006065 2 ;;; max: maximum value (2 byte)
0060A5 1 006065 2 ;;;----------------------------------------
0060A5 1 60 rts 006065 2 lda #<min
0060A6 1 .endproc 006065 2 sta MOUSE_CMIN_LSB
0060A6 1 006065 2 lda #>min
0060A6 1 006065 2 sta MOUSE_CMIN_MSB
0060A6 1 ;;;--------------------------------------------------------- 006065 2 lda #<max
0060A6 1 ;;; Send a full set of input state updates. 006065 2 sta MOUSE_CMAX_LSB
0060A6 1 006065 2 lda #>max
0060A6 1 ;;; Assumes time to transmit is roughly comparable to time 006065 2 sta MOUSE_CMAX_MSB
0060A6 1 ;;; to measure input state, therefore only sending changes is 006065 2 lda #axis
0060A6 1 ;;; not worthwhile in most cases. 006065 2 MOUSE_CALL ClampMouse
0060A6 1 006065 2 .endmacro
0060A6 1 .proc SendInputState 006065 2
0060A6 1 20 B0 60 jsr MaybeSendKeyboard 006065 2 ;;;----------------------------------------
0060A9 1 20 E3 60 jsr SendButtons 006065 2 .macro DoPosMouse px, py
0060AC 1 006065 2 ;;;----------------------------------------
0060AC 1 .ifdef PADDLE_SUPPORT 006065 2 ldx mouse_slot
0060AC 1 20 04 61 jsr SendPaddles 006065 2 lda #<px
0060AF 1 .endif 006065 2 sta MOUSE_X_LSB,x
0060AF 1 006065 2 lda #>px
0060AF 1 .ifdef MOUSE_SUPPORT 006065 2 sta MOUSE_X_MSB,x
0060AF 1 jsr SendMouse 006065 2 lda #<py
0060AF 1 .endif 006065 2 sta MOUSE_Y_LSB,x
0060AF 1 006065 2 lda #>py
0060AF 1 .endproc 006065 2 sta MOUSE_Y_MSB,x
0060AF 1 006065 2 MOUSE_CALL PosMouse
0060AF 1 006065 2 .endmacro
0060AF 1 ;;;------------------------------------------------------------ 006065 2
0060AF 1 ;;; Keyboard 006065 2 ;;;----------------------------------------
0060AF 1 006065 2 .macro DoSetMouse mode
0060AF 1 ;;; NOTE: Can't use KBDSTRB to detect key up -> key down transition 006065 2 ;;;----------------------------------------
0060AF 1 ;;; since the msb can change before the key code. Instead, consider 006065 2 lda #mode
0060AF 1 ;;; these cases: 006065 2 MOUSE_CALL SetMouse
0060AF 1 ;;; 006065 2 .endmacro
0060AF 1 ;;; OLD STATE KBD KBDSTRB RESULT 006065 2
0060AF 1 ;;; Up Up - No-op 006065 2
0060AF 1 ;;; Up Down - Save and send key down 006065 2 ;;;---------------------------------------------------------
0060AF 1 ;;; Down - Up Save and send key up 006065 2 ;;; Find and initialize the mouse port
0060AF 1 ;;; Down - Down Save and send key ONLY if different 006065 2
0060AF 1 ;;; 006065 2 .proc FindMouse
0060AF 1 006065 2
0060AF 1 00 last_kb: .byte 0 006065 2 ;;; Reference: http://home.swbell.net/rubywand/R034MOUSEPRG.TXT
0060B0 1 006065 2
0060B0 1 .proc MaybeSendKeyboard 006065 2 78 sei ; No interrupts while we're getting set up
0060B0 1 AD AF 60 lda last_kb 006066 2
0060B3 1 D0 08 bne key_was_down 006066 2 ;; Find mouse card by scanning slots for ID bytes
0060B5 1 006066 2
0060B5 1 key_was_up: 006066 2 A0 07 ldy #MAX_SLOT ; Start search in slot 7
0060B5 1 ;; Key was up - send only if now down. 006068 2
0060B5 1 AD 00 C0 lda KBD ; Read keyboard 006068 2 slot_loop:
0060B8 1 10 28 bpl done ; Do nothing if it is still up. 006068 2 8C 62 60 sty mouse_slot ; Save for later
0060BA 1 4C CF 60 jmp send ; Otherwise send. 00606B 2 98 tya
0060BD 1 00606C 2 18 clc
0060BD 1 key_was_down: 00606D 2 69 C0 adc #>SLOT_BASE ; Firmware is $Cn
0060BD 1 ;; Key was down - strobe should match 00606F 2 8D 7C 60 sta slot_addr + 1 ; Update msb of signature test
0060BD 1 ;; unless the key changed or was released. 006072 2 A2 04 ldx #MOUSEID_MAX ; This many signature bytes
0060BD 1 AD 10 C0 lda KBDSTRB 006074 2
0060C0 1 30 05 bmi kbdstrb_down 006074 2 BD 58 60 : lda MOUSEID_ADDR,x
0060C2 1 006077 2 8D 7B 60 sta slot_addr ; Update lsb of signature test
0060C2 1 kbdstrb_up: 00607A 2
0060C2 1 A9 00 lda #0 ; Now released 00607A 2 slot_addr := *+1
0060C4 1 4C CF 60 jmp send 00607A 2 AD 00 C0 lda SLOT_BASE ; Self-modified
0060C7 1 00607D 2 DD 5D 60 cmp MOUSEID_VAL,x ; Does it match the signature?
0060C7 1 kbdstrb_down: 006080 2 D0 06 bne no_match ; Nope - try the next slot
0060C7 1 CD AF 60 cmp last_kb ; Same key as last time? 006082 2 CA dex ; Yes! Keep testing
0060CA 1 F0 16 beq done ; - no change, don't send. 006083 2 10 EF bpl :- ; Fall through if all done
0060CC 1 4C CF 60 jmp send 006085 2 4C 8F 60 jmp found
0060CF 1 006088 2
0060CF 1 8D AF 60 send: sta last_kb 006088 2 no_match:
0060D2 1 A5 00 lda Protocol::Keyboard 006088 2 88 dey ; Didn't match
0060D4 1 20 30 60 jsr SSC::Put 006089 2 D0 DD bne slot_loop ; Keep looking until slot 0
0060D7 1 A9 01 lda #1 ; Data size 00608B 2 8C 62 60 sty mouse_slot ; Oops, no mouse - make a note
0060D9 1 20 30 60 jsr SSC::Put 00608E 2 60 rts ; and bail
0060DC 1 AD AF 60 lda last_kb 00608F 2
0060DF 1 20 30 60 jsr SSC::Put 00608F 2 ;; Store results needed for call ($Cn and $n0)
0060E2 1 00608F 2
0060E2 1 60 done: rts 00608F 2 98 found: tya ; Slot is in y
0060E3 1 .endproc 006090 2 09 C0 ora #>SLOT_BASE ; Compute $Cn - needed for calls
0060E3 1 006092 2 8D 63 60 sta mouse_fw_hi
0060E3 1 ;;;------------------------------------------------------------ 006095 2
0060E3 1 ;;; Buttons 006095 2 98 tya
0060E3 1 006096 2 0A asl ; Compute $n0 - needed for calls
0060E3 1 .proc SendButtons 006097 2 0A asl
0060E3 1 006098 2 0A asl
0060E3 1 A5 10 lda Protocol::Button0 006099 2 0A asl
0060E5 1 20 30 60 jsr SSC::Put 00609A 2 8D 64 60 sta mouse_op
0060E8 1 A9 01 lda #1 ; Data size 00609D 2
0060EA 1 20 30 60 jsr SSC::Put 00609D 2 ;; Initialize and configure mouse card
0060ED 1 AD 61 C0 lda BUTN0 00609D 2
0060F0 1 20 30 60 jsr SSC::Put 00609D 2 A4 19 4C FD MOUSE_CALL InitMouse ; reset, clamp to 0-1023 x/y
0060F3 1 0060A1 2 60
0060F3 1 A5 11 lda Protocol::Button1 0060A2 2
0060F5 1 20 30 60 jsr SSC::Put 0060A2 2 A9 01 A4 12 DoSetMouse $01 ; mouse on, no interrupts
0060F8 1 A9 01 lda #1 ; Data size 0060A6 2 4C FD 60
0060FA 1 20 30 60 jsr SSC::Put 0060A9 2 ; TODO: test carry bit result (set = error)
0060FD 1 AD 62 C0 lda BUTN1 0060A9 2
006100 1 20 30 60 jsr SSC::Put 0060A9 2 ;; Clamp for deltas
006103 1 0060A9 2 A9 10 8D 78 DoClampMouse MOUSE_CLAMP_X, MOUSE_CLAMP_MIN, MOUSE_CLAMP_MAX
006103 1 60 rts 0060AD 2 04 A9 00 8D
006104 1 .endproc 0060B1 2 78 05 A9 1F
006104 1 0060B5 2 8D F8 04 A9
006104 1 ;;;------------------------------------------------------------ 0060B9 2 00 8D F8 05
006104 1 ;;; Paddles 0060BD 2 A9 00 A4 17
006104 1 0060C1 2 4C FD 60
006104 1 .ifdef PADDLE_SUPPORT 0060C4 2 A9 10 8D 78 DoClampMouse MOUSE_CLAMP_Y, MOUSE_CLAMP_MIN, MOUSE_CLAMP_MAX
006104 1 .proc SendPaddles 0060C8 2 04 A9 00 8D
006104 1 0060CC 2 78 05 A9 1F
006104 1 A5 20 lda Protocol::Paddle0 0060D0 2 8D F8 04 A9
006106 1 20 30 60 jsr SSC::Put 0060D4 2 00 8D F8 05
006109 1 A9 01 lda #1 ; Data size 0060D8 2 A9 01 A4 17
00610B 1 20 30 60 jsr SSC::Put 0060DC 2 4C FD 60
00610E 1 0060DF 2
00610E 1 A2 00 ldx #0 0060DF 2 AE 62 60 A9 DoPosMouse MOUSE_CENTER, MOUSE_CENTER
006110 1 20 1E FB jsr PREAD 0060E3 2 17 9D 78 04
006113 1 98 tya 0060E7 2 A9 00 9D 78
006114 1 20 30 60 jsr SSC::Put 0060EB 2 05 A9 17 9D
006117 1 0060EF 2 F8 04 A9 00
006117 1 ;; Assumes at least 11 cycles to send, so 0060F3 2 9D F8 05 A4
006117 1 ;; timer has a chance to reset. 0060F7 2 16 4C FD 60
006117 1 0060FB 2
006117 1 A5 21 lda Protocol::Paddle1 0060FB 2 58 cli ; Enable interrupts so mouse can function
006119 1 20 30 60 jsr SSC::Put 0060FC 2
00611C 1 A9 01 lda #1 ; Data size 0060FC 2 60 rts
00611E 1 20 30 60 jsr SSC::Put 0060FD 2 .endproc
006121 1 0060FD 2
006121 1 A2 01 ldx #1 0060FD 2 ;;;--------------------------------------------------
006123 1 20 1E FB jsr PREAD 0060FD 2 ;;; Call mouse firmware, param in A, routine in Y
006126 1 98 tya 0060FD 2
006127 1 20 30 60 jsr SSC::Put 0060FD 2 .proc CallMouse
00612A 1 0060FD 2 48 pha ; Save A (param)
00612A 1 60 rts 0060FE 2 AE 63 60 ldx mouse_fw_hi ; $Cn
00612B 1 .endproc 006101 2 86 EC stx mouse_ptr+1
00612B 1 .endif 006103 2 A9 00 lda #0
00612B 1 006105 2 85 EB sta mouse_ptr
00612B 1 ;;;------------------------------------------------------------------- 006107 2 B1 EB lda (mouse_ptr),y ; Look up routine offset
00612B 1 ;;; 006109 2 85 EB sta mouse_ptr
00612B 1 ;;; Hi-res graphics routines 00610B 2
00612B 1 ;;; 00610B 2 68 pla ; param in A
00612B 1 ;;;------------------------------------------------------------------- 00610C 2 AC 64 60 ldy mouse_op ; $n0 in Y
00612B 1 00610F 2
00612B 1 ;;;--------------------------------------------------------- 00610F 2 08 php
00612B 1 ;;; Set up the graphics display and pointers 006110 2 78 sei
00612B 1 006111 2 20 16 61 jsr call
00612B 1 .proc InitHires 006114 2 28 plp
00612B 1 A9 20 lda #PAGE1 ; clear page 1 006115 2 60 rts
00612D 1 85 E6 sta PAGE 006116 2
00612F 1 20 F2 F3 jsr HCLR 006116 2 6C EB 00 call: jmp (mouse_ptr)
006132 1 006119 2 .endproc
006132 1 20 42 61 jsr FlipHires ; then show it and flip to 2 006119 2
006135 1 8D 57 C0 sta HIRES 006119 2 ;;;--------------------------------------------------
006138 1 8D 50 C0 sta TXTCLR 006119 2 ;;; Read mouse pos, send deltas, and recenter
00613B 1 8D 52 C0 sta MIXCLR 006119 2
00613E 1 8D 54 C0 sta LOWSCR 006119 2 .proc SendMouse
006141 1 006119 2 48 8A 48 98 SaveRegisters
006141 1 60 rts 00611D 2 48
006142 1 .endproc 00611E 2 AD 62 60 lda mouse_slot
006142 1 006121 2 F0 5E beq done
006142 1 006123 2
006142 1 ;;;--------------------------------------------------------- 006123 2 A4 14 4C FD MOUSE_CALL ReadMouse
006142 1 ;;; Call when done with the current plotting page 006127 2 60
006142 1 ;;; (selected in PAGE) and it will be shown and the 006128 2
006142 1 ;;; other page will be shown. 006128 2 A5 30 lda Protocol::MouseX
006142 1 00612A 2 20 30 60 jsr SSC::Put
006142 1 .proc FlipHires 00612D 2 A9 01 lda #1 ; Data size
006142 1 A5 E6 lda PAGE ; plotting on which page? 00612F 2 20 30 60 jsr SSC::Put
006144 1 C9 20 cmp #PAGE1 006132 2 AE 62 60 ldx mouse_slot
006146 1 F0 08 beq :+ 006135 2 BD 78 04 lda MOUSE_X_LSB,x
006148 1 006138 2 05 0F ora MOUSE_POS_MASK
006148 1 8D 55 C0 sta HISCR ; page 2 - so show it 00613A 2 20 30 60 jsr SSC::Put
00614B 1 A9 20 lda #PAGE1 ; and plot on page 1 00613D 2
00614D 1 85 E6 sta PAGE 00613D 2 A5 31 lda Protocol::MouseY
00614F 1 60 rts 00613F 2 20 30 60 jsr SSC::Put
006150 1 006142 2 A9 01 lda #1 ; Data size
006150 1 8D 54 C0 : sta LOWSCR ; page 1 - so show it 006144 2 20 30 60 jsr SSC::Put
006153 1 A9 40 lda #PAGE2 ; and plot on page 2 006147 2 AE 62 60 ldx mouse_slot
006155 1 85 E6 sta PAGE 00614A 2 BD F8 04 lda MOUSE_Y_LSB,x
006157 1 60 rts 00614D 2 05 0F ora MOUSE_POS_MASK
006158 1 .endproc 00614F 2 20 30 60 jsr SSC::Put
006158 1 006152 2
006152 2 A5 32 lda Protocol::MouseBtn
006154 2 20 30 60 jsr SSC::Put
006157 2 A9 01 lda #1 ; Data size
006159 2 20 30 60 jsr SSC::Put
00615C 2 AE 62 60 ldx mouse_slot
00615F 2 BD 78 07 lda MOUSE_STATUS,x
006162 2 20 30 60 jsr SSC::Put
006165 2
006165 2 AE 62 60 A9 DoPosMouse MOUSE_CENTER, MOUSE_CENTER
006169 2 17 9D 78 04
00616D 2 A9 00 9D 78
006171 2 05 A9 17 9D
006175 2 F8 04 A9 00
006179 2 9D F8 05 A4
00617D 2 16 4C FD 60
006181 2
006181 2 68 A8 68 AA done: RestoreRegisters
006185 2 68
006186 2 60 rts
006187 2 .endproc
006187 2
006187 2 .endproc
006187 2
006187 1 .endif
006187 1
006187 1
006187 1 ;;;-------------------------------------------------------------------
006187 1 ;;; Variables
006187 1 ;;;-------------------------------------------------------------------
006187 1
006187 1 ;;; Application configuration
006187 1 03 PSPEED: .byte SSC::BPS_115k ; Hardcoded for Apple IIc (TODO: Allow configuration)
006188 1 02 PSLOT: .byte 2 ; Hardcoded for Apple IIc (TODO: Allow configuration)
006189 1 00 PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemented)
00618A 1
00618A 1
00618A 1 ;;;---------------------------------------------------------
00618A 1 ;;; Initialize the application, and enter the main loop
00618A 1
00618A 1 .proc AppEntry
00618A 1 AD 88 61 lda PSLOT ; Use slot 2
00618D 1 20 07 60 jsr SSC::Init ; Initialize Super Serial Card
006190 1 20 60 62 jsr InitHires ; Initialize Hi-Res graphics
006193 1 20 D4 61 jsr InitInput ; Initialize input devices
006196 1 20 A3 61 jsr MainLoop
006199 1 ;; fall through
006199 1 .endproc
006199 1
006199 1 ;;;---------------------------------------------------------
006199 1 ;;; Clean up and exit app
006199 1
006199 1 .proc AppExit
006199 1 20 54 60 jsr SSC::Reset
00619C 1 8D 54 C0 sta LOWSCR
00619F 1 8D 51 C0 sta TXTSET
0061A2 1 60 rts
0061A3 1 .endproc
0061A3 1
0061A3 1 ;;;-------------------------------------------------------------------
0061A3 1 ;;;
0061A3 1 ;;; Main loop functionality
0061A3 1 ;;;
0061A3 1 ;;;-------------------------------------------------------------------
0061A3 1
0061A3 1
0061A3 1 ;;;---------------------------------------------------------
0061A3 1 .proc MainLoop
0061A3 1
0061A3 1 ;;; TODO: Sort out the protocol - should be able to send
0061A3 1 ;;; input state without receiving data
0061A3 1 ;;; jsr SSC::HasData ; Anything to read?
0061A3 1 ;;; bne :+ ; Nope
0061A3 1
0061A3 1 20 AD 61 : jsr ReceivePage
0061A6 1 ;; Input is sent every 256 bytes (32 times per page)
0061A6 1 20 77 62 jsr FlipHires
0061A9 1
0061A9 1 4C A3 61 jmp :- ; TODO: define an exit trigger
0061AC 1 60 rts
0061AD 1 .endproc
0061AD 1
0061AD 1
0061AD 1 ;;;---------------------------------------------------------
0061AD 1 ;;; Request a hires page, sending input state along every
0061AD 1 ;;; 256 bytes.
0061AD 1 ;;;
0061AD 1
0061AD 1 .proc ReceivePage
0061AD 1
0061AD 1 ptr := $FA
0061AD 1
0061AD 1 A9 80 lda #Protocol::Screen
0061AF 1 20 30 60 jsr SSC::Put
0061B2 1 A9 00 lda #0 ; data size
0061B4 1 20 30 60 jsr SSC::Put
0061B7 1
0061B7 1
0061B7 1 A9 00 lda #0 ; set up write pointer
0061B9 1 85 FA sta ptr
0061BB 1 A5 E6 lda PAGE
0061BD 1 85 FB sta ptr+1
0061BF 1 A2 20 ldx #PAGESIZE ; plan to receive this many pages
0061C1 1 A0 00 ldy #0
0061C3 1
0061C3 1 20 3F 60 : jsr SSC::Get
0061C6 1 91 FA sta (ptr),Y
0061C8 1 C8 iny
0061C9 1 D0 F8 bne :- ; Do a full page...
0061CB 1
0061CB 1 ;; Interleave to maintain responsiveness
0061CB 1 20 D8 61 jsr SendInputState
0061CE 1
0061CE 1 E6 FB inc ptr+1
0061D0 1 CA dex
0061D1 1 D0 F0 bne :- ; ...as many pages as we need
0061D3 1 60 rts
0061D4 1 .endproc
0061D4 1
0061D4 1
0061D4 1 ;;;-------------------------------------------------------------------
0061D4 1 ;;;
0061D4 1 ;;; Input device routines
0061D4 1 ;;;
0061D4 1 ;;;-------------------------------------------------------------------
0061D4 1
0061D4 1 ;;;---------------------------------------------------------
0061D4 1 ;;; Initialize input devices and storage for detecting
0061D4 1 ;;; state transitions
0061D4 1
0061D4 1 .proc InitInput
0061D4 1
0061D4 1 .ifdef MOUSE_SUPPORT
0061D4 1 20 65 60 jsr Mouse::FindMouse
0061D7 1 .endif
0061D7 1
0061D7 1 60 rts
0061D8 1 .endproc
0061D8 1
0061D8 1
0061D8 1 ;;;---------------------------------------------------------
0061D8 1 ;;; Send a full set of input state updates.
0061D8 1
0061D8 1 ;;; Assumes time to transmit is roughly comparable to time
0061D8 1 ;;; to measure input state, therefore only sending changes is
0061D8 1 ;;; not worthwhile in most cases.
0061D8 1
0061D8 1 .proc SendInputState
0061D8 1 20 E5 61 jsr MaybeSendKeyboard
0061DB 1 20 18 62 jsr SendButtons
0061DE 1
0061DE 1 .ifdef PADDLE_SUPPORT
0061DE 1 20 39 62 jsr SendPaddles
0061E1 1 .endif
0061E1 1
0061E1 1 .ifdef MOUSE_SUPPORT
0061E1 1 20 19 61 jsr Mouse::SendMouse
0061E4 1 .endif
0061E4 1
0061E4 1 .endproc
0061E4 1
0061E4 1
0061E4 1 ;;;------------------------------------------------------------
0061E4 1 ;;; Keyboard
0061E4 1
0061E4 1 ;;; NOTE: Can't use KBDSTRB to detect key up -> key down transition
0061E4 1 ;;; since the msb can change before the key code. Instead, consider
0061E4 1 ;;; these cases:
0061E4 1 ;;;
0061E4 1 ;;; OLD STATE KBD KBDSTRB RESULT
0061E4 1 ;;; Up Up - No-op
0061E4 1 ;;; Up Down - Save and send key down
0061E4 1 ;;; Down - Up Save and send key up
0061E4 1 ;;; Down - Down Save and send key ONLY if different
0061E4 1 ;;;
0061E4 1
0061E4 1 00 last_kb: .byte 0
0061E5 1
0061E5 1 .proc MaybeSendKeyboard
0061E5 1 AD E4 61 lda last_kb
0061E8 1 D0 08 bne key_was_down
0061EA 1
0061EA 1 key_was_up:
0061EA 1 ;; Key was up - send only if now down.
0061EA 1 AD 00 C0 lda KBD ; Read keyboard
0061ED 1 10 28 bpl done ; Do nothing if it is still up.
0061EF 1 4C 04 62 jmp send ; Otherwise send.
0061F2 1
0061F2 1 key_was_down:
0061F2 1 ;; Key was down - strobe should match
0061F2 1 ;; unless the key changed or was released.
0061F2 1 AD 10 C0 lda KBDSTRB
0061F5 1 30 05 bmi kbdstrb_down
0061F7 1
0061F7 1 kbdstrb_up:
0061F7 1 A9 00 lda #0 ; Now released
0061F9 1 4C 04 62 jmp send
0061FC 1
0061FC 1 kbdstrb_down:
0061FC 1 CD E4 61 cmp last_kb ; Same key as last time?
0061FF 1 F0 16 beq done ; - no change, don't send.
006201 1 4C 04 62 jmp send
006204 1
006204 1 8D E4 61 send: sta last_kb
006207 1 A5 00 lda Protocol::Keyboard
006209 1 20 30 60 jsr SSC::Put
00620C 1 A9 01 lda #1 ; Data size
00620E 1 20 30 60 jsr SSC::Put
006211 1 AD E4 61 lda last_kb
006214 1 20 30 60 jsr SSC::Put
006217 1
006217 1 60 done: rts
006218 1 .endproc
006218 1
006218 1 ;;;------------------------------------------------------------
006218 1 ;;; Buttons
006218 1
006218 1 .proc SendButtons
006218 1
006218 1 A5 10 lda Protocol::Button0
00621A 1 20 30 60 jsr SSC::Put
00621D 1 A9 01 lda #1 ; Data size
00621F 1 20 30 60 jsr SSC::Put
006222 1 AD 61 C0 lda BUTN0
006225 1 20 30 60 jsr SSC::Put
006228 1
006228 1 A5 11 lda Protocol::Button1
00622A 1 20 30 60 jsr SSC::Put
00622D 1 A9 01 lda #1 ; Data size
00622F 1 20 30 60 jsr SSC::Put
006232 1 AD 62 C0 lda BUTN1
006235 1 20 30 60 jsr SSC::Put
006238 1
006238 1 60 rts
006239 1 .endproc
006239 1
006239 1 ;;;------------------------------------------------------------
006239 1 ;;; Paddles
006239 1
006239 1 .ifdef PADDLE_SUPPORT
006239 1 .proc SendPaddles
006239 1
006239 1 A5 20 lda Protocol::Paddle0
00623B 1 20 30 60 jsr SSC::Put
00623E 1 A9 01 lda #1 ; Data size
006240 1 20 30 60 jsr SSC::Put
006243 1
006243 1 A2 00 ldx #0
006245 1 20 1E FB jsr PREAD
006248 1 98 tya
006249 1 20 30 60 jsr SSC::Put
00624C 1
00624C 1 ;; Need to wait 3ms between reads.
00624C 1
00624C 1 A5 21 lda Protocol::Paddle1
00624E 1 20 30 60 jsr SSC::Put
006251 1 A9 01 lda #1 ; Data size
006253 1 20 30 60 jsr SSC::Put
006256 1
006256 1 A2 01 ldx #1
006258 1 20 1E FB jsr PREAD
00625B 1 98 tya
00625C 1 20 30 60 jsr SSC::Put
00625F 1
00625F 1 60 rts
006260 1 .endproc
006260 1 .endif
006260 1
006260 1 ;;;-------------------------------------------------------------------
006260 1 ;;;
006260 1 ;;; Hi-res graphics routines
006260 1 ;;;
006260 1 ;;;-------------------------------------------------------------------
006260 1
006260 1 ;;;---------------------------------------------------------
006260 1 ;;; Set up the graphics display and pointers
006260 1
006260 1 .proc InitHires
006260 1 A9 20 lda #PAGE1 ; clear page 1
006262 1 85 E6 sta PAGE
006264 1 20 F2 F3 jsr HCLR
006267 1
006267 1 20 77 62 jsr FlipHires ; then show it and flip to 2
00626A 1 8D 57 C0 sta HIRES
00626D 1 8D 50 C0 sta TXTCLR
006270 1 8D 52 C0 sta MIXCLR
006273 1 8D 54 C0 sta LOWSCR
006276 1
006276 1 60 rts
006277 1 .endproc
006277 1
006277 1
006277 1 ;;;---------------------------------------------------------
006277 1 ;;; Call when done with the current plotting page
006277 1 ;;; (selected in PAGE) and it will be shown and the
006277 1 ;;; other page will be shown.
006277 1
006277 1 .proc FlipHires
006277 1 A5 E6 lda PAGE ; plotting on which page?
006279 1 C9 20 cmp #PAGE1
00627B 1 F0 08 beq :+
00627D 1
00627D 1 8D 55 C0 sta HISCR ; page 2 - so show it
006280 1 A9 20 lda #PAGE1 ; and plot on page 1
006282 1 85 E6 sta PAGE
006284 1 60 rts
006285 1
006285 1 8D 54 C0 : sta LOWSCR ; page 1 - so show it
006288 1 A9 40 lda #PAGE2 ; and plot on page 2
00628A 1 85 E6 sta PAGE
00628C 1 60 rts
00628D 1 .endproc
00628D 1

View File

@ -5,7 +5,7 @@
;;;------------------------------------------------------------------- ;;;-------------------------------------------------------------------
PADDLE_SUPPORT = 1 PADDLE_SUPPORT = 1
;;; MOUSE_SUPPORT = 1 MOUSE_SUPPORT = 1
.include "apple2.inc" .include "apple2.inc"
@ -36,8 +36,6 @@ HCLR := $F3F2 ; Clear current hires screen to black
MAX_SLOT := 7 ; Maximum slot # on an Apple II MAX_SLOT := 7 ; Maximum slot # on an Apple II
ZP_PTR := $FA ; Write cursor location on zero page
;;;------------------------------------------------------------------- ;;;-------------------------------------------------------------------
;;; Protocol: ;;; Protocol:
;;;------------------------------------------------------------------- ;;;-------------------------------------------------------------------
@ -132,13 +130,14 @@ PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemente
;;;--------------------------------------------------------- ;;;---------------------------------------------------------
;;; Pull a hi-res page down over serial ;;; Request a hires page, sending input state along every
;;; 256 bytes.
;;; ;;;
;;; Protocol is:
;;; * Recieve 256 bytes (graphic data)
;;; * Send 1 byte (input state)
.proc ReceivePage .proc ReceivePage
ptr := $FA
lda #Protocol::Screen lda #Protocol::Screen
jsr SSC::Put jsr SSC::Put
lda #0 ; data size lda #0 ; data size
@ -146,21 +145,21 @@ PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemente
lda #0 ; set up write pointer lda #0 ; set up write pointer
sta ZP_PTR sta ptr
lda PAGE lda PAGE
sta ZP_PTR+1 sta ptr+1
ldx #PAGESIZE ; plan to receive this many pages ldx #PAGESIZE ; plan to receive this many pages
ldy #0 ldy #0
: jsr SSC::Get : jsr SSC::Get
sta (ZP_PTR),Y sta (ptr),Y
iny iny
bne :- ; Do a full page... bne :- ; Do a full page...
;; Interleave to maintain responsiveness ;; Interleave to maintain responsiveness
jsr SendInputState jsr SendInputState
inc ZP_PTR+1 inc ptr+1
dex dex
bne :- ; ...as many pages as we need bne :- ; ...as many pages as we need
rts rts
@ -203,7 +202,7 @@ PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemente
.endif .endif
.ifdef MOUSE_SUPPORT .ifdef MOUSE_SUPPORT
jsr SendMouse jsr Mouse::SendMouse
.endif .endif
.endproc .endproc
@ -299,8 +298,7 @@ done: rts
tya tya
jsr SSC::Put jsr SSC::Put
;; Assumes at least 11 cycles to send, so ;; Need to wait 3ms between reads.
;; timer has a chance to reset.
lda Protocol::Paddle1 lda Protocol::Paddle1
jsr SSC::Put jsr SSC::Put

View File

@ -3,34 +3,51 @@
;;; Mouse ;;; Mouse
;;; ;;;
;;;------------------------------------------------------------------- ;;;-------------------------------------------------------------------
.error "Mouse support not fully implemented" ;; .error "Mouse support not fully implemented"
.proc Mouse .proc Mouse
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;; Locations and constants ;;; Mouse Screen Holes
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;; For READMOUSE and POSMOUSE ;;; For ReadMouse and PosMouse
MOUSE_X_LSB := $0478 ; + slot Low byte of absolute X position MOUSE_X_LSB := $0478 ; + slot Low byte of X coordinate
MOUSE_X_MSB := $0578 ; + slot High byte of absolute X position MOUSE_Y_LSB := $04F8 ; + slot Low byte of Y coordinate
MOUSE_Y_LSB := $04F8 ; + slot Low byte of absolute Y position MOUSE_X_MSB := $0578 ; + slot High byte of X coordinate
MOUSE_Y_MSB := $05F8 ; + slot High byte of absolute Y position MOUSE_Y_MSB := $05F8 ; + slot High byte of Y coordinate
MOUSE_RSV1 := $0678 ; + slot Reserved and used by the firmware MOUSE_RSV1 := $0678 ; + slot Reserved
MOUSE_RSV2 := $06F8 ; + slot Reserved and used by the firmware MOUSE_RSV2 := $06F8 ; + slot Reserved
MOUSE_BTN := $0778 ; + slot Button 0/1 interrupt status byte 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
MOUSE_MODE := $07F8 ; + slot Mode byte MOUSE_MODE := $07F8 ; + slot Mode byte
;; 7-4 Reserved
;; 3 VBlInt active
;; 2 VBL interrupt on button
;; 1 VBL interrupt on movement
;; 0 Mouse active
;;; For CLAMPMOUSE: ;;; Scratch area for ClampMouse:
MOUSE_CMIN_LSB := $0478 ; low byte of low clamp MOUSE_CMIN_LSB := $0478 ; Low byte of clamping minimum
MOUSE_CMIN_MSB := $0578 ; high byte of low clamp MOUSE_CMAX_LSB := $04F8 ; Low byte of clamping maximum
MOUSE_CMAX_LSB := $04F8 ; low byte of high clamp MOUSE_CMIN_MSB := $0578 ; High byte of clamping minimum
MOUSE_CMAX_MSB := $05F8 ; high byte of high clamp MOUSE_CMAX_MSB := $05F8 ; High byte of clamping maximum
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 ;;; Mouse Constants
;;;--------------------------------------------------
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
;;; Mouse ID bytes ;;; Mouse ID bytes
MOUSEID_MAX := 4 MOUSEID_MAX := 4
@ -39,28 +56,44 @@ MOUSEID_VAL: .byte $38, $18, $01, $20, $d6
SLOT_BASE := $C000 SLOT_BASE := $C000
;;;--------------------------------------------------
;;; 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
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;; Data ;;; Data
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;; Mouse ;;; Mouse
MOUSE_SLOT: .byte 0 ; mouse slot, or 0 if none mouse_slot: .byte 0 ; mouse slot, or 0 if none
LAST_MX: .byte $7f mouse_fw_hi: .byte 0 ; mouse slot as $Cn
LAST_MY: .byte $7f mouse_op: .byte 0 ; mouse slot as $n0
mouse_ptr := $EB ; Zero page location
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;; Routines ;;; Routines
;;;-------------------------------------------------- ;;;--------------------------------------------------
MOUSEPTR := $EB ; Zero page location
MOUSE_MIN_X := $10 MOUSE_CLAMP_MIN := $10
MOUSE_MAX_X := $1f MOUSE_CLAMP_MAX := $1F
MOUSE_CENTER_X := $17 MOUSE_CENTER := $17
MOUSE_MIN_Y := $20 MOUSE_POS_MASK := $0F
MOUSE_MAX_Y := $2f
MOUSE_CENTER_Y := $2f
;;;-------------------------------------------------- ;;;--------------------------------------------------
@ -68,7 +101,7 @@ MOUSE_CENTER_Y := $2f
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;;---------------------------------------- ;;;----------------------------------------
.macro ClampMouse axis, min, max .macro DoClampMouse axis, min, max
;;;---------------------------------------- ;;;----------------------------------------
;;; axis: MOUSE_CLAMP_X or MOUSE_CLAMP_Y ;;; axis: MOUSE_CLAMP_X or MOUSE_CLAMP_Y
;;; min: minimum value (2 byte) ;;; min: minimum value (2 byte)
@ -83,22 +116,29 @@ MOUSE_CENTER_Y := $2f
lda #>max lda #>max
sta MOUSE_CMAX_MSB sta MOUSE_CMAX_MSB
lda #axis lda #axis
jsr CLAMPMOUSE MOUSE_CALL ClampMouse
.endmacro .endmacro
;;;---------------------------------------- ;;;----------------------------------------
.macro PosMouse px, py .macro DoPosMouse px, py
;;;---------------------------------------- ;;;----------------------------------------
ldx MOUSE_SLOT ldx mouse_slot
lda #<px lda #<px
sta MOUSE_X_LSB,X sta MOUSE_X_LSB,x
lda #>px lda #>px
sta MOUSE_X_MSB,X sta MOUSE_X_MSB,x
lda #<py lda #<py
sta MOUSE_Y_LSB,X sta MOUSE_Y_LSB,x
lda #>py lda #>py
sta MOUSE_Y_MSB,X sta MOUSE_Y_MSB,x
jsr POSMOUSE MOUSE_CALL PosMouse
.endmacro
;;;----------------------------------------
.macro DoSetMouse mode
;;;----------------------------------------
lda #mode
MOUSE_CALL SetMouse
.endmacro .endmacro
@ -110,183 +150,131 @@ MOUSE_CENTER_Y := $2f
;;; Reference: http://home.swbell.net/rubywand/R034MOUSEPRG.TXT ;;; Reference: http://home.swbell.net/rubywand/R034MOUSEPRG.TXT
sei ; No interrupts while we're getting set up sei ; No interrupts while we're getting set up
;
;;; Step 1: Find the mouse card by scanning slots for ID bytes ;; Find mouse card by scanning slots for ID bytes
;
ldy #MAX_SLOT ; Start search in slot 7 ldy #MAX_SLOT ; Start search in slot 7
TESTSLOT: slot_loop:
sty MOUSE_SLOT ; Save for later sty mouse_slot ; Save for later
tya tya
clc clc
adc #>SLOT_BASE ; Firmware is $c0 + slot adc #>SLOT_BASE ; Firmware is $Cn
sta slot_addr + 1 ; Update msb of signature test sta slot_addr + 1 ; Update msb of signature test
ldx #MOUSEID_MAX ; This many signature bytes ldx #MOUSEID_MAX ; This many signature bytes
TESTID: : lda MOUSEID_ADDR,x
lda MOUSEID_ADDR,x sta slot_addr ; Update lsb of signature test
sta MOD_MOUSE_ID + 1 ; Update lsb of signature test
slot_addr := *+1 slot_addr := *+1
lda SLOT_BASE ; Self-modified lda SLOT_BASE ; Self-modified
cmp MOUSEID_VAL,x ; Does it match the signature? cmp MOUSEID_VAL,x ; Does it match the signature?
bne NOMATCH ; Nope - try the next slot bne no_match ; Nope - try the next slot
dex ; Yes! Keep testing dex ; Yes! Keep testing
bpl TESTID ; Fall through if all done bpl :- ; Fall through if all done
jmp FOUND_MOUSE jmp found
NOMATCH: no_match:
dey ; Didn't match dey ; Didn't match
bne TESTSLOT ; Keep looking until slot 0 bne slot_loop ; Keep looking until slot 0
sty MOUSE_SLOT ; Oops, no mouse - make a note sty mouse_slot ; Oops, no mouse - make a note
rts ; and bail rts ; and bail
; ;; Store results needed for call ($Cn and $n0)
;;; Step 2: Set up indirect calling routines
;
FOUND_MOUSE: found: tya ; Slot is in y
; Slot is in y ora #>SLOT_BASE ; Compute $Cn - needed for calls
sta mouse_fw_hi
tya tya
ora #>SLOT_BASE ; Compute $Cn - needed for asl ; Compute $n0 - needed for calls
sta MOUSEPTR+1 ; MSB of MOUSEPTR ($Cn00)
sta TOMOUSE_Cn ; X register before firmware calls
sta TOMOUSE_msb ; MSB of firmware calls
lda #0
sta MOUSEPTR ; LSB of MOUSEPTR ($Cn00)
tya
asl ; Compute $n0 - needed for
asl asl
asl asl
asl asl
sta TOMOUSE_n0 ; Y register before firmware calls sta mouse_op
; ;; Initialize and configure mouse card
;;; Step 3: Configure the mouse card
;
;;; Initialize the mouse for use MOUSE_CALL InitMouse ; reset, clamp to 0-1023 x/y
jsr INITMOUSE ; reset, clamp to 0-1023 x/y
lda #1 ; mouse on, no interrupts DoSetMouse $01 ; mouse on, no interrupts
jsr SETMOUSE ; TODO: test carry bit result (set = error) ; TODO: test carry bit result (set = error)
;
;;; Since we want deltas, clamp and center ;; Clamp for deltas
; DoClampMouse MOUSE_CLAMP_X, MOUSE_CLAMP_MIN, MOUSE_CLAMP_MAX
ClampMouse MOUSE_CLAMP_X, MOUSE_MIN_X, MOUSE_MAX_X DoClampMouse MOUSE_CLAMP_Y, MOUSE_CLAMP_MIN, MOUSE_CLAMP_MAX
ClampMouse MOUSE_CLAMP_Y, MOUSE_MIN_Y, MOUSE_MAX_Y
PosMouse MOUSE_CENTER_X, MOUSE_CENTER_Y DoPosMouse MOUSE_CENTER, MOUSE_CENTER
cli ; Enable interrupts so mouse can function cli ; Enable interrupts so mouse can function
rts rts
.endproc .endproc
;;;--------------------------------------------------
;;; Indirect jump table for mouse firmware routines
;;;-------------------------------------------------- ;;;--------------------------------------------------
;;; Call mouse firmware, param in A, routine in Y
SETMOUSE: ldy #$12 .proc CallMouse
jmp GoMouse pha ; Save A (param)
SERVEMOUSE: ldy #$13 ldx mouse_fw_hi ; $Cn
jmp GoMouse stx mouse_ptr+1
READMOUSE: ldy #$14 lda #0
jmp GoMouse sta mouse_ptr
CLEARMOUSE: ldy #$15 lda (mouse_ptr),y ; Look up routine offset
jmp GoMouse sta mouse_ptr
POSMOUSE: ldy #$16
jmp GoMouse
CLAMPMOUSE: ldy #$17
jmp GoMouse
HOMEMOUSE: ldy #$18
jmp GoMouse
INITMOUSE: ldy #$19
jmp GoMouse
;;;-------------------------------------------------- pla ; param in A
ldy mouse_op ; $n0 in Y
.proc GoMouse php
tax ; Preserve the value in A sei
lda (MOUSEPTR),Y ; Get the routine entry point jsr call
sta TOMOUSE_lsb ; Patch the JMP instruction plp
txa ; Restore the value in A
;;; The following operand bytes must be patched by the
;;; initialization code which detects the mouse.
BANK := $C054
TOMOUSE:
TOMOUSE_Cn := *+1
ldx #$C1 ; Set up slot in $Cn form in X
TOMOUSE_n0 := *+1
ldy #$10 ; Set up slot in $n0 form in Y
php ; Save interrupt state
sei ; No interrupts while calling
bit BANK
TOMOUSE_slot := *+1
jsr 0 ; Go to the mouse routine
plp ; Restore interrupt state
rts rts
call: jmp (mouse_ptr)
.endproc .endproc
TOMOUSE_Cn := GoMouse::TOMOUSE_Cn
TOMOUSE_n0 := GoMouse::TOMOUSE_n0
TOMOUSE_lsb := GoMouse::TOMOUSE_slot
TOMOUSE_msb := GoMouse::TOMOUSE_slot+1
;;; TODO: Turn this into a proper delta-sending routine
;;;-------------------------------------------------- ;;;--------------------------------------------------
.proc FOOMOUSE ;;; Read mouse pos, send deltas, and recenter
txa ; save x .proc SendMouse
pha SaveRegisters
tya ; save y lda mouse_slot
pha beq done
jsr READMOUSE MOUSE_CALL ReadMouse
jmp DONE
ldx MOUSE_SLOT
lda Protocol::MouseX
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
ldx mouse_slot
lda MOUSE_X_LSB,x lda MOUSE_X_LSB,x
sta LAST_MX ora MOUSE_POS_MASK
jsr SSC::Put
lda Protocol::MouseY
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
ldx mouse_slot
lda MOUSE_Y_LSB,x lda MOUSE_Y_LSB,x
sta LAST_MY ora MOUSE_POS_MASK
lda LAST_MX
cmp #MOUSE_CENTER_X
bne SEND
lda LAST_MY
cmp #MOUSE_CENTER_Y
beq DONE
SEND:
lda LAST_MX
ora #SIS_MX
jsr SSC::Put
lda LAST_MY
ora #SIS_MY
jsr SSC::Put jsr SSC::Put
PosMouse MOUSE_CENTER_X, MOUSE_CENTER_Y lda Protocol::MouseBtn
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
ldx mouse_slot
lda MOUSE_STATUS,x
jsr SSC::Put
DONE: DoPosMouse MOUSE_CENTER, MOUSE_CENTER
pla ; restore y
tay done: RestoreRegisters
pla ; restore x
tax
rts rts
.endproc .endproc
.endproc .endproc