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