tfv: add cache for the color values

This commit is contained in:
Vince Weaver 2017-11-25 23:27:55 -05:00
parent 71fde333c9
commit 92e9d3a055
4 changed files with 76 additions and 19 deletions

View File

@ -99,15 +99,29 @@ struct cycle_counts {
int put_sprite; int put_sprite;
} cycles; } cycles;
static int last_color=0,last_xx=0,last_yy=0;
static int lookup_map(int xx, int yy) { static int lookup_map(int xx, int yy) {
int color,offset; int color,offset;
color=2; /* cache last value */
cycles.lookup_map+=9;
if (yy==last_yy) {
cycles.lookup_map+=8;
if (xx==last_xx) {
cycles.lookup_map+=8;
return last_color;
}
}
last_xx=xx;
xx=xx&MASK_X; xx=xx&MASK_X;
last_yy=yy;
yy=yy&MASK_Y; yy=yy&MASK_Y;
if (!displayed) { if (!displayed) {
printf("XX,YY! %x,%x\n",xx,yy); printf("XX,YY! %x,%x\n",xx,yy);
} }
@ -119,24 +133,32 @@ static int lookup_map(int xx, int yy) {
offset=yy<<3; offset=yy<<3;
offset+=xx; offset+=xx;
// color=water_map[((yy*8)+xx)&0x1f]; cycles.lookup_map+=37;
color=water_map[offset&0x1f];
if ((yy>7) || (xx>7)) {
cycles.lookup_map+=14;
color=water_map[offset&0x1f];
cycles.lookup_map+=11;
goto update_cache;
}
/* 2 2 2 2 2 2 2 2 */ /* 2 2 2 2 2 2 2 2 */
/* e 2 2 2 2 2 2 2 */ /* e 2 2 2 2 2 2 2 */
/* 2 2 2 2 2 2 2 2 */ /* 2 2 2 2 2 2 2 2 */
/* 2 2 2 2 e 2 2 2 */ /* 2 2 2 2 e 2 2 2 */
if ((yy<8) && (xx<8)) { color=flying_map[offset];
color=flying_map[offset]; cycles.lookup_map+=8;
}
if (!displayed) { if (!displayed) {
printf("COLOR! %x\n",color); printf("COLOR! %x\n",color);
} }
cycles.lookup_map+=53; update_cache:
cycles.lookup_map+=9;
last_color=color;
return color; return color;
} }

View File

@ -58,3 +58,16 @@ Update to optimize fast multiply (reusing NUM1H, return results in register)
Total = 135,575 Total = 135,575
Frame Rate = 7.38 fps Frame Rate = 7.38 fps
Add a cache to lookup_map
Cycles: flying= 162
Cycles: getkey= 46
Cycles: page_flip= 26
Cycles: multiply= 24,935
Cycles: mode7= 73,445
Cycles: lookup_map= 24,649
Cycles: put_sprite= 2,561
=================================
Total = 125,824
Frame Rate = 7.95 fps

View File

@ -955,11 +955,27 @@ done_screeny:
; finds value in space_x.i,space_y.i ; finds value in space_x.i,space_y.i
; returns color in A ; returns color in A
lookup_map: lookup_map:
; cache color and return if same as last time
lda SPACEY_I ; 3
cmp LAST_SPACEY_I ; 3
bne nomatch ; 2nt/3
lda SPACEX_I ; 3
cmp LAST_SPACEX_I ; 3
bne nomatch2 ; 2nt/3
lda LAST_MAP_COLOR ; 3
rts ; 6
nomatch:
lda SPACEX_I ; 3 lda SPACEX_I ; 3
nomatch2: ; 3
sta LAST_SPACEX_I ; 3
and #CONST_MAP_MASK ; 2 and #CONST_MAP_MASK ; 2
sta TEMPY ; 3 sta TEMPY ; 3
tay ; 2
lda SPACEY_I ; 3 lda SPACEY_I ; 3
sta LAST_SPACEY_I ; 3
and #CONST_MAP_MASK ; wrap to 64x64 grid ; 2 and #CONST_MAP_MASK ; wrap to 64x64 grid ; 2
@ -967,28 +983,31 @@ lookup_map:
asl ; 2 asl ; 2
asl ; multiply by 8 ; 2 asl ; multiply by 8 ; 2
clc ; 2 clc ; 2
adc TEMPY ; add in X value ; 2 adc TEMPY ; add in X value ; 3
; (use OR instead?) ; only valid if x<8 and y<8
ldy SPACEX_I ; 3 ; SPACEX_I is in y
cpy #$8 ; 2 cpy #$9 ; 2
beq ocean_color ; bgt ; 2nt/3 ;============
bcs ocean_color ; 2nt/3 ; 37
bcs ocean_color ; bgt 8 ; 2nt/3
ldy SPACEY_I ; 3 ldy SPACEY_I ; 3
cpy #$8 ; 2 cpy #$9 ; 2
beq ocean_color ; bgt ; 2nt/3 bcs ocean_color ; bgt 8 ; 2nt/3
bcs ocean_color ; 2nt/3
tay ; 2 tay ; 2
lda flying_map,Y ; load from array ; 4 lda flying_map,Y ; load from array ; 4
rts ; 6 bcc update_cache ; 3
ocean_color: ocean_color:
and #$1f ; 2 and #$1f ; 2
tay ; 2 tay ; 2
lda water_map,Y ; the color of the sea ; 4 lda water_map,Y ; the color of the sea ; 4
update_cache:
sta LAST_MAP_COLOR ; 3
rts ; 6 rts ; 6
flying_map: flying_map:

View File

@ -89,7 +89,10 @@ NUM1H EQU $7F
NUM2L EQU $80 NUM2L EQU $80
NUM2H EQU $81 NUM2H EQU $81
RESULT EQU $82 ; 83,84,85 RESULT EQU $82 ; 83,84,85
NEGATE EQU $86 NEGATE EQU $86 ; UNUSED?
LAST_SPACEX_I EQU $87
LAST_SPACEY_I EQU $88
LAST_MAP_COLOR EQU $89
SHIPY EQU $E4 SHIPY EQU $E4