vnIIc/client/client.s

363 lines
9.0 KiB
ArmAsm
Raw Normal View History

2018-10-29 05:23:33 +00:00
;;;-------------------------------------------------------------------
;;;
;;; vnIIc Client Application
;;;
;;;-------------------------------------------------------------------
PADDLE_SUPPORT = 1
2018-10-29 02:49:17 +00:00
;;; MOUSE_SUPPORT = 1
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.include "apple2.inc"
.include "macros.inc"
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Hi-res graphics constants/locations
;;;---------------------------------------------------------
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
PAGE := $E6 ; Active hires plotting page (Applesoft)
PAGE1 := $20
PAGE2 := $40
PAGESIZE := $20 ; Size of hi-res screen in pages
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
2018-10-29 05:10:05 +00:00
;;; ROM routines
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
2018-10-28 03:17:24 +00:00
2018-10-29 05:35:38 +00:00
PREAD := $FB1E ; Monitor paddle reading routine, call
2018-10-29 05:23:33 +00:00
; with paddle # in X, returns value in Y
2018-10-29 05:35:38 +00:00
HCLR := $F3F2 ; Clear current hires screen to black
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Other
;;;---------------------------------------------------------
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
MAX_SLOT := 7 ; Maximum slot # on an Apple II
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
ZP_PTR := $FA ; Write cursor location on zero page
2018-10-28 03:17:24 +00:00
2018-11-02 04:02:05 +00:00
;;;-------------------------------------------------------------------
;;; Protocol:
;;;-------------------------------------------------------------------
.proc Protocol
Keyboard := $00
Button0 := $10
Button1 := $11
Paddle0 := $20
Paddle1 := $21
MouseX := $30
MouseY := $31
MouseBtn := $32
Screen := $80
.endproc
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 05:23:33 +00:00
;;; Client Code
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-29 05:23:33 +00:00
.org $6000
jmp AppEntry
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.include "ssc.inc"
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.ifdef MOUSE_SUPPORT
2018-10-29 02:49:17 +00:00
.include "mouse.inc"
2018-10-29 05:23:33 +00:00
.endif
2018-10-29 02:49:17 +00:00
2018-10-29 05:10:05 +00:00
;;;-------------------------------------------------------------------
;;; Variables
;;;-------------------------------------------------------------------
;;; Application configuration
2018-10-29 05:23:33 +00:00
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)
2018-10-29 05:10:05 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Initialize the application, and enter the main loop
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.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
2018-11-02 04:02:05 +00:00
;; fall through
2018-10-28 03:17:24 +00:00
.endproc
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Clean up and exit app
2018-10-29 05:23:33 +00:00
.proc AppExit
jsr SSC::Reset
sta LOWSCR
sta TXTSET
rts
2018-10-28 03:17:24 +00:00
.endproc
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;; Main loop functionality
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
.proc MainLoop
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;; TODO: Sort out the protocol - should be able to send
;;; input state without receiving data
2018-10-29 05:23:33 +00:00
;;; jsr SSC::HasData ; Anything to read?
2018-10-29 02:49:17 +00:00
;;; bne :+ ; Nope
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
: jsr ReceivePage
2018-11-02 04:02:05 +00:00
;; Input is sent every 256 bytes (32 times per page)
2018-10-29 05:23:33 +00:00
jsr FlipHires
2018-11-02 04:02:05 +00:00
2018-10-29 05:23:33 +00:00
jmp :- ; TODO: define an exit trigger
rts
2018-10-28 03:17:24 +00:00
.endproc
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Pull a hi-res page down over serial
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;; Protocol is:
;;; * Recieve 256 bytes (graphic data)
;;; * Send 1 byte (input state)
2018-10-29 05:23:33 +00:00
.proc ReceivePage
2018-11-02 04:02:05 +00:00
lda #Protocol::Screen
jsr SSC::Put
lda #0 ; data size
jsr SSC::Put
2018-10-29 05:23:33 +00:00
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
2018-11-02 04:02:05 +00:00
: jsr SSC::Get
2018-10-29 05:23:33 +00:00
sta (ZP_PTR),Y
iny
bne :- ; Do a full page...
2018-11-02 04:02:05 +00:00
;; Interleave to maintain responsiveness
jsr SendInputState
2018-10-29 05:23:33 +00:00
inc ZP_PTR+1
dex
bne :- ; ...as many pages as we need
rts
2018-10-28 03:17:24 +00:00
.endproc
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;; Input device routines
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Initialize input devices and storage for detecting
;;; state transitions
2018-10-29 05:23:33 +00:00
.proc InitInput
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.ifdef MOUSE_SUPPORT
jsr Mouse::FindMouse
.endif
rts
2018-10-28 03:17:24 +00:00
.endproc
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
2018-11-02 04:02:05 +00:00
;;; Send a full set of input state updates.
;;; Assumes time to transmit is roughly comparable to time
;;; to measure input state, therefore only sending changes is
;;; not worthwhile in most cases.
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.proc SendInputState
2018-11-02 04:02:05 +00:00
jsr MaybeSendKeyboard
jsr SendButtons
.ifdef PADDLE_SUPPORT
jsr SendPaddles
.endif
.ifdef MOUSE_SUPPORT
jsr SendMouse
.endif
.endproc
2018-10-29 05:23:33 +00:00
2018-10-28 03:17:24 +00:00
2018-11-02 04:02:05 +00:00
;;;------------------------------------------------------------
;;; Keyboard
2018-10-29 02:49:17 +00:00
2018-10-29 05:10:05 +00:00
;;; NOTE: Can't use KBDSTRB to detect key up -> key down transition
2018-10-29 02:49:17 +00:00
;;; since the msb can change before the key code. Instead, consider
;;; these cases:
2018-10-29 05:10:05 +00:00
;;;
;;; OLD STATE KBD KBDSTRB RESULT
2018-10-29 02:49:17 +00:00
;;; Up Up - No-op
;;; Up Down - Save and send key down
;;; Down - Up Save and send key up
;;; Down - Down Save and send key ONLY if different
2018-10-29 05:10:05 +00:00
;;;
2018-10-28 03:17:24 +00:00
2018-11-02 04:02:05 +00:00
last_kb: .byte 0
.proc MaybeSendKeyboard
lda last_kb
bne key_was_down
2018-10-28 03:17:24 +00:00
2018-11-02 04:02:05 +00:00
key_was_up:
;; Key was up - send only if now down.
2018-10-29 05:23:33 +00:00
lda KBD ; Read keyboard
2018-11-02 04:02:05 +00:00
bpl done ; Do nothing if it is still up.
jmp send ; Otherwise send.
key_was_down:
;; Key was down - strobe should match
;; unless the key changed or was released.
2018-10-29 05:23:33 +00:00
lda KBDSTRB
2018-11-02 04:02:05 +00:00
bmi kbdstrb_down
kbdstrb_up:
lda #0 ; Now released
jmp send
kbdstrb_down:
cmp last_kb ; Same key as last time?
beq done ; - no change, don't send.
jmp send
send: sta last_kb
lda Protocol::Keyboard
jsr SSC::Put
lda #1 ; Data size
2018-10-29 05:23:33 +00:00
jsr SSC::Put
2018-11-02 04:02:05 +00:00
lda last_kb
2018-10-29 05:23:33 +00:00
jsr SSC::Put
2018-11-02 04:02:05 +00:00
done: rts
.endproc
;;;------------------------------------------------------------
;;; Buttons
.proc SendButtons
lda Protocol::Button0
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
lda BUTN0
jsr SSC::Put
lda Protocol::Button1
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
lda BUTN1
jsr SSC::Put
rts
.endproc
;;;------------------------------------------------------------
;;; Paddles
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.ifdef PADDLE_SUPPORT
2018-11-02 04:02:05 +00:00
.proc SendPaddles
lda Protocol::Paddle0
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
ldx #0
jsr PREAD
tya
2018-11-02 04:02:05 +00:00
jsr SSC::Put
;; Assumes at least 11 cycles to send, so
;; timer has a chance to reset.
lda Protocol::Paddle1
jsr SSC::Put
lda #1 ; Data size
jsr SSC::Put
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
ldx #1
jsr PREAD
tya
jsr SSC::Put
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
rts
2018-10-28 03:17:24 +00:00
.endproc
2018-11-02 04:02:05 +00:00
.endif
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;; Hi-res graphics routines
2018-10-29 05:10:05 +00:00
;;;
2018-10-29 02:49:17 +00:00
;;;-------------------------------------------------------------------
2018-10-28 03:17:24 +00:00
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Set up the graphics display and pointers
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
.proc InitHires
lda #PAGE1 ; clear page 1
sta PAGE
jsr HCLR
jsr FlipHires ; then show it and flip to 2
sta HIRES
sta TXTCLR
sta MIXCLR
sta LOWSCR
2018-10-28 03:17:24 +00:00
2018-10-29 05:23:33 +00:00
rts
2018-10-28 03:17:24 +00:00
.endproc
2018-10-29 02:49:17 +00:00
;;;---------------------------------------------------------
;;; Call when done with the current plotting page
2018-10-29 05:23:33 +00:00
;;; (selected in PAGE) and it will be shown and the
2018-10-29 02:49:17 +00:00
;;; other page will be shown.
2018-10-29 05:23:33 +00:00
.proc FlipHires
lda PAGE ; plotting on which page?
cmp #PAGE1
beq :+
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
2018-10-28 03:17:24 +00:00
.endproc