CBASIC on 68k-mbc, V20-mbc and Z80-mbc2

by coopzone in Circuits > Computers

159 Views, 0 Favorites, 0 Comments

CBASIC on 68k-mbc, V20-mbc and Z80-mbc2

IN-intro.jpg

This instructable gives an outline of how-to compile a CBASIC program, in this case a simple DISKIO test program. On any of the mbc based SBC computers.

Details for the versions of CBASIC for the three SBC's are in the Supplies Section.

The Demo I will use is DISKIO.BAS. It creates a file TEST.DAT on each of the virtual disks A-P, fills the file with a message, then deletes the file and moves on to the next disk. It does this until any key is pressed on the terminal or a maximum of 200 times. The idea being to test the SD-Card you are using, since some SD cards can be unreliable. This normally highlights them with a disk io error. If all is well you will not get any errors. (200 times is a bit much I normally terminate it after 10-20 runs through or overnight)

Supplies

All of the versions of CBASIC for CP/M-80, CP/M-68 and CP/M-86 have been uploaded to GITHUB as either a zip file or individual files. You can find them here:

https://github.com/coopzone-dc/cbasic

If you prefer you can also find all the files around the WEB. The only file you need in addition (and you can just type it in if you like) is the DISKIO.BAS source file.

You will need a working cpmtools setup on either linux of windows, some people like to use cpmtools GUI. I assume you have a working setup of this if not see:

