From dc0827941eac256217a2fd4f829ad87d9dfb03b1 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 29 Nov 2017 23:17:32 -0500 Subject: [PATCH] tfv: inner loop optimization --- gr-sim/tfv_flying_6502.c | 2 +- tfv/OPTIMIZATION | 14 ++++++++++++++ tfv/tfv_flying.s | 10 ++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/gr-sim/tfv_flying_6502.c b/gr-sim/tfv_flying_6502.c index 49611029..dc45d74c 100644 --- a/gr-sim/tfv_flying_6502.c +++ b/gr-sim/tfv_flying_6502.c @@ -838,7 +838,7 @@ match: ram[SCREEN_X]++; if (ram[SCREEN_X] >= LOWRES_W) break; - cycles.mode7+=43; + cycles.mode7+=41; /* cache last value */ diff --git a/tfv/OPTIMIZATION b/tfv/OPTIMIZATION index 094edc05..dcd9c55d 100644 --- a/tfv/OPTIMIZATION +++ b/tfv/OPTIMIZATION @@ -186,5 +186,19 @@ In-line unsigned multiply inside of signed multiply (save 12 cycles) Frame Rate = 5.42 fps +Have loop counter count down from 40 instead of count up (avoid compare) + Cycles: flying= 187 + Cycles: getkey= 46 + Cycles: page_flip= 26 + Cycles: multiply= 40,888 + Cycles: mode7= 115,538 + Cycles: lookup_map= 22,747 + Cycles: put_sprite= 2,561 + ================================ + Total = 181,993 + Frame Rate = 5.49 fps + + + Each cycle removed from inner X loop saves 32*40=1280 cycles diff --git a/tfv/tfv_flying.s b/tfv/tfv_flying.s index 916b7eec..f971a8d2 100644 --- a/tfv/tfv_flying.s +++ b/tfv/tfv_flying.s @@ -935,8 +935,7 @@ calc_horizontal_scale: ; brk ; space_y = f7:04 - ; FIXME: start at 40 and decrement? - ldx #0 ; was SCREEN_X ; 2 + ldx #40 ; was SCREEN_X ; 2 ;========== ; 22 screenx_loop: @@ -994,11 +993,10 @@ dyi_label: adc #0 ; 2 sta SPACEY_I ; 3 - inx ;inc SCREEN_X ; 2 - cpx #40 ; LOWRES width ; 2 - beq done_screenx_loop ; 2nt/3 + dex ; decrement SCREEN_X ; 2 + beq done_screenx_loop ; branch until we've done 40 ; 2nt/3 ;============= - ; 43 + ; 41 ; cache color and return if same as last time