Q(uick)BASIC Statement: BLOAD
Quick View
BLOAD Statement
A file I/O statement that loads a memory-image file, created by BSAVE, into memory from an input file or device
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- BSAVE filespec$, offset%, length&
- BLOAD filespec$[,offset%]
Description/Parameter(s)
In binary mode, you can read or write information to any byte position in the file using GET or PUT statements.
filespec$ | For BSAVE, a file to which an area of memory (a byte-for-byte memory image) is copied. For BLOAD, a memory-image file created by a previous BSAVE. |
offset% | For BSAVE, the offset of the starting address of the area of memory being saved. For BLOAD, the offset of the address where loading starts. |
length& | The number of bytes to copy (from 0 through 65,535). |
The starting address of the memory area saved or loaded is determined by the offset and the most recent DEF SEG statement.
See also:
Syntax
- BLOAD filespec[,offset]
Description/Parameter(s)
filespec | A string expression containing the file specification. Input devices other than the keyboard (KYBD:) are supported. |
offset | The offset of the address where loading is to start. |
The BLOAD statement allows a program or data saved as a memory-image file to be loaded anywhere in memory. A memory-image file is a byte-for-byte copy of what was originally in memory.
Note: | Programs written in earlier versions of BASIC no longer work if they use VARPTR to access numeric arrays. |
The starting address for loading is determined by the specified offset and the most recent DEF SEG statement. If offset is omitted, the segment address and offset contained in the file (the address used in the BSAVE statement) are used. Thus, the file is loaded at the address used when saving the file.
If you supply an offset, the segment address used is the segment set by the most recently executed DEF SEG statement. If there has been no DEF SEG statement, the BASIC data segment (DS) is used as the default.
If the offset is a single-precision or double-precision number it is coerced to an integer. If the offset is a negative number in the range -1 to -32,768, it is treated as an unsigned 2-byte offset.
Note: | Because BLOAD does not perform an address-range check, it is possible to load a file anywhere in memory. You must be careful not to write over BASIC or the operating system. |
Since different screen modes use memory differently, do not load graphic images in a screen mode other than the one used when they were created.
Also, because BASIC program code and data items are not always stored in the same locations as they were in BASICA, do not use BLOAD with files created by BASICA programs.
Example
This example uses BLOAD to retrieve and display a drawing of a magenta cube inside a box. The BSAVE statement programming example shows how the drawing was created and saved on disk in a file named MAGCUBE.GRH.
'*** Programming example using BLOAD ***
' You must create the file MAGCUBE.GRH using the BSAVE statement
' programming example before you can run this program. This program
' uses MAGCUBE.GRH.
'
DIM Cube(1 TO 675)
' Set the screen mode. The mode should be the same as the
' mode used to create the original drawing.
SCREEN 1
' Set segment to the array Cube's segment and load
' the graphic file into Cube.
DEF SEG = VARSEG(Cube(1))
BLOAD "MAGCUBE.GRH", VARPTR(Cube(1))
DEF SEG ' Restore default BASIC segment.
' Put the drawing on the screen.
PUT (80, 10), Cube
See also:
Syntax
- BLOAD filespec$[,offset%]
Description/Parameter(s)
filespec$ | The file or device from which to load a memory-image file. |
offset% | The offset of the address where loading is to start. |
The argument filespec$ is a string expression that specifies the file or device from which to load a memory-image file.
Usage Notes
- The BLOAD statement allows a program or data saved as a memory-image file to be loaded anywhere in memory. A memory-image file is a byte-for-byte copy of what was originally in memory.
- The starting address for loading is determined by the specified offset and the most recent DEF SEG statement. If offset% is omitted, the segment address and offset contained in the file (the address used in the BSAVE statement) are used. Thus, the file is loaded at the address used when saving the file.
- If you supply an offset, the segment address used is the segment set by the most recently executed DEF SEG statement. If there has been no DEF SEG statement, the BASIC data segment (DGROUP) is used as the default.
- If the offset is a long integer, or a single-precision or double-precision number, it is coerced to an integer. If the offset is a negative number between -1 and -32,768, inclusive, it is treated as an unsigned 2-byte offset.
BLOAD and Expanded Memory Arrays
- Do not use BLOAD to load a file into an expanded memory array. (If you start QBX with the /Ea switch, any of these arrays may be stored in expanded memory:
- Numeric arrays < 16K in size
- Fixed-length string arrays < 16K in size
- User-defined-type arrays < 16K in size
- If you want to use BLOAD to load a file into an array, first start QBX without the /Ea switch. (Without the /Ea switch, no arrays are stored in expanded memory.)
- For more information on using expanded memory, see ⮜ Using Expanded Memory ⮞.
Important
- Programs written in earlier versions of BASIC no longer work if they use VARPTR to access numeric arrays.
- Because BLOAD does not perform an address-range check, it is possible to load a file anywhere in memory. You must be careful not to write over BASIC or the operating system.
- Because different screen modes use memory differently, do not load graphic images in a screen mode other than the one used when they were created.
- Because BASIC program code and data items are not stored in the same locations as they were in BASICA, do not use BLOAD with files created by BASICA programs.
Differences From BASICA
- BLOAD does not support the cassette device.
Example
This example uses the BLOAD statement to retrieve and display a drawing of a magenta cube inside a box. The BSAVE statement programming example shows how the drawing was created and saved on disk. Note: To run this program, you must first create the file MAGCUBE.GRH using the ⮜ BSAVE statement programming example ⮞.
DIM Cube(1 TO 675)
'Set the screen mode. The mode should be the same as the
'mode used to create the original drawing.
SCREEN 1
'Set segment to the array Cube's segment and load
'the graphic file into Cube.
DEF SEG = VARSEG(Cube(1))
BLOAD "MAGCUBE.GRH", VARPTR(Cube(1))
DEF SEG 'Restore default BASIC segment.
'Put the drawing on the screen.
PUT (80, 10), Cube
See also: