Perceptions

Authors

Publication

Pub Details

Date

Pages

See all articles from SYNC v2 n1

4K and 8K ROM Command Conversions

4K and 8KROM Command Conversions

In the last issue of SYNC (1 :6) I began a discussion of the conversion of programs from the 4K Integer Basic to the 8K F.P. (Floating Point) Basic and covered expressions and functions. In this issue I will conclude the discussion by detailing the processes necessary for the conversion of commands from one ROM to the other.

The following commands are 100% transferable from a program on one ROM to a program on the other ROM:

  • LET
  • REM
  • NEW
  • IF….THEN
  • RUN
  • INPUT
  • CONT (INUE)
  • PRINT
  • STOP
  • LIST
  • GOTO
  • POKE
  • RAND (OMISE)
  • CLEAR
  • GOSUB
  • RETURN

Because a parallel for each of the commands in the 4K ROM exists in the 8K ROM, I will list alphabetically all the 8K ROM commands. When possible, a 4K ROM conversion will be given. (The names of the 4K commands will be given in brackets.)

CLS [CLS]

The CLS command is used to clear the entire (TV) screen. On a 4K ROM system or an 8K ROM system with less than 3.25K of RAM, the CLS command works identically (i.e., it creates a minimal display file). On an 8K machine with more than 3.25K of RAM, a full display file, padded with spaces, is created. The command is generally interchangeable between ROMs.

COPY

The COPY command is used to print the screen, as is, on the ZX Printer. As the printer cannot be used with a 4K ROM system, there is no simulation available to perform a parallel function.

DIM [DIM]

DIM is used to create arrays and matrices. On the 8K ROM, both numeric (F.P.) and string (character) arrays are available. On the 4K ROM, only numeric (Integral) arrays are available. As noted earlier, (see Perceptions, SYNC 1:6), there is no way to use floating point numerics on a 4K system. String arrays are also, generally, out of the question.

The 4K ROM’s integral arrays are useful in that they save 3-bytes per number. If you have an application that really needs integral arrays because of memory size constraints, a method can be derived to emulate them. As usual, the gain in space will result in a slow-down of the system.

Imagine a situation in which you want a 100-element intergral array. Running the 4K Basic, to allocate it, you might type:

DIM A(100)

This would instruct the system to reserve 200 bytes for the elements of the array (2bytes each). To reference the 40th element, you might use the statement:

LET J=A(40)

My 8K emulation is relatively simple. In place of the original DIM statement, use the following:

DIM A$(200)

Then, to reference the 40th element, you would use an expression like:

LET J = CODE A$(39*2+1)+ CODE A$(39*2+2)*256

This method accesses the appropriate element’s value by reading its 2 data bytes and combining them, putting the result into the variable J.

To change the value of an element, you might use the following sequence:

10 LET TEMP=INT(J/256)
20 LET A$(39*2+ 1 TO 39*2+2) = CHR$(J-TEMP*256)+CHR$(TEMP)

This would set the 40th element to the value of J and is equivalent to:

LET A(40)=J

Generally, the subexpression to use if you want to reference the Xth element is:

CODE A$((X-1)*2+1)+CODE A$((X-1)*2+2)*256

FAST

FAST is a command used to control the video mode of the ZX81. The ZX80 (i.e.. 4K ROM) is always in FAST mode.

FOR…NEXT (STEP) [FOR…NEXT]

The FOR and NEXT commands are used to set up a loop in the program. The 8K version has two features not implemented on the 4K version. The first is that you may have non-integral values for the looping variable. This cannot be simulated on the 4K ROM. The other feature, a STEP modifier, can be simulated.

If you run the following program:

10 FOR J=1 TO 10
20 PRINT J
30 NEXT J

you will see the numbers from 1 to 10, stepping by 1, printed on the screen. If, on an 8K ROM, you run the program:

10 FOR J=1 TO 10 STEP 2
20 PRINT J
30 NEXT J

you will see the numbers from 1 to 10, stepping by 2, printed on the screen.

The first program is equivalent to the following:

10 LET J=1
20 PRINT J
30 LET J=J+1
40 IF J<11 THEN GOTO 20

Notice that in line 30, the value stored in J is incremented by one. To make this run as per the 8K program, add line 5 as follows:

5 LET ST = 2 

and change line 30 to say:

30 LET J=J+ST 

Now it will run and print the numbers from 1 to 10 on the screen, stepping by two.

LLIST

The LLIST command is used to list out the program on the ZX Printer. As is the case with the COPY command, it is not possible to use the printer, and, thus, the printer commands, on the 4K ROM.

LOAD [LOAD]

The LOAD command is used to bring a previously SAVEd program back into the computer. The 8K version uses a file name {possibly null) to specify which program on the tape you want to LOAD. The 4K version simply takes the next program on the tape and LOADs it. The formats on 4K and 8K programs involve such a differential as to make it a fruitless venture to attempt to LOAD a program SAVEd oil a 4K machine into an 8K machine, or vice versa.

LPRINT

The LPRINT, used to print a line out to the ZX Printer, has the same constraints applied to it as does LLIST.

PAUSE

The PAUSE command is used to delay for a given number of frames on the TV (16ms), while continuously scanning the picture. Barring a moderately complex machine language program, it cannot be simulated. (For those interested, I suggest my article ‘The ZX80 Keyboard” (SYNC 1 :2), which describes the keyboard/display scanning routine, as a good starting point.)

PLOT/UNPLOT

These commands are used to PLOT particular graphics points on the screen. There is no completely parallel function on the 4K ROM. It must be done with a PRINT statement.

SAVE [SAVE]

The SAVE command, used to SAVE the current program on tape for later retrieval, is available on both ROMs. The only difference is that the 8K version takes a name as an argument.

SCROLL

SCROLL (SCreen ROLL) is used to roll the entire screen up one line. Although no parallel exists in the 4K Basic, it can be (and has been) simulated with machine language. See Ian Logan’s article “Screen Scrolling” (SYNC 1:4) for more details.

SLOW

The SLOW command, like the FAST command, is used to select the video mode of the ZX81. It is non-functional on a ZX80 with an 8K ROM and cannot be simulated on a 4K machine.

Products

 

Downloadable Media

 
Scroll to Top