v06i110: glib part 9 of 15

Brandon S. Allbery - comp.sources.misc allbery at uunet.UU.NET
Mon May 15 13:40:51 AEST 1989


Posting-number: Volume 6, Issue 110
Submitted-by: lee at uhccux.uhcc.Hawaii.Edu (Greg Lee )
Archive-name: glib/part09

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 9 (of 15)."
# Contents:  dx7.mnu mac-vt.c
# Wrapped by lee at uhccux on Sun May  7 00:40:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'dx7.mnu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dx7.mnu'\"
else
echo shar: Extracting \"'dx7.mnu'\" \(21054 characters\)
sed "s/^X//" >'dx7.mnu' <<'END_OF_FILE'
X/* $Id: dx7.mnu,v 1.6 89/05/06 17:13:22 lee Exp $
X * GLIB - a Generic LIBrarian and editor for synths
X *
X * DX-7 routines
X *
X * Scott Snyder - ssnyder at citromeo.bitnet, ssnyder at romeo.caltech.edu
X * $Log:	dx7.mnu,v $
X * Revision 1.6  89/05/06  17:13:22  lee
X * rel. to comp.sources.misc
X * 
X */
X
X#define VCED_SIZE 155
X
X#include "glib.h"
X#include <ctype.h>
X#include <math.h>
X
Xchar *visnum(), *visonoff(), *vism3num(), *viswave(), *vismono();
Xchar *visfreq(), *visdx1a(), *visr2num();
X
Xchar *visxq(), *visxx(), *vism7num(), *visx7note(), *visx7crv();
Xchar *visx7a(), *visx7wave(), *visx7brkpt();
X
Xchar *visxq1(), *visxq2(), *visxq3();
Xchar *visxq4(), *visxq5(), *visxq6();
Xchar *visxx1(), *visxx2(), *visxx3();
Xchar *visxx4(), *visxx5(), *visxx6();
X
X#define RESERVESIZE 0
X
X/* This array contains arbitrary screen labels */
Xstruct labelinfo Ldx7[] = {
X#MENU
X                      N: set name; q: quit; K: incr; J: decr; >: max; <: min  k
X                      space: play autonote Pitch  %   Vol   %                h l
X                                           Dur    %   Chan  %                 j
X
X    Atk  Sust1 Sust2  Rls        Fix/  Out De  Rat  Sens   Brk  Depth  Curve   
XOP Rt Lv Rt Lv Rt Lv Rt Lv  Freq Ratio Lvl tun Scl Key Mod Pt   L  R   L    R  
X-- -- -- -- -- -- -- -- -- ----- ----- --- --- --- --- --- ---- -- -- ---- ----
X 1 %  %  %  %  %  %  %  %  %     %      %   %   %   %   %  %    %  %  %    %   
X 2 %  %  %  %  %  %  %  %  %     %      %   %   %   %   %  %    %  %  %    %   
X 3 %  %  %  %  %  %  %  %  %     %      %   %   %   %   %  %    %  %  %    %   
X 4 %  %  %  %  %  %  %  %  %     %      %   %   %   %   %  %    %  %  %    %   
X 5 %  %  %  %  %  %  %  %  %     %      %   %   %   %   %  %    %  %  %    %   
X 6 %  %  %  %  %  %  %  %  %     %      %   %   %   %   %  %    %  %  %    %   
XPE %  %  %  %  %  %  %  %
X
XAlgorithm   %                    LFO Speed    %        Osc. Sync          @
X==============                   LFO Delay    %        Feedback           @
X                                 LFO AM Depth %        Middle C           @
X                                 LFO PM Depth %
X                                 LFO Wave     %
X                                 LFO Sync     %
X                                 LFO PM Sense %
X
X
X
X
X#END
X-1,-1,NULL
X};
X
X/* This array defines all the editable parameters. */
Xstruct paraminfo Pdx7[] = {
X"autopitch",	NULL, -1, -1, %%, visnum, 0, 127, 60, 0,
X"autovol",	NULL, -1, -1, %%, visnum, 0, 127, 63, 0,
X"autodur",	NULL, -1, -1, %%, visnum, 1,  20,  5, 0,
X"autochan",	NULL, -1, -1, %%, visnum, 1,  16,  1, 0,
X
X/*NAME		TYPE		POS	MAX	OFFSET	MASK	SHIFT	ADHOC*/
X#O op1atkrt	r2num		%%	99	85
X#O op1atklv	r2num		%%	99	89
X#O op1sust1rt	r2num		%%	99	86
X#O op1sust1lv	r2num		%%	99	90
X#O op1sust2rt	r2num		%%	99	87
X#O op1sust2lv	r2num		%%	99	91
X#O op1rlsrt	r2num		%%	99	88
X#O op1rlslv	r2num		%%	99	92
X#O op1freq	xq1		%%	4067	101			*3
X#O op1coarsefq	num		--	255	100	0x3E	1	*4
X#O op1fx	xx1		%%	1	100	0x01
X#O op1outlevel	num		%%	99	99
X#O op1detune	m7num		%%	14	97	0x78	3
X#O op1ratscl	num		%%	7	97	0x07
X#O op1tchsens	num		%%	7	98	0x1C	2
X#O op1modsens	num		%%	3	98	0x03
X#O op1brkpt	x7brkpt		%%	99	93
X#O op1ldepth	r2num		%%	99	94
X#O op1rdepth	r2num		%%	99	95
X#O op1lcurve	x7crv		%%	3	96	0x03
X#O op1rcurve	x7crv		%%	3	96	0x0C	2
X
X#O op2atkrt	r2num		%%	99	68
X#O op2atklv	r2num		%%	99	72
X#O op2sust1rt	r2num		%%	99	69
X#O op2sust1lv	r2num		%%	99	73
X#O op2sust2rt	r2num		%%	99	70
X#O op2sust2lv	r2num		%%	99	74
X#O op2rlsrt	r2num		%%	99	71
X#O op2rlslv	r2num		%%	99	75
X#O op2freq	xq2		%%	4067	84			*3
X#O op2coarsefq	num		--	255	83	0x3E	1	*4
X#O op2fx	xx2		%%	1	83	0x01
X#O op2outlevel	num		%%	99	82
X#O op2detune	m7num		%%	14	80	0x78	3
X#O op2ratscl	num		%%	7	80	0x07
X#O op2tchsens	num		%%	7	81	0x1C	2
X#O op2modsens	num		%%	3	81	0x03
X#O op2brkpt	x7brkpt		%%	99	76
X#O op2ldepth	r2num		%%	99	77
X#O op2rdepth	r2num		%%	99	78
X#O op2lcurve	x7crv		%%	3	79	0x03
X#O op2rcurve	x7crv		%%	3	79	0x0C	2
X
X#O op3atkrt	r2num		%%	99	51
X#O op3atklv	r2num		%%	99	55
X#O op3sust1rt	r2num		%%	99	52
X#O op3sust1lv	r2num		%%	99	56
X#O op3sust2rt	r2num		%%	99	53
X#O op3sust2lv	r2num		%%	99	57
X#O op3rlsrt	r2num		%%	99	54
X#O op3rlslv	r2num		%%	99	58
X#O op3freq	xq3		%%	4067	67			*3
X#O op3coarsefq	num		--	255	66	0x3E	1	*4
X#O op3fx	xx3		%%	1	66	0x01
X#O op3outlevel	num		%%	99	65
X#O op3detune	m7num		%%	14	63	0x78	3
X#O op3ratscl	num		%%	7	63	0x07
X#O op3tchsens	num		%%	7	64	0x1C	2
X#O op3modsens	num		%%	3	64	0x03
X#O op3brkpt	x7brkpt		%%	99	59
X#O op3ldepth	r2num		%%	99	60
X#O op3rdepth	r2num		%%	99	61
X#O op3lcurve	x7crv		%%	3	62	0x03
X#O op3rcurve	x7crv		%%	3	62	0x0C	2
X
X#O op4atkrt	r2num		%%	99	34
X#O op4atklv	r2num		%%	99	38
X#O op4sust1rt	r2num		%%	99	35
X#O op4sust1lv	r2num		%%	99	39
X#O op4sust2rt	r2num		%%	99	36
X#O op4sust2lv	r2num		%%	99	40
X#O op4rlsrt	r2num		%%	99	37
X#O op4rlslv	r2num		%%	99	41
X#O op4freq	xq4		%%	4067	50			*3
X#O op4coarsefq	num		--	255	49	0x3E	1	*4
X#O op4fx	xx4		%%	1	49	0x01
X#O op4outlevel	num		%%	99	48
X#O op4detune	m7num		%%	14	46	0x78	3
X#O op4ratscl	num		%%	7	46	0x07
X#O op4tchsens	num		%%	7	47	0x1C	2
X#O op4modsens	num		%%	3	47	0x03
X#O op4brkpt	x7brkpt		%%	99	42
X#O op4ldepth	r2num		%%	99	43
X#O op4rdepth	r2num		%%	99	44
X#O op4lcurve	x7crv		%%	3	45	0x03
X#O op4rcurve	x7crv		%%	3	45	0x0C	2
X
X#O op5atkrt	r2num		%%	99	17
X#O op5atklv	r2num		%%	99	21
X#O op5sust1rt	r2num		%%	99	18
X#O op5sust1lv	r2num		%%	99	22
X#O op5sust2rt	r2num		%%	99	19
X#O op5sust2lv	r2num		%%	99	23
X#O op5rlsrt	r2num		%%	99	20
X#O op5rlslv	r2num		%%	99	24
X#O op5freq	xq5		%%	4067	33			*3
X#O op5coarsefq	num		--	255	32	0x3E	1	*4
X#O op5fx	xx5		%%	1	32	0x01
X#O op5outlevel	num		%%	99	31
X#O op5detune	m7num		%%	14	29	0x78	3
X#O op5ratscl	num		%%	7	29	0x07
X#O op5tchsens	num		%%	7	30	0x1C	2
X#O op5modsens	num		%%	3	30	0x03
X#O op5brkpt	x7brkpt		%%	99	25
X#O op5ldepth	r2num		%%	99	26
X#O op5rdepth	r2num		%%	99	27
X#O op5lcurve	x7crv		%%	3	28	0x03
X#O op5rcurve	x7crv		%%	3	28	0x0C	2
X
X#O op6atkrt	r2num		%%	99	0
X#O op6atklv	r2num		%%	99	4
X#O op6sust1rt	r2num		%%	99	1
X#O op6sust1lv	r2num		%%	99	5
X#O op6sust2rt	r2num		%%	99	2
X#O op6sust2lv	r2num		%%	99	6
X#O op6rlsrt	r2num		%%	99	3
X#O op6rlslv	r2num		%%	99	7
X#O op6freq	xq6		%%	4067	16			*3
X#O op6coarsefq	num		--	255	15	0x3E	1	*4
X#O op6fx	xx6		%%	1	15	0x01
X#O op6outlevel	num		%%	99	14
X#O op6detune	m7num		%%	14	12	0x78	3
X#O op6ratscl	num		%%	7	12	0x07
X#O op6tchsens	num		%%	7	13	0x1C	2
X#O op6modsens	num		%%	3	13	0x03
X#O op6brkpt	x7brkpt		%%	99	8
X#O op6ldepth	r2num		%%	99	9
X#O op6rdepth	r2num		%%	99	10
X#O op6lcurve	x7crv		%%	3	11	0x03
X#O op6rcurve	x7crv		%%	3	11	0x0C	2
X
X#O pegatkrt	r2num		%%	99	102
X#O pegatklv	r2num		%%	99	106
X#O pegsust1rt	r2num		%%	99	103
X#O pegsust1lv	r2num		%%	99	107
X#O pegsust2rt	r2num		%%	99	104
X#O pegsust2lv	r2num		%%	99	108
X#O pegrlsrt	r2num		%%	99	105
X#O pegrlslv	r2num		%%	99	109
X
X#O algorithm	x7a		%%	31	110	0x1F
X
X#O lfospeed	num		%%	99	112
X#O lfodelay	num		%%	99	113
X#O lfoamdepth	num		%%	99	115
X#O lfopmdepth	num		%%	99	114
X#O lfowave	x7wave		%%	5	116	0x0E	1
X#O lfosync	onoff		%%	1	116	0x01
X#O lfopmsens	num		%%	7	116	0x70	4
X
X#O oscsync	onoff		@@	1	111	0x08	3
X#O feedback	num		@@	7	111	0x07
X#O transpose	x7note		@@	48	117
X
XNULL,	NULL, -1, -1, -1, -1, visnum, 0, 0, 0, 0
X};
X
X/*
X#ifdef __TURBOC__
X# pragma warn -par
X#endif
X*/
X
X#if !defined(TX81Z) && !defined(TX81ZPERF) && !defined(DX100)
X
X/* else these routines are in yama_com */
X
Xsetopval(n,str,v)
Xchar *str;
X{
X	char buff[32];
X	(void)sprintf(buff,"op%d%s",n,str);
X	setval(buff,v);
X}
X
X/* not used
Xgetopval(n,str)
Xchar *str;
X{
X	char buff[32];
X	(void)sprintf(buff,"op%d%s",n,str);
X	return(getval(buff));
X}
X*/
X
Xchar *
Xvismono(v)
X{
X	if ( v==0 )
X		return("poly");
X	else
X		return("mono");
X}
X
X#endif
X
Xchar *vism7num(v)
Xint v;
X{
X  static char Nbuff[16];
X
X  (void)sprintf(Nbuff, "%d", v-7);
X  return Nbuff;
X}
X
X/* 2-digit, right-justified */
Xchar *visr2num(v)
Xint v;
X{
X  static char Nbuff[16];
X
X  (void)sprintf(Nbuff, "%2d", v);
X  return Nbuff;
X}
X
Xchar *Dx7Notes[] =
X { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
X
Xchar *visx7note(v)
Xint v;
X{
X  int oct, tone;
X  char *p;
X  static char buf[8];
X
X  oct = floor((double)v / 12.0);
X  tone = v - oct*12;
X
X  strcpy(buf, Dx7Notes[tone]);
X  p = buf + (buf[1] == 0 ? 1 : 2);
X  (void)sprintf(p, "%d", oct+1);
X
X  return buf;
X}
X
Xchar *visx7brkpt(v)
Xint v;
X{
X  return visx7note(v - 15);
X}
X
Xchar *visx7crv(v)
Xint v;
X{
X  switch (v) {
X    case 0: return "-LIN";
X    case 1: return "-EXP";
X    case 2: return "+EXP";
X    case 3: return "+LIN";
X    default: return "???";
X  }
X}
X
Xchar *visx7wave(v)
Xint v;
X{
X  switch (v) {
X    case 0: return "Tri";
X    case 1: return "Saw Down";
X    case 2: return "Saw Up";
X    case 3: return "Square";
X    case 4: return "Sine";
X    case 5: return "S/Hold";
X    default: return "???";
X  }
X}
X
Xchar *visxqr(c, f)
Xint c, f;
X{
X  static char buf[8];
X  float freq;
X
X  freq = c;
X  if (c == 0) freq = 0.5;
X
X  freq += f * freq / 100;
X
X  (void)sprintf(buf, "%5.2f", freq);
X  return buf;
X}
X
Xint Dx7Freqs[] = {
X  1000, 1023, 1047, 1072, 1096, 1122, 1148, 1175, 1202, 1230,
X  1259, 1288, 1318, 1349, 1380, 1413, 1445, 1479, 1514, 1549,
X  1585, 1622, 1660, 1698, 1738, 1778, 1820, 1862, 1905, 1950,
X  1995, 2042, 2089, 2138, 2188, 2239, 2291, 2344, 2399, 2455,
X  2512, 2570, 2630, 2692, 2716, 2818, 2884, 2951, 3020, 3090,
X  3162, 3236, 3311, 3388, 3467, 3548, 3631, 3715, 3802, 3890,
X  3981, 4074, 4169, 4266, 4365, 4467, 4571, 4677, 4786, 4898,
X  5012, 5129, 5248, 5370, 5495, 5623, 5754, 5888, 6026, 6166,
X  6310, 6457, 6607, 6761, 6918, 7079, 7244, 7413, 7586, 7762,
X  7943, 8128, 8318, 8511, 8718, 8913, 9120, 9333, 9550, 9772,
X};
X
Xchar *visxqf(c, f)
Xint c, f;
X{
X  static char buf[8];
X  int i;
X
X  c %= 4;
X
X  (void)sprintf(buf, "%4d ", Dx7Freqs[f]);
X
X  if (c < 3) {
X    for (i=4; i>c; i--)
X      buf[i+1] = buf[i];
X    buf[c+1] = '.';
X  }
X
X  return buf;
X}
X
Xchar *visxq(v, op)
Xint v, op;
X{
X  char buff[8];
X  int c, f;
X
X  c = v / 128;
X  f = v % 128;
X
X  if (f > 99) {
X    if (f > 110) {
X      f = 99;
X    }
X    else {
X      c++;
X      f = 0;
X    }
X    setopval(op, "freq", c*128 + f);
X  }
X
X  (void)sprintf(buff, "op%dfx", op);
X  if (getval(buff) == 0)
X    return visxqr(c, f);
X  else
X    return visxqf(c, f);
X}
X
Xchar *visxx(v, op, s)   /* s == 1 for a DX7s */
Xint v, op, s;
X{
X  static int lastfx[] = { 0, -1, -1, -1, -1, -1, -1 };
X  char buff2[8];
X  int fqindex;
X
X  if ( lastfx[op] != -1 && lastfx[op] == v )
X    goto nochange;
X
X  lastfx[op] = v;
X  (void)sprintf(buff2,"op%dfreq",op);
X  fqindex = parmindex(buff2);
X  showparam(fqindex,0);
Xnochange:
X  if ( v == 0 )
X    return(s ? " R" : "Ratio");
X  else
X    return(s ? "Hz" : "Fixed");
X}
X
Xchar *visxx1(v) { return visxx(v, 1, 0); }
Xchar *visxx2(v) { return visxx(v, 2, 0); }
Xchar *visxx3(v) { return visxx(v, 3, 0); }
Xchar *visxx4(v) { return visxx(v, 4, 0); }
Xchar *visxx5(v) { return visxx(v, 5, 0); }
Xchar *visxx6(v) { return visxx(v, 6, 0); }
X
Xchar *visxq1(v) { return visxq(v, 1); }
Xchar *visxq2(v) { return visxq(v, 2); }
Xchar *visxq3(v) { return visxq(v, 3); }
Xchar *visxq4(v) { return visxq(v, 4); }
Xchar *visxq5(v) { return visxq(v, 5); }
Xchar *visxq6(v) { return visxq(v, 6); }
X
X/*
X  6+--5   6---5   3   6+   3   6+
X  ++  |       |   |   ++   |   ||
X  2   4   2+  4   2   5    2   5|   2   4   6+   2   4   6+
X  |   |   ++  |   |   |    |   ||   |   |   ++   |   |   ||
X  1   3   1   3   1   4    1   4|   1   3   5    1   3   5|
X  +-+-+   +-+-+   +-+-+    +-+-++   +---+---+    +---+---++
X    1       2       3        4          5            6
X
X          6+           6           6           3+           3
X          ++           |           |           ++           |
X  2   4   5    2  +4   5   2+  4   5   5   6   2    5   6+  2
X  |   |   |    |  ++   |   ++  |   |   |   |   |    |   ++  |
X  1   3---+    1   3---+   1   3---+   +---4   1    +---4   1
X  +-+-+        +-+-+       +-+-+           +-+-+        +-+-+
X    7            8           9               10           11
X
X                             5--+6+   5--+6      4  6+      4  6
X  4  5  6  2+   4  5  6+ 2      |++      ||      |  ++      |  |
X  |  |  |  ++   |  |  ++ |   2  +4    2+ +4   2  3  5    2+ 3  5
X  +--3--+  1    +--3--+  1   |   |    ++  |   |  |  |    ++ |  |
X     |     |       |     |   1   3    1   3   +--1--+    +--1--+
X     +--+--+       +--+--+   +-+-+    +-+-+      |          |
X        12            13       14       15       16         17
X
X      6---5   3
X          |   | 
X  2   3+  4   2  +6       3+  5-+ 6   3+      6   2      6+
X  |   ++  |   |  ++---+   ++--+ | |  ++++   +-++  |  +---++-+
X  +---1---+   1   4   5   1   2 +-4  1  2   4  5  1  3   4  5
X      |       +---+---+   +---+---+  +--+-+-+--+  +--+-+-+--+
X      18          19          20          21           22
X
X     3    6+         6+         6+      3   5  6+    3+  5  6+
X     |   ++++      +-+++        +++     |   |  ++    ++  |  ++
X  1  2   4  5  1 2 3 4 5  1 2 3 4 5  1  2   +--4  1  2   +--4
X  +--+-+-+--+  +-+-+-+-+  +-+-+-+-+  +--+-+-+--+  +--+-+-+--+
X       23          24         25          26           27
X
X      5+                          5+
X      ++                          ++
X  2   4             4  6+         4             6+
X  |   |             |  ++         |             ++
X  1   3   6  1  2   3  5   1  2   3  6  1 2 3 4 5   1 2 3 4 5 6+
X  +---+---+  +--+-+-+--+   +--+-+-+--+  +-+-+-+-+   +-+-+-+-+-++
X      28          29            30          31            32
X*/
X
Xchar *Dx7Algstr[] = {
X"1 ~3d~10l6~T~-~-5~n~[~]  ~|~n2   4~n~|   ~|~n1   3~n~[~-~T~-~]",
X"2 ~3d~10l6~-~-~-5~n    ~|~n2~}  4~n~>~]  ~|~n1   3~n~[~-~T~-~]",
X"3 ~3d~10l3   6~}~n~|   ~>~]~n2   5~n~|   ~|~n1   4~n~[~-~T~-~]",
X"4 ~3d~10l3   6~}~n~|   ~|~|~n2   5~|~n~|   ~|~|~n1   4~|~n~[~-~T~-~^~]",
X"5 ~5d~12l2   4   6~}~n~|   ~|   ~>~]~n1   3   5~n~[~3-~+~3-~]",
X"6 ~5d~12l2   4   6~}~n~|   ~|   ~|~|~n1   3   5~|~n~[~3-~+~3-~^~]",
X"7 ~3d~12l~8 6~}~n~8 ~>~]~n2   4   5~n~|   ~|   ~|~n1   3~3-~]~n~[~-~T~-~]",
X"8 ~3d~12l~8 6~n~8 ~|~n2  ~{4   5~n~|  ~[~<   ~|~n1   3~3-~]~n~[~-~T~-~]",
X"9 ~3d~12l~8 6~n~8 ~|~n2~}  4   5~n~>~]  ~|   ~|~n1   3~3-~]~n~[~-~T~-~]",
X"10~3d~12l~8 3~}~n~8 ~>~]~n5   6   2~n~|   ~|   ~|~n~[~3-4   1~n~4 ~[~-~T~-~]",
X"11~3d~12l~8 3~n~8 ~|~n5   6~}  2~n~|   ~>~]  ~|~n~[~3-4   1~n~4 ~[~-~T~-~]",
X"12~4d~13l4  5  6  2~}~n~|  ~|  ~|  ~>~]~n~[~2-3~2-~]  1~n   ~|~5 ~|~n   ~[~2-~T~2-~]",
X"13~4d~13l4  5  6~} 2~n~|  ~|  ~>~] ~|~n~[~2-3~2-~]  1~n   ~|~5 ~|~n   ~[~2-~T~2-~]",
X"14~3d~10l5~2-~}6~}~n   ~|~>~]~n2  ~[4~n~|   ~|~n1   3~n~[~-~T~-~]",
X"15~3d~10l5~2-~}6~n   ~|~|~n2~} ~[4~n~>~]  ~|~n1   3~n~[~-~T~-~]",
X"16~3d~11l   4  6~}~n   ~|  ~>~]~n2  3  5~n~|  ~|  ~|~n~[~2-1~2-~]~n   ~|",
X"17~3d~11l   4  6~n   ~|  ~|~n2~} 3  5~n~>~] ~|  ~|~n~[~2-1~2-~]~n   ~|",
X"18~3d~12l~4 6~3-5~n~8 ~|~n2   3~}  4~n~|   ~>~]  ~|~n~[~3-1~3-~]~n~4 ~|",
X"19~3d~12l3~n~|~n2  ~{6~n~|  ~[~+~3-~}~n1   4   5~n~[~3-~+~3-~]",
X"20~5d~12l3~}  5~-~} 6~n~>~^~2-~} ~| ~|~n1   2 ~[~-4~n~[~3-~+~3-~]",
X"21~5d~13l 3~}~6 6~n~{~^~^~}   ~{~-~^~}~n1  2   4  5~n~[~2-~^~-~T~-~^~2-~]",
X"22~5d~13l2~6 6~}~n~|  ~{~3-~+~^~-~}~n1  3   4  5~n~[~2-~^~-~T~-~^~2-~]",
X"23~5d~13l   3    6~}~n   ~|   ~{~^~^~}~n1  2   4  5~n~[~2-~^~-~T~-~^~2-~]",
X"24~5d~13l~6 6~}~n    ~{~-~+~^~}~n1 2 3 4 5~n~[~-~^~-~+~-~^~-~]",
X"25~5d~13l~6 6~}~n~6 ~>~^~}~n1 2 3 4 5~n~[~-~^~-~+~-~^~-~]",
X"26~5d~13l   3   5  6~}~n   ~|   ~|  ~>~]~n1  2   ~[~2-4~n~[~2-~^~-~T~4-~]",
X"27~5d~13l   3~}  5  6~}~n   ~>~]  ~|  ~>~]~n1  2   ~[~2-4~n~[~2-~^~-~T~4-~]",
X"28~3d~12l~4 5~}~n~4 ~>~]~n2   4~n~|   ~|~n1   3   6~n~[~3-~+~3-~]",
X"29~5d~13l~7 4  6~}~n~7 ~|  ~>~]~n1  2   3  5~n~[~2-~^~-~T~-~^~2-~]",
X"30~3d~13l~7 5~}~n~7 ~>~]~n~7 4~n~7 ~|~n1  2   3  6~n~[~2-~^~-~T~-~^~2-~]",
X"31~5d~12l~8 6~}~n~8 ~>~]~n1 2 3 4 5~n~[~-~^~-~+~-~^~-~]",
X"32~7d~13l1 2 3 4 5 6~}~n~[~-~^~-~^~-~+~-~^~-~^~]",
X};
X
Xchar *visx7a(v)
Xint v;
X{
X  if (v >= 0 && v < sizeof(Dx7Algstr)/sizeof(char *))
X    return(Dx7Algstr[v]);
X  else
X    return("????");
X}
X
Xdx7din(data)
Xchar *data;
X{
X#SETVAL
X}
X
Xdx7dout(data)
Xchar *data;
X{
X#GETVAL
X
X  Channel = getval("autochan");
X}
X
Xchar *dx7nof(data)
Xchar *data;
X{
X  static char buf[11];
X  char *p;
X  int i;
X
X  p = buf;
X  for (i=118; i<=127; i++)
X    *p++ = data[i];
X
X  *p = '\0';
X
X  return buf;
X}
X
Xdx7snof(data, name)
Xchar *data, *name;
X{
X  int i;
X
X  for (i=118; i<=127 && *name; i++)
X    data[i] = *name++;
X  for (; i<=127; i++)
X    data[i] = ' ';
X}
X
Xdx7vmemtovced(in, out)
Xchar *in, *out;
X{
X  int i;
X  char *opin, *opout;
X
X  for (i=0; i<6; i++) {
X    opin = in + (6-i-1)*17;
X    opout = out + (6-i-1)*21;
X
X    opout[ 0] = opin[ 0];		/* eg rate 1 */
X    opout[ 1] = opin[ 1];		/* eg rate 2 */
X    opout[ 2] = opin[ 2];		/* eg rate 3 */
X    opout[ 3] = opin[ 3];		/* eg rate 4 */
X    opout[ 4] = opin[ 4];		/* eg level 1 */
X    opout[ 5] = opin[ 5];		/* eg level 2 */
X    opout[ 6] = opin[ 6];		/* eg level 3 */
X    opout[ 7] = opin[ 7];		/* eg level 4 */
X    opout[ 8] = opin[ 8];		/* breakpoint */
X    opout[ 9] = opin[ 9];		/* l. depth */
X    opout[10] = opin[10];		/* r. depth */
X    opout[11] = opin[11] & 0x03;	/* l. curve */
X    opout[12] = (opin[11]>>2) & 0x03;	/* r. curve */
X    opout[13] = opin[12] & 0x07;	/* rate scaling */
X    opout[14] = opin[13] & 0x03;	/* mod. sens. */
X    opout[15] = (opin[13]>>2) & 0x07;	/* touch sens. */
X    opout[16] = opin[14];		/* total level */
X    opout[17] = opin[15] & 0x01;	/* freq. mode */
X    opout[18] = (opin[15]>>1) & 0x1f;	/* coarse freq. */
X    opout[19] = opin[16];		/* fine freq. */
X    opout[20] = (opin[12]>>3) & 0x0f;	/* detune */
X  }
X
X  out[126] = in[102];			/* peg rate 1 */
X  out[127] = in[103];			/* peg rate 2 */
X  out[128] = in[104];			/* peg rate 3 */
X  out[129] = in[105];			/* peg rate 4 */
X  out[130] = in[106];			/* peg level 1 */
X  out[131] = in[107];			/* peg level 2 */
X  out[132] = in[108];			/* peg level 3 */
X  out[133] = in[109];			/* peg level 4 */
X  out[134] = in[110] & 0x1f;		/* algorithm */
X  out[135] = in[111] & 0x07;		/* feedback */
X  out[136] = (in[111]>>3) & 0x01;	/* osc sync */
X  out[137] = in[112];			/* lfo speed */
X  out[138] = in[113];			/* lfo delay time */
X  out[139] = in[114];			/* pm depth */
X  out[140] = in[115];			/* am depth */
X  out[141] = in[116] & 0x01;		/* lfo key sync */
X  out[142] = (in[116]>>1) & 0x07;	/* lfo wave */
X  out[143] = (in[116]>>4) & 0x0f;	/* lfo pm sens */
X  out[144] = in[117];			/* transpose */
X
X  for (i=0; i<10; i++)
X    out[145+i] = in[118+i];		/* name */
X}
X
Xdx7send_bulk(format, length, data)
Xint format, length;
Xchar *data;
X{
X  int csum, i;
X
X  sendmidi(0xf0);
X  sendmidi(0x43);
X  sendmidi(Channel-1);
X  sendmidi(format);
X  sendmidi(length / 128);
X  sendmidi(length % 128);
X
X  csum = 0;
X  for (i=0; i<length; i++) {
X    sendmidi(data[i]);
X    csum += data[i];
X  }
X
X  sendmidi((-csum) & 0x7f);
X  sendmidi(EOX);
X
X  return 0;
X}
X
Xdx7svced(data)
Xchar *data;
X{
X  return dx7send_bulk(0, VCED_SIZE, data);
X}
X
Xdx7sedit(data)
Xchar *data;
X{
X  char edmem[VCED_SIZE];
X
X  dx7vmemtovced(data, edmem);
X  return dx7svced(edmem);
X}
X
Xdx7sbulk(data)
Xchar *data;
X{
X  return dx7send_bulk(9, 4096, data);
X}
X
Xdx7get_bulk(format, maxlength, data)
Xint format;
Xunsigned maxlength;
Xchar *data;
X{
X  int c, n, b1, b2, cksum, ret = 1;
X  unsigned len;
X  long begin, toolong;
X  static char ckbuff[80];
X
X  flushmidi();
X
X  begin = milliclock();
X  toolong = begin + 1000 * TIMEOUT;
X
X  sendmidi(0xf0);
X  sendmidi(0x43);
X  sendmidi(0x20 | (Channel-1) );	/* Channel # */
X  sendmidi(format);			/* 4 == 32 voice bulk dump */
X  sendmidi(EOX);			/* EOX */
X
X#ifdef BYTEBOARD
X/*
X# ifdef __TURBOC__
X#  pragma warn -rch
X# endif
X*/
X  if (midi_getsex(toolong) == NULL) return 1;
X#endif
X
X  /* wait for the x43 byte starting the dump */
X  c = 0;
X  while ( milliclock() < toolong ) {
X    if ( STATMIDI && (c=(getmidi() & 0xff)) == 0x43 )
X      break;
X  }
X  if ( c != 0x43 ) {
X    Reason = "Timeout waiting for 0x43";
X    goto getout;
X  }
X
X  (void)getmidi();		/* channel # */
X  c = getmidi();	/* format # */
X  if (c != format) {
X    (void)sprintf(ckbuff, "Synth sent format %d instead of %d", c, format);
X    Reason = ckbuff;
X    goto getout;
X  }
X  len = 128 * getmidi();	/* byte count high byte */
X  len += getmidi();		/* byte count low byte */
X  if (len > maxlength) {
X    Reason = "Synth sent more data than I was expecting";
X    goto getout;
X  }
X
X  cksum = 0;
X  /* 32 voices are dumped */
X  for (n=0; n<len; n++) {
X    /* twiddle your thumbs, but not forever */
Xanotherch:
X    while ( ! STATMIDI ) {
X      if ( milliclock() > toolong )
X        goto timeout;	/* the end of an era */
X    }
X    c = (getmidi() & 0xff);
X    /* Ignore non-data bytes ? */
X    if ( c & 0x80 )
X      goto anotherch;
X    /* compute checksum */
X    cksum += c;
X    data[n] = c;
X  }
Xtimeout:
X  if ( n < len ) {
X    Reason = "Timeout while reading!";
X    goto getout;
X  }
X  b1 = (getmidi() & 0xff);	/* Checksum */
X  b2 = (getmidi() & 0xff);	/* EOX */
X  cksum = (-cksum) & 0x7f;	/* convert to what we must match */
X  if ( b2 != EOX )
X    Reason = "EOX not received";
X  else if ( b1 != cksum ) {
X    (void)sprintf(ckbuff,"Checksum doesn't match (got %d expected %d)",b1,cksum);
X    Reason = ckbuff;
X  }
X  else {
X    Reason = "";
X    ret = 0;	/* all's well */
X  }
Xgetout:
X  return(ret);
X}
X
Xdx7gbulk(data)
Xchar *data;
X{
X  return dx7get_bulk(9, 4096, data);
X}
END_OF_FILE
if test 21054 -ne `wc -c <'dx7.mnu'`; then
    echo shar: \"'dx7.mnu'\" unpacked with wrong size!
fi
# end of 'dx7.mnu'
fi
if test -f 'mac-vt.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mac-vt.c'\"
else
echo shar: Extracting \"'mac-vt.c'\" \(19069 characters\)
sed "s/^X//" >'mac-vt.c' <<'END_OF_FILE'
X/* $Id: mac-vt.c,v 1.6 89/05/06 17:13:35 lee Exp $
X**
X** vt.c - a replacement dev:console driver for the Keynote musical expression
X**        language.
X**
X** Provides a cursor, constant-width characters, and (someday) all the escape
X** sequences for vt100 emulation.  The driver (handler) is installed at
X** run-time (for MPW 1.0) by doing the following call (before doing any I/O,
X** since that would auto-initialize the default system driver). 
X**
X** _addDevHandler(1, 'CONS', vt_faccess, vt_close, vt_read, vt_write, vt_ioctl);
X**
X** WARNING: this code assumes the MPW 1.0 development system.  It hooks itself
X** in as a device driver using the undocumented _addDevHandler call, which
X** may change in future releases of MPW.  It expects the system driver to be
X** in slot 1 - this also may change.
X**
X** If you are not using MPW, some or all of this driver may be unnecessary.
X** The vt_getch and vt_peekch functions probably ARE necessary and probably
X** work correctly under any development system.  They mainly provide the 
X** ability to stat the console to do non-blocking input.  They completely
X** avoid MPW's stdio (and all other libraries for that matter), although
X** the vt_read call provides an stdio interface if desired (blocking input
X** only, of course).  They DO assume that the mac has been initialized and
X** the event queue has been set up (InitGraf et.al.).
X**
X** The problem is printf.  If your development system has an acceptable
X** implementation (MPW *does NOT*), then just comment out the definition
X** of MPW in Keynote source file machdep.h and give 'er a try.  If, however,
X** you want to use my vt_putch or vt_write routines, you will have to figure
X** out how to hook them into your system. The only thing to beware of is to
X** call vt_open before using vt_putch.  This is done automatically via the
X** vt_faccess call for MPW 1.0.
X**
X** Steven A. Falco  4/30/87  moss!saf
X*/
X#include <types.h>
X#include <quickdraw.h>
X#include <toolutils.h>
X#include <fonts.h>
X#include <events.h>
X#include <windows.h>
X#include <dialogs.h>
X#include <menus.h>
X#include <desk.h>
X#include <textedit.h>
X#include <scrap.h>
X#include <segload.h>
X#include <resources.h>
X#include <osutils.h>
X#include <ioctl.h>
X#include <fcntl.h>
X#include "vt.h"
X#include <stdio.h>
X
X#define MAXROW		24
X#define MAXCOL		80
X#define TABVAL		8
X
X#define ENONE		0
X#define EFIRST		1
X#define EBRACKET	2
X
X/* note - the pixel location is based on the character baseline. */
X#define	XL(x)	((x) * vt_font.widMax + 4)	/* x offset from chars to pixels */
X#define	YL(y)	(((y) + 1) * vt_line - 2)  	/* y offset from chars to pixels */
X#define HOP		MoveTo(XL(vt_col), YL(vt_row)); GetPen(&vt_pen)
X
X/* BLANK(1,1) scrubs one cell.  (1,2) does a cell and the cell below it,
X * while (2,1) does a cell and the cell to the right of it.  etc.
X */
X#define BLANK(i, j) SetRect(&vt_one_char, vt_pen.h, vt_pen.v - vt_above, \
X				  vt_pen.h + (i) * vt_font.widMax, \
X				  vt_pen.v + vt_below + ((j) - 1) * vt_line); \
X				  EraseRect(&vt_one_char)
X				  
X#define CURSOR	SetRect(&vt_one_char, vt_pen.h, vt_pen.v - vt_above, \
X				  vt_pen.h + vt_font.widMax, vt_pen.v + vt_below); \
X				  PenMode(patXor); \
X				  PaintRect(&vt_one_char); \
X				  PenMode(patCopy)
X
X#define SAVE	vt_saverow = vt_row; vt_savecol = vt_col
X
X#define RESTORE	vt_row = vt_saverow; vt_col = vt_savecol
X
XWindowPtr	vt;
XFontInfo	vt_font;
Xint 		vt_line, vt_above, vt_below;
Xint			vt_col, vt_savecol;
Xint			vt_row, vt_saverow;
XRect		vt_one_char;
XRect		vt_rect;
XRect		screenRect;
XPoint		vt_pen;
Xint			vt_rawf;
Xint			vt_esc;
Xint			vt_inprog;		/* number in progress */
Xint			vt_x, vt_y;		/* for motion escape code */
X
Xstatic int	firsttime = 0;
Xstatic int	linesize = 0;
Xstatic char	*lineptr;
Xstatic char	linebuf[256];
X
X/* initialize the world.  We call this based on the "firsttime" flag - not an
X * every faccess call! - we only want to do it once...
X */
Xvt_open()
X{
X	char *vt_title;
X	int i;
X
X	InitGraf(&qd.thePort);
X	InitFonts();
X	FlushEvents(everyEvent, 0);
X	InitWindows();
X	InitMenus();
X	TEInit();
X	InitDialogs(nil);
X	InitCursor();
X	
X	vt_title = "";
X	screenRect = qd.screenBits.bounds;
X	SetRect(&vt_rect, 4, 20 + 4, screenRect.right - 4, screenRect.bottom - 4);
X	vt = NewWindow(nil, &vt_rect, vt_title, true, plainDBox, -1, false, 0);
X	SetPort(vt);
X	vt_rect.left -= 4; /* make vt_rect local - only used for scrolls hereafter */
X	vt_rect.right -= 4;
X	vt_rect.top -= (20 + 4);
X	vt_rect.bottom -= (20 + 4);
X	
X	TextFont(monaco); /* this driver only supports constant-width */
X	TextSize(9);
X	GetFontInfo(&vt_font);
X	PenMode(patCopy);
X	vt_line = vt_font.ascent + vt_font.descent + vt_font.leading;
X	vt_above = vt_font.ascent; /* dereference structure for efficiency */
X	vt_below = vt_font.descent;
X	vt_rawf = 0;			/* start out cooked */
X	vt_esc = ENONE;			/* no escape sequence yet */
X	
X	vt_row = vt_col = 0;	/* start out at home */
X	HOP;					/* actually move there */
X	CURSOR;					/* put up a cursor (XOR) */
X
X	return;
X}
X
X/* scroll the whole screen up one line-height */
Xvt_scroll()
X{
X	RgnHandle scroll_rgn;
X	
X	scroll_rgn = NewRgn();
X	ScrollRect(&vt_rect, 0, -vt_line, scroll_rgn);
X	DisposeRgn(scroll_rgn);
X	
X	return;
X}
X
X/* put a character on the screen.  Set state flags so we can process sequences
X * of characters (to do escape sequences.)
X * Assume we are sitting on the cursor and vt_pen is valid
X */
Xvt_putch(c)
X	int c;
X{
X	if(vt_esc > ENONE) { /* we are in the middle of an escape sequence */
X		escape_code(c);
X	} else if(c >= ' ' && c <= '~') {	/* it is printable */
X		printable_code(c);
X	} else {					/* it is control */
X		control_code(c);
X	}
X	
X	return;
X}
X
X/* it is a simple character */
Xprintable_code(c)
X	int c;
X{
X	BLANK(1, 1);			/* take away the cursor */
X	DrawChar(c);			/* paint in the character */
X	if(++vt_col >= MAXCOL) {	/* time to auto-linefeed */
X		vt_col = 0;
X		if(++vt_row >= MAXROW) {/* scroll it */
X			vt_row = MAXROW - 1; /* not so far please... */
X			vt_scroll();
X		}
X	}
X	HOP;					/* move to the cell */
X	CURSOR;					/* paint in the cursor */
X	
X	return;
X}
X
X/* process a control code - all are exactly 1 character in length */
Xcontrol_code(c)
X	int c;
X{
X	int i, j;
X	
X	switch(c) {
X	  case '\007':			/* bell */
X		SysBeep(20);		/* beep for 20/60 seconds */
X		break;
X	  case '\010':			/* backspace */
X		if(vt_col > 0) {	/* can't backspace past left margin */
X			CURSOR;			/* exor it again to remove */
X			vt_col--;
X			HOP;			/* jump back one */
X			CURSOR;			/* and a new cursor */
X		} else {
X			SysBeep(20);	/* be a pain */
X		}
X		break;
X	  case '\011':			/* tab */
X		j = vt_col;			/* stack this for re-entrancy */
X		for(i = 0; i < (TABVAL - (j % TABVAL)); i++) {
X			vt_putch(' ');	/* just do some spaces */
X		}
X		break;
X	  case '\012':			/* line feed */
X		CURSOR;				/* kill the old cursor */
X		if(!vt_rawf) {		/* do both cr and lf */
X			vt_col = 0;		/* the cr part is easy */
X		}
X		if(++vt_row >= MAXROW) {/* scroll it */
X			vt_row = MAXROW - 1; /* not so far please... */
X			vt_scroll();
X		}
X		HOP;
X		CURSOR;
X		break;
X	  case '\015':			/* carriage return */
X		CURSOR;				/* kill the old cursor */
X		vt_col = 0;			/* the cr part is easy */
X		if(!vt_rawf) {		/* do both cr and lf */
X			if(++vt_row >= MAXROW) {/* scroll it */
X				vt_row = MAXROW - 1; /* not so far please... */
X				vt_scroll();
X			}
X		}
X		HOP;
X		CURSOR;
X		break;
X	  case '\033':			/* escape */
X		vt_esc = EFIRST;		/* ok - start an escape sequence */
X		break;
X	  /* the ones we don't handle come next */
X	  case '\013':			/* vertical tab */
X	  case '\014':			/* form feed */
X	  default:
X		break;
X	} /* end of switch */
X	
X	return;
X}
X
Xescape_code(c)
X	int c;
X{
X	switch(vt_esc) {
X	  case EFIRST:
X	    switch(c) {
X		  case '[':
X		  	vt_esc = EBRACKET; /* remember we saw it */
X			vt_inprog = vt_x = vt_y = 0; /* clear these */
X		  	break;
X			
X		  default:
X		  	vt_esc = ENONE; /* blew it */
X		  	break;
X		}
X		break;
X	  
X	  case EBRACKET:
X		switch(c) {
X		  case 'H': /* home (or motion) */
X		  	vt_x = vt_inprog; /* column number */
X			vt_inprog = 0;
X			/* adjust for brain damaged notion of screen starting at (1,1) */
X			if(--vt_x < 0) {
X				vt_x = 0;
X			}
X			if(--vt_y < 0) {
X				vt_y = 0;
X			}
X			CURSOR; /* take it away */
X			vt_row = vt_y;
X			vt_col = vt_x;
X			HOP;
X			CURSOR;
X			vt_esc = ENONE; /* code is complete */
X			break;
X			
X		  case 'J': /* clear to end of screen */
X		  	if(vt_row + 1 < MAXROW) { /* something below us */
X				SAVE;
X				vt_row++; 	/* drop down a row */
X				vt_col = 0;	/* and over to the beginning */
X				HOP;		/* actually move there */
X				BLANK(MAXCOL, MAXROW - vt_row);
X				RESTORE;
X				HOP;
X			}
X		  	/* fall through to clear the fractional part */
X		  case 'K': /* clear to end of line */
X		  	BLANK(MAXCOL - vt_col, 1); /* erase all on the row */
X			CURSOR;	/* replace the cursor */
X			vt_esc = ENONE;
X		  	break;
X		  
X		  case '0': /* a row or column number */
X		  case '1':
X		  case '2':
X		  case '3':
X		  case '4':
X		  case '5':
X		  case '6':
X		  case '7':
X		  case '8':
X		  case '9':
X		  	vt_inprog *= 10; 		/* make room */
X			vt_inprog += c - '0';	/* add in the new digit */
X		  	break;
X			
X		  case ';': /* end of row number */
X		  	vt_y = vt_inprog;
X			vt_inprog = 0;
X		  	break;
X			
X		  default:
X		  	vt_esc = ENONE; /* blew it */
X		  	break;
X		}
X		break;
X		
X	  default:
X	  	vt_esc = ENONE; /* blew it */
X	  	break;
X	}
X	
X	return;
X}
X
X/* low level reader - call this directly if you also want to use peek - that
X * way you get raw-mode and avoid all character buffers.  But note - this code
X * does NOT initialize the world first.  You must call vt_open() manually!
X */
Xvt_getch()
X{
X	EventRecord x;
X	int rc;
X	
X	SystemTask();
X	
X	/* GetNextEvent returns a boolean enum - make it an integer */
X	while(GetNextEvent(autoKeyMask | keyDownMask, &x) == false) {
X		SystemTask(); /* wait for it */
X	}
X	rc = x.message & 0xff;
X	if(x.modifiers & cmdKey) {	/* it is a control character */
X		rc &= 0x1f;				/* so fold it */
X	}
X	if(!vt_rawf && rc == '\004') { /* cooked mode and a ^D spells EOF */
X		return(EOF);
X	}
X	return(rc);
X}
X
X/* return a character but don't pull it off the queue!  Don't block if nothing is
X * available - just return a null.
X */
Xvt_peekch()
X{
X	EventRecord x;
X	int rc;
X	
X	SystemTask();
X	
X	/* EventAvail returns a boolean enum - make it an integer */
X	if(EventAvail(autoKeyMask | keyDownMask, &x) == true) { /* something */
X		rc = x.message & 0xff;
X		if(x.modifiers & cmdKey) {	/* it is a control character */
X			rc &= 0x1f;				/* so fold it */
X		}
X		if(!vt_rawf && rc == '\004') { /* cooked mode and a ^D spells EOF */
X			return(EOF);
X		} else {	/* normal character */
X			return(rc);
X		}
X		/*NOTREACHED*/
X	} else {
X		return(0);	/* nothing - call it a null */
X	}
X	/*NOTREACHED*/
X}
X
X/* handle system requests for open, rename, and delete.  Only open is legal.
X */
Xvt_faccess(fname, mode, perm)
X	char *fname;
X	int mode;
X	int perm;
X{
X	/* if we are not the correct driver, return and let the system try
X	 * another driver.
X	 */
X	if(EqualString(fname, "dev:console", false, true) == false) {
X		return(-1);
X	}
X	
X	/* this driver only handles opens */
X	if(mode == F_OPEN) {
X		if(firsttime == 0) { /* only do it once */
X			vt_open();
X			firsttime++;
X		}
X		return(0); /* but always claim success */
X	}
X	
X	/* tell them the request is bogus */
X	return(0x40000016);
X}
X
X/* not much to do */
Xvt_close()
X{
X	return(0);
X}
X
X/* return as many characters as asked for, up to a carriage return.  Someday
X * we need to add raw mode here.
X */
Xvt_read(ap)
X	IOSTR *ap;
X{
X	/* fill the buffer if it is empty */
X	if(linesize <= 0) {
X		linesize = vt_readline(linebuf, 256);
X		lineptr = linebuf;
X	}
X	
X	/* copy till either user is satisfied or we hit the end of the line.
X	 * We must leave the count field set in the ap structure to show how
X	 * much more is to be done.
X	 */
X	for( ; (ap->count > 0) && (linesize > 0); ap->count--, linesize--) {
X		*(ap->buffer)++ = *lineptr++;
X	}
X	
X	return(0);
X}
X
X/* read until a carriage return (or we fill the buffer). Return how much we
X * got.
X */
Xvt_readline(bp, size)
X	char *bp;
X	int size;
X{
X	int i;
X	
X	for(i = size; i; bp++, i--) {
X		*bp = vt_getch();
X		
X		if(*bp == '\010' && i < size) {
X			bp -= 2;
X			i += 2;
X		}
X		
X		if(*bp == '\004' || *bp == '\n') {
X			i--;
X			break;
X		}
X	}
X	
X	return(size - i);
X}
X
X/* loop characters to the screen */
Xvt_write(ap)
X	IOSTR *ap;
X{
X	for( ; ap->count; ap->count--) { /* must leave count at 0 on exit */
X		vt_putch(*(ap->buffer)++);
X	}
X	
X	return(0);
X}
X
X/* this routine turns out to be essential because the system intends to ask us
X * for the optimum buffer size.  We return -1 to tell it to choose for us.
X */
Xvt_ioctl(fd, op, arg)
X	int fd;
X	int op;
X	int *arg;
X{
X	switch(op) {
X	  case FIOINTERACTIVE:
X	  	return(0);
X		
X	  case TIOFLUSH:
X	  	return(0);
X		
X	  /* I don't trust this!  We would have to clear screen and reset
X	   * point sizes for it to be safe.
X	   */
X	  case TIOSPORT:
X	  	/* vt = (WindowPtr) *arg; */
X	  	return(0);
X		
X	  case TIOGPORT:
X	  	*arg = (int) vt;
X		return(0);
X		
X	  default:
X	  	return(-1);
X	}
X	/*NOTREACHED*/
X}
X
X/* this stuff should be via ioctl but why make it so hard? */
Xvt_raw()
X{
X	vt_rawf = 1;
X	
X	return;
X}
X
Xvt_cooked()
X{
X	vt_rawf = 0;
X	
X	return;
X}
X
X/* this code is a reverse compile of the cruntime.o module. */
X/*
Xwrite(fd, buf, cnt)
X	int fd;
X	char *buf;
X	int cnt;
X{
X	IOSTR *ind;
X	int foo;
X	
X	if(fd < 0) {
X		_uerror(0x16, 0);
X		return(-1);
X	}
X	
X	ind = _getIOPort(&fd);
X	
X	if(!ind) {
X		return(-1);
X	}
X	
X	if(!(ind->flags & 2)) {
X		_uerror(0x09, 0);
X		return(-1);
X	}
X	
X	ind->count = cnt;
X	ind->buffer = buf;
X	foo = (*(ind->handler->l_write))(ind);
X	
X	if(foo) {
X		_uerror(foo, ind->errcode);
X		return(-1);
X	} else {
X		return(cnt - (ind->count));
X	}
X}
X*/
X
X/* this bypasses printf and is useful for debugging to avoid recursion.
X * Prints a string.
X */
X/*
Xlpr(s)
X	char *s;
X{
X	while(*s != 0) {
X		vt_putch(*s++);
X	}
X	
X	return;
X}
X*/
X
X/* this one prints an integer in hex with leading zeros. */
X/*
Xlpx(x)
X	unsigned int x;
X{
X	int i, j;
X	
X	for(i = 0; i < 8; i++) {
X		j = (x >> (28 - (i * 4))) & 0xf;
X		if(j <= 9) {
X			vt_putch(j + '0');
X		} else {
X			vt_putch(j - 10 + 'a');
X		}
X	}
X	
X	return;
X}
X*/
X
X/* Start of code for da support.  We use these for a gp text editor among
X * other things.  Note - there is no way to pass the file name in.  Oh
X * well.  Most of this code is stolen from the sample application which
X * Apple distributes with MPW and hence is copyright Apple Computer Corp.
X */
X
X/*
X * Resource ID constants.
X */
X# define appleID		128
X# define fileID 		129
X# define editID 		130
X
X# define appleMenu		0
X
X# define fileMenu		1
X# define	quitCommand 	1
X
X# define editMenu		2
X# define	undoCommand 	1
X# define	cutCommand		3
X# define	copyCommand 	4
X# define	pasteCommand	5
X# define	clearCommand	6
X
X# define menuCount	 3
X
X/*
X * HIWORD and LOWORD macros, for readability.
X */
X# define HIWORD(aLong)		(((aLong) >> 16) & 0xFFFF)
X# define LOWORD(aLong)		((aLong) & 0xFFFF)
X
X/*
X * Global Data objects, used by routines external to main().
X */
XMenuHandle		MyMenus[menuCount]; 	/* The menu handles */
Xint				Doneflag;				/* Becomes TRUE when File/Quit chosen */
X
Xda_mode(fname)
X	char *fname;
X{
X	EventRecord 	myEvent;
X	WindowPtr		theActiveWindow, whichWindow;
X	GrafPtr 		savePort;
X	char			forcedDA[256];
X
X	setupMenus();
X
X	for (Doneflag = 0; !Doneflag; ) {
X		/*
X		 * Main Event tasks:
X		 */
X		SystemTask();
X		
X		/* if a name was passed in, assume it is a DA - we fake an open
X		 * of it.  DA's are funny in that the name contains a leading
X		 * NULL character.  So we stick one in 'cause they are hard to
X		 * type.  This results in a bizzare C string but the Desk Manager
X		 * is happy...
X		 */
X		if(fname[0] != '\0') {
X			forcedDA[0] = '\0'; /* DA names (usually) have this */
X			strcpy(forcedDA + 1, fname); /* don't step on the null */
X			fname[0] = '\0'; 	/* open it only once */
X			GetPort(&savePort);
X			(void) OpenDeskAcc(forcedDA);
X			SetPort(savePort);
X			continue;
X		}
X				
X		theActiveWindow = FrontWindow();		/* Used often, avoid repeated calls */
X		/*
X		 * Handle the next event.
X		 */
X		if ( ! GetNextEvent(everyEvent, &myEvent)) {
X			continue;	/* not for us */
X		}
X		/*
X		 * In the unlikely case that the active desk accessory does not
X		 * handle mouseDown, keyDown, or other events, GetNextEvent() will
X		 * give them to us!  So before we perform actions on some events,
X		 * we check to see that the affected window in question is really
X		 * our window.
X		 */
X		switch (myEvent.what) {
X			case mouseDown:
X				switch (FindWindow(&myEvent.where, &whichWindow)) {
X					case inSysWindow:
X						SystemClick(&myEvent, whichWindow);
X						break;
X					case inMenuBar:
X						doCommand(MenuSelect(&myEvent.where));
X						break;
X					case inDrag:
X					case inGrow:
X						/* No such - Fall through */
X					case inContent:
X						if (whichWindow != theActiveWindow) {
X							SelectWindow(whichWindow);
X						}
X						break;
X					default:
X						break;
X				}/*endsw FindWindow*/
X				break;
X
X			case keyDown:
X			case autoKey:
X				if (vt == theActiveWindow) {
X					if (myEvent.modifiers & cmdKey) {
X						doCommand(MenuKey(myEvent.message & charCodeMask));
X					}
X				}
X				break;
X
X			case activateEvt:
X				if ((WindowPtr) myEvent.message == vt) {
X					if (myEvent.modifiers & activeFlag) {
X						DisableItem(MyMenus[editMenu], 0);
X					} else {
X						EnableItem(MyMenus[editMenu], 0);
X					}
X					DrawMenuBar();
X				}
X				break;
X
X			default:
X				break;
X
X		}/*endsw myEvent.what*/
X
X	}/*endfor Main Event loop*/
X
X	trashMenus();
X	return;
X}
X
XsetupMenus()
X{
X	register MenuHandle *pMenu;
X	/*
X	 * Set up the desk accessories menu.
X	 *  We install the desk accessory names from the 'DRVR' resources.
X	 */
X	MyMenus[appleMenu] = GetMenu(appleID);
X	AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
X	/*
X	 * Now the File and Edit menus.
X	 */
X	MyMenus[fileMenu] = GetMenu(fileID);
X	MyMenus[editMenu] = GetMenu(editID);
X	/*
X	 * Now insert all of the application menus in the menu bar.
X	 *
X	 * "Real" C programmers never use array indexes
X	 * unless they're constants :-)
X	 */
X	for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
X		InsertMenu(*pMenu, 0);
X	}
X	DisableItem(MyMenus[editMenu], 0);
X
X	DrawMenuBar();
X
X	return;
X}
X
XtrashMenus()
X{
X	ClearMenuBar();		/* remove menus */
X	DrawMenuBar();		/* show it */
X	
X	ReleaseResource(MyMenus[appleMenu]);
X	ReleaseResource(MyMenus[fileMenu]);
X	ReleaseResource(MyMenus[editMenu]);
X
X	return;
X}
X
X/*
X * Process mouse clicks in menu bar
X */
XdoCommand(mResult)
Xlong mResult;
X{	
X	int 				theMenu, theItem;
X	char				daName[256];
X	GrafPtr 			savePort;
X
X	theItem = LOWORD(mResult);
X	theMenu = HIWORD(mResult);		/* This is the resource ID */
X
X	switch (theMenu) {
X		case appleID:
X			GetItem(MyMenus[appleMenu], theItem, daName);
X			GetPort(&savePort);
X			(void) OpenDeskAcc(daName);
X			SetPort(savePort);
X			break;
X
X		case fileID:
X			switch (theItem) {
X				case quitCommand:
X					Doneflag++;			/* Request exit */
X					break;
X				default:
X					break;
X			}
X			break;
X		case editID:
X			/*
X			 * If this is for a 'standard' edit item,
X			 * run it through SystemEdit.
X			 */
X			if (theItem <= clearCommand) {
X				SystemEdit(theItem-1);
X			}
X			break;
X
X		default:
X			break;
X
X	}/*endsw theMenu*/
X
X	HiliteMenu(0);
X
X	return;
X}
END_OF_FILE
if test 19069 -ne `wc -c <'mac-vt.c'`; then
    echo shar: \"'mac-vt.c'\" unpacked with wrong size!
fi
# end of 'mac-vt.c'
fi
echo shar: End of archive 9 \(of 15\).
cp /dev/null ark9isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 15 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Comp.sources.misc mailing list