| 1 | /*
 | 
|---|
| 2 |    =============================================================================
 | 
|---|
| 3 |         ettrns.c -- transposition field handlers
 | 
|---|
| 4 |         Version 20 -- 1988-07-12 -- D.N. Lynx Crowe
 | 
|---|
| 5 |    =============================================================================
 | 
|---|
| 6 | */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #define DEBUGIT 0
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "stddefs.h"
 | 
|---|
| 11 | #include "fields.h"
 | 
|---|
| 12 | #include "charset.h"
 | 
|---|
| 13 | #include "hwdefs.h"
 | 
|---|
| 14 | #include "vsdd.h"
 | 
|---|
| 15 | #include "graphdef.h"
 | 
|---|
| 16 | #include "score.h"
 | 
|---|
| 17 | #include "scfns.h"
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include "midas.h"
 | 
|---|
| 20 | #include "scdsp.h"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | extern  short   advscur();
 | 
|---|
| 23 | 
 | 
|---|
| 24 | extern  unsigned        *obj8;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | extern  short   ctrsw, recsw, stccol, stcrow;
 | 
|---|
| 27 | 
 | 
|---|
| 28 | extern  short   s_trns[12];     /* current transposition values */
 | 
|---|
| 29 | 
 | 
|---|
| 30 | extern  char    dspbuf[65];
 | 
|---|
| 31 | 
 | 
|---|
| 32 | extern  short   grpdyn[], grpmode[], grpstat[];
 | 
|---|
| 33 | 
 | 
|---|
| 34 | extern  struct  gdsel   *gdstbc[];
 | 
|---|
| 35 | 
 | 
|---|
| 36 | /*  | 
|---|
| 37 | 
 | 
|---|
| 38 | */
 | 
|---|
| 39 | 
 | 
|---|
| 40 | /*
 | 
|---|
| 41 |    =============================================================================
 | 
|---|
| 42 |         et_trns() -- load the edit buffer
 | 
|---|
| 43 |    =============================================================================
 | 
|---|
| 44 | */
 | 
|---|
| 45 | 
 | 
|---|
| 46 | short
 | 
|---|
| 47 | et_trns(n)
 | 
|---|
| 48 | short n;
 | 
|---|
| 49 | {
 | 
|---|
| 50 |         register short trval;
 | 
|---|
| 51 |         register char trsign;
 | 
|---|
| 52 | 
 | 
|---|
| 53 |         trval = s_trns[n];
 | 
|---|
| 54 | 
 | 
|---|
| 55 |         if (trval < 0) {
 | 
|---|
| 56 | 
 | 
|---|
| 57 |                 trval = (-trval);
 | 
|---|
| 58 |                 trsign = '-';
 | 
|---|
| 59 | 
 | 
|---|
| 60 |         } else {
 | 
|---|
| 61 | 
 | 
|---|
| 62 |                 trsign = '+';
 | 
|---|
| 63 |         }
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         sprintf(ebuf, "%04.4d%c", trval, trsign);
 | 
|---|
| 66 | 
 | 
|---|
| 67 |         ebflag = TRUE;
 | 
|---|
| 68 | 
 | 
|---|
| 69 | #if     DEBUGIT
 | 
|---|
| 70 |         printf("et_trns(0x%04.4x)  [%s]\r\n", n, ebuf);
 | 
|---|
| 71 | #endif
 | 
|---|
| 72 | 
 | 
|---|
| 73 |         return(SUCCESS);
 | 
|---|
| 74 | }
 | 
|---|
| 75 | 
 | 
|---|
| 76 | /*  | 
|---|
| 77 | 
 | 
|---|
| 78 | */
 | 
|---|
| 79 | 
 | 
|---|
| 80 | /*
 | 
|---|
| 81 |    =============================================================================
 | 
|---|
| 82 |         ef_trns() -- parse (unload) the edit buffer
 | 
|---|
| 83 |    =============================================================================
 | 
|---|
| 84 | */
 | 
|---|
| 85 | 
 | 
|---|
| 86 | short
 | 
|---|
| 87 | ef_trns(n)
 | 
|---|
| 88 | short n;
 | 
