Sunday, August 3, 2014

wrapping up / how to use the demo (more pics to come)

I figure I better write some "post demo coding" ramblings, etc.

First off, greetz to admash for the pile of Sun 3/50 machines. All I had to
do was pick them up from his parents house, and they were mine. This
was back when I was still in university, like Fall 2006 or such I guess.
There were actually two of the original monitors, and both of them actually
worked back then. However, the day they had to be moved it rained, and
by the time I got the machines home, even though I "dried" the insides of
the monitors out, they both ended up burning out after less than a month
of use. Well, before they burnt up, I had discovered that Plan 9's 2c could
produce binaries for them, and had gotten some faces showing on the bwtwo
(faces are just like icons or such in Plan 9, and they have them for various
vendors etc. for when incoming mail arrives, so that's where the Sun logo
comes from, and too that "unknown guy" is when you get an email from
someone who doesn't have a face). However, once the monitors burnt up,
I could only use the Sun 3/50s with a serial terminal, which is okay, but
not worthwhile for a graphics programmer. Not fun like the bwtwo was fun
(not trying to rain on your parade to everyone who did serial terminal stuff
-- hey I use them as a tool too, as you can see with the TeleVideo).

Well, let's just say they've been sitting around in my storage since then.

Enter RC2014SC.

Now, even though I killed one of them (we'll call that one Damon, why not),
at the completion of retrochallenge I do have a Sun 3/50 on an LCD panel
(works on a CRT too, but the LCD picks up better with the camera, so that's
what I'm using it on) using the little anaglyph board I made. So originally I
was just going to get the original look -- black and white, and I actually had
that going before killing the board. To get just black and white you need
an external power supply (I used a 5V AT power supply, and as you'll see in
the pictures, an old PC CDROM drive just to have enough load on the supply
for it to turn on (no that CDROM is not attached to the Sun 3 at all), a couple
resistors in a voltage divider configuration to get the 5V down to approx.
0.7-0.8V and a NPN transistor to amplify the signal. That is enough to boost
the video signal to drive the three red, green, and blue channels in a VGA
using the single "video" signal from the bwtwo.

If you were following along, you'll note my mournful post that followed the
announcement of the time extension. Well, I started to make the anaglyph
board because I had been looking at the datasheets for various components
that I had laying around (because to me the challenge was to use only parts
on hand -- with the exception of the Torx drivers which I needed to buy anyway)
and had just taken oscilloscope pictures of the sync lines coming out of the
bwtwo, and realized that the dual d-flip flop can handle those frequencies.

So it occured to me that instead of amping up the signal once, I could opt
to amp it only sometimes on the different color channels, and from there
it wasn't long before I had constructed the anaglyph board concept. Since
I didn't have any digital logic gate IC's (and's, inverter's and the like), I
was thinking to have to implement that using a pile of transistors, and had
actually been counting the number of transistors I had to see if I could make
enough gates (two and gates, two inverters), and I happened across the mention
on some forum or other that you can use a comparator as a logic gate if
you set the biasing up right using resistors. Well, I had a quad comparator,
and so I was all set.

Then I did all the point-to-point soldering and such to get everything
connected. All was going well, and I was starting to see a seperate
(ghosty) image, but while trying to get the biasing right since I kept having
to unplug/solder/plug the board, and since the connecter I used into the
power supply looks the same as some of the other stuff... I plugged the
5V power into the wrong spot and .. yeah. stabbed to death a bwtwo.

I don't see any reason you couldn't do this same thing on another arch.
So maybe the classic mac crowd wants to try anaglyph on their gear
(*I'm not responsible for mistakes.. you know what can happen if you
plug things up wrong from my example*).

I know before I said "red on even" "blue on odd" or whichever way
I said it, but it doesn't really matter (obviously it matters a lot) because
whichever way the code is, you can just reset one of the flip flops, and
have the colours switch, so, it's not too specific. I'll probably have a
button there eventually, but atm I'm just tapping it with a jumper wire
if I want to swap the colours.

Key parts list:

1N5819IR-ND - DIODE SCHOTTKY 40V 1A DO-41
    used on the bwtwo's V+ line to isolate the anaglyph board from the bwtwo
CD4013BE - IC DUAL D-TYPE FLIP-FLOP 14-DIP
    used to store parity of the vertical frames and horizontal lines
    (it has both an inverted and a non-inverted output for each)
LM339 - QUAD COMPARATOR 14-DIP
    two of the comparators are used in an and-gate configuration where the
    input comes from the flip flop outputs and two of the comparators are
    used as inverters where the input is the output of the other two comparators
    and the output of these is used drive the NPN transistors for red and blue.
2x 14-DIP sockets
    so you don't expose the IC's to the temperature of the soldering iron
2x 2N3904RLRAG - TRANS NPN GP 200MA 40V TO92
    to amplify/switch the video signal onto the two colour lines


I also used 2x 0.1uF decoupling caps on each of the IC's. Since the LM339 is
open-collecter output, you need pull-up resisters to +5V on the outputs
to get a valid result. Also you have to bias the non-inverting input to
configure the behaviour. This is done using voltage dividers between
+5V and GND. The resister values aren't as important as their relationship
and the pattern they're wired in, so you can use whichever values you
have on hand, supposing you get the right pattern.

So yeah, that's an overview of the parts on the board. Now the demo.

Obviously like I mentioned before I already knew Plan 9 had a 68020
compiler, so that's what I put on my development box (the Dell machine
I mentioned before, I didn't put any pictures of it yet, 'cause it's not
really the focus of the project, but it is where I am compiling things, and
what serves the boot images, and runs rarpd, bootpd, and tftpd), except
as I found out, apparently 2c got dropped out of the distribution some
time between 2006 when I last used it and now. Sad, but I had an older
"Plan 9 Fourth Edition" disc, so not really a problem.

The source code grew over the course of this month. I didn't have anything
left over from when I used to run Plan 9 (hard disk died), so it's not like
I had any useful bits laying around to get started. The key idea to drawing
on the bwtwo is that you know where it is in memory, and that it is a
16-bit single-plane thing at resolution 1152x900 sitting at 0x100000.

To use the keyboard, I found a source file online with the rom vector offsets.
Here is that file, hosted at carnagie mellon, so you know what I used to
learn keyboard input:

https://www.cs.cmu.edu/~jh6p/classes/studio/gcc-2.5.8/include/mon/sunromvec.h

This code didn't work by default in the Plan 9 C compiler, so I stripped out
all the Sun4 stuff, and edited it until it was usable. So that's the easy way
out for keyboard.. I was thinking about hitting the zilog chip myself, but didn't
have time, but the datasheet for the zilog chips is available. Also, the same
model of chip is used for the keyboard/mouse as is used for the serial A/B
ports. Does that mean you could have had four serial terminals on these
systems if you were coding the hardware yourself?

For a random number generator, I used something by Bob Jenkins whose
site is:

http://burtleburtle.net/bob/rand/isaacafa.html

His stuff was easy to make use of with the Plan 9 compiler, and just worked
on the Sun 3.

Like I mentioned before, the compression tool I used was lzss by Haruhiko
Okumura, and can be found here:

https://oku.edu.mie-u.ac.jp/~okumura/compression/lzss.c

To get this to work wasn't a big deal, but it did require modifications since
I am running on the Sun 3 metal, and don't have the file I/O facilities his
code expects (fputc/fgetc). I am only using this to pack the font characters,
and the code of the demo is stored unpacked. So I could get smaller file
sizes with a bit more work to have compressed code and data, but. yeah.
My demo is under 32k, so I don't feel too bad, though I know that 32k
is considered "large" by some people. I wasn't really trying for a small
size, mostly just doing that rushed coding which means my source tree
looks as messy as the board picture looks (now I know why all the demo
sceners release the binary, and not the source... the source is a mess by
the time they get the binary the way they want it -- and the binary is a jewel)

My "demo" as it is isn't that exciting. It simply runs a different routine
based on which key you press. So, press 'y' and get a font sample
(what used to be the numbers, but I replaced those with the letters in my
rush to pack/produce the final result -- though it still asks if you want to
see numbers...). You don't have to say 'y'. Other keys you can press would
be 'w' or 'W' to wipe the screen left or right. 's' or 'S' to apply shift operators
to the frame buffer data from left to right or vice versa. 'f' or 'F' for "fast wipe"
which is a bit faster than the other one. 'r' to throw some random boxes
on screen with the red and blue randomly offset from one another. There
are bound to be bugs ('cause I know of some,...).

And, of course, 'Z' to run the demo scene proper.
And 'q' to quit back to the rom monitor when you're ready to leave the demo.

The edit/compile/test turnaround was really nice with this project,
and I would just leave a "mk netboot" in my acme tagline, and middle
click it to deploy the latest revision (the netboot target in my mkfile
simply copies the compiled demo to the tftpboot directory I have).
Since the demo lets you hit 'q' to quit, then you just do 'ble()' in the
rom to boot from the lance ethernet again. Fast. If the code hangs,
you can usually press L1-A to get back to the rom monitor, but this
doesn't always work. In that case, you have to power cycle the Sun 3.
To run this, you don't need Plan 9 at all. Just some system with
rarpd, bootpd, and tftpd, that hands this file as a boot image to your
Sun 3's IP address. But I personally did not test with any boot server
other than a Plan 9 one.

As far as artwork, beyond doing the number font (which is not included
in the demo release proper, but was used in the intro video) and the
letter font (that's my handwriting, so you guys better not try and forge
cheques from purrfect) the most interesting thing I learned during this
compo was about screentones.

The screentones really make the look of this, and that's something that
I learned about after studying manga technique for backgrounds, because
they had to use a printing process which outputs either black or nothing,
and so the concept of screentones -- patterns which "look like" something
more interesting than black and white, even though it is being represented
in black and white. So the sky is a runtime-generated screentone that
I came to after (too much) experimentation, and the city skyline is based
on the code I was testing out in the 'r' section, but modified to only drop
buildings on the horizon. These are using a loop index as a screentone,
so they aren't solid either, and the detail is quite nice if you look closely.
The difference between what you can get with black and white vs. what
you can get with red, blue, pink, and black is astonishing, and going
into the compo, if you had shown me this final image, I would have
doubted it came from the bwtwo. But it does. This is all real hardware.

An interesting thing to do (which I didn't do due to time) would be to
hack tme (the machine emulator, which does emulate Sun 3 systems,
and I think has a bwtwo option, however I didn't use it: I tried to compile
it, and it didn't compile, so I said fuck this, my real hardware works)
to have an alternating red/blue style bwtwo, and test the demo there.

I got confused about when the actual ending was because I read
"Midnight Sunday GMT" and convinced myself that it is midnight on
sunday one minute after 11:59pm on Saturday, so that's why I rushed
to release this. It could be cleaner than the release here. If the compo
is indeed still running, I might clean it up and rerelease, but honestly
I think I better stop here. My time would be better spent uploading the
rest of the pictures I took of "the making of", and perhaps draw up
a schematic of what's on my anaglyph board (no. I don't even have
a pencil one yet: it's come into being by my dropping parts on the board
and experimenting -- that's why I put a pic of the NPN floating in the
air in a dead-bug style -- that's how pretty much everything was at one
or another point).

Well, whether or not I take the cake, I feel like a winner, since I went
beyond my expectations of this machine's capabilities, and learned
a lot about using a comparator as logic gates, biasing transistors,
how I perform under pressure, etc. Also, I was happy I did the
retr0briting early on because then we had so much rain mid-July
that I wouldn't have been able to do that at the end I suspect.

Yeah. That about sums it up. I'll up the VHS dump of running the
demo to youtube soon enough, and try and sift through these pictures
that I haven't gone through yet (many of them are blurry, or duplicate,
so I need to decide what I want up here still). After that, if there's still
time, I'll try and draw up a schematic for the anaglyph board, but I
think the text description is clear enough for someone to replicate it
if they really wanted to.


1 comment:

  1. Nice project. Using the comparator to get blue and red is a nice modification to the original black and white output. Looking at the final image, I can see where all that manga comes in useful when creating screen tones! Now, to use that signature to forge some cheques... haha

    ReplyDelete