Jump to content
dmsc

FastBasic 4.0 - Tenliners'19 release

Recommended Posts

Hi all!

 

To start the new year, and to provide a better Basic for all the new ten-liners, I'm releasing version 4.0 of FastBasic.

 

The major changes in this version are under the hood:

  • The interpreter has been changed from a stack-base virtual machine to a register plus stack, this makes the interpreter from 10% to 20% faster depending in the program. In the SIEVE.BAS benchmark, the Atari version is 13% faster and in the cross-compiler is 19% faster, but programs depending on fast PEEK and POKE should be much faster.
  • There is now a full test-suite to automatically catch regressions in the parser and interpreter, ensuring that bugs don't re-appear.
Also, there are some user visible changes:
  • There is now a command-line compiler "FBC.COM", this allows compiling large programs that don't fit in the full editor. Currently, "FBC" accepts the full floating-point syntax.
  • Added minimal support for Player/Missile graphics:
    • PMGRAPHICS (abbreviated PM.) statements setups P/M,
    • PMHMOVE (abbreviated PMH.) horizontal moving a a player/missile,
    • PMADR() returns the address of the given player/missile data.
  • Many small bugs fixed.
In this version the integer IDE is 8188 bytes in size (we still have 4 bytes less than 8K), and the floating-point IDE is 9405 bytes.

 

As always, full sources and binaries for Atari, Linux, Windows and MacOS are available over Github: https://github.com/dmsc/fastbasic/releases

  • Like 22
  • Thanks 2

Share this post


Link to post
Share on other sites

Hi all!

 

To start the new year, and to provide a better Basic for all the new ten-liners, I'm releasing version 4.0 of FastBasic.

 

Thank you very much for this great, amazing BASIC!

 

I have started a 10-Liner which probably won‘t be finished by Saturday.

 

May I ask two questions:

[li]Is there a way to enter graphics symbols as some of them are masked by commands?[/li]

[li]Would it be possible to add Action!-style direct-to-memory variables, ie assigning integer variables to memory locations?[/li]

 

 

 

Gesendet von iPhone mit Tapatalk

Share this post


Link to post
Share on other sites

Hi!

 

Thank you very much for this great, amazing BASIC!

 

I have started a 10-Liner which probably wont be finished by Saturday.

 

May I ask two questions:

[li]Is there a way to enter graphics symbols as some of them are masked by commands?[/li]

Yes, in the IDE simply press ESC before the key you want to enter.

 

[li]Would it be possible to add Action!-style direct-to-memory variables, ie assigning integer variables to memory locations?[/li]

It is possible, but probably would need an special syntax to differentiate from standard variables, to avoid confusion in the parser, and would make the IDE a lot bigger.

 

I'm thinking on a syntax like:

 

 DIM @SdlSt = 560, @Color0 byte = $2c4
 @SdlSt = $1234   ' Equivalent to DPOKE 560, $1234
 @Color0 = 27     ' Equivalent to POKE $2C4, 27
Note that currently the cross-compiler already supports using standard Atari symbols with "@" at front, like " poke @CRSINH, 0 ".
  • Like 1

Share this post


Link to post
Share on other sites

I'm thinking on a syntax like:

 

 

DIM @SdlSt = 560, @Color0 byte = $2c4
 @SdlSt = $1234   ' Equivalent to DPOKE 560, $1234
 @Color0 = 27     ' Equivalent to POKE $2C4, 27
.
Sounds great, didn‘t try the cross-compiler so far. IDE bloat would be a detriment, though, and differentiating between bytes and words would probably bloat it even more. Probably mostly a tenliners feature as it is much shorter ;)

 

 

Gesendet von iPhone mit Tapatalk

Share this post


Link to post
Share on other sites

Hi dmsc,

 

First of all thank you for improving FastBasic. I see that now it is super enhanced with the first version that I tested.

I already overcome all the Basic of atari for its speed, but I have the doubt I will have overcome the ACTION! language?

regards

Share this post


Link to post
Share on other sites

Hi dmsc,

 

First of all thank you for improving FastBasic. I see that now it is super enhanced with the first version that I tested.

 

I already overcome all the Basic of atari for its speed, but I have the doubt I will have overcome the ACTION! language?

 

regards

It probably wont, but while Action! gives you more control and flexibility it also requires more code/work/knowledge for e.g. P/M graphics and has more possibilities to get bitten by sloppy code.
  • Like 1

Share this post


Link to post
Share on other sites

Hi ascrnet!

 

Hi dmsc,

 

First of all thank you for improving FastBasic. I see that now it is super enhanced with the first version that I tested.

 

I already overcome all the Basic of atari for its speed, but I have the doubt I will have overcome the ACTION! language?

 

regards

Current FastBasic is a (very-fast) interpreter, so it is slower than a true compiler like Action. Remember that my goal with FastBasic is a *small* language.

 

But there is nothing preventing to write a compiler for FastBasic, as the language is already designed to allow easy compilation, I just need a lot of time :P .

 

Currently, those are my long-term projects for FastBasic:

 

- Parameters to PROC/EXEC;

- A simple way to call M/L procedures;

- Support for byte and word memory variables (the "@" syntax above);

- An optimizing compiler to 6502.

 

And last:

 

- Convince developers to help me in expanding FastBasic - I'm just waiting for pull requests ;)

Edited by dmsc
  • Like 7

Share this post


Link to post
Share on other sites

- Convince developers to help me in expanding FastBasic - I'm just waiting for pull requests ;)

Sounds great, what kind of help are you looking for? (Most probably beyond my simple ML abilities but maybe theres something low-grade assemblers can contribute as well.

Share this post


Link to post
Share on other sites

Hi!

 

Sounds great, what kind of help are you looking for? (Most probably beyond my simple ML abilities but maybe theres something low-grade assemblers can contribute as well.

Well, you can (IMHO in order of difficulty):

 

- Add examples and review the documentation. Recently 777ismyname helped me by reviewing all the manual, you can see his work at: https://github.com/dmsc/fastbasic/commit/9e92f4f8e69115b1d4699c8ff6c36df40558ae3a

 

- Add test to the testsuite at https://github.com/dmsc/fastbasic/tree/master/testsuite/tests, you add a ".bas" file with a test and a ".chk" file with the expected output, see https://github.com/dmsc/fastbasic/blob/master/testsuite/tests/testproc.chk and https://github.com/dmsc/fastbasic/blob/master/testsuite/tests/testproc.bas . Currently, not all functions are tested.

 

- Add issues for missing or wanted features.

 

- Help with optimizing!. there are probably still many simple ways to remove a few bytes, current git version is 86 bytes shorter than v4.0, and fixes a pair of bugs. See https://github.com/dmsc/fastbasic/commit/4639cc0d13e41b3039a36e293a7748c9975197c1for a simple size optimization in the parser.

 

- Proposing new statements or functions. See https://github.com/dmsc/fastbasic/commit/b718de04e376747590cac0a97166837abda1de59#diff-78ee65486131bb8d1d642829cf29dcb5for what is needed to add a simple statement - this only adds a parser script, or see https://github.com/dmsc/fastbasic/commit/082c9f46ff8146f73c3887273e4762a7126c67ee#diff-78ee65486131bb8d1d642829cf29dcb5 for how to add a statement with a new assembly language procedure.

 

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

Are there any GOTO _Label_ commands. I have a few Turbobasic programs the use this and is almost essential for program execution.

Share this post


Link to post
Share on other sites

Hi!

 

Are there any GOTO _Label_ commands. I have a few Turbobasic programs the use this and is almost essential for program execution.

No, I did not implement a GOTO on purpose, as it would allow breaking some assumptions in the generated code. I think that you can always rewrite the code to remove gotos. For example:

 

  FOR I=0 to 10
    ? I 
    IF I = 5 
      GO# LEAVE
    EDIF
  NEXT I
#LEAVE
This won't work because you exit from a FOR, leaving the loop information in the stack. You can do:

 

  FOR I=0 to 10
    ? I 
    IF I = 5 
      EXIT
    EDIF
  NEXT I
This works as the compiler recognizes an exit from a FOR and cleanups the stack properly.

 

If you want, you can send me some of your code to help converting to "no GOTOs" :)

  • Like 2

Share this post


Link to post
Share on other sites

Agreed regarding GOTO, despite the fact it's intrinsic to low-level code (in the form of branches and jumps). I used to enjoy making no use whatsoever of GOTO and GO# in large TBXL projects. :)

  • Like 2

Share this post


Link to post
Share on other sites

Just tried this for the first time, took a couple of hours to figure out the changes I needed to make to my TurboBasicXL program (most of that was me changing things that didn't need to be changed then realising later and changing them back) but as soon as it ran for the first time I was very pleased with how much smoother it was running.

 

TYVM for this, awesome work.

 

btw: is there something like turban for Fastbasic?  I really like coding in notepad++ then with a single click getting my TB program running on emulator.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Preppie!

14 hours ago, Preppie said:

Just tried this for the first time, took a couple of hours to figure out the changes I needed to make to my TurboBasicXL program (most of that was me changing things that didn't need to be changed then realising later and changing them back) but as soon as it ran for the first time I was very pleased with how much smoother it was running.

 

TYVM for this, awesome work.

Thank you!

 

And please, do tell if you have any suggestion to the documentation (or to FastBasic itself) to make it easier to port programs from TurboBasicXL.

 

14 hours ago, Preppie said:

btw: is there something like turban for Fastbasic?  I really like coding in notepad++ then with a single click getting my TB program running on emulator.

 

I would use the cross compiler plus a small batch script to run Altirra with the generated .XEX as an argument.

 

I don't use Windows, but I understand that the NppExec plugin allows running arbitrary commands just pressing F6 (or control-F6).

 

So, you could simply run:

C:\path\to\fb myprog.bas || exit /b %errorlevel%
C:\path\to\Altirra myprog.xex

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

EDIT: Ignore what I said, the problem was at my end, I'd messed up my DL

 

 

 

Also got a question.  Does FB use the unused ram at the start of the PMs or is that still available to the user?

Edited by Preppie

Share this post


Link to post
Share on other sites

Hi Preppie!

 

Sorry for not replying earlier, I was very busy last week.

 

On 7/12/2019 at 6:51 AM, Preppie said:

EDIT: Ignore what I said, the problem was at my end, I'd messed up my DL

 

Great that you solved it!

 

On 7/12/2019 at 6:51 AM, Preppie said:

Also got a question.  Does FB use the unused ram at the start of the PMs or is that still available to the user?

 

The PMGRAPHICS command is modeled after the Altirra BASIC one, it places the P/M area *bellow* the current MEMTOP value. This means that there is free memory between the last player and the display list, as this code shows:

  GR. 0
  PMGR. 1
  ? DPEEK($2E5) - ( PMADR(3) + 256 )

This shows 1055 bytes free in graphics 0, and 1953 in graphics 7, but only 53 bytes in graphics 8+16, 9, 10, 11 and 15+16.

 

The memory bellow the missiles ( so, bellow PMADR(-1) ) is the new top of RAM, and will be used for your program arrays and strings.

 

A simple memory map of FastBasic RAM usage is:

   $2000:           Start of runtime - jump table
   bytecode_start:  End of runtime, start of program bytecode
   bytecode_end:    End of bytecode. Next bytes are free up to next page, variables are always aligned to a page.
   var_page:        Page of start of variable data, 2 bytes for each integer, string and array variable, 6 bytes for each floating-point variable.
   array_ptr:       Start of array and string data - this area grows each time an array is DIMensioed or a new string is assigned.
   array_ptr:       End of array data (array_ptr holds current end of array data, start at top and grows).
   ----------:      Free memory
   PGMBASE:         Base of player/missile memory
   ----------:      Free memory up to display-list
   MEMTOP:          Top of application memory (set by OS, depend on available RAM)

 

Note that the runtime size depends on the interpreter (integer only or floating-point), and in the cross-compiled only the used functionality is included, so the start of bytecode is not predictable.

 

Have Fun!

 

Share this post


Link to post
Share on other sites

Thanks, very informative answer.

 

Ready for another question? :)

 

Would there be any value in giving the user the option of creating a single byte variable?  So many variables I use are just flags or sub 255 that it seems a waste of time and space to use 2 bytes.

 

You can create byte arrays but the overhead of the array makes them slower than the standard 2 byte integer, I thought a byte variable might be faster than a 2 byte.

 

And finaly. I find myself often changing flag states or reseting variables, would having commands to do this help in speed?  I'm guessing even if there is a speed benefit that it's so small it's not worth your time coding it, but figured I'd mention it.

 

eg.

 

SET var (this would be like var = 1)

CLEAR var (same as var = 0)

 

 

BTW: Is there a paypal or something where I could donate?  This language is so good I feel like I'm cheating you by using it for free :)

 

Thanks for your time.  

 

 

Share this post


Link to post
Share on other sites

Thanks, very informative answer.

 

Ready for another question? :)

 

Would there be any value in giving the user the option of creating a single byte variable?  So many variables I use are just flags or sub 255 that it seems a waste of time and space to use 2 bytes.

 

You can create byte arrays but the overhead of the array makes them slower than the standard 2 byte integer, I thought a byte variable might be faster than a 2 byte.

 

And finaly. I find myself often changing flag states or reseting variables, would having commands to do this help in speed?  I'm guessing even if there is a speed benefit that it's so small it's not worth your time coding it, but figured I'd mention it.

 

eg.

 

SET var (this would be like var = 1)

CLEAR var (same as var = 0)

 

 

BTW: Is there a paypal or something where I could donate?  This language is so good I feel like I'm cheating you by using it for free :)

 

Thanks for your time.  

 

EDIT:

 

Been doing some speed tests and noticed that doing two INCs is faster than A=A+2, which made me think would having a command that added 2 or 4 be just as fast as adding 1?  If so you could use something like INC A:INC2 A instead of A=A+3 (and all the other combinations for other numbers if we had INC4, INC8).

 

Also, if you implemented single byte variables we could also have ROTL, ROTR for quick doubling or halfing.  Although maybe that would be getting beyond the scope of a language you'd call BASIC.

 

 

 

 

 

Edited by Preppie

Share this post


Link to post
Share on other sites

Hi Preppie!

Quote

 

Thanks, very informative answer.

 

Ready for another question? :)

 

