Prev: 44525 Up: Map Next: 44674
44560: Draw Menu Sprite
Used by the routines at HandleMenuRevolverFiring and HandleMenuBullet.
Draws the sprite for the state of a menu entry (the gun firing or the bullet flying) at the position of the entry. The sprites are sixteen pixels wide and are drawn upwards from the bottom row. Each row has two bytes. If the horizontal position is not a multiple of eight, the bytes are indexes into the shift tables, which are used to shift the sprite across by two, four or six pixels. The routine takes the data from the stack to make it faster.
Input
IX The address of the menu entry
Find the sprite and the screen address.
DrawMenuSprite 44560 LD A,(IX+0) Fetch the state of the entry.
44563 LD BC,26724 Point BC at MenuSpritePointers.
44566 CALL GetTableEntry Point HL at the sprite.
44569 LD A,(HL) Fetch the number of rows.
44570 INC HL Move on to the data.
44571 EX AF,AF' Keep the number of rows in the alternate accumulator.
44572 EX DE,HL Swap the address of the data into DE.
44573 LD A,(IX+1) Fetch the horizontal position and keep the horizontal position of the sprite in L.
44576 LD L,A
44577 LD H,(IX+2) Fetch the vertical position into H.
44580 CALL CalculateScreenAddress Work out the screen address.
44583 LD (41501),SP Save the stack pointer.
44587 EX DE,HL Swap the screen address into DE and the address of the data into HL.
44588 LD SP,HL Point the stack pointer at the data.
44589 LD A,(IX+1) Fetch the horizontal position.
44592 AND %00000110 Keep the pixel offset within the byte.
44594 JR Z,DrawMenuSprite_Aligned Jump to DrawMenuSprite_Aligned if the sprite is on a byte boundary.
The sprite is not on a byte boundary, so shift it using the shift tables.
44596 OR %11111000 Make the offset the high byte of the address of a shift table.
44598 LD H,A Point H at the shift table.
44599 EX AF,AF' Fetch the number of rows.
DrawMenuSprite_ShiftedRow 44600 EX AF,AF' Keep the number of rows in the alternate accumulator.
44601 POP BC Fetch the indexes for a row.
44602 LD L,C Copy the first index into L.
44603 LD A,(HL) Fetch the shifted first byte.
44604 LD (DE),A Write it to the screen.
44605 INC E Move to the next byte.
44606 INC H Point H at the overflow table.
44607 LD A,(HL) Fetch the overflow of the first byte.
44608 DEC H Point H back at the shift table.
44609 LD L,B Copy the second index into L.
44610 OR (HL) Combine it with the shifted second byte.
44611 LD (DE),A Write the second byte to the screen.
44612 INC E Move to the next byte.
44613 INC H Point H at the overflow table.
44614 LD A,(HL) Fetch the overflow of the second byte.
44615 DEC H Point H back at the shift table.
44616 LD (DE),A Write it to the screen.
44617 DEC E Move back to the first byte.
44618 DEC E
44619 DEC D Move up a pixel row.
44620 LD A,D Fetch the pixel row.
44621 INC A Add one.
44622 AND %00000111 Check whether the row is the last in a character cell.
44624 JR NZ,DrawMenuSprite_ShiftedNext Jump to DrawMenuSprite_ShiftedNext unless it is.
44626 LD A,E Fetch the low byte of the screen address.
44627 SUB 32 Move up a character row.
44629 LD E,A Keep the low byte of the screen address.
44630 JR C,DrawMenuSprite_ShiftedNext Jump to DrawMenuSprite_ShiftedNext unless that moves up into the next third of the screen.
44632 LD A,D Fetch the high byte of the screen address.
44633 ADD A,8 Move up to the previous third of the screen.
44635 LD D,A Keep the high byte of the screen address.
DrawMenuSprite_ShiftedNext 44636 EX AF,AF' Fetch the number of rows.
44637 DEC A Count it down.
44638 JR NZ,DrawMenuSprite_ShiftedRow Loop back until every row has been drawn.
DrawMenuSprite_Done 44640 LD SP,(41501) Restore the stack pointer.
44644 RET Return.
The sprite is on a byte boundary, so copy the bytes straight to the screen.
DrawMenuSprite_Aligned 44645 EX AF,AF' Swap the number of rows into A.
44646 LD B,A Keep the number of rows in B.
44647 EX DE,HL Swap the screen address into HL.
DrawMenuSprite_AlignedRow 44648 POP DE Fetch two bytes.
44649 LD (HL),E Write the first byte to the screen.
44650 INC L Move to the next byte.
44651 LD (HL),D Write the second byte to the screen.
44652 DEC L Move back to the first byte.
44653 DEC H Move up a pixel row.
44654 LD A,H Fetch the pixel row.
44655 INC A Add one.
44656 AND %00000111 Check whether the row is the last in a character cell.
44658 JR NZ,DrawMenuSprite_AlignedNext Jump to DrawMenuSprite_AlignedNext unless it is.
44660 LD A,L Fetch the low byte of the screen address.
44661 SUB 32 Move up a character row.
44663 LD L,A Keep the low byte of the screen address.
44664 JR C,DrawMenuSprite_AlignedNext Jump to DrawMenuSprite_AlignedNext unless that moves up into the next third of the screen.
44666 LD A,H Fetch the high byte of the screen address.
44667 ADD A,8 Move up to the previous third of the screen.
44669 LD H,A Keep the high byte of the screen address.
DrawMenuSprite_AlignedNext 44670 DJNZ DrawMenuSprite_AlignedRow Loop back until every row has been drawn.
44672 JR DrawMenuSprite_Done Jump to DrawMenuSprite_Done.
Prev: 44525 Up: Map Next: 44674