home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / glib / part02 / st-mach.c < prev   
Encoding:
C/C++ Source or Header  |  1989-05-21  |  5.5 KB  |  376 lines

  1. /* $Id: st-mach.c,v 1.6 89/05/06 17:13:42 lee Exp $
  2.  *
  3.  * GLIB - a Generic LIBrarian and editor for synths
  4.  *
  5.  * Machine dependent stuff.
  6.  *
  7.  */
  8.  
  9. #include "glib.h"
  10. #include <ctype.h>
  11.  
  12. int Rows, Cols;
  13.  
  14. #define EscSeq(x) Cconout('\033');Cconout(x);
  15. struct iorecinfo {
  16.     char *ibuf;
  17.     int ibufsiz;
  18.     int ibufhd;
  19.     int ibuftl;
  20.     int ibuflow;
  21.     int ibufhigh;
  22. };
  23. #define MIDIBUFSIZE 5000
  24. char *Origbuf;
  25. int Origsize;
  26. struct iorecinfo *Ioptr;
  27. int work_in[12], work_out[60];  /* GEM & VDI stuff */
  28. int intin[128], ptsin[128];
  29. int intout[128], ptsout[128];
  30. int contrl[12];
  31. int Handle, Vhandle;
  32.  
  33. /* These contain the raw voice data */
  34. hello()
  35. {
  36.     int dummy, n;
  37.  
  38.     appl_init();
  39.  
  40.     /* Get the Midi Iorec and put in a bigger buffer */
  41.     flushmidi();
  42.     Ioptr = (struct iorecinfo *)(Iorec(2));
  43.     Origbuf = Ioptr->ibuf;
  44.     Origsize = Ioptr->ibufsiz;
  45.     Ioptr->ibuf = alloc(MIDIBUFSIZ);
  46.     Ioptr->ibufsiz = MIDIBUFSIZ;
  47.     Ioptr->ibuftl = Ioptr->ibufhd = 0;
  48.     Cursconf(2,0);        /* set non-blinking block cursor */
  49.     mouseon();
  50. }
  51.  
  52. bye()
  53. {
  54.     /* Restore the original Midi Iorec buffer */
  55.     flushmidi();
  56.     Ioptr->ibuf = Origbuf;
  57.     Ioptr->ibufsiz = Origsize;
  58.     Ioptr->ibuftl = Ioptr->ibufhd = 0;
  59.     mouseoff();
  60.     appl_exit();
  61.  
  62.     /* are these ever called? SAF */
  63.     windgoto(23,0);
  64.     windrefresh();
  65.     windexit(0);
  66. }
  67.  
  68. /* getmouse - get currect row and column of mouse */
  69. getmouse(amr,amc)
  70. int *amr;
  71. int *amc;
  72. {
  73. #ifdef USEMOUSE
  74.     int button, ret, keycode, tmp1, tmp2;
  75.     char msgbuf[8];
  76.  
  77.     graf_mkstate(amc,amr,&tmp1,&tmp2);
  78.     /* evnt_multi(MU_TIMER,
  79.         0,0,0,
  80.         0,0,0,0,0,
  81.         0,0,0,0,0,
  82.         msgbuf, 0, 0,
  83.         amc, amr, &button, &ret, &keycode, &ret); */
  84.     /* convert bitmap x,y coordinates to row,colum */
  85.     *amr = (*amr)/16;
  86.     *amc = (*amc)/8;
  87. #else
  88.     *amr = -1;
  89.     *amc = -1;
  90. #endif
  91. }
  92.  
  93. /* statmouse - return mouse button state (0=nothing pressed,1=left,2=right) */
  94. statmouse()
  95. {
  96. #ifdef USEMOUSE
  97.     int tmp1, tmp2, tmp3, buttons;
  98.     char msgbuf[8];
  99.  
  100.     graf_mkstate(&tmp1,&tmp2,&buttons,&tmp3);
  101.     /* evnt_multi(MU_TIMER,
  102.         0,0,0,
  103.         0,0,0,0,0,
  104.         0,0,0,0,0,
  105.         msgbuf, 0, 0,
  106.         &tmp1, &tmp1, &buttons, &tmp1, &tmp1, &tmp1); */
  107.     return(buttons);
  108. #else
  109.     return(-1);
  110. #endif
  111. }
  112.  
  113. int Mouseshown = 0;
  114. mouseon()
  115. {
  116. #ifdef USEMOUSE
  117.     if ( Mouseshown == 0 ) {
  118.         Vsync();    /* wait until next VBI to ensure updating */
  119.         Cursconf(1,0);        /* show block cursor */
  120.         Vsync();    /* wait until next VBI to ensure updating */
  121.         graf_mouse(257,NULL);    /* display mouse cursor */
  122.         Mouseshown = 1;
  123.         Vsync();
  124.     }
  125. #endif
  126. }
  127. mouseoff()
  128. {
  129. #ifdef USEMOUSE
  130.     if ( Mouseshown == 1 ) {
  131.         Vsync();    /* wait until next VBI to ensure updating */
  132.         graf_mouse(256,NULL);    /* hide mouse cursor */
  133.         Vsync();    /* wait until next VBI to ensure updating */
  134.         Cursconf(0,0);        /* hide block cursor */
  135.         Mouseshown = 0;
  136.         Vsync();
  137.     }
  138. #endif
  139. }
  140.  
  141. /* Return when either a console key or mouse button is pressed. */
  142. mouseorkey()
  143. {
  144. #ifdef USEMOUSE
  145.     int evnt, ret, keycode, button, mx, my, tmp1, tmp2, tmp3;
  146.     char msgbuf[8];
  147.  
  148.     mouseon();
  149.     for ( ;; ) {
  150.         graf_mkstate(&tmp1,&tmp2,&button,&tmp3);
  151.         /* evnt = evnt_multi(MU_TIMER,
  152.             0,0,0,
  153.             0,0,0,0,0,
  154.             0,0,0,0,0,
  155.             msgbuf, 0, 0,
  156.             &mx, &my, &button, &ret, &keycode, &ret); */
  157.         if ( button != 0 ) {
  158.             return(MOUSE);
  159.         }
  160.         if ( statmouse() > 0 )
  161.             return(MOUSE);
  162.         if ( statconsole() )
  163.             return(getconsole());
  164.     }
  165. #else
  166.     return(getconsole());
  167. #endif
  168. }
  169.  
  170. flushconsole()
  171. {
  172.     while ( statconsole() )
  173.         getconsole();
  174. }
  175.  
  176. statconsole()
  177. {
  178.     /* return(Bconstat(CONSOLE)); */
  179.     return(Cconis());
  180. }
  181.  
  182. getconsole()
  183. {
  184.     /* return(Bconin(CONSOLE)); */
  185.     return(Crawcin());
  186. }
  187.  
  188. getmidi()
  189. {
  190.     return(Bconin(MIDI));
  191. }
  192.  
  193. /*ARGSUSED*/
  194. sendmidi(c)
  195. {
  196.     Bconout(MIDI,c);
  197. }
  198.  
  199. flushmidi()
  200. {
  201.     while ( STATMIDI )
  202.         getmidi();
  203. }
  204.  
  205. long milliclock()
  206. {
  207.     register long save_ssp=Super(0L);
  208.     register long uhz200= *(long *)0x4ba;
  209.     Super(save_ssp);
  210.     return(uhz200 * 5);
  211. }
  212.  
  213. millisleep(n)
  214. {
  215.     long first = milliclock();
  216.     while ( milliclock() < (first+n) )
  217.         ;
  218. }
  219.  
  220. char *
  221. alloc(n)
  222. {
  223.     char *p;
  224.  
  225.     if ( (p=malloc((unsigned)n)) == (char *)NULL ) {
  226.         printf("*** Whoops *** alloc has failed?!?  No more memory!\n");
  227.         fflush(stdout);
  228.         bye();
  229.     }
  230.     return(p);
  231. }
  232.  
  233. windinit()
  234. {
  235.     Cols=80;
  236.     Rows=25;
  237.     Cursconf(1,NULL);
  238. }
  239.  
  240. windgoto(r,c)
  241. int r,c;
  242. {
  243.     mouseoff();
  244.     EscSeq('Y');
  245.     Cconout(r+040);
  246.     Cconout(c+040);
  247. }
  248.  
  249. windeeol()
  250. {
  251.     mouseoff();
  252.     EscSeq('K');
  253. }
  254.  
  255. winderaserow(r)
  256. {
  257.     windgoto(r,0);
  258.     windeeol();
  259. }
  260.  
  261. windexit(r)
  262. int r;
  263. {
  264.     exit(r);
  265. }
  266.  
  267. windclear()
  268. {
  269.     mouseoff();
  270.     EscSeq('H');
  271.     EscSeq('J');
  272. }
  273.  
  274. /* windgets - get a line of input from the console, handling backspaces */
  275. windgets(s)
  276. char *s;
  277. {
  278.     char *origs = s;
  279.     int c;
  280.  
  281.     while ( (c=getconsole()) != '\n' && c!='\r' && c!= EOF ) {
  282.         if ( c == '\b' ) {
  283.             if ( s > origs ) {
  284.                 windstr("\b \b");
  285.                 s--;
  286.             }
  287.         }
  288.         else {
  289.             windputc(c);
  290.             *s++ = c;
  291.         }
  292.         windrefresh();
  293.     }
  294.     *s = '\0';
  295. }
  296.  
  297. windstr(s)
  298. char *s;
  299. {
  300.     int c;
  301.  
  302.     while ( (c=(*s++)) != '\0' )
  303.         windputc(c);
  304. }
  305.  
  306. windputc(c)
  307. int c;
  308. {
  309.     mouseoff();
  310.     Cconout(c);
  311. }
  312.  
  313. windrefresh()
  314. {
  315. }
  316.  
  317. beep()
  318. {
  319.     Cconout('\007');
  320. }
  321.  
  322. windhigh()
  323. {
  324. }
  325.  
  326. windnorm()
  327. {
  328. }
  329.  
  330. /****************
  331.  * openls(), nextls(), and closels() are used to scan the current directory.
  332.  ***************/
  333.  
  334. char Dtabuff[44];
  335. long Origdta;
  336. int Atarifirst = 0;
  337.  
  338. char *
  339. openls()
  340. {
  341.     int n, c;
  342.  
  343.     Origdta = Fgetdta();
  344.     Fsetdta(Dtabuff);
  345.     Atarifirst = 1;
  346. }
  347. char *
  348. nextls()
  349. {
  350.     static char fname[17];
  351.     int n, c;
  352.  
  353.     if ( Atarifirst ) {
  354.         if ( Fsfirst("*.*",0x10) < 0 )
  355.             return(NULL);
  356.     }
  357.     else {
  358.         if ( Fsnext() < 0 )
  359.             return(NULL);
  360.     }
  361.     Atarifirst = 0;
  362.     for ( n=0; n<14; n++ ) {
  363.         c = fname[n] = Dtabuff[30+n];
  364.         /* ALL phrase names are lower case */
  365.         if ( c >= 'A' && c <= 'Z' )
  366.             fname[n] = c - 'A' + 'a';
  367.     }
  368.     fname[14] = '\0';
  369.     return(fname);
  370. }
  371. closels()
  372. {
  373.     Fsetdta((char *)Origdta);
  374. }
  375.  
  376.