| 1 | /*
 | 
|---|
| 2 |    =============================================================================
 | 
|---|
| 3 |         wdselbx.c -- waveshape editor box selection functions
 | 
|---|
| 4 |         Version 27 -- 1988-09-15 -- D.N. Lynx Crowe
 | 
|---|
| 5 |    =============================================================================
 | 
|---|
| 6 | */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #define DEBUGIT         0
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "stddefs.h"
 | 
|---|
| 11 | #include "fields.h"
 | 
|---|
| 12 | #include "vsdd.h"
 | 
|---|
| 13 | #include "graphdef.h"
 | 
|---|
| 14 | #include "hwdefs.h"
 | 
|---|
| 15 | #include "fpu.h"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include "midas.h"
 | 
|---|
| 18 | #include "instdsp.h"
 | 
|---|
| 19 | #include "wsdsp.h"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "memory.h"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | extern  int16_t entbh(int16_t n);
 | 
|---|
| 24 | extern  void    wdswin(int16_t n);
 | 
|---|
| 25 | 
 | 
|---|
| 26 | extern  int16_t curvce, curwdth, cursbox, hitbox, cxval, cyval, hitcx, hitcy;
 | 
|---|
| 27 | extern  int16_t curwave, curwfnl, curwpnt, curwoff, curwhrm, curwhrv, curwslt;
 | 
|---|
| 28 | extern  int16_t wdupdfl, wpntsv, wplast, wvlast, lstwoff, lstwpnt;
 | 
|---|
| 29 | 
 | 
|---|
| 30 | extern  int16_t offsets[NUMWPCAL];
 | 
|---|
| 31 | extern  int16_t vmtab[NUMHARM];
 | 
|---|
| 32 | extern  int16_t wsbuf[NUMWPCAL];
 | 
|---|
| 33 | 
 | 
|---|
| 34 | extern  int32_t vknm[NUMHARM][NUMWPCAL];
 | 
|---|
| 35 | 
 | 
|---|
| 36 | extern  int16_t wdbox[][8];
 | 
|---|
| 37 | 
 | 
|---|
| 38 | extern  int16_t wsnmod[12][2];
 | 
|---|
| 39 | 
 | 
|---|
| 40 | extern  int16_t crate1[], crate2[], *cratex, *cratey;
 | 
|---|
| 41 | 
 | 
|---|
| 42 | extern  struct  selbox  *csbp, *curboxp;
 | 
|---|
| 43 | 
 | 
|---|
| 44 | extern  struct  instdef vbufs[];
 | 
|---|
| 45 | 
 | 
|---|
| 46 | extern  struct  wstbl   wslib[];
 | 
|---|
| 47 | 
 | 
|---|
| 48 | /* forward references */
 | 
|---|
| 49 | 
 | 
|---|
| 50 | int16_t bx_null(void);
 | 
|---|
| 51 | int16_t wdfnbox(int16_t n);
 | 
|---|
| 52 | 
 | 
|---|
| 53 | extern  int16_t gcurpos(int16_t xloc, int16_t yloc);
 | 
|---|
| 54 | extern  void arcurs(uint16_t icolor);
 | 
|---|
| 55 | extern  void settc(int16_t rv, int16_t cv);
 | 
|---|
| 56 | extern  void updfpu(void);
 | 
|---|
| 57 | extern  void wadj(void);
 | 
|---|
| 58 | 
 | 
|---|
| 59 | /*  | 
|---|
| 60 | 
 | 
|---|
| 61 | */
 | 
|---|
| 62 | 
 | 
