Prev: C13B Up: Map Next: C381
C15E: Draw Block
Used by the routines at DrawItems, DrawRightStrip and DrawLeftStrip.
Draws a block from the drawing variables at DrawingVariables. The three sizes at RecordDetails supply the column and row sizes, from the high nibble of each byte. The shape index comes from the object's frame, unless a record has patched DrawBlock_Index so that it loads the record's own index. The shape byte is looked up from that index, and one section is drawn for each 40 in the byte.
The flags at ObjectFlagsTable, indexed by the shape kind, choose the layout. Bit 7 clear draws the block as it is. Bits 5-6 clear mirror it, 20 draws it as it is, 40 raises it, and any other value moves the origin back by 10. Kinds 11 and 12 use a column size of one and lower the screen position by the third size. Each section is drawn by DrawBlockShape.
Input
IX The object
Copy the high nibbles of the three sizes into the drawing variables, and make the shape index.
DrawBlock C15E PUSH IX Remember the object.
C160 LD IY,$BB9F Use the drawing variables.
C164 PUSH IY Remember the drawing variables.
C166 LD A,($5CF3) Take the high nibble of the first size.
C169 SRL A
C16B RRA
C16C RRA
C16D RRA
C16E LD ($BBA5),A Keep it as both copies of the column size.
C171 LD ($BBB3),A
C174 LD A,($5CF4) Take the high nibble of the second size.
C177 RRA
C178 RRA
C179 RRA
C17A RRA
C17B LD ($BBA4),A Keep it as the row size.
C17E LD ($BBAC),A
C181 LD ($BBB2),A
C184 LD A,($C1A0) Use the patched shape index when this instruction loads one.
C187 CP $3E
C189 JR Z,DrawBlock_Index
C18B LD A,(IX+$01) Read the object's frame.
C18E LD E,A
C18F AND %00001111 Keep the frame number.
C191 LD D,A Bring bit 4 of the frame down beside the frame number.
C192 LD A,E
C193 RRA
C194 RRA
C195 RRA
C196 AND %00010000 Keep that bit.
C198 OR D Remember the shape index made from the frame.
C199 LD E,A
C19A LD ($C1FE),A
C19D ADD A,A Triple the shape index.
C19E ADD A,A
C19F SUB E
Look the shape byte up. Below 40 there is one section, below 80 there are two, and a larger byte has a third. The bytes of the further sections follow the first shape byte.
DrawBlock_Index C1A0 AND %11111111 Keep the shape index. A record replaces this so that it loads its index.
C1A2 LD HL,$BBB1 Look the shape byte up.
C1A5 LD E,A
C1A6 LD D,$00
C1A8 ADD HL,DE
C1A9 LD A,(HL)
C1AA LD B,A
C1AB PUSH AF Remember the shape byte for the later sections.
C1AC AND %00111111 Keep the shape number.
C1AE LD ($BBA3),A Store the shape number in the drawing variables.
C1B1 LD A,B One section is enough when the shape byte is below 40.
C1B2 SUB $40
C1B4 JR C,DrawBlock_Details
C1B6 INC HL Read the second shape byte.
C1B7 LD A,(HL)
C1B8 LD ($BBAA),A
C1BB INC HL Read the third shape byte.
C1BC LD A,(HL)
C1BD LD ($BBB1),A
C1C0 LD A,($5CF5) Take the high nibble of the third size.
C1C3 SRL A
C1C5 RRA
C1C6 RRA
C1C7 RRA
C1C8 LD ($BBA4),A Use it as the row size of the further sections.
C1CB LD ($BBAB),A
C1CE LD HL,($BB9F) Fetch the origin.
C1D1 LD DE,($5CF3) Fetch the first two sizes.
C1D5 LD D,$00 Add the first size to the origin.
C1D7 ADD HL,DE
C1D8 LD ($BBA6),HL
C1DB LD HL,($BBA1) Fetch the screen position.
C1DE SRL E Add half of the first size to the screen position.
C1E0 ADD HL,DE
C1E1 LD ($BBA8),HL
C1E4 LD A,B Two sections are enough when the shape byte is below 80.
C1E5 SUB $80
C1E7 JR C,DrawBlock_Details
C1E9 LD HL,($BB9F) Keep the origin for a third section.
C1EC LD ($BBAD),HL
C1EF LD HL,($BBA1) Fetch the screen position again.
C1F2 LD DE,($5CF5) Subtract the third size from the screen position.
C1F6 LD D,$00
C1F8 SBC HL,DE
C1FA LD ($BBAF),HL
Kinds 11 and 12 are the special blocks. The byte loaded here is patched with the record's kind.
DrawBlock_Details C1FD LD E,$00 Take the shape kind.
C1FF LD A,E Use the special sizes for kind 12.
C200 CP $12
C202 JR Z,DrawBlock_Special
C204 CP $11 Use the special sizes for kind 11 too.
C206 JR NZ,DrawBlock_Flags
DrawBlock_Special C208 LD HL,($BBA1) Lower the screen position by the third size.
C20B LD A,($5CF5)
C20E LD C,A
C20F LD B,$00
C211 AND A
C212 SBC HL,BC
C214 LD ($BBA1),HL
C217 LD ($BBA8),HL
C21A LD A,$01 Use a column size of one.
C21C LD ($BBA5),A
C21F LD ($BBAC),A
The object's flags choose a mirrored block, a raised block, or a block shifted back by 10.
DrawBlock_Flags C222 LD D,$00 Look up the flags for this kind of object.
C224 LD HL,$D7B3
C227 ADD HL,DE
C228 BIT 7,(HL) Draw the block as it is when the top flag is clear.
C22A JP Z,DrawBlock_Shape
C22D LD A,(HL) Read the flags.
C22E AND %01100000 Keep the layout in bits 5-6.
C230 JR Z,DrawBlock_Mirror Mirror the block when those bits are clear.
C232 CP $20 Draw the block as it is when the layout is 20.
C234 JP Z,DrawBlock_Shape
C237 CP $40 Raise the block when the layout is 40.
C239 JP Z,DrawBlock_Raised
C23C LD A,($5CF3) Take the high nibble of the first size.
C23F SRL A
C241 RRA
C242 RRA
C243 RRA
C244 LD ($BBAB),A Use it as the extra row size.
C247 LD HL,($BBA6) Move the adjusted origin back by 10.
C24A LD DE,$FFF0
C24D ADD HL,DE
C24E LD ($BBA6),HL
C251 JP DrawBlock_Shape Draw the shape.
DrawBlock_Mirror C254 LD HL,($BB9F) Swap the origin with the adjusted origin.
C257 LD DE,($BBA6)
C25B LD ($BBA6),HL
C25E LD ($BB9F),DE
C262 LD HL,($BBA1) Swap the screen position with its adjusted copy.
C265 LD DE,($BBA8)
C269 LD ($BBA8),HL
C26C LD ($BBA1),DE
C270 LD HL,($BBA3) Swap the shape bytes with the extra shape bytes.
C273 LD DE,($BBAA)
C277 LD ($BBAA),HL
C27A LD ($BBA3),DE
C27E LD A,($BBA5) Swap the two column sizes.
C281 LD E,A
C282 LD A,($BBAC)
C285 LD ($BBA5),A
C288 LD A,E
C289 LD ($BBAC),A
C28C LD A,($5CF4) Take the high nibble of the second size.
C28F SRL A
C291 RRA
C292 RRA
C293 RRA
C294 LD ($BBAB),A Use it as the extra row size.
C297 LD A,($5CF3) Take the high nibble of the first size.
C29A SRL A
C29C RRA
C29D RRA
C29E RRA
C29F LD ($BBAC),A Use it as the other column size.
C2A2 LD A,($5CF4) Move the origin on by the second size less 10.
C2A5 SUB $10
C2A7 LD E,A
C2A8 LD HL,($BB9F)
C2AB LD D,$00
C2AD ADD HL,DE
C2AE LD ($BB9F),HL
C2B1 SRL E Move the screen position back by half of that step.
C2B3 LD HL,($BBA1)
C2B6 SBC HL,DE
C2B8 LD ($BBA1),HL
C2BB JR DrawBlock_Shape Draw the shape.
DrawBlock_Raised C2BD LD A,($5CF3) Move the origin on by the first size less 10.
C2C0 SUB $10
C2C2 LD E,A
C2C3 LD HL,($BB9F)
C2C6 LD D,$00
C2C8 ADD HL,DE
C2C9 LD ($BB9F),HL
C2CC SRL E Move the screen position on by half of that, and keep the old one.
C2CE LD HL,($BBA1)
C2D1 PUSH HL
C2D2 ADD HL,DE
C2D3 LD ($BBA1),HL
C2D6 POP HL
C2D7 LD ($BBAF),HL
C2DA JR DrawBlock_Shape Draw the shape.
DrawBlock_Next C2DC PUSH IY Remember the drawing variables.
C2DE PUSH AF Remember the shape byte.
Patch the draw routines from the block shape table, then draw the section. A shape number of 11 takes its row size from the third size.
DrawBlock_Shape C2DF LD A,(IY+$04) Read the shape number.
C2E2 LD E,A
C2E3 CP $11 Replace the sizes when the shape number is 11.
C2E5 JR NZ,DrawBlock_Count
C2E7 LD A,($5CF5) Take the high nibble of the third size.
C2EA SRL A
C2EC RRA
C2ED RRA
C2EE RRA
C2EF LD ($BBA4),A Use it as the row size.
C2F2 LD A,$01 Use a column size of one.
C2F4 LD ($BBA5),A
DrawBlock_Count C2F7 LD D,$00 Look the shape up in the block shape table.
C2F9 LD C,E
C2FA LD HL,$B913
C2FD ADD HL,DE
C2FE LD A,(HL)
C2FF AND %01111111 Keep the row count.
C301 LD ($C5E9),A Give the row count to the row routines.
C304 LD ($C739),A
C307 LD A,(HL) Read the same table byte again.
C308 AND %10000000 Keep its top bit.
C30A LD ($C5F3),A Give that bit to the row routines.
C30D LD ($C742),A
C310 LD L,(IY+$00) Fetch the origin and the screen position.
C313 LD H,(IY+$01)
C316 LD E,(IY+$02)
C319 LD D,(IY+$03)
C31C LD A,(IY+$05) Give the row size to the shape routine.
C31F LD ($C3D5),A
C322 LD B,(IY+$06) Fetch the column size.
C325 LD A,C Give the shape number to the shape routine.
C326 LD ($C3BE),A
C329 ADD A,A Multiply the shape number by seven.
C32A ADD A,A
C32B ADD A,A
C32C SUB C
C32D EXX Find this shape's seven-byte record.
C32E LD E,A
C32F LD D,$00
C331 LD IY,$B92F
C335 ADD IY,DE
C337 EXX
C338 LD A,($C1A0) Skip the edge bytes when the shape index was not patched.
C33B CP $E6
C33D JR Z,DrawBlock_Edges
C33F LD A,(IY+$05) Give the shape's first edge, less one, to the overlap test.
C342 DEC A
C343 LD ($C67C),A
C346 LD A,(IY+$06) Give the shape's other edge to the overlap test.
C349 LD ($C688),A
C34C LD ($C69A),A
C34F LD ($C6B5),A
DrawBlock_Edges C352 LD A,(IY+$06) Give the row offset to the row test.
C355 ADD A,$06
C357 LD ($C72A),A
C35A LD A,(IY+$00) Read the shape's position byte.
C35D BIT 7,A Add the offset when that byte is positive.
C35F JR Z,DrawBlock_Offset
C361 ADD A,E Keep a negative position that overflowed.
C362 JR C,DrawBlock_Section
C364 DEC D Sign-extend that negative position.
C365 JR DrawBlock_Section
DrawBlock_Offset C367 ADD A,E Add the offset to a positive position.
C368 LD E,A
C369 JR NC,DrawBlock_Section
C36B INC D Count the carry in the high byte.
DrawBlock_Section C36C CALL DrawBlockShape Draw this section of the block.
C36F POP AF Finish when the shape byte has no further section.
C370 POP IY
C372 SUB $40
C374 JR C,DrawBlock_Return
C376 LD DE,$0007 Step on seven bytes and draw the next section.
C379 ADD IY,DE
C37B JP DrawBlock_Next
DrawBlock_Return C37E POP IX Restore the object.
C380 RET Return.
Prev: C13B Up: Map Next: C381