A downloadable tool

Brainfuck interpreter 

A BASIC 10-Liner for the Sharp PC-1211 Pocket Computer

by aldweb

[BASIC 10Liner 2026] [SCHAU] [PUR-80]


Submission:

15th Edition of the BASIC 10 Liner Contest – "SCHAU" Category

Author:

Laurent Duveau (aldweb)

Coded for fun in 2026

License: Copyleft (attribution appreciated)


System Requirements:

Compatible with Sharp PC-1210, PC-1211, PC-1212, and Radio Shack Pocket Computers

Language:

S'-BASIC (Sharp Pocket Computer BASIC)

More Information:

Sharp PC-1211 Details & Articles

https://www.aldweb.com/articles.php?lng=en&pg=26


The challenge: Brainfuck on a 1980 Pocket Computer

==================================================

In March 1980, Sharp released the PC-1211—the world's first pocket computer. Its specs? 26 variables (A-Z, A$-Z$), 1,424 program steps (1.39 KB total memory), and 178 single-dimension array slots shared between data and code. It ran S'-BASIC, a stripped-down, interpreted dialect with no frills.

So, what is the challenge?

Could I fit a fully functional Brainfuck interpreter—an esoteric language with 8 distinct commands—into this tiny, 40-year-old machine?

Could I do it in 10 lines of BASIC, each under 80 characters, for the BASIC 10Liner Contest?

Spoiler: Yes.

This project pushes the limits of vintage computing, turning constraints into creativity. Welcome to Brainfuck on a pocket calculator!


Brainfuck interpreter

=====================

What is Brainfuck?

Brainfuck is an esoteric programming language created in 1993 by Swiss student Urban Müller. Its design is intentionally minimalistic: only eight commands, a memory pointer, and an instruction pointer. Despite its simplicity, Brainfuck is Turing-complete, meaning it can theoretically solve any computable problem. However, it is not meant for practical use — it is a challenge for programmers, designed to amuse and test their skills.

How Brainfuck works:

A Brainfuck program manipulates an array of memory cells, each initially set to zero. The language uses a movable pointer to navigate and modify these cells. In this PC-1211 implementation, each cell is an 8-bit unsigned integer (range: 0–255). Overflow and underflow are handled:

- Incrementing above 255 wraps around to 0.

- Decrementing below 0 wraps around to 255.

Brainfuck commands:

The language consists of eight single-character commands:

>       Move the pointer to the next cell

<       Move the pointer to the previous cell

+       Increment the current cell's value

-       Decrement the current cell's value

.       Output the number corresponding to the current cell's value

,       Input a number and store it in the current cell

