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

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

Zero redundant declarations.

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