ZX Fun
a) Adding new BASIC commands
This part will only give a brief theoretical overview of how new BASIC commands can be added to existing ones. To create a new command, you need to know the machine language of the Z80 processor and the operating system of the computer itself. Most personal computers had a built-in operating system that allowed you to create your own BASIC commands and add them to existing ones.
The creators of the ZX Spectrum did not provide for this possibility. Only with the Interface 1 operating system did it become possible to easily and simply add commands to suit your needs.
I-1 has a system variable VEKTOR that handles these operations.
When creating a new command, it is important that it throws an error both when it checks the syntax and when it executes. Here are some examples of how this can be achieved:
POKE 0,1,2— extra parameter;DRAW 10— skipping the required parameter;PLOT,10- incorrectly specified parameter;CODE— use of a function from E-MODE;!AUTO— adding a new command.
In the latter case, the command must be entered character by character. For the first character, choose something that is not a letter.
After this character, the cursor will move on, and you can enter a new command character by character. After the first character that is not a letter, you can enter existing BASIC keywords - in this case they will take on a new meaning.
Creating a new team
To create and add new commands, you must:
- good knowledge of the machine language of the Z80 processor;
- know how the computer operating system works and how errors are processed in the additional 8K ROM.
Working with the BASIC interpreter
This portion of the 16K ROM program processes each BASIC instruction twice. It first only checks the syntax and then executes the command.
For example, if you want to add one program line with one command to an existing program, the entire process can be divided into three stages:
-
The programmer enters a command (for example,
100 PLOT 0,0) at the bottom of the screen. While he is typing the program line, it is stored in the EDIT BUFFER. After you finish typing (by pressing the ENTER key), the line is copied from here to the top of the screen and pasted into the program. -
When the ENTER key is pressed, the interpreter begins checking the syntax of the newly entered line in the EDIT BUFFER. It first recognizes the
PLOTcommand, then looks for two numeric arguments separated by a comma. If they are found, the line is copied to the top of the screen and takes up ma place defined by its number.
Control then returns to the editor, and the computer is ready to enter a new line. If the syntax check does not find a valid command or required argument, an appropriate error message will be printed and the program line will not be copied from the EDIT BUFFER. However, correct command syntax does not guarantee its successful execution. For example, the following command is syntactically correct, but will still produce an error when executed:
100 PLOT 200,200
- Command execution begins with
RUNorGO TO. The BASIC interpreter begins step-by-step parsing again and executes the corresponding subroutine in ROM. If an error occurs, execution is interrupted and a corresponding message is displayed.
Error checking
If an error occurs while checking the syntax or while executing a command, the routine at address 0008 in the 16K ROM is called. Most often this call is made with the command:
RST 8
DEFB -N=error code
When an error is encountered during syntax checking, a question mark appears at the location where the error is most likely located; During execution, a corresponding message is displayed. If I-1 is connected to the computer, the error handling process changes slightly.
Going to address 0008 in 16K ROM causes a ROM switch. The old 16K ROM is disabled and the new, additional 8K ROM in I-1 is enabled and error processing continues there. First, the return address from the subroutine that caused the jump to address 0008 is checked. This address is loaded into the HL register pair. If the value in HL is zero, then the return is from the 16K ROM routine called by I-1. If HL=15FEh, then the search for channel I-1 has just completed.
If the error code does not match any of the following:
NONSENSE IN BASIC
INVALIDE FILE NAME
INVALID STREAM
control returns to the main 16K ROM, where the actual error message will be output. However, any of the listed errors could have been caused by our new team. Therefore, we now need to reinterpret the entire line in which the error was detected.
The system will first store the address pointer CH-ADD (5C5Dh) in CHADD- (5CCBh), that is, the position that the line interpretation has reached. This will allow you to restore the pointer value later.
The routine starting at this address restores the value from CHADD- to CH-ADD, after which it continues to output an error message to the 16K ROM. This means that instead of jumping to our subroutine, we can use the subroutine whose address is specified in VEKTOR. Enough before executing our commandYou can write to VEKTOR the starting address of a subroutine that will check for correct syntax and then execute the appropriate subroutine. Please note that your commands should not begin with commands designed to work with the Microdrive and I-1.
When writing a command execution routine, consider the following:
- When jumping or calling a subroutine, you always remain in 8K ROM (all addresses refer to the additional ROM, not the main one).
- Call the subroutine from ROM I-1 with the
CALLcommand, do not useHOOK CODE. - During execution of a subroutine in 8K ROM, the keyboard state is not read, and the internal clock (
FRAMES) does not work - regardless of whether interrupts are enabled or disabled.
The internal clock cannot be used during this time.
And you will have to provide keyboard reading yourself from the program.
- Using the restart procedure has a different effect than the procedure from the 16 KB ROM.
Material prepared by:
Brada Joseph
Bajmočka 18
24220 Cantavir
b) Sound effects
DARKO sent us two programs from Majdanpeka that create certain sound effects.
These are the programs:
10 FOR n=50000 TO 50040:READ a:POKE n,a:NEXT n
20 DATA 17,152,2,6,10,197,58,
30 RANDOMIZE USR 50000:IF INKEY$="" THEN GO TO 30
Adding the following line to the previous program produces a buzzing effect:
25 POKE 50000.17:POKE 50001.1:POKE 50002.23
Material prepared by:
Radulović Darko
O.Š. Debeli Lug
19250 Majdanpek
c) Error loading from cassette?
Surely this has happened to you: you received a cassette with programs (some people call it a cassette with games), but some programs could not be loaded. Usually the computer would freeze at startup or later, and sometimes it would reboot.
You check such a program with a neighbor who also uses Spectrum - it works for him.
You immediately suspect your tape recorder and try to adjust the azimuth, adjust the volume, move the equalizer...
But this doesn't help, and in the end you, clearly puzzled and frustrated, decide to buy a new tape recorder. You sit down impatiently, insert the cassette into the tape recorder, press PLAY and the download begins. You get to the point where the computer used to freeze with this program, but to your surprise, the program freezes again.
It's not the tape recorder or the program, but the ROM of your Spectrum itself. Since the Spectrum was produced by many manufacturers, the ROMs also varied. Some added commands, others entered their name instead of copyright information, others translated ERROR messages into Serbo-Croatian or German and made other similar changesia in ROM (look at PNP-electronic in its younger years).
Therefore, some data in memory does not match with the ROM, that is, with those 16 KB of machine code in the ROM, consisting of various procedures, and the program cannot interact with it normally.
This problem also arises when using some EPROM modules and interfaces that are produced both in our country and throughout Europe. Simply put, one manufacturer's ROM may not be compatible with another manufacturer's interface. This problem is usually solved by replacing the ROM at your favorite service center. Typically, you only do this when connecting equipment through an interface. There are 10,000 programs released for Spectrum - games and utilities (according to unofficial data, about 15,000), so about ten programs, that is, about 0.7%, may not work. Therefore, changing the ROM is not profitable.
Material prepared by:
Čanković Srđan
XII Voj. ud. brigade 59
25000 Sombor
Share your thoughts about the article