Prev: B436 Up: Map Next: B4C0
B43C: Draw Sprite
Used by the routine at DrawEntityItem.
Draws the sprite of an entity into the screen buffer, which is 18 bytes wide. The sprite data is read by using the stack pointer, and the sprite is drawn by one of the row routines in the table at RowRoutineTable, which is chosen using the width of the sprite and whether it is shifted by the low bits of the column. The addresses of the row routine and the step to the previous row are written into the drawing code before it is entered. If the sprite goes beyond the top of the screen buffer, the rows that are not needed are skipped.
Input
IX The entity
DrawSprite B43C CALL FindSpriteFrame Find the sprite.
B43F LD A,(IX+$16) Read the width byte.
B442 AND %11110000 Use the countdown nibble.
B444 CALL NZ,BuildPatternedSprite Build a patterned copy when that nibble is set.
B447 LD ($5CDA),SP Remember the stack pointer.
B44B LD HL,$ADE7 Use the row-routine table.
B44E LD A,(IX+$0E) Read the column.
B451 AND %00000110 Use bits 1-2 as the shift.
B453 LD C,A Keep the shift.
B454 LD A,(DE) Read the sprite's width.
B455 LD ($B4A7),A Give the width to the skip loop.
B458 LD B,A Keep the width.
B459 JR Z,DrawSprite_Index A shifted sprite uses the next routine and one more byte.
B45B ADD A,$04
B45D INC B
DrawSprite_Index B45E ADD A,A Double the width to make a table index.
B45F CALL AddToAddress Look the row routine up.
B462 LD A,(HL) Read the routine's address.
B463 INC HL
B464 LD H,(HL)
B465 LD L,A
B466 LD ($B4BA),HL Give the routine and the row step to the drawers.
B469 LD ($B4BE),HL
B46C LD ($B4E1),HL
B46F LD ($B534),HL
B472 LD ($B539),HL
B475 INC DE Move on to the sprite data.
B476 LD A,B The step back across a row is the width plus 17.
B477 ADD A,$17
B479 LD ($B530),A
B47C NEG The other step is the opposite of that width.
B47E LD ($B4DC),A
B481 LD L,(IX+$18) Fetch the screen address.
B484 LD H,(IX+$19)
B487 EX DE,HL Keep the sprite address aside.
B488 LD A,(HL) Read how many rows the sprite has.
B489 LD B,A
B48A EX AF,AF' Remember that count.
B48B LD A,(IX+$0F) The first row to draw is one past the entity's row.
B48E INC A
B48F INC HL Read the sprite through the stack.
B490 LD SP,HL
B491 CP B Clip the sprite when its rows end above the view.
B492 JP NC,DrawSprite_Clip
B495 LD B,A The row count is that first row.
B496 EX AF,AF' Bring the sprite's row count back.
B497 JP DrawSprite_2 Draw the sprite.
DrawSprite_Clip B49A SUB $80 A count below 80 is drawn whole.
B49C JP C,DrawSprite_2
B49F JP Z,DrawSprite_2 A count of exactly 80 is drawn whole.
B4A2 LD B,A The rows above the view are the excess.
B4A3 EX AF,AF' Bring the sprite's row count back.
B4A4 SUB B Drop the rows that are off the view.
B4A5 EX AF,AF'
DrawSprite_0 B4A6 LD B,$00 Skip one row of the sprite.
DrawSprite_1 B4A8 POP HL Skip the bytes of that row.
B4A9 DJNZ DrawSprite_1
B4AB DEC A Repeat for the remaining rows above the view.
B4AC JR NZ,DrawSprite_0
B4AE EX AF,AF' Bring the rows that are in view back.
B4AF LD B,A Use that as the row count.
B4B0 EX AF,AF'
DrawSprite_2 B4B1 LD A,C Read the shift.
B4B2 AND A An unshifted sprite is drawn directly.
B4B3 JR Z,DrawSprite_4
B4B5 ADD A,$F8 A shifted sprite uses the page selected by the shift.
B4B7 LD H,A
B4B8 LD A,(DE)
DrawSprite_3 B4B9 JP DrawSprite_3 Draw the shifted rows. The target is patched.
DrawSprite_4 B4BC EX DE,HL Put the screen address in HL.
DrawSprite_5 B4BD JP DrawSprite_5 Draw the unshifted rows. The target is patched.
Prev: B436 Up: Map Next: B4C0