8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

B39A LIST

Submitted by Steve Fewell

Description:

Zero &3B (FOR counter) & &3C (REPEAT counter).

Obtain the "list from" line number after the LIST token (if specified), as follows:
Set the IWA to zero.
Call &9B1E to set the IWA to the untokenised Line number value based on the tokenised Line Number at BASIC Text
pointer A (if any found; otherwise, the IWA will retain the value 0).
Store the processor flags (PHP) on the 6502 stack (for future checking).
Push the IWA value to the BASIC Stack.

Obtain the "list to" line number after the LIST token (if specified), as follows:
Set the IWA to -1 (&FFFFFFFF) (true).
Shift right the 2nd byte of the IWA (byte &2B), so that the first 2 bytes of the IWA contain the maximum Line Number
value: &7FFF.
Retrieve the processor flags from the stack and check the carry flag as follows:
   -->If carry is set (the first Line Number was specified) then check for a second (To) line number as follows:
      * Check whether the next non-space character (after the "from Line number") is a comma ','.
      * If comma found then check for a "To Line Number":
          * [&B3C6] Call &9B1E to set the IWA to the untokenised Line number value based on the tokenised Line Number at BASIC Text
            pointer A (if any found; otherwise, the IWA will retain the value &7FFF).
          * Store the IWA value ("To Line Number") at locations &31-&34.
          * If the next non-space character if 'IF-token' then set the BASIC text Pointer A to point to the next non-space character
            (and set PTR A offset to 1); otherwise, [&B3F3] Check for the end of statement ('Syntax error' if not terminated correctly).
      * If comma not found then, a single Line has been specified, so:
          * Retrieve the "from Line Number" IWA value from the BASIC Stack.
          * Store the "from Line Number" to the BASIC Stack again (keeping the IWA set to the "From Line Number" value).
          * Decrement the BASIC Text pointer A offset.
          * [&B3C9] Store the IWA value (the "From Line Number" specified) at locations &31-&34 (the "To Line Number").
          * If the next non-space character if 'IF-token' then set the BASIC text Pointer A to point to the next non-space character
            (and set PTR A offset to 1); otherwise, [&B3F3] Check for the end of statement ('Syntax error' if not terminated correctly).
   -->If carry was not set (the first Line Number wasn't specified) then check for a second (To) line number as follows:
      * Check whether the next non-space character (after the "from Line number") is a comma ','.
      * If comma found then check for a "To Line Number":
          * [&B3C6] Call &9B1E to set the IWA to the untokenised Line number value based on the tokenised Line Number at BASIC Text
            pointer A (if any found; otherwise, the IWA will retain the value &7FFF).
          * Store the IWA value ("To Line Number") at locations &31-&34.
          * If the next non-space character if 'IF-token' then set the BASIC text Pointer A to point to the next non-space character
            (and set PTR A offset to 1); otherwise, [&B3F3] Check for the end of statement ('Syntax error' if not terminated correctly).
      * If comma not found then:
          * [&B3C4] Decrement the BASIC Text Pointer A offset and jump to &B3C9.
          * [&B3C9] Store the IWA value ("To Line Number" - &7FFF) at locations &31-&34.
          * If the next non-space character if 'IF-token' then set the BASIC text Pointer A to point to the next non-space character
            (and set PTR A offset to 1); otherwise, [&B3F3] Check for the end of statement ('Syntax error' if not terminated correctly).

Now, BASIC Text pointer A points to the Next command line statement and BASIC text pointer B points to the 'IF' part of the
List Statement.
[&B3F6] Set BASIC Text Pointer B (LSB) to BASIC Text Pointer A (LSB).
Call routine &BDE5 to check that the program can be read correctly (display the warning message 'Bad program' if the
program is corrupt and cannot be read correctly).

Retrieve the Integer value from the BASIC Stack into the IWA. This is the minimum line number value.
Call routine &80CD to find the first program line that is greater than or equal to the IWA value.
Set text pointer A to the address of the first program line returned by the &80CD routine.

If the line is not equal to the one we want (carry is 0) then:
* [&B40D] Decrement the Y offset value, so that Y = 1
* [&B41F] Set the IWA to the next line number found (the 2-byte line number pointed to by PTR A + offset 1)
Compare the current Line number (in the IWA) with the Maximum line number (bytes &31-&32).
If the current line number is greater than the IWA Line number then we have reached the end of the LIST selection, so:
* Check the LISTO flag (&1F). If the flag is not negative then we are not in 'EDIT' mode, so jump to &8F86 to
   return to the command line prompt and await the user's next command entry.
* Otherwise, we are in 'EDIT' mode, and now that the program (in ASCII text) has been copied to memory we can load
   the editor application to enable the user to edit the program text.
* To do this, Set X (LSB) and Y (MSB) to point to address &B389, which contains the text "EDIT 12,2" + CHR$(13),
   and jump to the OSCLI (Operating System Command Line Interface) routine to execute the command at &B389.
* The BASIC language has now been exited, and will not be reloaded until the EDITOR exits back to the language.
Otherwise, the line number is within the specified range, so continue to display the line (in ASCII text) to the screen
(or memory if we are in EDIT mode!).

Zero locations &4C (ignore program text status) and &4D (meets IF condition status).
Store 4 in the BASIC Text pointer A offset and the BASIC text pointer B offset (to skip over the line number).
If &3B (FOR loop counter) is negative (encountered NEXT without a FOR) then zero location &3B.
If &3C (REPEAT loop counter) is negative (encountered UNTIL without a REPEAT) then zero location &3C.

[&B454] Process the LISTO spacing for the current Program Line, as follows:
Read the next character on the program line. If it is '<cr>' then jump to &B491 (Print program line).
If the current character on the program line is 'REM-token' then Store #&F4 in location &4C (ignore program text flag),
as the rest of the line is to be ignored as far as the LISTO spacing is concerned.

If the current character on the program line is '"' [quote] then EOR #&22 with the current value of location &4C
(ignore program text), i.e.: if we were inside a String-literal quote then the EOR would set &4C back to zero (stop
ignoring Program text); and if we weren't inside a String-literal then the EOR would set the &4C flag to #&22,
specifying that the rest of the text should be ignored until the end of the String-literal is found.

Check the Ignore Program Text flag (location &4C). If it is zero then we are not ignoring text, so set the loop
counters as follows:
* If the current character on the program line is 'NEXT-token' then decrement the FOR-loop counter (&3B)
* If the current character on the program line is 'UNTIL-token' then decrement the REPEAT-loop counter (&3C)
[&B476] Check the IF condition:
Set X to &19 (BASIC Text Pointer B LSB) - this location is used to store the current Command line (&700-&7FF) offset.
[&B478] Load the next character (after the IF keyword [if specified]) on the Command line). If it is '<cr>' then the
'IF' condition has been checked (and matches the text at the current location on the Program Line), so store #&0D in
location &4D (a non-zero value means that the 'IF' condition has passed), increment &1B (Program Line offset), set Y
to the &1B value and jump back to &B454 to continue checking the program line.
Compare each character of the 'IF'-condition text (at &700 + X) with the next character of the Program Line (&0B,&0C) + Y,
incrementing X and Y for each character checked. Keep checking [from &B478] until we find a mismatch or until the '<cr>'
character of the 'IF'-condition is reached.

If a mismatch is found then do not alter the &4D value (so that it remains as zero - meaning that the 'IF' test wasn't
passed), increment &1B (the Program Line offset [position of the current character on the Program Line]), set Y to the
&1B value and jump to &B454 to continue checking the program line.

[&B491] Print the program Line:
If the 'IF' condition flag (&4D) is zero then the 'IF' condition does not match the current line, so jump back to
&B41C to advance the (&0A, &0B) pointer to the next program line and [&B41F] continue processing with the
next program line.

Call the &A085 routine to display the Line Number (in the IWA) on the screen.

The user may specify that none, one or many of the different LISTO spacing options should be used, these are now checked.
Check LISTO option#1 as follows:
Set A to 1 and increment X to 1 [X is 0 after call the &A085 routine] which specifies the number of spaces to print if
the current LISTO option is met. And set the carry flag.
Call routine &BDB4 to check whether the LISTO option#1 is set (in the LISTO flag, &1F), if it is then X number of
spaces will be printed to the screen.

Check LISTO option#2 as follows:
Set A to 2 and set X to the value of location &3B (the FOR-loop counter) which specifies the number of spaces to print if
the current LISTO option is met. And set the carry flag.
Call routine &BDB3 to check whether the LISTO option#2 is set (in the LISTO flag, &1F), if it is then X number of
spaces will be printed to the screen.

Check LISTO option#4 as follows:
Set A to 4 and set X to the value of location &3C (the REPEAT-loop counter) which specifies the number of spaces to print if
the current LISTO option is met. And set the carry flag.
Call routine &BDB3 to check whether the LISTO option#4 is set (in the LISTO flag, &1F), if it is then X number of
spaces will be printed to the screen.

Zero flag &4C (the program text ignore flag).
Reset Y (Program Line offset) to the first character of the Program Line (from location &0A).
[&B4B1] Load the next character of the program line.
If the current character is '<cr>' then the line has been printed, so jump back to &B410 to do the following:
* Output the '<cr>' character to the screen (or to memory if we are in EDIT mode)
* If we are not in EDIT mode then also output a Linefeed character (ASCII &0A) to the screen
* Call &9BBC to increment the pointer (&0A, &0B) to the next program line
* Continue with &B41F to process the next program line
If the current character on the program line is '"' [quote] then EOR #&22 with the current value of location &4C
(ignore program text), i.e.: if we were inside a String-literal quote then the EOR would set &4C back to zero (stop
ignoring Program text); and if we weren't inside a String-literal then the EOR would set the &4C flag to #&22,
specifying that the rest of the text should be ignored until the end of the String-literal is found. Output the quote
character to the screen, increment Y (to point to the next character) and jump back to &B4B1 to check and output the
next character.

[&B4C7] If the ignore program text flag contains a value (&4C) then:
* [&B4C1] Call &BD94 to output the current character to the screen (or to memory if we are in EDIT mode)
* Increment Y (to point to the next character)
* Jump back to &B4B1 to check and output the next character
If the current character on the program line is a Line Number token (#&8D) then:
* Call &9B2A to load the next character and set &2A-&2B to the value of the tokenised Line Number held
   in the next 3 characters.
* Store the updated offset (Y) back in location &0A (PTR A offset)
* Call &A081 to output the Line number to the screen (or memory if we are in EDIT mode)
* Jump back to &A4DF to Load Y with the updated &0A value and [&B4B1] process the next character
If the current character on the program line is 'FOR-token' then increment the FOR-loop counter (at location &3B).
If the current character on the program line is 'REPEAT-token' then increment the REPEAT-loop counter (at location &3C).
If the current character on the program line is 'REM-token' then set the ignore program text flag (&4C) to #&F4,
causing the rest of the line to be ignored as far as LISTO space formatting is concerned.

Call routine &BD37 to output the current character/token to the screen (or to memory if we are in EDIT mdoe).
Increment Y (to point to the next character on the program line) and jump back to &B4B1 to process the next character.


Disassembly for the LIST - parameters routine

B39A d; 100 059 64 3B STZ &3B
B39C d< 100 060 64 3C STZ &3C
B39E   032 232 171 20 E8 AB JSR &ABE8 Set IWA to FALSE (0)
B3A1   032 030 155 20 1E 9B JSR &9B1E Detokenise the Line Number at PTR A & Set IWA to the Line Number value
B3A4   008 08 PHP
B3A5 & 032 038 188 20 26 BC JSR &BC26 Push IWA value to the BASIC Stack [pushi]
B3A8   032 219 171 20 DB AB JSR &ABDB Set IWA to TRUE (-1)
B3AB F+ 070 043 46 2B LSR &2B
B3AD ( 040 28 PLP
B3AE   144 015 90 0F BCC 15 --> &B3BF
B3B0   032 229 140 20 E5 8C JSR &8CE5 Compare next non-space [PTR A] character with ','
B3B3   240 017 F0 11 BEQ 17 --> &B3C6
B3B5   032 230 188 20 E6 BC JSR &BCE6 Retrieve IWA value from the BASIC Stack [popi]
B3B8 & 032 038 188 20 26 BC JSR &BC26 Push IWA value to the BASIC Stack [pushi]
B3BB   198 010 C6 0A DEC &0A
B3BD   128 010 80 0A BRA 10 --> &B3C9
B3BF   032 229 140 20 E5 8C JSR &8CE5 Compare next non-space [PTR A] character with ','
B3C2   240 002 F0 02 BEQ 2 --> &B3C6
B3C4   198 010 C6 0A DEC &0A
B3C6   032 030 155 20 1E 9B JSR &9B1E Detokenise the Line Number at PTR A & Set IWA to the Line Number value
B3C9 1 162 049 A2 31 LDX#&31
B3CB   032 198 189 20 C6 BD JSR &BDC6 Store Integer (IWA) to zero page location (specified by X)
B3CE   032 224 142 20 E0 8E JSR &8EE0 Get next non-space character pointed to by Ptr A
B3D1   201 231 C9 E7 CMP#&E7
B3D3   208 030 D0 1E BNE 30 --> &B3F3
B3D5   032 224 142 20 E0 8E JSR &8EE0 Get next non-space character pointed to by Ptr A
B3D8   032 188 155 20 BC 9B JSR &9BBC Update BASIC Text pointer A (Add offset value & then reset offset to 1)
B3DB   128 025 80 19 BRA 25 --> &B3F6

Disassembly for the LIST - listing routine

B3F3   032 176 155 20 B0 9B BRA 26 --> &9BB0 Check for end of Statement
B3F6   165 011 A5 0B LDA &0B
B3F8   133 025 85 19 STA &19
B3FA   032 229 189 20 E5 BD JSR &BDE5 Check program can be read correctly ('Bad program' message if not)
B3FD   032 230 188 20 E6 BC JSR &BCE6 Retrieve IWA value from the BASIC Stack [popi]
B400   032 205 128 20 CD 80 JSR &80CD Search for Program Line >= the Line Number in the IWA
B403 = 165 061 A5 3D LDA &3D
B405   133 011 85 0B STA &0B
B407 > 165 062 A5 3E LDA &3E
B409   133 012 85 0C STA &0C
B40B   176 027 B0 1B BCS 27 --> &B428
B40D   136 88 DEY
B40E   128 015 80 0F BRA 15 --> &B41F
B410   032 148 189 20 94 BD JSR &BD94 Output character to the screen
B413 $ 036 031 24 1F BIT &1F
B415 0 048 005 30 05 BMI 5 --> &B41C
B417   169 010 A9 0A LDA#&0A
B419   032 238 255 20 EE FF JSR &FFEE   OSWRCH
B41C   032 188 155 20 BC 9B JSR &9BBC Update BASIC Text pointer A (Add offset value & then reset offset to 1)
B41F   177 011 B1 0B LDA (&0B),Y
B421 + 133 043 85 2B STA &2B
B423   200 C8 INY
B424   177 011 B1 0B LDA (&0B),Y
B426 * 133 042 85 2A STA &2A
B428 * 165 042 A5 2A LDA &2A
B42A   024 18 CLC
B42B 1 229 049 E5 31 SBC &31
B42D + 165 043 A5 2B LDA &2B
B42F 2 229 050 E5 32 SBC &32
B431   144 011 90 0B BCC 11 --> &B43E
B433 $ 036 031 24 1F BIT &1F
B435   016 185 10 B9 BPL -71 --> &B3F0
B437   162 137 A2 89 LDX#&89
B439   160 179 A0 B3 LDY#&B3
B43B L 076 247 255 4C F7 FF JMP &FFF7   OSCLI
B43E dL 100 076 64 4C STZ &4C
B440 dM 100 077 64 4D STZ &4D
B442   160 004 A0 04 LDY#&04
B444   132 010 84 0A STY &0A
B446   132 027 84 1B STY &1B
B448 $; 036 059 24 3B BIT &3B
B44A   016 002 10 02 BPL 2 --> &B44E
B44C d; 100 059 64 3B STZ &3B
B44E $< 036 060 24 3C BIT &3C
B450   016 002 10 02 BPL 2 --> &B454
B452 d< 100 060 64 3C STZ &3C
B454   177 011 B1 0B LDA (&0B),Y
B456   201 013 C9 0D CMP#&0D
B458 7 240 055 F0 37 BEQ 55 --> &B491
B45A   201 244 C9 F4 CMP#&F4
B45C   240 006 F0 06 BEQ 6 --> &B464
B45E " 201 034 C9 22 CMP#&22
B460   208 004 D0 04 BNE 4 --> &B466
B462 EL 069 076 45 4C EOR &4C
B464 L 133 076 85 4C STA &4C
B466 L 166 076 A6 4C LDX &4C
B468   208 012 D0 0C BNE 12 --> &B476
B46A   201 237 C9 ED CMP#&ED
B46C   208 002 D0 02 BNE 2 --> &B470
B46E ; 198 059 C6 3B DEC &3B
B470   201 253 C9 FD CMP#&FD
B472   208 002 D0 02 BNE 2 --> &B476
B474 < 198 060 C6 3C DEC &3C
B476   166 025 A6 19 LDX &19
B478   189 000 007 BD 00 07 LDA &0700,X
B47B   201 013 C9 0D CMP#&0D
B47D   240 010 F0 0A BEQ 10 --> &B489
B47F   209 011 D1 0B CMP (&0B),Y
B481   208 008 D0 08 BNE 8 --> &B48B
B483   200 C8 INY
B484   232 E8 INX
B485   128 241 80 F1 BRA -15 --> &B478
B487   128 135 80 87 BRA -121 --> &B410
B489 M 133 077 85 4D STA &4D
B48B   230 027 E6 1B INC &1B
B48D   164 027 A4 1B LDY &1B
B48F   128 195 80 C3 BRA -61 --> &B454
B491 M 165 077 A5 4D LDA &4D
B493   240 135 F0 87 BEQ -121 --> &B41C
B495   032 133 160 20 85 A0 JSR &A085 Print Line Number on screen (width 5)
B498   169 001 A9 01 LDA#&01
B49A   232 E8 INX
B49B 8 056 38 SEC
B49C   032 180 189 20 B4 BD JSR &BDB4 AND value in A with LISTO option (&1F), Output (result divided by 2 + carry*&80) number of spaces
B49F ; 166 059 A6 3B LDX &3B
B4A1   169 002 A9 02 LDA#&02
B4A3   032 179 189 20 B3 BD JSR &BDB3 AND value in A with LISTO option (&1F), Output (result divided by 2) number of spaces
B4A6 < 166 060 A6 3C LDX &3C
B4A8   169 004 A9 04 LDA#&04
B4AA   032 179 189 20 B3 BD JSR &BDB3 AND value in A with LISTO option (&1F), Output (result divided by 2) number of spaces
B4AD dL 100 076 64 4C STZ &4C
B4AF   164 010 A4 0A LDY &0A
B4B1   177 011 B1 0B LDA (&0B),Y
B4B3   201 013 C9 0D CMP#&0D
B4B5   240 208 F0 D0 BEQ -48 --> &B487
B4B7 " 201 034 C9 22 CMP#&22
B4B9   208 012 D0 0C BNE 12 --> &B4C7
B4BB EL 069 076 45 4C EOR &4C
B4BD L 133 076 85 4C STA &4C
B4BF " 169 034 A9 22 LDA#&22
B4C1   032 148 189 20 94 BD JSR &BD94 Output character to the screen
B4C4   200 C8 INY
B4C5   128 234 80 EA BRA -22 --> &B4B1
B4C7 L 166 076 A6 4C LDX &4C
B4C9   208 246 D0 F6 BNE -10 --> &B4C1
B4CB   201 141 C9 8D CMP#&8D
B4CD   208 010 D0 0A BNE 10 --> &B4D9
B4CF * 032 042 155 20 2A 9B JSR &9B2A Detokenise Line Number at PTR A (without skip spaces or skip #&8D char) & Set IWA to the Line Number value
B4D2   132 010 84 0A STY &0A
B4D4   032 129 160 20 81 A0 JSR &A081 Print Line Number on screen (width 0)
B4D7   128 214 80 D6 BRA -42 --> &B4AF
B4D9   201 227 C9 E3 CMP#&E3
B4DB   208 002 D0 02 BNE 2 --> &B4DF
B4DD ; 230 059 E6 3B INC &3B
B4DF   201 245 C9 F5 CMP#&F5
B4E1   208 002 D0 02 BNE 2 --> &B4E5
B4E3 < 230 060 E6 3C INC &3C
B4E5   201 244 C9 F4 CMP#&F4
B4E7   208 002 D0 02 BNE 2 --> &B4EB
B4E9 L 133 076 85 4C STA &4C
B4EB 7 032 055 189 20 37 BD JSR &BD37 Output Character/Token on screen
B4EE   200 C8 INY
B4EF   128 192 80 C0 BRA -64 --> &B4B1

 


 Back to 8BS
Or