home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / REND / CRTM500.C < prev    next >
C/C++ Source or Header  |  1989-11-30  |  5KB  |  213 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <dos.h>
  5. #include <FIF.H>
  6.  
  7. static    int        vline ;
  8.  
  9. #define LINE1        80
  10. #define LINE2        160
  11.  
  12. #define setval0(c0, c1, c2, c3)                        \
  13.           (char)( ((c0)     > tiletable[0] ? 0x80 : 0) \
  14.                 | ((c0)     > tiletable[1] ? 0x40 : 0) \
  15.                 | ((c1)     > tiletable[2] ? 0x20 : 0) \
  16.                 | ((c1)     > tiletable[3] ? 0x10 : 0) \
  17.                 | ((c2)     > tiletable[0] ? 0x08 : 0) \
  18.                 | ((c2)     > tiletable[1] ? 0x04 : 0) \
  19.                 | ((c3)     > tiletable[2] ? 0x02 : 0) \
  20.                 | ((c3)     > tiletable[3] ? 0x01 : 0) )
  21.  
  22. #define setval1(c0,c1,c2,c3)                        \
  23.           (char)( ((c0)     > tiletable[4] ? 0x80 : 0) \
  24.                 | ((c0)     > tiletable[5] ? 0x40 : 0) \
  25.                 | ((c1)     > tiletable[6] ? 0x20 : 0) \
  26.                 | ((c1)     > tiletable[7] ? 0x10 : 0) \
  27.                 | ((c2)     > tiletable[4] ? 0x08 : 0) \
  28.                 | ((c2)     > tiletable[5] ? 0x04 : 0) \
  29.                 | ((c3)     > tiletable[6] ? 0x02 : 0) \
  30.                 | ((c3)     > tiletable[7] ? 0x01 : 0) )
  31.  
  32. #define setval2(c0,c1,c2,c3)                         \
  33.           (char)( ((c0)     > tiletable[ 8] ? 0x80 : 0) \
  34.                 | ((c0)     > tiletable[ 9] ? 0x40 : 0) \
  35.                 | ((c1)     > tiletable[10] ? 0x20 : 0) \
  36.                 | ((c1)     > tiletable[11] ? 0x10 : 0) \
  37.                 | ((c2)     > tiletable[ 8] ? 0x08 : 0) \
  38.                 | ((c2)     > tiletable[ 9] ? 0x04 : 0) \
  39.                 | ((c3)     > tiletable[10] ? 0x02 : 0) \
  40.                 | ((c3)     > tiletable[11] ? 0x01 : 0) )
  41.  
  42. int tiletable[] = {
  43.          7 * 32 / 12,  4 * 32 / 12, 10 * 32 / 12,  1 * 32 / 12,
  44.          3 * 32 / 12,  0 * 32 / 12,     6 * 32 / 12,  9 * 32 / 12,
  45.         11 * 32 / 12,  8 * 32 / 12,     2 * 32 / 12,  5 * 32 / 12
  46. };
  47.  
  48. #define gc(c)        ((c) >> 11) /* (((c) >> 11) & 0x1f) */
  49. #define rc(c)        (((c) >>  6) & 0x1f)
  50. #define bc(c)        (((c) >>  1) & 0x1f)
  51.  
  52. static    GraphData    data ;
  53.  
  54. int        GDS_open();
  55. int        GDS_setcompat();
  56. int        GDS_setplane();
  57. int        GDS_resolution();
  58. void    GDS_clearScreen();
  59. int        GDS_initData();
  60. int        GDS_resetData();
  61. int        GDS_lineColor();
  62. int        GDS_chainFirst();
  63. int        GDS_outputGraph();
  64.  
  65. void    crtclr( void );
  66.  
  67. char    *program = "Do-GA C.G.A System Rendering Program for Panacom M500" ;
  68.  
  69. /*    CRTの初期化    */
  70. void    crtinit( line )
  71. int        line ;
  72. {
  73.     static    int        openflag = 0 ;
  74.  
  75.     /*    縦ライン数    */
  76.     vline = line ;
  77.  
  78.     /*    グラフィックの初期化  */
  79.     if ( ! openflag )
  80.     {
  81.         openflag = 1 ;
  82.  
  83.         if ( GDS_initData( &data , 1000 ) != 0 )
  84.         {
  85.             fprintf( stderr,
  86.             "正常に 図形データ列格納領域を初期化できませんでした。\n");
  87.             exit(1);
  88.         }
  89.  
  90.         if ( GDS_open( 1000 ) )
  91.         {
  92.             fprintf( stderr , "正常に 初期化できませんでした。\n");
  93.             exit(1);
  94.         }
  95.  
  96.         GDS_resolution( 640, 400 );
  97.         GDS_setplane( 3 );
  98.         GDS_setcompat( 0 );
  99.     }
  100. }
  101.  
  102. /*    CRTのクリア    */
  103. void    crtclr()
  104. {
  105.     fprintf( stderr, "\x1B[2J" );
  106.     GDS_clearScreen();
  107. }
  108.  
  109. /*    CRT出力    */
  110. void    crtout( framebuf, xlen, y )
  111. short    *framebuf ;
  112. int        xlen ;
  113. int        y ;
  114. {
  115.     int                    i, n ;
  116.     unsigned short        cl0, cl1, cl2, cl3 ;
  117.     unsigned short        c0, c1, c2, c3 ;
  118.  
  119.     unsigned char far    *p_vram;
  120.     union    REGS regs;
  121.  
  122.     if ( y == 0 )
  123.     {
  124.         regs.h.ah = 0x80;        /* initialize */
  125.         int86(0x92, ®s, ®s);
  126.         regs.h.ah = 0xfa;        /* max plane */
  127.         regs.h.al = 0x03;
  128.         int86(0x92, ®s, ®s);
  129.         regs.h.ah = 0xf9;        /* 8 color */
  130.         regs.h.al = 0x00;
  131.         int86(0x92, ®s, ®s);
  132.     }
  133.  
  134.     if ( vline == 256 ) {
  135.         if (y % 2 != 0)
  136.             return;
  137.         p_vram = (unsigned char far *)0xc0000000 + (y / 2) * 80 * 3;
  138.         n = xlen / 4 ;
  139.     } else {
  140.         if (y % 4 != 0)
  141.             return;
  142.         p_vram = (unsigned char far *)0xc0000000 + (y / 4) * 80 * 3;
  143.         n = xlen / 8 ;
  144.     }
  145.  
  146.     for (i = 0; i < n; i++, p_vram++) {
  147.         if ( vline == 256 ) {
  148.             cl0 = *framebuf++;
  149.             cl1 = *framebuf++;
  150.             cl2 = *framebuf++;
  151.             cl3 = *framebuf++;
  152.         } else {
  153.             cl0 = *framebuf;
  154.             cl1 = *(framebuf + 2);
  155.             cl2 = *(framebuf + 4);
  156.             cl3 = *(framebuf + 6);
  157.             framebuf += 8;
  158.         }
  159.  
  160.         *(char far *)0xc000ff81 = 4;
  161.         c0 = gc(cl0);        /* green */
  162.         c1 = gc(cl1);
  163.         c2 = gc(cl2);
  164.         c3 = gc(cl3);
  165.         *(p_vram        ) = setval0(c0, c1, c2, c3);
  166.         *(p_vram + LINE1) = setval1(c0, c1, c2, c3);
  167.         *(p_vram + LINE2) = setval2(c0, c1, c2, c3);
  168.  
  169.         *(char far *)0xc000ff81 = 2;
  170.         c0 = rc(cl0);        /* red */
  171.         c1 = rc(cl1);
  172.         c2 = rc(cl2);
  173.         c3 = rc(cl3);
  174.         *(p_vram        ) = setval1(c0, c1, c2, c3);
  175.         *(p_vram + LINE1) = setval2(c0, c1, c2, c3);
  176.         *(p_vram + LINE2) = setval0(c0, c1, c2, c3);
  177.  
  178.         *(char far *)0xc000ff81 = 1;
  179.         c0 = bc(cl0);        /* blue */
  180.         c1 = bc(cl1);
  181.         c2 = bc(cl2);
  182.         c3 = bc(cl3);
  183.         *(p_vram        ) = setval2(c0, c1, c2, c3);
  184.         *(p_vram + LINE1) = setval0(c0, c1, c2, c3);
  185.         *(p_vram + LINE2) = setval1(c0, c1, c2, c3);
  186.     }
  187. }
  188.  
  189. /*    ライン        */
  190. void    crtline( x1, y1, x2, y2 )
  191. int        x1, y1, x2, y2 ;
  192. {
  193.     int        ret;
  194.     unsigned    n, offset;
  195.  
  196.     if ( vline == 256 )
  197.     {
  198.         x1 *= 2 ;
  199.         y1 *= 2 ;
  200.         x2 *= 2 ;
  201.         y2 *= 2 ;
  202.     }
  203.  
  204.     y1 = y1 * 3 / 4 ;
  205.     y2 = y2 * 3 / 4 ;
  206.  
  207.     GDS_lineColor( &data , 7 );
  208.     GDS_chainFirst( &data , x1 , y1 , x2 , y2 );
  209.     GDS_outputGraph( &data , &n ,&offset );
  210.     GDS_resetData( &data );
  211. }
  212.  
  213.