Prev: 52984 Up: Map Next: 53157
53000: 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 53000 LD HL,57345 Mark the columns that are outside the view as already drawn (see DrawnColumns).
53003 LD (48059),HL
53006 LD A,(48272) Fetch the column and the row of the player's cell.
53009 LD L,A
53010 LD A,(48274)
53013 LD H,A
53014 CALL ConvertCell Turn them into the column and the row in the view, if the view is turned round.
53017 PUSH HL Keep the player's cell.
53018 LD E,0 Start with an empty pattern of cells.
Make the pattern of the five cells next to the player's cell that are not empty.
53020 DEC L Set bit 0 if the cell one column back and one row on is not empty.
53021 INC H
53022 CALL GetMapCell
53025 JR Z,DrawView_Pattern1
53027 SET 0,E
DrawView_Pattern1 53029 POP HL Set bit 1 if the cell one column back is not empty.
53030 PUSH HL
53031 DEC L
53032 CALL GetMapCell
53035 JR Z,DrawView_Pattern2
53037 SET 1,E
DrawView_Pattern2 53039 POP HL Set bit 2 if the cell one row on is not empty.
53040 PUSH HL
53041 INC H
53042 CALL GetMapCell
53045 JR Z,DrawView_Pattern3
53047 SET 2,E
DrawView_Pattern3 53049 POP HL Set bit 3 if the cell one column back and one row back is not empty.
53050 PUSH HL
53051 DEC L
53052 DEC H
53053 CALL GetMapCell
53056 JR Z,DrawView_Pattern4
53058 SET 3,E
DrawView_Pattern4 53060 POP HL Set bit 4 if the cell one column on and one row on is not empty.
53061 PUSH HL
53062 INC L
53063 INC H
53064 CALL GetMapCell
53067 JR Z,DrawView_FindEntry
53069 SET 4,E
Find the entry in the table at ViewPatterns for the pattern.
DrawView_FindEntry 53071 LD D,0 Find the entry in the table for the pattern, and set a counter for five cells.
53073 LD A,E
53074 EX DE,HL
53075 LD E,L
53076 LD D,H
53077 ADD HL,HL
53078 ADD HL,HL
53079 ADD HL,DE
53080 LD DE,25092
53083 ADD HL,DE
53084 EX DE,HL
53085 LD B,5
DrawView_Cell 53087 POP HL Get the player's cell back and fetch the next byte of the entry.
53088 PUSH HL
53089 LD A,(DE)
53090 INC DE
53091 BIT 5,A Keep the column as it is if bit 5 is set.
53093 JR NZ,DrawView_Row
53095 BIT 4,A Jump to DrawView_ColumnBack to move the column back one if bit 4 is clear.
53097 JR Z,DrawView_ColumnBack
53099 INC L Move the column on two...
53100 INC L
DrawView_ColumnBack 53101 DEC L ... and back one, to give one on.
DrawView_Row 53102 BIT 7,A Keep the row as it is if bit 7 is set.
53104 JR NZ,DrawView_Select
53106 BIT 6,A Jump to DrawView_RowBack to move the row back one if bit 6 is clear.
53108 JR Z,DrawView_RowBack
53110 INC H Move the row on two...
53111 INC H
DrawView_RowBack 53112 DEC H ... and back one, to give one on.
DrawView_Select 53113 AND 3 Keep the counter and the address of the entry, and make DrawView_Next the address to return to.
53115 PUSH BC
53116 PUSH DE
53117 LD DE,53133
53120 PUSH DE
53121 JP Z,DrawObjectsInCell Draw only the objects in the cell if bits 0 and 1 are 0.
53124 DEC A Draw the cell with its walls if bits 0 and 1 are 1.
53125 JP Z,DrawCellWithWalls
53128 DEC A Draw the cell if bits 0 and 1 are 2.
53129 JP Z,DrawCell
53132 POP DE Throw away the address to return to.
DrawView_Next 53133 POP DE Get the address of the entry and the counter back, and loop back until all five cells have been drawn.
53134 POP BC
53135 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.
53137 POP HL Draw the player's cell, and the objects in it.
53138 PUSH HL
53139 CALL DrawCellAndObjects
53142 POP HL Draw the cell one row back, and the objects in it.
53143 PUSH HL
53144 DEC H
53145 CALL DrawCellAndObjects
53148 POP HL Draw the cell one column on, and the objects in it.
53149 PUSH HL
53150 INC L
53151 CALL DrawCellAndObjects
53154 POP HL Move to the cell one column on and one row back, and draw it and its objects in the routine that follows.
53155 INC L
53156 DEC H
View the equivalent code in;
Prev: 52984 Up: Map Next: 53157