Prev: 62F2 Up: Map Next: 6394
6319: Collect A Word
Used by the routine at FinishWord.
Adds the character to the current word. A space, ENTER or a terminator flushes the word, wrapping when it would pass column 2B.
CollectWord 6319 PUSH AF Stash the registers around the word buffer.
631A PUSH HL
631B PUSH BC
631C PUSH DE
631D LD HL,($5B99) Store the character.
6320 LD (HL),A
6321 INC HL Advance the word pointer.
6322 LD ($5B99),HL
6325 LD HL,$5B98 Point HL at WordLength.
6328 INC (HL) Count it.
6329 CP $20 Jump to CollectWord_Flush if it is a space.
632B JR Z,CollectWord_Flush
632D CP $0D Jump to CollectWord_Flush if it is ENTER.
632F JR Z,CollectWord_Flush
6331 CP $5E Jump to CollectWord_Flush if it is 5E.
6333 JR Z,CollectWord_Flush
6335 CP $7E Jump to CollectWord_Flush if it is 7E.
6337 JR Z,CollectWord_Flush
6339 JP PrintCharacter_Done Any other character returns.
Flush the buffered word.
CollectWord_Flush 633C LD HL,$5B98 Point HL at WordLength.
633F CP $5E Jump to CollectWord_Drop if it is 5E.
6341 JR Z,CollectWord_Drop
6343 CP $7E Jump to CollectWord_Drop if it is 7E.
6345 JR Z,CollectWord_Drop
6347 CP $20 A space is not part of the width either.
6349 JR NZ,CollectWord_Width
Drop the terminator from the width.
CollectWord_Drop 634B DEC (HL) Drop that character from the count.
See whether the word fits.
CollectWord_Width 634C PUSH AF Remember the character being flushed.
634D LD A,($5B8A) Call WrapLine when *PrintColumn plus the word would pass 2A.
6350 ADD A,(HL)
6351 CP $2B
6353 CALL NC,WrapLine
6356 POP AF Restore the character from the stack.
6357 LD HL,$5B60 The buffered word starts at WordBuffer.
Print the flushed characters.
CollectWord_Character 635A LD A,(HL) Jump to CollectWord_End if it is not 7E.
635B CP $7E
635D JR NZ,CollectWord_End
635F LD A,$20 Print a space.
6361 CALL PrintCharacter
6364 JR CollectWord_Reset Jump to CollectWord_Reset.
Finish the message or keep printing.
CollectWord_End 6366 CP $5E 5E finishes the message.
6368 JR Z,CollectWord_Newline
636A CP $20 Jump to CollectWord_Break if it is a space.
636C JR Z,CollectWord_Break
636E CP $0D Jump to CollectWord_Break if it is ENTER.
6370 JR Z,CollectWord_Break
6372 CALL PrintCharacter Call PrintCharacter.
6375 INC HL Advance to the next buffered character.
6376 JR CollectWord_Character Jump to CollectWord_Character.
The word does not fit on this row.
WrapLine 6378 LD A,$0D Start a new line.
637A CALL PrintCharacter
637D RET Return.
Start a new line, then reset the word.
CollectWord_Newline 637E PUSH AF Stash the character on the stack.
637F CALL WrapLine Call WrapLine.
6382 POP AF Restore the character from the stack.
6383 JR CollectWord_Reset Jump to CollectWord_Reset.
A space or ENTER is printed before the reset.
CollectWord_Break 6385 CALL PrintCharacter Call PrintCharacter.
Reset the word buffer.
CollectWord_Reset 6388 LD HL,$5B60 Point the next word back at WordBuffer.
638B LD ($5B99),HL
638E XOR A Write 00 to WordLength.
638F LD ($5B98),A
6392 JR PrintCharacter_Done Jump to PrintCharacter_Done.
Prev: 62F2 Up: Map Next: 6394