![]() |
Routines |
| Prev: 8B7A | Up: Map | Next: 8C2D |
|
Used by the routines at TakeEnergyFromPlayer, HandlerFoodItem, HandlerKnight, HurtPlayer, PreparePlayer and HandlerMushroom.
Updates the picture of the roast chicken so that it shows the energy of the player. The energy in PlayerEnergy and the level that was last drawn in ChickenLevel are both divided by eight, and nothing is done if they are the same. When the energy has gone up, the picture of the full chicken is drawn with a height of the new level. When it has gone down, the part of the empty chicken (see Graphic_Chicken_2) below that level is drawn, by pointing the entry for it in the graphics table at A626 at the data for that row and temporarily writing a new width and height there.
|
||||||||
|
Work out the new level and the level that was last drawn.
|
||||||||
| DrawChicken | 8B8A | LD A,($5E28) | Fetch the energy of the player from PlayerEnergy. | |||||
| 8B8D | SRL A | Divide the energy of the player by eight, to get the new level. | ||||||
| 8B8F | SRL A | |||||||
| 8B91 | SRL A | |||||||
| 8B93 | LD C,A | Keep the new level in C. | ||||||
| 8B94 | LD A,($5E29) | Fetch the level of the chicken from ChickenLevel. | ||||||
| 8B97 | SRL A | Divide the level that was drawn by eight. | ||||||
| 8B99 | SRL A | |||||||
| 8B9B | SRL A | |||||||
| 8B9D | LD B,A | Keep the level that was drawn in B. | ||||||
| 8B9E | CP C | Compare it with the new level. | ||||||
| 8B9F | RET Z | Return if they are the same. | ||||||
|
Stash the heights of the two chicken graphics, and the entity, as they are changed below.
|
||||||||
| 8BA0 | LD A,($C543) | Fetch the height of the full chicken from C543 and keep it in E. | ||||||
| 8BA3 | LD E,A | |||||||
| 8BA4 | LD A,($C48D) | Fetch the height of the empty chicken from C48D and keep it in D. | ||||||
| 8BA7 | LD D,A | |||||||
| 8BA8 | PUSH IX | Stash the chicken entity on the stack. | ||||||
| 8BAA | LD IX,$8C2D | Point IX at the entity for the chicken at Entity_Chicken. | ||||||
| 8BAE | PUSH DE | Stash the heights of the graphics on the stack. | ||||||
| 8BAF | JR C,DrawChicken_Increase | Jump to DrawChicken_Increase if the energy has gone up. | ||||||
|
The energy has gone down, so draw the part of the empty chicken that is below the new level. First find the data for the row.
|
||||||||
| 8BB1 | LD A,($C48C) | Fetch the width of the graphics in bytes from Graphic_Chicken_2 and keep it in E. | ||||||
| 8BB4 | LD E,A | |||||||
| 8BB5 | LD D,$00 | Clear the high byte of the width in D. | ||||||
| 8BB7 | LD A,C | Fetch the new level. | ||||||
| 8BB8 | PUSH BC | Stash the levels on the stack. | ||||||
| 8BB9 | CALL MultiplyAByDE | Call MultiplyAByDE to multiply the width by the new level. | ||||||
| 8BBC | POP BC | Restore the levels from the stack. | ||||||
| 8BBD | LD DE,($A626) | Fetch the address of the graphic from A626. | ||||||
| 8BC1 | PUSH DE | Stash it on the stack. | ||||||
| 8BC2 | ADD HL,DE | Add the offset to the address of the graphic. | ||||||
| 8BC3 | LD ($A626),HL | Update the address of the graphic at A626. | ||||||
|
Save the two bytes at that address, and replace them with the width and the height that is left.
|
||||||||
| 8BC6 | LD E,(HL) | Fetch the first byte. | ||||||
| 8BC7 | INC HL | Move HL on to the second byte. | ||||||
| 8BC8 | LD D,(HL) | Fetch the second byte. | ||||||
| 8BC9 | LD A,($C48D) | Fetch the height of the empty chicken from C48D. | ||||||
| 8BCC | SUB C | Subtract the new level to get the height that is left. | ||||||
| 8BCD | JR Z,DrawChicken_RestoreGraphic | Jump to DrawChicken_RestoreGraphic if there is nothing left to draw. | ||||||
| 8BCF | PUSH DE | Stash DE on the stack. | ||||||
| 8BD0 | LD (HL),A | Write the height that is left to the second byte. | ||||||
| 8BD1 | LD A,($C48C) | Fetch the width from Graphic_Chicken_2. | ||||||
| 8BD4 | DEC HL | Move HL back to the first byte. | ||||||
| 8BD5 | LD (HL),A | Write the width to the first byte. | ||||||
| 8BD6 | PUSH HL | Stash the address of the graphic on the stack. | ||||||
|
Draw the part of the empty chicken, which is moved up by the new level.
|
||||||||
| 8BD7 | LD A,$14 | A=14 (the empty chicken). | ||||||
| 8BD9 | LD (IX+$00),A | Update the graphic of the entity. | ||||||
| 8BDC | LD HL,$77C8 | HL=77C8 (the position of the chicken). | ||||||
| 8BDF | LD A,H | Fetch the Y position. | ||||||
| 8BE0 | SUB C | Subtract the new level. | ||||||
| 8BE1 | LD H,A | Set the new Y position in H. | ||||||
| 8BE2 | LD ($8C30),HL | Update the position of the entity. | ||||||
| 8BE5 | CALL DrawItemGraphic | Call DrawItemGraphic to draw the entity. | ||||||
| 8BE8 | LD HL,($8C30) | Fetch the position of the entity. | ||||||
| 8BEB | CALL ScreenAddress | Call ScreenAddress to get the screen address of the position. | ||||||
|
Clear a row of bytes at that address.
|
||||||||
| 8BEE | LD A,($C48C) | Fetch the width from Graphic_Chicken_2 and keep the number of bytes to clear, which is the width in B. | ||||||
| 8BF1 | LD B,A | |||||||
| DrawChicken_ClearRow | 8BF2 | LD (HL),$00 | Clear a byte of the row. | |||||
| 8BF4 | INC L | Move on to the next byte. | ||||||
| 8BF5 | DJNZ DrawChicken_ClearRow | Decrease the byte counter by one and loop back to DrawChicken_ClearRow until the whole row has been cleared. | ||||||
|
Put back the two bytes that were replaced.
|
||||||||
| 8BF7 | POP HL | Restore the address of the first byte from the stack. | ||||||
| 8BF8 | POP DE | Restore the two bytes from the stack. | ||||||
| 8BF9 | LD (HL),E | Write the first byte. | ||||||
| 8BFA | INC HL | Move HL on to the second byte. | ||||||
| 8BFB | LD (HL),D | Write the second byte. | ||||||
| DrawChicken_RestoreGraphic | 8BFC | POP HL | Restore the address of the graphic from the stack. | |||||
| 8BFD | LD ($A626),HL | Update the address of the graphic at A626. | ||||||
|
Put back the heights of the graphics, and remember the level that has been drawn.
|
||||||||
| DrawChicken_Finish | 8C00 | POP DE | Restore the stashed heights from the stack. | |||||
| 8C01 | LD A,E | Fetch the height of the full chicken. | ||||||
| 8C02 | LD ($C543),A | Update the height of the full chicken in C543. | ||||||
| 8C05 | LD A,D | Fetch the height of the empty chicken. | ||||||
| 8C06 | LD ($C48D),A | Update the height of the empty chicken in C48D. | ||||||
| 8C09 | POP IX | Restore the chicken entity from the stack. | ||||||
|
See Infinite Chicken.
|
||||||||
| 8C0B | LD A,($5E28) | Fetch the energy of the player from PlayerEnergy. | ||||||
| 8C0E | LD ($5E29),A | Update the level of the chicken in ChickenLevel. | ||||||
| 8C11 | RET | Return. | ||||||
|
The energy has gone up, so draw the full chicken with the height of the new level.
|
||||||||
| DrawChicken_Increase | 8C12 | LD A,C | Keep the new level in A. | |||||
| 8C13 | LD ($C543),A | Update the height of the full chicken in C543. | ||||||
| 8C16 | LD A,$13 | A=13 (the full chicken). | ||||||
| 8C18 | LD (IX+$00),A | Update the graphic of the entity. | ||||||
| 8C1B | LD HL,$77C8 | HL=77C8 (the position of the chicken). | ||||||
| 8C1E | LD ($8C30),HL | Update the position of the entity. | ||||||
| 8C21 | CALL DrawItemGraphic | Call DrawItemGraphic to draw the entity. | ||||||
| 8C24 | LD B,$06 | B=06 (the number of bytes to clear). | ||||||
| DrawChicken_ClearBytes | 8C26 | LD (HL),$00 | Clear a byte of the chicken. | |||||
| 8C28 | INC L | Move on to the next byte. | ||||||
| 8C29 | DJNZ DrawChicken_ClearBytes | Decrease the byte counter by one and loop back to DrawChicken_ClearBytes until all six bytes have been cleared. | ||||||
| 8C2B | JR DrawChicken_Finish | Jump to DrawChicken_Finish to put back the heights of the graphics. | ||||||
| Prev: 8B7A | Up: Map | Next: 8C2D |