GBUF

Introduction

All drawing operations operate on a 768 byte buffer in memory. This buffer is copied to the screen after every drawing operation providing that *REFRESH has not been switched OFF.

You may wish to create multiple screen buffers and switch between them when your program is running. Switching display buffers is extremely fast; you can perform a slow, complex series of drawing operations once, swap out the buffer then recall it in an instant when required.

Usage

*GBUF takes an optional argument that specifies the address of the buffer in hexadecimal:

*GBUF addr

If you do not pass an argument to *GBUF the buffer address is reset to BBC BASIC's internal buffer.

10 HIMEM=HIMEM-768:buf%=HIMEM : REM Allocate 768 bytes at the end of memory.
20 OSCLI"GBUF"+STR$~buf%      : REM Set this buffer as the current graphics buffer.
30 :
40 CLS:PRINT "Hello, World!"  : REM Drawing operations now act on this new buffer.
50 WAIT 500                   : REM Wait 5 seconds.
60 :
70 OSCLI"GBUF"                : REM Revert to the original internal buffer.
80 HIMEM=HIMEM+768            : REM Move HIMEM back up to its original position.

Warning

All drawing operations operate on the graphics buffer that you have specified, even after program termination. You must ensure that the buffer is in a safe place - preferably the internal buffer - when your program has terminated. The following code

10 DIM buf% 767
20 OSCLI"GBUF"+STR$~buf%

allocates 768 bytes on the heap (which starts immediately after the end of the program in memory) for use as a secondary buffer. If more lines were added to the program after running the above code it would grow into the area that used to be the heap and so into the area that contains the active graphics buffer. As this buffer is still being used any changes to it will also corrupt the program, resulting in a Bad program error.

The safest way to allocate memory is to move HIMEM down as BBC BASIC will not touch memory above HIMEM; to free the memory at the end of your program first invoke *GBUF without any arguments to revert to the internal buffer then move HIMEM back up.

Syntax

*GBUF [addr]

See Also