Prev: 74BA Up: Map Next: 7574
74C1: Print Token
Input
DE The token.
PrintToken 74C1 LD A,D Take the token's high byte.
74C2 AND %00001111 Keep its low nibble (bits 8-11 of the token).
74C4 OR E Merge in the low byte.
74C5 RET Z Return if bits 0-11 of the token are all zero.
74C6 PUSH HL Save the text pointer, BC and the token, and keep the class in C.
74C7 PUSH BC
74C8 PUSH DE
74C9 LD C,D
74CA LD A,D Take the token's high byte again.
74CB AND $0F Keep bits 8-11 of the token in D.
74CD LD D,A
74CE LD HL,$6000 Add the token index to the pointer.
74D1 ADD HL,DE
74D2 LD DE,$74A6 Point DE at output buffer.
74D5 PUSH HL Save the dictionary address and start the letter count at zero.
74D6 LD B,$00
PrintToken_Loop 74D8 LD A,(HL) Read the next byte of the dictionary word.
74D9 AND $1F Jump to PrintToken_ChooseTheSubject if the low five bits of this dictionary byte are zero.
74DB JR Z,PrintToken_ChooseTheSubject
74DD INC B Count one more character of the message.
74DE ADD A,$60 Add 60 to A to convert to ASCII.
74E0 LD (DE),A Store the result in the output buffer.
74E1 INC DE Increase the output buffer pointer by one.
74E2 BIT 7,(HL) Check if this is the last character in it.
74E4 INC HL Increase the character pointer reference by one.
74E5 JR Z,PrintToken_Loop If this is not the last character in it, loop back to PrintToken_Loop to continue processing.
Check minimum length.
74E7 LD A,B Copy the count in B into A.
74E8 CP $02 If the number of characters is only 02 then jump back to PrintToken_Loop to continue processing.
74EA JR Z,PrintToken_Loop
74EC CP $03 If it is not 03, then jump to PrintToken_ChooseTheSubject.
74EE JR NZ,PrintToken_ChooseTheSubject
74F0 DEC HL Otherwise fetch the second character again and test its bit 7.
74F1 DEC HL
74F2 LD A,(HL)
74F3 INC HL
74F4 INC HL
74F5 BIT 7,A
74F7 JR NZ,PrintToken_Loop Loop back to PrintToken_Loop to continue processing if bit 7 of the second character is set.
PrintToken_ChooseTheSubject 74F9 POP HL Jump to PrintToken_MeasureTheOutput if the high nibble of the result is 50.
74FA LD A,C
74FB AND $F0
74FD CP $50
74FF JR Z,PrintToken_MeasureTheOutput
7501 CP $40 Jump to PrintToken_ExpandTheVerbEnding if the high nibble of the result is 40.
7503 JR Z,PrintToken_ExpandTheVerbEnding
7505 CP $10 Take the current object, and jump to PrintToken_TestForThePlayer if the high nibble of the result is 10.
7507 LD A,($B6E8)
750A JR Z,PrintToken_TestForThePlayer
750C LD A,($B6EA) Read *CurrentCharacter.
PrintToken_TestForThePlayer 750F AND A Jump to PrintToken_MeasureTheOutput if the subject in A is the player (id 00).
7510 JR Z,PrintToken_MeasureTheOutput
PrintToken_ExpandTheVerbEnding 7512 INC HL Jump to PrintToken_MeasureTheOutput if the token index is not a class token.
7513 BIT 7,(HL)
7515 JR Z,PrintToken_MeasureTheOutput
7517 INC HL Step to the next byte of the token index.
7518 LD A,(HL) Read the token index.
7519 AND $E0 Shift the top three bits down by three places. That index, times four, selects an ending in B71F.
751B RRCA
751C RRCA
751D RRCA
751E LD L,A The shifted index is the low byte of the pointer.
751F LD H,$00 The pointer's high byte is zero.
7521 LD BC,$B71F Add the verb-ending table at B71F.
7524 ADD HL,BC
7525 LD B,$04 Copy at most 04 bytes of the ending.
PrintToken_CopyTheEnding 7527 LD A,(HL) Jump to PrintToken_MeasureTheOutput if the token index is zero.
7528 AND A
7529 JR Z,PrintToken_MeasureTheOutput
752B INC HL Step to the next byte of the token index.
752C LD (DE),A Store it at OutputBuffer and step on.
752D INC DE
752E DJNZ PrintToken_CopyTheEnding Loop back to PrintToken_CopyTheEnding until 04 runs out.
PrintToken_MeasureTheOutput 7530 LD HL,$74A6 Point HL at output buffer.
7533 EX DE,HL Swap the print pointer with the start of the output buffer.
7534 AND A Clear carry before measuring how far the print pointer has moved.
7535 SBC HL,DE See how far the pointer is past OutputBuffer.
7537 LD B,L Keep the length just measured, and read the action countdown.
7538 LD A,($B701)
753B AND A See whether the action countdown is zero.
753C PUSH AF Jump to PrintToken_PrintASpace if the action countdown is not zero.
753D JR NZ,PrintToken_PrintASpace
753F LD A,($86A0) Read the character flag.
7542 AND A See whether the character flag is zero.
PrintToken_PrintASpace 7543 LD A,$20 Take 20, and call Print_Character to print it if the action countdown or the character flag is not zero.
7545 CALL NZ,Print_Character
7548 POP AF Take the characters left on the line from 85B3, and jump to PrintToken_FitOnTheLine if the action countdown is not zero.
7549 LD A,($85B3)
754C JR NZ,PrintToken_FitOnTheLine
754E LD A,($869B) Read the room left on the line at PrintWriteACharacterToTheScreen.
PrintToken_FitOnTheLine 7551 LD HL,$B704 Jump to PrintToken_TestTheClassNibble if A is not below the character count. A is *85B3 when the action countdown is not zero, and the room left on the line otherwise.
7554 CP B
7555 JR NC,PrintToken_TestTheClassNibble
7557 LD A,(HL) Save the capitalise-the-next-letter flag.
Print a newline.
7558 CALL Print_LineBreak Call Print_LineBreak to print a newline.
755B LD (HL),A Put the capitalise-the-next-letter flag back as it was before the newline.
PrintToken_TestTheClassNibble 755C POP DE Take 01 and jump to PrintToken_Print unless the high nibble of D is 70.
755D LD A,D
755E AND $F0
7560 CP $70
7562 LD A,$01
7564 JR NZ,PrintToken_Print
7566 LD (HL),A Set the capitalise-the-next-letter flag.
PrintToken_Print 7567 LD HL,$74A6 Point HL at output buffer.
PrintToken_Print_Loop 756A LD A,(HL) Fetch the next character from the output buffer.
756B CALL Print_Character Call Print_Character to print one character.
756E INC HL Increase the output buffer pointer by one.
756F DJNZ PrintToken_Print_Loop Decrease counter by one and loop back to PrintToken_Print_Loop until counter is zero.
7571 POP BC Restore BC and HL from the stack.
7572 POP HL
7573 RET Return.
Prev: 74BA Up: Map Next: 7574