## CHAPTER 8

### Error Messages, Bells, Whistles, and Anomalies

8.1 ERROR MESSAGES

MCS BASIC-52 has a relatively sophisticated error processor. When BASIC is in the run mode the generalized form of the error message is as follows:

ERROR: XXX - IN LINE YYY

YYY BASIC STATEMENT
-----------X

Where XXX is the error type and YYY is the line number of the program in which the error occurred. A specific example is:

    ERROR BAD SYNTAX - IN LINE 10

    10 PRINT 34*21*

    ------------- X

The X signifies approximately where the error occurred in the line number. The specific location of the X may be off by one or two characters or expressions depending on the type of error and where the error occurred in the program. If an error occurs in the command mode only the error type will be printed out not the line number. This makes sense, because there are no line numbers in the command mode. The error types are as follows:

BAD SYNTAX

A BAD SYNTAX error means that either an invalid MCS BASIC-52 command, statement or operator was entered and BASIC cannot process the entry. The user should check and make sure that everything was typed in correctly. In Version 1.1 of MCS BASIC-52 a BAD SYNTAX error is also generated if the programmer attempts to use a reserved keyword as part of a variable.

BAD ARGUMENT

When the argument of an operator is not within the limits of the operator a BAD ARGUMENT error will be generated. For instance, DBY(257) would generate a BAD ARGUMENT error because the argument for the DBY operator is limited to the range 0 to 255. Similarly, XBY(5000H) = -1 would generate a BAD ARGUMENT error because the value of the XBY operator is limited to the range 0 to 255.

ARITH. UNDERFLOW

If the result of an arithmetic operation exceeds the lower limit of an MCS BASIC-52 floating point number, an ARITH. UNDERFLOW error will occur. The smallest floating point number in MCS BASIC-52 is +- 1E-127. For instance, 1E-80/1E + 80 would cause an ARITH. UNDERFLOW error.

ARITH. OVERFLOW

If the result of an arithmetic operation exceeds the upper limit of an MCS BASIC-52 floating point number, an ARITH. OVERFLOW error will occur. The largest floating point number in MCS BASIC-52 is +-.99999999E+127. For instance, 1E+70*1E+70 would cause an ARITH. OVERFLOW error.

DIVIDE BY ZERO

A division by zero was attempted i.e. 12/0, will cause a DIVIDE BY ZERO error.

ILLEGAL DIRECT (VERSION 1.0 ONLY)

Some statements, such as IF-THEN and DATA cannot be executed while the MCS BASIC-52 device is in the command mode. If you attempt to execute one of these statements the message ERROR: ILLEGAL DIRECT will be printed to the console device. The ILLEGAL DIRECT error is not trapped in Version 1.1 of MCS BASIC-52. ILLEGAL DIRECT errors retum a BAD SYNTAX error in Version 1.1.

INVALID LINE NUMBER

An attempt to branch to a program line number that does not exist was attempted. This can occur in the command mode or the run mode.

LINE TOO LONG (VERSION 1.0 ONLY)

If you type in a line that contains more than 73 characters the message ERROR: LINE TOO LONG will be printed to the console device. MCS BASlC-52's input buffer can only handle up to 73 characters.

NOTE - This error does not exist in Version 1.1. Instead the input buffer has been increased to 79 characters and MCS BASIC-52 will echo a bell character to the user terminal if too many characters are entered into the input buffer.

NO DATA

If a READ ststement is executed and no DATA statement exists or all DATA has been read and a RESTORE instruction was not executed the message ERROR: NO DATA-IN LINE XXX will be printed to the console device.

CAN'T CONTINUE

Program execution can be halted by either typing in a control-C to the console device or by executing a STOP statement. Normally, program execution can be resumed by typing in the CONT command. However, if the user edits the program after halting execution and then enters the CONT command, a CAN'T CONTINUE error will be generated. A control-C must be typed during program execution or a STOP statement must be executed before the CONT command will work.

PROM MODE
PROGRAMMING

If an error occurs while the MCS BASIC-52 device is programming an EPROM, a PROGRAMMING error will be generated. An error encountered during programming destroys the EPROM file structure, so the user cannot save any more programs on that particular EPROM once a PROGRAMMING error occurs.

