reformat, dedupe

This commit is contained in:
Joshua Bell 2018-10-28 22:23:33 -07:00
parent efeff6cdb9
commit 684b82ca56
6 changed files with 801 additions and 864 deletions

Binary file not shown.

View File

@ -2,10 +2,16 @@ ca65 V2.16 - Git f5e9b401
Main file : client.s
Current file: client.s
000000r 1 PADDLE_SUPPORT = 1
000000r 1 ;;;-------------------------------------------------------------------
000000r 1 ;;;
000000r 1 ;;; vnIIc Client Application
000000r 1 ;;;
000000r 1 ;;;-------------------------------------------------------------------
000000r 1
000000r 1 PADDLE_SUPPORT = 1
000000r 1 ;;; MOUSE_SUPPORT = 1
000000r 1
000000r 1 .include "apple2.inc"
000000r 1 .include "apple2.inc"
000000r 2
000000r 2 ;-----------------------------------------------------------------------------
000000r 2 ; Zero page stuff
@ -72,66 +78,68 @@ Current file: client.s
000000r 2 BUTN1 := $C062 ; Closed-Apple Key
000000r 2
000000r 1
000000r 1 .include "macros.inc"
000000r 2 ;;;---------------------------------------------------------
000000r 2 ;;;
000000r 2 ;;; Generic Macros
000000r 2 ;;;
000000r 2 ;;;---------------------------------------------------------
000000r 2
000000r 2 .macro SaveRegisters
000000r 2 pha
000000r 2 txa
000000r 2 pha
000000r 2 tya
000000r 2 pha
000000r 2 .endmacro
000000r 2
000000r 2 .macro RestoreRegisters
000000r 2 pla
000000r 2 tay
000000r 2 pla
000000r 2 tax
000000r 2 pla
000000r 2 .endmacro
000000r 2
000000r 1
000000r 1 ;;;---------------------------------------------------------
000000r 1 ;;; Hi-res graphics constants/locations
000000r 1 ;;;---------------------------------------------------------
000000r 1
000000r 1 PLOTPAGE := $E6 ; Active hires plotting page (Applesoft)
000000r 1 PLOTPAGE1 := $20
000000r 1 PLOTPAGE2 := $40
000000r 1 PAGESIZE := $20 ; Size of hi-res screen in pages
000000r 1 PAGE := $E6 ; Active hires plotting page (Applesoft)
000000r 1 PAGE1 := $20
000000r 1 PAGE2 := $40
000000r 1
000000r 1 PAGESIZE := $20 ; Size of hi-res screen in pages
000000r 1
000000r 1 ;;;---------------------------------------------------------
000000r 1 ;;; ROM routines
000000r 1 ;;;---------------------------------------------------------
000000r 1
000000r 1 PREAD := $FB1E ; Monitor paddle reading routine, call
000000r 1 ; with paddle # in X, returns value in Y
000000r 1 PREAD := $FB1E ; Monitor paddle reading routine, call
000000r 1 ; with paddle # in X, returns value in Y
000000r 1
000000r 1 HCLR := $F3F2 ; Clear current hires screen to black
000000r 1
000000r 1 ;;;---------------------------------------------------------
000000r 1 ;;; Other
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 ZP_PTR := $FA ; Write cursor location on zero page
000000r 1
000000r 1 ;;;---------------------------------------------------------
000000r 1 ;;; Generic Macros
000000r 1 ;;;---------------------------------------------------------
000000r 1
000000r 1 ;;;----------------------------------------
000000r 1 .macro SaveRegisters
000000r 1 ;;;----------------------------------------
000000r 1 pha
000000r 1 txa
000000r 1 pha
000000r 1 tya
000000r 1 pha
000000r 1 .endmacro
000000r 1
000000r 1 ;;;----------------------------------------
000000r 1 .macro RestoreRegisters
000000r 1 ;;;----------------------------------------
000000r 1 pla
000000r 1 tay
000000r 1 pla
000000r 1 tax
000000r 1 pla
000000r 1 .endmacro
000000r 1 ZP_PTR := $FA ; Write cursor location on zero page
000000r 1
000000r 1
000000r 1 ;;;-------------------------------------------------------------------
000000r 1 ;;;
000000r 1 ;;; Application-level logic
000000r 1 ;;; Client Code
000000r 1 ;;;
000000r 1 ;;;-------------------------------------------------------------------
000000r 1
000000r 1
000000r 1 .org $6000
006000 1 4C 60 60 jmp AppEntry
000000r 1 .org $6000
006000 1 4C 60 60 jmp AppEntry
006003 1
006003 1 .include "ssc.inc"
006003 1 .include "ssc.inc"
006003 2 ;;;-------------------------------------------------------------------
006003 2 ;;;
006003 2 ;;; Serial port routines
@ -147,118 +155,113 @@ Current file: client.s
006003 2 ;;;---------------------------------------------------------
006003 2
006003 2 ;;; These get incremented by the slot where they appear
006003 2 UACTRL = $C08B ; Control Register
006003 2 UACMND = $C08A ; Command Register
006003 2 UASTAT = $C089 ; Status Register
006003 2 UADATA = $C088 ; Data Register - incoming and outgoing data
006003 2 UACTRL = $C08B ; Control Register
006003 2 UACMND = $C08A ; Command Register
006003 2 UASTAT = $C089 ; Status Register
006003 2 UADATA = $C088 ; Data Register - incoming and outgoing data
006003 2
006003 2 ;;; Lookup table for UACTRL register, by baud rate
006003 2
006003 2 16 1E 1F 10 BPSCTRL: .byte $16,$1E,$1F,$10 ; 300, 9600, 19200, 115k (with 8 data bits, 1 stop bit, no echo)
006007 2 .enum
006007 2 BPS_300
006007 2 BPS_9600
006007 2 BPS_19200
006007 2 BPS_115k
006007 2 .endenum
006003 2 16 1E 1F 10 BPSCTRL: .byte $16,$1E,$1F,$10 ; 300, 9600, 19200, 115k (with 8 data bits, 1 stop bit, no echo)
006007 2 .enum
006007 2 BPS_300
006007 2 BPS_9600
006007 2 BPS_19200
006007 2 BPS_115k
006007 2 .endenum
006007 2
006007 2 CMND_NRDI = $0B ; Command: no parity, RTS on, DTR on, no interrupts
006007 2 CMND_NRDI = $0B ; Command: no parity, RTS on, DTR on, no interrupts
006007 2
006007 2
006007 2 ;;;---------------------------------------------------------
006007 2 .proc Init
006007 2 ;;;---------------------------------------------------------
006007 2 ;;; Initialize the SSC; slot passed in A
006007 2 ;;;---------------------------------------------------------
006007 2 0A asl ; Slot passed in A
006008 2 0A asl
006009 2 0A asl
00600A 2 0A asl ; Now $S0
00600B 2 69 88 adc #$88 ; Low byte of UADATA
00600D 2 AA tax
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
006013 2 AC 58 60 ldy PSPEED ; Control register: look up by baud rate (8 data bits, 1 stop bit)
006016 2 B9 03 60 lda BPSCTRL,Y
006019 2 9D 03 C0 sta $C003,X
00601C 2 8E 3C 60 stx MOD_UADATA_1 ; Modify references to
00601F 2 8E 49 60 stx MOD_UADATA_2 ; UADATA to point at
006022 2 8E 55 60 stx MOD_UADATA_3 ; correct slot (UADATA+S0)
006025 2 E8 inx
006026 2 8E 32 60 stx MOD_UASTAT_1 ; Modify reference to
006029 2 8E 40 60 stx MOD_UASTAT_2 ; UASTAT to point at
00602C 2 8E 4D 60 stx MOD_UASTAT_3 ; correct slot (UASTAT+S0)
00602F 2 60 rts
006007 2
006007 2 .proc Init
006007 2 0A asl ; Slot passed in A
006008 2 0A asl
006009 2 0A asl
00600A 2 0A asl ; Now $S0
00600B 2 69 88 adc #$88 ; Low byte of UADATA
00600D 2 AA tax
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
006013 2 AC 58 60 ldy PSPEED ; Control register: look up by baud rate (8 data bits, 1 stop bit)
006016 2 B9 03 60 lda BPSCTRL,Y
006019 2 9D 03 C0 sta $C003,X
00601C 2 8E 3C 60 stx MOD_UADATA_1 ; Modify references to
00601F 2 8E 49 60 stx MOD_UADATA_2 ; UADATA to point at
006022 2 8E 55 60 stx MOD_UADATA_3 ; correct slot (UADATA+S0)
006025 2 E8 inx
006026 2 8E 32 60 stx MOD_UASTAT_1 ; Modify reference to
006029 2 8E 40 60 stx MOD_UASTAT_2 ; UASTAT to point at
00602C 2 8E 4D 60 stx MOD_UASTAT_3 ; correct slot (UASTAT+S0)
00602F 2 60 rts
006030 2 .endproc
006030 2
006030 2
006030 2 ;;;---------------------------------------------------------
006030 2 .proc Put
006030 2 ;;;---------------------------------------------------------
006030 2 ;;; Send accumulator out the serial port
006030 2 ;;;---------------------------------------------------------
006030 2 48 pha ; Push A onto the stack
006031 2 MOD_UASTAT_1 := *+1
006031 2 AD 89 C0 : lda UASTAT ; Check status bits
006034 2 29 70 and #$70
006036 2 C9 10 cmp #$10
006038 2 D0 F7 bne :- ; Output register is full, so loop
00603A 2 68 pla
00603B 2 MOD_UADATA_1 := *+1
00603B 2 8D 88 C0 sta UADATA ; Put character
00603E 2 60 rts
006030 2
006030 2 .proc Put
006030 2 48 pha ; Push A onto the stack
006031 2 MOD_UASTAT_1 := *+1
006031 2 AD 89 C0 : lda UASTAT ; Check status bits
006034 2 29 70 and #$70
006036 2 C9 10 cmp #$10
006038 2 D0 F7 bne :- ; Output register is full, so loop
00603A 2 68 pla
00603B 2 MOD_UADATA_1 := *+1
00603B 2 8D 88 C0 sta UADATA ; Put character
00603E 2 60 rts
00603F 2 .endproc
00603F 2 MOD_UASTAT_1 := Put::MOD_UASTAT_1
00603F 2 MOD_UADATA_1 := Put::MOD_UADATA_1
00603F 2 MOD_UASTAT_1 := Put::MOD_UASTAT_1
00603F 2 MOD_UADATA_1 := Put::MOD_UADATA_1
00603F 2
00603F 2 ;;;---------------------------------------------------------
00603F 2 .proc Get
00603F 2 ;;;---------------------------------------------------------
00603F 2 ;;; Read a character from the serial port to the accumulator
00603F 2 ;;;---------------------------------------------------------
00603F 2 MOD_UASTAT_2 := *+1
00603F 2 AD 89 C0 lda UASTAT ; Check status bits
006042 2 29 68 and #$68
006044 2 C9 08 cmp #$8
006046 2 D0 F7 bne Get ; Input register empty, loop
006048 2 MOD_UADATA_2 := *+1
006048 2 AD 88 C0 lda UADATA ; Get character
00604B 2 60 rts
00603F 2
00603F 2 .proc Get
00603F 2 MOD_UASTAT_2 := *+1
00603F 2 AD 89 C0 lda UASTAT ; Check status bits
006042 2 29 68 and #$68
006044 2 C9 08 cmp #$8
006046 2 D0 F7 bne Get ; Input register empty, loop
006048 2 MOD_UADATA_2 := *+1
006048 2 AD 88 C0 lda UADATA ; Get character
00604B 2 60 rts
00604C 2 .endproc
00604C 2 MOD_UASTAT_2 := Get::MOD_UASTAT_2
00604C 2 MOD_UADATA_2 := Get::MOD_UADATA_2
00604C 2 MOD_UASTAT_2 := Get::MOD_UASTAT_2
00604C 2 MOD_UADATA_2 := Get::MOD_UADATA_2
00604C 2
00604C 2 ;;;---------------------------------------------------------
00604C 2 ;;; Check if the serial port has pending data
00604C 2
00604C 2 .proc HasData
00604C 2 ;;;---------------------------------------------------------
00604C 2 ;;; Read a character from the serial port to the accumulator
00604C 2 ;;;---------------------------------------------------------
00604C 2 MOD_UASTAT_3 := *+1
00604C 2 AD 89 C0 lda UASTAT ; Check status bits
00604F 2 29 68 and #$68
006051 2 C9 08 cmp #$8
006053 2 60 rts
00604C 2 MOD_UASTAT_3 := *+1
00604C 2 AD 89 C0 lda UASTAT ; Check status bits
00604F 2 29 68 and #$68
006051 2 C9 08 cmp #$8
006053 2 60 rts
006054 2 .endproc
006054 2 MOD_UASTAT_3 := HasData::MOD_UASTAT_3
006054 2 MOD_UASTAT_3 := HasData::MOD_UASTAT_3
006054 2
006054 2
006054 2 ;;;---------------------------------------------------------
006054 2 .proc Reset
006054 2 ;;;---------------------------------------------------------
006054 2 ;;; Clean up serial port
006054 2 ;;;---------------------------------------------------------
006054 2 MOD_UADATA_3 := *+1
006054 2 2C 88 C0 bit UADATA
006057 2 60 rts
006054 2
006054 2 .proc Reset
006054 2 MOD_UADATA_3 := *+1
006054 2 2C 88 C0 bit UADATA
006057 2 60 rts
006058 2 .endproc
006058 2 MOD_UADATA_3 := Reset::MOD_UADATA_3
006058 2 MOD_UADATA_3 := Reset::MOD_UADATA_3
006058 2
006058 2 .endproc
006058 2
006058 1
006058 1 .ifdef MOUSE_SUPPORT
006058 1 .ifdef MOUSE_SUPPORT
006058 1 .include "mouse.inc"
006058 1 .endif ; MOUSE_SUPPORT
006058 1 .endif
006058 1
006058 1
006058 1 ;;;-------------------------------------------------------------------
@ -266,47 +269,45 @@ Current file: client.s
006058 1 ;;;-------------------------------------------------------------------
006058 1
006058 1 ;;; Application configuration
006058 1 03 PSPEED: .byte SSC::BPS_115k ; Hardcoded for Apple IIc (TODO: Allow configuration)
006059 1 02 PSLOT: .byte 2 ; Hardcoded for Apple IIc (TODO: Allow configuration)
00605A 1 00 PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemented)
006058 1 03 PSPEED: .byte SSC::BPS_115k ; Hardcoded for Apple IIc (TODO: Allow configuration)
006059 1 02 PSLOT: .byte 2 ; Hardcoded for Apple IIc (TODO: Allow configuration)
00605A 1 00 PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemented)
00605B 1
00605B 1 ;;; Keyboard state
00605B 1 00 LASTKB: .byte 0
00605C 1 00 LASTOA: .byte 0
00605D 1 00 LASTCA: .byte 0
00605B 1 00 LASTKB: .byte 0
00605C 1 00 LASTOA: .byte 0
00605D 1 00 LASTCA: .byte 0
00605E 1
00605E 1 .ifdef PADDLE_SUPPORT
00605E 1 .ifdef PADDLE_SUPPORT
00605E 1
00605E 1 ;;; Paddle state
00605E 1 00 LASTP0: .byte 0
00605F 1 00 LASTP1: .byte 0
00605E 1 00 LASTP0: .byte 0
00605F 1 00 LASTP1: .byte 0
006060 1
006060 1 .endif ; PADDLE_SUPPORT
006060 1 .endif ; PADDLE_SUPPORT
006060 1
006060 1
006060 1 ;;;---------------------------------------------------------
006060 1 .proc AppEntry
006060 1 ;;;---------------------------------------------------------
006060 1 ;;; Initialize the application, and enter the main loop
006060 1 ;;;---------------------------------------------------------
006060 1 AD 59 60 lda PSLOT ; Use slot 2
006063 1 20 07 60 jsr SSC::Init ; Initialize Super Serial Card
006066 1 20 8C 61 jsr InitHires ; Initialize Hi-Res graphics
006069 1 20 A0 60 jsr InitInput ; Initialize input devices
00606C 1 20 79 60 jsr MainLoop
006060 1
006060 1 .proc AppEntry
006060 1 AD 59 60 lda PSLOT ; Use slot 2
006063 1 20 07 60 jsr SSC::Init ; Initialize Super Serial Card
006066 1 20 8C 61 jsr InitHires ; Initialize Hi-Res graphics
006069 1 20 A0 60 jsr InitInput ; Initialize input devices
00606C 1 20 79 60 jsr MainLoop
00606F 1
00606F 1 ; fall through
00606F 1 ; fall through
00606F 1 .endproc
00606F 1
00606F 1 ;;;---------------------------------------------------------
00606F 1 .proc AppExit
00606F 1 ;;;---------------------------------------------------------
00606F 1 ;;; Clean up and exit app
00606F 1 ;;;---------------------------------------------------------
00606F 1 20 54 60 jsr SSC::Reset
006072 1 8D 54 C0 sta LOWSCR
006075 1 8D 51 C0 sta TXTSET
006078 1 60 rts
00606F 1
00606F 1 .proc AppExit
00606F 1 20 54 60 jsr SSC::Reset
006072 1 8D 54 C0 sta LOWSCR
006075 1 8D 51 C0 sta TXTSET
006078 1 60 rts
006079 1 .endproc
006079 1
006079 1
@ -319,48 +320,45 @@ Current file: client.s
006079 1
006079 1 ;;;---------------------------------------------------------
006079 1 .proc MainLoop
006079 1 ;;;---------------------------------------------------------
006079 1
006079 1 ;;; TODO: Sort out the protocol - should be able to send
006079 1 ;;; input state without receiving data
006079 1 ;;; jsr SSCHasData ; Anything to read?
006079 1 ;;; jsr SSC::HasData ; Anything to read?
006079 1 ;;; bne :+ ; Nope
006079 1
006079 1 20 83 60 : jsr ReceivePage
00607C 1 20 A3 61 jsr FlipHires
00607F 1 4C 79 60 jmp :- ; TODO: define an exit trigger
006082 1 60 rts
006079 1 20 83 60 : jsr ReceivePage
00607C 1 20 A3 61 jsr FlipHires
00607F 1 4C 79 60 jmp :- ; TODO: define an exit trigger
006082 1 60 rts
006083 1 .endproc
006083 1
006083 1
006083 1 ;;;---------------------------------------------------------
006083 1 .proc ReceivePage
006083 1 ;;;---------------------------------------------------------
006083 1 ;;; Pull a hi-res page down over serial
006083 1 ;;;
006083 1 ;;; Protocol is:
006083 1 ;;; * Recieve 256 bytes (graphic data)
006083 1 ;;; * Send 1 byte (input state)
006083 1 ;;;---------------------------------------------------------
006083 1
006083 1 A9 00 lda #0 ; set up write pointer
006085 1 85 FA sta ZP_PTR
006087 1 A5 E6 lda PLOTPAGE
006089 1 85 FB sta ZP_PTR+1
00608B 1 A2 20 ldx #PAGESIZE ; plan to receive this many pages
00608D 1 A0 00 ldy #0
006083 1 .proc ReceivePage
006083 1 A9 00 lda #0 ; set up write pointer
006085 1 85 FA sta ZP_PTR
006087 1 A5 E6 lda PAGE
006089 1 85 FB sta ZP_PTR+1
00608B 1 A2 20 ldx #PAGESIZE ; plan to receive this many pages
00608D 1 A0 00 ldy #0
00608F 1
00608F 1 20 3F 60 : jsr SSC::Get ; TODO: look for escape codes in the sequence
006092 1 91 FA sta (ZP_PTR),Y
006094 1 C8 iny
006095 1 D0 F8 bne :- ; Do a full page...
00608F 1 20 3F 60 : jsr SSC::Get ; TODO: look for escape codes in the sequence
006092 1 91 FA sta (ZP_PTR),Y
006094 1 C8 iny
006095 1 D0 F8 bne :- ; Do a full page...
006097 1
006097 1 20 BE 60 jsr SendInputState ; brief moment to send data back upstream
006097 1 20 BE 60 jsr SendInputState ; brief moment to send data back upstream
00609A 1
00609A 1 E6 FB inc ZP_PTR+1
00609C 1 CA dex
00609D 1 D0 F0 bne :- ; ...as many pages as we need
00609F 1 60 rts
00609A 1 E6 FB inc ZP_PTR+1
00609C 1 CA dex
00609D 1 D0 F0 bne :- ; ...as many pages as we need
00609F 1 60 rts
0060A0 1 .endproc
0060A0 1
0060A0 1
@ -373,61 +371,58 @@ Current file: client.s
0060A0 1 ;;; $7f - $ff - key down, ASCII code + $80
0060A0 1 ;;; otherwise, a transition:
0060A0 1 ;;;
0060A0 1 SIS_KBUP = $00 ; Key up
0060A0 1 SIS_OADOWN = $01 ; Open Apple transitioned to down
0060A0 1 SIS_OAUP = $02 ; Open Apple transitioned to up
0060A0 1 SIS_CADOWN = $03 ; Closed Apple transitioned to down
0060A0 1 SIS_CAUP = $04 ; Closed Apple transitioned to up
0060A0 1 SIS_KBUP = $00 ; Key up
0060A0 1 SIS_OADOWN = $01 ; Open Apple transitioned to down
0060A0 1 SIS_OAUP = $02 ; Open Apple transitioned to up
0060A0 1 SIS_CADOWN = $03 ; Closed Apple transitioned to down
0060A0 1 SIS_CAUP = $04 ; Closed Apple transitioned to up
0060A0 1 ;;;
0060A0 1 ;;; $05 - $0f : reserved
0060A0 1 ;;;
0060A0 1 SIS_MX = $10 ; Mouse X high nibble
0060A0 1 SIS_MY = $20 ; Mouse Y high nibble
0060A0 1 SIS_PDL0 = $30 ; Paddle 0 high nibble
0060A0 1 SIS_PDL1 = $40 ; Paddle 1 high nibble
0060A0 1 SIS_MX = $10 ; Mouse X high nibble
0060A0 1 SIS_MY = $20 ; Mouse Y high nibble
0060A0 1 SIS_PDL0 = $30 ; Paddle 0 high nibble
0060A0 1 SIS_PDL1 = $40 ; Paddle 1 high nibble
0060A0 1 ;;;
0060A0 1 ;;; $50 - $7e : reserved
0060A0 1 ;;;
0060A0 1 SIS_SYNC = $7f
0060A0 1 SIS_SYNC = $7f
0060A0 1
0060A0 1 ;;;---------------------------------------------------------
0060A0 1 .proc InitInput
0060A0 1 ;;;---------------------------------------------------------
0060A0 1 ;;; Initialize input devices and storage for detecting
0060A0 1 ;;; state transitions
0060A0 1 ;;;---------------------------------------------------------
0060A0 1
0060A0 1 .proc InitInput
0060A0 1
0060A0 1 ;;; Init keyboard state
0060A0 1 A9 00 lda #SIS_KBUP
0060A2 1 8D 5B 60 sta LASTKB
0060A0 1 A9 00 lda #SIS_KBUP
0060A2 1 8D 5B 60 sta LASTKB
0060A5 1
0060A5 1 ;;; Init Open/Closed Apple states
0060A5 1 A9 02 lda #SIS_OAUP ; NOTE: Don't store OA state as it fluctuates
0060A7 1 8D 5C 60 sta LASTOA
0060AA 1 A9 04 lda #SIS_CAUP ; NOTE: Don't store CA state as it fluctuates
0060AC 1 8D 5D 60 sta LASTCA
0060A5 1 A9 02 lda #SIS_OAUP ; NOTE: Don't store OA state as it fluctuates
0060A7 1 8D 5C 60 sta LASTOA
0060AA 1 A9 04 lda #SIS_CAUP ; NOTE: Don't store CA state as it fluctuates
0060AC 1 8D 5D 60 sta LASTCA
0060AF 1
0060AF 1 .ifdef PADDLE_SUPPORT
0060AF 1 .ifdef PADDLE_SUPPORT
0060AF 1 ;;; Init Paddle state
0060AF 1 A9 30 lda #SIS_PDL0
0060B1 1 09 08 ora #8 ; Middle of range 0...15
0060B3 1 8D 5E 60 sta LASTP0
0060B6 1 A9 40 lda #SIS_PDL1
0060B8 1 09 08 ora #8 ; Middle of range 0...15
0060BA 1 8D 5F 60 sta LASTP1
0060BD 1 .endif
0060AF 1 A9 30 lda #SIS_PDL0
0060B1 1 09 08 ora #8 ; Middle of range 0...15
0060B3 1 8D 5E 60 sta LASTP0
0060B6 1 A9 40 lda #SIS_PDL1
0060B8 1 09 08 ora #8 ; Middle of range 0...15
0060BA 1 8D 5F 60 sta LASTP1
0060BD 1 .endif
0060BD 1
0060BD 1 .ifdef MOUSE_SUPPORT
0060BD 1 jsr Mouse::FindMouse
0060BD 1 .endif
0060BD 1 .ifdef MOUSE_SUPPORT
0060BD 1 jsr Mouse::FindMouse
0060BD 1 .endif
0060BD 1
0060BD 1 60 rts
0060BD 1 60 rts
0060BE 1 .endproc
0060BE 1
0060BE 1
0060BE 1 ;;;---------------------------------------------------------
0060BE 1 .proc SendInputState
0060BE 1 ;;;---------------------------------------------------------
0060BE 1 ;;; Send keyboard joystick and/or mouse state over the
0060BE 1 ;;; serial port
0060BE 1 ;;;
@ -438,11 +433,12 @@ Current file: client.s
0060BE 1 ;;; - otherwise send paddle 0 state (if it changed)
0060BE 1 ;;; - (TODO: Mouse state)
0060BE 1 ;;; - otherwise send sync byte
0060BE 1 ;;;---------------------------------------------------------
0060BE 1
0060BE 1 48 8A 48 98 SaveRegisters ; Store registers
0060BE 1 .proc SendInputState
0060BE 1
0060BE 1 48 8A 48 98 SaveRegisters ; Store registers
0060C2 1 48
0060C3 1 18 clc
0060C3 1 18 clc
0060C4 1
0060C4 1 ;;;--------------------------------------
0060C4 1 ;;; Send key state, if it changed
@ -458,32 +454,32 @@ Current file: client.s
0060C4 1 ;;; Down - Down Save and send key ONLY if different
0060C4 1 ;;;
0060C4 1
0060C4 1 AD 5B 60 lda LASTKB
0060C7 1 D0 0E bne KEY_WAS_DOWN
0060C4 1 AD 5B 60 lda LASTKB
0060C7 1 D0 0E bne KEY_WAS_DOWN
0060C9 1
0060C9 1 KEY_WAS_UP:
0060C9 1 AD 00 C0 lda KBD ; Read keyboard
0060CC 1 10 27 bpl END_KEY ; - still up
0060CE 1 8D 5B 60 sta LASTKB ; Down, so save it
0060D1 1 20 30 60 jsr SSC::Put ; and send it
0060D4 1 4C 86 61 jmp DONE
0060C9 1 AD 00 C0 lda KBD ; Read keyboard
0060CC 1 10 27 bpl END_KEY ; - still up
0060CE 1 8D 5B 60 sta LASTKB ; Down, so save it
0060D1 1 20 30 60 jsr SSC::Put ; and send it
0060D4 1 4C 86 61 jmp DONE
0060D7 1
0060D7 1 KEY_WAS_DOWN:
0060D7 1 ; key was down - strobe should match
0060D7 1 ; unless the key changed or was released
0060D7 1 AD 10 C0 lda KBDSTRB
0060DA 1 30 0B bmi KBDSTRB_DOWN
0060D7 1 ; key was down - strobe should match
0060D7 1 ; unless the key changed or was released
0060D7 1 AD 10 C0 lda KBDSTRB
0060DA 1 30 0B bmi KBDSTRB_DOWN
0060DC 1 KBDSTRB_UP:
0060DC 1 A9 00 lda #SIS_KBUP ; Key was released
0060DE 1 8D 5B 60 sta LASTKB ; so save it
0060E1 1 20 30 60 jsr SSC::Put ; and send it
0060E4 1 4C 86 61 jmp DONE
0060DC 1 A9 00 lda #SIS_KBUP ; Key was released
0060DE 1 8D 5B 60 sta LASTKB ; so save it
0060E1 1 20 30 60 jsr SSC::Put ; and send it
0060E4 1 4C 86 61 jmp DONE
0060E7 1 KBDSTRB_DOWN:
0060E7 1 CD 5B 60 cmp LASTKB ; Same key as last time?
0060EA 1 F0 09 beq END_KEY ; - no change
0060EC 1 8D 5B 60 sta LASTKB ; New key, so save it
0060EF 1 20 30 60 jsr SSC::Put ; and send it
0060F2 1 4C 86 61 jmp DONE
0060E7 1 CD 5B 60 cmp LASTKB ; Same key as last time?
0060EA 1 F0 09 beq END_KEY ; - no change
0060EC 1 8D 5B 60 sta LASTKB ; New key, so save it
0060EF 1 20 30 60 jsr SSC::Put ; and send it
0060F2 1 4C 86 61 jmp DONE
0060F5 1
0060F5 1 END_KEY:
0060F5 1
@ -494,22 +490,22 @@ Current file: client.s
0060F5 1 ;;; for both OA states and bit = 0 down: lda BUTN0 ; ROL ; LDA #0 ; ROL ; ORA #signature
0060F5 1
0060F5 1 TEST_OA:
0060F5 1 AD 61 C0 lda BUTN0 ; Test Open Apple state
0060F8 1 30 10 bmi OA_IS_DOWN
0060F5 1 AD 61 C0 lda BUTN0 ; Test Open Apple state
0060F8 1 30 10 bmi OA_IS_DOWN
0060FA 1 OA_IS_UP:
0060FA 1 A9 02 lda #SIS_OAUP
0060FC 1 CD 5C 60 cmp LASTOA ; Changed?
0060FF 1 F0 19 beq END_OA ; Nope
006101 1 8D 5C 60 sta LASTOA ; Yes, save it / send it!
006104 1 20 30 60 jsr SSC::Put
006107 1 4C 86 61 jmp DONE
0060FA 1 A9 02 lda #SIS_OAUP
0060FC 1 CD 5C 60 cmp LASTOA ; Changed?
0060FF 1 F0 19 beq END_OA ; Nope
006101 1 8D 5C 60 sta LASTOA ; Yes, save it / send it!
006104 1 20 30 60 jsr SSC::Put
006107 1 4C 86 61 jmp DONE
00610A 1 OA_IS_DOWN:
00610A 1 A9 01 lda #SIS_OADOWN
00610C 1 CD 5C 60 cmp LASTOA ; Changed?
00610F 1 F0 09 beq END_OA ; Nope
006111 1 8D 5C 60 sta LASTOA ; Yes, save it / send it!
006114 1 20 30 60 jsr SSC::Put
006117 1 4C 86 61 jmp DONE
00610A 1 A9 01 lda #SIS_OADOWN
00610C 1 CD 5C 60 cmp LASTOA ; Changed?
00610F 1 F0 09 beq END_OA ; Nope
006111 1 8D 5C 60 sta LASTOA ; Yes, save it / send it!
006114 1 20 30 60 jsr SSC::Put
006117 1 4C 86 61 jmp DONE
00611A 1
00611A 1 END_OA:
00611A 1
@ -517,89 +513,89 @@ Current file: client.s
00611A 1 ;;; Send Closed Apple state, if it changed
00611A 1
00611A 1 TEST_CA:
00611A 1 AD 62 C0 lda BUTN1 ; Has the Open Apple/Button 1 value changed?
00611D 1 30 10 bmi CA_IS_DOWN
00611A 1 AD 62 C0 lda BUTN1 ; Has the Open Apple/Button 1 value changed?
00611D 1 30 10 bmi CA_IS_DOWN
00611F 1 CA_IS_UP:
00611F 1 A9 04 lda #SIS_CAUP
006121 1 CD 5D 60 cmp LASTCA ; Changed?
006124 1 F0 19 beq END_CA ; Nope
006126 1 8D 5D 60 sta LASTCA ; Yes, save it
006129 1 20 30 60 jsr SSC::Put ; and send it
00612C 1 4C 86 61 jmp DONE
00611F 1 A9 04 lda #SIS_CAUP
006121 1 CD 5D 60 cmp LASTCA ; Changed?
006124 1 F0 19 beq END_CA ; Nope
006126 1 8D 5D 60 sta LASTCA ; Yes, save it
006129 1 20 30 60 jsr SSC::Put ; and send it
00612C 1 4C 86 61 jmp DONE
00612F 1 CA_IS_DOWN:
00612F 1 A9 03 lda #SIS_CADOWN
006131 1 CD 5D 60 cmp LASTCA ; Changed?
006134 1 F0 09 beq END_CA ; Nope
006136 1 8D 5D 60 sta LASTCA ; Yes, save it
006139 1 20 30 60 jsr SSC::Put ; and send it
00613C 1 4C 86 61 jmp DONE
00612F 1 A9 03 lda #SIS_CADOWN
006131 1 CD 5D 60 cmp LASTCA ; Changed?
006134 1 F0 09 beq END_CA ; Nope
006136 1 8D 5D 60 sta LASTCA ; Yes, save it
006139 1 20 30 60 jsr SSC::Put ; and send it
00613C 1 4C 86 61 jmp DONE
00613F 1
00613F 1 END_CA:
00613F 1
00613F 1 .ifdef PADDLE_SUPPORT
00613F 1 .ifdef PADDLE_SUPPORT
00613F 1
00613F 1 ;;;--------------------------------------
00613F 1 ;;; Send Paddle 0 state, if it changed
00613F 1 TEST_PDL0:
00613F 1 A2 00 ldx #0
006141 1 20 1E FB jsr PREAD
006144 1 98 tya
006145 1 4A lsr ; Shift to low nibble
006146 1 4A lsr
006147 1 4A lsr
006148 1 4A lsr
006149 1 09 30 ora #SIS_PDL0 ; And mark it with the signature
00614B 1 CD 5E 60 cmp LASTP0 ; Change?
00614E 1 F0 09 beq END_PDL0 ; Nope
006150 1 8D 5E 60 sta LASTP0 ; Yes, save it
006153 1 20 30 60 jsr SSC::Put ; and send it
006156 1 4C 86 61 jmp DONE
00613F 1 A2 00 ldx #0
006141 1 20 1E FB jsr PREAD
006144 1 98 tya
006145 1 4A lsr ; Shift to low nibble
006146 1 4A lsr
006147 1 4A lsr
006148 1 4A lsr
006149 1 09 30 ora #SIS_PDL0 ; And mark it with the signature
00614B 1 CD 5E 60 cmp LASTP0 ; Change?
00614E 1 F0 09 beq END_PDL0 ; Nope
006150 1 8D 5E 60 sta LASTP0 ; Yes, save it
006153 1 20 30 60 jsr SSC::Put ; and send it
006156 1 4C 86 61 jmp DONE
006159 1 END_PDL0:
006159 1 ; Chew up time so next paddle read will be correct
006159 1 ; TODO: Replace this with a "read both" strobes
006159 1 ; routine
006159 1 EA EA EA EA : .repeat 11 ; By experiment, need 11 NOPs.
006159 1 ; Chew up time so next paddle read will be correct
006159 1 ; TODO: Replace this with a "read both" strobes
006159 1 ; routine
006159 1 EA EA EA EA : .repeat 11 ; By experiment, need 11 NOPs.
00615D 1 EA EA EA EA
006161 1 EA EA EA
006164 1 nop
006164 1 .endrep
006164 1 C8 iny
006165 1 D0 F2 bne :-
006164 1 nop
006164 1 .endrep
006164 1 C8 iny
006165 1 D0 F2 bne :-
006167 1
006167 1 ;;;--------------------------------------
006167 1 ;;; Send Paddle 1 state, if it changed
006167 1 TEST_PDL1:
006167 1 A2 01 ldx #1
006169 1 20 1E FB jsr PREAD
00616C 1 98 tya
00616D 1 4A lsr ; Shift to low nibble
00616E 1 4A lsr
00616F 1 4A lsr
006170 1 4A lsr
006171 1 09 40 ora #SIS_PDL1 ; And mark it with the signature
006173 1 CD 5F 60 cmp LASTP1 ; Change?
006176 1 F0 09 beq END_PDL1 ; Nope
006178 1 8D 5F 60 sta LASTP1 ; Yes, save it
00617B 1 20 30 60 jsr SSC::Put ; and send it
00617E 1 4C 86 61 jmp DONE
006167 1 A2 01 ldx #1
006169 1 20 1E FB jsr PREAD
00616C 1 98 tya
00616D 1 4A lsr ; Shift to low nibble
00616E 1 4A lsr
00616F 1 4A lsr
006170 1 4A lsr
006171 1 09 40 ora #SIS_PDL1 ; And mark it with the signature
006173 1 CD 5F 60 cmp LASTP1 ; Change?
006176 1 F0 09 beq END_PDL1 ; Nope
006178 1 8D 5F 60 sta LASTP1 ; Yes, save it
00617B 1 20 30 60 jsr SSC::Put ; and send it
00617E 1 4C 86 61 jmp DONE
006181 1 END_PDL1:
006181 1 ; NOTE: No need to chew time like PDL0
006181 1 ; since data receive will make up for it; if we
006181 1 ; loop in SendInputState need to add it here
006181 1 ; NOTE: No need to chew time like PDL0
006181 1 ; since data receive will make up for it; if we
006181 1 ; loop in SendInputState need to add it here
006181 1
006181 1 .endif
006181 1 .endif
006181 1
006181 1
006181 1 ;;;--------------------------------------
006181 1 ;;; No state changes so send sync byte
006181 1
006181 1 A9 7F lda #SIS_SYNC
006183 1 20 30 60 jsr SSC::Put
006181 1 A9 7F lda #SIS_SYNC
006183 1 20 30 60 jsr SSC::Put
006186 1
006186 1 DONE:
006186 1 68 A8 68 AA RestoreRegisters
006186 1 68 A8 68 AA RestoreRegisters
00618A 1 68
00618B 1 60 rts
00618B 1 60 rts
00618C 1
00618C 1 .endproc
00618C 1
@ -611,66 +607,41 @@ Current file: client.s
00618C 1 ;;;-------------------------------------------------------------------
00618C 1
00618C 1 ;;;---------------------------------------------------------
00618C 1 .proc InitHires
00618C 1 ;;;---------------------------------------------------------
00618C 1 ;;; Set up the graphics display and pointers
00618C 1 ;;;---------------------------------------------------------
00618C 1 A9 20 lda #PLOTPAGE1 ; clear page 1
00618E 1 85 E6 sta PLOTPAGE
006190 1 20 B9 61 jsr ClearHires
00618C 1
00618C 1 .proc InitHires
00618C 1 A9 20 lda #PAGE1 ; clear page 1
00618E 1 85 E6 sta PAGE
006190 1 20 F2 F3 jsr HCLR
006193 1
006193 1 20 A3 61 jsr FlipHires ; then show it and flip to 2
006196 1 8D 57 C0 sta HIRES
006199 1 8D 50 C0 sta TXTCLR
00619C 1 8D 52 C0 sta MIXCLR
00619F 1 8D 54 C0 sta LOWSCR
006193 1 20 A3 61 jsr FlipHires ; then show it and flip to 2
006196 1 8D 57 C0 sta HIRES
006199 1 8D 50 C0 sta TXTCLR
00619C 1 8D 52 C0 sta MIXCLR
00619F 1 8D 54 C0 sta LOWSCR
0061A2 1
0061A2 1 60 rts
0061A2 1 60 rts
0061A3 1 .endproc
0061A3 1
0061A3 1
0061A3 1 ;;;---------------------------------------------------------
0061A3 1 .proc FlipHires
0061A3 1 ;;;---------------------------------------------------------
0061A3 1 ;;; Call when done with the current plotting page
0061A3 1 ;;; (selected in PLOTPAGE) and it will be shown and the
0061A3 1 ;;; (selected in PAGE) and it will be shown and the
0061A3 1 ;;; other page will be shown.
0061A3 1 ;;;---------------------------------------------------------
0061A3 1 A5 E6 lda PLOTPAGE ; plotting on which page?
0061A5 1 C9 20 cmp #PLOTPAGE1
0061A7 1 F0 08 beq :+
0061A3 1
0061A3 1 .proc FlipHires
0061A3 1 A5 E6 lda PAGE ; plotting on which page?
0061A5 1 C9 20 cmp #PAGE1
0061A7 1 F0 08 beq :+
0061A9 1
0061A9 1 8D 55 C0 sta HISCR ; page 2 - so show it
0061AC 1 A9 20 lda #PLOTPAGE1 ; and plot on page 1
0061AE 1 85 E6 sta PLOTPAGE
0061B0 1 60 rts
0061A9 1 8D 55 C0 sta HISCR ; page 2 - so show it
0061AC 1 A9 20 lda #PAGE1 ; and plot on page 1
0061AE 1 85 E6 sta PAGE
0061B0 1 60 rts
0061B1 1
0061B1 1 8D 54 C0 : sta LOWSCR ; page 1 - so show it
0061B4 1 A9 40 lda #PLOTPAGE2 ; and plot on page 2
0061B6 1 85 E6 sta PLOTPAGE
0061B8 1 60 rts
0061B1 1 8D 54 C0 : sta LOWSCR ; page 1 - so show it
0061B4 1 A9 40 lda #PAGE2 ; and plot on page 2
0061B6 1 85 E6 sta PAGE
0061B8 1 60 rts
0061B9 1 .endproc
0061B9 1
0061B9 1
0061B9 1 ;;;---------------------------------------------------------
0061B9 1 .proc ClearHires
0061B9 1 ;;;---------------------------------------------------------
0061B9 1 ;;; Clear hires plotting page (selected in PLOTPAGE) to
0061B9 1 ;;; black uses ZP_PTR; not terribly efficient
0061B9 1 ;;;---------------------------------------------------------
0061B9 1 A9 00 lda #0 ; Set up ZP_PTR as a pointer into the hires page
0061BB 1 85 FA sta ZP_PTR
0061BD 1 A5 E6 lda PLOTPAGE
0061BF 1 85 FB sta ZP_PTR+1
0061C1 1 A2 20 ldx #PAGESIZE ; Clear this many pages
0061C3 1 A9 00 lda #0 ; with black!
0061C5 1 A8 tay
0061C6 1 91 FA : sta (ZP_PTR),Y
0061C8 1 C8 iny
0061C9 1 D0 FB bne :-
0061CB 1 E6 FB inc ZP_PTR+1
0061CD 1 CA dex
0061CE 1 D0 F6 bne :-
0061D0 1 60 rts
0061D1 1 .endproc
0061D1 1

