From 7563d411adc9d4d117562cf88c159508875b7fc2 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 16 Jul 2020 01:56:26 -0400 Subject: [PATCH] mist: cabin: can now ride tree to channelwood --- mist/cabin.s | 3 + mist/cabin_boiler_puzzle.s | 170 ++++++++++++++++++++++++++++++++++++- mist/common_routines.inc | 1 + mist/generate_common.c | 1 + mist/init_state.s | 71 ++-------------- mist/leveldata_cabin.inc | 7 +- mist/mist.s | 2 + mist/mist_puzzles.s | 37 -------- mist/simple_sounds.s | 47 ++++++++++ mist/zp.inc | 2 + 10 files changed, 237 insertions(+), 104 deletions(-) create mode 100644 mist/simple_sounds.s diff --git a/mist/cabin.s b/mist/cabin.s index 6f63b1c7..126b4cc5 100644 --- a/mist/cabin.s +++ b/mist/cabin.s @@ -123,6 +123,8 @@ done_match_handler: ; handle special-case forground logic ;==================================== + jsr update_boiler_state + jsr draw_marker_switch lda LOCATION @@ -327,3 +329,4 @@ exit_to_mist: ; linking books .include "link_book_channel.s" + .include "simple_sounds.s" diff --git a/mist/cabin_boiler_puzzle.s b/mist/cabin_boiler_puzzle.s index ee50a005..4518bce0 100644 --- a/mist/cabin_boiler_puzzle.s +++ b/mist/cabin_boiler_puzzle.s @@ -34,9 +34,121 @@ ; button does nothing in basement ; dial in basement does same as one upstairs +; 0123456789012345678901234 ; \ \ \ \ \ : / / / / / ; P S I -; \ +; \ + +; BOILER_VALVE +; BOILER_LEVEL: high bit is if pilot lit, low bits are PSI +; BOILER_TOTAL: +; 0...128 warming up +; then if valve>12 inc level, when hit 15 inc tree +; if valve<12 dec level, when hit 0 dec tree +; rate of adding is (valve-12) 0..12 / 4 = 0..3 +; 0 = FRAMEL&1f==0 +; 1 = FRAMEL&f==0 +; 2 = FRAMEL&7==0 +; 3 = FRAMEL&3==0 +; Make noise when change tree level + +update_boiler_state: + + ; if pilot not lit, nothing to do + lda BOILER_LEVEL + bpl done_boiler_state + + lda BOILER_VALVE + beq done_boiler_state + sec + sbc #12 + + bpl skip_abs + + eor #$ff + clc + adc #$1 +skip_abs: + + ; div by 4 + lsr + lsr + + lda FRAMEL + and #$1f + beq actually_adjust_boiler + + rts + +actually_adjust_boiler: + lda BOILER_VALVE + cmp #12 + bcs valve_positive + bcc valve_negative + +valve_positive: + jsr inc_boiler + jmp done_boiler_state + +valve_negative: + jsr dec_boiler +done_boiler_state: + + rts + +inc_boiler: + lda BOILER_LEVEL + and #$7f + cmp #25 + beq inc_boiler_overflow + inc BOILER_LEVEL + rts + +inc_boiler_overflow: + lda TREE_LEVEL + cmp #6 + beq tree_at_top + + lda BOILER_LEVEL + and #$80 + sta BOILER_LEVEL + + inc TREE_LEVEL + jsr change_tree_level + +tree_at_top: + rts + +dec_boiler: + lda BOILER_LEVEL + and #$1f + cmp #0 + beq dec_boiler_overflow + dec BOILER_LEVEL + rts + +dec_boiler_overflow: + lda TREE_LEVEL + beq tree_at_bottom + + lda #$80|24 + sta BOILER_LEVEL + + dec TREE_LEVEL + jsr change_tree_level + +tree_at_bottom: + rts + + +change_tree_level: + jsr cabin_update_state + + jsr change_direction + + jsr beep + + rts tree_base_backgrounds: @@ -68,7 +180,7 @@ tree_elevator_backgrounds: tree_basement_backgrounds: .word tree_basement_n_lzsa ; 0 basement - .word tree_basement_n_lzsa ; 1 underground + .word tree_basement_noelev_n_lzsa ; 1 underground .word tree_basement_noelev_n_lzsa ; 2 ground .word tree_basement_noelev_n_lzsa ; 3 L6 .word tree_basement_noelev_n_lzsa ; 4 L8 @@ -94,6 +206,8 @@ tree_entrance: .byte CABIN_TREE_LOOK_UP ; 5 L10 .byte CABIN_TREE_LOOK_UP ; 6 TOP + ; south if getting on elevator + ; north if looking up tree_entrance_dir: .byte DIRECTION_N ; 0 basement .byte DIRECTION_N ; 1 underground @@ -174,6 +288,17 @@ cabin_update_state: rts + ;========================== + ; valve clicked in basement + +valve_clicked_basement: + lda CURSOR_X + cmp #8 + bcc valve_dec + bcs valve_inc + + ;================================== + ; goto safe or valve (cabin boiler) goto_safe_or_valve: lda DIRECTION @@ -532,8 +657,42 @@ pilot_smc: skip_pilot: + +draw_psi: + bit TEXTGR ; bit of a hack + ; adjust to correct page + lda DRAW_PAGE + clc + adc #$7 + sta psi_smc+2 + + lda BOILER_LEVEL + and #$1f + tay + + cpy #13 + beq want_colon + bcc want_backslash +want_slash: + lda #'/'|$80 + bne put_psi ; bra + +want_backslash: + lda #'\'|$80 + bne put_psi ; bra +want_colon: + lda #':'|$80 + +put_psi: + + ; 7,44 = $757 +psi_smc: + sta $757,Y + + + lda #31 sta XPOS lda #14 @@ -580,11 +739,18 @@ press_elevator_button: bcc button_ineffective dec TREE_LEVEL ; drops you a floor + lda #$80 + sta BOILER_LEVEL ; give some time before hitting again + + jsr change_tree_level button_ineffective: rts bump_up: inc TREE_LEVEL ; if on ground floor it bumps you up + + jsr change_tree_level + jmp button_ineffective diff --git a/mist/common_routines.inc b/mist/common_routines.inc index 6574d09a..196918d6 100644 --- a/mist/common_routines.inc +++ b/mist/common_routines.inc @@ -38,6 +38,7 @@ psc_smc2 =$19b7 ; keyboard.s handle_keypress =$1a38 +change_direction =$1ae0 change_location =$1b19 ; text_print.s diff --git a/mist/generate_common.c b/mist/generate_common.c index cf252ce9..28a52b0b 100644 --- a/mist/generate_common.c +++ b/mist/generate_common.c @@ -89,6 +89,7 @@ int main(int argc, char **argv) { printf("; keyboard.s\n"); find_address("handle_keypress"); + find_address("change_direction"); find_address("change_location"); printf("\n"); diff --git a/mist/init_state.s b/mist/init_state.s index edf74209..086e211c 100644 --- a/mist/init_state.s +++ b/mist/init_state.s @@ -3,7 +3,14 @@ ; initial state at start of game is for all vars to be 0 init_state: -.if 1 + + ; global game state + lda #0 + sta SOUND_DISABLED + sta JOYSTICK_ENABLED + + ; game state in saves init + lda #$0 ldy #WHICH_LOAD init_state_loop: @@ -20,65 +27,3 @@ init_state_loop: rts -.else - ; book pages - sta RED_PAGES_TAKEN - sta BLUE_PAGES_TAKEN - sta HOLDING_PAGE - sta RED_PAGE_COUNT - sta BLUE_PAGE_COUNT - - ; init clock puzzles - sta CLOCK_MINUTE - sta CLOCK_HOUR - sta CLOCK_TOP - sta CLOCK_MIDDLE - sta CLOCK_BOTTOM - sta CLOCK_COUNT - sta CLOCK_LAST - - ; init gear - sta GEAR_OPEN - - ; init generator - sta BREAKER_TRIPPED - sta GENERATOR_VOLTS - sta ROCKET_VOLTS - sta GENERATOR_VOLTS_DISP - sta ROCKET_VOLTS_DISP - sta SWITCH_TOP_ROW - sta SWITCH_BOTTOM_ROW - sta ROCKET_HANDLE_STEP - - ; init rocket sliders - sta ROCKET_NOTE1 - sta ROCKET_NOTE2 - sta ROCKET_NOTE3 - sta ROCKET_NOTE4 - - ; meche elevator - sta MECHE_ELEVATOR - sta MECHE_ROTATION - sta MECHE_LOCK1 - sta MECHE_LOCK2 - sta MECHE_LOCK3 - sta MECHE_LOCK4 - - sta VIEWER_CHANNEL - sta VIEWER_LATCHED - - sta TOWER_ROTATION - - sta SHIP_RAISED - - sta PUMP_STATE - sta BATTERY_CHARGE - sta COMPASS_ANGLE - sta CRANK_ANGLE - sta CHANNEL_SWITCHES - - lda #$ff ; for debugging - sta MARKER_SWITCHES -.endif - - rts diff --git a/mist/leveldata_cabin.inc b/mist/leveldata_cabin.inc index 9af96ae0..65c20898 100644 --- a/mist/leveldata_cabin.inc +++ b/mist/leveldata_cabin.inc @@ -172,7 +172,7 @@ location8: .byte $ff ; east exit .byte $ff ; west exit .byte $ff ; north exit_dir - .byte DIRECTION_N ; south exit_dir + .byte DIRECTION_S ; south exit_dir .byte $ff ; east exit_dir .byte $ff ; west exit_dir .word $0000 ; north bg @@ -201,7 +201,10 @@ location9: .word $0000 ; east bg .word $0000 ; west bg .byte BG_SOUTH|BG_NORTH - .byte $ff + .byte DIRECTION_N ; special exit + .byte 3,10 ; special x + .byte 20,30 ; special y + .word valve_clicked_basement-1 ; CABIN_TREE_BOOK -- tree basement book location10: diff --git a/mist/mist.s b/mist/mist.s index 3e7af76a..298eda94 100644 --- a/mist/mist.s +++ b/mist/mist.s @@ -361,5 +361,7 @@ flip_dock_switch: .include "handle_pages.s" + .include "simple_sounds.s" + ; level data .include "leveldata_mist.inc" diff --git a/mist/mist_puzzles.s b/mist/mist_puzzles.s index 5e60fa08..5fda4459 100644 --- a/mist/mist_puzzles.s +++ b/mist/mist_puzzles.s @@ -282,43 +282,6 @@ move_the_ship: rts - - ;=========================== - ; BEEP (inlined) - ;=========================== -beep: - ldy #235 - sty tone_smc+1 - - ; BEEP - ; repeat 30 times - lda #30 ; 2 -tone1_loop: - -tone_smc: - - ldy #24 ; 2 -loopC: ldx #6 ; 2 -loopD: dex ; 1 - bne loopD ; 2 - dey ; 1 - bne loopC ; 2 - - bit SPEAKER ; 3 ; click speaker - - sec ; 1 - sbc #1 ; 2 - bne tone1_loop ; 2 - - ; Try X=6 Y=21 cycles=757 - ; Try X=6 Y=24 cycles=865 - ; Try X=7 Y=235 cycles=9636 - - rts - - - - powersoftwo: .byte $01,$02,$04,$08,$10,$20,$40,$80 diff --git a/mist/simple_sounds.s b/mist/simple_sounds.s new file mode 100644 index 00000000..7ac3fe17 --- /dev/null +++ b/mist/simple_sounds.s @@ -0,0 +1,47 @@ + + +click_speaker: + lda SOUND_DISABLED + bne done_click + bit $c030 +done_click: + rts + + ;=========================== + ; BEEP (inlined) + ;=========================== +beep: + lda SOUND_DISABLED + bne done_beep + + ldy #235 + sty tone_smc+1 + + ; BEEP + ; repeat 30 times + lda #30 ; 2 +tone1_loop: + +tone_smc: + + ldy #24 ; 2 +loopC: ldx #6 ; 2 +loopD: dex ; 1 + bne loopD ; 2 + dey ; 1 + bne loopC ; 2 + + bit SPEAKER ; 3 ; click speaker + + sec ; 1 + sbc #1 ; 2 + bne tone1_loop ; 2 + + ; Try X=6 Y=21 cycles=757 + ; Try X=6 Y=24 cycles=865 + ; Try X=7 Y=235 cycles=9636 +done_beep: + rts + + + diff --git a/mist/zp.inc b/mist/zp.inc index e9360f88..3db45588 100644 --- a/mist/zp.inc +++ b/mist/zp.inc @@ -217,6 +217,8 @@ END_OF_SAVE = $C9 ; done game puzzle state +JOYSTICK_ENABLED= $DD +SOUND_DISABLED = $DE GRID_PAGE = $DF ANIMATE_FRAME = $E0 LEVEL_OVER = $E1