tfv: some cycle counting

This commit is contained in:
Vince Weaver
2017-11-22 01:02:29 -05:00
parent 7c764fb0c1
commit be98d15390
2 changed files with 135 additions and 115 deletions

View File

@@ -53,6 +53,7 @@
#define CONST_BETA_I 0xff // -0.5 ?? #define CONST_BETA_I 0xff // -0.5 ??
#define CONST_BETA_F 0x80 #define CONST_BETA_F 0x80
#define CONST_SHIPX 15
/* Mode7 code based on code from: */ /* Mode7 code based on code from: */
/* http://www.helixsoft.nl/articles/circle/sincos.htm */ /* http://www.helixsoft.nl/articles/circle/sincos.htm */
@@ -548,15 +549,19 @@ void draw_background_mode7(void) {
} }
#define SHIPX 15
struct cycle_counts {
int flying;
int getkey;
int page_flip;
} cycles;
static int iterations=0;
int flying(void) { int flying(void) {
unsigned char ch; unsigned char ch;
int draw_splash=0,splash_count=0;
int zint;
long long cycles=0;
/************************************************/ /************************************************/
/* Flying */ /* Flying */
@@ -590,11 +595,20 @@ int flying(void) {
ram[SPACEZ_F]=0x80; /* sta SPACEZ_F */ ram[SPACEZ_F]=0x80; /* sta SPACEZ_F */
while(1) { while(1) {
cycles=0; memset(&cycles,0,sizeof(cycles));
if (splash_count>0) splash_count--; // lda SPLASH_COUNT 3
cycles.flying+=3;
// beq flying_keyboard nt2/3
cycles.flying+=3;
if (ram[SPLASH_COUNT]>0) {
cycles.flying--;
ram[SPLASH_COUNT]--; // dec SPLASH_COUNT 5
cycles.flying+=5;
}
ch=grsim_input(); ch=grsim_input(); // jsr get_key 6+40
cycles.getkey=46;
if ((ch=='q') || (ch==27)) break; if ((ch=='q') || (ch==27)) break;
@@ -603,7 +617,7 @@ int flying(void) {
ram[SHIPY]-=2; ram[SHIPY]-=2;
ram[SPACEZ_I]++; ram[SPACEZ_I]++;
} }
splash_count=0; ram[SPLASH_COUNT]=0;
} }
if ((ch=='s') || (ch==APPLE_DOWN)) { if ((ch=='s') || (ch==APPLE_DOWN)) {
if (ram[SHIPY]<28) { if (ram[SHIPY]<28) {
@@ -611,7 +625,7 @@ int flying(void) {
ram[SPACEZ_I]--; ram[SPACEZ_I]--;
} }
else { else {
splash_count=10; ram[SPLASH_COUNT]=10;
} }
} }
if ((ch=='a') || (ch==APPLE_LEFT)) { if ((ch=='a') || (ch==APPLE_LEFT)) {
@@ -665,14 +679,12 @@ int flying(void) {
if (landing_color==12) { if (landing_color==12) {
int loop; int loop;
zint=ram[SPACEZ_I];
/* Land the ship */ /* Land the ship */
for(loop=zint;loop>0;loop--) { for(loop=ram[SPACEZ_I];loop>0;loop--) {
draw_background_mode7(); draw_background_mode7();
grsim_put_sprite(shadow_forward,SHIPX+3,31+zint); grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_forward,SHIPX,ram[SHIPY]); grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]);
page_flip(); page_flip();
usleep(200000); usleep(200000);
@@ -715,64 +727,66 @@ int flying(void) {
draw_background_mode7(); draw_background_mode7();
zint=ram[SPACEZ_I]; ram[DRAW_SPLASH]=0;
draw_splash=0;
if (ram[SPEED]>0) { if (ram[SPEED]>0) {
if ((ram[SHIPY]>25) && (ram[TURNING]!=0)) { if ((ram[SHIPY]>25) && (ram[TURNING]!=0)) {
splash_count=1; ram[SPLASH_COUNT]=1;
} }
if ((ram[OVER_WATER]) && (splash_count)) { if ((ram[OVER_WATER]) && (ram[SPLASH_COUNT])) {
draw_splash=1; ram[DRAW_SPLASH]=1;
} }
} }
// printf("VMW: %d %d\n",draw_splash,splash_count);
if (ram[TURNING]==0) { if (ram[TURNING]==0) {
if (draw_splash) { if (ram[DRAW_SPLASH]) {
grsim_put_sprite(splash_forward, grsim_put_sprite(splash_forward,
SHIPX+1,ram[SHIPY]+9); CONST_SHIPX+1,ram[SHIPY]+9);
} }
grsim_put_sprite(shadow_forward,SHIPX+3,31+zint); grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_forward,SHIPX,ram[SHIPY]); grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]);
} }
else if (ram[TURNING]>128) { else if (ram[TURNING]>128) {
if (draw_splash) { if (ram[DRAW_SPLASH]) {
grsim_put_sprite(splash_left, grsim_put_sprite(splash_left,
SHIPX+1,36); CONST_SHIPX+1,36);
} }
grsim_put_sprite(shadow_left,SHIPX+3,31+zint); grsim_put_sprite(shadow_left,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_left,SHIPX,ram[SHIPY]); grsim_put_sprite(ship_left,CONST_SHIPX,ram[SHIPY]);
ram[TURNING]++; ram[TURNING]++;
} }
else { else {
if (draw_splash) { if (ram[DRAW_SPLASH]) {
grsim_put_sprite(splash_right, grsim_put_sprite(splash_right,
SHIPX+1,36); CONST_SHIPX+1,36);
} }
grsim_put_sprite(shadow_right,SHIPX+3,31+zint); grsim_put_sprite(shadow_right,CONST_SHIPX+3,31+ram[SPACEZ_I]);
grsim_put_sprite(ship_right,SHIPX,ram[SHIPY]); grsim_put_sprite(ship_right,CONST_SHIPX,ram[SHIPY]);
ram[TURNING]--; ram[TURNING]--;
} }
page_flip(); page_flip(); cycles.page_flip+=26;
iterations++;
if (iterations==100) {
int total_cycles;
total_cycles=cycles.flying+cycles.getkey+
cycles.page_flip;
printf("Cycles: flying=%d\n",cycles.flying);
printf("Cycles: getkey=%d\n",cycles.getkey);
printf("Cycles: page_flip=%d\n",cycles.page_flip);
printf("Total = %d\n",total_cycles);
printf("Frame Rate = %.2lf fps\n",
(1000000.0 / (double)total_cycles));
iterations=0;
}
printf("Cycles: %lld\n",cycles);
usleep(20000); usleep(20000);
} }
return 0; return 0;
} }

View File

@@ -29,22 +29,24 @@ clear_screens:
;========== ;==========
page_flip: page_flip:
lda DISP_PAGE lda DISP_PAGE ; 3
beq page_flip_show_1 beq page_flip_show_1 ; 2nt/3
page_flip_show_0: page_flip_show_0:
bit PAGE0 bit PAGE0 ; 4
lda #4 lda #4 ; 2
sta DRAW_PAGE ; DRAW_PAGE=1 sta DRAW_PAGE ; DRAW_PAGE=1 ; 3
lda #0 lda #0 ; 2
sta DISP_PAGE ; DISP_PAGE=0 sta DISP_PAGE ; DISP_PAGE=0 ; 3
rts rts ; 6
page_flip_show_1: page_flip_show_1:
bit PAGE1 bit PAGE1 ; 4
sta DRAW_PAGE ; DRAW_PAGE=0 sta DRAW_PAGE ; DRAW_PAGE=0 ; 3
lda #1 lda #1 ; 2
sta DISP_PAGE ; DISP_PAGE=1 sta DISP_PAGE ; DISP_PAGE=1 ; 3
rts rts ; 6
;====================
; DISP_PAGE=0 26
; DISP_PAGE=1 24
;====================== ;======================
; memset ; memset
@@ -253,89 +255,93 @@ check_paddle_button:
; check for paddle button ; check for paddle button
bit PADDLE_BUTTON0 bit PADDLE_BUTTON0 ; 4
bpl no_button bpl no_button ; 2nt/3
lda #' '+128 lda #' '+128 ; 2
jmp save_key jmp save_key ; 3
no_button: no_button:
lda KEYPRESS lda KEYPRESS ; 3
bpl no_key bpl no_key ; 2nt/3
figure_out_key: figure_out_key:
cmp #' '+128 ; the mask destroys space cmp #' '+128 ; the mask destroys space ; 2
beq save_key ; so handle it specially beq save_key ; so handle it specially ; 2nt/3
and #$5f ; mask, to make upper-case and #$5f ; mask, to make upper-case ; 2
check_right_arrow: check_right_arrow:
cmp #$15 cmp #$15 ; 2
bne check_left_arrow bne check_left_arrow ; 2nt/3
lda #'D' lda #'D' ; 2
check_left_arrow: check_left_arrow:
cmp #$08 cmp #$08 ; 2
bne check_up_arrow bne check_up_arrow ; 2nt/3
lda #'A' lda #'A' ; 2
check_up_arrow: check_up_arrow:
cmp #$0B cmp #$0B ; 2
bne check_down_arrow bne check_down_arrow ; 2nt/3
lda #'W' lda #'W' ; 2
check_down_arrow: check_down_arrow:
cmp #$0A cmp #$0A ; 2
bne check_escape bne check_escape ; 2nt/3
lda #'S' lda #'S' ; 2
check_escape: check_escape:
cmp #$1B cmp #$1B ; 2
bne save_key bne save_key ; 2nt/3
lda #'Q' lda #'Q' ; 2
jmp save_key jmp save_key ; 3
no_key: no_key:
bit PADDLE_STATUS bit PADDLE_STATUS ; 3
bpl no_key_store bpl no_key_store ; 2nt/3
; check for paddle action ; check for paddle action
; code from http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.06.html ; code from http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.06.html
inc PADDLE_STATUS inc PADDLE_STATUS ; 5
lda PADDLE_STATUS lda PADDLE_STATUS ; 3
and #$03 and #$03 ; 2
beq check_paddles beq check_paddles ; 2nt/3
jmp no_key_store jmp no_key_store ; 3
check_paddles: check_paddles:
lda PADDLE_STATUS lda PADDLE_STATUS ; 3
and #$80 and #$80 ; 2
sta PADDLE_STATUS sta PADDLE_STATUS ; 3
ldx #$0 ldx #$0 ; 2
LDA PTRIG ;TRIGGER PADDLES LDA PTRIG ;TRIGGER PADDLES ; 4
LDY #0 ;INIT COUNTER LDY #0 ;INIT COUNTER ; 2
NOP ;COMPENSATE FOR 1ST COUNT NOP ;COMPENSATE FOR 1ST COUNT ; 2
NOP NOP ; 2
PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. ; 4
BPL RTS2D ;BRANCH WHEN TIMED OUT BPL RTS2D ;BRANCH WHEN TIMED OUT ; 2nt/3
INY ;INCREMENT COUNTER INY ;INCREMENT COUNTER ; 2
BNE PREAD2 ;CONTINUE COUNTING BNE PREAD2 ;CONTINUE COUNTING ; 2nt/3
DEY ;COUNTER OVERFLOWED DEY ;COUNTER OVERFLOWED ; 2
RTS2D: ;RETURN W/VALUE 0-255 RTS2D: ;RETURN W/VALUE 0-255
cpy #96 cpy #96 ; 2
bmi paddle_left bmi paddle_left ; 2nt/3
cpy #160 cpy #160 ; 2
bmi no_key_store bmi no_key_store ; 2nt/3
lda #'K' lda #'D' ; 2
jmp save_key jmp save_key ; 3
paddle_left: paddle_left:
lda #'J' lda #'A' ; 2
jmp save_key jmp save_key ; 3
no_key_store: no_key_store:
lda #0 ; no key, so save a zero lda #0 ; no key, so save a zero ; 2
save_key: save_key:
sta LASTKEY ; save the key to our buffer sta LASTKEY ; save the key to our buffer ; 2
bit KEYRESET ; clear the keyboard buffer bit KEYRESET ; clear the keyboard buffer ; 4
rts rts ; 6
;============
; 33=nokey
; 48=worstkey
;============================================= ;=============================================
; put_sprite ; put_sprite