Cpmtools GUI version (from http://star.gmobb.jp/koji/cgi/wiki.cgi?page=Cpmtoo... ) use google translate the original is in Japanese - unless you are skilled enough to read it. I found that windows complained about the binary file not being signed and blocked it on the first run. You need to decide if you trust the author and the program before you use it! I did, but i'm only working on a VM. It did work ok, but these instructions are based on the non-gui version.

The non-gui version, if you prefer. (I have based the instructions on this version. From http://www.cpm8680.com/cpmtools/cpmtoolsWin32.zip

You will also need a copy of the diskdefs file for your system, from the cpmtools directory on the SD-Card.

Setup Cpmtools

CB-cpmtools.png

Use the links in the "supplies" page to get a copy of cpmtools

You may want to read through https://www.instructables.com/Z80-mbc2-Virtual-Disks-Copying-Files/ to explain in more detail about the disk images and copying files to them.

Windows

I recommend using a directory in the root of your C: disk for example C:\cpmtools

Unzip your downloaded files to a temporary directory by right-clicking on the filename and choosing extract all. Choose a path for your extracted files.

Copy the following files to your working directory:

cpmcp.exe

cpmls.exe

Copy the diskdef file to the working directory, form the SD-CARD /cpmtools/ directory.

Linux

Install the cpmtools package for your version of linux (for debian/ubuntu versions it's 'apt-get install cpmtools')

Replace the diskdef file (normally in /etc/cpmtools) with the one from the SD-CARD /cpmtools/ directory.

Done

Copy the CBASIC Files to the SD-CARD

ng-dir.png

The SBC computers use virtual disk files to represent disk drives in CP/M. You can find a description of this works here https://www.instructables.com/Z80-mbc2-Virtual-Disks-Copying-Files/ I am only going to list the steps needed to copy the files from the CBASIC zip files on the github site (supplies section).

Note:

The v20-mbc already has a copy of CBASIC on the SD-CARD, in the image DS1N04.DSK this loads as disk E under cpm.

The 68k-mbc already has a copy of CBASIC on the SD-CARD, in the image DS0N01.DSK this loads as disk B under cpm.

If you used these copy's of CBASIC you only need to copy the DISKIO.BAS file (or cut/past it into a file on the respective disk above).

Steps to copy to Drive G:

1, Download and unzip to a temporary directory the version of CBASIC for your MBC board.(see Github)

cb80.zip - z80-mbc2

cb86.zip - v20-mbc

cb68.zip - 68k-mbc

2, Put your SD-CARD into your computer, note where it is mounted (linux and windows will auto mount it, windows gives it a drive letter linux gives it a path)

3, Copy to the correct disk image (assuming you are in the directory you just unzipped the files to, the path of drive letter are the ones given by windows/linux when you inserted your SD-CARD)

for 68k-mbc

cpmcp -f 68kMBC-D0-15 [path or drive letter]/DS0N06.DSK *.* 0:

for v20-mbc

cpmcp -f V20MBC-D1-15 [path or drive letter]/DS1N06.DSK *.* 0:

for z80-mbc2 (assuming cp/m 3)

cpmcp -f z80mbc2-cpm3 [path or drive letter]/DS2N06.DSK *.* 0:

When done, eject or umount the SD-CARD , use it to boot your MBC and check the content of drive G.

The Test Program

This is the test program, if all went well it should be on your drive G (or if B or D if you choose to use the already installed versions of CBASIC). It's pretty simple. The only thing that is unusual really is the lack of line numbers on each line. When yo remember back to BASIC programs most people recall each line started with a line number. In CBASIC you only need line numbers if yo intend to refer to it from a goto or gosub etc.

for l%=1 to 200
 print "LOOP:"; L%
 for D%=0 to 15 
  F$=CHR$(65+D%)+":TEST.DAT"
  print "FILE: "; f$
  create F$ as 1
  for f%=1 to 4096
  print #1; "This is a large file for testing purposes - delete it 01234561234"
  if CONSTAT% <> 0 then goto 999
  print using "###### !"; f%,chr$(13);
  next f%
  delete 1
 next D%
next L%

999 rem 
l%=CONCHAR%
print "Exit program"
delete 1
end

The program consists of 3 loops using variables f%, D% and I%. The exit condition is detected by the special variable CONSTAT% and the code from line 999 onwards cleans up and exits the program. I have also included copied of the CBASIC manuals on the github site. They are all slightly different versions but the core of CBASIC is the same on all MBC's.

Compile the Program

The process of compiling is very simple, unless you intend to write a major project in CBASIC it's possible to compile the code into an object file using the command:

for z80-mbc2

cb80 diskio.bas

for v20-mbc

cb86 diskio.bas

for 68k-mbc

cb68 diskio.bas

When you run your compiler command it will output the following (or similar), any error should be corrected if you manually entered the code it's most likely going to be syntax related.

Sample output from z80 version:

G>cb80 diskio.bas
-------------------------------------------------
CBASIC Compiler CB-80   21 May 83 Version 2.0
Serial No. ACB-0000-000072  All rights reserved
Copyright (c) 1982, 1983  Digital Research, Inc.
-------------------------------------------------
end of pass 1
end of pass 2
  1: 008bh for l%=1 to 200
  2: 0094h  print "LOOP:"; L%
  3: 00a0h  for D%=0 to 15 
  4: 00a9h  F$=CHR$(65+D%)+":TEST.DAT"
  5: 00c0h  print "FILE: "; f$
  6: 00cch  create F$ as 1
  7: 00e0h  for f%=1 to 4096
  8: 00e9h   print #1; "This is a large file for testing purposes - delete 
>it 01234561234"
  9: 00f5h   if CONSTAT% <> 0 then goto 999
  10: 0100h   print using "###### !"; f%,chr$(13);
  11: 0118h  next f%
  12: 0126h  delete 1
  13: 012ch  next D%
  14: 013ah next L%
  15: 0148h 
  16: 0148h 999 rem
  17: 0148h l%=CONCHAR%
  18: 014eh print "Exit program"
  19: 0154h delete 1
  20: 0160h end
end of compilation
no errors detected
code area size:  352    0160h
data area size:  8     0008h
common area size: 0     0000h
symbol table space remaining: 30685

Linking the Program

There are some differences in the linker usage for the different systems. I think this is because over the years people have added/substituted the original versions with later ones. So on some systems the linker has been copied from other packages and does not have the defaults set for CBASIC. On others there are at least two linkers in the directory, but only one works!. So look closely at the command that matches your system.

To link your object file and produce an executable you need to run the following command:

For z80-mbc2

lk80 diskio=diskio,cb80.irl
--------------------------------------------------
LK80 Linker       15 Apr 1983  Version 2.0
Serial No. ACB-0000-000072  All rights reserved
Copyright (c) 1982,1983   Digital Research, Inc.
--------------------------------------------------
code size:   2680 (0100-277F)
common size:  0000
data size:   024F (2780-29CE)
symbol table space remaining:  B116<br>

Note: for the z80 you don't need to specify the .com extension for the linker.

For 68k-mbc

link68 diskio.68k=diskio,cb68.l68
--------------------------------------------------
LINK68 Overlay Linker                  Release 0.f
Serial No. XXXX-0000           All Rights Reserved
Copyright (c) 1983          Digital Research, Inc.
--------------------------------------------------

diskio.68k=diskio,cb68.l68 <br>

Note: on the 68k version, you don't get as much information as the others.

For v20-mbc

link86 diskio
--------------------------------------------------
LINK-86 Linkage Editor                 Version 1.2
Serial No. 3152-0598-000051    All Rights Reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------

CODE    026C8
DATA    00423

USE FACTOR:  07%

Note: with the v20 version you don't specify the library to link.

Running the Program

Untitled 2.png

This is the easy bit!

To run your compiled program, just type it's name:

E>diskio
LOOP: 1
FILE: A:TEST.DAT
Exit program<br>

And away you go. Exit with any key.

Have fun!