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