![]() |
Routines |
| Prev: ADED | Up: Map | Next: AE82 |
|
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.
|
||||||||
|
Find the sprite and the screen address.
|
||||||||
| DrawMenuSprite | AE10 | LD A,(IX+$00) | Fetch the state of the entry. | |||||
| AE13 | LD BC,$6864 | Point BC at MenuSpritePointers. | ||||||
| AE16 | CALL GetTableEntry | Point HL at the sprite. | ||||||
| AE19 | LD A,(HL) | Fetch the number of rows. | ||||||
| AE1A | INC HL | Move on to the data. | ||||||
| AE1B | EX AF,AF' | Keep the number of rows in the alternate accumulator. | ||||||
| AE1C | EX DE,HL | Swap the address of the data into DE. | ||||||
| AE1D | LD A,(IX+$01) | Fetch the horizontal position and keep the horizontal position of the sprite in L. | ||||||
| AE20 | LD L,A | |||||||
| AE21 | LD H,(IX+$02) | Fetch the vertical position into H. | ||||||
| AE24 | CALL CalculateScreenAddress | Work out the screen address. | ||||||
| AE27 | LD ($A21D),SP | Save the stack pointer. | ||||||
| AE2B | EX DE,HL | Swap the screen address into DE and the address of the data into HL. | ||||||
| AE2C | LD SP,HL | Point the stack pointer at the data. | ||||||
| AE2D | LD A,(IX+$01) | Fetch the horizontal position. | ||||||
| AE30 | AND %00000110 | Keep the pixel offset within the byte. | ||||||
| AE32 | 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.
|
||||||||
| AE34 | OR %11111000 | Make the offset the high byte of the address of a shift table. | ||||||
| AE36 | LD H,A | Point H at the shift table. | ||||||
| AE37 | EX AF,AF' | Fetch the number of rows. | ||||||
| DrawMenuSprite_ShiftedRow | AE38 | EX AF,AF' | Keep the number of rows in the alternate accumulator. | |||||
| AE39 | POP BC | Fetch the indexes for a row. | ||||||
| AE3A | LD L,C | Copy the first index into L. | ||||||
| AE3B | LD A,(HL) | Fetch the shifted first byte. | ||||||
| AE3C | LD (DE),A | Write it to the screen. | ||||||
| AE3D | INC E | Move to the next byte. | ||||||
| AE3E | INC H | Point H at the overflow table. | ||||||
| AE3F | LD A,(HL) | Fetch the overflow of the first byte. | ||||||
| AE40 | DEC H | Point H back at the shift table. | ||||||
| AE41 | LD L,B | Copy the second index into L. | ||||||
| AE42 | OR (HL) | Combine it with the shifted second byte. | ||||||
| AE43 | LD (DE),A | Write the second byte to the screen. | ||||||
| AE44 | INC E | Move to the next byte. | ||||||
| AE45 | INC H | Point H at the overflow table. | ||||||
| AE46 | LD A,(HL) | Fetch the overflow of the second byte. | ||||||
| AE47 | DEC H | Point H back at the shift table. | ||||||
| AE48 | LD (DE),A | Write it to the screen. | ||||||
| AE49 | DEC E | Move back to the first byte. | ||||||
| AE4A | DEC E | |||||||
| AE4B | DEC D | Move up a pixel row. | ||||||
| AE4C | LD A,D | Fetch the pixel row. | ||||||
| AE4D | INC A | Add one. | ||||||
| AE4E | AND %00000111 | Check whether the row is the last in a character cell. | ||||||
| AE50 | JR NZ,DrawMenuSprite_ShiftedNext | Jump to DrawMenuSprite_ShiftedNext unless it is. | ||||||
| AE52 | LD A,E | Fetch the low byte of the screen address. | ||||||
| AE53 | SUB $20 | Move up a character row. | ||||||
| AE55 | LD E,A | Keep the low byte of the screen address. | ||||||
| AE56 | JR C,DrawMenuSprite_ShiftedNext | Jump to DrawMenuSprite_ShiftedNext unless that moves up into the next third of the screen. | ||||||
| AE58 | LD A,D | Fetch the high byte of the screen address. | ||||||
| AE59 | ADD A,$08 | Move up to the previous third of the screen. | ||||||
| AE5B | LD D,A | Keep the high byte of the screen address. | ||||||
| DrawMenuSprite_ShiftedNext | AE5C | EX AF,AF' | Fetch the number of rows. | |||||
| AE5D | DEC A | Count it down. | ||||||
| AE5E | JR NZ,DrawMenuSprite_ShiftedRow | Loop back until every row has been drawn. | ||||||
| DrawMenuSprite_Done | AE60 | LD SP,($A21D) | Restore the stack pointer. | |||||
| AE64 | RET | Return. | ||||||
|
The sprite is on a byte boundary, so copy the bytes straight to the screen.
|
||||||||
| DrawMenuSprite_Aligned | AE65 | EX AF,AF' | Swap the number of rows into A. | |||||
| AE66 | LD B,A | Keep the number of rows in B. | ||||||
| AE67 | EX DE,HL | Swap the screen address into HL. | ||||||
| DrawMenuSprite_AlignedRow | AE68 | POP DE | Fetch two bytes. | |||||
| AE69 | LD (HL),E | Write the first byte to the screen. | ||||||
| AE6A | INC L | Move to the next byte. | ||||||
| AE6B | LD (HL),D | Write the second byte to the screen. | ||||||
| AE6C | DEC L | Move back to the first byte. | ||||||
| AE6D | DEC H | Move up a pixel row. | ||||||
| AE6E | LD A,H | Fetch the pixel row. | ||||||
| AE6F | INC A | Add one. | ||||||
| AE70 | AND %00000111 | Check whether the row is the last in a character cell. | ||||||
| AE72 | JR NZ,DrawMenuSprite_AlignedNext | Jump to DrawMenuSprite_AlignedNext unless it is. | ||||||
| AE74 | LD A,L | Fetch the low byte of the screen address. | ||||||
| AE75 | SUB $20 | Move up a character row. | ||||||
| AE77 | LD L,A | Keep the low byte of the screen address. | ||||||
| AE78 | JR C,DrawMenuSprite_AlignedNext | Jump to DrawMenuSprite_AlignedNext unless that moves up into the next third of the screen. | ||||||
| AE7A | LD A,H | Fetch the high byte of the screen address. | ||||||
| AE7B | ADD A,$08 | Move up to the previous third of the screen. | ||||||
| AE7D | LD H,A | Keep the high byte of the screen address. | ||||||
| DrawMenuSprite_AlignedNext | AE7E | DJNZ DrawMenuSprite_AlignedRow | Loop back until every row has been drawn. | |||||
| AE80 | JR DrawMenuSprite_Done | Jump to DrawMenuSprite_Done. | ||||||
| Prev: ADED | Up: Map | Next: AE82 |