Jump to content
IGNORED

BASIC / XB Translator (TidBit)


matthew180

Recommended Posts

I see what you are saying. I may be able to hack that in there, but at the point where I'm joining lines, I'm not actually scanning the tokens (remember, I was going to cheap and easy the first time around.) This "auto double colon" thing would only work inside of an IF construct though, and the ENDIF would be required.

 

I'll see what I can do later tonight.

 

Matthew

Link to comment
Share on other sites

Motivation... Aside from the "that's neat" factor, is anyone seriously interested in using this? I was working on getting it on my website, followed by a Windows GUI version, but if I end up being the only one who would use it, I'll just keep it in its current form (command line PHP script.)

 

It was fun to hack out, but I'm not going to keep spending time on it if there is no real benefit or interest. I have a video chip to get done. :)

 

Matthew

Link to comment
Share on other sites

I think I could use it, but some people wont see the benefit from it until they try it and for them to try it .You need to push on a bit, make it simple with a windows IDE and a decent amount of functions to be able to do something with. You don't have to get everything in there yet, like don't worry about files support for now. Then people can get a good try on it and see if they like it, once people start using it then you can futher develop it as people notice things that would improve it.

 

You know for myself, I like using basic it's fast to get something working in, powerful commands but I just hate the line numbers. So I can see a real plus to using this.

Link to comment
Share on other sites

I'm not much of a coder, but having support for this kind syntax could really be beneficial in getting new programmers to work with the TI... I've always programmed in BASIC, because in the two years I've been programming, BASIC (and XB) is all I've known (with the exception of my hack and slash attempts at assembly). This also seems like it would make porting games from other languages easier... Does that make sense?

 

 

Link to comment
Share on other sites

There is already a BASIC/XB converter out there I believe programmed by a German TIer. As a matter of fact I found it on a CD distributed by Berry Harmsen a couple of years ago. What it does is take a plain text file and convert it into a program. I will play with it tonight and see if it still requires line numbers or not.

It looks like you are going beyond a straight converter though with some potentially nice enhancements, and I'm looking forward to the final product.

Link to comment
Share on other sites

  • 2 months later...

So I'm wondering, is anyone using this? I never heard any feedback (other than Owen of course ;) ), and subsequently I have not done anything with it beyond this initial implementation. Online version is here:

 

http://codehackcreate.com/archives/237

I have to admit that I had completely forgotten about it... I gave it a very quick try and I can see how BASIC code immediately becomes much more readable, especially with the long labels and the indentations. Kind of reminds me of Microsoft's QBasic a bit. This will be very valuable for big projects. Are you planning a standalone version usable under Windows?

One potential annoyance though would be having to switch back and forth between Classic 99 and the translator for every edit, but I suspect the much improved readability and ease of editing will more than offset that minor issue, especially if one has a large enough screen real estate to keep both Classic 99 and the translator open at the same time.

Edited by Vorticon
Link to comment
Share on other sites

Once we get the outstanding contests resolved, you should make a "best thingie written with my tool" contest. That'll get you traction. Might even get me to stay up past 10 these days.

 

This may, however, increase the amount of code I have to paste into classic99... That would make it a difficult tool to use. Repasting entire project instead of smaller ranges (depending on how the line numbers re-allocate with changes) for minor updates could slow down my dev time.... But just theorizing here.

Edited by unhuman
Link to comment
Share on other sites

I had not seen this, but will put it to some use as I continue the re-writing of some of my programs. Is it specific to XB multiple statement lines, or can it be used to define TI BASIC blocks?

 

I have some other thoughts, but I think the simplicity of this translator may work well to defeat the complexity of what I am thinking.

Link to comment
Share on other sites

Yeah, I understand the problems about having to copy-and-paste. It is a bit of a pain. However, personally, when I program in BASIC, I do the bulk of it in a text editor on a PC, then move the thing to an emulator. It would suck for those debugging sessions where you want a fast code, run, debug cycle.

 

Is it specific to XB multiple statement lines, or can it be used to define TI BASIC blocks?

 

It has no knowledge of XB vs BASIC. If you use XB specific commands or syntax, then it will require XB. Otherwise it will work equally well with BASIC. The current implementation is simply a scanner, there is no syntax parsing beyond what is needed to recognize a label and line concatenation.

 

This was really more and a test to see if BASIC could be made more readable and manageable, without actually writing a new interpreter. If it actually gets some use, feedback, user requests, etc. then I'll work on it. Otherwise it will just remain as is. I had initially planned on a native desktop GUI version, but without interest that won't happen. Also, it may be possible to work out some way to interface with the emulators to make getting to code into the emulators easier. The first thing that comes to mind would be to export the code in a "merge" format, saving to, for example, the DSK1 directory of Classic99. Then your development cycle might go like this:

 