[       Jump past the matching ] if the current cell's value is zero

]       Jump back to the matching [ if the current cell's value is nonzero

{eof}   Stop execution

PC-1211 adaptation:

Since the Sharp PC-1211 cannot handle characters directly, Brainfuck commands are translated into numeric codes:

>       1

<       2

+       3

-       4

.       5

,       6

[       7

]       8

{eof}   0

A word of warning:

Brainfuck programs are notoriously difficult to read. Even simple tasks require long sequences of commands. This complexity is exactly why the language earned its name - Brainfuck - because it challenges your brain in unexpected ways!


Listing

=======

chr tkn   Basic code

[65](52)  1:T=27:U=71:V=79:FOR X=U TO V:A(X)=0:NEXT X:X=U:Y=T:W=0:S=0:USING
[76](67)  2:Q=(A(Y)=1)-(A(Y)=2):IF A(Y)=0 PRINT "P(";Y;")=";A(Y);" D(";X;")=";A(X):END
[72](72)  3:P=Y:X=X+(S=0)*Q:Q=A(X)+(S=0)*((A(Y)=3)-(A(Y)=4)):A(X)=(Q>=0)*(Q<256)*Q
[77](66)  4:A(X)=A(X)+(Q>255)*(Q-256)+(Q<0)*(Q+256):IF (S=0)*(A(Y)=5) BEEP 1:PRINT A(X)
[76](51)  5:IF (S=0)*(A(Y)=6) BEEP 1:INPUT R:A(X)=INT R:IF (R<0)+(R>255) BEEP 2:GOTO 5
[49](44)  6:IF A(Y)=7 LET W=W+1:A(W)=Y:S=S+(S=0)*W*(A(X)=0)
[61](55)  7:IF (S=0)*(A(Y)=8) LET Y=(A(W)-1)*(A(X)<>0)+Y*(A(X)=0):W=W-1
[41](34)  8:IF (S<>0)*(A(Y)=8) LET S=S*(W<>S):W=W-1
[64](58)  9:Y=Y+1:IF (Y<T)+(Y>=U)+(X<U)+(X>V)+(W<0)+(W>6) LET Y=U-1:A(Y)=0
[50](41)  10:PAUSE "P(";P;")=";A(P);" D(";X;")=";A(X):GOTO 2

Code metrics:

- Total characters: [631] (including spaces for readability)

- Tokenized size:   (540) 8-bit memory cells

- Constraints met:  all 10 lines adhere to the <80 characters limit for the PUR-80 category.

Important: setup instructions for the interpreter

This program is a Brainfuck interpreter for the Sharp PC-1211. To run it, you must first load your Brainfuck source code into the PC-1211's memory (see instructions below).

Before execution, you need to manually set the first three variables in line 1 of the program:

T: Pointer to the first command of your Brainfuck source code.

U: Pointer to the first memory cell used by the interpreter.

V: Pointer to the last memory cell allocated for the interpreter.

These variables define the memory layout and execution range of your Brainfuck program. Make sure they match the location of your source code in memory.


Uploading and running Brainfuck programs on the Sharp PC-1211

=============================================================

To simplify the process of loading Brainfuck programs into the PC-1211's memory, you can use the following predefined routines to automatically populate the Brainfuck source code. These routines are designed to be called as the first instruction in your program:

Option 1: load the "addition" program

Call GOSUB 11 as the first instruction to load a Brainfuck program that performs addition.

  1:GOSUB 11:FOR X=U TO V:A(X)=0:NEXT X:X=U:Y=T:W=0:S=0:USING
  11:REM *ADD*
  12:A(27)=6:A(28)=1
  13:A(29)=6:A(30)=7
  14:A(31)=2:A(32)=3
  15:A(33)=1:A(34)=4
  16:A(35)=8:A(36)=2
  17:A(37)=5:A(38)=0
  18:T=27:U=39:V=40
  19:BEEP 1:PRINT "ADD 2 NUMBERS":RETURN

Memory usage:

- Brainfuck commands: 14 cells (from A(27) to A(38))

- Memory cells: 2 cells (from A(39) to A(40))

Option 2: load the "multiplication" program

Call GOSUB 21 as the first instruction to load a Brainfuck program that performs multiplication.

  1:GOSUB 21:FOR X=U TO V:A(X)=0:NEXT X:X=U:Y=T:W=0:S=0:USING
  21:REM *MUL*
  22:A(27=6:A(28)=1
  23:A(29))=6:A(30)=2
  24:A(31)=7:A(32)=1
  25:A(33)=7:A(34)=4
  26:A(35)=1:A(36)=3
  27:A(37)=1:A(38)=3
  28:A(39)=2:A(40)=2
  29:A(41)=8:A(42)=1
  30:A(43)=1:A(44)=7
  31:A(45)=4:A(46)=2
  32:A(47)=2:A(48)=3
  33:A(49)=1:A(50)=1
  34:A(51)=8:A(52)=2
  35:A(53)=2:A(54)=2
  36:A(55)=4:A(56)=8
  37:A(57)=1:A(58)=1
  38:A(59)=5:A(60)=0
  39:T=27:U=61:V=64
  40:BEEP 1:PRINT "MULTIPLY 2 NUMBERS":RETURN

Memory usage:

- Brainfuck commands: 38 cells (from A(27) to A(60))

- Memory cells: 4 cells (from A(61) to A(64))

Memory availability:

If you use the 10-line interpreter alone and manually populate the Brainfuck commands, you have 110 memory cells available for your Brainfuck program and data.

If you use the predefined routines (GOSUB 11 or GOSUB 21), you will have 52 memory cells available, which is still sufficient for most Brainfuck programs.

Note:

The decoding and explanation of these sample Brainfuck programs (addition and multiplication) are provided later in this guide.


Executing the Brainfuck interpreter

===================================

Real-time execution feedback:

While the interpreter runs, it provides real-time status updates after each command. For example: P(27.)=6. D(39.)=1.

- P(27.)=6: The program pointer is at cell 27, executing command 6 (input).

- D(39.)=1: The data pointer is at cell 39, with a current value of 1.

This feedback helps you track execution flow and debug your Brainfuck programs.

User input for sample programs:

For the preloaded sample programs (addition and multiplication), the interpreter will prompt you twice (with a ?) to enter an integer between 0 and 255:

- The addition program will return the sum of the two numbers.

- The multiplication program will return their product.

Performance note:

The Sharp PC-1211 is extremely slow by modern standards. For the multiplication program, which uses successive additions, we strongly recommend using single-digit inputs (e.g., 2 × 3). Larger values will result in very long computation times—patience will be required!

Tip: start with small numbers to test the interpreter efficiently. ;-)