A-STACK

An A-STACK (argument stack) error occurs when the argument stack pointer is forced "out of bounds." This can happen if the user overflows the argument stack by PUSHing too many expressions onto the stack, or by attempting to POP data off the stack when no data is present.

C-STACK

A C-STACK (control stack) error will occur if the control stack pointer is forced "out of bounds." 158 bytes of external memory are allocated for the control stack, FOR-NEXT loops require 17 bytes of control stack DO-UNTIL, DO-WHILE, and GOSUB require 3 bytes of control stack. This means that 9 nested FOR-NEXT loops is the maximum that MCS BASIC-52 can handle because 9 times 17 equals 153. If the user attempts to use more control stack than is available in MCS BASIC-52 a C-STACK error will be generated. In addition, C-STACK errors will occur if a RETURN is executed before a GOSUB a WHILE or UNTIL before a DO, or a NEXT before a FOR.

I-STACK

An I-STACK (internal stack) error occurs when MCS BASIC-52 does not have enough stack space to evaluate an expression. Normally, I-STACK errors will not occur unless insufficient memory has been allocated to the 8052AH's stack pointer. Details of how to allocate memory to the stack pointer are covered in the assembly language linkage section of this manual.

ARRAY SIZE

If an array is dimensioned by a DIM statement and then you attempt to access a variable that is outside of the dimensioned bounds, an ARRAY SIZE error will be generated.

EXAMPLE:

    >DIM A(10)

    >PRINT A(11)

    ERROR: ARRAY SIZE
    READY
    >

MEMORY ALLOCATION

MEMORY ALLOCATION errors are generated when user attempts to access strings that are "outside" the defined string limits. Additionally, if the system control value, MTOP is assigned a value that does not contain any RAM memory, a MEMORY ALLOCATION error will occur.

8.2 DISABLING CONTROL-C

In some applications, it may be desirable or even a requirement that program execution not accidentally be halted. Under "normal" operation the execution of any MCS BASIC-52 program can be terminated by typing a "control-C" on the console device. However, it is possible to disable the "control-C" break function in MCS BASIC-52. This is accomplished by setting bit 48 (30H) to a one. Bit 48 is located in internal memory location 38.0 (26.0H). This bit may be set by executing the following statement in an MCS BASIC-52 program:

DBY(38) = DBY(38) .OR. 01H

Once this bit is set to a one, the control-C break function, for both LIST and RUN operations will be disabled. The user has the option to create a custom break character or string of characters by using the GET operator. The following is an example of how to implement a custom break character:

EXAMPLE:

    >10 STRING 100,10: A=1: REM INITIALIZE STRINGS
    >20 $(1) = "BREAK" : REM "BREAK" IS THE PASSWORD
    >30 DBY(38) = DBY(38).OR.1 : REM DISABLE CONTROL-C
    >40 FOR I=1 T0 1000 : REM DUMMY LOOP
    >50 J=SIN(I)
    >60 K=GET : IF K<>0 THEN 100 ELSE NEXT I
    >70 END
    >100 IF K=ASC($(1),A) THEN A=A+1 ELSE A=1
    >110 REM TEST FOR MATCH
    >120 IF A=1 THEN NEXT I
    >130 IF A=6 THEN 200 ELSE NEXT I
    >140 END
    >200 PRINT "BREAK"
    >210 DBY(38)=DBY(38).AND.0FEH : REM ENABLE CONTROL-C

In this example, typing the word BREAK will stop program execution. In other words, BREAK is a password.

8.3 IMPLEMENTING "FAKE DMA"

The MCS BASIC-52 device does not contain an hardware mechanism that supports Direct Memory Access (DMA). However, the DMA function is supported in software by MCS BASIC-52. During DMA operation MCS BASIC-52 guarantees that no external memory access will be performed. To enable the DMA function, the following must be performed:

1) Bit 49, which is located in internal memory location 38.1 (26.1H) must be set to a one. This can be accomplished in BASIC by using the statement - DBY(38) = DBY(38) .0R. 02H

