Mycelium

From Esolang
Jump to navigation Jump to search

Mycelium is an image-based esoteric programming language designed by Lode Vandevenne in 2005. The commands are read from a png image. There is some freedom in the colors you can give a pixel to get a certain command, so it's possible to create an image out of commands or encode the commands in a photo.

Mycelium has both memory and a stack. Stack and Memory are of arbitrary size and consist out of signed integers of at least 32 bits. There is also a gosub stack used to remember where to return to. It remembers the location and direction of the instruction pointer.

Commands

Every command is an RGB pixel with 8 bit per color channel. R % 16 (R modulo 16) selects the command or group of commands, G and B select the behaviour, the actual command or data. For some commands, G and B are unused and may be anything.

  • IP = Instruction Pointer (x, y, direction)
  • MP = Memory Pointer
  • *MP = Memory value the MP is pointing at
R % 16 Description
0 NOP
1 Set IP direction (B % 4 selects direction: e, s, w, n)
2 Jump over next 256 * G + B pixels
3 If popped value is 0, jump over next 256 * G + B pixels
4 Translocation command (B % 8 selects: goto, gosub, return, relative goto, relative gosub)
5 Memory command (B % 8 selects: set *MP, set *MP, get MP, set MP, MP++, MP--)
6 Set code pixel color channel (self modifying)
7 Get code pixel color channel
8 Push constant: 256 * G + B.
9 Push two constants: G and B
10 Stack commands (B % 4 selects: pop, dup, swap, dup2)
11 Math commands (B % 32 selects: +, -, *, /, %, |, &, ^, ~, >>, <<, ==, !=, >, <, >=, <=, &&, ||, !)
12 I/O commands (B % 4 selects: print char, get char, print integer)

Other values result in undefined behavior.

External resources