Where is the system monitor in the ZX Spectrum? Riddle PC Duet

    The PC Duet is a Russian clone of the ZX Spectrum 48k, manufactured by the Lianozovsky Electromechanical Plant (LEMZ). This is my very first computer and it is still with me. From a young age, I began to learn the basics of programming, microprocessor architectures and designing digital circuits on it. But since then I have been haunted by the question: where is the system monitor? After all, it is mentioned in the documentation. In the standard ZX Spectrum, I do not recall the presence of any system monitor. And the documentation about the system monitor is not a word more. There is a Monitor for 48k in the ROM version of 1990 . However, after turning on, the Duet PC displays instead of the standard greeting - "(c) 1982 sinclair research ltd" another greeting: "(c) DUET". And this means that the ROM there is still changed. Or maybe there are hardware monitoring capabilities? For example, the clone Orel BK-08 has a number of improvements: shadow RAM, the NMI button and the MZ80 monitor. It would be very interesting, after so many years, to find some hidden capabilities of your piece of iron.

    Finally, I found the answer to a question that periodically worried me all these years.

    image

    Why now?


    As you know, spektrumizm - almost incurable. And long periods of remission can be replaced by exacerbations under the influence of external factors: some article, the anniversary of the Spectrum , and here you are again on the forums , again on the table there are Spectrum (which are not one or even two ) and turn on and work(or not). And then, gradually lets go. But some questions still remain unresolved and they hang somewhere deep in the subconscious and every time they strive to break out. They are not solved, as a rule, due to the hardware irrelevance of the platform (which is actually debatable). But what if the resolution of long-standing issues, problems or desires, even if not relevant now, can please the present? Indeed, now it is easier to do. I think it's worth a try!

    The next coming issue of the monitor


    For the first time, I asked about the monitor almost immediately after the purchase, but I did not find the answer. Already in our time, in early 2016, I tried to find out on the forum , but again the answer was not found. The question would have been forgotten, but by chance I came across an advertisement for the sale of the Spectrum clone - “Nafanya” , and there was a photograph of the documentation page in which it read: “The ROM contains a Basic language interpreter and a system monitor” . Well, we still decided to figure it out and put an end to this issue. The

    image

    comrades in the forum gave advice:
    Most likely, a system monitor refers to a set of standard ROM routines. Try:
    1. look at the installed ROMs on the board, it looks like you have 2 pcs of 8K each, it's 16K, if there are no additional ROMs, then you need to look among the available 16Ks.
    2. merge the ROM dump and compare with the standard Sinclair dump, usually only the inscription in clones changed. According to the differences, one can figure out if there is something interesting.
    Well, it can't be that simple! Studying the circuit showed that there are no additional ROMs there: two ROMs of 8Kb each (components of a standard 16kB ROM with a basic). Judging by the photograph of the insides of my particular instance, my version is no different from the scheme on the site (in fact, there are minor improvements / changes, which, perhaps, another time). Thus, the hardware capabilities for the existence of the monitor were not found.

    Compare ROM dumps


    In order to merge the dump and compare it with the original, you need to do the following steps:

    1) Get data from the ROM on the Duet PC. To remove the ROM from the board and use the programmer for this is not required at all. For the simple reason that the ROM in the 48k version is entirely mapped to the address space at 0..16383 addresses . This is the bottom of the address space. You can either read it programmatically or save it through a tape output using the BASIC command SAVE "ROM" CODE 0, 16384

    2) Convert data from the sound file to a TAP file using the utility on your PC
    3) Extract data from the TAP format to binary
    4) Write or find a utility for comparing two binary bytes files - from the Duet and from the original Spectrum.

    Already at the first stage I rejected this idea, because the laptop does not have a linear input, and the adapter is soldered to me only in the direction of playing sound on a PC or smartphone through a linear output to connect to the input of the Duet PC. Because 99% of the time now is loading data into a Duet, and not vice versa.

    Therefore, I decided to do exactly the opposite. Take the original ROM and load it into the Duet's RAM via the tape input. Then write a program for reconciling data in memory cells with the output of information of different cells. The binary data of the original ROM is in almost every ZX Spectrum emulator. But to translate them into sound, for subsequent download via the tape input, I had to tinker a bit. I went through 3-4 programs before I could make a TAP file from a binary file. Then it’s easier - with the help of the utility Tape2WAV received sound files.

    To load data from a tape recorder in the ZX Spectrum BASIC, the LOAD command is used, with parameters that indicate that the code is loaded and in which memory address to load it, respectively, the commandLOAD "" CODE 40000 loaded the data of the original ROM into memory, starting at address 40,000.

    Writing a program for reconciling memory


    I rub my hands joyfully because I have to remember my school experience and program under the ZX Spectrum and on it myself! But, by the way, what is there to remember? Basic is impossible to forget, all the more so simple. To make a mistake in the instruction set is difficult, because each press of the button brings the whole team at once. Fast and convenient, like T9, only for BASIC! I also want to say that using 48k BASIC on the emulator is just not convenient, due to the fact that BASIC commands are not signed on modern computers. Another plus of even such a small machine as 48k: we are immediately ready to work after switching on. No development environment, no compiler required. All that is needed for work is in ROM.

    The basic inside the ZX Spectrum is interpreted. This reduces the speed of the programs. But to write such a simple and not speed-critical program in assembler - I think this is already too much. The program is written in 5 minutes. And even if it works the same, then it will suit me. But it turned out that it took even less than five minutes:

    image

    In the screenshot, the program that I typed in the emulator (only to take a screenshot with the source code). I got the same program on the Duet. On top of the screenshot, I signed the data on the differences found in the memory cells. Well, there are not so many changes. Now you need to understand what these changes have affected. To do this, you need to know what is in the ROM at the addresses found. Fortunately, all the information is in the book “Complete ZX-Spectrum ROM Disassembler” in Russian .

    Cell 109 - in the original 40d ROM in the Duo 32d
    006d 32 instead of 40. This means 20h (JR nz, *) instead of 28h (JR z, *), and in the book jr nz.

    image

    As it turned out, in the original version of ROM from 82 years old, a mistake was made in this place. This is the code for handling a non-maskable interrupt. Without this error, you can set the NMIADD variable to the address of the transition to the processor, for example, the same monitor. And by the NMI signal (using the NMI button, as on the Orel BK-08 ), the computer would switch to this processor. Corrections at this address indicate that in the Duet this error has been fixed and the NMI signal can be fully used. Well, it’s not bad anymore, but judging by the number of remaining changes in the ROM, the monitor code is not sewn into it :(

    Expectedly, 4 bytes is “DUET” instead of (C) 1982 Sinclair Research Ltd
    1539 (C)
    153A пробел " "
    153B 68 "D"
    153C 85 "U"
    153D 69 "E"
    153E 212 последний символ. инвертированный. 212d + 80h = 54h - "T"


    (MESSAGES - Each message is displayed with the last character inverted (+80, hexadecimal).

    There is no monitor, are we diverging?


    Unfortunately, I did not find any system monitor-debugger, although I tried very hard. But I am very glad that I was able to find out on my own ... But. But what exactly is a “system monitor”? Why is it written about him in the documentation for the Duet and Nathan? As described above, “Most likely, a system monitor refers to a set of standard ROM routines . Also, in a book with a complete ZX Spectrum ROM disassembler, we can read the following:

    ...
    ПОЛНОЕ ОПИСАНИЕ ПЗУ КОМПЬЮТЕРА ZX SPECTRUM
    ...
    ВВЕДЕНИЕ
    Монитор Spectrum, объемом 16K, представляет собой сложную программу в машинных кодах
    Z80. Ее можно разделить на три основные части:
    а. Программы ввода/вывода.
    б. Интерпретатор BASIC.
    в. Вычислительные процедуры.
    Однако, для подробного описания эти блоки слишком громоздки, и поэтому монитор
    разделен еще на 10 частей. Каждая часть будет представлять собой элемент монитора.


    In recent years, when someone writes about the ZX Spectrum, then he will most likely call the contents of the ROM the OS ZX Spectrum - this is the built-in BASIC. But in those days, apparently, such a concept has not yet been formed. There were small programs - monitors for viewing and changing the contents of memory cells in the HEX form. Used to debug programs in machine codes. Compared to them, the Spectrum "monitor" was very cool. And what we now call the “monitor” was then more often called the “display”.

    Thus, a certain change in the meaning of concepts occurred. A monitor then and a monitor now are different concepts. So, we can assume that the monitor is still found :) Or maybe someone has additional information? ZX Spectrum

    Links
    for Users and Programmers - System Variables - NMIADD
    ZX-Review 1991 №1 - Secrets of the ROM - NMIADD and an error in the ROM
    Microprocessor Kit Z80. Book 1. 6. System interruption. - about NMI
    "Full disassembler ROM ZX-Spectrum" in Russian
    Z80 Instruction table

    Also popular now: