Prev: 8008 Up: Map Next: 80B9
8014: Load a stage
Returns at once if the wanted stage is already loaded. Otherwise it records the new stage number, clears the playfield and starts a reverse transition, then reads two-byte headers into hazard_1 until one arrives whose two bytes agree; that byte is the stage number. When it is the wanted stage, tape_load_stage loads $1AF0 (6896) bytes of stage data to $5C00.
Used by the routine at main_loop.
load_stage 8014 LD A,($8007) Load wanted_stage_number
8017 LD HL,$A13A Point HL at current_stage_number
801A CP (HL) Exit if they match
801B RET Z
801C LD (HL),A Set current_stage_number to wanted_stage_number
801D LD ($A220),A Set dont_draw_screen_attrs to a non-zero value
8020 ADD A,$B0 Update the level number in "SEARCHING FOR <N>"
8022 LD ($81AE),A
ls_loop 8025 CALL set_playfield_attrs Call set_playfield_attrs
8028 CALL clear_playfield_attrs Call clear_playfield_attrs
802B LD A,$F8 Reverse transition
802D CALL setup_transition Call setup_transition
8030 LD B,$02
ls_prompt_and_load_header 8032 CALL ls_print_start_tape Call ls_print_start_tape
ls_load_header 8035 LD IX,$A19C Load to address &hazards[1] as a temporary scratch area
8039 LD DE,$0002 Load 2 bytes
803C CALL tape_load_at_ix Call tape_load_at_ix subroutine
803F JR NC,ls_load_header Loop to ls_load_header while failed
8041 LD HL,$A19C HL = &hazards[1]
8044 LD A,(HL) Both header bytes must hold the same stage number, a simple integrity check
8045 INC HL
8046 CP (HL)
8047 JR NZ,ls_load_header Loop to ls_load_header if not
8049 ADD A,$B0 Make it ASCII and terminate it by adding 48+128
804B LD ($81BA),A Set x in "FOUND x"
804E LD B,$03
8050 LD A,($8007) A = wanted_stage_number
8053 CP (HL) Is it the wanted stage?
8054 JR NZ,ls_prompt_and_load_header not the wanted stage
8056 CALL ls_print_start_tape Call ls_print_start_tape
8059 CALL tape_load_stage Call tape_load_stage
805C JR NC,ls_loop Jump to ls_loop if no carry
Success - must have loaded the correct level data.
805E XOR A Set border to black
805F OUT ($FE),A
8061 CALL set_playfield_attrs Call set_playfield_attrs
8064 CALL clear_playfield_attrs Call clear_playfield_attrs
8067 LD HL,$81BB HL -> "STOP THE TAPE" message structure
806A LD B,$02
806C CALL ls_print_message Call ls_print_message
806F PUSH HL Preserve HL across the keypress wait below
Wait for a keypress - debounce.
load_stage_0 8070 CALL keyscan Call keyscan
8073 AND $10 Loop while key not pressed
8075 JR Z,load_stage_0
load_stage_1 8077 CALL keyscan Call keyscan
807A AND $10 Loop while key pressed
807C JR NZ,load_stage_1
807E LD A,$08 Forward transition
8080 CALL setup_transition Call setup_transition
8083 POP HL Restore HL after the keypress wait
8084 LD B,$02 B = 2
8086 JR ls_print_message Exit via ls_print_message
B is passed in.
ls_print_start_tape 8088 LD HL,$818C Point HL at "START TAPE" message structure
808B LD A,($8007) A = wanted_stage_number - 1
808E DEC A
808F JR NZ,ls_print_twice Jump if > 0
8091 INC B
8092 LD HL,$8169 Point HL at the rewind_tape messages
ls_print_twice 8095 CALL ls_print_message Call the routine below, then fall into it, so it runs twice
ls_print_message 8098 PUSH BC preserve counter
8099 PUSH HL preserve message pointer
ls_print_loop 809A LD A,$05 flags byte for print_message
809C DEC HL Step back one byte: print_message skips a flags byte these messages lack
809D CALL print_message Call print_message
80A0 DJNZ ls_print_loop Print B consecutive messages
80A2 CALL transition Call transition
80A5 CALL send_playfield Call send_playfield
80A8 POP HL restore message pointer
80A9 POP BC restore counter
80AA LD A,($A231) Load transition_control
80AD AND A Return if zero
80AE RET Z
80AF LD DE,$0A00 Delay loop
ls_delay_loop 80B2 DEC DE
80B3 LD A,D
80B4 OR E
80B5 JR NZ,ls_delay_loop
80B7 JR ls_print_message Loop
Prev: 8008 Up: Map Next: 80B9