Loading & Drawing BSV files in QBasic

The following is a subroutine from the file BLD.BAS that automatically dimensions an integer (2 byte per element) array to the correct size, by looking at the length of the BSV file (in bytes) and removing the 7-byte BSV header information (see Appendix: the QBasic BSV format). It then loads the BSV file using the normal method.

'Note: the '$DYNAMIC meta-instruction is needed in main program
'for the REDIM command to work
DEFINT A-Z
SUB bld (f$, a())

'get amount of memory needed for a():
bsvnum = FREEFILE
OPEN f$ FOR RANDOM AS #bsvnum LEN = 1

'redimension a() exactly:
REDIM a((LOF(bsvnum)-7) \ 2)
CLOSE #bsvnum

'BLoad the image:
DEF SEG = VARSEG(a(0))
BLOAD f$, VARPTR(a(0))
END SUB

The array can then be drawn on the screen using the QBasic PUT command, or drawn transparently (using color 0) with the following code:

DEFINT A-Z

SUB gPUT (i(), ix, iy)
DEF SEG = VARSEG(i(2))
o& = VARPTR(i(2))

maxx = ix + i(0) \ 8 - 1 '(optimize calc upper x loop)
FOR y = iy TO iy + i(1) - 1
FOR x = ix TO maxx
IF (x >= 0 AND x <= 319) AND (y >= 0 AND y <= 199) THEN PSET (x, y), PEEK(o&)
o& = o& + 1
NEXT x, y
END SUB

For more information about drawing BSV images, see www.qb45.com

If the BSV file was generated using a different palette file than the default screen 13h one, then see the loading PAL files page.

Back to contents page

BSV Babel is copyright Trelsoft freeware.