Would there be any value in giving the user the option of creating a single byte variable?  So many variables I use are just flags or sub 255 that it seems a waste of time and space to use 2 bytes.

 

You can create byte arrays but the overhead of the array makes them slower than the standard 2 byte integer, I thought a byte variable might be faster than a 2 byte.

 

First, remember that there are currently two FastBasic compilers, the native one (the Atari IDE) and the cross compiler. Both share the same parser and interpreter, but the cross compiler adds a peephole optimization pass that reorder and transform the code, so it can give different speed for the same code.

 

About byte variables, the problem is that currently all arithmetic is performed as words, and also the stack is word sized, so it would only be faster for reading / writing the variable, and I don't think that the added size to the IDE would be worth it.

 

Also, currently I have "GET", "GET #", and "INPUT" accept byte references, but "FOR", "INC" and "DEC" only work with words.
 

Quote

And finaly. I find myself often changing flag states or reseting variables, would having commands to do this help in speed?  I'm guessing even if there is a speed benefit that it's so small it's not worth your time coding it, but figured I'd mention it.

 

eg.

 

SET var (this would be like var = 1)

CLEAR var (same as var = 0)

 

In the cross compiler, the expressions "A = 0" and "A = 1" are special cased so are faster than other values (as the VM have tokens to load 0 and 1), but that optimization is not done in the IDE.

 

Also, FastBasic uses byte expressions for the "boolean" operators, as they are assumed to be always "1" or "0", so  "A AND B OR C" converts A, B and C to booleans before doing the AND/OR:

 VAR_LOAD "A"
 COMP_0
 PUSH
 VAR_LOAD "B"
 COMP_0
 L_AND
 PUSH
 VAR_LOAD "C"
 COMP_0
 L_OR
 CJUMP jump_lbl_1

In the cross compiler, the code is a little shorter, because the "load variable" are merged with the "push" tokens:

 VAR_LOAD "A"
 COMP_0
 PUSH_VAR_LOAD "B"
 COMP_0
 L_AND
 PUSH_VAR_LOAD "C"
 COMP_0
 L_OR
 CJUMP jump_lbl_1
