CBASIC 2.8 = CBASIC-86 1.00



DIFFCBAS.TXT
------------

Differences between the 8080 and 8086 implementations of CBASIC
by Emmanuel ROCHE

CBASIC is the oldest BASIC running under CP/M. You may remember
that Gary Kildall was a Computer Science professor at the Naval
Postgraduate School of Monterey, California, teaching compiler
writing by using his own ALGOL-like compiler as an example. To
write this demo compiler, he needed a "system language", so he
created PL/M, that he wrote in FORTRAN-66 (so as to be portable)
on an IBM System/360 (the "standard" hardware, back then)
running under CP/MVS.

PL/M had been designed to "replace serious system programming in
assembly language" for the brand-new Intel 8008 CPU (and the
8080, which appeared just a few months later). To use this PL/M
compiler on the first Intel demo microcomputers, Gary needed one
Operating System. After seeing the first 8-inch floppy disk
drives (used by IBM to replace paper tapes), he decided to write
one DOS for floppies, that he called CP/M, rather than for
magnetic cassette tapes, as several other persons did in the
early days of microcomputers (copying what they were using at
work on mini-computers).

Several students of Gary wrote compilers for their Master of
Science Theses, using PL/M. One of them was Gordon Eubanks, Jr,
who choose to make an "Extended BASIC" following closely the
first BASIC, Dartmouth BASIC. It was named NBASIC, standing for
NPS BASIC. It was running on the S/360 of the NPS, under an
emulator emulating CP/M 1.2. Gordon wrote it with two other
students, in six months. It is heavily based on the ALGOL
compiler of Gary Kildall.

BASIC had made a revolution as a simpler way to use computers.
So, Gary logically choose it as one of the first programs to be
released for CP/M. Gary ported NBASIC under CP/M 1.3, renaming
it BASIC-E (E standing, of course, for Eubanks) in the process.
The source code of this version can be found in the first
"Volumes" of the CP/M User's Group 8-inch disks.

BASIC-E was very popular, because it enabled people to write
useful software for CP/M with very high numerical precision, yet
managed to run in a 24K TPA. Even better: since it was a
compiler producing INT files, the source code was not released!
"Commercial" software "houses" (well... kitchen tables, in most
cases) loved this feature.

BASIC-E was so successful that an S-100 Bus card executing
directly the INT files produced by BASIC-E appeared, greatly
increasing their speed (10 times faster than interpreting them).

After Digital Research was created, it was found that it needed
a BASIC to sell... So, a third version was made, named this time
CBASIC. Maybe it is because Gary Kildall was teaching compiler
writing, but an interpreted version never appeared, and CBASIC
remained a compiler.

Over the years, CBASIC evolved very, very little. The highest
known version number is 2.8. Since CP/M-86 (Plus) is
experiencing a revival, I though that the 8086 version of
CBASIC, known as CBASIC-86, would be interesting.
Unfortunately, it was nowhere to be found, so I called several
times for it on the comp.os.cpm Newsgroup over the years (and
tracked the sender of every message that I managed to found
dealing with it for the NEC APC -- to no avail).

Very recently, someone warned me that a lost copy had finally
been found. However, as usual, no paper doc seems to have
survived. So, we are going first to investigate how different
the 8080 and 8086 versions of CBASIC are. Since they are
compilers, we also first need a simple demo program. It is a
tradition to start with a program displaying "Hello, World!" on
the screen, so let us follow the custom.


Classical test program ("HELLO.BAS")
----------------------

PRINT "Hello, World!"
END


CBASIC session (8080 version)
--------------

A>cbasic28 hello
--------------------------------------------------
CBAS Version 2.8
Serial No. 3504-0000-003284 All rights reserved
Copyright (c) 1981-1983 Digital Research, Inc.
--------------------------------------------------
1: PRINT "Hello, World!"
2: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE: 19
DATA STMT AREA: 0
VARIABLE AREA: 0

A>crun hello
--------------------------------------------------
CRUN Version 2.8
Serial No. 3504-0000-003284 All rights reserved
Copyright (c) 1981-1983 Digital Research, Inc.
--------------------------------------------------
Hello, World!


CBASIC-86 session (8086 version)
-----------------

