home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / VGX3.ZIP / VGXSPECS.DOC < prev    next >
Text File  |  1993-01-06  |  7KB  |  156 lines

  1.                      VGX FILE FORMAT SPECIFICATION
  2.                              Version 3.0
  3.                             January, 1993
  4.  
  5.  
  6.                             Dwain Goforth
  7.                           Milestone Software
  8.                            1260 Sunset Ave.
  9.                            Arcata, CA 95521
  10.  
  11.  
  12.  
  13. The VGX file format uses a run-length encoding scheme for each of the four 
  14. video banks (or planes.)  Like BLOAD, it uses 64k EGA banks; like PCX, it 
  15. uses run-length encoding.  Each bank is one color attribute (red, blue, 
  16. green, intensity).  Compressing banks is more efficient than scan lines - 
  17. VGX changes banks only 4 times for each file while PCX changes 1920 times 
  18. for a VGA 640x480 16-color image (four times each scan line.)  
  19.  
  20. Using VGXLoad will add approximately 8k to your finished EXE program.  Using 
  21. VGXSave will add approximately 6k of compiled code to your EXE program.
  22.  
  23. In addition to this compiled code, the routines will allocate additional 
  24. memory each time they are called.
  25.  
  26. While running, VGXSave will allocate 78k of RAM, while VGXLoad will need 56k 
  27. of RAM.  Please note that this used RAM is released after each call (except 
  28. for the VGXGRAB.COM TSR's which allocate RAM permanently - until you re-boot 
  29. your computer.)  
  30.  
  31. Most critical DOS errors are "passed through"; that is, if an error occurs 
  32. (filename, disk or memory), the VGX routines will pass control back to your 
  33. program (the call may fail, but your program will not crash, though your 
  34. palette may be all black.)  However, you do have to have sufficient RAM 
  35. available.  Remember that speed was the guiding criterion when designing 
  36. VGX. If error catching is essential you will need to use ON ERROR in your 
  37. program.
  38.  
  39. VGX will work with any IBM-compatible microcomputer with a VGA display 
  40. adapter.  DOS 2.1 and above are required.  Versions of Microsoft BASIC 
  41. supported are PDS BASIC 7.x.
  42.  
  43. The VGX routines are "word-aligned"; that is they are optimized for the 286 
  44. CPU.  8088 CPU machines (PC's and XT's) will work just as fast, and 386 
  45. CPU's will work to nearly as fast as possible. 
  46.  
  47. VGXSave and VGXLoad were written in MASM assembly language and BASIC itself.  
  48.  
  49.  
  50. FILE FORMAT:
  51.  
  52. The first 48 bytes of a VGX file contain the palette information.  Each of 
  53. the 16 colors has a byte for red, blue and green, respectively.  Thus byte 
  54. #1 is the red value for color 0, byte #6 is the green value for color 1, 
  55. etc...
  56.  
  57. Following the 48-byte palette header is the compressed bank data.  Three 
  58. flags (words or 2 bytes) are used to indicate runs or bank changes. These 
  59. are: 
  60.      893E  -  run of zeros follows 
  61.      883E  -  run of ones follows 
  62.      0F27  -  end of bank
  63.  
  64. The data is stored as words (2 bytes.)
  65.  
  66. Those of you on the astute side may be wondering what happens if the data 
  67. contains these words. Well, one is subtracted from the data; that is, 893E 
  68. becomes 893D, 883E becomes 883D and 0F27 becomes 0F26. In these cases, one 
  69. of your pixels on the screen will have one bank (red, green, blue or 
  70. intensity) off when it should have been set. Since, on the average, there
  71. is a .0000457 probability of this happening, you will only notice this in 
  72. the unlucky event of geometric patterns you are trying to save as a VGX file 
  73. that has many repetitions of these "reserved" numbers. Oh, well, but did I 
  74. tell you how fast it is?
  75.  
  76. The following is an example of the beginning of a VGX file which has a
  77. custom palette and red circle in the center of the screen:
  78.  
  79. 00 00 00 00 12 13 24 1C 1D 2D 21 1F 3F 2B 1F 3F \
  80. 38 20 3F 29 0A 3A 3A 0C 35 26 09 31 13 07 2C 05   >  palette header
  81. 07 28 02 12 23 01 1B 1C 00 1F 0E 00 1B 06 06 32 /
  82. 0F 27 0F 27 89 3E F3 15 01 FF FF C0 89 3E 25 00
  83.                                    
  84. skip bank 1 .     .     .     .     .     .
  85.            .     .     .     .     .     .
  86.       skip bank 2 .     .     .     .     .
  87.                  .     .     .     .     .
  88.             run of zeros next word  .     .
  89.                        .     .     .     .
  90.                   5619 words of zeros (decimal of F315)
  91.                              .     .     .
  92.                         01FF as bit pattern (= 0000000111111111)
  93.                                    .     .
  94.                               FFC0 as bit pattern
  95.                                          .
  96.                                     run of zeros next word
  97.                                           
  98.                                           37 words of zeros (dec. of 2500)
  99.  
  100.  
  101. 00 01 FE 00 00 3F C0 00 89 3E 24 00 00 3E 00 00    etc....
  102. 00 00 3E 00 89 3E 24 00 03 C0 00 00 00 00 01 E0
  103. 89 3E 24 00 1C 00 00 00 00 00 00 1C 89 3E 24 00...
  104.  
  105.                        ------------------------
  106.  
  107. OPTIMIZING VGX FILES:
  108.  
  109. Because VGX files are stored in banks (red, green, blue and intensity) it is 
  110. to your advantage to design colors in your pictures that allow continuous 
  111. runs of banks.
  112.  
  113. Consider the relationship of the palette and the banks:
  114.  
  115.            BANK0  BANK1  BANK2  BANK3   
  116.            (RED)  (GRN)  (BLU)  (INT)
  117. ----------------------------------------
  118. COLOR 0          
  119. COLOR 1                    X
  120. COLOR 2             X
  121. COLOR 3             X      X
  122. COLOR 4      X
  123. COLOR 5      X             X
  124. COLOR 6      X      X
  125. COLOR 7      X      X      X
  126. COLOR 8                           X
  127. COLOR 9                    X      X
  128. COLOR 10            X             X
  129. COLOR 11            X      X      X
  130. COLOR 12     X                    X
  131. COLOR 13     X             X      X
  132. COLOR 14     X      X             X
  133. COLOR 15     X      X      X      X
  134.  
  135. If you look at LASSEN1.VGX you see blue sky with lots of light blue words 
  136. ("Milestone Software") and a brown mountain with a black "web" on it.
  137.  
  138. The sky is Color 1 and the words are Color 3 which means most of the sky 
  139. area is stored very efficiently for Bank 2 (blue) as a solid run of FFFF 
  140. bytes. Bank 1 (green) is broken by the words (and accounts for much of the 
  141. file size.) Had I used, say, Color 12 for the words, I would have not only 
  142. broken up the continuous Bank 2 (blue) in the sky, but I would also have 
  143. dragged Bank 4 (intensity) into the top of the picture and added greatly to 
  144. the file size. If I wanted the words to be bright red (normal for Color 12), 
  145. I would have *changed* Color 3 to be bright red (and still used the more 
  146. efficient bank choice.)
  147.  
  148. I pulled a similar trick with the "black" web on the mountain. The mountain 
  149. is actually Color 9 and the web is Color 11, so Bank 2 is an efficient solid 
  150. run of FFFF bytes. In fact, Bank 2 is solid FFFF for the whole picture!
  151.  
  152. Keeping these relationships in mind when making pictures for VGX can make 
  153. highly efficient and small VGX files :)
  154.  
  155.  
  156.