| The Hobbit (v1.0) | Routines |
| Prev: 74B1 | Up: Map | Next: 756B |
|
Prints one word from the dictionary, with the right verb ending and with word wrap. On entry DE holds the word reference: the low nibble of D and all of E are the offset from 6000, and the high nibble of D holds flags. A reference of zero prints nothing.
The letters are unpacked into a buffer at 749D (five-bit letter codes plus $60 give lower-case ASCII), using the usual end-of-word rule (bit 7, but never in the first two bytes).
VERB ENDINGS. The flag nibble decides whether the verb is to agree with a third-person subject: $50 never, $40 always, $10 if the target is not Bilbo, and anything else if the actor is not Bilbo. So one message can say 'you attack thorin' or 'thorin attacks you'. If an ending is needed and the word allows one (bit 7 of its second byte), the top three bits of its third byte choose an ending from the table at B60F: S, ES, IES, a backspace followed by IES (to turn 'carry' into 'carries'), D, or ING.
WORD WRAP. The length of the word, with its ending, is compared with the room left on the line (at 75A8 in the lower window or 768E in the story window). If it will not fit, a new line is started first, keeping the capital-letter flag. A space is printed before the word unless it starts a line.
Words with flag nibble $70 set the capital-letter flag afterwards, so that the next word starts a sentence.
|
||||||||
| 74B8 | LD A,D | Is the word reference zero? | ||||||
| 74B9 | AND $0F | |||||||
| 74BB | OR E | |||||||
| 74BC | RET Z | Yes: nothing to print | ||||||
| 74BD | PUSH HL | |||||||
| 74BE | PUSH BC | |||||||
| 74BF | PUSH DE | |||||||
| 74C0 | LD C,D | C = the flags | ||||||
| 74C1 | LD A,D | DE = the offset... | ||||||
| 74C2 | AND $0F | |||||||
| 74C4 | LD D,A | |||||||
| 74C5 | LD HL,$6000 | ...plus 6000: HL = the word in the dictionary | ||||||
| 74C8 | ADD HL,DE | |||||||
| 74C9 | LD DE,$749D | DE = the letter buffer | ||||||
| 74CC | PUSH HL | |||||||
| 74CD | LD B,$00 | B counts the letters | ||||||
| 74CF | LD A,(HL) | Next letter code | ||||||
| 74D0 | AND $1F | |||||||
| 74D2 | JR Z,$74F0 | 0 (padding): the word has ended | ||||||
| 74D4 | INC B | Count it | ||||||
| 74D5 | ADD A,$60 | Turn it into a lower-case letter | ||||||
| 74D7 | LD (DE),A | Put it in the buffer | ||||||
| 74D8 | INC DE | |||||||
| 74D9 | BIT 7,(HL) | Was it the last letter (bit 7)? | ||||||
| 74DB | INC HL | |||||||
| 74DC | JR Z,$74CF | No: next letter | ||||||
| 74DE | LD A,B | Bit 7 in the first two bytes does not count... | ||||||
| 74DF | CP $02 | |||||||
| 74E1 | JR Z,$74CF | |||||||
| 74E3 | CP $03 | ...and for a two-letter word... | ||||||
| 74E5 | JR NZ,$74F0 | |||||||
| 74E7 | DEC HL | ...look back at the first byte | ||||||
| 74E8 | DEC HL | |||||||
| 74E9 | LD A,(HL) | |||||||
| 74EA | INC HL | |||||||
| 74EB | INC HL | |||||||
| 74EC | BIT 7,A | |||||||
| 74EE | JR NZ,$74CF | |||||||
| 74F0 | POP HL | HL = the start of the word again | ||||||
| 74F1 | LD A,C | What does the flag nibble say about verb endings? | ||||||
| 74F2 | AND $F0 | |||||||
| 74F4 | CP $50 | $50: never add an ending | ||||||
| 74F6 | JR Z,$7527 | |||||||
| 74F8 | CP $40 | $40: always add one | ||||||
| 74FA | JR Z,$7509 | |||||||
| 74FC | CP $10 | $10: add one if the target is not Bilbo | ||||||
| 74FE | LD A,($B5D9) | |||||||
| 7501 | JR Z,$7506 | |||||||
| 7503 | LD A,($B5DB) | Otherwise: add one if the actor is not Bilbo | ||||||
| 7506 | AND A | Bilbo ("you")? | ||||||
| 7507 | JR Z,$7527 | Yes: no ending | ||||||
| 7509 | INC HL | Does the word take an ending (bit 7 of its second byte)? | ||||||
| 750A | BIT 7,(HL) | |||||||
| 750C | JR Z,$7527 | No | ||||||
| 750E | INC HL | The top three bits of its third byte... | ||||||
| 750F | LD A,(HL) | |||||||
| 7510 | AND $E0 | |||||||
| 7512 | RRCA | ...times 4... | ||||||
| 7513 | RRCA | |||||||
| 7514 | RRCA | |||||||
| 7515 | LD L,A | |||||||
| 7516 | LD H,$00 | |||||||
| 7518 | LD BC,$B60F | ...index the table of endings | ||||||
| 751B | ADD HL,BC | |||||||
| 751C | LD B,$04 | Up to four characters | ||||||
| 751E | LD A,(HL) | |||||||
| 751F | AND A | A 0 ends it | ||||||
| 7520 | JR Z,$7527 | |||||||
| 7522 | INC HL | |||||||
| 7523 | LD (DE),A | Add the character to the word | ||||||
| 7524 | INC DE | |||||||
| 7525 | DJNZ $751E | |||||||
| 7527 | LD HL,$749D | B = the length of the word | ||||||
| 752A | EX DE,HL | |||||||
| 752B | AND A | |||||||
| 752C | SBC HL,DE | |||||||
| 752E | LD B,L | |||||||
| 752F | LD A,($B5F2) | Lower window or story window? | ||||||
| 7532 | AND A | |||||||
| 7533 | PUSH AF | |||||||
| 7534 | JR NZ,$753A | |||||||
| 7536 | LD A,($7693) | Story window: is this the start of a line? | ||||||
| 7539 | AND A | |||||||
| 753A | LD A,$20 | If not, print a space first | ||||||
| 753C | CALL NZ,$7580 | |||||||
| 753F | POP AF | |||||||
| 7540 | LD A,($75A8) | A = the room left on the line (lower window)... | ||||||
| 7543 | JR NZ,$7548 | |||||||
| 7545 | LD A,($768E) | ...or in the story window | ||||||
| 7548 | LD HL,$B5F5 | |||||||
| 754B | CP B | Will the word fit? | ||||||
| 754C | JR NC,$7553 | Yes | ||||||
| 754E | LD A,(HL) | No: start a new line, keeping the capital-letter flag | ||||||
| 754F | CALL $7578 | |||||||
| 7552 | LD (HL),A | |||||||
| 7553 | POP DE | Does the word end a sentence (flag nibble $70)? | ||||||
| 7554 | LD A,D | |||||||
| 7555 | AND $F0 | |||||||
| 7557 | CP $70 | |||||||
| 7559 | LD A,$01 | |||||||
| 755B | JR NZ,$755E | |||||||
| 755D | LD (HL),A | Yes: the next word gets a capital | ||||||
| 755E | LD HL,$749D | Print the letters | ||||||
| 7561 | LD A,(HL) | |||||||
| 7562 | CALL $7580 | |||||||
| 7565 | INC HL | |||||||
| 7566 | DJNZ $7561 | |||||||
| 7568 | POP BC | |||||||
| 7569 | POP HL | |||||||
| 756A | RET | |||||||
| Prev: 74B1 | Up: Map | Next: 756B |