×   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

BA98 Remove the Line Number (specified in the IWA) from the program

Submitted by Steve Fewell

Routine:RemoveLine
Name: Remove Line Number from Program
Starting Address: &BA98
Entry criteria: The IWA contains the Line number to remove (in ASCII Text format).
Exit: The specified line number has been removed from the program.

Description:

Call routine &80CD to find the first program line that is greater than or equal to the line numeric number value in the IWA.
If the line number in the IWA does not exist in the program (Carry flag is clear) then exit, as no line to remove.

Routine &80CD returns with pointer (&3D, &3E) set to point to the start of the program line (specified in the IWA).
Set TOP and pointer (&37, &38) to point to the current program text for the line we want to remove - i.e. the value
of the pointer (&3D, &3E).

Read the 3rd byte from location (&37, &38), this contains the length of the program line.
Add the length of the program line to the (&37, &38) pointer.
Now: TOP points to the location of the line to remove and pointer (&37, &38) points to the next line after the
line we wish to remove.

[&BAB6] Move the next line number (pointed to by (&37, &38)) to the TOP location (overwriting the current line
in the program (that is the Line that TOP originally pointed to) as follows:
Set Y to 0
[&BAB8] Keep doing the following:
* Copy the next character from the ((&37, &38) + Y) location to the (TOP + Y) location
* [&BAD3] increment Y (if Y overflowed then also increment &38 and TOP MSB).
Until the next character is <cr> [end of program line]
[&BAC0] Increment Y (to account for the <cr> byte that was copied). If Y overflowed then also increment &38 and
TOP MSB.
[&BAC7] Copy the next character from ((&37, &38) + Y) pointer to (TOP + Y) location.
If the character (which should be the first byte of the next line number) is negative (i.e. #&FF, then end of the program has been
found, so update TOP (Add Y+1 to TOP) and exit as the whole program (from the line after the IWA line number) has been copied
to its new location.

Otherwise (end of program not found yet, so need to move next line), increment Y (to account for the copied byte).
If Y overflowed then also increment &38 and TOP MSB.
Copy the next character (Line number byte 2) from ((&37, &38) + Y) pointer to (TOP + Y) location.
Increment Y (to account for the copied byte). If Y overflowed then also increment &38 and TOP MSB.
Copy the next character from ((&37, &38) + Y) pointer to (TOP + Y) location.
Increment Y (to account for the copied byte). If Y overflowed then also increment &38 and TOP MSB.
Jump back to &BAB8 to copy the rest of the line, and continue checking for more program lines.


Disassembly for the Remove Line Number from Program routine

BA98   032 205 128 20 CD 80 JSR &80CD Search for Program Line >= the Line Number in the IWA
BA9B M 144 077 90 4D BCC 77 --> &BAEA [RTS]
BA9D = 165 061 A5 3D LDA &3D
BA9F 7 133 055 85 37 STA &37
BAA1   133 018 85 12 STA &12
BAA3 > 165 062 A5 3E LDA &3E
BAA5 8 133 056 85 38 STA &38
BAA7   133 019 85 13 STA &13
BAA9   160 003 A0 03 LDY#&03
BAAB 7 177 055 B1 37 LDA (&37),Y
BAAD   024 18 CLC
BAAE e7 101 055 65 37 ADC &37
BAB0 7 133 055 85 37 STA &37
BAB2   144 002 90 02 BCC 2 --> &BAB6
BAB4 8 230 056 E6 38 INC &38
BAB6   160 000 A0 00 LDY#&00
BAB8 7 177 055 B1 37 LDA (&37),Y
BABA   145 018 91 12 STA (&12),Y
BABC   201 013 C9 0D CMP#&0D
BABE   208 019 D0 13 BNE 19 --> &BAD3
BAC0   200 C8 INY
BAC1   208 004 D0 04 BNE 4 --> &BAC7
BAC3 8 230 056 E6 38 INC &38
BAC5   230 019 E6 13 INC &13
BAC7 7 177 055 B1 37 LDA (&37),Y
BAC9   145 018 91 12 STA (&12),Y
BACB 0 048 015 30 0F BMI 15 --> &BADC
BACD   032 223 186 20 DF BA JSR &BADF
BAD0   032 223 186 20 DF BA JSR &BADF
BAD3   200 C8 INY
BAD4   208 226 D0 E2 BNE -30 --> &BAB8
BAD6 8 230 056 E6 38 INC &38
BAD8   230 019 E6 13 INC &13
BADA   128 220 80 DC BRA -36 --> &BAB8
BADC L 076 005 190 4C 05 BE JMP &BE05 Update TOP (TOP value = Y (+1 if carry flag set), set Y to 1 & exit)
BADF   200 C8 INY
BAE0   208 004 D0 04 BNE 4 --> &BAE6
BAE2   230 019 E6 13 INC &13
BAE4 8 230 056 E6 38 INC &38
BAE6 7 177 055 B1 37 LDA (&37),Y
BAE8   145 018 91 12 STA (&12),Y
BAEA ` 096 60 RTS

 


 Back to 8BS
Or