Quote

BTW: Is there a paypal or something where I could donate?  This language is so good I feel like I'm cheating you by using it for free :)

 

Don't worry, I'm happy with anyone finding FastBasic useful. And also, instead of money, you could try to contribute to the code, it is open source after all :)

 

Quote

Thanks for your time.  

 

EDIT:

 

Been doing some speed tests and noticed that doing two INCs is faster than A=A+2, which made me think would having a command that added 2 or 4 be just as fast as adding 1?  If so you could use something like INC A:INC2 A instead of A=A+3 (and all the other combinations for other numbers if we had INC4, INC8).

Well, you are right on the times. I just measured about 81 cycles for each "INC VAR" (this is in the cross-compiler) and 291 cycles for "VAR = VAR + ##", so it is a valid optimization.

 

Currently the cross compiler transforms "A = A + 1" and "A = A - 1" to "INC A" and "DEC A", so I could teach the cross-compiler to also transform "A = A + 2", "A=A+3", "A=A-2", "A=A-3" and "A=A-4" also, this would bring the gain to all cases, and it is simple (only add a new peep-hole rule).

 

I don't like adding something like "INC A, B", because I think is not clear enough and the speed is not that much faster. Also, in my prof-of-concept compiler to 6502 code (available in a branch over github) the addition would be faster than multiple INC's.

 

 

Quote

Also, if you implemented single byte variables we could also have ROTL, ROTR for quick doubling or halfing.  Although maybe that would be getting beyond the scope of a language you'd call BASIC.

Currently the VM has tokens for shift-left by one and shift-left by eight, and in the cross compiler if you write " A = A * 2 " or " A = A * 4" it is transformed to one or two shifts.

 

Using the cross-compiler you can discover how the code is transformed by reading the resulting ASM file, and if you pass the "-n" option the code produced is exactly the same as the IDE, so you can compare both.

 

Have Fun!

 

Edited by dmsc
(borwser sent message before finish!)

Share this post


Link to post
Share on other sites

Thanks for all the informative answers, they really give a good idea of how things work behing the curtain.

 

I'd luv to contribute to the code but my assembler skills are extremely rusty, even in the eightier they weren't the shiniest :)

Share this post


Link to post
Share on other sites
On 7/11/2019 at 5:42 AM, dmsc said:

I would use the cross compiler plus a small batch script to run Altirra with the generated .XEX as an argument.

 

I don't use Windows, but I understand that the NppExec plugin allows running arbitrary commands just pressing F6 (or control-F6).

 

So, you could simply run:

C:\path\to\fb myprog.bas || exit /b %errorlevel%
C:\path\to\Altirra myprog.xex

 

On my PC I managed to compile and run with this command:

C:\FastBasic\CC65\FB\fb-int.bat C:\FastBasic\CC65\FB\program.bas || exit /b %errorlevel%

Program.bas is compiled and runs with Altirra (.bas extension is associated with Altirra on my PC).

 

I think someone more skilled than me would be able to compile and run active program, whatever filename it has...

Moreover, a FastBasic language syntax could be defined.

Share this post


Link to post
Share on other sites

Hi!

On 7/17/2019 at 12:39 AM, Preppie said:

Thanks for all the informative answers, they really give a good idea of how things work behing the curtain.

 

I'd luv to contribute to the code but my assembler skills are extremely rusty, even in the eightier they weren't the shiniest :)

But you can contribute in other ways ;):

  • You could help writing documentation, tutorials and simple code examples to aid beginners.
  • Write more test for the test-suite at https://github.com/dmsc/fastbasic/tree/master/testsuite/tests. Currently there are tests for almost all statements, but no specific test for functions and operators. For this, you write a "BAS" file and a "CHK" file that provides input and the expected output of the test.
  • If you use notepad++, perhaps writing a syntax highlighting file and BAT scripts to automate cross-compiling and testing.

And at last, you can simply provide with new ideas and bug reports!

 

Have fun!

 

Share this post


Link to post
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.

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...