Prev: E512 Up: Map Next: E5B0
E53C: Handler: Cursor Movement
Handler_CursorMovement E53C CALL FetchTileObject Call FetchTileObject.
E53F LD A,($D82C) Write *DestinationCursor_Y_Position to *StorageCursor_Y_Position.
E542 LD ($D830),A
E545 LD A,($D82D) Write *DestinationCursor_X_Position to *StorageCursor_X_Position.
E548 LD ($D831),A
E54B LD A,R A=the contents of the Memory Refresh Register.
E54D RLCA Multiply A by 02 and store the result in L.
E54E LD L,A
E54F LD H,$00 H=00.
E551 LD B,$46 Set a counter in B for the first outer loop.
E553 LD D,$05 Set a counter in D for the first inner loop.
CursorMovement_SoundLoop_01 E555 LD A,(HL) Fetch a byte from the ZX Spectrum ROM and store it in A.
E556 AND %00011000 Keep only bits 3-4.
E558 OR %00000101 Set bits 0, 2.
E55A OUT ($FE),A Send to the speaker.
E55C INC HL Increment the ROM pointer by one.
E55D PUSH BC Stash the outer loop counter on the stack.
E55E LD B,D Set B to the inner loop counter held by D.
CursorMovement_DelayLoop_01 E55F DJNZ CursorMovement_DelayLoop_01 Decrease the inner loop counter by one and loop back to CursorMovement_DelayLoop_01 until the counter is zero.
E561 POP BC Restore the outer loop counter from the stack.
E562 DJNZ CursorMovement_SoundLoop_01 Decrease the outer loop counter by one and loop back to CursorMovement_SoundLoop_01 until the counter is zero.
E564 HALT Halt operation (suspend CPU until the next interrupt).
Update the cursor position.
E565 LD A,($D82C) Jump to Handler_CursorMovement_1 if *DestinationCursor_Y_Position is equal to *CurrentCursor_Y_Position.
E568 LD HL,$D82E
E56B CP (HL)
E56C JR Z,Handler_CursorMovement_1
E56E JP P,Handler_CursorMovement_0 Jump to Handler_CursorMovement_0 if *DestinationCursor_Y_Position is greater than or equal to *CurrentCursor_Y_Position.
E571 DEC (HL) Decrease *CurrentCursor_Y_Position by one.
E572 JR Handler_CursorMovement_1 Jump to Handler_CursorMovement_1.
Handler_CursorMovement_0 E574 INC (HL) Increment *HL by one.
Handler_CursorMovement_1 E575 LD A,($D82D) Jump to Handler_CursorMovement_3 if *DestinationCursor_X_Position is equal to *CurrentCursor_X_Position.
E578 LD HL,$D82F
E57B CP (HL)
E57C JR Z,Handler_CursorMovement_3
E57E JP P,Handler_CursorMovement_2 Jump to Handler_CursorMovement_2 if *DestinationCursor_X_Position is greater than or equal to *CurrentCursor_X_Position.
E581 DEC (HL) Decrease *CurrentCursor_X_Position by one.
E582 JR Handler_CursorMovement_3 Jump to Handler_CursorMovement_3.
Handler_CursorMovement_2 E584 INC (HL) Increment *HL by one.
Handler_CursorMovement_3 E585 LD A,($D82E) Jump to Handler_CursorMovement if *CurrentCursor_Y_Position is not equal to *DestinationCursor_Y_Position.
E588 LD HL,$D82C
E58B CP (HL)
E58C JR NZ,Handler_CursorMovement
E58E LD A,($D82F) Jump to Handler_CursorMovement if *CurrentCursor_X_Position is not equal to *DestinationCursor_X_Position.
E591 LD HL,$D82D
E594 CP (HL)
E595 JR NZ,Handler_CursorMovement
The final sound effect when the cursor reaches its destination.
E597 LD A,R Set the lower byte in L, which for randomness is the contents of the Memory Refresh Register.
E599 LD L,A
E59A LD H,$0A Set the upper byte of the sound data address (00A00-00AFF).
E59C LD B,$23 Set a counter in B for the second outer loop.
E59E LD C,$64 Set a counter in C for the second inner loop.
CursorMovement_SoundLoop_02 E5A0 LD A,(HL) Fetch a byte from the ZX Spectrum ROM and store it in A.
E5A1 INC HL Increment the ROM pointer by one.
E5A2 AND %00011000 Keep only bits 3-4.
E5A4 OR %00000101 Set bits 0, 2.
E5A6 OUT ($FE),A Send to the speaker.
E5A8 PUSH BC Stash the outer loop counter on the stack.
E5A9 LD B,C Set B to the inner loop counter held by C.
CursorMovement_DelayLoop_02 E5AA DJNZ CursorMovement_DelayLoop_02 Decrease the inner loop counter by one and loop back to CursorMovement_DelayLoop_02 until counter is zero.
E5AC POP BC Restore the outer loop counter from the stack.
E5AD DJNZ CursorMovement_SoundLoop_02 Decrease the outer loop counter by one and loop back to CursorMovement_SoundLoop_02 until the counter is zero.
E5AF RET Return.
Prev: E512 Up: Map Next: E5B0