Prev: E25E Up: Map Next: E2F9
E286: Print Encoded Message
Print one […] encoded message at HL. First runs a short border/sound flash, then filters control bytes into the display buffer at PrimaryDisplayBuffer and jumps to Paint_MessageBuffer to paint it. Control bytes before ` gate fragments by MessageTrigger / MessageColour; + starts a new row; $ marks an alternate fragment.
Input
HL Address of an encoded message (starts at [)
Flash / click 0A times before decoding.
Print_EncodedMessage E286 PUSH HL Stash HL on the stack.
E287 LD B,$0A Load B with 0A flash iterations.
Flash the border and click sound 0A for each of 0A iterations before decoding.
Print_EncodedMessage_FlashLoop E289 PUSH BC Stash BC on the stack.
E28A LD A,$10 Pick a pseudo-random flash/sound parameter via PseudoRandom and store it at F958.
E28C CALL PseudoRandom
E28F ADD A,$14
E291 LD ($F958),A
E294 LD A,$0A Play sound effect 0A via Queue_Sound / Play_QueuedSound.
E296 CALL Queue_Sound
E299 CALL Play_QueuedSound
E29C POP BC Restore BC from the stack.
E29D DJNZ Print_EncodedMessage_FlashLoop Loop until the flash sequence is done.
E29F POP HL Restore HL from the stack.
Decode the selected fragment into the buffer at PrimaryDisplayBuffer.
E2A0 LD IX,$63A0 Point IX at the display buffer (PrimaryDisplayBuffer).
E2A4 XOR A Clear A, then clear the task progress repeat count (TaskProgressRepeatCount).
E2A5 LD ($72F1),A
Resume after a skipped fragment by stepping onto the next encoded block.
Print_EncodedMessage_NextFrag E2A8 INC HL Advance past the previous message fragment.
Scan the encoded stream for ` text-start, trigger, indirect, or mask controls.
Print_EncodedMessage_Scan E2A9 INC HL Advance the message pointer by one.
E2AA LD A,(HL) Fetch the next control/text byte.
E2AB CP $60 Is it the text-start marker (`)? If not, try the other controls at Print_EncodedMessage_CheckTrigger.
E2AD JR NZ,Print_EncodedMessage_CheckTrigger
E2AF INC HL Advance past `.
E2B0 JR Print_EncodedMessage_CopyText Jump to Print_EncodedMessage_CopyText to copy literal text into the buffer.
Gate this fragment on the message trigger in MessageTrigger matching !'s key.
Print_EncodedMessage_CheckTrigger E2B2 CP $21 Is it a trigger gate (!)? If not, try the indirect-load control at Print_EncodedMessage_CheckIndirect.
E2B4 JR NZ,Print_EncodedMessage_CheckIndirect
E2B6 INC HL Advance onto the trigger key.
E2B7 LD A,($72C5) Fetch the message trigger (MessageTrigger). Does it match this fragment's key? If not, keep scanning at Print_EncodedMessage_Scan.
E2BA CP (HL)
E2BB JR NZ,Print_EncodedMessage_Scan
E2BD CALL Skip_ToMessageMarker Call Skip_ToMessageMarker to skip to the next [ then continue with the next fragment at Print_EncodedMessage_NextFrag.
E2C0 JR Print_EncodedMessage_NextFrag
Indirect-load one byte into TaskProgressRepeatCount from the address that follows ).
Print_EncodedMessage_CheckIndirect E2C2 CP $29 Is it an indirect-load control ())? If not, treat it as a mask byte at Print_EncodedMessage_CheckMask.
E2C4 JR NZ,Print_EncodedMessage_CheckMask
E2C6 INC HL Fetch the address word, read that byte into TaskProgressRepeatCount, and continue scanning at Print_EncodedMessage_Scan.
E2C7 LD C,(HL)
E2C8 INC HL
E2C9 LD B,(HL)
E2CA LD A,(BC)
E2CB LD ($72F1),A
E2CE JR Print_EncodedMessage_Scan
Keep the fragment only when its mask ANDs non-zero with the colour mask in MessageColour.
Print_EncodedMessage_CheckMask E2D0 LD A,($72EB) Fetch the message colour/mask (MessageColour). AND with this fragment's mask byte. If nothing matches, skip to Print_EncodedMessage_Scan.
E2D3 AND (HL)
E2D4 JR Z,Print_EncodedMessage_Scan
E2D6 CALL Skip_ToMessageMarker Call Skip_ToMessageMarker to skip to the next [ then continue with the next fragment at Print_EncodedMessage_NextFrag.
E2D9 JR Print_EncodedMessage_NextFrag
Copy literal characters into PrimaryDisplayBuffer until ] (or a $ alternate).
Print_EncodedMessage_CopyText E2DB LD A,(HL) Fetch the next text byte. Store it in the display buffer through IX. Advance the buffer pointer. Advance the message pointer. Is it an alternate-fragment marker ($)? If so, handle it at Print_EncodedMessage_SkipAlternate.
E2DC LD (IX+$00),A
E2DF INC IX
E2E1 INC HL
E2E2 CP $24
E2E4 JR Z,Print_EncodedMessage_SkipAlternate
E2E6 CP $5D Is it the message terminator (])? If so, jump to Paint_MessageBuffer to paint the buffer. Otherwise keep copying at Print_EncodedMessage_CopyText.
E2E8 JR Z,Paint_MessageBuffer
E2EA JR Print_EncodedMessage_CopyText
Take the $ alternate key and search for the matching [ fragment.
Print_EncodedMessage_SkipAlternate E2EC LD A,(HL) Fetch the alternate key byte, then keep it in C.
E2ED LD C,A
Walk successive [ markers until the alternate key matches, then resume at Print_EncodedMessage_Scan.
Print_EncodedMessage_SkipAlternateLoop E2EE CALL Skip_ToMessageMarker Call Skip_ToMessageMarker to find the next [. Step onto the key after that marker. Fetch it. Does it match the alternate key? If not, keep searching at Print_EncodedMessage_SkipAlternateLoop.
E2F1 INC HL
E2F2 LD A,(HL)
E2F3 CP C
E2F4 JR NZ,Print_EncodedMessage_SkipAlternateLoop
E2F6 JP Print_EncodedMessage_Scan Jump to Print_EncodedMessage_Scan to resume scanning after the chosen alternate.
Prev: E25E Up: Map Next: E2F9