Prev: 81ED Up: Map Next: 830E
8212: Init stage
Initialize stage and display X WARPS TO Y message. Used by the routines at entry, switch_player and next_stage.
init_stage 8212 LD HL,ship_background_data Clear $28 bytes from $722E
8215 LD DE,$722F ...
8218 LD BC,$0028 ...
821B LD (HL),$00 ...
821D LDIR ...
821F LD A,$01 Set sprite countdown to 1
8221 LD (sprite_countdown),A ...
8224 LD HL,status_flags Clear died flag
8227 RES 2,(HL) ...
Calculate stage data index
8229 LD A,(completed_stages) Get completed stages
822C OR A Test if zero
822D JR NZ,init_stage_0 If not, skip ahead to set max value
822F LD A,(stage) Stage
8232 CP $04 Compare stage to 4
8234 JR NC,init_stage_1 Jump if stage >= 4, to set value = stage / 4 + 1
8236 LD B,A B = stage 1-3
8237 XOR A A = 0
8238 DEC B B = 0-2
8239 JR Z,init_stage_2 If zero then skip ahead to save value
823B INC A Stage = 2 or 3, set A = 1
823C JR init_stage_2 Skip ahead to save value
init_stage_0 823E LD A,$18 24
init_stage_1 8240 SRL A Divide stage by 4
8242 SRL A ...
8244 INC A + 1
init_stage_2 8245 LD (stage_data_index),A Save value (0 - 7)
Display stage number
8248 LD A,(stage) Current stage
824B LD HL,completed_stages Completed stages
824E ADD A,(HL) Add to stage
824F LD DE,$1AFE VDP address (stage number tens)
8252 CP $0A
8254 JR C,init_stage_5 Jump if < 10
8256 LD B,$00 Divide by ten into B
init_stage_3 8258 SUB $0A ...
825A JR C,init_stage_4 ...
825C INC B ...
825D JR init_stage_3 ...
init_stage_4 825F ADD A,$0A Restore ones
8261 LD C,A Save in C
8262 LD A,B Tens
8263 ADD A,$30 Add ASCII 0
8265 RST $10 Write VDP byte
8266 LD A,C Ones
init_stage_5 8267 INC DE Increment VDP address to stage number ones
8268 ADD A,$30 Add ASCII 0
826A RST $10 Write VDP byte
Display X WARPS TO Y message
826B LD A,(wave) Check whether you just died
826E OR A So we want to display READY instead
826F JR NZ,init_stage_7 And if so jump ahead
8271 LD A,(stage) Get stage
8274 LD B,A Save in B
8275 SRL A Divide by 2
8277 AND $0E Clamp to 0, 2, 4, 6, 8, 10, 12
8279 LD HL,planet_table Base planet table
827C RST $08 Add A to HL
827D LD E,(HL) Get LSB of planet data
827E INC HL To MSB
827F LD D,(HL) Get MSB of planet data
8280 LD HL,$0010 Planet name offset is 16
8283 ADD HL,DE Add planet data address
8284 PUSH HL Save it
8285 LD DE,$71A4 Buffer address for the string buffer+1
8288 LD A,B Restore stage
8289 AND $03 Clamp to 0, 1, 2, 3
828B CP $03 If 3 we have reached a chance stage
828D JR Z,init_stage_8 Then jump ahead
828F XOR $03 Flip the bits, so we know how many warps TO the planet
8291 ADD A,$30 Add ASCII 0
8293 LD (DE),A Store number in the buffer
8294 INC DE Next buffer address
8295 LD HL,warps_msg WARPS message
8298 LD BC,$0005 Copy 5 bytes '_WARP'
829B CP $31 If the number is less than 2,
829D JR Z,init_stage_6 then skip ahead
829F INC BC Otherwise copy one more byte '_WARPS'
init_stage_6 82A0 LDIR Make the copy
82A2 LD HL,to_msg Copy _TO_ message
82A5 LD BC,$0004 4 bytes
82A8 LDIR Make the copy
82AA POP HL Restore the planet name address
82AB LD C,(HL) Get length of name
82AC INC HL Next byte
82AD LDIR Copy planet name
82AF EX DE,HL Now HL=destination and DE=source
82B0 LD DE,$71A4 Buffer address for the string buffer+1
82B3 SBC HL,DE Now HL contain the length of the string
82B5 EX DE,HL Now DE=length and HL=$71A4
82B6 DEC HL HL=buffer
82B7 LD (HL),E Set length
82B8 JR init_stage_9 Jump ahead
init_stage_7 82BA LD HL,ready_msg Ready message
82BD JR init_stage_9 Skip ahead
init_stage_8 82BF POP HL Drop the pushed planet name address
82C0 LD HL,chance_stage_msg Chance stage message
init_stage_9 82C3 LD A,$20 At this point HL contains a pointer to the length prefixed message to print
82C5 SUB (HL) 32 - string length
82C6 SRL A / 2 = offset to center line
82C8 LD DE,$1A00 VDP address of line start
82CB ADD A,E Add address to offset
82CC LD E,A Copy back to destination
82CD LD C,(HL) Length
82CE LD B,$00 MSB of length
82D0 INC HL Increment source to text
82D1 RST $38 WRITE_VRAM Display the X WARPS TO Y message
Display ship and stars with music for a short while
82D2 CALL display_player Display player if 2 player
82D5 LD B,$00 For calculating ...
82D7 LD A,(stage) Get stage
82DA LD HL,completed_stages Add completed stages
82DD ADD A,(HL) ...
82DE CP $01 If 1 then skip ahead with B = 0
82E0 JR Z,init_stage_10 ...
82E2 AND $03 Stage mod 4
82E4 LD B,$05 Set B = 5
82E6 CP $01 And skip ahead if stage mod 4 < 1
82E8 JR C,init_stage_10 ...
82EA LD B,$03 Set B = 3
82EC JR Z,init_stage_10 And skip ahead if stage mod 4 = 1
82EE LD B,$04 Set B = 4
82F0 CP $02 And skip ahead if stage mod 4 = 2
82F2 JR Z,init_stage_10 ...
82F4 LD B,$06 Set B = 6
init_stage_10 82F6 LD A,B Set A = B
82F7 CALL call_play_tune Play selected tune
82FA CALL display_lives Display lives
82FD CALL init_sprite_data Init sprite data
8300 CALL initial_game_loop Initial game loop
8303 CALL init_mine_variables_2 Init some variables
8306 LD HL,status_flags Update status flags
8309 RES 4,(HL) ...
830B SET 6,(HL) Set main loop flag
830D RET
Prev: 81ED Up: Map Next: 830E