Sunday, 16 February 2020

How banked ROM cartridges work

Following on from last week's blog post on the new Marina 64 banked ROM cartridge for the Commodore 64, I thought I would answer a few of the questions that post raised by going into a bit more detail.
The Commodore 64 has a processor with a 64K address space, and has 64K of RAM installed, so any ROMs need to be switched in and out of blocks of addresses within that space. There are various combinations available which swap in the system ROMs and the two 8K regions on the cartridge slot.
This is all controlled by the PLA chip, which is why you get big problems when they fail. (see a previous blog post on Commodore 64 cartridges for more information on the different modes)
As designed, a Commodore 64 cartridge would contain one or two 8K ROM chips, in various combinations, so you could have up to 16K of ROM code for your game or utility. There are two chip select lines ROM_L and ROM_H which are used to activate the ROM chips as required.
What happens if you want more? Well, in the case of the Magic Desk 1 cartridge, they needed 32K, so the code would need to be on four 8K ROM chips, but the cartridge could only be 8K or 16K? I don't know exactly what happened, but my theory is they decided they could use a single 8K ROM cartridge with one of the ROM chips in, and the other three ROM chips in a little tray by the side. Each cartridge would be supplied with a robot arm and whenever they wanted something on one of the other ROM chips, the robot arm would unplug the current ROM chip and plug in one of the others.
Due to practical issues of size and cost and sanity, they had to do that electronically. What they did was build the cartridge as if it was a single 8K ROM cartridge, so on boot a single 8K ROM is selected and works as if it were a normal cartridge. There are some IO ranges on the cartridge port, and they used one of these to add a register which latched in the address of the ROM that was required, and next time the 8K ROM range was accessed, the appropriate ROM chip would respond. No robot arms were required. The robot arms unions were furious.
The 74LS139 is a dual 2 to 4 line decoder, in each half, one of four outputs goes low based on a two bit address on the input. Here, the left hand half of the 74LS139 is used to generate the clock pulse for the data latch. This is triggered on the high going edge, so the output goes low when the clock is high, I/O 1 region is low and write is low, so the first part of the write cycle. Whilst the clock is high, the databus is being prepared with the data to be written, and when the clock goes low, it should be ready, so is latched into the 74LS175. (note on the only schematic I have found, this is incorrectly shown as connected to pin 12 of the 139, but I believe this to be a mistake as it would latch too early in the cycle, so have shown the connection to pin 11 in my redrawn schematics)
The 74LS175 is a 4 bit latch, and latches D0 and D1. This is a two bit address of the ROM. It has a reset line connected, so is reset to 00 when the C64 is reset. The right hand half of the 74LS139 is used to decode this two bit address into four select lines, one for each ROM chip, only active when the /ROM_L line from the cartridge port is low, so working like a single EPROM.
At the time, 8K ROM chips were the best option, but as time progressed, larger chips were more easily available, and the design could be reworked to use a single ROM chip. This is a theoretical intermediate state for a 32K ROM cartridge, there were various implementations, with different decoding logic (often a 74LS02 quad NOR gate) and sometimes different latch chips. But I have kept with the 139 and 175 as on the original for clarity.
Here the right hand half of the 139 is not used, and instead the two bit address forms the upper address lines of a 32K ROM chip. This gives the same result as the four ROM chips in the previous design, but at a cost and complexity saving.
Of course, the next logical step is to connect up an extra data line to the latch, and use a 64K ROM chip, and as if by magic, you have a 64K ROM bank cartridge, selectable by writing a 3 bit address to the IO port.
But why stop there? change that latch to a 74LS273 8 bit latch and the EPROM to a 27C080 1MB ROM and you have a 1MB banked ROM cartridge selectable by a 7 bit address written to the IO port.
Why not 8 bit? Well, at some point someone decided to use the eighth bit as an enable. This is used to drive the /EXROM line on the cartridge port which enables the 8K space we have been using. This is useful for a program which loads from ROM into RAM and can then disable the ROM elements and run entirely from RAM. This is often used with a compression step to fit even more into the ROM chip. The decoding can also be changed to stop further writes to the latches, but I have not shown that for clarity.
At this stage, when you are implementing a practical cartridge, there are other things to consider, which add complexity to the simple schematic above. Mainly it is adding jumpers to allow different ROM chips. Borrowing the table from the previous blog post, on the Marina 64 cartridge we removed a few of the less common chips to give a 32K -1MB range with only a single jumper to select 28 pin or 32 pin ROM chips.
So there you have it, that sort of bank switching is common on larger ROM cartridge (such as those produced in the 1980s by Ocean), and on modern multicarts (such as the VIC20 Penultimate Cartridge).
The Marina 64 32K-1MB banked ROM cartridge is available from TFW8b.com. There will be a production surface mount version available as soon as the world PCB production facilities return to normal.

