issue #11

tip of the month

By nekrophidius

S
B
S

For the longest time, QB programmers have been using the BSAVE command to save screens to files. However, the only problem we have faced is with the color palette. A typical BSAVE does not save the palette, so unless we work around this then our colors will be lost and our image appears messed up. Well, Rich Geldreich knew this as well, and he set out to solve the problem. His technique involved placing the color bytes above the image data in screen memory, where it wouldn't be seen, but where it could be easily accessed. When I discovered this technique, I gave it a name: SBS, short for Super BSave. Ever since, I've used this neat technique, and now I'll show you how to use it as well.

The main advantage to this technique is that when done properly, it is amazingly fast. We'll use a couple of tricks to obtain maximum speed from this unique technique. Also, keep in mind that this is designed for the typical SCREEN 13, and may not work in other modes.

---CODE SEGMENT:CUT AND PASTE---

'Access the screen memory segment
DEF SEG = &HA000
'Tell the video display to start at palette register 0
OUT &H3C7, 0

'Let's read the palette and place it above the video display
'We can do this because the video display is 65536 bytes, however, only 64000 are ever used.
'This gives us 1536 bytes to play with, we only need 768 so this works out perfectly
FOR a = 0 TO 767
      POKE a + 64000, INP(&H3C9)
NEXT

'Using the standard BSAVE, we can save the whole thing to a single file!
BSAVE "filename.sbs", 0, 64768
'Don't forget to restore the segment back to the default
DEF SEG

---END OF CODE SEGMENT---

That writes a 64775 byte SBS file to disk. Your screen is saved! Now, there are two ways to load the screen back in, using the standard BLOAD or using BLOAD with a few extra lines of code. So, here we go...

---CODE SEGMENT:CUT AND PASTE---

'Access the screen memory segment
DEF SEG = &HA000
'Load the file
BLOAD "filename.sbs"
'Now, we can read the palette from the screen memory above the visual screen
OUT &H3C8, 0

FOR A = 0 TO 767
      OUT &H3C9, PEEK (64000 + A)
NEXT

'Restore the default segment
DEF SEG

---END OF CODE SEGMENT---

There you have it. A set of super-fast screen read/write routines. Like a BMP file, this format is pretty large. However, using compression theories will eliminate that, but that's a story for another tutorial...

 
Petition nekro to call this the Super Extraordinary Humongous Happy Magical BSAVE (or SEHHMBS for short) at this address.

F
I
L
E

F
O
R
M
A
T

Back to Top