PRB: Image Corrupted When Using BLOAD to Load Into Video Memory (101516)
The information in this article applies to:
- Microsoft Visual Basic for MS-DOS
- Microsoft Cinemania for Windows 1993 edition
- Microsoft QuickBASIC for MS-DOS
- Microsoft MS-DOS operating system 6.0
This article was previously published under Q101516 SYMPTOMS
Using the BLOAD statement to load binary images directly into video memory
from a disk drive that uses either the DoubleSpace disk compressor
(DBLSPACE.BIN) or the SMARTDrive disk cache (SMARTDRV.EXE or SMARTDRV.SYS)
may result in a corrupted image.
CAUSE
The DoubleSpace and SMARTDrive implementations assume they can read back
from memory the same data they write. But because graphics screen memory is
write-only with some video systems, this can yield incorrect data.
RESOLUTION
Here are several possible workarounds:
- Copy the files to a drive that does not use SMARTDrive or DoubleSpace
(such as a RAM drive). Then use BLOAD to load the files from that drive.
- Use BLOAD to load the image into the memory occupied by a temporary
dynamic array. Then move the image to video memory using PEEK and POKE.
This method is slow but it works. For example:
REDIM tmp(0 TO (BitPlaneSize - 1) \ 4) AS LONG ' allocate memory
DEF SEG = VARSEG(tmp(0))
BLOAD f$, VARPTR(tmp(0))
DIM j AS LONG
FOR j = 0 TO BitPlaneSize - 1
DEF SEG = VARSEG(tmp(0))
DIM byte AS INTEGER
byte = PEEK(VARPTR(tmp(0)) + j)
DEF SEG = VideoPageSegment
POKE j, byte
NEXT
REDIM tmp(0) AS LONG ' deallocate memory
- Use BLOAD to load the image into the memory occupied by a temporary
dynamic array. Then move the image to video memory using the Microsoft
C function _fmemcpy. This method is fast, but it requires the correct
version of Microsoft C. For example:
' put the next statement at the module level, all on one line
DECLARE SUB fmemcpy CDECL ALIAS "__fmemcpy" (BYVAL o%, BYVAL s%,
SEG s AS ANY, BYVAL n%)
...
REDIM tmp(0 TO (BitPlaneSize - 1) \ 4) AS LONG ' allocate memory
DEF SEG = VARSEG(tmp(0))
BLOAD f$, VARPTR(tmp(0))
CALL fmemcpy(0, VideoPageSegment, tmp(0), BitPlaneSize)
REDIM tmp(0) AS LONG ' deallocate memory
- To use _fmemcpy in the interpreter environment, create a Quicklibrary named FMEMCPY.QLB by using the following commands:
lib mlibce.lib *fmemcpy.obj;
link /q fmemcpy.obj,,,vbdosqlb.lib mlibce.lib;
- To link an EXE that uses _fmemcpy, use the following command. Use
VBDRT10E.LIB for the run-time module, or VBDCL10E.LIB for stand-alone:
link <objects here>,,,vbdrt10e.lib mlibce.lib;
STATUS
This behavior is by design. It is a limitation of DoubleSpace and
SMARTDrive. Note that DoubleSpace comes with the MS-DOS operating
system versions listed above, and SMARTDrive comes with many Microsoft
products.
Modification Type: | Minor | Last Reviewed: | 8/16/2005 |
---|
Keywords: | kbprb KB101516 |
---|
|