You all know Befunge, right?
Well, now it's time to port it to the Ti-83+ line of calculators! 😁
I'm using Axe 1.2.2 to write this, for the amount of user control and the speed.
It can now let the user see and pick programs, but nothing else.
Source code:

Code:
.BFINTPR
#Axiom(MEMKIT)
DiagnosticOff
ClrHome
ZXmin)
1->X-1->N->A
While X
   If dim()=21 and (dim()^^r^^r=0)
      ZXresL1+A)
      While {L1+A}
         A++
      End
      0->{L1+A}
      A++
      N++
   End
   ZXmax)->X
End
If N
   Text(0,0,"Choose a file.
   0->A
   For(B,7,N*7
      Text(5,B,B/7+48>Char
      Text(9,B,":
      Text(11,B,L1+A
      While {L1+A}
         A++
      End
      A++
      B+6->B
   End
Else
   Text(0,0,"No Files Found!
   Text(0,7,"Press any key to exit.
   getKey
   Repeat getKey
   End
   Return
End
1->K->A-1->B
Repeat K=15 or (K=54)
   getKey->K
   If getKey(1) and (A<N)
      Text(0,A*7,"   
      A++
   End
   If getKey(4) and (A>1)
      Text(0,A*7,"   
      A--
   End
   Text(0,A*7,5>Char
   Pause 250
End
If K=54
   For(A)
      "appv"->Str1
      Copy(L1+B,Str1+1,length(L1+B)+1
      GetCalc(Str1)->P
      While {L1+B}
         B++
      End
      B++
   End
Else
Return
End

Programs are AppVars, and I plan to interpret Befunge-93, as it's easier, and also doesn't have an infinite grid of cells.

Compilation instructions:
Compile using Axe 1.2.2 and the axiom MEMKIT (included in the axe.zip file).

If anyone knows how to make 2000 byte long appvars easily, please leave a post below 🙂
UPDATE:
To make development faster, for the time being I'll just allow users to use one AppVar for programs.
Also, an on-calc editor is on the way. 🙂
Forget the last post... it's rubbish

Anyways, typing 2000 characters by hand on a calculator isn't feasible, so I'm just going to write a convertor in Python using the tivars_lib library. 🙂

Hope this goes well. (I have virtually 0 experience dealing with files in Python) â˜šī¸
Ok, a crude version of the convertor is available here. (Look in the tools folder. It uses the tivars_lib_py libraries)
The generated AppVar is named "UNNAMED" on the calculator, and the input file must be named "hello.bf".
Stay tuned! (3-day break coming soon 😁)
updated the convertor tool to allow naming.
May have some time in a few days.

Code:
.BFINTPR
#Axiom(MEMKIT)
DiagnosticOff
ClrHome
GetCalc("tmpTEMP",2000)->Q
ZXmin)
1->X-1->N->A
While X
   If dim()=21 and (dim()^^r^^r=0)
      ZXresL1+A)
      While {L1+A}
         A++
      End
      0->{L1+A}
      A++
      N++
   End
   ZXmax)->X
End
!If N
   Text(0,0,"No Files Found!
   Text(0,7,"Press any key to exit.
   getKey
   Repeat getKey
   End
   ClrHome
   Return
End
Text(0,0,"Choose a file.
0->A
For(B,7,N*7
   Text(5,B,B/7+48>Char
   Text(9,B,":
   Text(11,B,L1+A
   While {L1+A}
      A++
   End
   A++
   B+6->B
End
1->A-1->B->K
Repeat K=15 or (K=54)
   getKey->K
   If A<N and getKey(1)
      Text(0,A*7,"   "
      A++
   End
   If A>1 and getKey(4)
      Text(0,A*7,"   "
      A--
   End
   Text(0,A*7,5>Char
   Pause 250
End
!If K=54
   ClrHome
   Return
End
For(A)
   "appv"->Str1
   Copy(L1+B,Str1+1,length(L1+B)+1
   GetCalc(Str1->P
   While {L1+B}
      B++
   End
   B++
End
ClrHome
0->S->T->X+1->Y
!If Q
   Disp "Not enough memory!"
   Disp [i]
   Disp "Please delete some files or do a RAM clear"
   Disp [i]
   Disp "Press any key to exit."
   getKey
   Repeat getKey
   End
   ClrHome
   Return
End
Fill(Q,2000,20
For(A,0,length(P
   If {P+A}=10
      0->T
      S++
   Else
      {P+A}->{S*80+T+Q}
   End
   T++
End
Disp "P
Disp P
Pause 2000
ClrHome
Disp "Q
Disp Q
Pause 2000
ClrHome


Added some code to copy the program into a temporary pointer Q, because Befunge is capable of SMC.
It's not fully working, though.
It turns out that I forgot to change CRLF to LF on windows, and CR to LF on Mac, I think. So, again... anyone whose python is good, please help!

Well, here's my solution, is this right?

Code:
from tivars import *
n=input('Please enter Befunge program name: ')
m=input('Please enter output program name: ')
m=m.upper()
my_appvar = TIAppVar(name=m)
my_appvar.archived = False
with open(n,'rb') as f:
  my_appvar.data=(f.read().replace(b"\r\n",b"\n")).replace(b"\r",b"\n")
my_appvar.save(m+".8xv")
Pushed code to main branch here. :)

I will start implementing the actual language once I've debugged it and the program starts putting bytes from P into Q.

EDIT: Bug fixed, turned out to be a missing parentheses grrrrrrr...

Code:
.BFINTPR
#Axiom(MEMKIT)
DiagnosticOff
ClrHome
GetCalc("tmpTEMP",2000)->Q
ZXmin)
1->X-1->N->A
While X
   If dim()=21 and (dim()^^r^^r=0)
      ZXresL1+A)
      While {L1+A}
         A++
      End
      0->{L1+A}
      A++
      N++
   End
   ZXmax)->X
End
!If N
   Text(0,0,"No Files Found!
   Text(0,7,"Press any key to exit.
   getKey
   Repeat getKey
   End
   ClrHome
   Return
End
Text(0,0,"Choose a file.
0->A
For(B,7,N*7
   Text(5,B,B/7+48>Char
   Text(9,B,":
   Text(11,B,L1+A
   While {L1+A}
      A++
   End
   A++
   B+6->B
End
1->A-1->B->K
Repeat K=15 or (K=54)
   getKey->K
   If A<N and getKey(1)
      Text(0,A*7,"   "
      A++
   End
   If A>1 and getKey(4)
      Text(0,A*7,"   "
      A--
   End
   Text(0,A*7,5>Char
   Pause 250
End
!If K=54
   ClrHome
   Return
End
For(A)
   "appv"->Str1
   Copy(L1+B,Str1+1,length(L1+B)+1
   GetCalc(Str1)->P
   While {L1+B}
      B++
   End
   B++
End
ClrHome
0->S->T->X+1->Y
!If Q
   Disp "Not enough memory!"
   Disp [i]
   Disp "Please delete some files or do a RAM clear"
   Disp [i]
   Disp "Press any key to exit."
   getKey
   Repeat getKey
   End
   ClrHome
   Return
End
Fill(Q,2000,32
For(A,0,length(P)-2
   If {P+A}=10
      0->T
      S++
   Else
      {P+A}->{S*80+T+Q}
   End
   T++
End
ClrHome
BIG UPDATE:
Literally wrote most of the engine in 2 hours or so.

Code:
.BFINTPR
#Axiom(MEMKIT)
DiagnosticOff
ClrHome
GetCalc("appvTEMP",2000)->Q
ZXmin)
1->X-1->N->A
While X
   If dim()=21 and (dim()^^r^^r=0)
      ZXresL1+A)
      While {L1+A}
         A++
      End
      0->{L1+A}
      A++
      N++
   End
   ZXmax)->X
End
!If N
   Text(0,0,"No Files Found!
   Text(0,7,"Press any key to exit.
   getKey
   Repeat getKey
   End
   ClrHome
   Return
End
Text(0,0,"Choose a file.
0->A
For(B,7,N*7
   Text(5,B,B/7+48>Char
   Text(9,B,":
   Text(11,B,L1+A
   While {L1+A}
      A++
   End
   A++
   B+6->B
End
1->A-1->B->K
Repeat K=15 or (K=54)
   getKey->K
   If A<N and getKey(1)
      Text(0,A*7,"   "
      A++
   End
   If A>1 and getKey(4)
      Text(0,A*7,"   "
      A--
   End
   Text(0,A*7,5>Char
   Pause 250
End
ClrHome
!If K=54
   Return
End
For(A)
   "appv"->Str1
   Copy(L1+B,Str1+1,length(L1+B)+1
   GetCalc(Str1)->P
   While {L1+B}
      B++
   End
   B++
End
0->S->T->X+1->Y
!If Q
   Text(0,0,"           "
   Text(0,7,"Too little memory!
   Text(0,14,"Please delete some files or
   Text(0,21,"do a RAM clear.
   Text(0,35,"Press any key to exit.
   getKey
   Repeat getKey
   End
   ClrHome
   Return
End
Fill(Q,2000,32
For(A,0,{P-2}^^r-1
   If {P+A}=10
      0->T
      S++
   Else
      {P+A}->{S*80+T+Q}
      T++
   End
End
.Start of befunge interpreter
0->S->T->C->R->A->F->Y+1->X
Repeat {S*80+T+Q}=|E40 or getKey(15)
   {S*80+T+Q}->E
   !If F
      If |E30<=E and (E<=|E39) and (A<768)
         E-32->{L1+A}
         A++
      End
      If E=|E2B and (A>1)
         ({L1+A-1}+{L1+A-2})^256->{L1+A-2}
         A--
      End
      If E=|E2D and (A>1)
         ({L1+A-2}-{L1+A-1})^256->{L1+A-2}
         A--
      End
      If E=|E2A and (A>1)
         ({L1+A-1}*{L1+A-2})^256->{L1+A-2}
         A--
      End
      If E=|E2F and (A>1) and {L1+A-1}
         ({L1+A-2}/{L1+A-1})^256->{L1+A-2}
         A--
      End
      If E=|E25 and (A>1)
         ({L1+A-2}^{L1+A-1})^256->{L1+A-2}
         A--
      End
      If E=|E21 and (A>0)
         ({L1+A-1}=0)->{L1+A-1}
      End
      If E=|E27 and (A>1)
         {L1+A-2}>{L1+A-1}->{L1+A-2}
         A--
      End
      If E=|E3C
         0->Y-1->X
      End
      If E=|E3E
         0->Y+1->X
      End
      If E=|E5E
         0->X-1->Y
      End
      If E=|E76
         0->X+1->Y
      End
      If E=|E3F
         rand^4->B
         !If B
            0->Y-1->X
         End
         If B=1
            0->Y+1->X
         End
         If B=2
            0->X-1->Y
         End
         If B=3
            0->X+1->Y
         End
      End
      If E=|E5F and (A>0)
         If {L1+A-1}
            0->Y-1->X
         Else
            0->Y+1->X
         End
         A--
      End
      If E=|E7C and (A>0)
         If {L1+A-1}
            0->X+1->Y
         Else
            0->X-1->Y
         End
         A--
      End
      If E=|E22
         (F=0)->F
      End
      If E=|E3A and (A<768) and (A>0)
         {L1+A-1}->{L1+A}
         A++
      End
      If E=|E5C and (A>1)
         {L1+A-1}->B
         {L1+A-2}->{L1+A-1}
         B->{L1+A-2}
      End
      If E=|EF2 and (A>0)
         A--
      End
      If E=|E2E and (A>0)
         .Output as integer
         A--
      End
      If E=|E2C and (A>0)
         .Output as char
         A--
      End
      If E=|E23
         S+Y->S
         T+X->T
      End
      If E=|E67 and (A>1)
         If {L1+A-1}<25 and ({L1+A-2}<80)
            {{L1+A-1}*80+{L1+A-2}+Q}->{L1+A-2}
         Else
            0->{L1+A-2}
         End
         A--
      End
      If E=|E70 and (A>2) and ({L1+A-1}<25) and ({L1+A-2}<80)
         {L1+A-3}->{{L1+A-1}*80+{L1+A-2}+Q}
         A-3->A
      End
      If E=|E26 and (A<768)
         .Asks user for an integer
         A++
      End
      If E=|E7E and (A<768)
         .Asks user for a char
         A++
      End
   Else
      If A<768
         E->{L1+A}
         A++
      End
   End
...
   Disp S>Dec
   Disp "
   Disp T>Dec
   Disp "
   Disp E>Char
   Disp [i]
   Pause 1500
...
   S+Y->S
   T+X->T
   If S>65505
      S+25->S
   End
   If S>=25
      S-25->S
   End
   If T>65450
      T+80->T
   End
   If T>=80
      T-80->T
   End
End
Disp "Done"
Pause 500
getKey
Repeat getKey
End
ClrHome


Actually compiles and runs, though input and output not done yet. Also, it's not tested well, so use at your own risk! 😉

Also, there may be some discrepancies between ASCII and the "Large Font Character Map", so gotta fix those too.
Well, a sample program being run:


Things the Interpreter currently supports (tested):
> < v ^ ? _ | " : . , # @

Note: pretty sure a weird edge case happens when the (Befunge) stack is empty.
Source code

Befunge code used:
"!dlroW olleH">:#,_@
Beta testing!

To get started with running this, you'll need to download
a. convertor.py: The convertor for converting .bf to .8xv. You need to install Python 3 and the tivars library. I may upload it somewhere and make it an online tool. (If it's just displaying text, press Ctrl + S)
b. BEFINTR.8xp: The interpreter program.

Steps to run this:
1. Place convertor.py in a directory with some Befunge programs.
2. Run "python convertor.py" and first input the full name of the Befunge program, and then input the name of the Appvar created (No need to enter ".8xv")
3. Send BEFINTR.8xp and the created Appvar to a calculator
5. Run the program BFINTPR, and choose the Befunge program.
6. It should be running the program. If it has apparently frozen, press [clear] to quit immediately.

Source code (program)
The program is about 4K bytes when compiled and there's another 2K bytes when running.
Most commands should work, except for the ~ command, which I haven't implemented.
If you can optimize the code, go ahead!
For reference, here's the original Befunge-93 reference distribution and docs: https://codeberg.org/catseye/Befunge-93

Happy testing!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement