2024-05-07 05:24:37 +00:00
|
|
|
; Keen1 Story
|
|
|
|
|
|
|
|
; by deater (Vince Weaver) <vince@deater.net>
|
|
|
|
|
|
|
|
; Zero Page
|
|
|
|
.include "zp.inc"
|
|
|
|
.include "hardware.inc"
|
|
|
|
.include "common_defines.inc"
|
|
|
|
|
|
|
|
story_data = $7000
|
|
|
|
|
2024-05-09 20:45:11 +00:00
|
|
|
story_end = $83A0
|
|
|
|
|
2024-05-07 05:24:37 +00:00
|
|
|
keen_story_start:
|
|
|
|
;===================
|
|
|
|
; init screen
|
|
|
|
;===================
|
|
|
|
|
|
|
|
bit KEYRESET
|
|
|
|
|
|
|
|
bit SET_GR
|
|
|
|
bit PAGE1
|
|
|
|
bit HIRES
|
|
|
|
bit FULLGR
|
|
|
|
|
|
|
|
;===================
|
|
|
|
; Load story data
|
|
|
|
;===================
|
|
|
|
|
|
|
|
lda #<compressed_story_data
|
|
|
|
sta ZX0_src
|
|
|
|
lda #>compressed_story_data
|
|
|
|
sta ZX0_src+1
|
|
|
|
|
|
|
|
lda #>story_data ; decompress to story data location
|
|
|
|
|
|
|
|
jsr full_decomp
|
|
|
|
|
|
|
|
|
|
|
|
;===================
|
|
|
|
; Load hires graphics
|
|
|
|
;===================
|
|
|
|
|
|
|
|
load_background:
|
|
|
|
|
|
|
|
lda #<story_bg
|
|
|
|
sta ZX0_src
|
|
|
|
lda #>story_bg
|
|
|
|
sta ZX0_src+1
|
|
|
|
|
|
|
|
lda #$20 ; decompress to hgr page1
|
|
|
|
|
|
|
|
jsr full_decomp
|
|
|
|
|
|
|
|
|
2024-05-08 05:12:57 +00:00
|
|
|
jsr wait_until_keypress
|
2024-05-07 05:24:37 +00:00
|
|
|
|
2024-05-08 05:12:57 +00:00
|
|
|
|
|
|
|
bit SET_TEXT
|
|
|
|
bit PAGE1
|
|
|
|
|
2024-05-08 23:52:31 +00:00
|
|
|
lda #<story_data
|
|
|
|
sta START_LINE_L
|
|
|
|
lda #>story_data
|
|
|
|
sta START_LINE_H
|
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
;===========================
|
|
|
|
; main loop
|
|
|
|
;===========================
|
2024-05-09 20:25:11 +00:00
|
|
|
; 14 + 16 * (16 + 40*(16) + 19 + 7) + 17 + 17*40
|
|
|
|
; 14 + 16 * ( 682 ) + 697
|
|
|
|
; 14 + 10912 + 697
|
|
|
|
; 11623 / 65 = 179 lines
|
2024-05-09 13:09:42 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
draw_loop:
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
ldx #0 ; line counter ; 2
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
lda START_LINE_L ; load up input pointers ; 3
|
|
|
|
sta INL ; 3
|
2024-05-09 13:09:42 +00:00
|
|
|
lda START_LINE_H ; 3
|
2024-05-09 20:25:11 +00:00
|
|
|
sta INH ; 3
|
2024-05-09 13:09:42 +00:00
|
|
|
;===========
|
2024-05-09 20:25:11 +00:00
|
|
|
; 14
|
2024-05-08 05:12:57 +00:00
|
|
|
|
2024-05-08 23:52:31 +00:00
|
|
|
outer_text_loop:
|
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
; set up lo-res output pointers
|
|
|
|
; page aligned so no page-crossing issues
|
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
lda gr_offsets_low,X ; 4+
|
|
|
|
sta OUTL ; 3
|
|
|
|
lda gr_offsets_high,X ; 4+
|
|
|
|
sta OUTH ; 3
|
2024-05-08 05:12:57 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
ldy #39 ; line offset pointer ; 2
|
2024-05-09 13:09:42 +00:00
|
|
|
;============
|
|
|
|
; 16
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-08 05:12:57 +00:00
|
|
|
inner_text_loop:
|
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
input_smc:
|
2024-05-09 20:25:11 +00:00
|
|
|
lda (INL),Y ; 5+
|
2024-05-09 13:09:42 +00:00
|
|
|
sta (OUTL),Y ; 6
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
dey ; 2
|
|
|
|
bpl inner_text_loop ; 2/3
|
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
;============
|
2024-05-09 20:25:11 +00:00
|
|
|
; 16
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
; -1
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
; increment
|
|
|
|
; we don't want to cross a page so if we are
|
|
|
|
; 200 then skip to next page
|
|
|
|
|
|
|
|
; -1
|
|
|
|
lda INL ; 3
|
|
|
|
cmp #200 ; 2
|
|
|
|
beq in_next_page ; 2/3
|
|
|
|
; 6
|
|
|
|
ldy $0 ; nop3 ; 3
|
|
|
|
clc ; 2
|
|
|
|
adc #40 ; 2
|
|
|
|
bne in_done ; bra ; 3
|
|
|
|
; 16
|
|
|
|
|
|
|
|
in_next_page:
|
|
|
|
; 7
|
|
|
|
inc INH ; 5
|
|
|
|
lda #0 ; 2
|
|
|
|
nop
|
|
|
|
; 16
|
|
|
|
|
|
|
|
in_done:
|
|
|
|
sta INL ; 3
|
|
|
|
;============
|
|
|
|
; 19
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
inx ; 2
|
|
|
|
cpx #16 ; 2
|
|
|
|
bne outer_text_loop ; 2/3
|
|
|
|
;============
|
|
|
|
; 7
|
2024-05-07 05:24:37 +00:00
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
; -1
|
|
|
|
;==================
|
|
|
|
; draw message
|
|
|
|
;==================
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
ldx #17 ; 2
|
|
|
|
lda gr_offsets_low,X ; 4+
|
|
|
|
sta OUTL ; 3
|
|
|
|
lda gr_offsets_high,X ; 4+
|
|
|
|
sta OUTH ; 3
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
ldy #39 ; 2
|
|
|
|
;==================
|
|
|
|
; 17
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
message_text_loop:
|
|
|
|
lda message,Y ; 4+
|
|
|
|
and #$3f ; 2
|
|
|
|
sta (OUTL),Y ; 6
|
|
|
|
dey ; 2
|
|
|
|
bpl message_text_loop ; 2/3
|
|
|
|
|
|
|
|
;==================
|
|
|
|
; 17*40
|
|
|
|
|
|
|
|
; -1
|
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
|
|
|
|
; 11623
|
2024-05-09 13:09:42 +00:00
|
|
|
;===================================
|
|
|
|
; can we do this constant time?
|
|
|
|
;===================================
|
2024-05-09 20:25:11 +00:00
|
|
|
; no keys pressed = 41
|
|
|
|
; invalid key pressed = 41
|
|
|
|
; up pressed =
|
|
|
|
; down pressed =
|
2024-05-09 13:09:42 +00:00
|
|
|
|
|
|
|
check_keypress:
|
|
|
|
lda KEYPRESS ; 4
|
|
|
|
bpl done_key7 ; 2/3
|
|
|
|
; 6
|
|
|
|
bit KEYRESET ; 4
|
|
|
|
|
|
|
|
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
|
2024-05-09 20:25:11 +00:00
|
|
|
beq do_up_w ; 2/3
|
2024-05-09 13:09:42 +00:00
|
|
|
; 26
|
|
|
|
cmp #$0B ; 2
|
2024-05-09 20:25:11 +00:00
|
|
|
beq do_up_up ; 2/3
|
2024-05-09 13:09:42 +00:00
|
|
|
; 30
|
|
|
|
cmp #'S' ; 2
|
2024-05-09 21:12:56 +00:00
|
|
|
beq do_down_s ; 2/3
|
2024-05-09 13:09:42 +00:00
|
|
|
; 34
|
|
|
|
cmp #$0A ; 2
|
2024-05-09 21:12:56 +00:00
|
|
|
beq do_down_down ; 2/3
|
2024-05-09 13:09:42 +00:00
|
|
|
; 38
|
|
|
|
bne done_key41 ; bra ; 3
|
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
done_with_story:
|
|
|
|
jmp real_done_with_story
|
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
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:
|
2024-05-09 21:12:56 +00:00
|
|
|
inc $00 ; nop5
|
|
|
|
lda $00 ; nop3
|
|
|
|
done_key_49:
|
|
|
|
inc $00 ; nop5
|
|
|
|
lda $00 ; nop3
|
|
|
|
done_key_57:
|
|
|
|
inc $00 ; nop5
|
|
|
|
inc $00 ; nop5
|
2024-05-09 13:09:42 +00:00
|
|
|
nop
|
2024-05-09 21:12:56 +00:00
|
|
|
done_key_69:
|
|
|
|
inc $00 ; nop5
|
|
|
|
nop
|
|
|
|
done_key_76:
|
|
|
|
|
|
|
|
; 11623+76 = 11699
|
|
|
|
|
|
|
|
; want to delay total of 144+70 lines, 214
|
|
|
|
; 214*65 = 13910
|
|
|
|
; -11699
|
|
|
|
; =========
|
|
|
|
; 2211
|
2024-05-09 13:09:42 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
; want to delay 2211 - 4 = 2207 - 20 = 2187/9 = 243
|
|
|
|
; 243/256= 0 r 243
|
2024-05-09 13:09:42 +00:00
|
|
|
;
|
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
lda #0 ; 2
|
|
|
|
ldy #243 ; 2
|
2024-05-09 13:09:42 +00:00
|
|
|
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
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
;done_key:
|
2024-05-09 13:09:42 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
jmp draw_loop ; 3
|
2024-05-09 00:07:48 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
;=================================
|
|
|
|
; handle up pressed
|
|
|
|
;=================================
|
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
do_up_w:
|
|
|
|
; 27
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
do_up_up:
|
|
|
|
; 31
|
|
|
|
lda START_LINE_H ; 3
|
|
|
|
cmp #>story_data ; 2
|
|
|
|
bne up_ok ; 2/3
|
|
|
|
; 38
|
|
|
|
lda START_LINE_L ; 3
|
|
|
|
cmp #<story_data ; 2
|
2024-05-09 21:12:56 +00:00
|
|
|
beq up_done_46 ; 2/3
|
2024-05-09 20:25:11 +00:00
|
|
|
bne up_ok_ok ; bra ; 3
|
|
|
|
; 48
|
2024-05-09 00:07:48 +00:00
|
|
|
|
|
|
|
up_ok:
|
2024-05-09 20:25:11 +00:00
|
|
|
; 39
|
|
|
|
inc $0 ; nop5
|
|
|
|
nop ; nop2
|
|
|
|
nop ; nop2
|
|
|
|
|
|
|
|
; 48
|
|
|
|
up_ok_ok:
|
|
|
|
sec ; 2
|
|
|
|
lda START_LINE_L ; 3
|
2024-05-09 21:12:56 +00:00
|
|
|
beq to_prev_page ; 2/3
|
|
|
|
; 55
|
|
|
|
ldy $0 ; nop3 ; 3
|
|
|
|
sbc #40 ; 2
|
|
|
|
jmp up_done ; 3
|
|
|
|
; 63
|
2024-05-09 20:25:11 +00:00
|
|
|
|
|
|
|
to_prev_page:
|
2024-05-09 21:12:56 +00:00
|
|
|
; 56
|
|
|
|
dec START_LINE_H ; 5
|
|
|
|
lda #200 ; 2
|
2024-05-09 20:25:11 +00:00
|
|
|
up_done:
|
2024-05-09 21:12:56 +00:00
|
|
|
; 63 / 63
|
2024-05-09 20:25:11 +00:00
|
|
|
sta START_LINE_L ; 3
|
2024-05-09 21:12:56 +00:00
|
|
|
jmp done_key_69 ; 3
|
2024-05-09 20:25:11 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
up_done_46:
|
|
|
|
jmp done_key_49 ; 3
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
;=================================
|
|
|
|
; handle down pressed
|
|
|
|
;=================================
|
2024-05-09 00:07:48 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
do_down_s:
|
|
|
|
; 35
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
do_down_down:
|
|
|
|
; 39
|
2024-05-09 20:25:11 +00:00
|
|
|
lda START_LINE_H ; 3
|
2024-05-09 20:45:11 +00:00
|
|
|
cmp #>story_end ; 2
|
2024-05-09 20:25:11 +00:00
|
|
|
bne down_ok ; 2/3
|
2024-05-09 00:07:48 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
; 46
|
2024-05-09 20:25:11 +00:00
|
|
|
lda START_LINE_L ; 3
|
2024-05-09 20:45:11 +00:00
|
|
|
cmp #<story_end ; 2
|
2024-05-09 21:12:56 +00:00
|
|
|
beq down_done ; 2/3
|
|
|
|
; 53
|
|
|
|
bne down_ok_ok ; bra ; 3
|
2024-05-09 00:07:48 +00:00
|
|
|
|
2024-05-09 21:12:56 +00:00
|
|
|
; 47
|
2024-05-09 00:07:48 +00:00
|
|
|
down_ok:
|
2024-05-09 21:12:56 +00:00
|
|
|
lda $0 ; nop5
|
|
|
|
nop ; nop2
|
|
|
|
nop ; nop2
|
|
|
|
|
|
|
|
|
|
|
|
down_ok_ok:
|
|
|
|
; 56
|
2024-05-09 20:25:11 +00:00
|
|
|
; increment input row
|
|
|
|
; we don't want to cross a page so if we are
|
|
|
|
; 200 then skip to next page
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
lda START_LINE_L ; 3
|
|
|
|
cmp #200 ; 2
|
|
|
|
beq to_next_page ; 2/3
|
2024-05-09 21:12:56 +00:00
|
|
|
; 63
|
2024-05-09 20:25:11 +00:00
|
|
|
ldy $0 ; nop3 ; 3
|
|
|
|
clc ; 2
|
|
|
|
adc #40 ; 2
|
|
|
|
bne down_done ; bra ; 3
|
2024-05-09 21:12:56 +00:00
|
|
|
; 73
|
2024-05-09 20:25:11 +00:00
|
|
|
|
|
|
|
to_next_page:
|
2024-05-09 21:12:56 +00:00
|
|
|
; 64
|
2024-05-09 20:25:11 +00:00
|
|
|
inc START_LINE_H ; 5
|
|
|
|
lda #0 ; 2
|
2024-05-09 21:12:56 +00:00
|
|
|
nop ; 2
|
|
|
|
|
|
|
|
; 73 / 73
|
2024-05-09 20:25:11 +00:00
|
|
|
down_done:
|
|
|
|
sta START_LINE_L ; 3
|
2024-05-09 21:12:56 +00:00
|
|
|
jmp done_key_76 ; 3
|
|
|
|
|
|
|
|
early_down_done:
|
|
|
|
; 54
|
|
|
|
jmp done_key_57 ; 3
|
2024-05-08 23:52:31 +00:00
|
|
|
|
2024-05-09 20:25:11 +00:00
|
|
|
real_done_with_story:
|
2024-05-07 05:24:37 +00:00
|
|
|
|
|
|
|
lda #LOAD_TITLE
|
|
|
|
sta WHICH_LOAD
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
;==========================
|
|
|
|
; includes
|
|
|
|
;==========================
|
|
|
|
|
|
|
|
.include "gr_pageflip.s"
|
|
|
|
.include "gr_copy.s"
|
|
|
|
; .include "wait_a_bit.s"
|
|
|
|
.include "gr_offsets.s"
|
2024-05-09 13:09:42 +00:00
|
|
|
|
2024-05-07 05:24:37 +00:00
|
|
|
.include "zx02_optim.s"
|
|
|
|
|
|
|
|
.include "gr_fast_clear.s"
|
|
|
|
.include "text_print.s"
|
|
|
|
|
|
|
|
; .include "lc_detect.s"
|
|
|
|
|
|
|
|
|
|
|
|
story_bg:
|
|
|
|
.incbin "graphics/keen1_story.hgr.zx02"
|
|
|
|
|
|
|
|
compressed_story_data:
|
|
|
|
.incbin "story/story_data.zx02"
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-08 05:12:57 +00:00
|
|
|
wait_until_keypress:
|
|
|
|
lda KEYPRESS
|
|
|
|
bpl wait_until_keypress
|
|
|
|
bit KEYRESET
|
|
|
|
rts
|
|
|
|
|
2024-05-09 13:09:42 +00:00
|
|
|
.align $100
|
2024-05-07 05:24:37 +00:00
|
|
|
|
2024-05-08 23:52:31 +00:00
|
|
|
message:
|
|
|
|
.byte " ESC TO EXIT / ARROWS TO READ ",0
|
2024-05-09 13:09:42 +00:00
|
|
|
|
|
|
|
.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
|