Prev: 56913 Up: Map Next: 57176
56937: Draw Tile
Used by the routine at 63489.
Draw_Tile 56937 LD IX,57176 Set IX to Table_TileDataOffsets.
56941 LD B,0 Initialise B to 0 for the sum below.
56943 LD A,(58055) Load *Item_ID into A.
Find which spritesheet the image is located in. There are 20 sprites in each sheet, so test if the sprite ID is less than 21 to check if it's in the first one. Else, subtract 20 and check again.
56946 LD C,3 Set a counter in C with 3 to track the three spritesheets (two item sheets and one for the game tiles).
FindSpritesheet_Loop 56948 CP 21 Jump to LocateSprite if A is lower than 21 (unsigned comparison).
56950 JP M,LocateSprite
56953 SUB 20 Subtract 20 from A.
56955 DEC C Decrease C by one.
56956 JR NZ,FindSpritesheet_Loop Jump back to FindSpritesheet_Loop until C is zero.
Default the sprite ID to 1.
56958 LD A,1 A=1.
Adjust the sprite ID for 0-based indexing.
LocateSprite 56960 DEC A Decrease the sprite ID by one.
There are 4 offset bytes, so multiply the sprite ID by 4 to find the relevant offsets in the table.
56961 RLCA Multiply the sprite ID by 4 and store the result in C.
56962 RLCA
56963 LD C,A
Fetch the offsets for the sprite being processed.
56964 ADD IX,BC Add the result to IX to locate the offsets for the tile.
56966 LD C,(IX+0) Fetch the graphic data offset and store it in BC.
56969 LD B,(IX+1)
56972 LD E,(IX+2) Fetch the attribute data offset and store it in DE.
56975 LD D,(IX+3)
Calculate the graphic data address.
56978 LD IX,(58056) Add *Item_SpriteBank and the offset in BC to locate the start of the graphics data - store the result in IX.
56982 ADD IX,BC
Calculate the attribute address.
56984 LD HL,(58056) Add *Item_SpriteBank and 2560 to locate the start of the attributes for the spritesheet. Then, add the offset held in DE to the total, this will locate the start of the attributes for the sprite currently being processed - store the result in IY (using the stack).
56987 LD BC,2560
56990 ADD HL,BC
56991 ADD HL,DE
56992 PUSH HL
56993 POP IY
Print the sprite to the screen.
56995 LD B,4 B=4.
56997 LD H,40 H=40.
Draw_Tile_0 56999 PUSH BC Stash BC on the stack.
57000 LD A,8 A=8.
57002 PUSH IX Stash IX on the stack.
57004 LD BC,20 BC=0020.
Draw_Tile_1 57007 PUSH AF Stash AF on the stack.
57008 LD L,A L=A.
57009 CALL CalculateScreenAddress Call CalculateScreenAddress.
57012 LD A,(IX+0) Write *IX+0 to *DE.
57015 LD (DE),A
57016 ADD IX,BC IX+=BC.
57018 POP AF Restore AF from the stack.
57019 INC A Increment A by one.
57020 CP 40 Jump to Draw_Tile_1 if A is not equal to 40.
57022 JP NZ,Draw_Tile_1
Switch IX to point to the attributes.
57025 PUSH IY IX=IY (using the stack).
57027 POP IX
57029 LD DE,22565 DE=22565 (attribute buffer location).
57032 LD B,4 B=4.
57034 PUSH HL Stash HL on the stack.
Colour_Tile_Loop 57035 PUSH BC Stash BC on the stack.
57036 LD A,(IX+0) Write *IX+0 to *DE.
57039 LD (DE),A
57040 LD BC,20 IX+=0020.
57043 ADD IX,BC
57045 LD HL,32 DE+=0032.
57048 ADD HL,DE
57049 EX DE,HL
57050 POP BC Restore BC from the stack.
57051 DJNZ Colour_Tile_Loop Decrease counter by one and loop back to Colour_Tile_Loop until counter is zero.
57053 POP HL Restore HL, IX and BC from the stack.
57054 POP IX
57056 POP BC
57057 LD A,B A=B.
57058 PUSH BC Stash BC, IX and HL on the stack.
57059 PUSH IX
57061 PUSH HL
57062 CP 1 Jump to Draw_Tile_7 if A is equal to 1.
57064 JP Z,Draw_Tile_7
57067 LD A,5 A=5.
57069 LD C,35 C=35.
Draw_Tile_2 57071 LD B,C B=C.
57072 SLA B Shift B left (with carry).
Draw_Tile_3 57074 DJNZ Draw_Tile_3 Decrease counter by one and loop back to Draw_Tile_3 until counter is zero.
57076 XOR %00010000 Flip bit 4.
57078 OUT (254),A Send to the speaker.
57080 DEC C Decrease C by one.
57081 JP NZ,Draw_Tile_2 Jump to Draw_Tile_2 until C is zero.
57084 LD HL,5000 HL=5000.
57087 LD DE,1250 DE=1250.
Draw_Tile_4 57090 LD A,(HL) A=*HL.
57091 AND %11110000 Keep only bits 4-7.
57093 OR %00000101 Set bits 0, 2.
57095 OUT (254),A Send to the speaker.
57097 INC HL Increment HL by one.
57098 DEC DE Decrease DE by one.
57099 LD A,D Jump to Draw_Tile_4 if DE is not zero.
57100 OR E
57101 JP NZ,Draw_Tile_4
57104 LD A,1 Write 1 to *59231.
57106 LD (59231),A
57109 LD B,4 B=4.
Draw_Tile_5 57111 PUSH BC Stash BC on the stack.
57112 LD A,(59231) B=*59231.
57115 LD B,A
57116 LD C,7 C=7.
57118 CALL Calculate_ScreenBlockAddress Call Calculate_ScreenBlockAddress.
57121 LD A,8 A=8.
57123 PUSH HL Stash HL on the stack.
Draw_Tile_6 57124 LD BC,3 BC=0003.
57127 PUSH HL DE=HL (using the stack).
57128 POP DE
57129 INC DE Increment DE by one.
57130 PUSH HL Stash HL on the stack.
57131 LDDR LDDR.
57133 INC HL Increment HL by one.
57134 LD (HL),C Write C to *HL.
57135 POP HL Restore HL from the stack.
57136 INC H Increment H by one.
57137 DEC A Decrease A by one.
57138 JP NZ,Draw_Tile_6 Jump to Draw_Tile_6 until A is zero.
57141 POP HL Restore HL from the stack.
57142 CALL Calculate_AttributeAddress Call Calculate_AttributeAddress.
57145 PUSH DE HL=DE (using the stack).
57146 POP HL
57147 INC DE Increment DE by one.
57148 LD BC,3 BC=0003.
57151 LDDR LDDR.
57153 LD A,0 Write 0 to *DE.
57155 LD (DE),A
57156 LD HL,59231 HL=59231.
57159 INC (HL) Increment *HL by one.
57160 POP BC Restore BC from the stack.
57161 DJNZ Draw_Tile_5 Decrease counter by one and loop back to Draw_Tile_5 until counter is zero.
Draw_Tile_7 57163 POP HL Restore HL and IX from the stack.
57164 POP IX
57166 DEC IX Decrease IX by one.
57168 DEC IY Decrease IY by one.
57170 POP BC Restore BC from the stack.
57171 DEC B Decrease B by one.
57172 JP NZ,Draw_Tile_0 Jump to Draw_Tile_0 until B is zero.
57175 RET Return.
Prev: 56913 Up: Map Next: 57176