Prev: 52344 Up: Map Next: 52619
52354: Dispatch The Character Script
Used by the routine at ProcessScriptCommandWithCounter.
Gets the character's script position and dispatches the next command.
DispatchCharacterScript 52354 LD L,(IY+1) Get the character's script position.
52357 LD H,(IY+2)
52360 XOR A Clear the display.
52361 LD (47412),A
52364 LD A,(52235) Jump to TerminateCharacterScript if the script command counter at 52235 is 10.
52367 CP 10
52369 JP Z,TerminateCharacterScript
DispatchCharacterScript_NextByte 52372 LD A,(HL) Jump ahead to DispatchCharacterScript_UseCommand if this byte is not zero.
52373 AND A
52374 JR NZ,DispatchCharacterScript_UseCommand
52376 INC HL Jump back to DispatchCharacterScript_NextByte to find next command.
52377 JR DispatchCharacterScript_NextByte
Use the saved pointer as the character record, then record the pointer in the currently processed character command position at CurrentCharacter_CommandPosition, then keep bits 0-3.
Process the current script command.
DispatchCharacterScript_UseCommand 52379 PUSH HL Record the current character command position.
52380 POP IX
52382 LD (40921),HL
52385 AND %00001111 Keep the script command number (the low nibble).
52387 CP 10 Jump to DispatchCharacterScript_TestGoto when the command is at least 10.
52389 JR NC,DispatchCharacterScript_TestGoto
52391 LD A,(52237) Go to DispatchCharacterScript_DispatchOpcode unless the display-list flag at 52237 is 1.
52394 CP 1
52396 JR NZ,DispatchCharacterScript_DispatchOpcode
52398 SUB A Clear the display-list flag at 52237.
52399 LD (52237),A
The room display asked to skip?
52402 LD A,(HL) Read this script byte, call ProcessScriptDisplay, and jump to 52625 if it returns carry.
52403 CALL ProcessScriptDisplay
52406 JP C,52625
52409 JR Z,DispatchCharacterScript_DispatchOpcode Go to DispatchCharacterScript_DispatchOpcode if ProcessScriptDisplay returns zero.
Did ProcessDisplayAction accept this display?
52411 CALL ProcessDisplayAction Return if ProcessDisplayAction does not accept this display.
52414 RET NC
52415 CALL FindCharacterScriptEntry Call FindCharacterScriptEntry to find the character script, then write 2 into the object attribute.
52418 LD (IX+5),2
52422 RET Return.
Reads one command byte from the character script and dispatches it. Command 7 refreshes the room display.
DispatchCharacterScript_DispatchOpcode 52423 LD A,(HL) Get the command byte.
52424 AND %00001111 Extract the command type.
52426 CP 7 Jump ahead to HandleRoomDisplay when the command is 7.
52428 JP Z,HandleRoomDisplay
52431 CP 6 Jump ahead to PrintCommandMessage when the command is 6.
52433 JP Z,PrintCommandMessage
52436 CP 5 Jump ahead to ShowRoomDescription when the command is 5.
52438 JP Z,ShowRoomDescription
52441 CP 4 Jump ahead to 52671 when the command is 4.
52443 JP Z,52671
52446 CP 1 Jump ahead to RunSimpleAction when the command is 1.
52448 JP Z,RunSimpleAction
52451 CP 3 Jump ahead to ClearRoomDisplayParameters when the command is 3.
52453 JP Z,ClearRoomDisplayParameters
52456 CP 8 Jump ahead to DispatchCharacterScript_Push when the command is 8.
52458 JR Z,DispatchCharacterScript_Push
52460 CP 9 Jump ahead to DispatchCharacterScript_Pop when the command is 9.
52462 JR Z,DispatchCharacterScript_Pop
52464 JP 52760 Jump ahead to 52760 to handle display room description.
Handles command Type 14/12/11/10.
DispatchCharacterScript_TestGoto 52467 CP 14 Jump to DispatchCharacterScript_TestStop when the command is not 14.
52469 JR NZ,DispatchCharacterScript_TestStop
52471 LD A,(IX+1) Copy IX+1 into IY+1.
52474 LD (IY+1),A
52477 LD A,(IX+2) Copy the script position into the character record and parse again from DispatchCharacterScript.
52480 LD (IY+2),A
52483 JP DispatchCharacterScript
Command 12 repeats, and command 11 copies the script pointer, returning when it is 2.
DispatchCharacterScript_TestStop 52486 CP 12 See whether the command is 12.
DispatchCharacterScript_0 52488 JR Z,DispatchCharacterScript_0 Jump back to DispatchCharacterScript_0 if the command is 12.
52490 CP 11 Jump to DispatchCharacterScript_TestNested when the command is not 11.
52492 JR NZ,DispatchCharacterScript_TestNested
52494 CALL GetScriptPointer Call GetScriptPointer and return when it reports 2.
52497 CP 2
52499 RET Z
52500 JP ContinueScriptExecution Jump ahead to ContinueScriptExecution to resume script execution.
Command 10 copies it is 2.
DispatchCharacterScript_TestNested 52503 CP 10 Jump to DispatchCharacterScript_MarkError when the command is not 10.
52505 JR NZ,DispatchCharacterScript_MarkError
52507 CALL GetScriptPointer Call GetScriptPointer and return when it reports 2.
52510 CP 2
52512 RET Z
52513 JP ProcessScriptCommandWithCounter Jump ahead to ProcessScriptCommandWithCounter to run script command with counter.
Handles push Stack.
DispatchCharacterScript_Push 52516 LD A,(IX+1) Read the moved marker and use 2 for the record, then call AllocateMemory to allocate memory.
52519 PUSH AF
52520 LD A,2
52522 CALL AllocateMemory
52525 LD HL,(40935) Read the saved pointer.
52528 LD (40935),IX
52532 LD (IX-2),L Store the low byte of the pointer in the previous record.
52535 LD (IX-1),H Store the high byte of the pointer in the previous record.
52538 LD A,(41014) Write *CurrentCharacter_ID to *IX+0.
52541 LD (IX+0),A
52544 POP AF Restore AF from the stack.
52545 LD (IX+1),A Store A at offset 1 and jump to ContinueScriptExecution.
52548 JP ContinueScriptExecution
Handles pop Stack.
DispatchCharacterScript_Pop 52551 LD B,(IX+1) Use the character list pointer at CharacterListPointer.
52554 LD IX,40937
DispatchCharacterScript_Loop 52558 CALL FetchObjectPointerFromStack Go to ProcessScriptCommandWithCounter if the object pointer is zero.
52561 JP Z,ProcessScriptCommandWithCounter
52564 LD A,(41014) Jump back to DispatchCharacterScript_Loop while this id does not match the moved marker.
52567 CP (IX+1)
52570 JR NZ,DispatchCharacterScript_Loop
52572 LD A,B Jump back to DispatchCharacterScript_Loop while this id does not match the record's flag byte.
52573 CP (IX+0)
52576 JR NZ,DispatchCharacterScript_Loop
52578 PUSH IY Save the schedule entry.
52580 PUSH IX Copy the character record from IX into DE.
52582 POP DE
52583 LD IY,40935 Use the saved pointer (40935).
Step pointer and compare.
52587 CALL IncrementPointerAndCompare Call IncrementPointerAndCompare to compare the pointer with the next record.
52590 LD L,(IX-2) Read the pointer saved ahead of this record.
52593 LD H,(IX-1)
52596 LD (IY-2),L Store the low byte of the pointer in the previous record.
52599 LD (IY-1),H Store the high byte of the link and call ProcessMemoryEntry.
52602 CALL ProcessMemoryEntry
52605 POP IY
52607 JP ContinueScriptExecution Jump ahead to ContinueScriptExecution to resume script execution.
Sets character Script Error.
Set script completion flag.
DispatchCharacterScript_MarkError 52610 LD HL,1 Write 0001 to *CharacterScriptCycles.
52613 LD (40991),HL
52616 JP ContinueScriptExecution Jump ahead to ContinueScriptExecution to resume script execution.
Prev: 52344 Up: Map Next: 52619