Coding challenges on the Sharp PC-1211

======================================

A pioneer in pocket computing:

The Sharp PC-1211, released in 1980, was the first pocket computer programmable in BASIC, using S'-BASIC (S-prime BASIC). While it featured two 4-bit processors, its successor, the Sharp PC-1251 (1983), and later models adopted a full 8-bit architecture. Despite this, the code submitted here is fully compatible with the PC-1251 and other Sharp Pocket Computers, requiring no modifications.

Both the PC-1211 and PC-1251 share the same 24-character display, making them ideal for retro programming challenges.

S'-BASIC: efficiency in minimalism!

- Single-byte tokenization: every BASIC command, function, and operator is stored as a single-byte token, including the entire character set (uppercase only).

- Memory optimization: commands occupy only one memory cell, equivalent to one character. However, all lines in this submission remain under 80 characters, even without strict accounting.

Unique constraints of S'-BASIC:

No ELSE in IF statements

- The IF instruction lacks an ELSE feature. If the condition is true, the rest of the line executes; if false, execution jumps to the next line.

Workaround: Use IF as the last instruction in a line or rely on Boolean calculations to handle conditional logic.

Limited INPUT Instruction

- The INPUT instruction only accepts void entries if it is the last command in a line, which is restrictive in a 10-line contest.

Variable speed

- Variables W to Z execute faster and are ideal for FOR/NEXT loops and frequent calculations.

Dual variable mapping

- A(1) to A(26) map directly to variables A to Z. For example, A(3) and C store the same value. This allows the use of single-letter variables for simplicity, reserving A() arrays for bulk calculations or data transfers.

Implicit Multiplication

- The multiplication sign (*) can often be omitted. For example: ZT is equivalent to Z*T and 221Z is equivalent to 221*Z.

- Exception: I*F (calculation) is different from IF (keyword).

No pseudo-random function

- Randomness must be simulated in code.

Limited User Input

- No INKEY$ function—only basic INPUT is available, limiting interactivity.

Performance considerations:

Execution Speed: The real Sharp PC-1211 is extremely slow by modern standards. However, emulators like PokecomGO (PC-1251) and the PC-1211 simulator offer significantly faster execution, making them ideal for testing and gameplay.

Why this matters for the 10-Liner contest

Coding for the Sharp PC-1211 is a test of creativity and optimization. The constraints of S'-BASIC—limited memory, no ELSE, and slow execution—push programmers to innovate within tight boundaries. This submission is a perfect example of how to maximize functionality in minimal space!


Sample Brainfuck programs source code explained

===============================================

Addition Program

Objective: add two numbers entered by the user.

Memory layout:

- A(27) to A(38): Brainfuck commands.

- A(39): n1 (first input, result).

- A(40): n2 (second input).

Step-by-Step Execution:

