Archive for July, 2008

Toad in the Hole

Friday, July 11th, 2008

This recipe is based on the one from this book which my parents bought for me when I went off to university, but I have tweaked it a bit and made it more specific. This is the only thing I've made the book regularly - it now falls open at this page.

(To serve 2)

Put 7 breakfast sausages in a metal baking pan with a bit of cooking oil and put them in a 425°F oven for 7 minutes.

While the sausages are cooking, put 4 heaped tablespoons of plain flour into a bowl, add a couple of pinches of salt and a couple of eggs. Beat the egg into the flour (this is much easier with an electric whisk) until it's homogeneous. Gradually add 1 cup of milk while continuing to mix. If you add too much milk too quickly it'll go all lumpy.

Pour the batter over the hot sausages and oil (this bit makes a nice sizzling sound) and bake for about 24 minutes. Try not to open the oven door for the first 10 to 15 minutes, so that the pudding will rise well. The Yorkshire pudding should be golden brown.

About 10 minutes before it's done, wash a couple of medium-sized potatoes, stab them all over with a fork and put them on a plate in the microwave for 10 minutes. Peel and slice up some raw carrots to serve with it as well.

Plate it up and eat it with a nice tall glass of cold milk (you may be sensing a theme here with the beverage choices - I do like a nice glass of cold milk with a hot meal).

Pasta dish I made up

Thursday, July 10th, 2008

This is another one I made up myself in my bachelor days.

Cut up some vegetables into small pieces. I found the best combination to be:

  • Celery (1 stick per person)
  • Red bell pepper (1/4 per person)
  • Carrot (1 per person)
  • Onion (1/2 per person)

Add some chopped garlic if you like.

Slice up some bacon as in yesterday's recipe and cook it with the vegetables. The vegetables will fry nicely in the fat from the bacon.

Cook some pasta (I like the twisty ones), drain it and add some sort of pre-made tomato-y sauce. I found one in the supermarket that just said "made with Meat" (no specific animals species were mentioned) so I used that for amusement's sake and it worked pretty well.

Mix the pasta and the sauce together and then dump that into the saucepan with the vegetables and bacon. Turn the heat right up and keep stirring it until the runniness disappears and it acquires a more gloopy consistency (technical term).

Plate it up and eat it with a nice tall glass of cold milk.

Spaghetti carbonara

Wednesday, July 9th, 2008