If you want to support this blog, you can donate via Patreon or Paypal, or buy something from my store.

Sunday, 9 February 2020

Marina64 1MB Banked ROM Cartridge for C64

This is the Marina 64, a new 1MB banked ROM cartridge for the Commodore 64 (and Commodore 128 and SX-64).
This is based on the Magic Desk cartridge. This was a Commodore product back in the 1980s which was an early attempt at a desktop operating system. With a literal desktop (possibly the origin of that?).
There was a file manager, calculator, and a very strange word processor that was like a virtual typewrite simulator where as you typed, the page of text moved to the left, creating a document 80 characters wide on a 40 column screen.
This didn't catch on, and was superseded by GEOS and things like that. However, it lives on in the hardware that was used. I haven't been able to find any pictures of the original Magic Desk 1 cartridge, but it consisted of four 8K ROMs, and two TTL chips. These formed a simple bank switching mechanism to allow the four ROMs to be accessed through a single 8K window. On boot, the first ROM would be selected, and the C64 would boot as if it were a normal 8K cartridge. When the program needed to access one of the other blocks of code, it would write to an IO address which would select a different ROM from the four available.
At some time in the past, a thought must have occurred to someone that it would be a good starting point for their own cartridge. The C64 was limited to 16K ROM in a cartridge, so this was a way to get a 32K game in cartridge form. Another thought would have occurred that this could be achieved with similar logic and a single ROM chip, selecting one block or bank of 8K from a single 32K ROM chip (not sure if Commodore ever did this or it was later clones). Further thoughts could have been along the lines that the bank is selected by writing a byte to the IO port, and only the first two bits were used to select the bank, so a larger ROM chip could be used by latching more bits of the byte written to the IO port to use to select the bank. (There will be a more detailed look at this in a later blog post). There are now many variations of the design of 'Magic Desk compatible' cartridges, and when looking for a cartridge for larger games for The Future Was 8 bit '999' range of cartridges, this seemed a well established and well supported way to go.
My first attempt was a 'developers edition' cartridge, really just an in house testing tool. This had the ROM socket, and two TTL chips. One of these is simple decoding logic, the other latches the number of the bank selected. Here I am using a 74HCT273, so it latches the whole byte written to the port. The original design used a 74LS174 which can only latch 6 bits. Most of the versions of the design I have seen online had lots of jumpers. TFW8b doesn't like jumpers (he asked me to add here he also hates cardigans), so I looked into which ones we actually needed.
This is the result of my analysis of the various options for common EPROM types. The first jumper I got rid of was the one on the /EXROM pin. This was there to disable the cartridge so it could be programmed in system. I didn't see this as a requirement of this implementation of Magic Desk, at 300 bytes per second out of an IEC drive, it would take just under an hour to program a 1MB ROM chip, so I would recommend just using a standard EPROM programmer where it takes a couple of minutes.
The remainder of the jumpers were selecting a bank address or 5V for the upper address lines on smaller chips. The 27C64 and 27C128 aren't really relevant here as they can use plain cartridge PCBs for 8K and 16K titles. By discounting those, and the writable chips version the 28C64, and the 28C256 with it's address lines in a different place, and the largest writable 39F series chips, you get down to a single jumper, one to select if the ROM is 28 pin or 32 pin.

EPROM
Jumper
Banks
Capacity
27C256
28 pin
4
32K
27C512
28 pin
8
64K
27C010
32 pin
16
128K
27C020
32 pin
32
256K
27C040
32 pin
64
512K
27C080
32 pin
128
1M

