[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | wheel.c -- MIDAS-VII -- scroll wheel, trackball and mouse functions
|
---|
| 4 | Version 47 -- 1989-12-19 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
| 6 | M8 Mouse driver -- uses 3 byte Microsoft format (default).
|
---|
| 7 | =============================================================================
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #define DEBUGMS 0
|
---|
| 11 | #define DEBUGTF 0
|
---|
| 12 | #define DEBUGTK 0
|
---|
| 13 |
|
---|
[6262b5c] | 14 | #include "all.h"
|
---|
[f40a309] | 15 |
|
---|
[7258c6a] | 16 | extern uint16_t setipl(uint16_t arg);
|
---|
[f40a309] | 17 |
|
---|
[e225e77] | 18 | extern int16_t infield(int16_t row, int16_t col, struct fet *fetp);
|
---|
| 19 | extern void cmfix(void);
|
---|
| 20 | extern void smy_up(int16_t tag);
|
---|
| 21 | extern void sqy_up(int16_t tag);
|
---|
| 22 |
|
---|
[f40a309] | 23 | #define M_FL_CT 1024 /* mouse flush count */
|
---|
| 24 |
|
---|
| 25 | #define M_ST_TM 2
|
---|
| 26 | #define C_PER_S 500
|
---|
| 27 | #define MAXTRIES 10
|
---|
| 28 |
|
---|
| 29 | #define MATIME 2000 /* mouse activity timeout -- ms*/
|
---|
| 30 |
|
---|
| 31 | #define CFR0 (BR_1200|NSB_1) /* UART CFR0 1200 baud, 1 stop bit */
|
---|
| 32 | #define CFR1 (P_NONE|NDB_7) /* UART CFR1 7 data bits, no parity */
|
---|
| 33 |
|
---|
| 34 | #define M_NONE 0 /* No errors detected */
|
---|
| 35 | #define M_FLUSH 1 /* Unable to flush mouse buffer */
|
---|
| 36 | #define M_SYNC 2 /* Mouse out of sync */
|
---|
| 37 | #define M_NORESP 3 /* No response from mouse */
|
---|
| 38 | #define M_RESPNG 4 /* Bad response from mouse */
|
---|
| 39 |
|
---|
| 40 | /* |
---|
| 41 |
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | #if DEBUGMS
|
---|
| 45 | short debugms;
|
---|
| 46 | #endif
|
---|
| 47 |
|
---|
| 48 | #if DEBUGTF
|
---|
| 49 | short debugtf;
|
---|
| 50 |
|
---|
| 51 | long txficnt;
|
---|
| 52 | long tyficnt;
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
| 55 | #if DEBUGTK
|
---|
| 56 | short debugtk;
|
---|
| 57 | #endif
|
---|
[7258c6a] | 58 |
|
---|
| 59 | int16_t M_error; /* mouse I/F error code */
|
---|
| 60 | int16_t M_state; /* mouse state */
|
---|
[f40a309] | 61 | int16_t M_oldbs; /* previous mouse button state */
|
---|
[7258c6a] | 62 |
|
---|
[f40a309] | 63 | int8_t M_strng[32]; /* mouse input string buffer */
|
---|
[7258c6a] | 64 |
|
---|
| 65 | int16_t msctrl; /* mouse control flag -- mouse update */
|
---|
| 66 | int16_t msflag; /* mouse control flag -- mouse movement */
|
---|
[9519422] | 67 | int16_t msrtag; /* mouse control flag -- mouse reset */
|
---|
[7258c6a] | 68 | int16_t msxres; /* mouse x residue */
|
---|
| 69 | int16_t msyres; /* mouse y residue */
|
---|
| 70 | int16_t msxmov; /* mouse x movement */
|
---|
| 71 | int16_t msymov; /* mouse y movement */
|
---|
| 72 | int16_t msxdiv; /* mouse x divisor */
|
---|
[f40a309] | 73 | int16_t msydiv; /* mouse y divisor */
|
---|
[7258c6a] | 74 |
|
---|
[f40a309] | 75 | int16_t tkboth; /* both trackball axes went active */
|
---|
[7258c6a] | 76 |
|
---|
| 77 | int16_t txdiv; /* text cursor X divider */
|
---|
[f40a309] | 78 | int16_t tydiv; /* text cursor Y divider */
|
---|
[7258c6a] | 79 |
|
---|
| 80 | int16_t tkxdvr = TKXDVR; /* text cursor X divisor */
|
---|
[f40a309] | 81 | int16_t tkydvr = TKYDVR; /* text cursor Y divisor */
|
---|
[7258c6a] | 82 |
|
---|
| 83 | int16_t tkhdvr = TKCDVR; /* text cursor horizontal movement threshold */
|
---|
[f40a309] | 84 | int16_t tkvdvr = TKCDVR; /* text cursor vertical movement threshold */
|
---|
| 85 |
|
---|
| 86 | /* |
---|
| 87 |
|
---|
[7258c6a] | 88 | */
|
---|
[f40a309] | 89 |
|
---|
| 90 | int16_t msxgdv[13] = { /* mouse x cursor divisor table */
|
---|
| 91 |
|
---|
| 92 | 1, /* -1 -- Main menu */
|
---|
| 93 | 1, /* 0 -- Librarian */
|
---|
| 94 | 1, /* 1 -- Patch editor */
|
---|
| 95 | 1, /* 2 -- Score editor */
|
---|
| 96 | 1, /* 3 -- Sequence editor */
|
---|
| 97 | 1, /* 4 -- Instrument editor */
|
---|
| 98 | 1, /* 5 -- Initialize system */
|
---|
| 99 | 1, /* 6 -- Waveshape editor */
|
---|
| 100 | 1, /* 7 -- Write program to disk */
|
---|
| 101 | 1, /* 8 -- Tuning editor */
|
---|
| 102 | 1, /* 9 -- Format disk */
|
---|
| 103 | 1, /* 10 -- Assignment editor */
|
---|
| 104 | 1 /* 11 -- Diagnostics */
|
---|
[7258c6a] | 105 | };
|
---|
[f40a309] | 106 |
|
---|
| 107 | int16_t msygdv[13] = { /* mouse y cursor divisor table */
|
---|
| 108 |
|
---|
| 109 | 2, /* -1 -- Main menu */
|
---|
| 110 | 2, /* 0 -- Librarian */
|
---|
| 111 | 2, /* 1 -- Patch editor */
|
---|
| 112 | 2, /* 2 -- Score editor */
|
---|
| 113 | 2, /* 3 -- Sequence editor */
|
---|
| 114 | 2, /* 4 -- Instrument editor */
|
---|
| 115 | 2, /* 5 -- Initialize system */
|
---|
| 116 | 2, /* 6 -- Waveshape editor */
|
---|
| 117 | 2, /* 7 -- Write program to disk */
|
---|
| 118 | 2, /* 8 -- Tuning editor */
|
---|
| 119 | 2, /* 9 -- Format disk */
|
---|
| 120 | 2, /* 10 -- Assignment editor */
|
---|
| 121 | 2 /* 11 -- Diagnostics */
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | /* |
---|
[0c834c5] | 125 |
|
---|
| 126 | */
|
---|
| 127 |
|
---|
| 128 | extern void (*curmove)(void);
|
---|
| 129 | extern void (*cx_upd)(void);
|
---|
| 130 | extern void (*cy_upd)(void);
|
---|
| 131 | extern void (*xy_dn)(void);
|
---|
| 132 | extern void (*xy_up)(void);
|
---|
[f40a309] | 133 | extern void (*e_key)(void);
|
---|
[7258c6a] | 134 | extern void (*m_key)(void);
|
---|
| 135 | extern void (*x_key)(void);
|
---|
| 136 |
|
---|
| 137 | extern int16_t asig;
|
---|
| 138 | extern int16_t astat;
|
---|
| 139 | extern int16_t aval;
|
---|
| 140 | extern int16_t chtime;
|
---|
| 141 | extern int16_t chwait;
|
---|
| 142 | extern int16_t clkctl;
|
---|
| 143 | extern int16_t clkrun;
|
---|
| 144 | extern int16_t cmfirst;
|
---|
| 145 | extern int16_t cmtype;
|
---|
| 146 | extern int16_t ctrsw;
|
---|
| 147 | extern int16_t curhold;
|
---|
| 148 | extern int16_t cvtime;
|
---|
| 149 | extern int16_t cvwait;
|
---|
| 150 | extern int16_t cxrate;
|
---|
| 151 | extern int16_t cxval;
|
---|
| 152 | extern int16_t cyrate;
|
---|
| 153 | extern int16_t cyval;
|
---|
| 154 | extern int16_t nchwait;
|
---|
| 155 | extern int16_t ncvwait;
|
---|
| 156 | extern int16_t ndisp;
|
---|
| 157 | extern int16_t ss_ptsw;
|
---|
| 158 | extern int16_t ss_sqsw;
|
---|
| 159 | extern int16_t stccol;
|
---|
| 160 | extern int16_t stcrow;
|
---|
| 161 | extern int16_t swback;
|
---|
| 162 | extern int16_t swctrl;
|
---|
| 163 | extern int16_t swdelta;
|
---|
| 164 | extern int16_t swdir;
|
---|
| 165 | extern int16_t swfiin;
|
---|
| 166 | extern int16_t swflag;
|
---|
| 167 | extern int16_t swlast;
|
---|
| 168 | extern int16_t swndx;
|
---|
| 169 | extern int16_t swstop;
|
---|
[f40a309] | 170 | extern int16_t swthr;
|
---|
| 171 | extern int16_t swtime;
|
---|
| 172 | extern int16_t swwait;
|
---|
| 173 |
|
---|
[7258c6a] | 174 | /* |
---|
| 175 |
|
---|
| 176 | */
|
---|
| 177 |
|
---|
| 178 | extern int16_t tkback;
|
---|
| 179 | extern int16_t tkctrl;
|
---|
| 180 | extern int16_t tkrmin;
|
---|
| 181 | extern int16_t tkthr;
|
---|
| 182 | extern int16_t tktime;
|
---|
| 183 | extern int16_t tkwait;
|
---|
| 184 | extern int16_t trkball;
|
---|
| 185 | extern int16_t txfiin;
|
---|
| 186 | extern int16_t txflag;
|
---|
| 187 | extern int16_t txlast;
|
---|
| 188 | extern int16_t tyfiin;
|
---|
| 189 | extern int16_t tyflag;
|
---|
| 190 | extern int16_t tylast;
|
---|
| 191 | extern int16_t txstop;
|
---|
| 192 | extern int16_t tystop;
|
---|
| 193 | extern int16_t vtccol;
|
---|
| 194 | extern int16_t vtcrow;
|
---|
| 195 | extern int16_t vtpcol;
|
---|
| 196 | extern int16_t vtprow;
|
---|
| 197 | extern int16_t xkstat;
|
---|
| 198 | extern int16_t ykstat;
|
---|
| 199 |
|
---|
| 200 | extern int32_t swcount;
|
---|
| 201 | extern int32_t swrate;
|
---|
| 202 | extern int32_t swrmin;
|
---|
| 203 | extern int32_t swtemp;
|
---|
| 204 |
|
---|
| 205 | extern int16_t *cratex;
|
---|
| 206 | extern int16_t *cratey;
|
---|
| 207 |
|
---|
[f40a309] | 208 | extern int16_t sigtab[][2];
|
---|
| 209 | extern int16_t swfifo[NSWFIFO];
|
---|
| 210 | extern int16_t txfifo[NTKFIFO];
|
---|
| 211 | extern int16_t tyfifo[NTKFIFO];
|
---|
| 212 |
|
---|
| 213 | #include "swrtab.h" /* long swrtab[128]; */
|
---|
| 214 |
|
---|
| 215 | /* |
---|
| 216 |
|
---|
| 217 | */
|
---|
| 218 |
|
---|
| 219 | /*
|
---|
[7258c6a] | 220 | =============================================================================
|
---|
[f40a309] | 221 | MouseRT() -- reset the mouse activity timer
|
---|
[7258c6a] | 222 | =============================================================================
|
---|
[f40a309] | 223 | */
|
---|
| 224 |
|
---|
| 225 | void MouseRT(uint16_t t)
|
---|
| 226 | {
|
---|
| 227 | uint16_t oldi;
|
---|
| 228 |
|
---|
| 229 | oldi = setipl(TIM_DI); /* disable interrupts */
|
---|
| 230 |
|
---|
| 231 | timers[MUTIMER] = t; /* set the mouse timer */
|
---|
| 232 |
|
---|
| 233 | setipl(oldi); /* enable interrupts */
|
---|
| 234 |
|
---|
| 235 | #if DEBUGMS
|
---|
| 236 | if (debugms > 2)
|
---|
| 237 | printf("MouseRT(%d)\n", t);
|
---|
| 238 | #endif
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | /* |
---|
| 242 |
|
---|
| 243 | */
|
---|
| 244 |
|
---|
[7258c6a] | 245 | /*
|
---|
[f40a309] | 246 | =============================================================================
|
---|
[7258c6a] | 247 | MouseRD() -- read a string from the mouse
|
---|
[f40a309] | 248 | =============================================================================
|
---|
[7258c6a] | 249 | */
|
---|
[f40a309] | 250 |
|
---|
| 251 | int16_t MouseRD(int8_t *str, int16_t nc, int16_t nt)
|
---|
| 252 | {
|
---|
| 253 | int32_t tc;
|
---|
| 254 |
|
---|
[7258c6a] | 255 | tc = nt * (int32_t)C_PER_S;
|
---|
[f40a309] | 256 |
|
---|
| 257 | while (nc > 0) {
|
---|
| 258 |
|
---|
| 259 | if (BIOS(B_RDAV, PRT_DEV)) {
|
---|
| 260 |
|
---|
| 261 | *str++ = (int8_t)BIOS(B_GETC, PRT_DEV);
|
---|
| 262 | *str = '\0';
|
---|
| 263 | --nc;
|
---|
| 264 |
|
---|
| 265 | } else {
|
---|
| 266 |
|
---|
| 267 | if (tc-- LE 0)
|
---|
| 268 | return(FAILURE);
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | return(SUCCESS);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[7258c6a] | 275 | /*
|
---|
[f40a309] | 276 | =============================================================================
|
---|
[7258c6a] | 277 | MouseWR() -- write a string to the mouse
|
---|
[f40a309] | 278 | =============================================================================
|
---|
| 279 | */
|
---|
| 280 |
|
---|
| 281 | void MouseWR(int8_t *str)
|
---|
| 282 | {
|
---|
| 283 | register uint16_t c;
|
---|
| 284 |
|
---|
| 285 | #if DEBUGMS
|
---|
| 286 | if (debugms > 1)
|
---|
| 287 | printf("OUT \"%s\"\n", str);
|
---|
| 288 | #endif
|
---|
| 289 |
|
---|
| 290 | while (c = 0x00FF & *str++) /* get a byte */
|
---|
| 291 | BIOS(B_PUTC, PRT_DEV, c); /* output it */
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | /* |
---|
| 295 |
|
---|
| 296 | */
|
---|
[7258c6a] | 297 |
|
---|
[f40a309] | 298 | /*
|
---|
[7258c6a] | 299 | =============================================================================
|
---|
[f40a309] | 300 | MouseFL() -- flush the mouse input buffer
|
---|
| 301 | =============================================================================
|
---|
| 302 | */
|
---|
| 303 |
|
---|
| 304 | int16_t MouseFL(int16_t tc)
|
---|
| 305 | {
|
---|
| 306 | int32_t flushed;
|
---|
| 307 |
|
---|
| 308 | flushed = 0L; /* reset the flush counter */
|
---|
| 309 |
|
---|
| 310 | M_state = 0; /* reset mouse state */
|
---|
| 311 | msflag = FALSE; /* reset mouse movement flag */
|
---|
| 312 | msctrl = FALSE; /* reset mouse update flag */
|
---|
| 313 |
|
---|
| 314 | while (BIOS(B_RDAV, PRT_DEV)) { /* check for data */
|
---|
| 315 |
|
---|
| 316 | BIOS(B_GETC, PRT_DEV); /* read a byte */
|
---|
| 317 | ++flushed; /* update flush count */
|
---|
| 318 |
|
---|
| 319 | if (--tc LE 0) { /* see if we've timed out */
|
---|
| 320 |
|
---|
| 321 | #if DEBUGMS
|
---|
| 322 | if (debugms)
|
---|
| 323 | printf("FLUSH %d %ld FAILURE\n", M_state, flushed);
|
---|
| 324 | #endif
|
---|
| 325 |
|
---|
| 326 | return(FAILURE); /* FAILED */
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | #if DEBUGMS
|
---|
| 331 | if (debugms)
|
---|
| 332 | printf("FLUSH %d %ld SUCCESS\n", M_state, flushed);
|
---|
| 333 | #endif
|
---|
| 334 |
|
---|
| 335 | return(SUCCESS); /* SUCCEEDED */
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | /* |
---|
| 339 |
|
---|
[7258c6a] | 340 | */
|
---|
[f40a309] | 341 |
|
---|
[7258c6a] | 342 | /*
|
---|
[f40a309] | 343 | =============================================================================
|
---|
| 344 | MouseWK() -- wake up the mouse
|
---|
| 345 | =============================================================================
|
---|
| 346 | */
|
---|
| 347 |
|
---|
| 348 | int16_t MouseWK(void)
|
---|
| 349 | {
|
---|
| 350 | int16_t tries;
|
---|
| 351 |
|
---|
| 352 | M_error = M_NONE; /* reset mouse error flag */
|
---|
| 353 | M_oldbs = 0; /* reset mouse button state */
|
---|
| 354 | M_state = 0; /* reset the mouse state machine */
|
---|
| 355 |
|
---|
| 356 | /* set the UART to 1200 baud, 7 data bits, No parity, 1 stop bit */
|
---|
| 357 |
|
---|
| 358 | XBIOS(X_SETPRT, PRT_DEV, L_NUL, -1, CFR0, CFR1);
|
---|
| 359 |
|
---|
| 360 | if (MouseFL(M_FL_CT)) { /* flush the FIFO */
|
---|
| 361 |
|
---|
| 362 | M_error = M_FLUSH; /* error -- can't flush */
|
---|
| 363 |
|
---|
| 364 | #if DEBUGMS
|
---|
| 365 | if (debugms)
|
---|
| 366 | printf("MouseWK() -- FAILURE\n");
|
---|
| 367 | #endif
|
---|
| 368 |
|
---|
| 369 | return(FAILURE); /* return -- we failed */
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | for (tries = 0; tries < MAXTRIES; tries++) {
|
---|
| 373 |
|
---|
| 374 | MouseWR("t"); /* ask the mouse its mode */
|
---|
| 375 |
|
---|
| 376 | if (MouseRD(M_strng, 2, M_ST_TM)) {
|
---|
| 377 |
|
---|
| 378 | M_error = M_NORESP;
|
---|
| 379 |
|
---|
| 380 | } else if (strcmp("VO", M_strng)) {
|
---|
| 381 |
|
---|
| 382 | M_error = M_RESPNG;
|
---|
| 383 |
|
---|
| 384 | if (MouseFL(M_FL_CT))
|
---|
| 385 | M_error = M_FLUSH;
|
---|
| 386 |
|
---|
| 387 | } else {
|
---|
| 388 |
|
---|
| 389 | M_error = M_NONE;
|
---|
| 390 | MouseRT(MATIME);
|
---|
| 391 |
|
---|
| 392 | #if DEBUGMS
|
---|
| 393 | if (debugms)
|
---|
| 394 | printf("MouseWK() -- SUCCESS\n");
|
---|
| 395 | #endif
|
---|
| 396 | return(SUCCESS);
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | #if DEBUGMS
|
---|
| 401 | if (debugms)
|
---|
| 402 | printf("MouseWK() -- FAILURE\n");
|
---|
| 403 | #endif
|
---|
| 404 |
|
---|
| 405 | return(FAILURE);
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 |
|
---|
| 409 | /* |
---|
[7258c6a] | 410 |
|
---|
[f40a309] | 411 | */
|
---|
[7258c6a] | 412 |
|
---|
[f40a309] | 413 | /*
|
---|
| 414 | =============================================================================
|
---|
| 415 | MouseEX() -- process a mouse report
|
---|
| 416 | =============================================================================
|
---|
| 417 | */
|
---|
| 418 |
|
---|
| 419 | void MouseEX(int8_t *str)
|
---|
| 420 | {
|
---|
| 421 | uint16_t oldi, msc, mst;
|
---|
| 422 |
|
---|
| 423 | #if DEBUGMS
|
---|
| 424 | if (debugms > 2)
|
---|
| 425 | printf("REPORT %02.2X %02.2X %02.2X\n",
|
---|
| 426 | str[0] & 0x00FF, str[1] & 0x00FF, str[2] & 0x00FF);
|
---|
| 427 | #endif
|
---|
| 428 |
|
---|
| 429 | M_error = M_NONE; /* reset error code */
|
---|
| 430 |
|
---|
| 431 | if ((str[0] & 0x0040) NE 0x0040) {
|
---|
| 432 |
|
---|
| 433 | if (MouseFL(M_FL_CT))
|
---|
| 434 | M_error = M_FLUSH;
|
---|
| 435 | else
|
---|
| 436 | M_error = M_SYNC;
|
---|
| 437 |
|
---|
| 438 | M_state = 0;
|
---|
| 439 | MouseRT(MATIME);
|
---|
| 440 |
|
---|
| 441 | #if DEBUGMS
|
---|
| 442 | if (debugms)
|
---|
| 443 | printf("SYNC\n");
|
---|
| 444 | #endif
|
---|
| 445 |
|
---|
| 446 | return;
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | mst = str[0] & 0x0030; /* extract mouse buttons */
|
---|
| 450 | msc = M_oldbs ^ mst; /* see what changed */
|
---|
| 451 | M_oldbs = mst; /* update button state */
|
---|
| 452 |
|
---|
| 453 | if (msc) { /* check for button status change */
|
---|
| 454 |
|
---|
| 455 | if (msc & 0x0010) { /* m key ? (right mouse button) */
|
---|
| 456 |
|
---|
| 457 | astat = (mst & 0x0010) >> 4;
|
---|
| 458 | (*m_key)();
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | if (msc & 0x0020) { /* e key ? (left mouse button) */
|
---|
| 462 |
|
---|
| 463 | astat = (mst & 0x0020) >> 5;
|
---|
| 464 | (*e_key)();
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | if ((ss_ptsw NE 0) OR (ss_sqsw NE 0)) {
|
---|
| 469 |
|
---|
| 470 | cxrate = 0;
|
---|
| 471 | cyrate = 0;
|
---|
| 472 | return;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | /* |
---|
| 476 |
|
---|
| 477 | */
|
---|
| 478 |
|
---|
| 479 | msxmov = str[1] | ((str[0] & 0x0003) << 6);
|
---|
| 480 |
|
---|
| 481 | if (msxmov & 0x0080)
|
---|
| 482 | msxmov |= 0xFF80;
|
---|
| 483 |
|
---|
| 484 | msxmov += msxres;
|
---|
| 485 |
|
---|
| 486 | msymov = str[2] + ((str[0] & 0x000C) << 4);
|
---|
| 487 |
|
---|
| 488 | if (msymov & 0x0080)
|
---|
| 489 | msymov |= 0xFF80;
|
---|
| 490 |
|
---|
| 491 | msymov += msyres;
|
---|
| 492 |
|
---|
| 493 | msxdiv = msxgdv[ndisp + 1];
|
---|
| 494 | msydiv = msygdv[ndisp + 1];
|
---|
| 495 |
|
---|
| 496 | /* calculate rates */
|
---|
| 497 |
|
---|
| 498 | if (msxdiv > 1)
|
---|
| 499 | cxrate = msxmov / msxdiv;
|
---|
| 500 | else
|
---|
| 501 | cxrate = msxmov;
|
---|
| 502 |
|
---|
| 503 | if (msydiv > 1)
|
---|
| 504 | cyrate = msymov / msydiv;
|
---|
| 505 | else
|
---|
| 506 | cyrate = msymov;
|
---|
| 507 |
|
---|
| 508 | /* calculate residues */
|
---|
| 509 |
|
---|
| 510 | if (msxdiv > 1)
|
---|
| 511 | msxres = msxmov % msxdiv;
|
---|
| 512 | else
|
---|
| 513 | msxres = 0;
|
---|
| 514 |
|
---|
| 515 | if (msydiv > 1)
|
---|
| 516 | msyres = msymov % msydiv;
|
---|
| 517 | else
|
---|
| 518 | msyres = 0;
|
---|
| 519 |
|
---|
| 520 | /* |
---|
| 521 |
|
---|
| 522 | */
|
---|
| 523 |
|
---|
| 524 | if ((cxrate EQ 0) AND (cyrate EQ 0)) /* we're done if nothing changed */
|
---|
| 525 | return;
|
---|
| 526 |
|
---|
| 527 | msctrl = TRUE; /* setup movement switches */
|
---|
| 528 | cmfirst = FALSE;
|
---|
| 529 | trkball = FALSE;
|
---|
| 530 |
|
---|
| 531 | cvtime = 0; /* clear delays */
|
---|
| 532 | ncvwait = 0;
|
---|
| 533 | chtime = 0;
|
---|
| 534 | nchwait = 0;
|
---|
| 535 | curhold = 0;
|
---|
| 536 |
|
---|
| 537 | if (NOT msflag) /* if mouse just started moving ... */
|
---|
| 538 | (*xy_dn)(); /* ... process key down */
|
---|
| 539 |
|
---|
| 540 | oldi = setipl(TIM_DI); /* set the mouse movement timer */
|
---|
| 541 | timers[MSTIMER] = MSTOVAL;
|
---|
| 542 | setipl(oldi);
|
---|
| 543 |
|
---|
| 544 | msflag = TRUE; /* indicate the mouse has started moving */
|
---|
[7258c6a] | 545 | }
|
---|
[f40a309] | 546 |
|
---|
| 547 | /* |
---|
| 548 |
|
---|
| 549 | */
|
---|
| 550 |
|
---|
| 551 | /*
|
---|
| 552 | =============================================================================
|
---|
| 553 | MouseIN() -- process a byte from the mouse
|
---|
| 554 | =============================================================================
|
---|
| 555 | */
|
---|
| 556 |
|
---|
| 557 | void MouseIN(int16_t c)
|
---|
| 558 | {
|
---|
| 559 | c &= 0x00FF; /* mask off extraneous bits from mouse input */
|
---|
| 560 |
|
---|
| 561 | #if DEBUGMS
|
---|
| 562 | if (debugms > 2)
|
---|
| 563 | printf("IN %d %02.2X\n", M_state, c);
|
---|
| 564 | #endif
|
---|
| 565 |
|
---|
| 566 | if ((M_state GE 0) AND (M_state < 3)) {
|
---|
| 567 |
|
---|
| 568 | M_strng[M_state] = c;
|
---|
| 569 |
|
---|
| 570 | if (M_state EQ 2) {
|
---|
| 571 |
|
---|
| 572 | MouseEX(M_strng);
|
---|
| 573 | M_state = 0;
|
---|
| 574 |
|
---|
| 575 | } else {
|
---|
| 576 |
|
---|
| 577 | ++M_state;
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | /* |
---|
| 583 |
|
---|
| 584 | */
|
---|
| 585 |
|
---|
| 586 | #if DEBUGTF
|
---|
| 587 | /*
|
---|
| 588 | =============================================================================
|
---|
| 589 | tfdump() -- dump a trackball FIFO
|
---|
| 590 | =============================================================================
|
---|
| 591 | */
|
---|
| 592 |
|
---|
| 593 | tfdump(msg, fifo, ndx, fin, cnt)
|
---|
| 594 | char *msg;
|
---|
| 595 | register short *fifo, ndx, fin;
|
---|
| 596 | long cnt;
|
---|
| 597 | {
|
---|
| 598 | register short nol = 0, i = fin, j = fin - 1;
|
---|
| 599 |
|
---|
| 600 | printf("Dump of %s FIFO\n", msg);
|
---|
| 601 | printf(" ndx=%d fin=%d cnt=%ld\n", ndx, fin, cnt);
|
---|
| 602 |
|
---|
| 603 | if (j < 0)
|
---|
| 604 | j = NTKFIFO - 1;
|
---|
| 605 |
|
---|
| 606 | do {
|
---|
| 607 |
|
---|
| 608 | if (nol EQ 0)
|
---|
| 609 | printf(" ");
|
---|
| 610 |
|
---|
| 611 | if (i EQ ndx)
|
---|
[9519422] | 612 | printf("<%2d ", fifo[i]);
|
---|
[f40a309] | 613 | else if (i EQ j)
|
---|
| 614 | printf(" %2d> ", fifo[i]);
|
---|
| 615 | else
|
---|
| 616 | printf(" %2d ", fifo[i]);
|
---|
| 617 |
|
---|
| 618 | if (++nol GE 15) {
|
---|
| 619 |
|
---|
| 620 | printf("\n");
|
---|
| 621 | nol = 0;
|
---|
| 622 | }
|
---|
| 623 |
|
---|
| 624 | if (++i GE NTKFIFO)
|
---|
| 625 | i = 0;
|
---|
| 626 |
|
---|
| 627 | } while (i NE fin);
|
---|
| 628 |
|
---|
| 629 | if (nol)
|
---|
| 630 | printf("\n");
|
---|
| 631 |
|
---|
[0580615] | 632 | printf("\n");
|
---|
[f40a309] | 633 | }
|
---|
[7258c6a] | 634 | #endif
|
---|
[f40a309] | 635 |
|
---|
| 636 | /* |
---|
| 637 |
|
---|
| 638 | */
|
---|
| 639 |
|
---|
| 640 | /*
|
---|
| 641 | =============================================================================
|
---|
| 642 | wheel() -- process inputs from the scroll wheel
|
---|
| 643 | =============================================================================
|
---|
| 644 | */
|
---|
| 645 |
|
---|
| 646 | void wheel(void)
|
---|
| 647 | {
|
---|
| 648 | register int16_t i, oldi;
|
---|
| 649 |
|
---|
| 650 | if (astat) { /* if it's touched ... */
|
---|
| 651 |
|
---|
| 652 | if (NOT swflag) {
|
---|
| 653 |
|
---|
| 654 | /* GOING DOWN */
|
---|
| 655 |
|
---|
| 656 | swflag = TRUE;
|
---|
| 657 | swctrl = FALSE;
|
---|
| 658 | swfiin = 0;
|
---|
| 659 | swlast = aval;
|
---|
| 660 | swstop = swwait;
|
---|
| 661 | swcount = 0;
|
---|
| 662 |
|
---|
| 663 | for (i = 0; i < NSWFIFO; i++)
|
---|
| 664 | swfifo[i] = aval;
|
---|
| 665 | /* |
---|
| 666 |
|
---|
| 667 | */
|
---|
| 668 | } else { /* finger moved */
|
---|
| 669 |
|
---|
| 670 | if (0 EQ swstop) {
|
---|
| 671 |
|
---|
| 672 | swdelta = swlast - aval;
|
---|
| 673 |
|
---|
| 674 | if (swdelta GE swthr) {
|
---|
| 675 |
|
---|
| 676 | if ((clkctl EQ CK_STEP) OR
|
---|
| 677 | ((clkctl NE CK_STEP) AND
|
---|
| 678 | (NOT clkrun))) {
|
---|
| 679 |
|
---|
| 680 | /* FINGER MOVED LEFT */
|
---|
| 681 |
|
---|
| 682 | swtemp = swdelta / swthr;
|
---|
| 683 | oldi = setipl(TIM_DI);
|
---|
| 684 | fc_val += swtemp;
|
---|
| 685 |
|
---|
| 686 | if (fc_val GE 0x00FFFFFFL)
|
---|
| 687 | fc_val = 0x00FFFFFFL;
|
---|
| 688 |
|
---|
| 689 | setipl(oldi);
|
---|
| 690 | swlast = aval;
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | } else if ((swdelta = abs(swdelta)) GE swthr) {
|
---|
| 694 |
|
---|
| 695 | if ((clkctl EQ CK_STEP) OR
|
---|
| 696 | ((clkctl NE CK_STEP) AND
|
---|
| 697 | (NOT clkrun))) {
|
---|
| 698 |
|
---|
| 699 | /* FINGER MOVED RIGHT */
|
---|
| 700 |
|
---|
| 701 | swtemp = swdelta / swthr;
|
---|
| 702 | oldi = setipl(TIM_DI);
|
---|
| 703 | fc_val -= swtemp;
|
---|
| 704 |
|
---|
| 705 | if (fc_val LT 0L)
|
---|
| 706 | fc_val = 0L;
|
---|
| 707 |
|
---|
| 708 | setipl(oldi);
|
---|
| 709 | swlast = aval;
|
---|
| 710 | }
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | } else {
|
---|
| 714 |
|
---|
| 715 | swlast = aval;
|
---|
| 716 | --swstop;
|
---|
| 717 | }
|
---|
| 718 | }
|
---|
| 719 | /* |
---|
| 720 |
|
---|
| 721 | */
|
---|
| 722 | } else { /* FINGER UP */
|
---|
| 723 |
|
---|
| 724 | swlast = aval;
|
---|
| 725 | swflag = FALSE;
|
---|
| 726 | swctrl = FALSE;
|
---|
| 727 |
|
---|
| 728 | if ((clkctl EQ CK_STEP) OR
|
---|
| 729 | ((clkctl NE CK_STEP) AND
|
---|
| 730 | (NOT clkrun))) {
|
---|
| 731 |
|
---|
| 732 | swndx = swfiin - swback;
|
---|
| 733 |
|
---|
| 734 | if (swndx < 0)
|
---|
| 735 | swndx += NSWFIFO;
|
---|
| 736 |
|
---|
| 737 | swrate = swfifo[swndx] - swlast;
|
---|
| 738 |
|
---|
| 739 | if (swrate > swrmin) {
|
---|
| 740 |
|
---|
| 741 | swdir = D_FWD; /* SCROLL FORWARD */
|
---|
| 742 | swrate = swrtab[swrate - swrmin];
|
---|
| 743 | swctrl = TRUE;
|
---|
| 744 |
|
---|
| 745 | } else if ((swrate = abs(swrate)) > swrmin) {
|
---|
| 746 |
|
---|
| 747 | swdir = D_BAK; /* SCROLL BACKWARD */
|
---|
| 748 | swrate = swrtab[swrate - swrmin];
|
---|
| 749 | swctrl = TRUE;
|
---|
| 750 |
|
---|
| 751 | } else {
|
---|
[0580615] | 752 |
|
---|
[f40a309] | 753 | swrate = 0L; /* STOP SCROLLING */
|
---|
[7258c6a] | 754 | }
|
---|
[f40a309] | 755 | }
|
---|
| 756 | }
|
---|
| 757 | }
|
---|
| 758 |
|
---|
| 759 | /* |
---|
| 760 |
|
---|
| 761 | */
|
---|
| 762 |
|
---|
| 763 | /*
|
---|
| 764 | =============================================================================
|
---|
| 765 | txyup() -- process trackball -- both axes inactive
|
---|
| 766 | =============================================================================
|
---|
| 767 | */
|
---|
| 768 |
|
---|
| 769 | void txyup(void)
|
---|
| 770 | {
|
---|
| 771 | register int16_t txndx, tyndx, txrate, tyrate;
|
---|
| 772 |
|
---|
| 773 | #if DEBUGTF
|
---|
| 774 | if (debugtf)
|
---|
| 775 | printf("txyup(): both inactive\n");
|
---|
| 776 | #endif
|
---|
| 777 |
|
---|
| 778 | tkboth = FALSE; /* both axes inactive now */
|
---|
| 779 |
|
---|
| 780 | txdiv = 0; /* reset text cursor dividers */
|
---|
| 781 | tydiv = 0;
|
---|
| 782 |
|
---|
| 783 | if ((txndx = txfiin - tkback) < 0) /* get fifo index */
|
---|
| 784 | txndx += NTKFIFO; /* adjust index */
|
---|
| 785 |
|
---|
| 786 | txrate = txfifo[txndx] - txlast; /* get movement */
|
---|
| 787 |
|
---|
| 788 | #if DEBUGTF
|
---|
| 789 | if (debugtf)
|
---|
| 790 | tfdump("X", txfifo, txndx, txfiin, txficnt);
|
---|
| 791 | #endif
|
---|
| 792 |
|
---|
| 793 | if (txrate GE tkrmin)
|
---|
| 794 | cxrate = -cratex[txrate - tkrmin]; /* tracking left */
|
---|
| 795 | else if ((txrate = abs(txrate)) GE tkrmin)
|
---|
| 796 | cxrate = cratex[txrate - tkrmin]; /* tracking right */
|
---|
| 797 | else
|
---|
| 798 | cxrate = 0; /* X inactive */
|
---|
| 799 |
|
---|
| 800 | /* |
---|
| 801 |
|
---|
| 802 | */
|
---|
| 803 | if ((tyndx = tyfiin - tkback) < 0) /* get fifo index */
|
---|
| 804 | tyndx += NTKFIFO; /* adjust index */
|
---|
| 805 |
|
---|
| 806 | tyrate = tyfifo[tyndx] - tylast; /* get movement */
|
---|
| 807 |
|
---|
| 808 | #if DEBUGTF
|
---|
| 809 | if (debugtf)
|
---|
| 810 | tfdump("Y", tyfifo, tyndx, tyfiin, tyficnt);
|
---|
| 811 | #endif
|
---|
| 812 |
|
---|
| 813 | if (tyrate GE tkrmin)
|
---|
| 814 | cyrate = cratey[tyrate - tkrmin]; /* tracking down */
|
---|
| 815 | else if ((tyrate = abs(tyrate)) GE tkrmin)
|
---|
| 816 | cyrate = -cratey[tyrate - tkrmin]; /* tracking up */
|
---|
| 817 | else
|
---|
| 818 | cyrate = 0; /* Y inactive */
|
---|
| 819 |
|
---|
| 820 | if ((cxrate EQ 0) AND (cyrate EQ 0)) {
|
---|
| 821 |
|
---|
| 822 | tkctrl = FALSE; /* STOP -- both rates are zero */
|
---|
| 823 | (*xy_up)();
|
---|
| 824 |
|
---|
| 825 | } else {
|
---|
| 826 |
|
---|
| 827 | tkctrl = TRUE; /* ROLL -- some rate is non-zero */
|
---|
| 828 | }
|
---|
[0580615] | 829 |
|
---|
[f40a309] | 830 | #if DEBUGTK
|
---|
[7258c6a] | 831 | if (debugtk)
|
---|
[f40a309] | 832 | printf("txyup(): %s rmin=%d txr=%d cxr=%d tyr=%d cyr=%d\n",
|
---|
| 833 | tkctrl ? "ROLL" : "STOP", tkrmin, txrate, cxrate, tyrate, cyrate);
|
---|
| 834 | #endif
|
---|
| 835 |
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | /* |
---|
| 839 |
|
---|
| 840 | */
|
---|
| 841 |
|
---|
| 842 | /*
|
---|
| 843 | =============================================================================
|
---|
| 844 | txydn() -- process trackball -- both axes active
|
---|
| 845 | =============================================================================
|
---|
| 846 | */
|
---|
| 847 |
|
---|
| 848 | void txydn(void)
|
---|
| 849 | {
|
---|
| 850 | register int16_t i;
|
---|
| 851 |
|
---|
| 852 | #if DEBUGTK
|
---|
| 853 | if (debugtk)
|
---|
| 854 | printf("txydn(): both active txlast=%d tylast=%d\n",
|
---|
| 855 | txlast, tylast);
|
---|
| 856 | #endif
|
---|
| 857 |
|
---|
| 858 | tkboth = TRUE; /* both down now */
|
---|
| 859 | (*xy_dn)();
|
---|
| 860 |
|
---|
| 861 | tkctrl = FALSE; /* stop rolling */
|
---|
| 862 | cxrate = 0;
|
---|
| 863 | cyrate = 0;
|
---|
| 864 |
|
---|
| 865 | txfiin = 0; /* preset the FIFOs */
|
---|
| 866 | tyfiin = 0;
|
---|
| 867 |
|
---|
| 868 | for (i = 0; i < NTKFIFO; i++) {
|
---|
| 869 |
|
---|
[0580615] | 870 | txfifo[i] = txlast;
|
---|
[f40a309] | 871 | tyfifo[i] = tylast;
|
---|
[7258c6a] | 872 | }
|
---|
[f40a309] | 873 |
|
---|
| 874 | #if DEBUGTF
|
---|
| 875 | txficnt = 0;
|
---|
| 876 | tyficnt = 0;
|
---|
| 877 | #endif
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | /* |
---|
| 881 |
|
---|
| 882 | */
|
---|
| 883 |
|
---|
| 884 | /*
|
---|
| 885 | =============================================================================
|
---|
| 886 | txstd() -- process inputs from the trackball X axis
|
---|
| 887 | =============================================================================
|
---|
| 888 | */
|
---|
| 889 |
|
---|
| 890 | void txstd(void)
|
---|
| 891 | {
|
---|
| 892 | register int16_t i, oldcx, oldi, txdelta, txcdvr;
|
---|
| 893 |
|
---|
| 894 | trkball = TRUE; /* set trackball mode */
|
---|
| 895 | cmfirst = FALSE;
|
---|
| 896 | chtime = tktime;
|
---|
| 897 | nchwait = tktime;
|
---|
| 898 | chwait = tktime;
|
---|
| 899 |
|
---|
| 900 |
|
---|
| 901 | /* get rate divisor */
|
---|
| 902 |
|
---|
| 903 | txcdvr = (cmtype EQ CT_GRAF) ? tkthr : tkhdvr;
|
---|
| 904 |
|
---|
| 905 | if (astat) { /* is axis active ? */
|
---|
| 906 |
|
---|
| 907 | if (NOT txflag) {
|
---|
| 908 |
|
---|
| 909 | /* GOING ACTIVE */
|
---|
| 910 |
|
---|
| 911 | txflag = TRUE;
|
---|
| 912 | txstop = tkwait;
|
---|
| 913 | txlast = aval;
|
---|
| 914 |
|
---|
| 915 | if (tyflag AND (NOT tkboth))
|
---|
| 916 | txydn(); /* both active now */
|
---|
| 917 |
|
---|
| 918 | /* |
---|
| 919 |
|
---|
| 920 | */
|
---|
| 921 | } else { /* finger moved ? */
|
---|
| 922 |
|
---|
| 923 | if (txstop LE 0) { /* debounced ? */
|
---|
| 924 |
|
---|
| 925 | txdelta = txlast - aval;
|
---|
| 926 | oldcx = cxval;
|
---|
| 927 |
|
---|
| 928 | if (txdelta GE txcdvr) {
|
---|
| 929 |
|
---|
| 930 | /* FINGER MOVED LEFT */
|
---|
| 931 |
|
---|
| 932 | cxrate = -(txdelta / txcdvr);
|
---|
| 933 |
|
---|
| 934 | (*cx_upd)(); /* update cxval */
|
---|
| 935 |
|
---|
| 936 | if (oldcx NE cxval) /* new cxval ? */
|
---|
| 937 | (*curmove)(); /* move cursor */
|
---|
| 938 |
|
---|
| 939 | txlast = aval;
|
---|
| 940 | cxrate = 0;
|
---|
| 941 |
|
---|
| 942 | } else if ((txdelta = abs(txdelta)) GE txcdvr) {
|
---|
| 943 |
|
---|
| 944 | /* FINGER MOVED RIGHT */
|
---|
| 945 |
|
---|
| 946 | cxrate = txdelta / txcdvr;
|
---|
| 947 |
|
---|
| 948 | (*cx_upd)(); /* update cxval */
|
---|
| 949 |
|
---|
| 950 | if (oldcx NE cxval) /* new cxval ? */
|
---|
| 951 | (*curmove)(); /* move cursor */
|
---|
| 952 |
|
---|
| 953 | txlast = aval;
|
---|
| 954 | cxrate = 0;
|
---|
| 955 | }
|
---|
| 956 |
|
---|
| 957 | } else { /* debounce data */
|
---|
| 958 |
|
---|
| 959 | txlast = aval;
|
---|
| 960 | --txstop;
|
---|
| 961 | }
|
---|
| 962 | }
|
---|
[0580615] | 963 | /* |
---|
[f40a309] | 964 |
|
---|
[7258c6a] | 965 | */
|
---|
[f40a309] | 966 | } else { /* AXIS GOING INACTIVE */
|
---|
| 967 |
|
---|
| 968 | txlast = aval; /* get current value */
|
---|
| 969 | txflag = FALSE; /* X axis inactive */
|
---|
| 970 |
|
---|
| 971 | if (NOT tyflag) /* check other axis */
|
---|
| 972 | txyup(); /* both inactive now */
|
---|
| 973 | }
|
---|
| 974 | }
|
---|
| 975 |
|
---|
| 976 | /* |
---|
| 977 |
|
---|
| 978 | */
|
---|
| 979 |
|
---|
| 980 | /*
|
---|
| 981 | =============================================================================
|
---|
| 982 | tystd() -- process inputs from the trackball Y axis
|
---|
| 983 | =============================================================================
|
---|
| 984 | */
|
---|
| 985 |
|
---|
| 986 | void tystd(void)
|
---|
| 987 | {
|
---|
| 988 | register int16_t i, oldcy, oldi, tydelta, tycdvr;
|
---|
| 989 |
|
---|
| 990 | trkball = TRUE; /* set trackball mode */
|
---|
| 991 | cmfirst = FALSE;
|
---|
| 992 | cvtime = tktime;
|
---|
| 993 | ncvwait = tktime;
|
---|
| 994 | cvwait = tktime;
|
---|
| 995 |
|
---|
| 996 | /* get rate divisor */
|
---|
| 997 |
|
---|
| 998 | tycdvr = (cmtype EQ CT_GRAF) ? tkthr : tkvdvr;
|
---|
| 999 |
|
---|
| 1000 | if (astat) { /* if axis active ? */
|
---|
| 1001 |
|
---|
| 1002 | if (NOT tyflag) {
|
---|
| 1003 |
|
---|
| 1004 | /* GOING ACTIVE */
|
---|
| 1005 |
|
---|
| 1006 | tyflag = TRUE;
|
---|
| 1007 | tystop = tkwait;
|
---|
| 1008 | tylast = aval;
|
---|
| 1009 |
|
---|
| 1010 | if (txflag AND (NOT tkboth))
|
---|
| 1011 | txydn(); /* both active now */
|
---|
| 1012 | /* |
---|
| 1013 |
|
---|
| 1014 | */
|
---|
| 1015 | } else { /* finger moved ? */
|
---|
| 1016 |
|
---|
| 1017 | if (tystop LE 0) { /* debounced ? */
|
---|
| 1018 |
|
---|
| 1019 | tydelta = tylast - aval;
|
---|
| 1020 | oldcy = cyval;
|
---|
| 1021 |
|
---|
| 1022 | if (tydelta GE tycdvr) {
|
---|
| 1023 |
|
---|
| 1024 | /* FINGER MOVED DOWN */
|
---|
| 1025 |
|
---|
| 1026 | cyrate = tydelta / tycdvr;
|
---|
| 1027 |
|
---|
| 1028 | (*cy_upd)(); /* update cyval */
|
---|
| 1029 |
|
---|
| 1030 | if (oldcy NE cyval) /* new cyval ? */
|
---|
| 1031 | (*curmove)(); /* move cursor */
|
---|
| 1032 |
|
---|
| 1033 | tylast = aval;
|
---|
| 1034 | cyrate = 0;
|
---|
| 1035 |
|
---|
| 1036 | } else if ((tydelta = abs(tydelta)) GE tycdvr) {
|
---|
| 1037 |
|
---|
| 1038 | /* FINGER MOVED UP */
|
---|
| 1039 |
|
---|
| 1040 | cyrate = -(tydelta / tycdvr);
|
---|
| 1041 |
|
---|
| 1042 | (*cy_upd)(); /* udpate cyval */
|
---|
| 1043 |
|
---|
| 1044 | if (oldcy NE cyval) /* new cyval ? */
|
---|
| 1045 | (*curmove)(); /* move cursor */
|
---|
| 1046 |
|
---|
| 1047 | tylast = aval;
|
---|
| 1048 | cyrate = 0;
|
---|
| 1049 | }
|
---|
| 1050 |
|
---|
| 1051 | } else { /* debounce data */
|
---|
| 1052 |
|
---|
| 1053 | tylast = aval;
|
---|
[0580615] | 1054 | --tystop;
|
---|
[f40a309] | 1055 | }
|
---|
[7258c6a] | 1056 | }
|
---|
| 1057 | /* |
---|
| 1058 |
|
---|
[f40a309] | 1059 | */
|
---|
| 1060 | } else { /* AXIS GOING INACTIVE */
|
---|
| 1061 |
|
---|
| 1062 | tylast = aval; /* get current value */
|
---|
| 1063 | tyflag = FALSE; /* Y axis inactive */
|
---|
| 1064 |
|
---|
| 1065 | if (NOT txflag) /* check other axis */
|
---|
| 1066 | txyup(); /* both inactive now */
|
---|
| 1067 | }
|
---|
| 1068 | }
|
---|
| 1069 |
|
---|
| 1070 | /* |
---|
| 1071 |
|
---|
| 1072 | */
|
---|
| 1073 |
|
---|
| 1074 | /*
|
---|
| 1075 | =============================================================================
|
---|
| 1076 | curproc() -- process cursor trackball and scroll wheel updates
|
---|
| 1077 | =============================================================================
|
---|
| 1078 | */
|
---|
| 1079 |
|
---|
| 1080 | void curproc(void)
|
---|
| 1081 | {
|
---|
| 1082 | register int16_t i, cxprev, cyprev;
|
---|
| 1083 | int16_t oldcx, oldcy;
|
---|
| 1084 | register uint16_t oldi;
|
---|
| 1085 |
|
---|
| 1086 | /* SET CURRENT WAIT COUNTS FROM TIMERS */
|
---|
| 1087 |
|
---|
| 1088 | chwait = timers[TXTIMER];
|
---|
| 1089 | cvwait = timers[TYTIMER];
|
---|
| 1090 |
|
---|
| 1091 | if (trkball) { /* are we tracking ? */
|
---|
| 1092 |
|
---|
| 1093 | if (txflag AND (chwait LE 0)) {
|
---|
| 1094 |
|
---|
| 1095 | /* SAMPLE THE TRACKBALL X AXIS */
|
---|
| 1096 |
|
---|
| 1097 | txfifo[txfiin] = sigtab[55][0];
|
---|
| 1098 |
|
---|
| 1099 | #if DEBUGTF
|
---|
| 1100 | ++txficnt;
|
---|
[7258c6a] | 1101 | #endif
|
---|
[f40a309] | 1102 |
|
---|
| 1103 | if (++txfiin GE NTKFIFO)
|
---|
| 1104 | txfiin = 0;
|
---|
| 1105 | }
|
---|
| 1106 |
|
---|
| 1107 | if (tyflag AND (cvwait LE 0)) {
|
---|
| 1108 |
|
---|
| 1109 | /* SAMPLE THE TRACKBALL Y AXIS */
|
---|
| 1110 |
|
---|
| 1111 | tyfifo[tyfiin] = sigtab[56][0];
|
---|
| 1112 |
|
---|
| 1113 | #if DEBUGTF
|
---|
| 1114 | ++tyficnt;
|
---|
| 1115 | #endif
|
---|
| 1116 |
|
---|
| 1117 | if (++tyfiin GE NTKFIFO)
|
---|
| 1118 | tyfiin = 0;
|
---|
| 1119 | }
|
---|
| 1120 | }
|
---|
| 1121 | /* |
---|
| 1122 |
|
---|
| 1123 | */
|
---|
| 1124 | /* PROCESS MOUSE INPUTS */
|
---|
| 1125 |
|
---|
| 1126 | if (BIOS(B_RDAV, PRT_DEV)) {
|
---|
| 1127 |
|
---|
| 1128 | MouseIN((int16_t)BIOS(B_GETC, PRT_DEV));
|
---|
| 1129 |
|
---|
| 1130 | MouseRT(MATIME); /* reset mouse activity timer */
|
---|
| 1131 | }
|
---|
| 1132 |
|
---|
| 1133 | /* PROCESS THE CURSORS */
|
---|
| 1134 |
|
---|
| 1135 | if (cvwait LE 0) { /* has the vertical timer run out ? */
|
---|
| 1136 |
|
---|
| 1137 | if (ss_ptsw) /* see if the patches need scrolled */
|
---|
| 1138 | smy_up(ss_ptsw); /* scroll the patch display */
|
---|
| 1139 |
|
---|
| 1140 | if (ss_sqsw) /* see if the sequences need scrolled */
|
---|
| 1141 | sqy_up(ss_sqsw); /* scroll the sequence display */
|
---|
| 1142 | }
|
---|
| 1143 |
|
---|
| 1144 | if (msctrl OR /* is the mouse moving ? */
|
---|
| 1145 | (cvwait LE 0) OR (chwait LE 0)) { /* has X or Y timer runout ? */
|
---|
| 1146 |
|
---|
| 1147 | if (msctrl OR tkctrl OR (xkstat AND ykstat)) { /* cursor moving ? */
|
---|
| 1148 |
|
---|
| 1149 | oldcx = cxrate; /* save old cxrate, cyrate */
|
---|
| 1150 | oldcy = cyrate;
|
---|
| 1151 | cxprev = cxval; /* save old cxval, cyval */
|
---|
| 1152 | cyprev = cyval;
|
---|
| 1153 | vtprow = vtcrow; /* save old vtrow, vtcol */
|
---|
| 1154 | vtpcol = vtccol;
|
---|
| 1155 |
|
---|
| 1156 | if (NOT msctrl) /* if it's not the mouse ... */
|
---|
| 1157 | cmfix(); /* ... adjust the rates */
|
---|
| 1158 |
|
---|
| 1159 | /* |
---|
| 1160 |
|
---|
| 1161 | */
|
---|
| 1162 | if ((cxrate NE 0) AND (msctrl OR (chwait LE 0))) /* UPDATE X VALUES */
|
---|
| 1163 | (*cx_upd)();
|
---|
| 1164 |
|
---|
| 1165 | if ((cyrate NE 0) AND (msctrl OR (cvwait LE 0))) /* UPDATE Y VALUES */
|
---|
| 1166 | (*cy_upd)();
|
---|
| 1167 |
|
---|
| 1168 | cxrate = oldcx;
|
---|
| 1169 | cyrate = oldcy;
|
---|
| 1170 |
|
---|
| 1171 | /* see if cursor should be moved */
|
---|
| 1172 |
|
---|
| 1173 | if ( (cxprev NE cxval) OR (cyprev NE cyval) OR
|
---|
| 1174 | (vtprow NE vtcrow) OR (vtpcol NE vtccol) ) {
|
---|
| 1175 |
|
---|
| 1176 | (*curmove)(); /* MOVE CURSOR */
|
---|
| 1177 |
|
---|
| 1178 | if (ebflag) { /* FIXUP EDIT BUFFER */
|
---|
| 1179 |
|
---|
| 1180 | if ((struct fet *)NULL NE curfet) {
|
---|
| 1181 |
|
---|
| 1182 | if (infield(stcrow, stccol, curfet)) {
|
---|
| 1183 |
|
---|
| 1184 | if ((cfetp NE NULL) AND
|
---|
| 1185 | (cfetp NE infetp)) {
|
---|
| 1186 |
|
---|
| 1187 | (*cfetp->redisp)(cfetp->ftags);
|
---|
| 1188 | ebflag = FALSE;
|
---|
| 1189 | }
|
---|
| 1190 |
|
---|
| 1191 | } else { /* isn't in a field */
|
---|
| 1192 |
|
---|
| 1193 | if (cfetp NE NULL)
|
---|
| 1194 | (*cfetp->redisp)(cfetp->ftags);
|
---|
| 1195 |
|
---|
| 1196 | ebflag = FALSE;
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | } else { /* no fet, no field */
|
---|
| 1200 |
|
---|
| 1201 | ebflag = FALSE;
|
---|
| 1202 | }
|
---|
| 1203 | }
|
---|
| 1204 | }
|
---|
| 1205 | }
|
---|
| 1206 | }
|
---|
| 1207 | /* |
---|
| 1208 |
|
---|
| 1209 | */
|
---|
| 1210 | /* CHECK THE MOUSE MOTION TIMER */
|
---|
| 1211 |
|
---|
| 1212 | if (msflag AND (0 EQ timers[MSTIMER])) {
|
---|
| 1213 |
|
---|
| 1214 | (*xy_up)(); /* indicate key up */
|
---|
| 1215 |
|
---|
| 1216 | msflag = FALSE; /* indicate mouse stopped */
|
---|
| 1217 | }
|
---|
| 1218 |
|
---|
| 1219 | msctrl = FALSE; /* indicate mouse movement processed */
|
---|
| 1220 |
|
---|
| 1221 |
|
---|
| 1222 | /* CHECK THE MOUSE ACTIVITY TIMER */
|
---|
| 1223 |
|
---|
| 1224 | if (0 EQ timers[MUTIMER]) {
|
---|
| 1225 |
|
---|
| 1226 | if (M_state)
|
---|
| 1227 | if (MouseFL(M_FL_CT))
|
---|
| 1228 | M_error = M_FLUSH;
|
---|
| 1229 |
|
---|
| 1230 | M_state = 0;
|
---|
| 1231 | MouseRT(MATIME);
|
---|
| 1232 |
|
---|
| 1233 | #if DEBUGMS
|
---|
| 1234 | if (debugms > 1)
|
---|
| 1235 | printf("MRESET\n");
|
---|
| 1236 | #endif
|
---|
| 1237 | }
|
---|
| 1238 |
|
---|
| 1239 | /* |
---|
| 1240 |
|
---|
| 1241 | */
|
---|
| 1242 | /* UPDATE THE CURSOR TIMERS */
|
---|
| 1243 |
|
---|
| 1244 | if (cvwait LE 0) { /* reset vertical timer */
|
---|
| 1245 |
|
---|
| 1246 | cvwait = ncvwait;
|
---|
| 1247 | ncvwait = cvtime;
|
---|
| 1248 |
|
---|
| 1249 | oldi = setipl(TIM_DI);
|
---|
| 1250 | timers[TYTIMER] = cvwait;
|
---|
| 1251 | setipl(oldi);
|
---|
| 1252 | }
|
---|
| 1253 |
|
---|
| 1254 |
|
---|
| 1255 | if (chwait LE 0) { /* reset horizontal timer */
|
---|
| 1256 |
|
---|
| 1257 | chwait = nchwait;
|
---|
| 1258 | nchwait = chtime;
|
---|
| 1259 |
|
---|
| 1260 | oldi = setipl(TIM_DI);
|
---|
| 1261 | timers[TXTIMER] = chwait;
|
---|
| 1262 | setipl(oldi);
|
---|
| 1263 | }
|
---|
| 1264 | /* |
---|
| 1265 |
|
---|
| 1266 | */
|
---|
| 1267 | /* PROCESS THE SCROLL WHEEL */
|
---|
| 1268 |
|
---|
| 1269 | if (0 EQ timers[SWTIMER]) { /* is it time ? */
|
---|
| 1270 |
|
---|
| 1271 | if (swflag) { /* SAMPLE THE SCROLL WHEEL */
|
---|
| 1272 |
|
---|
| 1273 | swfifo[swfiin] = sigtab[59][0];
|
---|
| 1274 |
|
---|
| 1275 | if (++swfiin GE NSWFIFO)
|
---|
| 1276 | swfiin = 0;
|
---|
| 1277 | }
|
---|
| 1278 |
|
---|
| 1279 | if (swctrl) { /* SCROLL ... */
|
---|
| 1280 |
|
---|
| 1281 | swtemp = swcount + swrate;
|
---|
| 1282 | swcount = swtemp & 0x0000FFFFL;
|
---|
| 1283 | swtemp >>= 16;
|
---|
| 1284 |
|
---|
| 1285 | if (swdir EQ D_FWD) { /* ... FORWARD */
|
---|
| 1286 |
|
---|
| 1287 | oldi = setipl(TIM_DI);
|
---|
| 1288 | fc_val += swtemp;
|
---|
| 1289 |
|
---|
| 1290 | if (fc_val GE 0x00FFFFFFL) {
|
---|
| 1291 |
|
---|
| 1292 | swctrl = FALSE;
|
---|
| 1293 | fc_val = 0x00FFFFFFL;
|
---|
| 1294 | }
|
---|
| 1295 |
|
---|
| 1296 | setipl(oldi);
|
---|
| 1297 |
|
---|
| 1298 | } else { /* ... BACKWARD */
|
---|
| 1299 |
|
---|
| 1300 | oldi = setipl(TIM_DI);
|
---|
[0580615] | 1301 | fc_val -= swtemp;
|
---|
[f40a309] | 1302 |
|
---|
| 1303 | if (fc_val < 0) {
|
---|
| 1304 |
|
---|
| 1305 | swctrl = FALSE;
|
---|
| 1306 | fc_val = 0L;
|
---|
| 1307 | }
|
---|
| 1308 |
|
---|
| 1309 | setipl(oldi);
|
---|
| 1310 | }
|
---|
| 1311 | }
|
---|
| 1312 | /* |
---|
| 1313 |
|
---|
| 1314 | */
|
---|
[6262b5c] | 1315 | if (swflag OR swctrl) { /* RESET THE SCROLL TIMER */
|
---|
| 1316 |
|
---|
| 1317 | oldi = setipl(TIM_DI);
|
---|
| 1318 | timers[SWTIMER] = swtime;
|
---|
| 1319 | setipl(oldi);
|
---|
| 1320 | }
|
---|
| 1321 | }
|
---|
| 1322 | }
|
---|
| 1323 |
|
---|
| 1324 | /* |
---|
| 1325 |
|
---|
| 1326 | */
|
---|
| 1327 |
|
---|
| 1328 | /*
|
---|
| 1329 | =============================================================================
|
---|
| 1330 | tkinit() -- initialize trackball variables
|
---|
| 1331 | =============================================================================
|
---|
| 1332 | */
|
---|
| 1333 |
|
---|
| 1334 | void tkinit(void)
|
---|
| 1335 | {
|
---|
| 1336 | trkball = FALSE; /* stop the trackball */
|
---|
| 1337 | txflag = FALSE; /* ... */
|
---|
| 1338 | tyflag = FALSE; /* ... */
|
---|
| 1339 | tkctrl = FALSE; /* ... */
|
---|
| 1340 | tkboth = FALSE; /* ... */
|
---|
| 1341 |
|
---|
| 1342 | memsetw(txfifo, 0, NTKFIFO); /* clear trackball X fifo */
|
---|
| 1343 | txfiin = 0; /* ... */
|
---|
| 1344 |
|
---|
| 1345 | memsetw(tyfifo, 0, NTKFIFO); /* clear trackball Y fifo */
|
---|
| 1346 | tyfiin = 0; /* ... */
|
---|
| 1347 | }
|
---|
| 1348 |
|
---|