Prev: CEF8 Up: Map Next: CFA5
CF08: Draw View
Used by the routine at StartGame.
Draws the view of the village in the pixel buffer, as seen from the player. The view is made of cells of the map, drawn from the furthest to the nearest, with the objects that are in each cell drawn after the cell.
The cells around the player are drawn in an order that depends on which of the five cells beside the player's cell are not empty. A pattern of five bits is made from them and used to find an entry in the table at ViewPatterns, which is made of five bytes for each pattern. Each byte gives one cell to draw: bits 0 and 1 choose what to draw (0 for only the objects in the cell, 1 for the cell with its walls, 2 for the cell); bits 4 and 5 give the column (0 for one back, 1 for one on, 2 or 3 for the same one); and bits 6 and 7 give the row in the same way.
Before After DrawView
draw-view-before draw-view-after
DrawView CF08 LD HL,$E001 Mark the columns that are outside the view as already drawn (see DrawnColumns).
CF0B LD ($BBBB),HL
CF0E LD A,($BC90) Fetch the column and the row of the player's cell.
CF11 LD L,A
CF12 LD A,($BC92)
CF15 LD H,A
CF16 CALL ConvertCell Turn them into the column and the row in the view, if the view is turned round.
CF19 PUSH HL Keep the player's cell.
CF1A LD E,$00 Start with an empty pattern of cells.
Make the pattern of the five cells next to the player's cell that are not empty.
CF1C DEC L Set bit 0 if the cell one column back and one row on is not empty.
CF1D INC H
CF1E CALL GetMapCell
CF21 JR Z,DrawView_Pattern1
CF23 SET 0,E
DrawView_Pattern1 CF25 POP HL Set bit 1 if the cell one column back is not empty.
CF26 PUSH HL
CF27 DEC L
CF28 CALL GetMapCell
CF2B JR Z,DrawView_Pattern2
CF2D SET 1,E
DrawView_Pattern2 CF2F POP HL Set bit 2 if the cell one row on is not empty.
CF30 PUSH HL
CF31 INC H
CF32 CALL GetMapCell
CF35 JR Z,DrawView_Pattern3
CF37 SET 2,E
DrawView_Pattern3 CF39 POP HL Set bit 3 if the cell one column back and one row back is not empty.
CF3A PUSH HL
CF3B DEC L
CF3C DEC H
CF3D CALL GetMapCell
CF40 JR Z,DrawView_Pattern4
CF42 SET 3,E
DrawView_Pattern4 CF44 POP HL Set bit 4 if the cell one column on and one row on is not empty.
CF45 PUSH HL
CF46 INC L
CF47 INC H
CF48 CALL GetMapCell
CF4B JR Z,DrawView_FindEntry
CF4D SET 4,E
Find the entry in the table at ViewPatterns for the pattern.
DrawView_FindEntry CF4F LD D,$00 Find the entry in the table for the pattern, and set a counter for five cells.
CF51 LD A,E
CF52 EX DE,HL
CF53 LD E,L
CF54 LD D,H
CF55 ADD HL,HL
CF56 ADD HL,HL
CF57 ADD HL,DE
CF58 LD DE,$6204
CF5B ADD HL,DE
CF5C EX DE,HL
CF5D LD B,$05
DrawView_Cell CF5F POP HL Get the player's cell back and fetch the next byte of the entry.
CF60 PUSH HL
CF61 LD A,(DE)
CF62 INC DE
CF63 BIT 5,A Keep the column as it is if bit 5 is set.
CF65 JR NZ,DrawView_Row
CF67 BIT 4,A Jump to DrawView_ColumnBack to move the column back one if bit 4 is clear.
CF69 JR Z,DrawView_ColumnBack
CF6B INC L Move the column on two...
CF6C INC L
DrawView_ColumnBack CF6D DEC L ... and back one, to give one on.
DrawView_Row CF6E BIT 7,A Keep the row as it is if bit 7 is set.
CF70 JR NZ,DrawView_Select
CF72 BIT 6,A Jump to DrawView_RowBack to move the row back one if bit 6 is clear.
CF74 JR Z,DrawView_RowBack
CF76 INC H Move the row on two...
CF77 INC H
DrawView_RowBack CF78 DEC H ... and back one, to give one on.
DrawView_Select CF79 AND $03 Keep the counter and the address of the entry, and make DrawView_Next the address to return to.
CF7B PUSH BC
CF7C PUSH DE
CF7D LD DE,$CF8D
CF80 PUSH DE
CF81 JP Z,DrawObjectsInCell Draw only the objects in the cell if bits 0 and 1 are 0.
CF84 DEC A Draw the cell with its walls if bits 0 and 1 are 1.
CF85 JP Z,DrawCellWithWalls
CF88 DEC A Draw the cell if bits 0 and 1 are 2.
CF89 JP Z,DrawCell
CF8C POP DE Throw away the address to return to.
DrawView_Next CF8D POP DE Get the address of the entry and the counter back, and loop back until all five cells have been drawn.
CF8E POP BC
CF8F DJNZ DrawView_Cell
Draw the player's cell and the three cells next to it that are nearer to the viewer, with the objects in each.
CF91 POP HL Draw the player's cell, and the objects in it.
CF92 PUSH HL
CF93 CALL DrawCellAndObjects
CF96 POP HL Draw the cell one row back, and the objects in it.
CF97 PUSH HL
CF98 DEC H
CF99 CALL DrawCellAndObjects
CF9C POP HL Draw the cell one column on, and the objects in it.
CF9D PUSH HL
CF9E INC L
CF9F CALL DrawCellAndObjects
CFA2 POP HL Move to the cell one column on and one row back, and draw it and its objects in the routine that follows.
CFA3 INC L
CFA4 DEC H
View the equivalent code in;
Prev: CEF8 Up: Map Next: CFA5