Frage deutsch
~~~~~~~~~~~~
Wie kann ich Grafikelemente mit BSAVE/BLOAD bearbeiten?
 

Question English
~~~~~~~~~~~~~~
What's this BLOAD/BSAVE stuff used with images?
 

Antwort 1
~~~~~~~~
[ von Thomas Antoni, 9.5.02 ]
 
Über Grafikbearbeitung mit BSAVE/BLOAD kannst Du Vieles in dem englischen "QBasic-Tutorial" von Mallard (alias David Zohrob) lernen. Download auf http://www.qbasic.de in der QBasic-Tutorial Rubrik.


Answer 2
~~~~~~~~
What's this bload stuff used with images?
The BLoad function in Qb is quite powerful indeed... it allows you to load much data in, quickly... so how to use it with an image? Well, first we need to save it, let's say it was made with the tile editor n!Media, that's bsave format. Then we need to load it in... Make an array for it, bload, and pow. It's ready to be Put.
 
DIM SHARED Tile(201) ' For 20x20 tile
DEF SEG = VARSEG(Tile(0))
BLOAD "tile.mdt", VARPTR(Tile(0))
 
This sets the array for the tile, then we define segment at Tile(0)) (Loading starts at 0), then we bload, and just for good
measure, point it to Tile(0).


Answer 3
~~~~~~~~
Where can I find a graphics program using the BSAVE format?
Be sure to check out the graphics utility section of QCity for a handful of editors. I also have my own editor, available in QCity².
 

Answer 4
~~~~~~~~~
[ Autodemo by Jesse Dorland ]
 
'**********************************************************************
' BSAVE_1.BAS = Autodemo for BSAVE and BLOAD
' ===========
' BSAVEing arrays and BLOADing to arrays in QBasic/QuickBASIC
' (c)Jesse Dorland
'**********************************************************************
SCREEN 13
RANDOMIZE TIMER
'$DYNAMIC
'Now we dimension the array we're going to be using. For this
'code, we're only going to be saving a 50x50 square.
DIM Array%(1252)
'In order to BSAVE our array, we have to tell QBasic/QuickBASIC where
'the array is in memory. This next line will set the memory segment
'to the beginning of where Array%() is in memory
DEF SEG = VARSEG(Array%(1))
'Now we want to draw something on the screen. Since we're only saving
'a 50x50 square, we won't draw on the whole screen.
PRINT "Press any key to stop drawing"
DO UNTIL LEN(INKEY$)
'Draw a pixel within a 50x50 box
PSET (50 * RND + 50, 50 * RND + 50), 255 * RND + 1
LOOP
'Make our doodle a box
LINE (50, 50)-(99, 99), 15, B
'Get our box into an array
GET (50, 50)-(99, 99), Array%(1)
'Now comes the BSAVE part. Here, we're going to save the
'entire array to a file called "BOX.SAV." We've already told QBasic/
'QB where in memory Array%() starts. Now we've got to tell BSAVE how
'many bytes after that we want to skip before starting to save. We'll
'use VARPTR for that. The reason you see "1252*2" below is because
'an integer is two bytes. Array% is an integer array, which means each
'element holds two bytes. Without the * 2, only half the box would be
'saved.
BSAVE "BOX.SAV", VARPTR(Array%(1)), 1252 * 2
'Reset the memory segment.
DEF SEG
'
'Great! Now the box is saved to disk. A loading routine follows.
CLS
'Erase Array%() just to show that the box is on disk and we're not
'using the copy that's in memory anymore.
ERASE Array%'Dimension the array we'll use to hold the box.
DIM Box%(1252)
'
'We have to tell QBasic/QB where to start loading
DEF SEG = VARSEG(Box%(1))
'
'Now we BLOAD the box into the array. Again, we use VARPTR to tell
'BLOAD what byte position to begin loading to.
PRINT "Press a key to load and display."
A$ = INPUT$(1)
BLOAD "BOX.SAV", VARPTR(Box%(1))
'
'Display the box onscreen to prove that we've loaded it.
PUT (50, 50), Box%(1), PSET
'
'Delete the box file
KILL "BOX.SAV"
 
