home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 July / VPR9707B.ISO / DRIVER / IODATA / GA360 / DISK2.EXE / SAMPLE / RGBLD16.C < prev    next >
Text File  |  1993-04-01  |  5KB  |  229 lines

  1. /************************************************************************
  2.     GA-1024A / GA-1280A グラフィックライブラリ サンプルソース
  3.         RGBLD16.C    < 65536 色モード用 >
  4.     
  5.     RGBファイルロ-ダ   
  6.  
  7.                 アイ・オー・データ機器 Device Inc...
  8. *************************************************************************/
  9. #include <io.h>
  10. #include <stdio.h>
  11. #include <fcntl.h>
  12. #include <math.h>
  13.  
  14. #ifndef TURBO
  15. #include <sys\types.h>
  16. #include <sys\stat.h>
  17. #include <malloc.h>
  18. #else
  19. #include <alloc.h>
  20. #endif
  21.  
  22. #include "gagraph.h"
  23.  
  24. typedef unsigned char  uchar;
  25. typedef unsigned short ushort;
  26. typedef unsigned int   uint;
  27. typedef unsigned long  ulong;
  28.  
  29. #define    SQR(x)        ((x) * (x))
  30.  
  31. #define SIZE_OF_BUFF 1024*16
  32.  
  33. #define    COL_CNT        (6 * 6 * 6)
  34.  
  35. int     handle;        /* DOS file handle */
  36. int        buff_len;    /* buff reset */
  37. uchar   buff[SIZE_OF_BUFF]; /* file buffer */
  38. ushort  buff2[2048];
  39. int        x_wid = 640;        /* screen size */
  40. int        y_wid = 768;
  41. int     gmode = 1;
  42.  
  43. static unsigned int  gaport;
  44. static volatile uchar far *ga_wind;
  45.  
  46. static uchar radj[256];
  47. static uchar gadj[256];
  48. static uchar badj[256];
  49.  
  50. void ginit();
  51. void convert();
  52. void save();
  53. void    wait(int);
  54. int     freadline(int ,int *,int );
  55. void    error(char *);
  56.  
  57. /********************************************
  58.  
  59.     main()
  60.  
  61. *********************************************/
  62. void main(argc,argv)
  63. int    argc;
  64. char    *argv[];
  65. {
  66.     int i,x,y;
  67.     int pal_flg;
  68.  
  69.     puts("GA-1024 RGB File loader program Ver 1.00 I」O DATA DEVICE Inc.");
  70.     if (argc < 2) error("usage : RGBLOAD <RGB file > -Xxxx -Yxxx");
  71.     if ((handle=open(argv[1],O_RDONLY | O_BINARY))==-1) {
  72.         error("file can't open");
  73.     }
  74.     for (i=2;i<argc;i++) {
  75.         if (argv[i][0] == '-' || argv[i][0] == '/') {
  76.             switch(argv[i][1]) {
  77.             case 'X' :
  78.             case 'x' :
  79.                 x_wid = atoi(&argv[i][2]);
  80.              break;
  81.             case 'Y' :
  82.             case 'y' :
  83.                 y_wid = atoi(&argv[i][2]);
  84.              break;
  85.             default:
  86.                 puts("パラメ-タ無効 ");
  87.             }
  88.         }
  89.     }
  90.     gmode = 15; /* 640x480 64k */
  91.     ginit();                /* screen init */
  92.     GAcrtSel(1);
  93.     convert(handle);
  94.     close(handle);
  95.  
  96.     while (1) {
  97.         switch (getch()) {
  98.             case 'C':
  99.             case 'c':   /* 画面モードを変える */
  100.             if (gmode == 15)
  101.                      gmode -= 2 ;
  102.                 else 
  103.                      gmode += 2 ;
  104.                 GAinit(gmode);
  105.                 continue;
  106.             case 'Q':
  107.             case 'q':    /* パレットを変更しないで終了 */
  108.                 pal_flg = PAL_USER;
  109.                 break;
  110.             default:
  111.                 pal_flg = PAL_DEF;
  112.                 break;
  113.         }
  114.         break;
  115.     }
  116.     GAcrtSel(CRT_PC);
  117.     GAterm( pal_flg );
  118.     exit(0);
  119. }
  120.  
  121. /************************************************
  122.  
  123.     初期化
  124.  
  125. *************************************************/
  126. void ginit()
  127. {
  128.     struct VDCONFIG vd;
  129.  
  130.     if (GAinit(gmode)) {
  131.         puts("GAINST が常駐していません");
  132.         exit(1);
  133.     }
  134.     GAclrScreen();
  135.     GAgetVideoConfig((void far *)&vd);
  136.     gaport = vd.port    ; /* GA レジスタのポート番号 */
  137.     ga_wind = (void far *) ((long)vd.ga_seg    << 16); /*グラフィックボードウィンドウのセグメント*/
  138. }
  139.  
  140. /***************************************************
  141.  
  142.     フルカラ-のデ-タを誤差拡散により減色する
  143.  
  144. *****************************************************/
  145. void convert(int handle)
  146. {
  147.     int     x, y, i, c,idx;
  148.  
  149.     for (y = 0; y < y_wid; y++) {
  150.         if (freadline(handle, &idx,x_wid * 3) == 0)
  151.             break;
  152.         for (x = 0; x < x_wid; x++,idx += 3) {
  153.             buff2[x] = ((buff[idx]   & 0xf8) << 8)   | 
  154.                        ((buff[idx+1] & 0xfc) << 3)   |
  155.                        ((buff[idx+2] & 0xf8) >> 3)   ;
  156.         }
  157.         GArestoreImage(0,y,x_wid-1,y,1,(void far *)buff2);  
  158.     }
  159.  
  160. /**************************************************
  161.  
  162.     エラ-処理
  163.  
  164. ***************************************************/
  165. void error(s)
  166. char *s;
  167. {
  168.     puts(s);
  169.     GAcrtSel(0);
  170.     exit(1);
  171. }
  172.  
  173.  
  174. /*****************************************************************
  175.  
  176.     1ライン分ファイルリード
  177.  
  178. ******************************************************************/
  179. int freadline( handl,idx,size)
  180. int  handl;
  181. int *idx;
  182. int  size;
  183. {
  184.     static int fp = 0;
  185.     static int remain = 0;
  186.     int    ret = size;
  187.     
  188.     if (remain < size) {
  189.         fp = 0;
  190.         remain = ( SIZE_OF_BUFF / size ) * size;
  191.         ret = read(handl,buff,remain);
  192.     } 
  193.     *idx = fp;
  194.     fp += size;
  195.     remain -= size;
  196.     return(ret);
  197. }
  198.  
  199.  
  200.  
  201. /* グラフィック コントロ-ル レジスタ ポ-ト */
  202. #define CRTC_AR 0x1e00
  203. #define CRTC_CR 0x1f00
  204. /***********************************************************
  205.  
  206.     CRTC の垂直同期信号をカウントしてウエイトする
  207.  
  208. ************************************************************/
  209. void wait(int count) 
  210. {
  211. #if 0
  212.     int  i;
  213.     for (i=0 ; i < count ; i++) {
  214. #ifdef TURBO
  215.         outportb(CRTC_AR+gaport,31);       /* CRTC STATUS register */
  216.         while ( inportb(CRTC_CR+gaport) & 2) ;
  217.         while ( !(inportb(CRTC_CR+gaport) & 2)) ;
  218. #else
  219.         outp(CRTC_AR+gaport,31);       /* CRTC STATUS register */
  220.         while ( inp(CRTC_CR+gaport) & 2) ;
  221.         while ( !(inp(CRTC_CR+gaport) & 2)) ;
  222. #endif
  223.     }
  224. #endif
  225. }
  226.  
  227.  
  228.