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
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:
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.
When the argument of an operator is not within the limits of the operator a BAD ARGUMENT ERROR will be generated. For instanee. 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.
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.
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.
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.
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.
If a READ STATEMENT 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.
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.
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 STRUC- TURE, so the user cannot save any more programs on that particular EPROM once a PROGRAMMING ERROR occurs.
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.
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.
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.
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.
>DIM A(10) >PRINT A(11) ERROR: ARRAY SIZE READY
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 possibie 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:
>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 th 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.
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.
>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.
>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 te 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-57 interprets this as an error.
Copyright © Madis Kaal 2000-