Skip to content

Commit

Permalink
shave some bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterferrie committed Oct 10, 2019
1 parent c4ac488 commit 89869a2
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 110 deletions.
5 changes: 1 addition & 4 deletions src/constants.a
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; D000..E611 - persistent data structures (per-game cheat categories,
; gGlobalPrefsStore, gGamesListStore)
; ...unused...
; EC5F..FFF9 - main program code
; ECA6..FFF9 - main program code
; FFFA..FFFF - NMI, reset, IRQ vectors
;
; LC RAM BANK 2
Expand Down Expand Up @@ -71,9 +71,6 @@ PTR = $02 ; word
SRC = $04 ; word
DEST = $06 ; word
SAVE = $08 ; word
KEYLEN = $0A ; byte
VALUELEN = $0B ; byte
MAX = $0C ; byte
HTAB = $24 ; byte
VTAB = $25 ; byte
RNDSEED = $4E ; word
Expand Down
14 changes: 2 additions & 12 deletions src/glue.launch.a
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,8 @@ PlayGame
+STAY SAVE
+STAY @pfile ; assume we're loading a game-specific prelaunch file

jsr Home ; clear screen (clobbers $106, must do now before loading prelaunch code)
lda #$20 ; clear both hi-res pages
sta @clear+2 ; (in case game loader shows them, we don't want
ldx #$40 ; to flash previous bits of the launcher UI)
ldy #$00
tya
@clear sta $FD00,y ; SMC
iny
bne @clear
inc @clear+2
dex
bne @clear
jsr ClearScreens ; avoid seeing code load into the HGR page
; (clobbers $106, must do now before loading prelaunch code)

jsr LoadFile ; load this game's prelaunch file at $106
!word kPrelaunchDirectory
Expand Down
38 changes: 20 additions & 18 deletions src/okvs.a
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,16 @@ okvs_append
ldy #0
lda (SRC),y
tay
iny
sty KEYLEN
- dey ; copy new key
lda (SRC),y
tax
- lda (SRC),y ; copy new key
sta (PTR),y
dey
cpy #$FF
bne -

lda PTR ; update PTR to byte after copied key
clc
adc KEYLEN
sec
txa
adc PTR ; update PTR to byte after copied key
sta PTR
bcc +
inc PTR+1
Expand All @@ -168,21 +167,22 @@ okvs_append
+STAY SRC ; SRC -> new value to copy
ldy #7
lda (PARAM),y ; get max length of value
tay
tax
bne +
lda (SRC),y ; no max, use actual length instead
tay
iny
+ sty VALUELEN
- dey
lda (SRC),y
lda (SRC),y ; no max, use actual length instead
tax
inx
+ tay
- lda (SRC),y
sta (PTR),y
dey
cpy #$FF
bne -

lda PTR
txa
clc
adc VALUELEN
adc PTR
sta SRC
bcc +
inc PTR+1
Expand Down Expand Up @@ -229,7 +229,7 @@ okvs_get
; Y = 0
lda (PTR),y ; A = number of keys in store
beq @fail ; no keys, fail immediately
sta MAX
sta @max
jsr incptr3
; PTR -> first record
ldx #0
Expand All @@ -255,7 +255,8 @@ okvs_get
cmp (DEST),y
bne @next
iny
cpy KEYLEN
KEYLEN = *+1
cpy #$D1 ; SMC
bne @matchKeyLoop
+LDAY PTR
clc
Expand All @@ -271,7 +272,8 @@ okvs_get
+ rts
@next jsr derefptr ; PTR -> next record
inx
cpx MAX
@max = *+1
cpx #$D1 ; SMC
bne @matchRecordLoop
@fail sec
rts
Expand Down
6 changes: 3 additions & 3 deletions src/prodos.path.a
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ kSFXFizzleFile
; Y contains high byte of address of length-prefixed string to append
; out: all registers and flags clobbered
; $02/$03 (PTR/PTR+1) clobbered
; MAX clobbered
; gPathname updated with concatenated length-prefixed string
;------------------------------------------------------------------------------
SetPath
Expand All @@ -133,14 +132,15 @@ AddToPath
beq @done
tay
iny
sty MAX
sty @max
ldx gPathname ; current pathname length
ldy #$01
- lda (PTR),y
sta gPathname+1,x
inx
iny
cpy MAX
@max = *+1
cpy #$D1 ; SMC
bcc -
stx gPathname
@done
Expand Down
3 changes: 3 additions & 0 deletions src/ui.animation.a
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

; /!\ execution falls through from ui.search.mode/FindMatchingTitle
MaybeAnimateTitle
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1

; out: C clear
lda #$3F
ldy OffscreenPage
Expand Down
7 changes: 3 additions & 4 deletions src/ui.attract.hgr.a
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ HGRSingle
@fname !word $FDFD ; SMC
!word $4000
jsr LoadHGRTransition ; load transition effect code at $6000
+LDADDR $6000
jmp ExecuteTransitionAndWait
jmp .transition

;------------------------------------------------------------------------------
; LoadHGRTransition [private]
Expand Down Expand Up @@ -100,8 +99,7 @@ HGRTitleCallback
+ !word $FDFD ; SMC
!word $4000

+LDADDR $6000
jmp ExecuteTransitionAndWait
jmp .transition

;------------------------------------------------------------------------------
; HGRActionCallback [private]
Expand Down Expand Up @@ -160,6 +158,7 @@ HGRActionCallback
lda #3 ; solid vertical bar character
jsr @drawline

.transition
+LDADDR $6000
jmp ExecuteTransitionAndWait
@resetline
Expand Down
3 changes: 2 additions & 1 deletion src/ui.attract.mode.a
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ RunAttractModule
beq +
stx gGameToLaunch
+
jsr Home ; avoid seeing code load into the HGR page
jsr ClearScreens ; avoid seeing code load into the HGR page
; (clobbers $106, must do now before loading prelaunch code)

jsr LoadFile ; load standard prelaunch code (|Launch| will call it)
!word kPrelaunchDirectory
Expand Down
10 changes: 1 addition & 9 deletions src/ui.attract.shr.a
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,8 @@ BlankSHR
sta SHADOW

lda #$20 ; clear $2000..$9FFF in auxmem
sta @a+2
ldx #$80
lda #0
tay
@a sta $2000,y
iny
bne @a
inc @a+2
dex
bne @a
jsr ClearMem

sta WRITEMAINMEM ; writes go to main memory

Expand Down
31 changes: 15 additions & 16 deletions src/ui.browse.mode.a
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,25 @@ OnBrowseSearch
jmp SearchMode

OnBrowsePrevious
dec gGameToLaunch
jmp +
ldx gGameToLaunch
bne .decindex
ldx GameCount

.decindex
dex

.setindex
stx gGameToLaunch
jmp OnBrowseChanged

OnBrowseNext
inc gGameToLaunch
+
ldx gGameToLaunch
cpx #$FF
bne @notTooSmall
inx
GameCount = *+1
ldx #$D1 ; SMC
dex
bne @done ; always branches
@notTooSmall
cpx GameCount
bcc @done
cpx #$D1 ; SMC
bne .setindex
ldx #0
@done stx gGameToLaunch
jmp OnBrowseChanged
beq .setindex ; branch always

OnBrowseLaunch
jsr PlayGame
Expand All @@ -112,8 +113,6 @@ OnBrowseChanged
jsr EnableAcceleratorAndSwitchToBank1
jsr LoadGameTitleOffscreen
jsr DrawUIWithoutDots
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1
jmp MaybeAnimateTitle

;------------------------------------------------------------------------------
Expand Down
26 changes: 25 additions & 1 deletion src/ui.common.a
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,36 @@
; miscellaneous UI functions
;
; Public functions
; - ClearScreens
; - Home
; - BlankDHGR
; - IsSearchKey
; - IsUpDownOrRightArrow
;

;------------------------------------------------------------------------------
; ClearScreens
; clear and display text screen and then clear both hires screens
; (in this order so that the erasing isn't visible)
;
; in: none
; out: $0106..$011F clobbered
;------------------------------------------------------------------------------
ClearScreens
jsr Home
lda #$20 ; clear both hi-res pages
sta @clear+2 ; (in case game loader shows them, we don't want
ldx #$40 ; to flash previous bits of the launcher UI)
ldy #$00
tya
@clear sta $FD00,y ; SMC
iny
bne @clear
inc @clear+2
dex
bne @clear
rts

;------------------------------------------------------------------------------
; Home
; clear and display text screen (HARDER THAN IT SOUNDS)
Expand Down Expand Up @@ -75,7 +99,7 @@ BlankDHGR
; out: A &= 0x7F
; Y preserved
; X clobbered
; Z = 1 if this is a search key
; Z = 1 and C = 0 if this is a search key
; Z = 0 if this is not a search key
;------------------------------------------------------------------------------
IsSearchKey
Expand Down
2 changes: 1 addition & 1 deletion src/ui.credits.a
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Help
jsr IsUpDownOrRightArrow
beq -
jsr IsSearchKey
beq -
bne --
rts
12 changes: 6 additions & 6 deletions src/ui.offscreen.a
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
; - ToggleOffscreenPage
; - ClearOffscreen
; - ClearHGR1
; - ClearMem
;
; Public variables
; - OffscreenPage
Expand All @@ -27,16 +28,14 @@
; preserves X/Y
;------------------------------------------------------------------------------
GetOffscreenAddress
lda #$40
OffscreenPage = * + 1
lda #$00 ; SMC
bne + ; SMC
; 0 = currently showing HGR page 2
; (so offscreen is page 1 @ $2000)
; 1 = currently showing HGR page 1
; (so offscreen is page 2 @ $4000)
beq +
lda #$40
rts
+ lda #$20
+ lsr
rts

;------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,8 +112,9 @@ ClearOffscreen
+HIDE_NEXT_2_BYTES
ClearHGR1
lda #$20 ; note to self: LDX #$20 can't move here
sta @a+2
ldx #$20
ClearMem
sta @a+2
lda #$80
ldy #0
@a sta $2000,y
Expand Down

0 comments on commit 89869a2

Please sign in to comment.