tfv: more cycles annotations

This commit is contained in:
Vince Weaver 2017-11-23 23:57:30 -05:00
parent 91df570368
commit aff3b25264
3 changed files with 277 additions and 255 deletions

View File

@ -85,6 +85,16 @@ static unsigned char water_map[32]={
static int displayed=0;
struct cycle_counts {
int flying;
int getkey;
int page_flip;
int mode7;
int multiply;
int lookup_map;
int put_sprite;
} cycles;
static int lookup_map(int xx, int yy) {
int color,offset;
@ -122,7 +132,7 @@ static int lookup_map(int xx, int yy) {
}
cycles.lookup_map+=53;
return color;
}
@ -183,15 +193,7 @@ static unsigned char horizontal_lookup[7][16] = {
};
struct cycle_counts {
int flying;
int getkey;
int page_flip;
int mode7;
int multiply;
int lookup_map;
int put_sprite;
} cycles;
static void fixed_add(unsigned char x_i,unsigned char x_f,
@ -573,7 +575,7 @@ void draw_background_mode7(void) {
}
// go through all points in this screen line
for (ram[SCREEN_X] = 0; ram[SCREEN_X] < LOWRES_W-1; ram[SCREEN_X]++) {
for (ram[SCREEN_X] = 0; ram[SCREEN_X] < LOWRES_W; ram[SCREEN_X]++) {
// get a pixel from the tile and put it on the screen
map_color=lookup_map(ram[SPACEX_I],ram[SPACEY_I]);
@ -618,50 +620,43 @@ int flying(void) {
/************************************************/
gr();
clear_bottom(PAGE0); /* jsr clear_screens */
clear_bottom(PAGE1); /* jsr set_gr_page0 */
clear_bottom(PAGE0);
clear_bottom(PAGE1);
ram[SHIPY]=20; /* lda #20 */
/* sta SHIPY */
/* lda #0 */
ram[TURNING]=0; /* sta TURNING */
ram[SPACEX_I]=0; /* sta SPACEX_I */
ram[SPACEY_I]=0; /* sta SPACEY_I */
ram[CX_I]=0; /* sta CX_I */
ram[CX_F]=0; /* sta CX_F */
ram[CY_I]=0; /* sta CY_I */
ram[CY_F]=0; /* sta CY_F */
ram[DRAW_SPLASH]=0; /* sta DRAW_SPLASH */
ram[SPEED]=0; /* sta SPEED */
ram[SPLASH_COUNT]=0; /* sta SPLASH_COUNT */
ram[OVER_WATER]=0; /* sta OVER_WATER */
ram[SHIPY]=20;
ram[TURNING]=0;
ram[SPACEX_I]=0;
ram[SPACEY_I]=0;
ram[CX_I]=0;
ram[CX_F]=0;
ram[CY_I]=0;
ram[CY_F]=0;
ram[DRAW_SPLASH]=0;
ram[SPEED]=0;
ram[SPLASH_COUNT]=0;
ram[OVER_WATER]=0;
/* lda #1 */
ram[ANGLE]=1; /* sta ANGLE */
ram[ANGLE]=1; /* 1 so you can see island */
/* lda #4 */
ram[SPACEZ_I]=4; /* sta SPACEZ_I */
/* lda #$80 */
ram[SPACEZ_F]=0x80; /* sta SPACEZ_F */
ram[SPACEZ_I]=4;
ram[SPACEZ_F]=0x80; /* Z=4.5 */
while(1) {
memset(&cycles,0,sizeof(cycles));
// lda SPLASH_COUNT 3
cycles.flying+=3;
// beq flying_keyboard nt2/3
cycles.flying+=3;
cycles.flying+=6;
if (ram[SPLASH_COUNT]>0) {
cycles.flying--;
ram[SPLASH_COUNT]--; // dec SPLASH_COUNT 5
ram[SPLASH_COUNT]--;
cycles.flying+=5;
}
ch=grsim_input(); // jsr get_key 6+40
ch=grsim_input();
cycles.getkey=46;
if ((ch=='q') || (ch==27)) break;
cycles.flying+=3;
if ((ch=='q') || (ch==27)) break;
cycles.flying+=5;
if ((ch=='w') || (ch==APPLE_UP)) {
if (ram[SHIPY]>16) {
ram[SHIPY]-=2;
@ -669,6 +664,7 @@ int flying(void) {
}
ram[SPLASH_COUNT]=0;
}
cycles.flying+=5;
if ((ch=='s') || (ch==APPLE_DOWN)) {
if (ram[SHIPY]<28) {
ram[SHIPY]+=2;
@ -678,6 +674,7 @@ int flying(void) {
ram[SPLASH_COUNT]=10;
}
}
cycles.flying+=5;
if ((ch=='a') || (ch==APPLE_LEFT)) {
if ((ram[TURNING]>0) && (!(ram[TURNING]&0x80))) {
ram[TURNING]=0;
@ -689,6 +686,7 @@ int flying(void) {
if (ram[ANGLE]<0) ram[ANGLE]+=ANGLE_STEPS;
}
}
cycles.flying+=5;
if ((ch=='d') || (ch==APPLE_RIGHT)) {
if (ram[TURNING]>128) {
ram[TURNING]=0;
@ -700,24 +698,24 @@ int flying(void) {
}
}
cycles.flying+=5;
/* Used to be able to go backwards */
if (ch=='z') {
if (ram[SPEED]<3) ram[SPEED]++;
}
cycles.flying+=5;
if (ch=='x') {
if (ram[SPEED]>0) ram[SPEED]--;
}
cycles.flying+=5;
if (ch==' ') {
ram[SPEED]=SPEED_STOPPED;
}
cycles.flying+=5;
if (ch=='h') {
print_help();
}
cycles.flying+=5;
/* Ending */
if (ch==13) {
int landing_color,tx,ty;
@ -752,10 +750,12 @@ int flying(void) {
print_both_pages("NEED TO LAND ON GRASS!");
}
}
cycles.flying+=5;
// check_done:
cycles.flying+=14;
if (ram[SPEED]!=SPEED_STOPPED) {
cycles.flying--;
int ii;
@ -763,7 +763,7 @@ int flying(void) {
ram[DX_F] = fixed_sin_scale[(ram[ANGLE]+4)&0xf].f; // cos
ram[DY_I] = fixed_sin_scale[ram[ANGLE]&0xf].i;
ram[DY_F] = fixed_sin_scale[ram[ANGLE]&0xf].f;
cycles.flying+=54;
for(ii=0;ii<ram[SPEED];ii++) {
fixed_add(ram[CX_I],ram[CX_F],
ram[DX_I],ram[DX_F],
@ -771,14 +771,16 @@ int flying(void) {
fixed_add(ram[CY_I],ram[CY_F],
ram[DY_I],ram[DY_F],
&ram[CY_I],&ram[CY_F]);
cycles.flying+=45;
}
cycles.flying--;
}
draw_background_mode7();
cycles.flying+=6;
ram[DRAW_SPLASH]=0;
cycles.flying+=11;
if (ram[SPEED]>0) {
if ((ram[SHIPY]>25) && (ram[TURNING]!=0)) {
@ -794,32 +796,40 @@ int flying(void) {
if (ram[DRAW_SPLASH]) {
grsim_put_sprite(splash_forward,
CONST_SHIPX+1,ram[SHIPY]+9);
cycles.flying+=33;
}
grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]);
cycles.flying+=46;
}
else if (ram[TURNING]>128) {
if (ram[DRAW_SPLASH]) {
grsim_put_sprite(splash_left,
CONST_SHIPX+1,36);
cycles.flying+=28;
}
grsim_put_sprite(shadow_left,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_left,CONST_SHIPX,ram[SHIPY]);
ram[TURNING]++;
cycles.flying+=48;
}
else {
if (ram[DRAW_SPLASH]) {
grsim_put_sprite(splash_right,
CONST_SHIPX+1,36);
cycles.flying+=28;
}
grsim_put_sprite(shadow_right,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_right,CONST_SHIPX,ram[SHIPY]);
ram[TURNING]--;
cycles.flying+=51;
}
page_flip(); cycles.page_flip+=26;
cycles.flying+=17;
page_flip(); cycles.page_flip+=26;
cycles.flying+=9;
iterations++;
if (iterations==100) {

View File

@ -4,6 +4,8 @@ mode7 speed fixes:
+ move multiply vars to zero page
+ leave one of multiply results in accumulator at end?
+ Skip key parsing if no key read
short term:
longer term:

View File

@ -83,16 +83,15 @@ flying_start:
flying_loop:
lda SPLASH_COUNT
beq flying_keyboard
dec SPLASH_COUNT ; decrement splash count
lda SPLASH_COUNT ; 3
beq flying_keyboard ; 2nt/3
dec SPLASH_COUNT ; decrement splash count ; 5
flying_keyboard:
jsr get_key ; get keypress ; 6
jsr get_key ; get keypress
lda LASTKEY
lda LASTKEY ; 3
; cmp #('Q') ; if quit, then return
; bne skipskip
@ -100,8 +99,8 @@ flying_keyboard:
;skipskip:
cmp #('W')
bne check_down
cmp #('W') ; 2
bne check_down ; 3/2nt
;===========
; UP PRESSED
@ -301,99 +300,98 @@ check_done:
;================
; Wrap the Angle
;================
lda ANGLE
and #$f
sta ANGLE
; FIXME: only do this in right/left routine?
lda ANGLE ; 3
and #$f ; 2
sta ANGLE ; 3
;================
; Handle Movement
;================
speed_move:
ldx SPEED
beq draw_background
lda ANGLE ; dx.i=fixed_sin[(angle+4)&0xf].i; // cos()
clc
adc #4
and #$f
asl
tay
lda fixed_sin_scale,Y
sta DX_I
iny ; dx.f=fixed_sin[(angle+4)&0xf].f; // cos()
lda fixed_sin_scale,Y
sta DX_F
lda ANGLE ; dy.i=fixed_sin[angle&0xf].i; // sin()
and #$f
asl
tay
lda fixed_sin_scale,Y
sta DY_I
iny ; dx.f=fixed_sin[angle&0xf].f; // sin()
lda fixed_sin_scale,Y
sta DY_F
ldx SPEED ; 3
beq draw_background ; 2nt/3
;=============
lda ANGLE ; dx.i=fixed_sin[(angle+4)&0xf].i; // cos() ; 3
clc ; 2
adc #4 ; 2
and #$f ; 2
asl ; 2
tay ; 2
lda fixed_sin_scale,Y ; 4
sta DX_I ; 3
iny ; dx.f=fixed_sin[(angle+4)&0xf].f; // cos() ; 2
lda fixed_sin_scale,Y ; 4
sta DX_F ; 3
lda ANGLE ; dy.i=fixed_sin[angle&0xf].i; // sin() ; 3
and #$f ; 2
asl ; 2
tay ; 2
lda fixed_sin_scale,Y ; 4
sta DY_I ; 3
iny ; dx.f=fixed_sin[angle&0xf].f; // sin() ; 2
lda fixed_sin_scale,Y ; 4
sta DY_F ; 3
;============
; 54
speed_loop:
clc ; fixed_add(&cx,&dx,&cx);
lda CX_F
adc DX_F
sta CX_F
lda CX_I
adc DX_I
sta CX_I
clc ; fixed_add(&cx,&dx,&cx); ; 2
lda CX_F ; 3
adc DX_F ; 3
sta CX_F ; 3
lda CX_I ; 3
adc DX_I ; 3
sta CX_I ; 3
clc ; fixed_add(&cy,&dy,&cy);
lda CY_F
adc DY_F
sta CY_F
lda CY_I
adc DY_I
sta CY_I
dex
bne speed_loop
clc ; fixed_add(&cy,&dy,&cy); ; 2
lda CY_F ; 3
adc DY_F ; 3
sta CY_F ; 3
lda CY_I ; 3
adc DY_I ; 3
sta CY_I ; 3
dex ; 2
bne speed_loop ; 2nt/3
;============
; 45
;====================
; Draw the background
;====================
draw_background:
jsr draw_background_mode7
; lda #1
; sta OVER_WATER
jsr draw_background_mode7 ; 6
; Calculate whether to draw the splash
lda #0 ; set splash drawing to 0
sta DRAW_SPLASH
lda #0 ; set splash drawing to 0 ; 2
sta DRAW_SPLASH ; 3
lda SPEED ; if speed==0, no splash
beq no_splash
lda SPEED ; if speed==0, no splash ; 3
beq no_splash ; 2nt/3
lda TURNING
beq no_turning_splash
lda TURNING ; 3
beq no_turning_splash ; 2nt/3
lda SHIPY
cmp #27
bcc no_turning_splash ; blt if shipy<25 skip
lda SHIPY ; 3
cmp #27 ; 2
bcc no_turning_splash ; blt if shipy<25 skip ; 2nt/3
lda #1
sta SPLASH_COUNT
lda #1 ; 2
sta SPLASH_COUNT ; 3
no_turning_splash:
lda OVER_WATER ; no splash if over land
beq no_splash
lda OVER_WATER ; no splash if over land ; 3
beq no_splash ; 2nt/3
lda SPLASH_COUNT ; no splash if splash_count expired
beq no_splash
lda SPLASH_COUNT ; no splash if splash_count expired ; 3
beq no_splash ; 2nt/3
lda #1
sta DRAW_SPLASH
lda #1 ; 2
sta DRAW_SPLASH ; 3
no_splash:
@ -401,146 +399,158 @@ no_splash:
; Draw the ship
;==============
clv
lda TURNING
beq draw_ship_forward
bpl draw_ship_right
bmi draw_ship_left ;; FIXME: optimize order
clv ; 2
lda TURNING ; 3
beq draw_ship_forward ; 2nt/3
bpl draw_ship_right ; 2nt/3
bmi draw_ship_left ;; FIXME: optimize order ; 2nt/3
draw_ship_forward:
lda DRAW_SPLASH
beq no_forward_splash
lda DRAW_SPLASH ; 2
beq no_forward_splash ; 2nt/3
; Draw Splash
lda #>splash_forward
sta INH
lda #<splash_forward
sta INL
lda #(SHIPX+1)
sta XPOS
clc
lda SHIPY
adc #9
and #$fe ; make sure it's even
sta YPOS
jsr put_sprite
lda #>splash_forward ; 2
sta INH ; 3
lda #<splash_forward ; 2
sta INL ; 3
lda #(SHIPX+1) ; 2
sta XPOS ; 3
clc ; 2
lda SHIPY ; 3
adc #9 ; 2
and #$fe ; make sure it's even ; 2
sta YPOS ; 3
jsr put_sprite ; 6
;==========
; 33
no_forward_splash:
; Draw Shadow
lda #>shadow_forward
sta INH
lda #<shadow_forward
sta INL
lda #(SHIPX+3)
sta XPOS
clc
lda SPACEZ_I
adc #31
and #$fe ; make sure it's even
sta YPOS
jsr put_sprite
lda #>ship_forward
sta INH
lda #<ship_forward
sta INL
bvc draw_ship
lda #>shadow_forward ; 2
sta INH ; 3
lda #<shadow_forward ; 2
sta INL ; 3
lda #(SHIPX+3) ; 2
sta XPOS ; 3
clc ; 2
lda SPACEZ_I ; 3
adc #31 ; 2
and #$fe ; make sure it's even ; 2
sta YPOS ; 3
jsr put_sprite ; 6
lda #>ship_forward ; 2
sta INH ; 3
lda #<ship_forward ; 2
sta INL ; 3
bvc draw_ship ; 3
;===========
; 46
draw_ship_right:
lda DRAW_SPLASH
beq no_right_splash
lda DRAW_SPLASH ; 3
beq no_right_splash ; 2nt/3
; Draw Splash
lda #>splash_right
sta INH
lda #<splash_right
sta INL
lda #(SHIPX+1)
sta XPOS
clc
lda #36
sta YPOS
jsr put_sprite
lda #>splash_right ; 2
sta INH ; 3
lda #<splash_right ; 2
sta INL ; 3
lda #(SHIPX+1) ; 2
sta XPOS ; 3
clc ; 2
lda #36 ; 2
sta YPOS ; 3
jsr put_sprite ; 6
;===========
; 28
no_right_splash:
; Draw Shadow
lda #>shadow_right
sta INH
lda #<shadow_right
sta INL
lda #(SHIPX+3)
sta XPOS
clc
lda SPACEZ_I
adc #31
and #$fe ; make sure it's even
sta YPOS
jsr put_sprite
lda #>shadow_right ; 2
sta INH ; 3
lda #<shadow_right ; 2
sta INL ; 3
lda #(SHIPX+3) ; 2
sta XPOS ; 3
clc ; 2
lda SPACEZ_I ; 3
adc #31 ; 2
and #$fe ; make sure it's even ; 2
sta YPOS ; 3
jsr put_sprite ; 6
lda #>ship_right
sta INH
lda #<ship_right
sta INL
lda #>ship_right ; 2
sta INH ; 3
lda #<ship_right ; 2
sta INL ; 3
dec TURNING
bvc draw_ship
dec TURNING ; 5
bvc draw_ship ; 3
;==========
; 51
draw_ship_left:
lda DRAW_SPLASH
beq no_left_splash
lda DRAW_SPLASH ; 3
beq no_left_splash ; 2nt/3
; Draw Splash
lda #>splash_left
sta INH
lda #<splash_left
sta INL
lda #(SHIPX+1)
sta XPOS
clc
lda #36
sta YPOS
jsr put_sprite
lda #>splash_left ; 2
sta INH ; 3
lda #<splash_left ; 2
sta INL ; 3
lda #(SHIPX+1) ; 2
sta XPOS ; 3
clc ; 2
lda #36 ; 2
sta YPOS ; 3
jsr put_sprite ; 6
;===========
; 28
no_left_splash:
; Draw Shadow
lda #>shadow_left
sta INH
lda #<shadow_left
sta INL
lda #(SHIPX+3)
sta XPOS
clc
lda SPACEZ_I
adc #31
and #$fe ; make sure it's even
sta YPOS
jsr put_sprite
lda #>shadow_left ; 2
sta INH ; 3
lda #<shadow_left ; 2
sta INL ; 3
lda #(SHIPX+3) ; 2
sta XPOS ; 3
clc ; 2
lda SPACEZ_I ; 3
adc #31 ; 2
and #$fe ; make sure it's even ; 2
sta YPOS ; 3
jsr put_sprite ; 6
lda #>ship_left
sta INH
lda #<ship_left
sta INL
lda #>ship_left ; 2
sta INH ; 3
lda #<ship_left ; 2
sta INL ; 3
inc TURNING
inc TURNING ; 5
;==========
; 48
draw_ship:
lda #SHIPX
sta XPOS
lda SHIPY
sta YPOS
jsr put_sprite
lda #SHIPX ; 2
sta XPOS ; 3
lda SHIPY ; 3
sta YPOS ; 3
jsr put_sprite ; 6
;===========
; 17
;==================
; flip pages
;==================
jsr page_flip
jsr page_flip ; 6
;==================
; loop forever
;==================
jmp flying_loop
jmp flying_loop ; 3
;===========================
@ -969,41 +979,41 @@ done_screeny:
; finds value in space_x.i,space_y.i
; returns color in A
lookup_map:
lda SPACEX_I
and #MAP_MASK
sta TEMPY
lda SPACEX_I ; 3
and #MAP_MASK ; 2
sta TEMPY ; 3
lda SPACEY_I
and #MAP_MASK ; wrap to 64x64 grid
lda SPACEY_I ; 3
and #MAP_MASK ; wrap to 64x64 grid ; 2
asl
asl
asl ; multiply by 8
clc
adc TEMPY ; add in X value
asl ; 2
asl ; 2
asl ; multiply by 8 ; 2
clc ; 2
adc TEMPY ; add in X value ; 2
; (use OR instead?)
ldy SPACEX_I
cpy #$8
beq ocean_color ; bgt
bcs ocean_color
ldy SPACEY_I
cpy #$8
beq ocean_color ; bgt
bcs ocean_color
ldy SPACEX_I ; 3
cpy #$8 ; 2
beq ocean_color ; bgt ; 2nt/3
bcs ocean_color ; 2nt/3
ldy SPACEY_I ; 3
cpy #$8 ; 2
beq ocean_color ; bgt ; 2nt/3
bcs ocean_color ; 2nt/3
tay
lda flying_map,Y ; load from array
tay ; 2
lda flying_map,Y ; load from array ; 4
rts
rts ; 6
ocean_color:
and #$1f
tay
lda water_map,Y ; the color of the sea
and #$1f ; 2
tay ; 2
lda water_map,Y ; the color of the sea ; 4
rts
rts ; 6
flying_map:
.byte $22,$ff,$ff,$ff, $ff,$ff,$ff,$22