Prev: 89D2 Up: Map Next: 8A28
89D3: Start an attacker in a free record
Used by the routine at spawn_attacker.
Called by spawn_tick with IX a free record among the first four. The kinds of attacker are taken in turn (the wave counter wave_counter counts round 0-5, or 0-7 once +$0A and +$0B of the player's record, score, are both set); kind 4, the tough attacker, is usually turned into kind 3 (unless the refresh register's bits $32 are all 0), and kinds 1 and 5 (clouds) become kind 0 outside screen rows 3-9. While a meteor shower is on (meteor_shower) and the view is above screen row $0B, a rock or comet starts near the ship instead (at the end of start_at_edge).
start_at_edge chooses where. The view overlaps four screens: its own (view_column, view_row), the one to its right (right_map_column), the one below and the one right and below; bit 1 of scratch_count picks right, bit 0 below. B says which bits may be chosen at random, C which are forced: when the ship moves fast across (the high byte of its speed across, +$19 of its record in bare_ship, not 0 or $FF), the screen to the right if the scroll step across (the second byte of scroll_down) is negative and the view's own column if not; likewise in Y with its speed down (+$1B) and the first byte of scroll_down (the screen below when that is negative). Up to four screens are tried in turn (speed_limit_down).
Then one screen is tried: the screen's tile (its byte in map_window_tile_bytes) gives a mask of allowed spawn points (spawn_point_masks); a random start point (the instruction shown as RLC B in start_at_edge is rewritten to BIT n,A) is followed round the mask to the first allowed one (spawn_points), which sets the record's +2 and +5. The record is cleared (free_object), given the kind's four bytes from the wave table wave_table (type, +$10, +$13, +$14) and a colour ($FF, or $77 now and then; for most types one of the eight colours in attacker_colours, the first four only in screen rows 4-11), and put in the chosen screen's column and row. If it would be in view now (place_on_screen sets +$10 bit 7) it is freed and the next screen tried; otherwise it is turned towards the view (head_for_view).
place_on_screen is given DE pointing at the screen's kind's byte in the ROM's first bytes ($0000-$0003, D being 0), not at a graphic, so the size it tests with is not the attacker's: a large one. Whether that is meant is not known; it keeps attackers from starting near the view.
A cloud (type $13) takes frame 0 or, one in eight, the big cloud; in screen rows 0-4 it is put at line $1F of row 4 instead, level with the view's x, and not tested. Kinds 8 and 9 (type $1D) move 2 or 4 pixels a pass each way, right in the view's own column and left in the next.
Input
IX The free record
start_attacker 89D3 LD B,$06 Six kinds, or eight
89D5 LD A,(addon_four)
89D8 AND A
89D9 JR Z,start_attacker_0
89DB LD A,(addon_five)
89DE AND A
89DF JR Z,start_attacker_0
89E1 LD B,$08
start_attacker_0 89E3 LD A,(wave_counter) The next kind in turn
89E6 INC A
89E7 LD (wave_counter),A
89EA CP B
89EB JR C,start_attacker_1
89ED XOR A
89EE LD (wave_counter),A
start_attacker_1 89F1 CP $04 Kind 4 mostly becomes 3
89F3 JR NZ,start_attacker_2
89F5 LD B,A
89F6 LD A,R
89F8 AND $32
89FA LD A,B
89FB JR Z,start_attacker_2
89FD DEC A
start_attacker_2 89FE LD (attacker_kind),A Clouds only in screen rows 3-9; elsewhere kind 0
8A01 CP $01
8A03 JR Z,start_attacker_3
8A05 CP $05
8A07 JR NZ,start_attacker_5
start_attacker_3 8A09 LD A,(view_row)
8A0C CP $03
8A0E JR C,start_attacker_4
8A10 CP $0A
8A12 JR C,start_attacker_5
start_attacker_4 8A14 XOR A
8A15 LD (attacker_kind),A
start_attacker_5 8A18 LD A,(view_row) A meteor shower above row $0B
8A1B CP $0B
8A1D JR NC,start_attacker_6
8A1F LD A,(meteor_shower)
8A22 AND A
8A23 JP NZ,start_at_edge_17
start_attacker_6 8A26 LD B,$03 Any screen
Prev: 89D2 Up: Map Next: 8A28