forked from fxsound2/fxsound-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComwrite.cpp
More file actions
288 lines (232 loc) · 7.72 KB
/
Copy pathComwrite.cpp
File metadata and controls
288 lines (232 loc) · 7.72 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
FxSound
Copyright (C) 2023 FxSound LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "codedefs.h"
/* Standard includes */
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "pt_defs.h"
#include "slout.h"
#define PC_TARGET
#include "platform.h"
#include "boardrv1.h"
extern "C"
{
/*
#include "hrdwr.h"
*/
#include "comSftwr.h"
}
#include "com.h"
#include "u_com.h"
int fmsbintoti(realtype *,realtype *);
/*
* FUNCTION: comIntWrite()
* DESCRIPTION:
* Writes the passed integer value to the passed memory location.
* (memory location = i_mem_offset + COMM_MEM_BASE_ADDR).
*/
int PT_DECLSPEC comIntWrite(PT_HANDLE *hp_com, long l_mem_offset, int i_value)
{
struct comHdlType *cast_handle;
long long_value;
cast_handle = (struct comHdlType *)hp_com;
if (cast_handle == NULL)
return(NOT_OKAY);
if (cast_handle->turned_off)
return(OKAY);
if ((!cast_handle->program_running) && (!cast_handle->softdsp_mode))
return(NOT_OKAY);
if (l_mem_offset < 0L)
return(NOT_OKAY);
/* Transfer value to a long */
long_value = (long)i_value;
/* To speed up parameter writes with remote operation, use single call.
* This new function will handle COMM_MEM_BASE_ADDR offsetting.
*/
if(cast_handle->softdsp_mode)
{
if( comSftwrWriteParam(cast_handle->comSftwr_hdl, (long)(l_mem_offset), long_value) != OKAY)
return(NOT_OKAY);
}
/* Print the sent value if in debug mode */
if (cast_handle->debug_mode)
{
sprintf(cast_handle->msg1, "(int) value=%d", i_value);
(cast_handle->slout_hdl)->Message(FIRST_LINE, cast_handle->msg1);
sprintf(cast_handle->msg1, " mem_offset=%ld", l_mem_offset);
(cast_handle->slout_hdl)->Message(NEXT_LINE, cast_handle->msg1);
}
return(OKAY);
}
/*
* FUNCTION: comLongIntWrite()
* DESCRIPTION:
* Writes the passed long integer value to the passed memory location.
* (memory location = i_mem_offset + COMM_MEM_BASE_ADDR).
*/
int PT_DECLSPEC comLongIntWrite(PT_HANDLE *hp_com, long l_mem_offset, long l_value)
{
struct comHdlType *cast_handle;
cast_handle = (struct comHdlType *)hp_com;
if (cast_handle == NULL)
return(NOT_OKAY);
if (cast_handle->turned_off)
return(OKAY);
if ((!cast_handle->program_running) && (!cast_handle->softdsp_mode))
return(NOT_OKAY);
if (l_mem_offset < 0L)
return(NOT_OKAY);
/* To speed up parameter writes with remote operation, use single call.
* This new function will handle COMM_MEM_BASE_ADDR offsetting.
*/
if( cast_handle->softdsp_mode )
{
if( comSftwrWriteParam(cast_handle->comSftwr_hdl, (long)(l_mem_offset), l_value) != OKAY)
return(NOT_OKAY);
}
/* Print the sent value if in debug mode */
if (cast_handle->debug_mode)
{
sprintf(cast_handle->msg1, "(long) value=%ld", l_value);
(cast_handle->slout_hdl)->Message(FIRST_LINE, cast_handle->msg1);
sprintf(cast_handle->msg1, " mem_offset=%ld", l_mem_offset);
(cast_handle->slout_hdl)->Message(NEXT_LINE, cast_handle->msg1);
}
return(OKAY);
}
/*
* FUNCTION: comRealWrite()
* DESCRIPTION:
* Writes the passed real value to the passed memory location.
* (memory location = i_mem_offset + COMM_MEM_BASE_ADDR).
*/
int PT_DECLSPEC comRealWrite(PT_HANDLE *hp_com, long l_mem_offset, realtype r_value)
{
struct comHdlType *cast_handle;
cast_handle = (struct comHdlType *)hp_com;
if (cast_handle == NULL)
return(NOT_OKAY);
if (cast_handle->turned_off)
return(OKAY);
if ((!cast_handle->program_running) && (!cast_handle->softdsp_mode))
return(NOT_OKAY);
if (l_mem_offset < 0L)
return(NOT_OKAY);
if( cast_handle->softdsp_mode )
{
void *i_val;
i_val = &r_value;
/* To speed up parameter writes with remote operation, use single call.
* This new function will handle COMM_MEM_BASE_ADDR offsetting.
*/
if( comSftwrWriteParam(cast_handle->comSftwr_hdl, (long)(l_mem_offset), *(long*)i_val) != OKAY)
return(NOT_OKAY);
}
/* Print the sent value if in debug mode */
if (cast_handle->debug_mode)
{
sprintf(cast_handle->msg1, "(real) value=%g", r_value);
(cast_handle->slout_hdl)->Message(FIRST_LINE, cast_handle->msg1);
sprintf(cast_handle->msg1, " mem_offset=%ld", l_mem_offset);
(cast_handle->slout_hdl)->Message(NEXT_LINE, cast_handle->msg1);
}
return(OKAY);
}
/*
* FUNCTION: comSetDemoMode()
* DESCRIPTION:
* Sets a global shared variable in the comSftwr module.
*/
int PT_DECLSPEC comSetDemoMode(PT_HANDLE *hp_com, int i_DemoModeOnFlag)
{
struct comHdlType *cast_handle;
cast_handle = (struct comHdlType *)hp_com;
if (cast_handle == NULL)
return(NOT_OKAY);
if (comSftwrSetDemoFlag( cast_handle->comSftwr_hdl, i_DemoModeOnFlag) != OKAY)
return(NOT_OKAY);
return(OKAY);
}
/*
* FUNCTIONS TO CONVERT BETWEEN TI C30,C40
* AND PC FLOATING POINT FORMATS
*/
int fmsbintoti(float *src4, float *dest4)
{
unsigned char *msbin = (unsigned char *)src4;
unsigned char *ti = (unsigned char *)dest4;
unsigned char sign = 0x00;
int i;
/* Intel Binary Format MODIFIED BY PFT
* msbin[3] is exponent, which contains sign and bias of 63
* msbin[2] is MSB
* msbin[1] is Middle byte
* msbin[0] is LSB
* EXP MSB LSB
* seeeeeee|emmmmmmm|mmmmmmmm|mmmmmmmm
* msbin[3] msbin[0]
* Note Intel format has a "bias" of 127 in the exponent- ie
* 2 => 64 | 0 | 0 | 0 (exp is 128)
* To negate a number, just add 128 to msbin[3], and let it wrap
* -2 => 192 | 0 | 0 | 0
*
* Float = (sign) * 1.mmmm... * 2 exp (eeeeeeee - 127)
*
* TI Single Precision Float Format- normalized with an implied most
* significant sign bit, for additional precision.
* EXP MSB LSB
* eeeeeeee|smmmmmmm|mmmmmmmm|mmmmmmmm
* ti[3] ti[0]
* s = sign bit
* e = exponent bit
* m = mantissa bit
*
* Float = 1 + .mmmm... * 2 exp (eeeeeeee) for s = 0
* Float = -2 + .mmmm... * 2 exp (eeeeeeee) for s = 1
*/
for (i=0; i<=3; i++) ti[i] = 0; /* Zero all TI bits */
if( *src4 == 1.0 )
return 0; /* all zero's is a one for TI */
/* any msbin w/ exponent of zero = zero (or also 128 for -0)*/
if ( (msbin[3] == 0) || (msbin[3] == 128) )
{
ti[3] = 0x80; /* For TI normalized zero, exponent = -128 (0x80) */
return 0;
}
sign = msbin[3] & 0x80; /* 1000|0000b Is there a faster way? */
ti[2] = msbin[2] & 0x7F; /* Strip out 7 mantissa bits */
ti[3] = (msbin[3] << 1); /* Shift exponent bits over original sign bit */
if( (msbin[2] & 0x80) ) /* Add last exponent bit if it was set */
ti[3] += 1;
ti[3] -= 127; /* Remove Bias */
ti[1] = msbin[1]; /* Copy the rest of the mantissa */
ti[0] = msbin[0];
if(sign)
{
unsigned char exp = ti[3]; /* Save formed exponent */
*(long *)ti &= 0x00FFFFFFL; /* Mask out exponent bits */
*(long *)ti ^= 0x00FFFFFFL; /* Reverse all the mantissa bits */
*(long *)ti += 1; /* Add one, completeing mantissa negation */
/* Carry bit will overflow into exponent */
/* where it needs to be treated as a decrement */
ti[3] = exp - ti[3]; /* Restore exponent, decremented by carry bit */
ti[2] |= sign; /* Set sign bit */
}
return 0;
}