Brainf#ck interpreter

brainf-ck.hex (32.0 KB)

As first finished project I made interactive Brainf#ck interpreter.

Repo:

Releases (.hex files):

Current version has:

  • 512 characters of program memory
  • 256 characters of data memory
  • 40 characters of input
  • 40 characters of output
  • NO overflow check.

Standard version is shipped with Hello World demo program.
To run it use A, B, RIGHT.
To upload custom program from Serial first send program and second select READ from menu.

Controls

A - start
B - menu

Blue mode - navigation

ARROWS - movement

White mode - typing

UP/DOWN - command selection
LEFT - delete
RIGHT - insert

Yellow mode - execution

A+B - abort execution

Red mode - user input

UP/DOWN - select input value

Menu mode

UP - run program
DOWN - save to EEPROM
LEFT - read data waiting on serial, overwrite
RIGHT - write program to serial

8 Likes

Dear lord. I always wondered if someone would do this.

You win the prize, it is… a brain :brain: but it seems like you may already be full in that department considering the wizardy required to pull this off.

Nice.

1 Like

I’m surprised nobody has done this already.
(I know we’ve got a Chip8 processor somewhere.)
It certainly works at least. Sadly I can’t find my folder of brainfuck programs.

My one feature request would be to make holding either A or B cause the program to be executed faster (e.g. 128-256 steps per frame).


A few tips.

Instead of char you should use either signed char/int8_t or unsigned char/uint8_t because char's signedness is implementation defined and the signedness is probably important here.

Also arduboy.begin() already calls arduboy.clear() so you don’t need to call it again so soon.

And you might want to read into constexpr and scoped enumerations (a.k.a. enum class).

1 Like

Cool! is Brainboy the name of the interpreter? or just brainf#ck interpreter?

I added it to https://arduboy.ried.cl/ (but it does not work in @FManga emu)

I started this project as Brainboy, and, to be franc, I don’t care hot to name it.
I think I should add MIT licence, by the way.

1 Like

Yes

1 Like

Changed MIT license. Am planning update for fast-forward execution with respect to user input.

1 Like

Looks like it does now. Unfortunately RGB led is not displayed, thus it is hard to understand in which mode you are currently. Also can not press A+B to abort execution.

Done.

I think you should also put a .hex in the GitHub releases so you can link to the releases in the main post,
and then people who like to just have the .hex file to upload can easily access the .hex files for different versions.

(Personally I prefer to compile from source, but I know there are a lot of people who like to just use .hex files and/or .arduboy files.)

The documentation says:

You can play by touching the buttons, if you have a touchscreen. If your device has a keyboard, use the arrow keys and Ctrl/A/Z for button A and Alt/B/S/X for button B. Joysticks/pads are also supported, if your browser supports the gamepad API.

I just tested with A+X and it worked on Chrome.

I think @FManga didn’t bother emulating the LED because not many games use the LED.
(I’m just guessing though.)

That’s true, though it does emulate the LED if you don’t use PWM (this game does).

1 Like

I always forget which set of LED functions are the PWM set and which are the other (presumably analogue output) set.

digitalWriteRGB = digital (full on / off only)

setRGBled = PWM adjustable brightness

Added hex and fast-forward.

1 Like

Hello!

I am happy some one has done it. I asked sometime ago here for it actually. Thanks for sharing.

1 Like

Yes, this day had to come :slight_smile: But brainfu*k is only the beginning! It is the assembly of esoteric languages.

Here is how anyone can continue this endeavor:

https://esolangs.org/wiki/Category:Brainfuck_derivatives