Prev: CB71 Up: Map Next: CBAC
CB7B: Choose Start Position
Used by the routine at StartGame.
Chooses a random cell of the village for the player to start in, avoiding cells that are solid (tiles 01 and 02), and stores its column and row in the template for the player at PlayerTemplate.
Pick a random cell that is not solid.
ChooseStartPosition CB7B CALL RandomNumber Update the random number generator.
CB7E LD DE,($BBAA) Fetch the random number.
ChooseStartPosition_Cell CB82 LD A,D Turn the random number into a place in the map of the village.
CB83 AND $03
CB85 LD D,A
CB86 LD HL,$5E04 Find the tile in the map.
CB89 ADD HL,DE
CB8A LD A,(HL) Jump to ChooseStartPosition_Found to use this cell unless the tile is solid (01 or 02).
CB8B DEC A
CB8C CP $02
CB8E JR NC,ChooseStartPosition_Found
CB90 INC DE Otherwise move on to the next cell and try again.
CB91 JR ChooseStartPosition_Cell
Store the column and the row in the template.
ChooseStartPosition_Found CB93 LD A,E Store the column of the cell in the template for the player.
CB94 AND $1F
CB96 LD ($CC38),A
CB99 RL E Shift the place in the map left three times, which moves the row of the cell into the lowest five bits of D.
CB9B RL D
CB9D RL E
CB9F RL D
CBA1 RL E
CBA3 RL D
CBA5 LD A,D Store the row of the cell in the template for the player.
CBA6 AND $1F
CBA8 LD ($CC3A),A
CBAB RET Return.
Prev: CB71 Up: Map Next: CBAC