Brainfuck compiler and VM

A place where you can keep others updated about your NES-related projects through screenshots, videos or information in general.

Moderator: Moderators

Post Reply
yaros
Posts: 145
Joined: Tue Aug 28, 2018 8:54 am
Location: Edmonton, Canada

Brainfuck compiler and VM

Post by yaros » Tue Feb 12, 2019 12:07 pm

Image

Why? Why not. Use this awesome language to write your subroutines, when you feel that assembler is too difficult to master.

* uses 8 bit memory cells
* input is supported but limited

Source is here: https://github.com/veremenko-y/nes-brainfuck

Code: Select all

; Hello World
BF_run:
BF_compile "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."
jsr BF_run
Result:

Image

Code: Select all

; Factorial
BF_run:
BF_compile "+++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++>++++++>>+<<[>++++++++++++++++++++++++++++++++++++++++++++++++.------------------------------------------------<<<<.-.>.<.+>>>>>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[<+>-]>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<.>>+>[>>+<<-]>>[<<<[>+>+<<-]>>[<<+>>-]>-]<<<<-]"
jsr BF_run
Result:

Image

Edit: Updated version with fixed screen glitch
Attachments
game.nes
(40.02 KiB) Downloaded 209 times
Last edited by yaros on Fri Feb 15, 2019 9:25 pm, edited 4 times in total.

yaros
Posts: 145
Joined: Tue Aug 28, 2018 8:54 am
Location: Edmonton, Canada

Re: Brainfuck compiler using ca65 macroses

Post by yaros » Tue Feb 12, 2019 3:54 pm

Now with bottles of beer =) "Compiled version" is 6647 bytes...
Attachments
bottles of beer.png
bottles of beer.png (5.69 KiB) Viewed 4895 times

yaros
Posts: 145
Joined: Tue Aug 28, 2018 8:54 am
Location: Edmonton, Canada

Re: Brainfuck compiler using ca65 macroses

Post by yaros » Fri Feb 15, 2019 7:28 pm

Too bad, ca65 macroses are too slow to be useful (I should say abused). As soon as I started doing small optimizations, execution time decreased dramatically, so I rewrote compiler to C#.

I also changed compilation from jsr opcode to opcodes with jumptable to save space. It runs slower, but now it can actually run "Adv" - text adventure by Jon Ripley (http://jonripley.com/brainfuck/games/adv.html).

Controls:
left, right, up, down = west, east, north, south
select = down
start = up
a = look
b = inventory
Attachments
game.nes
(40.02 KiB) Downloaded 208 times
adv.png
adv.png (4.98 KiB) Viewed 4782 times

Post Reply