8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


BASIC IV ROM Routines
Page Last Altered:


8FF2 Startup initialisations (part 2)

Submitted by Steve Fewell

Description:

Set the IWA to value #&F2.
Call &BF22 to read the contents of memory location &000000F2. This value is the LSB value of the Operating System's
Text pointer. Store this value in X.
Call &BF22 to read the contents of memory location &000000F3. This value is the MSB value of the Operating System's
Text pointer. Store the pointer's address in the IWA (&2A = X (contents of &F2); &2B = contents of &F3).
The *EDIT command uses the Operating system's text pointer (&F2-&F3) to point to the 2-byte code '@' followed by '<cr>'
and pointer (&00-&01) to store the address of the edited BASIC program (in ASCII text).

Set X to #&14 (the number of attempts to try finding the byte value that we are expecting).
[&9004] Decrement X. If X has reached zero then [&9045] create a NEW empty program and jump to the command line
prompt as startup initialisation is now complete.

Call &BF22 to read the byte at the memory location pointed to by the address in the IWA, and then increment the IWA
address.
If the byte is '<cr>' then no program text found at the IWA location, so [&9045] create a NEW empty program and
jump to the command line prompt as startup initialisation is now complete.

If the byte is not #&40 ('@'), then jump back to &9004 to check the next byte at the IWA address.

Otherwise, we have found byte #&40 ('@'), which indicates that BASIC has been called from *EDIT (or possibly another
application).
[&9012] Call &BF22 to read the byte at the memory location pointed to by the address in the IWA, and then increment
the IWA address. This is the next byte after the '@' character.

If the byte is not '<cr>' then no program text found at the IWA location, so [&9045] create a NEW empty program
and jump to the command line prompt as startup initialisation is now complete.

Now we have found the byte sequence #&40 ('@') followed by #&0D ('<cr>').
Call &BF3E (NEW) to create an empty program that consists of the following bytes:
* #&0D ('<cr>') - to indicate the start of the program
* #&FF - to indicate the end of the program

[&901C] Set BASIC Text pointer A (&0B-&0C) value to &0700.
Set Y (pointer offset) to 0.
[&9024] Load the next character pointed to by pointer (&00-&01). *EDIT places the start address of the BASIC
program (in ASCII text) in locations (&00-&01).

If the character is &00 (or 'null', ASCII 0) then this indicates the end of the BASIC program, so jump to &8F83
to initialise variable workspace (etc...) and prompt for the command line entry as the startup initialisations and
tokenisation of the *EDIT program are now complete.

Otherwise store the character in the command line buffer (&0700, pointed to by (&0B, &0C) at offset Y and
increment Y to next next character in the command line buffer).
If Y has now rolled over from &FF to 0, then the BASIC program ASCII text line is too long, and cannot have been
created from the *EDIT application, so [&9045] create a new empty program and jump to &9048 to initialise
variable workspace (etc...) and prompt for the command line entry as the startup initialisations are now complete.
Note: This wipes out the entire program (all lines entered so far), as they were not the *EDIT ASCII text program lines
(that we had thought they were).

Increment the (&00-&01) pointer (to the next character on the program line).
If the character that we have just stored at the end of the command line buffer is not '<cr>', then we haven't reached
the end of the line yet, so jump back to &9024 to copy the next character to the command line buffer.

Otherwise, the end of the libne has been reached, so we now need to tokenise the line and insert it into the BASIC program
as follows:
* Check whether the *EDIT program text pointer MSB (&01) is more than or equal to the HIMEM MSB address (&07).
If it is then do not insert the current line into the program, and do not insert any further lines from the *EDIT text
pointer. Instead, jump to &9048 to initialise variable workspace (etc...) and prompt for the command line entry as
the startup initialisations (and tokenisation of the *EDIT program) tasks are now complete.
* Call routine &BAEB to tokenise the ASCII program line text contained within the command line buffer (&0700)
and insert the tokenised program line into the program (at the line number specified at the start of the line text).
* Jump back to &9024 to copy and tokenise the next *EDIT program line.


Disassembly for the Startup initialisations (part 2) routine

8FF2

 

169 242

A9 F2

LDA#&F2

8FF4

`

032 096 174

20 60 AE

JSR &AE60 Set IWA to the 8-bit value in A

8FF7

""""

032 034 191

20 22 BF

JSR &BF22 Read byte from I/O processor (at the address in IWA) & increment IWA

8FFA

 

170

AA

TAX

8FFB

""""

032 034 191

20 22 BF

JSR &BF22 Read byte from I/O processor (at the address in IWA) & increment IWA

8FFE

+

133 043

85 2B

STA &2B

9000

*

134 042

86 2A

STX &2A

9002

 

162 020

A2 14

LDX#&14

9004

 

202

CA

DEX

9005

240 062

F0 3E

BEQ 62 --> &9045 NEW (create null program)

9007

""""

032 034 191

20 22 BF

JSR &BF22 Read byte from I/O processor (at the address in IWA) & increment IWA

900A

 

201 013

C9 0D

CMP#&0D

900C

7

240 055

F0 37

BEQ 55 --> &9045 NEW (create null program)

900E

@

201 064

C9 40

CMP#&40

9010

 

208 242

D0 F2

BNE -14 --> &9004

9012

""""

032 034 191

20 22 BF

JSR &BF22 Read byte from I/O processor (at the address in IWA) & increment IWA

9015

 

201 013

C9 0D

CMP#&0D

9017

","

208 044

D0 2C

BNE 44 --> &9045 NEW (create null program)

9019

032 062 191

20 3E BF

JSR &BF3E NEW - reset the current program to an empty program

901C

 

160 000

A0 00

LDY#&00

901E

d

100 011

64 0B

STZ &0B

9020

 

169 007

A9 07

LDA#&07

9022

 

133 012

85 0C

STA &0C

9024

 

178 000

B2 00

LDA (&00)

9026

 

240 032

F0 20

BEQ 32 --> &9048 Initialise & prompt for (and execute) command line input

9028

 

145 011

91 0B

"STA (&0B),Y"

902A

 

200

C8

INY

902B

 

240 024

F0 18

BEQ 24 --> &9045 NEW (create null program)

902D

 

230 000

E6 00

INC &00

902F

 

208 002

D0 02

BNE 2 --> &9033

9031

 

230 001

E6 01

INC &01

9033

 

201 013

C9 0D

CMP#&0D

9035

 

208 237

D0 ED

BNE -19 --> &9024

9037

 

165 001

A5 01

LDA &01

9039

 

197 007

C5 07

CMP &07

903B

 

176 011

B0 0B

BCS 11 --> &9048 Initialise & prompt for (and execute) command line input

903D

 

032 027 187

20 1B BB

JSR &BB1B

JSR &BB1B Tokenise Line of program text and Insert Line into Program

9040

 

128 218

80 DA

BRA -38 --> &901C

 


 Back to 8BS
Or