Thursday 23 December 2010

#CarolsInCode - Top Five Countdown

#carolsincode
#CarolsInCode is a programming meme with a seasonal twist. Short programs are used to encode the lyrics of a Christmas carol. Some display the lyrics when the program runs while the more ingenious examples define the song with the program's control structures.

For example in JavaScript:

while ( shepherds.watch() == 'flocks' &&
  date.getHours() in night )
{
  lord.angel--;
  glory.shone_around();
}

This is While Shepherds Watched Their Flocks by Nahum Tate:

“While Shepherds watch their flocks by night,
All seated on the ground,
The angel of the Lord came down,
And glory shone around.”

Here's the top five countdown of the very best #CarolsInCode. Can you identify all five? Is your favourite missing?

GrumpyWookie:

Weather.Outside="frightful";
Fire.Delightful=true;
Lights.Luminosity=WayDownLow;
for (int i=1; i<=3; i++) { LetItSnow(); }

ShinyEmptyHead:

public Sleigh sleigh;
public void dashThroughSnow()
{
int horses = 1;
sleigh = new Sleigh(horses);
for (Field field : fields)
{
laugh();
}
}

JohnGirvin:

var wenceslas = new Person({
    rank: 'king',
    alignment: 'good'
});
$.bind(FeastOfStephen, function() {
    wenceslas.lookOut();
});

Costall:

if (DateTime.Now()=="25/12/2010")
{
for (i=0;i<3;i++) Ship[i].Visibility = Visibility.Visible;
}

GrumpyWookie:

Kiss.PersonA="Mummy";
Kiss.PersonB="Santa";
Kiss.Witness=Me;
Kiss.Location=Mistletoe.Underneath;
Kiss.Time=Date.LastNight;

More #CarolsInCode




#songsincode, lyrics for programmers

Friday 17 December 2010

#carolsincode - Christmas for Programmers

#carolsincode
#carolsincode are small pseudo-programs which contain a Christmas song. Some examples display the lyrics while others use the program's control structures to define the song.

Here are five examples in C, CSS and JavaScript. Can you do better? ;-)

var kings=new Array(3);
for (x in kings)
{
  kings[x].origin='orient';
  kings[x].bearingGift=true;
  kings[x].travelled='afar';
}

main() {
  int a;
  for (a=1;a<5;a++) printf("Noel, ");
  printf("Born is the King of Israel.");
}

#rudolf .nose {
  color: red;
  background: url('very_shiny.jpg');
}

while ( shepherds.watch() == 'flocks' &&
  date.getHours() in night )
{
  lord.angel--;
  glory.shone_around();
}

for ( c=1, c<=4, c++)
{
  noel()
};
king = new Object();
king.kingdom = 'Israel';

Monday 6 December 2010

Programming Contest: Topswaps

Al Zimmermann's latest programming challenge asks up to arrange a deck of n cards numbered 1 .. n to maximise the number of swaps. Each swap looks at the value x on the top card and reverses the top x cards.

For n=4 the sequence 3, 1, 4, 2 requires 4 swaps:

3 1 4 2

4 1 3 2

2 3 1 4

3 2 1 4

1 2 3 4

Al challenges us to find the best solution for the first 25 primes, n=2, 3, 5 .. 97. Even a simple program which tests random combinations can throw out some reasonable scores:

10 rem setup array
20 input z
30 dim x(z)
40 for a=1 to z
50 x(a)=a
60 next a
70 h=0

100 rem shuffle array
110 for a=1 to z
120 r=int(rnd*z+1)
130 t=x(a)
140 x(a)=x(r)
150 x(r)=t
160 next a

200 rem remember order
210 a$=""
220 for a=1 to z
230 a$=a$+","+str$(x(a))
240 next a

300 rem swap until done
310 c=0

400 q=x(1)
410 for a=1 to int(q/2)
420 t=x(a)
430 x(a)=x(q+1-a)
440 x(q+1-a)=t
450 next a

500 c=c+1
510 if x(1)>1 then goto 400

600 rem display highscore
610 if c>h then h=c:print c;" : ";a$
620 goto 100

