Close

CP/M on VGL: Issues and Solutions (Updated!)

A project log for V-Tech Genius Leader / PreComputer Hacking

Turning a toy into a hardware tinkering platform

bernhard-hotkey-slawikBernhard "HotKey" Slawik 11/04/2019 at 10:461 Comment

Most of the inner workings of the V-Tech Genius Leader / PreComputer have been discovered. Even some lesser known functionality, which is hidden inside a proprietary silicon, is understood. Especially, how the LCD, the keyboard matrix, printer port and most of bank switching works.

Now for the philosophical question: What should we do with it?

When talking to people, most of them agree that getting an own operating system to work is priority 1. But on which OS to focus on is not fully clear. Personally, I would prefer CP/M, since it is the Z80 operating system with the most impact and support.

There are two problems with CP/M on this "toy hardware":

  1. CP/M requires a disk drive. The V-Tech computers don't have one. But since we do have a cartridge port and proof-of-concept memory-mapped I/O, as well as a working serial port, getting some sort of SD card reader or serial storage medium to work should not be a big problem. In the meantime we can use bank-switched ROM/PROMS/SRAM or load software from the serial port (already working!)
  2. CP/M requires RAM to start at memory address 0x0000, since this is how CP/M programs interface with the BIOS/BDOS drivers. See: http://www.primrosebank.net/computers/cpm/cpm_structure.htm

The latter problem is a bit more tricky. See, on power-up the Z80 CPU jumps to address 0x0000 and starts executing the instructions located there. That's why there is a big system ROM located at that address.

Bank switching the system ROM

After thinking long and hard, I decided to leave the "non-invasive" route and add a little hardware modification to my beloved Genius Leader 4000 Quadro. I opened it up and put wires to the "Chip Select" lines of the ROM, the RAM and the cartridge port. Fortunately, these 3 lines are conveniently located on one corner of the PCB (near the cartridge port) and each go through a wire bridge. It is really simple to cut these bridges and add some wires, so they can be connected/disconnected at will:

V-Tech hardware mod
"Chip Select break out" connector (upper right) allows disconnecting the internal ROM at will. A simple "Bus Doubler" (bottom) allows inserting two cartridges at once. You'll see why.

On its own, this is not a very helpful mod :)

But now you can insert a ROM cartridge and use a different "Chip Select" pin (the new "internal ROM ~CS" instead of the default "cartridge ~CS" on Pin 35). A slight modification in your code (segment now needs to be 0x0000 instead of 0x8000) and your external ROM cartridge can now act as the internal system ROM! That means: Now we have a full 32kB of additional address space without de-soldering the internal ROM!

But be aware that the internal system ROM also contains crucial hardware initialization functions which now need to be done in our own ROM. This includes the LCD initialization sequence, resetting all the MUXes and bank switchers and -most importantly- reacting to interrupts and polling the keyboard matrix.

My current implementation works fine in the MAME gl4000 emulator, but still has some issues with the LCD (one line is not showing - using a non-standard DDRAM mapping) and the keyboard is not working reliably. This still needs some more research to get right. But enough to continue with some more experiments...

Booting from RAM

But now for the really tricky part: As I said, CP/M needs RAM to be at 0x0000. But since RAM is -usually- volatile, we can not simply solder in a SRAM IC and call it a day. It won't boot, since it is empty.

My current idea is to use the battery backed SRAM cartridge VTech Super Speicher 32KB for that. It contains a 32 kilobyte SRAM IC, as well as a coin cell battery and a few transistors (to invert signals and switch from internal to external power).

It should be possible to boot from a custom system ROM (mapped to 0x0000) while having the SRAM connected to the cartridge slot (mapped to 0x8000). Then, prepare/bootstrap the RAM contents to contain the initial jump instructions. When this is done, ROM and SRAM would "swap places" (remember, the "Super Speicher" is battery backed and won't lose its contents) and the system should now be forced to "boot from RAM".

At least that's the theory.

Bus Doubler
Bus Doubler in action: ROM at 0x0000, RAM at 0x8000

I tried it yesterday in the late, late evening. And while the initial bootstrapping of the SRAM worked, the system did not boot from SRAM once I swapped it in as "system ROM".  The screen just went weird (reset loop?) It seems like there is still some interrupt or timing issue... But I won't give up just yet!

Also, creating the ROM image is not trivial, since it needs to contain code segments that are compiled for the 0x0000 segment, as well as code that is run, once it is mapped to the cartridge port at 0x8000. The current build tool chain now contains some calls to "dd" to extract and merge parts of different binary images. Stuff you shouldn't be doing on a Sunday night at 2am...

Do you have any better ideas to get CP/M running? (e.g. re-locating programs to use 0x8000 instead of 0x0000?) Let me know!

Update: It flippin' works!

The memory model is there!
Booting from RAM: YES IT CAN!

I can't believe it: I just fiddled around with the initialization sequence a bit more and... HEUREKA! IT BOOTS FROM SRAM!

Of course, this is not a real CP/M system, yet. But I had to give it a name anyway, so I just went straight for it. "Aim high!", they say ;-)

So: This solves the main issue of getting CP/M up and running: Booting from address 0x0000. I am pretty sure, we will find an even more elegant solution of disabling the internal system ROM (using the "A17" and "A18" lines? Or using the software controlled CAPSLOCK LED for it?). But soldering 2 wires to well-accessible parts of the PCB is already quite easy to pull off.

And suddenly, there is the biggest question yet:

When will it play the original ZORK?

Soon, I hope! Will we master it in 2019? For the holidays? Let's find out together!

Discussions

Evan Allen wrote 11/04/2019 at 20:41 point

I'm working along a parallel path. I just embedded a NiMH charger and did some changes to the power circuitry so that I can run from wall power or batteries, and recharge them if they're rechargable (just like a real laptop)! I also kept the ability to swap batteries to regular AAs if that's all that's around.  After reading this post my experience with S100 bus systems earlier this year may come in handy.  I think what would help is to permanently remap the ram to address 0x0000 and install this circuit: http://www.glitchwrks.com/2013/04/17/power-on-jump  I don't know how hard it would be to make in an external cartridge, but a couple minor internal wiring modifications (address mapping) and then having it able to run CP/M from a cartridge would be cool.  I'm also going to try to dump my precomputer power pad rom, see if it's in MAME, add it if not.  It looks like the same pinout as a 27c2001, hopefully it's easy to dump as I already socketed it. 

  Are you sure? yes | no