source: buchla-68k/ram/setwq.c@ 6aa430b

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

Zero redundant declarations.

  • Property mode set to 100644
File size: 3.0 KB
Line 
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
30uint16_t setwq(struct wordq *qp, uint16_t *qadr, uint16_t qsiz, uint16_t hi, uint16_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*/
49
50/*
51 ============================================================================
52 putwq(qp, c) -- put a word in a word queue
53
54 Where:
55
56 qp queue structure pointer
57 c word to put in the queue
58
59 Return values:
60
61 -2 error, queue size was 0
62 -1 queue was full, word not added to queue
63 0 word added to queue
64 1 at high water mark, word added to queue
65 ============================================================================
66*/
67
68int16_t putwq(struct wordq *qp, uint16_t c)
69{
70 if (0 NE qp->qsize) { /* verify queue is ok */
71
72 if (qp->qlen EQ qp->qsize) /* check queue length */
73 return(-1); /* -1 = full */
74
75 qp->qbuf[qp->qin++] = c; /* put word in queue */
76
77 if (qp->qin GE qp->qsize) /* update input index */
78 qp->qin = 0; /* wrap around */
79
80 if (++qp->qlen EQ qp->qhi) /* check length again */
81 return(1); /* 1 = at hi water */
82 else
83 return(0); /* 0 = OK */
84
85 } else {
86
87 return(-2); /* -2 = error */
88 }
89}
90
91/*
92
93*/
94
95/*
96 ============================================================================
97 getwq(qp, p) -- get a word from a word queue
98
99 Where:
100
101 qp queue structure pointer
102 p word pointer for returned word
103
104 Return values:
105
106 -2 error, queue size was 0
107 -1 queue was empty, no word returned
108 0 word returned
109 1 at low water, word returned
110 ============================================================================
111*/
112
113int16_t getwq(struct wordq *qp, uint16_t *p)
114{
115 if (0 NE qp->qsize) { /* check queue is ok */
116
117 if (0 NE qp->qlen) { /* check queue length */
118
119 *p = qp->qbuf[qp->qout++]; /* get word from queue */
120
121 if (qp->qout GE qp->qsize) /* check out pointer */
122 qp->qout = 0; /* wrap around */
123
124 if (--qp->qlen EQ qp->qlo) /* check length again */
125 return(1); /* 1 = at low water */
126 else
127 return(0); /* 0 = OK */
128
129 } else {
130
131 return(-1); /* -1 = emtpy */
132 }
133
134 } else {
135
136 return(-2); /* -2 = error */
137 }
138}
139
Note: See TracBrowser for help on using the repository browser.