Prev: D9EA Up: Map Next: DA97
DA2A: Cycle Border from Screen
Drives the per-frame border colour cycling effect. Reads successive pixel bytes from the screen buffer pointer at C523 ANDs each byte with 18 to extract the paper colour bits, and writes the result to the border port FE. Between each byte a variable delay is run, its period advanced by the step value at C52B. After the outer loop the frame counter at C527 is decremented; when it reaches the threshold at C52D Entity_State_Flag is set to 01 (step complete). When the frame counter reaches zero, Entity_State_Flag is set to 02 (all complete). The alternate entry at Cycle_Border_Toggle_Loop drives the same counter machinery without sampling screen data, instead XOR-toggling the border between two colours.
Cycle_Border_From_Screen DA2A LD HL,($C523) Load the screen data pointer from C523 and the outer loop count from C529 into B.
DA2D LD A,($C529)
DA30 LD B,A
Cycle_Border_Loop DA31 LD A,$18 Read the next pixel byte, mask to paper bits with 18 and write to the border port FE.
DA33 AND (HL)
DA34 OUT ($FE),A
DA36 INC HL Advance the screen data pointer.
DA37 LD A,($C525) Load the current delay count from C525 into C.
DA3A LD C,A
Cycle_Border_Delay DA3B DEC C Busy-wait for the delay period.
DA3C JR NZ,Cycle_Border_Delay
DA3E LD C,A Reload C, add the step increment from C52B and store the updated delay back to C525.
DA3F LD A,($C52B)
DA42 ADD A,C
DA43 LD ($C525),A
DA46 DJNZ Cycle_Border_Loop Loop back to Cycle_Border_Loop for the next pixel byte.
DA48 LD ($C523),HL Save the updated screen data pointer back to C523.
DA4B LD A,($C527) Decrement the frame counter at C527 and jump to Cycle_Border_Complete if it has reached zero.
DA4E DEC A
DA4F JR Z,Cycle_Border_Complete
DA51 LD ($C527),A Save the decremented frame counter; return if it has not yet reached the completion threshold at C52D.
DA54 LD B,A
DA55 LD A,($C52D)
DA58 CP B
DA59 RET NZ
DA5A LD A,$01 Set Entity_State_Flag to 01 (step complete) and return.
DA5C LD ($C52F),A
DA5F RET
Cycle_Border_Complete DA60 LD A,$02 Set Entity_State_Flag to 02 (all complete) and return.
DA62 LD ($C52F),A
DA65 RET
Alternate entry: toggle the border colour on each pass without reading screen data.
Cycle_Border_Toggle DA66 LD A,($C529) Load the outer loop count from C529 into B and clear A.
DA69 LD B,A
DA6A XOR A
Cycle_Border_Toggle_Loop DA6B XOR %00011000 XOR the border value with 18 to toggle between two colours.
DA6D OUT ($FE),A Write the toggled value to the border port FE and stash it in D.
DA6F LD D,A
DA70 LD A,($C525) Load the delay count from C525 into C.
DA73 LD C,A
Cycle_Border_Toggle_Delay DA74 DEC C Busy-wait for the delay period.
DA75 JR NZ,Cycle_Border_Toggle_Delay
DA77 LD C,A Reload C, add the step increment from C52B and store the updated delay back to C525.
DA78 LD A,($C52B)
DA7B ADD A,C
DA7C LD ($C525),A
DA7F LD A,D Reload the toggled border value from D and loop back to Cycle_Border_Toggle_Loop.
DA80 DJNZ Cycle_Border_Toggle_Loop
DA82 LD A,($C527) Decrement the frame counter at C527 and jump to Cycle_Border_Complete if it has reached zero.
DA85 DEC A
DA86 JR Z,Cycle_Border_Complete
DA88 LD ($C527),A Save the decremented frame counter; return if it has not yet reached the completion threshold at C52D.
DA8B LD B,A
DA8C LD A,($C52D)
DA8F CP B
DA90 RET NZ
DA91 LD A,$01 Set Entity_State_Flag to 01 (step complete) and return.
DA93 LD ($C52F),A
DA96 RET
Prev: D9EA Up: Map Next: DA97