Prev: 35706 Up: Map Next: 35885
35722: Draw Chicken
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 42534 at the data for that row and temporarily writing a new width and height there.
Before After
chicken-before chicken-after
Work out the new level and the level that was last drawn.
DrawChicken 35722 LD A,(24104) Fetch the energy of the player from PlayerEnergy.
35725 SRL A Divide the energy of the player by eight, to get the new level.
35727 SRL A
35729 SRL A
35731 LD C,A Keep the new level in C.
35732 LD A,(24105) Fetch the level of the chicken from ChickenLevel.
35735 SRL A Divide the level that was drawn by eight.
35737 SRL A
35739 SRL A
35741 LD B,A Keep the level that was drawn in B.
35742 CP C Compare it with the new level.
35743 RET Z Return if they are the same.
Stash the heights of the two chicken graphics, and the entity, as they are changed below.
35744 LD A,(50499) Fetch the height of the full chicken from 50499 and keep it in E.
35747 LD E,A
35748 LD A,(50317) Fetch the height of the empty chicken from 50317 and keep it in D.
35751 LD D,A
35752 PUSH IX Stash the chicken entity on the stack.
35754 LD IX,35885 Point IX at the entity for the chicken at Entity_Chicken.
35758 PUSH DE Stash the heights of the graphics on the stack.
35759 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.
35761 LD A,(50316) Fetch the width of the graphics in bytes from Graphic_Chicken_2 and keep it in E.
35764 LD E,A
35765 LD D,0 Clear the high byte of the width in D.
35767 LD A,C Fetch the new level.
35768 PUSH BC Stash the levels on the stack.
35769 CALL MultiplyAByDE Call MultiplyAByDE to multiply the width by the new level.
35772 POP BC Restore the levels from the stack.
35773 LD DE,(42534) Fetch the address of the graphic from 42534.
35777 PUSH DE Stash it on the stack.
35778 ADD HL,DE Add the offset to the address of the graphic.
35779 LD (42534),HL Update the address of the graphic at 42534.
Save the two bytes at that address, and replace them with the width and the height that is left.
35782 LD E,(HL) Fetch the first byte.
35783 INC HL Move HL on to the second byte.
35784 LD D,(HL) Fetch the second byte.
35785 LD A,(50317) Fetch the height of the empty chicken from 50317.
35788 SUB C Subtract the new level to get the height that is left.
35789 JR Z,DrawChicken_RestoreGraphic Jump to DrawChicken_RestoreGraphic if there is nothing left to draw.
35791 PUSH DE Stash DE on the stack.
35792 LD (HL),A Write the height that is left to the second byte.
35793 LD A,(50316) Fetch the width from Graphic_Chicken_2.
35796 DEC HL Move HL back to the first byte.
35797 LD (HL),A Write the width to the first byte.
35798 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.
35799 LD A,20 A=20 (the empty chicken).
35801 LD (IX+0),A Update the graphic of the entity.
35804 LD HL,30664 HL=30664 (the position of the chicken).
35807 LD A,H Fetch the Y position.
35808 SUB C Subtract the new level.
35809 LD H,A Set the new Y position in H.
35810 LD (35888),HL Update the position of the entity.
35813 CALL DrawItemGraphic Call DrawItemGraphic to draw the entity.
35816 LD HL,(35888) Fetch the position of the entity.
35819 CALL ScreenAddress Call ScreenAddress to get the screen address of the position.
Clear a row of bytes at that address.
35822 LD A,(50316) Fetch the width from Graphic_Chicken_2 and keep the number of bytes to clear, which is the width in B.
35825 LD B,A
DrawChicken_ClearRow 35826 LD (HL),0 Clear a byte of the row.
35828 INC L Move on to the next byte.
35829 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.
35831 POP HL Restore the address of the first byte from the stack.
35832 POP DE Restore the two bytes from the stack.
35833 LD (HL),E Write the first byte.
35834 INC HL Move HL on to the second byte.
35835 LD (HL),D Write the second byte.
DrawChicken_RestoreGraphic 35836 POP HL Restore the address of the graphic from the stack.
35837 LD (42534),HL Update the address of the graphic at 42534.
Put back the heights of the graphics, and remember the level that has been drawn.
DrawChicken_Finish 35840 POP DE Restore the stashed heights from the stack.
35841 LD A,E Fetch the height of the full chicken.
35842 LD (50499),A Update the height of the full chicken in 50499.
35845 LD A,D Fetch the height of the empty chicken.
35846 LD (50317),A Update the height of the empty chicken in 50317.
35849 POP IX Restore the chicken entity from the stack.
35851 LD A,(24104) Fetch the energy of the player from PlayerEnergy.
35854 LD (24105),A Update the level of the chicken in ChickenLevel.
35857 RET Return.
The energy has gone up, so draw the full chicken with the height of the new level.
DrawChicken_Increase 35858 LD A,C Keep the new level in A.
35859 LD (50499),A Update the height of the full chicken in 50499.
35862 LD A,19 A=19 (the full chicken).
35864 LD (IX+0),A Update the graphic of the entity.
35867 LD HL,30664 HL=30664 (the position of the chicken).
35870 LD (35888),HL Update the position of the entity.
35873 CALL DrawItemGraphic Call DrawItemGraphic to draw the entity.
35876 LD B,6 B=6 (the number of bytes to clear).
DrawChicken_ClearBytes 35878 LD (HL),0 Clear a byte of the chicken.
35880 INC L Move on to the next byte.
35881 DJNZ DrawChicken_ClearBytes Decrease the byte counter by one and loop back to DrawChicken_ClearBytes until all six bytes have been cleared.
35883 JR DrawChicken_Finish Jump to DrawChicken_Finish to put back the heights of the graphics.
Prev: 35706 Up: Map Next: 35885