Prev: DF4E Up: Map Next: E005
DF72: Update sprite for any objects which need to animate, and update counters.
Used by the routine at routine86.
Each position on the map has an associated animation timeout and frame number in map_animation_timeout_table and map_animation_frame_table.
For all map positions containing an object, decrement the timeout until it reaches 1, then cycle to the next frame and reset the timeout from the object data table.
update_animation DF72 PUSH HL Preserve registers.
DF73 PUSH BC
DF74 PUSH DE
DF75 PUSH AF
DF76 LD A,($5C8F) Preserve value of ATTR-T.
DF79 PUSH AF
DF7A LD HL,($5C36) Preserve value of CHARS.
DF7D PUSH HL
DF7E LD HL,map_object_table Set HL to address of map_object_table.
DF81 PUSH HL Call KEY-SCAN routine in Spectrum ROM to see if a key was pressed.
DF82 CALL $028E
DF85 POP HL
DF86 LD A,D If CAPS SHIFT is pressed jump to end_of_table.
DF87 CP $28
DF89 JR Z,end_of_table
next_object_entry DF8B LD A,(HL) Else read entry from map_object_table.
DF8C CP $FF If value is $FF jump to end_of_table.
DF8E JR Z,end_of_table
DF90 OR A Else if value is not $00 jump to object_not_zero.
DF91 JR NZ,object_not_zero
check_zero DF93 LD A,(HL) If object is $01 set it to zero.
DF94 CP $01
DF96 JR NZ,not_1
DF98 XOR A
DF99 LD (HL),A
not_1 DF9A INC HL Move on to next address and jump back to next_object_entry.
DF9B JR next_object_entry
end_of_table DF9D POP HL Restore value of CHARS.
DF9E LD ($5C36),HL
DFA1 POP AF Restore value of ATTR-T.
DFA2 LD ($5C8F),A
DFA5 POP AF Restore registers and return.
DFA6 POP DE
DFA7 POP BC
DFA8 POP HL
DFA9 RET
object_not_zero DFAA PUSH HL Preserve position in map_object_table and object number.
DFAB PUSH AF
DFAC LD DE,$00A1 If corresponding entry in map_animation_timeout_table is $01 jump to animation_delay_timeout.
DFAF ADD HL,DE
DFB0 LD A,(HL)
DFB1 DEC A
DFB2 JR Z,animation_delay_timeout
DFB4 LD (HL),A Else decrement it and jump back to check_zero.
DFB5 POP AF
DFB6 POP HL
DFB7 JR check_zero
animation_delay_timeout DFB9 POP AF Restore object number and preserve position in map_animation_timeout_table.
DFBA PUSH HL
DFBB LD HL,nothing_pointer Set HL to address of first object.
DFBE DEC A Decrement object number (to make first object 0).
DFBF ADD A,A Double it and add to HL.
DFC0 LD B,$00
DFC2 LD C,A
DFC3 ADD HL,BC
DFC4 LD C,(HL) Load object pointer into BC.
DFC5 INC HL
DFC6 LD B,(HL)
DFC7 LD HL,$0016 Load animation delay attribute from object.
DFCA ADD HL,BC
DFCB LD A,(HL)
DFCC EX DE,HL Swap address of delay attribute into DE.
DFCD POP HL Restore position in map_animation_timeout_table and store animation delay there.
DFCE LD (HL),A
DFCF LD BC,$00A0 Add $0A to get corresponding address in map_animation_frame_table and load it.
DFD2 ADD HL,BC
DFD3 LD A,(HL)
DFD4 INC A Increment the frame number.
DFD5 CP $04 If 4 reset to frame 0 (loop the animation).
DFD7 JR NZ,not_4
DFD9 XOR A
not_4 DFDA CP $05 If 5 reset to frame 4 (dead creature sprite).
DFDC JR NZ,not_5
DFDE DEC A
not_5 DFDF LD (HL),A Update value in map_animation_frame_table.
DFE0 EX DE,HL Swap address of animation delay attribute back into HL and increment to address of first sprite pointer.
DFE1 INC HL
DFE2 LD B,$00 Add frame number * 3 to get to required pointer.
DFE4 LD C,A
DFE5 ADD HL,BC
DFE6 ADD HL,BC
DFE7 ADD HL,BC
DFE8 LD C,(HL) Store sprite pointer in C_DATA.
DFE9 INC HL
DFEA LD B,(HL)
DFEB LD (C_DATA),BC
DFEF INC HL Load attribute for sprite and copy to ATTR-T.
DFF0 LD A,(HL)
DFF1 LD ($5C8F),A
DFF4 POP HL Restore position in map_object_table and store in temp_entry_pointer.
DFF5 LD (temp_entry_pointer),HL
DFF8 PUSH HL Convert position to coordinates and store in LC_POS then print the sprite.
DFF9 CALL address_to_coordinate
DFFC LD (LC_POS),HL
DFFF CALL P_CHAR
E002 POP HL
E003 JR check_zero Jump back to check_zero.
Prev: DF4E Up: Map Next: E005