home *** CD-ROM | disk | FTP | other *** search
/ MegaDoom Adventures / PMWMEGADOOM.iso / doom / creators / deu521 / source / gfx.c < prev    next >
C/C++ Source or Header  |  1994-05-18  |  18KB  |  723 lines

  1. /*
  2.    Doom Editor Utility, by Brendon Wyber and Raphaël Quinet.
  3.  
  4.    You are allowed to use any parts of this code in another program, as
  5.    long as you give credits to the authors in the documentation and in
  6.    the program itself.  Read the file README.1ST for more information.
  7.  
  8.    This program comes with absolutely no warranty.
  9.  
  10.    GFX.C - Graphics routines.
  11. */
  12.  
  13. /* the includes */
  14. #include "deu.h"
  15. #include <math.h>
  16. #include <dos.h>
  17.  
  18. /* if your graphics driver doesn't like circles, draw squares instead */
  19. #ifdef NO_CIRCLES
  20. #define circle( x, y, r)    line( x - r, y - r, x - r, y + r); \
  21.                 line( x - r, y + r, x + r, y + r); \
  22.                 line( x + r, y + r, x + r, y - r); \
  23.                 line( x + r, y - r, x - r, y - r)
  24. #endif /* NO_CIRCLES */
  25.  
  26. /* the global variables */
  27. int GfxMode = 0;    /* graphics mode number, or 0 for text */
  28.             /* 1 = 320x200, 2 = 640x480, 3 = 800x600, 4 = 1024x768 */
  29.             /* positive = 16 colors, negative = 256 colors */
  30. int OrigX;        /* the X origin */
  31. int OrigY;        /* the Y origin */
  32. float Scale;        /* the scale value */
  33. int PointerX;        /* X position of pointer */
  34. int PointerY;        /* Y position of pointer */
  35. int ScrMaxX;        /* maximum X screen coord */
  36. int ScrMaxY;        /* maximum Y screen coord */
  37. int ScrCenterX;        /* X coord of screen center */
  38. int ScrCenterY;        /* Y coord of screen center */
  39.  
  40. #ifdef CIRRUS_PATCH
  41. char mp[ 256];
  42.  
  43. char HWCursor[] =
  44. {
  45.    0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  46.    0x30, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
  47.    0x1F, 0x00, 0x00, 0x00, 0x1F, 0xC0, 0x00, 0x00,
  48.    0x0F, 0xF0, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00,
  49.    0x07, 0xC0, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00,
  50.    0x03, 0x70, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00,
  51.    0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  60.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61.    0x3F, 0xFF, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF,
  62.    0x83, 0xFF, 0xFF, 0xFF, 0x80, 0xFF, 0xFF, 0xFF,
  63.    0xC0, 0x3F, 0xFF, 0xFF, 0xC0, 0x0F, 0xFF, 0xFF,
  64.    0xE0, 0x07, 0xFF, 0xFF, 0xE0, 0x0F, 0xFF, 0xFF,
  65.    0xF0, 0x1F, 0xFF, 0xFF, 0xF0, 0x0F, 0xFF, 0xFF,
  66.    0xF8, 0x07, 0xFF, 0xFF, 0xF8, 0x83, 0xFF, 0xFF,
  67.    0xFD, 0xC7, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF, 0xFF,
  68.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  69.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  70.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  71.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  72.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  73.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  74.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  75.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  76.    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  77. };
  78. #endif /* CIRRUS_PATCH */
  79.  
  80.  
  81. /*
  82.    initialise the graphics display
  83. */
  84.  
  85. void InitGfx()
  86. {
  87.    static Bool firsttime = TRUE;
  88.    static int  gdriver;
  89.    static int  gmode;
  90.    int         errorcode = grNoInitGraph;
  91.  
  92.    printf( "Switching to graphics mode...\n");
  93. #ifdef CIRRUS_PATCH
  94.    if (CirrusCursor == TRUE)
  95.       SetHWCursorMap( HWCursor);
  96. #endif /* CIRRUS_PATCH */
  97.    if (firsttime)
  98.    {
  99.       if (VideoMode > 0)
  100.       {
  101.      gdriver = installuserdriver( BGIDriver, NULL);
  102.      gmode = VideoMode;
  103.      initgraph( &gdriver, &gmode, NULL);
  104.      errorcode = graphresult();
  105.       }
  106.       if (errorcode != grOk)
  107.       {
  108.      gdriver = VGA;
  109.      gmode = VGAHI;
  110.       }
  111.    }
  112.    if (gdriver == VGA || !firsttime)
  113.    {
  114.       initgraph( &gdriver, &gmode, NULL);
  115.       errorcode = graphresult();
  116.       if (errorcode != grOk)
  117.      ProgError( "graphics error: %s", grapherrormsg( errorcode));
  118.    }
  119.    if (gdriver == VGA)
  120.       GfxMode = 2; /* 640x480x16 */
  121.    else
  122.    {
  123.       GfxMode = -gmode; /* 640x480x256, 800x600x256, or 1024x768x256 */
  124.       SetDoomPalette( 0);
  125.    }
  126.    setlinestyle( 0, 0, 1);
  127.    setbkcolor( TranslateToDoomColor( BLACK));
  128.    settextstyle( 0, 0, 1);
  129.    firsttime = FALSE;
  130.    ScrMaxX = getmaxx();
  131.    ScrMaxY = getmaxy();
  132.    ScrCenterX = ScrMaxX / 2;
  133.    ScrCenterY = ScrMaxY / 2;
  134. }
  135.  
  136.  
  137.  
  138. /*
  139.    terminate the graphics display
  140. */
  141.  
  142. void TermGfx()
  143. {
  144.    if (GfxMode)
  145.    {
  146.       closegraph();
  147.       GfxMode = 0;
  148.    }
  149. }
  150.  
  151.  
  152.  
  153. /*
  154.    switch from VGA 16 colours to VGA 256 colours
  155. */
  156.  
  157. Bool SwitchToVGA256()
  158. {
  159.    static int gdriver = -1;
  160.    int gmode, errorcode;
  161.  
  162.    if (GfxMode > 0 && gdriver != VGA) /* if 16 colors and not failed before */
  163.    {
  164.       if (gdriver == -1)
  165.       {
  166.      gdriver = installuserdriver( "VGA256", NULL);
  167.      errorcode = graphresult();
  168.       }
  169.       if (UseMouse)
  170.      HideMousePointer();
  171.       closegraph();
  172.       gmode = 0;
  173.       initgraph( &gdriver, &gmode, NULL);
  174.       errorcode = graphresult();
  175.       if (errorcode != grOk)
  176.       {
  177.      /* failed for 256 colors - back to 16 colors */
  178.      gdriver = VGA;
  179.      gmode = VGAHI;
  180.      initgraph( &gdriver, &gmode, NULL);
  181.      errorcode = graphresult();
  182.       }
  183.       if (errorcode != grOk) /* shouldn't happen */
  184.      ProgError( "graphics error: %s", grapherrormsg( errorcode));
  185.       if (UseMouse)
  186.      ShowMousePointer();
  187.       GfxMode = -1 /* 320x200x256 */;
  188.       SetDoomPalette( 0);
  189.       ScrMaxX = getmaxx();
  190.       ScrMaxY = getmaxy();
  191.       ScrCenterX = ScrMaxX / 2;
  192.       ScrCenterY = ScrMaxY / 2;
  193.       return TRUE;
  194.    }
  195.    return FALSE;
  196. }
  197.  
  198.  
  199.  
  200. /*
  201.    switch from VGA 256 colours to VGA 16 colours
  202. */
  203.  
  204. Bool SwitchToVGA16()
  205. {
  206.    int gdriver, gmode, errorcode;
  207.  
  208.    if (GfxMode == -1) /* switch only if we are in 320x200x256 colors */
  209.    {
  210.       if (UseMouse)
  211.      HideMousePointer();
  212.       closegraph();
  213.       gdriver = VGA;
  214.       gmode = VGAHI;
  215.       initgraph( &gdriver, &gmode, NULL);
  216.       errorcode = graphresult();
  217.       if (errorcode != grOk) /* shouldn't happen */
  218.      ProgError( "graphics error: %s", grapherrormsg( errorcode));
  219.       if (UseMouse)
  220.      ShowMousePointer();
  221.       GfxMode = 2; /* 640x480x16 */
  222.       ScrMaxX = getmaxx();
  223.       ScrMaxY = getmaxy();
  224.       ScrCenterX = ScrMaxX / 2;
  225.       ScrCenterY = ScrMaxY / 2;
  226.       return TRUE;
  227.    }
  228.    return FALSE;
  229. }
  230.  
  231.  
  232.  
  233. /*
  234.    clear the screen
  235. */
  236.  
  237. void ClearScreen()
  238. {
  239.    cleardevice();
  240. }
  241.  
  242.  
  243.  
  244. /*
  245.    set the current drawing color
  246. */
  247.  
  248. void SetColor( int color)
  249. {
  250.    if (GfxMode < 0)
  251.       setcolor( TranslateToDoomColor(color));
  252.    else
  253.       setcolor( color);
  254. }
  255.  
  256.  
  257.  
  258. /*
  259.    draw a line on the screen from map coords
  260. */
  261.  
  262. void DrawMapLine( int mapXstart, int mapYstart, int mapXend, int mapYend)
  263. {
  264.    line( SCREENX( mapXstart), SCREENY( mapYstart), SCREENX( mapXend), SCREENY( mapYend));
  265. }
  266.  
  267.  
  268.  
  269. /*
  270.    draw a circle on the screen from map coords
  271. */
  272.  
  273. void DrawMapCircle( int mapXcenter, int mapYcenter, int mapRadius)
  274. {
  275.    circle( SCREENX( mapXcenter), SCREENY( mapYcenter), (int) (mapRadius * Scale));
  276. }
  277.  
  278.  
  279.  
  280. /*
  281.    draw an arrow on the screen from map coords
  282. */
  283.  
  284. void DrawMapVector( int mapXstart, int mapYstart, int mapXend, int mapYend)
  285. {
  286.    int    scrXstart = SCREENX( mapXstart);
  287.    int    scrYstart = SCREENY( mapYstart);
  288.    int    scrXend   = SCREENX( mapXend);
  289.    int    scrYend   = SCREENY( mapYend);
  290.    double r         = hypot( (double) (scrXstart - scrXend), (double) (scrYstart - scrYend));
  291.    int    scrXoff   = (r >= 1.0) ? (int) ((scrXstart - scrXend) * 8.0 / r * Scale) : 0;
  292.    int    scrYoff   = (r >= 1.0) ? (int) ((scrYstart - scrYend) * 8.0 / r * Scale) : 0;
  293.  
  294.    line( scrXstart, scrYstart, scrXend, scrYend);
  295.    scrXstart = scrXend + 2 * scrXoff;
  296.    scrYstart = scrYend + 2 * scrYoff;
  297.    line( scrXstart - scrYoff, scrYstart + scrXoff, scrXend, scrYend);
  298.    line( scrXstart + scrYoff, scrYstart - scrXoff, scrXend, scrYend);
  299. /*
  300.    line( scrXstart - scrYoff, scrYstart + scrXoff, scrXend + scrXoff, scrYend + scrYoff);
  301.    line( scrXstart + scrYoff, scrYstart - scrXoff, scrXend + scrXoff, scrYend + scrYoff);
  302. */
  303. }
  304.  
  305.  
  306.  
  307. /*
  308.    draw an arrow on the screen from map coords and angle (0 - 65535)
  309. */
  310.  
  311. void DrawMapArrow( int mapXstart, int mapYstart, unsigned angle)
  312. {
  313.    int    mapXend   = mapXstart + (int) (50 * cos(angle / 10430.37835));
  314.    int    mapYend   = mapYstart + (int) (50 * sin(angle / 10430.37835));
  315.    int    scrXstart = SCREENX( mapXstart);
  316.    int    scrYstart = SCREENY( mapYstart);
  317.    int    scrXend   = SCREENX( mapXend);
  318.    int    scrYend   = SCREENY( mapYend);
  319.    double r         = hypot( scrXstart - scrXend, scrYstart - scrYend);
  320.    int    scrXoff   = (r >= 1.0) ? (int) ((scrXstart - scrXend) * 8.0 / r * Scale) : 0;
  321.    int    scrYoff   = (r >= 1.0) ? (int) ((scrYstart - scrYend) * 8.0 / r * Scale) : 0;
  322.  
  323.    line( scrXstart, scrYstart, scrXend, scrYend);
  324.    scrXstart = scrXend + 2 * scrXoff;
  325.    scrYstart = scrYend + 2 * scrYoff;
  326.    line( scrXstart - scrYoff, scrYstart + scrXoff, scrXend, scrYend);
  327.    line( scrXstart + scrYoff, scrYstart - scrXoff, scrXend, scrYend);
  328. }
  329.  
  330.  
  331.  
  332. /*
  333.    draw a line on the screen from screen coords
  334. */
  335.  
  336. void DrawScreenLine( int Xstart, int Ystart, int Xend, int Yend)
  337. {
  338.    line( Xstart, Ystart, Xend, Yend);
  339. }
  340.  
  341.  
  342.  
  343. /*
  344.    draw a filled in box on the screen from screen coords
  345. */
  346.  
  347. void DrawScreenBox( int Xstart, int Ystart, int Xend, int Yend)
  348. {
  349.    setfillstyle( 1, getcolor());
  350.    bar( Xstart, Ystart, Xend, Yend);
  351. }
  352.  
  353.  
  354.  
  355. /*
  356.    draw a filled-in 3D-box on the screen from screen coords
  357. */
  358.  
  359. void DrawScreenBox3D( int Xstart, int Ystart, int Xend, int Yend)
  360. {
  361.    setfillstyle( 1, TranslateToDoomColor( LIGHTGRAY));
  362.    bar( Xstart + 1, Ystart + 1, Xend - 1, Yend - 1);
  363.    SetColor( DARKGRAY);
  364.    line( Xstart, Yend, Xend, Yend);
  365.    line( Xend, Ystart, Xend, Yend);
  366.    if (Xend - Xstart > 20 && Yend - Ystart > 20)
  367.    {
  368.       line( Xstart + 1, Yend - 1, Xend - 1, Yend - 1);
  369.       line( Xend - 1, Ystart + 1, Xend - 1, Yend - 1);
  370.       SetColor( WHITE);
  371.       line( Xstart + 1, Ystart + 1, Xstart + 1, Yend - 1);
  372.       line( Xstart + 1, Ystart + 1, Xend - 1, Ystart + 1);
  373.    }
  374.    SetColor( WHITE);
  375.    line( Xstart, Ystart, Xend, Ystart);
  376.    line( Xstart, Ystart, Xstart, Yend);
  377.    SetColor( BLACK);
  378. }
  379.  
  380.  
  381.  
  382. /*
  383.    draw a hollow 3D-box on the screen from screen coords
  384. */
  385.  
  386. void DrawScreenBoxHollow( int Xstart, int Ystart, int Xend, int Yend)
  387. {
  388.    setfillstyle( 1, TranslateToDoomColor( BLACK));
  389.    bar( Xstart + 1, Ystart + 1, Xend - 1, Yend - 1);
  390.    SetColor( WHITE);
  391.    line( Xstart, Yend, Xend, Yend);
  392.    line( Xend, Ystart, Xend, Yend);
  393.    if (Xend - Xstart > 20 && Yend - Ystart > 20)
  394.    {
  395.       line( Xstart + 1, Yend - 1, Xend - 1, Yend - 1);
  396.       line( Xend - 1, Ystart + 1, Xend - 1, Yend - 1);
  397.       SetColor( DARKGRAY);
  398.       line( Xstart + 1, Ystart + 1, Xstart + 1, Yend - 1);
  399.       line( Xstart + 1, Ystart + 1, Xend - 1, Ystart + 1);
  400.    }
  401.    SetColor( DARKGRAY);
  402.    line( Xstart, Ystart, Xend, Ystart);
  403.    line( Xstart, Ystart, Xstart, Yend);
  404.    SetColor( WHITE);
  405. }
  406.  
  407.  
  408.  
  409. /*
  410.    draw a meter bar on the screen from screen coords (in a hollow box); max. value = 1.0
  411. */
  412.  
  413. void DrawScreenMeter( int Xstart, int Ystart, int Xend, int Yend, float value)
  414. {
  415.    if (value < 0.0)
  416.       value = 0.0;
  417.    if (value > 1.0)
  418.       value = 1.0;
  419.    setfillstyle( 1, TranslateToDoomColor( BLACK));
  420.    bar( Xstart + 1 + (int) ((Xend - Xstart - 2) * value), Ystart + 1, Xend - 1, Yend - 1);
  421.    setfillstyle( 1, TranslateToDoomColor( LIGHTGREEN));
  422.    bar( Xstart + 1, Ystart + 1, Xstart + 1 + (int) ((Xend - Xstart - 2) * value), Yend - 1);
  423. }
  424.  
  425.  
  426.  
  427. /*
  428.    write text to the screen
  429. */
  430.  
  431. void DrawScreenText( int Xstart, int Ystart, char *msg, ...)
  432. {
  433.    static int lastX;
  434.    static int lastY;
  435.    char temp[ 120];
  436.    va_list args;
  437.  
  438.    va_start( args, msg);
  439.    vsprintf( temp, msg, args);
  440.    va_end( args);
  441.    if (Xstart < 0)
  442.       Xstart = lastX;
  443.    if (Ystart < 0)
  444.       Ystart = lastY;
  445.    outtextxy( Xstart, Ystart, temp);
  446.    lastX = Xstart;
  447.    lastY = Ystart + 10;  /* or textheight("W") ? */
  448. }
  449.  
  450.  
  451.  
  452. /*
  453.    draw (or erase) the pointer if we aren't using the mouse
  454. */
  455.  
  456. void DrawPointer( Bool rulers)
  457. {
  458.    int r;
  459.  
  460.    /* use XOR mode : drawing the pointer twice erases it */
  461.    setwritemode( XOR_PUT);
  462.    /* draw the pointer */
  463.    if ( rulers)
  464.    {
  465.       SetColor( MAGENTA);
  466.       r = (int) (512 * Scale);
  467.       circle( PointerX, PointerY, r);
  468.       r >>= 1;
  469.       circle( PointerX, PointerY, r);
  470.       r >>= 1;
  471.       circle( PointerX, PointerY, r);
  472.       r >>= 1;
  473.       circle( PointerX, PointerY, r);
  474.       r = (int) (1024 * Scale);
  475.       line( PointerX - r, PointerY, PointerX + r, PointerY);
  476.       line( PointerX, PointerY - r, PointerX, PointerY + r);
  477.    }
  478.    else
  479.    {
  480.       SetColor( YELLOW);
  481.       line( PointerX - 15, PointerY - 13, PointerX + 15, PointerY + 13);
  482.       line( PointerX - 15, PointerY + 13, PointerX + 15, PointerY - 13);
  483.    }
  484.    /* restore normal write mode */
  485.    setwritemode( COPY_PUT);
  486. }
  487.  
  488.  
  489.  
  490. /*
  491.    load one "playpal" palette and change all palette colours
  492. */
  493.  
  494. void SetDoomPalette( int playpalnum)
  495. {
  496.    MDirPtr             dir;
  497.    unsigned char huge *dpal;
  498.    int                 n;
  499.  
  500.    if (playpalnum < 0 && playpalnum > 13)
  501.       return;
  502.    dir = FindMasterDir( MasterDir, "PLAYPAL");
  503.    if (dir)
  504.    {
  505.       dpal = GetFarMemory( 768 * sizeof( char));
  506.       BasicWadSeek( dir->wadfile, dir->dir.start);
  507.       for (n = 0; n <= playpalnum; n++)
  508.      BasicWadRead( dir->wadfile, dpal, 768L);
  509.       for (n = 0; n < 768; n++)
  510.      dpal[ n] /= 4;
  511.       _AX = 0x1012;
  512.       _BX = 0;
  513.       _CX = 256;
  514.       _ES = FP_SEG( dpal);
  515.       _DX = FP_OFF( dpal);
  516.       __int__( 0x10);
  517.       FreeFarMemory( dpal);
  518.     }
  519. }
  520.  
  521.  
  522.  
  523. /*
  524.    translate a standard color to Doom palette 0 (approx.)
  525. */
  526.  
  527. int TranslateToDoomColor( int color)
  528. {
  529.    if (GfxMode < 0)
  530.       switch (color)
  531.       {
  532.       case BLACK:
  533.      return 0;
  534.       case BLUE:
  535.      return 202;
  536.       case GREEN:
  537.      return 118;
  538.       case CYAN:
  539.      return 194;
  540.       case RED:
  541.      return 183;
  542.       case MAGENTA:
  543.      return 253;
  544.       case BROWN:
  545.      return 144;
  546.       case LIGHTGRAY:
  547.      return 88;
  548.       case DARKGRAY:
  549.      return 96;
  550.       case LIGHTBLUE:
  551.      return 197;
  552.       case LIGHTGREEN:
  553.      return 112;
  554.       case LIGHTCYAN:
  555.      return 193;
  556.       case LIGHTRED:
  557.      return 176;
  558.       case LIGHTMAGENTA:
  559.      return 250;
  560.       case YELLOW:
  561.      return 231;
  562.       case WHITE:
  563.      return 4;
  564.       }
  565.    return color;
  566. }
  567.  
  568.  
  569.  
  570. /*
  571.    translate (dx, dy) into an integer angle value (0-65535)
  572. */
  573.  
  574. unsigned ComputeAngle( int dx, int dy)
  575. {
  576.    return (unsigned) (atan2( (double) dy, (double) dx) * 10430.37835 + 0.5);
  577.    /* Yes, I know this function could be in another file, but */
  578.    /* this is the only source file that includes <math.h>...  */
  579. }
  580.  
  581.  
  582.  
  583. /*
  584.    compute the distance from (0, 0) to (dx, dy)
  585. */
  586.  
  587. unsigned ComputeDist( int dx, int dy)
  588. {
  589.    return (unsigned) (hypot( (double) dx, (double) dy) + 0.5);
  590.    /* Yes, I know this function could be in another file, but */
  591.    /* this is the only source file that includes <math.h>...  */
  592. }
  593.  
  594.  
  595.  
  596. /*
  597.    insert the vertices of a new polygon
  598. */
  599.  
  600. void InsertPolygonVertices( int centerx, int centery, int sides, int radius)
  601. {
  602.    int n;
  603.  
  604.    for (n = 0; n < sides; n++)
  605.       InsertObject( OBJ_VERTEXES, -1, centerx + (int) ((double) radius * cos( 6.28 * (double) n / (double) sides)), centery + (int) ((double) radius * sin( 6.2832 * (double) n / (double) sides)));
  606.    /* Yes, I know... etc. */
  607. }
  608.  
  609.  
  610.  
  611. /*
  612.    move (x, y) to a new position: rotate and scale around (0, 0)
  613. */
  614.  
  615. void RotateAndScaleCoords( int *x, int *y, double angle, double scale)
  616. {
  617.    double r, theta;
  618.  
  619.    r = hypot( (double) *x, (double) *y);
  620.    theta = atan2( (double) *y, (double) *x);
  621.    *x = (int) (r * scale * cos( theta + angle) + 0.5);
  622.    *y = (int) (r * scale * sin( theta + angle) + 0.5);
  623.    /* Yes, I know... etc. */
  624. }
  625.  
  626.  
  627.  
  628. #ifdef CIRRUS_PATCH
  629. /*
  630.    Cirrus Logic Hardware Mouse Cursor Stuff
  631. */
  632.  
  633. #define CRTC 0x3D4
  634. #define ATTR 0x3C0
  635. #define SEQ  0x3C4
  636. #define GRC  0x3CE
  637. #define LOBYTE(w)           ((unsigned char)(w))
  638. #define HIBYTE(w)           ((unsigned char)((unsigned int)(w) >> 8))
  639.  
  640. unsigned rdinx( unsigned pt, unsigned inx)
  641. {
  642.    if (pt == ATTR)
  643.       inportb( CRTC + 6);
  644.    outportb( pt, inx);
  645.    return inportb( pt + 1);
  646. }
  647.  
  648. void wrinx( int pt, unsigned inx, unsigned val)
  649. {
  650.    if (pt == ATTR)
  651.    {
  652.       inportb( CRTC + 6);
  653.       outportb( pt, inx);
  654.       outportb( pt, val);
  655.    }
  656.    else
  657.    {
  658.       outportb( pt, inx);
  659.       outportb( pt + 1, val);
  660.    }
  661. }
  662.  
  663. void modinx( unsigned pt, unsigned inx, unsigned mask, unsigned nwv)
  664. {
  665.    unsigned temp;
  666.  
  667.    temp = (rdinx( pt, inx) & ~mask) + (nwv & mask);
  668.    wrinx( pt, inx, temp);
  669. }
  670.  
  671. void clrinx( unsigned pt, unsigned inx, unsigned val)
  672. {
  673.    unsigned x;
  674.  
  675.    x = rdinx( pt, inx);
  676.    wrinx( pt, inx, x & ~val);
  677. }
  678.  
  679. void SetHWCursorPos( unsigned x, unsigned y)
  680. {
  681.    outport( SEQ, (x << 5) | 0x10);
  682.    outport( SEQ, (y << 5) | 0x11);
  683. }
  684.  
  685. void SetHWCursorCol( long fgcol, long bgcol)
  686. {
  687.    modinx( SEQ, 0x12, 3, 2);
  688.    outportb( 0x3C8, 0xFF);
  689.    outportb( 0x3C9, LOBYTE( fgcol) >> 2);
  690.    outportb( 0x3C9, HIBYTE( bgcol) >> 2);
  691.    outportb( 0x3C8, 0);
  692.    outportb( 0x3C9, LOBYTE( bgcol) >> 2);
  693.    outportb( 0x3C9, HIBYTE( bgcol) >> 2);
  694.    outportb( 0x3C9, bgcol >> 18);
  695.    modinx( SEQ, 0x12, 3, 1);
  696. }
  697.  
  698. void CopyHWCursorMap( unsigned bytes)
  699. {
  700.    char    *curmapptr = 0xA000FF00L;
  701.    unsigned lbank = (1024 / 64) - 1;
  702.  
  703.    if ((rdinx( GRC, 0x0B) & 32)==0)
  704.       lbank = lbank << 2;
  705.    wrinx( GRC, 9, lbank << 2);
  706.    memmove( curmapptr, &mp, bytes);
  707. }
  708.  
  709. void SetHWCursorMap( char *map)
  710. {
  711.    memmove( &mp, map, 128);
  712.    memmove( &mp + 128, &mp, 128);
  713.    CopyHWCursorMap( 256);
  714.    SetHWCursorCol( 0xFF00000L, 0xFF);
  715.    wrinx( SEQ, 0x13, 0x3F);
  716. }
  717.  
  718. #endif /* CIRRUS_PATCH */
  719.  
  720.  
  721.  
  722. /* end of file */
  723.