Soon after I moved to the US I fancied eating this but didn't have a recipe. So, I looked up one on the internet and adapted it to what I happened to have in the apartment. This isn't exactly what most people would consider carbonara (it's more like scrambled eggs and bacon with spaghetti) but it's filling, yummy comfort food.

Cut up some bacon (2 or 3 slices per person) into pieces about 1cm wide. I sometimes cut off most of the fatty bits to make it a bit healthier but this could quite rightly be considered an abomination.

Put some water on to boil and when it gets there put the spaghetti in and turn it down to medium. That's about the right time to put the bacon on. Put it in a nice big saucepan on a medium-high heat (not too hot or the fat that oozes out from the bacon will burn off before the bacon gets a chance to sizzle in it). No extra oil should be necessary.

While the bacon is frying, put some eggs (2 per person), a bit of salt and pepper and some grated cheese (the more kinds of cheese the better - I have had good results with cheddar, shredded mozzarella, parmesan and chevre). Mix it all up together.

If the bacon is done before the spaghetti, turn the heat down to low to stop it getting too crunchy. When the spaghetti is done (which should take 10 minutes or so - you want it just a little al dente but not so much that you get bits of it stuck in your teeth) strain the water off and dump it into the bowl with the eggs and cheese. Turn the heat back up on the bacon now if you turned it down before. Stir that about a bit so that the spaghetti gets coated in the egg. Once it's nicely homogeneous, plop it into the saucepan with the spaghetti and bacon juice. Stir it around a bit until bacon is all mixed in and the egg is just beginning to solidify. I find it's better if the egg isn't completely cooked through but be warned - undercooked eggs might give you food poisoning. I've not killed anyone with this dish so far though.

Plate it up and eat it with a nice tall glass of cold milk.

Risotto

Tuesday, July 8th, 2008

Another of Mum's recipes.

An easy one pot meal good for using up odd leftovers. As long as you have oil, onion, rice and water everything else is flexible.

Per person:

  • 1 very small onion chopped (or half a bigger one)
  • chopped or crushed garlic (optional!)
  • 1 bay leaf (optional but recommended)
  • Chopped herbs (optional but recommended - you could use dried)
  • 75g long grain rice ( "easy cook" rice is good as it won't go sticky)
  • 190 mls hot water ( = 2.5 times volume of rice)
  • half a stock cube
  • 1 tablespoon oil
  • salt & pepper ( stock cube may be quite salty so you might not need much salt you can always add more when it's on the plate)

any or all of the following, quantity depends on how hungry you are:-

  • cooked meat, - bacon, chicken, sausage
  • celery - chopped small
  • carrot - chopped small
  • peas
  • sweetcorn
  • peppers - chopped small
  • chopped tomato
  • sliced mushrooms
  • anything else you've got that you think will taste good

Dissolve stock cube in hot water.

Heat oil in saucepan and cook onion and any raw vegetables until onion is softened. Add garlic, bay leaf and rice a cook for a minute or so. Pour in stock and bring back to boil. Add everything else and simmer gently until rice is cooked and all the liquid is absorbed. Watch it doesn't stick to the bottom of the pan near the end of cooking time. Take out the bay leaf and sprinkle with grated cheese to serve.

Easy or what!

Chicken and rice

Monday, July 7th, 2008

It's recipe week this week at Reenigne blog. Not my usual fare, but not completely without precedent either. Some of these recipes (including this one) are from my mother, others I've made up or adapted myself.

  • 1 onion peeled & chopped
  • 1 carrot peeled & chopped
  • 3 sticks of celery washed & chopped
  • about 2 tbsps oil
  • about 2 tbsps flour
  • 1lb chicken
  • 1 chicken (or vegetable if vegetarians are joining in!) stock cube stock cube dissolved in 10 - 15 fl oz boiling water
  • handful frozen peas &/or sweetcorn
  • a few mushrooms sliced
  • about 2fl oz cream

If the chicken is raw cut it into bit size bits and fry it in oil 'til it's browned. It doesn't have to be cooked through at this stage. Remove it from the pan with a slotted spoon to drain the oil off. Now fry the onion, carrot & celery in the oil 'til they just start to brown but you don't want them too dark. Add the flour and stir it in until it coats the vegetables and cooks a bit. Add the liquid gradually, - stirring all the time and bring to the boil still stirring. It should thicken.

Add the peas, sweetcorn and mushrooms. If you're feeding vegetarians, separate out their bit and add the chicken to the rest. You could add other vegetables or extra mushrooms to the vege bit. Season with salt & pepper and simmer the whole lot until the chicken is cooked through and the vegetables
are tender. If it's not thick enough you can add some cornflour mixed with water to make it thicker. Add the cream at the end. If you've got any herbs bung them in too and it'll be even yummier.

Cook the rice in a separate pan while the whole thing is cooking.

You can adapt it as you see fit - put in leftover sausages for example or add a bit of chopped up bacon with the onion etc if you're all meat eaters, or serve it with pasta instead of rice.

Generations of screen sizes

Sunday, July 6th, 2008

If you make a list of common screen resolutions and plot them on a log/log scale, you will notice that a regular pattern emerges - given an x by y resolution, x*2 by y*2 also tends to be common. However the sizes are not evenly distributed throughout logarithmic spaces - there are gaps which suggest different "generations" of monitor sizes, each monitor having 4 times the number of pixels as the corresponding monitor in the previous generation. I suspect this is because of the influence of TV - the resolutions are clustered around powers of 2 of TV resolutions.

Generation 1 - 256-480 pixels wide, 180-300 pixels tall (non-interlaced TV, handhelds)
Generation 2 - 512-960 pixels wide, 360-600 pixels tall (interlaced TV, older computer monitors)
Generation 3 - 1024-1920 pixels wide, 720-1200 pixels tall (most current computer monitors)
Generation 4 - 2048-3840 pixels wide, 1440-2400 pixels tall ("Q" standards - very high end monitors)
Generation 5 - 4096-7680 pixels wide, 2880-4800 pixels tall ("H" standards - no monitors exist yet)

Screen aspect ratios as musical notes

Saturday, July 5th, 2008

Aspect ratios of televisions and computer monitors tend to be ratios of small integers. On my desk right now I have 3 monitors that are 4:3 and one that is 8:5.

Another thing involving ratios of small integers is musical intervals in Just Intonation.

C 1:1
C# 16:15
D 9:8
D# 6:5
E 5:4 5:4 monitors exist but are not common
F 4:3 the most common non-widescreen aspect ratio
G 3:2 3:2 monitors exist but are not common
G# 8:5 the most common computer widescreen format
A 5:3 5:3 monitors exist but are not common
A# 16:9 HDTV format
B 15:8

Lispy composable compiler

Friday, July 4th, 2008

When I finally write the compiler for my super-language, I want to make it nice and modular - i.e. make it very easy to compile different languages, target different architectures and include different optimizations.

In order to achieve this I will need to have some kind of intermediate form in which pieces of code in various states of compilation to be transmitted from one module to another.

This form should be as simple as possible but should also make it possible to express all the complexities that occur in real code. In short, it will need to be a tree structure.

While I'm not convinced that the Lisp idea of "code without syntax" is a great one (I think every available visual/syntactical clue makes it easier to understand unfamiliar code) I have to admit that the lisp data structures (SExps and Lists) are perfect for this role. I wouldn't expect people to be reading large quantities of this code but it's handy to be able to print it out for debugging purposes.

A Symbol (what lispers call a SExp, S-Expression or Symbolic Expression) is either an Integer, a String, an Atom, a List or a Vector. Integers are what you'd expect them to be. Strings are used to hold things like variable names. Atoms are displayed as strings but treated as unique, opaque integers internally. All you do with an Atom is compare it to another Atom and see if they are the same. See Stringy Identifiers for another perspective on these. This is not quite the same as the lisp usage of the word, where integers are also atoms.

A List (delimited with parentheses) is effectively an object. It consists one or more Symbols, the first of which must be an Atom. It has a type, which is represented by its Atom and the number and types of the following Symbols.

A Vector [delimited with square brackets] is effectively an array of length possibly not known until run-time. This can be used for a sequence of statements (for example) or for the bytes in the compiled program before it is output to disk. Lisp doesn't distinguish between lists and vectors but I think it is useful to keep them separate.

It is not a coincidence that this is quite similar to the RTL of GCC. Many of the same problems are being solved, and I was learning about RTL when I came up with this. However, this structure is a little more general-purpose and a little simpler. In particular it can also be used for front-ends.

These expressions will generally be manipulated by pattern matchers - that is, we search through the program for an object matching some characteristics, perform some transformation on it and then substitute the result for the original object.

For example, here is a part of an x86 assembler written in a hypothetical language which has support for these Symbols built in:

    with(x) {
        match (`jmp` d:Int):
            if (isSByte(d))
                becomes (`db` [0xeb d]);
            else
                becomes (`db` [0xe9 bytesFromDWord(d)]);
        ...
    }

This matches a List which consists of the `jmp` atom followed by an integer (which we will call d). We pass that integer to a function and (depending on the result) we emit one of two possible forms of the x86 JMP instruction. As "bytesFromDWord" is known to be a function and not an Symbol, it is evaluated and the result placed into the vector rather than two Symbols (bytesFromDWord and (d)) being created and placed into the vector.

This works just as well for the front end. The "unless" statement that I have written about before can be broken down using this code:

    match (`unless` condition): becomes (`if` (`!` condition));

And we should have this optimization as well, in case condition is itself a negated condition:

    match (`!` (`!` x)): becomes (x);

Quite a lot of the compiler can be written very easily and tersely this way. There are some complications to do with the order in which transformations are applied, though - we would rather avoid having to specify that explicitly and let the computer figure it out. But the order might depend in quite a complicated way on the context. One way to deal with this might be to keep the pre-transformed Symbol around and continue to match against it even after it has been replaced. Another might be for transformations to transform other transformations as they are applied to the Symbols. I haven't quite figured this bit out yet. This seems like one of those problems that might be technically intractable but always works out to be fast enough in practice.

With some cleverness, it ought to be possible to write a very good compiler this way. Great speed is possible as no string handling is done after the initial parsing phase and symbol table lookups (e.g. we don't write out assembler instructions and rely on a separate assembler to assemble them, though we could still easily obtain assembly code if necessary by having a separate output module.) Many speed improvements are possible (e.g. by performing some transformations when the compiler is compiled).

But the really great thing about this scheme is that code for the compiler is completely self-describing - it's exactly the code one would hope to be able to write.

Having a set format for code also enables the scenario I wrote about in Compiler compilers.

Finally, this structure works just as well for disassemblers and decompilers as it does for compilers and assemblers. Some of the algorithms will be different most of the transformations probably cannot be reversed directly but many of the same patterns show up.

Sampling keyboard

Thursday, July 3rd, 2008

I'd like to write a piece of software which makes it trivially easy to record and instantaneously play back sound. This piece of software would be operated by holding down keys on the computer's keyboard. For example:

  1. Holding down 'R' records whatever goes into the computer's microphone while the key is held down and stored in the next unused buffer.
  2. Holding down 'P' plays back all the buffers at the same time (until the last buffer runs out or the key is released, whichever happens first).
  3. Holding down 'B' does both (with appropriate cancellation of the output signal from the input signal).

This software would enable a truly epic (and slightly shorter than normal) reading of the children's book "Doggies". For those unfamiliar with the book, there are ten dogs, each of which has a different bark ("Woof", "Yap yap", "Ruff ruff ruff" etc.). On the first page the first dog barks, on the second page the first and second dogs bark and so on.

With the aid of this software, the human reader/operator need only make each dog sound once. Furthermore, all the dog sounds would be heard simultaneously, making the immediate vicinity sound like a dog pound by page ten.

I'm sure there are other uses too, but this was the inspiration.

PAL version of demo machine

Wednesday, July 2nd, 2008

The demo machine described the other day could easily be generalized to PAL output. There are some complexities though. Because of the missing quarter cycle of the carrier frequency per line, the PAL signal for a still image repeats every 4 frames. This means that in order to do the same "extremely simple, highly standards-compliant demo" that was possible on the original demo machine for NTSC, we need 2.7Mb of sample data. Let's run with this and round up the PAL machine's memory to 4Mb - rather than making the PAL machine as similar as possible to the NTSC machine, we should take the opportunity to introduce some variety.

Similarly, the CPU clock speed for the PAL machine should be (exactly) 17.734475MHz.

Generating interesting standard PAL signals does have some complications that NTSC signals don't have. Because of the 25Hz offset, the colour carrier frequency starts at a different phase on each line, meaning that a sprite needs to have different sample data depending on its vertical position. I expect that most demos written for the machine would use one of three simplications of the PAL standard (as most if not all computers and consoles that generate PAL signals did):

  1. eliminate the 25Hz offset so that the colour carrier phase repeats every 4 lines
  2. use a whole number of subcarrier cycles per line (making the chroma patterns vertical)
  3. eliminate interlacing, doubling the frame rate at the expense of halving the vertical resolution

These simplifications change the horizontal and vertical retrace frequencies slightly from the standard 15.625KHz and 50Hz rates, but not so much that real hardware is likely to fail to display the intended image.