This programm is available in the Progs\ directory and online under www.antonis.de/faq/progs/bsave_1.bas .
 
 

Answer 5
~~~~~~~~~~
[ This Article From Peter Cooper's "The BASIC Fanzine" ]
_________________________________________________
SECTION 1 PART B SUBPART 2 | Graphics tips and tactics |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This article is by James Erickson, he can be reached at:
ericksnj*teleport.com
For how long I don't know.. he changes email address a lot. 8-)
Cheers, James 8-)
 
Have you ever wanted to save a graphic in BASICs Screen 13. Or more
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
importantly load one quickly? Well its easy! Here's how...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First you'll need to draw something on the screen.. It doesn't matter
how. Then you need to save it. The first step is to point to the
segment of the video address. Then you want to bSAVE the graphic:
 
DEF SEG=&HA000
BSAVE "filename",0,64000
 
64000 will save the entire screen. So use that to save an entire screen.
It works sort of like Peter Coopers putpixel. Just multiply the y value
by 320 and the x value and add by one. So if you only wanted to save the
upper half of the screen it would be ((y*320)+x)+1. In this case y would
be 99 and x would be 319. The reason you need to add by one is when you
are saving the graphic it thinks of (0,0) as 1 instead of 0. So that means
you have to add the entire thing by one. So once again here is the equation:
((Y*320)+X)+1
 
The parenthesis are not really needed, but they are good to put in.
 
To Load the screen back up later, just do this simple thing:
Def Seg=&HA000
BLOAD "filename"
 
That's it!!!
-----------------------------------------------------------------------------
Well those loading and saving routines are all well and good if you want
to grab the entire screen, or the upper parts, but what if you want to save
and load a sprite? Well that is a little more complex, but it is still
easy!
 
First as usual you draw something on the screen. Then you need to make
an array for your sprite. I am not sure how you demention your array
based on the graphic size, because the demensions of the array can be
smaller then the sprite's demensions! So if anyone knows what the equation
is for dimensioning an array based on the sprites dimensions then I would
LOVE to know. But until then I just dimention the array according to the
sprite size. So if the sprite is 20x20 the the I make the array 20x20.
What I do is say
 
Dim array(20*20) or..
Dim array(20,20)
 
Then you need to get the image. If you don't know how GET works then look
it up in you BASICs help file.
Like..
GET (1,1)-(20,20),array
 
Now you need to point to that array like so..
DEF SEG=VARSEG(array(0))
 
Now it is safe to save it. Like so...
BSAVE "filename",Varptr(array(0)),length
 
The equation for the length of the file does not work for saving a sprite
either. it is not X*Y, so I don't know what the equation for it is. So
I hope someone who knows the equation can contribute it to the fanzine.
Meanwhile for length I usually use 16384, but if the sprite does not load
up all the way when you try to load it, then increase that number.
VARPTR tells BSAVE where to look for the info. In this case it is the
memory location where the array is stored.
 
OK, now that you have the image saved, you can use it in one of your
programs. But this time when you load up the graphic, you load it into
an array instead of to the screen. Don't worry it is just as fast.
 
First dimension your array, the way you did before...
Dim array(20*20) or..
Dim array(20,20)
 
Now point to that array again:
DEF SEG=VARSEG(array(0))
 
Now Load the graphic the same way you did before, but this time load it into
the array. Like so:
BLOAD "filename",VARPTR(array(0))
 
Now that it is in the array you can put it on the screen whenever you want!
Just use PUT. If you don't know what PUT is then look it up in the online
help. But here is the general idea...
PUT (x,y),array,PSET
 
I Hope I have not further confused you, but nevertheless those things work.
 
 
 
Answer 6
~~~~~~~~~~~~~
[ from the Microsoft Knowledge Base, Artikel 45699, 25.1.2004 ]
 