|---|
| 89 | {
 | 
|---|
| 90 |         register short i, trval;
 | 
|---|
| 91 |         register struct s_entry *ep, *trnval;
 | 
|---|
| 92 | 
 | 
|---|
| 93 |         ebuf[5] = '\0';                 /* terminate the string in ebuf */
 | 
|---|
| 94 | 
 | 
|---|
| 95 | #if     DEBUGIT
 | 
|---|
| 96 |         printf("ef_trns(0x%04.4x) [%s]\r\n", n, ebuf);
 | 
|---|
| 97 | #endif
 | 
|---|
| 98 | 
 | 
|---|
| 99 |         ebflag = FALSE;
 | 
|---|
| 100 |         trval = 0;
 | 
|---|
| 101 | 
 | 
|---|
| 102 |         for (i = 0; i < 4; i++)         /* convert from ASCII to binary */
 | 
|---|
| 103 |                 trval = (trval * 10) + (ebuf[i] - '0');
 | 
|---|
| 104 | 
 | 
|---|
| 105 |         if (trval GT 1200)              /* check against limit */
 | 
|---|
| 106 |                 return(FAILURE);
 | 
|---|
| 107 | 
 | 
|---|
| 108 |         if (ebuf[4] EQ '-')             /* fixup sign of value */
 | 
|---|
| 109 |                 trval = (-trval);
 | 
|---|
| 110 | 
 | 
|---|
| 111 |         s_trns[n] = trval;              /* store new value */
 | 
|---|
| 112 |         settune();                      /* update FPU */
 | 
|---|
| 113 | 
 | 
|---|
| 114 |         if (recsw AND grpmode[n] AND (2 EQ grpmode[n])) {
 | 
|---|
| 115 | 
 | 
|---|
| 116 |                 trnval = (struct s_entry *)((long)trval << 16);
 | 
|---|
| 117 | 
 | 
|---|
| 118 |                 if (E_NULL NE (ep = findev(p_cur, t_cur, EV_TRNS, n, -1))) {
 | 
|---|
| 119 | 
 | 
|---|
| 120 |                         ep->e_lft = trnval;
 | 
|---|
| 121 | 
 | 
|---|
| 122 |                 } else if (E_NULL NE (ep = e_alc(E_SIZE3))) {
 | 
|---|
| 123 | 
 | 
|---|
| 124 |                         ep->e_type  = EV_TRNS;
 | 
|---|
| 125 |                         ep->e_time  = t_cur;
 | 
|---|
| 126 |                         ep->e_data1 = n;
 | 
|---|
| 127 |                         ep->e_lft   = trnval;
 | 
|---|
| 128 |                         p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
 | 
|---|
| 129 |                         eh_ins(ep, EH_TRNS);
 | 
|---|
| 130 |                         ctrsw = TRUE;
 | 
|---|
| 131 |                         se_disp(ep, D_FWD, gdstbc, 1);
 | 
|---|
| 132 |                         scupd();
 | 
|---|
| 133 |                 }
 | 
|---|
| 134 |         }
 | 
|---|
| 135 | 
 | 
|---|
| 136 | #if     DEBUGIT
 | 
|---|
| 137 |         printf("   SUCCESS: %d\r\n", trval);
 | 
|---|
| 138 | #endif
 | 
|---|
| 139 |         return(SUCCESS);
 | 
|---|
| 140 | }
 | 
|---|
| 141 | 
 | 
|---|
| 142 | /*  | 
|---|
| 143 | 
 | 
|---|
| 144 | */
 | 
|---|
| 145 | 
 | 
|---|
| 146 | /*
 | 
|---|
| 147 |    =============================================================================
 | 
|---|
| 148 |         rd_trns() -- (re)display the value
 | 
|---|
| 149 |    =============================================================================
 | 
|---|
| 150 | */
 | 
|---|
| 151 | 
 | 
|---|
| 152 | short
 | 
|---|
| 153 | rd_trns(n)
 | 
|---|
| 154 | short n;
 | 
|---|
| 155 | {
 | 
|---|
| 156 |         register short trval, i;
 | 
|---|
| 157 |         register char trsign;
 | 
|---|
| 158 | 
 | 
|---|
| 159 |         trval = s_trns[n];              /* get the value */
 | 
|---|
| 160 | 
 | 
|---|
| 161 |         if (trval < 0) {                /* adjust for the sign */
 | 
|---|
| 162 | 
 | 
|---|
| 163 |                 trsign = '-';
 | 
|---|
| 164 |                 trval = (-trval);
 | 
|---|
| 165 | 
 | 
|---|
| 166 |         } else {
 | 
|---|
| 167 | 
 | 
|---|
| 168 |                 trsign = '+';
 | 
|---|
| 169 |         }
 | 
|---|
| 170 | 
 | 
|---|
| 171 |         sprintf(dspbuf, "%04.4d", trval);       /* convert to ASCII */
 | 
|---|
| 172 | 
 | 
|---|
| 173 | #if     DEBUGIT
 | 
|---|
| 174 |         printf("rd_trns:  %d <%d> [%s] -> ", n, s_trns[n], dspbuf);
 | 
|---|
| 175 | #endif
 | 
|---|
| 176 | 
 | 
|---|
| 177 |         if (trsign EQ '-') {            /* handle +1, -1 cases */
 | 
|---|
| 178 | 
 | 
|---|
| 179 |                 if (dspbuf[0] EQ '1')
 | 
|---|
| 180 |                         dspbuf[0] = SP_M1;      /* -1 */
 | 
|---|
| 181 |                 else
 | 
|---|
| 182 |                         dspbuf[0] = '-';
 | 
|---|
| 183 | 
 | 
|---|
| 184 |         } else {
 | 
|---|
| 185 | 
 | 
|---|
| 186 |                 if (dspbuf[0] EQ '1')
 | 
|---|
| 187 |                         dspbuf[0] = SP_P1;      /* +1 */
 | 
|---|
| 188 |                 else
 | 
|---|
| 189 |                         dspbuf[0] = '+';
 | 
|---|
| 190 |         }
 | 
|---|
| 191 | 
 | 
|---|
| 192 | #if     DEBUGIT
 | 
|---|
| 193 |         printf("{%02x %02x %02x %02x}\r\n",
 | 
|---|
| 194 |                 dspbuf[0], dspbuf[1], dspbuf[2], dspbuf[3]);
 | 
|---|
| 195 | #endif
 | 
|---|
| 196 | 
 | 
|---|
| 197 |         if (v_regs[5] & 0x0180)
 | 
|---|
| 198 |                 vbank(0);                       /* display the value */
 | 
|---|
| 199 | 
 | 
|---|
| 200 |         vputs(obj8, 3, (5 * (n + 1)), dspbuf, SDW11ATR);
 | 
|---|
| 201 | 
 | 
|---|
| 202 |         return(SUCCESS);
 | 
|---|
| 203 | }
 | 
|---|
| 204 | 
 | 
|---|
| 205 | /*  | 
|---|
| 206 | 
 | 
|---|
| 207 | */
 | 
|---|
| 208 | 
 | 
|---|
| 209 | /*
 | 
|---|
| 210 |    =============================================================================
 | 
|---|
| 211 |         ds_trns() -- display all transposition values
 | 
|---|
| 212 |    =============================================================================
 | 
|---|
| 213 | */
 | 
|---|
| 214 | 
 | 
|---|
| 215 | ds_trns()
 | 
|---|
| 216 | {
 | 
|---|
| 217 |         register short i;
 | 
|---|
| 218 | 
 | 
|---|
| 219 |         for (i = 0; i < 12; i++)        /* display each of the groups */
 | 
|---|
| 220 |                 rd_trns(i);
 | 
|---|
| 221 | }
 | 
|---|
| 222 | 
 | 
|---|
| 223 | /*  | 
|---|
| 224 | 
 | 
|---|
| 225 | */
 | 
|---|
| 226 | 
 | 
|---|
| 227 | /*
 | 
|---|
| 228 |    =============================================================================
 | 
|---|
| 229 |         nd_trns() -- handle new data entry
 | 
|---|
| 230 |    =============================================================================
 | 
|---|
| 231 | */
 | 
|---|
| 232 | 
 | 
|---|
| 233 | short
 | 
|---|
| 234 | nd_trns(n, k)
 | 
|---|
| 235 | short n;
 | 
|---|
| 236 | register short  k;
 | 
