diff --git a/games/keen/story.s b/games/keen/story.s index e529a8ee..6c33b858 100644 --- a/games/keen/story.s +++ b/games/keen/story.s @@ -57,89 +57,172 @@ load_background: bit SET_TEXT bit PAGE1 - lda #story_data sta START_LINE_H + ;=========================== + ; main loop + ;=========================== + ; 16 + 16 * (16 + 40*(39) +7) + 17 + 17*40 + ; 16 + 16*(1583) + 17 + 680 + ; 16 + 25328 + 17 + 680 + ; 26041 = 400 lines :( we're on 16*8=128 + redraw_text: - ldx #0 + ldx #0 ; 2 - lda START_LINE_L - sta INL - lda START_LINE_H - sta INH + lda START_LINE_L ; 3 + sta input_smc+1 ; 4 + lda START_LINE_H ; 3 + sta input_smc+2 ; 4 + ;=========== + ; 16 outer_text_loop: - lda gr_offsets_low,X - sta OUTL - lda gr_offsets_high,X - sta OUTH + lda gr_offsets_low,X ; 4+ + sta OUTL ; 3 + lda gr_offsets_high,X ; 4+ + sta OUTH ; 3 + ldy #0 ; 2 + ;============ + ; 16 - ldy #39 inner_text_loop: - lda (INL),Y - sta (OUTL),Y - dey - bpl inner_text_loop - clc - lda INL - adc #40 - sta INL - lda INH - adc #0 - sta INH +input_smc: + lda story_bg ; 4 + sta (OUTL),Y ; 6 - inx - cpx #17 - bne outer_text_loop + clc ; 2 + lda input_smc+1 ; 4 + adc #1 ; 2 + sta input_smc+1 ; 4 + lda input_smc+2 ; 4 + adc #0 ; 2 + sta input_smc+2 ; 4 + iny ; 2 + cpy #40 ; 2 + bne inner_text_loop ; 2/3 + ;============ + ; 39 + + ; -1 + + + inx ; 2 + cpx #16 ; 2 + bne outer_text_loop ; 2/3 + ;============ + ; 7 + + ; -1 ;================== ; draw message ;================== - ldx #18 - lda gr_offsets_low,X - sta OUTL - lda gr_offsets_high,X - sta OUTH + ldx #17 ; 2 + lda gr_offsets_low,X ; 4+ + sta OUTL ; 3 + lda gr_offsets_high,X ; 4+ + sta OUTH ; 3 + + ldy #39 ; 2 + ;================== + ; 17 - ldy #39 message_text_loop: - lda message,Y - and #$3f - sta (OUTL),Y - dey - bpl message_text_loop + lda message,Y ; 4+ + and #$3f ; 2 + sta (OUTL),Y ; 6 + dey ; 2 + bpl message_text_loop ; 2/3 + ;================== + ; 17*40 - jsr wait_until_keypress + ; -1 - and #$7f ; clear high bit - and #$df ; change lower to upper + ;=================================== + ; can we do this constant time? + ;=================================== - cmp #13 - beq done_with_story - cmp #27 - beq done_with_story +check_keypress: + lda KEYPRESS ; 4 + bpl done_key7 ; 2/3 +; 6 + bit KEYRESET ; 4 - cmp #'W' - beq do_up - cmp #$0B - beq do_up + and #$7f ; clear high bit ; 2 + and #$df ; change lower to upper ; 2 +; 14 + cmp #13 ; 2 + beq done_with_story ; 2/3 +; 18 + cmp #27 ; 2 + beq done_with_story ; 2/3 +; 22 + cmp #'W' ; 2 + beq do_up ; 2/3 +; 26 + cmp #$0B ; 2 + beq do_up ; 2/3 +; 30 + cmp #'S' ; 2 + beq do_down ; 2/3 +; 34 + cmp #$0A ; 2 + beq do_down ; 2/3 +; 38 + bne done_key41 ; bra ; 3 - cmp #'S' - beq do_down - cmp #$0A - beq do_down +done_key7: + ; need to waste 34 cycles + + inc $00 ; 5 + inc $00 ; 5 + inc $00 ; 5 + inc $00 ; 5 + inc $00 ; 5 + inc $00 ; 5 + nop + nop +done_key41: + inc $00 + nop + + ; 18*8*65= 9360 + ; want to delay 9360 - 41 - 7 - 4 = 9308 - 20 = 9288/9 = 1032 + ; 1032/256= 4 r 8 + ; + + lda #4 ; 2 + ldy #8 ; 2 + jsr delay_loop + + ; want to delay 6*8*65 = 3120+4550 = 7670 + ; want to delay 7670 - 15 - 12 = 7643 - 20 = 7623/9 = 847 + ; 905/256=3 r 79 + + inc $00 ; nop5 + inc $00 ; nop5 + nop ; nop2 + + bit SET_GR ; 4 + + lda #3 ; 2 + ldy #79 ; 2 + jsr delay_loop + bit SET_TEXT ; 4 done_key: - jmp redraw_text + + jmp check_keypress ; 3 do_up: lda START_LINE_H @@ -171,7 +254,6 @@ do_down: beq done_key down_ok: - clc lda START_LINE_L adc #40 @@ -181,7 +263,6 @@ down_ok: sta START_LINE_H jmp redraw_text - done_with_story: @@ -199,7 +280,7 @@ done_with_story: .include "gr_copy.s" ; .include "wait_a_bit.s" .include "gr_offsets.s" - .include "gr_offsets_split.s" + .include "zx02_optim.s" .include "gr_fast_clear.s" @@ -222,6 +303,27 @@ wait_until_keypress: bit KEYRESET rts +.align $100 message: .byte " ESC TO EXIT / ARROWS TO READ ",0 + + .include "gr_offsets_split.s" + + + ;===================================== + ; short delay by Bruce Clark + ; any delay between 8 to 589832 with res of 9 + ;===================================== + ; 9*(256*A+Y)+8 + 12 for jsr/rts + ; A and Y both $FF at the end + +size_delay: + +delay_loop: + cpy #1 + dey + sbc #0 + bcs delay_loop +delay_12: + rts