Address  Command  Action

A(27)    6        input number and store in n1

A(28)    1        move to n2

A(29)    6        input number and store in n2

A(30)    7        start loop if n2<>0

A(31)    2          move to n1

A(32)    3          increment n1

A(33)    1          move to n2

A(34)    4          decrement n2

A(35)    8        end loop if n2=0

A(36)    2        move to n1

A(37)    5        display n1 (result)

A(38)    0        end of program

Equivalent Brainfuck code: ,>,[<+>-]<.

Multiplication Program

Objective: multiply two numbers using successive addition.

Memory layout:

- A(27) to A(60): Brainfuck commands.

- A(61): n1 (first input).

- A(62): n2 (second input).

- A(63): n3 (result).

- A(64): n4 (temporary storage).

Step-by-Step Execution:

Address  Command  Action

A(27)    6        input number and store in n1

A(28)    1        move to n2

A(29)    6        input number and store in n2

A(30)    2        move to n1

A(31)    7        start main loop if n1<>0

A(32)    1          move to n2

A(33)    7          start loop if n2<>0

A(34)    4            decrement n2

A(35)    1            move to n3

A(36)    3            increment n3

A(37)    1            move to n4

A(38)    3            increment n4

A(39)    2            move to n3

A(40)    2            move to n2

A(41)    8          end loop if n2=0

A(42)    1          move to n3

A(43)    1          move to n4

A(44)    7          start loop if n4<>0

A(45)    4            decrement n4

A(46)    2            move to n3

A(47)    2            move to n2

A(48)    3            increment n2

A(49)    1            move to n3

A(50)    1            move to n4

A(51)    8          end loop if n4=0

A(52)    2          move to n3

A(53)    2          move to n2

A(54)    2          move to n1

A(55)    4          decrement n1

A(56)    8        end main loop if n1=0

A(57)    1        move to n2

A(58)    1        move to n3

A(59)    5        display n3 (result)

A(60)    0        end of program

Equivalent Brainfuck code: ,>,<[>[->+>+<<]>>[-<<+>>]<<<-]>>.

These examples illustrate how Brainfuck's minimalist commands can perform arithmetic operations, even on a 40-year-old pocket computer! Want to explore more complex programs? :-)


Variables

=========

A-F   Loop stack (manages nested loops in Brainfuck)

G-O   (Unused)

P     Program pointer (points to the currently executed command)

Q     Temporary value (used for intermediate calculations)

R     Input value (stores user input)

S     Stack exit (marks the end of the loop stack)

T     Initial program pointer (starting address of the Brainfuck code)

U     Minimum data pointer (start of the data memory block)

V     Maximum data pointer (end of the data memory block)

W*    Stack pointer (tracks the current position in the loop stack)

X*    Data pointer (initially used for memory setup, then repurposed)

Y*    Program pointer (alternative to P for flexibility)

Z*    (Unused) Reserved (preserved for random number generation in my other programs)

Key:

* = Optimized for speed (used in loops or frequent calculations)


Code listing and explanations

=============================

Line 1: Initialization

1:T=27:U=71:V=79:FOR X=U TO V:A(X)=0:NEXT X:X=U:Y=T:W=0:S=0:USING

Purpose: Sets up the interpreter environment.

Actions:

- Initializes program, data, and stack pointers.

- Resets all data cells to zero.

- Configures the numeric display format.


Line 2: Main loop start & command parsing

2:Q=(A(Y)=1)-(A(Y)=2):IF A(Y)=0 PRINT "P(";Y;")=";A(Y);" D(";X;")=";A(X):END

Purpose: Begins the main execution loop and processes pointer movement commands (> and <).

Key Logic:

- Uses Q as a temporary variable to split calculations across lines (to comply with the PUR-80 80-character limit).

- Determines if the current command (stored in A(Y)) is > (1) or < (2) to adjust the data pointer.