This is a common differentiator with TFW8b products. This will work for most people, most of the time. For the few who want to use different chips, or write in system etc. other products are available, but we try not to over complicate the main product for the average user. I was asked about the need to stack two 512K chips to get 1MB. I have seen a cartridge which requires this, but I don't see why that is necessary when you can use a single 27C080 1MB chip.
This is the prototype of the cartridge, dubbed the Marina 64 (for obvious reasons). These boards are available now as a bare PCB from TFW8b.com. A production version will be available soon, with surface mount ICs pre-assembled, and an activity LED, which shows when the cartridge is active.
Naturally, the cartridge PCB is designed to fit into the TFW8b.com C64 Stumpy Cartridge Cases. Available in a range of tasteful colours (and pink), and also available blank labels for your own titles.
One of the benefits of going down the Magic Desk route, is there are a number of programs around to generate compilation cartridges and self extracting programs to work with a Magic Desk cartridge, and these can be previewed and tested in the Vice C64 emulator.
A good example of this is the Magic Desk Cartridge Generator v3.0 by Žarko Živanov. This is a python script which can be used to compile a cartridge from normal PRG files. The script generates a menu program which allows you to select a program, which is then decompressed into RAM. The programs can span multiple banks, and with 1MB capacitor you can fit dozens of programs on a single cartridge.
Another option is if you have a single large prg file, you can use a program such as the C64 Cartridge Creator tool 1.0.0 by Solo761. There is no menu in this case, it just copies the prg file from the ROM cartridge into RAM and starts it running. None of these options are suitable for programs which require multiple files (for example disk games), only single prg files.
The PCB only versions are available now Marina64 PCBs from TFW8b.com. The production boards will be available next month. (image blurred for security reasons).
Update - see the following blog post for more details on How banked ROM cartridges work.

If you want to support this blog, you can donate via Patreon or Paypal, or buy something from my store.

Sunday, 19 January 2020

Minstrel building hints and tips

Whilst I offer the Minstrel 2 and Minstrel 3 as built and tested units, most are purchased as kits or bare PCBs. As such, you see all sorts of construction techniques and case solutions.
I've put together a gallery of photos of Minstrel builds I have been sent as a Twitter Moment. I have a feeling moments are being phased out all the integration seems to have been removed and the current version is considerably more difficult to operate than it used to be.
I'm going to start with a few hints and tips from all the boards that I have assembled. The Minstrel is a fairly conventional through hole design, that wouldn't look too out of place in the 1980s, other than maybe the tracks are a bit thin by 80s standards. I don't think I would have been able to route the board using standard thickness tracks without it being a lot larger.
Standard assembly techniques apply here, work in order of height above the board, start with the lowest parts like the resistors, capacitors and diodes. Here I prefer to solder the parts in from the top of the board. A bit unconventional, but it's a very fast technique as you don't need to keep flipping the board over, and I think it gives a nice finish as you get a decent solder fillet on the top side, rather than just the occasional blob if too much solder was used on the underside. I go through and resolder each leg from the other side of the board when I am doing the chips, that gives a nice even appearance on both sides.
The chips I also tend to tack solder the corner pin, usually the ground pin, the one which is least likely the flow through itself when the rest of the chip is soldered.
The main collection of chips on the board is a mixture of 14 and 16 pin devices. Texas Instruments use the same package for both of these, so the board is laid out to look neatest using these packages. If you look carefully, you will see the pin count of the row of chips on the right changes near the top, but all appear uniform. This is entirely irrelevant to functionality, but I think aesthetics are important too.
You can fit sockets if you like. Turned pin are recommended. However, if I'm building one for myself these days, I only fit a socket on the ROM chip. Once all the bits are soldered, I give the board a good clean with flux remover, and then with IPA to remove the flux remover residue.
With the move to HC logic on the Minstrel 3, it runs at less than 100mA, even with the Minstrel ZXpand attached, so it runs fine with a standard 7805 5V regulator without the need to fit a heatsink. You can leave it 'flapping about in the breeze', or can bolt it down, or I like to rivet them in place.
The Minstrel 2 with it's LS logic runs at more like 200-300mA, so if you want to use a 7805, you need to fit a heatsink, such as the one from a ZX81.
Alternatively, on either board, you can fit a Recom or similar 7805 switching replacement, which reduce current consumption from the supply even more and generates negligible heat.

Keyboard options