|---|
| 237 | {
 | 
|---|
| 238 |         register short ec, c, advsw;
 | 
|---|
| 239 | 
 | 
|---|
| 240 |         ec = stccol - cfetp->flcol;     /* setup edit buffer column */
 | 
|---|
| 241 | 
 | 
|---|
| 242 | #if     DEBUGIT
 | 
|---|
| 243 |         printf("nd_trns(0x%04.4x, 0x%02.2x) ec = %d, tp = 0x%08.8lx\r\n",
 | 
|---|
| 244 |                 n, k, ec, tp);
 | 
|---|
| 245 | #endif
 | 
|---|
| 246 | 
 | 
|---|
| 247 |         advsw = TRUE;
 | 
|---|
| 248 | 
 | 
|---|
| 249 |         if (ec EQ 0) {          /* first column of field ? */
 | 
|---|
| 250 | 
 | 
|---|
| 251 |                 switch (k) {    /* what are we entering ? */
 | 
|---|
| 252 | 
 | 
|---|
| 253 |                 case 0:         /* digit 0 */
 | 
|---|
| 254 | 
 | 
|---|
| 255 |                         ebuf[0] = '0';
 | 
|---|
| 256 |                         k = ebuf[4];
 | 
|---|
| 257 |                         break;
 | 
|---|
| 258 | 
 | 
|---|
| 259 |                 case 1:         /* digit 1 */
 | 
|---|
| 260 | 
 | 
|---|
| 261 |                         if (ebuf[4] EQ '+')
 | 
|---|
| 262 |                                 k = SP_P1;      /* +1 */
 | 
|---|
| 263 |                         else
 | 
|---|
| 264 |                                 k = SP_M1;      /* -1 */
 | 
|---|
| 265 | 
 | 
|---|
| 266 |                         ebuf[0] = '1';
 | 
|---|
| 267 |                         break;
 | 
|---|
| 268 | 
 | 
|---|
| 269 |                 case 8:         /* - */
 | 
|---|
| 270 | 
 | 
|---|
| 271 |                         if (ebuf[0] EQ '0')
 | 
|---|
| 272 |                                 k = '-';
 | 
|---|
| 273 |                         else
 | 
|---|
| 274 |                                 k = SP_M1;
 | 
|---|
| 275 | 
 | 
|---|
| 276 |                         ebuf[4] = '-';
 | 
|---|
| 277 |                         advsw = FALSE;
 | 
|---|
| 278 |                         break;
 | 
|---|
| 279 | 
 | 
|---|
| 280 | 
 | 
|---|
| 281 |                 case 9:         /* + */
 | 
|---|
| 282 | 
 | 
|---|
| 283 |                         if (ebuf[0] EQ '0')
 | 
|---|
| 284 |                                 k = '+';
 | 
|---|
| 285 |                         else
 | 
|---|
| 286 |                                 k = SP_P1;
 | 
|---|
| 287 | 
 | 
|---|
| 288 |                         ebuf[4] = '+';
 | 
|---|
| 289 |                         advsw = FALSE;
 | 
|---|
| 290 |                         break;
 | 
|---|
| 291 | 
 | 
|---|
| 292 |                 default:        /* anything else is an error */
 | 
|---|
| 293 | 
 | 
|---|
| 294 |                         return(FAILURE);
 | 
|---|
| 295 |                 }
 | 
|---|
| 296 | 
 | 
|---|
| 297 |         } else {        /* any other column */
 | 
|---|
| 298 | 
 | 
|---|
| 299 |                 ebuf[ec] = k + '0';
 | 
|---|
| 300 |         }
 | 
|---|
| 301 | 
 | 
|---|
| 302 |         dspbuf[0] = (k > 9) ? k : (k + '0');
 | 
|---|
| 303 |         dspbuf[1] = '\0';
 | 
|---|
| 304 | 
 | 
|---|
| 305 |         if (v_regs[5] & 0x0180)
 | 
|---|
| 306 |                 vbank(0);
 | 
|---|
| 307 | 
 | 
|---|
| 308 |         vputs(obj8, 3, stccol, dspbuf, SDW11DEA);
 | 
|---|
| 309 | 
 | 
|---|
| 310 | #if     DEBUGIT
 | 
|---|
| 311 |         printf("nd_trns: char=0x%02.2x, col=%d\n", dspbuf[0], stccol);
 | 
|---|
| 312 | #endif
 | 
|---|
| 313 | 
 | 
|---|
| 314 |         if (advsw)
 | 
|---|
| 315 |                 advscur();
 | 
|---|
| 316 | 
 | 
|---|
| 317 |         return(SUCCESS);
 | 
|---|
| 318 | }
 | 
|---|