pull more out of core client src

This commit is contained in:
Joshua Bell 2018-10-28 22:10:05 -07:00
parent f92ef31fe4
commit efeff6cdb9
5 changed files with 751 additions and 761 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,75 +1,31 @@
PADDLE_SUPPORT = 1
;;; MOUSE_SUPPORT = 1
;;;---------------------------------------------------------
;;; Super Serial constants/locations
;;;---------------------------------------------------------
;;; 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
.include "apple2.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
CLRTEXT = $C050 ;display graphics
SETTEXT = $C051 ;display text
CLRMIXED = $C052 ;clear mixed mode- enable full graphics
SETMIXED = $C053 ;enable graphics/text mixed mode
PAGE1 = $C054 ;select text/graphics page1
PAGE2 = $C055 ;select text/graphics page2
CLRHIRES = $C056 ;select Lo-res
SETHIRES = $C057 ;select Hi-res
PLOTPAGE := $E6 ; Active hires plotting page (Applesoft)
PLOTPAGE1 := $20
PLOTPAGE2 := $40
PAGESIZE := $20 ; Size of hi-res screen in pages
;;;---------------------------------------------------------
;;; Keyboard input constants/locations
;;; ROM routines
;;;---------------------------------------------------------
KEYBD = $C000 ; key down in bit 7; key code in lower bits
STROBE = $C010 ; write to clear key down state
OPNAPPLE = $C061 ; open apple (command) key data (read)
CLSAPPLE = $C062 ; closed apple (option) key data (read)
PB2 = $C063 ; Paddle button 2 (read)
PB3 = $C060 ; Paddle button 3 (read)
;;;---------------------------------------------------------
;;; Paddle/Joystick constants/locations/routines
;;;---------------------------------------------------------
PADDLE0 = $C064 ; bit 7 = status of pdl-0 timer (read)
PADDLE1 = $C065 ; bit 7 = status of pdl-1 timer (read)
PADDLE2 = $C066 ; bit 7 = status of pdl-2 timer (read)
PADDLE3 = $C067 ; bit 7 = status of pdl-3 timer (read)
PDLTRIG = $C070 ; trigger paddles
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
;;;---------------------------------------------------------
;;; Other
;;;---------------------------------------------------------
SLOT_CASE = $c000 ; Firmware for slots are at $cx00
MAX_SLOT = 7 ; Maximum slot # on an Apple II
ZP = $FA ; Write cursor location on zero page
ESCAPE = $80 ; Unused image data byte (all black2)
ESCAPE2 = $FF ; Unused image data byte (all white2)
MAX_SLOT := 7 ; Maximum slot # on an Apple II
ZP_PTR := $FA ; Write cursor location on zero page
;;;---------------------------------------------------------
;;; Generic Macros
@ -97,9 +53,9 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
;;;-------------------------------------------------------------------
;
;;;
;;; Application-level logic
;
;;;
;;;-------------------------------------------------------------------
@ -113,6 +69,29 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
.endif ; MOUSE_SUPPORT
;;;-------------------------------------------------------------------
;;; Variables
;;;-------------------------------------------------------------------
;;; 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)
;;; Keyboard state
LASTKB: .byte 0
LASTOA: .byte 0
LASTCA: .byte 0
.ifdef PADDLE_SUPPORT
;;; Paddle state
LASTP0: .byte 0
LASTP1: .byte 0
.endif ; PADDLE_SUPPORT
;;;---------------------------------------------------------
.proc AppEntry
;;;---------------------------------------------------------
@ -133,16 +112,16 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
;;; Clean up and exit app
;;;---------------------------------------------------------
jsr SSC::Reset
sta PAGE1
sta SETTEXT
sta LOWSCR
sta TXTSET
rts
.endproc
;;;-------------------------------------------------------------------
;
;;;
;;; Main loop functionality
;
;;;
;;;-------------------------------------------------------------------
@ -166,27 +145,27 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
.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
sta ZP_PTR
lda PLOTPAGE
sta ZP+1
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),Y
sta (ZP_PTR),Y
iny
bne :- ; Do a full page...
jsr SendInputState ; brief moment to send data back upstream
inc ZP+1
inc ZP_PTR+1
dex
bne :- ; ...as many pages as we need
rts
@ -194,29 +173,29 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
;;;-------------------------------------------------------------------
;
;;;
;;; Input device routines
;
;;;
;;;-------------------------------------------------------------------
;;; Protocol:
;;; $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
;
;;;
;;; $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
;
;;;
;;; $50 - $7e : reserved
;
;;;
SIS_SYNC = $7f
;;;---------------------------------------------------------
@ -259,7 +238,7 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
;;;---------------------------------------------------------
;;; Send keyboard joystick and/or mouse state over the
;;; serial port
;
;;;
;;; Algorithm:
;;; - Send key state (if it changed)
;;; - otherwise send open-apple state (if it changed)
@ -275,22 +254,22 @@ ESCAPE2 = $FF ; Unused image data byte (all white2)
;;;--------------------------------------
;;; Send key state, if it changed
;;; NOTE: Can't use STROBE to detect key up -> key down transition
;;; NOTE: Can't use KBDSTRB to detect key up -> key down transition
;;; since the msb can change before the key code. Instead, consider
;;; these cases:
;
;;; OLD STATE KEYBD STROBE RESULT
;;;
;;; OLD STATE KBD KBDSTRB RESULT
;;; 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
;
;;;
lda LASTKB
bne KEY_WAS_DOWN
KEY_WAS_UP:
lda KEYBD ; Read keyboard
lda KBD ; Read keyboard
bpl END_KEY ; - still up
sta LASTKB ; Down, so save it
jsr SSC::Put ; and send it
@ -299,14 +278,14 @@ KEY_WAS_UP:
KEY_WAS_DOWN:
; key was down - strobe should match
; unless the key changed or was released
lda STROBE
bmi STROBE_DOWN
STROBE_UP:
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
STROBE_DOWN:
KBDSTRB_DOWN:
cmp LASTKB ; Same key as last time?
beq END_KEY ; - no change
sta LASTKB ; New key, so save it
@ -319,10 +298,10 @@ END_KEY:
;;; Send Open Apple state, if it changed
;;; TODO: Can simplify this code if we make the high bits the same
;;; for both OA states and bit = 0 down: lda OPNAPPLE ; ROL ; LDA #0 ; ROL ; ORA #signature
;;; for both OA states and bit = 0 down: lda BUTN0 ; ROL ; LDA #0 ; ROL ; ORA #signature
TEST_OA:
lda OPNAPPLE ; Test Open Apple state
lda BUTN0 ; Test Open Apple state
bmi OA_IS_DOWN
OA_IS_UP:
lda #SIS_OAUP
@ -345,7 +324,7 @@ END_OA:
;;; Send Closed Apple state, if it changed
TEST_CA:
lda CLSAPPLE ; Has the Open Apple/Button 1 value changed?
lda BUTN1 ; Has the Open Apple/Button 1 value changed?
bmi CA_IS_DOWN
CA_IS_UP:
lda #SIS_CAUP
@ -430,9 +409,9 @@ DONE:
;;;-------------------------------------------------------------------
;
;;;
;;; Hi-res graphics routines
;
;;;
;;;-------------------------------------------------------------------
;;;---------------------------------------------------------
@ -445,10 +424,10 @@ DONE:
jsr ClearHires
jsr FlipHires ; then show it and flip to 2
sta SETHIRES
sta CLRTEXT
sta CLRMIXED
sta PAGE1
sta HIRES
sta TXTCLR
sta MIXCLR
sta LOWSCR
rts
.endproc
@ -465,12 +444,12 @@ DONE:
cmp #PLOTPAGE1
beq :+
sta PAGE2 ; page 2 - so show it
sta HISCR ; page 2 - so show it
lda #PLOTPAGE1 ; and plot on page 1
sta PLOTPAGE
rts
: sta PAGE1 ; page 1 - so show it
: sta LOWSCR ; page 1 - so show it
lda #PLOTPAGE2 ; and plot on page 2
sta PLOTPAGE
rts
@ -481,60 +460,20 @@ DONE:
.proc ClearHires
;;;---------------------------------------------------------
;;; Clear hires plotting page (selected in PLOTPAGE) to
;;; black uses ZP; not terribly efficient
;;; black uses ZP_PTR; not terribly efficient
;;;---------------------------------------------------------
lda #0 ; Set up ZP as a pointer into the hires page
sta ZP
lda #0 ; Set up ZP_PTR as a pointer into the hires page
sta ZP_PTR
lda PLOTPAGE
sta ZP+1
sta ZP_PTR+1
ldx #PAGESIZE ; Clear this many pages
lda #0 ; with black!
tay
: sta (ZP),Y
: sta (ZP_PTR),Y
iny
bne :-
inc ZP+1
inc ZP_PTR+1
dex
bne :-
rts
.endproc
;;;-------------------------------------------------------------------
;
;;; Lookup Tables and Variable Storage
;
;;;-------------------------------------------------------------------
;;; 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
CMND_NRDI = $0B ; Command: no parity, RTS on, DTR on, no interrupts
;;; Application configuration
PSPEED: .byte 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
.ifdef PADDLE_SUPPORT
;;; Paddle state
LASTP0: .byte 0
LASTP1: .byte 0
.endif ; PADDLE_SUPPORT