1. Editing in text editor.

2. Save.

3. Hit "convert" button in the translator.

4. In the emulator:

4a. NEW

4b. MERGE DSK1.xxxxxx

4c. RUN

 

This works well for assembly language with Classic99 because Classic99 does not cache any files and opens/reads them every time you reference the file. This is a very good thing.

 

It all comes down to money really. ;) And "money" around here is basically participation and feedback. Anyone who works on a tool for our community gets their drive and motivation from the rest of us saying "cool, this is awesome!", etc. Without that sense of need or interest, people stop working on stuff. Just something to keep in mind. For a while we had a lot of good threads going where people were making layout screen and graphics editors, and all kinds of cool stuff. I have not seen much of that lately though, which is too bad because we have a lot of new people and those tools are really great! I might go bump some of them. ;)

 

Anyway, I feed on that participation and feedback mojo, so "show me the money!" :)

Link to comment
Share on other sites

I was thinking macros and operator expansions, interpreter variables, loop controls, things like that.

 

Macros

 

For instance, a pre-defined macro might be

INC A

to expand to

A=A+1

Although, writing either is probably just as easy.

 

Or one could define a macro like this

#TO GetSpace:
CALL KEY(3,K,S)
IF K<>32 THEN GetSpace
#ENDTO

Notice a couple of things: the label is used as the macro name, and the "#TO" (while a reserved word in BASIC, is never valid at the beginning of a line) and "#ENDTO" is used to tell the interpreter how-to do something, a-la LOGO. The macro would then be called like so

CALL CLEAR
CALL SCREEN(9)
Begin:
PRINT "PRESS SPACE"
:GetSpace
GOTO Begin

 

This is very simplistic, and I suppose that in many cases a subroutine might be of better use than a macro.

 

 

Operator expansions

 

Expansion of += -=

A+=
B-=
C+=8
D+=E

expands to

A=A+1
B=B-1
C=C+8
D=D+E

We would have to use the operation-equals notation, since in the instance of C it would be technically valid to say "C=+8" for a value of 8, or the obvious "C=-8", and "D=+E" or "D=-E" would also be valid BASIC statements.

 

 

 

Interpreter variables

Something simple like in C with DEFs and IFDEFs, so one could do something like this

#DEF XB FALSE

REM SOME PROGRAM CODE

#IFDEF XB
DISPLAY AT(12,10):"MESSAGE"
#ELSE
M$="MESSAGE"
R=12
C=10
GOSUB DisplayAt
#ENDIF

REM SOME MORE PROGRAM CODE

#IFDEF !XB
DisplayAt:
FOR I=1 TO LEN(M$)
CALL HCHAR(R,C+I-1,ASC(SEG$(M$,I,1)))
NEXT I
RETURN
#ENDIF

 

In this example, one could use the same pseudo-code to generate a program targeted specifically at BASIC or Extended BASIC. Useful for my purposes as I have a couple of programs in mind from which I could generate BASIC, Extended BASIC, and Super XB program listings from the same pseudo-code.

 

(It occurred to me here that you could also use the hash for the macro initiator (#TO) as well.) As well, I only address boolean values.

 

 

Loop controls

 

Pretty self-explanatory: while-wend, loop-until, repeat.

#WHILE I<4
GetI:
INPUT "VALUE FOR I (CANNOT BE LESS THAN 4)":I
#WEND

The interpreter should create code like:

100 INPUT "VALUE FOR I (MUST BE GREATER THAN 3)":I
110 IF I<4 THEN 100

 

Loop-until would work similarly:

A=1
#LOOP
A=A+A
PRINT A
#UNTIL A>64

and would generate

100 A=1
110 A=A+A
120 IF A<65 THEN 100

This requires a little extra thought due to comparisons. As x>y translates to IF x<y+1, x<y would translate to x>y-1, and x=y would translate to x<>y.

 

Then repeat would require a programmer-supplied counter variable

#REPEAT 4 I
PRINT "THIS WILL PRINT FOUR TIMES"
#END

generates

100 FOR I=1 TO 4
110 PRINT "THIS WILL PRINT FOUR TIMES"
120 NEXT I

 

Unlike LOGO loops, wherein the procedure is ignorant to its counter, you could use the provided counter variable within the REPEATed block.

 

 

 

That is all I have right now. It might all be too much or cause undue complexity, but seems like it would be a neat factor. In any case, I have a severe headache right now so I completely disavow and deny any responsibility for errors or quirkiness, but take full credit for anything that looks like a good idea. :)

 

(Edited to fix some errors and make some concepts more clear.)

Edited by OLD CS1
Link to comment
Share on other sites

ok, here are my thoughts:

 

1) You would need some kind of standalone version, without having to connect to the internet.

