home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / ATOLKIT / TWEAK.DOC < prev    next >
Encoding:
Text File  |  1991-12-14  |  16.2 KB  |  332 lines

  1. /***************************************************************** 
  2. tweak.h
  3.  
  4.     The following functions make up Fabco's current 
  5.     VGA Animation/Graphics/Multi-media Toolkit as of 12-8-91
  6.     The functions below amount to an "Abstract Data Type"
  7.     of a "Sprite" that can be animated or moved around
  8.     on the screen in 320x200x256 color mode.
  9.  
  10.     In order to do "page flipping" and eliminate flicker,
  11.     a special "tweaked" video mode was used (as described
  12.     in "Power Graphics Programming" by Michael Abrash).
  13.     This video mode is not compatible with MCGA mode 13h,
  14.     and a special conversion program, (supplied as convert.c)
  15.     must be used on MCGA mode 13h files before they can be
  16.     used in this mode. Actually, all the functions in this
  17.     toolkit should work in any of the "tweaked" modes. All
  18.     you have to do is supply your own mode set routine if you
  19.     want to do 320x400x256 or 380x400x256 etc. I have chosen
  20.     320x200 for it's compatability with normal mode 13 paint
  21.     programs etc. The other tweaked modes and "mode X" offer
  22.     higher resolution at the cost of this compatability. 
  23.  
  24.     Currently, only ColoRIX.sc? files are supported by the 
  25.     convert program, since that is the only paint program's 
  26.     file format I could get any legal information on. (Rix 
  27.     thoughtfully makes their uncompressed format available,
  28.     unlike most other companies). However, any file format 
  29.     could be converted, if you know the format. Just
  30.     look at the program convert.c and make the needed 
  31.     adjustments. Also, the popular shareware program: "Vpic",
  32.     will translate many different formats (including ".GIF")
  33.     to "Rix" format merely by pressing "R" while viewing 
  34.     the picture. Be sure you are in the video mode you want the 
  35.     final output in though.
  36.  
  37.     With all the outside support for different file formats, 
  38.     I decided not to bother writing a lot of code for interfacing
  39.     to different paint programs. I chose instead to concentrate 
  40.     on the bit-blt graphics, that are so hard to find anywhere else.  
  41.     However, anyone with information on AutoDesk Animator ".CEL"
  42.     or ".FLI" file formats, please send it in. Anyone who knows
  43.     any slick method to compress/decompress video in real time
  44.     likewise get in touch. I have just never been able to figure
  45.     a way to do that "on the fly", in real time so to speak. 
  46.       
  47.  
  48.     The toolkit's current function list is not yet complete,
  49.     and in a state of flux. This is only a sampler, but it is
  50.     already a core group of functions that have been tested
  51.     to perform on a wide variety of VGA cards, with no problems.
  52.     Bounds Checking is up to you, however. It is possible to
  53.     write sprites to illegal addresses, especially if a 
  54.     protected mode program (like QEMM) is running. If you
  55.     are moving a sprite around by calculating the index into
  56.     a one of your video buffers, and that calculation places
  57.     some of the dimensions of the sprite rectangle off of the
  58.     screen, unpredictable things can happen. Sometimes the 
  59.     buffer area will just wrap, sometimes (especially for
  60.     negative destination coords above or to the left 
  61.     of the upper left hand corner of the screen), you might 
  62.     get a processor exception. 
  63.  
  64.  
  65.     This Toolkit is currently provided only as a small model
  66.     "linkable .obj" made with Microsoft "C". This is ShareWare, 
  67.     it is not free. I will provide other memory models, 
  68.     for other languages only for registered users. 
  69.     So register today. I cannot continue to improve this 
  70.     product unless you support it.
  71.  
  72.     
  73.     The current registration price is $39.95. It will 
  74.     probably have to go up when more functions are added.
  75.     I am poor, and sympathetic, if you cannot afford this,
  76.     send what you can. All donations accepted. However, 
  77.     support levels drop with price. Also, I am not hard to
  78.     get along with, and I am very interested in the concept of
  79.     working together in a group cooperative effort. Two
  80.     people can do more than one; Five people can do even more.
  81.     It's just so hard to get five people to cooperate on anything.
  82.     It's just impossible if they aren't getting paid.
  83.     I am no genius at this stuff, and I'm not stuck up about it.
  84.     A willing attitude toward assembler, registers,  
  85.     flip-flops, or graphics, goes a long way with me. 
  86.     And, people who really contribute go even farther.
  87.     So, if you want to collaborate, talk about enhancements
  88.     etc., drop me a line at my work address below, or leave
  89.     me e-mail on Compuserve. (ID# 73530,2105). All comments
  90.     and suggestions are welcome. Sorry, I am just not available 
  91.     by phone, unless you want me to call you back collect 
  92.     or something.
  93.  
  94.     
  95.  
  96.     Masm 5.1 Source code is available for only $99.95. 
  97.     Believe me, you can't write it yourself for that.
  98.     No extra Royalties are charged, although I do ask that
  99.     you keep me posted on any enhancements that you make, or plan
  100.     to make. (To avoid duplication of effort).I will even 
  101.     be happy to suggest areas where I think the most 
  102.     improvement can be made.
  103.  
  104.     Send check or Money Order to:
  105.  
  106.                     James Faubus
  107.                     Rt.1, Box 37
  108.                     Godley, Texas 76044
  109.  
  110.  
  111.  
  112.  
  113.     Limits of Liability and Disclaimer of Warranty:
  114.  
  115.     The author has used his best efforts in preparing this 
  116.     toolkit, and the programs contained within it. These
  117.     efforts include the development, research, and the 
  118.     testing of the theories and programs to determine their
  119.     effectiveness. The author makes no warranty of any kind,
  120.     expressed or implied, with regard to the programs or the
  121.     documentation contained in this toolkit. The author shall
  122.     not be liable in any event for incidental or consequential
  123.     damages in connection with or rising out of the furnishing,
  124.     performance, or use of these programs.
  125.  
  126. ******************************************************************/
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. /*****************************************************
  135. Animation Toolkit Functions
  136.  
  137. All Routines are highly optimized, and very fast.
  138. (Or at least as fast as I could make them).
  139. However, I have used some 286 instructions, and the 
  140. code won't run on 8088 machines. I chose not to 
  141. support XT's because even on 12MHz AT's some of these
  142. highly optimized assembler routines start to become
  143. a little sluggish. Let's face it, a 12Mhz AT is sort
  144. of the minimum system for 256 color graphics, even
  145. in 320x200 mode. Especially if there is a sound 
  146. interrupt occurring 10,000 times a second. Although,
  147. if you just have to make the code run on an XT for 
  148. some reason, purchase the source code. The only 
  149. conversion required will be to change a few 
  150. "shr ax,4" to "shr ax, 1" four times.
  151.  
  152. ******************************************************/
  153.  
  154. extern int active_page;
  155. /* Current video page segment of the screen being displayed.
  156.    A000h for page1 A800h for page2. I'm not sure why you
  157.    would want to know it, but it's here if you need it. */
  158.  
  159. extern void set_mode            (int mode);
  160. /* Sets the screen to any of the normal VGA modes, set_mode(3);
  161.    returns you to normal text mode. */
  162.  
  163. extern void set320by200TweakMode(void);
  164. /* Sets the screen to 320x200x256 tweaked mode. It could also set it
  165.    to 320x400x256, but there are no paint programs that support it
  166.    so I don't either. See "Power Graphics Programming" by M.Abrash
  167.    for more details. */
  168.  
  169. extern void set_palette         (char huge *buf);
  170. /* Loads the palette regs with the data it finds in buf. Note
  171.    that all data buffer pointers are SEG:OFFSET far pointers. 
  172.    This way "halloc()" can be used to allocate buffers larger
  173.    than 64k, or multiple buffers of 64k each can be used, 
  174.    even in small model code. */
  175.  
  176. extern void move_backgnd        (char huge *buf);
  177. /* This routine moves the data it finds in buf to the current
  178.    video page. Buf must be exactly the size of the screen,
  179.    and already in planar format (as supplied by convert.exe).
  180.    No checking is performed. */
  181.  
  182. extern void write_pixel_twk     (int x, int y, int color);
  183. /* Sets any pixel at any screen (x,y) coordinate to the 8-bit value
  184.    specified by color. (The upper 8 MSBits are ignored).  
  185.    Can also be used for lines, circles, etc., since they 
  186.    are not currently supported as such. */
  187.  
  188. extern void fill_rectangle      (int x, int y, int w, int h, int color);
  189. /* Similar, but fills a rectangular area to the specified color.
  190.    Good for windows, menus etc. */
  191.  
  192. extern void get_rectangle       (int x, int y, int w, int h, char huge *buf);
  193. /* Saves any rectangular area of the screen in the buffer you provide.
  194.    Could be used for a whole screen save, or just a partial screen save. */ 
  195.  
  196. extern void put_rectangle       (int x, int y, int w, int h, char huge *buf);
  197. /* Restores the rectangle you previously saved with get_rectangle(); */
  198.  
  199. extern void switch_pages_poll   (void);
  200. /* Switches to the next page of video memory, at the next occurring
  201.    vertical retrace. Successive calls toggle back and forth between
  202.    the two video pages. VGA cards could support 4 pages w/ 256k
  203.    or 8 pages w/512k in this tweaked mode. Currently, I only support
  204.    toggling between the first two pages. If there is enough demand,
  205.    I will add support for all 8 pages.*/
  206.  
  207. extern void set_page            (unsigned int pg);
  208. /* Used the Bios write pixel to bank switch the video card any one of 8
  209.    pages. This does not work on all cards, use sparingly. Also,
  210.    set_page(4); causes subsequent writes to go to our page 2;
  211.    Which will then be seen by a call to switch_pages_poll();
  212.    This is only useful for starting your writes on a known page.
  213.    Switch_pages_poll(), changes the page for all future writes,
  214.    to the unseen page automatically. */
  215.  
  216. extern void draw_sprite         (int x, int y, int w, int h, char huge *buf);
  217. /* Draws a sprite located in buf. Sprites must have the color "Black"
  218.    hex 00, as the cutout color. In other words, anywhere you want the
  219.    background to show through on the sprite, erase that spot with the
  220.    special color black00. Anywhere you want to look black, use a shade
  221.    that is almost black. This is easy with most paint programs that
  222.    allow you to adjust the palette. ColoRIX will show you the numeric
  223.    value of the color while you are adjusting the palette. */
  224.  
  225. extern void erase_sprite        (int x, int y, int w, int h, char huge *buf);
  226. /* Restores only the rectangular area at (x,y) from a larger background
  227.    screen pointed to by buff. This routine requires buf to be exactly 
  228.    the size of the screen. If you need to erase from a bigger virtual
  229.    screen use scroll_screen(); instead. */
  230.  
  231. extern void scroll_window       (int sourceX, int sourceY, 
  232.                                  int destX, int destY,
  233.                                  int w, int h, char huge *buf);
  234. /* Grabs a rectangular area from a larger source buffer that can be up to 
  235.    the size of a full screen, and places it on the screen at the 
  236.    destination coordinates. By varying the source coordinates in a loop, 
  237.    the object in the window will appear to scroll. By varying the
  238.    destination coordinates at the same time, a rectangle can appear to
  239.    have live video going on in a moving window. */
  240.  
  241. extern void scroll_zoom_window  (int sourceX, int sourceY, 
  242.                                  int destX, int destY,
  243.                                  int w, int h, char huge *buf,
  244.                                            int Vzoom, int Hzoom);
  245. /* Similar to above, but can also vary the vertical and horizontal zoom
  246.    factors. This routine is restricted to integer zoom factors, and the
  247.    width and height of the source area must be evenly divisible by 
  248.    the zoom factor. (Otherwise bizarre things might happen.) 
  249.    For example: A width of 96 and a height of 96 can be zoomed
  250.    at factors of 2, 3, 4, 6, 8, 12, 24. This is critical in the 
  251.    width but more forgiving in the height. I have used this 
  252.    technique to produce a nice screen fade that just fades into 
  253.    bigger and bigger pixels. */
  254.  
  255. extern void scroll_screen       (int sourceX, int sourceY, 
  256.                                  int destX, int destY,
  257.                                  int w, int h, char huge *buf,
  258.                                  int buf_wid, long bytes_per_plane);
  259. /* Similar to scroll_window above, but supports buffersizes larger 
  260.    than one screen. A 640x400x256 color pic can be 4 backgrounds. 
  261.    This routine can be used to scroll inside this virtual screen.
  262.    Due to optical effects, scrolls in the vertical direction look
  263.    smoother though. Bytes_per_plane would be 16000 for a 320x200
  264.    screen 64001 for a 640x400 virtual screen. Why it has one extra
  265.    byte per plane more than you would think it would be, since
  266.    640 x 400 = 64000, I have no idea. Perhaps it is an anomilie
  267.    caused by translating the pic. ??? Experiment w/ it. If anyone
  268.    figures this out please let me know. */
  269.  
  270. extern void scroll_sprite       (int sourceX, int sourceY, 
  271.                                  int destX, int destY,
  272.                                  int w, int h, char huge *buf,
  273.                                  int buf_wid, int bytes_per_plane);
  274. /* Similar to scroll_screen above, still supports buffersizes larger 
  275.    than one screen. This routine treats black as a special color though,
  276.    and can be used to scroll text on top of a background. (If the text
  277.    has been created in bitmap form like in draw_sprite above. */
  278.  
  279.  
  280.  
  281. /* Digital Sound Routines that will play SoundBlaster files on the
  282.    PC speaker. */
  283.  
  284. extern void init_speaker_port   (void);
  285. extern void IRQ0_install        (void);
  286. /* These two functions must be called before playing background sound */
  287.  
  288. extern long *play_sound_IRQ0    (char huge *buf, unsigned long bufflen, 
  289.                                  int rate );
  290. /* Plays 8 bit digitized sound located in buf, as a background 
  291.    task. Returns a pointer to the number of bytes it has yet 
  292.    to play. Before calling the first time, setup with a call to 
  293.    init_speaker_port(), and IRQ0_install(). (In that order). Then, 
  294.    tempLen = play_sound_IRQ0(...); will return immediately to 
  295.    your program but sound will be playing in the background. 
  296.    Graphics can be performed while the sound is playing, and 
  297.    can be coordinated with the sound by polling the tempLen 
  298.    pointer. For example: 64k of sound buffer played back at 
  299.    10kHz samples per second, will last about 3 seconds. 
  300.    That means we could be doing animation on the screen, 
  301.    while the first sound buffer is playing. Let's say it takes
  302.    us 2.5 seconds to do our graphics, and we want to coordinate
  303.    the next set of animated graphics with another sound. We 
  304.    can just go into a tight polling loop checking the tempLen 
  305.    variable. When tempLen reaches zero, we make the switch to the 
  306.    second sound buffer with a call to play_sound_IRQ0(...) again. 
  307.    Immediately after that we can start our next graphic. 
  308.    Perfect coordination. Unfortunately, this technique cannot 
  309.    be used to double buffer directly from HardDisk. Since,
  310.    the sound interrupt is using the same (and only) channel that
  311.    Dos uses for disk I/O, all disk access must be suspended while
  312.    the sound is playing. However, graphics can be animated while
  313.    the sound is playing, and if you have EMS memory available,
  314.    it can also be paged into main memory while the sound is playing.
  315.    Double buffering from EMS or Ram Disk is theoreticly possible.
  316.    You would just have to preload the EMS during times when sound
  317.    is not playing. I'm sure if you think about it a while, you 
  318.    can find other interesting applications.
  319.  
  320.  
  321. extern void restore_ports       (void);
  322. extern void IRQ0_remove         (void);
  323. /* These two functions must be called to clean up after you are 
  324.    through playing sound. */
  325. extern void play                (char huge *buf, unsigned long bufflen, 
  326.                                  int rate, int delay );
  327. /* This function plays sound by the software delay loop method, 
  328.    instead of using the interrupt. It hogs the processor completely
  329.    and different delay values must be used on different speed 
  330.    machines; But, it does eliminate sample whine, and provides
  331.    the best possible digital sound on the PC speaker. */
  332.