The BBC and Master Computer Public Domain Library
Page Last Altered:
B82A Get Line Number & return the Line Number's Program Address
Submitted by Steve Fewell
Name: Get Program Line Number and Program Address
Starting Address: &B82A
Entry criteria: The BASIC Text Pointer A points to a tokenised Line Number
Exit: Locations &3D-&3E contain a pointer to the specified Line Number's start address location within
the Program Code
Call routine &9B1E to Skip any leading spaces and detokenise the Line Number pointed to by BASIC Text Pointer A.
[&B836] Now the IWA contains the specified Line Number.
If a Line Number was not found (carry flag is not set) then, the Line Number is probably a variable or calculation, so:
- * Call routine &926F to evaluate the expression at BASIC Text Pointer A & convert the result to Integer
- * The IWA should now contain the Line Number value. Only 16-Bits of the IWA value will be used (that is
- locations &2A-&2B). As the Line Number cannot be greater than 32767, reset bit 7 (#&80)
- of the Line Number high-byte (location &2B) to reduce the number to a valid Line Number
- value (if it was > 32767 (#&7FFF)).
Call routine &80CD to search for the first program line that is greater than or equal to the Line Number specified
in the IWA.
If &80CD returned with the Carry flag clear, then the specified line was not found in the program, so issue
'No such line' error, as we are unable to perform an operation on a Line that doesn't exist in the Program.
Otherwise exit with &3D-&3E containing a pointer to the specified Line Number's start address location within
the Program Code.
Disassembly for the Get Line Number & return the Line Number's Program Address routine
||032 030 155
||20 1E 9B
||JSR &9B1E Detokenise the Line Number at PTR A & Set IWA to the Line Number value
||BCS 7 --> &B836 Set &3D-&3E to the IWA Line's Start address & issue error if No Such Line
||032 111 146
||20 6F 92
||JSR &926F Evaluate Expression at BASIC Text pointer A convert result to integer
||032 205 128
||20 CD 80
||JSR &80CD Search for Program Line >= the Line Number in the IWA
||BCC -71 --> &B7F4 No such line error