Prev: 25330 Up: Map Next: 25492
25369: 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 43.
CollectWord 25369 PUSH AF Save the registers around the word buffer.
25370 PUSH HL
25371 PUSH BC
25372 PUSH DE
25373 LD HL,(23449) Store the character and advance the word pointer.
25376 LD (HL),A
25377 INC HL
25378 LD (23449),HL
25381 LD HL,23448 Count it.
25384 INC (HL)
25385 CP 32 A space or ENTER flushes the word.
25387 JR Z,CollectWord_Flush
25389 CP 13
25391 JR Z,CollectWord_Flush
25393 CP 94 94 or 126 flushes it too.
25395 JR Z,CollectWord_Flush
25397 CP 126
25399 JR Z,CollectWord_Flush
25401 JP PrintCharacter_Done Any other character returns.
CollectWord_Flush 25404 LD HL,23448 Point at the length.
25407 CP 94 94 or 126 is not part of the width.
25409 JR Z,CollectWord_Drop
25411 CP 126
25413 JR Z,CollectWord_Drop
25415 CP 32 A space is not part of the width either.
25417 JR NZ,CollectWord_Width
CollectWord_Drop 25419 DEC (HL) Drop that character from the count.
CollectWord_Width 25420 PUSH AF Remember the character being flushed.
25421 LD A,(23434) Wrap when the column plus the word would pass 42.
25424 ADD A,(HL)
25425 CP 43
25427 CALL NC,WrapLine Call WrapLine when the word does not fit.
25430 POP AF Restore the character from the stack.
25431 LD HL,23392 The buffered word starts at WordBuffer.
CollectWord_Character 25434 LD A,(HL) 126 is printed as a space and finishes the message.
25435 CP 126
25437 JR NZ,CollectWord_End
25439 LD A,32 Print that space and finish.
25441 CALL PrintCharacter
25444 JR CollectWord_Reset
CollectWord_End 25446 CP 94 94 finishes the message.
25448 JR Z,CollectWord_Newline
25450 CP 32 A space or ENTER finishes after it is printed.
25452 JR Z,CollectWord_Break
25454 CP 13
25456 JR Z,CollectWord_Break
25458 CALL PrintCharacter Print this character and continue the word.
25461 INC HL
25462 JR CollectWord_Character
The word does not fit on this row.
WrapLine 25464 LD A,13 Start a new line.
25466 CALL PrintCharacter
25469 RET Return.
CollectWord_Newline 25470 PUSH AF 94 starts a new line and then resets the word.
25471 CALL WrapLine
25474 POP AF
25475 JR CollectWord_Reset
CollectWord_Break 25477 CALL PrintCharacter A space or ENTER is printed before the reset.
CollectWord_Reset 25480 LD HL,23392 Point the next word back at WordBuffer.
25483 LD (23449),HL
25486 XOR A Clear the length and restore the registers.
25487 LD (23448),A
25490 JR PrintCharacter_Done
Prev: 25330 Up: Map Next: 25492