×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

9B1C Detokenise the requested Line Number and Set IWA to the Line Number value

Submitted by Steve Fewell

Starting Address: &9B1C (or 9B1E if &0A doesn't need incrementing)
Entry criteria: &0A and &0B (the PTR A) point to the position on the program line where a Line Number
is expected.
Exit: The IWA contains the detokenised value of the Line Number.
Carry Flag = 1 if a line number was found (and its value is in the IWA).
Carry Flag = 0 if a tokenised line number was not found.
Y contains the offset of the next character after the line number (or the next non-space character if no Line Number was
found.

Description:

If called from &9B1C, increment the PTR A Offset.
Get the next non-space character from Basic text Pointer A (including the offset (&0A)).

If the next character is not #&8D (Line Number token) then goto &9B44 (exit with Carry = 0 ) as there is no
Line Number to detokenise.

Get the next (1st) character from PTR A (the character after the &8D token).
Multiply the ASCII code by 4 (to clear the lower 2-bits, ready to be merged with the next byte).
Store the result in X, to backup current value of the first ASCII code.
AND the ASCII code by #&C0 (1100 0000) to clear all but the top 2 bits.
EOR the ASCII code with the next (2nd) character from PTR A.
Store the result (of the merged first and second bytes) in &2A.
A = X (i.e. the backup value of the Line Number's first ASCII code).
Multiply A by 4 (to clear the top 2-bits).
EOR A with the next (3rd) character from PTR A.
Store the result in &2B.
So, basically, the detokenised line number LSB is the 2nd byte of the line number EORed with bytes 4 and 5 (positioned
in bytes 6 and 7 of the byte) of the 1st byte; and the detokenised line number MSB is the 3rd byte of the
line number EORed with bytes 2 and 3 (positioned in bytes 6 and 7 of the byte) of the 1st byte.

Update PTR A offset to point to the next character after the line number.
Set carry and exit.


Examples:

Example 1: [Line Number = 10]
Tokenised Line value = &8D &54 &4A &40
A = &54. Multiply by 4, now A = &50. X = 50.
AND A with #&C0 -> A = &40.
EOR A with next character [&4A EOR &40] -> A = &0A (Store in &2A).
A = X (&50). Multiply by 4, now A = &40.
EOR A with next character [&40 EOR &40] -> A = &00 (Store in &2B).
Finished. &2A-&2B contains &000A (LSB first) = 10 in decimal.
Example 2: [Line Number = 1816]
Tokenised Line value = &8D &54 &58 &47
A = &54. Multiply by 4, now A = &50. X = 50.
AND A with #&C0 -> A = &40.
EOR A with next character [&58 EOR &40] -> A = &18 (Store in &2A).
A = X (&50). Multiply by 4, now A = &40.
EOR A with next character [&47 EOR &40] -> A = &07 (Store in &2B).
Finished. &2A-&2B contains &0718 (LSB first) = 1816 in decimal.
Example 3: [Line Number = 1000]
Tokenised Line value = &8D &64 &68 &43
A = &64. Multiply by 4, now A = &90. X = 90.
AND A with #&C0 -> A = &80.
EOR A with next character [&68 EOR &80] -> A = &E8 (Store in &2A).
A = X (&90). Multiply by 4, now A = &40.
EOR A with next character [&43 EOR &40] -> A = &03 (Store in &2B).
Finished. &2A-&2B contains &03E8 (LSB first) = 1000 in decimal.
Example 4: [Line Number = 121]
Tokenised Line value = &8D &44 &79 &40
A = &44. Multiply by 4, now A = &10. X = 10.
AND A with #&C0 -> A = &00.
EOR A with next character [&79 EOR &00] -> A = &79 (Store in &2A).
A = X (&10). Multiply by 4, now A = &40.
EOR A with next character [&40 EOR &40] -> A = &00 (Store in &2B).
Finished. &2A-&2B contains &0079 (LSB first) = 121 in decimal.
Example 5: [Line Number = 32766]
Tokenised Line value = &8D &60 &7E &7F
A = &60. Multiply by 4, now A = &80. X = 80.
AND A with #&C0 -> A = &80.
EOR A with next character [&7E EOR &80] -> A = &FE (Store in &2A).
A = X (&80). Multiply by 4, now A = &00.
EOR A with next character [&7F EOR &00] -> A = &7F (Store in &2B).
Finished. &2A-&2B contains &7FFE (LSB first) = 32766 in decimal.


Disassembly for the Detokenise the requested Line Number and Set IWA to the Line Number value routine

9B1C   230 010 E6 0A INC &0A
9B1E   164 010 A4 0A LDY &0A
9B20   177 011 B1 0B LDA (&0B),Y
9B22   201 032 C9 20 CMP#&20
9B24   240 246 F0 F6 BEQ -10 --> &9B1C
9B26   201 141 C9 8D CMP#&8D
9B28   208 026 D0 1A BNE 26 --> &9B44
9B2A   200 C8 INY
9B2B   177 011 B1 0B LDA (&0B),Y
9B2D   010 0A ASL A
9B2E   010 0A ASL A
9B2F   170 AA TAX
9B30 ) 041 192 29 C0 AND#&C0
9B32   200 C8 INY
9B33 Q 081 011 51 0B EOR (&0B),Y
9B35 * 133 042 85 2A STA &2A
9B37   138 8A TXA
9B38   010 0A ASL A
9B39   010 0A ASL A
9B3A   200 C8 INY
9B3B Q 081 011 51 0B EOR (&0B),Y
9B3D + 133 043 85 2B STA &2B
9B3F   200 C8 INY
9B40   132 010 84 0A STY &0A
9B42 8 056 38 SEC
9B43 ` 096 60 RTS
9B44   024 18 CLC
9B45 ` 096 60 RTS

 


 Back to 8BS
Or