Prev: 605B Up: Map Next: 61A9
6113: Deal a player the places of the pick-ups
Used by the routine at new_game.
Called twice by new_game at a new game, once for each player's record (score, other_player_record). Goes through the dealing list at dealing_list and, for each entry, writes a four-byte place (see place_pool_kind3) to the record and moves on four bytes. An entry of 1 to 5 deals a place at random from that group of the pool, one not dealt already; an entry of 0 deals nothing, leaving the four bytes as they were ($FF, no place) -- unless the next entry is 3, when it copies the place before it, 16 to the right and 35 up, so the two pick-ups lie side by side. The list ends with its entry of 4, which is dealt too.
Every place in the pool is free again at the start, so the two players are dealt independently and may be given the same places.
Input
DE The player record's first place (+$1D)
deal_places 6113 LD IY,dealing_list The whole list, nineteen entries
This entry point is used by the routine at planet_secured.
With IY at the list's last entry alone (planet_secured, at the end of a stage), this deals the record's last place again.
deal_places_0 6117 LD HL,place_pool_kind3 Mark all 46 places in the pool free
611A LD B,$2E
deal_places_1 611C LD A,(HL)
611D AND $7F
611F LD (HL),A
6120 INC HL
6121 INC HL
6122 INC HL
6123 INC HL
6124 DJNZ deal_places_1
6126 LD A,$FF Except the first and third places of kind 2, never dealt
6128 LD (place_pool_kind2),A
612B LD (place_pool_kind2_third),A
deal_places_2 612E LD A,(IY+$00) An entry of 1-5: deal from a group
6131 AND A
6132 JR NZ,deal_places_3
6134 LD A,(IY+$01) An entry of 0: unless the next entry is 3, leave this place alone
6137 CP $03
6139 JR NZ,deal_places_6
613B PUSH DE Copy the place before it
613C POP HL
613D DEC HL
613E DEC HL
613F DEC HL
6140 DEC HL
6141 LD BC,$0004
6144 LDIR
6146 DEC DE Its y 35 less
6147 LD A,(DE)
6148 SUB $23
614A LD (DE),A
614B DEC DE Its x 16 more
614C LD A,(DE)
614D ADD A,$10
614F LD (DE),A
6150 JR deal_places_7 Next entry
deal_places_3 6152 LD C,$0F Pick the kind's group and a mask one less than its size: kind 1 the second group of place_pool_kind3, 3 the first, 2 the fourth, 4 the fifth, 5 the third
6154 LD HL,place_pool_kind1
6157 CP $01
6159 JR Z,deal_places_4
615B LD HL,place_pool_kind3
615E CP $03
6160 JR Z,deal_places_4
6162 LD C,$07
6164 LD HL,place_pool_kind2
6167 CP $02
6169 JR Z,deal_places_4
616B LD C,$03
616D LD HL,place_pool_kind4
6170 CP $04
6172 JR Z,deal_places_4
6174 LD HL,place_pool_kind5
6177 LD C,$01
deal_places_4 6179 PUSH HL A place of the group chosen by the random number (random_a)
617A LD A,(random_a)
617D AND C
617E ADD A,A
617F ADD A,A
6180 CALL add_a_to_hl
6183 BIT 7,(HL) Already dealt: stir the random number (random) and try again
6185 JR Z,deal_places_5
6187 CALL random
618A POP HL
618B JR deal_places_4
deal_places_5 618D LD BC,$0004 Copy it to the record
6190 LDIR
6192 DEC HL Mark it dealt
6193 DEC HL
6194 DEC HL
6195 DEC HL
6196 SET 7,(HL)
6198 POP HL Next entry
6199 JR deal_places_8
deal_places_6 619B INC DE Leave four bytes
619C INC DE
deal_places_7 619D INC DE
619E INC DE
deal_places_8 619F LD A,(IY+$00) Stop after the entry of 4
61A2 CP $04
61A4 RET Z
61A5 INC IY Next entry
61A7 JR deal_places_2
Prev: 605B Up: Map Next: 61A9