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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
/***************************************************************************
debug.c - description
-------------------
begin : Wed May 15 2002
copyright : (C) 2002 by Pete Bernert
email : BlackDove@addcom.de
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. See also the license.txt file for *
* additional informations. *
* *
***************************************************************************/
//*************************************************************************//
// History of changes:
//
// 2004/09/18 - Pete
// - corrected ADSRX value display
//
// 2003/01/06 - Pete
// - added Neil's ADSR timings
//
// 2002/05/15 - Pete
// - generic cleanup for the Peops release
//
//*************************************************************************//
#include "stdafx.h"
#define _IN_DEBUG
#include "externals.h"
////////////////////////////////////////////////////////////////////////
// WINDOWS DEBUG DIALOG HANDLING
////////////////////////////////////////////////////////////////////////
#ifdef _WINDOWS
#include "resource.h"
//#define SMALLDEBUG
//#include <dbgout.h>
////////////////////////////////////////////////////////////////////////
// display debug infos
const COLORREF crStreamCol[]={
RGB( 0, 0, 0),
RGB(255,255,255),
RGB(128, 0,128),
RGB( 0,128, 0),
RGB( 0, 0,255),
RGB(255, 0, 0)
};
const COLORREF crAdsrCol[] ={
RGB( 0, 0, 0),
RGB(255, 0, 0),
RGB( 0,255, 0),
RGB(255, 0,255),
RGB( 0, 0,255),
RGB( 0, 0, 0),
};
HBRUSH hBStream[6]; // brushes for stream lines
HPEN hPAdsr[6]; // pens for adsr lines
int iSelChannel=0; // user selected channel
////////////////////////////////////////////////////////////////////////
// display the sound data waves: no subclassing used, so the
// area will not be redrawn... but faster that way, and good enuff
// for debugging purposes
void DisplayStreamInfos(HWND hW)
{
HWND hWS=GetDlgItem(hW,IDC_SAREA);
HDC hdc;RECT r;HBRUSH hBO;int ch,dy,i,j,id;
//----------------------------------------------------//
GetClientRect(hWS,&r); // get size of stream display
hdc=GetDC(hWS); // device context
r.right--; // leave the right border intact
ScrollDC(hdc,-1,0,&r,&r,NULL,NULL); // scroll one pixel to the left
//----------------------------------------------------//
hBO=SelectObject(hdc,hBStream[0]); // clean the right border
PatBlt(hdc,r.right-1,0,1,r.bottom,PATCOPY);
//----------------------------------------------------//
dy=r.bottom/MAXCHAN; // size of one channel area
for(ch=0;ch<MAXCHAN;ch++) // loop the channels
{
if(s_chan[ch].bOn) // channel is on?
{
if(s_chan[ch].iIrqDone)
{
s_chan[ch].iIrqDone=0;
PatBlt(hdc,r.right-1,ch*r.bottom/MAXCHAN,
1,dy,BLACKNESS);
continue;
}
j=s_chan[ch].sval;if(j<0) j=-j; // -> get one channel data (-32k ... 32k)
j=(dy*j)/32768; if(j==0) j=1; // -> adjust to display coords
i=(dy/2)+(ch*r.bottom/MAXCHAN)-j/2; // -> position where to paint it
if (s_chan[ch].iMute) id=1; // -> get color id
else if(s_chan[ch].bNoise) id=2;
else if(s_chan[ch].bFMod==2) id=3;
else if(s_chan[ch].bFMod==1) id=4;
else id=5;
SelectObject(hdc,hBStream[id]); // -> select the brush
PatBlt(hdc,r.right-1,i,1,j,PATCOPY); // -> paint the value line
}
if(ch) SetPixel(hdc,r.right-1, // -> not first line?
ch*r.bottom/MAXCHAN,RGB(0,0,0)); // --> draw the line (one dot scrolled to the left)
}
//----------------------------------------------------//
SelectObject(hdc,hBO); // repair brush
ReleaseDC(hWS,hdc); // release context
}
////////////////////////////////////////////////////////////////////////
// display adsr lines: also no subclassing for repainting used
void DisplayADSRInfos(HWND hW)
{
HWND hWS=GetDlgItem(hW,IDC_ADSR);
HDC hdc;RECT r;HBRUSH hBO;char szB[16];
int ch=iSelChannel,dx,dy,dm,dn,ia,id,is,ir;
//----------------------------------------------------// get display size
GetClientRect(hWS,&r);
hdc=GetDC(hWS);
//----------------------------------------------------// clean the area
hBO=SelectObject(hdc,hBStream[0]);
PatBlt(hdc,0,0,r.right,r.bottom,PATCOPY);
r.left++;r.right-=2;r.top++;r.bottom-=2; // shrink the display rect for better optics
//----------------------------------------------------//
ia=min(s_chan[ch].ADSR.AttackTime,10000); // get adsr, but limit it for drawing
id=min(s_chan[ch].ADSR.DecayTime,10000);
is=min(s_chan[ch].ADSR.SustainTime,10000);
ir=min(s_chan[ch].ADSR.ReleaseTime,10000);
dx=ia+id+is+ir; // get the dx in (limited) adsr units
// set the real values to the info statics
SetDlgItemInt(hW,IDC_SADSR1,s_chan[ch].ADSRX.AttackRate^0x7f,FALSE);
SetDlgItemInt(hW,IDC_SADSR2,(s_chan[ch].ADSRX.DecayRate^0x1f)/4,FALSE);
SetDlgItemInt(hW,IDC_SADSR3,s_chan[ch].ADSRX.SustainRate^0x7f,FALSE);
SetDlgItemInt(hW,IDC_SADSR4,(s_chan[ch].ADSRX.ReleaseRate^0x1f)/4,FALSE);
SetDlgItemInt(hW,IDC_SADSR5,s_chan[ch].ADSRX.SustainLevel>>27,FALSE);
SetDlgItemInt(hW,IDC_SADSR6,s_chan[ch].ADSRX.SustainIncrease,TRUE);
SetDlgItemInt(hW,IDC_SADSR7,s_chan[ch].ADSRX.lVolume,TRUE);
wsprintf(szB,"%08lx",s_chan[ch].ADSRX.EnvelopeVol);
SetDlgItemText(hW,IDC_SADSR8,szB);
if(dx) // something to draw?
{
HPEN hPO=SelectObject(hdc,hPAdsr[1]); // sel A pen
dn=r.left;
MoveToEx(hdc,dn,r.bottom,NULL); // move to bottom left corner
dn+=(ia*r.right)/dx; // calc A x line pos
LineTo(hdc,dn,r.top); // line to AxPos,top
SelectObject(hdc,hPAdsr[2]); // sel D pen
dn+=(id*r.right)/dx; // calc D x line pos
dy=r.top+((1024-s_chan[ch].ADSR.SustainLevel)* // calc the D y pos
r.bottom)/1024; // (our S level is ranged from 0 to 1024)
LineTo(hdc,dn,dy); // line to DxPos,SLevel
SelectObject(hdc,hPAdsr[3]); // sel S pen
if(s_chan[ch].ADSR.SustainTime>10000) dm=1; // we have to fake the S values... S will
else // inc/decrease until channel stop...
if(s_chan[ch].ADSR.SustainTime==0) dm=0; // we dunno here when this will happen,
else dm=21-(((s_chan[ch].ADSR.SustainTime/500))); // so we do some more ore less angled line,
dy=dy-(s_chan[ch].ADSR.SustainModeDec*dm); // roughly depending on the S Time
if(dy>r.bottom) dy=r.bottom;
if(dy<r.top) dy=r.top;
dn+=(is*r.right)/dx;
LineTo(hdc,dn,dy); // line to SxPos, fake end volume level
SelectObject(hdc,hPAdsr[4]); // sel R pen
dn+=(ir*r.right)/dx; // calc R x line pos
LineTo(hdc,dn,r.bottom); // line to RxPos, bottom right y
SelectObject(hdc,hPO); // repair pen
}
SelectObject(hdc,hBO); // repair brush
ReleaseDC(hWS,hdc); // release context
}
////////////////////////////////////////////////////////////////////////
void DisplayChannelInfos(HWND hW)
{
int ch=iSelChannel;char szB[16];
// channel infos
SetDlgItemInt(hW,IDC_CI1,s_chan[ch].bOn,TRUE);
SetDlgItemInt(hW,IDC_CI2,s_chan[ch].bStop,TRUE);
SetDlgItemInt(hW,IDC_CI3,s_chan[ch].bNoise,TRUE);
SetDlgItemInt(hW,IDC_CI4,s_chan[ch].bFMod,TRUE);
SetDlgItemInt(hW,IDC_CI5,s_chan[ch].bReverb,TRUE);
SetDlgItemInt(hW,IDC_CI6,s_chan[ch].bRVBActive,TRUE);
SetDlgItemInt(hW,IDC_CI7,s_chan[ch].iRVBNum,TRUE);
SetDlgItemInt(hW,IDC_CI8,s_chan[ch].iRVBOffset,TRUE);
SetDlgItemInt(hW,IDC_CI9,s_chan[ch].iRVBRepeat,TRUE);
SetDlgItemInt(hW,IDC_CI10,(unsigned long)s_chan[ch].pStart-(unsigned long)spuMemC,FALSE);
SetDlgItemInt(hW,IDC_CI11,(unsigned long)s_chan[ch].pCurr-(unsigned long)spuMemC,FALSE);
SetDlgItemInt(hW,IDC_CI12,(unsigned long)s_chan[ch].pLoop-(unsigned long)spuMemC,FALSE);
SetDlgItemInt(hW,IDC_CI13,s_chan[ch].iRightVolume,TRUE);
SetDlgItemInt(hW,IDC_CI14,s_chan[ch].iLeftVolume,TRUE);
SetDlgItemInt(hW,IDC_CI15,s_chan[ch].iActFreq,TRUE);
SetDlgItemInt(hW,IDC_CI16,s_chan[ch].iUsedFreq,TRUE);
wsprintf(szB,"%04x",s_chan[ch].iRightVolRaw);
SetDlgItemText(hW,IDC_CI17,szB);
wsprintf(szB,"%04x",s_chan[ch].iLeftVolRaw);
SetDlgItemText(hW,IDC_CI18,szB);
// generic infos
if(pSpuIrq==0)
SetDlgItemInt(hW,IDC_STA1,-1,TRUE);
else SetDlgItemInt(hW,IDC_STA1,(unsigned long)pSpuIrq-(unsigned long)spuMemC,FALSE);
wsprintf(szB,"%04x",spuCtrl);
SetDlgItemText(hW,IDC_STA2,szB);
wsprintf(szB,"%04x",spuStat);
SetDlgItemText(hW,IDC_STA3,szB);
SetDlgItemInt(hW,IDC_STA4,spuAddr,TRUE);
// xa infos
if(XAPlay<=XAFeed) ch=XAFeed-XAPlay;
else ch=(XAFeed-XAStart)+(XAEnd-XAPlay);
SetDlgItemInt(hW,IDC_XA4,ch,FALSE);
SetDlgItemInt(hW,IDC_XA5,iLeftXAVol,TRUE);
SetDlgItemInt(hW,IDC_XA6,iRightXAVol,TRUE);
if(!xapGlobal) return;
SetDlgItemInt(hW,IDC_XA1,xapGlobal->freq,TRUE);
SetDlgItemInt(hW,IDC_XA2,xapGlobal->stereo,TRUE);
SetDlgItemInt(hW,IDC_XA3,xapGlobal->nsamples,TRUE);
}
////////////////////////////////////////////////////////////////////////
// display everything (called in dialog timer for value refreshing)
void DisplayDebugInfos(HWND hW)
{
DisplayStreamInfos(hW);
DisplayADSRInfos(hW);
DisplayChannelInfos(hW);
}
////////////////////////////////////////////////////////////////////////
// main debug dlg handler
BOOL CALLBACK DebugDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
//--------------------------------------------------// init
case WM_INITDIALOG:
{
int i;
ShowCursor(TRUE); // mmm... who is hiding it? main emu? tsts
iSelChannel=0; // sel first channel
CheckRadioButton(hW,IDC_CHAN1,IDC_CHAN24,IDC_CHAN1);
// create brushes/pens
hBStream[0]=CreateSolidBrush(GetSysColor(COLOR_3DFACE));
hPAdsr[0]=CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DFACE));
for(i=1;i<6;i++)
{
hBStream[i]=CreateSolidBrush(crStreamCol[i]);
hPAdsr[i]=CreatePen(PS_SOLID,0,crAdsrCol[i]);
}
SetTimer(hW,999,50,NULL); // now create update timer
return TRUE;
}
//--------------------------------------------------// destroy
case WM_DESTROY:
{
int i;
KillTimer(hW,999); // first kill timer
for(i=0;i<6;i++) // then kill brushes/pens
{
DeleteObject(hBStream[i]);
DeleteObject(hPAdsr[i]);
}
}break;
//--------------------------------------------------// timer
case WM_TIMER:
{
if(wParam==999) DisplayDebugInfos(hW); // update all values
}break;
//--------------------------------------------------// command
case WM_COMMAND:
{
if(wParam==IDCANCEL) iDebugMode=2; // cancel? raise flag for destroying the dialog
if(wParam>=IDC_MUTE1 && wParam<=IDC_MUTE24) // mute clicked?
{
if(IsDlgButtonChecked(hW,wParam)) // -> mute/unmute it
s_chan[wParam-IDC_MUTE1].iMute=1;
else s_chan[wParam-IDC_MUTE1].iMute=0;
}
// all mute/unmute
if(wParam==IDC_MUTEOFF) SendMessage(hW,WM_MUTE,0,0);
if(wParam==IDC_MUTEON) SendMessage(hW,WM_MUTE,1,0);
if(wParam>=IDC_CHAN1 && wParam<=IDC_CHAN24) // sel channel
{
if(IsDlgButtonChecked(hW,wParam))
{
iSelChannel=wParam-IDC_CHAN1;
SetDlgItemInt(hW,IDC_CHANNUM,iSelChannel+1,FALSE);
}
}
}break;
//--------------------------------------------------// mute
case WM_MUTE:
{ // will be called by the mute/unmute all button and on savestate load
int i;
for(i=IDC_MUTE1;i<=IDC_MUTE24;i++)
{
CheckDlgButton(hW,i,wParam);
if(wParam) s_chan[i-IDC_MUTE1].iMute=1;
else s_chan[i-IDC_MUTE1].iMute=0;
}
}break;
//--------------------------------------------------// size
case WM_SIZE:
if(wParam==SIZE_MINIMIZED) SetFocus(hWMain); // if we get minimized, set the foxus to the main window
break;
//--------------------------------------------------// setcursor
case WM_SETCURSOR:
{
SetCursor(LoadCursor(NULL,IDC_ARROW)); // force the arrow
return TRUE;
}
//--------------------------------------------------//
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////
#endif
|