• R/O
  • SSH
  • HTTPS

oswan: Commit


Commit MetaInfo

Revision81 (tree)
Time2010-05-11 11:35:19
Authorbird_may_nike

Log Message

(empty log message)

Change Summary

Incremental Difference

--- oswanj/trunk/src/WSMain.cpp (revision 80)
+++ oswanj/trunk/src/WSMain.cpp (revision 81)
@@ -46,7 +46,7 @@
4646 drawCreate();
4747 SetDrawSize(DS_2);
4848 WsInputInit(hWnd);
49- SetKeyMap(0);
49+ WsInputSetKeyMap(0);
5050 WsSplash();
5151 while (1) {
5252 if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
--- oswanj/trunk/src/WSApu.cpp (revision 80)
+++ oswanj/trunk/src/WSApu.cpp (revision 81)
@@ -9,6 +9,7 @@
99 #include "WSHard.h"
1010 #include "WSApu.h"
1111 #include "WSError.h"
12+#include "WSInput.h"
1213
1314 #define BUFSIZEN 0x10000
1415 #define BPSWAV 12000 // WSのHblankが12KHz
@@ -45,7 +46,8 @@
4546 break;
4647 case WOM_DONE:
4748 rBuf++;
48- if (rBuf >= BUFCOUNT) {
49+ if (rBuf >= BUFCOUNT)
50+ {
4951 rBuf = 0;
5052 }
5153 break;
@@ -72,11 +74,13 @@
7274 wfe.nSamplesPerSec = BPSWAV;
7375 wfe.nAvgBytesPerSec = wfe.nSamplesPerSec * wfe.nBlockAlign;
7476 result = waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfe, (DWORD_PTR)apuWaveOutProc, NULL, CALLBACK_FUNCTION);
75- if (result != MMSYSERR_NOERROR ) {
77+ if (result != MMSYSERR_NOERROR )
78+ {
7679 waveOutGetErrorText(result, msg, sizeof(msg));
7780 ErrorMsg(ERR_WAVEOUT_OPEN);
7881 }
79- for (i = 0; i < BUFCOUNT; i++) {
82+ for (i = 0; i < BUFCOUNT; i++)
83+ {
8084 whdr[i] = (WAVEHDR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WAVEHDR));
8185 whdr[i]->lpData = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, BUFSIZEW * 4);
8286 whdr[i]->dwBufferLength = BUFSIZEW * 4;
@@ -83,7 +87,8 @@
8387 whdr[i]->dwFlags = 0;
8488 whdr[i]->dwLoops = 0;
8589 result = waveOutPrepareHeader(hWaveOut, whdr[i], sizeof(WAVEHDR));
86- if (result != MMSYSERR_NOERROR ) {
90+ if (result != MMSYSERR_NOERROR )
91+ {
8792 waveOutGetErrorText(result, msg, sizeof(msg));
8893 ErrorMsg(ERR_WAVEOUT_PREPAREHEADER);
8994 }
@@ -96,8 +101,10 @@
96101 int i;
97102
98103 waveOutReset(hWaveOut);
99- for(i = 0; i < BUFCOUNT; i++) {
100- if (whdr[i]) {
104+ for(i = 0; i < BUFCOUNT; i++)
105+ {
106+ if (whdr[i])
107+ {
101108 waveOutUnprepareHeader(hWaveOut,whdr[i],sizeof(WAVEHDR));
102109 HeapFree(GetProcessHeap(),0,whdr[i]->lpData);
103110 HeapFree(GetProcessHeap(),0,whdr[i]);
@@ -113,7 +120,8 @@
113120 int i;
114121
115122 waveOutReset(hWaveOut);
116- for (i = 0; i < BUFCOUNT; i++) {
123+ for (i = 0; i < BUFCOUNT; i++)
124+ {
117125 ZeroMemory(whdr[i]->lpData, BUFSIZEW * 4);
118126 }
119127 rBuf = 0;
@@ -125,18 +133,23 @@
125133 {
126134 int i, j;
127135
128- for (i = 0; i < 4; i++) {
129- for (j = 0; j < 32; j++) {
136+ for (i = 0; i < 4; i++)
137+ {
138+ for (j = 0; j < 32; j++)
139+ {
130140 PData[i][j] = 8;
131141 }
132142 }
133- for (i = 0; i < 8; i++) {
134- for (j = 0; j < BUFSIZEN; j++) {
143+ for (i = 0; i < 8; i++)
144+ {
145+ for (j = 0; j < BUFSIZEN; j++)
146+ {
135147 PDataN[i][j] = ((apuMrand(15 - i) & 1) ? 15 : 0);
136148 }
137149 }
138150
139- for (i = 0; i < BUFSIZEN; i++) {
151+ for (i = 0; i < BUFSIZEN; i++)
152+ {
140153 RandData[i] = apuMrand(15);
141154 }
142155 apuWaveCreate();
@@ -151,7 +164,8 @@
151164 unsigned int apuMrand(unsigned int Degree)
152165 {
153166 #define BIT(n) (1<<n)
154- typedef struct {
167+ typedef struct
168+ {
155169 unsigned int N;
156170 int InputBit;
157171 int Mask;
@@ -180,31 +194,38 @@
180194 int XorReg = 0;
181195 int Masked;
182196
183- if(pTbl->N != Degree) {
197+ if(pTbl->N != Degree)
198+ {
184199 pTbl = TblMask;
185200 while(pTbl->N) {
186- if(pTbl->N == Degree) {
201+ if(pTbl->N == Degree)
202+ {
187203 break;
188204 }
189205 pTbl++;
190206 }
191- if(!pTbl->N) {
207+ if(!pTbl->N)
208+ {
192209 pTbl--;
193210 }
194211 ShiftReg &= pTbl->InputBit-1;
195- if(!ShiftReg) {
212+ if(!ShiftReg)
213+ {
196214 ShiftReg = pTbl->InputBit-1;
197215 }
198216 }
199217 Masked = ShiftReg & pTbl->Mask;
200- while(Masked) {
218+ while(Masked)
219+ {
201220 XorReg ^= Masked & 0x01;
202221 Masked >>= 1;
203222 }
204- if(XorReg) {
223+ if(XorReg)
224+ {
205225 ShiftReg |= pTbl->InputBit;
206226 }
207- else {
227+ else
228+ {
208229 ShiftReg &= ~pTbl->InputBit;
209230 }
210231 ShiftReg >>= 1;
@@ -232,13 +253,16 @@
232253 {
233254 b++;
234255 }
235- if (v < 0x80) {
256+ if (v < 0x80)
257+ {
236258 v += 0x80;
237259 }
238- else {
260+ else
261+ {
239262 v -= 0x80;
240263 }
241- if (SDMACNT <= index) {
264+ if (SDMACNT <= index)
265+ {
242266 index = 0;
243267 b = 0;
244268 }
@@ -250,7 +274,8 @@
250274 {
251275 b++;
252276 }
253- if (SDMACNT <= index) {
277+ if (SDMACNT <= index)
278+ {
254279 SDMACTL &= 0x7F; // DMA end
255280 SDMACNT = 0;
256281 index = 0;
@@ -262,8 +287,10 @@
262287
263288 void apuSweep(void)
264289 {
265- if ((Swp.step) && Swp.on) { // sweep on
266- if (Swp.cnt < 0) {
290+ if ((Swp.step) && Swp.on) // sweep on
291+ {
292+ if (Swp.cnt < 0)
293+ {
267294 Swp.cnt = Swp.time;
268295 Ch[2].freq += Swp.step;
269296 Ch[2].freq &= 0x7ff;
@@ -276,7 +303,8 @@
276303 {
277304 static int nPos = 0;
278305 // Noise counter
279- if (++nPos >= BUFSIZEN) {
306+ if (++nPos >= BUFSIZEN)
307+ {
280308 nPos = 0;
281309 }
282310 return RandData[nPos];
@@ -289,33 +317,50 @@
289317 int channel, index;
290318 short value, lVol[4], rVol[4];
291319 short LL, RR, vVol;
292- static int wPos = 0;
320+ static int wait = 0;
293321 short *dataAdr;
294322
323+ if (WsInputGetNowait())
324+ {
325+ wait = 1;
326+ }
327+ else if (wait)
328+ {
329+ wait = 0;
330+ apuWaveClear();
331+ }
295332 apuSweep();
296- for (channel = 0; channel < 4; channel++) {
333+ for (channel = 0; channel < 4; channel++)
334+ {
297335 lVol[channel] = 0;
298336 rVol[channel] = 0;
299- if (Ch[channel].on) {
300- if (channel == 1 && VoiceOn && Sound[4]) {
337+ if (Ch[channel].on)
338+ {
339+ if (channel == 1 && VoiceOn && Sound[4])
340+ {
301341 continue;
302342 }
303- else if (channel == 2 && Swp.on && !Sound[5]) {
343+ else if (channel == 2 && Swp.on && !Sound[5])
344+ {
304345 continue;
305346 }
306- else if (channel == 3 && Noise.on && Sound[6]){
347+ else if (channel == 3 && Noise.on && Sound[6])
348+ {
307349 index = (3072000 / BPSWAV) * point[3] / (2048 - Ch[3].freq);
308- if ((index %= BUFSIZEN) == 0 && preindex[3]) {
350+ if ((index %= BUFSIZEN) == 0 && preindex[3])
351+ {
309352 point[3] = 0;
310353 }
311354 value = (short)PDataN[Noise.pattern][index] - 8;
312355 }
313- else if (Sound[channel] == 0) {
356+ else if (Sound[channel] == 0)
357+ {
314358 continue;
315359 }
316360 else {
317361 index = (3072000 / BPSWAV) * point[channel] / (2048 - Ch[channel].freq);
318- if ((index %= 32) == 0 && preindex[channel]) {
362+ if ((index %= 32) == 0 && preindex[channel])
363+ {
319364 point[channel] = 0;
320365 }
321366 value = (short)PData[channel][index] - 8;
@@ -333,16 +378,21 @@
333378 dataAdr = (short*)(whdr[wBuf]->lpData);
334379 dataAdr[wPos * 2] = LL;
335380 dataAdr[wPos * 2 + 1] = RR;
336- if (++wPos >= BUFSIZEW) {
381+ if (++wPos >= BUFSIZEW)
382+ {
337383 waveOutWrite(hWaveOut, whdr[wBuf], sizeof(WAVEHDR));
338384 wPos = 0;
339- if (++wBuf >= BUFCOUNT) {
385+ if (++wBuf >= BUFCOUNT)
386+ {
340387 wBuf = 0;
341388 }
342- while (wBuf == rBuf) // 書き込みが再生に追いついた
343- {
344- Sleep(1); // WaveOutのコールバック関数でrBufが更新されるまで待つ
345- }
389+ if (wait == 0)
390+ {
391+ while (wBuf == rBuf) // 書き込みが再生に追いついた
392+ {
393+ Sleep(1); // WaveOutのコールバック関数でrBufが更新されるまで待つ
394+ }
395+ }
346396 }
347397 }
348398
--- oswanj/trunk/src/WSDraw.cpp (revision 80)
+++ oswanj/trunk/src/WSDraw.cpp (revision 81)
@@ -319,7 +319,7 @@
319319 if(DrawMode != Mode)
320320 {
321321 DrawMode = Mode;
322- SetKeyMap(Mode);
322+ WsInputSetKeyMap(Mode);
323323 WsResize();
324324 }
325325 return 0;
--- oswanj/trunk/src/WSInput.cpp (revision 80)
+++ oswanj/trunk/src/WSInput.cpp (revision 81)
@@ -200,10 +200,29 @@
200200 HRESULT hRet;
201201 BYTE diKeys[256];
202202 WORD JoyState = 0;
203- WORD ButtonState = 0;
203+ WORD KeyState = 0;
204204
205205 ZeroMemory(&js, sizeof(DIJOYSTATE2));
206206 ZeroMemory(diKeys, 256);
207+ if (lpKeyDevice != NULL)
208+ {
209+ hRet = lpKeyDevice->Acquire();
210+ if (hRet == DI_OK || hRet == S_FALSE)
211+ {
212+ hRet = lpKeyDevice->GetDeviceState(256, diKeys);
213+ if (hRet == DI_OK)
214+ {
215+ for (i = 0; i < 12; i++)
216+ {
217+ KeyState <<= 1;
218+ if (diKeys[WsKeyboard[i]] & 0x80)
219+ {
220+ KeyState |= 1;
221+ }
222+ }
223+ }
224+ }
225+ }
207226 if (lpJoyDevice != NULL)
208227 {
209228 hRet = lpJoyDevice->Poll();
@@ -210,11 +229,12 @@
210229 if (FAILED(hRet))
211230 {
212231 hRet = lpJoyDevice->Acquire();
213- while(hRet == DIERR_INPUTLOST)
232+ while (hRet == DIERR_INPUTLOST)
233+ {
214234 hRet = lpJoyDevice->Acquire();
215- return 0;
235+ }
236+ return KeyState;
216237 }
217-
218238 hRet = lpJoyDevice->GetDeviceState(sizeof(DIJOYSTATE2), &js);
219239 if (hRet == DI_OK){
220240 for (i = 0; i < 12; i++)
@@ -224,7 +244,32 @@
224244 }
225245 }
226246 }
247+ return JoyState | KeyState;
248+}
227249
250+void WsInputSetKeyMap(int mode)
251+{
252+ if (mode & 1)
253+ {
254+ WsJoypad = WsJoypadV;
255+ WsKeyboard = WsKeyboardV;
256+ }
257+ else
258+ {
259+ WsJoypad = WsJoypadH;
260+ WsKeyboard = WsKeyboardH;
261+ }
262+}
263+
264+int WsInputGetNowait(void)
265+{
266+ int i;
267+ HRESULT hRet;
268+ BYTE diKeys[256];
269+ int flag = 0;
270+
271+ ZeroMemory(&js, sizeof(DIJOYSTATE2));
272+ ZeroMemory(diKeys, 256);
228273 if (lpKeyDevice != NULL)
229274 {
230275 hRet = lpKeyDevice->Acquire();
@@ -233,30 +278,29 @@
233278 hRet = lpKeyDevice->GetDeviceState(256, diKeys);
234279 if (hRet == DI_OK)
235280 {
236- for (i = 0; i < 12; i++)
281+ if (diKeys[WsKeyboard[12]] & 0x80)
237282 {
238- ButtonState <<= 1;
239- if (diKeys[WsKeyboard[i]] & 0x80)
240- {
241- ButtonState |= 1;
242- }
283+ flag = 1;
243284 }
244285 }
245286 }
246287 }
247- return JoyState | ButtonState;
248-}
249-
250-void SetKeyMap(int mode)
251-{
252- if (mode & 1)
288+ if (lpJoyDevice != NULL)
253289 {
254- WsJoypad = WsJoypadV;
255- WsKeyboard = WsKeyboardV;
290+ hRet = lpJoyDevice->Poll();
291+ if (FAILED(hRet))
292+ {
293+ hRet = lpJoyDevice->Acquire();
294+ while (hRet == DIERR_INPUTLOST)
295+ {
296+ hRet = lpJoyDevice->Acquire();
297+ }
298+ return flag;
299+ }
300+ hRet = lpJoyDevice->GetDeviceState(sizeof(DIJOYSTATE2), &js);
301+ if (hRet == DI_OK){
302+ flag = WsInputCheckJoy(WsJoypad[12]);
303+ }
256304 }
257- else
258- {
259- WsJoypad = WsJoypadH;
260- WsKeyboard = WsKeyboardH;
261- }
305+ return flag;
262306 }
--- oswanj/trunk/src/WSInput.h (revision 80)
+++ oswanj/trunk/src/WSInput.h (revision 81)
@@ -57,6 +57,7 @@
5757 void WsInputRelease(void);
5858 int WsInputCheckJoy(int value);
5959 WORD WsInputGetState(void);
60-void SetKeyMap(int mode);
60+void WsInputSetKeyMap(int mode);
61+int WsInputGetNowait(void);
6162
6263 #endif
Show on old repository browser