Giter Club home page Giter Club logo

bfgame's Introduction

SPEC!

bfgame is a brainfuck game engine (yes, seriously). This is its spec.

Memory (a.k.a. "tape")

bfgame's memory space consists of a 'tape' with infinite cells, and a pointer, which you can move with the < and > operators.

In bfgame, each cell can hold an arbitrarily large integer.

The first five cells are reserved for the FFI.

Instructions

bfgame has 8 instructions. The print(.) and input(,) operators have different functionalities than those in brainfuck:

. Run the currently selected function
, Get the next event from the event queue. If there are no events, this will be return 0.
+ Increment the current cell's value by 1
- Decrease the current cell's value by 1
> Move pointer to next cell
< Move pointer to previous cell (won't do anything if in cell #0)
[ Jump past the matching ] if the cell under the pointer is 0 
] Jump back to the matching [ if the cell under the pointer is nonzero

Any other characters will be ignored by the interpreter, acting like comments.

FFI

To call external functions, you'll use the first 5 'tape' cells. Here's what each of them is used for:

0: Module ID - When you select a module, its functions become available
1: Function ID to call
2: Pointer to beginning of args - This should point to a cell which will be the first one in the functions arguments list. If there are no args, this should be 0.
3: Pointer to ending of args - If there are no args, this should be 0. If there is only one arg, it should be the same as #2.
4: Returned value - If a function returns a value, it'll go here.

Now, let's say we want to print the string "A" (ASCII codes 65). The function for this is function 1, and it's in the IO module (ID 1). It takes a list of any length and prints it, returning 0.

Example: Printing "A"

+     Load the IO module
>     Move forward to cell #1
+     Add 1 to its value so it's now 1
>     Move to cell #2
+++++ Add 5 to its value so it points to cell #5 which is where our string will start.
>     Move to cell #3
+++++ Add 5 to its value which is where our string will end
>>> Move to cell #6 our loop counter
++++++ Set the loop counter to 6
[
    <++++++++++ Go back to cell #5 and add 10
    >-          Go back to cell #6 and subtract 1
]
<+++++ Go back to cell #5 and add 5 so it's 65
<<<<. Go back to cell #1 and print it to run the function

Easy, right? :D

bfgame's People

Contributors

pta2002 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.