LBB
LB Booster
LB Booster is a new utility for Liberty BASIC
programmers. With LBB you can:
- Speed up a Liberty BASIC program by up to ten times.
- Compile a Liberty BASIC program to a compact, standalone executable.
- Overcome many of Liberty BASIC's bugs and limitations.
LB Booster is Freeware;
you are strongly encouraged to purchase the full version of Liberty Basic on which to develop,
test and debug your programs prior to 'boosting' them.
Here are some examples of the benefits offered by LB Booster:
- Speed is typically improved. For example the ELAPSED.bas program supplied with LB
reported an execution time of approximately 2400 milliseconds under LB4 and 230 ms under LBB
(more than ten times faster) and the SIEVE2.bas program ran in about 250 ms under
LB4 and 40 ms under LBB (more than six times faster).
- Executables are much smaller. For example the supplied example program ContactMgr424.bas,
when compiled with LB4 (using the Create Application menu selection), created ten files totalling over
2.8 Megabytes. The same program compiled using LBB created a single file executable
of 118 Kilobytes (approximately 24 times smaller).
- Compiled executables include the necessary manifest to make them fully Vista,
Windows 7 and Windows 8 compatible.
- Compiled executables are much more secure. The TKN files generated by LB4 are easily reverse-engineered to
recover the BASIC program, and even your LB User Name and Password!
- LBB and its executables run successfully even if DEP (Data Execution Prevention) is enabled.
- You can change the printer font within a page. If you assign a new value to
PrinterFont$ it will immediately affect subsequent output with LPRINT, allowing you
to mix different fonts and styles (e.g. bold) on the same sheet.
- You can change the current printer (used by LPRINT and the graphics command 'print') by setting
PrinterName$ to the name of the printer, e.g. PrinterName$ = "DoPDF v7".
- The PRINTERDIALOG works correctly.
- The FILEDIALOG does not impose a path
length limitation of 128 characters and the 'tooltips crash' doesn't occur.
- A new statement PAGESETUPDIALOG is implemented. This displays the standard Page Setup
dialogue box, which allows the user to select the margins and paper orientation (portrait or landscape) that
will be used by a subsequent LPRINT.
- Graphics 'stick' (i.e. automatically get redrawn when a window is restored or uncovered)
without any extra effort by the programmer.
- The TEXTEDITOR control can be configured for word-wrap using STYLEBITS (LB4's TEXTEDITOR
does not support word-wrap at all).
- The unary minus is supported. For example the statement 'y = –x' is valid in LBB.
- USING() supports a much wider range of options than the LB4 version, including trailing minus, leading or trailing plus, leading asterisks, currency ($ and £), thousands separated by commas
and scientific notation.
- DATE$ can return the date in many additional formats, such as European day-month ordering,
hyphen delimiters or the month as an abbreviation. For example
PRINT date$("dd/mm/yyyy") or PRINT date$("dd-mmm-yyyy").
- Array elements and structure members can be read directly from a DATA statement, e.g. READ array(i),
and can be passed by reference to SUBs and functions.
- An entire array may be passed as a parameter to a function or subroutine, making it possible to
write general-purpose routines which operate on the contents of any specified array.
- LOADBMP accepts a wider range of BMP files than LB4, including files created by Photoshop and GIMP.
- The HWND(#handle) function has been extended to work with files and communication
ports as well as windows. It returns the native Windows file handle, making it possible to use
file-related API functions on files opened in LBB.
- The background colour of (for example) a STATICTEXT control may be selected independently
of the background colour of its parent window, by changing the value of the BackgroundColor$
variable in between.
- EXIT can exit from nested loops. For example if a FOR...NEXT loop is nested inside a DO loop,
an EXIT DO used within the FOR...NEXT loop will exit both loops.
- SPRITECOLLIDES works correctly when one or both sprites have been scaled,
centered, or have an offset applied.
- Sprites can have a linear transparency (alpha mask), allowing the background to show through to varying
degrees.
- Unicode text is supported in the mainwin and when outputting to the printer using LPRINT.
There is also partial support for displaying Unicode in a GUI control, with the help of some API code.
- Anywhere you can specify a colour using one of the preset names (e.g. "brown") you can alternatively
specify it using an RGB value (e.g. "0 127 200"). LB4 doesn't allow you to set a GUI colour (e.g.
BackgroundColor$) that way.
- OPEN can open a parallel port (e.g. open "LPT1:" for output as #lpt), for example in
order to send data to a printer that does not have (or need) a printer driver.
- Alt-key shortcuts (access keys) for pushbutton controls are correctly underlined when
the Alt key is pressed. In LB4 this works for menus, but not for buttons.
- A window of type WINDOW can have a default button (which is 'pressed' when you use the Enter key).
In LB4 only a window of type DIALOG can have a default button.
- MAPHANDLE can be used with child controls as well as with windows. This allows, for example,
the creation of multiple child controls in a loop, something you cannot normally achieve in LB4.
- A TEXTEDITOR control can be used in a DIALOG window, allowing entry of multi-line
text (the Enter key moves the cursor to the next line rather than activating the 'default' button).
- The GETBMP command can 'see' graphics which are outside the currently
visible window, so if you have a scrollable graphics window you can get its entire contents into a bitmap.
- The !contents? command also works with STATICTEXT controls.
- The TIMER statement can specify a subroutine to be called, instead of a label. This
option does not work correctly in LB 4.04.
Create a suitable directory (e.g. C:\Program Files\LBB\) and copy the
LBB.exe file there. You will need administrative privileges to copy the file
and when you execute it for the first time (in Windows Vista™,
Windows 7™ and Windows 8™ use Run
as administrator); however it can be run from a normal user account thereafter.
You can, if you wish, create a desktop shortcut to the program by right-dragging
the LBB.exe file to your desktop and selecting 'Create shortcut here' from
the menu that appears when you release the mouse button. You can create a shortcut
in your Start Menu in a similar way.
LBB requires Windows 2000 or later. It is not compatible with Windows 95, Windows 98 or Windows Me.
Sprites require a CPU with 'integer SSE' support, i.e. an Intel Pentium III or an AMD Athlon or later.
Although LBB can successfully boost most Liberty BASIC 4 programs, there
are a few incompatibilities, including:
- There are no graphics segments; the 'delsegment' and 'segment' commands
are ignored. However, on the plus side no special measures are required to make
graphics 'stick'; if your program suffers from this problem under LB4 it won't when
run under LBB!
- LBB does not support arbitrary precision arithmetic; integers (whole numbers) are limited
to the range
–18,446,744,073,709,551,615 to +18,446,744,073,709,551,615.
Values outside this range will be stored as floating-point numbers and accuracy may suffer.
In addition, the bitwise operations
AND, OR and XOR work only with 64-bit integer values.
- The EVAL function works only with simple expressions containing 'standard' BASIC
functions, and may fail if the expression contains variable names starting with a keyword.
EVAL doesn't work if the expression contains a structure member.
- The string collation order is different, affecting SORT and string comparisons. However,
LBB uses the conventional ASCII character sequence which is likely to be what you expect.
- Handle variables are assumed always to refer to windows, not to files or other
devices.
- When printing a window, the resulting quality on the printer is no better than it is on the
screen.
- The size of the 'canvas' onto which you can draw in a graphics box is limited (the width is
limited to the width of your screen display). You can increase it using the horizscrollbar
and/or vertscrollbar commands.
- The mainwin can hold only about 84 lines of text; if more lines are output the remainder
will be 'scrolled off' the top of the window and lost. Also, the mainwin has no menu. You can copy
the contents of the mainwin onto the clipboard by typing Ctrl+Tab.
- The ComboboxColor$ variable affects the border of the combobox, but not the background
colour of the actual items listed. This is a limitation of the Win32 API.
- If one of the keypad number keys is pressed, two 'when characterInput' events are
generated. One is the regular event that LB4 generates, and the other is a 'special key' event (LEN(Inkey$)=2).
This make it possible to distinguish the keypad from the regular number keys.
- The syntax for serial port parameters is slightly different. The basic options are
the same, so for example this works:
open "COM1:9600,n,8,1" for random as #comm
but when specifying 'handshaking' parameters the syntax accepted by LBB is as follows:
open "COMn: [baud=b] [parity=p] [data=d] [stop=s]
[to=on|off] [xon=on|off] [odsr=on|off] [octs=on|off]
[dtr=on|off|hs] [rts=on|off|hs|tg] [idsr=on|off]"
A full description of these parameters can be found
here.
- Logical operators have the conventional precedence: AND is evaluated before OR; this is different from LB4. If necessary add brackets (parentheses) to force the required order of evaluation.
- In a single-line IF statement LBB may behave differently from LB4 if there are multiple (cascaded) IFs and an ELSE clause. To resolve this recast the code as nested multi-line IFs.
-
RESUME resumes execution at the line (not statement) where the error occurred; if
in doubt use only one statement per line. Also, RESUME must be used within the scope of the SUB
or FUNCTION (if any) in which the error occurred.
- Opening a file in BINARY mode does not prevent PRINT outputting a newline (CRLF).
To suppress the newline add a trailing semicolon (;) to the PRINT statement; this will not affect the operation
of the program in LB4.
In general, LBB may not always tolerate coding errors or weaknesses even if Liberty BASIC itself does. However in the case of an
incompatibility from this cause it will usually be possible to modify the program so that it works under LBB
as well as LB4. See Troubleshooting for some examples.
If, exceptionally, the only way to achieve compatibility is to use different code for LB4 and LBB you can test which
platform your program is running under as follows:
if instr(Platform$, "LBB") then
print "Running under LBB"
else
print "Running under LB"
end if
When you start LBB you are presented with a conventional window containing
the normal features which make up the Windows™ Graphical User Interface:
a title bar, a set of drop-down menus,
a toolbar and a status bar.
The main part of the screen is an editing pane in which the BASIC program
appears and can be edited. This pane can be scrolled horizontally and vertically as necessary.
LBB will accept parameters on the command line in a similar fashion to Liberty BASIC.
If a filename is specified, it is automatically loaded; this allows you to drop
a .BAS file onto the LBB icon, or to associate the .BAS file extension with LBB.exe.
The following command line switches are accepted:
| -R | Run a BAS file on startup |
| -T | Translate and tokenise a BAS file to an LBB file |
| -C | Translate and compile a BAS file to an EXE file |
| -A | Automatically exit LBB on completion |
| -M | Minimise LBB on startup |
Examples:
LBB program.bas (loads the program)
LBB -R -A -M program.bas (runs the program)
LBB -T -A -M program.bas (generates program.lbb)
The title bar contains the name of the application and its version number,
the name of the current BASIC program (or 'untitled' if the New
command has been issued), a minimise button, a maximise button
and a close button. If you right-click in the title bar you will get a
context menu containing the Restore, Move, Size,
Minimize, Maximize and Close items.
The menu bar contains the drop-down menus
File, Edit, Run,
Options and Help. These menus
may be activated by clicking on the appropriate menu name or by using a
keyboard shortcut (hold down Alt and press the key corresponding to the underlined
character). When a menu is opened a brief description of the highlighted item is
displayed in the status bar. Menu items are 'greyed
out' if they are not functional in the current circumstances.
The toolbar provides easy access to the most common commands, without
having to select them from the drop-down menus, simply by clicking
on the appropriate button. The commands for which buttons are provided are as follows:
From the File menu: New,
Load, Save and Print.
From the Edit menu: Undo, Cut,
Copy, Paste, Find and
Replace.
From the Run menu: Run Program
and Make Executable.
Toolbar buttons are 'greyed out' if they are not functional in the current circumstances.
When a menu item is highlighted, the status bar displays a brief description of
the function of that command. Otherwise, the status bar displays the version number
and copyright information for LB Booster.
At the right-hand end of the status bar is displayed the number of the line containing the
text cursor (caret), starting at line 1. This can be useful in locating the line which is responsible
for a run-time error (the error message usually includes a line number).
The File menu contains the items New, Load,
Save, Save As, Page
Setup, Print, Recent files and Exit.
The File menu can be accessed by clicking on its name in the menu bar
or by means of the keyboard shortcut Alt-F.
The New command (keyboard shortcut Ctrl+N) deletes the current BASIC program from
memory, giving you a 'clean sheet' into which to load, paste or type a new program. If the current
program has been modified and not saved, you are first prompted to save it.
The Load command (keyboard shortcut Ctrl+L) loads a Liberty BASIC program into memory.
The file must be in plain text (ASCII) format and should ideally have been tested on, and
saved from, the full version of Liberty BASIC
to ensure it does not contain any syntax errors. The file will normally have the extension .BAS.
If the current
program has been modified and not saved, you are first prompted to save it.
The Save command (keyboard shortcut Ctrl+S) saves the current BASIC program,
replacing the original file; it is enabled
only if the program has been modified since it was loaded. If you have made changes which might be
incompatible with Liberty BASIC 4 you are advised to save the program under a new name (see
Save As below).
The Save As command saves the current BASIC program under a new name, or in a new location.
It is useful for making a backup copy, or to avoid modifying the original program if a change has been
made which might be incompatible with Liberty BASIC 4.
The Page Setup command allows you to configure the paper size, orientation (portrait or
landscape) and margins used when you print out the BASIC program. You can also use
this command to select a different printer.
The Print command (keyboard shortcut Ctrl+P) creates a hardcopy printout of the current
BASIC program.
The nine most-recently loaded programs are listed, and can be re-loaded simply by clicking
on the appropriate entry or by using the keyboard shortcut Alt-F followed by the digit 1 to 9.
When one of the entries is highlighted, the full pathname of the file is displayed in the Status Bar.
If the previous program was not saved, you are first prompted to save it.
The Exit command quits from LB Booster and closes its window. If modifications
have been made to the program and not saved, you are first prompted to save it. If BASIC programs
are still running (and therefore using up Windows resources and potentially wasting CPU time) you
are prompted to terminate them.
The Edit menu contains the items Undo, Cut,
Copy, Paste, Delete,
Select All, Find,
Find Next and Replace.
The Edit menu can be accessed by clicking on its name in
the menu bar or by means of the keyboard shortcut Alt-E.
The Undo command (keyboard shortcut Ctrl+Z) reverses the effect of the last editing operation.
Multiple operations can be undone.
The Cut command (keyboard shortcut Ctrl+X) transfers any selected text to the clipboard, and
deletes it from the program. If no text is selected, the Cut command is inhibited.
Once the selected text is in the clipboard, you can Paste
it either elsewhere in your BASIC program or into any other application which
supports pasting of text from the clipboard. Any previous contents of the clipboard
are discarded. Selected text is highlighted in reverse-video.
The Copy command (keyboard shortcut Ctrl+C) transfers any selected text to the clipboard,
but unlike Cut it leaves the text in the BASIC program.
If no text is selected, the Copy command is inhibited.
Once the selected text is in the clipboard, you can Paste
it either elsewhere in your BASIC program or into any other application which
supports pasting of text from the clipboard. Any previous contents of the clipboard
are discarded.
The Paste command (keyboard shortcut Ctrl+V) inserts the contents of the clipboard into
the BASIC program at the current position of the text cursor (caret).
If the clipboard contains no text, the Paste command is inhibited. You
can use Paste to transfer a block of code from elsewhere in your BASIC
program, or to insert a block of code which has been placed in the
clipboard by any other application.
The Delete command deletes any selected text, without copying
it into the clipboard. Text which is deleted can only
be recovered by using the Undo command.
The Select All command (keyboard shortcut Ctrl+A) selects the entire BASIC program.
It is useful if you want to transfer the program into another application (e.g. a word processor) via the clipboard
The Find command (keyboard shortcut Ctrl+F) allows you to search your program for
the occurrence of some specified text. The command opens the Find dialogue box
into which you can type the text you wish to search for. You can also specify whether
the case (capitals or lower-case) is significant and whether to match only an entire
word. The search begins at the position of the text cursor (caret) when the Find command
was issued. If you want to search the entire program, ensure that you move the cursor
to the start of the program before issuing the command.
Once the Find dialogue box has been dismissed, you can
continue to search for the next and subsequent occurrences of the search string
by using the Find Next command or by pressing F3. If the text
is not found before the end of the program the message "Text not found" is
displayed; selecting Find Next again causes the search to restart from the beginning
of the program.
The Replace command (keyboard shortcut Ctrl+R) allows you to search your program for
the occurrence of some specified text and then, optionally, replace it with some
different text. The command opens the Replace dialogue box
into which you can type the text you wish to search for and the text you want it to
be replaced with. The search begins at the position of the text cursor (caret) when the Replace command
was issued.
The Run menu contains the items Run Program,
Make Executable and Kill BASIC Programs. The Run
menu can be accessed by clicking on its name in the menu bar
or by means of the keyboard shortcut Alt-R.
The Run Program command firsts 'boosts' (translates) the current BASIC program
and then runs it. If an error occurs during the translation process, a message is reported
and the process is aborted (once the error message is dismissed the line which resulted
in the error is highlighted). If the program has already been translated, it is simply run.
If no program is loaded, the command is inhibited.
The Make Executable command firsts 'boosts' (translates) the current BASIC program
(if necessary) and then 'compiles' the program to a compact, standalone executable file (typically less
than 150 Kbytes in size). The executable may run a little faster than when using the
Run Program command. If no program is loaded, the command is inhibited.
You are prompted to supply a filename and location for the executable; by default it will be stored
in the same directory as the Liberty BASIC program but with the extension '.exe'. LBB incorporates
a manifest in the executable, to enable the use of Windows XP Visual Styles
and improve compatibility with Windows™ Vista, Windows™ 7 and Windows™ 8.
The program's icon may be changed by clicking on the Change Icon button in the dialogue box.
You can select an icon either from an existing executable file, or from a separate icon file (for example
as produced by an icon editor). If the file contains a number of different icons, you can select the one
you want to use. Please respect Copyright, and use only an icon which you have generated yourself
or have legitimately obtained for this purpose.
If the selected icon contains multiple variants with different resolutions (e.g. 16x16, 32x32, 48x48)
and/or different colour depths (e.g. 8 bits, 32 bits) all the variants will be stored in the compiled
executable file. The version used will be the one most suited to the current display settings.
Note that such an icon can significantly increase the size of the executable.
You can edit the Version Information which will be embedded in the executable. There are three
checkboxes (Debug, Patched and Prerelease) and eight text fields. Two
of those fields (File version and Product version) are expected to contain a
numeric version number in the format n.n.n.n (e.g. 5.94.123.678); if you use a different format a
warning is issued but the creation of the executable proceeds normally.
The Kill BASIC Programs command terminates any BASIC programs which are still executing
in memory after having been run during this LBB session. If a BASIC program doesn't
properly exit (e.g. because of omitting a TRAPCLOSE command) it may have no visible window
yet be using up Windows resources and CPU time. If no programs are still running, the command is
inhibited.
In the current version of LBB you cannot choose which programs to kill.
The Options menu contains the items Show LBB Pane,
Emulate Slicing, Unicode Support,
Set Font and Set Printer Font. The Options
menu can be accessed by clicking on its name in the menu bar
or by means of the keyboard shortcut Alt-O.
The Show LBB Pane command alternately enables and disables a 'split window' mode
in which the original Liberty BASIC program is displayed in the left-hand pane and the translated
program is shown in the right-hand pane. This may be useful for diagnostic purposes
or simply for interest.
The Emulate Slicing command alternately enables and disables the full emulation
of Liberty BASIC's LEFT$, MID$ and RIGHT$ functions when the
length parameter is negative. In that case LB4 returns an empty string.
Since emulating the negative-length case significantly slows execution of the functions, and
since very few programs rely on this behaviour, it is not enabled by default.
The Unicode Support command alternately enables and disables partial support for
Unicode output. When this option is selected foreign-alphabet literal strings may be included
in a program, and will display correctly in the mainwin and when output to a printer using LPRINT.
Unicode strings may also be displayed in GUI controls (except TEXTBOX and TEXTEDITOR
controls), with the assistance of a little API code.
The Set Font command selects the font used to display the BASIC program on
the screen. The default is the System Fixed Font (FixedSys).
The Set Printer Font command selects the font used when a hardcopy printout of the
BASIC program is generated.
The Help menu contains the items Help Topics,
Email, Website, Discussion
Group, Message Board, Wiki and
About LB Booster. The Help menu can be accessed by clicking on its
name in the menu bar or by means of the keyboard shortcut Alt-H.
The Help Topics command (keyboard shortcut F1) displays this Help documentation.
The Email command opens your default mail program (if any) so that you can send
a message to request help or information about LB Booster.
The Website command opens your default web browser (if any) and automatically
directs it to the LB Booster home page.
The Discussion Group command takes you to the LBB Yahoo!™ group, where you
can seek help and advice, report bugs, download (or upload) useful utilities and learn about
new developments in LB Booster.
The Message Board command takes you to the LBB Conforums message board, where
you can take part in discussions about LB Booster.
The Wiki command takes you to the LB Booster Wiki, where you will find articles on all
aspects of using LBB.
The About LB Booster command displays information about LBB,
including the version number and copyright information.
Here are some hints for how to get the best from LB Booster:
- Be careful with the order in which you issue graphics commands. For example this works
in LB4 but not in LBB:
#main.df, "Discard"
#main.df, "Getbmp BitmapName 0 0 240 100"
#main.df, "Drawbmp BitmapName 0 0; Flush"
Changing the code to this makes it work properly with both LB4 and LBB:
#main.df, "Getbmp BitmapName 0 0 240 100"
#main.df, "Discard"
#main.df, "Drawbmp BitmapName 0 0; Flush"
- Compatibility with LBB may be impaired if you draw graphics using the Windows API, without
periodically executing a wait statement. For example, rather than calling the Sleep API
(or simply having an 'infinite loop' containing a scan statement) use a
timer/wait combination:
timer 40, [loop]
wait
[loop]
' do the graphics drawing here
wait
- If you receive the error message 'Bad use of array' check that your program doesn't
attempt to access an array before it is DIMensioned. This code, taken from FreeForm404.bas,
runs (but doesn't do anything useful) under LB4, but LBB reports an error:
font$(1)=dFont$
...
dim font$(3)
- If you receive the error message 'Handle used for incompatible devices' it means you
have used the same handle name for both a file and a window (or a DLL and a window, etc.). LBB
needs each handle name to refer to only one kind of device. To fix the problem change one of the handles.
- If you receive the error message 'Duplicate structure with ambiguous member' it means
you have used the same name for two different STRUCTs, which share a member having
the same name but a different type. To fix the problem change one of the structure or member names.
For those who may be interested, here is a technical description of how LB Booster works.
LBB is a hybrid translator and emulator. The translator automatically converts
Liberty BASIC syntax to the equivalent
BBC BASIC syntax. This translation takes place when
you first issue the Run Program or Make Executable
command.
The emulator (LBLIB) implements at run-time those aspects of Liberty BASIC which aren't part
of the standard BASIC language and which have no direct equivalent in BBC BASIC; principally these are the
Graphical User Interface elements (windows, controls, graphics and sprites). The emulator is
itself written in BBC BASIC.
When you issue the Make Executable command LBB creates a single-file
standalone executable containing the BBC BASIC for Windows run-time engine, the LBLIB emulator
and a tokenised/compressed version of the translated BASIC program.
LB Booster is thought to be free from serious bugs, and it is highly unlikely that
it could do any harm to other software or systems. However there is NO warranty that it
will not and its use is at your own risk.
LB Booster is the Copyright © 2013 of R. T. Russell.
BBC BASIC for Windows is the Copyright © 2001-2012 of R. T. Russell.
The name BBC BASIC is used with the permission of the British Broadcasting Corporation.
Liberty BASIC is the trademark of Carl Gundel trading as Shoptalk Systems.
The aPLib compression library is used
with permission. Copyright © 1998-2009 by Joergen Ibsen, All Rights Reserved.
©
Richard Russell 2013