I'm a web guy, but for this type of application a standalone version would be cooler.

 

2) If going the web way, some kind of repository feature could be added where code can be exchanged or loaded

from the internet and then pumped directly into classic99.

 

3) Writing such a tool without knowing if the community will actually use it, can be *very* frustrating.

I kinda get the same feeling with spectra2. The motivation that keeps me going is that I'm convincing myself I'll

get use of it for my future stuff, sooner or later :|

 

4) The value of such translator could be improved if there is a more easy way to get the code into the emulators.

Perhaps Tursi could help out there for classic99 (see 2)

Ofcourse the idea of macro expansion mentioned earlies also sound very cool.

Link to comment
Share on other sites

ok, here are my thoughts:

 

1) You would need some kind of standalone version, without having to connect to the internet.

I'm a web guy, but for this type of application a standalone version would be cooler.

If it is a PHP script, the script itself can be written to run stand-alone with a PHP interpreter. hrmmmm an interpreter interpreting and interpreted language. Insane, I tell ya! INSANE!

 

2) If going the web way, some kind of repository feature could be added where code can be exchanged or loaded

from the internet and then pumped directly into classic99.

Neat. We could become code-hippies.

 

3) Writing such a tool without knowing if the community will actually use it, can be *very* frustrating.

I kinda get the same feeling with spectra2. The motivation that keeps me going is that I'm convincing myself I'll

get use of it for my future stuff, sooner or later :|

I suspect that as more homebrewers see the power of your library, it will get used for other games. "Pitfall!" is just a start to demonstrate its power. As I invest more time in expanding my knowledge of TMS-9900 assembly and the TI itself, I have some games I would love to work out on the TI, and an existing library as a game-oriented operating system available is very valuable.

 

4) The value of such translator could be improved if there is a more easy way to get the code into the emulators.

Perhaps Tursi could help out there for classic99 (see 2)

Ofcourse the idea of macro expansion mentioned earlies also sound very cool.

 

More so than copy-n-paste?

Link to comment
Share on other sites

Hey, matthew,

 

I put "32010" as my starting line number and the translator changed it back to "100".

 

EDIT:

 

Also, this block

J=0
IF P<0 THEN JoyStick
CALL KEY(P,K,S)
IF S THEN PKeyDown ELSE JoyStick
PKeyDown:
J=POS(K$(0),CHR$(K),1)
IF J=0 THEN GetKey
RETURN
JoyStick:
CALL JOYST(ABS(P),X,Y)
IF X+Y THEN JoyDecode
GetKey:
CALL KEY(3,K,S)
IF S THEN KeyDown ELSE Exit
KeyDown:
J=4+POS(K$(1),CHR$(K),1)
SetJ:
J=J*-(J>4)
Exit:
RETURN
JoyDecode:
IF SGN(X)*SGN(Y)THEN SetJ
J=JOY(X)+(JOY(Y)-2*(Y<>0))
RETURN

 

Did not give "SetJ" a line number, so the output is

1350 J=0
1360 IF P<0 THEN 1420
1370 CALL KEY(P,K,S)
1380 IF S THEN 1390 ELSE 1420
1390 J=POS(K$(0),CHR$(K),1)
1400 IF J=0 THEN 1440
1410 RETURN
1420 CALL JOYST(ABS(P),X,Y)
1430 IF X+Y THEN 1490
1440 CALL KEY(3,K,S)
1450 IF S THEN 1460 ELSE 1480
1460 J=4+POS(K$(1),CHR$(K),1)
1470 J=J*-(J>4)
1480 RETURN
1490 IF SGN(X)*SGN(Y)THEN SetJ
1500 J=JOY(X)+(JOY(Y)-2*(Y<>0))
1510 RETURN

 

Edited by OLD CS1
Link to comment
Share on other sites

ok, here are my thoughts:

 

1) You would need some kind of standalone version, without having to connect to the internet.

I'm a web guy, but for this type of application a standalone version would be cooler.

 

2) If going the web way, some kind of repository feature could be added where code can be exchanged or loaded

from the internet and then pumped directly into classic99.

 

Yes, you do need a desktop version, unless the editor and emulator were also web-based. I've thought about that a lot with HTML5's promises, as well as JavaScript's power. Heck, my kids play full-blown first-person games "in the browser" (currently via Flash), but I have seen some impressive HTML5 too.)

 

3) Writing such a tool without knowing if the community will actually use it, can be *very* frustrating.

I kinda get the same feeling with spectra2. The motivation that keeps me going is that I'm convincing myself I'll

get use of it for my future stuff, sooner or later :|

 

Ahhh. Here is the biggest problem. I wrote the web based version for two reasons. 1. I know PHP really well and it came together quickly. 2. Making the web version was a lot faster and easier than a desktop version. Plus, *everyone* can use the web version (Win, Mac, Unix). If there was enough interest, then I was going to move forward with a desktop version. I'm still not sure if there is enough interest to warrant the work.

 

As for something like Spectra2, personally I think it is an excellent piece of work, but I'm not sure how many people in our small community will actually take advantage of it? Unfortunately, I think the people who want to make games want to use a higher level language.

 

I have come to the conclusion that, if you do something for a retro-computer, you better be doing first and foremost because you *want* to use whatever it is you are making. Then if people get excited about it or use it too, then that is a bonus. I made the BASIC translator because I hate having to deal with line numbers and the lack of indentation or labels. I also did it because I like to make tools and because I want to make a full-blown interpreted language, eventually.

 

4) The value of such translator could be improved if there is a more easy way to get the code into the emulators.

Perhaps Tursi could help out there for classic99 (see 2)

Ofcourse the idea of macro expansion mentioned earlies also sound very cool.

 

There definitely has to be a better, faster, easier way to get the code into an emulator.

Link to comment
Share on other sites

Ahhh. Here is the biggest problem. I wrote the web based version for two reasons. 1. I know PHP really well and it came together quickly. 2. Making the web version was a lot faster and easier than a desktop version. Plus, *everyone* can use the web version (Win, Mac, Unix). If there was enough interest, then I was going to move forward with a desktop version. I'm still not sure if there is enough interest to warrant the work.

 

Is there a "distributable" PHP interpreter? I have a number of administration scripts I wrote in PHP which use the command line interpreter.

 

As for something like Spectra2, personally I think it is an excellent piece of work, but I'm not sure how many people in our small community will actually take advantage of it? Unfortunately, I think the people who want to make games want to use a higher level language.

 

I think this is sadly true. There is a BASIC programming environment for the Atari 2600, and I bet digging a little bit turns up several BASIC-type languages for other console platforms. Having said that, I think that programmers who want real power, especially on the TI, will be quite accepting of Spectra2. As well, having a framework available may just entice new programmers to the realm.

Link to comment
Share on other sites

I will look into those errors. Thanks for the feedback!

 

The code block which was not producing the line number for one of the labels now works. It have one last suggestion: the ability to define starting line numbers for certain blocks. Kind-of like an AORG directive, giving the ability to assign specific blocks starting as specific numbers. Perhaps

#NUM 1500,5

with the ,5 being the optional increment.

 

I am using it to put together test blocks as I work on "Tiles." (Since a lot of my development notes are in essentially compatible pseudo-code, I could probably convert my entire program, now.) I think I am going to use it fully with my next rewrite.

 

EDIT: Okay, I was wrong. I have another suggestion: forced REMarks in the output. This would allow for program or section headers, and ease of finding blocks within the output. Something like

Begin:
CALL CLEAR
CALL SCREEN(
#REM ASK USER FOR NAME
AskName:
INPUT "WHAT IS YOUR NAME?":NAME$
IF NAME$<>"OLD CS1" THEN NotLying
PRINT "YOU'RE LYING!  TRY AGAIN!"
GOTO AskName
NotLying:
#REM USER ENTERED A CORRECT NAME
PRINT "I AM HAPPY TO SEE THE TRUTH."
...

 

I am not going to show the expected output, as I suspect it is fairly obvious.

 

Thanks for all the work. I see this as a quite powerful tool.

Edited by OLD CS1
Link to comment
Share on other sites

The problem with the line numbers was, I had the max limit set to 32000. XB imposes a 32767 line number limit, which the code now supports. If the program tries to number higher than that, it will dump out an error.

 

The other problem the the label not being assigned a line number was due to there not being a space after the SNG() function and the word "THEN". I tested on real XB and if you type:

100 IF SGN(X) THEN 200

 

XB will suck out the space and produce:

 

* Space gets sucked out here
100 IF SGN(X)THEN 200

* Space is left alone here
200 IF X=1 THEN 300

 

Gotta love those nuances... Anyway, I made the converter aware of expressions (anything in parens), which includes functions, and it corrected the problem. Thanks for finding that problem!

 

I might be able to add the "block" ability, let me see how easily that will go in. I had thought of that originally, but I figured I would never really work with the line-number version of the code, it really didn't matter.

 

As for running on Windows, yes you can get PHP for Windows and run the script. I think there is even some sort of tool for making a GUI with PHP. It has been a long time since I looked in to it though. But I would probably just use C for a native GUI solution. I don't know, maybe not. In the mean time, does anyone want the code to run on their own machine?

Link to comment
Share on other sites

The problem with the line numbers was, I had the max limit set to 32000. XB imposes a 32767 line number limit, which the code now supports. If the program tries to number higher than that, it will dump out an error.

 

The other problem the the label not being assigned a line number was due to there not being a space after the SNG() function and the word "THEN". I tested on real XB and if you type:

100 IF SGN(X) THEN 200

 

XB will suck out the space and produce:

 

* Space gets sucked out here
100 IF SGN(X)THEN 200

* Space is left alone here
200 IF X=1 THEN 300

 

Gotta love those nuances... Anyway, I made the converter aware of expressions (anything in parens), which includes functions, and it corrected the problem. Thanks for finding that problem!

 

You are welcome. Yeah, TI BASIC does that, too. The output is directly from Classic99 LIST "CLIP" paste-job (well, with minor modifications.)

 

As for running on Windows, yes you can get PHP for Windows and run the script. I think there is even some sort of tool for making a GUI with PHP. It has been a long time since I looked in to it though. But I would probably just use C for a native GUI solution. I don't know, maybe not. In the mean time, does anyone want the code to run on their own machine?

 

I have PHP installed on my machines. I was thinking more in terms of like a simple redistributable like Microsoft provides for VC++, etc. I thought there might be a CLI-only installation for Windows: nope. Then I looked at PHP compilers: I found a couple, but nothing free. Ah, well.

 

I would be interested in looking at the source. If you put a link to the file on your site with a .phps extension, the server *should* expose the source. That way we can see it "live."

 

For example, I have a map script I wrote with the file name of "map.php" then a link "map.phps" pointing to the .php file. So, if you access map.php, it runs the script. If you access map.phps, it shows the source.

Link to comment
Share on other sites

Ok, I made some changes:

 

1. Remarks. Instead of having a "special" remark token like #REM, I figured I would just retain any existing REM statements, and remove the C/C++ style // remarks. So, any comments you want to "go away", use //. Any you want in your final code, use REM.

 

2. Forced line numbers. I added support for recognizing existing line numbers to override the internal counter. So, every line can start with a line number now if you want. This will make it easier to convert existing code, as well as support the forced line numbers for subroutines or other code sections.

 

Here is an example of forcing the line numbers:

 

REM TI BASIC Translator Example
A=1
Loop:
   GOSUB disp
   A=A+1
   IF A<10 THEN Loop
// Loop End
END

1000 disp:
   PRINT A
RETURN

100 REM TI BASIC Translator Example
110 A=1
120 GOSUB 1000
130 A=A+1
140 IF A<10 THEN 120
150 END
1000 PRINT A
1010 RETURN

 

EDIT: I added the source code to the first post in this thread.

Edited by matthew180
Link to comment
Share on other sites

Hey Matthew... quick question. I tried to input the following:

 

  A=1
B  PRINT A:
  A=A+1
  GOTO B

 

and received the following code output:

 

100 A=1
110 B  PRINT A:
120 A=A+1
130 GOTO B

 

Then I tried using a number for a "label" instead of B and the following was the resulting code:

 

Code In:

  A=1
1  PRINT A:
  A=A+1
  GOTO 1

Code Out:

100 A=1
1 PRINT A:
11 A=A+1
21 GOTO 1

 

So... Neither of these was my intended output... The first try (label B) would be a syntax error in XB or BASIC because of line 110. The second try (label 1) started with line number 100 and then went to 1,11,21.... Now, I am 100% positive that this is just me not knowing how to input this code properly. I don't REALLY understand indention all that well, so I'm wondering if there is a short lesson somewhere (other than the one on TIdBiT) that I can read to learn? I noticed the default example and I want to know "why." I'm really using this particularly because I have a concept in my head that is probably much better suited to this kind of language. In other words, I don't know the best way to do what I want to do in BASIC or XB code... I'm creating a menu system for my RPG, and the line numbers are killing me. I feel like I'm running a bunch of electrical wires everywhere with no real plan.... Spaghetti would be an understatement. I'd like to use TIdBiT for this part of my project, I just need to learn a bit more about the syntax, that's all. =) Great program though... I can't wait until I know how to use it better.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...