Stone Soup

Exotic and Rare, the C Compiler

Once upon a time, a C compiler was a rare and exotic thing. They weren’t commonly available outside of research labs or well funded corporations, and if you were working on a newly minted microprocessor based machine, you were out of luck. In those days you were lucky to have an assembler – sometimes your day started by keying it in address by address, byte by byte, or by laying some rudimentary tools into RAM from a tape and pushing the Go button. Once upon a time, lifting a machine by its bootstraps was an important start of the development process.

3D0G!

The bootstrapping process was well known to old school game coders. We knew all the Apple ][ system vectors and how to lay in boot loaders to hijack the startup process straight into a game. The boot ROM in the disk controller card loaded the first 256 bytes of code and jumped into it; increasingly complicated loaders were overlaid until finally your game was in memory, and you were off. The Apple ][ was a great to-the-metal playground for learning to code. Its primal tool was a marvelous mini-assembler; no symbols or branch calculation helpers, it had just a simple translator from opcode mnemonics to bytes, and its greatest treasure was the “L” command to list a few more lines of code. It was enough to put together a lot of fun, and reveal the innermost secrets of programming. Steve Wozniak wrote the mini-assembler, he was a teacher from the start, and the Apple ][ monitor was the best school.

Early Console Hackery


But what about systems not quite so hacker friendly? One of my favorite bootstraps was the one we did at Interphase Technologies on the Colecovision. The Colecovision was an archetypical closed gaming console, popular long before the days of SDKs. When we started we knew nothing about the machine, some components were sealed under epoxy blobs, and some parts had numbers removed. Our first order of business was some radical deconstruction. This involved acids, sledgehammers, microscopes, and drops from high altitudes. It also involved diagramming out circuit diagrams and other down to earth engineering.

We worked out the general capabilities of the machine; most importantly we found that it was sporting a Z80. Going back to an unpulverized unit, we desoldered the CPU and wired in a breakout header, then carefully reattached the CPU above it. We attached a signal analyzer to the breakout header, and built a latch on the address lines so that we could halt the CPU when a certain address was requested from the ROM. We wired LEDs to some outputs. Now we had a debugger! We dumped the system ROM, and it was all straight forward from there. We hacked a TRS-80 assembler to target the features of the Colecovision, got some EPROM burners and UV lights to erase the ROMs for the next debugging sessions, and we had a development system. A couple of weeks later, an early success – I was able to display an X in the middle of the screen! It was only a small step from there to a fully functioning game. You can grab my first console ROM, Aquattack, from this link: http://meshula.net/download/aquattack.zip. It works in any Colecovision emulator. My proudest moment was when the Coleco engineers came by at CES because they had heard I had managed smooth scrolling. The advantage of not having any documentation or guidance was that we didn’t know what the machine couldn’t do!

Coding in Silos

In those days we coded in silos. A little light came in from the top, but you might go weeks or months without actually talking with someone who was doing the same things as you. Occasionally you’d hear rumors of something called Siggraph or what have you, but it could take a really long time to track down those sorts of resources, and in the mean time you did the next best thing which was to work it out for yourself…

At that time the C compiler was still a rare and exotic thing, but at last the great day arrived – I managed to dredge up the source code for a C compiler off usenet. It was a stunning surprise to discover that the C compiler was written in… C.

The source code was not the most readable thing in the world, but I was determined to work out how it could be that C might be written in C. I turned to Forth, a language I was already familiar with from my work in robotics. Forth is the classic bootstrappable language.

Bootstrapping a Compiler

At its simplest level, Forth doesn’t do much. Here’s my implementation of the innermost bit, written in 68000 code (it was certainly a luxury to not have to build the assembler first!):

doNext MACRO
movea.l (a5)+,a3 ; fetch cfa pointed to by ip, and inc ip
adda.l a4,a3 ; convert the base address to absolute
jmp (a3) ; go execute the next word
ENDM

Every Forth command ends with the doNext macro which picks up the next opcode to execute, adjusts its address via the base pointer in a4, and jumps through it. To start Forth, a few registers are set up in assembly code to point to the first executable bit of Forth code, and the doNext macro is invoked. That drops into the cold start, written as a series of hard coded Forth word offsets, and so it begins.

cold bra doColon
dc.l coldStuff ; do all the neat power up stuff
dc.l clrPage ; clear screen
dc.l adotqa ; write the following message
dc.b 53
dc.b 'FUSION FORTH 1.00',13,10
dc.b 'by Nick Porcino and Don Palmer'
dc.b 27,'e' ; make cursor visible
dc.b 27,'v' ; wrap around
EVEN
dc.l cr ; do a carriage return
dc.l shell ; start the command line stuff
dc.l exit ; end of definition

Once this much code was written in assembly, I wrote a few of the most basic bits such as “compile a Forth word definition”, “save to disk”, and “parse a number”. Little by little enough functionality came on line that more and more sophisticated parts of the language could be written directly in Forth, and the Forth implementation began to compile itself as part of the bootstrap sequence. The file below is part of the start up; it invokes bits of Forth code to keep building up more of the compiler and base libraries. The last file that is loaded is the saving code that allows new Forth programs to be saved out to disk.

( Fusion FORTH compilation link file )
" INIT.BLK"ENTER LOAD
ENTER GRAFIX.4TH LOAD
ENTER MISC.4TH LOAD
ENTER FEN.4TH LOAD
ENTER FSEL.4TH LOAD
CD .
CD EDITOR
ENTER PRINT.4TH LOAD
ENTER EDFEN.4TH LOAD
ENTER ED2.4TH LOAD
CD .
CD CORE
ENTER SAVEFORTH.4TH LOAD

If you are interested in digging through the code, a version of Fusion Forth for the Atari ST is available at http://meshula.net/download/FusionForth68k.zip.

Ultimately, I enlisted a couple of friends to help, and we built the language out completely, including a GUI, a text editor, a graphical IDE, some games and utilities, and more, and all of it bootstrapped up from only a few lines of initial assembly code. It’s a bit like the old parable of Stone Soup. I never did get around to compiling that C compiler though!

Stone Soup

The process of bootstrapping goes on around us all the time, in the form of new platforms and protocols. When I think back on the humble beginnings of the computer revolution, and how recently it was a major effort just to display an X on the screen, I am simply awed at how complexity has enfolded upon complexity to turn the microprocessor into an engine of societal change.

http://en.wikipedia.org/wiki/Stone_soup:

  • A kindly, old stranger was walking through the land when he came upon a village. As he entered, the villagers moved towards their homes locking doors and windows. The stranger smiled and asked, why are you all so frightened. I am a simple traveler, looking for a soft place to stay for the night and a warm place for a meal. “There’s not a bite to eat in the whole province,” he was told. “We are weak and our children are starving. Better keep moving on.” “Oh, I have everything I need,” he said. “In fact, I was thinking of making some stone soup to share with all of you.” He pulled an iron cauldron from his cloak, filled it with water, and began to build a fire under it. Then, with great ceremony, he drew an ordinary-looking stone from a silken bag and dropped it into the water. By now, hearing the rumor of food, most of the villagers had come out of their homes or watched from their windows. As the stranger sniffed the “broth” and licked his lips in anticipation, hunger began to overcome their fear. “Ahh,” the stranger said to himself rather loudly, “I do like a tasty stone soup. Of course, stone soup with cabbage — that’s hard to beat.” Soon a villager approached hesitantly, holding a small cabbage he’d retrieved from its hiding place, and added it to the pot. “Wonderful!!” cried the stranger. “You know, I once had stone soup with cabbage and a bit of salt beef as well, and it was fit for a king.” The village butcher managed to find some salt beef . . . and so it went, through potatoes, onions, carrots, mushrooms, and so on, until there was indeed a delicious meal for everyone in the village to share. The villager elder offered the stranger a great deal of money for the stone, but he refused to sell it and traveled on the next day. As he left, the stranger came upon a group of village children standing near the road. He gave the silken bag containing the stone to the youngest child, whispering to a group, that it was not the stone, but the villagers that had performed the magic.”

Post to Twitter Post to Delicious Post to Facebook

Gallery

Click any image to visit the corresponding gallery.

2009 Summer

Volcanoes from Mt. Baker to Crater Lake

Amazing aircraft at Chino Airfield

Mono Lake

Kowloon, 1990

Point Reyes Lighthouse

Reference Photos for Artists

U.S.S. Enterprise

Reference Materials and Renders

Life and Character Drawing

Robots

Paintings, Drawings, and Renders

Creatures are everywhere

Boats

Lunar Lander

Star Trek Concept Art

Character Drawings and Renders

Toy Designs

Vehicle Designs

Flower Photo, 1990

Darlingtonia

Fractal Flame

Apollo 11 Painting

Ribbons at the Marin County Fair

Ballard Class Starship Concept

Japan Trip, 2008

Japan – Toba Monster

Osaka, 2008

BuddhaBrot Fractal Render

Bodie Stamp Mill

Sundew Macrophotograph

Devil’s Postpile

Bodie Ghost Town Buildings

Artifacts at Bodie

Japanese Electric Spiders

Dancing Wu Li Frog Mandala

In The Garden

Self Portrait, 1982

Photographs with Atmospheric Effects

The Jungle in my Living Room

The Jungle in my Yard

Star Trek Type 9 Shuttle Concept

Post to Twitter Post to Delicious Post to Facebook

DIY Microphone wind muffler

Wind muffler

Wind mufflers (sometimes called “dead cats”) can be pretty pricey, and they’re not available for every microphone.

I got a good quality stereo mic for my digital recorder, and discovered I needed a muffler when some of my outdoor recordings picked up too much wind noise. I made my own muffler. The first one I made was much more elaborate and involved sewing. After some thought, I came up with a much simpler design that I thought I’d share here.

At the craft store, I bought a rope of feathers intended for making feather boas, for a total cost of a few bucks. I blew it out and shook all the loose feathers free (it was pretty cheap), then carefully wound it around the microphone. I secured it with a girl’s hair elastic and trimmed the extra boa material. It works great; recordings are clear, but if you are outdoors you don’t pick up wind, and even if you blow directly on the mic wind noise is greatly reduced.

Post to Twitter Post to Delicious Post to Facebook

Flame art

Flame art

I created this image using the open source Flame algorithm by Scott Draves. Full view on my deviantart page.

Post to Twitter Post to Delicious Post to Facebook

Pixel Bender Fractals

Fractal

Continuing with the theme of procedural toys:

Adobe Labs has published a rather awesome toolkit for writing image process toolkits. Pixel Bender compiles a rather straight forward language into GPU code, and provides an interactive UI for tweaking parameters on the fly. The IDE stands alone, so you can play with filter writing without needing to host inside Photoshop or After Effects.

Tom Beddard wrote some amazing plugins for it. His Fractal Explorer is a lot of fun to play with. The image above is an Ernst Haeckel image applied to a fractal using orbit trapping.

Post to Twitter Post to Delicious Post to Facebook

Another realtime procedural piece

I’m a fan of the silhouette animation style.

Wowlab’s Factory and Fantasy trailer:

And here it is in action, implemented as a Processing app:

via: Tiny Cartridge

PS, here’s another silhouette piece that’s fun to try.

Post to Twitter Post to Delicious Post to Facebook

Debris in HD

This isn’t new, but it is my favourite realtime procedural demo ever.

The exe is available on pouet; it runs on quite a variety of machines I’ve tried it on.

Post to Twitter Post to Delicious Post to Facebook

StructureSynth

StructureSynth

StructureSynth is an extension to three dimensions of the concepts in ContextFree. The software is fast, as stable as it needs to be, and fun to experiment with. One of the key features of an open source software is its community, and the StructureSynth community is vigorous – have a look at the latest work. A pipeline exists for taking creations from StructureSynth into Blender, POVRay, Renderman, and SunFlow.

Post to Twitter Post to Delicious Post to Facebook

HDR One Mile Underground, and other pics

I’ve posted an album page with pictures from my recent road trip amonst the Volcanoes of the west coast.

There are nineteen of them located here.

Here are a couple of reduced samples of the photos:

Crater smoke

I experimented with Ansel Adam’s zone system, where you expose for shadows and develop for highlights. In order to get the necessary dynamic range, I bracketed all of my exposures by a couple of stops in either direction.

crater lake

Many of the photos are HDR tonemapped, using Photomatix.

a mile underground

Some of the photos are taken a mile underground in a lava tube, and painted by Coleman lanterns and flashlights.

cute

Some of the photos are just cute.

Post to Twitter Post to Delicious Post to Facebook

A New Method for Volume Rendering of Solid Objects

Volumetric Billboards is a new technique for rendering voxel objects, created by Philippe Decaudin and Fabrice Neyret. Their research page is at http://www.antisphere.com/Research/VolumetricBillboards.php.



Objects are represented as a volume textures, the volume textures are created in a MIP hierarchy for level of detail. The resulting textures can be surprisingly small; the Eiffel Tower model shown here is voxelized at 128×128x256, and takes up 4.8MB of compressed texture memory. Applying the techniques from Vidal, Mei, and Decaudin 2008, a further 75% reduction on this model is claimed. The MIP chain associated with each volume model allows the hardware to interpolate smoothly between different levels of detail. This can be observed in the video.

Rendering a scene proceeds as follows: A scene containing such primitives is sorted on the CPU from far to near, and a series of slices parallel to the camera is intersected with the primitives. Starting in the distance, a series of polygons are generated. These are the intersection of each volume primitive with the slice, mapped into each object’s volume textures. As can be seen in the diagram below, these polygons will have 3, 4, or 5 sides. A nicety of this approach is that slices can be spaced according to visible resolution; the stepping is in projected screen space.


These slices are submitted to the GPU per slice, rather than per object, and thus the usual problems with interleaved transparent object rendering are avoided; all objects, including translucent and transparent objects, will inter-sort properly. A potential drawback of this method is that there might not be enough GPU memory to hold all the volume textures in a slice, or that the volume textures will thrash through memory as rendering progresses. A mitigation would be to take the proposed algorithm one step further, and partition slices according to horizontal overlap in order to schedule volume textures across the bus more efficiently.

These ideas have been gestating for a little while: A similar rendering technique has been described by Kevin Boulanger for rendering grass, as previously described here. An extruded patch describes grass volumes, and in a step similar to Volumetric Billboards, middle distance grass is rendered as slices through that volume. Volumetric Billboards were also preceded by previous work by the same authors in rendering forests. A terrain is extruded into prisms, and volume cell containing a voxel image of a tree encoded in a volume texture is ray-traced. This method was suitable for distant, or fly-over views, but didn’t generalize the rendering problem. The Volumetric Billboards algorithm can also deal with this sort of representation, as can be seen in the animated grass in the video.

As described, the technique has most lighting information baked in. One can imagine that the technique can be extended to incorporate information to allow for dynamic relighting. It would also probably be useful to be able to switch between polygonal and voxel representations on the fly as the camera gets close to an object. Dynamic objects subject to more than just affine transformation could also be interesting.

References:

Ph. Decaudin, F. Neyret. Volumetric Billboards. Computer Graphics Forum, Volume 28, 2009.

V. Vidal, X. Mei, Ph. Decaudin. Simple Empty-Space Removal for Interactive Volume Rendering. Journal of Graphics Tools, Volume 13 (2), p 21-–36, 2008

Post to Twitter Post to Delicious Post to Facebook

Compact Normal Storage

If you’re visiting here, you’ve likely already visited Lost in the Triangles. But, just in case, I want to point out an awesomely useful investigation going on over there on evaluating different strategies for compact normal storage as typically required in a deferred renderer.

Similarly, Aras recently wrote a great post on encoding a float into an rgba tuple.

Post to Twitter Post to Delicious Post to Facebook

Dark Energy? Pshaw I say.

The first of the alternatives to dark matter and dark energy appear.

http://www.space.com/scienceastronomy/090817-dark-energy-alternative.html

Wait and see, dark energy and matter will pass from vogue, as the expansion of the universe turns out to be “the apparent expansion” of the universe. Next up: the Higgs Boson, which (in my opinion) is another bug patch, not a fix to the underlying models.

http://en.wikipedia.org/wiki/Higgs_boson

Post to Twitter Post to Delicious Post to Facebook

Coding is magic.

Software engineering isn’t engineering, and software management is nearly oxymoronic. I used to think coding was art or craft, but now I understand it is magic. Coding is spell casting; we move electrons, the very resonances of existence in an ordered manner with our incantations. What an incredible age we live in.

I recommend having a look at this article and discussion thread on Jeff Atwood’s blog. As a software engineer, I understand and appreciate the uproar that software engineering guru Tom DeMarco has caused, yet sympathize with his base arguments. Worth a read as you consider how to improve your own development processes.

Post to Twitter Post to Delicious Post to Facebook

Apollo 11 painting

I painted this for Apollo 11’s 40th anniversary:

Post to Twitter Post to Delicious Post to Facebook

Apollo 11 site photographed




New Scientist has an amazing gallery of photographs recently taken by the Lunar Reconnaissance Orbiter.


Much more is available at the LRO Camera website.

Post to Twitter Post to Delicious Post to Facebook

Bad Behavior has blocked 558 access attempts in the last 7 days.