- Checks for the end of the program (A(Y) = 0) using a clever IF workaround (due to the lack of ELSE in S'-BASIC).


Line 3: Data pointer & cell value updates

3:P=Y:X=X+(S=0)*Q:Q=A(X)+(S=0)*((A(Y)=3)-(A(Y)=4)):A(X)=(Q>=0)*(Q<256)*Q

Purpose: Updates the data pointer and prepares for cell value modifications (+ and -).

Key Logic:

- Stores the current program pointer (Y) in P (to preserve it for later display).

- Uses S=0 to ensure Brainfuck commands are only processed if not skipping a loop.

- Adjusts the data pointer (X) based on the command (> or <).

- Loads the current cell value (A(X)) into Q and checks if the command is + (3) or - (4).

- Ensures the cell value stays within the 0–255 range.


Line 4: Cell value & output handling

4:A(X)=A(X)+(Q>255)*(Q-256)+(Q<0)*(Q+256):IF (S=0)*(A(Y)=5) BEEP 1:PRINT A(X)

Purpose: Finalizes cell value updates and handles the output command (.).

Key Logic:

- Applies the + or - operation to the cell value (A(X)).

- If the command is . (5), outputs the current cell value.

Line 5: Input command handling


5:IF (S=0)*(A(Y)=6) BEEP 1:INPUT R:A(X)=INT R:IF (R<0)+(R>255) BEEP 2:GOTO 5

Purpose: Manages the input command (,).

Key Logic:

- Prompts the user for input and stores it in the current cell (A(X)).

- Validates the input to ensure it is within the 0–255 range (re-prompts if invalid).

Line 6: Loop start command ([)


6:IF A(Y)=7 LET W=W+1:A(W)=Y:S=S+(S=0)*W*(A(X)=0)

Purpose: Processes the loop start command ([).

Key Logic:

- Pushes the current program pointer onto the loop stack.

- Sets S=0 if the current cell value is non-zero (indicating the loop should execute).

- Sets S=1 if the current cell value is zero (indicating the loop should be skipped).

Line 7: Loop end command (]) – Case 1


7:IF (S=0)*(A(Y)=8) LET Y=(A(W)-1)*(A(X)<>0)+Y*(A(X)=0):W=W-1

Purpose: Handles the loop end command (]) when actively looping (S=0).

Key Logic:

- If the current cell value is non-zero, jumps back to the matching [ by restoring the program pointer from the loop stack.

- Decrements the stack pointer (it will be incremented again in Line 6 during the next loop iteration).

Line 8: Loop end command (]) – Case 2


8:IF (S<>0)*(A(Y)=8) LET S=S*(W<>S):W=W-1

Purpose: Handles the loop end command (]) when skipping the loop (S≠0).

Key Logic:

