home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bgi256-3.zip / BITFONT.DOC < prev    next >
Text File  |  1992-12-27  |  8KB  |  188 lines

  1.                 Modifying the BGI256 Bit-Mapped Font
  2.                      Michael Day - 12/26/92
  3.  
  4. The BGI256 driver obtains the basic bit-mapped font by reading in 
  5. the system font. The system font is actually obtained from two 
  6. locations. The lower 128 characters are read from the BIOS ROM, 
  7. which is the font the graphics mode uses when the 8x8 font is 
  8. selected. The lower font table is located at the real address 
  9. $F000:$FA6E, and is arranged as an array[0..127,0..7] of byte. 
  10. Each of the eight bytes in a table entry make up a character 
  11. definition, the first byte representing the first scan line of 
  12. the character. The system font table is located in ROM, so you 
  13. can't change it. 
  14.  
  15. The upper 128 character set is derived by reading the extended 
  16. system font, which can be found at the location indicated by the 
  17. vector found at interrupt $1F. If the vector at interrupt $1F is 
  18. zero, the extended character set is not available. On these 
  19. systems you can load the character set by running the 
  20. GRAFTABL.COM program that comes with MS-DOS. GRAFTABL.COM loads 
  21. the extended character set into memory and points the $1F 
  22. interrupt at the table.
  23.  
  24. Normally on MCGA and VGA display systems the character set is 
  25. automatically loaded. Actually, the character set isn't really
  26. "loaded" -- the interrupt vector at location $1F simply points at
  27. the display BIOS ROM where the extended character table is 
  28. stored. Once again, the interrupt points at a ROM location, which
  29. means it can't be changed.
  30.  
  31. Or can it? Remember that you can load the extended character set 
  32. as a TSR into RAM and point the $1F interrupt to the character 
  33. set using the GRAFTABL.COM program. Having the character set in 
  34. RAM means we can change it. When you do, it will displace the 
  35. ROM based table that the display card provides with the one that 
  36. GRAFTABL provides.)
  37.  
  38. The BGI256 driver provides hooks which allow a full character 
  39. font set to be loaded into memory. It does this by looking at a 
  40. font ID in character 127 of the upper font table. If it finds the 
  41. ID there, it knows that the modified table has been loaded into 
  42. the interrupt vector at $1F, and a full font table can be used.
  43.  
  44. Note: The BITFNT.ZIP file found in the Compuserve Borland Pascal 
  45. library contains modified BGI drivers and a full description on 
  46. how they were modified to support the user loadable bit-mapped 
  47. fonts. 
  48.  
  49. -----------------------------------------------------------------
  50.  
  51. The MAKEFONT program shown below will create the needed full font 
  52. table. As before, it assumes that you have loaded the extended 
  53. character font using the GRAFTABL program where needed.
  54.  
  55. {Program to build a font definition file}
  56. program MAKEFONT;
  57. uses  Dos;
  58. type  FontChar = array [0..7] of byte;
  59.       FontArray = array [0..127] OF FontChar;
  60. const FontFilename = 'FNTIMG.DAT';
  61.       FontID : FontChar = ($4D,$49,$4B,$45,$20,$44,$41,$59);
  62. var   LoFont : FontArray absolute $F000:$FA6E;
  63.       UpFont : FontArray;
  64.       SysFont : ^FontArray;
  65.       f : file of FontArray;
  66. begin 
  67.   assign(f,FontFilename);                   { Create font file }
  68.   rewrite(f);
  69.   GetIntVec($1F,pointer(SysFont));    { Get upper font address }
  70.   UpFont := SysFont^;                 { copy font to local mem }
  71.   UpFont^[127] := FontID;            { Insert our font ID mark }
  72.   write(f,LoFont);            { Write system font to the disk, }
  73.   write(f,UpFont^);               { Followed by the upper font }
  74.   close(f);                                   { Close the file }
  75. end. 
  76.  
  77. Within a program you can load the modified font table with the 
  78. following procedure:
  79.  
  80.   {procedure for loading the modified character font}
  81.   const FontFilename = 'FNTIMG.DAT';
  82.   type  FontArray = array [0..255, 0..7] of byte;
  83.   var   ExtFont : FontArray;
  84.         f : file of FontArray;
  85.   procedure LoadFont;
  86.   begin
  87.     assign(f,FontFilename);  { Read the font table into memory }
  88.     reset(f);
  89.     read(f,ExtFont);
  90.     close(f);
  91.     SetIntVec($1F,@ExtFont[128]);   { set the interrupt vector }
  92.   end; 
  93.  
  94. Alternately, you can load the font as a TSR with the following 
  95. program:
  96.  
  97. {TSR program for loading the modified character font to memory}
  98. {$M 1000,0,0}
  99. program MGRAFTBL;
  100. const FontFilename = 'FNTIMG.DAT';
  101. type  FontArray = array [0..255, 0..7] of byte;
  102. var   ExtFont : FontArray;
  103.       f : file of FontArray;
  104. begin
  105.   assign(f,FontFilename);   { Read the font table into memory }
  106.   reset(f);
  107.   read(f,ExtFont);
  108.   close(f);
  109.   SetIntVec($1F,@ExtFont[128]);    { set the interrupt vector }
  110.   Keep(0);
  111. end; 
  112.  
  113. -----------------------------------------------------------------
  114.  
  115. The BGI256 driver tests if the vector found at $1F is valid (non-
  116. zero). Next a test is made to see if it is our own modified table 
  117. or some other table.  It determines whether it is the modified 
  118. table by looking for a signature (4D,49,4B,45) in the first half 
  119. of the last font character (#127). If this is a standard system 
  120. font, the character would have zeros in it. If the font table is 
  121. not our custom table, the driver uses the system font as normal. 
  122. This means it uses the lower font found at address $F000:$FA6E, 
  123. and assumes the font being pointed to by interrupt $1F is the 
  124. upper (extended) font. 
  125.  
  126. If the driver finds the custom font signature, it assumes the 
  127. font table being addressed by $1F is the custom font and that the 
  128. normal lower system font is to be replaced by the font found in 
  129. the half of the extended font table located below the interrupt 
  130. vector. Be sure to restore the old interrupt vector when you are 
  131. done with it so that other programs will be happy.
  132.  
  133. A note about loading your own font:
  134.  
  135. With the older V2.00 BGI drivers, you could reload the font table 
  136. address at Int $1f anytime you wanted and the BGI driver would 
  137. automatically reflect the new font on the next usage. 
  138.  
  139. In the V3.00 drivers, this is no longer true. To deal with 
  140. protected mode, the BGI driver must pre-load the address at the 
  141. time the BGI driver is registered. That means that if you change 
  142. the address found at INT $1f after the driver has been 
  143. registered, the change will not be reflected in the BGI driver. 
  144.  
  145. There are two ways in which a BGI driver can be registered, the 
  146. normal method is to call the BGI InitGraph function which 
  147. automatically attempts to register the indicated driver. (If no 
  148. driver is indicated it will attempt to determine the proper 
  149. driver to use.)
  150.  
  151. Alternately, you can use the RegisterBGIdriver function to 
  152. specifically register a driver that you have loaded into memory 
  153. either via Linking it into the code, or via loading it on the 
  154. heap (or elsewhere in memory).
  155.  
  156. The act of registering the driver updates the various registers 
  157. in the driver. This is true for both protected mode and real mode 
  158. operation. 
  159.  
  160. Keep in mind that while the memory address is fixed, the contents 
  161. of the memory can still be changed. Thus to change the font, you 
  162. only need to change the contents in the memory where you loaded 
  163. the font table. The only limitation is that you cannot move the 
  164. table to a different memory address once the driver has been 
  165. registered.
  166.  
  167. Also keep in mind that the BGI driver expects the font to appear 
  168. in real memory. This means that if you are writing a protected 
  169. mode application, you must use the GlobalDOSAlloc system call to 
  170. allocate memory that can be shared by both protected and real 
  171. mode in which to place the font table if you intend to load it 
  172. inside your application. If you use a TSR to load the font before 
  173. you run your application rather than loading it inside your 
  174. application, you don't need to worry about that.
  175.  
  176. Additionally, remember that when in protected mode, you are in a 
  177. virtual environment. That means that the $1f interrupt vector 
  178. that you set with SetIntVec is not the real mode interrupt 
  179. vector, but rather a simulated vector that is isolated from the 
  180. real mode interrupt. To change the real $1f interrupt vector 
  181. inside your program, you must place a call to the DPMI server to 
  182. perform that action. 
  183.  
  184. The program TESTFONT.PAS shows an example of working with the 
  185. modified BGI in real and protected mode operation.
  186.  
  187. <eof>
  188.