home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 677 / GAMELIB / GAMES.DOC < prev    next >
Text File  |  1993-10-07  |  14KB  |  321 lines

  1.                         MIKE'S GAME GRAPHICS ROUTINES
  2.                         -----------------------------
  3.                       Copyright (c) 1992 Michael Cantelmi
  4.  
  5.  
  6.    For years I've searched high and low for a package of routines that would
  7. allow me to program my own arcade games and never found one. The problem was
  8. that the few I did find either didn,t have the right combinations of
  9. routines or they were just to slow. Well I finally got fed up and started to
  10. learn assembly and these routines are the result.
  11.    These routines should allow anyone with a knowledge of C to create there
  12. own arcade, adventure or roleplaying games. Yep, you read it right, I said
  13. ARCADE. These routines are FAST.
  14.    These routines were written for an 80286 or higher computer with VGA 
  15. (320x200x256) color and a Microsoft C compiler or 100% compatible.They will 
  16. allow you to use virtual screens of any size and of any number(within your 
  17. computer's memory limit of course). You will also be able to control the mouse, 
  18. joystick and EMS memory, and the sprite routines don't require a bit mask while 
  19. giving you the ability to make any color trasparent, not just the color 0. You 
  20. can also load PCX files in 320x200x256 format.
  21.  
  22.  
  23.                 Freeware
  24.                 --------
  25.  
  26.    You can market programs that use these routines without
  27. paying any royalties to me. You may not ,however, sell the routines by
  28. themselves. You may distribute these routines for nonprofit or you may charge a
  29. fee for distribution on disk provided it does not exceed $5.00, and all
  30. libraries, documentation and affiliated files are included and unaltered.
  31.    These routines are provided as is. I cannot be liable for any damage caused
  32. directly or indirectly by the use or misuse of these routines.
  33.  
  34.                                 
  35.                                 ------------
  36.  
  37. Before using the block manipulation routines (eg. _spritev,_putv,_getv) you
  38. must allocate memory for them using _amem().
  39.    NOTE-If you want to copy a sprite or virtual screen to the visual screen
  40. create a integer variable and assign the value a000h(40960 decimal), this 
  41. is the memory address of video memory. (eg. mainscreen=40960;)
  42.    I included a couple of demos with source code. They should be
  43. helpfull in demostrating the use of the routines. If you have any questions
  44. I will be more than happy to answer them.
  45. Just drop me some E-mail (74270,1664) or send me a letter with a SASE.
  46.    Whether you're registered or not, I'll welcome any comments, complaints or
  47. suggestions.
  48.  
  49.                                 About Memory
  50.                                 ------------
  51.  
  52.    Before I explain the individual routines, I think a word about how they use
  53. memory is in order. For those of you who know how DOS uses memory, you're in
  54. luck, these routines use memory in 64k blocks just like DOS.
  55.    Here's how it works, if you don't know much about memory handling just keep
  56. in mind that a buffer can only be as large as 64k (or a screen 320x200 max).
  57. It's possible for you to allocate a block as large as 640k and then manage it
  58. in blocks of 64k by adjusting the segment address (the value returned by 
  59. _amem()), but unfortunatly that's beyond the scope of these docs.
  60.    If you already know some assembly and the memory addressing techniques of
  61. DOS and the 80x86 chips, you'll find that these routines provide the
  62. versatility to produce some fantastic animation. If not, don't worry, you'll
  63. still be able to produce commercial quality games.
  64.    If you're interested in learning to use these routines to their fullest
  65. potential you will need an intermediate knowledge of assemble, DOS and the VGA.
  66.  
  67.                            About Expanded Memory
  68.                            ---------------------
  69.  
  70.    You must have an expanded memory driver installed before using the EMS
  71. routines.
  72.    First you need to know that the EMS driver will set aside a 64k block of
  73. memory called the page frame. This page frame is divided into four 16k byte
  74. blocks numbered 0-3 to which expanded memory will be moved in and out of.
  75.    For example: lets say you have 512k expanded memory. This memory is divided
  76. into 32 16k blocks of virtual memory. If you want to access this memory you
  77. must tell the EMS manager how many blocks you wish to use. Lets say you want
  78. 10 blocks of EMS memory, first call _eallocmem. The EMS manager will allocate
  79. 10 blocks for you labled 0-9 and it will give you a handle. This handle is like
  80. a file name that identifies the 10 blocks you requested. You may have more 
  81. than one handle at a time to identify different blocks of memory.
  82.    To move these virtual blocks in and out of expanded memory you must first
  83. ask the EMS manager what address in memory it has placed the page frame buffer
  84. into. You do this by calling _epageframe. You can then use the graphics 
  85. routines on the page frame as you would on a buffer created with _amem().
  86.    You must then tell the EMS manager which virtual blocks you want to move
  87. into the page frame with _emapmem. From now on you just use _emapmem to move
  88. the 10 blocks you allocated in and out of the page frame whenever you need
  89. them. Remember that the page frame is 64k bytes but each ems page is 16k bytes.
  90. To access page 2 in the page frame, add 16384 decimal(4000 hex) to the value
  91. returned by _epageframe. Add 32768 dec(8000 hex) and 49152 dec(c000 hex) for
  92. page 3 and 4 respectively.
  93.  
  94.                                 
  95.                                 The Routines
  96.                                 ------------
  97.  
  98.    Remember to have your Expanded Memory manger installed for the EMS routines
  99. and your Microsoft compatible mouse driver installed for the mouse routines.
  100.  
  101.  
  102. int _amem (int block)-
  103.         Allocates memory. Returns integer pointer to segment allocated.
  104.         block=# of blocks to locate.(Each block is 16 bytes long).
  105.         For instance, to allocate memory for a whole screen, which is 64000
  106.         bytes long, you would use [screen=_amem(4000);].
  107.         
  108. void _damem (int block)-
  109.         Deallocates memory.
  110.  
  111. void _showpointer (void)-
  112.         Shows the mouse pointer.
  113.  
  114. void _hidepointer (void)-
  115.         Hides the mouse pointer.
  116.  
  117. int _getbuttondown (void)-
  118.         Returns button down status.
  119.         1=left button down.
  120.         2=right button down.
  121.         4=center button down.
  122.  
  123. int _initmouse (void)-
  124.         Initializes mouse and clears all mouse buffers. Returns a 0 if a
  125.         mouse is not available.
  126.  
  127. int _xmouse (void)-
  128.         Returns x position of mouse.
  129.  
  130. int _ymouse (void)-
  131.         Returns y position of mouse.
  132.  
  133. int _stickx (void)-
  134.         Returns joystick x value.
  135.  
  136. int _sticky (void)-
  137.         Returns joystick y value.
  138.  
  139. int _button1 (void)-
  140.         Returns joystick button #1 status.
  141.         1=pressed
  142.         0=not pressed
  143.  
  144. int _button2 (void)-
  145.         Returns joystick button #2 status.
  146.         1=pressed
  147.         0=not pressed
  148.  
  149. void _delay (int tm)-
  150.         Sets a delay in integral multiples of 976ms. 
  151.         tm=0 to 65535.
  152.  
  153. void _clsv (int scrn,int size, char color)-
  154.         Clears a screen or part of screen.
  155.         scrn=pointer to screen.
  156.         size=size of screen in bytes. (eg. 320x200 is 64000 bytes)
  157.         color=0-255.
  158.  
  159. void _setpoint (int x,int y,char color,int scrn,int sxs)-
  160.         Sets a point on the screen.
  161.         x,y=location of point.
  162.         color=0-255.
  163.         scrn=pointer to screen.
  164.         sxs=width of screen in pixels.
  165.  
  166. void _getpoint (intx,int y,int scrn,int sxs)-
  167.         Gets color value of a point on the screen.
  168.         x,y=location of point.
  169.         scrn=pointer to screen.
  170.         sxs=width of screen in pixels.
  171.  
  172. void LoadPCX (char filename[],int smem)-
  173.         Loads a 320x200x256 PCX file to screen or buffer.
  174.         filename[]=filename of PCX file.
  175.         smem=pointer to screen or buffer.
  176.  
  177. void _putv (int x,int y,int xs,int ys,int pic,int screen,int sxs)-
  178.         Puts picture buffer to the screen or another buffer 2 bytes at a
  179.         time.
  180.         x,y=location to put pic.
  181.         xs,ys=horizontal and vertical size of pic. xs must be an even #.(eg.
  182.               xs=30 or xs=32, not xs=31)
  183.         pic=buffer or picture to put on screen.
  184.         screen=pointer to screen or buffer to put pic on.
  185.         sxs=width of screen or buffer.
  186.  
  187. void _getv (int x,int y,int xs,int ys,int pic,int screen,int sxs)-
  188.         Gets a picture from screen or buffer 2 bytes at a time.
  189.         x,y=location to get from.
  190.         xs,ys=x and y size of pic. xs must be an even #.
  191.         pic=buffer to store pic in.
  192.         screen=pointer to screen or buffer to get pic from.
  193.         sxs=width of screen or buffer to get from.
  194.  
  195. void _spritev (int x,int y,int xs,int ys,int pic,int screen,int sxs,
  196.                 char COLOR)-
  197.         Same as _putv except pixels with color value of COLOR are 
  198.         transparent.
  199.  
  200. void _sprite2 (int x,int y,int xs,int ys,int pic,int screen,int sxs,
  201.                 char color)-
  202.         Same as _spritev except its faster. It copies 2 bytes at a time.
  203.         xs must be an even #.
  204.  
  205. void _screencopy (int screen1,int screen2,int numwords)-
  206.         Copies part or all of one screen or buffer to another.
  207.         screen1=pointer to screen or buffer to copy from.
  208.         screen2=pointer to screen or buffer to copy to.
  209.         numwords=size of screen in WORDS(# of bytes/2). eg. 320x200 screen is
  210.         64000 bytes, numwords would equal 64000/2 which is 32000.
  211.  
  212. int _epageframe (void)-
  213.         Returns the address of the page frame used by the EMS manager.
  214.         The page frame is the 64k block that the EMS manager maps the EMS
  215.         memory in and out of. The address is the beginning of this block.
  216.         The 64k block is divided further into four 16kbyte pages numbered 0-3.
  217.  
  218. int _etotalmem (void)-
  219.         Returns the total number of EMS pages.
  220.         Each page is 16k bytes long.
  221.  
  222. int _eunusedmem (void)-
  223.         Returns the number of available EMS pages.
  224.  
  225. int _eallocmem (int pages)-
  226.         Assigns the requested number of EMS pages to an EMM handle.
  227.         Returns the EMM handle assigned to the requested pages.
  228.  
  229. void _emapmem (char mainpage,int emspage,int emmhandle)-
  230.         Maps requested EMS page to requested page in the page frame.
  231.         mainpage=page frame to map EMS page to. There are 4 pages 0-3.
  232.         emspage=EMS page to map into page frame. This value ranges from
  233.                 0 to the requested number of pages -1.
  234.         emmhandle=The EMM handle returned from _eallocmem.
  235.  
  236. void _edallocmem (int emmhandle)-
  237.         Deallocates EMM handle and pages assigned to it.
  238.  
  239. void _settick(int count)
  240.         Sets the tick counter.
  241.         count=the value the tick counter should start at. 0-65535.
  242.  
  243. int _gettick(void)
  244.         Returns the tick counter value.
  245.         Every tick occurs 18.2 times per second regardless of the speed of
  246.         the computer.
  247.  
  248. void _drawline (int x1,int y1,int x2,int y2,char color,int scrn,int sxs)
  249.     Draws a line.
  250.     x1,y1=start of line.
  251.     x2,y2=end of line.
  252.     color=color of line.
  253.     scrn=address of screen to draw line on.
  254.     sxs=width of screen in pixles.(bytes)
  255.  
  256. void _copywindow (int x1,int y1,int x2,int y2,int xs,int ys,int pic,int screen,int sxs)
  257.     Copies a window from one screen to another or from one part of a
  258.     screen to another part of the same screen. The width of the window
  259.     must be an even multiple of 2. The source and destination screens must
  260.     be the same width.
  261.     x1,y1=Destination of window.
  262.     x2,y2=Source of window.
  263.     xs=width of window to be copied.
  264.     ys=hight of window to be copied.
  265.     pic=Address of screen window is being copied from.
  266.     screen=Address of screen window is being copied to.
  267.     sxs=width of screen in pixels.(bytes)
  268.  
  269. long int _getcolorval (int color)
  270.     Returns the RGB values of the color. The value returned is compatible
  271.     with QuickC pallette functions.
  272.     color=0-256
  273.  
  274. void _scrollleft (int xs,int ys,int pic,int scroll)
  275.     Scrolls a buffer or screen to the left. The width of the screen and
  276.     the xs value must be an even multiple of 2.
  277.     xs=width of screen or buffer to scroll.
  278.     ys=hight of screen or buffer to scroll.
  279.     pic=address of screen or buffer to scroll.
  280.     scroll=number of bytes to scroll.
  281.  
  282. void _scrollright (int x2,int ys,int pic,int scroll)
  283.     Same as _scrollleft, except it scrolls right.
  284.  
  285. void _scrollup (int xs,int ys,int pic,int scroll)
  286.     Scrolls a screen up. Same parameters as _scrollleft.
  287.  
  288. void _scrolldown (int xs,int ys,int pic,int scroll)
  289.     Scrolls a screen down. Same parameters as _scrolleft.
  290.  
  291. void _putvc (int x,int y,int xs,int ys,int pic,int screen,int sxs,int sys)
  292.     Same as _putv with clipping added.
  293.     x,y=destination of buffer. x must be an even number.
  294.     xs=width of buffer.
  295.     ys=hight of buffer.
  296.     pic=address of picture buffer.
  297.     screen=address of screen.
  298.     sxs=width of screen.
  299.     sys=hight of screen.
  300.  
  301. void _spritevc (int x,int y,int xs,int ys,int pic,int screen,int sxs,int sys,char color)
  302.     Same as _spritev with clipping added.
  303.     Use same parameters as above.
  304.     color=transparent color.
  305.  
  306. void _sprite2c (int x,int y,int xs,int ys,int pic,int screen,int sxs,int sys,char color)
  307.     Same as _sprite2 with clipping added.
  308.     Use same parameters as above.
  309.  
  310. void _scale (int xs2,int ys2,int xd1,int yd1,int xd2,int yd2,int pic,int screen,int sxsp,int sxss)
  311.     Will scale a buffer to any size. Color 0 is always transparent.
  312.     xd2 and yd2 must be greater than 1.
  313.  
  314.     xs2,ys2=width and hight of buffer -1.
  315.     xd1,yd1=upper left of rectangle to copy buffer to.
  316.     xd2,yd2=lower right of rectangle to copy buffer to.
  317.     pic=address of buffer.
  318.     screen=address of screen.
  319.     sxsp=width of buffer.
  320.     sxss=width of screen.
  321.