Prev: C629 Up: Map Next: C6C5
C646: Draw Overlapped Block
Draws a block in the parts left uncovered by entities drawn earlier. Those entities are in the table at B1B3, four bytes each, and the count is patched into this routine. Each item that covers the row leaves a span, which DrawBlockSpan draws.
The two limits of the row are remembered, and the count of overlapping items is patched into the loop.
DrawOverlappedBlock C646 LD ($C657),HL Remember the first limit.
C649 LD ($C680),DE Remember the second limit.
C64D EXX Use the limits' register set.
C64E LD IX,$B1B3 Start at the first overlapping item.
C652 LD B,$00 The number of items is patched.
C654 AND A Clear the carry for the comparison.
DrawOverlappedBlock_Loop C655 PUSH BC Remember how many items remain.
C656 LD HL,$0000 Read the patched first limit.
C659 LD A,L Take its low byte.
C65A AND %11111000 Use the patched mask.
C65C OR %00000000 Apply the patched bits.
C65E LD L,A Remember the masked limit.
C65F LD ($C7AD),A
C662 LD D,$80 Take the item's first byte, with the patched high byte.
C664 LD E,(IX+$00)
C667 SBC HL,DE Subtract it from the limit.
C669 JR C,DrawOverlappedBlock_Above The item starts above the row.
C66B LD A,H The item is a whole byte or more past the row.
C66C AND A
C66D JR NZ,DrawOverlappedBlock_Next
C66F LD A,L The gap is at least the item's next byte.
C670 SUB (IX+$02)
C673 JR NC,DrawOverlappedBlock_Next
C675 JR DrawOverlappedBlock_Second Join the second limit.
DrawOverlappedBlock_Above C677 INC H The other side is a whole byte or more away.
C678 JR NZ,DrawOverlappedBlock_Next
C67A LD A,L The item's extra size does not reach the row.
C67B ADD A,$00
C67D JR NC,DrawOverlappedBlock_Next
DrawOverlappedBlock_Second C67F LD HL,$0000 Read the patched second limit.
C682 SLA H The high byte has to be clear.
C684 JR NZ,DrawOverlappedBlock_Next
C686 LD A,L The low byte has to reach the patched edge.
C687 SUB $00
C689 JR C,DrawOverlappedBlock_Height
C68B INC A Shift that distance up.
C68C RLA
C68D JR C,DrawOverlappedBlock_Next A distance that overflowed does not cover the row.
DrawOverlappedBlock_Height C68F LD B,(IY+$06) Read the shape's position byte.
C692 LD A,L Subtract the item's byte from the distance.
C693 SUB (IX+$01)
C696 JR C,DrawOverlappedBlock_Far The item covers the far side of the row.
C698 LD H,A The remainder is the height so far.
C699 SUB $00 A remainder past the patched edge does not cover the row.
C69B JR NC,DrawOverlappedBlock_Next
C69D LD L,(IX+$01) The height is the item's byte, negated.
C6A0 NEG
C6A2 LD B,A
C6A3 CP (IX+$03) Use the smaller of that height and the item's other byte.
C6A6 JR C,DrawOverlappedBlock_Draw
C6A8 LD B,(IX+$03) Use the item's byte when it is the smaller.
C6AB JR DrawOverlappedBlock_Draw
DrawOverlappedBlock_Far C6AD ADD A,(IX+$03) Add the item's byte to the distance.
C6B0 JR NC,DrawOverlappedBlock_Next The sum has to reach past zero.
C6B2 JR Z,DrawOverlappedBlock_Next
C6B4 CP $00 Use the patched edge when the sum is below it.
C6B6 JR NC,DrawOverlappedBlock_Draw
C6B8 LD B,A The height is that sum.
DrawOverlappedBlock_Draw C6B9 CALL DrawBlockSpan Draw the span that this item leaves.
DrawOverlappedBlock_Next C6BC LD BC,$0004 Move on to the next item.
C6BF ADD IX,BC
C6C1 POP BC Bring the count back.
C6C2 DJNZ DrawOverlappedBlock_Loop Repeat for the remaining items.
C6C4 RET Return.
Prev: C629 Up: Map Next: C6C5