Prev: D630 Up: Map Next: D794
D637: Draw Entity Sprite
Draws or erases an entity's sprite on the display. Draw_Entity_Sprite sets draw mode so the entity colour is written to the attribute area. Erase_Entity_Sprite sets erase mode and skips the attribute write. Both paths enter Draw_Entity_Sprite_Render, which reads the entity type to look up sprite data from Sprite_Pixel_Data_Table, computes the screen position from the Y and X bytes, then XOR-blends twelve pixel rows of sprite data onto the display.
Input
HL Entity record pointer
Draw_Entity_Sprite D637 EXX Set draw mode (attribute write enabled).
D638 LD D,$01
D63A EXX
This entry point is used by the routine at Erase_Entity_Sprite.
Draw_Entity_Sprite_Render D63B LD B,H Copy the entity record pointer to BC.
D63C LD C,L
D63D LD E,(HL) Look up the sprite data address for this entity type.
D63E SLA E
D640 LD D,$00
D642 LD HL,$C60C
D645 ADD HL,DE
D646 LD E,(HL)
D647 INC HL
D648 LD D,(HL)
D649 LD H,B Copy the entity record pointer from BC.
D64A LD L,C
D64B INC HL Read the entity's Y position.
D64C LD B,$46
D64E LD C,(HL)
D64F INC HL
D650 SLA C Double the Y position to form the pixel row address.
D652 RL B
D654 PUSH BC Stash the pixel row address on the stack.
D655 LD A,(HL) Read the X position and extract the byte column and bit offset.
D656 AND A
D657 LD HL,$0000
D65A RRA
D65B RR L
D65D RRA
D65E RR L
D660 RRA
D661 RR L
D663 EXX Save the pixel bit offset in the shadow register.
D664 LD C,A
D665 EXX
D666 LD A,L Compute the sprite pixel data address and add the column offset.
D667 RRCA
D668 LD L,A
D669 RRCA
D66A ADD A,L
D66B LD L,A
D66C ADD HL,DE
D66D LD B,H Copy the sprite data pointer to BC.
D66E LD C,L
D66F POP HL Restore the pixel row address from the stack.
D670 EXX Read the pixel bit offset from the shadow register.
D671 LD A,C
D672 EXX
Render the sprite row by row. Each row XOR-blends two bytes of pixel data onto the display. After every seventh row the entity's colour is written to the screen attribute cells.
Draw_Entity_Sprite_Row1 D673 ADD A,(HL) Blit the first sprite row onto the display.
D674 LD E,A
D675 INC HL
D676 LD D,(HL)
D677 INC HL
D678 LD A,(BC)
D679 EX DE,HL
D67A XOR (HL)
D67B LD (HL),A
D67C INC BC
D67D INC HL
D67E LD A,(BC)
D67F INC BC
D680 XOR (HL)
D681 LD (HL),A
D682 EXX Jump to Draw_Entity_Sprite_Row2 if in erase mode (skip the attribute write).
D683 LD A,D
D684 AND A
D685 EXX
D686 JP Z,Draw_Entity_Sprite_Row2
D689 LD A,H Compute the attribute area address from the current screen row.
D68A RRCA
D68B RRCA
D68C RRCA
D68D AND %00000011 Keep only the row address bits.
D68F OR %01011000 Set the attribute memory flag.
D691 LD H,A Write the entity's colour to two attribute cells.
D692 EXX
D693 LD A,B
D694 EXX
D695 LD (HL),A
D696 DEC HL
D697 LD (HL),A
Draw_Entity_Sprite_Row2 D698 EX DE,HL Blit row two.
D699 EXX
D69A LD A,C
D69B EXX
D69C ADD A,(HL)
D69D LD E,A
D69E INC HL
D69F LD D,(HL)
D6A0 INC HL
D6A1 LD A,(BC)
D6A2 EX DE,HL
D6A3 XOR (HL)
D6A4 LD (HL),A
D6A5 INC BC
D6A6 INC HL
D6A7 LD A,(BC)
D6A8 INC BC
D6A9 XOR (HL)
D6AA LD (HL),A
D6AB EX DE,HL Blit row three.
D6AC EXX
D6AD LD A,C
D6AE EXX
D6AF ADD A,(HL)
D6B0 LD E,A
D6B1 INC HL
D6B2 LD D,(HL)
D6B3 INC HL
D6B4 LD A,(BC)
D6B5 EX DE,HL
D6B6 XOR (HL)
D6B7 LD (HL),A
D6B8 INC BC
D6B9 INC HL
D6BA LD A,(BC)
D6BB INC BC
D6BC XOR (HL)
D6BD LD (HL),A
D6BE EX DE,HL Blit row four.
D6BF EXX
D6C0 LD A,C
D6C1 EXX
D6C2 ADD A,(HL)
D6C3 LD E,A
D6C4 INC HL
D6C5 LD D,(HL)
D6C6 INC HL
D6C7 LD A,(BC)
D6C8 EX DE,HL
D6C9 XOR (HL)
D6CA LD (HL),A
D6CB INC BC
D6CC INC HL
D6CD LD A,(BC)
D6CE INC BC
D6CF XOR (HL)
D6D0 LD (HL),A
D6D1 EX DE,HL Blit row five.
D6D2 EXX
D6D3 LD A,C
D6D4 EXX
D6D5 ADD A,(HL)
D6D6 LD E,A
D6D7 INC HL
D6D8 LD D,(HL)
D6D9 INC HL
D6DA LD A,(BC)
D6DB EX DE,HL
D6DC XOR (HL)
D6DD LD (HL),A
D6DE INC BC
D6DF INC HL
D6E0 LD A,(BC)
D6E1 INC BC
D6E2 XOR (HL)
D6E3 LD (HL),A
D6E4 EX DE,HL Blit row six.
D6E5 EXX
D6E6 LD A,C
D6E7 EXX
D6E8 ADD A,(HL)
D6E9 LD E,A
D6EA INC HL
D6EB LD D,(HL)
D6EC INC HL
D6ED LD A,(BC)
D6EE EX DE,HL
D6EF XOR (HL)
D6F0 LD (HL),A
D6F1 INC BC
D6F2 INC HL
D6F3 LD A,(BC)
D6F4 INC BC
D6F5 XOR (HL)
D6F6 LD (HL),A
D6F7 EX DE,HL Blit row seven.
D6F8 EXX
D6F9 LD A,C
D6FA EXX
D6FB ADD A,(HL)
D6FC LD E,A
D6FD INC HL
D6FE LD D,(HL)
D6FF INC HL
D700 LD A,(BC)
D701 EX DE,HL
D702 XOR (HL)
D703 LD (HL),A
D704 INC BC
D705 INC HL
D706 LD A,(BC)
D707 INC BC
D708 XOR (HL)
D709 LD (HL),A
D70A EXX Jump to Draw_Entity_Sprite_Row8 if in erase mode (skip the attribute write).
D70B LD A,D
D70C AND A
D70D EXX
D70E JP Z,Draw_Entity_Sprite_Row8
D711 LD A,H Compute the attribute area address from the current screen row.
D712 RRCA
D713 RRCA
D714 RRCA
D715 AND %00000011 Keep only the row address bits.
D717 OR %01011000 Set the attribute memory flag.
D719 LD H,A Write the entity's colour to two attribute cells.
D71A EXX
D71B LD A,B
D71C EXX
D71D LD (HL),A
D71E DEC HL
D71F LD (HL),A
Draw_Entity_Sprite_Row8 D720 EX DE,HL Blit row eight.
D721 EXX
D722 LD A,C
D723 EXX
D724 ADD A,(HL)
D725 LD E,A
D726 INC HL
D727 LD D,(HL)
D728 INC HL
D729 LD A,(BC)
D72A EX DE,HL
D72B XOR (HL)
D72C LD (HL),A
D72D INC BC
D72E INC HL
D72F LD A,(BC)
D730 INC BC
D731 XOR (HL)
D732 LD (HL),A
D733 EX DE,HL Blit row nine.
D734 EXX
D735 LD A,C
D736 EXX
D737 ADD A,(HL)
D738 LD E,A
D739 INC HL
D73A LD D,(HL)
D73B INC HL
D73C LD A,(BC)
D73D EX DE,HL
D73E XOR (HL)
D73F LD (HL),A
D740 INC BC
D741 INC HL
D742 LD A,(BC)
D743 INC BC
D744 XOR (HL)
D745 LD (HL),A
D746 EX DE,HL Blit row ten.
D747 EXX
D748 LD A,C
D749 EXX
D74A ADD A,(HL)
D74B LD E,A
D74C INC HL
D74D LD D,(HL)
D74E INC HL
D74F LD A,(BC)
D750 EX DE,HL
D751 XOR (HL)
D752 LD (HL),A
D753 INC BC
D754 INC HL
D755 LD A,(BC)
D756 INC BC
D757 XOR (HL)
D758 LD (HL),A
D759 EX DE,HL Blit row eleven.
D75A EXX
D75B LD A,C
D75C EXX
D75D ADD A,(HL)
D75E LD E,A
D75F INC HL
D760 LD D,(HL)
D761 INC HL
D762 LD A,(BC)
D763 EX DE,HL
D764 XOR (HL)
D765 LD (HL),A
D766 INC BC
D767 INC HL
D768 LD A,(BC)
D769 INC BC
D76A XOR (HL)
D76B LD (HL),A
D76C EX DE,HL Blit row twelve.
D76D EXX
D76E LD A,C
D76F EXX
D770 ADD A,(HL)
D771 LD E,A
D772 INC HL
D773 LD D,(HL)
D774 INC HL
D775 LD A,(BC)
D776 EX DE,HL
D777 XOR (HL)
D778 LD (HL),A
D779 INC BC
D77A INC HL
D77B LD A,(BC)
D77C INC BC
D77D XOR (HL)
D77E LD (HL),A
D77F EXX Return if in erase mode (skip the final attribute write).
D780 LD A,D
D781 AND A
D782 EXX
D783 RET Z
D784 LD A,H Compute the attribute area address from the current screen row.
D785 RRCA
D786 RRCA
D787 RRCA
D788 AND %00000011 Keep only the row address bits.
D78A OR %01011000 Set the attribute memory flag.
D78C LD H,A Write the entity's colour to two attribute cells.
D78D EXX
D78E LD A,B
D78F EXX
D790 LD (HL),A
D791 DEC HL
D792 LD (HL),A
D793 RET Return.
Prev: D630 Up: Map Next: D794