home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / look / src / graphic.c next >
Text File  |  1990-06-14  |  7KB  |  258 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <mmi.h>
  4. #include    <egb.h>
  5. #include    <mos.h>
  6. #include    <snd.h>
  7. #include    <msdos.cf>
  8.  
  9.         char    *work;
  10.         char    *swork;
  11. static    char    *mwork;
  12. static    int        cd_vol;
  13.  
  14. /*** Disk Pattn ****/
  15. char    diskptn[]={
  16.     0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFE,
  17.     0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
  18.     0x80, 0x1F, 0xF0, 0x02, 0x9F, 0xFF, 0xFF, 0xF2,
  19.     0x9F, 0xFF, 0xFF, 0xF2, 0x80, 0x1F, 0xF0, 0x02,
  20.     0x80, 0x1F, 0xF0, 0x02, 0x80, 0x00, 0x00, 0x02,
  21.     0x86, 0x00, 0x00, 0x02, 0x86, 0x00, 0x00, 0x02,
  22.     0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
  23.     0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00 };
  24.  
  25. /**** Exit Pattn ***/
  26. char    exitptn[]={
  27.     0x7F, 0xFC, 0x55, 0x04, 0x6B, 0x44, 0x55, 0x44, 
  28.     0x6B, 0x04, 0x55, 0x04, 0x68, 0x84, 0x54, 0x44, 
  29.     0x68, 0x24, 0x7F, 0xFC, 0x00, 0x00, 0x75, 0x5C, 
  30.     0x45, 0x48, 0x72, 0x48, 0x45, 0x48, 0x75, 0x48 };
  31.  
  32. /**** sub Menu Pattn ****/
  33. char    subptn[]={
  34.     0x00, 0x00, 0x03, 0xE0, 0x0C, 0x18, 0x30, 0x06, 
  35.     0x2C, 0x1A, 0x23, 0xE2, 0x20, 0x82, 0x30, 0x86, 
  36.     0x0C, 0x98, 0x03, 0xE0, 0x00, 0x00, 0x56, 0xAA, 
  37.     0x74, 0xEA, 0x76, 0xEA, 0x54, 0xEA, 0x56, 0xA4 };
  38.  
  39. /***** <- pattn *****/
  40. char    lftptn[]={
  41.     0xFF, 0xFF, 0x80, 0x01, 0x80, 0x01, 0x81, 0x01, 
  42.     0x83, 0x01, 0x87, 0x01, 0x8F, 0xF9, 0x9F, 0xF9, 
  43.     0x8F, 0xF9, 0x87, 0x01, 0x83, 0x01, 0x81, 0x01, 
  44.     0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFF, 0xFF };
  45.  
  46. /***** -> pattn ****/
  47. char    ritptn[]={
  48.     0xFF, 0xFF, 0x80, 0x01, 0x80, 0x01, 0x80, 0x81, 
  49.     0x80, 0xC1, 0x80, 0xE1, 0x9F, 0xF1, 0x9F, 0xF9, 
  50.     0x9F, 0xF1, 0x80, 0xE1, 0x80, 0xC1, 0x80, 0x81, 
  51.     0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFF, 0xFF };
  52.  
  53. /**** MOS 1 Pattn ****/
  54. static    char    mosptn[5][66]={
  55.     { 2, 16,
  56.     0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x60, 0x00, 
  57.     0x30, 0x00, 0x58, 0x00, 0x3C, 0x00, 0x5E, 0x00, 
  58.     0x2F, 0x00, 0x5F, 0x80, 0x2E, 0x00, 0x7C, 0x00, 
  59.     0x66, 0x00, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00, 
  60.     0x7F, 0xFF, 0x3F, 0xFF, 0x5F, 0xFF, 0x6F, 0xFF, 
  61.     0x37, 0xFF, 0x5B, 0xFF, 0x3D, 0xFF, 0x5E, 0xFF, 
  62.     0x2F, 0x7F, 0x5F, 0xBF, 0x2E, 0x7F, 0x7D, 0xFF, 
  63.     0x66, 0xFF, 0x16, 0xFF, 0x7B, 0x7F, 0xF8, 0x7F },
  64.     { 2, 16,
  65.     0x00, 0x00, 0x2F, 0xF4, 0x2F, 0xF4, 0x2F, 0xF4, 
  66.     0x37, 0xEC, 0x39, 0x9C, 0x3C, 0x3C, 0x3E, 0x7C, 
  67.     0x3E, 0x7C, 0x3D, 0xBC, 0x3B, 0xDC, 0x36, 0x6C, 
  68.     0x2C, 0x34, 0x28, 0x14, 0x20, 0x04, 0x00, 0x00,
  69.     0x00, 0x00, 0xAF, 0xF5, 0xAF, 0xF5, 0xAF, 0xF5, 
  70.     0xB7, 0xED, 0xB9, 0x9D, 0xBC, 0x3D, 0xBE, 0x7D, 
  71.     0xBE, 0x7D, 0xBD, 0xBD, 0xBB, 0xDD, 0xB6, 0x6D, 
  72.     0xAC, 0x35, 0xA8, 0x15, 0xA0, 0x05, 0x00, 0x00 },
  73.     { 2, 16,
  74.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x40, 
  75.     0x05, 0x40, 0x05, 0x50, 0x15, 0x50, 0x15, 0x50, 
  76.     0x1F, 0xF0, 0x1F, 0xF0, 0x1F, 0xF0, 0x0F, 0xF0, 
  77.     0x07, 0xE0, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
  78.     0xFF, 0xFF, 0xFF, 0xFF, 0xFA, 0xBF, 0xF5, 0x5F, 
  79.     0xF5, 0x4F, 0xE5, 0x57, 0xD5, 0x57, 0xD5, 0x57, 
  80.     0xDF, 0xF7, 0xDF, 0xF7, 0xDF, 0xF7, 0xEF, 0xF7, 
  81.     0xF7, 0xEF, 0xFB, 0xDF, 0xFF, 0xFF, 0xFF, 0xFF },
  82.     { 2, 16,
  83.     0x03, 0x00, 0x03, 0x80, 0x02, 0xC0, 0x02, 0x40, 
  84.     0x02, 0x40, 0x02, 0x00, 0x0E, 0x00, 0x1E, 0x00, 
  85.     0x1E, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x6A, 0xE0, 
  86.     0x4A, 0xA0, 0x6A, 0xE0, 0x4A, 0x80, 0x6E, 0x80,
  87.     0xFB, 0x7F, 0xFB, 0xBF, 0xFA, 0xDF, 0xFA, 0x5F, 
  88.     0xFA, 0x5F, 0xE2, 0x9F, 0xCE, 0xFF, 0xDE, 0xFF, 
  89.     0xDE, 0xFF, 0xCD, 0xFF, 0xE1, 0xFF, 0xFF, 0xFF, 
  90.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
  91.     { 2, 16,
  92.     0x00, 0x00, 0x07, 0x00, 0x08, 0x80, 0x0A, 0x40, 
  93.     0x01, 0x40, 0x05, 0x40, 0x02, 0x40, 0x08, 0x40, 
  94.     0x04, 0x80, 0x07, 0x00, 0x00, 0x00, 0x75, 0x60, 
  95.     0x47, 0x50, 0x77, 0x50, 0x17, 0x50, 0x75, 0x60,
  96.     0xF0, 0x7F, 0xF7, 0x7F, 0xE8, 0xBF, 0xEA, 0x5F, 
  97.     0xE1, 0x5F, 0xE5, 0x5F, 0xE2, 0x5F, 0xE8, 0x5F, 
  98.     0xF4, 0xBF, 0xF7, 0x7F, 0xF0, 0x7F, 0xFF, 0xFF, 
  99.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
  100.  
  101. void    wrtmos(int tp)
  102. {
  103.     MOS_type(1, 0, 0, mosptn[tp]);
  104. }
  105. int        mosclip(int s,int x,int y)
  106. {
  107.     int        i;
  108.     int        bs,bx,by;
  109.  
  110.     i = 10000;
  111.     do {
  112.         MOS_rdpos(&bs,&bx,&by);
  113.         if ( --i == 5000 )
  114.             wrtmos(2);
  115.     } while ( i > 0 && bs == 0 &&
  116.               bx >= (x - 8) && bx <= (x + 8) &&
  117.               by >= (y - 8) && by <= (y + 8) );
  118.     wrtmos(0);
  119.     return (bs != 0 ? 1 : 0);            
  120. }
  121. void    grainit(void)
  122. {
  123.     int        i;
  124.     char    *p;
  125.  
  126.     if ( (p = work = malloc(2048)) == NULL )
  127.         exit(0);
  128.     for ( i=2048 ; i > 0 ; i-- ) *(p++) = 0;
  129.     if ( (p = mwork = malloc(2048)) == NULL )
  130.         exit(0);
  131.     for ( i=2048 ; i > 0 ; i-- ) *(p++) = 0;
  132.     if ( (swork = malloc(16384)) == NULL )
  133.         exit(0);
  134.  
  135.     SND_elevol_read(1,&cd_vol,&cd_vol);
  136.     SND_init(swork);
  137.     MOS_start(mwork,2048);
  138.     MOS_resolution(0, 3);
  139.     MOS_writePage(0);
  140.     EGB_init(work,2048);
  141.     SND_elevol_mute(0x33);
  142.     SND_elevol_set(1,cd_vol,cd_vol);
  143.     EGB_resolution(work, 0, 3);
  144.     EGB_resolution(work, 1, 3);
  145.     EGB_displayPage(work, 0, 3);
  146.     EGB_pen(work,0);
  147.     EGB_penSize(work,1);
  148.     wrtmos(0);
  149. }
  150. void    graend(void)
  151. {
  152.     MOS_end();
  153.     SND_end();
  154.     SND_elevol_mute(0x30);
  155.     SND_elevol_set(1,cd_vol,cd_vol);
  156.     exit(0);
  157. }
  158. void    line(int x1, int y1, int x2, int y2, int col, int mode)
  159. {
  160.     char    para[10];
  161.  
  162.     MOS_disp(0);
  163.     EGB_writeMode(work,mode);
  164.     EGB_paintMode(work,0x002);
  165.     EGB_color(work,0,col);
  166.     WORD(para + 0) = 2;
  167.     WORD(para + 2) = x1;
  168.     WORD(para + 4) = y1;
  169.     WORD(para + 6) = x2;
  170.     WORD(para + 8) = y2;
  171.     EGB_connect(work,para);
  172.     MOS_disp(1);
  173. }
  174. void    box(int x1, int y1, int x2, int y2, int col, int mode)
  175. {
  176.     char    para[8];
  177.  
  178.     MOS_disp(0);
  179.     EGB_writeMode(work,mode);
  180.     EGB_paintMode(work,0x002);
  181.     EGB_color(work,0,col);
  182.     WORD(para + 0) = x1;
  183.     WORD(para + 2) = y1;
  184.     WORD(para + 4) = x2;
  185.     WORD(para + 6) = y2;
  186.     EGB_rectangle(work,para);
  187.     MOS_disp(1);
  188. }
  189. void    fbox(int x1, int y1, int x2, int y2, int col, int bcol, int mode)
  190. {
  191.     char    para[8];
  192.  
  193.     MOS_disp(0);
  194.     EGB_writeMode(work,mode);
  195.     EGB_paintMode(work,0x022);
  196.     EGB_color(work,0,col);
  197.     EGB_color(work,2,bcol);
  198.     WORD(para + 0) = x1;
  199.     WORD(para + 2) = y1;
  200.     WORD(para + 4) = x2;
  201.     WORD(para + 6) = y2;
  202.     EGB_rectangle(work,para);
  203.     MOS_disp(1);
  204. }
  205. char    *getvram(int x1,int y1,int x2, int y2)
  206. {
  207.     int        i;
  208.     char    *vram;
  209.     char    para[14];
  210.  
  211.     i = (((x2 - x1) + 8) / 8) * 4 * ((y2 - y1) + 1);
  212.     if ( (vram = malloc(i)) == NULL )
  213.         return NULL;
  214.  
  215.     DWORD(para + 0) = (int)vram;
  216.     WORD(para + 4) = getds();
  217.     WORD(para + 6) = x1;
  218.     WORD(para + 8) = y1;
  219.     WORD(para + 10) = x2;
  220.     WORD(para + 12) = y2;
  221.     MOS_disp(0);
  222.     EGB_getBlock(work,para);
  223.     MOS_disp(1);
  224.     return vram;
  225. }
  226. void    putvram(char *vram,int x1,int y1,int x2, int y2)
  227. {
  228.     char    para[14];
  229.  
  230.     if ( vram == NULL )
  231.         return;
  232.  
  233.     DWORD(para + 0) = (int)vram;
  234.     WORD(para + 4) = getds();
  235.     WORD(para + 6) = x1;
  236.     WORD(para + 8) = y1;
  237.     WORD(para + 10) = x2;
  238.     WORD(para + 12) = y2;
  239.     MOS_disp(0);
  240.     EGB_writeMode(work,0);
  241.     EGB_putBlock(work,0,para);
  242.     MOS_disp(1);
  243. }
  244. void    wrtstrf(x,y,fnt,col,bak,frm,pa1,pa2,pa3,pa4,pa5)
  245. int        x,y,fnt,col,bak;
  246. char    *frm;
  247. int        pa1,pa2,pa3,pa4,pa5;
  248. {
  249.     char    tmp[256];
  250.  
  251.     sprintf(tmp,frm,pa1,pa2,pa3,pa4,pa5);
  252.     VRAM_wrtstr(tmp,x,y,fnt == 0 ? 16 : 0x90,col,bak,0,0);
  253. }
  254. void    wrtstr(char *str,int x,int y,int fnt,int col,int bak)
  255. {
  256.     VRAM_wrtstr(str,x,y,fnt == 0 ? 16 : 0x90,col,bak,0,0);
  257. }
  258.