Talk:2DFuck

From Esolang
Jump to navigation Jump to search

Befunge-96 interpreter

The following is my Befunge-96 interpreter I made with MTFI shortly after uncovering the official spec from archive.org. It does not support the "l" or "?" command. It can only currently be run with MTFI (which can be found here or here).

; ---------------------------------------------------------------
; | - This is a 2DF*** implementation in Befunge-96,            |
; |   the most forgotten version of Befunge.                    |
; | - By BoundedBeans/Kronosta                                  |
; | - I have absolutely every reason to copyright this          |
; |   (this took me hours for just one error alone)             |
; |   but please enjoy Public Domain use of this ugly program!  |
; |-------------------------------------------------------------|
; |=======================INVOCATION============================|
; | - mtfi -6 2dfuck.befunge-96                                 |
; | - No command-line parameters are accepted since Befunge-96  |
; |   can't deal with them.                                     |
; | - Instead, the input is used.                               |
; |   - The first line shall be "1" if tracing is desired,      |
; |     otherwise "0".                                          |
; |   - The second line shall be the 2DFuck program.            |
; |   - The third line shall be the input to the 2DFuck program,|
; |     as a sequence of "1"s and "0"s.                         |
; |     - Other bytes are treated as byte & 0x01                |
; |-------------------------------------------------------------|
; |======================LIMITATIONS============================|
; | - The "l" game of life command is not included.             |
; | - Loop brackets are not traced (the statements inside are). |
; | - A 2DFuck program is guaranteed 32767 bits down and right  |
; |   by the Befunge-96 specification.                          |
; | - The program has almost that many bits up and left, but may|
; |   cut into/corrupt this interpreter if going really close   |
; |   to the top left corner.                                   |
; |-------------------------------------------------------------|
; |========================TRACING==============================|
; | - Tracing is pretty barebones                               |
; | - Prints "Trace: Store pointer X&Y, store trace on" before  |
; |   executing the program                                     |
; | - For the commands !,.<>rvx, prints "C"(Command)            |
; |   - The commands []^T don't do this                         |
; |-------------------------------------------------------------|
; |======================EXTENSIONS=============================|
; | - The only extension is the T command, which prints the     |
; |   current cell as a decimal number.                         |
; |   - This is useful because uninitialized values start out   |
; |     with 32, allowing you an extra printing character       |
; |     sequence and a way of diagnosing problems with this     |
; |     interpreter.                                            |
; ---------------------------------------------------------------
; Hexadecimal digit definitions
;$C a 10
;$C b 11
;$C c 12
;$C d 13
;$C e 14
;$C f 15
; Y=0 -- Ask the user if they want to enable trace mode
" ?ecarT",,,,,,,&a,v
; Y=1 X=*   -- Store trace? 32768 32768 on the stack
 v>v j3:*8**::+1f$~<
; Y=2 X=0,1 -- Store 2DF*** pointer x (default 32768) in 0 2
; Y=2 X=2,3 -- Testing trace
; Y=2 X=1   -- Later self-modified to be the code pointer
 }3
; Y=3 X=0,1 -- Store 2DF*** pointer y (default 32768) in 0 3
; Y=3 X=2,3 -- Testing trace
; Y=3 X=1   -- Later self-modified to be the accumulator
 }0-
; Y=4 X=0,1 -- Store trace boolean in 0 4
; Y=4 X=2,3 -- Testing trace
; Y=4 X=5,- -- Printing trace
 }0G >0a"no ecart erots ,Y&X retniop erotS :ecarT">:#,_013pv
; Y=4 X=1,6 -- Testing trace
                                                       v   <
 >^>#^_013p                                          2j>$012pv
; Y=5,9 X=* -- Getting a line of input into y=0 (null-terminated)
                                                   v<
                                    p21  +1g21p0g21<|!!-a  :~<   <  
                       v                 p210p0g210$<
; Y=10,11 X=* -- If the line is empty, quit, otherwise go
;              into the following labyrinth of codes based on the first character
                       v                                p21+1g21  <
v   -*b3g0g21    _@#g00<                                >12g1+  0g|
j                                                                 >@
; Y=12 X=*  -- The labyrinth of commands
>13g1+2%13p          104g-6*j"!C",,                     ^!
>                                                       ^"
>                                                       ^#
>                                                       ^$
>                                                       ^%
>                                                       ^&
>                                                       ^'
>                                                       ^(
>                                                       ^)
>                                                       ^*
>                                                       ^+
>~2%13p              104g-6*j",C",,                     ^,
>                                                       ^-
>13gc4*+,            104g-6*j".C",,                     ^.
>                                                       ^/
>                                                       ^0
>                                                       ^1
>                                                       ^2
>                                                       ^3
>                                                       ^4
>                                                       ^5
>                                                       ^6
>                                                       ^7
>                                                       ^8
>                                                       ^9
>                                                       ^:
>                                                       ^;
>02g1-02p            104g-6*j"<C",,                     ^<
>                                                       ^=
>02g1+02p            104g-6*j">C",,                     ^>      
>                                                       ^? [Debug command not implemented, try using T instead]
>                                                       ^@
>                                                       ^A
>                                                       ^B
>                                                       ^C
>                                                       ^D
>                                                       ^E
>                                                       ^F
>                                                       ^G
>                                                       ^H
>                                                       ^I
>                                                       ^J
>                                                       ^K
>                                                       ^L
>                                                       ^M
>                                                       ^N
>                                                       ^O
>                                                       ^P
>                                                       ^Q
>                                                       ^R
>                                                       ^S
>02g03gg.                                               ^T
>>                                                      ^U
>                                                       ^V
>^          >12g1+12p12g0g'[-#v_1+v                     ^W
>^                            >    12g0g']-#v_1-v       ^X
>^                                                      ^Y
>^       <  ^              _v#:<  <         <   <       ^Z
>13g    #^_1^               >                           ^[
>                                                       ^\
>113g      #v_$                                         ^]                 
>03g1-03pv  >12g1-12p12g0g']-#v_1+v                     ^^
>v       <                    >    12g0g'[-#v_1-v       ^_
>v                                                      ^`
>v          ^              _v#:<  <         <   <       ^a
>v                          >                           ^b
>>                                                      ^c
>                                                       ^d
>                                                       ^e
>                                                       ^f
>                                                       ^g
>                                                       ^h
>                                                       ^i
>                                                       ^j
>                                                       ^k
>                                                       ^l [Game of life command unsupported]
>                                                       ^m
>                                                       ^n
>                                                       ^o
>                                                       ^p
>                                                       ^q
>02g03gg2%13p       104g-6*j"rC",,                      ^r
>                                                       ^s
>                                                       ^t
>                                                       ^u
>03g1+03p           104g-6*j"vC",,                      ^v
>                                                       ^w
>02g03gg13g+2%02g03gp   104g-6*j"xC",,                  ^x
>                                                       ^y
>                                                       ^z

BoundedBeans (talk) 03:11, 11 May 2024 (UTC)

If this gives an error when run with MTFI, try removing carriage returns from it (such as with sed 's/\r//g' filename -i_backup). BoundedBeans (talk) 03:14, 11 May 2024 (UTC)
Note that the Y values listed in the comments changed a lot during development and are not correct in this source code. BoundedBeans (talk) 03:18, 11 May 2024 (UTC)