Complete Instructions to BLOAD and BSAVE EGA and VGA Screens
(German-language overview: Kurz & bündig: Du musst mit diesen sog. Latch-Registern herumoperieren, damit mit POKE/PEEK() (und damit auch BLOAD/BSAVE) im Videospeicher gezielt die gewünschte Bitplane adressiert werden kann.)
 
SUMMARY
This article describes how to BLOAD and BSAVE EGA and VGA SCREEN modes (7, 8, 9, 10, 11, 12, and 13) in Microsoft QuickBasic versions 4.00 4.00b and 4.50 for MS-DOS; in Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS; and in Microsoft Basic PDS version 7.00 for MS-DOS.
 
MORE INFORMATION
SCREEN modes 11, 12, and 13 require a VGA card, and SCREEN modes 7, 8, 9, and 10 require an EGA or VGA card.
 
Using QuickBasic or the Basic compiler, the BLOAD and BSAVE technique required for EGA and VGA screens is more involved than the technique used for CGA and Hercules screen modes. EGA and VGA screen modes 7, 8, 9, 10, 11, and 12 are stored differently in video memory than other screen modes. EGA and VGA memory (except SCREEN mode 13) is broken up into four different bit planes: blue, green, red, and intensity.
 
Each bit plane is addressed in parallel; that is, the planes are all in one location, stacked on top of one another. When manipulating a particular address in video memory, the address refers to 4 bytes, not just 1 (1 byte in each bit plane). To read or write EGA/VGA screens, we need to send or retrieve information to or from each of the four bit planes separately. Each plane can be accessed by placing information in registers located on the Graphics Controller.
 
Programming EGA and VGA graphics depends heavily on the Graphics Controller. The Graphics Controller manages the CPU and video memory when executing EGA/VGA read and write operations. To access the Graphics Controller, sending output to a set of ports is necessary. Two registers are important when reading and writing EGA/VGA screens: map mask and read map select. These registers are located on the Graphics Controller.
 
Accessing the map mask and read map registers requires writing to two ports. Writing to the first port (the address register) is necessary to select the desired register, and the second (the data register) to send information to the selected register. The second port is used by all the registers. To select the map mask register for writing (i.e., BLOADing) EGA/VGA screens, send a 2 (the index for the map mask register) to port &H3C4 (the sequencer address register). Then, put the bit plane number (0 to 3) you want to write to in port &H3C5 (the data register). To select the read map register for reading (i.e., BSAVEing) EGA/VGA screens, send a 4 (the index for the read map register) to port &H3CE (the graphics address register). Then, put the bit plane number you want to read in port &H3CF (the data register). This procedure is demonstrated in the subprogram, GRAPHSUB.BAS, shown below.
 
Different screen modes have different resolutions. Therefore, variable amounts of EGA/VGA memory must be BLOADed or BSAVEd. The formula for calculating the number of bytes to be BLOADed or BSAVEd (with the exception of SCREEN mode 13) is as follows:
Number of bytes = (Maximum y-coordinate)*(Maximum x-coordinate)/8

For example, SCREEN mode 9 has a resolution of 640 x 350. The number of pixels in this screen mode is 640 * 350 or 224,000 pixels/bits. To obtain the number of bytes to save or load, divide this number by 8. Therefore, the number of bytes to save or load is 28,000.
 
In SCREEN mode 13 (VGA medium resolution), the Graphics Controller is not used. As in other non-EGA/VGA modes, a contiguous block of memory is BLOADed or BSAVEd. SCREEN mode 13 has a resolution of 320 x 200 with 256K colors (1 byte per pixel); therefore, 64,000 bytes need to be saved or loaded.
 
REFERENCES
The following are excellent resources for detailed information concerning EGA and VGA screen modes and how to program for them:
"Programmer's Guide to PC and PS/2 Video Systems" by Richard Wilton, published by Microsoft Press (1987)
 
"The New Peter Norton Programmer's Guide to the IBM PC and PS/2" by Peter Norton, published by Microsoft Press (1988)
 