Are you planning to take part in the contest?

Friday 8 October 2010

URISC / OISC: One Instruction Computers

URISC is an abstract computer designed to have a minimal instruction set, only one instruction. URISC is an abbreviation of Ultimate RISC, although technically the machine doesn’t meet the criteria for RISC.

Types of URISC


There are four common types of URISC – MOV, RSSB, SUBLEQ and SUBNEG.

MOV – Transport Triggered Architecture


In a MOV URISC machine there's one instruction with two operands. When the instruction executes, it copies one location in memory to another, using the operands as pointers. Jumps, arithmetic and input / output are achieve with a memory mapped program counter, arithmetic unit and input / output ports.

More information about MOV TTA:


RSSB – Reverse Subtract and Skip if Borrow


The instruction in a RSSB URISC machine is Reverse Subtract and Skip if Borrow. Each instruction has one operand which is a pointer into memory. When the instruction executes, it subtracts the accumulator from a memory location and stores the result in both. If the value in memory was lower than the accumulator, the next instruction will be skipped. The program counter, accumulator and input / output are mapped to memory.

More information about RSSB:


SUBNEG – Subtract and Branch if Negative


Also abbreviated to SBN, a SUBNEG computer uses an instruction with three operands. When executed, SUBNEG subtracts the contents of the first memory location from a second location, storing the result in the second. If the first value was higher than the second, SUBNEG jumps to where the third operand points. Input / output are memory mapped.

More information about SUBNEG:


SUBLEQ – Subtract and Branch if Less than or Equal


SUBLEQ is similar to a SUBNEG computer, but also branches if the contents of the two memory locations is identical.

More information about SUBLEQ:


Other Types of OISC


There have been several attempts to simplify OISC even further.  Here are a couple of examples:


Tuesday 5 October 2010

Core War - The King of Programming Games

corewar: the war of the programmers
The aim of a programming game is to write a short program that competes towards a goal, usually destroying all opponents or capturing a flag.

There are two main types of programming game:
  • games inspired by RobotWar - programs control a battle robot which moves around an arena firing at opponents – RobotWar was created in the 1970s.
  • games inspired by Darwin - programs attempt to modify and crash the opponent's program. Darwin was first played at Bell Labs in 1961.

Both games have spawned a series of clones, the most popular being CRobots (1985) and Core War (1984).

In Core War players write programs in Redcode, the assembly language of the MARS virtual computer. The aim of the game is to survive while causing all opponents to terminate. There are three basic strategies:

  • paper - programs spawn off new copies in the hope at least one survives.
  • scissors - programs search for opponents and attempt to disable them.
  • stone - programs drops instructions at random hoping to hit the opponent.

A couple of years after A. K. Dewdney introduced Core War a society was formed which organised an annual tournament. The First International Core War Tournament held in the Computer Museum, Boston MA was a great success with a paper coming out on top, Mice by Chip Wendell.

Core War is now played as a King of the Hill tournament. Players submit their program to a hill containing some of the top Core War programs, receiving results a few minutes later. If the program is successful it enters the hill, knocking off the lowest warrior.

Despite being 26 years old Core War still has a community of regular players. Although the major techniques appear to have been discovered new ideas are constantly being tested, occasionally with impressive results. If you’d like to find out more about Core War here are some handy links for new players:


If you’re planning to try your hand at writing a battle program, good luck and may the core be with you!

Saturday 12 June 2010

The Vintage Computer Festival, Bletchley Park

The computing highlight of June will be the Vintage Computer Festival at The National Museum of Computing, Bletchley Park.  Held on 19-20 June, the event is the first of it's kind in the U.K.  Tickets can be purchased for £8.50 online or £10.00 on the door.

The National Museum of Computing's website has the full list of exhibitors, lectures and events. Some of the highlights include:

  • The launch of the new Amiga X1000 boasting a dual-core 1.8GHz PowerISA CPU, 2GB memory and Xena 500MHz SDS co-processor
  • 20+ exhibitors demonstrating a variety of historic computers
  • Lectures by a number of key figures in computing history, including Sophie Wilson, one of the designers of Acorn Computers and ARM processors
  • Retro gaming competition

I'll be there when the gates open at 10:30am on Saturday. Are you planning to attend?

Saturday 5 June 2010

Computer Museums in the U.K.

The U.K. has a number of dedicated computer museums while a few other museums have permanent computer history collections. If you're interested in the history of computing the following are definitely worth a visit:

The National Museum of Computing


During World War II Bletchley Park was home to Britain's secret codebreaking activities. The National Museum of Computing is based at Bletchley and has a collection which includes an Elliot 803, ICL 2966 and the Colossus. The museum is open Thursday and Saturday afternoons. Admission is £12 for Bletchley Park plus £5 for TNMOC.

Museum of Computing


The Museum of Computing is close to Swindon's town centre and specialises in home computers and games consoles. The museum is open on Friday and Saturday. Admission is £2.

The Science Museum


London's Science Museum has a collection dedicated to the history of computing. The museum is home to a variety of notable systems including a Cray 1, Ferranti Pegasus and Charles Babbage's Difference Engine. Entry is free.

The Centre for Computing History


The Centre for Computing History is based at Haverhill in Suffolk. The museum has an extensive collection of home computers, manuals and magazines. Admission is free but by appointment only.

The Museum of Science and Industry


The calculating and computing exhibition at Manchester's Museum of Science and Industry includes a rebuilt Baby, the world's first stored program computer. Entry to the museum is free.

Friday 7 May 2010

My Latest Gadget: Altera MAX II

SLS ELT II development board with Altera MAX II

Here's my latest gadget, a SLS ELT II development board with Altera MAX II picked up for £1.20 on eBay :-) It provides 240 programmable logic elements and 8 kilobits of flash memory.  I haven't got anything planned for it yet apart from a crazy idea about evolving a logic array to solve a problem.  Have you got any great ideas for a project?

Monday 3 May 2010

10 Alternative Monospace Fonts for Programmers

Recently I started to look for an alternative programming font after spending far too many hours staring at Courier New. I needed to find a free fixed-width font that's easy on the eye and clearly distinguishes between similar characters, e.g. O01Il.

Here's a quick round up of the best alternatives I found. Which programming font are you using? Did I miss your favourite?

Default Monospace Fonts


First let's take a look at the default fonts. The examples show the font at 12 point with subpixel rendering switched off:

Consolas



Consolas is a monospace programming font created for Microsoft by Lucas de Groot and ships with Windows Vista / Windows 7. Has a slashed zero and designed to look best with ClearType enabled.

Courier New



Courier New is perhaps the most familiar monospace font having been introduced in 1992 with Windows 3.1. Courier New is a serifed font designed by Adrian Frutiger and lacks a slashed zero.

Lucida Console



Lucida Console designed by Charles Bigelow and Kris Holmes is the default font for Windows Notepad and also lacks a slashed zero.

Monaco



Monaco is a sans-serif monospace font designed by Susan Kare and Kris Holmes and ships with Mac OS X. Includes a slashed zero.

Alternative Monospace Fonts


While some of the default fonts aren't too bad, we can do much better. Here are some great alternatives mostly designed with programmers in mind:

Anonymous Pro



Anonymous Pro is a programming font designed by Mark Simonson. The serifed font was influenced by Susan Lesch and David Lamkins' Anonymous 9. Very clear with plenty of white space and a slashed zero.

Bitstream Vera Sans Mono



Bitstream Vera Sans Mono is a sans-serif coding font designed by Jim Lyles from Bitstream. The zero is dotted and the bottom of the lower case l curls to the right.

DejaVu Sans Mono



DejaVu Sans Mono is extended from Bitstream Vera Sans Mono and supports a wider selection of characters. The clean sans-serif font ships with a number of Linux distributions.

Dina



Dina is a sans-serif programming font created by Jørgen Ibsen and is available in 8, 9 or 10 point. Has a slashed zero.

Droid Sans Mono



Droid Sans Mono was designed by Steve Matteson of Ascender Corporation. The sans-serif font is clear but lacking a slashed or dotted zero.

Envy Code R



Envy Code R is a clean sans-serif programming font designed by Damien Guard and includes a slashed zero.