2) Bit 0 and bit 7 of the special function register, IE (Interrupt enable) must be set to a one. This can be accomplished in BASIC by using the statement - IE = IE .OR. 81H

After the three bits mentioned above are set to a one, external interrupt zero (/INT0) acts as a DMA input pin. /INT0 is pin 12 on the 8052AH. Whenever /INT0 is pulled low (to a logical zero state), the MCS BASIC-52 device will enter the DMA mode and no accesses will be made to external memory. To acknowledge that MCS BASIC-52 has entered the DMA mode, MCS BASIC-52 outputs a zero on pin 7 (P1.6). In essence, PORT 1.6 is the /DMA ACK pin of the MCS BASIC-52 device. In most applications, this pin would be used to disable three-state buffers that would be placed on PORT2, PORT0, and the address latch of the MCS BASIC-52 system. After the user pulls the /INT0 pin high, MCS BASIC-52 will output a one on P1.6 and normal program execution will continue. During this "fake DMA" cycle, the MCS BASIC-52 program does nothing except wait for the /INT0 pin to be pulled high. So, program execution is halted.

It should be noted that although this "fake DMA" operation does provide the same functionality as a norrnal DMA hardware mechanism, it also takes substantially longer for the normal DMA request - DMA acknowledge cycle to be performed. That is because MCS BASIC-52 uses interrupts to implement the DMA operation, instead of dedicated hardware. As a general rule, cycle stealing DMA is not an option with MCS BASlC-52's "fake" DMA. Only "burst mode" DMA cycles can be implemented without a significant time penalty. When "fake DMA" is implemented, the user must provide three-state buffers on the PORT2, PORT0, and the address latch of the MCS BASIC-52 system.

8.4 RUN TRAP OPTION (Version 1.1 Only)

Version 1.1 of MCS BASIC-52 permits the user to trap the interpreter in the run mode. This option is evoked by putting a 34H (52D) in external data memory location 5EH (94D). After a 34H (52D) is placed in external data memory location 5EH (94D) the MCS BASIC-52 interpreter will be trapped in the run mode forever or until the contents of external data memory location is changed to something other than 34H (52D). If no program is present when a 34H (52D) is placed in location 5EH (94D), MCS BASIC-52 will print the READY message forever and it will be time to reset the device. The run trap option can be employed with the other reset options to permit the user to execute a program from RAM on a reset or power-up condition when some type of battery back-up memory scheme is employed.

8.5 ANOMALIES

Most dictionaries define an anomaly as a deviation from the normal or common order or as an irregularity. Anomalies to an extreme become "bugs" or something that is wrong with the program. Like all programs, MCS BASIC-52 contains some anomalies, hopefully, no bugs. The purpose of mentioning the known anomalies here is that it may save the programmer some time, should strange things happen during program execution. The known anomalies deal mainly with the way MCS BASIC-52 compacts or tokenizes the BASIC program. The known anomalies and cautions are as follows:

1) When using the variable H after a line number, make sure you put a space between the line number and the H, or else BASIC will assume that the line number is a HEX number.

EXAMPLES:

    >20H=10 (WRONG)          >20 H=10 (RIGHT)
    >LIST                    >LlST
     32     =10               20    H=10

2) When using the variable I before an ELSE statement, make sure you put a space between the I and the ELSE statement, or else BASIC will assume that the IE portion of IELSE is the special function operator IE.

EXAMPLES:

    >20 IF I>10 THEN PRINT IELSE 100
    >LIST
     20    IF I>10 THEN PRINT IELSE 100 (WRONG)

    >20 IF I>10 THEN PRINT I ELSE 100
    >LIST
     20    IF 1>10 THEN PRINT I ELSE 100 (RIGHT)

3) A Space character may not be placed inside the ASC() operator. In other words, a statement like PRINT ASC( ) will yield a BAD SYNTAX error. Spaces may be placed in strings however, so a statement like LET $(1) = "HELLO, HOW ARE YOU" will work properly. The reason ASC( ) yields an error is because MCS BASIC-52 eliminates all spaces when a line is processed. so ASC( ) will be stored as ASC() and MCS BASIC-52 interprets this as an error.