"The Waite Group's Microsoft C Programming for the PC Revised Edition" by Robert Lafore, published by The Waite Group, Inc. (1989)
 
"The Programmer's PC Sourcebook" by Thom Hogan, published by Microsoft Press (1988)
 
BLOAD/BSAVE Example
Below is a Basic program, MAIN.BAS, which is a driver program that CALLs the BLOAD and BSAVE EGA/VGA subprogram EgaVgaSub further below. The EgaVgaSub subprogram module can be easily pasted into your own programs. MAIN.BAS is as follows:
 
DECLARE SUB EgaVgaSub (FileName$, Mode AS INTEGER, RW AS INTEGER)
'********************************************************************
' Sample program that calls the EgaVgaSub subprogram. This program
' works with QuickBasic versions 4.00, 4.00b, and 4.50, Microsoft
' Basic Compiler versions 6.00 and 6.00b for MS-DOS, and Microsoft
' Basic PDS version 7.00 for MS-DOS.
'********************************************************************
TYPE ModeType 'Type to describe the SCREEN mode selected.
MaxX AS INTEGER 'Maximum value of x coordinate.
MaxY AS INTEGER 'Maximum value of y coordinate.
Mode AS INTEGER 'Mode selected in the SCREEN statement.
NoColors AS INTEGER 'Max. # of colors available in selected mode.
END TYPE
DIM ScreenRec AS ModeType
DIM ReadWrite AS INTEGER
CLS
PRINT "Please input the correct options below. NOTE: if BLOADing a"
PRINT "file, please make sure the file exists in the current"
PRINT "directory or the program may hang!"
PRINT : PRINT "Option to BLOAD or BSAVE EGA screen data files--"
INPUT "Enter (1) for BLOAD or (2) for BSAVE: ", ReadWrite
PRINT : PRINT "Enter the filename (maximum 7 characters) to BLOAD or"
PRINT "BSAVE EGA screen data to or from (do not include extension):";
INPUT FileName$
CLS
'CHANGE AS NEEDED:
SCREEN 9 'SCREEN statement that invokes EGA 640x350 16 color mode.
'Can substitute mode 9 with mode 7, 8, 10, 11, 12 or 13 here.
ScreenRec.MaxX = 640 'CHANGE AS NEEDED:
' Maximum x coordinate for mode 9 is 640.
ScreenRec.MaxY = 350 'CHANGE AS NEEDED:
' Maximum y coordinate for mode 9 is 350.
ScreenRec.Mode = 9 'CHANGE AS NEEDED: Mode selected in the SCREEN
' statement.
ScreenRec.NoColors = 15 'CHANGE AS NEEDED:
' Maximum number of colors available in
' mode 9 (0 to 15 colors).
IF ReadWrite = 1 THEN GOTO CallSub 'BLOAD- no need to output graphics.
FOR i = 1 TO 200 'Generate random lines in random colors.
x1 = INT(ScreenRec.MaxX * RND)
y1 = INT(ScreenRec.MaxY * RND)
x2 = INT(ScreenRec.MaxX * RND)
y2 = INT(ScreenRec.MaxY * RND)
co = INT(ScreenRec.NoColors * RND)
LINE (x1, y1)-(x2, y2), co
NEXT i
CallSub: CALL EgaVgaSub(FileName$, ScreenRec.Mode, ReadWrite)
INPUT "Press <ENTER> to restore screen ...", a$
END
SUB EgaVgaSub (FileName$, mode AS INTEGER, RW AS INTEGER) STATIC
' ---------------------------------------------------------------
' EgaVgaSub is a SUBprogram that will BSAVE or BLOAD a given
' file to or from SCREEN mode 7, 8, 9, 10, 11, 12 or 13.
' SCREENs 11, 12, and 13 require a VGA card, and
' SCREENs 7, 8, 9, and 10 require an EGA or VGA card.
' EgaVgaSub will produce four files with extension .GRA which
' contain graphics information from each bit plane (with the
' exception of SCREEN modes 10 and 13).
' Variable:
' FileName$-- the name of the file to be BLOADed or BSAVEd.
' Mode -- the SCREEN mode being used.
' RW -- the choice to BLOAD or BSAVE the file. If RW=1,
' then the file is BLOADed. Otherwise, the file is
' BSAVEd.
'
' Compatibility:
' This subprogram works with QuickBasic versions 4.00, 4.00b and
' 4.50, Basic compiler 6.00 and 6.00b for MS-DOS and Basic PDS 7.00
' for MS-DOS.
' ---------------------------------------------------------------
'
SELECT CASE mode 'Determine how much to BSAVE.
'
'Mode 7 is 320x200- save/load 8000 bytes.
'Mode 8 is 640x200- save/load 16000 bytes.
'Modes 9 and 10 are 640x350- save/load 28000 bytes.
'Modes 11 and 12 are 640x480- save/load 38400 bytes.
'Mode 13 is 320x200x(1byte/256 colors)- save/load 64000 bytes.
'
CASE 7
total! = 8000
CASE 8
total! = 16000
CASE 9 TO 10
total! = 28000
CASE 11 TO 12
total! = 38400
CASE 13
total! = 64000
CASE ELSE
PRINT "ERROR: Non EGA/VGA graphics mode!"
GOTO NonEGAorVGA
END SELECT
'
IF mode = 10 THEN 'SCREEN mode 10 only has two bit planes
cycle = 1 'because it is used on a monochrome display.
ELSE
cycle = 3 'SCREEN modes 7, 8, 9, 11, and 12 have four
END IF 'bit planes.
'
DEF SEG = &HA000 'Define the segment for EGA/VGA graphics.
'BSAVEing and BLOADing SCREEN mode 13 does not
IF mode = 13 THEN 'require the use of the graphics map register.
IF RW = 1 THEN 'BLOAD the file.
f$ = FileName$ + "0" + ".GRA" 'Load the file into VGA memory.
BLOAD f$, 0 '0 is the offset to page 0.
ELSE 'BSAVE the file.
f$ = FileName$ + "0" + ".GRA" 'Save VGA memory in a file.
BSAVE f$, 0, total! 'Save the visual page, at offset 0.
END IF
'
ELSE
FOR i = 0 TO cycle 'Cycle through each bit plane of EGA/VGA.
IF RW = 1 THEN 'BLOAD files.
OUT &H3C4, 2 'We want to index the map register.
OUT &H3C5, 2 ^ i 'Bit plane we want to reference.
'Load each file into its corresponding bit plane.
f$ = FileName$ + CHR$(i + 48) + ".GRA"
BLOAD f$, 0 '0 is the offset to page 0.
ELSE 'BSAVE files.
OUT &H3CE, 4 'Select Read Map Select Register.
OUT &H3CF, i 'Select the bit plane to save.
'Save each bit plane in its own file.
f$ = FileName$ + CHR$(i + 48) + ".GRA"
BSAVE f$, 0, total! 'Save the visual page, at offset 0.
END IF
NEXT i
END IF
'
DEF SEG 'Restore the segment.
'
NonEGAorVGA:
END SUB

