![]() |
Correction to PUT and GET example in QBASIC online help - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html) +--- Forum: QB/FB News (http://qbasicnews.com/newforum/forum-8.html) +--- Thread: Correction to PUT and GET example in QBASIC online help (/thread-9997.html) |
Correction to PUT and GET example in QBASIC online help - Bill Buckels - 06-01-2007 'This source code is herewith released by me into the Public Domain. 'Bill Buckels, May 30, 2007 'You have a royalty-free right to use, modify, reproduce and distribute this 'source code and the binaries that it produces in any way you find useful ' This is a corrected and rewritten example based on the QBASIC manual ' Demonstrating GET, BSAVE, PUT and BLOAD. ' Both the GWBASIC manual and the QBASIC manual presented their ' examples in a confusing manner, with too much or too little information. ' The QBASIC manual further complicated the matter with incorrect calculations. ' Here's a less-confusing example with properly calculated values. ' A BASIC Screen Fragment is stored in a byte array ' Preceded with a header giving the image size. ' Header - 4 bytes ' X - width of image in bits - short integer (2 bytes) ' Y - height of image in rasters - short integer (2 bytes) ' Image data - Variable ' Image data is arranged in rasters. Each raster is byte-aligned. ' In the example below, CGA 4-color screen mode is used. ' Rasters are stored at 2 bits per pixel (4 pixels per byte). ' Since the Cube is 101 pixels wide, 26 bytes are required per raster. ' The last 6 bits (3 pixels) of each scanline are unused (padding) ' Since the Cube is 101 rasters high, image data is 26 bytes x 101 = 2626 bytes. ' The Header requires 4 bytes. ' The array size required to store the image is 2630 bytes. ' Since a short integer is 2 bytes in size and since an integer array is ' required to use the GET and PUT commands, an integer array size of 2630/2 = ' 1315 is required for this example. ' Allocate enough memory in an integer array to hold an image fragment DIM fragment(1315) fragmentSize = 2630 fragmentName$ = "MAGCUBE.PUT" SCREEN 1 ' Create an image fragment GOSUB DRAWCUBE ' Transfer the image fragment into the integer array GET (140, 25)-(240, 125), fragment ' BSAVE ' Point to the the fragment array and BSAVE to disk. DEF SEG = VARSEG(fragment(1)) BSAVE fragmentName$, VARPTR(fragment(1)), fragmentSize DEF SEG ' Restore default BASIC segment. LOCATE 1, 1: PRINT fragmentName$ + " Saved. Press a key to load." KeyPress$ = INPUT$(1) CLS ' BLOAD ' The image fragment's array size is BSaved ' so the BLoad command knows how to re-load it from disk DEF SEG = VARSEG(fragment(1)) BLOAD fragmentName$, VARPTR(fragment(1)) DEF SEG ' Restore default BASIC segment. ' Put the fragment on the screen. ' The fragment dimensions that the GET command stored are now in ' the array, so the PUT command knows the width and height to display PUT (80, 10), fragment LOCATE 1, 1: PRINT "Press a key to end..." KeyPress$ = INPUT$(1) SCREEN 2 SCREEN 0 END DRAWCUBE: ' Draw a white box. LINE (140, 25)-(140 + 100, 125), 3, B ' Draw the outline of a magenta cube inside the box. DRAW "C2 BM140,50 M+50,-25 M+50,25 M-50,25" DRAW "M-50,-25 M+0,50 M+50,25 M+50,-25 M+0,-50 BM190,75 M+0,50" RETURN |