Prev: 43100 Up: Map Next: 43311
43136: Extract Token From Text
Input
HL Pointer to text data
Output
DE Token value (word)
HL Updated pointer
Read the token value from the text data.
ExtractTokenFromText 43136 LD E,(HL) E=*HL (load the first byte of the token into E).
43137 INC HL Increment HL by one (move to the second byte).
43138 LD A,(HL) A=*HL (load the second byte of the token into A).
43139 INC HL Increment HL by one (advance the text pointer past the token).
43140 AND %00001111 Keep only bits 0-3 (extract the low nibble from the second byte).
43142 LD D,A D=A (store the low nibble in D).
PrintTextToken 43143 LD A,(23612) Return if *TV-FLAG is not set.
43146 AND A
43147 RET Z
43148 LD (40994),DE Write DE (the token value) to *TokenValueBuffer.
Check if this is a simple token that doesn't need further processing.
43152 LD A,D A=D (load the low nibble into A).
43153 AND %00001111 Keep only bits 0-3 (ensure we have just the low nibble).
43155 OR E Set the bits from E (merge with the first byte).
43156 RET Z Return if this is a simple token (HL equals E).
43157 PUSH IX Stash IX, HL, BC and DE on the stack.
43159 PUSH HL
43160 PUSH BC
43161 PUSH DE
Process the token format and prepare for dictionary lookup.
43162 LD A,32 A=32 (load space character code).
43164 CALL Print_Character Call Print_Character to print the space character.
43167 LD A,D A=D (load the token byte).
43168 AND %11110000 Keep only bits 4-7 (extract the high nibble).
43170 LD C,A Compare C (the high nibble) with 112.
43171 CP 112
Prepare to set a flag if the token format is 112.
43173 LD A,1 A=1.
43175 JR NZ,ExtractTokenFromText_ProcessToken Jump to ExtractTokenFromText_ProcessToken if the token format is not 112.
43177 LD (40998),A Write A to *TokenFormatFlag (set a flag for this token format).
ExtractTokenFromText_ProcessToken 43180 LD A,D A=D (restore the token byte).
43181 AND %00001111 Keep only bits 0-3 (extract the low nibble).
43183 LD D,A D=A (store the low nibble in D).
43184 EX DE,HL Exchange the DE and HL registers (swap token and text pointer).
43185 PUSH HL Stash HL (the text pointer) on the stack.
43186 LD A,H A=H (load the high byte of the token).
43187 OR C Set the bits from C (merge with the format bits).
43188 LD H,A H=A (store the modified high byte).
43189 LD (40994),HL Write HL (the modified token) to *TokenValueBuffer.
43192 POP HL Restore HL (the text pointer) from the stack.
43193 PUSH BC Stash BC on the stack.
Search the word index table for the token value.
43194 LD IX,23936 IX=Table_WordIndex (load the address of the word index table).
43198 LD B,95 B=95 (initialise the search index).
ExtractTokenFromText_SearchLoop 43200 INC B Increment B by one (move to the next entry).
43201 LD A,(IX+1) Jump to ExtractTokenFromText_ContinueSearch if the high byte of the table entry is less than H (token high byte).
43204 CP H
43205 JR C,ExtractTokenFromText_ContinueSearch
43207 JR NZ,ExtractTokenFromText_FoundEntry Jump to ExtractTokenFromText_FoundEntry if the high byte doesn't match (IX+1 is not equal to H).
43209 LD A,(IX+0) Jump to ExtractTokenFromText_FoundEntry if the low byte is too high (IX+0 is greater than or equal to L).
43212 CP L
43213 JR NC,ExtractTokenFromText_FoundEntry
ExtractTokenFromText_ContinueSearch 43215 INC IX Increment IX by two (move to the next table entry).
43217 INC IX
43219 LD A,B Jump to ExtractTokenFromText_SearchLoop if we haven't reached the end of the table (B is not equal to 123).
43220 CP 123
43222 JR NZ,ExtractTokenFromText_SearchLoop
43224 INC B Increment B by one (adjust for end of table).
ExtractTokenFromText_FoundEntry 43225 JR Z,ExtractTokenFromText_GetWordAddress Jump to ExtractTokenFromText_GetWordAddress if no matching entry was found (B is zero).
ExtractTokenFromText_BackupEntry 43227 DEC IX Decrease IX by two (back up to the matching entry).
43229 DEC IX
43231 DEC B Decrease B by one (adjust the index).
ExtractTokenFromText_GetWordAddress 43232 LD E,(IX+0) Load the word address from the table entry into DE.
43235 LD D,(IX+1)
43238 LD A,D Jump to ExtractTokenFromText_BackupEntry until we find a non-zero word address (DE is zero).
43239 OR E
43240 JR Z,ExtractTokenFromText_BackupEntry
Print the word from the dictionary.
43242 LD A,B A=B (load the word index).
43243 CALL Print_Character Call Print_Character to print the word character.
43246 LD BC,23999 HL+=23999 (add the dictionary base address to get the word data pointer).
43249 ADD HL,BC
43250 PUSH HL Stash HL (the word data pointer) on the stack.
43251 EX DE,HL Exchange the DE and HL registers (swap word address and word data pointer).
43252 ADD HL,BC HL+=BC (add the offset to the word data).
ExtractTokenFromText_PrintWordContinue 43253 PUSH HL Stash HL (the calculated word data address) on the stack.
ExtractTokenFromText_PrintWordLoop 43254 AND A HL-=DE (with carry) (calculate the remaining length).
43255 SBC HL,DE
43257 POP HL Restore HL (the word data address) from the stack.
43258 PUSH AF Stash AF (the length comparison result) on the stack.
43259 CALL ProcessFormatDataByte Call ProcessFormatDataByte to print characters from the word.
43262 POP AF Restore AF (the length comparison result) from the stack.
43263 JR NZ,ExtractTokenFromText_PrintWordContinue Jump to ExtractTokenFromText_PrintWordContinue if there are more characters to print (B is not equal to A).
43265 POP HL Restore HL and BC from the stack.
43266 POP BC
Handle special token format cases.
43267 LD A,C Jump to ExtractTokenFromText_PrintRemainingText if the token format is 80.
43268 CP 80
43270 JR Z,ExtractTokenFromText_PrintRemainingText
43272 CP 64 Jump to ExtractTokenFromText_ProcessFormat if the token format is 64.
43274 JR Z,ExtractTokenFromText_ProcessFormat
Check if the token format is 16 (requires special handling).
43276 CP 16 Compare C (the token format) with 16.
43278 LD A,(41012) A=*RoomDisplayParameter (load the room display parameter).
43281 JR Z,ExtractTokenFromText_Format10 Jump to ExtractTokenFromText_Format10 if the token format is 16.
43283 LD A,(41014) Load A with *CurrentCharacter_ID.
ExtractTokenFromText_Format10 43286 AND A Jump to ExtractTokenFromText_PrintRemainingText (skip format processing for format 16).
43287 JR Z,ExtractTokenFromText_PrintRemainingText
ExtractTokenFromText_ProcessFormat 43289 CALL ProcessTextTokenFormat Call ProcessTextTokenFormat to process the text token format.
ExtractTokenFromText_PrintRemainingText 43292 LD HL,23618 HL=NEWPPC.
ExtractTokenFromText_PrintLoop 43295 LD A,(HL) Load a byte from *NEWPPC.
43296 AND A Jump to ExtractTokenFromText_End if we've reached the end of the text (A is zero).
43297 JR Z,ExtractTokenFromText_End
43299 CALL Print_Character Call Print_Character to print the character.
43302 INC HL Increment HL by one (move to the next character).
43303 JR ExtractTokenFromText_PrintLoop Jump to ExtractTokenFromText_PrintLoop to continue printing.
All text printed - restore registers and return.
ExtractTokenFromText_End 43305 POP DE Restore DE, BC, HL and IX from the stack.
43306 POP BC
43307 POP HL
43308 POP IX
43310 RET Return.
Prev: 43100 Up: Map Next: 43311