View File

@ -1,72 +1,58 @@
PADDLE_SUPPORT = 1
;;;-------------------------------------------------------------------
;;;
;;; vnIIc Client Application
;;;
;;;-------------------------------------------------------------------
PADDLE_SUPPORT = 1
;;; MOUSE_SUPPORT = 1
.include "apple2.inc"
.include "apple2.inc"
.include "macros.inc"
;;;---------------------------------------------------------
;;; Hi-res graphics constants/locations
;;;---------------------------------------------------------
PLOTPAGE := $E6 ; Active hires plotting page (Applesoft)
PLOTPAGE1 := $20
PLOTPAGE2 := $40
PAGESIZE := $20 ; Size of hi-res screen in pages
PAGE := $E6 ; Active hires plotting page (Applesoft)
PAGE1 := $20
PAGE2 := $40
PAGESIZE := $20 ; Size of hi-res screen in pages
;;;---------------------------------------------------------
;;; ROM routines
;;;---------------------------------------------------------
PREAD := $FB1E ; Monitor paddle reading routine, call
; with paddle # in X, returns value in Y
PREAD := $FB1E ; Monitor paddle reading routine, call
; with paddle # in X, returns value in Y
HCLR := $F3F2 ; Clear current hires screen to black
;;;---------------------------------------------------------
;;; Other
;;;---------------------------------------------------------
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
;;;---------------------------------------------------------
;;; Generic Macros
;;;---------------------------------------------------------
;;;----------------------------------------
.macro SaveRegisters
;;;----------------------------------------
pha
txa
pha
tya
pha
.endmacro
;;;----------------------------------------
.macro RestoreRegisters
;;;----------------------------------------
pla
tay
pla
tax
pla
.endmacro
ZP_PTR := $FA ; Write cursor location on zero page
;;;-------------------------------------------------------------------
;;;
;;; Application-level logic
;;; Client Code
;;;
;;;-------------------------------------------------------------------
.org $6000
jmp AppEntry
.org $6000
jmp AppEntry
.include "ssc.inc"
.include "ssc.inc"
.ifdef MOUSE_SUPPORT
.ifdef MOUSE_SUPPORT
.include "mouse.inc"
.endif ; MOUSE_SUPPORT
.endif
;;;-------------------------------------------------------------------
@ -74,47 +60,45 @@ ZP_PTR := $FA ; Write cursor location on zero page
;;;-------------------------------------------------------------------
;;; Application configuration
PSPEED: .byte SSC::BPS_115k ; Hardcoded for Apple IIc (TODO: Allow configuration)
PSLOT: .byte 2 ; Hardcoded for Apple IIc (TODO: Allow configuration)
PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemented)
PSPEED: .byte SSC::BPS_115k ; Hardcoded for Apple IIc (TODO: Allow configuration)
PSLOT: .byte 2 ; Hardcoded for Apple IIc (TODO: Allow configuration)
PEXIT: .byte 0 ; Set when it's time to exit (Not Yet Implemented)
;;; Keyboard state
LASTKB: .byte 0
LASTOA: .byte 0
LASTCA: .byte 0
LASTKB: .byte 0
LASTOA: .byte 0
LASTCA: .byte 0
.ifdef PADDLE_SUPPORT
.ifdef PADDLE_SUPPORT
;;; Paddle state
LASTP0: .byte 0
LASTP1: .byte 0
LASTP0: .byte 0
LASTP1: .byte 0
.endif ; PADDLE_SUPPORT
.endif ; PADDLE_SUPPORT
;;;---------------------------------------------------------
.proc AppEntry
;;;---------------------------------------------------------
;;; Initialize the application, and enter the main loop
;;;---------------------------------------------------------
lda PSLOT ; Use slot 2
jsr SSC::Init ; Initialize Super Serial Card
jsr InitHires ; Initialize Hi-Res graphics
jsr InitInput ; Initialize input devices
jsr MainLoop
; fall through
.proc AppEntry
lda PSLOT ; Use slot 2
jsr SSC::Init ; Initialize Super Serial Card
jsr InitHires ; Initialize Hi-Res graphics
jsr InitInput ; Initialize input devices
jsr MainLoop
; fall through
.endproc
;;;---------------------------------------------------------
.proc AppExit
;;;---------------------------------------------------------
;;; Clean up and exit app
;;;---------------------------------------------------------
jsr SSC::Reset
sta LOWSCR
sta TXTSET
rts
.proc AppExit
jsr SSC::Reset
sta LOWSCR
sta TXTSET
rts
.endproc
@ -127,48 +111,45 @@ LASTP1: .byte 0
;;;---------------------------------------------------------
.proc MainLoop
;;;---------------------------------------------------------
;;; TODO: Sort out the protocol - should be able to send
;;; input state without receiving data
;;; jsr SSCHasData ; Anything to read?
;;; jsr SSC::HasData ; Anything to read?
;;; bne :+ ; Nope
: jsr ReceivePage
jsr FlipHires
jmp :- ; TODO: define an exit trigger
rts
: jsr ReceivePage
jsr FlipHires
jmp :- ; TODO: define an exit trigger
rts
.endproc
;;;---------------------------------------------------------
.proc ReceivePage
;;;---------------------------------------------------------
;;; Pull a hi-res page down over serial
;;;
;;; Protocol is:
;;; * Recieve 256 bytes (graphic data)
;;; * Send 1 byte (input state)
;;;---------------------------------------------------------
lda #0 ; set up write pointer
sta ZP_PTR
lda PLOTPAGE
sta ZP_PTR+1
ldx #PAGESIZE ; plan to receive this many pages
ldy #0
.proc ReceivePage
lda #0 ; set up write pointer
sta ZP_PTR
lda PAGE
sta ZP_PTR+1
ldx #PAGESIZE ; plan to receive this many pages
ldy #0
: jsr SSC::Get ; TODO: look for escape codes in the sequence
sta (ZP_PTR),Y
iny
bne :- ; Do a full page...
: jsr SSC::Get ; TODO: look for escape codes in the sequence
sta (ZP_PTR),Y
iny
bne :- ; Do a full page...
jsr SendInputState ; brief moment to send data back upstream
jsr SendInputState ; brief moment to send data back upstream
inc ZP_PTR+1
dex
bne :- ; ...as many pages as we need
rts
inc ZP_PTR+1
dex
bne :- ; ...as many pages as we need
rts
.endproc
@ -181,60 +162,57 @@ LASTP1: .byte 0
;;; $7f - $ff - key down, ASCII code + $80
;;; otherwise, a transition:
;;;
SIS_KBUP = $00 ; Key up
SIS_OADOWN = $01 ; Open Apple transitioned to down
SIS_OAUP = $02 ; Open Apple transitioned to up
SIS_CADOWN = $03 ; Closed Apple transitioned to down
SIS_CAUP = $04 ; Closed Apple transitioned to up
SIS_KBUP = $00 ; Key up
SIS_OADOWN = $01 ; Open Apple transitioned to down
SIS_OAUP = $02 ; Open Apple transitioned to up
SIS_CADOWN = $03 ; Closed Apple transitioned to down
SIS_CAUP = $04 ; Closed Apple transitioned to up
;;;
;;; $05 - $0f : reserved
;;;
SIS_MX = $10 ; Mouse X high nibble
SIS_MY = $20 ; Mouse Y high nibble
SIS_PDL0 = $30 ; Paddle 0 high nibble
SIS_PDL1 = $40 ; Paddle 1 high nibble
SIS_MX = $10 ; Mouse X high nibble
SIS_MY = $20 ; Mouse Y high nibble
SIS_PDL0 = $30 ; Paddle 0 high nibble
SIS_PDL1 = $40 ; Paddle 1 high nibble
;;;
;;; $50 - $7e : reserved
;;;
SIS_SYNC = $7f
SIS_SYNC = $7f
;;;---------------------------------------------------------
.proc InitInput
;;;---------------------------------------------------------
;;; Initialize input devices and storage for detecting
;;; state transitions
;;;---------------------------------------------------------
.proc InitInput
;;; Init keyboard state
lda #SIS_KBUP
sta LASTKB
lda #SIS_KBUP
sta LASTKB
;;; Init Open/Closed Apple states
lda #SIS_OAUP ; NOTE: Don't store OA state as it fluctuates
sta LASTOA
lda #SIS_CAUP ; NOTE: Don't store CA state as it fluctuates
sta LASTCA
lda #SIS_OAUP ; NOTE: Don't store OA state as it fluctuates
sta LASTOA
lda #SIS_CAUP ; NOTE: Don't store CA state as it fluctuates
sta LASTCA
.ifdef PADDLE_SUPPORT
.ifdef PADDLE_SUPPORT
;;; Init Paddle state
lda #SIS_PDL0
ora #8 ; Middle of range 0...15
sta LASTP0
lda #SIS_PDL1
ora #8 ; Middle of range 0...15
sta LASTP1
.endif
lda #SIS_PDL0
ora #8 ; Middle of range 0...15
sta LASTP0
lda #SIS_PDL1
ora #8 ; Middle of range 0...15
sta LASTP1
.endif
.ifdef MOUSE_SUPPORT
jsr Mouse::FindMouse
.endif
.ifdef MOUSE_SUPPORT
jsr Mouse::FindMouse
.endif
rts
rts
.endproc
;;;---------------------------------------------------------
.proc SendInputState
;;;---------------------------------------------------------
;;; Send keyboard joystick and/or mouse state over the
;;; serial port
@ -246,10 +224,11 @@ LASTP1: .byte 0
;;; - otherwise send paddle 0 state (if it changed)
;;; - (TODO: Mouse state)
;;; - otherwise send sync byte
;;;---------------------------------------------------------
SaveRegisters ; Store registers
clc
.proc SendInputState
SaveRegisters ; Store registers
clc
;;;--------------------------------------
;;; Send key state, if it changed
@ -265,32 +244,32 @@ LASTP1: .byte 0
;;; Down - Down Save and send key ONLY if different
;;;
lda LASTKB
bne KEY_WAS_DOWN
lda LASTKB
bne KEY_WAS_DOWN
KEY_WAS_UP:
lda KBD ; Read keyboard
bpl END_KEY ; - still up
sta LASTKB ; Down, so save it
jsr SSC::Put ; and send it
jmp DONE
lda KBD ; Read keyboard
bpl END_KEY ; - still up
sta LASTKB ; Down, so save it
jsr SSC::Put ; and send it
jmp DONE
KEY_WAS_DOWN:
; key was down - strobe should match
; unless the key changed or was released
lda KBDSTRB
bmi KBDSTRB_DOWN
; key was down - strobe should match
; unless the key changed or was released
lda KBDSTRB
bmi KBDSTRB_DOWN
KBDSTRB_UP:
lda #SIS_KBUP ; Key was released
sta LASTKB ; so save it
jsr SSC::Put ; and send it
jmp DONE
lda #SIS_KBUP ; Key was released
sta LASTKB ; so save it
jsr SSC::Put ; and send it
jmp DONE
KBDSTRB_DOWN:
cmp LASTKB ; Same key as last time?
beq END_KEY ; - no change
sta LASTKB ; New key, so save it
jsr SSC::Put ; and send it
jmp DONE
cmp LASTKB ; Same key as last time?
beq END_KEY ; - no change
sta LASTKB ; New key, so save it
jsr SSC::Put ; and send it
jmp DONE
END_KEY:
@ -301,22 +280,22 @@ END_KEY:
;;; for both OA states and bit = 0 down: lda BUTN0 ; ROL ; LDA #0 ; ROL ; ORA #signature
TEST_OA:
lda BUTN0 ; Test Open Apple state
bmi OA_IS_DOWN
lda BUTN0 ; Test Open Apple state
bmi OA_IS_DOWN
OA_IS_UP:
lda #SIS_OAUP
cmp LASTOA ; Changed?
beq END_OA ; Nope
sta LASTOA ; Yes, save it / send it!
jsr SSC::Put
jmp DONE
lda #SIS_OAUP
cmp LASTOA ; Changed?
beq END_OA ; Nope
sta LASTOA ; Yes, save it / send it!
jsr SSC::Put
jmp DONE
OA_IS_DOWN:
lda #SIS_OADOWN
cmp LASTOA ; Changed?
beq END_OA ; Nope
sta LASTOA ; Yes, save it / send it!
jsr SSC::Put
jmp DONE
lda #SIS_OADOWN
cmp LASTOA ; Changed?
beq END_OA ; Nope
sta LASTOA ; Yes, save it / send it!
jsr SSC::Put
jmp DONE
END_OA:
@ -324,86 +303,86 @@ END_OA:
;;; Send Closed Apple state, if it changed
TEST_CA:
lda BUTN1 ; Has the Open Apple/Button 1 value changed?
bmi CA_IS_DOWN
lda BUTN1 ; Has the Open Apple/Button 1 value changed?
bmi CA_IS_DOWN
CA_IS_UP:
lda #SIS_CAUP
cmp LASTCA ; Changed?
beq END_CA ; Nope
sta LASTCA ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
lda #SIS_CAUP
cmp LASTCA ; Changed?
beq END_CA ; Nope
sta LASTCA ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
CA_IS_DOWN:
lda #SIS_CADOWN
cmp LASTCA ; Changed?
beq END_CA ; Nope
sta LASTCA ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
lda #SIS_CADOWN
cmp LASTCA ; Changed?
beq END_CA ; Nope
sta LASTCA ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
END_CA:
.ifdef PADDLE_SUPPORT
.ifdef PADDLE_SUPPORT
;;;--------------------------------------
;;; Send Paddle 0 state, if it changed
TEST_PDL0:
ldx #0
jsr PREAD
tya
lsr ; Shift to low nibble
lsr
lsr
lsr
ora #SIS_PDL0 ; And mark it with the signature
cmp LASTP0 ; Change?
beq END_PDL0 ; Nope
sta LASTP0 ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
ldx #0
jsr PREAD
tya
lsr ; Shift to low nibble
lsr
lsr
lsr
ora #SIS_PDL0 ; And mark it with the signature
cmp LASTP0 ; Change?
beq END_PDL0 ; Nope
sta LASTP0 ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
END_PDL0:
; Chew up time so next paddle read will be correct
; TODO: Replace this with a "read both" strobes
; routine
: .repeat 11 ; By experiment, need 11 NOPs.
nop
.endrep
iny
bne :-
; Chew up time so next paddle read will be correct
; TODO: Replace this with a "read both" strobes
; routine
: .repeat 11 ; By experiment, need 11 NOPs.
nop
.endrep
iny
bne :-
;;;--------------------------------------
;;; Send Paddle 1 state, if it changed
TEST_PDL1:
ldx #1
jsr PREAD
tya
lsr ; Shift to low nibble
lsr
lsr
lsr
ora #SIS_PDL1 ; And mark it with the signature
cmp LASTP1 ; Change?
beq END_PDL1 ; Nope
sta LASTP1 ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
ldx #1
jsr PREAD
tya
lsr ; Shift to low nibble
lsr
lsr
lsr
ora #SIS_PDL1 ; And mark it with the signature
cmp LASTP1 ; Change?
beq END_PDL1 ; Nope
sta LASTP1 ; Yes, save it
jsr SSC::Put ; and send it
jmp DONE
END_PDL1:
; NOTE: No need to chew time like PDL0
; since data receive will make up for it; if we
; loop in SendInputState need to add it here
; NOTE: No need to chew time like PDL0
; since data receive will make up for it; if we
; loop in SendInputState need to add it here
.endif
.endif
;;;--------------------------------------
;;; No state changes so send sync byte
lda #SIS_SYNC
jsr SSC::Put
lda #SIS_SYNC
jsr SSC::Put
DONE:
RestoreRegisters
rts
RestoreRegisters
rts
.endproc
@ -414,66 +393,41 @@ DONE:
;;;
;;;-------------------------------------------------------------------
;;;---------------------------------------------------------
.proc InitHires
;;;---------------------------------------------------------
;;; Set up the graphics display and pointers
;;;---------------------------------------------------------
lda #PLOTPAGE1 ; clear page 1
sta PLOTPAGE
jsr ClearHires
jsr FlipHires ; then show it and flip to 2
sta HIRES
sta TXTCLR
sta MIXCLR
sta LOWSCR
.proc InitHires
lda #PAGE1 ; clear page 1
sta PAGE
jsr HCLR
rts
jsr FlipHires ; then show it and flip to 2
sta HIRES
sta TXTCLR
sta MIXCLR
sta LOWSCR
rts
.endproc
;;;---------------------------------------------------------
.proc FlipHires
;;;---------------------------------------------------------
;;; Call when done with the current plotting page
;;; (selected in PLOTPAGE) and it will be shown and the
;;; (selected in PAGE) and it will be shown and the
;;; other page will be shown.
;;;---------------------------------------------------------
lda PLOTPAGE ; plotting on which page?
cmp #PLOTPAGE1
beq :+
sta HISCR ; page 2 - so show it
lda #PLOTPAGE1 ; and plot on page 1
sta PLOTPAGE
rts
.proc FlipHires
lda PAGE ; plotting on which page?
cmp #PAGE1
beq :+
: sta LOWSCR ; page 1 - so show it
lda #PLOTPAGE2 ; and plot on page 2
sta PLOTPAGE
rts
.endproc
;;;---------------------------------------------------------
.proc ClearHires
;;;---------------------------------------------------------
;;; Clear hires plotting page (selected in PLOTPAGE) to
;;; black uses ZP_PTR; not terribly efficient
;;;---------------------------------------------------------
lda #0 ; Set up ZP_PTR as a pointer into the hires page
sta ZP_PTR
lda PLOTPAGE
sta ZP_PTR+1
ldx #PAGESIZE ; Clear this many pages
lda #0 ; with black!
tay
: sta (ZP_PTR),Y
iny
bne :-
inc ZP_PTR+1
dex
bne :-
rts
sta HISCR ; page 2 - so show it
lda #PAGE1 ; and plot on page 1
sta PAGE
rts
: sta LOWSCR ; page 1 - so show it
lda #PAGE2 ; and plot on page 2
sta PAGE
rts
.endproc

