×   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

BDE5 Check program can be read correctly

Submitted by Steve Fewell

Description:

Set TOP (&12-&13) to PAGE (&18) [The LSB byte of TOP is zero as PAGE does not store an LSB byte].

[&BDED] If the first byte of the program line is not #&0D then show the 'Bad program' message [described below].

If the second byte of the program line is negative then we have reached the end of the program (#&FF value), so add 2
to the TOP value to account for the 2-byte null line value and exit with Y = 1. The program was checked correctly!

If the fourth byte of the program line (line length) is #&00 then the program is corrupt, as this is an invalid line
length, so show the 'Bad program' message [described below - &BE11].

[&BDFE] Otherwise, the program line is ok, so Add the line length to TOP and set Y back to 1 (offset for next line);
then, jump back to &BDED to check the next program line.

[&BE11] Show 'Bad program' message
This routine is called if the program check located an error or corruption in the program, meaning that the program
is not correct. The text 'Bad program' will be shown on the screen - this is only a screen message and not a forced
error that stops the current operation and jumps to a specified error routine - specified by the BBC's Break [BRK] vector.

This routine call routine &BECF.
Routine &BECF does the following:
* Retrieves the address of the position to return to (after the subroutine finishes) from the stack.
* Store this address in (&37, &38). Now, (&37,. &38) point to the first character after the &BECF call.
* Keep on incrementing (&37, &38), reading the character from this location and, if the character is positive
(less than #&80), then:
      -> Show the character on the screen [if the characetr is #&0D then a new line will be shown instead]
      -> Jump back to increment (&37, &38) and process the next character.
* If the character is negative (greater than or equal to #&80) then there are no more characters to display, so
jump to the current location pointed to by (&37, &38) -> this will be the location directly after the text message.
[The first character after the text message is usually #&EA (The NOP Mnenomic), which represents the end of the text,
as its value is negative (>=&80].

In the case of the 'check program can be read correctly' routine, the program code after the Text message is:
NOP
JMP &8F86

The NOP command does nothing (but as it has a value >= #&80, it represents the end of the message).
The JMP command jumps to &8F86 which returns to the BASIC command line to read and execute the user's next command
line instruction.

Note: This routine does not need to end with an RTS, as the stack has already been tidied up by the removal of the return
address bytes.

Disassembly for the Check program can be read correctly routine

BDE5   165 024 A5 18 LDA &18
BDE7   133 019 85 13 STA &13
BDE9 d 100 018 64 12 STZ &12
BDEB   160 001 A0 01 LDY#&01
BDED   178 018 B2 12 LDA (&12)
BDEF   201 013 C9 0D CMP#&0D
BDF1   208 030 D0 1E BNE 30 --> &BE11
BDF3   177 018 B1 12 LDA (&12),Y
BDF5 0 048 012 30 0C BMI 12 --> &BE03
BDF7   160 003 A0 03 LDY#&03
BDF9   177 018 B1 12 LDA (&12),Y
BDFB   240 020 F0 14 BEQ 20 --> &BE11
BDFD   024 18 CLC
BDFE   032 006 190 20 06 BE JSR &BE06
BE01   128 234 80 EA BRA -22 --> &BDED
BE03   200 C8 INY
BE04   024 18 CLC
BE05   152 98 TYA
BE06 e 101 018 65 12 ADC &12
BE08   133 018 85 12 STA &12
BE0A   144 002 90 02 BCC 2 --> &BE0E
BE0C   230 019 E6 13 INC &13
BE0E   160 001 A0 01 LDY#&01
BE10 ` 096 60 RTS
BE11   032 207 190 20 CF BE JSR &BECF Print following text as a warning message & jump to address specified
BE14 Bad program 013 066 097 100 032 112 114 111 103 114 097 109 013 0D 42 61 64 20 70 72 6F 67 72 61 6D 0D EQUS chr$(13) + "Bad program" + chr$(13)
BE21 234 EA NOP
BE22 L 076 134 143 4C 86 8F JMP &8F86 Read & execute command line input

Output text warning message and jump to the address specified

BECF h 104 68 PLA
BED0 7 133 055 85 37 STA &37
BED2 h 104 68 PLA
BED3 8 133 056 85 38 STA &38
BED5   128 003 80 03 BRA 3 --> &BEDA
BED7   032 227 255 20 E3 FF JSR &FFE3 OSASCI (OSWRCH - or OSNEWL (if A = #&0D))
BEDA   032 169 141 20 A9 8D JSR &8DA9 Increment and read character at (&37, &38) pointer
BEDD   016 248 10 F8 BPL -8 --> &BED7
BEDF l7 108 055 000 6C 37 00 JMP (&0037)

 


 Back to 8BS
Or