Routines
| Prev: A9B5 | Up: Map | Next: AA14 |
A9B7: Print character A, a word at a time (word wrap)
|
Every character the message interpreter prints comes here. Unless quoted printing is on ($A027: straight to C1E1), characters are collected in the buffer at $5C0B, a backspace (8) taking the last one off again - which is how suffixes such as '<delete>IES' work. A space, a carriage return or a quote mark ends the word: if the word is longer than the count at C1F5 allows, a new line is started first, and then the word is sent to AA14 character by character. AA14 turns letters to lower case and drops spaces at the start of a line ($A025 = 0 there).
How it works:
2. A space, carriage return or quote ends a word. Any other character is added to the word buffer at $5C0B; a delete removes the last letter.
3. When a word ends: if it does not fit on the rest of the line (C1F5), start a new line first. Then print the word, and then the character that ended it.
|
||||||||||||
| A9B7 | PUSH AF | Save AF on the stack - Quoted printing on? | ||||||||||
| A9B8 | LD A,($A027) | Read $A027 in "Game variables" into A | ||||||||||
| A9BB | AND A | Test A for zero (this leaves A as it was and clears carry) | ||||||||||
| A9BC | JR NZ,$AA10 | If A is not zero, jump on to AA10 - Yes: print it as it is | ||||||||||
| A9BE | POP AF | Restore AF from the stack | ||||||||||
| A9BF | PUSH AF | Save AF on the stack | ||||||||||
| A9C0 | PUSH HL | Save HL on the stack | ||||||||||
| A9C1 | LD HL,($A9B5) | The end of the word so far | ||||||||||
| A9C4 | CP $20 | Compare A with $20 - A space... | ||||||||||
| A9C6 | JR Z,$A9DF | If A equals $20, skip ahead to A9DF | ||||||||||
| A9C8 | CP $0D | Compare A with $0D - ...a carriage return... | ||||||||||
| A9CA | JR Z,$A9DF | If A equals $0D, skip ahead to A9DF | ||||||||||
| A9CC | CP $22 | Compare A with $22 - ...or a quote mark ends the word | ||||||||||
| A9CE | JR Z,$A9DF | If A equals $22, skip ahead to A9DF | ||||||||||
| A9D0 | CP $08 | Compare A with $08 - A delete... | ||||||||||
| A9D2 | JR NZ,$A9D7 | If A differs from $08, skip ahead to A9D7 | ||||||||||
| A9D4 | DEC HL | Step HL back one byte - ...takes the last letter back | ||||||||||
| A9D5 | JR $A9D9 | Skip ahead to A9D9 | ||||||||||
| A9D7 | LD (HL),A | Store A at the address HL points to - Otherwise add the letter | ||||||||||
| A9D8 | INC HL | Step HL on to the next byte | ||||||||||
| A9D9 | LD ($A9B5),HL | Store HL in "Word buffer pointer for A9B7" (A9B5) | ||||||||||
| A9DC | POP HL | Restore HL from the stack | ||||||||||
| A9DD | POP AF | Restore AF from the stack | ||||||||||
| A9DE | RET | Return to the caller | ||||||||||
| A9DF | PUSH DE | Save DE on the stack - An empty word? | ||||||||||
| A9E0 | LD DE,$5C0B | Point DE at the tape header workspace ($5C0B) | ||||||||||
| A9E3 | AND A | Clear the carry flag, so that the subtraction that follows is a plain one (a compare) | ||||||||||
| A9E4 | SBC HL,DE | Subtract DE from HL (a compare: carry = HL was smaller, zero = equal) | ||||||||||
| A9E6 | JR Z,$AA0B | If the two values are equal, skip ahead to AA0B | ||||||||||
| A9E8 | LD A,($C1F5) | Read the characters left on the line (C1F5) into A - Does the word fit? | ||||||||||
| A9EB | CP L | Compare A with L | ||||||||||
| A9EC | PUSH AF | Save AF on the stack | ||||||||||
| A9ED | JR NC,$A9F4 | If A is L or more, skip ahead to A9F4 | ||||||||||
| A9EF | LD A,$0D | Load A with $0D - No: new line first | ||||||||||
| A9F1 | CALL $AA14 | Call the routine "Send one character to the screen layer" (AA14) | ||||||||||
| A9F4 | PUSH BC | Save BC on the stack - Send the word out | ||||||||||
| A9F5 | LD B,L | Copy L into B | ||||||||||
| A9F6 | LD HL,$5C0B | Point HL at the tape header workspace ($5C0B) | ||||||||||
| A9F9 | LD ($A9B5),HL | Store HL in "Word buffer pointer for A9B7" (A9B5) | ||||||||||
| A9FC | LD A,(HL) | Read the byte HL points at into A | ||||||||||
| A9FD | CALL $AA14 | Call the routine "Send one character to the screen layer" (AA14) | ||||||||||
| AA00 | INC HL | Step HL on to the next byte | ||||||||||
| AA01 | DJNZ $A9FC | Count B down and, while it is not zero, go back to A9FC | ||||||||||
| AA03 | POP BC | Restore BC from the stack | ||||||||||
| AA04 | POP AF | Restore AF from the stack | ||||||||||
| AA05 | JR NZ,$AA0B | If the zero flag is clear, skip ahead to AA0B | ||||||||||
| AA07 | XOR A | Clear A to zero (and the carry flag) | ||||||||||
| AA08 | LD ($A025),A | Store A in $A025 in "Game variables" | ||||||||||
| AA0B | POP DE | Restore DE from the stack - ...then the character that ended it | ||||||||||
| AA0C | POP HL | Restore HL from the stack | ||||||||||
| AA0D | POP AF | Restore AF from the stack | ||||||||||
| AA0E | JR $AA14 | Skip ahead to the routine "Send one character to the screen layer" (AA14) | ||||||||||
| AA10 | POP AF | Restore AF from the stack | ||||||||||
| AA11 | JP $C1E1 | Jump on to the routine "Print gatekeeper: check two flags, then dispatch" (C1E1) | ||||||||||
| Prev: A9B5 | Up: Map | Next: AA14 |