Rearranged code for more short branches.

This commit is contained in:
Chris Hodges 2022-12-28 11:51:37 +01:00
parent 7bac794dd8
commit 2a1d9e9bc1
3 changed files with 63 additions and 52 deletions

View File

@ -100,6 +100,14 @@ about 34 on average!).
Watch out for *Presto*, the [LightSpeedPlayer](https://github.com/arnaud-carre/LSPlayer) variant that should
solve this problem.
### Known issues
- Behaviour for undefined volume slides with both up- and down nibble specified is different (e.g. A9A, hi Rapture!). Don't do that.
- Don't use loops with odd lengths and offsets.
- Don't stop the music with F00 and use a note delay (EDx) in the same line.
- Don't try to play music with no waves, instruments or patterns.
- Shinobi seemed to have used an early beta version of Pretracker where it was possible to specify a Subloop Wait of 0. That's illegal.
## Changelog
### V1.1 (unreleased)
@ -110,7 +118,10 @@ solve this problem.
- Various small optimizations
- Store instrument number * 4 on loading to avoid using two adds every frame
- Optimized speed/shuffle code. Idea of using xor turned out to make things too complicated for pattern breaks/jumps.
- Rearranged code for more short branches.
- Drop-in replacement code size: 6324 bytes.
### V1.0 (26-Dec-22)
- Initial release
- Initial release.
- Drop-in replacement code size: 6446 bytes.

View File

@ -2,4 +2,4 @@ This file "raspberry_casket.bin" can replace the original "player.bin"
provided that you used the 16 KB + 16 KB allocation for player
variables as in the original player.
It has been assembled from src/drop_in_replacement.asm.
It has been assembled from src/drop_in_replacement.asm (version V1.0).

View File

@ -2767,6 +2767,32 @@ pre_PlayerTick:
dc.w .pat_set_speed-.pattern_command_jmptable
; d5 = command parameter data
; ----------------------------------------
.pat_set_speed
lea pv_pat_speed_even_b(a4),a1
cmpi.b #MAX_SPEED,d5
bhs.s .pat_set_speed_shuffle
move.b d5,(a1)+ ; pv_pat_speed_even_b
move.b d5,(a1)+ ; pv_pat_speed_odd_b
move.b d5,(a1)+ ; pv_pat_line_ticks_b
sne (a1)+ ; pv_pat_stopped_b
IFNE PRETRACKER_SONG_END_DETECTION
seq (a1)+ ; pv_songend_detected_b
ENDC
bra .pat_play_cont
.pat_set_speed_shuffle
moveq.l #15,d2
and.w d5,d2 ; odd speed
lsr.w #4,d5 ; even speed
move.b d5,(a1)+ ; pv_pat_speed_even_b
move.b d2,(a1)+ ; pv_pat_speed_odd_b
btst #0,pv_pat_curr_row_b(a4)
beq.s .pat_shuffle_on_even
move.b d2,d5 ; toggle speed to odd row
.pat_shuffle_on_even
move.b d5,(a1)+ ; pv_pat_line_ticks_b
bra .pat_play_cont
; ----------------------------------------
.pat_set_vibrato
clr.w pcd_vibrato_pos_w(a5)
@ -2781,12 +2807,12 @@ pre_PlayerTick:
muls pcd_vibrato_depth_w(a5),d2
asr.w #4,d2
move.w d2,pcd_vibrato_speed_w(a5)
bra .pat_play_cont
bra.s .pat_play_cont
; ----------------------------------------
.pat_set_track_delay
cmp.b #NUM_CHANNELS-1,pcd_channel_num_b(a5)
beq .pat_play_cont ; we are at channel 3 -- track delay not available here
beq.s .pat_play_cont ; we are at channel 3 -- track delay not available here
lea pcd_SIZEOF+pcd_track_delay_buffer+ocd_volume(a5),a1
moveq.l #MAX_TRACK_DELAY-1,d2
@ -2800,6 +2826,24 @@ pre_PlayerTick:
st pcd_track_delay_steps_b(a5)
bra.s .handle_track_delay
; ----------------------------------------
.pat_volume_ramp
tst.b d5
beq.s .pat_play_cont
moveq.l #15,d3
and.b d5,d3
beq.s .pat_vol_ramp_up
; NOTE: Changed behaviour: using d3 instead of d5
; if both lower and upper were specified, this
; probably led to a drastic decrease of volume.
neg.b d3
move.b d3,pcd_pat_vol_ramp_speed_b(a5)
bra.s .pat_play_cont
.pat_vol_ramp_up
lsr.b #4,d5
move.b d5,pcd_pat_vol_ramp_speed_b(a5)
bra.s .pat_play_cont
.pat_track_delay_set
moveq.l #15,d2
and.b d5,d2
@ -2824,26 +2868,13 @@ pre_PlayerTick:
bra.s .pat_play_cont
; ----------------------------------------
.pat_volume_ramp
tst.b d5
beq.s .pat_play_cont
moveq.l #15,d3
and.b d5,d3
beq.s .pat_vol_ramp_up
; NOTE: Changed behaviour: using d3 instead of d5
; if both lower and upper were specified, this
; probably led to a drastic decrease of volume.
neg.b d3
move.b d3,pcd_pat_vol_ramp_speed_b(a5)
bra.s .pat_play_cont
.pat_vol_ramp_up
lsr.b #4,d5
move.b d5,pcd_pat_vol_ramp_speed_b(a5)
.pat_pos_jump
move.b d5,pv_next_pat_pos_b(a4)
bra.s .pat_play_cont
; ----------------------------------------
.pat_pos_jump
move.b d5,pv_next_pat_pos_b(a4)
.pat_pat_break
move.b d5,pv_next_pat_row_b(a4)
bra.s .pat_play_cont
; ----------------------------------------
@ -2853,37 +2884,6 @@ pre_PlayerTick:
moveq.l #MAX_VOLUME,d5
.pat_set_volume_nomax
move.b d5,pcd_pat_vol_b(a5)
bra.s .pat_play_cont
; ----------------------------------------
.pat_pat_break
move.b d5,pv_next_pat_row_b(a4)
bra.s .pat_play_cont
; ----------------------------------------
.pat_set_speed
lea pv_pat_speed_even_b(a4),a1
cmpi.b #MAX_SPEED,d5
bhs.s .pat_set_speed_shuffle
move.b d5,(a1)+ ; pv_pat_speed_even_b
move.b d5,(a1)+ ; pv_pat_speed_odd_b
move.b d5,(a1)+ ; pv_pat_line_ticks_b
sne (a1)+ ; pv_pat_stopped_b
IFNE PRETRACKER_SONG_END_DETECTION
seq (a1)+ ; pv_songend_detected_b
ENDC
bra.s .pat_play_cont
.pat_set_speed_shuffle
moveq.l #15,d2
and.w d5,d2 ; odd speed
lsr.w #4,d5 ; even speed
move.b d5,(a1)+ ; pv_pat_speed_even_b
move.b d2,(a1)+ ; pv_pat_speed_odd_b
btst #0,pv_pat_curr_row_b(a4)
beq.s .pat_shuffle_on_even
move.b d2,d5 ; toggle speed to odd row
.pat_shuffle_on_even
move.b d5,(a1)+ ; pv_pat_line_ticks_b
; ----------------------------------------