1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include "platform.h"
27#if defined(DIVA_ISTREAM)
28#include "pc.h"
29#include "pr_pc.h"
30#include "di_defs.h"
31#include "divasync.h"
32#include "di.h"
33#if !defined USE_EXTENDED_DEBUGS
34#include "dimaint.h"
35#else
36#define dprintf
37#endif
38#include "dfifo.h"
39int diva_istream_write(void *context,
40 int Id,
41 void *data,
42 int length,
43 int final,
44 byte usr1,
45 byte usr2);
46int diva_istream_read(void *context,
47 int Id,
48 void *data,
49 int max_length,
50 int *final,
51 byte *usr1,
52 byte *usr2);
53
54
55
56void diva_xdi_provide_istream_info(ADAPTER *a,
57 diva_xdi_stream_interface_t *pi) {
58 pi->provided_service = 0;
59}
60
61
62
63
64
65
66
67
68
69
70int diva_istream_write(void *context,
71 int Id,
72 void *data,
73 int length,
74 int final,
75 byte usr1,
76 byte usr2) {
77 ADAPTER *a = (ADAPTER *)context;
78 int written = 0, to_write = -1;
79 char tmp[4];
80 byte *data_ptr = (byte *)data;
81 for (;;) {
82 a->ram_in_dw(a,
83#ifdef PLATFORM_GT_32BIT
84 ULongToPtr(a->tx_stream[Id] + a->tx_pos[Id]),
85#else
86 (void *)(a->tx_stream[Id] + a->tx_pos[Id]),
87#endif
88 (dword *)&tmp[0],
89 1);
90 if (tmp[0] & DIVA_DFIFO_READY) {
91 if (to_write < 0)
92 return (-1);
93 break;
94 }
95 to_write = min(length, DIVA_DFIFO_DATA_SZ);
96 if (to_write) {
97 a->ram_out_buffer(a,
98#ifdef PLATFORM_GT_32BIT
99 ULongToPtr(a->tx_stream[Id] + a->tx_pos[Id] + 4),
100#else
101 (void *)(a->tx_stream[Id] + a->tx_pos[Id] + 4),
102#endif
103 data_ptr,
104 (word)to_write);
105 length -= to_write;
106 written += to_write;
107 data_ptr += to_write;
108 }
109 tmp[1] = (char)to_write;
110 tmp[0] = (tmp[0] & DIVA_DFIFO_WRAP) |
111 DIVA_DFIFO_READY |
112 ((!length && final) ? DIVA_DFIFO_LAST : 0);
113 if (tmp[0] & DIVA_DFIFO_LAST) {
114 tmp[2] = usr1;
115 tmp[3] = usr2;
116 }
117 a->ram_out_dw(a,
118#ifdef PLATFORM_GT_32BIT
119 ULongToPtr(a->tx_stream[Id] + a->tx_pos[Id]),
120#else
121 (void *)(a->tx_stream[Id] + a->tx_pos[Id]),
122#endif
123 (dword *)&tmp[0],
124 1);
125 if (tmp[0] & DIVA_DFIFO_WRAP) {
126 a->tx_pos[Id] = 0;
127 } else {
128 a->tx_pos[Id] += DIVA_DFIFO_STEP;
129 }
130 if (!length) {
131 break;
132 }
133 }
134 return (written);
135}
136
137
138
139
140
141
142
143
144
145
146
147
148int diva_istream_read(void *context,
149 int Id,
150 void *data,
151 int max_length,
152 int *final,
153 byte *usr1,
154 byte *usr2) {
155 ADAPTER *a = (ADAPTER *)context;
156 int read = 0, to_read = -1;
157 char tmp[4];
158 byte *data_ptr = (byte *)data;
159 *final = 0;
160 for (;;) {
161 a->ram_in_dw(a,
162#ifdef PLATFORM_GT_32BIT
163 ULongToPtr(a->rx_stream[Id] + a->rx_pos[Id]),
164#else
165 (void *)(a->rx_stream[Id] + a->rx_pos[Id]),
166#endif
167 (dword *)&tmp[0],
168 1);
169 if (tmp[1] > max_length) {
170 if (to_read < 0)
171 return (-2);
172 break;
173 }
174 if (!(tmp[0] & DIVA_DFIFO_READY)) {
175 if (to_read < 0)
176 return (-1);
177 break;
178 }
179 to_read = min(max_length, (int)tmp[1]);
180 if (to_read) {
181 a->ram_in_buffer(a,
182#ifdef PLATFORM_GT_32BIT
183 ULongToPtr(a->rx_stream[Id] + a->rx_pos[Id] + 4),
184#else
185 (void *)(a->rx_stream[Id] + a->rx_pos[Id] + 4),
186#endif
187 data_ptr,
188 (word)to_read);
189 max_length -= to_read;
190 read += to_read;
191 data_ptr += to_read;
192 }
193 if (tmp[0] & DIVA_DFIFO_LAST) {
194 *final = 1;
195 }
196 tmp[0] &= DIVA_DFIFO_WRAP;
197 a->ram_out_dw(a,
198#ifdef PLATFORM_GT_32BIT
199 ULongToPtr(a->rx_stream[Id] + a->rx_pos[Id]),
200#else
201 (void *)(a->rx_stream[Id] + a->rx_pos[Id]),
202#endif
203 (dword *)&tmp[0],
204 1);
205 if (tmp[0] & DIVA_DFIFO_WRAP) {
206 a->rx_pos[Id] = 0;
207 } else {
208 a->rx_pos[Id] += DIVA_DFIFO_STEP;
209 }
210 if (*final) {
211 if (usr1)
212 *usr1 = tmp[2];
213 if (usr2)
214 *usr2 = tmp[3];
215 break;
216 }
217 }
218 return (read);
219}
220
221
222
223
224void pr_stream(ADAPTER *a) {
225}
226#endif
227