home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 2d / canvas.c < prev    next >
Text File  |  1998-06-08  |  7KB  |  233 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13.  /*
  14.  * $Source: f:/miner/source/2d/rcs/canvas.c $
  15.  * $Revision: 1.14 $
  16.  * $Author: john $
  17.  * $Date: 1995/03/06 09:18:45 $
  18.  *
  19.  * Graphical routines for manipulating grs_canvas's.
  20.  *
  21.  * $Log: canvas.c $
  22.  * Revision 1.14  1995/03/06  09:18:45  john
  23.  * Made modex page flipping wait for retrace be default.
  24.  * 
  25.  * Revision 1.13  1995/03/01  15:37:40  john
  26.  * Better ModeX support.
  27.  * 
  28.  * Revision 1.12  1994/11/28  17:08:29  john
  29.  * Took out some unused functions in linear.asm, moved
  30.  * gr_linear_movsd from linear.asm to bitblt.c, made sure that
  31.  * the code in ibiblt.c sets the direction flags before rep movsing.
  32.  * 
  33.  * Revision 1.11  1994/11/18  22:50:24  john
  34.  * Changed shorts to ints in parameters.
  35.  * 
  36.  * Revision 1.10  1994/11/10  15:59:33  john
  37.  * Fixed bugs with canvas's being created with bogus bm_flags.
  38.  * 
  39.  * Revision 1.9  1994/06/24  17:26:34  john
  40.  * Made rowsizes bigger than actual screen work with SVGA.
  41.  * 
  42.  * Revision 1.8  1994/05/06  12:50:41  john
  43.  * Added supertransparency; neatend things up; took out warnings.
  44.  * 
  45.  * Revision 1.7  1993/12/08  16:41:26  john
  46.  * fixed color = -1 bug
  47.  * 
  48.  * Revision 1.6  1993/10/15  16:22:25  john
  49.  * *** empty log message ***
  50.  * 
  51.  * Revision 1.5  1993/09/29  16:14:07  john
  52.  * added globol variables describing current canvas
  53.  * 
  54.  * Revision 1.4  1993/09/14  16:03:40  matt
  55.  * Added new function, gr_clear_canvas()
  56.  * 
  57.  * Revision 1.3  1993/09/14  13:51:38  matt
  58.  * in gr_init_sub_canvas(), copy bm_rowsize from source canvas
  59.  * 
  60.  * Revision 1.2  1993/09/08  17:37:34  john
  61.  * Checking for potential errors
  62.  * 
  63.  * Revision 1.1  1993/09/08  11:43:18  john
  64.  * Initial revision
  65.  * 
  66.  *
  67.  */
  68.  
  69. #include <stdlib.h>
  70. #include <malloc.h>
  71. #include <stdio.h>
  72.  
  73. #include "mem.h"
  74.  
  75.  
  76. #include "gr.h"
  77. #include "grdef.h"
  78.  
  79. grs_canvas * grd_curcanv;    //active canvas
  80. grs_screen * grd_curscreen;  //active screen
  81.  
  82. grs_canvas *gr_create_canvas(int w, int h)
  83. {
  84.     unsigned char * data;
  85.     grs_canvas *new;
  86.     
  87.     new = (grs_canvas *)malloc( sizeof(grs_canvas) );
  88.     data = (unsigned char *)malloc(w*h);
  89.  
  90.     new->cv_bitmap.bm_x = 0;
  91.     new->cv_bitmap.bm_y = 0;
  92.     new->cv_bitmap.bm_w = w;
  93.     new->cv_bitmap.bm_h = h;
  94.     new->cv_bitmap.bm_flags = 0;
  95.     new->cv_bitmap.bm_type = BM_LINEAR;
  96.     new->cv_bitmap.bm_rowsize = w;
  97.     new->cv_bitmap.bm_data = data;
  98.  
  99.     new->cv_color = 0;
  100.     new->cv_drawmode = 0;
  101.     new->cv_font = NULL;
  102.     new->cv_font_fg_color = 0;
  103.     new->cv_font_bg_color = 0;
  104.     return new;
  105. }
  106.  
  107. grs_canvas *gr_create_sub_canvas(grs_canvas *canv, int x, int y, int w, int h)
  108. {
  109.     grs_canvas *new;
  110.  
  111.     new = (grs_canvas *)malloc( sizeof(grs_canvas) );
  112.  
  113.     new->cv_bitmap.bm_x = x+canv->cv_bitmap.bm_x;
  114.     new->cv_bitmap.bm_y = y+canv->cv_bitmap.bm_y;
  115.     new->cv_bitmap.bm_w = w;
  116.     new->cv_bitmap.bm_h = h;
  117.     new->cv_bitmap.bm_flags = 0;
  118.     new->cv_bitmap.bm_type = canv->cv_bitmap.bm_type;
  119.     new->cv_bitmap.bm_rowsize = canv->cv_bitmap.bm_rowsize;
  120.  
  121.     new->cv_bitmap.bm_data = canv->cv_bitmap.bm_data;
  122.     new->cv_bitmap.bm_data += y*canv->cv_bitmap.bm_rowsize;
  123.     new->cv_bitmap.bm_data += x;
  124.  
  125.     new->cv_color = canv->cv_color;
  126.    new->cv_drawmode = canv->cv_drawmode;
  127.    new->cv_font = canv->cv_font;
  128.     new->cv_font_fg_color = canv->cv_font_fg_color;
  129.     new->cv_font_bg_color = canv->cv_font_bg_color;
  130.    return new;
  131. }
  132.  
  133. void gr_init_canvas(grs_canvas *canv, unsigned char * pixdata, int pixtype, int w, int h)
  134. {
  135.     canv->cv_color = 0;
  136.     canv->cv_drawmode = 0;
  137.     canv->cv_font = NULL;
  138.     canv->cv_font_fg_color = 0;
  139.     canv->cv_font_bg_color = 0;
  140.  
  141.     canv->cv_bitmap.bm_x = 0;
  142.     canv->cv_bitmap.bm_y = 0;
  143.     if (pixtype==BM_MODEX)
  144.         canv->cv_bitmap.bm_rowsize = w / 4;
  145.     else
  146.         canv->cv_bitmap.bm_rowsize = w;
  147.     canv->cv_bitmap.bm_w = w;
  148.     canv->cv_bitmap.bm_h = h;
  149.     canv->cv_bitmap.bm_flags = 0;
  150.     canv->cv_bitmap.bm_type = pixtype;
  151.     canv->cv_bitmap.bm_data = pixdata;
  152.  
  153. }
  154.  
  155. void gr_init_sub_canvas(grs_canvas *new, grs_canvas *src, int x, int y, int w, int h)
  156. {
  157.     new->cv_color = src->cv_color;
  158.     new->cv_drawmode = src->cv_drawmode;
  159.     new->cv_font = src->cv_font;
  160.     new->cv_font_fg_color = src->cv_font_fg_color;
  161.     new->cv_font_bg_color = src->cv_font_bg_color;
  162.  
  163.     new->cv_bitmap.bm_x = src->cv_bitmap.bm_x+x;
  164.     new->cv_bitmap.bm_y = src->cv_bitmap.bm_y+y;
  165.     new->cv_bitmap.bm_w = w;
  166.     new->cv_bitmap.bm_h = h;
  167.     new->cv_bitmap.bm_flags = 0;
  168.     new->cv_bitmap.bm_type = src->cv_bitmap.bm_type;
  169.     new->cv_bitmap.bm_rowsize = src->cv_bitmap.bm_rowsize;
  170.  
  171.  
  172.     new->cv_bitmap.bm_data = src->cv_bitmap.bm_data;
  173.     new->cv_bitmap.bm_data += y*src->cv_bitmap.bm_rowsize;
  174.     new->cv_bitmap.bm_data += x;
  175. }
  176.  
  177. void gr_free_canvas(grs_canvas *canv)
  178. {
  179.     free(canv->cv_bitmap.bm_data );
  180.     free(canv);
  181. }
  182.  
  183. void gr_free_sub_canvas(grs_canvas *canv)
  184. {
  185.     free(canv);
  186. }
  187.  
  188. int gr_wait_for_retrace = 1;
  189.  
  190. void gr_show_canvas( grs_canvas *canv )
  191. {
  192.     if (canv->cv_bitmap.bm_type == BM_MODEX )
  193.         gr_modex_setstart( canv->cv_bitmap.bm_x, canv->cv_bitmap.bm_y, gr_wait_for_retrace );
  194.  
  195.     else if (canv->cv_bitmap.bm_type == BM_SVGA )
  196.         gr_vesa_setstart( canv->cv_bitmap.bm_x, canv->cv_bitmap.bm_y );
  197.  
  198.         //    else if (canv->cv_bitmap.bm_type == BM_LINEAR )
  199.         // Int3();        // Get JOHN!
  200.         //gr_linear_movsd( canv->cv_bitmap.bm_data, (void *)0xA0000, 320*200);
  201. }
  202.  
  203. void gr_set_current_canvas( grs_canvas *canv )
  204. {
  205.     if (canv==NULL)
  206.         grd_curcanv = &(grd_curscreen->sc_canvas);
  207.     else
  208.         grd_curcanv = canv;
  209.  
  210.     if ( (grd_curcanv->cv_color >= 0) && (grd_curcanv->cv_color <= 255) )    {
  211.         gr_var_color = grd_curcanv->cv_color;
  212.     } else
  213.         gr_var_color  = 0;
  214.     gr_var_bitmap = grd_curcanv->cv_bitmap.bm_data;
  215.     gr_var_bwidth = grd_curcanv->cv_bitmap.bm_rowsize;
  216.  
  217. }
  218.  
  219. void gr_clear_canvas(int color)
  220. {
  221.     gr_setcolor(color);
  222.     gr_rect(0,0,WIDTH-1,HEIGHT-1);
  223. }
  224.  
  225. void gr_setcolor(int color)
  226. {
  227.     grd_curcanv->cv_color=color;
  228.  
  229.     gr_var_color = color;
  230.  
  231. }
  232. 
  233.