source: buchla-68k/ram/wheel.c@ 0c834c5

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

Prototypes for global function pointers. Consistent global types.

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