Skip to content

Instantly share code, notes, and snippets.

@lukego
Last active December 12, 2015 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukego/4706885 to your computer and use it in GitHub Desktop.
Save lukego/4706885 to your computer and use it in GitHub Desktop.
Cute code (written in Forth)

Below is some cute code that I wrote for the OLPC Openfirmware HD Audio driver.

The firmware is allowed to hard-code knowledge of the physical design of the laptop and motherboard. This firmware code tells the audio chip explicit details such as the size and colour of each physical audio jack in the laptop. The operating system can later query the chip for this information and present it to a user, for example in an audio mixer application.

porta  config(  1/8" green left hp-out jack     )config
porta  config(  1/8" green left hp-out jack     )config
portb  config(  1/8" pink left mic-in jack      )config
portc  config(  builtin internal top mic-in no-detect other-analog )config
portd  config(  unused line-out no-detect       )config
porte  config(  unused line-out no-detect       )config
portf  config(  unused line-out no-detect       )config
portg  config(  builtin internal front speaker no-detect other-analog )config
porth  config(  unused line-out no-detect       )config
porti  config(  unused line-out no-detect       )config
portj  config(  unused line-out no-detect       )config
portk  config(  unused line-out no-detect       )config

The code reads a bit like english - 1/8" pink left mic-in jack - but is actually purely imperative Forth code. Inspired by Thinking Forth.

Sometimes it's fun and okay to be a little cute :-)

@dyokomizo
Copy link

Forth solutions are some of the cleanest when you manage to create the right set of words.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment