home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / doc / creating_textmodes_from_scratch.HOWTO < prev    next >
Encoding:
Text File  |  1996-04-19  |  17.7 KB  |  471 lines

  1.  
  2. This document describes how to create a completely new textmode from scratch
  3.  
  4.  
  5. related documents: - SVGATextMode/doc/monitor-timings.howto
  6.                    - The Hitchhiker's Guide to X386/XFree86 Video Timing
  7.                      <VideoModes.html> (included in the XFree86
  8.                      distribution)
  9.  
  10.  
  11.  
  12. Many people have questions like the one below (extracted from a message sent
  13. to me by Gerhard Thomas):
  14.  
  15.       I wish to get a Textmode for my Sony GDM-1950 fixed
  16.       frequency monitor. It works at 61kHz (horizontal frequency)
  17.       and 66Hz (vertical frequency) (+/-5%). My vga-card has a
  18.       trio64 chipset (70Mhz maximum pixelclock by default in text
  19.       mode). Do you have any ideas, where to get more information
  20.       about that configuration?
  21.  
  22.  
  23.  
  24. OK. Let's see.
  25.  
  26. 61 kHz horizontal by 66 Hz vertical. This means you will have to have 
  27.  
  28.     61000/66 = 924
  29.     
  30. total number of lines on the screen (this is including the black borders
  31. around the active image area). This can be understood easily: the monitor
  32. sweeps the beam 61000 times from left to right, and does a whole screen 66
  33. times per second. Thus, when the beam has scanned 924 lines at that speed,
  34. it will start all over again for another scan, 66 times per second.
  35.  
  36. So we already have the following mode line:
  37.  
  38. "[Modename]" ***   *** *** *** ***   *** *** *** 924 [options]
  39.  
  40. If you allow the use of doublescan, you get two possibilities for this:
  41.  
  42. "[Modename]" ***   *** *** *** ***   *** *** *** 924 [options]
  43. "[Modename]" ***   *** *** *** ***   *** *** *** 462 [options] DoubleScan
  44.  
  45. (doublescan shows all lines twice, so there are only half as many "real" lines)
  46.  
  47.  
  48. A normal monitor needs about 25% of extra space around the active screen
  49. area horizontally, and about 5% vertically, which would mean that in our
  50. case the number of _active_ lines would be something like 
  51.  
  52.     924*.95 = 878 lines
  53.     
  54. Most monitors work well when the sync starts right after the active area
  55. stopped, so we'll take that as the sync start. Vertical syncs need to be
  56. only a few (or even just one) line "wide". We then get:
  57.  
  58. "[Modename]" ***   *** *** *** ***   878 878 882 924 [options]
  59.  
  60.  
  61. That was the easy part. Now comes the guesswork
  62.  
  63. Knowing that you want 61kHz, you know that the total number of pixels per
  64. line (i.e. including the 20 % blank area around the active screen) should be
  65. as follows:
  66.  
  67.     total_pixels_per_line = pixel_clock/61000
  68.     
  69. This lets you a lot of room for playing around, since the range of pixel
  70. clocks available on a programmable clockchip card like yours is virtually
  71. unlimited. All you have to know now is, knowing that the horizontal
  72. frequency is fixed, the more pixels you want on a line, the higher the pixel
  73. clock will have to be in order to comply with that fixed-frequency demand of
  74. your screen.
  75.  
  76. But lets first fix some more numbers, so we can start defining the mode.
  77.  
  78. A nice thing to start with is a font height of 16 pixels. This is the same
  79. font size used in the standard 80x25 mode, which will give you some initial
  80. advantages (e.g. no need to load a new font).
  81.  
  82. With a font height of 16 pixels, you will get a total of 
  83.  
  84.     878/16 = 54.875
  85.     
  86. text lines on the screen. Since this is not a whole number, we'll make that
  87. into 54 lines, and adjust the active total number of pixels so it is a
  88. multiple of 16 (actually, there is no need to do that: SVGATextMode will
  89. round it down for you -- but it's a little more clean). We'll also be moving
  90. the vertical sync together with the change in total number of pixels. That
  91. will give us the best chance that it will work right out of the box.
  92.  
  93. Let's also assume a font width of 8 pixels (this is easier to work with --
  94. see below ) So we now have:
  95.  
  96. "[Modename]" ***   *** *** *** ***   864 864 868 924 font 8x16
  97.  
  98.  
  99. Now let's pick a number of text characters per line. We'll start off with a
  100. wild guess that looks nice, and see where that gets us.
  101.  
  102. Since we have 54 lines on screen, we'll need something appropriate. 80
  103. characters for example is ridiculous. Remember the old VGA 80x50 mode? All
  104. characters look flattened, and the width is not in proportion with the
  105. height. We'll start off with, for example, 140 characters (I deliberately
  106. avoided picking 132, because I want to show you that you are NOT restricted
  107. to the things DOS shows you).
  108.  
  109. Ok. 140 chars per line. This means you'll need 
  110.  
  111.     140*8 = 1120
  112.     
  113. pixels in the active screen.
  114.  
  115. The downside is that this extra black pixel actually takes up a clock cycle
  116. from the VGA chip (and thus a "pixel"), although it doesn't take up space in
  117. the font. It's a bit more tricky to calculate timings this way. 
  118.  
  119. Using the rule mentionned before that we need some 25% blanked space around
  120. the active video area, we will need something like
  121.  
  122.     1120*1.25 = 1400
  123.     
  124. total number of pixels per line.
  125.  
  126. ANd you already know you want a 61 khz horizontal sync, so now you can
  127. calculate the pixel clock needed! Like this:
  128.  
  129.     pixel_clock = number_of_total_pixels * horizontal_frequency
  130.     
  131.                 = 1400 * 61000 
  132.                 
  133.                 = 85.4 MHz
  134.                 
  135. Until now, the mode line looks like:
  136.  
  137. "[Modename]"  85.4   1120 *** *** 1400   864 864 868 924 font 8x16
  138.  
  139. All we need to do, is add the horizontal syncs. Starting with the start of
  140. the Hsync around a microsecond after the last active pixel is a good start
  141. for most monitors (unless you have exact specs for these timings, in which
  142. case you'd better use those), so we'll use 1 microsecond for now (you will
  143. HAVE to adjust that using e.g. vgaset later, so it fits nicely in the middle
  144. of the screen).
  145.  
  146. At 96 MHz, 1 usec is
  147.  
  148.     96 * 1 = 96 pixels
  149.     
  150. (the "meg" of the pixel clock in MHz nicely cancels with the "micro" of
  151. that 1 microsecond timing -- that's why I just multiplied MHz with
  152. microseconds).
  153.  
  154. Sync width? In most cases, 2 microseconds is more than enough for the
  155. higher-frequency monitors, while the really cheap ones need over 3
  156. Microseconds or more.
  157.  
  158. Let's pick 2 micro's and see where that gets us:
  159.  
  160.     2 * 96 = 192 pixels
  161.     
  162. This puts the start of the Hsync at 
  163.  
  164.     1120 + 96 = 1216
  165.     
  166. and the end of the hsync at:
  167.  
  168.     1216 + 192 = 1408
  169.     
  170. So now we get the complete mode line:
  171.  
  172. "[Modename]"  85.4   1120 1216 1408 1400   864 864 868 924 font 8x16
  173.  
  174. This will cause an error, since the sync ends AFTER the complete line image
  175. has ended, which means NEVER. We will have to adjust the numbers a bit (and
  176. this is where it gets really hairy).
  177.  
  178. Since you have a high-speed monitor (high-frequency is also high speed),
  179. we'll assume that that 1 microsecond pause before the start of the sync was
  180. a bit overkill, so we'll reduce that from 96 to, say, 70 (just a guess).
  181. Also, the sync width of 2 microseconds will have been equally conservative
  182. in this case, so we'll reduce that to about 150 as well.
  183.  
  184. Now we get:
  185.  
  186. "Sony_140x54"  85.4   1120 1190 1340 1400   864 864 868 924 font 8x16
  187.  
  188. This looks more like it.
  189.  
  190. We'll do a final check to see we didn't screw up somewhere:
  191.  
  192.     hor. sync = 85400000/1400 = 61000        (OK!)
  193.     vert sync = 61000/924 = 66            (OK!)
  194.     number of characters per line = 1120/8 = 140    (OK!)
  195.     number of text lines per screen = 864/16 =  54    (OK!)
  196.  
  197. This looks all great! Would we try it? Sure!
  198.  
  199.     stm Sony_140x54
  200.     
  201. Oops! We're in some trouble here: Most S3 cards cannot handle 96 MHz pixel
  202. clocks in text mode (they can in graphics mode, but NOT in text mode: see
  203. SVGATextMode/doc/PROBLEMS in the chapter on character bandwidth).
  204.  
  205. That's why SVGATextMode will report an error at this point, saying that the
  206. pixel clock is too high for this card. (70 MHz maximum, default).
  207.  
  208. At this point you can either ignore the error, and take your chance by
  209. adding the "-v" option to avoid validation of the mode (overriding both
  210. pixel clock limits and monitor limits -- so be warned!), or you could decide
  211. to try and change the mode to use a lower pixel clock.
  212.  
  213.  
  214. Note that on an S3, using high-speed textmode, some S3 cards WILL be able to
  215. handle these high pixel clocks, although not the cheaper and older ones (S3
  216. 801/805, 928, 924, 911 : forget it! 732 and 764 (Trio): maybe. 864/964:
  217. sometimes).
  218.  
  219.  
  220.  
  221. So we'll need to get a lower pixel clock. How? By reducing the number of
  222. characters per line, which would reduce the number of pixels and thus also
  223. the pixel clock (for the same horizontal frequency).
  224.  
  225. Let's work towards our goal from the other direction this time: We'll say we
  226. USE a 70 MHZ pixel clock.
  227.  
  228. With a 70 MHz pixel clock, you would get a total of 
  229.  
  230.     70000000/61000 = 1148
  231.     
  232. pixels per line, or, taking the active area rule into account:
  233.  
  234.     1148 / 1.25 = 918 (or 920 when rounded to a multiple of 8)
  235.     
  236. active pixels.
  237.     
  238. With an 8-pixel font (see below for 9-pixel fonts), this would mean
  239.  
  240.     920/8 = 115 characters per line
  241.     
  242. For the other parameters (Hsync in this case), scaling the numbers roughly
  243. with the ratio of the old and the new pixel clock (in this case "* 70 /
  244. 85.4") will get you going for a first shot.
  245.  
  246. "Sony_140x54"  70   920 980 1104 1148   864 864 868 924 font 8x16
  247.  
  248. Just to be sure, let's check again:
  249.  
  250.     hor. sync = 70000000/1148 = 60975        (OK!)
  251.     vert sync = 60975/924 = 65.99            (OK!)
  252.     number of characters per line = 920/8 = 115    (OK!)
  253.     number of text lines per screen = 864/16 =  54    (OK!)
  254.  
  255.  
  256. Try it!
  257.  
  258. It could be that a fixed frequency monitor like this Sony needs specific
  259. sync polarities to work, so you might have to add "+hsync" or "-hsync" and
  260. "+vsync" or "-vsync" to the mode line to make this work. SVGATextMode picks
  261. the default normally used for VGA when nothing is defined, but since those
  262. workstation monitors are _not_ VGA almost by definition, they could be
  263. sensitive to sync polarities. Good designs don't depend on details like
  264. this...
  265.  
  266.  
  267. If it shows something, but not centered properly, try using vgaset on it,
  268. and adjust the timings so it's nicely centered.
  269.  
  270.  
  271. Now that we're that far, we can start fiddling with it. 
  272.  
  273. First of all, 54 lines of text is a bit much when there are only 115
  274. characters per line (this is a personal oppinion, and you might prefer
  275. having 200 lines of text on screen, not in the least concerned how flat
  276. characters would look in such a mode).
  277.  
  278. Using the exact same timings, you can build a lot of extra modes without
  279. having to go through the whole process again.
  280.  
  281. Changing the font size for example will give you a whole bundle of new modes:
  282.  
  283. Now we have 864/16 = 54 text lines on screen.
  284.  
  285. The list below shows you some other options:
  286.  
  287.     Font size    Number of text lines
  288.     
  289.       16                    54
  290.       14                    61
  291.       12                    72
  292.       8                    108
  293.       20                    43
  294.       32                    27
  295.  
  296. This table uses some common font sizes to get more modes. _All_ font sizes
  297. between 1 and 32 pixels height are allowed, but most have no suitable font
  298. available. 20-pixel high fonts are really neat, but are not available for
  299. Linux by default. If you happen to own UltraVision for DOS, you can convert
  300. its 20-pixel fonts to Linux format, so you can use them there as well. There
  301. is a conversion program included in the contrib/Ultra2Linux directory.
  302.  
  303. The mode lines for all the font sizes above would be:
  304.  
  305. "Sony_115x54"  70   920 980 1104 1148   864 864 868 924 font 8x16
  306. "Sony_115x61"  70   920 980 1104 1148   864 864 868 924 font 8x14
  307. "Sony_115x72"  70   920 980 1104 1148   864 864 868 924 font 8x12
  308. "Sony_115x108" 70   920 980 1104 1148   864 864 868 924 font 8x8
  309. "Sony_115x43"  70   920 980 1104 1148   864 864 868 924 font 8x20
  310. "Sony_115x27"  70   920 980 1104 1148   864 864 868 924 font 8x32
  311.  
  312. Note that I changed the mode labels as well, although they have no real
  313. meaning to SVGATextMode. The only thing that determines the _actual_ number
  314. of lines is the font size at the end of the mode line.
  315.  
  316.  
  317. This is the right spot to introduce DoubleScan into the picture: the
  318. 32-pixel high font of the last mode is not normally available on Linux
  319. systems as well. But using DoubleScan, we can achieve the same with a
  320. 16-pixel font. Rewriting that last mode using doublescan results in two
  321. modes that are exactly the same:
  322.  
  323. "Sony_115x27"  70   920 980 1104 1148   432 432 434 462 font 8x16 DoubleScan
  324. "Sony_115x27"  70   920 980 1104 1148   864 864 868 924 font 8x32
  325.  
  326. Note that in the DoubleScan mode the vertical timings are halved!
  327.  
  328. The only difference is if you happen to have a REAL 32-pixel high font, the
  329. non-DoubeScan mode will have more detail (less "jaggies"). The 32-pixel font
  330. included with SVGATextMode is just a 16-pixel font that was artificially
  331. doubled in size by copying each line in the font. 
  332.  
  333.  
  334. Now is also the time to introduce 9-pixel wide fonts. SVGATextMode supports
  335. 8- and 9-pixel wide fonts, but both use the _same_ font file.
  336.  
  337. VGA cards use a strange trick to get a character cell of 9 pixels. It's
  338. actually a cell of just 8 characters, but with a 9th, empty (black) pixel
  339. appended to it.
  340.  
  341. This exploits the fact that (almost) all fonts need character spacing
  342. between them, and thus all "normal" 8-pixel fonts used to have one or more
  343. black rows on the right side and below the characters anyway. Using this
  344. trick, you can fill the 8-pixel font definition a little more (=higher
  345. resolution), using the full 8-pixel resolution available in the 8-pixel
  346. cell, and let the VGA chip add the black space (or at least part of it)
  347. between characters.
  348.  
  349. There's just one catch: the VGA chip must STILL be programmed as if it were
  350. doing a 8-pixel font ,even when using a 9-pixel cell width. This means that
  351. if you want the same number of characters per line, you need to enter the
  352. SAME parameters:
  353.  
  354. "Sony_115x54"  70   920 980 1104 1148   864 864 868 924 font 9x16
  355.                                                             ^^^^^^
  356.  
  357. Is this OK? NO! It's not _that_ simple. Using a 9-pixel wide font cell also
  358. requires 9 pixel clock periods to draw (only 8 pixels are actually drawn
  359. from the font information. The 9th is just black, but it must be drawn
  360. anyway).
  361.  
  362. In other words, a mode line that says there are a total of 1148 pixels on
  363. one line (as in our mode) will _actually_ require
  364.  
  365.     1148 * ( 9 / 8) = 1291
  366.     
  367. clocks to draw, and thus, with the same pixel clock, the horizontal
  368. frequency would drop from
  369.  
  370.     70000000 / 1148 = 60.975 kHz
  371.     
  372. to
  373.     70000000 / 1148 * ( 8 / 9 ) = 54.2 khz
  374.  
  375. Which is much too low for this screen.
  376.  
  377. The solution is simple: multiply the pixel clock with the same factor (9/8)
  378. and you get the same mode again:
  379.  
  380.     70 * 9 / 8 = 78.75 MHz
  381.  
  382. "Sony_115x54x9"  78.75   920 980 1104 1148   864 864 868 924 font 9x16
  383.  
  384. But, I hear you say, now the pixel clock is too high again!
  385.  
  386. Well, yes and no. As explained in SVGATextMode/doc/PROBLEMS, this is not so
  387. in most -if not all- cases. SVGATextMode will report that the clock is too
  388. high, yes (I need to fix that some day), but the VGA will work just as well
  389. with 78 MHz and a 9-pixel font as with 70 MHz and an 8-pixel font.
  390.  
  391. In fact, SVGATextMode should multiply the maximum text mode clock by 9/8 if
  392. you're using a 9-pixel font, because that's what the hardware will be able
  393. to handle then.
  394.  
  395. The real limit in VGA text modes (see also that .../PROBLEMS file) is the
  396. number of character cells per second it has to draw, and with a 9-pixel cell
  397. at 78 MHz or an 8-pixel cell at 70 MHz, that number is the same (about 10
  398. Million per second).
  399.  
  400.  
  401. TIP: In fact, a good rule is that any mode which will work with a certain
  402.      clock in 8-pixel wide mode (font width of 8), will also work in 9-pixel
  403.      mode with the clock multiplied by a factor 9/8.
  404.      
  405.      In other words, if you have a mode working with an 8-pixel font at a
  406.      certain pixel clock, just changing the font width from 8 to 9 AND (!)
  407.      the clock
  408.      
  409.          from     (x)
  410.          
  411.          to     (x) * 9/8
  412.          
  413.      will get you the EXACT same timings, and in almost all cases, the same
  414.      performance. The only difference will be the font spacing.
  415.      
  416.      In other words, if you want to crate a new mode, just take the easiest
  417.      way and desing an 8-pixel mode, so you can forget all about that
  418.      strange factor you have to use all the time, and once the mode is
  419.      tested and works fine, THEN switch it to a 9-pixel wide mode, as
  420.      described above.
  421.      
  422.  
  423. Now, let's do some more tweaking.
  424.  
  425. For starters, most fixed frequency monitors are only fixed in their
  426. _horizontal_ frequency, while the vertical frequency can, in most cases, be
  427. in a whole range. E.g. a 66 Hz monitor wwill almost always be able to handle
  428. 60 to 75 Hz or more. The only thing that could happen is that the display
  429. becomes more and more distorted (especially pincushion, trapezoid and
  430. horizontal linearity) the further you get from that ideal 66 Hz.
  431.  
  432. Going to e.g. 70 Hz with the same parameters, by reducing the number of
  433. active lines to:
  434.  
  435.     61000/70 = 871
  436.  
  437. instead of 924, and adjusting the other vertical parameters accordingly
  438. (e.g. by scaling them with the same 66/70 ratio), you'd get the following
  439. modes:
  440.  
  441. "Sony_115x51"  70   920 980 1104 1148   814 814 818 871 font 8x16
  442. "Sony_115x58"  70   920 980 1104 1148   814 814 818 871 font 8x14
  443. "Sony_115x67"  70   920 980 1104 1148   814 814 818 871 font 8x12
  444. "Sony_115x101" 70   920 980 1104 1148   814 814 818 871 font 8x8
  445. "Sony_115x40"  70   920 980 1104 1148   814 814 818 871 font 8x20
  446. "Sony_115x25"  70   920 980 1104 1148   814 814 818 871 font 8x32
  447.  
  448.  
  449. This mode used the maximum pixel clock, and thus also the maximum amount of
  450. characters per line possible on your card (asasuming that 70 MHz actually
  451. _is_ the maximum -- you might want to experiment with that limit).
  452.  
  453. Using lower pixel clocks, you would also achieve a lower number of
  454. characters per line. But since the vertical and horizontal frequencies are
  455. fixed, you will almost certainly need very high fonts (e.g. 32 pixels) to
  456. get a nice H/V ratio of the number of characters.
  457.  
  458. Try for example to achieve 100 characters per line, and use a 16-pixel
  459. doublescanned font. I'm sure there is some mode possible for this:
  460.  
  461. "Sony_100x27" 60.8  800 852 960 998   432 432 434 462 font 8x16 DoubleScan
  462.               ^^^^^^^^^^^^^^^^^^^^^
  463. For this mode, I basically scaled down all horizontal values plus the pixel
  464. clock (all the numbers with arrows underneath) by a factor 100/115, and
  465. copied the vertical parameters.
  466.  
  467. You can go on and on like this, creating an endless amount of modes.
  468.  
  469.  
  470. Got it?
  471.