A>cbas86 hello
CBASIC/86 COMPILER VER 1.00
COPYRIGHT 1981 COMPILER SYSTEMS INC.
1: PRINT "Hello, World!"
2: END
NO ERRORS DETECTED
CONSTANT AREA: 8
CODE SIZE: 19
DATA STMT AREA: 0
VARIABLE AREA: 0

A>crun86 hello
CRUN86 VER 1.00
COPYRIGHT 1981 COMPILER SYSTEMS INC.
Hello, World!


The first thing to note is that this CP/M-86 version of
CBASIC-86 is titled "CBASIC/86"... One small patch will quickly
remedy this "MeSs"...

The second thing we note is that the version numbers differ: the
8080 version is 2.8, the 8086 version is 1.0. So, we need to
investigate a little deeper how different/identical they are. To
do this, short of a complete disassembly of the compiler, the
simplest and easiest way is to have a look to the ASCII strings
stored in both versions. DUMPASC to the rescue!

But, before, let us try a simpler test: see if the 8080 and 8086
versions of CBASIC can run **THE SAME** INT file?

A>crun hello
--------------------------------------------------
CRUN Version 2.8
Serial No. 3504-0000-003284 All rights reserved
Copyright (c) 1981-1983 Digital Research, Inc.
--------------------------------------------------
Hello, World!

A>crun86 hello
CRUN86 VER 1.00
COPYRIGHT 1981 COMPILER SYSTEMS INC.
Hello, World!

YES! So, we already know that CBASIC-86 is at least downward
compatible with CBASIC v2.8.

For the record, this HELLO.INT file is:

0000|.1$*...........Hello, World!.$d4...s...t...L...M...L.t..9t....a.
0040|......J.t....$.<.t..St..L.LKK.uy....K.myC...1K+.u...tRS........H

Now, let us use DUMPASC to compare both versions of CBASIC.


DUMPASC CBASIC28.COM
--------------------

0000|.wI--------------------------------------------------..CBAS
0040| Version 2.8..Serial No. 3504-0000-
0080|003284 All rights reserved..Copyright (c) 1981-1983 Digit
00C0|al Research, Inc...---------------------------------------------
0100|-----..$...2.........COPYRIGHT 1977,1981 COMPILER SYSTEMS, INC.'
0140|..d.......END....#.(.).*.+.,.-./.:.;.<.=.>.^.AS.EQ.GE.GO.GT.IF.L
0180|E.LT.NE.ON.OR.TO.ABS.AND.ASC.ATN.COS.DEF.DIM.END.EXP.FOR.FRE.INP
01C0|.INT.LEN.LET.LOG.NOT.OUT POS.REMbRND.SGN.SIN.SQR.SUB!TAB.TAN.VAL
0200|.XOR"BUFF(CALL#CHR$.DATAcELSE$FEND%FILE&GOTO'INT%.LINE)MID$.NEXT
0240|*OPEN+PEEK.POKE,READ-RECL.RECS/SADD.SIZE.STEP0STOP1STR$.THEN2WEN
0280|D3%LIST.%PAGE.CHAINICLOSE4FLOAT.GOSUB5INPUT6LEFT$.LO###7MATCH.PR
02C0|INT8USING9WHILE:WIDTH;%CHAIN.%EJECT.COMMON<CREATE=DELETE>REMARKb
0300|RENAME.RETURN?RIGHT$.UCASE$.VARPTR.%NOLIST.CONSOLEBRESTORECSAVEM
0340|EMD%INCLUDE.COMMAND$.CONCHAR%.CONSTAT%.LPRINTERGRANDOMIZEHINITIA
0380|LIZEI..O.m.........#.C.p.z............PAGE$OUT OF DISK SPACE$OUT
03C0| OF DIRECTORY SPACE$DISK ERROR $BASNO SOURCE FILE: $.BAS$ERROR $
0400| IN LINE$ AT POSITION$WARNING: INVALID CHARACTER IGNORED IN LINE
0440|$INCLUDE NESTING TO DEEP NEAR LINE$FILE: $!.Ps+q+..p+q.:.P=2.P..

