ZX SIMDOS
by Carlo Delhez 
from Your Computer, October 1983

Discover the ease of programming with a Disc Operating System
on the ZX-81 with Carlo Delhez.

[To use demo files:
[* LOAD and RUN file SIMDOS to set RAMtop
[* LOAD (auto-run) file SIMDOS4 to load and relocate SIMDOS program
[* RAND USR 32300 to run SIMDOS program
[To load files from demo "disk":
[* LOAD and RUN file SIMDOS to set RAMtop
[* LOAD (auto-run) file DISK
[JimG

A DISC OPERATING system is a small part of the ROM that enables a
computer to write and read programs on to and from a disc. The read or
Load procedure is very fast as is the write or Save procedure. The
Load procedure usually provides a menu of all the programs available
from the disc.

Using this machine-code program for the 16K ZX-81 you can discover the
ease of programming with a DOS - Disc Operating System. I have called
it Simdos, an abbreviation for Simulated DOS. It allows for fast
Loading and Saving without having to use a cassette or diskette.

Simdos is totally written in machine code so you can place it above
RAMtop where it is protected against Clear and New. Type in program 1,
start your tape recorder and Run. Whenever you want to use Simdos,
Load this program which resets RAMtop to address 32300. Now you can
start entering the hex codes in figure 1, using program 2 - a normal
hex loader with one extra advantage: when data has to be entered, you
do not have to type the hex codes corresponding with the data. You
just type the data preceded and ended by a dollar-sign.

So, when you want to enter SIMDOS as data, you do not have to type
382E32293438 - the hex codes for the individual letters - but simply
$SIMDOS$. This facilitates entering data. The Load, Save and Return
statements in the data at address 32418 can be obtained from the
keyboard by typing THEN, followed by the statement concerned and
finally by deleting the keyword THEN and putting the cursor back in
its correct position. Figure 1 contains all the machine-code
instructions and every four bytes of data is provided with an address
indication, so you can check whether or not you have forgotten one or
more bytes or double-typed some.

If you think you have mistyped a byte, break into the program by
inputting Stop. You will get an error-message, but do not bother about
that. Make a note of the address at which you made your mistake, list,
edit line 50 and change 32300 into your address. When you Run again
you can start entering the hex-codes from this address onwards. After
having entered all the hex-codes and data you will have to subject the
program to a final test by means of program 3.

Check everything very carefully as one little error might cause an
irretrievable program crash. Once you have tested all the bytes for
accuracy, you can Save them.

This has to be done with a special program as the position of RAMtop
and the bytes above it are not Saved by the Basic-Save. Program 4 uses
machine code to copy a block of bytes into array A, then Saves the
program and again uses machine code to copy the contents of A, placing
them in their proper positions, starting at address 32300.

The machine-code program to achieve this is shown in figure 2. The
second time this machine code is used the EX DE,HL is changed into
NOP. If you have done everything as described, the program can be Run.

Simdos offers three possibilities after being executed. I will discuss
them one by one.

Save: One stipulation that has to be met is to include a program-name.
This name has to be put behind a Rem-statement in the first line of
the program. It must contain at least one and at most 30 characters
which all have to have a code between 10 and 64. Spaces are also
allowed.

An error-message is displayed if the first line does not contain a Rem
statement or the number of characters behind the Rem is too small or
too large or illegal characters are found. If all is correct, the
program is Saved. On return the program can neither be seen, or Run.

Simdos-Load will put it back into visible memory. If you have machine
code stored in the first line here is a hint for you on how to adapt
it: First type Poke 16510,2. This instruction transfers the first
line, the one with the machine code, to line 2. If you already have a
line 2 in your program this will not be swallowed by the new line 2.

Next, add line 1 including the program name. To Run the machine code -
in the second line - use Rand USR (x+4+Peek 16511) instead of Rand USR
x, where x is something around 16514. You will have to go through your
Basic and machine-code program to change the addresses that are called
by USR and Call.

For example, if you give a certain program the name Name then Peek
16511 equals 6. The machine code that first started at address 16514,
now starts at address x+4+Peek 16511 or 16514+4+6 = 16524. If you want
to Save a Program without having to pass the menu, use Rand USR 32425.

Load: Having Saved several programs using the above routine, you will
probably want to reload them. This can be done employing Simdos-Load:
after having executed Rand USR 32300 just choose Load. Now the
computer will display a menu, showing all the programs available.

Pick out one of them by pressing the key corresponding with the number
- or letter if there are more than nine programs on the menu - in
front of the name. The program will now continue in fast mode and Load
the program preferred. Although the Loading goes very, very fast it
still might take a little while.

Once the program has been loaded it is automatically executed. If you
do not want this automatic run, just type Poke 32726,0 and to regain
this facility Poke 32726,64. Error messages are given when no programs
are available from the disc or when the program currently in memory is
not saved yet.

* When one program is Saved and another Loaded, all the variables used
with the first stay intact. You can use this with different programs
to generate and manipulate strings.

* The programs are stored above each other, all before the
display-file, that is shifted up each time you add a program. After
being Run program 5 will show all the programs stored.

* New will destroy the total contents of the disc, not only the one
that can be seen.

* When USR 32425 or Save is executed within the program, the execution
continues until a Goto, Gosub or Run statement is found; then the
computer will stop with an end-of-execution message. List and LList
are always ignored after Simdos-Save.

* To save a disc on cassette I should use program 6. The machine code
is not Saved by the Basic-Save; use program 4 instead.

* It is best to put all the full "discs" on one cassette, preceded by
program 1 - which resets RAMtop - and program 4 which Loads the
machine code above RAMtop.


Program 5
   1 REM PROGRAM 5
  10 FOR X=16509 TO PEEK 16396+256*PEEK 16397
  20 PRINT CHR$ PEEK X;
  30 NEXT X


Program 6
   1 REM DISK-SAVE
   2 REM PROGRAM 6
  10 RAND USR 32425
  20 SAVE "DISK"
  30 RAND USR 32300


Figure 2
16514    2A1040     LD HL,(16400)
16517    110600     LD DE,6
16520    19         ADD HL,BC
16521    112C7E     LD DE,32300
16524    EB         EX DE,HL
16525    01F401     LD BC,500
16528    EDB0       LDIR
16530    C9         RET