The information in this article applies to:

Microsoft QuickBASIC for MS-DOS 4.0
Microsoft QuickBASIC for MS-DOS 4.0b
Microsoft QuickBASIC for MS-DOS 4.5
Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
Microsoft BASIC Professional Development System (PDS) for MS-DOS 7.0
 
 
 
Answer 7
~~~~~~~~~~~~~
[ from the Microsoft Knowledge Base, Artikel
36022 , 25.1.2004 ]
 

How to BSAVE/BLOAD EGA SCREENs 7, 8, 9, 10 in QB 2.x, 3.0
 
SUMMARY
Below is a code example that uses BSAVE and BLOAD to store and retrieve a screen image in EGA SCREEN modes 7, 8, 9, and 10 to and from disk. This BSAVE and BLOAD technique required for EGA screens is not as straightforward as for CGA or Hercules SCREEN modes, because EGA memory is stored in discontinuous color planes.
 
Note: A BETTER BLOAD/BSAVE article is available. For an example of BLOAD and BSAVE of VGA screen modes 11, 12, and 13 (supported in QuickBasic 4.x, in Basic compiler 6.0 and 6.0b, and in Basic PDS 7.0 and 7.1), in addition to the EGA modes shown below, query on the following word for a separate, more complete, current article in this Knowledge Base:
BSAVEVGA
 
