From db5b86289adf1a88ee43c884a5ec6faccd8164a6 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 24 Nov 2017 00:17:43 -0500 Subject: [PATCH] tfv: more cycle annotation --- gr-sim/gr-sim.c | 23 +++++++-- gr-sim/tfv_flying_6502.c | 22 ++++---- tfv/tfv_utils.s | 105 ++++++++++++++++++++------------------- 3 files changed, 84 insertions(+), 66 deletions(-) diff --git a/gr-sim/gr-sim.c b/gr-sim/gr-sim.c index 72e8c505..20b5d84c 100644 --- a/gr-sim/gr-sim.c +++ b/gr-sim/gr-sim.c @@ -820,6 +820,7 @@ int grsim_put_sprite_page(int page, unsigned char *sprite_data, int xpos, int yp unsigned char i; unsigned char *ptr; short address; + int cycles=0; ptr=sprite_data; x=*ptr; @@ -829,41 +830,55 @@ int grsim_put_sprite_page(int page, unsigned char *sprite_data, int xpos, int yp ypos=ypos&0xfe; + cycles+=28; + while(1) { address=gr_addr_lookup[ypos/2]; address+=(page)<<8; address+=xpos; + cycles+=36; for(i=0;i0;loop--) { draw_background_mode7(); - grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]); - grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]); + cycles.put_sprite+=grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]); + cycles.put_sprite+=grsim_put_sprite(ship_forward,CONST_SHIPX,ram[SHIPY]); page_flip(); usleep(200000); @@ -794,35 +794,35 @@ int flying(void) { if (ram[TURNING]==0) { if (ram[DRAW_SPLASH]) { - grsim_put_sprite(splash_forward, + cycles.put_sprite+=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.put_sprite+=grsim_put_sprite(shadow_forward,CONST_SHIPX+3,31+ram[SPACEZ_I]); + cycles.put_sprite+=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, + cycles.put_sprite+=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]); + cycles.put_sprite+=grsim_put_sprite(shadow_left,CONST_SHIPX+3,31+ram[SPACEZ_I]); + cycles.put_sprite+=grsim_put_sprite(ship_left,CONST_SHIPX,ram[SHIPY]); ram[TURNING]++; cycles.flying+=48; } else { if (ram[DRAW_SPLASH]) { - grsim_put_sprite(splash_right, + cycles.put_sprite+=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]); + cycles.put_sprite+=grsim_put_sprite(shadow_right,CONST_SHIPX+3,31+ram[SPACEZ_I]); + cycles.put_sprite+=grsim_put_sprite(ship_right,CONST_SHIPX,ram[SHIPY]); ram[TURNING]--; cycles.flying+=51; } diff --git a/tfv/tfv_utils.s b/tfv/tfv_utils.s index 73423f23..ac73bc87 100644 --- a/tfv/tfv_utils.s +++ b/tfv/tfv_utils.s @@ -352,94 +352,97 @@ save_key: put_sprite: - ldy #0 ; byte 0 is xsize - lda (INL),Y - sta CH ; xsize is in CH - iny + ldy #0 ; byte 0 is xsize ; 2 + lda (INL),Y ; 5 + sta CH ; xsize is in CH ; 3 + iny ; 2 - lda (INL),Y ; byte 1 is ysize - sta CV ; ysize is in CV - iny - - lda YPOS ; make a copy of ypos - sta TEMPY ; as we modify it + lda (INL),Y ; byte 1 is ysize ; 5 + sta CV ; ysize is in CV ; 3 + iny ; 2 + lda YPOS ; make a copy of ypos ; 3 + sta TEMPY ; as we modify it ; 3 + ;=========== + ; 28 put_sprite_loop: - sty TEMP ; save sprite pointer + sty TEMP ; save sprite pointer ; 3 - ldy TEMPY + ldy TEMPY ; 3 lda gr_offsets,Y ; lookup low-res memory address ; 5 - clc - adc XPOS ; add in xpos + clc ; 2 + adc XPOS ; add in xpos ; 3 sta OUTL ; store out low byte of addy ; 3 lda gr_offsets+1,Y ; look up high byte ; 5 - adc DRAW_PAGE ; + adc DRAW_PAGE ; ; 3 sta OUTH ; and store it out ; 3 ldy TEMP ; restore sprite pointer ; 3 ; OUTH:OUTL now points at right place - ldx CH ; load xsize into x - + ldx CH ; load xsize into x ; 3 + ;=========== + ; 36 put_sprite_pixel: - lda (INL),Y ; get sprite colors - iny ; increment sprite pointer + lda (INL),Y ; get sprite colors ; 5 + iny ; increment sprite pointer ; 2 - sty TEMP ; save sprite pointer - ldy #$0 + sty TEMP ; save sprite pointer ; 3 + ldy #$0 ; 2 ; check if completely transparent ; if so, skip - cmp #$0 ; if all zero, transparent - beq put_sprite_done_draw ; don't draw it - ; FIXME: use BIT? + cmp #$0 ; if all zero, transparent ; 2 + beq put_sprite_done_draw ; don't draw it ; 2nt/3 + ; FIXME: use BIT? ;============== + ; 17 - sta COLOR ; save color for later + sta COLOR ; save color for later ; 3 ; check if top pixel transparent - and #$f0 ; check if top nibble zero - bne put_sprite_bottom ; if not skip ahead + and #$f0 ; check if top nibble zero ; 2 + bne put_sprite_bottom ; if not skip ahead ; 2nt/3 - lda #$f0 ; setup mask - sta MASK - bmi put_sprite_mask + lda #$f0 ; setup mask ; 2 + sta MASK ; 3 + bmi put_sprite_mask ; 2nt/3 put_sprite_bottom: - lda COLOR ; re-load color - and #$0f ; check if bottom nibble zero - bne put_sprite_all ; if not, skip ahead - lda #$0f - sta MASK ; setup mask + lda COLOR ; re-load color ; 3 + and #$0f ; check if bottom nibble zero ; 2 + bne put_sprite_all ; if not, skip ahead ; 2nt/3 + lda #$0f ; 2 + sta MASK ; setup mask ; 3 put_sprite_mask: - lda (OUTL),Y ; get color at output - and MASK ; mask off unneeded part - ora COLOR ; or the color in - sta (OUTL),Y ; store it back + lda (OUTL),Y ; get color at output ; 5 + and MASK ; mask off unneeded part ; 3 + ora COLOR ; or the color in ; 3 + sta (OUTL),Y ; store it back ; 5 - jmp put_sprite_done_draw ; we are done + jmp put_sprite_done_draw ; we are done ; 3 put_sprite_all: - lda COLOR ; load color - sta (OUTL),Y ; and write it out + lda COLOR ; load color ; 3 + sta (OUTL),Y ; and write it out ; 5 put_sprite_done_draw: - ldy TEMP ; restore sprite pointer + ldy TEMP ; restore sprite pointer ; 3 - inc OUTL ; increment output pointer - dex ; decrement x counter - bne put_sprite_pixel ; if not done, keep looping + inc OUTL ; increment output pointer ; 5 + dex ; decrement x counter ; 2 + bne put_sprite_pixel ; if not done, keep looping ; 2nt/3 - inc TEMPY ; each line has two y vars - inc TEMPY - dec CV ; decemenet total y count - bne put_sprite_loop ; loop if not done + inc TEMPY ; each line has two y vars ; 5 + inc TEMPY ; 5 + dec CV ; decemenet total y count ; 5 + bne put_sprite_loop ; loop if not done ; 2nt/3 - rts ; return + rts ; return ; 6 ;================================