• Please review our updated Terms and Rules here

S-Basic

Peter Schorn has kindly given two code examples for running the SIMH simulator. The first (above) talks to the SIMH from within vb.net via Telnet. The second method opens the SIMH in a dos window and runs a batch file which can include instructions such as change a drive or run a file. This is even faster and is particularly useful for debugging code.

Speed tests on compiling a 228 line program with one keypress from within vb.net:

Copy to a real CP/M board at 4Mhz and compile = 4 seconds for xmodem transfer and 60 seconds to compile.
On the SIMH via Telnet then sending to a real board and running = 8 seconds.
On the SIMH using the code below as a batch file = 3 seconds.

The trick is to create some small text files first and then shell the SIMH to run those files. This is the code in vb.net
Code:
      ' compile using SIMH but leave the SIMH window open, and don't send to N8VEM
        Dim Location As New Process
        Dim Filename1 As String 'eg MYFILE.BAS
        FileOpen(1, "C:\N8VEM\AltairSIMH\SIM.BAT", OpenMode.Output) ' open a file
        PrintLine(1, "altairZ80 sim_cmd")
        FileClose(1)
        ' create the large simulation file
        FileOpen(1, "C:\N8VEM\AltairSIMH\sim_cmd", OpenMode.Output) ' open a file
        PrintLine(1, "d tracks[0-7] 254")
        PrintLine(1, "attach dsk cpm2.dsk")
        PrintLine(1, "attach dsk1 basic.dsk")
        PrintLine(1, "attach dsk2 games.dsk")
        PrintLine(1, "attach dsk3 sbasic.dsk")
        PrintLine(1, "attach dsk4 supercalc.dsk")
        PrintLine(1, "attach dsk5 tools.dsk")
        PrintLine(1, "attach dsk6 wordstar.dsk")
        PrintLine(1, "attach hdsk i.dsk")
        PrintLine(1, "set cpu 64k")
        PrintLine(1, "set cpu noitrap")
        PrintLine(1, "set cpu z80")
        PrintLine(1, "set cpu altairrom")
        PrintLine(1, "set cpu nonbanked")
        PrintLine(1, "Reset cpu ")
        PrintLine(1, "set sio ansi")
        PrintLine(1, "set sio nosleep")
        PrintLine(1, "attach sio cpm_cmd") ' attach the little file below to run a batch
        PrintLine(1, "boot dsk") ' will run till type HALT which runs HALT.COM
        PrintLine(1, "bye")
        FileClose(1)
        ' now create the file to compile
        Filename1 = Strings.Left(SbasicFile, Len(SbasicFile) - 4) 'trim the .bas
        FileCopy("C:\N8VEM\" + Filename1 + ".BAS", "C:\N8VEM\AltairSIMH\" + Filename1 + ".BAS")
        FileOpen(1, "C:\N8VEM\AltairSIMH\cpm_cmd", OpenMode.Output) ' open a file
        PrintLine(1, "D:") ' sbasic is on the D drive
        PrintLine(1, "R " + Filename1 + ".BAS") ' read the file into the SIMH
        PrintLine(1, "SBASIC " + Filename1) 'compile it
        FileClose(1)
        ' shell the altair SIMH
        Location.StartInfo.FileName = "SIM.BAT"
        Location.StartInfo.WorkingDirectory = "C:\n8vem\AltairSIMH"
        Location.Start() ' shell the batch file
        Sleep(2000)
        Kill("C:\N8VEM\AltairSIMH\" + Filename1 + ".BAS") ' clean up
 
Last edited:
I think both systems complement each other. I always seem to need the real hardware running at the same time. I find I make two sorts of errors when writing code. The first are syntax errors, like writing "end procedure" instead of "end", or "dim a as integer" instead of "dim a = integer". These are usually the product of switching from other languages like vb.net. So for these errors, it is helpful to run them through the SIMH. But the second sort of error is the code not doing what it is supposed to. The only way to test these is on real hardware, and for my current projects, this is very much true because a lot of code is talking to real serial ports and other hardware specific code that isn't implemented on the SIMH. The CP/M board and the PC are permanently connected at the moment.

Another feature of sbasic is the ability to write procedures that replicate functions that have become indispensible in modern languages, eg trim and ucase. One thing that is easier now is to put these functions in a library on the internet and have others contribute.

And one day, down the track, I'd like to get this running on a good old fashioned original CP/M machine just to prove it can be done. I keep scouring ebay and other places and sooner or later something will turn up that is local and doesn't involve large shipping costs. Meanwhile, I can admire with admiration the wonderful photos people post on this forum!
 
Oh, I get it (I think). So the PC is being used as an emulator for preliminary testing/debugging your code? That makes sense, I guess. I wish you luck in getting a vintage CP/M box soon. Then you'll understand where I'm coming from. There's nothing like running the old hardware (I didn't realize you don't have anything like that).

--T
 
A quick update on where this sbasic is going. I've been coding for several hours a day every day for the last month but haven't had a chance to write it up yet. I've got a program that has grown to 30k in size now. Compiling that on a real cp/m board is taking a *long* time so the SIMH is proving invaluable (though it is still 20 seconds and another 20 to download the .COM).

The program is designed to be a repeater for wireless modules and is going to end up in cp/m machines out in the field, so one feature is an auto upgrade via the network. Trials are running with three cp/m boards. This is now working - the sbasic program can create a batch file and then shell out to that batch file, and the last entry reruns the program. It can shell out to xmodem, and tell another board, via wireless, to also shell xmodem and then the xmodem does the file transfer. 30k at 1200 baud takes a little while, but it only does this when the network is quiet. There are rf modules up to 19200 baud but 1200 has a longer range. So an upgrade consists of programs periodically comparing their version numbers, and if a new version is ready it is copied across, and then another batch file is created that renames the old version as the new version, and then reruns the program but it is now the new version. The new version of the program propagates through the network.

The point of all this is to have a program that can route messages through a wireless network. It is all the backend stuff in the internet that we take for granted and it is quite challenging to simplify it to fit in a cp/m environment. Wireless nodes need to send out 'ping' messages from time to time to see who is near them, and then test those links for reliability. That ends up being a simple text file that sbasic can create, and which can be read with any text editor. It can also be copied to other boards via wireless by shelling xmodem as above. So every board can build up links to nearby boards, and then get the list of links from every board. With that information, any board can work out the optimum path for a message through the network with the minimum number of hops.

The thing that is becoming increasingly clear is how well structured sbasic is. Programs in, say, mbasic, become very difficult to understand once they grow to 30k in size, with gosubs to line numbers that have no meaning. sbasic, on the other hand, can take subroutines and call them names that make sense. I've added some vb.net commands such as ucase and trim, and then the code ends up looking like .net code.

sbasic does have a few disadvantages. Loading and Saving text files takes a little time. And one has to remember it is a single pass compiler, so subroutines can only reference subroutines above them so there is sometimes some cutting and pasting to change the order of subroutines in the code. And the Chain command only can chain sbasic programs so there is a bit of custom programming to make a $$$.sub file in the exact format required in order to chain programs like xmodem.

Overall though, it is proving a pleasure to work with. I've got about 30 useful functions and procedures now and when I get a moment I might publish those somewhere in case anyone else wants to use this program.
 
I've got a complete standalone CP/M computer now http://hackaday.com/2009/03/04/n8vem-computer-with-a-3km-wireless-link/

Technically, it isn't vintage, but I do note that most of the chips on the N8VEM board were made in the mid to late 1980s.

Sbasic is going well. Recently on the N8VEM forum someone wanted to move the cursor around on the screen and they wanted to use LOCATE. We couldn't quite do that as locate is already a keyword, but we got close with CURLOCARE. Or we could have used LOCATE_CURSOR or anything really. sbasic enables you to add your own keywords, eg CLS, and hence build up your own language.

And of course, for the purists, it would be written in Wordstar or another text editor on the actual computer. Sbasic takes about 1 minute minimum to compile on a CP/M computer which is a bit longer than doing it on a PC and sending it over. On the other hand, a PC takes over a minute to boot up, but a CP/M computer is about 3 seconds. So for one simple change to a program and then a recompile, it is now faster on a real CP/M computer.

There are standard vt100 codes to change text color. So sbasic can work in color too :)
 

Attachments

  • locate.jpg
    locate.jpg
    90.3 KB · Views: 1
Back
Top