![]() |
Routines |
| Prev: D74C | Up: Map | Next: D7D8 |
|
Used by the routine at NEW_GAME.
Called by the main loop every turn (NEW_GAME). When the bonus record is empty it picks a cell: the knight's own column or the one four to its right (the random number's bits 0-2 masked with $FC leave only 0 or 4), and a row from four above his to three below. If that cell is not solid (types 1 and 2) and is not within one cell of the knight, the bonus goes there, at a random place in the middle half of the cell, as graphic 2 or 3 by whether the turn count is even or odd.
So a bonus is almost always about: the moment one is taken, or left behind by more than three cells (SPEED_BONUS), the next turn tries again. One placed four columns to the right is outside the three cells SPEED_BONUS keeps it within, so it goes again on its first update, unless the knight has moved towards it; so does one placed four rows up. Measured in the simulator with the knight standing in cell (16,16): of 330 placements only those in his own column two or three rows away outlasted their first update, and a bonus was there in every one of 300 turns left alone.
The column is wrapped to the town's 32 but the row is looked up before it is wrapped, so a knight in the top four or bottom three rows has the bonus's cell looked up outside the map (PLACE_IN_CELL, from offset 41, adds the row times 32 to the map's address as it is); only the stored row is wrapped.
|
||||
| PLACE_BONUS | D76C | LD IX,BONUS | Nothing to do while there is a bonus (or its vanishing) | |
| D770 | LD A,(IX+$00) | |||
| D773 | AND A | |||
| D774 | RET NZ | |||
| D775 | CALL STIR_RANDOM | Stir the random number | ||
| D778 | LD A,(KNIGHT_COLUMN) | L=the knight's column, H=his row | ||
| D77B | LD L,A | |||
| D77C | LD A,(KNIGHT_ROW) | |||
| D77F | LD H,A | |||
| D780 | LD A,(RANDOM) | Column: his own or four to the right, wrapped to 0-31 | ||
| D783 | AND $07 | |||
| D785 | AND $FC | |||
| D787 | ADD A,L | |||
| D788 | AND $1F | |||
| D78A | LD L,A | |||
| D78B | LD (IX+$02),A | |||
| D78E | LD A,($BBAB) | Row: four above his to three below; the stored row is wrapped, H is not | ||
| D791 | AND $07 | |||
| D793 | ADD A,$FC | |||
| D795 | ADD A,H | |||
| D796 | LD H,A | |||
| D797 | AND $1F | |||
| D799 | LD (IX+$04),A | |||
| D79C | CALL TOWN_CELL | Look the cell up (L column, H row); no bonus in a solid cell (type 1 or 2) | ||
| D79F | DEC A | |||
| D7A0 | CP $02 | |||
| D7A2 | RET C | |||
| D7A3 | LD C,$02 | None within one cell of the knight, either | ||
| D7A5 | CALL NEAR_KNIGHT | |||
| D7A8 | RET C | |||
| D7A9 | LD A,(TURNS) | Graphic 2 on an even turn, 3 on an odd one | ||
| D7AC | AND $01 | |||
| D7AE | OR $02 | |||
| D7B0 | LD (IX+$00),A | |||
| D7B3 | LD A,(RANDOM) | A random place in the middle half of the cell, U and V 64-191 | ||
| D7B6 | AND $7F | |||
| D7B8 | ADD A,$40 | |||
| D7BA | LD (IX+$01),A | |||
| D7BD | LD A,($BBAB) | |||
| D7C0 | AND $7F | |||
| D7C2 | ADD A,$40 | |||
| D7C4 | LD (IX+$03),A | |||
| D7C7 | LD (IX+$08),$10 | Half-size 16 each way | ||
| D7CB | LD (IX+$09),$10 | |||
| D7CF | LD (IX+$0C),$F4 | The drawing offset | ||
| D7D3 | LD (IX+$0D),$04 | |||
| D7D7 | RET | |||
| Prev: D74C | Up: Map | Next: D7D8 |