source: buchla-68k/orig/RAM/WHEEL.C@ 7bf3856

Last change on this file since 7bf3856 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

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