- Updates the loop stack pointer to reflect that the matching [ has been processed.

- Ensures proper handling of nested loops.


Line 9: Program flow & boundary checks

9:Y=Y+1:IF (Y<T)+(Y>=U)+(X<U)+(X>V)+(W<0)+(W>6) LET Y=U-1:A(Y)=0

Purpose: Advances the program pointer and performs boundary checks.

Key Logic:

- Increments the program pointer (Y) to move to the next command.

- Verifies that all pointers and values are within valid ranges.

- If the end of the program is detected, prepares to stop execution in the next loop iteration.


Line 10: Display & loop back

10:PAUSE "P(";P;")=";A(P);" D(";X;")=";A(X):GOTO 2

Purpose: Displays the current command and data value, then loops back to Line 2.

Key Logic:

- Shows the executed command and current cell value (e.g., P(27.)=6. D(39.)=1.).

- Increments the program pointer (Y) and jumps back to Line 2 to continue execution.

This structure ensures the interpreter efficiently processes all 8 Brainfuck commands while adhering to the 10-line, 80-character limit of the PUR-80 challenge!

Published 11 days ago
StatusReleased
CategoryTool
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
AuthorBASIC 10Liner
Tags10liner, basic, pc-1211, pocket-computer, sharp

Download

Download
29 Brainfuck.zip 2.1 MB
Download
Brainfuck.bas 649 bytes
Download
Brainfuck.txt 22 kB
Download
icone.bmp 22 kB
Download
Pocket80.exe 398 kB
Download
TRS80_x1.bmp 549 kB
Download
TRS80_x2.bmp 2.1 MB

Install instructions

Quick start guide: install & run the Brainfuck interpreter

==========================================================

TL;DR – just the essentials

Download the ZIP file to your Windows PC.

Launch the Pocket80.exe emulator.

Power on the virtual PC-1211 by pressing [ON].

Press the [ON] button.

Right clic anywhere on the simulator window to open the popup menu.

Select [Load RAM (BASIC 10 Liner Contest)].

Choose [Brainfuck emulator (2026)].

Type RUN and press [ENTER].

Enter two numbers (0–255) when prompted by ?.

Wait for the result (addition or multiplication, depending on the loaded program).

Full guide below

(For detailed setup and advanced usage, keep reading!)

Installing the source code

==========================

(Options for running on modern systems)

The Sharp PC-1211 lacks a dedicated emulator due to the unavailability of its processor and ROM specifications. However, you have a few alternatives:

Recommended alternative: custom simulator (Windows only)

In 2019, I began developing a Windows-based simulator for the Sharp PC-1211. While it is not yet finalized, it is functional enough to input and run the provided source code.

For convenience, a preconfigured version of the simulator is provided in this submission, preloaded with the Brainfuck interpreter source code and ready to run.

Alternative: PokecomGO emulator

For Android users, the PokecomGO emulator (running the Sharp PC-1251) is the closest alternative to the Sharp PC-1211.

All source codes designed for the PC-1211 can be executed on the PC-1251 without modification.

Alternative: PockEmul emulator

Windows, macOS, Android, and online versions of PockEmul are available, but note that the software now requires a subscription for activation.

Running the simulator

=====================

Extract the ZIP File:

Unzip the downloaded file to a folder on your Windows computer.

Launch the simulator:

Open the Pocket80sim subdirectory and double-click Pocket80.exe to start the simulator.

Customize your experience:

Right-click on the simulator's main screen to open a popup menu, where you can:

- Resize the window to fit your display.

- View the About section for additional details and credits.

Running the Brainfuck interpreter

=================================

Step-by-Step Execution:

Power on

- Click [ON] to boot the simulator (or the real device). The simulator faithfully replicates the PC-1211's initialization sequence.

Choose source code

- Right clic anywhere on the simulator window to open the popup menu.

- Select [Load RAM (BASIC 10 Liner Contest)].

- Choose [Brainfuck emulator (2026)].

Start the program

- Press the keys R, U, N, then [ENTER] to launch the interpreter.

Input values

- When prompted with ?, enter the first number (0–255).

- At the second ? prompt, enter the second number (0–255).

Wait for the result

- The interpreter will compute and display the result (addition or multiplication, depending on the loaded program).

- Note: The Sharp PC-1211 is slow—patience is key!

Important note on memory

Memory reset: each time you launch the simulator (configured for this contest), the memory is reset to its initial state.

Listing the source code

=======================

Interrupting program execution:

While a program is running, you can pause execution at any time by pressing the [ON] key.

A message like "BREAK AT 4" will appear. Press the [CL] key to clear it.

Switching to program mode:

Press the [MODE] key twice until "PRO" appears in the top-right corner of the screen.

           

Viewing the source code:

Type LIST and press [ENTER], or use the down arrow key (to the right of the [ON] key) to start browsing the code.

Navigating the code:

Use the up/down arrow keys to move between lines.

Use the left arrow key (marked DEL) or right arrow key (marked INS) to navigate within a line.

Experimenting with the simulator:

Feel free to edit or write new code — almost all Sharp PC-1211 BASIC commands are fully functional.

Warning: any changes made will be lost when you close the simulator. The next time you launch it, the original preloaded source code will be restored.

Running the program again:

Switch back to RUN mode : press the [MODE] key until "DEF" or "RUN" appears at the top of the screen.

Execute the code: type RUN and press [ENTER] to restart the program (or any new code you have written).

Leave a comment

Log in with itch.io to leave a comment.