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 Save the registers around the word buffer.
631A PUSH HL
631B PUSH BC
631C PUSH DE
631D LD HL,($5B99) Store the character and advance the word pointer.
6320 LD (HL),A
6321 INC HL
6322 LD ($5B99),HL
6325 LD HL,$5B98 Count it.
6328 INC (HL)
6329 CP $20 A space or ENTER flushes the word.
632B JR Z,CollectWord_Flush
632D CP $0D
632F JR Z,CollectWord_Flush
6331 CP $5E 5E or 7E flushes it too.
6333 JR Z,CollectWord_Flush
6335 CP $7E
6337 JR Z,CollectWord_Flush
6339 JP PrintCharacter_Done Any other character returns.
CollectWord_Flush 633C LD HL,$5B98 Point at the length.
633F CP $5E 5E or 7E is not part of the width.
6341 JR Z,CollectWord_Drop
6343 CP $7E
6345 JR Z,CollectWord_Drop
6347 CP $20 A space is not part of the width either.
6349 JR NZ,CollectWord_Width
CollectWord_Drop 634B DEC (HL) Drop that character from the count.
CollectWord_Width 634C PUSH AF Remember the character being flushed.
634D LD A,($5B8A) Wrap when the column plus the word would pass 2A.
6350 ADD A,(HL)
6351 CP $2B
6353 CALL NC,WrapLine Call WrapLine when the word does not fit.
6356 POP AF Restore the character from the stack.
6357 LD HL,$5B60 The buffered word starts at WordBuffer.
CollectWord_Character 635A LD A,(HL) 7E is printed as a space and finishes the message.
635B CP $7E
635D JR NZ,CollectWord_End
635F LD A,$20 Print that space and finish.
6361 CALL PrintCharacter
6364 JR CollectWord_Reset
CollectWord_End 6366 CP $5E 5E finishes the message.
6368 JR Z,CollectWord_Newline
636A CP $20 A space or ENTER finishes after it is printed.
636C JR Z,CollectWord_Break
636E CP $0D
6370 JR Z,CollectWord_Break
6372 CALL PrintCharacter Print this character and continue the word.
6375 INC HL
6376 JR 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.
CollectWord_Newline 637E PUSH AF 5E starts a new line and then resets the word.
637F CALL WrapLine
6382 POP AF
6383 JR CollectWord_Reset
CollectWord_Break 6385 CALL PrintCharacter A space or ENTER is printed before the reset.
CollectWord_Reset 6388 LD HL,$5B60 Point the next word back at WordBuffer.
638B LD ($5B99),HL
638E XOR A Clear the length and restore the registers.
638F LD ($5B98),A
6392 JR PrintCharacter_Done
Prev: 62F2 Up: Map Next: 6394