source: buchla-68k/ram/wheel.c@ 411371e

Last change on this file since 411371e was 411371e, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Removed redundant declarations.

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