Monday, 24 April 2017

USB Mouse for the ZX81 and ZXpand (Part 1)

A USB mouse on a ZX81 sounds a little mad and yet given the wealth of plug and play electronics available in 2017, it's a comparatively painless task to implement. To be clear I'm talking about a digital mouse, one that uses an Atari style joystick port, where proportional mouse movements are converted to digital signals.

Why a digital mouse? While not being a true proportional mouse implantation, it is a path taken by at least one 8bit computer, the Commodore 64 and it's 1351 Mouse back in the 1980s. As an added bonus this also means the mouse interface should work on all 8bit systems that support the Atari protocol. At the end of the day it's smarter to build on an existing solid and supported base such as Charlie Robsons'  ZXpand with its digital joystick implementation, than it is to implement a non supported (by existing software) standalone proportional mouse interface; at least for now.

So now it's down to how to get this thing to work, and my prototyping weapon of choice is an Arduino UNO armed with a USB host shield. The USB host shield really is the key to the project, it comes with an extensive Arduino / C++ library ready to plug in, leaving the casual developer or hobbiest free to solve other non-USB related hardware and software puzzles.

Stage 1: Getting a Test up and Running

Testing a 4006 IC vs a Diode
As we will be leveraging the ZXpands joystick port for interfacing our mouse (and Adruino) with, we need to trigger all mouse movements by simulating joystick button presses. To achieve this the correct signal lines on the joystick port must be pulled low (pulled to ground). We also need to insure that we don't unduly damage the ZX81 / ZXpand in the process of doing so. Ideally we'd wish to partially electrically separate the Arduino from the ZXpand (partially, as we will eventually be drawing power from the joystick port), so that unintentional voltage are not shot in the wrong direction, particularly during testing phase. There are numerous ways ways to achieve this, I tested 2 options.

Option 1: Use Some Diodes.  Diodes can be placed with the cathode to Arduino output pins, and anodes to the joystick port lines. Our Arduino can then set the input to 0v when we wish to trigger a simulated push button action, and there will be no possibility of feeding +5v back to the ZXpand / ZX81.

Option 2: Use a 4066 IC bilateral Switch. This is the slightly more complicated method, though not by much. A bilateral switch can be used to act as Joystick buttons. Power is applied to the IC switch and 2 connected lines are switched on, much in the same way a relay works. There is an easy to follow tutorial to be found on the subject at Brainy Bits. Th e main downside to this method is that in order to trigger the 5 required buttons on the joystick port (up, down, left, right and fire), we would need 2 ICs and all that extra routing on a PCB that that would require.

I wired up the 4066 IC switch for one input and implemented the diode method on an other, needles to say both of the above variations worked, producing the same results of simulting a button press / movement on the ZXpand Joystick port. I decided to go with the diode method for ease of implementation. If however we were in a position were we might be dealing with different voltage levels, such as a Teensy or Pro Micro with 3.3volts and the ZX81 with 5volts, the switch would be the better option here.

Stage 2: A DIY Cut-down Arduino Clone

If one of the aims of this project is to make something a little more permanent, then using a Uno for the end solution is not the ideal. I could just design a simple shield for the UNO, however the USB host shield will still be required, and with the addition of an extra shield on top, would leave the whole project a little unwieldy for what it actually achieves.

It seems apt to mention here before proceeding, there is such a beast as a Adruino UNO and USB host in one easy to use package. Freetronics makes the USBDroid, this could be a perfect solution for proof of concept stages, however to use this in a semi-permanent ZX81 mouse interface seems a bit of a waste.

Bare-bones Breadboard Arduino (and shiny lights)
Anyways, the last little blurb aside, the intention is to mount a USB shield on a Arduino clone board, one with all the other required elements built in. All parts, from the diodes to connectors for the the joystick port and a through port for an actual digital joystick. As I've never built one of these before, I thought it best to build a bare-bones cut down Arduino on a breadboard first, then hook that up a USB shield for some more testing.

At the risk of sounding like a paid advocate for Freetronics, I used their easy to follow Tutorial - build your own "breadboard Arduino", as the basis for the rest of the design. The rest of the design consisting of connecting to USB host shield and the ZXpands joystick port.

There are a number of Arduino pins that must be connected to the USB shield, INT, SS, SCK, MOSI, MISO and RESET. Also required are  a 5v power source (which we will eventually tap from the ZXpands joystick port) and a 3.3v input. To generate the 3.3v a down voltage regulator circuit needs to be added to the end design.

For full details on the USB Host Shield, there is an extensive manual and resources available on the Circuits at Home website. I can't recommend that highly enough.