First thing to note: The copyright dates are 1977-1981 for
Compiler Systems, Inc, and 1981-1983 for Digital Research, Inc,
for Version 2.8. And we just saw that the CP/M-86 version was
dated 1981, and copyrighted by Compiler Systems, not Digital
Research...

1780|M..!.O.*.O_DM.....1.CONSTANT AREA: $CODE SIZE: $DATA STMT
17C0|AREA: $VARIABLE AREA: $.AQGFKLPBTNOCDEIJHXRrU[qZWpS\YVsvwxq....
1800|.......................&..&.....................................
1840|....PROD $FUNCTION REFERENCE BEFORE DEF: $PROGRAM CONTAINS $ UNM
1880|ATCHED $ STATEMENTS$FOR$WHILE$DEF$NO$ ERROR$ DETECTED$:pM......P

4C40|...................CBASIC V2.08 COMPILATION OF $................

Hugh? At the beginning, it says that it is Version 2.8, and
inside it says that it is Version 2.08... (Personally, I have a
book using Version 2.07, so this was probably the version number
used by Compiler Systems. Digital Research probably shortened it
to 2.8.)


DUMPASC CBAS86.CMD
------------------

3980|....................................CBASIC/86 V1.00 COMPILATION
39C0|OF $............................................................

3EC0|.................'..d.......k.....!.....?._.....COPYRIGHT 1981 C
3F00|OMPILER SYSTEMS, INC..END....#.(.).*.+.,.-./.:.;.<.=.>.^.AS.EQ.G
3F40|E.GO.GT.IF.LE.LT.NE.ON.OR.TO.ABS.AND.ASC.ATN.COS.DEF.DIM.END.EXP
3F80|.FOR.FRE.INP.INT.LEN.LET.LOG.NOT.OUT POS.REMbRND.SGN.SIN.SQR.SUB
3FC0|!TAB.TAN.VAL.XOR"BUFF(CALL#CHR$.DATAcELSE$FEND%FILE&GOTO'INT%.LI
4000|NE)MID$.NEXT*OPEN+PEEK.POKE,READ-RECL.RECS/SADD.SIZE.STEP0STOP1S
4040|TR$.THEN2WEND3%LIST.%PAGE.CHAINICLOSE4FLOAT.GOSUB5INPUT6LEFT$.LO
4080|###7MATCH.PRINT8USING9WHILE:WIDTH;%CHAIN.%EJECT.COMMON<CREATE=DE
40C0|LETE>REMARKbRENAME.RETURN?RIGHT$.UCASE$.VARPTR.%NOLIST.CONSOLEBR
4100|ESTORECSAVEMEMD%INCLUDE.COMMAND$.CONCHAR%.CONSTAT%.LPRINTERGRAND
4140|OMIZEHINITIALIZEI...........PAGE$OUT OF DISK SPACE$OUT OF DIRECT
4180|ORY SPACE$DISK ERROR $BASNO SOURCE FILE: $.BAS$ERROR $ IN LINE$
41C0|AT POSITION$WARNING: INVALID CHARACTER IGNORED IN LINE$INCLUDE N
4200|ESTING TO DEEP NEAR LINE$FILE: $.AQGFKLPBTNOCDEIJHXRrU[qZWpS\YVs

5000|.............................................................CBA
5040|SIC/86 COMPILER VER 1.00$COPYRIGHT 1981 COMPILER SYSTEMS INC.$CO
5080|NSTANT AREA: $CODE SIZE: $DATA STMT AREA: $VARIABLE AREA:
50C0| $PROGRAM CONTAINS $ UNMATCHED $ STATEMENT$FOR$WHILE$DEF$NO$ ERR
5100|OR$ DETECTED$...................................................

Again, the CP/M-86 version of CBASIC is only copyrighted by
Compiler Systems, not Digital Research... And the version number
is x.yy, rather than Digital Research's x.y...


DUMPASC CRUN.COM
----------------

0000|.y..............P.----------------------------------------------
0040|----..CRUN Version 2.8..Serial
0080| No. 3504-0000-003284 All rights reserved..Copyright (c) 1981
00C0|-1983 Digital Research, Inc...------------------------------
0100|--------------------..$COPYRIGHT (C) 1978, 1979, 1980 COMPILER S
0140|YSTEMS INC.........................x...w..#.c...................

You will note that the run-time system is dated one year after
the compiler! (Those RTSes are always more difficult to debug
than foreseen...) And there is no 1981 overlap.

1A00|@......P................E.....v2..(.<.P.d.x...PRINTER BUSY?$ IN
1A40|LINE $ERROR $WARNING $IMPROPER INPUT - REENTER $AT LINE $1.D.7&1

3BC0|.?6..2.5.NO INTERMEDIATE LANGUAGE FILE $ REQUIRES CP/M V2 OR MP/
3C00|M$!.E".F!\.".F:.D..\=...!K.6 ....H.........".D}...==..<.H....!..

44C0|......................P..............MXList ...................

Yes, it really requires MP/M, since the above line talks of the
"Mutual Exclusion List" of MP/M. And it checks the status of the
printer...


DUMPASC CRUN86.CMD
------------------

3E40|................P.COPYRIGHT (C) 1981 COMPILER SYSTEMS INC.......

4380|..P5.....D.. .@...cbe.....@.(u?......B...p6W..>...W"f(@E.3..SxNO
43C0| INTERMEDIATE LANGUAGE FILE: $CRUN86 VER 1.00..$COPYRIGHT 1981 C
4400|OMPILER SYSTEMS INC...$...d.......(.<.P.d.x...@......P..........
4440|......E.....v2 IN LINE $ERROR $WARNING $IMPROPER INPUT - REENTER
4480| $AT LINE $.....................................................

Always this date of 1981, and I did not see any MP/M-86 code or
message dealing with the printer...

One funny difference: the compilers are "copyright date", while
the run-time systems are "copyright (c) date"!

I also noticed another funny bug in the XREF utility for CBASIC:

XREF04: TO MANY FUNCTIONS
XREF05: INCLUDE NESTING TO DEEP NEAR LINE

Maybe someone could warn Compiler Systems that "to" should be
"too", in both cases? (This bug is present in both versions, so
I am ready to bet that it is a PL/M program recompiled without
having a look at it...)


What to do?
-----------

As can be seen, both compilers contain a list of keywords at
their beginning. But how to compare them? I decided to do it as
simple as possible: cut those lists with an editor, then put
each keyword on a separate line. Most keywords are separated by
a ".", but some have funny characters. While doing this, it
became clear that those keywords are listed according to their
number of characters, so I added a few paragraph titles, then
saved those "CBASIC(-86) Keywords" files.

I now had 2 ASCII files. Using the editor, I could see that they
had the same number of lines... But how to be *ABSOLUTELY* sure
that both files are identical? Of course, I could simply run my
COMPARE.BAS program, but the titles of the files and one comment
line was different in both files...

I remembered my DUMPATWO utility, which dumps 2 files in ASCII
side by side. Clearly, one way to check both files would be to
display them side by side... After a quick hack, I got the
following:

10 REM TYPEATWO.BAS by Emmanuel ROCHE
20 :
30 PRINT
40 PRINT "Type 2 files in ASCII (file1|file2)"
50 PRINT
60 INPUT "Enter 1st filename.typ: " ; file1$
70 INPUT " 2nd filename.typ: " ; file2$
80 PRINT
90 :
100 lin = 0
110 OPEN "I", #1, file1$
120 OPEN "I", #2, file2$
130 WHILE NOT EOF (1) OR LOC (1) = 0 OR NOT EOF (2) OR LOC (2) = 0
140 LINE INPUT #1, line1$
150 LINE INPUT #2, line2$
160 PRINT line1$ "|" line2$
170 lin = lin + 1
180 IF lin = 23 THEN lin = 0 : PRINT : PRINT "Press ENTER to Continue
" ; : WHILE INKEY$ = "" : WEND : PRINT
190 WEND
200 CLOSE
210 PRINT
220 END

Only 22 lines, including 2 empty lines! I like BASIC for being
so much powerful in so few lines... yet so easy to understand!
And so easy to debug!!! (And all this in a 30 KB program...)

Using the above program, I got the following on screen:

run"typeatwo

Type 2 files in ASCII (file1|file2)

Enter 1st filename.typ: ? cbaskw.asc
2nd filename.typ: ? cb86kw.asc

CBASIC Keywords by Emmanuel ROCHE|CBASIC-86 Keywords by Emmanuel ROCHE
---------------|------------------
|
1-char long|1-char long
-----------|-----------
#|#
(|(
)|)
*|*
+|+
,|,
-|-
/|/
:|:
;|;
<|<
=|=
>|>
^|^
|
|
2-chars long|2-chars long
------------|------------
AS|AS
EQ|EQ
GE|GE
GO|GO
GT|GT
IF|IF
LE|LE
LT|LT
NE|NE
ON|ON
OR|OR
TO|TO
|
|
3-chars long|3-chars long
------------|------------
ABS|ABS
AND|AND
ASC|ASC
ATN|ATN
COS|COS
DEF|DEF
DIM|DIM
END|END
EXP|EXP
FOR|FOR
FRE|FRE
INP|INP
INT|INT
LEN|LEN
LET|LET
LOG|LOG
NOT|NOT
OUT|OUT
POS|POS
REM|REM
RND|RND
SGN|SGN
SIN|SIN
SQR|SQR
SUB|SUB
TAB|TAB
TAN|TAN
VAL|VAL
XOR|XOR
|
|
4-chars long|4-chars long
------------|------------
BUFF|BUFF
CALL|CALL
CHR$|CHR$
DATA|DATA
ELSE|ELSE
FEND|FEND
FILE|FILE
GOTO|GOTO
INT%|INT%
LINE|LINE
MID$|MID$
NEXT|NEXT
OPEN|OPEN
PEEK|PEEK
POKE|POKE
READ|READ
RECL|RECL
RECS|RECS
SADD|SADD
SIZE|SIZE
STEP|STEP
STOP|STOP
STR$|STR$
THEN|THEN
WEND|WEND
|
|
5-chars long|5-chars long
------------|------------
%LIST|%LIST
%PAGE|%PAGE
CHAIN|CHAIN
CLOSE|CLOSE
FLOAT|FLOAT
GOSUB|GOSUB
INPUT|INPUT
LEFT$|LEFT$
LO### <--- ??? ("L#CAL" for CBASXREF...)|
LO### <--- ??? ("L#CAL" for XREF86...)
MATCH|MATCH
PRINT|PRINT
USING|USING
WHILE|WHILE
WIDTH|WIDTH
|
|
6-chars long|6-chars long
------------|------------
%CHAIN|%CHAIN
%EJECT|%EJECT
COMMON|COMMON
CREATE|CREATE
DELETE|DELETE
REMARK|REMARK
RENAME|RENAME
RETURN|RETURN
RIGHT$|RIGHT$
UCASE$|UCASE$
VARPTR|VARPTR
|
|
7-chars long|7-chars long
------------|------------
%NOLIST|%NOLIST
CONSOLE|CONSOLE
RESTORE|RESTORE
SAVEMEM|SAVEMEM
|
|
8-chars long|8-chars long
------------|------------
%INCLUDE|%INCLUDE
COMMAND$|COMMAND$
CONCHAR%|CONCHAR%
CONSTAT%|CONSTAT%
LPRINTER|LPRINTER
|
|
9-chars long|9-chars long
------------|------------
RANDOMIZE|RANDOMIZE
|
|
10-chars long|10-chars long
-------------|-------------
INITIALIZE|INITIALIZE
|
|
EOF|EOF

Ok


Conclusion
----------

We have demonstrated that the 8080 and 8086 versions of CBASIC
have the same keywords. So, CBASIC Version 2.8 = CBASIC-86
Version 1.0.

The only difference I can see at a glance, without disassembly,
is that the 8080 version can also run under MP/M, while the 8086
version seems only to run under CP/M-86. And the 8086 version no
longer checks the printer.

However, if anybody out there finds a copy of the CBASIC-86
User's Guide for CP/M-86, I will be very happy to know what it
says. In particular, I would like to know how to CALL 8086
subroutines...

If you ever wrote any, say, "General Ledger" for CP/M 2.2, you
will be happy to learn that you can continue to use it under
CP/M-86! Of course, your 8080 assembly language subroutines will
no longer work, but it look likes CBASIC-86 can run natively
8080 INT files... This Old Faithful "General Ledger" is going to
run!

Yours Sincerely,
"French Luser"


EOF


.