Prev: 58166 Up: Map Next: 58365
58316: Increase/decrease Maroc's energy and play short beep sound
Used by the routines at 52445, 53349, 53526, 53714, 53819, 54393, 54842, 59389 and 59869.
Input
A Value to decrease Maroc's energy by. If bit 7 of the value is set, it indicates the amount to add to Maroc's energy bar (energy being restored)
Check if it's an increase or decrease:
58316 LD C,A Store increase/decrease value in C register
58317 CP 128 If bit 7 is set, it indicates an increase in energy (e.g. CHALICE, ENERGIZE, AMULET spells)
58319 JR NC,58331
Decrease Maroc's energy:
58321 LD A,(60128) Maroc's current energy
58324 SUB C The amount of damage to subtract
58325 JR NC,58342 Is Maroc's energy now less than zero?
58327 LD A,0 If energy < 0, set energy to zero
58329 JR 58342
Increase Maroc's energy:
58331 NEG Maroc is being healed - invert damage (resets bit 7) to indicate energy increase
58333 LD C,A
58334 LD A,(60128) Maroc's current energy
58337 ADD A,C Increase by relevant amount
58338 JR NC,58342
58340 LD A,255 If energy is now > 255, set energy to 255
Play beep sound - pitch corresponds to Maroc's energy
58342 LD (60128),A Re-store Maroc's new energy level
58345 NEG Inverts energy value so that the higher the energy, the higher the pitch of the beep sound
58347 OR 1 Ensure value to use is at least 1 (i.e. not zero)
58349 LD D,A Delay for inner beep loop
58350 LD C,16 Delay for beep sound pitch register (outer loop)
58352 LD A,16 Set bit 4 (speaker bit)
58354 LD B,D Delay counter
58355 DJNZ 58355 Short delay, affects beep pitch based on energy left
58357 OUT (254),A Play sound
58359 XOR 16 Toggle speaker bit
58361 DEC C
58362 JR NZ,58354 Keep toggling for short time (outer repeat loop)
58364 RET
Prev: 58166 Up: Map Next: 58365