Stage 3: Build a Prototype Mouse Interface PCB

Mouse PCB. Note the USB Host Shield Mounts on Top.
Lastly on the hardware side of thing I wanted to build a demo PCB board to bring everything together. I employed the help of Fritzing for the PCB design. Fritzing is not the most feature rich of programs, however it is approachable and presents a low learning curve to the casual user, perfect for these small projects.

I wanted the end PCB to be easily producible and assemblable at home. As such I designed the board to be primarily one sided, any tracks that had to be placed on the topside are straight. The final (or ongoing) Fritzing files will be available for download. if anybody plans to make the PCB at home, only the bottom layer needs to be etched and copper wire strands can be used for the linking via's. If preferred, the boards can be fully double sided for usage by PCB fabrication houses or the DIY experts.

I've covered the home PCB making process I use in a previous article way back when I first started this blog. If you're interested refer to Creating A PCB For Mounting The Keyboard Controller.

Next Time: Software and Other Bits

Coming up in Part 2, I'll look into the software side of the project, post the schematics, code and parts list for building the ZX81 USB mouse interface. For now feel free to have one or more views of the teaser video on You Tube.

Thursday, 23 March 2017

Peeking into the ZX81s Screen Maze

While thinking about some possibilities of how to approach various projects in my to-do list, I realised that these were going to need some screen reading elements, or rather I'd need to PEEK into the display file to see what was going on. This lead to some re-research into how the ZX81 handles its screen output. While some excellent information on the subject is not hard to find, I figure a poke into this might be of use to others.

What's being displayed by the ZX81 on a monitor at any given time is not exactly a mystery, nor is how it got there. What  can be mystery is how to retrieve that information for (re)usage in an application. Actually that's not much of a puzzle either, though possibly a little ambiguous at first.

The ZX81 stores screen related information in a area of memory known as the "display file" or DFILE for short, this is outlined briefly in chapters 27 of the ZX81 manual. What's not made quite so clear is how to access that area of memory, or how that area is configured at any given moment by the machine. This last part is particularly crucial if your ZX81 has less than 4k of RAM (Not of any real concern these days I suppose, but you never know.)

The relationship between the ZX81 Display File and D_File system variables laid out for easy reference.

First off we need to know where the DFILE resides. The location is not static (unlike the ZX Spectrum's DFILE) and moves up or down depending on the size the BASIC program listing. Thankfully there is a system variable, D_FILE, which stores this starting location. What we need to do is PEEK the address of the D_FILE variable to ascertain the location of the actual DFILE. Note that address is stored in 2 bytes.

PRINT PEEK 16396 + PEEK 16397 * 256

On a freshly booted system the result of  the above should be 16509. You might notice that this is also the starting address for the "Program" memory area, which indicates that there is currently no program stored.

Next we can determine how large the DFILE is by reading the system variable VARS. This is where a non expanded ZX81 will differ from one with a RAM pack attached. The returned value will give you the starting location of the user Variables memory allocation area. Again note that the returned listed values from PEEKing the VARS system variable assume there in no program loaded.

PRINT PEEK 16400 + PEEK 16401 * 256

Variables starting address on a 1k ZX81 (or 2k Timex 1000) is: 16534
On a ZX81 with 4k or more expanded memory: 17302

If we subtract the value of D_FILE from VARS, the byte allocation or size of the DFILE is revealed. What we notice is that on a 1k ZX81 the default size of the DFILE is 25 bytes, and on a 4k plus system the DFILE is allocated 793 bytes. The massive (overstatement) size difference between an expanded and unexpaned machine comes down to how the ZX81 handles the DFILE. On a 2k or less machine the DFILE is expanded as it is required, while on a 4k plus computer the DFILE is always fully extended.

On a 1k or 2k ZX81, each of those 25 bytes contains a CHR$ 118, the Newline Character. One CHR$ 118 marks the start of the DFILE , and when a line is printed to, the DFILE is expanded to a maximum of 32 characters per line, with each line always being terminated by a Newline.

A ZX81 with 4k or more always has a fully expanded DFILE, containing 25 CHR$ 118, marking the start of the DFILE and end of each line, plus 32 * 24 characters, which are initially CHR$ 0, the space character, yielding a 793 byte total.

Putting the above into practice, two programs below demonstrate how to POKE to the screen directly, instead of PRINTing. The key lines in both applications are 80 (highlighted), where the second PEEK address is adjusted for either the expanded or collapsed DFILE.

1) Program For a 1K ZX81. If using an emulator make sure it's set for 1K
20 PRINT AT 2,8;"+++"
30 PRINT TAB 8;"+ +"
40 PRINT TAB 8;"+++"
80 POKE PEEK 16396+PEEK 16397*256+41,CODE A$
90 GOTO 60

