1 | /*
|
---|
2 | ============================================================================
|
---|
3 | setwq.c -- word queue functions
|
---|
4 | Version 1 -- 1988-11-02 -- D.N. Lynx Crowe
|
---|
5 | ============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define WORDQHDR /* so wordq.h gets it right */
|
---|
9 |
|
---|
10 | #include "ram.h"
|
---|
11 |
|
---|
12 | /*
|
---|
13 | ============================================================================
|
---|
14 | setwq(qp, qadr, qsiz, hi, lo) -- setup a word queue
|
---|
15 |
|
---|
16 | Where:
|
---|
17 |
|
---|
18 | struct wordq *qp queue structure pointer
|
---|
19 | unsigned short *qadr queue buffer pointer
|
---|
20 | unsigned short qsiz maximum length of queue
|
---|
21 | unsigned short hi high water mark count
|
---|
22 | unsigned short lo low water mark count
|
---|
23 |
|
---|
24 | Return value:
|
---|
25 |
|
---|
26 | unsigned short qsiz size of queue
|
---|
27 | ============================================================================
|
---|
28 | */
|
---|
29 |
|
---|
30 | int16_t setwq(struct wordq *qp, uint16_t *qadr, int16_t qsiz, int16_t hi, int16_t lo)
|
---|
31 | {
|
---|
32 | if ((uint16_t *)0L EQ qadr)
|
---|
33 | qsiz = 0;
|
---|
34 |
|
---|
35 | qp->qbuf = qadr;
|
---|
36 | qp->qsize = qsiz;
|
---|
37 | qp->qlen = 0;
|
---|
38 | qp->qin = 0;
|
---|
39 | qp->qout = 0;
|
---|
40 | qp->qhi = hi;
|
---|
41 | qp->qlo = lo;
|
---|
42 |
|
---|
43 | return(qsiz);
|
---|
44 | }
|
---|
45 |
|
---|
46 | /*
|
---|
47 | ============================================================================
|
---|
48 | putwq(qp, c) -- put a word in a word queue
|
---|
49 |
|
---|
50 | Where:
|
---|
51 |
|
---|
52 | qp queue structure pointer
|
---|
53 | c word to put in the queue
|
---|
54 |
|
---|
55 | Return values:
|
---|
56 |
|
---|
57 | -2 error, queue size was 0
|
---|
58 | -1 queue was full, word not added to queue
|
---|
59 | 0 word added to queue
|
---|
60 | 1 at high water mark, word added to queue
|
---|
61 | ============================================================================
|
---|
62 | */
|
---|
63 |
|
---|
64 | int16_t putwq(struct wordq *qp, uint16_t c)
|
---|
65 | {
|
---|
66 | if (0 NE qp->qsize) { /* verify queue is ok */
|
---|
67 |
|
---|
68 | if (qp->qlen EQ qp->qsize) /* check queue length */
|
---|
69 | return(-1); /* -1 = full */
|
---|
70 |
|
---|
71 | qp->qbuf[qp->qin++] = c; /* put word in queue */
|
---|
72 |
|
---|
73 | if (qp->qin GE qp->qsize) /* update input index */
|
---|
74 | qp->qin = 0; /* wrap around */
|
---|
75 |
|
---|
76 | if (++qp->qlen EQ qp->qhi) /* check length again */
|
---|
77 | return(1); /* 1 = at hi water */
|
---|
78 | else
|
---|
79 | return(0); /* 0 = OK */
|
---|
80 |
|
---|
81 | } else {
|
---|
82 |
|
---|
83 | return(-2); /* -2 = error */
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | /*
|
---|
88 | ============================================================================
|
---|
89 | getwq(qp, p) -- get a word from a word queue
|
---|
90 |
|
---|
91 | Where:
|
---|
92 |
|
---|
93 | qp queue structure pointer
|
---|
94 | p word pointer for returned word
|
---|
95 |
|
---|
96 | Return values:
|
---|
97 |
|
---|
98 | -2 error, queue size was 0
|
---|
99 | -1 queue was empty, no word returned
|
---|
100 | 0 word returned
|
---|
101 | 1 at low water, word returned
|
---|
102 | ============================================================================
|
---|
103 | */
|
---|
104 |
|
---|
105 | int16_t getwq(struct wordq *qp, uint16_t *p)
|
---|
106 | {
|
---|
107 | if (0 NE qp->qsize) { /* check queue is ok */
|
---|
108 |
|
---|
109 | if (0 NE qp->qlen) { /* check queue length */
|
---|
110 |
|
---|
111 | *p = qp->qbuf[qp->qout++]; /* get word from queue */
|
---|
112 |
|
---|
113 | if (qp->qout GE qp->qsize) /* check out pointer */
|
---|
114 | qp->qout = 0; /* wrap around */
|
---|
115 |
|
---|
116 | if (--qp->qlen EQ qp->qlo) /* check length again */
|
---|
117 | return(1); /* 1 = at low water */
|
---|
118 | else
|
---|
119 | return(0); /* 0 = OK */
|
---|
120 |
|
---|
121 | } else {
|
---|
122 |
|
---|
123 | return(-1); /* -1 = emtpy */
|
---|
124 | }
|
---|
125 |
|
---|
126 | } else {
|
---|
127 |
|
---|
128 | return(-2); /* -2 = error */
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|