Kicking Bishop Brennan
The other day, John Linville sent out a challenge. Basically, "get something done before CoCoFEST!" (an annual US-based event for Colour Computer users, apparently spelt with the exclamation mark). Admirable! Blogging makes an implied commitment, and I don't know about you, but deadlines are usually what get my brain out of "thinking it through" and into "actually doing".
Ok, what I mean is, it's incredibly unlikely I'd attend CoCoFEST! (see footnote 1) as it's in the US. But we do have our own two-day event coming up in July, here in Little England: the now-annual Dragon meet-up in Cambridge (I'll link to this once Tony posts the announcement to something other than Facebook). I've used this for motivation before, why not again? And... I have an idea. Not necessarily a good one, but let's see where it leads.
Most of the things I try out are due to wanting to explore some specific thing in software, or some interesting aspect of the hardware (with notable exceptions based on nostalgia). This time it's hardware-oriented, so unfortunately I'm going to blather on about that for a while to justify myself.
Draw it again, SAM
The video system in the Dragon supports multiple vertical resolutions, achieved by using dividers to draw the same line data a selectable number of times. Supported modes have line heights of 1, 2, 3 or 12 pixels. If you get the timing right, you should be able to vary the mode as the frame progresses.
Some years ago now, I tried to implement a simple vertical magnifying glass. It's a noddy effect where you take a high resolution image and "zoom" lines by temporarily switching to a lower resolution (taller line height). It can look kinda neat, and even appears in some early Amiga demos. The result would be to "push" the rest of the screen down, and that would be an interesting precursor to another use for this approach which I'll get to later.
Unfortunately, it didn't seem to work. Something was happening, but not what I expected.
Actually, skip that
As I've taken a certain amount of pride in researching the classical model of SAM-VDG interaction, and indeed implement the result in XRoar, the fact I'd hit something not covered by it was a trifle irksome, so I tried to find out what was going on.
I used a logic analyser to see which RAM address the SAM was fetching for video, and wrote a custom program that let me change mode at an arbitrary position within the frame. The main thing that became obvious was that when you change the SAM mode, it doesn't just set it up to do something differently the next time a divider is strobed. Something—sometimes—happens immediately. Usually, the SAM appears to have skipped a bunch of addresses.
Now, this sort of thing can be explained by how binary counters work. If the input to one part of the counter is moved around, you can see a high-low transition which cascades to the rest of the counter. I could find a bunch of interesting transitions, but despite a lot of banging my head against the numbers, I couldn't spot the pattern. Yet Motorola surely does not play dice with video addressing.
All those dividers could be organised in a number of different ways. So I noted what changed to what, when, and wrote a small Perl script to try and brute force the problem. It went through every permutation of dividers I could think of—with varying duty cycles—along with all the effects I could imagine the horizontal sync signal having, and simulated the VDG clocking in a new address. All it had to do was find some combination that would work for all the values I'd noted down. It was my last, best, hope for understanding.
It failed.
Enter stage left
But in last year's Dragon meetup, it turned out that Stewart Orchard (him again) has also been tackling this problem. A proof-of-concept vertically scrolling demo that worked in XRoar wasn't happening on real hardware, and so he started his own investigations (this is the other thing that being able to arbitrarily push the screen down allows you to do).
What Stewart brings to the table is being an actual electronics engineer with a very large brain (see footnote 2), and he realised that mode changes may well reconfigure a set of dividers, but in real life these things don't happen instantly. The internal design of the SAM, it would appear, means that in some cases a "glitch" occurs, and the input to one part of the counter may be briefly pulled low (or indeed connected elsewhere) before being connected "correctly".
This opened up a whole new set of solutions to the problem, and Stewart did all the legwork in putting together a detailed analysis of what's really going on. Some transitions seem to end up floating internally, and the result is uncertainty over one of two possible outcomes (the screen jumps around even though you're doing the same thing each frame), but for the most part, the model seems to be far more complete (and this behaviour is now mostly reflected in the development branch of XRoar).
So what is it?
So instead of "pushing" the screen down, it turns out you can quite easily "pull" the screen up by causing the SAM to skip addresses.
By being careful about blanking and redrawing (a relatively small number of) lines, you can use this to achieve a form of "hardware vertical scrolling". You've burnt a bit of CPU time getting in sync with the display and manipulating some registers at the top of the active area, but that's nothing compared to copying a whole screenful of data around. The main limitation is that you absolutely have to get everything in your program done in one frame, as you need to be ready to tweak modes again at the top of the next one.
So this is the effect I'd like to use in an original (ish) game of my own. A car game (because I have limited imagination (see footnote 3)) where the background scrolls past your vehicle with some speed, and where maybe you have to blast some enemies.
A game tenuously called... Speed Blaster! (spelt with the exclamation mark).
Maybe.
So that name's pretty much just the combination of {Road, Speed} {Blaster, Fighter} that wasn't already the title of a video game. And I might change it yet if I can't work the blasting of anything into the gameplay. Curious aside: it's amazing how few Dragon games appear to have invoked the word "speed" in their title. Hopefully I can live up to the promises this name offers.
Originally I was thinking of doing the bare minimum for a hi-res version of Ken Reighard's Nightmare Highway. I figured that with the jokes Ken makes about it ("if you got it for free, you paid too much!" (see footnote 4)), a sequel involving clever hardware trickery would be quite amusing. But in the end I think I want to aim for something a bit different.
So here's what I'd like my game to have:
- Variable-speed "hardware" scrolling
- Steerable car (actually pointing in different directions, though perhaps only through 90-180°)
- Things to blast, at speed
- A track and objectives that make better use of the landscape display (compare to a portrait-mode game like Road Fighter)
- Ramps for bonus points?
- Some sort of turbo boost?
- In my head this is happening in hi-res black & white (or green & green), but I'll have a think about colour
- Probably targetted at the Games Master Cartridge for "free" sound
Yeah, a bit vague. I'll try and develop those ideas a bit, but before I write again, I think I'll need a proof-of-concept of my own.