2) Program For a 4K and up ZX81. If using an emulator make sure it's set for 4K or more
20 PRINT AT 2,8;"+++"
30 PRINT TAB 8;"+ +"
40 PRINT TAB 8;"+++"
80 POKE PEEK 16396+PEEK 16397*256+109,CODE A$
90 GOTO 60

The programs above have been modified from listings originally published in the September / October 1981 issue of Sync Magazine, which is available from the Internet Archive. It's well worth trawling through the entire Sync back catalogue for all manner of useful insights.

Using the information above you can see how easy it is to read or write to the ZX81s screen, and then take that into more complex programs. For a deeper insights into the ZX81s display, you can't go past Wilf Rigters' extensive write up The ZX81 Video Display System.

Finally, yes you really can do something interesting with this information, the below maze is generated by a program written in C for the Z88DK compiler. The Maze generator relies heavily on being able to read the Screen / DFILE (that and a maze algorithm). Feel free to download The Maze C source and ZX81 P file for perusal.

Output of the ZX81 Maze Program.

Tuesday, 7 March 2017

RAMming in Some External Retrofits

With the internal updates out of the way in the last 2 Retrofitting articles (Simple Start to Retrofitting a ZX81 and Advancing along with the Retrofitting of a ZX81), it's time to add an external RAM pack. Nothing unusual there, after all the first expansion (and possibly the only expansion) any ZX81 owner attaches to the back of their humble 1k micro is a 16k RAM pack. But this is 2017 and a simple 16k RAM expansion just doesn't cut it, and it certainly didn't cut it back in 2011 either, and so enters the amazing ZXpand, bringing RAM packs and ZX81s into the new millennium.

The Amazing ZXpand


The ZXpand created by Charlie Robson is firstly a 32k RAM expansion, nothing odd there, however it's also an SD card reader, provides user configurable memory mapping, hires graphics modes, a reset switch, pads on the circuit board to add a joystick port and optionally (via an extra add on expansion) the ZXpand can accommodate an AY sound interface with a fully built in joystick port. For the moment I'm happy with the base model sans AY.

In a nut shell the ZXpand does for the ZX81 what the DIVIDE (in all it's incarnations) does for the ZX Spectrum. Coming pre-assembled, the ZXpand plugs right into the back of a ZX81 (or TS1000) and is ready to go. The build quality of the board is exceptional, and there are even little amusing gems of ZX81 lore written on the boards Silk screen layers.

If you need some convincing of the ZXpands merits check out VectrexRoli's typically flamboyant video review on the Youtubes.

The ZXpand is intermittently available on Sell My Retro, normally released in batches. You'll need to watch out for these appearing as they sell very quickly. The AY Sound interfaces seem to go at an even quicker rate.

ZXpand Needs a Case

Now for all it's merits the ZXpand comes without an encasing. The good news is that there are options, firstly if you have an existing Memotech RAM expansion, then you can gut that, make a minor modification, then slide the ZXpand into void.

The Elongated Cube ZXpand Board Enclosure

Alternatively, should the massacre of harmless ancient peripherals disturb your delicate sensibilities, or more likely you find yourself bereft of Memotech devices, then as luck would have it mhudson52 on Sell My Retro, has recently started producing 3D printed enclosures in various form factors. Models include a classic Memotech inspired design or the ever popular elongated cube form factor. Both versions have counterparts that allow for the AY interface. I obtained a rectangular version of the ZXpand Board Enclosure for my purposes.

The Enclosure  is a well designed smart little black case. The ZXpand fits very snugly inside, and the
whole unit nestles perfectly behind a grateful ZX81. Being 3D printed, the board enclosures finish is a little rough, so don't expect molded plastic perfection.

The only minor short coming in the cases design is the slightly diminutive hole at the back for accessing the ZXpands momentary reset / NMI switch. In order to press the switch through the case you require something the width of a knitting needle or a thin tablet stylis.

Wire Soldered to the ZXpands Pads

Adding A Joystick Port 

ZXpand Joystick Solder Pads
Adding a joystick port to the base ZXpand requires a little soldering, a DB9 male connector, and the usual assortment of wires. The location of attachment points / pads are outlined in the ZXpands manual and these can easily be hooked up to a male DB9 solder-able connector. Wiring should follow the standard Atari 2600 joysick pinouts.

As I intended to attach the  joystick port to the ZXpand Enclosure, I figured the best way would be to separate the metal casing on the DB9 connector. This would allow me to attach the connector to the inside of the enclosure and at the same time cover up any defects created when making some necessary holes in the enclosure on the outside.

Atari Joystick Port Pinout
Atari Joystick Port Pinout
DB9, with Metal Surrounds Separated
The two metal halves of the DB9 connector are pressed together, a lip in the bolt / screw holes keeps two halves firmly in place. To separate them you can file away the lip around the bolt holes. Once separated connecting wires from the ZXpand joystick pads can be attached to the back of the DB9 shell.

After some examination and testing, I found the most convenient location on the enclosure to place the DB9 connector was at the bottom right. This placement allows the ZXpand to slide in and out of the case without hindrance from the DB9 connector.

Using the outer metal shell of the connector as a template, the placement of the joystick port can be marked out before cutting into the case. I used a Dremel like tool for cutting into 3D printed case. You need to be careful and take your time, as printed plastic likes to re-melt when heated by friction generating power tools. Regardless of how genteel one is, the process will most likely leave a rough edge that needs to be carefully filed away by hand.

The Back of the ZXpand Enclosure, With Holes for the DB9 Connector and Mounting Bolts Cut Out

Joystick Port Mounted
Mounting the DB9 connector is straight forward, if a little fiddly. The enclosure is a little flexible and the mounting point I chose is rather close to one of the ICs on the ZXpand. For this reason I chose to use plastic bolts and nuts for mounting; I didn't want some accidental short circuiting taking place when inserting a joystick.

As the case is designed to fit the ZXpand snugly, the wires to the joystick port had to be routed via the bottom of the enclosure, not a major issue, as these can still be tucked up inside the case mostly out of sight and definitely out of the way.

Joystick Port as seen from the Rear of the Enclosure.

It should also be noted that there is no standard for Joystick interfaces on the ZX81. So much of the software supported by the ZXpands Joystick port has been adapted by the community. There is a list over at the Sinclair ZX World forum of some of the supported tittles.

Getting to that Reset Button

Fully Sprung Reset Tube
As mentioned earlier, the case design makes is a little challenging to access the reset / NMI switch. With fate on my side and some creative thinking I had the means to bodge up an effective solution to that minor issue.

In my draw of miscellaneous items I found a small aluminium tube with a handy flange on one end. The rim fitted over the momentary switch perfectly and the barrel was the perfect length and width to fit through the reset hole on the ZXpand enclosure.

To complete the switching mechanism, a spring extracted from a donor retractable biro was cut down to size, fitted over the tube, and a perfect rest switch was in place.

Another option for the reset switch length problem would be to de-solder the existing SPST momentary push button, replacing it with a longer stalked equivalent. This one from Altronics would do the job quite nicely, any components vendor should have similar items.

So that's it, a ZX81 fit for use, super charged and in better shape than it was 36 years when rolled off the Sinclair (ok Timex) production line.

ZXpand / Enclosure attached to the ZX81. The Reset Switch is the Perfect Length

Sunday, 19 February 2017

Lode Runner on the ZX81 - Part 2 (Level Design)

There are going to be numerous challenges facing the design and implementation of Lode Runner on the ZX81, and one of the first I need to consider is level storage.

The original Apple II version of Lode Runner comprised 150 levels, these were loaded from disk when required. The ZX81 doesn't afford us the luxury of being able to load from a disk or tape without clearing the running application and memory. So even if we assume our ZX81 has 32k of RAM (about the maximum for the time), squeezing all 150 levels into the diminutive black box is an insurmountable task.

There are modern storage solutions available such as the ZXpand, that could be used to negate the space restrictions, however there is no common file access method shared across these modern deceives. So regardless of current available solutions, the challenge here is to fit as many levels as possible into the resources we do have at our disposal.

To make the challenge slightly easier I'm going to base the level design on the Apple II version, not the (possibly expected) ZX Spectrum incarnation. The reason for this is a simple matter of level storage space. The Apple II maps are a convenient space saving 28 wide x 16 tiles high, where as the Spectrum versions comes in at 32 wide x 22 tiles high. Or to put it another way, 448 tiles on the Apple version versus 704 tiles on the Spectrum version per level to define.

If we look to any "type in" game from the period as a (bad) example, most defined entire screens in the program listings on a one to one tile basis. This method would uses 1 byte per tile, and clearly there is not enough space in a ZX81 for even 10 levels defined in this manner (and still have a game to play). It's imperative to compress each level down as far as possible.

The solution is to store the tile type and the number of tiles(of the same type)  in succession into 1 byte. To achieve this, we can use two 4 bit numbers. This affords us up to 16 available tile types, and 16 successions of that tile. Wwe add the number of tile repeats, 0 to 15 to the tile type value. The tile type value is bit shifted before the addition, and this will produce an 8bit number we can store.

Lode Runner Map Tiles: 4 bit Number Values Chart
Tile No4 Bit ShitedLevel Starting Position Tile Type
000000Empty: Clear Tile / Background
001016Block: Can't dig through tile
002032Bricks: Can be dug into to create traps
003048Bricks, Fake: Player falls through fake bricks
004064Rope: Player can move horizontally, or jump down
005080Ladder: Visible all game / level
006096Ladder, Escape: Visible only after all gold is collected on a level
007112Gold: Player to collect all gold
008128Guard: Starting position of Guards. After level begins guards fall from the top of screen (after being trapped).
009144Player: The Lode Runner

For example, using the table above, if we require 4 Bircks in a row, we take the value of Bricks, 32 and add it to the number of required repeats 3, for a total of 35. In, in order to produce the entire starting positions of the first level of the Apple II version of Load Runner, each of the 16 rows would be defined as bellow.

01) 15,1,96,8,
02) 3,112,12,96,8,
03) 38,80,38,2,96,8,
04) 6,80,73,96,3,112,3,
05) 6,80,3,33,80,2,38,80,33,
06) 6,80,3,33,80,9,80,1,
07) 4,128,0,80,3,33,80,9,80,1, (missing right guard and gold)
08) 33,80,36,3,39,80,38,
09) 1,80,15,0,80,6,
10) 1,80,10,128,4,80,6,
11) 40,80,41,80,6,
12) 8,80,9,80,6,
13) 6,112,0,80,73,80,2,112,2,
14) 3,80,37,8,38,80,
15) 3,80,8,144,1,112,8,80,
16) 47,43

