Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Aug 3, 2016
1 parent 12b1424 commit 1863155
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 57 deletions.
58 changes: 13 additions & 45 deletions apu.s
Expand Up @@ -2,35 +2,30 @@
; Updates the APU registers. x and y are free to use
;

.if 0
; Found this on nesdev bbs by blargg,
; this can replace the volume table but takes a little more CPU
ft_get_volume:

lda var_ch_VolColumn, x
lsr a
lsr a
lsr a
sta var_Temp
lda var_ch_Volume, x
sta var_Temp2

lda var_Temp ; 4x4 multiplication
; calculates FLOOR(((var_Temp + 1) * (var_Temp2 + 1) - 1) / 16)
; 4 effective bits for var_Temp2, each block adds one
.if .defined(USE_VRC6) || .defined(USE_FDS)
ft_multiply_volume: ;;; ;; ; 050B
lda var_Temp
lsr var_Temp2
bcs :+
lsr a
: lsr var_Temp2
:
lsr var_Temp2
bcc :+
adc var_Temp
: lsr a
: lsr a

lsr var_Temp2
bcc :+
adc var_Temp
: lsr a
: lsr a

lsr var_Temp2
bcc :+
adc var_Temp
: lsr a
: lsr a

beq :+
rts
: lda var_Temp
Expand Down Expand Up @@ -478,33 +473,6 @@ ft_update_apu:
@Return:
rts

.if .defined(USE_VRC6) || .defined(USE_FDS)
ft_multiply_volume: ;;; ;; ; 050B
lda var_Temp ; 5x4 multiplication
lsr var_Temp2
bcs :+
lsr a
: lsr var_Temp2
bcc :+
adc var_Temp
: lsr a
lsr var_Temp2
bcc :+
adc var_Temp
: lsr a
lsr var_Temp2
bcc :+
adc var_Temp
: lsr a
beq :+
rts
: lda var_Temp
ora var_ch_Volume, x
beq :+
lda #$01 ; Round up to 1
: rts
.endif

; Lookup tables

ft_duty_table:
Expand Down
14 changes: 8 additions & 6 deletions init.s
Expand Up @@ -539,10 +539,12 @@ ft_SkipToRow:
sta var_Temp2
jmp @Finished

@EffectDispatch: ;;; ;; ;
jsr @Effect
@NoRowDelay:
; Read a row
lda (var_Temp_Pattern), y
bmi @Effect
bmi @EffectDispatch

lda var_ch_DefaultDelay, x
cmp #$FF
Expand Down Expand Up @@ -611,30 +613,30 @@ ft_SkipToRow:
iny ; Command takes two bytes
@OneByteCommand: ; Command takes one byte
iny
jmp @NoRowDelay ; A new command or note is immediately following
rts ; A new command or note is immediately following
@EffectDuration:
iny
lda (var_Temp_Pattern), y
iny
sta var_ch_DefaultDelay, x
jmp @NoRowDelay
rts
@EffectNoDuration:
iny
lda #$FF
sta var_ch_DefaultDelay, x
jmp @NoRowDelay
rts
@LoadInstCmd: ; mult-byte
iny
lda (var_Temp_Pattern), y
iny
sta var_Temp3
jmp @NoRowDelay
rts
@LoadInst: ; single byte
iny
and #$0F
asl a
sta var_Temp3
jmp @NoRowDelay ;;; ;; ; var_ch_NoteDelay remains unaltered
rts ;;; ;; ; var_ch_NoteDelay remains unaltered

.else ; ENABLE_ROW_SKIP
rts
Expand Down
10 changes: 4 additions & 6 deletions instrument.s
Expand Up @@ -334,15 +334,13 @@ ft_run_sequence:
pha
lda var_ch_State, x
and #STATE_RELEASE ;;; ;; ;
bne :+
pla
bne :++
: pla
rts ; Return new index
: ldy #$02 ; Check release point
lda (var_Temp_Pointer), y
bne :+
pla ; Release point not found, loop
rts
: sta var_Temp ;;; ;; ;
beq :-- ; Release point not found, loop
sta var_Temp ;;; ;; ;
dec var_Temp
pla ; Release point found, don't loop
cmp var_Temp
Expand Down

0 comments on commit 1863155

Please sign in to comment.