Prev: 57950 Up: Map Next: 58105
57990: 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 10 times before decoding.
Print_EncodedMessage 57990 PUSH HL Stash HL on the stack.
57991 LD B,10 Load B with 10 flash iterations.
Flash the border and click sound 10 for each of 10 iterations before decoding.
Print_EncodedMessage_FlashLoop 57993 PUSH BC Stash BC on the stack.
57994 LD A,16 Pick a pseudo-random flash/sound parameter via PseudoRandom and store it at 63832.
57996 CALL PseudoRandom
57999 ADD A,20
58001 LD (63832),A
58004 LD A,10 Play sound effect 10 via Queue_Sound / Play_QueuedSound.
58006 CALL Queue_Sound
58009 CALL Play_QueuedSound
58012 POP BC Restore BC from the stack.
58013 DJNZ Print_EncodedMessage_FlashLoop Loop until the flash sequence is done.
58015 POP HL Restore HL from the stack.
Decode the selected fragment into the buffer at PrimaryDisplayBuffer.
58016 LD IX,25504 Point IX at the display buffer (PrimaryDisplayBuffer).
58020 XOR A Clear A, then clear the task progress repeat count (TaskProgressRepeatCount).
58021 LD (29425),A
Resume after a skipped fragment by stepping onto the next encoded block.
Print_EncodedMessage_NextFrag 58024 INC HL Advance past the previous message fragment.
Scan the encoded stream for ` text-start, trigger, indirect, or mask controls.
Print_EncodedMessage_Scan 58025 INC HL Advance the message pointer by one.
58026 LD A,(HL) Fetch the next control/text byte.
58027 CP 96 Is it the text-start marker (`)? If not, try the other controls at Print_EncodedMessage_CheckTrigger.
58029 JR NZ,Print_EncodedMessage_CheckTrigger
58031 INC HL Advance past `.
58032 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 58034 CP 33 Is it a trigger gate (!)? If not, try the indirect-load control at Print_EncodedMessage_CheckIndirect.
58036 JR NZ,Print_EncodedMessage_CheckIndirect
58038 INC HL Advance onto the trigger key.
58039 LD A,(29381) Fetch the message trigger (MessageTrigger). Does it match this fragment's key? If not, keep scanning at Print_EncodedMessage_Scan.
58042 CP (HL)
58043 JR NZ,Print_EncodedMessage_Scan
58045 CALL Skip_ToMessageMarker Call Skip_ToMessageMarker to skip to the next [ then continue with the next fragment at Print_EncodedMessage_NextFrag.
58048 JR Print_EncodedMessage_NextFrag
Indirect-load one byte into TaskProgressRepeatCount from the address that follows ).
Print_EncodedMessage_CheckIndirect 58050 CP 41 Is it an indirect-load control ())? If not, treat it as a mask byte at Print_EncodedMessage_CheckMask.
58052 JR NZ,Print_EncodedMessage_CheckMask
58054 INC HL Fetch the address word, read that byte into TaskProgressRepeatCount, and continue scanning at Print_EncodedMessage_Scan.
58055 LD C,(HL)
58056 INC HL
58057 LD B,(HL)
58058 LD A,(BC)
58059 LD (29425),A
58062 JR Print_EncodedMessage_Scan
Keep the fragment only when its mask ANDs non-zero with the colour mask in MessageColour.
Print_EncodedMessage_CheckMask 58064 LD A,(29419) Fetch the message colour/mask (MessageColour). AND with this fragment's mask byte. If nothing matches, skip to Print_EncodedMessage_Scan.
58067 AND (HL)
58068 JR Z,Print_EncodedMessage_Scan
58070 CALL Skip_ToMessageMarker Call Skip_ToMessageMarker to skip to the next [ then continue with the next fragment at Print_EncodedMessage_NextFrag.
58073 JR Print_EncodedMessage_NextFrag
Copy literal characters into PrimaryDisplayBuffer until ] (or a $ alternate).
Print_EncodedMessage_CopyText 58075 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.
58076 LD (IX+0),A
58079 INC IX
58081 INC HL
58082 CP 36
58084 JR Z,Print_EncodedMessage_SkipAlternate
58086 CP 93 Is it the message terminator (])? If so, jump to Paint_MessageBuffer to paint the buffer. Otherwise keep copying at Print_EncodedMessage_CopyText.
58088 JR Z,Paint_MessageBuffer
58090 JR Print_EncodedMessage_CopyText
Take the $ alternate key and search for the matching [ fragment.
Print_EncodedMessage_SkipAlternate 58092 LD A,(HL) Fetch the alternate key byte, then keep it in C.
58093 LD C,A
Walk successive [ markers until the alternate key matches, then resume at Print_EncodedMessage_Scan.
Print_EncodedMessage_SkipAlternateLoop 58094 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.
58097 INC HL
58098 LD A,(HL)
58099 CP C
58100 JR NZ,Print_EncodedMessage_SkipAlternateLoop
58102 JP Print_EncodedMessage_Scan Jump to Print_EncodedMessage_Scan to resume scanning after the chosen alternate.
Prev: 57950 Up: Map Next: 58105