; Lo-res cycle-counting water transparency hack ; by deater (Vince Weaver) ; Zero Page FRAMEBUFFER = $00 ; $00 - $0F YPOS = $10 YPOS_SIN = $11 CH = $24 CV = $25 GBASL = $26 GBASH = $27 BASL = $28 BASH = $29 MASK = $2E COLOR = $30 FRAME = $60 MB_VALUE = $91 BIRD_STATE = $E0 BIRD_DIR = $E1 DRAW_PAGE = $EE LASTKEY = $F1 PADDLE_STATUS = $F2 XPOS = $F3 OLD_XPOS = $F4 TEMP = $FA TEMPY = $FB INL = $FC INH = $FD OUTL = $FE OUTH = $FF ; Soft Switches KEYPRESS= $C000 KEYRESET= $C010 SET_GR = $C050 ; Enable graphics FULLGR = $C052 ; Full screen, no text PAGE0 = $C054 ; Page0 PAGE1 = $C055 ; Page1 LORES = $C056 ; Enable LORES graphics PADDLE_BUTTON0 = $C061 PADDL0 = $C064 PTRIG = $C070 ; ROM routines TEXT = $FB36 ;; Set text mode HOME = $FC58 ;; Clear the text screen WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us ; location we don't care about DUMMY = $300 waterfall_demo: ;=================== ; init screen jsr TEXT jsr HOME bit PAGE0 ;=================== ; init vars lda #0 sta BIRD_DIR sta BIRD_STATE sta FRAME sta OLD_XPOS lda #4 sta DRAW_PAGE sta XPOS ;=================== ; Mockingboard jsr mockingboard_init ; Enable channel A tone+noise ldx #7 ; 2 lda #$36 ; 2 sta MB_VALUE ; 3 jsr write_ay_both ; 6+65 ; enable white noise ldx #6 ; 2 lda #1 ; 2 sta MB_VALUE ; 3 jsr write_ay_both ; 6+65 ;=============== ; 78 ;============================= ; Load foreground to graphic page1 (apple page2) lda #$0c sta BASH lda #$00 sta BASL ; load image to $c00 lda #waterfall_page1 sta GBASH jsr load_rle_gr jsr gr_copy_to_current ; copy to page1 ;============================= ; Load bg to memory lda #$0c sta BASH lda #$00 sta BASL ; load image to $c00 lda #waterfall_page2 sta GBASH jsr load_rle_gr ;============================== ; setup graphics for vapor lock ;============================== jsr vapor_lock ; 6 ; vapor lock returns with us at beginning of hsync in line ; 114 (7410 cycles), so with 5070 lines to go jsr gr_copy_to_current ; 6+ 9292 ; now we have 322 left ; GR part bit LORES ; 4 bit SET_GR ; 4 bit FULLGR ; 4 ; 322 - 12 = 310 ; -3 for jmp ; 307 ; Try X=9 Y=6 cycles=307 ldy #6 ; 2 wfloopA:ldx #9 ; 2 wfloopB:dex ; 2 bne wfloopB ; 2nt/3 dey ; 2 bne wfloopA ; 2nt/3 jmp display_loop jump_table: .word (display_even-1) .word (display_odd-1) .word (display_three-1) .word (display_four-1) .align $100 ;================================================ ; Display Loop ;================================================ ; each scan line 65 cycles ; 1 cycle each byte (40cycles) + 25 for horizontal ; Total of 12480 cycles to draw screen ; Vertical blank = 4550 cycles (70 scan lines) ; Total of 17030 cycles to get back to where was ; jump_table ; 38 + display_odd ; we have 3 (the jmp back) ; = 3 cycles that need to be eaten by the vblank display_loop: inc FRAME ; 5 lda FRAME ; 3 and #$30 ; 2 ; 0011 0000, so more or less div by 16, 3.75Hz lsr ; 2 lsr ; 2 lsr ; 2 tay ; 2 ; 18 lda jump_table+1,y ; 4 pha ; 3 lda jump_table,y ; 4 pha ; 3 rts ; 6 ; 38 display_loop_return: vblank: ;====================================================== ; We have 4550 cycles in the vblank, use them wisely ;====================================================== ; do_nothing should be 4550 ; -3 letfover from HBLANK code ; ** -9 ; -49 check for keypress ; -2252 copy screen ; -2231 draw sprite ; ============= ; 15 cycles ; 15 cycles inc YPOS ; 5 nop ; 2 nop ; 2 lda YPOS ; 3 lda YPOS ; 3 ;========================= ; Clear background ;========================= jsr gr_copy_row22 ; 6+ 2246 ;========= ; 2252 ;========================== ; draw bird sprite ;========================== ; 8 prefix ; bird_walk_right= 14 + 2175 2206 (need 17) ; bird_stand_right= 13 + 2190 2206 (need 3) ; bird_walk_left= 15 + 2175 2206 (need 16) ; bird_stand_left= 14 + 2190 2206 (need 2) ; call to sprite 17 postfix ;==================================================== ; 2231 lda BIRD_STATE ; 3 and #1 ; 2 ldx BIRD_DIR ; 3 bne bird_left bird_right: ; 2 cmp #1 ; 2 beq bird_walk_right ; 2 bird_stand_right: ldx #>bird_rider_stand_right ; 2 ldy #bird_rider_walk_right ; 2 ldy #bird_rider_stand_left ; 2 ldy #bird_rider_walk_left ; 2 ldy #