Lode Runner, Level 1, Apple II Version

After reading the level data as outlined, the ZX81 level would look something like the bellow screen shot (if using standard character set, no hires graphics yet). Notice that the the escape ladder is drawn in with the "S" character.

Lode Runner, Level 1, ZX81 level Map., Starting Position.

Rather than guess the levels layout, I converted directly from the LodeRunner TotalRecall levels, as (re-)implented by Simon Hung. The TotalRecall levels are implemented in ASCII, which makes reading them easy. The ZX81 map is missing the 2nd guard and gold on line 7, I overlooked these items when writting up the test.

That's all for now, be assured I'm still wotking away on the project, it's just going a little slower than anticipated due to some time and life constraints.

Tuesday, 14 February 2017

Advancing along with the Retrofitting of a ZX81

At the end of the last article, 'Simple Start To Retrofitting A ZX81', a new power supply was sourced and a composite video mod was fitted. This entry sees the near completion of the internal retrofitting project; where some capacitors are replaced, a new voltage regulator is fitted, a lower Amperage CPU inserted and some heatsinks affixed.

Replace Those Old Capacitors

Over a number of years, particularly if exposed to continual high temperatures, electrolytic capacitors tend towards failure. While there is no obvious evidence that the capacitors in my ZX81 have bitten the dust, they are 35 old and probably due for replacement even if purely as a precautionary measure.

Depending on the Issue number of a ZX81, there will be either 2 or 3 electrolytic capacitors on the main board. I have an Issue 1 USA board, as such there are 2 capacitors I'd be replacing. The caps are numbered C3 and C5, are located up the back of the ZX81 PCB, to the right of the modulator and left of the expansion edge.

New Capacitors in Place
Visually the 35 year old capacitors seemed okay, there was no tell tale bulging, or leaking of electrolytic fluids. What wasn't so brilliant was the illegibility of the markings on C5, as the the outer plastic / paper casing of the Caps had shriveled over time (and heating). Handily the ZX81 Service and Assembly Manual is available from numerous online services, confirming the values required:

  • C3 22uF Electrolytic 16V minimum
  • C5 1uF Electrolytic 5V minimum

Both the existing capacitors had voltage levels specked well over the minimums at 50V. Higher voltage ratings are a good thing for capacitors, as a higher voltage rating will prolong their life expectancy. I had some 63V Electrolytic 22uF and 1uF caps at hand and so simply swapped those over for the existing ones.

Switch Mode Regulator

Heat is possibly one of greatest enemy of the aged microcomputer, and lurking inside a typical ZX81 are two major heat manufacturing components, the ULA and a linear voltage regulator. The ULA we can't do to much about, however the regulator can be replaced with a modern switch mode equivalent.

7805 Regulator and Replacement Recom R-78B5
Linear Regulators can get quite hot as all excess energy is converted to heat, the higher the voltage drop required the hotter the regulator becomes. As the case of the ZX81 has minimal ventilation this heat has very few places to go. Modern Switch mode regulators on the other hand produce very little in the way of heat, and no heat equals no ventilation problem.

