From be98d1539057005c0677fe126707033c3b74e23c Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 22 Nov 2017 01:02:29 -0500 Subject: [PATCH] tfv: some cycle counting --- gr-sim/tfv_flying_6502.c | 102 +++++++++++++++------------ tfv/tfv_utils.s | 148 ++++++++++++++++++++------------------- 2 files changed, 135 insertions(+), 115 deletions(-) diff --git a/gr-sim/tfv_flying_6502.c b/gr-sim/tfv_flying_6502.c index a0ae7e21..c74fca56 100644 --- a/gr-sim/tfv_flying_6502.c +++ b/gr-sim/tfv_flying_6502.c @@ -53,6 +53,7 @@ #define CONST_BETA_I 0xff // -0.5 ?? #define CONST_BETA_F 0x80 +#define CONST_SHIPX 15 /* Mode7 code based on code from: */ /* 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) { unsigned char ch; - int draw_splash=0,splash_count=0; - int zint; - - long long cycles=0; /************************************************/ /* Flying */ @@ -590,11 +595,20 @@ int flying(void) { ram[SPACEZ_F]=0x80; /* sta SPACEZ_F */ 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; @@ -603,7 +617,7 @@ int flying(void) { ram[SHIPY]-=2; ram[SPACEZ_I]++; } - splash_count=0; + ram[SPLASH_COUNT]=0; } if ((ch=='s') || (ch==APPLE_DOWN)) { if (ram[SHIPY]<28) { @@ -611,7 +625,7 @@ int flying(void) { ram[SPACEZ_I]--; } else { - splash_count=10; + ram[SPLASH_COUNT]=10; } } if ((ch=='a') || (ch==APPLE_LEFT)) { @@ -665,14 +679,12 @@ int flying(void) { if (landing_color==12) { int loop; - zint=ram[SPACEZ_I]; - /* Land the ship */ - for(loop=zint;loop>0;loop--) { + for(loop=ram[SPACEZ_I];loop>0;loop--) { draw_background_mode7(); - grsim_put_sprite(shadow_forward,SHIPX+3,31+zint); - grsim_put_sprite(ship_forward,SHIPX,ram[SHIPY]); + grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]); + grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]); page_flip(); usleep(200000); @@ -715,64 +727,66 @@ int flying(void) { draw_background_mode7(); - zint=ram[SPACEZ_I]; - - draw_splash=0; - + ram[DRAW_SPLASH]=0; if (ram[SPEED]>0) { if ((ram[SHIPY]>25) && (ram[TURNING]!=0)) { - splash_count=1; + ram[SPLASH_COUNT]=1; } - if ((ram[OVER_WATER]) && (splash_count)) { - draw_splash=1; + if ((ram[OVER_WATER]) && (ram[SPLASH_COUNT])) { + ram[DRAW_SPLASH]=1; } } -// printf("VMW: %d %d\n",draw_splash,splash_count); - if (ram[TURNING]==0) { - if (draw_splash) { + if (ram[DRAW_SPLASH]) { 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(ship_forward,SHIPX,ram[SHIPY]); + grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]); + grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]); } else if (ram[TURNING]>128) { - if (draw_splash) { + if (ram[DRAW_SPLASH]) { grsim_put_sprite(splash_left, - SHIPX+1,36); + CONST_SHIPX+1,36); } - grsim_put_sprite(shadow_left,SHIPX+3,31+zint); - grsim_put_sprite(ship_left,SHIPX,ram[SHIPY]); + grsim_put_sprite(shadow_left,CONST_SHIPX+3,31+ram[SPACEZ_I]); + grsim_put_sprite(ship_left,CONST_SHIPX,ram[SHIPY]); ram[TURNING]++; } else { - if (draw_splash) { + if (ram[DRAW_SPLASH]) { grsim_put_sprite(splash_right, - SHIPX+1,36); + CONST_SHIPX+1,36); } - grsim_put_sprite(shadow_right,SHIPX+3,31+zint); - grsim_put_sprite(ship_right,SHIPX,ram[SHIPY]); + grsim_put_sprite(shadow_right,CONST_SHIPX+3,31+ram[SPACEZ_I]); + grsim_put_sprite(ship_right,CONST_SHIPX,ram[SHIPY]); 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); } return 0; } - - - - - - diff --git a/tfv/tfv_utils.s b/tfv/tfv_utils.s index 8d3397b4..79240d5e 100644 --- a/tfv/tfv_utils.s +++ b/tfv/tfv_utils.s @@ -29,22 +29,24 @@ clear_screens: ;========== page_flip: - lda DISP_PAGE - beq page_flip_show_1 + lda DISP_PAGE ; 3 + beq page_flip_show_1 ; 2nt/3 page_flip_show_0: - bit PAGE0 - lda #4 - sta DRAW_PAGE ; DRAW_PAGE=1 - lda #0 - sta DISP_PAGE ; DISP_PAGE=0 - rts + bit PAGE0 ; 4 + lda #4 ; 2 + sta DRAW_PAGE ; DRAW_PAGE=1 ; 3 + lda #0 ; 2 + sta DISP_PAGE ; DISP_PAGE=0 ; 3 + rts ; 6 page_flip_show_1: - bit PAGE1 - sta DRAW_PAGE ; DRAW_PAGE=0 - lda #1 - sta DISP_PAGE ; DISP_PAGE=1 - rts - + bit PAGE1 ; 4 + sta DRAW_PAGE ; DRAW_PAGE=0 ; 3 + lda #1 ; 2 + sta DISP_PAGE ; DISP_PAGE=1 ; 3 + rts ; 6 + ;==================== + ; DISP_PAGE=0 26 + ; DISP_PAGE=1 24 ;====================== ; memset @@ -253,89 +255,93 @@ check_paddle_button: ; check for paddle button - bit PADDLE_BUTTON0 - bpl no_button - lda #' '+128 - jmp save_key + bit PADDLE_BUTTON0 ; 4 + bpl no_button ; 2nt/3 + lda #' '+128 ; 2 + jmp save_key ; 3 no_button: - lda KEYPRESS - bpl no_key + lda KEYPRESS ; 3 + bpl no_key ; 2nt/3 figure_out_key: - cmp #' '+128 ; the mask destroys space - beq save_key ; so handle it specially + cmp #' '+128 ; the mask destroys space ; 2 + 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: - cmp #$15 - bne check_left_arrow - lda #'D' + cmp #$15 ; 2 + bne check_left_arrow ; 2nt/3 + lda #'D' ; 2 check_left_arrow: - cmp #$08 - bne check_up_arrow - lda #'A' + cmp #$08 ; 2 + bne check_up_arrow ; 2nt/3 + lda #'A' ; 2 check_up_arrow: - cmp #$0B - bne check_down_arrow - lda #'W' + cmp #$0B ; 2 + bne check_down_arrow ; 2nt/3 + lda #'W' ; 2 check_down_arrow: - cmp #$0A - bne check_escape - lda #'S' + cmp #$0A ; 2 + bne check_escape ; 2nt/3 + lda #'S' ; 2 check_escape: - cmp #$1B - bne save_key - lda #'Q' - jmp save_key + cmp #$1B ; 2 + bne save_key ; 2nt/3 + lda #'Q' ; 2 + jmp save_key ; 3 no_key: - bit PADDLE_STATUS - bpl no_key_store + bit PADDLE_STATUS ; 3 + bpl no_key_store ; 2nt/3 ; check for paddle action ; code from http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.06.html - inc PADDLE_STATUS - lda PADDLE_STATUS - and #$03 - beq check_paddles - jmp no_key_store + inc PADDLE_STATUS ; 5 + lda PADDLE_STATUS ; 3 + and #$03 ; 2 + beq check_paddles ; 2nt/3 + jmp no_key_store ; 3 check_paddles: - lda PADDLE_STATUS - and #$80 - sta PADDLE_STATUS + lda PADDLE_STATUS ; 3 + and #$80 ; 2 + sta PADDLE_STATUS ; 3 - ldx #$0 - LDA PTRIG ;TRIGGER PADDLES - LDY #0 ;INIT COUNTER - NOP ;COMPENSATE FOR 1ST COUNT - NOP -PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. - BPL RTS2D ;BRANCH WHEN TIMED OUT - INY ;INCREMENT COUNTER - BNE PREAD2 ;CONTINUE COUNTING - DEY ;COUNTER OVERFLOWED + ldx #$0 ; 2 + LDA PTRIG ;TRIGGER PADDLES ; 4 + LDY #0 ;INIT COUNTER ; 2 + NOP ;COMPENSATE FOR 1ST COUNT ; 2 + NOP ; 2 +PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. ; 4 + BPL RTS2D ;BRANCH WHEN TIMED OUT ; 2nt/3 + INY ;INCREMENT COUNTER ; 2 + BNE PREAD2 ;CONTINUE COUNTING ; 2nt/3 + DEY ;COUNTER OVERFLOWED ; 2 RTS2D: ;RETURN W/VALUE 0-255 - cpy #96 - bmi paddle_left - cpy #160 - bmi no_key_store - lda #'K' - jmp save_key + cpy #96 ; 2 + bmi paddle_left ; 2nt/3 + cpy #160 ; 2 + bmi no_key_store ; 2nt/3 + lda #'D' ; 2 + jmp save_key ; 3 paddle_left: - lda #'J' - jmp save_key + lda #'A' ; 2 + jmp save_key ; 3 no_key_store: - lda #0 ; no key, so save a zero + lda #0 ; no key, so save a zero ; 2 save_key: - sta LASTKEY ; save the key to our buffer - bit KEYRESET ; clear the keyboard buffer - rts + sta LASTKEY ; save the key to our buffer ; 2 + bit KEYRESET ; clear the keyboard buffer ; 4 + rts ; 6 + ;============ + ; 33=nokey + ; 48=worstkey + ;============================================= ; put_sprite