×   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

B82A Get Line Number & return the Line Number's Program Address

Submitted by Steve Fewell

Routine:GetLineNumberAddress
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

Description:

Call routine &9B1E to Skip any leading spaces and detokenise the Line Number pointed to by BASIC Text Pointer A.

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)).
[&B836] Now the IWA contains the specified Line Number.
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

B82A   032 030 155 20 1E 9B JSR &9B1E Detokenise the Line Number at PTR A & Set IWA to the Line Number value
B82D   176 007 B0 07 BCS 7 --> &B836 Set &3D-&3E to the IWA Line's Start address & issue error if No Such Line
B82F o 032 111 146 20 6F 92 JSR &926F Evaluate Expression at BASIC Text pointer A convert result to integer
B832   169 128 A9 80 LDA#&80
B834 + 020 043 14 2B TRB &2B
B836   032 205 128 20 CD 80 JSR &80CD Search for Program Line >= the Line Number in the IWA
B839   144 185 90 B9 BCC -71 --> &B7F4 No such line error
B83B ` 096 60 RTS

 


 Back to 8BS
Or