There are a number of manufactures producing switching regulators, I'm using a Recom R-78B5.0-1.0L, which I sourced from Element14. If  you're conducting a similar mod, the main things to be sure of are that the switching regulator is a drop in replacement for 7805, is 5 volts and rated at 1A or 1.5A. (2A is overkill, unless your ZX81s controlling a nuclear power plant)

The voltage regulator is not hard to spot, it's attached to what looks like a tractor part, or aluminium heatsink if you prefer. If you ever wondered why your left hand got so toasty on a cold winters night programming (OK gaming)  on your ZX81, this thing is the most likely culprit.

Recom R-78B5 In Situ
I started the process by removing the bolt which secures the heatsink to the 7805  and circuit board, once unscrewed the heatsink slid out easily. The heatsink is not required after fitting the new regulator.

Removing the 7805 regulator itself proved slightly trickier due to the large amount of solder holing it in place, plus there being a channel selection switch (being a USA ZX81 variant) and some rubber like trim isolating the switch from the 7805 obscuring the pins at the base of the regulator. In the end I found it easiest to remove the channel selection switch before finally removing the 7805. Note that the process of converting the ZX81 to composite video out, had already made the channel selection switch redundant so decided not to reattach it latter.

The Recom R-78B5 dropped in easily and after soldering it to the board I powered the ZX81 on with no issues or incidents. The only thing to notice is a comparative drop in heat production, the keyboard certainly won't be roasting slowly over an aluminium hot plate anymore.

Cooling the ULA

Self-adhesive Heatsinks mounted onto the ULA.
With the heat now taken out off voltage regulation, this leaves the ULA as the only other major heat source. While there is no easy way to extract radiant heat from the ZX81 case, the overall temperature level inside has vastly subsided.The heat generated by the ULA is now able to permeate the cool void sans 7805. Hopefully attaching some self adhesive heatsinks to the ULA will help keep this vital part a little cooler in general, prolonging its lifespan.

I used two self adhesive heatsinks sourced from Jaycar, laid end to end on the ULA, these are a little overhang and don't quite cover the whole chip. If you're a little more OCD, then it is possible to track down exactly fitting 40 Pin DIP IC heatsinks at specialists stores like Retroleum, or more general and extensive component suppliers such as Element14.

CPU for a CPU, a Fair Swap

Swapping out the existing CPU is more about power consumption than anything else. There are no gains to be made in speed or reliability (unless the old CPU is on the blink of course). The original CPU in my ZX81 was Z80A  made by NEC an NEC - D780C NMOS chip. NMOS chips use quite a lot more power than the more modern CMOS equivalents.

An NMOS Z80 CPU requires  200mA, where as a CMOS Z80 CPU requires only 20mA when running at 4MHz. Considering I dropped the theoretical output of the regulator by 500mA when replacing the the linear regulator for the switching regulator that's a saving worth making.

You can drop in any 40pin DIP 8bit Z80 processor, no matter what the MHz rating. The CPU will only work as fast as permitted by the ZX81s oscillator circuit set at 3.35MHz. My drop in replacement is a 10MHz Zilog Z80.

Z80 processors are still readily available, they come up on Ebay (though proceed there with caution), specialists stores such as Retroleum, and once again though I procured mine via Element14.

Next Time

I still haven't covered everything, I'll attempt a summing up of the (semi) final fixes and extras and addons (which I failed to get to this time), next entry.

Friday, 3 February 2017

Simple Start to Retrofitting a ZX81

My Sourced ZX81 was Modified for the American Market
Having played around with emulating the ZX81 as part of building a Raspberry PI / Arduino platform in the AZ15, I thought it might be fun to revisit the real device.

To start I'd be needing a ZX81, a process that proved trickier than anticipated. There should be no shortage of ZX81s in Australia, yet they seem sparse enough to command high-ish prices, high enough to send me searching further afield. European and UK prices again seemed rather expensive, particularly if including postage. So to the USA then, a Timex 1000 would be just as acceptable, in the end I found a reasonably priced American fitted out ZX81, obviously sent to the new world before the official deal between Timex and Sinclair.

So what exactly can be done to update and bring a ZX81 into the now? Well, there is a great deal of information out there concerning the upgrading, modifying and repairing of ZX81s. Should you decide to do everything from scratch the information and resources are available. However the really good news is that many of the parts required for a refurbishment and upgrade can be bought right off the shelf.

New or Replacement Power Supply