21
client/macros.inc Normal file
View File

@ -0,0 +1,21 @@
;;;---------------------------------------------------------
;;;
;;; Generic Macros
;;;
;;;---------------------------------------------------------
.macro SaveRegisters
pha
txa
pha
tya
pha
.endmacro
.macro RestoreRegisters
pla
tay
pla
tax
pla
.endmacro

View File

@ -3,7 +3,7 @@
;;; Mouse
;;;
;;;-------------------------------------------------------------------
.error "Mouse support not fully implemented"
.error "Mouse support not fully implemented"
.proc Mouse
@ -13,54 +13,54 @@
;;; For READMOUSE and POSMOUSE
MOUSE_X_LSB := $0478 ; + slot Low byte of absolute X position
MOUSE_X_MSB := $0578 ; + slot High byte of absolute X position
MOUSE_Y_LSB := $04F8 ; + slot Low byte of absolute Y position
MOUSE_Y_MSB := $05F8 ; + slot High byte of absolute Y position
MOUSE_RSV1 := $0678 ; + slot Reserved and used by the firmware
MOUSE_RSV2 := $06F8 ; + slot Reserved and used by the firmware
MOUSE_BTN := $0778 ; + slot Button 0/1 interrupt status byte
MOUSE_MODE := $07F8 ; + slot Mode byte
MOUSE_X_LSB := $0478 ; + slot Low byte of absolute X position
MOUSE_X_MSB := $0578 ; + slot High byte of absolute X position
MOUSE_Y_LSB := $04F8 ; + slot Low byte of absolute Y position
MOUSE_Y_MSB := $05F8 ; + slot High byte of absolute Y position
MOUSE_RSV1 := $0678 ; + slot Reserved and used by the firmware
MOUSE_RSV2 := $06F8 ; + slot Reserved and used by the firmware
MOUSE_BTN := $0778 ; + slot Button 0/1 interrupt status byte
MOUSE_MODE := $07F8 ; + slot Mode byte
;;; For CLAMPMOUSE:
MOUSE_CMIN_LSB := $0478 ; low byte of low clamp
MOUSE_CMIN_MSB := $0578 ; high byte of low clamp
MOUSE_CMAX_LSB := $04F8 ; low byte of high clamp
MOUSE_CMAX_MSB := $05F8 ; high byte of high clamp
MOUSE_CMIN_LSB := $0478 ; low byte of low clamp
MOUSE_CMIN_MSB := $0578 ; high byte of low clamp
MOUSE_CMAX_LSB := $04F8 ; low byte of high clamp
MOUSE_CMAX_MSB := $05F8 ; high byte of high clamp
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_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
MOUSEID_MAX := 4
MOUSEID_ADDR: .byte $05, $07, $0b, $0c, $fb
MOUSEID_VAL: .byte $38, $18, $01, $20, $d6
MOUSEID_ADDR: .byte $05, $07, $0b, $0c, $fb
MOUSEID_VAL: .byte $38, $18, $01, $20, $d6
SLOT_BASE := $C000
SLOT_BASE := $C000
;;;--------------------------------------------------
;;; Data
;;;--------------------------------------------------
;;; Mouse
MOUSE_SLOT: .byte 0 ; mouse slot, or 0 if none
LAST_MX: .byte $7f
LAST_MY: .byte $7f
MOUSE_SLOT: .byte 0 ; mouse slot, or 0 if none
LAST_MX: .byte $7f
LAST_MY: .byte $7f
;;;--------------------------------------------------
;;; Routines
;;;--------------------------------------------------
MOUSEPTR = $EB ; Zero page location
MOUSEPTR := $EB ; Zero page location
MOUSE_MIN_X := $10
MOUSE_MAX_X := $1f
MOUSE_CENTER_X := $17
MOUSE_MIN_Y := $20
MOUSE_MAX_Y := $2f
MOUSE_CENTER_Y := $2f
MOUSE_MIN_X := $10
MOUSE_MAX_X := $1f
MOUSE_CENTER_X := $17
MOUSE_MIN_Y := $20
MOUSE_MAX_Y := $2f
MOUSE_CENTER_Y := $2f
;;;--------------------------------------------------
@ -74,116 +74,114 @@ MOUSE_CENTER_Y := $2f
;;; min: minimum value (2 byte)
;;; max: maximum value (2 byte)
;;;----------------------------------------
; Clamp X to 0...255
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
jsr CLAMPMOUSE
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
jsr CLAMPMOUSE
.endmacro
;;;----------------------------------------
.macro PosMouse px, py
;;;----------------------------------------
ldx MOUSE_SLOT
lda #<px
sta MOUSE_X_LSB,X
lda #>px
sta MOUSE_X_MSB,X
lda #<py
sta MOUSE_Y_LSB,X
lda #>py
sta MOUSE_Y_MSB,X
jsr POSMOUSE
ldx MOUSE_SLOT
lda #<px
sta MOUSE_X_LSB,X
lda #>px
sta MOUSE_X_MSB,X
lda #<py
sta MOUSE_Y_LSB,X
lda #>py
sta MOUSE_Y_MSB,X
jsr POSMOUSE
.endmacro
;;;---------------------------------------------------------
.proc FindMouse
;;;---------------------------------------------------------
;;; Find and initialize the mouse port
;;;---------------------------------------------------------
.proc FindMouse
;;; 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
;
;
ldy #MAX_SLOT ; Start search in slot 7
ldy #MAX_SLOT ; Start search in slot 7
TESTSLOT:
sty MOUSE_SLOT ; Save for later
tya
clc
adc #>SLOT_BASE ; Firmware is $c0 + slot
sta slot_addr + 1 ; Update msb of signature test
ldx #MOUSEID_MAX ; This many signature bytes
sty MOUSE_SLOT ; Save for later
tya
clc
adc #>SLOT_BASE ; Firmware is $c0 + slot
sta slot_addr + 1 ; Update msb of signature test
ldx #MOUSEID_MAX ; This many signature bytes
TESTID:
lda MOUSEID_ADDR,x
sta MOD_MOUSE_ID + 1 ; Update lsb of signature test
slot_addr := *+1
lda SLOT_BASE ; Self-modified
cmp MOUSEID_VAL,x ; Does it match the signature?
bne NOMATCH ; Nope - try the next slot
dex ; Yes! Keep testing
bpl TESTID ; Fall through if all done
jmp FOUND_MOUSE
lda MOUSEID_ADDR,x
sta MOD_MOUSE_ID + 1 ; Update lsb of signature test
slot_addr := *+1
lda SLOT_BASE ; Self-modified
cmp MOUSEID_VAL,x ; Does it match the signature?
bne NOMATCH ; Nope - try the next slot
dex ; Yes! Keep testing
bpl TESTID ; Fall through if all done
jmp FOUND_MOUSE
NOMATCH:
dey ; Didn't match
bne TESTSLOT ; Keep looking until slot 0
sty MOUSE_SLOT ; Oops, no mouse - make a note
rts ; and bail
dey ; Didn't match
bne TESTSLOT ; Keep looking until slot 0
sty MOUSE_SLOT ; Oops, no mouse - make a note
rts ; and bail
;
;
;;; Step 2: Set up indirect calling routines
;
;
FOUND_MOUSE:
; Slot is in y
; Slot is in y
tya
ora #>SLOT_BASE ; Compute $Cn - needed for
sta MOUSEPTR+1 ; MSB of MOUSEPTR ($Cn00)
sta TOMOUSE_Cn ; X register before firmware calls
sta TOMOUSE_msb ; MSB of firmware calls
tya
ora #>SLOT_BASE ; Compute $Cn - needed for
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)
lda #0
sta MOUSEPTR ; LSB of MOUSEPTR ($Cn00)
tya
asl ; Compute $n0 - needed for
asl
asl
asl
sta TOMOUSE_n0 ; Y register before firmware calls
tya
asl ; Compute $n0 - needed for
asl
asl
asl
sta TOMOUSE_n0 ; Y register before firmware calls
;
;
;;; Step 3: Configure the mouse card
;
;
;;; Initialize the mouse for use
jsr INITMOUSE ; reset, clamp to 0-1023 x/y
lda #1 ; mouse on, no interrupts
jsr SETMOUSE ; TODO: test carry bit result (set = error)
;
jsr INITMOUSE ; reset, clamp to 0-1023 x/y
lda #1 ; mouse on, no interrupts
jsr SETMOUSE ; TODO: test carry bit result (set = error)
;
;;; Since we want deltas, clamp and center
;
ClampMouse MOUSE_CLAMP_X, MOUSE_MIN_X, MOUSE_MAX_X
ClampMouse MOUSE_CLAMP_Y, MOUSE_MIN_Y, MOUSE_MAX_Y
PosMouse MOUSE_CENTER_X, MOUSE_CENTER_Y
;
ClampMouse MOUSE_CLAMP_X, MOUSE_MIN_X, MOUSE_MAX_X
ClampMouse MOUSE_CLAMP_Y, MOUSE_MIN_Y, MOUSE_MAX_Y
PosMouse MOUSE_CENTER_X, MOUSE_CENTER_Y
cli ; Enable interrupts so mouse can function
cli ; Enable interrupts so mouse can function
rts
rts
.endproc
@ -192,104 +190,102 @@ FOUND_MOUSE:
;;; Indirect jump table for mouse firmware routines
;;;--------------------------------------------------
SETMOUSE: ldy #$12
jmp GoMouse
SERVEMOUSE: ldy #$13
jmp GoMouse
READMOUSE: ldy #$14
jmp GoMouse
CLEARMOUSE: ldy #$15
jmp GoMouse
POSMOUSE: ldy #$16
jmp GoMouse
CLAMPMOUSE: ldy #$17
jmp GoMouse
HOMEMOUSE: ldy #$18
jmp GoMouse
INITMOUSE: ldy #$19
jmp GoMouse
SETMOUSE: ldy #$12
jmp GoMouse
SERVEMOUSE: ldy #$13
jmp GoMouse
READMOUSE: ldy #$14
jmp GoMouse
CLEARMOUSE: ldy #$15
jmp GoMouse
POSMOUSE: ldy #$16
jmp GoMouse
CLAMPMOUSE: ldy #$17
jmp GoMouse
HOMEMOUSE: ldy #$18
jmp GoMouse
INITMOUSE: ldy #$19
jmp GoMouse
;;;--------------------------------------------------
.proc GoMouse
;;;--------------------------------------------------
tax ; Preserve the value in A
lda (MOUSEPTR),Y ; Get the routine entry point
sta TOMOUSE_lsb ; Patch the JMP instruction
txa ; Restore the value in A
tax ; Preserve the value in A
lda (MOUSEPTR),Y ; Get the routine entry point
sta TOMOUSE_lsb ; Patch the JMP instruction
txa ; Restore the value in A
;;; The following operand bytes must be patched by the
;;; initialization code which detects the mouse.
BANK := $C054
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
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
.endproc
TOMOUSE_Cn := GoMouse::TOMOUSE_Cn
TOMOUSE_n0 := GoMouse::TOMOUSE_n0
TOMOUSE_lsb := GoMouse::TOMOUSE_slot
TOMOUSE_msb := GoMouse::TOMOUSE_slot+1
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
;;;--------------------------------------------------
;
;;;--------------------------------------------------
txa ; save x
pha
tya ; save y
pha
jsr READMOUSE
txa ; save x
pha
tya ; save y
pha
jmp DONE
jsr READMOUSE
ldx MOUSE_SLOT
jmp DONE
lda MOUSE_X_LSB,x
sta LAST_MX
ldx MOUSE_SLOT
lda MOUSE_Y_LSB,x
sta LAST_MY
lda MOUSE_X_LSB,x
sta LAST_MX
lda LAST_MX
cmp #MOUSE_CENTER_X
bne SEND
lda MOUSE_Y_LSB,x
sta LAST_MY
lda LAST_MY
cmp #MOUSE_CENTER_Y
beq DONE
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
lda LAST_MX
ora #SIS_MX
jsr SSC::Put
lda LAST_MY
ora #SIS_MY
jsr SSC::Put
PosMouse MOUSE_CENTER_X, MOUSE_CENTER_Y
PosMouse MOUSE_CENTER_X, MOUSE_CENTER_Y
DONE:
pla ; restore y
tay
pla ; restore x
tax
rts
pla ; restore y
tay
pla ; restore x
tax
rts
.endproc