The code example further below works in the following products: Microsoft QuickBasic versions 3.0, 4.0, 4.0b, and 4.5; Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS; and Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS. (Note that EGA SCREENs are not supported in the protected mode of OS/2.)
 
QuickBasic versions 2.0 and 2.1 do not support SELECT CASE, and the program below needs to be modified to use IF statements instead.
 
QuickBasic versions 1.0, 1.01, and 1.02 do not support the EGA SCREEN modes (7, 8, 9, and 10), and cannot use this program.
 
This program can also be found in the May 12, 1987 issue of "PC Magazine" on pages 403-404.
 
MORE INFORMATION
The EGA memory is broken into color planes. The program below is designed to save a given EGA screen into separate disk files; one file for each EGA color plane.
 
For more technical information about EGA memory, please refer to the following book, which is available at book stores or from Microsoft Press at (800) 638-3030 or (206) 882-8080:
"Programmer's Guide to PC and PS/2 Video Systems," Richard Wilton, Microsoft Press, 1987
 
Code Example
' HOW TO BLOAD AND BSAVE EGA SCREENS 7, 8, 9, and 10.
SCREEN 9 ' Invokes EGA 640 x 350 16-color mode.
FOR i = i TO 200 ' Draw some random lines in random colors:
x1 = INT(640 * RND)
y1 = INT(350 * RND)
x2 = INT(640 * RND)
y2 = INT(350 * RND)
co = INT(15 * RND)
LINE (x1, y1)-(x2, y2), co
NEXT i
'
' Save EGA video memory from video memory to disk:
filename$ = "TEST"
mode = 9
RW = 0
CALL EGA(filename$, mode, RW)
CLS
INPUT "Hit <ENTER> to restore screen:", a$
'
'Load EGA video memory from disk to video memory:
RW = 1
CALL EGA(filename$, mode, RW)
END
'
SUB EGA (filename$, mode, RW) STATIC
' filename$=filename
' mode=video mode (EGA SCREEN number)
' RW=read/write EGA from/to disk R=T, W=F
'
'Determine amount of video memory for display mode:
SELECT CASE mode
CASE 7
Total = 8000
CASE 8
Total = 16000
CASE 9 TO 10
Total = 28000
CASE ELSE
PRINT "ERROR: NonEGA Graphics Mode!"
GOTO NOEGA
END SELECT
'
'Cycle through each video plane of EGA
IF mode = 10 THEN cycle = 1 ELSE cycle = 3
DEF SEG = &HA000 ' Segment of EGA video memory
FOR i = 0 TO cycle
IF RW = 1 THEN
' Set EGA register for write to each plane:
OUT &H3C4, 2
OUT &H3C5, 2 ^ i
'
F$ = filename$ + CHR$(i + 48) + ".EGA"
BLOAD F$, 0
ELSE
' Set EGA register for read from each plane:
OUT &H3CE, 4
OUT &H3CF, i
F$ = filename$ + CHR$(i + 48) + ".EGA"
BSAVE F$, 0, Total
END IF
NEXT i
DEF SEG
NOEGA:
END SUB

The information in this article applies to:

Microsoft QuickBASIC 3.0
Microsoft QuickBASIC 4.0
Microsoft QuickBASIC 4.0b
Microsoft QuickBASIC 4.5
Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
Microsoft BASIC Professional Development System (PDS) for MS-DOS 7.0
Microsoft BASIC Professional Development System (PDS) for MS-DOS 7.1

[ The QBasic-MonsterFAQ --- Start Page: www.antonis.de/faq ]