╒───·───════════════════════════════════════════════════───·───╕
│·▒█░█▒·▓█████████████████▓ ·HARDWARE· ▓█████████████████▓·▒█░█▒ │
╘───────════════════════════════════════════════════════───·───╛
(C) Jason Frost
I want to share a few thoughts on developing the hardware side
of the SPECCY:
- Video processor.
- Adapting Dendy games for the Spectrum with a video processor.
- IDE hard drive—build it yourself. See HDD_IDE1.C and HDD_IDE2.C
for the connection diagrams. - A network Robot for the ZXnet network, based on any Spectrum-
compatible computer, preferably with a hard drive (Scorpion ZS,
ZXNEXT, or PROFI). - AY-3-8910(12): new capabilities. Undocumented registers and how
to use them. - HAYES modem—not just simple, but dead simple!!! See HAYES.C for
the connection diagram. - SWEATY, DISGUSTING LAMERS are switched with OUT (#FD),A !!!:::((>>
- The world's smallest 4-channel, 8-bit music card. Circuit
included.
A.S. The article isn't finished yet; for now, read what there is. It's
4 a.m., you understand...
Many will agree that having just one graphics mode for every
occasion is pretty boring, and not always optimal.
Although there are computers with or modes (SCORPION,
ZX NEXT:-)))))) and PROFY), implementing them on a standard 128
machine is difficult, and not always possible :-((. Besides, these
modes are mostly supported by programs that use CP/M.
Adding an extra attribute video mode requires less drastic
changes to the video controller circuit, but I'll talk about
programmable hardware multicolor later.
Of course, you could go the route of adding more video memory
and clock speed, but that's the IBM PC way—not our way. We like
graceful elegance, and we don't like clumsy overengineering. By the
way, the French say: "Elegance is born of a lack of resources."
There you have it. I looked at PC schematics )>:->>(( and they made
me sick :()()()! Nothing more hideous and monstrously stupid could
possibly be invented! Sewn together with crooked bits and white
thread! No wonder you need insane megahertz and megabytes just to
make the whole thing work at all! But that's a subject for another
article. I'll just say that if you compare the quality of ZILOG
hardware 15 years ago with Intel today, Intel will be left in the
SHIT!!!
The much-praised, heavily advertised, "progressive" Pentium MMX
is 8 Z-80s + MHz + a fan on top! And the Z-380 isn't even worth
talking about! The Pentium is shit! You can't fool an old
Sinclairist!!!
So Intel and ZILOG are like an ass on a throne, but as far as I'm
concerned, I'd rather have a small throne than a big, heavily
advertised, multicolored ass!
In 1996, ZX РЕВЮ ran a series of articles by S. Veremeenko on
a video processor for the ZX Spectrum based on Motorola's UM1F-2
chip. Either Sinclairists have forgotten how to read, or they
don't have any memory, but hardly anyone knows about it. Well, I
know!!! ::;-)))))))))) And I'll tell everyone!!!
1. What this system can do
It can be used in different ways: either as the main video controller or as an additional one. The screen can display images generated simultaneously by the standard ZX controller and the new video processor.
It can also be used as an active two-channel sound card, something like General Sound; you can put it to work on mathematical calculations—in short, anything you like.
This piece of hardware costs next to nothing and won’t bankrupt anyone. The circuit is extremely simple (like all the designs by our homebrew geniuses—Intel should learn a thing or two from them!), yet effective.
2. What is UM1F-2?
Basically, it is intended for 8-bit video consoles, but ours is a special case, so we’ll treat it accordingly.
This chip consists of three very neatly integrated components:
- A central processor based on Motorola MC2.
- A Motorola 7 sound chip.
- A video processor 8 from the same company.
To avoid confusion, let’s get this straight: MC2 is the LINK between the Z80 and the sound processor and video processor, and it is the only one that can execute assembler commands.
I should also add that in most video consoles, at most 20–25% of the system’s capabilities are used. If we use them to the fullest, it’ll be really cool!
The MC2 CPU, along with the Z80, is considered one of the most successful processors in the world. In particular, the well-known Apple II computers use it.
I have a description of the 2 assembler; I’ll definitely type it up and put it online. The cross-assembler and cross-monitor/disassembler for the 2 on the SPECTRUM were written by S. Veremeenko, and you’ll soon be able to get them on any BBS.
The instruction set and architecture of the 2 deserve a special mention.
The MC2 has three 8-bit registers: A, X, and Y, each with accumulator capabilities, as well as a 9-bit stack pointer and a program counter. Instructions are up to three bytes long, and every instruction executes in two cycles. Its memory addressing is insane (those familiar with Amiga assembly will understand): there’s some sort of triple-indirect and double-indexed addressing, though that’s what gives Motorola its speed and flexibility.
Here are just a few instructions:
| Mnemonic | Code | Approximate Z80 equivalent |
|---|---|---|
LDA #12 |
#A9 #12 |
LD A, #12 |
LDA 2h |
#AD #12 #00 |
LD A, (#2) |
LDA 12h, X |
#A1 #12 |
LD A, ((#2 + X)) |
LDY #12 |
#A0 #12 |
LD Y, #12 |
LDY X, 12h |
#BC #12 |
LD Y, (X + #12) |
LDX Y, 4h |
#BE #34 #12 |
LD X, (Y + #4) |
ADC #34 |
#69 #34 |
ADC A, #34 |
ADC 34h, Y |
#71 #34 |
ADC A, ((#4) + Y) |
JMP (8h) |
#6C #78 #56 |
JP ((#8)) |
Not only the accumulator, but the other registers can also be loaded and stored directly.
Notation: a # sign, as in #12, indicates data; the letter h, as in 2h, indicates an address.
The sound processor’s audio quality is close to the AY, but it far surpasses the AY in the variety of sound modulations. In any case, a couple of extra channels won’t hurt.
In the address space of the 2, the sound processor’s registers (ports) are located at addresses #0–#3.
║ Here, REGISTER does not mean a CPU register (except A, X, Y):
║physically, it is a PORT! The thing is, the MC2 has no IN or
║OUT instructions, so several memory locations were assigned to
║ports and called registers! In other words, the program has to
║access them as memory, using instructions such as LDA and STA,
║while the hardware decodes them as PORTS!
It’s very convenient that they’re all right there, so you don’t have to switch, as with AY via #FFFD.
The video processor can display an image of * pixels in 64 colors, with 4 brightness levels (this has not been precisely determined; there may be additional shades). Each pixel can have its own color, and there is no attribute clash.
It’s something like the Sinclair QL, only better and faster. The image consists of three independent planes:
- background plane
- landscape plane
- sprite plane
All three planes are INDEPENDENT of each other, and each has its own color palette.
The sprite-generation system is fully autonomous and allows up to 64 sprites to be displayed on screen simultaneously.
I’ll describe everything in detail below.
2. How is all this connected?
Nothing complicated: 17 wires + Reset + power. There are some synchronization issues, but they’re not a problem either. A phase synchronizer has been developed; it monitors the frame and line sync pulses and prevents them from losing synchronization.
From the programmer’s point of view, it’s a bidirectional I/O port with address #7F on the Z80 side, and two registers (ports) with addresses #0 and #1 on the UM1F-2 side.
3. How does it all work?
After power-up and system initialization, the ZX video controller is active across the entire screen. The ZX and 1 are separated as follows: if FLASH=0 in a character cell, that cell displays the standard image; if FLASH=1, it displays the image from the new video processor.
When a “Sinclair window” is defined, part of the video processor’s image is replaced with the SPECTRUM image. The window can be any size, from one character cell to the entire screen, and can have any shape or connectivity.
To implement the Sinclair window, we had to sacrifice the FLASH function. This function is hardly used in modern programs, since the effect it produces is very crude and looks bad on screen.
Thus, in the active part of the screen, the video processor is enabled in character cells whose FLASH attribute is 1—that is, when bit 7 of the attribute byte is set to 1.
BASIC example:
FLASH 0
CLS
; THE STANDARD ZX SCREEN IS VISIBLE
FLASH 1
CLS
; THE VIDEO PROCESSOR SCREEN IS VISIBLE
4. CONTROL
This is simple. The video processor is completely autonomous and works by commands. It takes up not a single byte of Spectrum memory and can be connected to any computer.
The video board has a ROM containing a video processor driver loader. It executes only two commands: “identify memory” and “load driver.” The first runs automatically on reset, the second after writing a byte that controls the operating mode.
When you need to use the video processor, you must, after reset:
- read the size of the available memory from port #7F (from 4 to 64K),
- determine whether there is enough, and if there is,
- write two bytes to port #7F:
1st byte — control byte, determines the operating mode after startup.
2nd byte — the high byte of the video driver’s load address; the low byte is always = 0, and the driver length is a multiple of a byte. - Then load the video processor driver from disk and transfer it byte by byte to port #7F, without any delays.
Input/output is synchronized by /WAIT.
The driver autostarts as soon as the transfer is complete; all further control is by commands.
Command codes are simply written from the Z80 side to port #7F.
A command is received via a maskable interrupt; execution is via a non-maskable interrupt, or somehow else.
The driver can be of any imaginable complexity and execute any commands. There are already about a dozen drivers; using cross-assembler 2, you can write as many of them as you like, in all sorts of varieties.
The commands mean things like: “move sprite number... by ... pixels to the right and flip it horizontally; scroll screen number... left and up for... frames at speed...” and so on and so forth. In short, we’ve got a little Amiga on the Spectrum.
The command stream through port #7F is usually around 50 per second, which means the Z80 has a huge amount of free time left. You can sing songs through the AY, ;-) hunt for viruses in ROM—in short, it’s all up to the wise programmer.
You can write games in anything; you don’t have to use assembly. If you can make a cartoon in classic LASER BASIC, you can certainly do it with LASER BASIC + UM.
For those who haven’t seen LASER BASIC, see the file LASDEMO.B. Run it in 48 mode. If you see an error message after loading, just press RUN. At any time, press BREAK, then INK 9 and LIST.
Though I would prefer GRAX. GRAX is a low-level graphics language, like assembly, but for pictures. HEAD OVER HEELS was written in it, along with many other games.
Right now I have a little driver that supports only 15 commands, 14 of which are two-byte commands. Here’s a brief description:
| Command | Description | Register address |
|---|---|---|
| #00 | Set status register | (#0) |
| #01 | Set video output mode register | (#1) |
| #02 | Horizontal scrolling command | (#5) |
| #03 | Vertical scrolling command | (#5) |
| #04 | \ Set external RAM addresses | |
| #05 | / Set external RAM addresses | |
| #06 | \ Set video RAM addresses | |
| #07 | / Set video RAM addresses | |
| #08 | Transfer data to video RAM | |
| #09 | Set X coordinate | |
| #0A | Set Y coordinate of the sprite block | |
| #0B | Change sprite block code | |
| #0C | Change sprite block attribute | |
| #0D | Change sprite block number | |
| #FF | Execute sprite |
The driver is designed for DIZZY-like games.
The attribute of an 8×8 sprite (not to be confused with the Spectrum’s!) looks like this:
bits:
0 - cluster code
/
\
- not figured out! but they’re definitely doing something!!
/
Hardware
Fragment 5/6.
- 0/1 = above/below the landscape
- 1 = mirror flip horizontally
- 1 = mirror flip vertically
Structure of status register (port) #0
Bits:
- 0 — current screen number
/ - not determined!
- number of the block set for sprites
- number of the block set for the landscape
- 1 = double-size sprites
- not determined!
- 0 = mask non-maskable interrupts
Structure of video output mode register #1
Bits:
- 0 — 1 = disable colour output; only brightness levels remain
- 0 = mask the left column of landscape character cells
/ — sprites - 0 = disable landscape output
- 0 = disable sprite output
- \
— have a noticeable effect on brightness and hues,
/ which one — not determined!
The system’s memory map consists of three independent areas, connected
through the DMA controller.
The first area is 64K of address space 2,
the second is 16K of the video processor’s main RAM 8,
the third is 8 bytes of built-in RAM.
┌─ #FFFF
│
│
│
│ Free.
│
│
│
├─ #8000
│
│ Free.
│
│
╔─ #1 Registers for communication with the Z80.
╚─ #0
│
│ Free.
│
╔─ #7
║ Music processor registers, DMA controller
║ control register, joystick ports.
╚─ #0
│
│ Free
│
╔─ #7
║ Registers for communication with video processor 8.
║
╚─ #0
│
│
│ Free
│
│
╔─ #01FF
║ Stack
║
║─ #00FF
║ “Short” addressing area.
║ Variables are often placed here.
╚─ #0
Adapting Dendy games for the Spectrum with a video processor
Adapting games from video game consoles was not the goal in creating
the video processor. The idea came later as a kind of free bonus.
This means we can more than DOUBLE the number of games available to us
in one fell swoop! The adaptation process is extremely simple. You need
a “cartridge analyzer” program and an interface board. The board is
easy to make, and one will be enough for everyone. Insert the cartridge
into the board and start the analysis. Once it’s finished, the program
reports the analysis results and tells you whether adaptation is
possible. The vast majority of cartridges can be extracted and adapted
without any problems. The contents of a cartridge can be viewed, edited
with Crossmonitor 2, and dumped to disk as several files.
All that remains is to attach a simple loader to them and, if
necessary, adapt them for a joystick.
The easiest option is to connect any suitable joystick directly to the
video board; then there’s no need to modify anything at all.
Alternatively, you can replace the joystick polling routine in the game
itself with a routine that sends a request to the Z80 asking, “So, what
the hell is he pressing on the keyboard?”
During gameplay, the data flow through port #7F is minimal—usually a
few dozen bytes per second, or none at all.
IDE HARD DRIVE FOR ANY SPECTRUM-COMPATIBLE COMPUTER
Well, what can I say? It’s not as difficult as many people think.
Putting 12 ports in the computer’s address space is the whole job. I
won’t list the port addresses; I’ll just say that they all end in #AF,
i.e. #FFAF, #FEAF, and so on.
Hardware
Fragment 6/6.
I can already hear the angry shouts: “But what about the modem!!!??” Nothing to be done: the bus conflict has to be fixed.
The thing is, all the IDE controller port addresses look like this:
% 11xxxxxx 01111 / #xxAF
while the CDOS modem port address is:
% 00000 01111 / abbreviated: #EF
There’s an obvious conflict on line A4, because the modem’s #EF port is not fully decoded.
I didn’t make up the IDE port addresses; they’ve long been standard in IS-DOS and CP/M. They’re all fully decoded, which you can’t say about CDOS (a hint to FARAON).
I’m no Clive Sinclair or GPV. I’m not going to change the standards, and I advise nobody else to. We’ve had quite enough trouble with incompatibility!
Fixing the glitch is very simple (two options):
- Solder one small chip (LE1) onto the modem. In addition to checking A4=0, it will also check A6=1. Use the modem and hard drive without glitches, with the ready-made drivers from IS-DOS or CP/M.
- Don’t solder anything, but rewrite all the drivers in IS-DOS and CP/M for your own addresses. That way you’ll get a pile of glitches on other address lines and lose compatibility!
HARDWARE
You need very little hardware: just 8 chips plus a few odds and ends. No expensive, hard-to-find parts, and no adjustments required. See the schematics in HDD_IDE1.C and HDD_IDE2.C.
PRICE
In Mitino you can find a used 40 MB IDE hard drive for 90 thousand rubles, and a new one for 180 thousand. Prices are constantly falling.
SOFTWARE SUPPORT
As I’ve already said, IS-DOS has drivers for various hard drives; you just need to install them correctly.
For example:
set S:RES\stA.blk ;install
dev ;connect
That’s all. Enjoy!
In TR-DOS, each program will have to be adapted separately, but that’s no problem either. Programming a hard drive is much easier than programming a floppy drive, since the hard drive is much smarter and all its ports are directly accessible. None of that idiocy of calling it through #3D2F.
THE ZXNet NETWORK ROBOT
This problem has been brewing for a long time, and it’s already been solved in St. Petersburg. If you’re interested, read ZXNews 37.
What is a network robot? It’s an intelligent server that doesn’t just send and receive files: it checks message headers, and if it finds NetRobot in the To: field, it interprets the contents of the Subj: field as a command.
The simplest option is the trivial %help; in practice, the command could be anything. For example, with %search NICRON47, the robot will download issue 47 of the NICRON newspaper for the user.
The only problem is that even with four drives, the available disk space doesn’t exceed *4=0K, which is clearly not enough. On my Scorpion, the hard drive can be as large as 1900 MB, though in practice even M would be enough. As for transmission speed, I’ll just say there are algorithms that can reach Kbaud at 3.5 MHz, so 00 baud with a HAYES modem connected is no problem.
It’s not hard to modify CDOS for a hard drive, and adding a simple command interpreter is easy too. So get to it, gentlemen coders—or you’ll have to put down the soldering iron, grab an assembler, and code it yourselves, to your utter shame.
Meanwhile, keep writing your absurd megademos and megafucks!!!
The discussion is still open. Send your messages to me at MAL'S BBS or FARAON 1, 2 BBS in a file named >Jason.
To be continued...
Share your thoughts about the article