giocomm.c
6.3 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
#include <ultratypes.h>
#include <libaudio.h>
#include <stdio.h>
#include <stdlib.h>
#include <bstring.h>
#include <unistd.h>
#include <fcntl.h>
#include <u64gio.h>
#include "midiApp.h"
#include "midiDmon.h"
#include "midiGlobals.h"
#ifdef SYSEX_IMPL
#include <sysex.h>
#include <synthcommon.h>
#endif
extern int gGIOfd,hardware;
void SetValue(u32 offset,int valType,u32 value)
{
u64_write_arg_t writeHdr;
SysExReq SEXReq;
SEXReq.pcktType = SYSEX_TYPE;
SEXReq.reqType = valType;
SEXReq.offset = offset;
SEXReq.value = value;
writeHdr.buffer = &SEXReq;
writeHdr.ramrom_addr = RAMROM_APP_READ_ADDR;
writeHdr.nbytes = sizeof(SysExReq);
writeHdr.value = HOST_APP_CMD_READY;
if(hardware)
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
}
u32 GetValue(u32 offset,int valType)
{
u64_read_arg_t readHdr;
u64_write_arg_t writeHdr;
SysExReq SEXReq;
int numBytes;
u32 buf,readBuf;
SEXReq.pcktType = SYSEX_TYPE;
SEXReq.reqType = valType;
SEXReq.offset = offset;
writeHdr.buffer = &SEXReq;
writeHdr.ramrom_addr = RAMROM_APP_READ_ADDR;
writeHdr.nbytes = sizeof(SysExReq);
writeHdr.value = HOST_APP_CMD_READY;
if(hardware)
{
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
readHdr.buffer = &readBuf;
readHdr.ramrom_addr = RAMROM_APP_WRITE_ADDR;
readHdr.nbytes = 4;
readHdr.value = HOST_APP_CMD_READY; /* GAME_APP_DATA_READY; */
/* block on read, waiting for a return ack */
numBytes = read(gGIOfd, &buf, 1);
/* read the data into the buffer */
ioctl(gGIOfd, U64_SAFE_READ,&readHdr);
return(readBuf);
}
return 0;
}
void WriteBlock(u32 destOffset,char *data,u32 size)
{
u64_write_arg_t writeHdr;
SysExReq SEXReq;
u32 sending,sent = 0;
SEXReq.pcktType = SYSEX_TYPE;
SEXReq.reqType = WRITE_BLOCK;
SEXReq.offset = destOffset;
SEXReq.value = size;
writeHdr.buffer = &SEXReq;
writeHdr.ramrom_addr = RAMROM_APP_READ_ADDR;
writeHdr.nbytes = sizeof(SysExReq);
writeHdr.value = HOST_APP_CMD_READY;
if(hardware)
{
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
while(size)
{
sending = MIN(size,RAMROM_BUF_SIZE);
writeHdr.buffer = &data[sent];
writeHdr.nbytes = sending;
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
sent+=sending;
size-=sending;
}
}
}
void WriteRamRom(u32 destAddr,char *data,u32 size)
{
u64_write_arg_t writeHdr;
SysExReq SEXReq;
SEXReq.pcktType = SYSEX_TYPE;
SEXReq.reqType = WRITE_RAMROM;
writeHdr.buffer = &SEXReq;
writeHdr.ramrom_addr = RAMROM_APP_READ_ADDR;
writeHdr.nbytes = sizeof(SysExReq);
writeHdr.value = HOST_APP_CMD_READY;
if(hardware)
{
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
writeHdr.buffer = data;
writeHdr.nbytes = size;
writeHdr.ramrom_addr = destAddr;
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
}
}
u32 WriteMirror(void)
{
int i,c,numPtrs;
char *tmpMirror;
ALBankFile *bnkfPtr;
ALBank *bankPtr;
ALInstrument *instPtr;
ALSound *sndPtr;
ALWaveTable *wvTblPtr;
ALADPCMWaveInfo *wvInfoPtr;
tmpMirror = malloc(gMirrorCur);
if(!tmpMirror)
{
fprintf(stderr,"%s: Unable to allocate memory for temp mirror\n",gAppName);
return(MEMORY_NOT_OK);
}
bcopy(gMirror,tmpMirror,gMirrorCur);
for(i=0;i<gObjCt;i++)
{
switch(gSymObj[i].SFObj.objectClass)
{
case AL_BNKFILE_CLASS:
bnkfPtr = (ALBankFile*)&tmpMirror[gSymObj[i].SFObj.bankFileOffset];
numPtrs = (int)bnkfPtr->bankCount;
for(c=0;c<numPtrs;c++)
bnkfPtr->bankArray[c] = (ALBank*)((u32)bnkfPtr->bankArray[c] + BANK_RDRAM_ADDR);
break;
case AL_BANK_CLASS:
bankPtr = (ALBank*)&tmpMirror[gSymObj[i].SFObj.bankFileOffset];
numPtrs = (int)bankPtr->instCount;
for(c=0;c<numPtrs;c++)
bankPtr->instArray[c] = (ALInstrument*)((u32)bankPtr->instArray[c] + BANK_RDRAM_ADDR);
bankPtr->percussion = (ALInstrument*)((u32)bankPtr->percussion + BANK_RDRAM_ADDR);
break;
case AL_INST_CLASS:
instPtr = (ALInstrument*)&tmpMirror[gSymObj[i].SFObj.bankFileOffset];
numPtrs = instPtr->soundCount;
for(c=0;c<numPtrs;c++)
instPtr->soundArray[c] = (ALSound*)((u32)instPtr->soundArray[c] + BANK_RDRAM_ADDR);
break;
case AL_SOUND_CLASS:
sndPtr = (ALSound*)&tmpMirror[gSymObj[i].SFObj.bankFileOffset];
sndPtr->envelope = (ALEnvelope*)((u32)sndPtr->envelope + BANK_RDRAM_ADDR);
sndPtr->wavetable = (ALWaveTable*)((u32)sndPtr->wavetable + BANK_RDRAM_ADDR);
sndPtr->keyMap = (ALKeyMap*)((u32)sndPtr->keyMap + BANK_RDRAM_ADDR);
break;
case AL_WAVETBL_CLASS:
wvTblPtr = (ALWaveTable*)&tmpMirror[gSymObj[i].SFObj.bankFileOffset];
wvTblPtr->base = (char*)((u32)wvTblPtr->base + SAMPLES_RAMROM_ADDR);
wvInfoPtr = (ALADPCMWaveInfo*)&wvTblPtr->waveInfo.adpcmWave;
wvInfoPtr->book = (ALADPCMBook*)((u32)wvInfoPtr->book + BANK_RDRAM_ADDR);
if(wvInfoPtr->loop)
wvInfoPtr->loop = (ALADPCMloop*)((u32)wvInfoPtr->loop + BANK_RDRAM_ADDR);
break;
}
}
WriteBlock(BANK_RDRAM_ADDR,tmpMirror,gMirrorCur);
free(tmpMirror);
return(MEMORY_OK);
}
void SendSetBank(u32 offset)
{
u64_write_arg_t writeHdr;
SysExReq SEXReq;
int i;
SEXReq.pcktType = SYSEX_TYPE;
SEXReq.reqType = RESET_BANK;
SEXReq.offset = offset;
SEXReq.value = 0;
writeHdr.buffer = &SEXReq;
writeHdr.ramrom_addr = RAMROM_APP_READ_ADDR;
writeHdr.nbytes = sizeof(SysExReq);
writeHdr.value = HOST_APP_CMD_READY;
if(hardware)
ioctl(gGIOfd, U64_SAFE_WRITE, &writeHdr);
for(i=0;i<MAX_SEQ_CHANNELS;i++)
gCurChanInst[i] = 0;
}