Prev: 54832 Up: Map Next: 55188
54839: 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 54839 EXX Set draw mode (attribute write enabled).
54840 LD D,1
54842 EXX
This entry point is used by the routine at Erase_Entity_Sprite.
Draw_Entity_Sprite_Render 54843 LD B,H Copy the entity record pointer to BC.
54844 LD C,L
54845 LD E,(HL) Look up the sprite data address for this entity type.
54846 SLA E
54848 LD D,0
54850 LD HL,50700
54853 ADD HL,DE
54854 LD E,(HL)
54855 INC HL
54856 LD D,(HL)
54857 LD H,B Copy the entity record pointer from BC.
54858 LD L,C
54859 INC HL Read the entity's Y position.
54860 LD B,70
54862 LD C,(HL)
54863 INC HL
54864 SLA C Double the Y position to form the pixel row address.
54866 RL B
54868 PUSH BC Stash the pixel row address on the stack.
54869 LD A,(HL) Read the X position and extract the byte column and bit offset.
54870 AND A
54871 LD HL,0
54874 RRA
54875 RR L
54877 RRA
54878 RR L
54880 RRA
54881 RR L
54883 EXX Save the pixel bit offset in the shadow register.
54884 LD C,A
54885 EXX
54886 LD A,L Compute the sprite pixel data address and add the column offset.
54887 RRCA
54888 LD L,A
54889 RRCA
54890 ADD A,L
54891 LD L,A
54892 ADD HL,DE
54893 LD B,H Copy the sprite data pointer to BC.
54894 LD C,L
54895 POP HL Restore the pixel row address from the stack.
54896 EXX Read the pixel bit offset from the shadow register.
54897 LD A,C
54898 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 54899 ADD A,(HL) Blit the first sprite row onto the display.
54900 LD E,A
54901 INC HL
54902 LD D,(HL)
54903 INC HL
54904 LD A,(BC)
54905 EX DE,HL
54906 XOR (HL)
54907 LD (HL),A
54908 INC BC
54909 INC HL
54910 LD A,(BC)
54911 INC BC
54912 XOR (HL)
54913 LD (HL),A
54914 EXX Jump to Draw_Entity_Sprite_Row2 if in erase mode (skip the attribute write).
54915 LD A,D
54916 AND A
54917 EXX
54918 JP Z,Draw_Entity_Sprite_Row2
54921 LD A,H Compute the attribute area address from the current screen row.
54922 RRCA
54923 RRCA
54924 RRCA
54925 AND %00000011 Keep only the row address bits.
54927 OR %01011000 Set the attribute memory flag.
54929 LD H,A Write the entity's colour to two attribute cells.
54930 EXX
54931 LD A,B
54932 EXX
54933 LD (HL),A
54934 DEC HL
54935 LD (HL),A
Draw_Entity_Sprite_Row2 54936 EX DE,HL Blit row two.
54937 EXX
54938 LD A,C
54939 EXX
54940 ADD A,(HL)
54941 LD E,A
54942 INC HL
54943 LD D,(HL)
54944 INC HL
54945 LD A,(BC)
54946 EX DE,HL
54947 XOR (HL)
54948 LD (HL),A
54949 INC BC
54950 INC HL
54951 LD A,(BC)
54952 INC BC
54953 XOR (HL)
54954 LD (HL),A
54955 EX DE,HL Blit row three.
54956 EXX
54957 LD A,C
54958 EXX
54959 ADD A,(HL)
54960 LD E,A
54961 INC HL
54962 LD D,(HL)
54963 INC HL
54964 LD A,(BC)
54965 EX DE,HL
54966 XOR (HL)
54967 LD (HL),A
54968 INC BC
54969 INC HL
54970 LD A,(BC)
54971 INC BC
54972 XOR (HL)
54973 LD (HL),A
54974 EX DE,HL Blit row four.
54975 EXX
54976 LD A,C
54977 EXX
54978 ADD A,(HL)
54979 LD E,A
54980 INC HL
54981 LD D,(HL)
54982 INC HL
54983 LD A,(BC)
54984 EX DE,HL
54985 XOR (HL)
54986 LD (HL),A
54987 INC BC
54988 INC HL
54989 LD A,(BC)
54990 INC BC
54991 XOR (HL)
54992 LD (HL),A
54993 EX DE,HL Blit row five.
54994 EXX
54995 LD A,C
54996 EXX
54997 ADD A,(HL)
54998 LD E,A
54999 INC HL
55000 LD D,(HL)
55001 INC HL
55002 LD A,(BC)
55003 EX DE,HL
55004 XOR (HL)
55005 LD (HL),A
55006 INC BC
55007 INC HL
55008 LD A,(BC)
55009 INC BC
55010 XOR (HL)
55011 LD (HL),A
55012 EX DE,HL Blit row six.
55013 EXX
55014 LD A,C
55015 EXX
55016 ADD A,(HL)
55017 LD E,A
55018 INC HL
55019 LD D,(HL)
55020 INC HL
55021 LD A,(BC)
55022 EX DE,HL
55023 XOR (HL)
55024 LD (HL),A
55025 INC BC
55026 INC HL
55027 LD A,(BC)
55028 INC BC
55029 XOR (HL)
55030 LD (HL),A
55031 EX DE,HL Blit row seven.
55032 EXX
55033 LD A,C
55034 EXX
55035 ADD A,(HL)
55036 LD E,A
55037 INC HL
55038 LD D,(HL)
55039 INC HL
55040 LD A,(BC)
55041 EX DE,HL
55042 XOR (HL)
55043 LD (HL),A
55044 INC BC
55045 INC HL
55046 LD A,(BC)
55047 INC BC
55048 XOR (HL)
55049 LD (HL),A
55050 EXX Jump to Draw_Entity_Sprite_Row8 if in erase mode (skip the attribute write).
55051 LD A,D
55052 AND A
55053 EXX
55054 JP Z,Draw_Entity_Sprite_Row8
55057 LD A,H Compute the attribute area address from the current screen row.
55058 RRCA
55059 RRCA
55060 RRCA
55061 AND %00000011 Keep only the row address bits.
55063 OR %01011000 Set the attribute memory flag.
55065 LD H,A Write the entity's colour to two attribute cells.
55066 EXX
55067 LD A,B
55068 EXX
55069 LD (HL),A
55070 DEC HL
55071 LD (HL),A
Draw_Entity_Sprite_Row8 55072 EX DE,HL Blit row eight.
55073 EXX
55074 LD A,C
55075 EXX
55076 ADD A,(HL)
55077 LD E,A
55078 INC HL
55079 LD D,(HL)
55080 INC HL
55081 LD A,(BC)
55082 EX DE,HL
55083 XOR (HL)
55084 LD (HL),A
55085 INC BC
55086 INC HL
55087 LD A,(BC)
55088 INC BC
55089 XOR (HL)
55090 LD (HL),A
55091 EX DE,HL Blit row nine.
55092 EXX
55093 LD A,C
55094 EXX
55095 ADD A,(HL)
55096 LD E,A
55097 INC HL
55098 LD D,(HL)
55099 INC HL
55100 LD A,(BC)
55101 EX DE,HL
55102 XOR (HL)
55103 LD (HL),A
55104 INC BC
55105 INC HL
55106 LD A,(BC)
55107 INC BC
55108 XOR (HL)
55109 LD (HL),A
55110 EX DE,HL Blit row ten.
55111 EXX
55112 LD A,C
55113 EXX
55114 ADD A,(HL)
55115 LD E,A
55116 INC HL
55117 LD D,(HL)
55118 INC HL
55119 LD A,(BC)
55120 EX DE,HL
55121 XOR (HL)
55122 LD (HL),A
55123 INC BC
55124 INC HL
55125 LD A,(BC)
55126 INC BC
55127 XOR (HL)
55128 LD (HL),A
55129 EX DE,HL Blit row eleven.
55130 EXX
55131 LD A,C
55132 EXX
55133 ADD A,(HL)
55134 LD E,A
55135 INC HL
55136 LD D,(HL)
55137 INC HL
55138 LD A,(BC)
55139 EX DE,HL
55140 XOR (HL)
55141 LD (HL),A
55142 INC BC
55143 INC HL
55144 LD A,(BC)
55145 INC BC
55146 XOR (HL)
55147 LD (HL),A
55148 EX DE,HL Blit row twelve.
55149 EXX
55150 LD A,C
55151 EXX
55152 ADD A,(HL)
55153 LD E,A
55154 INC HL
55155 LD D,(HL)
55156 INC HL
55157 LD A,(BC)
55158 EX DE,HL
55159 XOR (HL)
55160 LD (HL),A
55161 INC BC
55162 INC HL
55163 LD A,(BC)
55164 INC BC
55165 XOR (HL)
55166 LD (HL),A
55167 EXX Return if in erase mode (skip the final attribute write).
55168 LD A,D
55169 AND A
55170 EXX
55171 RET Z
55172 LD A,H Compute the attribute area address from the current screen row.
55173 RRCA
55174 RRCA
55175 RRCA
55176 AND %00000011 Keep only the row address bits.
55178 OR %01011000 Set the attribute memory flag.
55180 LD H,A Write the entity's colour to two attribute cells.
55181 EXX
55182 LD A,B
55183 EXX
55184 LD (HL),A
55185 DEC HL
55186 LD (HL),A
55187 RET Return.
Prev: 54832 Up: Map Next: 55188