From bb96ec6fb89d54538dcd6784b59dafceb6ed01bb Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 2 Aug 2018 15:50:49 -0400 Subject: [PATCH] waterfall: sprite placement works --- waterfall/Makefile | 1 + waterfall/put_sprite.s | 137 +++++++++++++++++++++++++++++++++++++++++ waterfall/waterfall.s | 80 ++++++++++++++++++------ 3 files changed, 198 insertions(+), 20 deletions(-) create mode 100644 waterfall/put_sprite.s diff --git a/waterfall/Makefile b/waterfall/Makefile index 7324579d..27a604c3 100644 --- a/waterfall/Makefile +++ b/waterfall/Makefile @@ -17,6 +17,7 @@ WATERFALL: waterfall.o ld65 -o WATERFALL waterfall.o -C ../linker_scripts/apple2_1000.inc waterfall.o: waterfall.s gr_copy.s gr_unrolled_copy.s \ + put_sprite.s \ waterfall_page1.inc waterfall_page2.inc tfv_sprites.inc ca65 -o waterfall.o waterfall.s -l waterfall.lst diff --git a/waterfall/put_sprite.s b/waterfall/put_sprite.s new file mode 100644 index 00000000..90577607 --- /dev/null +++ b/waterfall/put_sprite.s @@ -0,0 +1,137 @@ + ;============================================= + ; put_sprite + ;============================================= + ; Sprite to display in INH,INL + ; Location is XPOS,YPOS + ; Note, only works if YPOS is multiple of two + + + ; time= 28 setup + ; Y*outerloop + ; outerloop = 34 setup + ; X*innerloop + ; innerloop = 30 if $00 17+13(done) + ; 64 if $0X 16+7+8+20(put_sprite_mask)+13(done) + ; 69 if $X0 16+8+7+5+20(put_sprite_mask)+13(done) + ; 54 if if $XX 16+8+8+9(put_all)+13(done) + + + ; -1 for last iteration + ; 18 (-1 for last) + ; 6 return + + ; so cost = 28 + Y*(34+18)+ (INNER-Y) -1 + 6 + ; = 33 + Y*(52)+(INNER-Y) + ; = 33 + Y*(52)+ [30A + 64B + 69C + 54D]-Y +.align $100 +put_sprite: + + 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 ; 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 ; 3 + ldy TEMPY ; 3 + lda gr_offsets,Y ; lookup low-res memory address ; 4 + 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 ; 4 + 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 ; 3 + ;=========== + ; 34 +put_sprite_pixel: + lda (INL),Y ; get sprite colors ; 5 + iny ; increment sprite pointer ; 2 + + sty TEMP ; save sprite pointer ; 3 + ldy #$0 ; 2 + + ; check if completely transparent + ; if so, skip + + cmp #$0 ; if all zero, transparent ; 2 + beq put_sprite_done_draw ; don't draw it ; 2nt/3 + ;============== + ; 16/17 + + sta COLOR ; save color for later ; 3 + + ; check if top pixel transparent + + and #$f0 ; check if top nibble zero ; 2 + bne put_sprite_bottom ; if not skip ahead ; 2nt/3 + ;============== + ; 7/8 + + lda #$f0 ; setup mask ; 2 + sta MASK ; 3 + bmi put_sprite_mask ; always? ; 3 + ;============= + ; 8 + +put_sprite_bottom: + lda COLOR ; re-load color ; 3 + and #$0f ; check if bottom nibble zero ; 2 + bne put_sprite_all ; if not, skip ahead ; 2nt/3 + ;============= + ; 7/8 + + lda #$0f ; 2 + sta MASK ; setup mask ; 3 + ;=========== + ; 5 + +put_sprite_mask: + 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 ; 6 + + jmp put_sprite_done_draw ; we are done ; 3 + ;=========== + ; 20 + +put_sprite_all: + lda COLOR ; load color ; 3 + sta (OUTL),Y ; and write it out ; 6 + ;============ + ; 9 + +put_sprite_done_draw: + + ldy TEMP ; restore sprite pointer ; 3 + + inc OUTL ; increment output pointer ; 5 + dex ; decrement x counter ; 2 + bne put_sprite_pixel ; if not done, keep looping ; 2nt/3 + ;============== + ; 12/13 + + 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 + ;============== + ; 17/18 + + rts ; return ; 6 + + + diff --git a/waterfall/waterfall.s b/waterfall/waterfall.s index 90a2746a..a48a03fe 100644 --- a/waterfall/waterfall.s +++ b/waterfall/waterfall.s @@ -12,13 +12,20 @@ GBASL = $26 GBASH = $27 BASL = $28 BASH = $29 +MASK = $2E +COLOR = $30 FRAME = $60 BLARGH = $69 DRAW_PAGE = $EE LASTKEY = $F1 PADDLE_STATUS = $F2 +XPOS = $F3 TEMP = $FA - +TEMPY = $FB +INL = $FC +INH = $FD +OUTL = $FE +OUTH = $FF ; Soft Switches KEYPRESS= $C000 @@ -70,12 +77,6 @@ waterfall_demo: jsr gr_copy_to_current ; copy to page1 - ; GR part -; bit PAGE1 -; bit LORES ; 4 -; bit SET_GR ; 4 -; bit FULLGR ; 4 - ;============================= ; Load bg to memory @@ -90,14 +91,6 @@ waterfall_demo: sta GBASH jsr load_rle_gr -; lda #0 -; sta DRAW_PAGE - -; jsr gr_copy_to_current - - ; GR part -; bit PAGE0 - ;============================== ; setup graphics for vapor lock @@ -234,17 +227,63 @@ page1_loop: ; delay 115+(7 loop)+4 (bit)+4(extra) ; -2 display loop setup ; -6 jsr to do_nothing ; -10 check for keypress - ; -2257 copy screen + ; -2252 copy screen ; ============= ; 2276 jsr do_nothing ; 6 - lda #4 ; 2 - sta DRAW_PAGE ; 3 + ;========================= + ; Clear background + ;========================= + jsr gr_copy_row22 ; 6+ 2246 ;========= - ; 2257 + ; 2252 + + + +; beq bird_walking + ; 2 + lda #>bird_rider_stand_right ; 2 + sta INH ; 3 + lda #bird_rider_walk_right ; 2 + sta INH ; 3 + lda #