Prev: 49467 Up: Map Next: 50049
49502: 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 64 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, 32 draws it as it is, 64 raises it, and any other value moves the origin back by 16. Kinds 17 and 18 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 49502 PUSH IX Remember the object.
49504 LD IY,48031 Use the drawing variables.
49508 PUSH IY Remember the drawing variables.
49510 LD A,(23795) Take the high nibble of the first size.
49513 SRL A
49515 RRA
49516 RRA
49517 RRA
49518 LD (48037),A Keep it as both copies of the column size.
49521 LD (48051),A
49524 LD A,(23796) Take the high nibble of the second size.
49527 RRA
49528 RRA
49529 RRA
49530 RRA
49531 LD (48036),A Keep it as the row size.
49534 LD (48044),A
49537 LD (48050),A
49540 LD A,(49568) Use the patched shape index when this instruction loads one.
49543 CP 62
49545 JR Z,DrawBlock_Index
49547 LD A,(IX+1) Read the object's frame.
49550 LD E,A
49551 AND %00001111 Keep the frame number.
49553 LD D,A Bring bit 4 of the frame down beside the frame number.
49554 LD A,E
49555 RRA
49556 RRA
49557 RRA
49558 AND %00010000 Keep that bit.
49560 OR D Remember the shape index made from the frame.
49561 LD E,A
49562 LD (49662),A
49565 ADD A,A Triple the shape index.
49566 ADD A,A
49567 SUB E
Look the shape byte up. Below 64 there is one section, below 128 there are two, and a larger byte has a third. The bytes of the further sections follow the first shape byte.
DrawBlock_Index 49568 AND %11111111 Keep the shape index. A record replaces this so that it loads its index.
49570 LD HL,48049 Look the shape byte up.
49573 LD E,A
49574 LD D,0
49576 ADD HL,DE
49577 LD A,(HL)
49578 LD B,A
49579 PUSH AF Remember the shape byte for the later sections.
49580 AND %00111111 Keep the shape number.
49582 LD (48035),A Store the shape number in the drawing variables.
49585 LD A,B One section is enough when the shape byte is below 64.
49586 SUB 64
49588 JR C,DrawBlock_Details
49590 INC HL Read the second shape byte.
49591 LD A,(HL)
49592 LD (48042),A
49595 INC HL Read the third shape byte.
49596 LD A,(HL)
49597 LD (48049),A
49600 LD A,(23797) Take the high nibble of the third size.
49603 SRL A
49605 RRA
49606 RRA
49607 RRA
49608 LD (48036),A Use it as the row size of the further sections.
49611 LD (48043),A
49614 LD HL,(48031) Fetch the origin.
49617 LD DE,(23795) Fetch the first two sizes.
49621 LD D,0 Add the first size to the origin.
49623 ADD HL,DE
49624 LD (48038),HL
49627 LD HL,(48033) Fetch the screen position.
49630 SRL E Add half of the first size to the screen position.
49632 ADD HL,DE
49633 LD (48040),HL
49636 LD A,B Two sections are enough when the shape byte is below 128.
49637 SUB 128
49639 JR C,DrawBlock_Details
49641 LD HL,(48031) Keep the origin for a third section.
49644 LD (48045),HL
49647 LD HL,(48033) Fetch the screen position again.
49650 LD DE,(23797) Subtract the third size from the screen position.
49654 LD D,0
49656 SBC HL,DE
49658 LD (48047),HL
Kinds 17 and 18 are the special blocks. The byte loaded here is patched with the record's kind.
DrawBlock_Details 49661 LD E,0 Take the shape kind.
49663 LD A,E Use the special sizes for kind 18.
49664 CP 18
49666 JR Z,DrawBlock_Special
49668 CP 17 Use the special sizes for kind 17 too.
49670 JR NZ,DrawBlock_Flags
DrawBlock_Special 49672 LD HL,(48033) Lower the screen position by the third size.
49675 LD A,(23797)
49678 LD C,A
49679 LD B,0
49681 AND A
49682 SBC HL,BC
49684 LD (48033),HL
49687 LD (48040),HL
49690 LD A,1 Use a column size of one.
49692 LD (48037),A
49695 LD (48044),A
The object's flags choose a mirrored block, a raised block, or a block shifted back by 16.
DrawBlock_Flags 49698 LD D,0 Look up the flags for this kind of object.
49700 LD HL,55219
49703 ADD HL,DE
49704 BIT 7,(HL) Draw the block as it is when the top flag is clear.
49706 JP Z,DrawBlock_Shape
49709 LD A,(HL) Read the flags.
49710 AND %01100000 Keep the layout in bits 5-6.
49712 JR Z,DrawBlock_Mirror Mirror the block when those bits are clear.
49714 CP 32 Draw the block as it is when the layout is 32.
49716 JP Z,DrawBlock_Shape
49719 CP 64 Raise the block when the layout is 64.
49721 JP Z,DrawBlock_Raised
49724 LD A,(23795) Take the high nibble of the first size.
49727 SRL A
49729 RRA
49730 RRA
49731 RRA
49732 LD (48043),A Use it as the extra row size.
49735 LD HL,(48038) Move the adjusted origin back by 16.
49738 LD DE,65520
49741 ADD HL,DE
49742 LD (48038),HL
49745 JP DrawBlock_Shape Draw the shape.
DrawBlock_Mirror 49748 LD HL,(48031) Swap the origin with the adjusted origin.
49751 LD DE,(48038)
49755 LD (48038),HL
49758 LD (48031),DE
49762 LD HL,(48033) Swap the screen position with its adjusted copy.
49765 LD DE,(48040)
49769 LD (48040),HL
49772 LD (48033),DE
49776 LD HL,(48035) Swap the shape bytes with the extra shape bytes.
49779 LD DE,(48042)
49783 LD (48042),HL
49786 LD (48035),DE
49790 LD A,(48037) Swap the two column sizes.
49793 LD E,A
49794 LD A,(48044)
49797 LD (48037),A
49800 LD A,E
49801 LD (48044),A
49804 LD A,(23796) Take the high nibble of the second size.
49807 SRL A
49809 RRA
49810 RRA
49811 RRA
49812 LD (48043),A Use it as the extra row size.
49815 LD A,(23795) Take the high nibble of the first size.
49818 SRL A
49820 RRA
49821 RRA
49822 RRA
49823 LD (48044),A Use it as the other column size.
49826 LD A,(23796) Move the origin on by the second size less 16.
49829 SUB 16
49831 LD E,A
49832 LD HL,(48031)
49835 LD D,0
49837 ADD HL,DE
49838 LD (48031),HL
49841 SRL E Move the screen position back by half of that step.
49843 LD HL,(48033)
49846 SBC HL,DE
49848 LD (48033),HL
49851 JR DrawBlock_Shape Draw the shape.
DrawBlock_Raised 49853 LD A,(23795) Move the origin on by the first size less 16.
49856 SUB 16
49858 LD E,A
49859 LD HL,(48031)
49862 LD D,0
49864 ADD HL,DE
49865 LD (48031),HL
49868 SRL E Move the screen position on by half of that, and keep the old one.
49870 LD HL,(48033)
49873 PUSH HL
49874 ADD HL,DE
49875 LD (48033),HL
49878 POP HL
49879 LD (48047),HL
49882 JR DrawBlock_Shape Draw the shape.
DrawBlock_Next 49884 PUSH IY Remember the drawing variables.
49886 PUSH AF Remember the shape byte.
Patch the draw routines from the block shape table, then draw the section. A shape number of 17 takes its row size from the third size.
DrawBlock_Shape 49887 LD A,(IY+4) Read the shape number.
49890 LD E,A
49891 CP 17 Replace the sizes when the shape number is 17.
49893 JR NZ,DrawBlock_Count
49895 LD A,(23797) Take the high nibble of the third size.
49898 SRL A
49900 RRA
49901 RRA
49902 RRA
49903 LD (48036),A Use it as the row size.
49906 LD A,1 Use a column size of one.
49908 LD (48037),A
DrawBlock_Count 49911 LD D,0 Look the shape up in the block shape table.
49913 LD C,E
49914 LD HL,47379
49917 ADD HL,DE
49918 LD A,(HL)
49919 AND %01111111 Keep the row count.
49921 LD (50665),A Give the row count to the row routines.
49924 LD (51001),A
49927 LD A,(HL) Read the same table byte again.
49928 AND %10000000 Keep its top bit.
49930 LD (50675),A Give that bit to the row routines.
49933 LD (51010),A
49936 LD L,(IY+0) Fetch the origin and the screen position.
49939 LD H,(IY+1)
49942 LD E,(IY+2)
49945 LD D,(IY+3)
49948 LD A,(IY+5) Give the row size to the shape routine.
49951 LD (50133),A
49954 LD B,(IY+6) Fetch the column size.
49957 LD A,C Give the shape number to the shape routine.
49958 LD (50110),A
49961 ADD A,A Multiply the shape number by seven.
49962 ADD A,A
49963 ADD A,A
49964 SUB C
49965 EXX Find this shape's seven-byte record.
49966 LD E,A
49967 LD D,0
49969 LD IY,47407
49973 ADD IY,DE
49975 EXX
49976 LD A,(49568) Skip the edge bytes when the shape index was not patched.
49979 CP 230
49981 JR Z,DrawBlock_Edges
49983 LD A,(IY+5) Give the shape's first edge, less one, to the overlap test.
49986 DEC A
49987 LD (50812),A
49990 LD A,(IY+6) Give the shape's other edge to the overlap test.
49993 LD (50824),A
49996 LD (50842),A
49999 LD (50869),A
DrawBlock_Edges 50002 LD A,(IY+6) Give the row offset to the row test.
50005 ADD A,6
50007 LD (50986),A
50010 LD A,(IY+0) Read the shape's position byte.
50013 BIT 7,A Add the offset when that byte is positive.
50015 JR Z,DrawBlock_Offset
50017 ADD A,E Keep a negative position that overflowed.
50018 JR C,DrawBlock_Section
50020 DEC D Sign-extend that negative position.
50021 JR DrawBlock_Section
DrawBlock_Offset 50023 ADD A,E Add the offset to a positive position.
50024 LD E,A
50025 JR NC,DrawBlock_Section
50027 INC D Count the carry in the high byte.
DrawBlock_Section 50028 CALL DrawBlockShape Draw this section of the block.
50031 POP AF Finish when the shape byte has no further section.
50032 POP IY
50034 SUB 64
50036 JR C,DrawBlock_Return
50038 LD DE,7 Step on seven bytes and draw the next section.
50041 ADD IY,DE
50043 JP DrawBlock_Next
DrawBlock_Return 50046 POP IX Restore the object.
50048 RET Return.
Prev: 49467 Up: Map Next: 50049