View File

@ -13,110 +13,105 @@
;;;---------------------------------------------------------
;;; These get incremented by the slot where they appear
UACTRL = $C08B ; Control Register
UACMND = $C08A ; Command Register
UASTAT = $C089 ; Status Register
UADATA = $C088 ; Data Register - incoming and outgoing data
UACTRL = $C08B ; Control Register
UACMND = $C08A ; Command Register
UASTAT = $C089 ; Status Register
UADATA = $C088 ; Data Register - incoming and outgoing data
;;; Lookup table for UACTRL register, by baud rate
BPSCTRL: .byte $16,$1E,$1F,$10 ; 300, 9600, 19200, 115k (with 8 data bits, 1 stop bit, no echo)
.enum
BPS_300
BPS_9600
BPS_19200
BPS_115k
.endenum
BPSCTRL: .byte $16,$1E,$1F,$10 ; 300, 9600, 19200, 115k (with 8 data bits, 1 stop bit, no echo)
.enum
BPS_300
BPS_9600
BPS_19200
BPS_115k
.endenum
CMND_NRDI = $0B ; Command: no parity, RTS on, DTR on, no interrupts
CMND_NRDI = $0B ; Command: no parity, RTS on, DTR on, no interrupts
;;;---------------------------------------------------------
.proc Init
;;;---------------------------------------------------------
;;; Initialize the SSC; slot passed in A
;;;---------------------------------------------------------
asl ; Slot passed in A
asl
asl
asl ; Now $S0
adc #$88 ; Low byte of UADATA
tax
lda #CMND_NRDI ; Command register: no parity, RTS on, DTR on, no interrupts
sta $C002,X
ldy PSPEED ; Control register: look up by baud rate (8 data bits, 1 stop bit)
lda BPSCTRL,Y
sta $C003,X
stx MOD_UADATA_1 ; Modify references to
stx MOD_UADATA_2 ; UADATA to point at
stx MOD_UADATA_3 ; correct slot (UADATA+S0)
inx
stx MOD_UASTAT_1 ; Modify reference to
stx MOD_UASTAT_2 ; UASTAT to point at
stx MOD_UASTAT_3 ; correct slot (UASTAT+S0)
rts
.proc Init
asl ; Slot passed in A
asl
asl
asl ; Now $S0
adc #$88 ; Low byte of UADATA
tax
lda #CMND_NRDI ; Command register: no parity, RTS on, DTR on, no interrupts
sta $C002,X
ldy PSPEED ; Control register: look up by baud rate (8 data bits, 1 stop bit)
lda BPSCTRL,Y
sta $C003,X
stx MOD_UADATA_1 ; Modify references to
stx MOD_UADATA_2 ; UADATA to point at
stx MOD_UADATA_3 ; correct slot (UADATA+S0)
inx
stx MOD_UASTAT_1 ; Modify reference to
stx MOD_UASTAT_2 ; UASTAT to point at
stx MOD_UASTAT_3 ; correct slot (UASTAT+S0)
rts
.endproc
;;;---------------------------------------------------------
.proc Put
;;;---------------------------------------------------------
;;; Send accumulator out the serial port
;;;---------------------------------------------------------
pha ; Push A onto the stack
MOD_UASTAT_1 := *+1
: lda UASTAT ; Check status bits
and #$70
cmp #$10
bne :- ; Output register is full, so loop
pla
MOD_UADATA_1 := *+1
sta UADATA ; Put character
rts
.proc Put
pha ; Push A onto the stack
MOD_UASTAT_1 := *+1
: lda UASTAT ; Check status bits
and #$70
cmp #$10
bne :- ; Output register is full, so loop
pla
MOD_UADATA_1 := *+1
sta UADATA ; Put character
rts
.endproc
MOD_UASTAT_1 := Put::MOD_UASTAT_1
MOD_UADATA_1 := Put::MOD_UADATA_1
MOD_UASTAT_1 := Put::MOD_UASTAT_1
MOD_UADATA_1 := Put::MOD_UADATA_1
;;;---------------------------------------------------------
;;; Read a character from the serial port to the accumulator
.proc Get
;;;---------------------------------------------------------
;;; Read a character from the serial port to the accumulator
;;;---------------------------------------------------------
MOD_UASTAT_2 := *+1
lda UASTAT ; Check status bits
and #$68
cmp #$8
bne Get ; Input register empty, loop
MOD_UADATA_2 := *+1
lda UADATA ; Get character
rts
MOD_UASTAT_2 := *+1
lda UASTAT ; Check status bits
and #$68
cmp #$8
bne Get ; Input register empty, loop
MOD_UADATA_2 := *+1
lda UADATA ; Get character
rts
.endproc
MOD_UASTAT_2 := Get::MOD_UASTAT_2
MOD_UADATA_2 := Get::MOD_UADATA_2
MOD_UASTAT_2 := Get::MOD_UASTAT_2
MOD_UADATA_2 := Get::MOD_UADATA_2
;;;---------------------------------------------------------
;;; Check if the serial port has pending data
.proc HasData
;;;---------------------------------------------------------
;;; Read a character from the serial port to the accumulator
;;;---------------------------------------------------------
MOD_UASTAT_3 := *+1
lda UASTAT ; Check status bits
and #$68
cmp #$8
rts
MOD_UASTAT_3 := *+1
lda UASTAT ; Check status bits
and #$68
cmp #$8
rts
.endproc
MOD_UASTAT_3 := HasData::MOD_UASTAT_3
MOD_UASTAT_3 := HasData::MOD_UASTAT_3
;;;---------------------------------------------------------
.proc Reset
;;;---------------------------------------------------------
;;; Clean up serial port
;;;---------------------------------------------------------
MOD_UADATA_3 := *+1
bit UADATA
rts
.proc Reset
MOD_UADATA_3 := *+1
bit UADATA
rts
.endproc
MOD_UADATA_3 := Reset::MOD_UADATA_3
MOD_UADATA_3 := Reset::MOD_UADATA_3
.endproc