|---|
| 63 | struct  selbox  wdboxes[] = {
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         {  1,   1, 510, 307,      0, wdfnbox},  /*  0 */
 | 
|---|
| 66 |         {  1, 308, 510, 320,      1, wdfnbox},  /*  1 */
 | 
|---|
| 67 |         {  1, 322, 174, 348,      2, entbh},    /*  2 */
 | 
|---|
| 68 |         {176, 322, 230, 348,      3, wdfnbox},  /*  3 */
 | 
|---|
| 69 |         {232, 322, 398, 348,      4, entbh},    /*  4 */
 | 
|---|
| 70 |         {400, 322, 510, 348,      5, entbh},    /*  5 */
 | 
|---|
| 71 | 
 | 
|---|
| 72 |         {  0,   0,   0,   0,      0, FN_NULL}           /* end of table */
 | 
|---|
| 73 | };
 | 
|---|
| 74 | 
 | 
|---|
| 75 | /*
 | 
|---|
| 76 |    =============================================================================
 | 
|---|
| 77 |         dsnewws() -- display a new waveshape
 | 
|---|
| 78 |    =============================================================================
 | 
|---|
| 79 | */
 | 
|---|
| 80 | 
 | 
|---|
| 81 | void dsnewws(void)
 | 
|---|
| 82 | {
 | 
|---|
| 83 |         wdswin(0);
 | 
|---|
| 84 |         wdswin(2);
 | 
|---|
| 85 |         wdswin(4);
 | 
|---|
| 86 |         wdswin(5);
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | /*  | 
|---|
| 90 | 
 | 
|---|
| 91 | */
 | 
|---|
| 92 | 
 | 
|---|
| 93 | /*
 | 
|---|
| 94 |    =============================================================================
 | 
|---|
| 95 |         newws() -- setup editing for a new waveshape
 | 
|---|
| 96 |    =============================================================================
 | 
|---|
| 97 | */
 | 
|---|
| 98 | 
 | 
|---|
| 99 | void newws(void)
 | 
|---|
| 100 | {
 | 
|---|
| 101 |         register int16_t i;
 | 
|---|
| 102 |         register struct instdef *ip;
 | 
|---|
| 103 | 
 | 
|---|
| 104 |         ip = &vbufs[curvce];
 | 
|---|
| 105 | 
 | 
|---|
| 106 |         if (curwslt) {
 | 
|---|
| 107 | 
 | 
|---|
| 108 |                 for (i = 0; i < NUMWPNT; i++) {
 | 
|---|
| 109 | 
 | 
|---|
| 110 |                         offsets[i + 1] = ip->idhwvbo[i] >> 5;
 | 
|---|
| 111 |                         wsbuf[i + 1]   = ip->idhwvbf[i] >> 5;
 | 
|---|
| 112 |                 }
 | 
|---|
| 113 | 
 | 
|---|
| 114 |                 memcpyw(vmtab, ip->idhwvbh, NUMHARM);
 | 
|---|
| 115 | 
 | 
|---|
| 116 |         } else {
 | 
|---|
| 117 | 
 | 
|---|
| 118 |                 for (i = 0; i < NUMWPNT; i++) {
 | 
|---|
| 119 | 
 | 
|---|
| 120 |                         offsets[i + 1] = ip->idhwvao[i] >> 5;
 | 
|---|
| 121 |                         wsbuf[i + 1]   = ip->idhwvaf[i] >> 5;
 | 
|---|
| 122 |                 }
 | 
|---|
| 123 | 
 | 
|---|
| 124 |                 memcpyw(vmtab, ip->idhwvah, NUMHARM);
 | 
|---|
| 125 |         }
 | 
|---|
| 126 | 
 | 
|---|
| 127 |         offsets[0] = offsets[1];
 | 
|---|
| 128 |         wsbuf[0]   = wsbuf[1];
 | 
|---|
| 129 | 
 | 
|---|
| 130 |         curwhrv = vmtab[curwhrm];
 | 
|---|
| 131 |         lstwoff = wvlast = curwoff = offsets[1 + curwpnt];
 | 
|---|
| 132 |         curwfnl = wsbuf[curwpnt + 1];
 | 
|---|
| 133 |         lstwpnt = wplast = curwpnt;
 | 
|---|
| 134 | 
 | 
|---|
| 135 |         memsetw(vknm, 0, (NUMHARM * NUMWPCAL) << 1);
 | 
|---|
| 136 |         wadj();
 | 
|---|
| 137 | }
 | 
|---|
| 138 | 
 | 
|---|
| 139 | /*  | 
|---|
| 140 | 
 | 
|---|
| 141 | */
 | 
|---|
| 142 | 
 | 
|---|
| 143 | /*
 | 
|---|
| 144 |    =============================================================================
 | 
|---|
| 145 |         wdfnbox() -- waveshape display box hit processor
 | 
|---|
| 146 |    =============================================================================
 | 
|---|
| 147 | */
 | 
|---|
| 148 | 
 | 
|---|
| 149 | int16_t wdfnbox(int16_t n)
 | 
|---|
| 150 | {
 | 
|---|
| 151 |         register int16_t wval;
 | 
|---|
| 152 |         register int8_t wsgn;
 | 
|---|
| 153 |         register int16_t *fpuws;
 | 
|---|
| 154 | 
 | 
|---|
| 155 |         switch (n) {    /* switch off of window ID */
 | 
|---|
| 156 | 
 | 
|---|
| 157 |         case 0:         /* process a hit in the main window */
 | 
|---|
| 158 | 
 | 
|---|
| 159 |                 switch (wpntsv) {
 | 
|---|
| 160 | 
 | 
|---|
| 161 |                 case 0:         /* nothing selected so far:  select a point */
 | 
|---|
| 162 | 
 | 
|---|
| 163 |                         wpntsv = 1;
 | 
|---|
| 164 |                         curwpnt = (cxval - 2) / 2;
 | 
|---|
| 165 | 
 | 
|---|
| 166 |                         if (curwpnt GE NUMWPNT)
 | 
|---|
| 167 |                                 curwpnt = NUMWPNT - 1;
 | 
|---|
| 168 |                         else if (curwpnt < 0)
 | 
|---|
| 169 |                                 curwpnt = 0;
 | 
|---|
| 170 | 
 | 
|---|
| 171 |                         cratex = crate2;
 | 
|---|
| 172 |                         cratey = crate2;
 | 
|---|
| 173 |                         newws();
 | 
|---|
| 174 |                         cyval = WPOFF - ((curwoff * WPSF1) / WPSF2);
 | 
|---|
| 175 |                         cxval = (curwpnt << 1) + 2;
 | 
|---|
| 176 |                         arcurs(WS_GRAB);
 | 
|---|
| 177 |                         gcurpos(cxval, cyval);
 | 
|---|
| 178 |                         wplast = curwpnt;
 | 
|---|
| 179 |                         wvlast = curwoff;
 | 
|---|
| 180 |                         wdswin(4);
 | 
|---|
| 181 |                         break;
 | 
|---|
| 182 | /*  | 
|---|
| 183 | 
 | 
|---|
| 184 | */
 | 
|---|
| 185 |                 case 1:         /* point was selected:  unselect it */
 | 
|---|
| 186 | 
 | 
|---|
| 187 |                         wpntsv = 0;
 | 
|---|
| 188 |                         cratex = crate1;
 | 
|---|
| 189 |                         cratey = crate1;
 | 
|---|
| 190 | 
 | 
|---|
| 191 |                         arcurs(WDCURS);
 | 
|---|
| 192 |                         gcurpos(cxval, cyval);
 | 
|---|
| 193 |                         break;
 | 
|---|
| 194 | 
 | 
|---|
| 195 |                 case 2:         /* harmonic was selected:  unselect it */
 | 
|---|
| 196 | 
 | 
|---|
| 197 |                         wpntsv = 0;
 | 
|---|
| 198 |                         cratex = crate1;
 | 
|---|
| 199 |                         cratey = crate1;
 | 
|---|
| 200 | 
 | 
|---|
| 201 |                         arcurs(WDCURS);
 | 
|---|
| 202 |                         settc(22, 1 + (curwhrm << 1));
 | 
|---|
| 203 |                         break;
 | 
|---|
| 204 |                 }
 | 
|---|
| 205 | 
 | 
|---|
| 206 |                 return(TRUE);
 | 
|---|
| 207 | 
 | 
|---|
| 208 |         case 1:         /* process a hit in the harmonic legend */
 | 
|---|
| 209 | 
 | 
|---|
| 210 |                 wpntsv  = 2;
 | 
|---|
| 211 |                 cratex  = crate1;
 | 
|---|
| 212 |                 cratey  = crate1;
 | 
|---|
| 213 | 
 | 
|---|
| 214 |                 curwhrm = cxval >> 4;
 | 
|---|
| 215 |                 curwhrv = vmtab[curwhrm];
 | 
|---|
| 216 | 
 | 
|---|
| 217 |                 cxval = (curwhrm << 4) + 8;
 | 
|---|
| 218 | 
 | 
|---|
| 219 |                 if (curwhrv < 0) {
 | 
|---|
| 220 | 
 | 
|---|
| 221 |                         cyval = WBOFF - ((-curwhrv * WBSF1) / WBSF2);
 | 
|---|
| 222 | 
 | 
|---|
| 223 |                 } else {
 | 
|---|
| 224 | 
 | 
|---|
| 225 |                         cyval = WBOFF - ((curwhrv * WBSF1) / WBSF2);
 | 
|---|
| 226 |                 }
 | 
|---|
| 227 | 
 | 
|---|
| 228 |                 arcurs(WS_GRAB);
 | 
|---|
| 229 |                 gcurpos(cxval, cyval);
 | 
|---|
| 230 |                 wdswin(5);
 | 
|---|
| 231 |                 return(TRUE);
 | 
|---|
| 232 | /*  | 
|---|
| 233 | 
 | 
|---|
| 234 | */
 | 
|---|
| 235 |         case 3:         /* process a hit in the store & fetch window */
 | 
|---|
| 236 | 
 | 
|---|
| 237 |                 wsnmod[curvce][curwslt] = FALSE;
 | 
|---|
| 238 | 
 | 
|---|
| 239 |                 if (cyval < 336) {              /* store ? */
 | 
|---|
| 240 | 
 | 
|---|
| 241 |                         memcpyw(&wslib[curwave],
 | 
|---|
| 242 |                                 curwslt ? vbufs[curvce].idhwvbf
 | 
|---|
| 243 |                                         : vbufs[curvce].idhwvaf,
 | 
|---|
| 244 |                                 NUMHARM + (2 * NUMWPNT));
 | 
|---|
| 245 | 
 | 
|---|
| 246 |                         wdswin(2);
 | 
|---|
| 247 | 
 | 
|---|
| 248 |                 } else {                        /* retrieve */
 | 
|---|
| 249 | 
 | 
|---|
| 250 |                         memcpyw(curwslt ? vbufs[curvce].idhwvbf
 | 
|---|
| 251 |                                         : vbufs[curvce].idhwvaf,
 | 
|---|
| 252 |                                 &wslib[curwave],
 | 
|---|
| 253 |                                 NUMHARM + (2 * NUMWPNT));
 | 
|---|
| 254 | 
 | 
|---|
| 255 |                         updfpu();
 | 
|---|
| 256 |                         newws();
 | 
|---|
| 257 |                         dsnewws();
 | 
|---|
| 258 |                 }
 | 
|---|
| 259 | 
 | 
|---|
| 260 |                 cratex = crate1;
 | 
|---|
| 261 |                 cratey = crate1;
 | 
|---|
| 262 |                 return(TRUE);
 | 
|---|
| 263 | 
 | 
|---|
| 264 |         default:                /* anywhere else is an error */
 | 
|---|
| 265 | 
 | 
|---|
| 266 |                 cratex = crate1;
 | 
|---|
| 267 |                 cratey = crate1;
 | 
|---|
| 268 |                 return(FALSE);
 | 
|---|
| 269 |         }
 | 
|---|
| 270 | }
 | 
|---|