Getting the most out of 16KB ROM!

Lately I’ve been doing a lot of work on the rosco_m68k hardware, specifically on integrating the new Yamaha V9958 video board. As part of this, I wanted to extend the firmware to support basic “virtual consoles”, so that if a V9958 is detected it will use that for text output, or fall back to the UART if there isn’t a video card.

I’ve written up a longish post on Hackaday with the implementation details of the console itself (it’s worth a read if you’re interested in implementing a scrolling 80×24 text mode console on a thirty-year-old graphics chip), so I won’t go into too much detail here about how it works – I’ll just prove it does work with a picture:

V9958 text mode console in firmware, running Jeff Tranter’s Adventure game

One of the problems I faced while putting this together was that the ROMs I used for the rosco_m68k are only 16KB in size, and while the community has already come up with a workaround for this (thanks to RTS4E75!), I wanted the standard firmware to work on unmodified boards, so it had to fit in 16KB.

I also didn’t want to sacrifice any of the existing features supported by the firmware (because backward-compatibility matters, even in retro single-board computers!), so I was left with a bit of a dilemma – how to fit the video driver and associated text-mode font into the few bytes that I had left after the Kermit loader, Easy68k compatibility layer and basic machine initialisation code?

After playing around with a few different ideas, I eventually decided I would split the ROM in two stages – Stage 1 would contain the bootstrap code, and everything that needed to stay resident in ROM. Stage 2 would contain the program loader (so Kermit currently, though that can now easily be swapped out for something else such as the experimental SD card support we’ve been working on).

How does this split save space? Simple – Stage 2 would be compressed, and Stage 1 would be in charge of decompressing it from ROM into RAM and running it from there!

I’m not going to lie, I’m pretty pleased with this. I seriously doubt I’m the first to do it, but being able to take an almost-full ROM and fit in an entire graphics driver and text font, plus a simple Zip-like decompression algorithm (I didn’t write this, I used the excellent liblzg code – a LZ compress/decompress with a decompression written in M68k assembly) is, I think, something of a win. Making it all work together properly (especially tying up the parts in stage 2 that needed to call back to bits in stage 1) took a bit of work, but once I’d ironed out all the bugs and made sure I wasn’t doing anything silly (like overwriting the loader code with the bytes it was loading…) it all works really well.

As always, the code is on Github.


Published by roscopeco

IT guy, code junkie, mobile app developer, occasional blender artist and open-source activist.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Blog about the TTL based CPU design we're making

Don Charisma

because anything is possible with Charisma

Tech Filled Fantasy

One stop shop for all your tech-filled pleasures!

%d bloggers like this: