home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PCGPEV10.ZIP / VGAREGS.TXT < prev    next >
Text File  |  1994-05-10  |  41KB  |  807 lines

  1.  
  2.                          Programming the VGA Registers
  3.                       by Boone (boone@ucsd.edu), March '94
  4.  
  5.    The IBM PC has long been slammed by owners of other computers which come 
  6. with superior graphics capabilities built right into hardware.  The PC is a 
  7. strange beast to program in general, and when it comes to graphics the 
  8. programmer doesn't get much help from the video hardware.  However, there are 
  9. quite a few neat tricks you can do using the VGA registers, as I'm sure you're 
  10. aware.  The trick is knowing just which registers to use and how to use them to 
  11. achieve the desired results.  In particular, precise timing is necessary to 
  12. avoid screen flicker and/or "snow".  The registers on your video card are 
  13. necessary for just about any communication with the VGA besides basic 
  14. reading/writing of pixels.  Some of the registers are standard, which are the 
  15. ones we will be discussing here.  Most SVGA chipsets have their own special 
  16. functions associated with different registers for things such as bank 
  17. switching, which is part of what makes trying to write SVGA programs so 
  18. difficult.  The registers are also used to set the various attributes of each 
  19. video mode: horizontal and vertical resolution, color depth, refresh rate, 
  20. chain-4 mode, and so on.  Luckily, BIOS handles all this for us and since we 
  21. only need to set the video mode once at program start-up and once at exit, you 
  22. should need to mess with these particular functions too much, unless you are 
  23. using a special mode, such as mode X.  (See the mode X section for more info on 
  24. all this.)  If you want to experiment with the video mode registers, ftp 
  25. yourself a file called TWEAK*.* (my version is TWEAK10.ZIP).  For now we'll 
  26. just assume the video mode has already been set to whatever mode you wish.
  27.    One of the most common techniques used by game programmers is fade in/out.  
  28. A clean fade is simple but very effective.  Suprisingly, even big-budget games 
  29. like Ultima VII often have a lot of screen noise during their fades.  With a 
  30. little effort you can easily write your own noise-free fade routines.  There's 
  31. nothing like giving a professional first impression on your intro screen, since 
  32. the fade-in is likely to be the very first thing they see of your program.
  33.    BIOS is much to slow for this timing-critical opperation, so we'll have to 
  34. get down and dirty with our VGA card.  Fading is a fairly simple process.  As 
  35. you should know, the VGA palette consists of 256 colors with 3 attributes for 
  36. each color: red, green and blue.  Every cycle of the fade, we have to go 
  37. through all 768 attributes and if it is larger than 0 subtract one.  We'll use 
  38. regsiters 3C8h and 3C9h for palette opperations.  The operation for sending a 
  39. palette to the card is straight-forward: send a 0 to port 3C8h and then your 
  40. 768 byte buffer to port 3C9h.  This is good enough for setting the palette at 
  41. the start of your program, but of course it has to go in a loop for the fade, 
  42. since you'll have to do this 256 times, subtracting one from each non-zero 
  43. member of the buffer.  The pseudo-code looks something like this:
  44.  
  45.    constant PALSIZE = 256*3;
  46.    unsigned character buffer[PALSIZE];
  47.    boolean done;
  48.    counter i,j;
  49.  
  50.       for j = 255 to 0
  51.        {
  52.          for i = 0 to PALSIZE-1
  53.             if buffer[i] > 0
  54.                buffer[i] = buffer[i] - 1;
  55.  
  56.          output 0 to port 3C8h;
  57.          for i = 0 to PALSIZE-1
  58.             output buffer[i] to port 3C9h;
  59.        }
  60.  
  61.    Easy enough, right?  If you convert this to the language of your choice it 
  62. should run fine.  (Make sure you have the buffer pre-loaded with the correct 
  63. palette, however, or you will get very strange results...)  But you'll notice 
  64. the "snow" mentioned earlier.  Depending on your video card, this could mean 
  65. that you see no noise at all to fuzz covering your entire screen.  Even if it 
  66. look fine on your system, however, we want to make sure it will be smooth on 
  67. *all* setups it could potentially be run on.  For that we're going to have to 
  68. ask the video card when it's safe to send the palette buffer to the card, and 
  69. for that we'll need the retrace register.
  70.    Putting aside palette concerns for a moment, I'll briefly cover the retrace 
  71. on your video card.  (See the next section of this article for a more in-depth 
  72. discussion of this.)  Bascially the vertical retrace is a short time in which 
  73. the screen is not being updated (from video memory to your monitor) and you can 
  74. safely do writes to your video memory or palette without worrying about getting 
  75. snow, flicker, tearing, or other unwanted side-effects.  This is a pretty quick 
  76. period (retrace occurs 60 to 70 times a second) so you can't do too much at 
  77. once.
  78.    Returning to our fade: we want to update the palette during the vertical 
  79. retrace.  The value we want is bit 3 of register 3DAh.  While that bit is zero 
  80. we're safe to write.  The best practice in this case is to wait for the bit to 
  81. change to one (screen is being traced) and then the instant it changes to 0, 
  82. blast all our new video info to the card.  It won't be necessary in this case 
  83. since all we are doing is fading the palette and then waiting for the next 
  84. retrace, but if you're doing animation or playing music at the same time 
  85. you'll want to include this extra bit of code as a safety net.  Otherwise you 
  86. might detect the 0 in the refresh bit at the very last instant of the retrace 
  87. and end up writing while the screen is being traced.  The pseudo-code now goes 
  88. like this:
  89.  
  90.       for j = 255 to 0
  91.        {
  92.          for i = 0 to PALSIZE-1
  93.             if buffer[i] > 0
  94.                buffer[i] = buffer[i] - 1;
  95.  
  96.          while bit 3 of port 3DAh is 0
  97.             no opperation;
  98.          while bit 3 of port 3DAh is 1
  99.             no opperation;
  100.  
  101.          output 0 to port 3C8h;
  102.          for i = 0 to PALSIZE-1
  103.             output buffer[i] to port 3C9h;
  104.        }
  105.  
  106.    That's it!  All that's left is for you to implement it in your favorite 
  107. language.  However, I can hear the cries right now: "Code!  Give us some real 
  108. assembly code we can use!"  I'm reluctant to provided it as this is the exact 
  109. sort of thing that is easy to cut and paste into your program without knowing 
  110. how it works.  However, I'll give you the unoptimized main loop in 80x86 
  111. assembly as this may be clearer to you that my explanation or pseudo-code.  Two 
  112. things to remember about this code: it is optimized enough to be smooth on any 
  113. video card (or any that I've seen, anyway) assuming that the fade is the _only_ 
  114. thing going on.  There's some other things you may want to change if you plan 
  115. to say, play music during this process.  Secondly, you'll need to have the 
  116. current palette loaded into the buffer beforehand.  You could read it from the 
  117. VGA card using either registers or BIOS, but this is both slow and (in my 
  118. oppinion) sloppy coding.  You should *never* ask the video card about anything 
  119. (excluding retrace) that you could keep track of yourself.  In the case of the 
  120. palette, you probably already loaded it from disk anyway, or if you are using 
  121. the default palette <cough, gag, choke> just read the values once and store 
  122. them in your executable or in a resource file.
  123.  
  124.      palbuf   DB                  768 DUP (?)
  125.      fadecnt  DW                  040h
  126.  
  127. ; At this point, you should:
  128. ;  1) have the video mode set
  129. ;  2) have palbuf loaded with the current palette
  130. ;  3) have something on the screen to fade!
  131.  
  132. fadeloop:
  133.  
  134.      xor      al,al               ; used for comparisons and port 3D8h
  135.      mov      cx,768              ; loop counter
  136.      mov      si,offset palbuf    ; save palette buffer in si
  137.  
  138. decloop:
  139.      mov      dl,[si]              ; put next pal reg in dx
  140.      cmp      al,dl                ; is it 0?
  141.      je       next                 ; nope...
  142.      dec      dl                   ; yes, so subtract one
  143.      mov      [si],dl              ; put it back into palette buffer
  144.  
  145. next:
  146.      dec      cx                   ; decrement counter
  147.      inc      si                   ; increment our buffer
  148.      cmp      cx,0
  149.      jne      decloop              ; not done yet, so loop around
  150.  
  151.      mov      cx,768              ; reset for palette output
  152.      sub      si,768              ; reset palbuf pointer
  153.      mov      dx,03c8h
  154.      out      dx,al               ; inform VGA of palette change
  155.      inc      dx                  ; DX = 3C8h + 1 = 3C9h
  156.  
  157.      mov      ch,02h              ; do outter loop 2 times
  158.      mov      dx,03dah            ; prepare refresh register
  159.      mov      bx,03c9h            ; prepare palette reg (for quick loading)
  160.  
  161.      cli                          ; disable interrupts!
  162.  
  163. outloop:
  164.      mov      cl,80h              ; do inner loop 128 times
  165.  
  166.      in       al,dx               ; wait for current retrace to end
  167.      test     al,08h
  168.      jnz      $-5
  169.  
  170.      in       al,dx               ; wait for current screen trace to end
  171.      test     al,08h
  172.      jz       $-5
  173.  
  174.      mov      dx,bx               ; load up the palette change register
  175.  
  176. innerloop:
  177.      mov      al,[si]             ; load next byte of palbuf
  178.      out      dx,al               ; send it to the VGA card
  179.      dec      cl                  ; decrement counter
  180.      inc      si                  ; increment palbuf pointer
  181.      cmp      cl,0
  182.      jne      innerloop           ; loop while not done
  183.  
  184.      dec      ch                  ; decrement outer loop counter
  185.      cmp      ch,0
  186.      jne      outloop             ; loop while not done
  187.  
  188.      sti                          ; restore interrupts
  189.  
  190.      mov      ax,fadecnt          ; entire palette has been sent
  191.      dec      ax                  ; so check fade loop 
  192.      mov      fadecnt,ax
  193.      cmp      ax,0                ; ready to quit?
  194.      jne      fadeloop            ; nope, keep fading!
  195.  
  196.  
  197.    I should add a few comments about this code segment.  First of all, it 
  198. assumes you want to fade every color all the way down.  You may only want to 
  199. fade certain sections of the palette (if your screen was only using a certain 
  200. number of colors) or maybe your palette is low-intensity so you don't need to 
  201. go the full 256 loops to get every color down to 0.  It also goes by ones, so 
  202. if you want a faster fade you can have it subtract two from each attribute.  
  203. If you want to fade to a certain color other than black (for instance, fade to 
  204. red such as the "getting hit" effect in Doom), you'll need to check if each 
  205. attribute is above or below your target color and increment or decrement 
  206. accordingly.  Also, you may have noticed something in the code absent from the 
  207. pseudo-code: it only sends 128 colors to the card each retrace!  This is 
  208. because if you use all 256 the next retrace may start before you get all colors 
  209. sent to the video card, thanks to the unoptimized code.  Some recommend as 
  210. little as 64 colors per retrace, however I've found 128 to be okay and 
  211. certainly much faster.  The above code works for any VGA-equiped machine, 
  212. regardless of processor, but you'll probably want to compress all the IN and 
  213. OUT loops into REP INSB/OUTSB, REP INSW/OUTSW, or REP INSD/OUTSD instructions 
  214. depending upon the minimum processor requirement for your game/demo.
  215.    I won't describe fading in since it's the same sort of thing, and I'm sure 
  216. you can figure it out once you know how to use the registers themselves.  It's 
  217. a little more complicated since you need a second buffer of target values for 
  218. your attributes, but otherwise quite similar.
  219.  
  220.    Next up is vertical retrace.  This is simply one of many read registers on 
  221. your VGA, but it happens to be one of the most useful for animation and palette 
  222. fades (as shown above).  Here's a quick rundown of what exactly the vertical 
  223. retrace is, and why it's useful.
  224.    There's an electron gun in the back of your monitor that keeps the pixels 
  225. "refreshed" with their correct values every 1/60th of a second or so.  It fires 
  226. electrons at each pixel, row by row.  The horizontal retrace is the time it 
  227. takes it to return from the right side of the screen after it has traced a row.  
  228. This is a very short time and I wouldn't worry about that too much right now, 
  229. as it is only useful for very specialized (and quite tricky) hardware effects.
  230. More useful, however, is the vertical retrace which occurs when the electron 
  231. gun reaches the bottom of the screen (one entire screen traced) and it returns 
  232. diagonally to the upper-right hand corner of the screen.  During this time you 
  233. are free to update anything you like having to do with video with no noise or 
  234. interference (since nothing on the screen is being updated).  This is a fairly 
  235. short amount of time, though, so whatever you want to do you better do it 
  236. _quickly_.  For animation, you'll usually want to keep a second buffer in main 
  237. memory (remember that video RAM is quite slow compared to main RAM) which you 
  238. can use to write your animations to.  When the vertical retrace occurs, you'll 
  239. want to blast the entire thing to the VGA as quickly as possible, using a 
  240. memory copy instruction.  You can find more on this in articles which cover 
  241. animation.
  242.  
  243.    Lastly I'll briefly describe the VGA mode-set registers.  There are quite a 
  244. number of them and for the most part they're pretty boring.  By sending 
  245. different values to these registers you can achieve the various video modes 
  246. that your card is capable of.  These registers set values such as horizontal 
  247. and vertical resolution, retrace timing, addressing modes, color depth, timing, 
  248. and other fun stuff.  The truth is that it's easier and just as effective to
  249. let the BIOS (gasp!) handle setting the screen mode for you, particularly since 
  250. most games use standard modes such as 320x200 anyway.  At the very least you 
  251. can let BIOS set the mode to begin with and then just modify the registers to 
  252. "tweak" the mode the way you want it.  Any of these non-BIOS modes are 
  253. generally refered to as mode X.  I don't want to go deep into detail on the 
  254. setting and usage of mode X because there is already so much info availible on 
  255. the topic.  Check out the Mode X Faq (regularly posted in comp.sys.ibm.pc.demos 
  256. and rec.games.programmer), Micheal Abrash's collumn in Dr. Dobb's and his 
  257. X-sharp library, or the section on mode X in the PC-GPE.
  258.    One mode register I'll cover quickly is the chain-4 enable/disable.  A lot 
  259. of programmers seem to have trouble visualizing what this thing does exactly. 
  260. Bit 3 of port 3C4h (index 4) controls chain-4 mode.  Normally it is on.  This 
  261. allows fast linear addressing of the bytes in video memory, which is the way 
  262. you are probably used to addressing them.  For example, to change the second 
  263. pixel on the screen to a certain color, you simply write the value to address 
  264. A000:0001.  With chain-4 disabled (the main feature of mode X besides better 
  265. resolution) A000:0000 refers to the first pixel in the upper-left corner of 
  266. your screen, A000:0001 refers to the fourth pixel, A000:0002 to the eight pixel 
  267. and so on.  The odd pixels are accessed by changing the write plane.  Since 
  268. there are four planes, you effectively get an extra two bits of addressing 
  269. space, boosting the total bit width for your pixel addressing from 16 to 18.  
  270. Standard chain-4 four only allows access to 64K of memory (2^16) while 
  271. disabling this feature gives you the full 256K (2^18) of memory to work with.  
  272. The disadvantage, of course, is that pixel writes are slower due to the port 
  273. writes required to access odd pixels.  How can this be an advantage?  For one 
  274. thing, you can write four pixels at a time as long as they are all the same 
  275. color - handy for single-color polygons, as in flight simulators.  Secondly, 
  276. you get four times as much memory.  This allows you to have higher resolutions 
  277. without bank switching, or scroll the screen using hardware scrolling, or do 
  278. page flipping for smooth animation.  And since you can change the resolution, 
  279. you can give yourself a sqaure aspect ration (320x240) which is better for 
  280. bitmap rotations and the like.  But remember that it can be slower for 
  281. bitmapped graphics because you have to do at least four writes to the card (to 
  282. change planes) in order to copy bitmaps from main RAM to video memory.  Don't 
  283. use mode X just because you think it's "cool"; make sure you have a good reason 
  284. for wanting to use it in your program, or otherwise you're wasting a lot of 
  285. effort for no reason.
  286.  
  287.    Now, I'm sure you want me to continue until I divulge all the secrets of the 
  288. VGA register to you - but, I only have some much time and space.  Besides, I 
  289. still haven't uncovered all of their mysteries and capabilities myself.  
  290. However, below is a list of the registers which you may want to play with for 
  291. various effects.  The following list was posted on rec.games.programmer by 
  292. Andrew Bromage (bromage@mundil.cs.mu.OZ.AU), so thanks to him for posting in to 
  293. begin with.
  294.    That's it for this article and I hope it helped you understand your VGA card 
  295. a little better.  If not, re-read it, and try writing your own programs which 
  296. use the registers.  The only way to really understand it (as with most things) 
  297. is to get some hands-on experience.
  298.    If you've got any questions, comments, flames, or corrections related to 
  299. this document or game programming/design in general, feel free to post an 
  300. article in rec.games.programmer (in case you haven't noticed by now, I hang out 
  301. there regularly) or send mail to boone@ucsd.edu.
  302.  
  303. Here's the list.  Have fun...
  304.  
  305.           Documentation Over the I/O Registers for Standard VGA Cards
  306.  
  307.                     Documentated by Shaggy of The Yellow One
  308.                            Email: D91-SJD@TEKN.HJ.SE
  309.  
  310. Feel free to spread this to whoever wants it.....
  311. ------------------------------------------------------------
  312. Port-Index:  -               Port: Write/03c2h Read/03cch
  313. usage:       d7   Vertical sync polarity
  314.              d6   Horizontal sunc polarity
  315.              d5   Odd /even page
  316.              d4   Disable video
  317.              d3   Clock select 1
  318.              d2   Clock select 0
  319.              d1   Enable/Disable display RAM
  320.              d0   I/O address select
  321. Description: Sync polarity: Bits are set as below for VGA displays
  322.              that use sync polarity to determine screen resolution.
  323.              Many newer multiple frequency displays are insensitive
  324.              to sync polarity
  325.  
  326.              d7 d6      Resolution
  327.              0  0       Invalid
  328.              0  1       400 lines
  329.              1  0       350 lines
  330.              1  1       480 lines
  331.  
  332.              I/O address select: When set to zero, selects the
  333.              monochrome I/O address space (3bx). When set to one,
  334.              it selects the color I/O address space (3dx)
  335.  
  336. ------------------------------------------------------------
  337. Port-Index: -                Port: 03c2h ; read only
  338. usage:      d7    Vertical Retrace Interrupt pendling
  339.             d6    Feature connector bit 1
  340.             d5    Feature connector bit 0
  341.             d4    Switch sense
  342.             d0-d3 Unused
  343.  
  344. Description: d7 uses IRQ2
  345.  
  346. ------------------------------------------------------------
  347. Port-Index: -                Port: 03bah,03dah ; read only
  348. usage:      d3  Vertical retrace
  349.             d0  Horizontal retrace
  350.  
  351. ------------------------------------------------------------
  352. Port-Index: -                Port: 03c3h,46e8h
  353. usage:      d7-d1  Reserved
  354.             d0     VGA enable/disable (03c3h only)
  355.  
  356. Description: Disables access to display memmory and the other
  357.              VGA's ports
  358.  
  359. ------------------------------------------------------------
  360. Port-Index: 00h              Port: 03d4h, 03b4h
  361. usage:      Horizontal total
  362. Description: Total number of characters in horizontal scan minus
  363.              five ( including blanked and border characters)
  364.  
  365. ------------------------------------------------------------
  366. Port-Index: 01h              Port: 03d4h, 03b4h
  367. usage:      Horizontal display enable
  368. Description: Total number of characters displayed in horizontal
  369.              scan minus one.
  370. ------------------------------------------------------------
  371. Port-Index: 02h              Port: 03d4h, 03b4h
  372. usage:      Start horizontal blanking
  373. Description: Character at which blanking starts
  374.  
  375. ------------------------------------------------------------
  376. Port-Index: 03h              Port: 03d4h, 03b4h
  377. usage:      End horizontal blanking
  378.             d7    Test
  379.             d6    Skew control
  380.             d5    Skew control
  381.             d0-d4 End blanking
  382. Description: End blanking: is five LSB bits of six-bit value,
  383.              which define the character at which blanking stops.
  384.              The MSB bit of this value is in register index 5.
  385.  
  386. ------------------------------------------------------------
  387. Port-Index: 04h              Port: 03d4h, 03b4h
  388. usage:      Start horizontal retrace
  389. Description: Character at which horizontal retrace starts
  390.  
  391. ------------------------------------------------------------
  392. Port-Index: 05h              Port: 03d4h, 03b4h
  393. usage:      End horizontal retrace
  394.             d7    End horizontal blanking bit 5
  395.             d6    Horizontal retrace delay
  396.             d5    Horizontal retrace delay
  397.             d0-d4 End horizontal retrace
  398. Description: End horizontal retrace: defines the character at
  399.              which horizontal retrace ends
  400.  
  401. ------------------------------------------------------------
  402. Port-Index: 06h              Port: 03d4h, 03b4h
  403. usage:      Vertical total
  404. Description: Total number of horizontal scan lines minus two
  405.              (including blanked and border characters). MSB bits
  406.              of this value are in register index 7
  407.  
  408. ------------------------------------------------------------
  409. Port-Index: 07h              Port: 03d4h, 03b4h
  410. usage:      Overflow register
  411.             d7  Vertical retrace start (bit 9)
  412.             d6  Vertical display enable end (bit 9)
  413.             d5  Vertical total (bit 9)
  414.             d4  Line compare (bit 8)
  415.             d3  Start vertical blank (bit 8)
  416.             d2  Vertical retrace start (bit 8)
  417.             d1  Vertical display enable end (bit 8)
  418.             d0  Vertical total (bit 8)
  419. ------------------------------------------------------------
  420. Port-Index: 08h              Port: 03d4h, 03b4h
  421. usage:      Preset row scan
  422.             d7    Unused
  423.             d6    Byte panning control
  424.             d5    Byte panning control
  425.             d0-d4 Preset row scan
  426. Description: Byte panning control: is used to control byte
  427.              panning. This register together with attribute
  428.              controller register 13h allows for up to 31 pixels of
  429.              panning in double word modes
  430.              Preset row scan: Which character scan line is the
  431.              first to be displayed
  432. ------------------------------------------------------------
  433. Port-Index: 09h              Port: 03d4h, 03b4h
  434. usage:      Maximum scan line/Character height
  435.             d7    double scan
  436.             d6    bit d9 of line compare register
  437.             d5    bit d9 of start vertical blank register
  438.             d0-d4 Maximum scan line
  439. Description: d0-d5=Character height-1,  only in textmodes
  440. ------------------------------------------------------------
  441. Port-Index: 0ah              Port: 03d4h, 03b4h
  442. usage:      Cursor start
  443.             d7,d6 Reserved (0)
  444.             d5    Cursor off
  445.             d4-d0 Cursor start
  446. Description:
  447. ------------------------------------------------------------
  448. Port-Index: 0bh              Port: 03d4h, 03b4h
  449. usage:      Cursor end
  450.             d7    reserved
  451.             d6,d5 Cursor skew
  452.             d4-d0 Cursor end
  453. Description:
  454. ------------------------------------------------------------
  455. Port-Index: 0ch              Port: 03d4h, 03b4h
  456. usage:      Start address high
  457. ------------------------------------------------------------
  458. Port-Index: 0dh              Port: 03d4h, 03b4h
  459. usage:      Start address low
  460. Description: Determine the offset in display memory to be
  461.              displayed on the upper-left corner on the screen
  462. ------------------------------------------------------------
  463. Port-Index: 0eh              Port: 03d4h, 03b4h
  464. usage:      Cursor location (high byte)
  465. ------------------------------------------------------------
  466. Port-Index: 0fh              Port: 03d4h, 03b4h
  467. usage:      Cursor location (low byte)
  468. Description: Where the cursor is displayed on screen
  469. ------------------------------------------------------------
  470. Port-Index: 10h              Port: 03d4h, 03b4h
  471. usage:      Vertical retrace start
  472. Description: 8 bits out of 10
  473. ------------------------------------------------------------
  474. Port-Index: 11h              Port: 03d4h, 03b4h
  475. usage:      Vertical retrace end
  476.             d7    Write protect CRTC register 0 to 7
  477.             d6    refresh cycle select
  478.             d5    enable vertical interrupt (when 0)
  479.             d4    Clear vertical interrupt (when 0)
  480.             d0-d3 Vertical retrace end
  481. ------------------------------------------------------------
  482. Port-Index: 12h              Port: 03d4h, 03b4h
  483. usage:      Vertical display enable end
  484. Description: eight LSB bits out of ten-bit value which define
  485.              scan line minus one at which the display ends.
  486.              The other two are in CRTC register index 7
  487. ------------------------------------------------------------
  488. Port-Index: 13h              Port: 03d4h, 03b4h
  489. usage:      Offset / Logical screen width
  490. Description: Logical screen width between successive scan lines
  491. ------------------------------------------------------------
  492. Port-Index: 14h              Port: 03d4h, 03b4h
  493. usage:      Underline location register
  494.             d7    Reserved
  495.             d6    Double word mode
  496.             d5    count by 4
  497.             d0-d4 Underline location
  498. Description: Underline location: Monochrome textmode only
  499. ------------------------------------------------------------
  500. Port-Index: 15h              Port: 03d4h, 03b4h
  501. usage:      Start vertical blanking
  502. Description: eight LSB bits of ten-bit value minus one which
  503.              define at which scan line the vertical blanking
  504.              starts. The other two bits are in CRTC registers
  505.              index 7 and 9
  506. ------------------------------------------------------------
  507. Port-Index: 16h              Port: 03d4h, 03b4h
  508. usage:      End vertical blanking
  509. Description: eight LSB bits of a value which determine the scan
  510.              line after which vertical blanking ends.
  511. ------------------------------------------------------------
  512. Port-Index: 17h              Port: 03d4h, 03b4h
  513. usage:      Mode control register
  514.             d7  Enable vertical and hoizontal retrace
  515.             d6  Byte mode (1), word mode (0)
  516.             d5  Address wrap
  517.             d4  Reserved
  518.             d3  count by 2
  519.             d2  multiple vertical by 2 (use half in
  520.                 CRTC (8,10,12,14,18)
  521.             d1  Select row scan counter (not used)
  522.             d0  compatibilty mode support (enable interleave)
  523. ------------------------------------------------------------
  524. Port-Index: 18h              Port: 03d4h, 03b4h
  525. usage:      Line compare register
  526. Description: Split screen,  8 bit value out of a ten-bit value
  527. ------------------------------------------------------------
  528. Port-Index: 00h              Port: 03c4h
  529. usage:      Reset register
  530.             d7-d2 Reserved
  531.             d1    Synchronous reset
  532.             d0    Asynchronous reset
  533. Description: Synchr. when set to zero, will halt and reset
  534.              the sequencer at the end of its current cycle
  535.              Asyncht. when set to zero, will immediatly halt
  536.              and reset the sequencer. Data can be loss.
  537. ------------------------------------------------------------
  538. Port-Index: 01h              Port: 03c4h
  539. usage:      Clock mode register
  540.             d7,d6 Reserved
  541.             d5    display off
  542.             d4    Allow 32-bit Fetch (not used in standard modes)
  543.             d3    Divide dot clock by 2 (used in some 320*200 modes)
  544.             d2    Allow 16-bit fetch (used in mon graphics modes)
  545.             d1    Reserved
  546.             d0    Enable (0) 9 dot characters (mono text and 400-line)
  547. Description: Display off: Will blank screen and give the cpu
  548.              uninterrupted access the display memory.
  549. ------------------------------------------------------------
  550. Port-Index: 02h              Port: 03c4h
  551. usage:      Color plane write enable register
  552.             d7,d6 Reserved
  553.             d3    Plane 3 Write enable
  554.             d2    Plane 2 Write enable
  555.             d1    Plane 1 Write enable
  556.             d0    Plane 0 Write enable
  557. Description:
  558. ------------------------------------------------------------
  559. Port-Index: 03h              Port: 03c4h
  560. usage:      Character generator select register
  561.             d7,d6 Reserved
  562.             d5    Character generator table select A (MSB)
  563.             d4    Character generator table select B (MSB)
  564.             d3,d2 Character generator table select A
  565.             d1,d0 Character generator table select B
  566. Description: This register is only of interest if your software
  567.              will be using multiple character sets. Either one
  568.              or two character sets can be active. Table A selects
  569.              the charcater with attribute d3 set to zero and
  570.              Table B is the one with d3 set to one.
  571. ------------------------------------------------------------
  572. Port-Index: 04h              Port: 03c4h
  573. usage:      Memory mode register
  574.             d4-d7 Reserved
  575.             d3    Chain 4 (address bits 0&1 to select plan, mode 13h)
  576.             d2    Odd/even (address bit 0 to select plane 0&2 or   
  577.                   1&3 text modes)
  578.             d1    Extended memory (disable 64k modes)
  579.             d0    Reserved
  580. Description:
  581. ------------------------------------------------------------
  582. Port-Index: 00h              Port: 03ceh
  583. usage:      Set / Reset register
  584.             d7-d4 Reserved (0)
  585.             d3    Fill data for plane 3
  586.             d2    Fill data for plane 2
  587.             d1    Fill data for plane 1
  588.             d0    Fill data for plane 0
  589. ------------------------------------------------------------
  590. Port-Index: 01h              Port: 03ceh
  591. usage:      Set / Reset enable register
  592.             d7-d4 Reserved (0)
  593.             d3    enable set/reset for plane 3 (1 = enable)
  594.             d2    enable set/reset for plane 2 (1 = enable)
  595.             d1    enable set/reset for plane 1 (1 = enable)
  596.             d0    enable set/reset for plane 0 (1 = enable)
  597. Description: Set/Reset enable defines which memory planes will
  598.              receive fill data from set/reset register. Any plane
  599.              that is disable for set/reset will be written with
  600.              normal processor output data
  601. ------------------------------------------------------------
  602. Port-Index: 02h              Port: 03ceh
  603. usage:      Color compare register
  604.             d7-d4 Reserved
  605.             d3    Color compare value for plane 3
  606.             d2    Color compare value for plane 2
  607.             d1    Color compare value for plane 1
  608.             d0    Color compare value for plane 0
  609. Description: one indicate that color is the same
  610. ------------------------------------------------------------
  611. Port-Index: 03h              Port: 03ceh
  612. usage:      Data rotate / Function select register
  613.             d7-d5 Resrved (0)
  614.             d4,d3 Function select
  615.             d2-d0 Rotate count
  616.  
  617.             d4 d3  Function
  618.             0  0   Write data unmodified
  619.             0  1   Write data ANDed with processor latches
  620.             1  0   Write data ORed with processor latches
  621.             1  1   Write data XORed with processor latches
  622. Description: Rotation is made before writing data
  623. ------------------------------------------------------------
  624. Port-Index: 04h              Port: 03ceh
  625. usage:      Read plane select register
  626.             d7-d2 Reserved (0)
  627.             d1,d0 Defines color plane for reading (0-3)
  628. Description: Doesnt matter in color compare mode
  629. ------------------------------------------------------------
  630. Port-Index: 05h              Port: 03ceh
  631. usage:      Mode register
  632.             d7    Reserved (0)
  633.             d6    256-colour mode
  634.             d5    Shift register mode
  635.             d4    Odd / Even mode
  636.             d3    Color compare mode enable (1 = enable)
  637.             d2    Reserved (0)
  638.             d1,d0 Write mode
  639.  
  640.             d1 d0 Write mode
  641.             0  0  Direct write (data rotate, set/reset may apply)
  642.             0  1  Use processor latches as write data
  643.             1  0  Color plane n (0-3) is filled with the value of
  644.                   bit n in the write data
  645.             1  1  Use (rotated) write data ANDed with Bit mask as
  646.                   bit mask. Use set/reset as if set/reset was
  647.                   enable for all planes
  648. Description:
  649. ------------------------------------------------------------
  650. Port-Index: 06h              Port: 03ceh
  651. usage:      Miscellaneous register
  652.             d7-d4 Reserved
  653.             d3-d2 Memory map
  654.                   00 = A000h for 128k
  655.                   01 = A000h for 64k
  656.                   10 = B000h for 32k
  657.                   11 = B800h for 32k
  658.             d1    Odd/even enable (used in text modes)
  659.             d0    Graphics mode enable
  660. Description: Memory map defines the location and size of the
  661.              host window
  662. ------------------------------------------------------------
  663. Port-Index: 07h              Port: 03ceh
  664. usage:      Color don't care register
  665.             d7-d4 Reserved (0)
  666.             d3    Plane 3 don't care
  667.             d2    Plane 2 don't care
  668.             d1    Plane 1 don't care
  669.             d0    Plane 0 don't care
  670. Description: Color don't care is used in conjunction with color
  671.              compare mode. This register masks particular planes
  672.              from being tested during color compare cycles.
  673. ------------------------------------------------------------
  674. Port-Index: 08h              Port: 03ceh
  675. usage:      Bitmask register
  676. Description: The bitmask register is used to mask certain bit
  677.              positons from being modified.
  678. ------------------------------------------------------------
  679. Port-Index: -                 Port: 03c0h both index and data
  680. usage:      d7,d6 Reserved
  681.             d5    Palette address source
  682.                   0 = palette can be modified, screen is blanked
  683.                   1 = screen is enable, palette cannot be modified
  684.             d4-d0 Palette register address
  685. Description: Palette register address selects which register of
  686.              the attributes controller will be addres,sed by the
  687.              next I/O write cycle
  688. ------------------------------------------------------------
  689. Port-Index: 00h-0fh          Port: 03c0h
  690. usage:      Color palette register
  691.             d6,d7 Reserved
  692.             d5-d0 Color value
  693. Description: not used in 256 color modes
  694. ------------------------------------------------------------
  695. Port-Index: 10h              Port: 03c0h
  696. usage:      Mode control register
  697.             d7  p4,p5 source select
  698.             d6  pixel width
  699.             d5  Horizontal panning compatibility
  700.             d4  Reserved
  701.             d3  Background intensify / enable blinking
  702.             d2  Line graphics enable (text modes only)
  703.             d1  display type
  704.             d0  graphics / text mode
  705. Description: p4,p5 source select: selects the source for video
  706.               outputs p4 and p5 to the DACs. If set to zero, p4
  707.               and p5 are driven from the palette registers (normal
  708.               operation). If set to one, p4 and p5 video outputs
  709.               come from bits 0 and 1 of the color select register.
  710.              pixel width: is set to one in mode 13h (256-color mode)
  711.              horizontal panning compatibility: enhances the
  712.               operation of the line compare register of the CRT
  713.               controller, which allows one section of the screen
  714.               to be scrolled while another section remains stationary.
  715.               When this bit is set to one, the stationary
  716.               section of the screen will also be immune to horizontal
  717.               panning.
  718. ------------------------------------------------------------
  719. Port-Index: 11h              Port: 03c0h
  720. usage:      Screen border color
  721. Description: In text modes, the screen border color register
  722.              selects the color of the border that sorrounds the
  723.              text display area on the screen. This is also referred
  724.              to by IBM as overscan. Unfortunately, this feature
  725.              does not work properly on EGA displays in 350-line
  726.              modes.
  727. ------------------------------------------------------------
  728. Port-Index: 12h              Port: 03c0h
  729. usage:      Color plane enable register
  730.             d7,d6 Reserved
  731.             d5,d4 Video status mux
  732.             d3    Enable color plane 3
  733.             d2    Enable color plane 2
  734.             d1    Enable color plane 1
  735.             d0    Enable color plane 0
  736. Description:  The video status mux bits can be used in conjunction
  737.              with the diagnostic bits of input status register 1
  738.              to read palette registers. For the EGA, this is the
  739.              only means available for reading the palette registers.
  740.               Enable color planes can be used to enable or disable
  741.              color planes at the input to the color lockup table.
  742.              A zero in any of these bit positions will mask the
  743.              data from that color plane. The effect on the display
  744.              will be the same as if that color plane were cleared
  745.              to all zeros.
  746. ------------------------------------------------------------
  747. Port-Index: 13h              Port: 03c0h
  748. usage:      Horizontal panning register
  749.             d7-d4 reserved
  750.             d3-d0 Horizontal pan
  751. Description: Horizontal pan allows the display to be shifted
  752.              horizontally one pixel at a time.
  753.  
  754.              d3-d0      Number of pixels shifted to the left
  755.                         0+,1+,2+     13h     Other modes
  756.                         3+,7,7+
  757.              0          1            0       0
  758.              1          2            1       -
  759.              2          3            2       1
  760.              3          4            3       -
  761.              4          5            4       2
  762.              5          6            5       -
  763.              6          7            6       3
  764.              7          8            7       -
  765.              8          9            -       -
  766. ------------------------------------------------------------
  767. Port-Index: 14h              Port: 03c0h
  768. usage:      Color select register
  769.             d7-d4 Reserved
  770.             d3    color 7
  771.             d2    color 6
  772.             d1    color 5
  773.             d0    color 4
  774. Description:  Color 7 and color 6: are normally used as the high
  775.              order bits of the eight-bit video color data from the
  776.              attribute controller to the DACs. The only exceptions
  777.              are 256-color modes
  778.               Color 5 and color 4: can be used in place of the p5
  779.              and p6 outputs from the palette registers (see mode
  780.              control register - index 10h). In 16-color modes, the
  781.              color select register can be used to rapidly cycle
  782.              between sets of colors in the video DAC.
  783. ------------------------------------------------------------
  784. Port-Index: -                Port: 03c6h
  785. usage:      Pixel mask register
  786. Description: ???
  787. ------------------------------------------------------------
  788. Port-Index: -                Port: 03c7h
  789. usage:      DAC state register (read-only)
  790. Description: if d0 and d1 is set to zero it indicates that
  791.              the lookup table is in a write mode
  792. ------------------------------------------------------------
  793. Port-Index: -                Port: 03c7h
  794. usage:      Lookup table read index register (Write only)
  795. Description: Used when you want to read the palette (set color
  796.              number)
  797. ------------------------------------------------------------
  798. Port-Index: -                Port: 03c8h
  799. usage:      Lookup table write index register
  800. Description: Used when you want to change palette (set color
  801.              number)
  802. ------------------------------------------------------------
  803. Port-Index: -                Port: 03c9h
  804. usage:      Lookup table data register
  805. Description: Read color value (Red-Green-Blue) or write same data.
  806. ------------------------------------------------------------
  807.