Skip to content
lolbot-iichan edited this page Jan 14, 2018 · 9 revisions

Welcome to the lolbot-iichan's TIC-80 fork wiki!

This fork introduces Brainfuck language scripting for TIC-80 fantasy console.

Brainfuck specification and API bindings:

There are some things specific to current implementation of Brainfuck in TIC-80.

Memory is looped, there are 65536 16-bit memory cells accessible with < and > operations

# can be used used to comment out any text until the line break, even including brainfuck commands (e.g. >#> is an equivalent of >). However, you can write comments without # mark as long as they don't have any punctuation ^_~

There are 9 commands:

  • < and >, [ and ], + and - works as usual
  • . appends current cell value to a memory buffer, not to interpreter's console as usual
  • , calls API function with that buffer (first value - id# of API function, other values - params) and stores result in current cell(s)
  • ? prints a trace with current cell id# (0~65535) and value

Another important Brainfuck extention is macros support:

  • Macros are used for code substitution, not function calls!
  • Define macro NAME with /NAME/<code>/. Macro name can contain any characters except / and \.
  • Use macro NAME with \NAME\. You can use macros inside other macros, but loops are prohibited
  • Built-in macros for API functions are pushing API fuction id# and resetting current cell (e.g. \cls\ is an equivalent of [-]++++.[-])
  • API macros don't call API functions, , is used to call an API function (e.g. use \cls\, & \btn\++., for calling cls() & btn(2))

Execution rules:

  • code outside of macro definitions is executed once, before game starts, all cells are zeroed before it's run
  • code MUST contain TIC macro, which is executed 60 times per second, cell #0 is zeroed before it's run
  • code MAY contain scanline macro, which is executed 136*60 times per second, cell #0 is set to scan line's number before it's run
  • code MAY contain OVR macro, which is executed 60 times per second, cell #0 is zeroed before it's run

API-specific details:

TIC-80's font, print and trace API functions reqiered strings as first argument.

  • Brainfuck version of those APIs require string length as first argument followed by given amount of arguments considered string bytes (e.g. \trace\+++.++++++++++++++++++++++++++++++.++.+., is tracing "!#$" string).
  • If string length is 0, then next argument is used for "%d" sprintf (e.g. \trace\.++++++++++++., is tracing "12" string)

Some TIC-80's API functions are not returning any values. In this case memory cells are left as is.

  • mouse API function currently writes result (x,y,lmb,mmb,rmb) to 5 (five!) memory cells
  • time API function currently writes result (sec,msec) to 2 memory cells

pmem API function uses int16 memory cells, not int32 as in usual TIC80's API

Brainfuck samples:

There are some API demos similar to <API> DEMO / <LANG> samples from TIC-80's Demos section

Run them, hit ESC & select "Exit to TIC-80" to read the source code. Download cartridges from here.