Getting Started with FreeBASIC

From GPWiki
Jump to: navigation, search

This is an excerpt from an article published in QBXL Magazine, with permission by SJ Zero, the author.

Getting started with the software

As of this writing, You can grab fbIDE bundled with FreeBASIC 0.12 from the links above. Install it like you would install any Windows program.

Hello World!

Open up fbIDE and type the following:

PRINT "Hello World!"

Now press F5. Congratulations, you've just seen how much like QB FreeBASIC really is. Now you can use most console commands for QB just like you remember. For example:

LOCATE 10,10
PRINT "I'm the center of the universe!"

The Amazing Screen 13

Now, put "SCREEN 13" before your code, to see how easy it is to use graphics modes:

 PRINT "Hello World!"

From there, all of the standard QB graphics commands work as you remember, as you can see in this example:

 LINE (1,1)-(100,100),1,bf
 PRINT "Hello World!"
 CIRCLE (10,10),10,2
 PSET (30,15),3


FreeBASIC also has new graphics features. For example, QB has never had a screen 14 or greater. Try running this program:

 LINE (1,1)-(100,100),1,bf
 PRINT "Hello World!"
 CIRCLE (10,10),10,2
 PSET (30,15),3


After opening a graphics window via the SCREEN command, you can also hit ALT-ENTER to change between windowed and fullscreen modes.

Another nice feature of the graphics library in FreeBASIC is that you can do page flipping in any video mode. The following code demonstrates this.

There is no exit in this program so you must close the console window to exit the program. This will work for any locked up or otherwise unexitable FreeBASIC program.

 DIM page
 DIM notpage
 DIM a,b

 screen 12, , 2 'This sets the screen for 2 pages
 notpage = 1   'This sets the backpage

  IF page = 0 THEN page = 1 ELSE page = 0   'These two lines flip the page and the
  IF notpage = 1 THEN notpage = 0 ELSE notpage = 1 'backpage
  SCREENSET page, notpage 'This flips the page
  CLS  'First we clear the screen
  b = b + 1 
  IF b > 100 THEN b = 0
  FOR a = 1 TO 128
   PSET (b,a),a 'Then we draw a line. It moves without flickering.
  NEXT a

This works for any mode, so you can use the high resolution modes for your programs with page flipping, using standard QB graphics commands!

Why ASM is Probably Pretty Dead In My Opinion

I wouldn't be saying this if it wasn't true. Using ASM in BASIC to increase the functionality of your program is dead. Ignoring SDL, Allegro, DirectX, OpenGL, et. al. for a minute, you've got the above page flipping and advanced graphics modes at your disposal, as well as inkey$, which we've all grown to love or hate, but there are also two new input commands which do things QBers have had to resort to assembly code to do since the dawn of time:

DIM x,y,buttons
CONST escapeKey = 1
WHILE NOT MULTIKEY(escapeKey) 'this checks the escape key every frame
 GETMOUSE x, y, , buttons 'This gets the mouse state 
 PRINT x,y,buttons   

With this knowlege, you should be able to begin the transition to FreeBASIC, with all the perks that it entails; Speed, power, and portability!