Jump to content
  • entries
    34
  • comments
    88
  • views
    25,981

bBasic - Hello World

Sign in to follow this  
Robert M

500 views

For my first bBasic program I choose to stay with tradition and write a Hello World program. For non-programmers reading this, there is a bit of a tradition in programming with a new language to start with a simple program that simply outputs "Hello World" to the user.

 

Goals:

-> Minimal source code size

-> Simple white text on a black background.

-> no user interaction.

 

Design:

-> Use the standard bBasic kernel to render an asymetrical playfield image of "Hello World". The 32 pixel resolution requires a less than pretty font to show 10 characters, but that is a problem common to all VCS programs and not exclusive to bBasic.

 

Implementation:

helloworld.txt

 

helloworld.txt.bin

 

Lessons learned:

-> Remarks need to be indented! ;)

-> Labels can not be followed by a colon like in DASM.

 

Recommendations for improving bBasic:

-> Looking at the .asm output from the compiler I see that the entire language library is included even if I never use most of the functions. Randomize for example and all the PF scroll functions are included in the image even though I didn't use them. I understand why this was done, but it would greatly reduce ROM consumption if unused functions were not included leaving more room for user defined code.

 

Up Next:

-> Can we do PF height animations?

Sign in to follow this  


3 Comments


Recommended Comments

-> Looking at the .asm output from the compiler I see that the entire language library is included even if I never use most of the functions. Randomize for example and all the PF scroll functions are included in the image even though I didn't use them. I understand why this was done, but it would greatly reduce ROM consumption if unused functions were not included leaving more room for user defined code.

The entire library isn't included (math routines need to be manually included, not unlike other languages) but yes, the random number generator, pfscrolling and plotting are by default whether they are used or not. But it's easy to change this.

 

To build a binary without these files, you can make a custom includesfile. The 4k standard kernel uses default.inc, so just copy that to your current directory and edit it, commenting out the libraries you don't want. Or if you prefer, you can rename the includesfile to something else and place " includesfile name.inc" at the beginning of your program.

Share this comment


Link to comment
Recommendations for improving bBasic:

-> Looking at the .asm output from the compiler I see that the entire language library is included even if I never use most of the functions. Randomize for example and all the PF scroll functions are included in the image even though I didn't use them. I understand why this was done, but it would greatly reduce ROM consumption if unused functions were not included leaving more room for user defined code.

bB uses an includes definition file-- called "default.inc"-- that lists the files it should include when it's compiling your bB code into assembly. In the past, if you wanted to modify that file, you had to save a backup of the original (always a good idea, unless you don't believe in that sort of thing), then edit the file to delete the include files you don't want, add more include files that you've written, or change the names so bB will use any modified include files you've created.

 

However, you don't need to do that anymore with bB v1.0, because now there's an "includesfile" bB statement that you can use. Oh, you still need to make your own includes definition file, typically by copying one of bB's (it actually uses more than one, depending on which kernel you use-- standard or multisprite-- and whether or not you use bankswitching), and then editing it as you see fit. But you no longer have to back up the original and use the filename of the original for your custom file. Instead, you can just copy the original to a new name, modify it, and then use the "includesfile" statement in your bB program to tell bB to use your file instead of the normal file. That way, you can still compile all of your programs that use the normal files, plus the programs that use your customized files, without having to remember to juggle around with renaming the files back and forth.

 

Anyway, you can easily create an includes definition file that will include only the files you want, which lets you omit any bB "system routines" that you won't be using in your program. This can be a little tricky if you aren't careful, since some routines may call other routines. But it shouldn't be difficult for an experienced programmer to do. Also note that some include files are essential-- in particular, the header and footer files-- although of course you can customize them as well.

 

If I remember correctly, when I started tinkering with my E7-bankswitched "Sudoku" WIP game a while back, I used a custom includes definition file that basically did away with *all* of bB's include files, so I could just use my own, since I was using my own kernel instead of bB's kernel, and I wanted to define my own RAM usage, etc. So when I compile my "Sudoku" game that way, I can still use most of bB's high-level statements, but the entire ROM contains just my own code and custom includes. I posted all of my code, along with the custom include files, so you're welcome to look at it and see what I did. A word of warning, though-- you might have trouble compiling it under bB v1.0, since it was written under bB v0.35, and I haven't updated it yet to bB v1.0. But it can still serve as an example of how to write a bB program using a completely stripped-down includes definition file.

 

Up Next:

-> Can we do PF height animations?

If your playfield is in RAM, you can do PF animation using the PF drawing commands. You can also change the heights of the PF rows, and (if you aren't using pfheights and pfcolors together) you can define multiple tables of PF heights, so that you can flip between different tables from frame to frame, making selected rows grow or shrink. Is that what you mean?

 

Michael

Share this comment


Link to comment
-> Looking at the .asm output from the compiler I see that the entire language library is included even if I never use most of the functions. Randomize for example and all the PF scroll functions are included in the image even though I didn't use them. I understand why this was done, but it would greatly reduce ROM consumption if unused functions were not included leaving more room for user defined code.

The entire library isn't included (math routines need to be manually included, not unlike other languages) but yes, the random number generator, pfscrolling and plotting are by default whether they are used or not. But it's easy to change this.

 

To build a binary without these files, you can make a custom includesfile. The 4k standard kernel uses default.inc, so just copy that to your current directory and edit it, commenting out the libraries you don't want. Or if you prefer, you can rename the includesfile to something else and place " includesfile name.inc" at the beginning of your program.

 

Thanks for the tip!

Share this comment


Link to comment
Guest
Add a comment...

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