Prev: C0D3 Up: Map Next: C19F
C0F8: Draw Town
Used by the routine at InitialiseGame.
Called every frame. In the town, it draws the walls and the objects of the cells which are around the sheriff, in an order which is chosen so that the cells nearer the viewer are drawn after the ones behind them. The order depends on which of five of the cells next to the sheriff's cell have buildings in them, and is taken from five-byte entries in a table at DrawingOrders. Each of the five bytes holds the offset of a cell from the sheriff's cell (bits 4 and 5 for the offset in the column, bits 6 and 7 for the offset in the row) and a kind of drawing to do in it (bits 0 and 1): 00 draws the objects in the cell, 01 draws the walls and 02 draws the edges. The sheriff's cell and three of its neighbours are drawn last. The town is a map of sixteen cells by sixteen, and when the view is rotated the cell numbers are turned round.
town
Return if this is not the town.
DrawTown C0F8 LD A,($A267) Fetch TownOffset.
C0FB AND A Return if it is not.
C0FC RET Z
The walls are not drawn on columns of the screen which already have a wall in them. The sixteen flags at ColumnFlags cover columns of sixteen pixels. The left sixteen pixels and the right forty eight sit outside the play area, so they are marked as done.
C0FD LD HL,$E001 Set ColumnFlags.
C100 LD ($A248),HL
Fetch the sheriff's cell.
C103 LD A,($A27F) Fetch the horizontal cell of the sheriff from A27F and keep it in L.
C106 LD L,A
C107 LD A,($A281) Fetch the vertical cell of the sheriff from A281 and keep it in H.
C10A LD H,A
Turn the cell round if the view is rotated.
C10B CALL ConvertCell Call ConvertCell.
C10E PUSH HL Stash the cell of the sheriff on the stack.
C10F LD E,$00 Clear the flags for the neighbouring cells.
Find out which of five neighbouring cells have something in them. Taking the column and row of the sheriff's cell as x and y, they are the cells (x-1, y+1), (x-1, y), (x, y+1), (x-1, y-1) and (x+1, y+1).
C111 DEC L Take one off the column...
C112 INC H ...and add one to the row.
Find the contents of the cell.
C113 CALL GetMapCell Call GetMapCell.
C116 JR Z,DrawTown_TestSecondCell Jump to DrawTown_TestSecondCell if it is empty.
C118 SET 0,E Set the bit for the first cell.
Test the cell at (x-1, y).
DrawTown_TestSecondCell C11A POP HL Restore the cell of the sheriff from the stack.
C11B PUSH HL Stash the cell of the sheriff on the stack.
C11C DEC L Take one off the column.
Find the contents of the cell.
C11D CALL GetMapCell Call GetMapCell.
C120 JR Z,DrawTown_TestThirdCell Jump to DrawTown_TestThirdCell if it is empty.
C122 SET 1,E Set the bit for the second cell.
Test the cell at (x, y+1).
DrawTown_TestThirdCell C124 POP HL Restore the cell of the sheriff from the stack.
C125 PUSH HL Stash the cell of the sheriff on the stack.
C126 INC H Add one to the row.
Find the contents of the cell.
C127 CALL GetMapCell Call GetMapCell.
C12A JR Z,DrawTown_TestFourthCell Jump to DrawTown_TestFourthCell if it is empty.
C12C SET 2,E Set the bit for the third cell.
Test the cell at (x-1, y-1).
DrawTown_TestFourthCell C12E POP HL Restore the cell of the sheriff from the stack.
C12F PUSH HL Stash the cell of the sheriff on the stack.
C130 DEC L Take one off the column...
C131 DEC H ...and take one off the row.
Find the contents of the cell.
C132 CALL GetMapCell Call GetMapCell.
C135 JR Z,DrawTown_TestFifthCell Jump to DrawTown_TestFifthCell if it is empty.
C137 SET 3,E Set the bit for the fourth cell.
Test the cell at (x+1, y+1).
DrawTown_TestFifthCell C139 POP HL Restore the cell of the sheriff from the stack.
C13A PUSH HL Stash the cell of the sheriff on the stack.
C13B INC L Add one to the column...
C13C INC H ...and add one to the row.
Find the contents of the cell.
C13D CALL GetMapCell Call GetMapCell.
C140 JR Z,DrawTown_FindEntry Jump to DrawTown_FindEntry if it is empty.
C142 SET 4,E Set the bit for the fifth cell.
Point at the entry in the table of five bytes for the cells which have been found.
DrawTown_FindEntry C144 LD D,$00 Clear D.
C146 LD A,E Fetch the flags for the cells.
C147 EX DE,HL Move the flags into HL.
C148 LD E,L Copy them into DE.
C149 LD D,H
C14A ADD HL,HL Multiply them by four.
C14B ADD HL,HL
C14C ADD HL,DE Add them again, to make five times.
C14D LD DE,$60B1 Point DE at DrawingOrders.
C150 ADD HL,DE Point HL at the entry.
C151 EX DE,HL Keep the address of the entry in DE.
C152 LD B,$05 Set the number of bytes to five.
Draw the next cell from the entry.
DrawTown_NextCell C154 POP HL Restore the cell of the sheriff from the stack.
C155 PUSH HL Stash the cell of the sheriff on the stack.
C156 LD A,(DE) Fetch the byte from the entry.
C157 INC DE Move on to the next byte.
C158 BIT 5,A Jump to DrawTown_TestRow if the cell is in the same column as the sheriff.
C15A JR NZ,DrawTown_TestRow
C15C BIT 4,A Jump to DrawTown_ColumnOffset if this is not the next column.
C15E JR Z,DrawTown_ColumnOffset
C160 INC L Add two to the column.
C161 INC L
DrawTown_ColumnOffset C162 DEC L Take one off the column, to make it one lower or one higher.
DrawTown_TestRow C163 BIT 7,A Jump to DrawTown_KeepKind if the cell is in the same row as the sheriff.
C165 JR NZ,DrawTown_KeepKind
C167 BIT 6,A Jump to DrawTown_RowOffset if this is not the next row.
C169 JR Z,DrawTown_RowOffset
C16B INC H Add two to the row.
C16C INC H
DrawTown_RowOffset C16D DEC H Take one off the row, to make it one lower or one higher.
Choose what to draw in the cell.
DrawTown_KeepKind C16E AND %00000011 Keep the kind of drawing.
C170 PUSH BC Stash the number of bytes left and the address in the entry on the stack.
C171 PUSH DE
Make the draw routine return to DrawTown_AfterDraw.
C172 LD DE,$C182 Point DE at DrawTown_AfterDraw.
C175 PUSH DE Stash it on the stack.
Draw the objects in the cell if the kind is zero.
C176 JP Z,DrawCellObjects Jump to DrawCellObjects if it is.
C179 DEC A Take one off the kind.
Draw the walls of the cell if the kind is one.
C17A JP Z,DrawCellWithWalls Jump to DrawCellWithWalls if it is.
C17D DEC A Take one off the kind.
Draw the edges of the cell if the kind is two.
C17E JP Z,DrawCell Jump to DrawCell if it is.
The kind is three, which is nothing.
C181 POP DE Throw away the return address from the stack.
DrawTown_AfterDraw C182 POP DE Restore the address in the entry and the number of bytes left from the stack.
C183 POP BC
Go back for the next byte of the entry.
C184 DJNZ DrawTown_NextCell Jump to DrawTown_NextCell if there are any left.
Draw the sheriff's cell and the three cells after it: the cells with the row one lower, the column one higher, and both of those.
C186 POP HL Restore the cell of the sheriff from the stack.
C187 PUSH HL Stash the cell of the sheriff on the stack.
Draw the edges and the objects in the cell.
C188 CALL DrawCellAndObjects Call DrawCellAndObjects.
C18B POP HL Restore the cell of the sheriff from the stack.
C18C PUSH HL Stash the cell of the sheriff on the stack.
C18D DEC H Take one off the row.
Draw the edges and the objects in the cell.
C18E CALL DrawCellAndObjects Call DrawCellAndObjects.
C191 POP HL Restore the cell of the sheriff from the stack.
C192 PUSH HL Stash the cell of the sheriff on the stack.
C193 INC L Add one to the column.
Draw the edges and the objects in the cell.
C194 CALL DrawCellAndObjects Call DrawCellAndObjects.
C197 POP HL Restore the cell of the sheriff from the stack.
C198 INC L Add one to the column...
C199 DEC H ...and take one off the row.
The last cell goes on into the routine, which returns to the caller.
DrawCellAndObjects C19A PUSH HL Stash the cell on the stack.
Draw the edges of the cell.
C19B CALL DrawCell Call DrawCell.
C19E POP HL Restore the cell from the stack.
Continue on to DrawCellObjects.
View the equivalent code in;
Prev: C0D3 Up: Map Next: C19F