Inconsolata



Inconsolata is a monospace programming font created by Raph Levien and inspired in part by Consolas. Has a slashed zero.

Monofur



Monofur is a quirky monospace font created by Tobias Benjamin Köhler. Includes a dotted zero and a curl on the lower case l.

Proggy Clean



Proggy Clean was designed by Tristan Grimmer and is available with either a dotted or slashed zero. Several variants of the Proggy font are available.

Triskweline



Triskweline is a clear monospace font created by Henning Koch. Lacks a slashed zero and only available in 10 point.

Sunday 4 April 2010

Classic Home Computer Fonts

Anyone who owned a home computer in the 80's would have been intimately familiar with the character set. Although it was possible to redefine the font, it had to be loaded from cassette and was restricted to an 8×8 pixel grid. Love it or hate it, you were stuck with it.

Fortunately for anyone who misses their 8-bit computer a selection of classic fonts are available online. Here are a few of my favourites:

Amstrad CPC Font Amstrad CPC font

Atari Font Atari font

Commodore 64 font Commodore font

ZX Spectrum font ZX Spectrum font

Which home computers did you own and what did you love / hate about the font? :-)

Saturday 20 March 2010

Threaded Interpretive Languages by R. G. Loeliger

Threaded Interpretive Languages by R. G. Loeliger
In Threaded Interpretive Languages, Loeliger explores the design and implementation of TILs in an individual quirky style.  Programs in a threaded language typically compiles to a list of subroutine calls or addresses. Loeliger focuses on Forth-like threaded languages and provides examples in Z80 assembly language.

After the standard introductory chapter the book gets straight down to the implementation details, first dealing with the design of the dictionary format, inner and outer interpreters.  This is followed by example code for the interpreters and assembly language definitions for 170 of the most common subroutines.

Later chapters investigate some common extensions to TILs including virtual memory and floating point numbers. A section is devoted to assemblers and includes code for a structured Z80 assembler.

Threaded Interpretive Languages contains the most in-depth examination of Forth internals I've seen. However the age of the books shows in the dialect of Forth used and the systems described. Despite this, I'd still recommend Threaded Interpretive Languages to anyone planning to implement a minimal Forth.

Sunday 28 February 2010

Emulating the Manchester SSEM

display from my Manchester SSEM emulator
The Manchester Small-Scale Experimental Machine was the first computer to store programs in memory and was built at the University of Manchester in 1948 by Williams, Kilburn and Toothill.

The machine had 32 words of 32 bit memory, one register and supported 7 instructions:

000JMPs, CJump
100JRPc+s, CRelative Jump
010LDN-s, ALoad and Negate
110STOa, SStore
001SUBa-s, ASubtract
011CMPTestSkip if Negative
111STOPStopHalt Machine

With only 7 instructions the SSEM makes an ideal system for an emulation project. A basic simulator can be written in under 40 Intel x86 instructions. If you're tempted to write your own, the SSEM Reference Manual will come in handy. :-)

Saturday 9 January 2010

8 Bit Home Computer Benchmarks

Over the years I've collected quite a few 8 bit home computers. Out of curiosity I decided to write a simple prime sieve benchmark to compare their implementations of BASIC.

10 LET W=500:DIM F(W):LET P=1:LET A=3
20 LET F(P)=A:LET P=P+1:IF P>W THEN STOP
30 LET A=A+2:LET X=1
40 LET S=A/F(X):IF S=INT(S) THEN 30
50 LET X=X+1:IF X<P AND F(X)*F(X)<=A THEN 40
60 GOTO 20

Here are the results from a few of the machines I have to hand:

System
CPU
Time
Acorn Electron
2.0MHz 6502
138
Amstrad CPC464
4.0MHz Z80A
140
Commodore C64
1.0MHz 6510
254
Commodore Plus/4
1.0 MHz 8501
267
Tandy 64K CoCo 2
0.895MHz 6809E
271
Atari 800XL
1.8MHz 6502
316
Sinclair Spectrum +3
3.55MHz Z80A
388

Let me know how long it takes to run on your favourite classic computer. :-)