I spent last night decoding some graphics chip code on computerarchaeolgy.com, and I managed to draw an Asteroid in the classic style. Today, a look at what I found out.

This delightful page on Computer Archaeology shows the code for the various objects in Asteroids, in the language of the Digital Vector Generator used back in 1979. Rock 1, in that language, looks like this:

``````; Rock Pattern 1
09E6: 08 F9          SVEC scale=03(/64)  bri=0     x=0       y=1       (0.0000, 0.0156)
09E8: 79 F9          SVEC scale=03(/64)  bri=7     x=1       y=1       (0.0156, 0.0156)
09EA: 79 FD          SVEC scale=03(/64)  bri=7     x=1       y=-1      (0.0156, -0.0469)
09EC: 7D F6          SVEC scale=02(/128) bri=7     x=-1      y=-2      (-0.0078, -0.0234)
09EE: 79 F6          SVEC scale=02(/128) bri=7     x=1       y=-2      (0.0078, -0.0234)
09F0: 8F F6          SVEC scale=02(/128) bri=8     x=-3      y=-2      (-0.0234, -0.0234)
09F2: 8F F0          SVEC scale=02(/128) bri=8     x=-3      y=0       (-0.0234, 0.0000)
09F4: 7D F9          SVEC scale=03(/64)  bri=7     x=-1      y=1       (-0.0156, 0.0156)
09F6: 78 FA          SVEC scale=03(/64)  bri=7     x=0       y=2       (0.0000, 0.0313)
09F8: 79 F9          SVEC scale=03(/64)  bri=7     x=1       y=1       (0.0156, 0.0156)
09FA: 79 FD          SVEC scale=03(/64)  bri=7     x=1       y=-1      (0.0156, -0.0469)
09FC: 00 D0          RTS
``````

Computer Archeology also has a page on the details of how the Digital Vector Generator works. It’s nearly accurate, but I’m sure it’s a bit incomplete, and I suspect some of the values it shows. But we’ve gotten past those difficulties.

That’s at least partly decompiled from the two hex digits that actually define each operation, and despite a comment about fixing the values for negative y, up at the top of the page, I think the comments in parens are wrong about the coordinates.

With a lot of effort and a certain amount of unnecessary frowning at my dear wife, I managed to make Codea draw one of the asteroids, after first managing to draw it on graph paper: Here’s my hacked-together code to do the drawing:

``````function drawNewAsteroid()
local m = 2
local a = {--vec2(0,1),
vec2(1,1),
vec2(1,-1),
vec2(-1,-2)/m,
vec2(1,-2)/m,
vec2(-3,-2)/m,
vec2(-3,0)/m,
vec2(-1,1),
vec2(0, 2),
vec2(1,1),
vec2(1,-1)}
pushStyle()
pushMatrix()
stroke(255)
local from = vec2(0,1)
translate(WIDTH/2, HEIGHT/2 +100)
fill(255)
ellipse(0,0,5)
local s = 25
scale(s)
strokeWidth(1.0/s)
for i,v in ipairs(a) do
local n = 1
local t = from+v
line(n*from.x, n*from.y, n*t.x,n*t.y)
from = vec2(t.x,t.y)
end
Once = false
popMatrix()
popStyle()
end``````

And here’s the screen with the new asteroid: Summing up what I learned …

Basically I produced that table by pulling values from the SVEC lines for Rock Number 1. I worked out that the scale factor 02 in fact means that those points need to be divided by two to align with the ones of scale factor 3. That is consistent with the Computer Archeology description, to some degree. However, since the values you can express in an SVEC are only 0, 1, 2 or 3, and since the Asteroids screen was 0-1023 (in the long dimension), dividing those values by 512 or 256 or whatever, leads to dots too small to see. So I conclude that SVEC scaling probably isn’t what the article thinks it is. And, I think the math is wrong anyway, in computing those values in the parenthesized comments. I’ll research that further and if I can find anything out for sure, I’ll let Computer Archaeology know.

I wound up using the x and y values from the writeup, and scaling them, and as you can see in the picture, it works. The code is a bit nasty but it, too, works.

