• Please review our updated Terms and Rules here

8BASIC: I finally wrote a Basic interpreter to my Z80 / AM95 8-bit NANO COMPUTER

ygg-it

Member
Joined
Mar 27, 2009
Messages
30
Hello, here the full documentation. It seems working reasonably fast for a 2.5 Mhz machine. Soon photos and video. I have just few bytes left of my 8KB EPROM, so it is hard to improve. But if you like please let me know your comment and suggestions. I want also to post the performance. Do you know any standard testing BASIC routine? Thanks!

8BASIC (C) is a BASIC interpreter developed by manufacturer G.G in 2010 for the homemade Z80/AM95 8 bit NANO COMPUTER. see PICS
Due to the strong mathematical support of the AM9511 processor, the interpreter offers floating-point arithmetic and is just hold in 3KB of EPROM memory.

The most interesting feature of the 8BASIC is that each statement is eight characters fixed-length, which exactly fits the computer's LED display.

8BASIC doesn't have line numbers but uses line labels which may be referenced by control flow statements.

VARIABLES

Statements use variables to keep track of numbers or strings or labels.
Variables and labels must consist of only one alphabetical character.

So the maximum number of GOTO/GOSUB's arguments is 26 and the labelled addresses are precompiled into RAM in a separate table during the program editing.

The range of the 26 numeric values which can be entered or stored, lies between -9.99999 and +9.99999 x 10^5 (always displayed in 8-char fixed format: six digits plus sign and decimal dot). Variables are anyway stored in RAM in floating-point representation during program editing when declared (precomplilation) or during interpretation for the intermediate results. The precision of intermediate calculations depends on the APU 9511 capability (1 bit sign, 7 bit two's complement exponent and 24 bit of mantissa).

During editing, just after having selected the correct statement, you can easily change any of the 26 letters of each variable, navigating through the alphabet using the telephone-like keypad.
For example the generic statement "Z=X+Y" which performs the addition, can be easily modified in

"A=X+Y" or
"A=A+A" or
"Z=X+Z" or
"A=A+X" etc..

It is also easy to handle any algebraic expression using multiple 8-chars functions by chaining intermediate results.
For example Z=2*A+15*C can be written as:

" LET X="
"+15.0000" ;X=15
"X=X*C " ;X=15*C
"B=A+A " ;B=2*A
"Z=B+X " ;Z=2*A+15*C

Each of the 26 text variables may contain max eight alphanumeric characters and symbols, as per the complete DL2416 character set.
But you may build texts with more chars by concatenating strings stored in consecutive letters (variables), with the last string ending with the "#" char: text will be displayed by scrolling right-to-left. So technically the max size of a displayed string is 207 characters.

Here the typical "Hello Word" program which displays the string "Hello World" in an infinite loop:

" LET A$="
"HELLO WO" ; A$="HELLO WO"
" LET B$="
"RLD# " ; B$="RLD"
" "F": " ; F label
"PRINT+A$" ; display from right to left A$&B$ = "HELLO WORLD"
"GO TO F " ; goto F and loop
" END "

COMMANDS

The 8BASIC COMMANDS are used in direct mode from the "Menù"

1 "RUN CMD " ; cause the 8BASIC program to begin operating
2 "NEW CMD " ; erase the 8BASIC program and launch the program editor
3 "LIST CMD" ; launch the 8BASIC program editor
4 "SAVE SER" ; send out to an IBM PC the binary 8BASIC program resident in RAM through the serial port
5 "LOAD SER" ; write in RAM the binary 8BASIC program read from an IBM PC through the serial port
6 "SAVE PAR" ; send out to an IBM PC the binary 8BASIC program resident in RAM through the parallel port
7 "LOAD PAR" ; write in RAM the binary 8BASIC program read from an IBM PC through the parallel port

During editing you can delete and insert new lines. Navigation through statements and variables has been strongly facilitated in submenus.

STATEMENTS

8BASIC consists of 51 fixed-format statements.

During editing you can change any of the 26 letters of each variable in any of the 51 statements.

1 "IF A>B:N" ; jump to line label N if A is greater than B
2 "IF A=B:N" ; jump to line label N if A is equal to B
3 "IF A#B:N" ; jump to line label N if A is not equal to B
4 "IFA>=B:N" ; jump to line label N if A is greater than or equal to B
5 " "N": " ; line label N marking the destination of a GoTo/GoSub statement
6 "GO TO N " ; jump unconditionally to line label N
7 "GO SUB N" ; temporarily jump to line label N and returning to the following line
8 "RETURN " ; jump back to the statement following the original GOSUB statement
9 " END " ; terminate the execution of the program and suspends CPU operation
10 "Z=X+Y " ; add X and Y and assign the result to Z
11 "Z=X-Y " ; subtract Y from X and assign the result to Z
12 "Z=X*Y " ; multiply X and Y and assign the result to Z
13 "Z=X/Y " ; divide X by Y and assign the result to Z
14 "Z=SQR(X)" ; assign to Z the square root of X
15 "Z=INT(X)" ; assign to Z the integer of X
16 "Z=ABS(X)" ; assign to Z the absolute value of X
17 "Z=NEG(X)" ; assign to Z the value of X and change sign of Z
18 "Z=SGN(X)" ; assign to Z the sign function of X
19 "Z= (X)^Y" ; assign to Z the result of X raised to the power of Y
20 "Z=EXP(X)" ; assign to Z the result of e raised to the power of X
21 "Z=LOG(X)" ; assign to Z the common logarithm (base 10) of X
22 "Z= LN(X)" ; assign to Z the natural logarithm of X
23 "Z= PI " ; assign to Z the PI value
24 "Z=RAD(X)" ; assign to Z the radians value of X degrees
25 "Z=DEG(X)" ; assign to Z the degrees value of X radians
26 "Z=SIN(X)" ; assign to Z the sine of X (radians)
27 "Z=COS(X)" ; assign to Z the cosine of X (radians)
28 "Z=TAN(X)" ; assign to Z the tangent of X (radians)
29 "Z=ASN(X)" ; assign to Z the inverse sine of X
30 "Z=ACS(X)" ; assign to Z the inverse cosine of X
31 "Z=ATN(X)" ; assign to Z the inverse tangent of X
32 "Z=RANDOM" ; assign to Z a random integer number between 0 and 255
33 "T$=STR A" ; assign to T$ the value of variable A converted into the equivalent string
34 " LET A=" ; (two lines statement) set the numeric variable A to the following number
"+0.00000" ; 8BASIC standard numeric format is 6 digits plus sign and decimal dot
35 " LET T$=" ; (two lines statement) set the text variable T$ to the following string
"ABCDEFGH" ; 8BASIC standard string format is 8 chars (alphanumeric and special symbols)
36 "LET B==A" ; assign to variable B the numeric value of variable A
37 "K=INKEY$" ; make a program wait until a key is pressed and assign to K the pressed key
38 "INPUT A " ; ask the user to enter the numeric value of variable A
39 "INPUT T$" ; ask the user to enter the string value of variable T$
40 " CLS " ; clears (blank) the 16-segment LED displays and reset (0) the 7-segment ones
41 " CLEAR " ; reset variables to their default type value
42 "PRINT A " ; display the numeric value of variable A
43 "PRINT T$" ; display the string value of variable T$
44 "PRINT+T$" ; display and scroll the strings T$ and consecutives till encountering # char
45 "PAUSE T " ; suspend the program execution. Value of T is the time in ms to pause
46 "BEEP T,F" ; generate a tone. T is the tone duration (ms). F is the tone number (max 7)
47 " IN (A) " ; assign to variable A the binary value input from the 8 bit parallel port
48 " OUT (A)" ; output binary value of variable A to the 8 bit parallel port
49 "A=PEEK X" ; assign to variable A the byte value at the X memory location
50 "POKE X,A" ; write byte value of variable A into X memory location
51 "SYS X " ; branch (and jump back) to the machine language program at the X location

Each statement is precompiled as much as possible to make the interpreter run faster and it always occupies 16 bytes.

Statements allow you extreme flexibility. For example a FOR...TO..NEXT cycle can be easily written as:

LET I=+1.00000
LET U=+1.00000
LET T=number of cycles
N:

cycle

I=I+U
IFT>=I:N
END

Due to the internal RAM memory structure, the maximum size of the 8BASIC program has been set to 488 lines, which will fit the first 8K RAM chip.
 
Last edited:
I finally found on the net the following excellent Basic routine written by R. Broucke at the University of Texas, Austin, which has been tested on several 80's 8-bit PCs to compare their speed and accuracy, measuring the propagation error due to the lack of mantissa precision.

S = 0
X = 0
For I = 1 To 1000
S = S + X * X
X = X + 0.00123
Next I
Print S,X
End


I soon wrote it on Microsoft Office VBA which returned in a shot the correct values
S = 503.543802149991
X = 1.23

Then I have tested this routine on several emulators, and I got results very closed to Broucke's:

Commodore Vic-20 emulator
S = 503.543832
X = 1.23000004 in about 26 seconds

ATARI 800 emulator
S = 503.543594
X = 1.23 in about 11 seconds

etc… (if you own real 80's machines, please post here your score please)

At the end I easily translated Broucke's routine in 8BASIC on my retrocomputer
and run in interpreted mode:

LET S=
+0.00000
LET X==S
LET I=
+1.00000
LET T=
+1000.00
LET U==I
"N":
A=X*X
S=S+A
LET C=
+0.00123
X=X+C
I=I+U
IFT>=I:N
PRINT S
PAUSE T
PRINT X
END


Here the results as I aspected:
Z80/AM95 NANO COMPUTER (@ 2.5MHz) returns
S = +503.508 :cry::cry:
X = +1.22995 in about three seconds !
:p:p

The lack of a longer format is a severe limitation of the use of the AM9511 arithmetic processor. AM9511 is in fact a math chip with just 7 decimal digit precision but is able to perform hard transcendental functions.
In spite of its limitation in term of precision, the AM9511 performs calculation several time faster than any equivalent assembly routines which would surely result cumbersome and memory consumptive if done on Z80 microprocessor alone.
At the end 8BASIC interpreter lies in just 3KB of EPROM.

PS: never forget that I have built and programmed my Z80/AM95 NANO COMPUTER just for fun!
 
Last edited:
Mouth watering eye candy.
Seeing BASIC language on what looks like a hand calculator screen, that's just cool.
I used to have a Radio Shack computer trainer kit, the one where you could actually program in mini assembly language.
I was on my way towards making it into a palm calculator shaped version, repackaging it, but my inexperience at building finished projects blew that to <bad word> and back.
It was a good try though, I put a bunch of effort into it. I had a neat keyboard matrix of tiny VCR buttons for the keyboard on the circuit board before I had to abandon it.



~Kiyote!

What's your end goal with this project? Are you going to make them as kits for people?
 
Tested on a contemporary little machine

Tested on a contemporary little machine

Hi,

I happened to write the BASIC interpreter for this:

http://www.soldercore.com

Details:

>list
10 S = 0
20 X = 0
30 FOR I = 1 TO 1000
40 S = S + X * X
50 X = X + 0.00123
60 NEXT I
70 PRINT S, X
80 END
>run
503.545 1.23
>

Unfortunately, I can't really time it because it is instantaneous.

If I change 1000 to 10,000 it executes in ~0.5s and reports:

>run
504185 12.3001
>

This is because 0.00123 is not exactly representable in binary floating point; you are multiplying that error by 10,000 now.

Anyway, nice to know somebody else likes writing BASIC interpeters and making something that interests them!
 
Back
Top