There are a few keyboard options, these days I prefer to use the tack switch keyboard with overlay PCBs. The original tact switch keyboard had a nicer feel, but there wasn't space to write all the keyboards and graphic symbols around the switches.
The membrane keyboards had all the keywords and symbols, but were not the greatest to type on. I produced a series of overlay stickers with the appropriate keywords and symbols on for 4K and 8K versions of BASIC, in ZX80 colours, that can be stuck over standard ZX81 replacement membranes.
If you are using a membrane on a baseplate, I normally fit the membrane connectors underneath the board, at 45 degrees, that way the membrane tails fits under the board.
If you are fitting the board in a ZX81 case, fit the membrane connectors on the front as with a ZX81, so the tails sit under the board when attached.
I have recently added overlay PCBs for the tactile switch keyboards. These bring the best of both worlds, as only the switch cap pokes through, there was enough space to fit the normal character, shifted character, keyword and extended keyword on each key.
The tact switch keyboard PCB is connected via a pin header and socket, for neatness, I normally fit these underneath the PCB.
If you are fitting in a ZX81 case, there is space to fit the jumpers on the top side, but I have been fitting right angle versions on the back, so they can be changed without unscrewing the case.
The ROM select can also be done like this, for a single address line anyway.
Another tip for fitting in a ZX81 case is the capacitor above the ROM chip can sometimes get in the way of the pillar, so I fit this with one leg soldered to pin 28 of the ROM socket instead, to give more clearance around the hole. You can see here I also fit the reset switch on the reverse for ZX81 case installs.

ZXpand

The construction of the Minstrel ZXpand is a simpler version of the main board, the same technique, just fewer parts.
The only potentially tricky item is the SD card socket which is surface mount, but I supply those presoldered to the PCB, so there is only through hole soldering remaining.
I recommend using the 0.1" double side pin header to solder the boards together. This gives a solid result, no chance of 'RAM pack wobble'. Start by soldering the shorter end to the Minstrel ZXpand board.
Then the longer end can be soldered to the Minstrel 3 board (or I have seen people fit a suitable socket). It does limit what you can plug in, but what else where you going to plug in?
The extra link for ROM selection can be mounted under the board, out of the way, once the connectors are soldered.
If you want to go down the edge connector route, you first need to cut down the edge connector. Two row, 23 way edge connectors have been out of production for many years, so the best option is two row, 28 way connectors that have to be cut down. These have sealed edges, so I usually leave the right hand end intact to locate the connector on the side of the PCB.
I remove two pairs of pins, one for the gap and one where it needs to be cut. Tidy up the cut end on the left with sandpaper, and then it slides nicely onto the end of the board, with the right hand end hard up against the right hand side of the board.
If you can find one, you can fit a polarising pin, or make something from a bit of PCB or card. I've removed the jumper wire so you can see better how it aligns at the edge.

ROMs

The ZXpand ROM contains various different images, to support the different versions of hardware and BASIC in use. If you are using the 4K ZX80 ROM image, either double it up to fill 8K, or place it in the first half of the 8K block. When testing you can set the A15 jumper to low and get the standard versions of BASIC.

A15 (ZXpand Select)
A14
A13
Contents
0
0
0
ZX80 4K Integer BASIC
0
0
1
ZX80 4K Integer BASIC with ZXpand
0
1
0
ZX80 8K Floating Point BASIC
0
1
1
ZX81 8K Floating Point BASIC
1
0
0
-
1
0
1
-
1
1
0
ZXpand overlay for ZX80 8K BASIC
1
1
1
ZXpand overlay for ZX81

When the ZXpand is connected, the A15 jumper is replaced with the wire link to the ZXpand board, that pin is normally low, but is pulled high when the extra ZXpand code is required.
If you ever see something like this, and the keyboard is responding and the cursor is moving, just not displaying the correct characters, have a look at the ROM settings, it is pointing at code rather than the character font.

Cases

The Minstrel board was designed to fit into a ZX81 case, however I have had quite a few people who had planned to do that come back and go for a different case option. Once built they have all said it seemed a shame to hide it away, so they wanted to go for one of the baseplates to show it off.
The boards are the same shape as a ZX81, so it will fit into a ZX81 case. If you've taken a few of those apart, you may appreciate the white rings around the two screws you need to fit to retain the board. The other three are screwed in from the back of the case.
With the Minstrel 2, it was a good use for a beaten up ZX81 case to sand it down and spray it white.
With the Minstrel 3, it should probably stay black.
I have also been sent a very nice 3D printed case for the Minstrel, which fits the Minstrel and the tact switch keyboard.
All very neatly done with the all the connectors lines up spot on.
I understand the designer is working on a version which includes the Minstrel ZXpand. If you want to make your own case, the dimension drawings are available.
I will have to stop there as this post is already getting quite long. I was going to go into some hints and tips about using the Minstrel 3, but I will leave that until next time. If you are playing along at home, make sure to have your Minstrel 3 up and running ready for the next lesson.

If you want to support this blog, you can donate via Patreon or Paypal, or buy something from my store.