Part of what makes it nasty was scaling it to be seen, and part is due to the fact that we’re emulating a vector scope, so that each move starts out from the end position of the previous move. Thus the addition

``````local t = from+v
``````

I’m not proud of that code. I finally got this figured out at 1 AM last night. It works, that’s the miracle. We’ll clean it up and do something sensible at a more sensible hour.

My current conclusion is that I’ll work from the X and Y values in the SVECs, and scale according to the scale shown. I need some data structure that I can use in Codea. So I read in the SVEC info and regexed it into this:

``````-- Rock Pattern 1
local R1 = {
{s=3, x=0, y=1},
{s=3, x=1, y=1},
{s=3, x=1, y=-1},
{s=2, x=-1, y=-2},
{s=2, x=1, y=-2},
{s=2, x=-3, y=-2},
{s=2, x=-3, y=0},
{s=3, x=-1, y=1},
{s=3, x=0, y=2},
{s=3, x=1, y=1},
{s=3, x=1, y=-1}
}
--
-- Rock Pattern 2
local R2 = {
{s=2, x=2, y=1},
{s=2, x=2, y=1},
{s=3, x=-1, y=1},
{s=2, x=-2, y=-1},
{s=2, x=-2, y=1},
{s=3, x=-1, y=-1},
{s=2, x=1, y=-2},
{s=2, x=-1, y=-2},
{s=3, x=1, y=-1},
{s=2, x=1, y=1},
{s=2, x=3, y=-1},
{s=2, x=2, y=3},
{s=3, x=-1, y=1}
}
--
-- Rock Pattern 3
local R3 = {
{s=3, x=-1, y=0},
{s=2, x=-2, y=-1},
{s=2, x=2, y=-3},
{s=2, x=2, y=3},
{s=2, x=0, y=-3},
{s=3, x=1, y=0},
{s=2, x=2, y=3},
{s=3, x=0, y=1},
{s=2, x=-2, y=3},
{s=2, x=-3, y=0},
{s=2, x=-3, y=-3},
{s=2, x=2, y=-1}
}
--
-- Rock Pattern 4
local R4 = {
{s=2, x=1, y=0},
{s=2, x=3, y=1},
{s=2, x=0, y=1},
{s=2, x=-3, y=2},
{s=2, x=-3, y=0},
{s=2, x=1, y=-2},
{s=2, x=-3, y=0},
{s=2, x=0, y=-3},
{s=2, x=2, y=-3},
{s=2, x=3, y=1},
{s=2, x=1, y=-1},
{s=3, x=1, y=1},
{s=2, x=-3, y=2}
}
``````

This may not be its final form, but I’m sure that from there I can draw all the asteroids. The hard part will be moving that table from my Mac into Codea. I’ll probably have to email it to myself.

## Legacy Code

In a way, this was a typical legacy exercise. I had to search high and low to find any documentation at all. When I found it, either it’s wrong or I can’t understand it. But with enough fiddling and experimentation, I think I have what I needed.

And, along the way, I discovered that the Ship isn’t a simple triangle. We’ll fix that one of these days as well.

Now can I have breakfast? Thanks!

## Post-Script

A bit deeper search today turned up a couple of additional references:

Hitch-Hacker’s Guide to the Atari Digital Vector Generator, a more comprehensive look at the device than the Computer Archaeology notes, and, I think, a bit more accurate.

Atari Digital Vector Generator Simulator is a running simulator for the card, which is more than I need but certainly both fun and good background information.

It’s amazing what the Internet contains. Here’s useful technical information from 40 years ago, delivered to my home with just a bit of searching effort. And I’m happy to know that I can draw the asteroids with the same shapes as they were four decades ago. On a tablet I can hold in one hand.

Life is good!

## News Flash

News flash! I stumbled on Nick Mikstas’ site earlier today, and also got a friendly link to it from Ted Young this afternoon. Check out Nick’s site and hire him if you can. Among his projects are rather complete code for the original Asteroids, and many other interesting things.