Before even turning on my ZX81 for the first time (in my possession at least) I needed a power supply, my unit came sans power brick. While I had no option but to source a new supply, it's recommended that even if you still have an original Sinclair unregulated power brick that you should still replace it with a switch mode equivalent.

An original Sinclair unit is rated at 9V, however as the supply is unregulated that can get as high as 12V, this leaves the ZX81s internal regulator doing all the heavy lifting. Governing the required 5v (down from 12V) leads to an excessive amount of heat being generated inside the case.

You can use a regulated power supply of anywhere between 7.5V and 9V with a minimum 1000mA (1 Amp ) current draw. The easiest or most available substitution seems to be regulated 9V supply. The power supply should also have 3.5mm phono plug jack plug at the business end. Power input of +7.5V to +9V should be at the tip of the plug, with the lower / outer ring being ground.

I picked up an appropriate Switchmode Plugpack 9VDC 1.66A from Jaycar (Australian Electronics Chain), the unit provided a variety of jacks that can be substituted as or if required. Similar Plugpacks should be available just about everywhere. Ebay often seems to have packs marketed as being specifically for the ZX81.

Optionally a power switching cable can be added between the supply and the ZX81. This will save some wear and tear on the ZX81s power socket These can be made easily enough, or purchased from specialist suppliers such as the Retro Sparse Shop, that's if you don't want the hassle of tracking down appropriate parts yourself and in all actuality might prove more cost effective.

Composite Video Output

The second thing in need of attention is the video signal. as the combination of modern (not the best quality admittedly) LED TV and RF signal emitting from the ZX81 is terrible to say the least.

There are various video mod available that will provide composite video out, ranging from ones that you can build yourself to others ready to fit into the case with minimal fuss. I've gone with an off the shelf fix in the form of the ZX8-CCB, a video mod created by the venerable Pokemon. The ZX8-CCB is available from The Sell My Retro website. Before going into the fitting of the ZX8-CCB, lets quickly look at other composite video mods.

If you choose to build your own then it would be hard to do better than the mod by Joulesper Coulomb detailed in the YouTube video, 'ZX81 Video Conditioning'. A lot of effort has gone into the mod, and spectacular results have been achieved, which can clearly be seen in the video. Minimal parts are required to undertake the modification, it is easily assembled on strip board and once built, the entire project can be housed in the existing ZX81s modulator case.

There are slightly easier mods to build yourself, most of these use a single transistor and a some resistors, such as the simple mod by the ZX-TEAM. You can see the results of that video modification on Terry Stewart's (retro computer collector extraordinaire) web page. However, these simple mods may not work so well with earlier issues of the ZX81 due to a missing back porch signal, and possibly leaving the resulting picture a little on the dark side.

For off the shelf options, there is the Atari (yes you read that correctly) composite video mod for the ZX81, sold by The Future was 8 bit. Dave Curran on his Tynemouth Software Blog, details the fitting of this interface to great effect. Lastly (of course there are bound to be more), there is the Sinclair ZX81 ZXVid - Composite Video/ULA Fix, available from Sell My Retro. You can see the results of this mod on the YouTube video ZX81 - ZXVid board, Composite mod.

Fitting the ZX8-CCB

The process of fitting the ZX8-CCB is very well documented in the instruction sheet supplied with the kit. There is no assembly of the kit required, and it's down to a little soldering to the ZX81.

To start, it's simply a matter of attaching the input wires to the back of the ZX81 circuit board: red wire +5V to ULA pin 40, the black wire 0V to ULA pin 34 and the yellow wire to video In at ULA pin 16.

For the output wires you have a choice to make, either integrating a small video jack (3.5mm) between the two cover parts (as suggested in the instructions sheet), or re-purpose the modulator casing. The second option is what I decided to go with.

In order to fit the ZX8-CCB into the modulator case, the case needs to be removed from the ZX81 circuit board. There are 2 or 3 wires going into the side of modulator, these can be trimmed of at the base, or de-soldered. Also there are two large pins directly underneath the modulator, these hold the modulator unit in place. These also need to be de-soldered to remove the modulator from the ZX81s circuit board.

Once the modulator casing is free from the ZX81 you can then set about removing the existing contents (though a combination of cutting and de-soldering). What's inside the box will vary depending on the modulator, on PAL models there is a cross bar and the main circuit board to remove, as I have a USA model there was no crossbar.

ZX81-CCB Input Wires Soldered at the Back to the ZX81 Circuit Board

After the modulator has been gutted it can then be re-attached to the main circuit board, with the ZX8-CCB placed inside the casing affixed with a square of double sided tape. The remaining wires are then attached: brown wire for video out to the center of the phono socket, and the the black wire 0V to to the side of the modulator casing.