View File

@ -3,7 +3,6 @@
;;; Mouse
;;;
;;;-------------------------------------------------------------------
.error "Mouse support not fully implemented"
.proc Mouse
@ -14,30 +13,32 @@
;;; 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_MAX := 4
MOUSEID_ADDR: .byte $05, $07, $0b, $0c, $fb
MOUSEID_VAL: .byte $38, $18, $01, $20, $d6
SLOT_BASE := $C000
;;;--------------------------------------------------
;;; Data
;;;--------------------------------------------------
@ -54,12 +55,12 @@ LAST_MY: .byte $7f
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
;;;--------------------------------------------------
@ -122,14 +123,14 @@ TESTSLOT:
tya
clc
adc #>SLOT_BASE ; Firmware is $c0 + slot
sta MOD_MOUSE_ID + 2 ; Update msb of signature test
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
MOD_MOUSE_ID:
lda SLOT_BASE
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
@ -215,28 +216,30 @@ INITMOUSE: ldy #$19
lda (MOUSEPTR),Y ; Get the routine entry point
sta TOMOUSE_lsb ; Patch the JMP instruction
txa ; Restore the value in A
.endproc
; fall through
;;; 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
jsr SLOT_BASE ; Go to the mouse routine
TOMOUSE_slot := *+1
jsr 0 ; Go to the mouse routine
plp ; Restore interrupt state
rts
.endproc
TOMOUSE_Cn = TOMOUSE + 1
TOMOUSE_n0 = TOMOUSE + 3
TOMOUSE_lsb = TOMOUSE + 10
TOMOUSE_msb = TOMOUSE + 11
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
@ -290,4 +293,4 @@ DONE:
.endproc
.endproc
.endproc

View File

@ -8,6 +8,29 @@
.proc SSC
;;;---------------------------------------------------------
;;; Super Serial constants/locations
;;;---------------------------------------------------------
;;; 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
;;; 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
CMND_NRDI = $0B ; Command: no parity, RTS on, DTR on, no interrupts
;;;---------------------------------------------------------
.proc Init
;;;---------------------------------------------------------
@ -24,15 +47,14 @@
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+1 ; Modify references to
stx MOD_UADATA_2+1 ; UADATA to point at
stx MOD_UADATA_3+1 ; correct slot (UADATA+S0)
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+1 ; Modify reference to
stx MOD_UASTAT_2+1 ; UASTAT to point at
stx MOD_UASTAT_3+1 ; correct slot (UASTAT+S0)
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
@ -42,13 +64,13 @@
;;; Send accumulator out the serial port
;;;---------------------------------------------------------
pha ; Push A onto the stack
MOD_UASTAT_1:
MOD_UASTAT_1 := *+1
: lda UASTAT ; Check status bits
and #$70
cmp #$10
bne :- ; Output register is full, so loop
pla
MOD_UADATA_1:
MOD_UADATA_1 := *+1
sta UADATA ; Put character
rts
.endproc
@ -60,12 +82,12 @@ MOD_UADATA_1:
;;;---------------------------------------------------------
;;; Read a character from the serial port to the accumulator
;;;---------------------------------------------------------
MOD_UASTAT_2:
MOD_UASTAT_2 := *+1
lda UASTAT ; Check status bits
and #$68
cmp #$8
bne Get ; Input register empty, loop
MOD_UADATA_2:
MOD_UADATA_2 := *+1
lda UADATA ; Get character
rts
.endproc
@ -77,7 +99,7 @@ MOD_UADATA_2:
;;;---------------------------------------------------------
;;; Read a character from the serial port to the accumulator
;;;---------------------------------------------------------
MOD_UASTAT_3:
MOD_UASTAT_3 := *+1
lda UASTAT ; Check status bits
and #$68
cmp #$8
@ -91,7 +113,7 @@ MOD_UASTAT_3:
;;;---------------------------------------------------------
;;; Clean up serial port
;;;---------------------------------------------------------
MOD_UADATA_3:
MOD_UADATA_3 := *+1
bit UADATA
rts
.endproc