Page 1 of 4

BuinoBasic - Basic Compiler and VM for the Gamebuino

PostPosted: Wed May 20, 2015 12:06 am
by Muessigb
Hey guys,
I was busy with school for the last months, but before that I was working on a BASIC interpreter for our all loved Gamebuino.
So because I think, that it is going to be another way to write programs easily for the Gamebuino, I restarted work on it a few days ago.
Check the post of me below, to see what features you're going to expect.

You can find more information on the official site.

Re: BASIC Interpreter

PostPosted: Wed May 20, 2015 12:53 am
by Skyrunner65
Wait, BASIC?
Atari confirmed?

What I meant by that statement is "Could we port Atari games to the Gamebuino (Albeit Graphically downgraded)?" .

Re: BASIC Interpreter

PostPosted: Wed May 20, 2015 5:31 am
by erico
Hey Muessigb, that is awesome news!
I´m a basic fan and user, just love it.
I used to code basic on trs-80 color and later on the amiga with AMOS...made many nice games back then. :)

I current use GLBasic for my games where I can export to multiple platforms, check it out:
http://www.glbasic.com/

Here a beta run of my last creation:


So, if we have basic going on here, I´m going to be a hell of a happy chap!
Keep it up!

Re: BASIC Interpreter

PostPosted: Wed May 20, 2015 10:52 am
by Sorunome
Wha, that is sounding very awesome Muessig! I can't wait to see it!

Re: Gamebuino BASIC VM

PostPosted: Wed May 20, 2015 11:43 am
by Muessigb
erico wrote:Hey Muessigb, that is awesome news!
I´m a basic fan and user, just love it.
I used to code basic on trs-80 color and later on the amiga with AMOS...made many nice games back then. :)

I current use GLBasic for my games where I can export to multiple platforms, check it out:
http://www.glbasic.com/

Here a beta run of my last creation:


So, if we have basic going on here, I´m going to be a hell of a happy chap!
Keep it up!

Looks awesome!

Skyrunner65 wrote:Wait, BASIC?
Atari confirmed?

What I meant by that statement is "Could we port Atari games to the Gamebuino (Albeit Graphically downgraded)?" .

Hmm, I don't know Atari Basic. Actually I think it would be hard to make it source compatible. I was more planning on going with custom functions (tell me any features you want!) than copying an already existing Basic dialekt. I am tailoring it especially for the Gamebuino Hardware.

Sorunome wrote:Wha, that is sounding very awesome Muessig! I can't wait to see it!

Thanks, Sorunome :)


After some thinking and because you all seem to like it, I am going to restart my codebase to make it even better. I will also put it on GitHub, so that you can track progress and request features or help me improve code quality. If you don't mind, will I make this a compiled language, so you basically write the (normal) basic source code on your PC or directly on the Gamebuino and then compile it on the device itself into some bytecode language that can be executed directly or saved to a file for later use. This would open us some new possibilities and make the code alot faster. I would start with the Compiler (for the PC to test it, as I'm faster in writing C# than plain C; the compiler on the Gamebuino will follow - I promise!) and the Gamebuino "VM". Any input from you about my new ideas would be great ;)

EDIT: So, I decided that I want to make a compiled language out of it in any case (because of the 1.5KB memory limit and the very low speed; I tried it and stumbled over this problem with my first attempt).

What BASIC dialekt do you want?

I, personally want to include following elements by default (please tell me which of them you really need and how you like them to be):
  • 8 or 16 bit signed numbers
  • 32 or 64 bit longs (if really needed)
  • Arrays (fixed size; not dynamic; maybe multidimensional; can contain strings and numbers)
  • Strings (possibly manipulatable)
  • Dynamic buffers, created at execution time (????, not sure if that's possible!)
  • For, While and Repeat until loops
  • If...Then...Else keywords
  • Goto and conditional Goto
  • Subs (maybe with arguments)
  • Gamebuino drawing functions
  • Debugging stuff (breakpoints with optional vardump).
  • No line numbers (because they suck and are worthless anyways)

Remember, that the most work is not done by the actual VM, but by the compiler. It needs to convert the code to small, lightweight binary instructions that the VM can understand. The VM only executes the code (with some Exception checking of course e.g. divide by zero, invalid operation, wrong data type, invalid array indexes, ...). There will be a variable lookup table which contains every (global) variable's data: its address in actual RAM, its type, its maximum size, ...

The variable scope will be global. Variables need to be defined before used (LET keyword) and arrays need to be initialized with the maximum size. I don't really care about the length of the name on the pc compiler. Floting point is very hard to implement and i don't really want to do that if not really, really needed. I think that I can manage this with a bytecode language (some parts might be tricky, but I should get it done). The variables will be pointers (not that that really matters to the user, but anyways). Many Gamebuino functions will be supported and text screen and drawing screen are the same.
The on-the-gamebuino compiler will only have a limited language subset, as I am not good in writing programming language parsers in C. It could have the full commandset if you are willing to help me with that. The on-the-gamebuino compiler will be seperated from the VM (so you have to reflash to go into that compiler). I really want to see what I can do with only 1.5KB of RAM and around 20KB of Flash. The PC compiler and the actual VM are not a real problem for me though.
I cannot promise to get it completly done alone (so help is really appreciated ;)). Also do I have alot of work for school to do in June, so no progress in June.

Tell me if I forgot anything.

EDIT #2: So I restarted the project. I'm working on the new PC compiler right now.
You can see the source of the compiler and contribute here: https://github.com/muessigb/BuinoBasicCompiler.
The source for the VM will go here: https://github.com/muessigb/BuinoBasic

I really hope that this language allows us to make alot new, awesome games!
Also does this save your Flash from additional cycles, makes development faster and easier. There will also be no waiting times anymore, as there is nothing that needs to be flashed.

Re: Gamebuino BASIC VM

PostPosted: Thu May 21, 2015 4:32 pm
by erico
I will be looking for this!

On dialekt, if you keep the base of basic, then a lot of basic games will be convertable and many old basic books might be usefull.
Still, I currently have nothing to suggest.

One interesting thing, while not a suggestion since I´m not sure it would be usefull, is related to inlining C++.
Back on GLBasic, all basic code gets transformed into C++ and you can also inline it if you need.

I´m not really sure this would be of any good here and I don´t know what kind of restrictions one would have creating a Basic for Gamebuino.

Either way, is it done already? ;)

Re: Gamebuino BASIC VM

PostPosted: Thu May 21, 2015 7:08 pm
by Muessigb
erico wrote:I will be looking for this!

On dialekt, if you keep the base of basic, then a lot of basic games will be convertable and many old basic books might be usefull.
Still, I currently have nothing to suggest.

One interesting thing, while not a suggestion since I´m not sure it would be usefull, is related to inlining C++.
Back on GLBasic, all basic code gets transformed into C++ and you can also inline it if you need.

I´m not really sure this would be of any good here and I don´t know what kind of restrictions one would have creating a Basic for Gamebuino.

Either way, is it done already? ;)

Yay! I can't wait to see what Basic games you all make!
If I have time, there could even be a small compiler *on* the Gamebuino. But it would have to have a way more limited subset of Basic, because the Gamebuino isn't nearly as much as powerful as a normal PC ;)

Well, yeah, the Basic is pretty much the normal basic syntax with some syntax elements of Microsoft's QBasic / QuickBasic / GW-Basic.
I will still add some Gamebuino related commands (we can have up to 255 different commands).

No, it's not yet done (actually I just started yesterday ;) - it's a total rewrite to support a bunch of more features -there were no strings nor arrays nor useful graphic functions before, just plain basic- and to make it fast!). I hope to get it to a useable state until the end of this month.
I am working on it real hard. The compiler already has quite alot of supported statements by now though :)
No, the Basic doesn't get translated into C++, but to something similar to Java. There will be a small Java-like Virtual Machine on the Gamebuino that does execute the so called "bytecode" there. Still, it will have access to most (or all) of the Gamebuino's library functions (LCD, SD, Settings, ...)

About the restrictions, yeah, we only have a starting point of 2KB of RAM. But not even the full RAM is available because of the Variable Jump Table (you get 255 different vars! strings, arrays, uint 8bit - int 64 bit; but they all must be declared before used (at the beginning of the program) and the maximum size needs to be specified. I guess there will only be like 1KB - 1.25KB of RAM available for you. But you can still load directly from SD or write to it. Also I will add support for external RAM (up to 256KB! - the chip only costs around 2€ = 3$).

Re: Gamebuino BASIC VM

PostPosted: Thu May 21, 2015 8:46 pm
by erico
NICE...it dearly recalls those 64kb days with expansion to 128 or 512kb! :)

Well, giving a harder thought about it, I´d say I have some recommendations.
It would be great if you Basic was kind of close to AMOS or GLBasic in a sense that it is geared towards multimedia/games kind of like:
Grafic commands (point, rectangle, line)
bmp commands (For background or tiles)
sprite commands (draw, rotate, scale, collision)
Sound commands (play sound, play music, maybe volume)

Also, the ability to load from SD, but that seems already into it.
Keep us update, if at anytime you have something workable and would like testing, let me know I would be glad to help.
It also seems we have many fronts on people trying to put up a tracker for the gamebuino, to load and play such files would be nice, but I fear they are not yet complete.

Cheers!

Re: Gamebuino BASIC VM (BuinoBasic)

PostPosted: Thu May 21, 2015 9:17 pm
by Muessigb
erico wrote:NICE...it dearly recalls those 64kb days with expansion to 128 or 512kb! :)

Oh yeah. I guess it was a nice time. Retro is just great :)

erico wrote:Well, giving a harder thought about it, I´d say I have some recommendations.
It would be great if you Basic was kind of close to AMOS or GLBasic in a sense that it is geared towards multimedia/games kind of like:
Grafic commands (point, rectangle, line)
bmp commands (For background or tiles)
sprite commands (draw, rotate, scale, collision)
Sound commands (play sound, play music, maybe volume)

Alright, I will implement them all over time :)
Well, but variables still need to be defined with their maximum size and type (because of the way I manage memory alignment).
Oh well. I'm not the best at Basic itself. I used to know QBasic on MS-DOS (although my first computer had WinXP on it, but my dad had an old Laptop with DOS and Basic on it). E.g. I totally forgot that If blocks can have and concernation (but this makes the compiler alot more complicated...)

erico wrote:Also, the ability to load from SD, but that seems already into it.

Yeah, SD support is very important. All compiled files are read (streamed) directly from SD to save RAM.
Basic will of course get SD support too (It can handle byte arrays and read and write from and to the SD).

erico wrote:Keep us update, if at anytime you have something workable and would like testing, let me know I would be glad to help.
It also seems we have many fronts on people trying to put up a tracker for the gamebuino, to load and play such files would be nice, but I fear they are not yet complete.

Alright, I'll do :)
Don't forget to check out my GitHub and my blog.

Cheers!

Re: Gamebuino BASIC VM

PostPosted: Fri May 22, 2015 12:04 am
by Quirby64
Ooh! A BASIC converter? This is great! This and JavaScript are the only two languages of code I can remember enough of to make basic programs from memory. (C and C++, why? :P) :D

If anything I'd like to have the basic BASIC ( :) ) commands for a text adventure (IF, PRINT and the like). I would love to make an actual game for the Gamebuino.