ZX81-CCB housed insdie the Modulator Case. (Wires latter moved to run through vaccant holes in the casing)

In the initial fitting I had the three wires which are soldered to the ZX81s circuit board running over the side of the modulator casing. With the modulator lid placed back over the top, this was perfectly serviceable but looked a little untidy. I latter decided to move these wires and have them running through the now vacant holes (of which there are three) on the side of the modulator.

Composite Results

So what of the results? In a word 'amazing'. It is unfortunate that I don't have a CRT TV laying around to give the proper picture, though even upscaled through a composite to VGA converter box the clarity is almost as clear as on many an emulators, it's certainly the best video I've even seen emanating from a ZX81.

After Composite Video Mod (with a little HRG graphic teaser)

Of course I'm not the only one to have retrofitted a ZX8-CCB to a ZX81, these things sell like hotcakes. And as is the way with these thing, half way through typing up this post I found another blog post detailing a similar install of a ZX8-CCB. I'd suggest checking out Kevin Phillip's entry 'Rejuvenating My Geriatric Childhood Friend' for extra information. The better you're informed before making any medications there better.

Next Time

There are a couple more modifications I'm wanting to make, along with a couple of interface addons to try out. (Hint one of the is in the final picture). I'll get around to detailing those and more soon.

Monday, 9 January 2017

Lode Runner on the ZX81 - Part 1 (The Intent)

There are games and then there are the games we wished existed on the ZX81. For me, Lode Runner falls firmly into the second category.

Lode Runner was and still is ubiquitous, making an appearance on just about every 8 bit system to crawl out the 80s micro computer swamp. From its inception on the Apple ][, ports have made their way to the BBC, the NES, the SEGA SC3000, the Atari XL/XE, the ZX Spectrum and hell it even even made it onto the Vic 20. But yet the poor old ZX81 missed out, this is of course due to the rather obvious lack of a suitable graphical display capacity.

But I say enough excuse, It's time to write a great historical wrong and bring once and for all a (probably rather cut down) version of Lode Runner to the ZX81.

So there it is, a statement of intent, (mainly to ensure that I stick with what I'm setting out to achieve) that over the ensuing months I'll slowly document the process of either failing miserably or succeeding gloriously in the (re-)creation of passable version of Lode Runner on the ZX81.

Thursday, 8 December 2016

ZX81 Draughts Challenge - Part 3 - Tims Checkers

As this whole little (and I say little in heavy quotes) escapade has been inspired by two very informative ZX-Computing articles penned by the late great Tim Hartnell, the game he inspired now bears the official title of "Tims' Checkers".

And as such this is now the official announcement and launch of the hightly anticipated, completely compelling retro-tastic ZX81 game "Tims' Checkers".

After the last blog entry I had hopped to have a couple of varieties of checkers available in the one game, unfortunately this was not to be. No doubt some of this is down to some slightly shoddy C programming, however there is one very valuable lesson to be learnt when using the WRX hires graphics mode in z88dk, namely that you loose at least 4k of valuable game writing space to the hires graphics screen itself. So what this largely means is that in order to keep the game within 16k limits, some things just had to be dropped.

Would You Like to Play a Game?
So yes due to space constraints I've had to drop the multiple game play options, there is no option to play Spanish checkers or Corners as originally envisaged, instead what we do have is a full-ish checkers implementation.

The computer player has been enhanced from the basic opponent provided in Tims' ZX-Computing articles. Although again due to the self imposed space issues the ZX81 is not the most brilliant of strategists, yet competent enough to play an enjoyable and somewhat surprising game.

Basic Rules:

  • Men may move and capture only diagonally forwards.
  • Kings may move and capture diagonally forwards or backwards, but can not jump over empty squares.
  • If a player is in a position to make a capture then a capture move must be taken. If there are multiple capture options the player is free to choose. Once a man or king has captured that piece must continue to capture until there are no more capture options available.
  • If a man lands on the final row, the row furthest from a players starting position, the man is kinged.

A Bit Further in. The ZX81 has KInged.

Playing The Computer:

  • Select if you or the ZX81 goes first.
  • Use standard algebraic notation to enter moves.
  • There is no backspace, so if you start to enter the wrong move just make the rest of the entry an impossible move.

Really there is not much to it, after all checkers is a simple game and perfect for the ZX81. I'm considering this to a beta release, if you the prospective player find any glaring errors then please feel free to report them.

Download Tims' Checkers and give it a go in your favorite ZX81 emulator. Remember that you'll need to enable WRX graphics in your emulator to play correctly.