home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / RGP.FAQ < prev    next >
Text File  |  1996-08-02  |  68KB  |  1,692 lines

  1. VGA programming and ModeX
  2.  
  3. TBA - To Be Added
  4. [Frequently Asked Questions about VGA]
  5. Q1.1    How do I program in mode xxx on my XXX?
  6. Q1.2    What is modeX?
  7. Q1.3    How do I program the VGA?
  8. [Frequently Asked Questions about Sound Cards]
  9. Q2.1    How do I program my XXX?
  10.  
  11. --------------------------------------------------------------------------------
  12. REC.GAMES.PROGRAMMER     IBM FAQ        VGA
  13. --------------------------------------------------------------------------------
  14. Q1.1    How do I program in mode xxx on my XXX?
  15.  
  16.     Perhaps the most frustrating thing that has ever been done is
  17.     the plithera of extended VGA modes.  Unfortunately on the VGA
  18.     is general enough for this FAQ to cover.  There is much too
  19.         much to know about other mode other than those supported by
  20.     VGA, that can be covered in such a SMALL amount of FAQ room.
  21.  
  22. Q1.2    What is modeX?
  23.  
  24.      The VGA card has 256K of memory built into it.  It uses the 64K 
  25.      segment located at segment A000 for a "frame" into the 256K of
  26.      memory.  In other words, when you write to A000, the VGA card 
  27.      wakes up, grabs the data, and puts it somewhere in its 256K of
  28.      memory. 
  29.  
  30.      In VGA's mode 13H, the pixels are stored in planes like this:
  31.      (x,y) = 1 byte of pixel data for location x,y
  32.  
  33.                           ---------------------
  34.       Plane 3           | 3,0 | 7,0 | 11,0 | ...
  35.                        ---------------------
  36.       Plane 2        | 2,0 | 6,0 | 10,0 | ...
  37.                                      --------------------
  38.       Plane 1    | 1,0 | 5,0 | 9,0 | ...
  39.                 --------------------
  40.       Plane 0   | 0,0 | 4,0 | 8,0 | ...
  41.                 | 0,1 | 4,1 | 8,1 | ...
  42.         .
  43.         .
  44.      
  45.       In mode 13h, you access a pixel by using a 16-bit offset into
  46.       the video frame.  The VGA card takes the lower 2 bits and uses this
  47.       to select the plane that the byte will go to.  The other 14 bits
  48.       are used as the offset into the plane. This is what is called
  49.       "chain 4" mode.
  50.  
  51.       ModeX is identical to mode 13h, but "chain 4" mode is turned
  52.       off so that now when you access the VGA card with a 16-bit offset
  53.       into the video frame, it uses the "Map Mask" register value to 
  54.       determine what plane to write to and then uses your 16-bit offset
  55.             to offset into the plane.  In other words, you now have an 18-bit
  56.       address by using a 16-bit pointer and a 2-bit out.  This allows you
  57.       to then access all 256K of the VGA memory, at the expense of having
  58.       to do an OUT for every pixel.
  59.  
  60.       But remember, internally, the data is stored *IDENTICALLY*.
  61.  
  62.       You just have to choose between a "slow" 18-bit pointer or
  63.       a "fast" 16-bit pointer to decide whether to use ModeX or not.
  64.  
  65. Q1.3    How do I program the VGA?
  66.  
  67.     Well the following should help, there are several books on
  68.         programing the VGA chipset.  If the following appears
  69.     complicated, sorry such is the nature of VGA!
  70.  
  71. Documentation over the I/O registers for standard VGA-cards
  72.  
  73. Documentated by Shaggy of The Yellow One.
  74.  
  75. Email: D91-SJD@TEKN.HJ.SE
  76.  
  77. Feel free to spread this to who ever wants it.....
  78. ------------------------------------------------------------
  79. Port-Index:  -               Port: Write/03c2h Read/03cch
  80. usage:       d7   Vertical sync polarity
  81.              d6   Horizontal sunc polarity
  82.              d5   Odd /even page
  83.              d4   Disable video
  84.              d3   Clock select 1
  85.              d2   Clock select 0
  86.                          d1   Enable/Disable display RAM
  87.              d0   I/O address select
  88. Description: Sync polarity: Bits are set as below for VGA displays
  89.              that use sync polarity to determine screen resolution.
  90.              Many newer multiple frequency displays are insensitive
  91.                          to sync polarity
  92.  
  93.              d7 d6      Resolution
  94.              0  0       Invalid
  95.              0  1       400 lines
  96.              1  0       350 lines
  97.              1  1       480 lines
  98.  
  99.              I/o address select: When set to zero, selects the
  100.              monochrome I/O address space (3bx). When set to one,
  101.              it selects the color I/O address space (3dx)
  102.  
  103. ------------------------------------------------------------
  104. Port-Index: -                Port: 03c2h ; read only
  105. usage:      d7    Vertical Retrace Interrupt pendling
  106.             d6    Feature connector bit 1
  107.             d5    Feature connector bit 0
  108.             d4    Switch sense
  109.                         d0-d3 Unused
  110.  
  111. Description: d7 uses IRQ2
  112.  
  113. ------------------------------------------------------------
  114. Port-Index: -                Port: 03bah,03dah ; read only
  115. usage:      d3  Vertical retrace
  116.             d0  Horizontal retrace
  117.  
  118. ------------------------------------------------------------
  119. Port-Index: -                Port: 03c3h,46e8h
  120. usage:      d7-d1  Reserved
  121.             d0     VGA enable/disable (03c3h only)
  122.  
  123. Description: Disables access to display memmory and the other
  124.              VGA's ports
  125.  
  126. ------------------------------------------------------------
  127. Port-Index: 00h              Port: 03d4h, 03b4h
  128. usage:      Horizontal total
  129. Description: Total number of characters in horizontal scan minus
  130.              five ( including blanked and border characters)
  131.  
  132. ------------------------------------------------------------
  133. Port-Index: 01h              Port: 03d4h, 03b4h
  134. usage:      Horizontal display enable
  135. Description: Total number of characters displayed in horizontal
  136.              scan minus one.
  137. ------------------------------------------------------------
  138. Port-Index: 02h              Port: 03d4h, 03b4h
  139. usage:      Start horizontal blanking
  140. Description: Character at which blanking starts
  141.  
  142. ------------------------------------------------------------
  143. Port-Index: 03h              Port: 03d4h, 03b4h
  144. usage:      End horizontal blanking
  145.                         d7    Test
  146.             d6    Skew control
  147.             d5    Skew control
  148.             d0-d4 End blanking
  149. Description: End blanking: is five LSB bits of six-bit value,
  150.              which define the character at which blanking stops.
  151.              The MSB bit of this value is in register index 5.
  152.  
  153. ------------------------------------------------------------
  154. Port-Index: 04h              Port: 03d4h, 03b4h
  155. usage:      Start horizontal retrace
  156. Description: Character at which horizontal retrace starts
  157.  
  158. ------------------------------------------------------------
  159. Port-Index: 05h              Port: 03d4h, 03b4h
  160. usage:      End horizontal retrace
  161.             d7    End horizontal blanking bit 5
  162.             d6    Horizontal retrace delay
  163.                         d5    Horizontal retrace delay
  164.             d0-d4 End horizontal retrace
  165. Description: End horizontal retrace: defines the character at
  166.              which horizontal retrace ends
  167.  
  168. ------------------------------------------------------------
  169. Port-Index: 06h              Port: 03d4h, 03b4h
  170. usage:      Vertical total
  171. Description: Total number of horizontal scan lines minus two
  172.              (including blanked and border characters). MSB bits
  173.              of this value are in register index 7
  174.  
  175. ------------------------------------------------------------
  176. Port-Index: 07h              Port: 03d4h, 03b4h
  177. usage:      Overflow register
  178.             d7  Vertical retrace start (bit 9)
  179.             d6  Vertical display enable end (bit 9)
  180.             d5  Vertical total (bit 9)
  181.                         d4  Line compare (bit 8)
  182.             d3  Start vertical blank (bit 8)
  183.             d2  Vertical retrace start (bit 8)
  184.             d1  Vertical display enable end (bit 8)
  185.             d0  Vertical total (bit 8)
  186. ------------------------------------------------------------
  187. Port-Index: 08h              Port: 03d4h, 03b4h
  188. usage:      Preset row scan
  189.             d7    Unused
  190.             d6    Byte panning control
  191.             d5    Byte panning control
  192.             d0-d4 Preset row scan
  193. Description: Byte panning control: is used to control byte
  194.                          panning. This register together with attribute
  195.              controller register 13h allows for up to 31 pixels of
  196.              panning in double word modes
  197.              Preset row scan: Which character scan line is the
  198.              first to be displayed
  199. ------------------------------------------------------------
  200. Port-Index: 09h              Port: 03d4h, 03b4h
  201. usage:      Maximum scan line/Character height
  202.             d7    double scan
  203.             d6    bit d9 of line compare register
  204.             d5    bit d9 of start vertical blank register
  205.             d0-d4 Maximum scan line
  206. Description: d0-d5=Character height-1,  only in textmodes
  207. ------------------------------------------------------------
  208. Port-Index: 0ah              Port: 03d4h, 03b4h
  209. usage:      Cursor start
  210.             d7,d6 Reserved (0)
  211.             d5    Cursor off
  212.                         d4-d0 Cursor start
  213. Description:
  214. ------------------------------------------------------------
  215. Port-Index: 0bh              Port: 03d4h, 03b4h
  216. usage:      Cursor end
  217.                         d7    reserved
  218.             d6,d5 Cursor skew
  219.             d4-d0 Cursor end
  220. Description:
  221. ------------------------------------------------------------
  222. Port-Index: 0ch              Port: 03d4h, 03b4h
  223. usage:      Start address high
  224. ------------------------------------------------------------
  225. Port-Index: 0dh              Port: 03d4h, 03b4h
  226. usage:      Start address low
  227. Description: Determine the offset in display memory to be
  228.              displayed on the upper-left corner on the screen
  229. ------------------------------------------------------------
  230. Port-Index: 0eh              Port: 03d4h, 03b4h
  231. usage:      Cursor location (high byte)
  232. ------------------------------------------------------------
  233. Port-Index: 0fh              Port: 03d4h, 03b4h
  234. usage:      Cursor location (low byte)
  235. Description: Where the cursor is displayed on screen
  236. ------------------------------------------------------------
  237. Port-Index: 10h              Port: 03d4h, 03b4h
  238. usage:      Vertical retrace start
  239. Description: 8 bits out of 10
  240. ------------------------------------------------------------
  241. Port-Index: 11h              Port: 03d4h, 03b4h
  242. usage:      Vertical retrace end
  243.             d7    Write protect CRTC register 0 to 7
  244.             d6    refresh cycle select
  245.             d5    enable vertical interrupt (when 0)
  246.             d4    Clear vertical interrupt (when 0)
  247.             d0-d3 Vertical retrace end
  248. ------------------------------------------------------------
  249. Port-Index: 12h              Port: 03d4h, 03b4h
  250. usage:      Vertical display enable end
  251. Description: eight LSB bits out of ten-bit value which define
  252.              scan line minus one at which the display ends.
  253.                          The other two are in CRTC register index 7
  254. ------------------------------------------------------------
  255. Port-Index: 13h              Port: 03d4h, 03b4h
  256. usage:      Offset / Logical screen width
  257. Description: Logical screen width between successive scan lines
  258. ------------------------------------------------------------
  259. Port-Index: 14h              Port: 03d4h, 03b4h
  260. usage:      Underline location register
  261.             d7    Reserved
  262.             d6    Double word mode
  263.             d5    count by 4
  264.             d0-d4 Underline location
  265. Description: Underline location: Monochrome textmode only
  266. ------------------------------------------------------------
  267. Port-Index: 15h              Port: 03d4h, 03b4h
  268. usage:      Start vertical blanking
  269. Description: eight LSB bits of ten-bit value minus one which
  270.              define at which scan line the vertical blanking
  271.                          starts. The other two bits are in CRTC registers
  272.              index 7 and 9
  273. ------------------------------------------------------------
  274. Port-Index: 16h              Port: 03d4h, 03b4h
  275. usage:      End vertical blanking
  276. Description: eight LSB bits of a value which determine the scan
  277.              line after which vertical blanking ends.
  278. ------------------------------------------------------------
  279. Port-Index: 17h              Port: 03d4h, 03b4h
  280. usage:      Mode control register
  281.             d7  Enable vertical and hoizontal retrace
  282.             d6  Byte mode (1), word mode (0)
  283.             d5  Address wrap
  284.                         d4  Reserved
  285.             d3  count by 2
  286.             d2  multiple vertical by 2 (use half in
  287.                 CRTC (8,10,12,14,18)
  288.             d1  Select row scan counter (not used)
  289.                         d0  compatibilty mode support (enable interleave)
  290. ------------------------------------------------------------
  291. Port-Index: 18h              Port: 03d4h, 03b4h
  292. usage:      Line compare register
  293. Description: Split screen,  8 bit value out of a ten-bit value
  294. ------------------------------------------------------------
  295. Port-Index: 00h              Port: 03c4h
  296. usage:      Reset register
  297.             d7-d2 Reserved
  298.             d1    Synchronous reset
  299.             d0    Asynchronous reset
  300. Description: Synchr. when set to zero, will halt and reset
  301.              the sequencer at the end of its current cycle
  302.                          Asyncht. when set to zero, will immediatly halt
  303.              and reset the sequencer. Data can be loss.
  304. ------------------------------------------------------------
  305. Port-Index: 01h              Port: 03c4h
  306. usage:      Clock mode register
  307.                         d7,d6 Reserved
  308.             d5    display off
  309.             d4    Allow 32-bit Fetch (not used in standard modes)
  310.             d3    Divide dot clock by 2 (used in some 320*200 modes)
  311.             d2    Allow 16-bit fetch (used in mon graphics modes)
  312.             d1    Reserved
  313.             d0    Enable (0) 9 dot characters (mono text and 400-line)
  314. Description: Display off: Will blank screen and give the cpu
  315.              uninterrupted access the display memory.
  316. ------------------------------------------------------------
  317. Port-Index: 02h              Port: 03c4h
  318. usage:      Color plane write enable register
  319.             d7,d6 Reserved
  320.                         d3    Plane 3 Write enable
  321.             d2    Plane 2 Write enable
  322.             d1    Plane 1 Write enable
  323.             d0    Plane 0 Write enable
  324. Description:
  325. ------------------------------------------------------------
  326. Port-Index: 03h              Port: 03c4h
  327. usage:      Character generator select register
  328.             d7,d6 Reserved
  329.             d5    Character generator table select A (MSB)
  330.             d4    Character generator table select B (MSB)
  331.             d3,d2 Character generator table select A
  332.             d1,d0 Character generator table select B
  333. Description: This register is only of interest if your software
  334.              will be using multiple character sets. Either one
  335.              or two character sets can be active. Table A selects
  336.              the charcater with attribute d3 set to zero and
  337.              Table B is the one with d3 set to one.
  338. ------------------------------------------------------------
  339. Port-Index: 04h              Port: 03c4h
  340. usage:      Memory mode register
  341.             d4-d7 Reserved
  342.             d3    Chain 4 (address bits 0&1 to select plan, mode 13h)
  343.                         d2    Odd/even (address bit 0 to select plane 0&2 or
  344.                   1&3 text modes)
  345.             d1    Extended memory (disable 64k modes)
  346.             d0    Reserved
  347. Description:
  348. ------------------------------------------------------------
  349. Port-Index: 00h              Port: 03ceh
  350. usage:      Set / Reset register
  351.             d7-d4 Reserved (0)
  352.             d3    Fill data for plane 3
  353.             d2    Fill data for plane 2
  354.             d1    Fill data for plane 1
  355.             d0    Fill data for plane 0
  356. ------------------------------------------------------------
  357. Port-Index: 01h              Port: 03ceh
  358. usage:      Set / Reset enable register
  359.             d7-d4 Reserved (0)
  360.             d3    enable set/reset for plane 3 (1 = enable)
  361.                         d2    enable set/reset for plane 2 (1 = enable)
  362.             d1    enable set/reset for plane 1 (1 = enable)
  363.             d0    enable set/reset for plane 0 (1 = enable)
  364. Description: Set/Reset enable defines which memory planes will
  365.              receive fill data from set/reset register. Any plane
  366.              that is disable for set/reset will be written with
  367.              normal processor output data
  368. ------------------------------------------------------------
  369. Port-Index: 02h              Port: 03ceh
  370. usage:      Color compare register
  371.             d7-d4 Reserved
  372.             d3    Color compare value for plane 3
  373.             d2    Color compare value for plane 2
  374.                         d1    Color compare value for plane 1
  375.             d0    Color compare value for plane 0
  376. Description: one indicate that color is the same
  377. ------------------------------------------------------------
  378. Port-Index: 03h              Port: 03ceh
  379. usage:      Data rotate / Function select register
  380.             d7-d5 Resrved (0)
  381.             d4,d3 Function select
  382.             d2-d0 Rotate count
  383.  
  384.             d4 d3  Function
  385.             0  0   Write data unmodified
  386.             0  1   Write data ANDed with processor latches
  387.             1  0   Write data ORed with processor latches
  388.             1  1   Write data XORed with processor latches
  389. Description: Rotation is made before writing data
  390. ------------------------------------------------------------
  391. Port-Index: 04h              Port: 03ceh
  392. usage:      Read plane select register
  393.             d7-d2 Reserved (0)
  394.             d1,d0 Defines color plane for reading (0-3)
  395. Description: Doesnt matter in color compare mode
  396. ------------------------------------------------------------
  397. Port-Index: 05h              Port: 03ceh
  398. usage:      Mode register
  399.             d7    Reserved (0)
  400.             d6    256-colour mode
  401.             d5    Shift register mode
  402.             d4    Odd / Even mode
  403.             d3    Color compare mode enable (1 = enable)
  404.             d2    Reserved (0)
  405.             d1,d0 Write mode
  406.  
  407.             d1 d0 Write mode
  408.             0  0  Direct write (data rotate, set/reset may apply)
  409.             0  1  Use processor latches as write data
  410.                         1  0  Color plane n (0-3) is filled with the value of
  411.                   bit n in the write data
  412.             1  1  Use (rotated) write data ANDed with Bit mask as
  413.                   bit mask. Use set/reset as if set/reset was
  414.                   enable for all planes
  415. Description:
  416. ------------------------------------------------------------
  417. Port-Index: 06h              Port: 03ceh
  418. usage:      Miscellaneous register
  419.             d7-d4 Reserved
  420.             d3-d2 Memory map
  421.                   00 = A000h for 128k
  422.                   01 = A000h for 64k
  423.                   10 = B000h for 32k
  424.                   11 = B800h for 32k
  425.             d1    Odd/even enable (used in text modes)
  426.             d0    Graphics mode enable
  427. Description: Memory map defines the location and size of the
  428.                          host window
  429. ------------------------------------------------------------
  430. Port-Index: 07h              Port: 03ceh
  431. usage:      Color don't care register
  432.             d7-d4 Reserved (0)
  433.                         d3    Plane 3 don't care
  434.             d2    Plane 2 don't care
  435.             d1    Plane 1 don't care
  436.             d0    Plane 0 don't care
  437. Description: Color don't care is used in conjunction with color
  438.              compare mode. This register masks particular planes
  439.              from being tested during color compare cycles.
  440. ------------------------------------------------------------
  441. Port-Index: 08h              Port: 03ceh
  442. usage:      Bitmask register
  443. Description: The bitmask register is used to mask certain bit
  444.              positons from being modified.
  445. ------------------------------------------------------------
  446. Port-Index: -                 Port: 03c0h both index and data
  447. usage:      d7,d6 Reserved
  448.             d5    Palette address source
  449.                   0 = palette can be modified, screen is blanked
  450.                   1 = screen is enable, palette cannot be modified
  451.                         d4-d0 Palette register address
  452. Description: Palette register address selects which register of
  453.              the attributes controller will be addres,sed by the
  454.              next I/O write cycle
  455. ------------------------------------------------------------
  456. Port-Index: 00h-0fh          Port: 03c0h
  457. usage:      Color palette register
  458.             d6,d7 Reserved
  459.             d5-d0 Color value
  460. Description: not used in 256 color modes
  461. ------------------------------------------------------------
  462. Port-Index: 10h              Port: 03c0h
  463. usage:      Mode control register
  464.                         d7  p4,p5 source select
  465.             d6  pixel width
  466.             d5  Horizontal panning compatibility
  467.             d4  Reserved
  468.             d3  Background intensify / enable blinking
  469.                         d2  Line graphics enable (text modes only)
  470.             d1  display type
  471.             d0  graphics / text mode
  472. Description: p4,p5 source select: selects the source fZ              outputs p4 and p5 to the DACs. If set to zero, p4
  473.               and p5 are driven from the palette registers (normal
  474.               operation). If set to one, p4 and p5 video outputs
  475.               come from bits 0 and 1 of the color select register.
  476.              pixel width: is set to one in mode 13h (256-color mode)
  477.              horizontal panning compatibility: enhances the
  478.               operation of the line compare register of the CRT
  479.               controller, which allows one section of the screen
  480.               to be scrolled while another section remains stationary.
  481.               When this bit is set to one, the stationary
  482.                             section of the screen will also be immune to horizontal
  483.               panning.
  484. ------------------------------------------------------------
  485. Port-Index: 11h              Port: 03c0h
  486. usage:      Screen border color
  487. Description: In text modes, the screen border color register
  488.              selects the color of the border that sorrounds the
  489.              text display area on the screen. This is also referred
  490.              to by IBM as overscan. Unfortunately, this feature
  491.              does not work properly on EGA displays in 350-line
  492.              modes.
  493. ------------------------------------------------------------
  494. Port-Index: 12h              Port: 03c0h
  495. usage:      Color plane enable register
  496.             d7,d6 Reserved
  497.             d5,d4 Video status mux
  498.             d3    Enable color plane 3
  499.             d2    Enable color plane 2
  500.                         d1    Enable color plane 1
  501.             d0    Enable color plane 0
  502. Description:  The video status mux bits can be used in conjunction
  503.              with the diagnostic bits of input status register 1
  504.              to read palette registers. For the EGA, this is the
  505.                          only means available for reading the palette registers.
  506.               Enable color planes can be used to enable or disable
  507.              color planes at the input to the color lockup table.
  508.              A zero in any of these bit positions will mask the
  509.              data from that color plane. The effect on the display
  510.              will be the same as if that color plane were cleared
  511.              to all zeros.
  512. ------------------------------------------------------------
  513. Port-Index: 13h              Port: 03c0h
  514. usage:      Horizontal panning register
  515.             d7-d4 reserved
  516.             d3-d0 Horizontal pan
  517. Description: Horizontal pan allows the display to be shifted
  518.                          horizontally one pixel at a time.
  519.  
  520.              d3-d0      Number of pixels shifted to the left
  521.                         0+,1+,2+     13h     Other modes
  522.                         3+,7,7+
  523.                          0          1            0       0
  524.              1          2            1       -
  525.              2          3            2       1
  526.              3          4            3       -
  527.              4          5            4       2
  528.              5          6            5       -
  529.              6          7            6       3
  530.              7          8            7       -
  531.              8          9            -       -
  532. ------------------------------------------------------------
  533. Port-Index: 14h              Port: 03c0h
  534. usage:      Color select register
  535.             d7-d4 Reserved
  536.                         d3    color 7
  537.             d2    color 6
  538.             d1    color 5
  539.             d0    color 4
  540. Description:  Color 7 and color 6: are normally used as the high
  541.                          order bits of the eight-bit video color data from the
  542.              attribute controller to the DACs. The only exceptions
  543.              are 256-color modes
  544.               Color 5 and color 4: can be used in place of the p5
  545.              and p6 outputs from the palette registers (see mode
  546.              control register - index 10h). In 16-color modes, the
  547.              color select register can be used to rapidly cycle
  548.              between sets of colors in the video DAC.
  549. ------------------------------------------------------------
  550. Port-Index: -                Port: 03c6h
  551. usage:      Pixel mask register
  552. Description: ???
  553. ------------------------------------------------------------
  554. Port-Index: -                Port: 03c7h
  555. usage:      DAC state register (read-only)
  556. Description: if d0 and d1 is set to zero it indicates that
  557.              the lookup table is in a write mode
  558. ------------------------------------------------------------
  559. Port-Index: -                Port: 03c7h
  560. usage:      Lookup table read index register (Write only)
  561. Description: Used when you want to read the palette (set color
  562.              number)
  563. ------------------------------------------------------------
  564. Port-Index: -                Port: 03c8h
  565. usage:      Lookup table write index register
  566. Description: Used when you want to change palette (set color
  567.              number)
  568. ------------------------------------------------------------
  569. Port-Index: -                Port: 03c9h
  570. usage:      Lookup table data register
  571. Description: Read color value (Red-Green-Blue) or write same data.
  572.  
  573. --------------------------------------------------------------------------------
  574. REC.GAMES.PROGRAMMER     IBM FAQ        Sound Cards
  575. --------------------------------------------------------------------------------
  576. Q2.1    How do I program my XXX?
  577.  
  578.     This question is asked a lot, there is information available
  579.     for the adlib, but for many of the NEWER cards this is a
  580.     problem.  The suggestion of rec.games.programmers is to read
  581.     the pc sound card group or the pc demos group.  Why?  Too
  582.     many cards unless someone else wishes to get the information
  583.     and make YAF! (yet another FAQ)
  584.  
  585. --------------------------------------------------------------------------------
  586. END OF FAQ
  587.  
  588.  
  589.  
  590.  
  591. Article 17548 of rec.games.programmer:
  592. Newsgroups: rec.games.programmer
  593. Path: usenet.ucs.indiana.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!news.intercon.com!panix!ddsw1!news.kei.com!ub!acsu.buffalo.edu!pleung
  594. From: pleung@cs.buffalo.edu (Patrick Leung)
  595. Subject: REPOST:  Mode X FAQ, part 2/2
  596. Message-ID: <Cp3uE7.9EA@acsu.buffalo.edu>
  597. Sender: nntp@acsu.buffalo.edu
  598. Nntp-Posting-Host: gagarin.cs.buffalo.edu
  599. Organization: State University of New York at Buffalo/Comp Sci
  600. Date: Sun, 1 May 1994 03:44:30 GMT
  601. Lines: 1087
  602.  
  603. Article 21306 of rec.games.programmer:
  604. Path: acsu.buffalo.edu!ub!toz!news
  605. From: cyberman@toz.buffalo.ny.us
  606. Newsgroups: rec.games.programmer
  607. Subject: RGP FAQ
  608. Message-ID: <gate.75gkHc1w165w@toz.buffalo.ny.us>
  609. Date: Fri, 11 Feb 94 00:01:28 EST
  610. Organization: TOZ automated posting
  611.  
  612. Revision 0.0.5  of REC.GAMES.FAQ
  613.  
  614. This document will be made available by mail request at a later
  615. date (mail server difficulties).  You may attempt to see if this
  616. mail server works by sending to:
  617.  
  618.     aser@toz.buffalo.ny.us
  619.  
  620. I cannot be sure it's working yet,  please leave feedback on what
  621. state it is in.
  622.  
  623. There are currently 3 FAQ's
  624.  
  625. RGP.FAQ - rec.games.programmer General FAQ
  626. RGP.IBM - rec.games.ibm relevant FAQ
  627. MAZE.FAQ - FAQ about MAZE's (more of a compilation of articles)
  628.  
  629. This was done so that someone who is looking for more general
  630. information will be able to find game programing information
  631. without being inundated by IBM, other computer-SPECIFIC
  632. information, or the topsy turvey world of maze generation.
  633.  
  634. The current Editor is Cyberman@toz.buffalo.ny.us
  635.  
  636. --------------------------------------------------------------------------------
  637. REC.GAMES.PROGRAMMER     General FAQ     Contents
  638. --------------------------------------------------------------------------------
  639. LEGAL
  640.  
  641. This document is FREE!  It is for your self enlightenment.  No
  642. warranty is provided nor implied with this information. The
  643. accuracy of the information contained herein is subject to
  644. conjecture.  Therefore the editor and contributers will take NO
  645. liability for improper use, misuse, or abuse of this information,
  646. and any damage to ANYTHING or ANYONE whether physical, financial,
  647. etc. in no way, shape, or form can be attributed to this
  648. document. Use this information at your OWN risk.
  649.  
  650. The above statement is to keep those who contributed and the
  651. editor free from personal injury for being nice.
  652.  
  653. Special thanks to:
  654. andrean@cs.utexas.edu (Andre A. Nurwono)
  655. roberts@brahms.amd.com (Dave Roberts)
  656. sean@stat.tamu.edu (Sean Barrett)
  657. Cyberman@toz.buffalo.ny.us (Cyberman)
  658. (and anyone else I forgot to mention for that matter)
  659.  
  660. If you wish to contribute CODE be sure it's something you DO NOT
  661. wish to COPYRIGHT!
  662.  
  663. All contributions and suggestions should be sent to me at:
  664. Cyberman@toz.buffalo.ny.us
  665. place in subject header
  666.  
  667. RGP.FAQ.*
  668. where * is any of the following
  669.     SUGGESTION      - to suggest Adding an area (I recommend that
  670.                         you send the information if you want it
  671.                         added)
  672.     ADD             - an addition (ie TBA's [see KEY for what TBA
  673.                         means])
  674.     EDIT            - for a correction somewhere (it is suggested
  675.                         contributers do there own editing)
  676.     FLAME           - complaints - I'll read these but be sure to
  677.                         be tasteful in you commentary.  You may or
  678.                         may NOT get a reply.
  679.  
  680. For now I'm going to use my personal mail account.  So please be
  681. careful.
  682.  
  683. Format:
  684. There are several categories and each category contains it's
  685. relevant questions as suggested.
  686.  
  687. Key:
  688. TBA - To Be Added
  689.  
  690. [Frequently Asked Questions about terminology]
  691. Q1.1    What are .MOD files?
  692. Q1.2    What is a pixel?
  693. Q1.3    What is a bitmap?
  694. Q1.4    What is flicker?
  695. Q1.5    What is snow?
  696. Q1.6    What is a frame buffer?
  697. Q1.7    What is a Sprite?
  698. Q1.8    What is vertical/horizontal retrace?
  699.  
  700. [Frequently Asked Questions about Animation]
  701. Q2.1    How do I make sprites on my xxx?
  702. Q2.2    What about collision detection?             TBA
  703. Q2.3    What about bitmap scaling?                  TBA
  704. Q2.4    What is perspective mapping?                TBA
  705. Q2.5    What about 3d objects and manipulation?
  706.  
  707. [Frequently Asked Questions about Map Generation]
  708. Q3.1    How do I generate a maze?
  709. Q3.2    How do I generate a landscape/terrain?      TBA
  710. Q3.3    How do I generate a hex map?                TBA
  711. Q3.4    What about random number generators?
  712.  
  713. [Frequently Asked Questions about Libraries and support software]
  714. Q4.1    What is there for the IBM compatible?
  715. Q4.2    "    "  "     "   "   Amiga?                TBA
  716. Q4.3    "    "  "     "   "   Atari?                TBA
  717. Q4.4    "    "  "     "   "   Macintosh?            TBA
  718. Q4.5    "    "  "     "   "   Sun/Sparc?
  719. Q4.6    "    "  "     "   "   X?                    TBA
  720.  
  721. [Frequently Asked Question about Where is ...]
  722. Q5.1    Where is Joshua Jensens famous Perspective Mapping Code?
  723. Q5.2    Where else should I read?
  724. Q5.3    Where can I find out about ray traceing?
  725.  
  726. Note 1: Fixing snow and flicker
  727. Note 2: 2 Part Tutorial on 3d graphics
  728.  
  729. --------------------------------------------------------------------------------
  730. REC.GAMES.PROGRAMMER     General FAQ     Terminology
  731. --------------------------------------------------------------------------------
  732.  
  733. Q1.1    What are .MOD files?
  734.     A .MOD file is a file generated for the Amiga.  A tracker is
  735.     used to play the MOD.  A mod consists of digitized sound and
  736.     sequencing information to play music.  Here is a BRIEF and
  737.     incomplete text file that is somewhat informative on the
  738.     subject.
  739.  
  740.     Note - Joshua Jensen has written a mod player that can be
  741.     linked into your code.  So has the author of mod play.
  742.  
  743.     SEE ALSO - Mod Format specification file.  (Modform.zoo)
  744.  
  745. Q1.2    What is a Pixel?
  746.  
  747.     Pixel is short for Picture Element.  It is a single dot
  748.     address on a grid used to display images on a monitor (Tv
  749.     included).
  750.  
  751. Q1.3    What is a bitmap?
  752.  
  753.     A bitmap aka bitimage is the representation of an image in
  754.     the form of a sequence of bits.  For example most graphic
  755.     modes on computers represent the pixels using a BITMAP.
  756.  
  757. Q1.4    What is flicker?
  758.     Flicker is a noticeable pulse or change in an image.  This
  759.     can be on a CRT (Cathode Ray Tube) or other type display
  760.     device.  The cause is that the refresh rate of the CRT is
  761.     lower than the persistance of vision of the person observing
  762.     it.
  763.  
  764.     Another form of flicker is due to rapid drawing of data on
  765.     the screen.  What happens is that the data is drawn out of
  766.     syncronization with the horizontal and vertical scan.  So
  767.     your image apears to fade in and out of visability.
  768.  
  769.     SEE ALSO fixing snow and Flicker
  770.  
  771. Q1.5    What is SNOW?
  772.  
  773.     Snow are small specals on the screen that appear like SNOW
  774.     falling on the screen (hence the name).
  775.  
  776.     Snow is caused by a number of things.  One of which is when
  777.     one is writting to the screen while the display card is
  778.     scanning that address of the screen, this causes a conflict
  779.     and can produce random specals.
  780.  
  781.     Another cause of snow is an improperly connected monitor.
  782.     This can damage the monitor.  Yet another source is noise
  783.     from an electro magnetic source, if indeed it's not from
  784.     anything you own the FCC might need to be notified.
  785.  
  786.     SEE ALSO fixing snow and Flicker
  787.  
  788. Q1.6    What is a frame buffer?
  789.  
  790.     Memory that contains image data that is translated to the image
  791.     on your screen.  A frame buffer does not have to be
  792.     "visible".  Also the methode of this tranformation is not
  793.         always the same, so no effort here will be made to explain
  794.     further.
  795.  
  796. Q1.7    What is a Sprite?
  797.  
  798.     A sprite is an image usually moveable about the screen.
  799.     Common information stored in a sprite are, width, height,
  800.     position, and image data.  A sprite ussually does not effect
  801.     the screen background, this is of course dependant on
  802.     implementation.
  803.  
  804. Q1.8    What is vertical/horizontal retrace?
  805.  
  806.     Most monitors are what is called a RASTER display.  This
  807.     means that an image is represented by setting the intensity
  808.     of a grid of dots on the display.  Each dot is called a
  809.     pixel.  In order to display the grid a CRT sweeps an electron
  810.     beam across the display surface sending pulses corresponding
  811.         to the intensity of the pixel.  However the stream of video
  812.     information is almost always represented left to right top to
  813.     bottom.  This mean that the beam must scan across the screen
  814.     and then move BACK to start a line.  This is called
  815.     Horizontal retrace.
  816.  
  817.     Vertical retrace is when the beam finishes painting the
  818.     screen from top to bottom again the beam must be moved to the
  819.     top of the screen.
  820.  
  821.     The horizontal sweep is controlled by an electric field the
  822.     vertical sweep is controlled usually magnetic field.
  823.  
  824. --------------------------------------------------------------------------------
  825. REC.GAMES.PROGRAMMER     General FAQ     Animation
  826. --------------------------------------------------------------------------------
  827.  
  828. [Frequently Asked Questions about Animation]
  829. Q2.1    How do I make sprites on my xxx?
  830.  
  831.     This, unfortunately, is a rather complex problem and its
  832.     implementation is often computer-specific, however some of it
  833.     can be addressed in the general FAQ.
  834.  
  835.     Sprites require one to copy pixels to the display in a
  836.     certain area of the screen.  There are various issues that
  837.     must be addressed about this.
  838.  
  839.     Getting and Putting an image: getting means you copy a
  840.     section of a screen (bitmap) to a buffer, putting means you
  841.     dump a buffer of data (bitmap) to a screen location.  These
  842.     are often used for less sophisticated sprite animation.
  843.  
  844.     The problem with this technique is put destroys the
  845.     background information.  So if you want a background at all,
  846.     there must be a way to "overlay" an image onto it without
  847.         causing a large area around the sprite to disappear. An old
  848.     way of "fixing" this is to copy the background of an image
  849.     before you destroy it, then put the background back after you
  850.     move it.
  851.  
  852.     Another methode of sprite creation requires custome hardware
  853.     (Amiga C64 Atari 8bits).
  854.  
  855. Q2.2    What about collision detection?                 TBA
  856. Q2.3    What about bitmap scaling?                      TBA
  857. Q2.4    What is perspective mapping?
  858.  
  859.     What is it?  Basically it takes an image and "pastes" it in
  860.     3d perspective onto a surface.  This is much faster than
  861.     rendering surfaces in real time.  Article 7716 of r.g.p
  862.     written by Joshua C. Jensen (sl8nl@cc.usu.edu) is an example
  863.     of this technique (implemented in Turbo Pascal).
  864.     Unfortunately this article # may not corespond to anything in
  865.         usenet! :)  However the date it was posted was 1 Aug 92
  866.     01:36:51 GMT.  SO you can grab the coresponding articles
  867.     there! :)
  868.  
  869. Q2.5    What about 3d objects and manipulation?
  870.  
  871.     Note 2 is a pair of tutorials on this subject.
  872.  
  873.     Another suggestion is to check comp.graphics FAQ and the
  874.     comp.graphics resources guide as well.
  875.  
  876. --------------------------------------------------------------------------------
  877. REC.GAMES.PROGRAMMER     General FAQ     Map Generation
  878. --------------------------------------------------------------------------------
  879.  
  880. Q3.1    How do I generate a maze?
  881.  
  882.     This is a VERY frequently asked question in rgp so we have
  883.         a unoffical maze FAQ.  It's is now posted WITH the RGP Faq.
  884.  
  885. Q3.2    How do I generate a landscape/terrain?
  886.     Another fun filled FAQ it has too many answers.  A suggestion
  887.     is to read sci.fractals.  Now if someone would conribute some
  888.     information on this I would be happy to construct the
  889.     "land.faq".
  890.  
  891. Q3.3    How do I generate/use a hex map?
  892.     Well this has discussed considerably on rgp.  We haven't a
  893.     FAQ for it until I get permission to use something I
  894.     captured.
  895.  
  896. Q3.4    What about random number generators?
  897.     These are mandatory for making a "new" universe each time a
  898.     program loads.  Usually the ones included in a C compiler 
  899.     library are sufficient for most needs.  However sometimes one
  900.     must go the extra mile and use there own random number
  901.         generator.  Currently we have no FAQ on random number
  902.     generators.  (sorry)
  903.  
  904. --------------------------------------------------------------------------------
  905. REC.GAMES.PROGRAMMER     General FAQ     Libraries and support software
  906. --------------------------------------------------------------------------------
  907.  
  908. Q4.1    What is there for the IBM and Compatibles?
  909.  
  910.     There is a lot.  I suggest scrounging around wuarchive
  911.     personally, but here is a terse UNOFFICIAL list!
  912.  
  913.     contributed by
  914. andrean@cs.utexas.edu (Andre A. Nurwono)
  915. ==========
  916.  --------
  917.  Graphics
  918.  --------
  919.  
  920. *.  Executable
  921.     File(s) : TWEAK06.ZIP
  922.     Who     : Robert Schmidt (robert@solan.unit.no)
  923.     When    : 1992
  924.     What    : A program to experiment w/ VGA registers, very useful
  925.           if you want to define new modes (like mode X & 360x400 modes)
  926.     Where   : simtel & mirrors
  927.  
  928. *.  Executable, (source code)
  929.     File    : SPRITE.ZIP
  930.     Who     : Billy Dalrymple
  931.     When    : 1989
  932.     What    : A sprite editor, produces sprites w/ mask in files.
  933.           info available for $10
  934.           source code available for $25
  935.     Where   : I forget
  936.  
  937. *.  Executable, Source Code
  938.     File(s) : VGA.ZIP
  939.     Who     : wardt@a.cs.okstate.edu
  940.     When    : 1992
  941.     What    : A sprite editor, includes full source (.ASM & .C)
  942.     Where   : I forget 
  943.  
  944. *.  Source Code, Library
  945.     File(s) : DDJ****.ZIP, XSHARP**.ZIP
  946.     Who     : M. Abrash
  947.     When    : Aug-Dec 1991, Jun-Aug 1992
  948.     What    : Mode X introduction. Sources to do animation,
  949.           polygon plotting, anti-aliasing, etc, on Mode X.
  950.     Where   : SIMTEL and mirrors, 
  951.           ftp.mv.com (Official DDJ site) in pub/ddj
  952.  
  953. *.  Source Code
  954.     File(s) : article 7198 of rec.games.programmer
  955.         Who     : Frederick J. Haab (otto@nevada.edu)
  956.     When    : 26 Jun 92 00:17:52 GMT
  957.     What    : Scrolling in mode 13h, C program
  958.     Where   : USENET archives
  959.  
  960. *.  Source Code
  961.     File(s) : article 7716 of rec.games.programmer
  962.     Who     : Joshua C. Jensen (sl8nl@cc.usu.edu)
  963.     When    : 30 Jul 92 00:02:36 GMT
  964.     What    : Bitmap manipulation (scaling + perspective), Turbo Pascal
  965.           source w/ inline assembly.
  966.     Where   : USENET archives
  967.  
  968. *.  Source Code
  969.     File(s) : VESAVGA.ZIP
  970.     Who     : Randy Buckland
  971.     When    : 6/18/92
  972.     What    : .ASM & .C source to provide fast routines for VESA VGA modes.
  973.         Where   : garbo
  974.  
  975. *.  Sprite Library, Code
  976.     File(s) : STK110.LZH
  977.     Who     : Jari Karjala
  978.     When    : 1991 (v 1.1)
  979.     What    : Sprite library & toolkit for Hi-Res EGA, BW
  980.           includes C source, demo & good docs.
  981.     Where   : simtel & mirrors
  982.  
  983. *.  Sprite Library, Source Code
  984.     File    : SPRITES.ZIP
  985.     Who     : Marius Kjeldahl
  986.     When    : 1991
  987.     What    : Sprite library for VGA mode $13
  988.           includes TPU, .PAS source.
  989.           (shareware, $69 ?)
  990.     Where   : garbo
  991.  
  992. *.  Sprite Library, Toolkit
  993.     File(s) : WGT_SPR2.ZIP, WGT_TC21.ZIP, WGT_TP2.ZIP
  994.     Who     :
  995.     When    : 1992
  996.     What    : Shareware Sprite toolkit for VGA mode $13
  997.               includes TPU (WGT_TP2.ZIP), example programs for usage
  998.           Nag-shareware program
  999.     Where   : wuarchive, if somebody hasn't erased it yet
  1000.  
  1001. *.  Library (Pascal)
  1002.     Files   : EGOF10.ZIP, EGOF10P.ZIP, EGOF10M.ZIP,
  1003.               EGOF10B.ZIP, EGOF106.ZIP
  1004.     Who     : Logi Ragnarsson
  1005.     When    : 1993
  1006.     What    : 256-colour graphics library for Turbo/Borland Pascal 6.0
  1007.               and 7.0, VESA SVGA, Mode-X (and more), VGA/MCGA 320x200,
  1008.               example programs, manual, shareware ($20).
  1009.         Where   : garbo
  1010.  
  1011. *.  Library Source
  1012.     File(s) : Xlib04c.zip
  1013.     Who     : Themie Gouthas (and company)
  1014.     When    : 11 Mar 93
  1015.     What    : mode X library for game, to many feature to mention
  1016.     Where   : pub/MSDOS_UPLOADS@wuarchive.wustl.edu
  1017.  
  1018.  -------------
  1019.  Sound & Music
  1020.  -------------
  1021.  
  1022. *.  Documentation
  1023.     File(s) : Article 6077 of rec.games.programmer
  1024.     Who     : Jeffrey S. Lee (jlee@smylex.uucp)
  1025.     When    : 25 Feb 92 15:02:02 GMT
  1026.     What    : Programming the AdLib/Sound Blaster FM Music Chips
  1027.         Where   : usenet archives, also at the SB project site
  1028.           (tybalt.cco.caltech.edu), & SB mailserver
  1029.           (listserv@porter.geo.brown.edu)
  1030.  
  1031. *.  Executable, Runtime Library
  1032.     File(s) : MODTECH.ZIP
  1033.     Who     : Mark J. Cox (M.J.H.Cox@bradford.ac.uk)
  1034.     When    : 1991
  1035.     What    : TSR Library to play .MOD files in the background
  1036.           Supports PC Speaker, SB, DisneySS, LPT DACs, etc
  1037.     Where   : ftp.brad.ac.uk in /misc/msdos/mp
  1038.  
  1039. *.  Library
  1040.     File(s) : MODOBJ.ZIP
  1041.     Who     : Mark J. Cox (M.J.H.Cox@bradford.ac.uk)
  1042.     When    : 1992
  1043.     What    : .OBJ file w/ routines to play .MOD files in the background
  1044.           Supports PC Speaker, SB, DisneySS, LPT DACs, etc
  1045.                 Includes examples in TC & TP
  1046.           (shareware, $30)
  1047.     Where   : ftp.brad.ac.uk in /misc/msdos/mp
  1048.  
  1049. *.  Source code
  1050.     File(s) : NH10SRC.ZIP
  1051.     Who     :
  1052.     When    :
  1053.     What    : Eliminate noise on sound samples, incl. .C source
  1054.     Where   : SB project site & mailserv site
  1055.  
  1056. *.  Source code, Executable
  1057.     File(s) : SB_OSC.ZIP
  1058.     Who     :
  1059.     When    :
  1060.     What    : SB input scope / oscillator. Incl. .ASM source
  1061.     Where   : SB project site & mailserv site
  1062.  
  1063. *.  Source code, Executable
  1064.     File(s) : SBDAC.ZIP
  1065.     Who     : Jeff Bird (cejjb@marlin.jcu.edu.au)
  1066.     When    : 12 Feb 92
  1067.     What    : SB DAC programming using DMA. Incl. .ASM & .C source
  1068.     Where   : I forget (probably on SB project sites too)
  1069.  
  1070. ==========
  1071.  
  1072. Q4.2    "    "  "     "   "   Amiga?                TBA
  1073.  
  1074. Q4.3    What is there for the Atari?
  1075.  
  1076. from warwick@cs.uq.oz.au
  1077.  
  1078.     AMS library - Atari Machine Specific library
  1079.       - C++ classes for Sprites, Screen, Joysticks, Double buffering, etc.
  1080.       - beta testing now
  1081.             - contact: warwick@cs.uq.oz.au
  1082.  
  1083. Q4.4    "    "  "     "   "   Macintosh?
  1084.  
  1085. from jmunkki@vipunen.hut.fi
  1086.  
  1087. *. Source code
  1088.     Files   : Arashi_Source.cpt.bin
  1089.     Who     : ???
  1090.     When    : ???
  1091.     What    : source code for an arcade quality game, vector
  1092.         graphics, multichannel sound, (no sprites)
  1093.     Where   : pub/mac/think-c/code@ics.uci.edu
  1094.  
  1095. Q4.5    "    "  "     "   "   Sun/Sparcs?
  1096.  
  1097.     contributed by
  1098. andrean@cs.utexas.edu (Andre A. Nurwono)
  1099. ==========
  1100.  --------
  1101.  Graphics
  1102.  --------
  1103. *.  Library
  1104.     What    : Standard PIXRECT library
  1105.           Bitmap manipulation routines for frame buffer.
  1106.  
  1107.  -------------
  1108.  Music & Audio
  1109.  -------------
  1110. *.  Source code
  1111.     File(s) : tracker.tar.Z
  1112.     Who     :
  1113.     When    :
  1114.     What    : .MOD file player through the audio device. Works on SPARCS
  1115.           w/ audio devices.
  1116.     Where   :
  1117.  
  1118. *.  Source code
  1119.     File(s) : csound.tar.Z
  1120.     What    : FFT & signal processor
  1121.  
  1122. *.  Source code
  1123.     What    : MixView
  1124. ==========
  1125.  
  1126. Q4.6    "    "  "     "   "   X                     TBA
  1127.  
  1128.     Additions are welcome.
  1129.  
  1130. --------------------------------------------------------------------------------
  1131. REC.GAMES.PROGRAMMER     General FAQ     FAQ's about Where is ...
  1132. --------------------------------------------------------------------------------
  1133.  
  1134. Q5.1    Where is Joshua Jensens famous Perspective Mapping Code?
  1135.  
  1136.     Beats me no one has found it yet (or at least hasn't told me
  1137.     they have and where to get it!) in one of the many usenet
  1138.     archive sites.  Places to look are gatekeeper.com and
  1139.     wuarchive.wustl.edu.  Both of these ftp sites archive usenet
  1140.     news.  I suspect all the rec.games.programmer articles are on
  1141.     these sites and maybe (heavem forbid) the original FAQ even.
  1142.  
  1143. Q5.2    Where else should I read?
  1144.  
  1145.     Here are SUGGESTED places you get information for things like
  1146.     perspective mapping programming the SB etc.
  1147.     
  1148.         comp.graphics
  1149.         comp.graphics.animation
  1150.         comp.sys.ibm.pc.soundcard
  1151.  
  1152.     I suggest before posting you read ALL newsgroups a minimum of
  1153.         1 week.  Ussually you will see the FAQ or where to get it.
  1154.  
  1155.     places suggested NOT to look for information
  1156.  
  1157.         comp.graphics.research
  1158.  
  1159.         if you want to get famed for posting off topic do it
  1160.         there.  That group is for research IE new frontiers.
  1161.  
  1162. Q5.3    Where can I find out about ray traceing?
  1163.  
  1164.     Ask about POV in comp.graphics should be good for about 30 to
  1165.     40 replies in your mailbox.  There are several packages
  1166.     available for free and comercially.  I suggest POV because
  1167.     it's free and actually quite good.  Vivid, Rayshade are just
  1168.     a few of the others.  POV seems to be the most popular (and
  1169.     portable also), with the most handy utilities.
  1170.  
  1171. --------------------------------------------------------------------------------
  1172. END OF FAQ
  1173.  
  1174. --------------------------------------------------------------------------------
  1175. REC.GAMES.PROGRAMMER     General FAQ     NOTES
  1176. --------------------------------------------------------------------------------
  1177.  
  1178. --------------------------------------------------------------------------------
  1179. NOTE 1: contributed by
  1180. --------------------------------------------------------------------------------
  1181. sean@stat.tamu.edu (Sean Barrett)
  1182.  
  1183. There are two things that qualify as flicker.  Well, hell, to make it
  1184. simpler, let's call it three.  At the end of this list I'll give a
  1185. rough definition of the problem.
  1186.  
  1187. 1)    You move a shape by erasing it and plotting it in a new position,
  1188. and there is a screen refresh during the time it is erased, resulting in
  1189. the background showing through.
  1190.  
  1191. 2)    You're using CGA and you try to write anywhere on the screen
  1192. during retrace, causing "noise" (due to DMA problems, I guess?).
  1193.  
  1194. 3)    You're moving a shape by some sort of "one-pass" technique in which
  1195. the screen memory is never set to the background temporarily, so (1)
  1196. can't happen, but the screen area the shape is in is refreshed during
  1197. the draw, so half of it gets displayed at the old location, and half
  1198. at the new.
  1199.  
  1200. I think a general rule would be that flicker occurs when a pixel on
  1201. the screen is displayed with a color other than the "correct" or
  1202. "intended" pixel value, as compared to an ideal "intended" case.  (Thus,
  1203. if you're simulating something moving, you shouldn't see the
  1204. background; if you're trying to simulate something moving and
  1205. turning on and off simultaneously, then you should see it; it's
  1206. all a question of intent.)
  1207.  
  1208. Back to the above problems.
  1209.  
  1210. Now, so far as I know, there are only two solutions to #2.  Only redraw
  1211. during the vertical retrace (blank), or don't support CGA.  So I'm going
  1212. to forget about this problem.
  1213.  
  1214. You can handle #1, as I suggested in #3, by simply making sure you never
  1215. write to the screen a value you don't want displayed.  Below I'll put a
  1216. list of ways I can think of to do this for bitmapped graphics--i.e.,
  1217. how to avoid the erase-redraw cycle.
  1218.  
  1219. If you really want to handle #3, then things get funky, and more power
  1220. to you.  I don't personally believe it's a problem.  If it's periodic,
  1221. so this one shape when you move it horizontally in the middle of the
  1222. screen is always split with the top half leading the bottom half by
  1223. a pixel, it's a problem; but if it just happens randomly once in a while
  1224. I doubt it's noticeable.  In general, though, the solutions require
  1225. paying attention to where the screen refresh is in some way.  My main
  1226. point, the reason I'm posting this whole thing, is that *solving problem
  1227. #1 does not require messing with knowing what section of the screen
  1228. is being refreshed.*  As far as I know, the methods to combatting #3
  1229. are to redraw everything during vertical refresh (same as #2, but
  1230. overkill) or drawing your shapes from top to bottom lagging about half
  1231. the time of a screen refresh behind the refresh, or some such.
  1232.  
  1233. Solutions to #1 that don't require timing considerations, e.g., how
  1234. never to write a wrong pixel to the screen.
  1235.  
  1236.   o    Don't use raw bitmaps, use sprite hardware.
  1237.  
  1238.   o    Use hardware page flipping: display one screen, draw a new
  1239.     screen "off-screen" and when it's finished, direct the
  1240.     display hardware to display the new one.  This can get messy
  1241.     for fast animation because you have to keep track of where
  1242.     sprites were the last two frames to erase and update them.
  1243.  
  1244.   o    Use software page flipping; display one screen, draw a new
  1245.     screen "off-screen" and when it's finished, copy the new
  1246.     screen into screen memory.
  1247.  
  1248.   o    Use techniques such as "store" sprites which overwrite the
  1249.     background.  Generally an out-of-date technique now, though;
  1250.     only works for mono-color backgrounds.  You simply write the
  1251.     sprite onto the screen; the sprite has enough border around
  1252.     it to overwrite its previous image.  This is gross, very
  1253.     fast, and flicker-free except when shapes get on top of each
  1254.     other, at which point you get massive flicker.
  1255.  
  1256.   o    Use scratch-pad calculations, a variant of software page flipping.
  1257.     Copy the section of the screen off that you need to update,
  1258.     update it offscreen, and put it back on the screen.  A lengthy
  1259.     time ago I posted a discussion of how to do this effectively
  1260.     for XOR-style graphics for 8-bit type machines--you can xor
  1261.     a single image onto the screen that both erases and replots
  1262.     in a new place the old sprite.  And you can calculate the
  1263.     image to do it on the fly, without additional memory, if you
  1264.     set up your shape tables, and it's faster than the normal
  1265.     draw shape with XOR to erase, draw shape with XOR to plot cycle
  1266.     because it only reads and writes screen memory once.
  1267.  
  1268. Performance enhancements for bit blitting:
  1269.  
  1270.   o    Unroll loops.
  1271.  
  1272.   o    Write a custom bit blit for each shape, dedicated to that shape.
  1273.     Cuts your memory accessing down if the machine has an
  1274.     "immediate" operand mode that's faster than an index-addressed
  1275.     one.
  1276.  
  1277. Memory performance enhancements for techniques that require many copies
  1278. of shapes or large routines (such as pre-shifted shape tables):
  1279.  
  1280.   o    If you're only using some of your shapes at any point in time
  1281.     (e.g. if you can divide your display up into "scenes"; for a
  1282.     certain period of time only these shapes are used), calculate
  1283.     the "larger" derived tables on the fly when the scene starts
  1284.     up.  For large games (this is rec.games.programmer, not
  1285.     rec.graphics.programmer, right?) that have to access the disk
  1286.     anyway to change scenes, this is no big time loss.  Also, if
  1287.     you write the code right then while you're idling the processor
  1288.     before starting work on the next display, you can do this stuff
  1289.     then.
  1290.  
  1291. --------------------------------------------------------------------------------
  1292. NOTE 2: contributed by
  1293. --------------------------------------------------------------------------------
  1294. sean@stat.tamu.edu (Sean Barrett)
  1295.  
  1296. 3D graphics: Using matrices and vectors        Part 1
  1297.  
  1298.  
  1299. -  Allows you to independently rotate objects and move the camera
  1300.    anywhere.
  1301. -  Does not discuss clipping.
  1302. -  Algorithm uses 9 multiplies, 2 divides, and 9 additions per point,
  1303.    plus overhead per independently located object.
  1304. -  Part 2 gives the derivation for these formulas.
  1305.  
  1306.  
  1307. Assume a right-handed universe, with x horizontal, y
  1308. depth, and z vertical, and a screen display unit with
  1309. x horizontal to the right and y vertical downward.
  1310.  
  1311.  
  1312. The following are the rotation matrices:
  1313.  
  1314.     Rx(t)            Ry(t)            Rz(t)
  1315. __                  __  __                  __  __                  __
  1316. | 1    0      0    0 |    | cos(t) 0 -sin(t) 0 |    |  cos(t) sin(t) 0 0 |
  1317. | 0  cos(t) sin(t) 0 |    |    0   1    0    0 |    | -sin(t) cos(t) 0 0 |
  1318. | 0 -sin(t) cos(t) 0 |    | sin(t) 0  cos(t) 0 |    |    0        0    1 0 |
  1319. | 0    0      0    1 |  |    0   0    0    1 |  |    0      0    0 1 |
  1320. --                  --  --                  --  --                  --
  1321.    rotate about x       rotate about y       rotate about z
  1322.  
  1323.  
  1324. The following is the translation matrix:
  1325.  
  1326.   T(a,b,c)
  1327. __       __
  1328. | 1 0 0 a |
  1329. | 0 1 0 b |
  1330. | 0 0 1 c |
  1331. | 0 0 0 1 |
  1332. --       --
  1333.  
  1334. Let each object be a collection of points or lines.  If lines, they
  1335. are drawn as lines connecting two 3D points, which can each be
  1336. individually transformed.  So this derivation just handles converting
  1337. individual points in three-space into pixel coordinates.
  1338.  
  1339. ---- BEGIN FORMULAS ----
  1340.  
  1341. If d is the distance from the eye to the window, h is the width
  1342. of the window, v is the height of the window (use the sizes
  1343. of the actual display if you don't know what else, but this is
  1344. actually referring to the virtual camera's window); num_x
  1345. is the number of pixels on the display in the x direction, num_y
  1346. the number of pixels in the y direction, and (center_x,center_y)
  1347. the location of the center of the display; 
  1348.  
  1349. let scale_x = d/h*number_of_x_pixels, scale_y = d/v*number_of_y_pixels.
  1350.  
  1351. Then let S be defined as
  1352. __                           __
  1353. | scale_x center_x    0     0 |
  1354. |   0        1        0     0 |
  1355. |   0     center_y -scale_y 0 |
  1356. |   0        0        0     1 |
  1357. --                           --
  1358.  
  1359. Let the camera be located at (cx,cy,cz).  Let the vector E be pointing
  1360. in the direction the camera is facing, the vector D be pointing to
  1361. the right (along the camera's x axis), and the vector F be pointing
  1362. up (along the camera's z axis); and let D, E, and F be of length 1.
  1363. Then define the following matrices:
  1364.  
  1365.    matrix J        matrix C
  1366. | Dx Dy Dz 0 |  | 1 0 0 -cx |
  1367. | Ex Ey Ez 0 |  | 0 1 0 -cy |
  1368. | Fx Fy Fz 0 |  | 0 0 1 -cz |
  1369. | 0  0  0  1 |  | 0 0 0  1  |
  1370.  
  1371. and let N = S*J*C.
  1372.  
  1373.  
  1374. Let each object i be at location cix, ciy, ciz, and let the matrix
  1375. which holds the current rotation for that object be O(i).  To rotate
  1376. the object around the q axis by n degrees, let new O(i) = Rq(n) * O(i).
  1377. To rotate the object about *its* q axis, let new O(i) = O(i) * Rq(n)
  1378. (I think.  I haven't looked at this closely, so it's probably wrong).
  1379.  
  1380. Let Otemp(i) be O(i) with the rightmost column of zeros replaced by
  1381. cix, ciy, and ciz, or in other words, the product of Temp(i)*O(i) where
  1382. Temp(i) is
  1383. __         __
  1384. | 1 0 0 cix |
  1385. | 0 1 0 ciy |
  1386. | 0 0 1 ciz |
  1387. | 0 0 0  1  |
  1388. --         --
  1389.  
  1390. Now, for each object i let M = N * Otemp(i).
  1391.  
  1392. Now, for each point P in i, let V = M * P, that is:
  1393.  
  1394.     Vx = M[0,0]*Px + M[0,1]*Py + M[0,2]*Pz + M[0,3];
  1395.     Vy = M[1,0]*Px + M[1,1]*Py + M[1,2]*Pz + M[1,3];
  1396.     Vz = M[2,0]*Px + M[2,1]*Py + M[2,2]*Pz + M[2,3];
  1397.  
  1398. Then the pixel to plot to is:
  1399.  
  1400.     If Vy>0
  1401.         (Vx/Vy, Vz/Vy)
  1402.  
  1403. Done.
  1404.  
  1405. -- 2 --
  1406.  
  1407. 3D graphics: using matrices and vectors        Part 2
  1408.  
  1409. -  Allows you to independently rotate objects and move the camera
  1410.      anywhere.
  1411. -  Does not discuss clipping.
  1412. -  Algorithm uses 16 multiplies, 2 divides, and 12 adds for each point,
  1413.    plus overhead per independently located object.  Also shows how some
  1414.    of the calculations are wasted, and reduces it to 9 multiplies and 9
  1415.    additions.
  1416.  
  1417.  
  1418. The folowomg is a derivation of some of the math for using 3D
  1419. graphics with matrices and vectors.  I don't see any way of
  1420. explaining how to use the matrix formulas without all the extra
  1421. context, so you'll have to wade through it.  In general, you can
  1422. simplify things by multiplying out the matrices and similar
  1423. techniques.
  1424.  
  1425. You have a world described by three dimensional coordinates--it
  1426. could be lines or points or polygons, whatever.  You have an
  1427. imaginary camera in this world, and you want to draw exactly
  1428. what this camera would see.
  1429.  
  1430. We represent the camera as a point where an "eye" is and a window
  1431. through which it's looking--that is, a point for the eye, a vector
  1432. from the eye to the center of the window, and another vector to tell
  1433. us which way is the up direction on the window.  We can figure out
  1434. the sideways direction of the window by taking a cross-product, but
  1435. it may be better to represent it explicitly, as discussed far
  1436. eventually below.
  1437.  
  1438. What we want to know is where on our screen we should plot a
  1439. particular point.  The solution is to figure out where on the
  1440. imaginary window the point would appear to be, and then to map
  1441. the window onto our screen.
  1442.  
  1443. Suppose the eye is at the origin, facing along the X axis, and
  1444. the point is in the XY plane so we can only look at two dimensions
  1445. for illustration purposes.
  1446.  
  1447. Y axis
  1448.  |                ___---
  1449.  |          ___---
  1450.  |    ___--- |           Point
  1451.  | ---       |
  1452. eye----------+------------------  X axis
  1453.    ---___    |
  1454.          ---_|_
  1455.         window ---___
  1456.                      ---___
  1457.  
  1458. Suppose the window ranges from (d,h/2) to (d,-h/2) and the point is at
  1459. (a,b).  We want to know where the line from the point to the eye
  1460. intersects the window line.  Well, the point is only visible if
  1461. it's in front of the eye, so assume a>0.  Now, the two lines are
  1462.  
  1463.     y = (b/a)*x        (from Point to eye)
  1464. and    x = d            (line window is on)
  1465.  
  1466. So the location of intersection is (d,(b/a)*d).  In other words,
  1467. the point appears on our imaginary window with horizontal position
  1468. d*b/a if |d*b/a| <= h/2.
  1469.  
  1470. Thus, the quick and dirty 3d graphics formula for assuming an eyepoint
  1471. at the origin, X horizontal, positive to the right, Y vertical, positive
  1472. up, and Z depth, positive going into the distance (this is a left-handed
  1473. universe, whereas the rest of the derivations will be for a right handed
  1474. universe), and screen coordinates sx horizontal, positive to the right
  1475. sy vertical, positive down, is:
  1476.  
  1477.     if (Z>0) then
  1478.         sx = x_scale * X / Z + x_center;
  1479.         sy = - y_scale * Y / Z + y_center;
  1480.     endif
  1481.  
  1482. where x_center, y_center is the pixel address of the center of the
  1483. screen; x_scale is d/h*number_of_pixels_horizontally and y_scale is
  1484. d/v*number_of_pixels_vertically; d is the distance between the eye
  1485. and the window in the imaginary camera, h and v are the height and
  1486. width respectively of the imaginary window.
  1487.  
  1488. Ok, back to the messy stuff.  Since our eyepoint won't necessarily
  1489. be at the origin and facing in the right direction, we need to be
  1490. able to handle arbitrary translations and rotations.  In general,
  1491. to rotate (a,b) into (a',b') based on a given angle t, we do
  1492.  
  1493.     a' = cos(t)*a + sin(t)*b;
  1494.     b' = cos(t)*b - sin(t)*a;
  1495. (or switch the signs depending on which way you want to define as
  1496. the positive direction of rotation).
  1497.  
  1498. Now, to cleanly handle multiple rotations, we want to use matrices
  1499. to handle this.  This is the same as
  1500.  
  1501.     | cos(t) sin(t)|  |a| _ |a'|
  1502.     |-sin(t) cos(t)|  |b| - |b'|
  1503.  
  1504. that is, a 2x2 matrix times a 2x1 matrix gives a 2x1 matrix.  Now
  1505. to handle an arbitrary 3D rotation, we need to rotate on any axis:
  1506.  
  1507.    rotate about x       rotate about y       rotate about z
  1508.  
  1509. | 1    0      0    |    | cos(t) 0 -sin(t) |    |  cos(t) sin(t) 0 |
  1510. | 0  cos(t) sin(t) |    |    0   1   0     |    | -sin(t) cos(t) 0 |
  1511. | 0 -sin(t) cos(t) |    | sin(t) 0  cos(t) |    |    0        0    1 |
  1512.  
  1513. Now, to rotate about a particular point, we have to translate to that
  1514. point.  Say we want to rotate about (d,e,f).  Then we subtract (d,e,f)
  1515. from our point, rotate, and then add (d,e,f) again.  It would be nice
  1516. if we could do that automatically with the matrices, and there is a way
  1517. to, a cute trick.  We switch from 3x3 matrices to 4x4 matrices, and use
  1518. 4-vectors.  For the rotation matrices, the new elements are all zero,
  1519. except the bottom right one which is 1; for example:
  1520.  
  1521. |  cos(t) sin(t) 0 0 |
  1522. | -sin(t) cos(t) 0 0 |
  1523. |    0      0    1 0 |
  1524. |    0      0    0 1 |
  1525.  
  1526. Also, all of our vectors have a fourth element, which is always 1.
  1527. (In programming this, you can just continue to use three-vectors and
  1528. program the 'multiply matrix by vector routine' to pretend there's
  1529. one there.)  Now, to do a translation we want:
  1530.  
  1531.     x' = x + k1;
  1532.     y' = y + k2;
  1533.     z' = z + k3;
  1534.  
  1535. It turns out that this does the trick:
  1536.  
  1537. | 1 0 0 k1 |  | x |
  1538. | 0 1 0 k2 |  | y |
  1539. | 0 0 1 k3 |  | z |
  1540. | 0 0 0 1  |  | 1 |
  1541.  
  1542.  
  1543. Now, let's define some matrix terms so we can compress our notation.
  1544. Let Rx(t), Ry(t), and Rz(t) be the 4x4 rotation matrices, and let
  1545. T(k1,k2,k3) signify the appropriate matrix as above.  To rotate a point
  1546. (a,b,c) theta around the y axis at point (d,e,f), we do the following
  1547. in sequence: T(-d,-e,-f), Ry(theta), T(d,e,f).  Now, one nice thing
  1548. about matrices is that we can get the effect of sequential application
  1549. by multiplying matrices; that is, if U = (a,b,c,1) and V=(a',b',c',1),
  1550. then do  T(-d,-e,-f)*U, and take that and do Ry(theta)*that, and take
  1551. this and do T(d,e,f)*this, giving V, then this is:
  1552.  
  1553.     T(d,e,f) * ( Ry(theta) * ( T(-d,-e,-f) * U ) ) ) = V
  1554.  
  1555. Since matrix operations are associative, this is the same as
  1556.  
  1557.     T(d,e,f) * Ry(theta) * T(-d,-e,-f) * U = V
  1558.  
  1559. or, in other words, let M = T(d,e,f)*Ry(theta)*T(-d,-e,-f), then
  1560. M is a matrix which performs the rotation we desire.
  1561.  
  1562. Ok, now to wrap it all up.  Suppose we have a bunch of objects in
  1563. 3D we want to display, and the aforementioned camera.  The camera
  1564. is at (cx,cy,cz), and we have a vector E pointing in the direction
  1565. the camera is aiming, a vector D which shows which way the window
  1566. is pointing to the right, and a vector F which points along the window
  1567. upward.  These vectors form an orthonormal basis, so to rotate into
  1568. the frame of reference for them we use the matrix
  1569.  
  1570. | Dx Dy Dz |
  1571. | Ex Ey Ez |
  1572. | Fx Fy Fz |
  1573.  
  1574. also, we want to use 4x4 matrices and first we want to translate
  1575. to cx..cz, so we use
  1576.  
  1577.    matrix J        matrix C
  1578. | Dx Dy Dz 0 |  | 0 0 0 -cx |
  1579. | Ex Ey Ez 0 |  | 0 0 0 -cy |
  1580. | Fx Fy Fz 0 |  | 0 0 0 -cz |
  1581. | 0  0  0  1 |  | 0 0 0  1  |
  1582.  
  1583. So for an arbitrary point (a,b,c) in three space, the screen coordinates
  1584. for it sx, sy are:  let U = (a,b,c,1); let V = J*C*U.  Then
  1585.  
  1586.     if (Vy>0) then
  1587.         sx = scale_x * Vx/Vy + center_x;
  1588.         sy = - scale_y * Vz/Vy + center_y;
  1589.     endif
  1590.  
  1591. Generally, we want to store J and C separately.  It is pretty simple
  1592. to move the camera, now; if the camera is always moving in the direction
  1593. its facing, use the E vector and factor direction in by hand, and
  1594. put this into C.  To rotate the camera, just multiply a rotation
  1595. matrix on the left by J.
  1596.  
  1597. Now, to rotate objects properly, keep a separate rotation matrix
  1598. for each object.  Then for each point in that object, rotate it and
  1599. translate it.  It's simplest to store each object with the origin
  1600. as the center of the object.  Then to calculate a point, you multiply
  1601. by the rotation matrix and then by the translation to put the objects
  1602. center where it should be in world space; because you're doing the
  1603. translation second, it's easy to put it into one matrix:
  1604.  
  1605. translation    rotation
  1606. | 1 0 0 l |   | a b c 0 |   | a b c l |
  1607. | 0 1 0 m |   | d e f 0 | _ | d e f m |
  1608. | 0 0 1 n | * | g h i 0 | - | g h i n |
  1609. | 0 0 0 1 |   | 0 0 0 1 |   | 0 0 0 1 |
  1610.  
  1611. Call this matrix O(q) where q is the object number.
  1612.  
  1613. Then, for each point in object q, the final multiply is
  1614. V = J * C * O(q) * U.
  1615.  
  1616. Finally, we can move some of the final calculation into a matrix.
  1617. We have:
  1618.     sx = scale_x * Vx/Vy + center_x;
  1619.     sy = -scale_y * Vz/Vy + center_y;
  1620.  
  1621. If we factor out Vy, we get
  1622.     sx = (scale_x * Vx + center_x * Vy)/Vy;
  1623.     sy = (-scale_y * Vz + center_y * Vy)/Vy;
  1624.  
  1625. Suppose from V we calculate V':
  1626.     (scale_x*Vx + center_x*Vy, Vy, -scale_y*Vz + center_y*Vz, 1)
  1627.  
  1628. Then
  1629.     sx = V'x / V'y;
  1630.     sy = V'z / V'y;
  1631.  
  1632. Well, to get V', we just multiply V by the matrix
  1633.  
  1634. | scale_x center_x    0     0 |
  1635. |   0        1        0     0 |
  1636. |   0     center_y -scale_y 0 |
  1637. |   0        0        0     1 |
  1638.  
  1639. Let us call this matrix S.  Remember, scale_x = d/h*number_of_x_pixels,
  1640. scale_y = d/v*number_of_y_pixels, d is distance from eye to window,
  1641. h is width of imaginary screen, v is height of imaginary screen.
  1642.  
  1643. So, now, the basic idea is this.  To minimize calculation, let 
  1644. N = S * J * C.  For each object q, let M = N * O(q).  For every point
  1645. U in q, let V = M * U.  If Vy>0, then that point is at (Vx/Vy,Vz/Vy)
  1646. on the screen.
  1647.  
  1648. In pseudo-code, that's
  1649.  
  1650. /* matrix_multiply (destination, left_multiplicand, right_multiplicand) */
  1651.  
  1652. for each time slice do
  1653.     if camera has moved then
  1654.         matrix_multiply ( N, J, C);
  1655.         matrix_multiply ( N, S, N);
  1656.     endif
  1657.  
  1658.     for q an object do
  1659.         matrix_multiply( M, N, O[q]);
  1660.         for p a point in object q do
  1661.             matrix_by_vector_multiply( V, M, U[q][p]);
  1662.             do something with  ( V[0]/V[1], V[2]/V[1] );
  1663.         endfor
  1664.     endfor
  1665. endfor
  1666.  
  1667. In truth, the matrix_by_vector_multiply wastes a bit of time, if you're
  1668. trying to tune the code, it'd be worth tuning it.  Normally, it does
  1669. this:
  1670.  
  1671. V0 = M00*U0 + M01*U1 + M02*U2 + M03*U3;
  1672. V1 = M10*U0 + M11*U1 + M12*U2 + M13*U3;
  1673. V2 = M20*U0 + M21*U1 + M22*U2 + M23*U3;
  1674. V3 = M30*U0 + M31*U1 + M32*U2 + M33*U3;
  1675.  
  1676. However, we know that the bottom row is never used, since V3 is always
  1677. 1; furthermore, we know that U3 is 1, so we can just do
  1678.  
  1679. V0 = M00*U0 + M01*U1 + M02*U2 + M03;
  1680. V1 = M10*U0 + M11*U1 + M12*U2 + M13;
  1681. V2 = M20*U0 + M21*U1 + M22*U2 + M23;
  1682.  
  1683. This uses nine multiplies and nine adds, plus the two divides required
  1684. to calculate the screen coordinate.  I believe this is the minimum
  1685. possible for arbitrary 3D graphics.  (You can turn the two divides into
  1686. one divide and two multiplies by calculating 1/Vy and multiplying by
  1687. that, which may be a win on some machines.)
  1688.  
  1689.  
  1690.  
  1691.  
  1692.