• R/O
  • SSH
  • HTTPS

oswan: コミット


コミットメタ情報

リビジョン102 (tree)
日時2010-09-29 17:51:41
作者bird_may_nike

ログメッセージ

(メッセージはありません)

変更サマリ

差分

--- oswanj/trunk/src/WSFileio.cpp (revision 101)
+++ oswanj/trunk/src/WSFileio.cpp (nonexistent)
@@ -1,480 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include <shlwapi.h>
7-#include <stdio.h>
8-#include "WSHard.h"
9-#include "WS.h"
10-#include "WSDraw.h"
11-#include "WSFileio.h"
12-#include "WSPdata.h"
13-#include "WSError.h"
14-#include "WSRender.h"
15-#include "nec/necintrf.h"
16-
17-// ファイル操作は表などとディレクトリセパレータがかぶるのでUNICODEを使います
18-static wchar_t CurDir[512];
19-static wchar_t *SaveDir = L"RAM";
20-static wchar_t *StateDir = L"STATE";
21-static wchar_t SaveName[512]; // ".sav"
22-wchar_t StateName[512];
23-wchar_t IniPath[512];
24-
25-void WsSetDir(void)
26-{
27- wchar_t *p;
28-
29- wcscpy(CurDir, __wargv[0]);
30- p = wcsrchr(CurDir, L'\\');
31- if (p == NULL)
32- {
33- return;
34- }
35- *(++p) = 0;
36- wcscpy(IniPath, CurDir);
37- wcscat(IniPath, L"OswanJ.ini");
38-}
39-
40-int WsSetPdata(void)
41-{
42- ROMBanks = 1;
43- RAMBanks = 0;
44- RAMSize = 0;
45- CartKind = 0;
46- SaveName[0] = 0;
47- if ((ROMMap[0xFF] = (BYTE*)malloc(0x10000)) == NULL)
48- {
49- ErrorMsg(ERR_MALLOC);
50- return -1;
51- }
52- memcpy(ROMMap[0xFF] + 0xF080, pdata, size_pdata);
53- WsReset();
54- SetDrawMode(0);
55- return 0;
56-}
57-
58-int WsCreate(wchar_t *CartName)
59-{
60- int Checksum, i, j;
61- FILE* fp;
62- BYTE buf[16];
63- wchar_t* p;
64-
65- for (i = 0; i < 256; i++)
66- {
67- ROMMap[i] = MemDummy;
68- RAMMap[i] = MemDummy;
69- }
70- memset(IRAM, 0, sizeof(IRAM));
71- memset(MemDummy, 0xA0, sizeof(MemDummy));
72- memset(IO, 0, sizeof(IO));
73- if (CartName == NULL)
74- {
75- return WsSetPdata();
76- }
77- if ((fp = _wfopen(CartName, L"rb")) == NULL)
78- {
79- ErrorMsg(ERR_FOPEN);
80- return -1;
81- }
82- fseek(fp, -10, 2);
83- if (fread(buf, 1, 10, fp) != 10)
84- {
85- ErrorMsg(ERR_FREAD_ROMINFO);
86- return -1;
87- }
88- switch (buf[4])
89- {
90- case 1:
91- ROMBanks = 4;
92- break;
93- case 2:
94- ROMBanks = 8;
95- break;
96- case 3:
97- ROMBanks = 16;
98- break;
99- case 4:
100- ROMBanks = 32;
101- break;
102- case 5:
103- ROMBanks = 48;
104- break;
105- case 6:
106- ROMBanks = 64;
107- break;
108- case 7:
109- ROMBanks = 96;
110- break;
111- case 8:
112- ROMBanks = 128;
113- break;
114- case 9:
115- ROMBanks = 256;
116- break;
117- default:
118- ROMBanks = 0;
119- break;
120- }
121- if (ROMBanks == 0)
122- {
123- ErrorMsg(ERR_ILLEGAL_ROMSIZE);
124- return -1;
125- }
126- switch (buf[5])
127- {
128- case 0x01:
129- RAMBanks = 1;
130- RAMSize = 0x2000;
131- CartKind = 0;
132- break;
133- case 0x02:
134- RAMBanks = 1;
135- RAMSize = 0x8000;
136- CartKind = 0;
137- break;
138- case 0x03:
139- RAMBanks = 2;
140- RAMSize = 0x20000;
141- CartKind = 0;
142- break;
143- case 0x04:
144- RAMBanks = 4;
145- RAMSize = 0x40000;
146- CartKind = 0;
147- break;
148- case 0x10:
149- RAMBanks = 1;
150- RAMSize = 0x80;
151- CartKind = CK_EEP;
152- break;
153- case 0x20:
154- RAMBanks = 1;
155- RAMSize = 0x800;
156- CartKind = CK_EEP;
157- break;
158- case 0x50:
159- RAMBanks = 1;
160- RAMSize = 0x400;
161- CartKind = CK_EEP;
162- break;
163- default:
164- RAMBanks = 0;
165- RAMSize = 0;
166- CartKind = 0;
167- break;
168- }
169- WsRomPatch(buf);
170- Checksum = (int)((buf[9] << 8) + buf[8]);
171- Checksum += (int)(buf[9] + buf[8]);
172- for (i = ROMBanks - 1; i >= 0; i--)
173- {
174- fseek(fp, (ROMBanks - i) * -0x10000, 2);
175- if ((ROMMap[0x100 - ROMBanks + i] = (BYTE*)malloc(0x10000)) != NULL)
176- {
177- if (fread(ROMMap[0x100 - ROMBanks + i], 1, 0x10000, fp) == 0x10000)
178- {
179- for (j = 0; j < 0x10000; j++)
180- {
181- Checksum -= ROMMap[0x100 - ROMBanks + i][j];
182- }
183- }
184- else
185- {
186- ErrorMsg(ERR_FREAD_ROM);
187- break;
188- }
189- }
190- else
191- {
192- ErrorMsg(ERR_MALLOC);
193- break;
194- }
195- }
196- fclose(fp);
197- if (i >= 0)
198- {
199- return -1;
200- }
201- if (Checksum & 0xFFFF)
202- {
203- //ErrorMsg(ERR_CHECKSUM);
204- }
205- if (RAMBanks)
206- {
207- for (i = 0; i < RAMBanks; i++)
208- {
209- if ((RAMMap[i] = (BYTE*)malloc(0x10000)) != NULL)
210- {
211- memset(RAMMap[i], 0x00, 0x10000);
212- }
213- else
214- {
215- ErrorMsg(ERR_MALLOC);
216- return -1;
217- }
218- }
219- }
220- if (RAMSize)
221- {
222- wcscpy (SaveName, CurDir);
223- p = wcsrchr(CartName, L'\\');
224- if (p)
225- {
226- wcscat(SaveName, SaveDir);
227- if (PathIsDirectoryW(SaveName) == FALSE)
228- {
229- CreateDirectoryW(SaveName, NULL);
230- }
231- wcscat(SaveName, p);
232- p = wcsrchr(SaveName, L'.');
233- if (p)
234- {
235- *p = 0;
236- }
237- wcscat(SaveName, L".sav");
238- }
239- else
240- {
241- SaveName[0] = 0;
242- }
243- if ((fp = _wfopen(SaveName, L"rb")) != NULL)
244- {
245- for (i = 0; i < RAMBanks; i++)
246- {
247- if (RAMSize < 0x10000)
248- {
249- if (fread(RAMMap[i], 1, RAMSize, fp) != (size_t)RAMSize)
250- {
251- ErrorMsg(ERR_FREAD_SAVE);
252- break;
253- }
254- }
255- else
256- {
257- if (fread(RAMMap[i], 1, 0x10000, fp) != 0x10000)
258- {
259- ErrorMsg(ERR_FREAD_SAVE);
260- break;
261- }
262- }
263- }
264- fclose(fp);
265- }
266- }
267- else
268- {
269- SaveName[0] = 0;
270- }
271- wcscpy (StateName, CurDir);
272- p = wcsrchr(CartName, L'\\');
273- if (p)
274- {
275- wcscat(StateName, StateDir);
276- if (PathIsDirectoryW(StateName) == FALSE)
277- {
278- CreateDirectoryW(StateName, NULL);
279- }
280- wcscat(StateName, p);
281- p = wcsrchr(StateName, L'.');
282- if (p)
283- {
284- *p = 0;
285- }
286- }
287- WsReset();
288- SetDrawMode(buf[6] & 1); // 0:横 1:縦
289- return 0;
290-}
291-
292-void WsRelease(void)
293-{
294- FILE* fp;
295- int i;
296-
297- if (SaveName[0] != '\0')
298- {
299- if ((fp = _wfopen(SaveName, L"wb"))!= NULL)
300- {
301- for (i =0; i < RAMBanks; i++)
302- {
303- if (RAMSize<0x10000)
304- {
305- if (fwrite(RAMMap[i], 1, RAMSize, fp) != (size_t)RAMSize)
306- {
307- break;
308- }
309- }
310- else
311- {
312- if (fwrite(RAMMap[i], 1, 0x10000, fp)!=0x10000)
313- {
314- break;
315- }
316- }
317- free(RAMMap[i]);
318- RAMMap[i] = NULL;
319- }
320- fclose(fp);
321- }
322- SaveName[0] = '\0';
323- }
324- for (i = 0xFF; i >= 0; i--)
325- {
326- if (ROMMap[i] == MemDummy)
327- {
328- break;
329- }
330- free(ROMMap[i]);
331- ROMMap[i] = MemDummy;
332- }
333- StateName[0] = '\0';
334-}
335-
336-void WsLoadEeprom(void)
337-{
338- FILE* fp;
339- wchar_t buf[512];
340-
341- wcscpy(buf, CurDir);
342- wcscat(buf, L"eeprom.dat");
343- if ((fp = _wfopen(buf, L"rb")) != NULL)
344- {
345- fread(IEep, sizeof(WORD), 64, fp);
346- fclose(fp);
347- }
348- else
349- {
350- memset(IEep, 0xFF, 0x60);
351- memset(IEep + 0x60, 0, 0x20);
352- }
353-}
354-
355-void WsSaveEeprom(void)
356-{
357- FILE* fp;
358- wchar_t buf[512];
359-
360- wcscpy(buf, CurDir);
361- wcscat(buf, L"eeprom.dat");
362- if ((fp = _wfopen(buf, L"wb")) != NULL)
363- {
364- fwrite(IEep, sizeof(WORD), 64, fp);
365- fclose(fp);
366- }
367-}
368-
369-#define MacroLoadNecRegisterFromFile(F,R) \
370- fread(&value, sizeof(unsigned int), 1, fp); \
371- nec_set_reg(R,value);
372-void WsLoadState(int num)
373-{
374- FILE* fp;
375- wchar_t buf[512];
376- unsigned int value;
377- int i;
378-
379- wsprintf(buf, L"%s.%03d", StateName, num);
380- if ((fp = _wfopen(buf, L"rb")) == NULL)
381- {
382- return;
383- }
384- MacroLoadNecRegisterFromFile(fp,NEC_IP);
385- MacroLoadNecRegisterFromFile(fp,NEC_AW);
386- MacroLoadNecRegisterFromFile(fp,NEC_BW);
387- MacroLoadNecRegisterFromFile(fp,NEC_CW);
388- MacroLoadNecRegisterFromFile(fp,NEC_DW);
389- MacroLoadNecRegisterFromFile(fp,NEC_CS);
390- MacroLoadNecRegisterFromFile(fp,NEC_DS);
391- MacroLoadNecRegisterFromFile(fp,NEC_ES);
392- MacroLoadNecRegisterFromFile(fp,NEC_SS);
393- MacroLoadNecRegisterFromFile(fp,NEC_IX);
394- MacroLoadNecRegisterFromFile(fp,NEC_IY);
395- MacroLoadNecRegisterFromFile(fp,NEC_BP);
396- MacroLoadNecRegisterFromFile(fp,NEC_SP);
397- MacroLoadNecRegisterFromFile(fp,NEC_FLAGS);
398- MacroLoadNecRegisterFromFile(fp,NEC_VECTOR);
399- MacroLoadNecRegisterFromFile(fp,NEC_PENDING);
400- MacroLoadNecRegisterFromFile(fp,NEC_NMI_STATE);
401- MacroLoadNecRegisterFromFile(fp,NEC_IRQ_STATE);
402- fread(IRAM, sizeof(BYTE), 0x10000, fp);
403- fread(IO, sizeof(BYTE), 0x100, fp);
404- for (i =0; i < RAMBanks; i++)
405- {
406- if (RAMSize < 0x10000)
407- {
408- fread(RAMMap[i], 1, RAMSize, fp);
409- }
410- else
411- {
412- fread(RAMMap[i], 1, 0x10000, fp);
413- }
414- }
415- fread(Palette, sizeof(WORD), 16 * 16, fp);
416- fclose(fp);
417- WriteIO(0xC1, IO[0xC1]);
418- WriteIO(0xC2, IO[0xC2]);
419- WriteIO(0xC3, IO[0xC3]);
420- WriteIO(0xC0, IO[0xC0]);
421- for (i = 0x80; i <= 0x90; i++)
422- {
423- WriteIO(i, IO[i]);
424- }
425-}
426-
427-#define MacroStoreNecRegisterToFile(F,R) \
428- value = nec_get_reg(R); \
429- fwrite(&value, sizeof(unsigned int), 1, fp);
430-void WsSaveState(int num)
431-{
432- FILE* fp;
433- wchar_t buf[512];
434- unsigned int value;
435- int i;
436-
437- if (StateName[0] == '\0')
438- {
439- return;
440- }
441- wsprintf(buf, L"%s.%03d", StateName, num);
442- if ((fp = _wfopen(buf, L"wb")) == NULL)
443- {
444- return;
445- }
446- MacroStoreNecRegisterToFile(fp,NEC_IP);
447- MacroStoreNecRegisterToFile(fp,NEC_AW);
448- MacroStoreNecRegisterToFile(fp,NEC_BW);
449- MacroStoreNecRegisterToFile(fp,NEC_CW);
450- MacroStoreNecRegisterToFile(fp,NEC_DW);
451- MacroStoreNecRegisterToFile(fp,NEC_CS);
452- MacroStoreNecRegisterToFile(fp,NEC_DS);
453- MacroStoreNecRegisterToFile(fp,NEC_ES);
454- MacroStoreNecRegisterToFile(fp,NEC_SS);
455- MacroStoreNecRegisterToFile(fp,NEC_IX);
456- MacroStoreNecRegisterToFile(fp,NEC_IY);
457- MacroStoreNecRegisterToFile(fp,NEC_BP);
458- MacroStoreNecRegisterToFile(fp,NEC_SP);
459- MacroStoreNecRegisterToFile(fp,NEC_FLAGS);
460- MacroStoreNecRegisterToFile(fp,NEC_VECTOR);
461- MacroStoreNecRegisterToFile(fp,NEC_PENDING);
462- MacroStoreNecRegisterToFile(fp,NEC_NMI_STATE);
463- MacroStoreNecRegisterToFile(fp,NEC_IRQ_STATE);
464- fwrite(IRAM, sizeof(BYTE), 0x10000, fp);
465- fwrite(IO, sizeof(BYTE), 0x100, fp);
466- for (i =0; i < RAMBanks; i++)
467- {
468- if (RAMSize < 0x10000)
469- {
470- fwrite(RAMMap[i], 1, RAMSize, fp);
471- }
472- else
473- {
474- fwrite(RAMMap[i], 1, 0x10000, fp);
475- }
476- }
477- fwrite(Palette, sizeof(WORD), 16 * 16, fp);
478- fclose(fp);
479-}
480-
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSConfig.cpp (revision 101)
+++ oswanj/trunk/src/WSConfig.cpp (nonexistent)
@@ -1,142 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include <windows.h>
7-#include <stdio.h>
8-#include "WSconfig.h"
9-#include "WSInput.h"
10-#include "WSFileio.h"
11-
12-extern wchar_t* RecentOfn[];
13-extern int WsWaveVol;
14-static LPCWSTR KeyName[] = {
15- L"B", L"A", L"START", L"OPTION",
16- L"X4", L"X3", L"X2", L"X1",
17- L"Y4", L"Y3", L"Y2", L"Y1",
18- L"NOWAIT"
19-};
20-
21-void ConfigCreate(void)
22-{
23- int i;
24-
25- /* default values */
26- WsKeyboardH[0] = DIK_Z; // B
27- WsKeyboardH[1] = DIK_X; // A
28- WsKeyboardH[2] = DIK_RETURN; // START
29- WsKeyboardH[3] = DIK_LCONTROL; // OPTION
30- WsKeyboardH[4] = DIK_LEFT; // X4
31- WsKeyboardH[5] = DIK_DOWN; // X3
32- WsKeyboardH[6] = DIK_RIGHT; // X2
33- WsKeyboardH[7] = DIK_UP; // X1
34- WsKeyboardH[8] = DIK_A; // Y4
35- WsKeyboardH[9] = DIK_S; // Y3
36- WsKeyboardH[10] = DIK_D; // Y2
37- WsKeyboardH[11] = DIK_W; // Y1
38- WsKeyboardH[12] = DIK_SPACE; // NO WAIT
39-
40- WsKeyboardV[0] = DIK_Z; // B
41- WsKeyboardV[1] = DIK_X; // A
42- WsKeyboardV[2] = DIK_RETURN; // START
43- WsKeyboardV[3] = DIK_LCONTROL; // OPTION
44- WsKeyboardV[4] = DIK_S; // X4
45- WsKeyboardV[5] = DIK_D; // X3
46- WsKeyboardV[6] = DIK_W; // X2
47- WsKeyboardV[7] = DIK_A; // X1
48- WsKeyboardV[8] = DIK_DOWN; // Y4
49- WsKeyboardV[9] = DIK_RIGHT; // Y3
50- WsKeyboardV[10] = DIK_UP; // Y2
51- WsKeyboardV[11] = DIK_LEFT; // Y1
52- WsKeyboardV[12] = DIK_SPACE; // NO WAIT
53-
54- WsJoypadH[0] = 1; // B
55- WsJoypadH[1] = 2; // A
56- WsJoypadH[2] = 8; // START
57- WsJoypadH[3] = 0; // OPTION
58- WsJoypadH[4] = WS_JOY_AXIS_X_M; // X4
59- WsJoypadH[5] = WS_JOY_AXIS_Y_P; // X3
60- WsJoypadH[6] = WS_JOY_AXIS_X_P; // X2
61- WsJoypadH[7] = WS_JOY_AXIS_Y_M; // X1
62- WsJoypadH[8] = WS_JOY_POV1_LEFT; // Y4
63- WsJoypadH[9] = WS_JOY_POV1_DOWN; // Y3
64- WsJoypadH[10] = WS_JOY_POV1_RIGHT; // Y2
65- WsJoypadH[11] = WS_JOY_POV1_UP; // Y1
66- WsJoypadH[12] = 7; // NO WAIT
67-
68- WsJoypadV[0] = 5; // B
69- WsJoypadV[1] = 6; // A
70- WsJoypadV[2] = 8; // START
71- WsJoypadV[3] = 0; // OPTION
72- WsJoypadV[4] = 1; // X4
73- WsJoypadV[5] = 2; // X3
74- WsJoypadV[6] = 4; // X2
75- WsJoypadV[7] = 3; // X1
76- WsJoypadV[8] = WS_JOY_AXIS_Y_P; // Y4
77- WsJoypadV[9] = WS_JOY_AXIS_X_P; // Y3
78- WsJoypadV[10] = WS_JOY_AXIS_Y_M; // Y2
79- WsJoypadV[11] = WS_JOY_AXIS_X_M; // Y1
80- WsJoypadV[12] = 7; // NO WAIT
81-
82- for (i = 12; i >= 0; i--)
83- {
84- WsKeyboardH[i] = GetPrivateProfileIntW(L"KEY_H", KeyName[i], WsKeyboardH[i], IniPath);
85- }
86- for (i = 12; i >= 0; i--)
87- {
88- WsKeyboardV[i] = GetPrivateProfileIntW(L"KEY_V", KeyName[i], WsKeyboardV[i], IniPath);
89- }
90- for (i = 12; i >= 0; i--)
91- {
92- WsJoypadH[i] = GetPrivateProfileIntW(L"JOY_H", KeyName[i], WsJoypadH[i], IniPath);
93- }
94- for (i = 12; i >= 0; i--)
95- {
96- WsJoypadV[i] = GetPrivateProfileIntW(L"JOY_V", KeyName[i], WsJoypadV[i], IniPath);
97- }
98- GetPrivateProfileStringW(L"RECENT_ROMS", L"0", L"", RecentOfn[0], 512, IniPath);
99- GetPrivateProfileStringW(L"RECENT_ROMS", L"1", L"", RecentOfn[1], 512, IniPath);
100- GetPrivateProfileStringW(L"RECENT_ROMS", L"2", L"", RecentOfn[2], 512, IniPath);
101- GetPrivateProfileStringW(L"RECENT_ROMS", L"3", L"", RecentOfn[3], 512, IniPath);
102- GetPrivateProfileStringW(L"RECENT_ROMS", L"4", L"", RecentOfn[4], 512, IniPath);
103- GetPrivateProfileStringW(L"RECENT_ROMS", L"5", L"", RecentOfn[5], 512, IniPath);
104- WsWaveVol = GetPrivateProfileIntW(L"VOLUME", L"VOL", 4, IniPath);
105-}
106-
107-static void WritePrivateProfileIntW(LPCWSTR lpAppName, LPCWSTR lpKeyName, int nInt, LPCWSTR lpFileName)
108-{
109- wchar_t s[32];
110-
111- swprintf_s(s, 32, L"%d", nInt);
112- WritePrivateProfileStringW(lpAppName, lpKeyName, s, lpFileName);
113-}
114-
115-void ConfigRelease(void)
116-{
117- int i;
118-
119- for (i = 12; i >= 0; i--)
120- {
121- WritePrivateProfileIntW(L"KEY_H", KeyName[i], WsKeyboardH[i], IniPath);
122- }
123- for (i = 12; i >= 0; i--)
124- {
125- WritePrivateProfileIntW(L"KEY_V", KeyName[i], WsKeyboardV[i], IniPath);
126- }
127- for (i = 12; i >= 0; i--)
128- {
129- WritePrivateProfileIntW(L"JOY_H", KeyName[i], WsJoypadH[i], IniPath);
130- }
131- for (i = 12; i >= 0; i--)
132- {
133- WritePrivateProfileIntW(L"JOY_V", KeyName[i], WsJoypadV[i], IniPath);
134- }
135- WritePrivateProfileStringW(L"RECENT_ROMS", L"0", RecentOfn[0], IniPath);
136- WritePrivateProfileStringW(L"RECENT_ROMS", L"1", RecentOfn[1], IniPath);
137- WritePrivateProfileStringW(L"RECENT_ROMS", L"2", RecentOfn[2], IniPath);
138- WritePrivateProfileStringW(L"RECENT_ROMS", L"3", RecentOfn[3], IniPath);
139- WritePrivateProfileStringW(L"RECENT_ROMS", L"4", RecentOfn[4], IniPath);
140- WritePrivateProfileStringW(L"RECENT_ROMS", L"5", RecentOfn[5], IniPath);
141- WritePrivateProfileIntW(L"VOLUME", L"VOL", WsWaveVol, IniPath);
142-}
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSRender.cpp (revision 101)
+++ oswanj/trunk/src/WSRender.cpp (nonexistent)
@@ -1,817 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include <string.h>
7-#include "WSRender.h"
8-#include "WS.h"
9-#include "WSDraw.h"
10-#include "WSSegment.h"
11-
12-#define MAP_TILE 0x01FF
13-#define MAP_PAL 0x1E00
14-#define MAP_BANK 0x2000
15-#define MAP_HREV 0x4000
16-#define MAP_VREV 0x8000
17-BYTE *Scr1TMap;
18-BYTE *Scr2TMap;
19-
20-#define SPR_TILE 0x01FF
21-#define SPR_PAL 0x0E00
22-#define SPR_CLIP 0x1000
23-#define SPR_LAYR 0x2000
24-#define SPR_HREV 0x4000
25-#define SPR_VREV 0x8000
26-BYTE *SprTTMap;
27-BYTE *SprETMap;
28-BYTE SprTMap[512];
29-
30-WORD Palette[16][16];
31-WORD MonoColor[8];
32-WORD FrameBuffer[144][LINE_SIZE];
33-WORD SegmentBuffer[(144 * 4) * (8 * 4)]; // 8 * 144 の4倍のサイズで描画
34-int Layer[3] = {1, 1, 1};
35-int Segment[11];
36-
37-void SetPalette(int addr)
38-{
39- WORD color;
40-
41- // RGB444 format
42- color = *(WORD*)(IRAM + (addr & 0xFFFE));
43- Palette[(addr & 0x1E0) >> 5][(addr & 0x1E) >> 1] = color | 0xF000;
44-}
45-
46-void RefreshLine(int Line)
47-{
48- WORD *pSBuf; // データ書き込みバッファ
49- WORD *pSWrBuf; // ↑の書き込み位置用ポインタ
50- int *pZ; // ↓のインクリメント用ポインタ
51- int ZBuf[0x100]; // FGレイヤーの非透明部を保存
52- int *pW; // ↓のインクリメント用ポインタ
53- int WBuf[0x100]; // FGレイヤーのウィンドーを保存
54- int OffsetX; //
55- int OffsetY; //
56- BYTE *pbTMap; //
57- int TMap; //
58- int TMapX; //
59- int TMapXEnd; //
60- BYTE *pbTData; //
61- int PalIndex; //
62- int i, j, k, index[8];
63- WORD BaseCol; //
64- pSBuf = FrameBuffer[Line] + 8;
65- pSWrBuf = pSBuf;
66-
67- if(IO[LCDSLP] & 0x01)
68- {
69- if(IO[COLCTL] & 0xE0)
70- {
71- BaseCol = Palette[(IO[BORDER] & 0xF0) >> 4][IO[BORDER] & 0x0F];
72- }
73- else
74- {
75- BaseCol = MonoColor[IO[BORDER] & 0x07];
76- }
77- }
78- else
79- {
80- BaseCol = 0;
81- }
82- for(i = 0; i < 224; i++)
83- {
84- {
85- *pSWrBuf++ = BaseCol;
86- }
87- }
88- if(!(IO[LCDSLP] & 0x01)) return;
89-/*********************************************************************/
90- if((IO[DSPCTL] & 0x01) && Layer[0]) //BG layer
91- {
92- OffsetX = IO[SCR1X] & 0x07;
93- pSWrBuf = pSBuf - OffsetX;
94- i = Line + IO[SCR1Y];
95- OffsetY = (i & 0x07);
96-
97- pbTMap = Scr1TMap + ((i & 0xF8) << 3);
98- TMapX = (IO[SCR1X] & 0xF8) >> 2;
99- TMapXEnd = ((IO[SCR1X] + 224 + 7) >> 2) & 0xFFE;
100-
101- for(; TMapX < TMapXEnd;)
102- {
103- TMap = *(pbTMap + (TMapX++ & 0x3F));
104- TMap |= *(pbTMap + (TMapX++ & 0x3F)) << 8;
105-
106- if(IO[COLCTL] & 0x40) // 16 colors
107- {
108- if(TMap & MAP_BANK)
109- {
110- pbTData = IRAM + 0x8000;
111- }
112- else
113- {
114- pbTData = IRAM + 0x4000;
115- }
116- pbTData += (TMap & MAP_TILE) << 5;
117- if(TMap & MAP_VREV)
118- {
119- pbTData += (7 - OffsetY) << 2;
120- }
121- else
122- {
123- pbTData += OffsetY << 2;
124- }
125- }
126- else
127- {
128- if((IO[COLCTL] & 0x80) && (TMap & MAP_BANK))// 4 colors and bank 1
129- {
130- pbTData = IRAM + 0x4000;
131- }
132- else
133- {
134- pbTData = IRAM + 0x2000;
135- }
136- pbTData += (TMap & MAP_TILE) << 4;
137- if(TMap & MAP_VREV)
138- {
139- pbTData += (7 - OffsetY) << 1;
140- }
141- else
142- {
143- pbTData += OffsetY << 1;
144- }
145- }
146-
147- if(IO[COLCTL] & 0x20) // Packed Mode
148- {
149- if(IO[COLCTL] & 0x40) // 16 Color
150- {
151- index[0] = (pbTData[0] & 0xF0) >> 4;
152- index[1] = pbTData[0] & 0x0F;
153- index[2] = (pbTData[1] & 0xF0) >> 4;
154- index[3] = pbTData[1] & 0x0F;
155- index[4] = (pbTData[2] & 0xF0) >> 4;
156- index[5] = pbTData[2] & 0x0F;
157- index[6] = (pbTData[3] & 0xF0) >> 4;
158- index[7] = pbTData[3] & 0x0F;
159- }
160- else // 4 Color
161- {
162- index[0] = (pbTData[0] & 0xC0) >> 6;
163- index[1] = (pbTData[0] & 0x30) >> 4;
164- index[2] = (pbTData[0] & 0x0C) >> 2;
165- index[3] = pbTData[0] & 0x03;
166- index[4] = (pbTData[1] & 0xC0) >> 6;
167- index[5] = (pbTData[1] & 0x30) >> 4;
168- index[6] = (pbTData[1] & 0x0C) >> 2;
169- index[7] = pbTData[1] & 0x03;
170- }
171- }
172- else
173- {
174- if(IO[COLCTL] & 0x40) // 16 Color
175- {
176- index[0] = (pbTData[0] & 0x80) ? 0x1 : 0;
177- index[0] |= (pbTData[1] & 0x80) ? 0x2 : 0;
178- index[0] |= (pbTData[2] & 0x80) ? 0x4 : 0;
179- index[0] |= (pbTData[3] & 0x80) ? 0x8 : 0;
180- index[1] = (pbTData[0] & 0x40) ? 0x1 : 0;
181- index[1] |= (pbTData[1] & 0x40) ? 0x2 : 0;
182- index[1] |= (pbTData[2] & 0x40) ? 0x4 : 0;
183- index[1] |= (pbTData[3] & 0x40) ? 0x8 : 0;
184- index[2] = (pbTData[0] & 0x20) ? 0x1 : 0;
185- index[2] |= (pbTData[1] & 0x20) ? 0x2 : 0;
186- index[2] |= (pbTData[2] & 0x20) ? 0x4 : 0;
187- index[2] |= (pbTData[3] & 0x20) ? 0x8 : 0;
188- index[3] = (pbTData[0] & 0x10) ? 0x1 : 0;
189- index[3] |= (pbTData[1] & 0x10) ? 0x2 : 0;
190- index[3] |= (pbTData[2] & 0x10) ? 0x4 : 0;
191- index[3] |= (pbTData[3] & 0x10) ? 0x8 : 0;
192- index[4] = (pbTData[0] & 0x08) ? 0x1 : 0;
193- index[4] |= (pbTData[1] & 0x08) ? 0x2 : 0;
194- index[4] |= (pbTData[2] & 0x08) ? 0x4 : 0;
195- index[4] |= (pbTData[3] & 0x08) ? 0x8 : 0;
196- index[5] = (pbTData[0] & 0x04) ? 0x1 : 0;
197- index[5] |= (pbTData[1] & 0x04) ? 0x2 : 0;
198- index[5] |= (pbTData[2] & 0x04) ? 0x4 : 0;
199- index[5] |= (pbTData[3] & 0x04) ? 0x8 : 0;
200- index[6] = (pbTData[0] & 0x02) ? 0x1 : 0;
201- index[6] |= (pbTData[1] & 0x02) ? 0x2 : 0;
202- index[6] |= (pbTData[2] & 0x02) ? 0x4 : 0;
203- index[6] |= (pbTData[3] & 0x02) ? 0x8 : 0;
204- index[7] = (pbTData[0] & 0x01) ? 0x1 : 0;
205- index[7] |= (pbTData[1] & 0x01) ? 0x2 : 0;
206- index[7] |= (pbTData[2] & 0x01) ? 0x4 : 0;
207- index[7] |= (pbTData[3] & 0x01) ? 0x8 : 0;
208- }
209- else // 4 Color
210- {
211- index[0] = (pbTData[0] & 0x80) ? 0x1 : 0;
212- index[0] |= (pbTData[1] & 0x80) ? 0x2 : 0;
213- index[1] = (pbTData[0] & 0x40) ? 0x1 : 0;
214- index[1] |= (pbTData[1] & 0x40) ? 0x2 : 0;
215- index[2] = (pbTData[0] & 0x20) ? 0x1 : 0;
216- index[2] |= (pbTData[1] & 0x20) ? 0x2 : 0;
217- index[3] = (pbTData[0] & 0x10) ? 0x1 : 0;
218- index[3] |= (pbTData[1] & 0x10) ? 0x2 : 0;
219- index[4] = (pbTData[0] & 0x08) ? 0x1 : 0;
220- index[4] |= (pbTData[1] & 0x08) ? 0x2 : 0;
221- index[5] = (pbTData[0] & 0x04) ? 0x1 : 0;
222- index[5] |= (pbTData[1] & 0x04) ? 0x2 : 0;
223- index[6] = (pbTData[0] & 0x02) ? 0x1 : 0;
224- index[6] |= (pbTData[1] & 0x02) ? 0x2 : 0;
225- index[7] = (pbTData[0] & 0x01) ? 0x1 : 0;
226- index[7] |= (pbTData[1] & 0x01) ? 0x2 : 0;
227- }
228- }
229-
230- if(TMap & MAP_HREV)
231- {
232- j = index[0];
233- index[0] = index[7];
234- index[7] = j;
235- j = index[1];
236- index[1] = index[6];
237- index[6] = j;
238- j = index[2];
239- index[2] = index[5];
240- index[5] = j;
241- j = index[3];
242- index[3] = index[4];
243- index[4] = j;
244- }
245-
246- PalIndex = (TMap & MAP_PAL) >> 9;
247- if((!index[0]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
248- else
249- {
250- *pSWrBuf++ = Palette[PalIndex][index[0]];
251- }
252- if((!index[1]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
253- else
254- {
255- *pSWrBuf++ = Palette[PalIndex][index[1]];
256- }
257- if((!index[2]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
258- else
259- {
260- *pSWrBuf++ = Palette[PalIndex][index[2]];
261- }
262- if((!index[3]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
263- else
264- {
265- *pSWrBuf++ = Palette[PalIndex][index[3]];
266- }
267- if((!index[4]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
268- else
269- {
270- *pSWrBuf++ = Palette[PalIndex][index[4]];
271- }
272- if((!index[5]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
273- else
274- {
275- *pSWrBuf++ = Palette[PalIndex][index[5]];
276- }
277- if((!index[6]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
278- else
279- {
280- *pSWrBuf++ = Palette[PalIndex][index[6]];
281- }
282- if((!index[7]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) pSWrBuf++;
283- else
284- {
285- *pSWrBuf++ = Palette[PalIndex][index[7]];
286- }
287- }
288- }
289-/*********************************************************************/
290- memset(ZBuf, 0, sizeof(ZBuf));
291- if((IO[DSPCTL] & 0x02) && Layer[1]) //FG layer表示
292- {
293- if((IO[DSPCTL] & 0x30) == 0x20) // ウィンドウ内部のみに表示
294- {
295- for(i = 0, pW = WBuf + 8; i < 224; i++)
296- {
297- *pW++ = 1;
298- }
299- if((Line >= IO[SCR2WT]) && (Line <= IO[SCR2WB]))
300- {
301- for(i = IO[SCR2WL], pW = WBuf + 8 + i; (i <= IO[SCR2WR]) && (i < 224); i++)
302- {
303- *pW++ = 0;
304- }
305- }
306- }
307- else if((IO[DSPCTL] & 0x30) == 0x30) // ウィンドウ外部のみに表示
308- {
309- for(i = 0, pW = WBuf + 8; i < 224; i++)
310- {
311- *pW++ = 0;
312- }
313- if((Line >= IO[SCR2WT]) && (Line <= IO[SCR2WB]))
314- {
315- for(i = IO[SCR2WL], pW = WBuf + 8 + i; (i <= IO[SCR2WR]) && (i < 224); i++)
316- {
317- *pW++ = 1;
318- }
319- }
320- }
321- else
322- {
323- for(i = 0, pW = WBuf + 8; i < 224; i++)
324- {
325- *pW++ = 0;
326- }
327- }
328-
329- OffsetX = IO[SCR2X] & 0x07;
330- pSWrBuf = pSBuf - OffsetX;
331- i = Line + IO[SCR2Y];
332- OffsetY = (i & 0x07);
333-
334- pbTMap = Scr2TMap + ((i & 0xF8) << 3);
335- TMapX = (IO[SCR2X] & 0xF8) >> 2;
336- TMapXEnd = ((IO[SCR2X] + 224 + 7) >> 2) & 0xFFE;
337-
338- pW = WBuf + 8 - OffsetX;
339- pZ = ZBuf + 8 - OffsetX;
340-
341- for(; TMapX < TMapXEnd;)
342- {
343- TMap = *(pbTMap + (TMapX++ & 0x3F));
344- TMap |= *(pbTMap + (TMapX++ & 0x3F)) << 8;
345-
346- if(IO[COLCTL] & 0x40)
347- {
348- if(TMap & MAP_BANK)
349- {
350- pbTData = IRAM + 0x8000;
351- }
352- else
353- {
354- pbTData = IRAM + 0x4000;
355- }
356- pbTData += (TMap & MAP_TILE) << 5;
357- if(TMap & MAP_VREV)
358- {
359- pbTData += (7 - OffsetY) << 2;
360- }
361- else
362- {
363- pbTData += OffsetY << 2;
364- }
365- }
366- else
367- {
368- if((IO[COLCTL] & 0x80) && (TMap & MAP_BANK))// 4 colors and bank 1
369- {
370- pbTData = IRAM + 0x4000;
371- }
372- else
373- {
374- pbTData = IRAM + 0x2000;
375- }
376- pbTData += (TMap & MAP_TILE) << 4;
377- if(TMap & MAP_VREV)
378- {
379- pbTData += (7 - OffsetY) << 1;
380- }
381- else
382- {
383- pbTData += OffsetY << 1;
384- }
385- }
386-
387- if(IO[COLCTL] & 0x20) // Packed Mode
388- {
389- if(IO[COLCTL] & 0x40) // 16 Color
390- {
391- index[0] = (pbTData[0] & 0xF0) >> 4;
392- index[1] = pbTData[0] & 0x0F;
393- index[2] = (pbTData[1] & 0xF0) >> 4;
394- index[3] = pbTData[1] & 0x0F;
395- index[4] = (pbTData[2] & 0xF0) >> 4;
396- index[5] = pbTData[2] & 0x0F;
397- index[6] = (pbTData[3] & 0xF0) >> 4;
398- index[7] = pbTData[3] & 0x0F;
399- }
400- else // 4 Color
401- {
402- index[0] = (pbTData[0] & 0xC0) >> 6;
403- index[1] = (pbTData[0] & 0x30) >> 4;
404- index[2] = (pbTData[0] & 0x0C) >> 2;
405- index[3] = pbTData[0] & 0x03;
406- index[4] = (pbTData[1] & 0xC0) >> 6;
407- index[5] = (pbTData[1] & 0x30) >> 4;
408- index[6] = (pbTData[1] & 0x0C) >> 2;
409- index[7] = pbTData[1] & 0x03;
410- }
411- }
412- else
413- {
414- if(IO[COLCTL] & 0x40) // 16 Color
415- {
416- index[0] = (pbTData[0] & 0x80) ? 0x1 : 0;
417- index[0] |= (pbTData[1] & 0x80) ? 0x2 : 0;
418- index[0] |= (pbTData[2] & 0x80) ? 0x4 : 0;
419- index[0] |= (pbTData[3] & 0x80) ? 0x8 : 0;
420- index[1] = (pbTData[0] & 0x40) ? 0x1 : 0;
421- index[1] |= (pbTData[1] & 0x40) ? 0x2 : 0;
422- index[1] |= (pbTData[2] & 0x40) ? 0x4 : 0;
423- index[1] |= (pbTData[3] & 0x40) ? 0x8 : 0;
424- index[2] = (pbTData[0] & 0x20) ? 0x1 : 0;
425- index[2] |= (pbTData[1] & 0x20) ? 0x2 : 0;
426- index[2] |= (pbTData[2] & 0x20) ? 0x4 : 0;
427- index[2] |= (pbTData[3] & 0x20) ? 0x8 : 0;
428- index[3] = (pbTData[0] & 0x10) ? 0x1 : 0;
429- index[3] |= (pbTData[1] & 0x10) ? 0x2 : 0;
430- index[3] |= (pbTData[2] & 0x10) ? 0x4 : 0;
431- index[3] |= (pbTData[3] & 0x10) ? 0x8 : 0;
432- index[4] = (pbTData[0] & 0x08) ? 0x1 : 0;
433- index[4] |= (pbTData[1] & 0x08) ? 0x2 : 0;
434- index[4] |= (pbTData[2] & 0x08) ? 0x4 : 0;
435- index[4] |= (pbTData[3] & 0x08) ? 0x8 : 0;
436- index[5] = (pbTData[0] & 0x04) ? 0x1 : 0;
437- index[5] |= (pbTData[1] & 0x04) ? 0x2 : 0;
438- index[5] |= (pbTData[2] & 0x04) ? 0x4 : 0;
439- index[5] |= (pbTData[3] & 0x04) ? 0x8 : 0;
440- index[6] = (pbTData[0] & 0x02) ? 0x1 : 0;
441- index[6] |= (pbTData[1] & 0x02) ? 0x2 : 0;
442- index[6] |= (pbTData[2] & 0x02) ? 0x4 : 0;
443- index[6] |= (pbTData[3] & 0x02) ? 0x8 : 0;
444- index[7] = (pbTData[0] & 0x01) ? 0x1 : 0;
445- index[7] |= (pbTData[1] & 0x01) ? 0x2 : 0;
446- index[7] |= (pbTData[2] & 0x01) ? 0x4 : 0;
447- index[7] |= (pbTData[3] & 0x01) ? 0x8 : 0;
448- }
449- else // 4 Color
450- {
451- index[0] = (pbTData[0] & 0x80) ? 0x1 : 0;
452- index[0] |= (pbTData[1] & 0x80) ? 0x2 : 0;
453- index[1] = (pbTData[0] & 0x40) ? 0x1 : 0;
454- index[1] |= (pbTData[1] & 0x40) ? 0x2 : 0;
455- index[2] = (pbTData[0] & 0x20) ? 0x1 : 0;
456- index[2] |= (pbTData[1] & 0x20) ? 0x2 : 0;
457- index[3] = (pbTData[0] & 0x10) ? 0x1 : 0;
458- index[3] |= (pbTData[1] & 0x10) ? 0x2 : 0;
459- index[4] = (pbTData[0] & 0x08) ? 0x1 : 0;
460- index[4] |= (pbTData[1] & 0x08) ? 0x2 : 0;
461- index[5] = (pbTData[0] & 0x04) ? 0x1 : 0;
462- index[5] |= (pbTData[1] & 0x04) ? 0x2 : 0;
463- index[6] = (pbTData[0] & 0x02) ? 0x1 : 0;
464- index[6] |= (pbTData[1] & 0x02) ? 0x2 : 0;
465- index[7] = (pbTData[0] & 0x01) ? 0x1 : 0;
466- index[7] |= (pbTData[1] & 0x01) ? 0x2 : 0;
467- }
468- }
469-
470- if(TMap & MAP_HREV)
471- {
472- j = index[0];
473- index[0] = index[7];
474- index[7] = j;
475- j = index[1];
476- index[1] = index[6];
477- index[6] = j;
478- j = index[2];
479- index[2] = index[5];
480- index[5] = j;
481- j = index[3];
482- index[3] = index[4];
483- index[4] = j;
484- }
485-
486- PalIndex = (TMap & MAP_PAL) >> 9;
487- if(((!index[0]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
488- else
489- {
490- *pSWrBuf++ = Palette[PalIndex][index[0]];
491- *pZ = 1;
492- }
493- pW++;pZ++;
494- if(((!index[1]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
495- else
496- {
497- *pSWrBuf++ = Palette[PalIndex][index[1]];
498- *pZ = 1;
499- }
500- pW++;pZ++;
501- if(((!index[2]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
502- else
503- {
504- *pSWrBuf++ = Palette[PalIndex][index[2]];
505- *pZ = 1;
506- }
507- pW++;pZ++;
508- if(((!index[3]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
509- else
510- {
511- *pSWrBuf++ = Palette[PalIndex][index[3]];
512- *pZ = 1;
513- }
514- pW++;pZ++;
515- if(((!index[4]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
516- else
517- {
518- *pSWrBuf++ = Palette[PalIndex][index[4]];
519- *pZ = 1;
520- }
521- pW++;pZ++;
522- if(((!index[5]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
523- else
524- {
525- *pSWrBuf++ = Palette[PalIndex][index[5]];
526- *pZ = 1;
527- }
528- pW++;pZ++;
529- if(((!index[6]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
530- else
531- {
532- *pSWrBuf++ = Palette[PalIndex][index[6]];
533- *pZ = 1;
534- }
535- pW++;pZ++;
536- if(((!index[7]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800))))) || (*pW)) pSWrBuf++;
537- else
538- {
539- *pSWrBuf++ = Palette[PalIndex][index[7]];
540- *pZ = 1;
541- }
542- pW++;pZ++;
543- }
544- }
545-/*********************************************************************/
546- if((IO[DSPCTL] & 0x04) && Layer[2]) //sprite
547- {
548- if (IO[DSPCTL] & 0x08) //sprite window
549- {
550- for (i = 0, pW = WBuf + 8; i < 224; i++)
551- {
552- *pW++ = 1;
553- }
554- if ((Line >= IO[SPRWT]) && (Line <= IO[SPRWB]))
555- {
556- for (i = IO[SPRWL], pW = WBuf + 8 + i; (i <= IO[SPRWR]) && (i < 224); i++)
557- {
558- *pW++ = 0;
559- }
560- }
561- }
562-
563- for (pbTMap = SprETMap; pbTMap >= SprTTMap; pbTMap -= 4) //
564- {
565- TMap = pbTMap[0];
566- TMap |= pbTMap[1] << 8;
567-
568- if (pbTMap[2] > 0xF8)
569- {
570- j = pbTMap[2] - 0x100;
571- }
572- else
573- {
574- j = pbTMap[2];
575- }
576- if (pbTMap[3] > 0xF8)
577- {
578- k = pbTMap[3] - 0x100;
579- }
580- else
581- {
582- k = pbTMap[3];
583- }
584-
585- if (Line < j)
586- continue;
587- if (Line >= j + 8)
588- continue;
589- if (224 <= k)
590- continue;
591-
592- i = k;
593- pSWrBuf = pSBuf + i;
594-
595- if (IO[COLCTL] & 0x40)
596- {
597- pbTData = IRAM + 0x4000;
598- pbTData += (TMap & SPR_TILE) << 5;
599- if (TMap & SPR_VREV)
600- {
601- pbTData += (7 - Line + j) << 2;
602- }
603- else
604- {
605- pbTData += (Line - j) << 2;
606- }
607- }
608- else
609- {
610- pbTData = IRAM + 0x2000;
611- pbTData += (TMap & SPR_TILE) << 4;
612- if (TMap & SPR_VREV)
613- {
614- pbTData += (7 - Line + j) << 1;
615- }
616- else
617- {
618- pbTData += (Line - j) << 1;
619- }
620- }
621-
622- if(IO[COLCTL] & 0x20) // Packed Mode
623- {
624- if(IO[COLCTL] & 0x40) // 16 Color
625- {
626- index[0] = (pbTData[0] & 0xF0) >> 4;
627- index[1] = pbTData[0] & 0x0F;
628- index[2] = (pbTData[1] & 0xF0) >> 4;
629- index[3] = pbTData[1] & 0x0F;
630- index[4] = (pbTData[2] & 0xF0) >> 4;
631- index[5] = pbTData[2] & 0x0F;
632- index[6] = (pbTData[3] & 0xF0) >> 4;
633- index[7] = pbTData[3] & 0x0F;
634- }
635- else // 4 Color
636- {
637- index[0] = (pbTData[0] & 0xC0) >> 6;
638- index[1] = (pbTData[0] & 0x30) >> 4;
639- index[2] = (pbTData[0] & 0x0C) >> 2;
640- index[3] = pbTData[0] & 0x03;
641- index[4] = (pbTData[1] & 0xC0) >> 6;
642- index[5] = (pbTData[1] & 0x30) >> 4;
643- index[6] = (pbTData[1] & 0x0C) >> 2;
644- index[7] = pbTData[1] & 0x03;
645- }
646- }
647- else
648- {
649- if(IO[COLCTL] & 0x40) // 16 Color
650- {
651- index[0] = (pbTData[0] & 0x80) ? 0x1 : 0;
652- index[0] |= (pbTData[1] & 0x80) ? 0x2 : 0;
653- index[0] |= (pbTData[2] & 0x80) ? 0x4 : 0;
654- index[0] |= (pbTData[3] & 0x80) ? 0x8 : 0;
655- index[1] = (pbTData[0] & 0x40) ? 0x1 : 0;
656- index[1] |= (pbTData[1] & 0x40) ? 0x2 : 0;
657- index[1] |= (pbTData[2] & 0x40) ? 0x4 : 0;
658- index[1] |= (pbTData[3] & 0x40) ? 0x8 : 0;
659- index[2] = (pbTData[0] & 0x20) ? 0x1 : 0;
660- index[2] |= (pbTData[1] & 0x20) ? 0x2 : 0;
661- index[2] |= (pbTData[2] & 0x20) ? 0x4 : 0;
662- index[2] |= (pbTData[3] & 0x20) ? 0x8 : 0;
663- index[3] = (pbTData[0] & 0x10) ? 0x1 : 0;
664- index[3] |= (pbTData[1] & 0x10) ? 0x2 : 0;
665- index[3] |= (pbTData[2] & 0x10) ? 0x4 : 0;
666- index[3] |= (pbTData[3] & 0x10) ? 0x8 : 0;
667- index[4] = (pbTData[0] & 0x08) ? 0x1 : 0;
668- index[4] |= (pbTData[1] & 0x08) ? 0x2 : 0;
669- index[4] |= (pbTData[2] & 0x08) ? 0x4 : 0;
670- index[4] |= (pbTData[3] & 0x08) ? 0x8 : 0;
671- index[5] = (pbTData[0] & 0x04) ? 0x1 : 0;
672- index[5] |= (pbTData[1] & 0x04) ? 0x2 : 0;
673- index[5] |= (pbTData[2] & 0x04) ? 0x4 : 0;
674- index[5] |= (pbTData[3] & 0x04) ? 0x8 : 0;
675- index[6] = (pbTData[0] & 0x02) ? 0x1 : 0;
676- index[6] |= (pbTData[1] & 0x02) ? 0x2 : 0;
677- index[6] |= (pbTData[2] & 0x02) ? 0x4 : 0;
678- index[6] |= (pbTData[3] & 0x02) ? 0x8 : 0;
679- index[7] = (pbTData[0] & 0x01) ? 0x1 : 0;
680- index[7] |= (pbTData[1] & 0x01) ? 0x2 : 0;
681- index[7] |= (pbTData[2] & 0x01) ? 0x4 : 0;
682- index[7] |= (pbTData[3] & 0x01) ? 0x8 : 0;
683- }
684- else // 4 Color
685- {
686- index[0] = (pbTData[0] & 0x80) ? 0x1 : 0;
687- index[0] |= (pbTData[1] & 0x80) ? 0x2 : 0;
688- index[1] = (pbTData[0] & 0x40) ? 0x1 : 0;
689- index[1] |= (pbTData[1] & 0x40) ? 0x2 : 0;
690- index[2] = (pbTData[0] & 0x20) ? 0x1 : 0;
691- index[2] |= (pbTData[1] & 0x20) ? 0x2 : 0;
692- index[3] = (pbTData[0] & 0x10) ? 0x1 : 0;
693- index[3] |= (pbTData[1] & 0x10) ? 0x2 : 0;
694- index[4] = (pbTData[0] & 0x08) ? 0x1 : 0;
695- index[4] |= (pbTData[1] & 0x08) ? 0x2 : 0;
696- index[5] = (pbTData[0] & 0x04) ? 0x1 : 0;
697- index[5] |= (pbTData[1] & 0x04) ? 0x2 : 0;
698- index[6] = (pbTData[0] & 0x02) ? 0x1 : 0;
699- index[6] |= (pbTData[1] & 0x02) ? 0x2 : 0;
700- index[7] = (pbTData[0] & 0x01) ? 0x1 : 0;
701- index[7] |= (pbTData[1] & 0x01) ? 0x2 : 0;
702- }
703- }
704-
705- if (TMap & SPR_HREV)
706- {
707- j = index[0];
708- index[0] = index[7];
709- index[7] = j;
710- j = index[1];
711- index[1] = index[6];
712- index[6] = j;
713- j = index[2];
714- index[2] = index[5];
715- index[5] = j;
716- j = index[3];
717- index[3] = index[4];
718- index[4] = j;
719- }
720-
721- pW = WBuf + 8 + k;
722- pZ = ZBuf + k + 8;
723- PalIndex = ((TMap & SPR_PAL) >> 9) + 8;
724- for(i = 0; i < 8; i++, pZ++, pW++)
725- {
726- if(IO[DSPCTL] & 0x08)
727- {
728- if(TMap & SPR_CLIP)
729- {
730- if(!*pW)
731- {
732- pSWrBuf++;
733- continue;
734- }
735- }
736- else
737- {
738- if(*pW)
739- {
740- pSWrBuf++;
741- continue;
742- }
743- }
744- }
745- if((!index[i]) && (!(!(IO[COLCTL] & 0x40) && (!(TMap & 0x0800)))))
746- {
747- pSWrBuf++;
748- continue;
749- }
750- if((*pZ) && (!(TMap & SPR_LAYR)))
751- {
752- pSWrBuf++;
753- continue;
754- }
755- *pSWrBuf++ = Palette[PalIndex][index[i]];
756- }
757- }
758- }
759-}
760-
761-/*
762- 8 * 144 のサイズを 32 * 576 で描画
763-*/
764-void RenderSegment(void)
765-{
766- int bit, x, y, i;
767- WORD* p = SegmentBuffer;
768- BYTE lcd[11] = {0x20, 0x10, 0x08, 0x04, 0x02, 0x40, 0, 0, 0x01, 0x80, 0}; // 大、中、小、横、縦、ヘッドホン、音量、電池、スリープ
769-
770- for (i = 0; i < 11; i++)
771- {
772- for (y = 0; y < segLine[i]; y++)
773- {
774- for (x = 0; x < 4; x++)
775- {
776- BYTE ch = seg[i][y * 4 + x];
777- for (bit = 0; bit < 8; bit++)
778- {
779- if (ch & 0x80)
780- {
781- if (Segment[i])
782- {
783- *p++ = 0xFCCC;
784- }
785- else
786- {
787- *p++ = 0xF222;
788- }
789- }
790- else
791- {
792- *p++ = 0xF000;
793- }
794- ch <<= 1;
795- }
796- }
797- }
798- }
799-}
800-
801-void RenderSleep(void)
802-{
803- int x, y;
804- WORD* p;
805-
806- // 背景をグレイでクリア
807- p = FrameBuffer[0] + 8;
808- for (y = 0; y < 144; y++)
809- {
810- for (x = 0; x < 224; x++)
811- {
812- *p++ = 0xF444;
813- }
814- p += 32;
815- }
816- drawDraw();
817-}
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSError.cpp (revision 101)
+++ oswanj/trunk/src/WSError.cpp (nonexistent)
@@ -1,17 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include <windows.h>
7-#include <tchar.h>
8-#include "WSError.h"
9-
10-void ErrorMsg(long err)
11-{
12- TCHAR dst[512];
13-
14- _stprintf_s(dst, 512, TEXT("%lX"), err);
15- MessageBox(NULL, dst, TEXT("WS エラー"), MB_OK);
16-}
17-
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSInput.cpp (revision 101)
+++ oswanj/trunk/src/WSInput.cpp (nonexistent)
@@ -1,305 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include "WSInput.h"
7-
8-int WsKeyboardH[13];
9-int WsKeyboardV[13];
10-int WsJoypadH[13];
11-int WsJoypadV[13];
12-LPDIRECTINPUTDEVICE8 lpKeyDevice;
13-LPDIRECTINPUTDEVICE8 lpJoyDevice;
14-static int* WsJoypad;
15-static int* WsKeyboard;
16-static LPDIRECTINPUT8 lpDInput;
17-static DIJOYSTATE2 js;
18-
19-BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* lpddi, LPVOID lpContext)
20-{
21- HRESULT hRet;
22-
23- hRet = lpDInput->CreateDevice(lpddi->guidInstance, &lpJoyDevice, NULL);
24- if(FAILED(hRet)) return DIENUM_CONTINUE;
25-
26- return DIENUM_STOP;
27-}
28-
29-int WsInputJoyInit(HWND hw)
30-{
31- HRESULT hRet;
32- if (lpJoyDevice != NULL)
33- return TRUE;
34-
35- hRet = lpDInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY);
36- if (hRet != DI_OK){
37- if (lpJoyDevice != NULL)
38- {
39- lpJoyDevice->Release();
40- lpJoyDevice = NULL;
41- }
42- return FALSE;
43- }
44- if (lpJoyDevice == NULL)
45- {
46- return FALSE;
47- }
48- hRet = lpJoyDevice->SetDataFormat(&c_dfDIJoystick2);
49- if (hRet != DI_OK){
50- if (lpJoyDevice != NULL)
51- {
52- lpJoyDevice->Release();
53- lpJoyDevice = NULL;
54- }
55- return FALSE;
56- }
57- hRet = lpJoyDevice->SetCooperativeLevel(hw, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
58- if (hRet != DI_OK){
59- if (lpJoyDevice != NULL)
60- {
61- lpJoyDevice->Release();
62- lpJoyDevice = NULL;
63- }
64- return FALSE;
65- }
66- lpJoyDevice->Acquire();
67-
68- return TRUE;
69-}
70-
71-int WsInputInit(HWND hw)
72-{
73- DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&lpDInput, NULL);
74- lpDInput->CreateDevice(GUID_SysKeyboard, &lpKeyDevice, NULL);
75- lpKeyDevice->SetDataFormat(&c_dfDIKeyboard);
76- lpKeyDevice->SetCooperativeLevel(hw, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
77- return WsInputJoyInit(hw);
78-}
79-
80-void WsInputJoyRelease(void)
81-{
82- if (lpJoyDevice != NULL)
83- {
84- lpJoyDevice->Unacquire();
85- lpJoyDevice->Release();
86- lpJoyDevice = NULL;
87- }
88-}
89-
90-void WsInputRelease(void)
91-{
92- if (lpKeyDevice != NULL)
93- {
94- lpKeyDevice->Unacquire();
95- lpKeyDevice->Release();
96- lpKeyDevice = NULL;
97- }
98- if (lpDInput != NULL)
99- {
100- lpDInput->Release();
101- lpDInput = NULL;
102- }
103- WsInputJoyRelease();
104-}
105-
106-#define HALFRECT JOY_POVRIGHT / 2
107-int WsInputCheckJoy(int value)
108-{
109- int i;
110-
111- if ((value >= 1) && (value <= 128))
112- {
113- return((js.rgbButtons[value - 1] & 0x80) ? 1 : 0);
114- }
115- if ((value & 0x1100) == 0x100)
116- {
117- i = (value & 0x30) >> 4;
118- switch (value & 0x0F)
119- {
120- case 1:
121- if (js.rgdwPOV[i] == JOY_POVLEFT + HALFRECT) return 1;
122- if (js.rgdwPOV[i] == JOY_POVFORWARD) return 1;
123- if (js.rgdwPOV[i] == JOY_POVFORWARD + HALFRECT) return 1;
124- break;
125- case 2:
126- if (js.rgdwPOV[i] == JOY_POVFORWARD + HALFRECT) return 1;
127- if (js.rgdwPOV[i] == JOY_POVRIGHT) return 1;
128- if (js.rgdwPOV[i] == JOY_POVRIGHT + HALFRECT) return 1;
129- break;
130- case 4:
131- if (js.rgdwPOV[i] == JOY_POVRIGHT + HALFRECT) return 1;
132- if (js.rgdwPOV[i] == JOY_POVBACKWARD) return 1;
133- if (js.rgdwPOV[i] == JOY_POVBACKWARD + HALFRECT) return 1;
134- break;
135- case 8:
136- if (js.rgdwPOV[i] == JOY_POVBACKWARD + HALFRECT) return 1;
137- if (js.rgdwPOV[i] == JOY_POVLEFT) return 1;
138- if (js.rgdwPOV[i] == JOY_POVLEFT + HALFRECT) return 1;
139- break;
140- }
141- return 0;
142- }
143- switch (value)
144- {
145- case WS_JOY_AXIS_X_P:
146- if (js.lX > 0xC000) return 1;
147- break;
148- case WS_JOY_AXIS_X_M:
149- if (js.lX < 0x4000) return 1;
150- break;
151- case WS_JOY_AXIS_Y_P:
152- if (js.lY > 0xC000) return 1;
153- break;
154- case WS_JOY_AXIS_Y_M:
155- if (js.lY < 0x4000) return 1;
156- break;
157- case WS_JOY_AXIS_Z_P:
158- if (js.lZ > 0xC000) return 1;
159- break;
160- case WS_JOY_AXIS_Z_M:
161- if (js.lZ < 0x4000) return 1;
162- break;
163- case WS_JOY_AXIS_RX_P:
164- if (js.lRx > 0xC000) return 1;
165- break;
166- case WS_JOY_AXIS_RX_M:
167- if (js.lRx < 0x4000) return 1;
168- break;
169- case WS_JOY_AXIS_RY_P:
170- if (js.lRy > 0xC000) return 1;
171- break;
172- case WS_JOY_AXIS_RY_M:
173- if (js.lRy < 0x4000) return 1;
174- break;
175- case WS_JOY_AXIS_RZ_P:
176- if (js.lRz > 0xC000) return 1;
177- break;
178- case WS_JOY_AXIS_RZ_M:
179- if (js.lRz < 0x4000) return 1;
180- break;
181- case WS_JOY_SLIDER1_P:
182- if (js.rglSlider[0] > 0xC000) return 1;
183- break;
184- case WS_JOY_SLIDER1_M:
185- if (js.rglSlider[0] < 0x4000) return 1;
186- break;
187- case WS_JOY_SLIDER2_P:
188- if (js.rglSlider[1] > 0xC000) return 1;
189- break;
190- case WS_JOY_SLIDER2_M:
191- if (js.rglSlider[1] < 0x4000) return 1;
192- break;
193- }
194- return 0;
195-}
196-
197-WORD WsInputGetState(void)
198-{
199- int i;
200- HRESULT hRet;
201- BYTE diKeys[256];
202- WORD JoyState = 0;
203- WORD KeyState = 0;
204-
205- ZeroMemory(&js, sizeof(DIJOYSTATE2));
206- 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- }
226- if (lpJoyDevice != NULL)
227- {
228- hRet = lpJoyDevice->Poll();
229- if (FAILED(hRet))
230- {
231- hRet = lpJoyDevice->Acquire();
232- while (hRet == DIERR_INPUTLOST)
233- {
234- hRet = lpJoyDevice->Acquire();
235- }
236- return KeyState;
237- }
238- hRet = lpJoyDevice->GetDeviceState(sizeof(DIJOYSTATE2), &js);
239- if (hRet == DI_OK){
240- for (i = 0; i < 12; i++)
241- {
242- JoyState <<= 1;
243- JoyState |= WsInputCheckJoy(WsJoypad[i]);
244- }
245- }
246- }
247- return JoyState | KeyState;
248-}
249-
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- HRESULT hRet;
267- BYTE diKeys[256];
268- int flag = 0;
269-
270- ZeroMemory(&js, sizeof(DIJOYSTATE2));
271- ZeroMemory(diKeys, 256);
272- if (lpKeyDevice != NULL)
273- {
274- hRet = lpKeyDevice->Acquire();
275- if (hRet == DI_OK || hRet == S_FALSE)
276- {
277- hRet = lpKeyDevice->GetDeviceState(256, diKeys);
278- if (hRet == DI_OK)
279- {
280- if (diKeys[WsKeyboard[12]] & 0x80)
281- {
282- flag = 1;
283- }
284- }
285- }
286- }
287- if (lpJoyDevice != NULL)
288- {
289- hRet = lpJoyDevice->Poll();
290- if (FAILED(hRet))
291- {
292- hRet = lpJoyDevice->Acquire();
293- while (hRet == DIERR_INPUTLOST)
294- {
295- hRet = lpJoyDevice->Acquire();
296- }
297- return flag;
298- }
299- hRet = lpJoyDevice->GetDeviceState(sizeof(DIJOYSTATE2), &js);
300- if (hRet == DI_OK){
301- flag |= WsInputCheckJoy(WsJoypad[12]);
302- }
303- }
304- return flag;
305-}
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSApu.cpp (revision 101)
+++ oswanj/trunk/src/WSApu.cpp (nonexistent)
@@ -1,494 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include <windows.h>
7-#include <mmsystem.h>
8-#include "../resource.h"
9-#include "WSHard.h"
10-#include "WSApu.h"
11-#include "WSError.h"
12-#include "WSInput.h"
13-
14-#define BUFSIZEN 0x10000
15-#define BPSWAV 12000 // WSのHblankが12KHz
16-#define BUFSIZEW 64
17-#define BUFCOUNT 30
18-
19-unsigned long WaveMap;
20-SOUND Ch[4];
21-int VoiceOn;
22-SWEEP Swp;
23-NOISE Noise;
24-int Sound[7] = {1, 1, 1, 1, 1, 1, 1};
25-int WsWaveVol = 4;
26-
27-static unsigned char PData[4][32];
28-static unsigned char PDataN[8][BUFSIZEN];
29-static unsigned int RandData[BUFSIZEN];
30-
31-static HWAVEOUT hWaveOut;
32-static WAVEHDR *whdr[BUFCOUNT];
33-static int rBuf, wBuf, wPos;
34-
35-extern HWND hWnd;
36-extern BYTE *Page[16];
37-extern BYTE IO[0x100];
38-
39-
40-
41-void CALLBACK apuWaveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
42-{
43- switch (uMsg)
44- {
45- case WOM_OPEN:
46- break;
47- case WOM_DONE:
48- rBuf++;
49- if (rBuf >= BUFCOUNT)
50- {
51- rBuf = 0;
52- }
53- break;
54- case WOM_CLOSE:
55- break;
56- }
57-}
58-
59-int apuWaveCreate(void)
60-{
61- MMRESULT result;
62- WAVEFORMATEX wfe;
63- int i;
64- TCHAR msg[255];
65-
66- rBuf = 0;
67- wBuf = 0;
68- wPos = 0;
69- ZeroMemory(&wfe, sizeof(wfe));
70- wfe.wFormatTag = WAVE_FORMAT_PCM;
71- wfe.nChannels = 2;
72- wfe.wBitsPerSample = 16;
73- wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample / 8;
74- wfe.nSamplesPerSec = BPSWAV;
75- wfe.nAvgBytesPerSec = wfe.nSamplesPerSec * wfe.nBlockAlign;
76- result = waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfe, (DWORD_PTR)apuWaveOutProc, NULL, CALLBACK_FUNCTION);
77- if (result != MMSYSERR_NOERROR )
78- {
79- waveOutGetErrorText(result, msg, sizeof(msg));
80- ErrorMsg(ERR_WAVEOUT_OPEN);
81- }
82- for (i = 0; i < BUFCOUNT; i++)
83- {
84- whdr[i] = (WAVEHDR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WAVEHDR));
85- whdr[i]->lpData = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, BUFSIZEW * 4);
86- whdr[i]->dwBufferLength = BUFSIZEW * 4;
87- whdr[i]->dwFlags = 0;
88- whdr[i]->dwLoops = 0;
89- result = waveOutPrepareHeader(hWaveOut, whdr[i], sizeof(WAVEHDR));
90- if (result != MMSYSERR_NOERROR )
91- {
92- waveOutGetErrorText(result, msg, sizeof(msg));
93- ErrorMsg(ERR_WAVEOUT_PREPAREHEADER);
94- }
95- }
96- return 0;
97-}
98-
99-void apuWaveRelease(void)
100-{
101- int i;
102-
103- waveOutReset(hWaveOut);
104- for(i = 0; i < BUFCOUNT; i++)
105- {
106- if (whdr[i])
107- {
108- waveOutUnprepareHeader(hWaveOut,whdr[i],sizeof(WAVEHDR));
109- HeapFree(GetProcessHeap(),0,whdr[i]->lpData);
110- HeapFree(GetProcessHeap(),0,whdr[i]);
111- whdr[i] = NULL;
112- }
113- }
114- waveOutClose(hWaveOut);
115- return;
116-}
117-
118-void apuWaveClear(void)
119-{
120- int i;
121-
122- waveOutReset(hWaveOut);
123- for (i = 0; i < BUFCOUNT; i++)
124- {
125- ZeroMemory(whdr[i]->lpData, BUFSIZEW * 4);
126- }
127- rBuf = 0;
128- wBuf = 0;
129- wPos = 0;
130-}
131-
132-int apuInit(void)
133-{
134- int i, j;
135-
136- for (i = 0; i < 4; i++)
137- {
138- for (j = 0; j < 32; j++)
139- {
140- PData[i][j] = 8;
141- }
142- }
143- for (i = 0; i < 8; i++)
144- {
145- for (j = 0; j < BUFSIZEN; j++)
146- {
147- PDataN[i][j] = ((apuMrand(15 - i) & 1) ? 15 : 0);
148- }
149- }
150-
151- for (i = 0; i < BUFSIZEN; i++)
152- {
153- RandData[i] = apuMrand(15);
154- }
155- apuWaveCreate();
156- return 0;
157-}
158-
159-void apuEnd(void)
160-{
161- apuWaveRelease();
162- apuDestroySound();
163-}
164-
165-unsigned int apuMrand(unsigned int Degree)
166-{
167-#define BIT(n) (1<<n)
168- typedef struct
169- {
170- unsigned int N;
171- int InputBit;
172- int Mask;
173- } POLYNOMIAL;
174-
175- static POLYNOMIAL TblMask[]=
176- {
177- { 2,BIT(2) ,BIT(0)|BIT(1)},
178- { 3,BIT(3) ,BIT(0)|BIT(1)},
179- { 4,BIT(4) ,BIT(0)|BIT(1)},
180- { 5,BIT(5) ,BIT(0)|BIT(2)},
181- { 6,BIT(6) ,BIT(0)|BIT(1)},
182- { 7,BIT(7) ,BIT(0)|BIT(1)},
183- { 8,BIT(8) ,BIT(0)|BIT(2)|BIT(3)|BIT(4)},
184- { 9,BIT(9) ,BIT(0)|BIT(4)},
185- {10,BIT(10),BIT(0)|BIT(3)},
186- {11,BIT(11),BIT(0)|BIT(2)},
187- {12,BIT(12),BIT(0)|BIT(1)|BIT(4)|BIT(6)},
188- {13,BIT(13),BIT(0)|BIT(1)|BIT(3)|BIT(4)},
189- {14,BIT(14),BIT(0)|BIT(1)|BIT(4)|BIT(5)},
190- {15,BIT(15),BIT(0)|BIT(1)},
191- { 0, 0, 0},
192- };
193- static POLYNOMIAL *pTbl = TblMask;
194- static int ShiftReg = BIT(2)-1;
195- int XorReg = 0;
196- int Masked;
197-
198- if(pTbl->N != Degree)
199- {
200- pTbl = TblMask;
201- while(pTbl->N) {
202- if(pTbl->N == Degree)
203- {
204- break;
205- }
206- pTbl++;
207- }
208- if(!pTbl->N)
209- {
210- pTbl--;
211- }
212- ShiftReg &= pTbl->InputBit-1;
213- if(!ShiftReg)
214- {
215- ShiftReg = pTbl->InputBit-1;
216- }
217- }
218- Masked = ShiftReg & pTbl->Mask;
219- while(Masked)
220- {
221- XorReg ^= Masked & 0x01;
222- Masked >>= 1;
223- }
224- if(XorReg)
225- {
226- ShiftReg |= pTbl->InputBit;
227- }
228- else
229- {
230- ShiftReg &= ~pTbl->InputBit;
231- }
232- ShiftReg >>= 1;
233- return ShiftReg;
234-}
235-
236-void apuSetPData(int addr, unsigned char val)
237-{
238- int i, j;
239-
240- i = (addr & 0x30) >> 4;
241- j = (addr & 0x0F) << 1;
242- PData[i][j]=(unsigned char)(val & 0x0F);
243- PData[i][j + 1]=(unsigned char)((val & 0xF0)>>4);
244-}
245-
246-unsigned char apuVoice(void)
247-{
248- static int index = 0, b = 0;
249- unsigned char v;
250-
251- if ((IO[SDMACTL] & 0x98) == 0x98) { // Hyper voice
252- v = Page[IO[SDMASH] + b][*(WORD*)(IO + SDMASL) + index++];
253- if ((*(WORD*)(IO + SDMASL) + index) == 0)
254- {
255- b++;
256- }
257- if (v < 0x80)
258- {
259- v += 0x80;
260- }
261- else
262- {
263- v -= 0x80;
264- }
265- if (*(WORD*)(IO+SDMACNT) <= index)
266- {
267- index = 0;
268- b = 0;
269- }
270- return v;
271- }
272- else if ((IO[SDMACTL] & 0x88) == 0x80) { // DMA start
273- IO[SND2VOL] = Page[IO[SDMASH] + b][*(WORD*)(IO + SDMASL) + index++];
274- if ((*(WORD*)(IO + SDMASL) + index) == 0)
275- {
276- b++;
277- }
278- if (*(WORD*)(IO + SDMACNT) <= index)
279- {
280- IO[SDMACTL] &= 0x7F; // DMA end
281- *(WORD*)(IO + SDMACNT) = 0;
282- index = 0;
283- b = 0;
284- }
285- }
286- return ((VoiceOn && Sound[4]) ? IO[SND2VOL] : 0x80);
287-}
288-
289-void apuSweep(void)
290-{
291- if ((Swp.step) && Swp.on) // sweep on
292- {
293- if (Swp.cnt < 0)
294- {
295- Swp.cnt = Swp.time;
296- Ch[2].freq += Swp.step;
297- Ch[2].freq &= 0x7ff;
298- }
299- Swp.cnt--;
300- }
301-}
302-
303-WORD apuShiftReg(void)
304-{
305- static int nPos = 0;
306- // Noise counter
307- if (++nPos >= BUFSIZEN)
308- {
309- nPos = 0;
310- }
311- return RandData[nPos];
312-}
313-
314-void apuWaveSet(void)
315-{
316- static int point[] = {0, 0, 0, 0};
317- static int preindex[] = {0, 0, 0, 0};
318- int channel, index;
319- short value, lVol[4], rVol[4];
320- short LL, RR, vVol;
321- static int wait = 0;
322- short *dataAdr;
323-
324- if (WsInputGetNowait())
325- {
326- wait = 1;
327- }
328- else if (wait)
329- {
330- wait = 0;
331- apuWaveClear();
332- }
333- apuSweep();
334- for (channel = 0; channel < 4; channel++)
335- {
336- lVol[channel] = 0;
337- rVol[channel] = 0;
338- if (Ch[channel].on)
339- {
340- if (channel == 1 && VoiceOn && Sound[4])
341- {
342- continue;
343- }
344- else if (channel == 2 && Swp.on && !Sound[5])
345- {
346- continue;
347- }
348- else if (channel == 3 && Noise.on && Sound[6])
349- {
350- index = (3072000 / BPSWAV) * point[3] / (2048 - Ch[3].freq);
351- if ((index %= BUFSIZEN) == 0 && preindex[3])
352- {
353- point[3] = 0;
354- }
355- value = (short)PDataN[Noise.pattern][index] - 8;
356- }
357- else if (Sound[channel] == 0)
358- {
359- continue;
360- }
361- else {
362- index = (3072000 / BPSWAV) * point[channel] / (2048 - Ch[channel].freq);
363- if ((index %= 32) == 0 && preindex[channel])
364- {
365- point[channel] = 0;
366- }
367- value = (short)PData[channel][index] - 8;
368- }
369- preindex[channel] = index;
370- point[channel]++;
371- lVol[channel] = value * Ch[channel].volL; // -8*15=-120, 7*15=105
372- rVol[channel] = value * Ch[channel].volR;
373- }
374- }
375- vVol = ((short)apuVoice() - 0x80);
376- // mix 16bits wave -32768 ~ +32767 32768/120 = 273
377- LL = (lVol[0] + lVol[1] + lVol[2] + lVol[3] + vVol) * WsWaveVol;
378- RR = (rVol[0] + rVol[1] + rVol[2] + rVol[3] + vVol) * WsWaveVol;
379- dataAdr = (short*)(whdr[wBuf]->lpData);
380- dataAdr[wPos * 2] = LL;
381- dataAdr[wPos * 2 + 1] = RR;
382- if (++wPos >= BUFSIZEW)
383- {
384- waveOutWrite(hWaveOut, whdr[wBuf], sizeof(WAVEHDR));
385- wPos = 0;
386- if (++wBuf >= BUFCOUNT)
387- {
388- wBuf = 0;
389- }
390- if (wait == 0)
391- {
392- while (wBuf == rBuf) // 書き込みが再生に追いついた
393- {
394- Sleep(1); // WaveOutのコールバック関数でrBufが更新されるまで待つ
395- }
396- }
397- }
398-}
399-
400-/*
401-PlaySound()は音量調節が出来ないのでいったんメモリに読み込んで
402-プレイ時にデータを加工する
403-*/
404-static void* SSMasterBuf;
405-static void* SSPlayBuf;
406-static DWORD SSDataLen, SSHeadLen;
407-
408-void apuLoadSound(void)
409-{
410- HINSTANCE hInst;
411- HRSRC hRsrc;
412- HGLOBAL hG;
413- BYTE* wave;
414- BYTE* tmp;
415- DWORD wfesize;
416-
417- hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
418- hRsrc = FindResource(hInst, MAKEINTRESOURCE(IDR_WAVE1), TEXT("WAVE"));
419- hG = LoadResource(hInst, hRsrc);
420- wave = (BYTE*)LockResource(hG); //RIFFヘッダの確認
421- tmp = wave;
422- if (*(LPDWORD)wave != *(LPDWORD)"RIFF")
423- {
424- ErrorMsg(ERR_WAVERESOURCE);
425- return;
426- }
427- wave += 4; //ポインタは次を指しておく
428- wave += 4; //ポインタは次を指しておく
429- //WAVEヘッダの確認
430- if (*(LPDWORD)wave != *(LPDWORD)"WAVE")
431- {
432- ErrorMsg(ERR_WAVERESOURCE);
433- return;
434- }
435- wave += 4; //ポインタは次を指しておく
436- //fmtチャンクの確認
437- if (*(LPDWORD)wave != *(LPDWORD)"fmt ")
438- {
439- ErrorMsg(ERR_WAVERESOURCE);
440- return;
441- }
442- wave += 4; //ポインタは次を指しておく
443- //fmtチャンクサイズの取得
444- wfesize = *(DWORD *)wave;
445- wave += 4; //ポインタは次を指しておく
446- wave += wfesize; //WAVEFORMATEX構造体分だけポインタを進めておく
447- //dataチャンクの確認
448- if (*(LPDWORD)wave != *(LPDWORD)"data")
449- {
450- ErrorMsg(ERR_WAVERESOURCE);
451- return;
452- }
453- wave += 4; //ポインタは次を指しておく
454- //波形データのバイト数の取得
455- SSDataLen = *(DWORD *)wave;
456- wave += 4; //ポインタは次を指しておく
457- SSHeadLen = wave - tmp;
458- SSMasterBuf = malloc(SSDataLen);
459- SSPlayBuf = malloc(SSHeadLen + SSDataLen);
460- if (SSMasterBuf != NULL && SSPlayBuf != NULL)
461- {
462- memcpy(SSMasterBuf, wave, SSDataLen);
463- memcpy(SSPlayBuf, tmp, SSHeadLen);
464- }
465- FreeResource(hG);
466-}
467-
468-void apuDestroySound(void)
469-{
470- free(SSMasterBuf);
471- SSMasterBuf = NULL;
472- free(SSPlayBuf);
473- SSPlayBuf = NULL;
474-}
475-
476-void apuStartupSound(void)
477-{
478- short *src, *dst;
479- int i;
480- int size = SSDataLen / sizeof(short);
481-
482- if (SSMasterBuf == NULL || SSPlayBuf == NULL)
483- {
484- return;
485- }
486- src = (short*)SSMasterBuf;
487- dst = (short*)((BYTE*)SSPlayBuf + SSHeadLen);
488- // マスターの音量を変更してプレイバッファーにコピー
489- for (i = 0; i < size; i++)
490- {
491- *dst++ = (*src++) * WsWaveVol / 32;
492- }
493- PlaySound((LPCTSTR)SSPlayBuf, NULL, SND_MEMORY | SND_ASYNC);
494-}
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WS.cpp (revision 101)
+++ oswanj/trunk/src/WS.cpp (nonexistent)
@@ -1,1119 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include <time.h>
7-#include "WSRender.h"
8-#include "WS.h"
9-#include "WSDraw.h"
10-#include "WSInput.h"
11-#include "WSApu.h"
12-#include "WSFileio.h"
13-#include "WSPdata.h"
14-#include "WSBandai.h"
15-#include "WSError.h"
16-#include "nec/necintrf.h"
17-
18-#define IPeriod 32 // HBlank/8 (256/8)
19-
20-int Run;
21-BYTE *Page[16]; // バンク割り当て
22-BYTE IRAM[0x10000]; // 内部RAM 64kB = Page[0]
23-BYTE IO[0x100]; // IO
24-BYTE MemDummy[0x10000]; // ダミーバンク 64kB
25-BYTE *ROMMap[0x100]; // C-ROMバンクマップ
26-int ROMBanks; // C-ROMバンク数
27-BYTE *RAMMap[0x100]; // C-RAMバンクマップ
28-int RAMBanks; // C-RAMバンク数
29-int RAMSize; // C-RAM総容量
30-WORD IEep[64]; // 内蔵EEPROM
31-struct EEPROM sIEep; // EEPROM読み書き用構造体(内蔵)
32-struct EEPROM sCEep; // EEPROM読み書き用構造体(カートリッジ)
33-int CartKind; // セーブメモリの種類(CK_EEP = EEPROM)
34-
35-static int ButtonState = 0x0000; // Button state: B.A.START.OPTION.X4.X3.X2.X1.Y4.Y3.Y2.Y1
36-static WORD HTimer;
37-static WORD VTimer;
38-static int RtcCount;
39-static int RAMEnable;
40-static int FrameSkip = 0;
41-static int SkipCnt = 0;
42-static int TblSkip[5][5] = {
43- {1,1,1,1,1},
44- {0,1,1,1,1},
45- {0,1,0,1,1},
46- {0,0,1,0,1},
47- {0,0,0,0,1},
48-};
49-#define MONO(C) 0xF000 | (C)<<8 | (C)<<4 | (C)
50-static WORD DefColor[] = {
51- MONO(0xF), MONO(0xE), MONO(0xD), MONO(0xC), MONO(0xB), MONO(0xA), MONO(0x9), MONO(0x8),
52- MONO(0x7), MONO(0x6), MONO(0x5), MONO(0x4), MONO(0x3), MONO(0x2), MONO(0x1), MONO(0x0)
53-};
54-
55-void ComEeprom(struct EEPROM *eeprom, WORD *cmd, WORD *data)
56-{
57- int i, j, op, addr;
58- const int tblmask[16][5]=
59- {
60- {0x0000, 0, 0x0000, 0, 0x0000}, // dummy
61- {0x0000, 0, 0x0000, 0, 0x0000},
62- {0x0000, 0, 0x0000, 0, 0x0000},
63- {0x0000, 0, 0x0000, 0, 0x0000},
64- {0x000C, 2, 0x0003, 0, 0x0003},
65- {0x0018, 3, 0x0006, 1, 0x0007},
66- {0x0030, 4, 0x000C, 2, 0x000F},
67- {0x0060, 5, 0x0018, 3, 0x001F},
68- {0x00C0, 6, 0x0030, 4, 0x003F}, // 1Kbits IEEPROM
69- {0x0180, 7, 0x0060, 5, 0x007F},
70- {0x0300, 8, 0x00C0, 6, 0x00FF},
71- {0x0600, 9, 0x0180, 7, 0x01FF},
72- {0x0C00, 10, 0x0300, 8, 0x03FF}, // 16Kbits
73- {0x1800, 11, 0x0600, 9, 0x07FF},
74- {0x3000, 12, 0x0C00, 10, 0x0FFF},
75- {0x6000, 13, 0x1800, 11, 0x1FFF},
76- };
77- if(eeprom->data == NULL)
78- {
79- return;
80- }
81- for(i = 15, j = 0x8000; i >= 0; i--, j >>= 1)
82- {
83- if(*cmd & j)
84- {
85- break;
86- }
87- }
88- op = (*cmd & tblmask[i][0]) >> tblmask[i][1];
89- switch(op)
90- {
91- case 0:
92- addr = (*cmd & tblmask[i][2]) >> tblmask[i][3];
93- switch(addr)
94- {
95- case 0: // 書込み禁止
96- eeprom->we = 0;
97- break;
98- case 1: // 全アドレス書き込み
99- for(j = tblmask[i][4]; j >= 0; j--)
100- {
101- eeprom->data[j] = *data;
102- }
103- break;
104- case 2: // チップ消去
105- if(eeprom->we)
106- {
107- memset(eeprom->data, 0xFF, sizeof(eeprom->data)*2);
108- }
109- break;
110- case 3: // 書き込み可能
111- eeprom->we = 1;
112- break;
113- }
114- *data = 0;
115- break;
116- case 1: // 書き込み
117- if(eeprom->we)
118- {
119- addr = *cmd & tblmask[i][4];
120- eeprom->data[addr] = *data;
121- if (ROMBanks == 1 && addr == 0x3A) // アナザヘブンも書き込んでた
122- {
123- WsSplash();
124- Run = 0; // パーソナルデータ最後の書き込みなので終了
125- }
126- }
127- *data = 0;
128- break;
129- case 2: // 読み出し
130- addr = *cmd & tblmask[i][4];
131- *data = eeprom->data[addr];
132- break;
133- case 3: // 消去
134- if(eeprom->we)
135- {
136- addr = *cmd & tblmask[i][4];
137- eeprom->data[addr] = 0xFFFF;
138- }
139- *data = 0;
140- break;
141- default: break;
142- }
143-}
144-
145-BYTE ReadMem(DWORD A)
146-{
147- return Page[(A >> 16) & 0xF][A & 0xFFFF];
148-}
149-
150-void WriteMem(DWORD A, BYTE V)
151-{
152- (*WriteMemFnTable[(A >> 16) & 0x0F])(A, V);
153-}
154-
155-typedef void (*WriteMemFn)(DWORD A, BYTE V);
156-
157-static void WriteRom(DWORD A, BYTE V)
158-{
159- //ErrorMsg(ERR_WRITE_ROM);
160-}
161-
162-static void WriteIRam(DWORD A, BYTE V)
163-{
164- IRAM[A & 0xFFFF] = V;
165- if((A & 0xFE00) == 0xFE00)
166- {
167- SetPalette(A);
168- }
169- if(!((A - WaveMap) & 0xFFC0))
170- {
171- apuSetPData(A & 0x003F, V);
172- }
173-}
174-
175-#define FLASH_CMD_ADDR1 0x0AAA
176-#define FLASH_CMD_ADDR2 0x0555
177-#define FLASH_CMD_DATA1 0xAA
178-#define FLASH_CMD_DATA2 0x55
179-#define FLASH_CMD_RESET 0xF0
180-#define FLASH_CMD_ERASE 0x80
181-#define FLASH_CMD_ERASE_CHIP 0x10
182-#define FLASH_CMD_ERASE_SECT 0x30
183-#define FLASH_CMD_CONTINUE_SET 0x20
184-#define FLASH_CMD_CONTINUE_RES1 0x90
185-#define FLASH_CMD_CONTINUE_RES2 0xF0
186-#define FLASH_CMD_CONTINUE_RES3 0x00
187-#define FLASH_CMD_WRITE 0xA0
188-static void WriteCRam(DWORD A, BYTE V)
189-{
190- static int flashCommand1 = 0;
191- static int flashCommand2 = 0;
192- static int flashWriteSet = 0;
193- static int flashWriteOne = 0;
194- static int flashWriteReset = 0;
195- static int flashWriteEnable = 0;
196- int offset = A & 0xFFFF;
197-
198- if (offset >= RAMSize)
199- {
200- ErrorMsg(ERR_OVER_RAMSIZE);
201- }
202- // WonderWitch
203- // FLASH ROM command sequence
204- if (flashCommand2)
205- {
206- if (offset == FLASH_CMD_ADDR1)
207- {
208- switch (V) {
209- case FLASH_CMD_CONTINUE_SET:
210- flashWriteSet = 1;
211- flashWriteReset = 0;
212- break;
213- case FLASH_CMD_WRITE:
214- flashWriteOne = 1;
215- break;
216- case FLASH_CMD_RESET:
217- break;
218- case FLASH_CMD_ERASE:
219- break;
220- case FLASH_CMD_ERASE_CHIP:
221- break;
222- case FLASH_CMD_ERASE_SECT:
223- break;
224- }
225- }
226- flashCommand2 = 0;
227- }
228- else if (flashCommand1)
229- {
230- if (offset == FLASH_CMD_ADDR2 && V == FLASH_CMD_DATA2)
231- {
232- flashCommand2 = 1;
233- }
234- flashCommand1 = 0;
235- }
236- else if (offset == FLASH_CMD_ADDR1 && V == FLASH_CMD_DATA1)
237- {
238- flashCommand1 = 1;
239- }
240- if (RAMSize != 0x40000 || IO[BNK1SLCT] < 8)
241- {
242- // normal sram
243- Page[1][offset] = V;
244- }
245- else if (IO[BNK1SLCT] >= 8 && IO[BNK1SLCT] < 15)
246- {
247- // FLASH ROM use SRAM bank(port 0xC1:8-14)(0xC1:15 0xF0000-0xFFFFF are write protected)
248- if (flashWriteEnable || flashWriteOne)
249- {
250- Page[IO[BNK1SLCT]][offset] = V;
251- flashWriteEnable = 0;
252- flashWriteOne = 0;
253- }
254- else if (flashWriteSet)
255- {
256- switch (V)
257- {
258- case FLASH_CMD_WRITE:
259- flashWriteEnable = 1;
260- flashWriteReset = 0;
261- break;
262- case FLASH_CMD_CONTINUE_RES1:
263- flashWriteReset = 1;
264- break;
265- case FLASH_CMD_CONTINUE_RES2:
266- case FLASH_CMD_CONTINUE_RES3:
267- if (flashWriteReset)
268- {
269- flashWriteSet = 0;
270- flashWriteReset = 0;
271- }
272- break;
273- default:
274- flashWriteReset = 0;
275- }
276- }
277- }
278-}
279-
280-void WriteIO(DWORD A, BYTE V)
281-{
282- int i, j, k;
283-
284- if(A >= 0x100)
285- {
286- return;
287- }
288- switch(A)
289- {
290- case 0x07:
291- Scr1TMap = IRAM + ((V & 0x0F) << 11);
292- Scr2TMap = IRAM + ((V & 0xF0) << 7);
293- break;
294- case 0x15:
295- if (V & 0x01)
296- {
297- Segment[8] = 1;
298- RenderSleep();
299- }
300- else
301- {
302- Segment[8] = 0;
303- }
304- if (V & 0x02)
305- {
306- SetDrawMode(1);
307- Segment[4] = 1;
308- }
309- else
310- {
311- Segment[4] = 0;
312- }
313- if (V & 0x04)
314- {
315- SetDrawMode(0);
316- Segment[3] = 1;
317- }
318- else
319- {
320- Segment[3] = 0;
321- }
322- if (V & 0x08)
323- {
324- Segment[2] = 1;
325- }
326- else
327- {
328- Segment[2] = 0;
329- }
330- if (V & 0x10)
331- {
332- Segment[1] = 1;
333- }
334- else
335- {
336- Segment[1] = 0;
337- }
338- if (V & 0x20)
339- {
340- Segment[0] = 1;
341- }
342- else
343- {
344- Segment[0] = 0;
345- }
346- break;
347- case 0x1C:
348- case 0x1D:
349- case 0x1E:
350- case 0x1F:
351- if(IO[COLCTL] & 0x80) break;
352- i = (A - 0x1C) << 1;
353- MonoColor[i] = DefColor[V & 0x0F];
354- MonoColor[i + 1] = DefColor[(V & 0xF0) >> 4];
355- for(k = 0x20; k < 0x40; k++)
356- {
357- i = (k & 0x1E) >> 1;
358- j = 0;
359- if(k & 0x01) j = 2;
360- Palette[i][j] = MonoColor[IO[k] & 0x07];
361- Palette[i][j + 1] = MonoColor[(IO[k] >> 4) & 0x07];
362- }
363- break;
364- case 0x20:
365- case 0x21:
366- case 0x22:
367- case 0x23:
368- case 0x24:
369- case 0x25:
370- case 0x26:
371- case 0x27:
372- case 0x28:
373- case 0x29:
374- case 0x2A:
375- case 0x2B:
376- case 0x2C:
377- case 0x2D:
378- case 0x2E:
379- case 0x2F:
380- case 0x30:
381- case 0x31:
382- case 0x32:
383- case 0x33:
384- case 0x34:
385- case 0x35:
386- case 0x36:
387- case 0x37:
388- case 0x38:
389- case 0x39:
390- case 0x3A:
391- case 0x3B:
392- case 0x3C:
393- case 0x3D:
394- case 0x3E:
395- case 0x3F:
396- if (IO[COLCTL] & 0x80) break;
397- i = (A & 0x1E) >> 1;
398- j = 0;
399- if (A & 0x01) j = 2;
400- Palette[i][j] = MonoColor[V & 0x07];
401- Palette[i][j + 1] = MonoColor[(V >> 4) & 0x07];
402- break;
403- case 0x48:
404- if(V & 0x80)
405- {
406- i = *(DWORD*)(IO + DMASRC); // IO[]が4バイト境界にあることが必要
407- j = *(WORD*)(IO + DMADST);
408- k = *(WORD*)(IO + DMACNT);
409- while(k--)
410- {
411- WriteMem(j++, ReadMem(i++));
412- }
413- *(WORD*)(IO + DMACNT) = 0;
414- *(DWORD*)(IO + DMASRC) = i; // IO[]が4バイト境界にあることが必要
415- *(WORD*)(IO + DMADST) = j;
416- V &= 0x7F;
417- }
418- break;
419- case 0x80:
420- case 0x81:
421- IO[A] = V;
422- Ch[0].freq = *(WORD*)(IO + SND1FRQ);
423- return;
424- case 0x82:
425- case 0x83:
426- IO[A] = V;
427- Ch[1].freq = *(WORD*)(IO + SND2FRQ);
428- return;
429- case 0x84:
430- case 0x85:
431- IO[A] = V;
432- Ch[2].freq = *(WORD*)(IO + SND3FRQ);
433- return;
434- case 0x86:
435- case 0x87:
436- IO[A] = V;
437- Ch[3].freq = *(WORD*)(IO + SND4FRQ);
438- return;
439- case 0x88:
440- Ch[0].volL = (V >> 4) & 0x0F;
441- Ch[0].volR = V & 0x0F;
442- break;
443- case 0x89:
444- Ch[1].volL = (V >> 4) & 0x0F;
445- Ch[1].volR = V & 0x0F;
446- break;
447- case 0x8A:
448- Ch[2].volL = (V >> 4) & 0x0F;
449- Ch[2].volR = V & 0x0F;
450- break;
451- case 0x8B:
452- Ch[3].volL = (V >> 4) & 0x0F;
453- Ch[3].volR = V & 0x0F;
454- break;
455- case 0x8C:
456- Swp.step = (signed char)V;
457- break;
458- case 0x8D:
459- Swp.time = (V + 1) << 5;
460- break;
461- case 0x8E:
462- Noise.pattern = V & 0x07;
463- break;
464- case 0x8F:
465- WaveMap = V << 6;
466- for (i = 0; i < 64; i++) {
467- apuSetPData(WaveMap + i, IRAM[WaveMap + i]);
468- }
469- break;
470- case 0x90:
471- Ch[0].on = V & 0x01;
472- Ch[1].on = V & 0x02;
473- Ch[2].on = V & 0x04;
474- Ch[3].on = V & 0x08;
475- VoiceOn = V & 0x20;
476- Swp.on = V & 0x40;
477- Noise.on = V & 0x80;
478- break;
479- case 0x91:
480- V |= 0x80; // ヘッドホンは常にオン
481- break;
482- case 0xA0:
483- V=0x02;
484- break;
485- case 0xA2:
486- if(V & 0x01)
487- {
488- HTimer = *(WORD*)(IO + HPRE);
489- }
490- else
491- {
492- HTimer = 0;
493- }
494- if(V & 0x04)
495- {
496- VTimer = *(WORD*)(IO + VPRE);
497- }
498- else
499- {
500- VTimer = 0;
501- }
502- break;
503- case 0xA4:
504- case 0xA5:
505- IO[A] = V;
506- HTimer = *(WORD*)(IO + HPRE); // FF
507- return;
508- case 0xA6:
509- case 0xA7:
510- IO[A] = V;
511- IO[A + 4] = V; // Dark eyes
512- if(IO[TIMCTL] & 0x04)
513- {
514- VTimer = *(WORD*)(IO + VPRE);
515- }
516- return;
517- case 0xB3:
518- if(V & 0x20)
519- {
520- V &= 0xDF;
521- }
522- V |= 0x04;
523- break;
524- case 0xB5:
525- IO[KEYCTL] = (BYTE)(V & 0xF0);
526- if(IO[KEYCTL] & 0x40) IO[KEYCTL] |= (BYTE)((ButtonState >> 8) & 0x0F);
527- if(IO[KEYCTL] & 0x20) IO[KEYCTL] |= (BYTE)((ButtonState >> 4) & 0x0F);
528- if(IO[KEYCTL] & 0x10) IO[KEYCTL] |= (BYTE)(ButtonState & 0x0F);
529- return;
530- case 0xB6:
531- IO[IRQACK] &= (BYTE)~V;
532- return;
533- case 0xBE:
534- ComEeprom(&sIEep, (WORD*)(IO + EEPCMD), (WORD*)(IO + EEPDATA));
535- V >>= 4;
536- break;
537- case 0xC0:
538- if(nec_get_reg(NEC_CS) >= 0x4000)
539- {
540- nec_execute(1);
541- }
542- j = (V << 4) & 0xF0;
543- Page[0x4] = ROMMap[0x4 | j];
544- Page[0x5] = ROMMap[0x5 | j];
545- Page[0x6] = ROMMap[0x6 | j];
546- Page[0x7] = ROMMap[0x7 | j];
547- Page[0x8] = ROMMap[0x8 | j];
548- Page[0x9] = ROMMap[0x9 | j];
549- Page[0xA] = ROMMap[0xA | j];
550- Page[0xB] = ROMMap[0xB | j];
551- Page[0xC] = ROMMap[0xC | j];
552- Page[0xD] = ROMMap[0xD | j];
553- Page[0xE] = ROMMap[0xE | j];
554- Page[0xF] = ROMMap[0xF | j];
555- break;
556- case 0xC1:
557- if (V >= 8) // WonderWitch
558- {
559- Page[1] = MemDummy;
560- }
561- else if (V >= RAMBanks)
562- {
563- RAMEnable = 0;
564- }
565- else
566- {
567- Page[1] = RAMMap[V];
568- }
569- break;
570- case 0xC2:
571- Page[2] = ROMMap[V];
572- break;
573- case 0xC3:
574- Page[3] = ROMMap[V];
575- break;
576- case 0xC8:
577- ComEeprom(&sCEep, (WORD*)(IO + CEEPCMD), (WORD*)(IO + CEEPDATA));
578- if(V & 0x10)
579- {
580- V >>= 4;
581- }
582- if(V & 0x20)
583- {
584- V >>= 4;
585- }
586- if(V & 0x40)
587- {
588- V >>= 5;
589- }
590- break;
591- case 0xCA: // RTC Command
592- if (V == 0x15)
593- {
594- RtcCount = 0;
595- }
596- break;
597- case 0xCB: //RTC DATA
598- break;
599- default:
600- break;
601- }
602- IO[A] = V;
603-}
604-
605-#define BCD(value) ((value / 10) << 4) | (value % 10)
606-BYTE ReadIO(DWORD A)
607-{
608- switch(A)
609- {
610- case 0xCA:
611- return IO[RTCCMD] | 0x80;
612- case 0xCB:
613- if (IO[RTCCMD] == 0x15) // get time command
614- {
615- BYTE year, mon, mday, wday, hour, min, sec, j;
616- struct tm *newtime;
617- time_t long_time;
618-
619- time(&long_time);
620- newtime = localtime(&long_time);
621- switch(RtcCount)
622- {
623- case 0:
624- RtcCount++;
625- year = newtime->tm_year;
626- year %= 100;
627- return BCD(year);
628- case 1:
629- RtcCount++;
630- mon = newtime->tm_mon;
631- mon++;
632- return BCD(mon);
633- case 2:
634- RtcCount++;
635- mday = newtime->tm_mday;
636- return BCD(mday);
637- case 3:
638- RtcCount++;
639- wday = newtime->tm_wday;
640- return BCD(wday);
641- case 4:
642- RtcCount++;
643- hour = newtime->tm_hour;
644- j = BCD(hour);
645- if (hour > 11)
646- j |= 0x80;
647- return j;
648- case 5:
649- RtcCount++;
650- min = newtime->tm_min;
651- return BCD(min);
652- case 6:
653- RtcCount = 0;
654- sec = newtime->tm_sec;
655- return BCD(sec);
656- }
657- return 0;
658- }
659- else {
660- // set ack
661- return (IO[RTCDATA] | 0x80);
662- }
663- }
664- return IO[A];
665-}
666-
667-WriteMemFn WriteMemFnTable[16]= {
668- WriteIRam,
669- WriteCRam,
670- WriteRom,
671- WriteRom,
672- WriteRom,
673- WriteRom,
674- WriteRom,
675- WriteRom,
676- WriteRom,
677- WriteRom,
678- WriteRom,
679- WriteRom,
680- WriteRom,
681- WriteRom,
682- WriteRom,
683- WriteRom,
684-};
685-
686-void WsReset (void)
687-{
688- int i, j;
689-
690- Page[0x0] = IRAM;
691- sIEep.data = IEep;
692- sIEep.we = 0;
693- if(CartKind & CK_EEP)
694- {
695- Page[0x1] = MemDummy;
696- sCEep.data = (WORD*)(RAMMap[0x00]);
697- sCEep.we = 0;
698- }
699- else
700- {
701- Page[0x1] = RAMMap[0x00];
702- sCEep.data = NULL;
703- sCEep.we = 0;
704- }
705- Page[0xF] = ROMMap[0xFF];
706- i = (IO[SPRTAB] & 0x1F) << 9;
707- i += IO[SPRBGN] << 2;
708- j = IO[SPRCNT] << 2;
709- memcpy(SprTMap, IRAM + i, j);
710- SprTTMap = SprTMap;
711- SprETMap = SprTMap + j - 4;
712- WriteIO(0x07, 0x00);
713- WriteIO(0x14, 0x01);
714- WriteIO(0x1C, 0x99);
715- WriteIO(0x1D, 0xFD);
716- WriteIO(0x1E, 0xB7);
717- WriteIO(0x1F, 0xDF);
718- WriteIO(0x20, 0x30);
719- WriteIO(0x21, 0x57);
720- WriteIO(0x22, 0x75);
721- WriteIO(0x23, 0x76);
722- WriteIO(0x24, 0x15);
723- WriteIO(0x25, 0x73);
724- WriteIO(0x26, 0x77);
725- WriteIO(0x27, 0x77);
726- WriteIO(0x28, 0x20);
727- WriteIO(0x29, 0x75);
728- WriteIO(0x2A, 0x50);
729- WriteIO(0x2B, 0x36);
730- WriteIO(0x2C, 0x70);
731- WriteIO(0x2D, 0x67);
732- WriteIO(0x2E, 0x50);
733- WriteIO(0x2F, 0x77);
734- WriteIO(0x30, 0x57);
735- WriteIO(0x31, 0x54);
736- WriteIO(0x32, 0x75);
737- WriteIO(0x33, 0x77);
738- WriteIO(0x34, 0x75);
739- WriteIO(0x35, 0x17);
740- WriteIO(0x36, 0x37);
741- WriteIO(0x37, 0x73);
742- WriteIO(0x38, 0x50);
743- WriteIO(0x39, 0x57);
744- WriteIO(0x3A, 0x60);
745- WriteIO(0x3B, 0x77);
746- WriteIO(0x3C, 0x70);
747- WriteIO(0x3D, 0x77);
748- WriteIO(0x3E, 0x10);
749- WriteIO(0x3F, 0x73);
750- WriteIO(0x01, 0x00);
751- WriteIO(0x8F, 0x03);
752- WriteIO(0x91, 0x80);
753- WriteIO(0xA0, 0x02);
754- WriteIO(0xB3, 0x04);
755- WriteIO(0xBA, 0x01);
756- WriteIO(0xBB, 0x00);
757- WriteIO(0xBC, 0x30); // 内蔵EEPROM
758- WriteIO(0xBD, 0x01); // 書き込み可能
759- WriteIO(0xBE, 0x83);
760- IO[BNKSLCT] = 0x0F;
761- j = 0xF0;
762- Page[0x4] = ROMMap[0x4 | j];
763- Page[0x5] = ROMMap[0x5 | j];
764- Page[0x6] = ROMMap[0x6 | j];
765- Page[0x7] = ROMMap[0x7 | j];
766- Page[0x8] = ROMMap[0x8 | j];
767- Page[0x9] = ROMMap[0x9 | j];
768- Page[0xA] = ROMMap[0xA | j];
769- Page[0xB] = ROMMap[0xB | j];
770- Page[0xC] = ROMMap[0xC | j];
771- Page[0xD] = ROMMap[0xD | j];
772- Page[0xE] = ROMMap[0xE | j];
773- Page[0xF] = ROMMap[0xF | j];
774- WriteIO(0xC2, 0xFF);
775- WriteIO(0xC3, 0xFF);
776- IRAM[0x75AC]=0x41;
777- IRAM[0x75AD]=0x5F;
778- IRAM[0x75AE]=0x43;
779- IRAM[0x75AF]=0x31;
780- IRAM[0x75B0]=0x6E;
781- IRAM[0x75B1]=0x5F;
782- IRAM[0x75B2]=0x63;
783- IRAM[0x75B3]=0x31;
784- apuWaveClear();
785- ButtonState = 0x0000;
786- for (i = 0; i < 11; i++)
787- {
788- Segment[i] = 0;
789- }
790- nec_reset(NULL);
791- nec_set_reg(NEC_SP, 0x2000);
792-}
793-
794-void WsRomPatch(BYTE *buf)
795-{
796- if((buf[0] == 0x01) && (buf[1] == 0x01) && (buf[2] == 0x16)) // SWJ-BANC16 STAR HEARTS
797- {
798- RAMBanks = 1;
799- RAMSize = 0x8000;
800- CartKind = 0;
801- }
802- if((buf[0] == 0x01) && (buf[1] == 0x00) && (buf[2] == 0x2C || buf[2] == 0x2F)) // SWJ-BAN02C,02F デジタルパートナー
803- {
804- RAMBanks = 1;
805- RAMSize = 0x8000;
806- CartKind = 0;
807- }
808- if((buf[0] == 0x01) && (buf[1] == 0x01) && (buf[2] == 0x38)) // SWJ-BANC38 NARUTO 木ノ葉忍法帖
809- {
810- RAMBanks = 1;
811- RAMSize = 0x10000;
812- CartKind = 0;
813- }
814-}
815-
816-int Interrupt(void)
817-{
818- static int LCount=0, Joyz=0x0000;
819- int i, j;
820-
821- if(++LCount>=8) // 8回で1Hblank期間
822- {
823- LCount=0;
824- }
825- switch(LCount)
826- {
827- case 0:
828- if (IO[RSTRL] == 144)
829- {
830- DWORD VCounter;
831-
832- ButtonState = WsInputGetState();
833- if((ButtonState ^ Joyz) & Joyz)
834- {
835- if(IO[IRQENA] & KEY_IFLAG)
836- {
837- IO[IRQACK] |= KEY_IFLAG;
838- }
839- }
840- Joyz = ButtonState;
841- // Vblankカウントアップ
842- VCounter = *(WORD*)(IO + VCNTH) << 16 | *(WORD*)(IO + VCNTL);
843- VCounter++;
844- *(WORD*)(IO + VCNTL) = (WORD)VCounter;
845- *(WORD*)(IO + VCNTH) = (WORD)(VCounter >> 16);
846- }
847- break;
848- case 2:
849- // Hblank毎に1サンプルセットすることで12KHzのwaveデータが出来る
850- apuWaveSet();
851- *(WORD*)(IO + NCSR) = apuShiftReg();
852- break;
853- case 4:
854- if(IO[RSTRL] == 140)
855- {
856- i = (IO[SPRTAB] & 0x1F) << 9;
857- i += IO[SPRBGN] << 2;
858- j = IO[SPRCNT] << 2;
859- memcpy(SprTMap, IRAM + i, j);
860- SprTTMap = SprTMap;
861- SprETMap= SprTMap + j - 4;
862- }
863-
864- if(IO[LCDSLP] & 0x01)
865- {
866- if(IO[RSTRL] == 0)
867- {
868- SkipCnt--;
869- if(SkipCnt < 0)
870- {
871- SkipCnt = 4;
872- }
873- }
874- if(TblSkip[FrameSkip][SkipCnt])
875- {
876- if(IO[RSTRL] < 144)
877- {
878- RefreshLine(IO[RSTRL]);
879- }
880- if(IO[RSTRL] == 144)
881- {
882- drawDraw();
883- }
884- }
885- }
886- break;
887- case 6:
888- if((IO[TIMCTL] & 0x01) && HTimer)
889- {
890- HTimer--;
891- if(!HTimer)
892- {
893- if(IO[TIMCTL] & 0x02)
894- {
895- HTimer = *(WORD*)(IO + HPRE);
896- }
897- if(IO[IRQENA] & HTM_IFLAG)
898- {
899- IO[IRQACK] |= HTM_IFLAG;
900- }
901- }
902- }
903- else if(*(WORD*)(IO + HPRE) == 1)
904- {
905- if(IO[IRQENA] & HTM_IFLAG)
906- {
907- IO[IRQACK] |= HTM_IFLAG;
908- }
909- }
910- if((IO[IRQENA] & VBB_IFLAG) && (IO[RSTRL] == 144))
911- {
912- IO[IRQACK] |= VBB_IFLAG;
913- }
914- if((IO[TIMCTL] & 0x04) && (IO[RSTRL] == 144) && VTimer)
915- {
916- VTimer--;
917- if(!VTimer)
918- {
919- if(IO[TIMCTL] & 0x08)
920- {
921- VTimer = *(WORD*)(IO + VPRE);
922- }
923- if(IO[IRQENA] & VTM_IFLAG)
924- {
925- IO[IRQACK] |= VTM_IFLAG;
926- }
927- }
928- }
929- if((IO[IRQENA] & RST_IFLAG) && (IO[RSTRL] == IO[RSTRLC]))
930- {
931- IO[IRQACK] |= RST_IFLAG;
932- }
933- break;
934- case 7:
935- IO[RSTRL]++;
936- if(IO[RSTRL] >= 159)
937- {
938- IO[RSTRL] = 0;
939- }
940- // Hblankカウントアップ
941- (*(WORD*)(IO + HCNT))++;
942- break;
943- default:
944- break;
945- }
946- return IO[IRQACK];
947-}
948-
949-int WsRun(void)
950-{
951- static int period = IPeriod;
952- int i, cycle, iack, inum;
953-// for(i = 0; i < 480; i++) //5ms
954- for(i = 0; i < 159*8; i++) // 1/75s
955- {
956- cycle = nec_execute(period);
957- period += IPeriod - cycle;
958- if(Interrupt())
959- {
960- iack = IO[IRQACK];
961- for(inum = 7; inum >= 0; inum--)
962- {
963- if(iack & 0x80)
964- {
965- break;
966- }
967- iack <<= 1;
968- }
969- nec_int((inum + IO[IRQBSE]) << 2);
970- }
971- }
972- return 0;
973-}
974-
975-#define POS_X (88)
976-#define POS_Y (32)
977-#define NAME_Y (96)
978-void WsSplash(void)
979-{
980- int x, y, i, len, pos, n;
981- WORD* p;
982- char* name = (char*)(IEep + 0x30);
983-
984- // 背景を黒でクリア
985- p = FrameBuffer[0] + 8;
986- for (y = 0; y < 144; y++)
987- {
988- for (x = 0; x < 224; x++)
989- {
990- *p++ = 0xF000;
991- }
992- p += 32;
993- }
994- drawDraw();
995- Sleep(300);
996- apuStartupSound();
997- Sleep(150);
998- Segment[3] = 1;
999- Segment[5] = 1;
1000- Segment[9] = 1;
1001- Segment[10] = 1;
1002- for (i = 0; i < 6; i++)
1003- {
1004- WORD color[6] = {0xFF00, 0xFF80, 0xFFF0, 0xF0F0, 0xF0FF, 0xF00F};
1005- // B,A,N,D,A,I,を1文字表示
1006- for (y = bandaiRect[i].top; y <= bandaiRect[i].bottom; y++)
1007- {
1008- p = FrameBuffer[POS_Y + y] + 8 + POS_X;
1009- for (x = bandaiRect[i].left; x <= bandaiRect[i].right; x++)
1010- {
1011- if (bandai[y][x] == 0xFFFF)
1012- {
1013- p[x] = color[i];
1014- }
1015- }
1016- }
1017- drawDraw();
1018- Sleep(70);
1019- // 文字消去
1020- p = FrameBuffer[0] + 8;
1021- for (y = 0; y < 144; y++)
1022- {
1023- for (x = 0; x < 224; x++)
1024- {
1025- *p++ = 0xF000;
1026- }
1027- p += 32;
1028- }
1029- }
1030- drawDraw();
1031- Sleep(200);
1032- // 背景を白でクリア
1033- p = FrameBuffer[0] + 8;
1034- for (y = 0; y < 144; y++)
1035- {
1036- for (x = 0; x < 224; x++)
1037- {
1038- *p++ = 0xFFFF;
1039- }
1040- p += 32;
1041- }
1042- // BANDAIロゴ表示
1043- p = FrameBuffer[POS_Y] + 8 + POS_X;
1044- for (y = 0; y < BANDAI_Y; y++)
1045- {
1046- for (x = 0; x < BANDAI_X; x++)
1047- {
1048- *p++ = bandai[y][x];
1049- }
1050- p += (256-BANDAI_X);
1051- }
1052- drawDraw();
1053- // 所有者の名前表示
1054- for (len = 15; name[len] == 0 && len > 0; len--);
1055- pos = 108 - len * 4;
1056- for (n = 0; n <= len; n++)
1057- {
1058- for (i = 0; i <= len; i++)
1059- {
1060- BYTE ar = pdataFontArray[name[i]];
1061- BYTE* ch = pdataFont + ar * 8;
1062- for (y = 0; y < 8; y++)
1063- {
1064- BYTE font = *ch++;
1065- p = FrameBuffer[NAME_Y + y] + 8 + pos + (i * 8);
1066- for (x = 0; x < 8; x++)
1067- {
1068- if (name[i] && (font & 0x80)) // スペースフォントは■になってるのでスキップ
1069- {
1070- if (n == i)
1071- {
1072- *p = 0xFFFF;
1073- }
1074- else
1075- {
1076- *p = 0xF000;
1077- }
1078- }
1079- p++;
1080- font <<= 1;
1081- }
1082- }
1083- }
1084- drawDraw();
1085- Sleep(30);
1086- }
1087- for (i = 0; i <= len; i++)
1088- {
1089- BYTE ar = pdataFontArray[name[i]];
1090- BYTE* ch = pdataFont + ar * 8;
1091- for (y = 0; y < 8; y++)
1092- {
1093- BYTE font = *ch++;
1094- p = FrameBuffer[NAME_Y + y] + 8 + pos + (i * 8);
1095- for (x = 0; x < 8; x++)
1096- {
1097- if (name[i] && (font & 0x80))
1098- {
1099- if (n == i)
1100- {
1101- *p = 0xFFFF;
1102- }
1103- else
1104- {
1105- *p = 0xF000;
1106- }
1107- }
1108- p++;
1109- font <<= 1;
1110- }
1111- }
1112- }
1113- Segment[3] = 0;
1114- Segment[5] = 0;
1115- Segment[9] = 0;
1116- drawDraw();
1117-}
1118-
1119-
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSDraw.cpp (revision 101)
+++ oswanj/trunk/src/WSDraw.cpp (nonexistent)
@@ -1,335 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include "WSDraw.h"
7-#include "WS.h"
8-#include "WSInput.h"
9-#include "WSRender.h"
10-
11-extern HWND hWnd;
12-int Kerorikan = 0;
13-static enum DRAWSIZE DrawSize = DS_1; // 描画サイズ フルスクリーン、x1 x2 x3
14-static int DrawMode = 0; // 縦横フラグ 0:横
15-static LPDIRECT3D9 pD3D; // IDirect3D9インターフェイスへのポインタ
16-static LPDIRECT3DDEVICE9 pD3DDevice; // IDirect3DDevice9インターフェイスへのポインタ
17-static D3DPRESENT_PARAMETERS D3DPP; // デバイスのプレゼンテーションパラメータ
18-static LPDIRECT3DVERTEXBUFFER9 pMyVB; // Vertex Buffer
19-static LPDIRECT3DTEXTURE9 pTexture; // Texture
20-static LPDIRECT3DSURFACE9 pSurface; // Surface
21-static LPDIRECT3DTEXTURE9 pSegTexture;
22-static LPDIRECT3DSURFACE9 pSegSurface;
23-
24-// 頂点1つのデータ型
25-struct MY_VERTEX{
26- D3DXVECTOR3 p; // 位置
27- DWORD color; // 色
28- D3DXVECTOR2 t; // テクスチャーの画像の位置
29-};
30-// MY_VERTEXのフォーマット設定
31-#define MY_VERTEX_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)
32-#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
33-
34-//-------------------------------------------------------------
35-// レンダラーの初期化
36-// 引数
37-// isFullScreen : フルスクリーンの場合TRUE
38-// 戻り値
39-// 成功したらS_OK
40-//-------------------------------------------------------------
41-HRESULT drawInitialize(BOOL isFullScreen)
42-{
43- D3DDISPLAYMODE d3ddm;
44-
45- // Direct3D9オブジェクトの作成
46- if((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
47- {
48- return E_FAIL; // 取得失敗
49- }
50- // 現在のディスプレイモードを取得
51- if(FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
52- {
53- return E_FAIL;
54- }
55- // デバイスのプレゼンテーションパラメータを初期化
56- ZeroMemory(&D3DPP, sizeof(D3DPRESENT_PARAMETERS));
57- if(isFullScreen) { // フルスクリーンの場合
58- D3DPP.Windowed = FALSE; // フルスクリーン表示の指定
59- D3DPP.BackBufferWidth = 800; // フルスクリーン時の横幅
60- D3DPP.BackBufferHeight = 600; // フルスクリーン時の縦幅
61- }
62- else {
63- D3DPP.Windowed = TRUE; // ウインドウ内表示の指定
64- D3DPP.BackBufferWidth = 2016; // 224と144の最小公倍数
65- D3DPP.BackBufferHeight = 2016;
66- }
67- D3DPP.BackBufferCount = 1;
68- D3DPP.BackBufferFormat = d3ddm.Format; // カラーモードの指定
69- D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; //
70- D3DPP.EnableAutoDepthStencil = TRUE; // エラー対策
71- D3DPP.AutoDepthStencilFormat = D3DFMT_D16; // エラー対策
72- D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // 垂直同期しない
73- // ディスプレイアダプタを表すためのデバイスを作成
74- // 描画と頂点処理をハードウェアで行なう
75- if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &D3DPP, &pD3DDevice)))
76- {
77- // 上記の設定が失敗したら
78- // 描画をハードウェアで行い、頂点処理はCPUで行なう
79- if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DPP, &pD3DDevice)))
80- {
81- // 初期化失敗
82- MessageBox(hWnd, TEXT(" グラフィックチップが未対応です "), TEXT("Direct3D Error"), MB_OK);
83- return E_FAIL;
84- }
85- }
86- return S_OK;
87-}
88-
89-//-------------------------------------------------------------
90-// 終了処理
91-//-------------------------------------------------------------
92-void drawFinalize(void)
93-{
94- // デバイスオブジェクトの解放
95- SAFE_RELEASE(pD3DDevice);
96- // DirectXGraphicsの解放
97- SAFE_RELEASE(pD3D);
98-}
99-
100-//-------------------------------------------------------------
101-// シーンを生成
102-// 戻り値
103-// 成功したらS_OK
104-//-------------------------------------------------------------
105-HRESULT drawCreate(void)
106-{
107- if(pD3DDevice == 0)
108- {
109- return E_FAIL;
110- }
111- drawDestroy();
112- //--------------------------------------
113- // オブジェクトの頂点バッファを生成
114- //--------------------------------------
115- // 8つの頂点からなる頂点バッファを作る(メイン4個 セグメント4個)
116- if(FAILED( pD3DDevice->CreateVertexBuffer(8 * sizeof(MY_VERTEX), D3DUSAGE_WRITEONLY, MY_VERTEX_FVF, D3DPOOL_MANAGED, &pMyVB, NULL)))
117- {
118- return E_FAIL;
119- }
120- pD3DDevice->CreateTexture(256, 256, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &pTexture, NULL);
121- pTexture->GetSurfaceLevel(0, &pSurface);
122- pD3DDevice->CreateTexture(32, 1024, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &pSegTexture, NULL);
123- pSegTexture->GetSurfaceLevel(0, &pSegSurface);
124- //--------------------------------------
125- // テクスチャステージの設定
126- //--------------------------------------
127- pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
128- pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
129- //--------------------------------------
130- // レンダリングステートパラメータの設定
131- //--------------------------------------
132- // 両面描画モードの指定
133- pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
134- // ディザリングを行なう(高品質描画)
135- pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);
136- // ノーライティングモード
137- pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
138- return S_OK;
139-}
140-
141-//-------------------------------------------------------------
142-// シーンの破棄
143-//-------------------------------------------------------------
144-void drawDestroy(void)
145-{
146- SAFE_RELEASE(pSurface);
147- SAFE_RELEASE(pTexture);
148- SAFE_RELEASE(pSegSurface);
149- SAFE_RELEASE(pSegTexture);
150- SAFE_RELEASE(pMyVB);
151-}
152-
153-//-------------------------------------------------------------
154-// 描画処理
155-//-------------------------------------------------------------
156-#define MAIN_X (224.0f/256.0f)
157-#define MAIN_Y (144.0f/256.0f)
158-#define MAIN_W (2 * 224.0f/234.0f - 1.0f)
159-#define SEG_X (4 * 8.0f/32.0f)
160-#define SEG_Y (4 * 144.0f/1024.0f)
161-#define SEG_W (1.0f - 2 * 8.0f/234.0f)
162-#define KERO 0.0075f
163-void drawDraw()
164-{
165- if(pD3DDevice == 0)
166- {
167- return;
168- }
169- if(pMyVB == 0)
170- {
171- return;
172- }
173- // 画像データをテクスチャに転送
174- D3DLOCKED_RECT lockRect;
175- int x, y, pitch;
176- WORD *p;
177- pSurface->LockRect(&lockRect, NULL, D3DLOCK_DISCARD);
178- p = FrameBuffer[0] + 8;
179- pitch = lockRect.Pitch / 2;
180- for (y = 0; y < 144; y++)
181- {
182- for (x = 0; x < 224; x++)
183- {
184- *((WORD*)lockRect.pBits + pitch * y + x) = *p++;
185- }
186- p += 32;
187- }
188- pSurface->UnlockRect();
189- // 液晶セグメントデータをテクスチャに転送
190- RenderSegment();
191- pSegSurface->LockRect(&lockRect, NULL, D3DLOCK_DISCARD);
192- p = SegmentBuffer;
193- pitch = lockRect.Pitch / 2;
194- for (y = 0; y < 144 * 4; y++)
195- {
196- for (x = 0; x < 32; x++)
197- {
198- *((WORD*)lockRect.pBits + pitch * y + x) = *p++;
199- }
200- }
201- pSegSurface->UnlockRect();
202- //頂点バッファの中身を埋める
203- MY_VERTEX* v;
204- pMyVB->Lock( 0, 0, (void**)&v, 0 );
205- if (Kerorikan)
206- {
207- // 頂点座標の設定
208- v[0].p = D3DXVECTOR3(-112*KERO, 72*KERO, 0.0f);
209- v[1].p = D3DXVECTOR3( 112*KERO, 72*KERO, 0.0f);
210- v[2].p = D3DXVECTOR3(-112*KERO, -72*KERO, 0.0f);
211- v[3].p = D3DXVECTOR3( 112*KERO, -72*KERO, 0.0f);
212- v[4].p = D3DXVECTOR3( 114*KERO, 72*KERO, 0.0f);
213- v[5].p = D3DXVECTOR3( 122*KERO, 72*KERO, 0.0f);
214- v[6].p = D3DXVECTOR3( 114*KERO, -72*KERO, 0.0f);
215- v[7].p = D3DXVECTOR3( 122*KERO, -72*KERO, 0.0f);
216- }
217- else
218- {
219- // 頂点座標の設定
220- v[0].p = D3DXVECTOR3(-1.0f, 1.0f, 0.0f);
221- v[1].p = D3DXVECTOR3(MAIN_W, 1.0f, 0.0f);
222- v[2].p = D3DXVECTOR3(-1.0f, -1.0f, 0.0f);
223- v[3].p = D3DXVECTOR3(MAIN_W,-1.0f, 0.0f);
224- v[4].p = D3DXVECTOR3(SEG_W, 1.0f, 0.0f);
225- v[5].p = D3DXVECTOR3( 1.0f, 1.0f, 0.0f);
226- v[6].p = D3DXVECTOR3(SEG_W, -1.0f, 0.0f);
227- v[7].p = D3DXVECTOR3( 1.0f, -1.0f, 0.0f);
228- }
229- // テクスチャ座標の設定
230- v[0].t = D3DXVECTOR2(0.0f, 0.0f);
231- v[1].t = D3DXVECTOR2(MAIN_X, 0.0f);
232- v[2].t = D3DXVECTOR2(0.0f, MAIN_Y);
233- v[3].t = D3DXVECTOR2(MAIN_X, MAIN_Y);
234- v[4].t = D3DXVECTOR2(0.0f, 0.0f);
235- v[5].t = D3DXVECTOR2(SEG_X, 0.0f);
236- v[6].t = D3DXVECTOR2(0.0f, SEG_Y);
237- v[7].t = D3DXVECTOR2(SEG_X, SEG_Y);
238- // 頂点カラーの設定
239- v[0].color = v[1].color = v[2].color = v[3].color = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);
240- v[4].color = v[5].color = v[6].color = v[7].color = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);
241- pMyVB->Unlock();
242- // 回転処理
243- D3DXMATRIX mat;
244- D3DXMatrixIdentity(&mat);
245- // 斜め(左atan(0.5)回転)
246- if (Kerorikan)
247- {
248- D3DXMatrixRotationZ(&mat, 0.4636476f); // atanf(0.5f)だと最適化されないかもしれないので
249- }
250- // 縦(左90度回転)
251- else if (DrawMode & 0x01)
252- {
253- D3DXMatrixRotationZ(&mat, D3DXToRadian(90));
254- }
255- // 描画開始宣言
256- if(SUCCEEDED(pD3DDevice->BeginScene()))
257- {
258- pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xFF666666, 0.0f, 0);
259- pD3DDevice->SetStreamSource(0, pMyVB, 0, sizeof(MY_VERTEX));
260- pD3DDevice->SetFVF(MY_VERTEX_FVF);
261- pD3DDevice->SetTexture( 0, pTexture);
262- pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // 0番の頂点から三角形を2個
263- pD3DDevice->SetTexture( 0, pSegTexture);
264- pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2); // 4番の頂点から三角形を2個
265- pD3DDevice->SetTransform(D3DTS_VIEW, &mat);
266- // 描画終了宣言
267- pD3DDevice->EndScene();
268- }
269- // 描画結果の転送
270- if(FAILED(pD3DDevice->Present(NULL, NULL, NULL, NULL)))
271- {
272- // デバイス消失から復帰
273- pD3DDevice->Reset(&D3DPP);
274- }
275-}
276-
277-//-------------------------------------------------------------
278-void WsResize(void)
279-{
280- RECT wind;
281- RECT wind2;
282- int lcdHeight = 144;
283- int lcdWidth = 224 + 10; // +10はセグメント分
284- int client_width;
285- int client_height;
286-
287- if (Kerorikan)
288- {
289- client_width = 256 * DrawSize;
290- client_height = 256 * DrawSize;
291- }
292- else if (DrawMode & 0x01)
293- {
294- client_width = lcdHeight * DrawSize;
295- client_height = lcdWidth * DrawSize;
296- }
297- else
298- {
299- client_width = lcdWidth * DrawSize;
300- client_height = lcdHeight * DrawSize;
301- }
302- wind.top = 0;
303- wind.left = 0;
304- wind.right = client_width;
305- wind.bottom = client_height;
306- AdjustWindowRectEx(&wind, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
307- TRUE, WS_EX_APPWINDOW | WS_EX_ACCEPTFILES);
308- wind2 = wind;
309- SendMessage(hWnd, WM_NCCALCSIZE, FALSE, (LPARAM) &wind2);
310- SetWindowPos(hWnd, NULL, 0, 0,
311- (wind.right - wind.left) + client_width - (wind2.right - wind2.left),
312- (wind.bottom - wind.top ) + client_height - (wind2.bottom - wind2.top ),
313- SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW);
314-}
315-
316-//-------------------------------------------------------------
317-int SetDrawMode(int Mode)
318-{
319- if(DrawMode != Mode)
320- {
321- DrawMode = Mode;
322- WsInputSetKeyMap(Mode);
323- WsResize();
324- }
325- return 0;
326-}
327-
328-//-------------------------------------------------------------
329-int SetDrawSize(enum DRAWSIZE Size)
330-{
331- DrawSize = Size;
332- WsResize();
333- return 0;
334-}
335-
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSDialog.cpp (revision 101)
+++ oswanj/trunk/src/WSDialog.cpp (nonexistent)
@@ -1,614 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include "../resource.h"
7-#include "WSDialog.h"
8-#include <commctrl.h>
9-#include <tchar.h>
10-#include "WSInput.h"
11-#include "keycode.h"
12-
13-static WNDPROC OrgEditProc;
14-static HWND hTabCtrl, hTab1, hTab2, hTab3, hTab4;
15-static int TmpKeyboardH[13];
16-static int TmpKeyboardV[13];
17-static int TmpJoypadH[13];
18-static int TmpJoypadV[13];
19-static int SelectedTab;
20-
21-void WsDlgConfInit(HWND hDlg)
22-{
23- HINSTANCE hInst;
24- TC_ITEM tc;
25- RECT rt;
26- LPPOINT pt = (LPPOINT)&rt;
27-
28- memcpy(TmpKeyboardH, WsKeyboardH, sizeof(int) * 13);
29- memcpy(TmpKeyboardV, WsKeyboardV, sizeof(int) * 13);
30- memcpy(TmpJoypadH, WsJoypadH, sizeof(int) * 13);
31- memcpy(TmpJoypadV, WsJoypadV, sizeof(int) * 13);
32- hInst = (HINSTANCE)GetWindowLong(hDlg, GWLP_HINSTANCE);
33- hTabCtrl = GetDlgItem(hDlg, IDC_TAB1);
34- // タブコントロールにタブシートを挿入
35- tc.mask = TCIF_TEXT;
36- tc.pszText = TEXT("キー横");
37- TabCtrl_InsertItem(hTabCtrl , 0, &tc);
38- tc.mask = TCIF_TEXT;
39- tc.pszText = TEXT("キー縦");
40- TabCtrl_InsertItem(hTabCtrl , 1, &tc);
41- tc.mask = TCIF_TEXT;
42- tc.pszText = TEXT("コントローラー横");
43- TabCtrl_InsertItem(hTabCtrl , 2, &tc);
44- tc.mask = TCIF_TEXT;
45- tc.pszText = TEXT("コントローラー縦");
46- TabCtrl_InsertItem(hTabCtrl , 3, &tc);
47- // タブに貼り付けるダイアログを生成
48- hTab1 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB1, hDlg, (DLGPROC)TabProc1);
49- hTab2 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB2, hDlg, (DLGPROC)TabProc2);
50- hTab3 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB1, hDlg, (DLGPROC)TabProc3);
51- hTab4 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB2, hDlg, (DLGPROC)TabProc4);
52- // タブコントロールのクライアント領域の座標を取得
53- GetClientRect(hTabCtrl, &rt);
54- TabCtrl_AdjustRect(hTabCtrl, FALSE, &rt);
55- // 親ウィンドウがhDlgなのでタブのマップが必要
56- MapWindowPoints(hTabCtrl, hDlg, pt, 2);
57- // タブのウィンドウの位置とサイズを変更する
58- MoveWindow(hTab1, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
59- MoveWindow(hTab2, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
60- MoveWindow(hTab3, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
61- MoveWindow(hTab4, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
62- // デフォルトでタブ1を表示
63- ShowWindow(hTab1, SW_SHOW);
64- SetFocus(GetDlgItem(hTab1, IDC_EDIT_Y1));
65- SendMessage(GetDlgItem(hTab1, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
66- lpKeyDevice->Acquire();
67-}
68-
69-LRESULT CALLBACK ConfProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
70-{
71- NMHDR *nm = (NMHDR *)lParam;
72-
73- switch (msg)
74- {
75- case WM_INITDIALOG:
76- WsInputInit(hDlg);
77- WsDlgConfInit(hDlg);
78- return TRUE;
79- case WM_NOTIFY:
80- // タブコントロールの選択されているタブが変更されたことを通知
81- switch (nm->code)
82- {
83- case TCN_SELCHANGE:
84- if (nm->hwndFrom == hTabCtrl)
85- {
86- SelectedTab = TabCtrl_GetCurSel(hTabCtrl);
87- switch (SelectedTab)
88- {
89- case 0:
90- ShowWindow(hTab1, SW_SHOW);
91- ShowWindow(hTab2, SW_HIDE);
92- ShowWindow(hTab3, SW_HIDE);
93- ShowWindow(hTab4, SW_HIDE);
94- SetFocus(GetDlgItem(hTab1, IDC_EDIT_Y1));
95- SendMessage(GetDlgItem(hTab1, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
96- lpKeyDevice->Acquire();
97- break;
98- case 1:
99- ShowWindow(hTab1, SW_HIDE);
100- ShowWindow(hTab2, SW_SHOW);
101- ShowWindow(hTab3, SW_HIDE);
102- ShowWindow(hTab4, SW_HIDE);
103- SetFocus(GetDlgItem(hTab2, IDC_EDIT_Y1));
104- SendMessage(GetDlgItem(hTab2, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
105- lpKeyDevice->Acquire();
106- break;
107- case 2:
108- ShowWindow(hTab1, SW_HIDE);
109- ShowWindow(hTab2, SW_HIDE);
110- ShowWindow(hTab3, SW_SHOW);
111- ShowWindow(hTab4, SW_HIDE);
112- SetFocus(GetDlgItem(hTab3, IDC_EDIT_Y1));
113- SendMessage(GetDlgItem(hTab3, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
114- break;
115- case 3:
116- ShowWindow(hTab1, SW_HIDE);
117- ShowWindow(hTab2, SW_HIDE);
118- ShowWindow(hTab3, SW_HIDE);
119- ShowWindow(hTab4, SW_SHOW);
120- SetFocus(GetDlgItem(hTab4, IDC_EDIT_Y1));
121- SendMessage(GetDlgItem(hTab4, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
122- break;
123- }
124- return TRUE;
125- }
126- break;
127- }
128- break;
129- case WM_COMMAND:
130- if(HIWORD(wParam) == BN_CLICKED)
131- {
132- switch (LOWORD(wParam))
133- {
134- case IDOK:
135- memcpy(WsKeyboardH, TmpKeyboardH, sizeof(int) * 13);
136- memcpy(WsKeyboardV, TmpKeyboardV, sizeof(int) * 13);
137- memcpy(WsJoypadH, TmpJoypadH, sizeof(int) * 13);
138- memcpy(WsJoypadV, TmpJoypadV, sizeof(int) * 13);
139- EndDialog(hDlg, LOWORD(wParam));
140- return TRUE;
141- case IDCANCEL:
142- EndDialog(hDlg, LOWORD(wParam));
143- return TRUE;
144- }
145- }
146- break;
147- case WM_DESTROY:
148- WsInputRelease();
149- break;
150- }
151- return FALSE;
152-}
153-
154-LRESULT CALLBACK EditProcKey(HWND hEditWnd, UINT msg, WPARAM wParam, LPARAM lParam)
155-{
156- HRESULT hRet;
157- BYTE diKeys[256];
158- int key, i;
159- HWND next;
160-
161- switch (msg)
162- {
163- case WM_GETDLGCODE:
164- return DLGC_WANTALLKEYS;
165- case WM_CHAR:
166- return 0;
167- case WM_KEYDOWN:
168- key = GetDlgCtrlID(hEditWnd) - IDC_EDIT_B;
169- wParam = 0;
170- hRet = lpKeyDevice->Acquire();
171- if (hRet == DI_OK || hRet == S_FALSE)
172- {
173- hRet = lpKeyDevice->GetDeviceState(256, diKeys);
174- if (hRet == DI_OK)
175- {
176- for (i = 0; i < 256; i++)
177- {
178- if (diKeys[i] & 0x80)
179- {
180- SetWindowText(hEditWnd, keyName[i]);
181- if (SelectedTab == 0)
182- {
183- TmpKeyboardH[key] = i;
184- }
185- else
186- {
187- TmpKeyboardV[key] = i;
188- }
189- next = GetNextDlgTabItem(GetParent(hEditWnd), hEditWnd, FALSE);
190- SetFocus(next);
191- SendMessage(next, EM_SETSEL, 0, -1);
192- return 0;
193- }
194- }
195- }
196- }
197- break;
198- }
199- return CallWindowProc(OrgEditProc, hEditWnd, msg, wParam, lParam);
200-}
201-
202-LRESULT CALLBACK EditProcJoy(HWND hEditWnd, UINT msg, WPARAM wParam, LPARAM lParam)
203-{
204- HWND next;
205-
206- switch (msg)
207- {
208- case WM_GETDLGCODE:
209- return DLGC_WANTALLKEYS;
210- case WM_CHAR:
211- return 0;
212- case WM_KEYDOWN:
213- if (wParam == VK_TAB || wParam == VK_RETURN)
214- {
215- next = GetNextDlgTabItem(GetParent(hEditWnd), hEditWnd, FALSE);
216- SetFocus(next);
217- SendMessage(next, EM_SETSEL, 0, -1);
218- }
219- return 0;
220- }
221- return CallWindowProc(OrgEditProc, hEditWnd, msg, wParam, lParam);
222-}
223-
224-LRESULT CALLBACK TabProc1(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
225-{
226- switch (msg) {
227- case WM_INITDIALOG:
228- OrgEditProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC);
229- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
230- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
231- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
232- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
233- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
234- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
235- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
236- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
237- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
238- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
239- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
240- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
241-
242- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), keyName[TmpKeyboardH[12]]);
243- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), keyName[TmpKeyboardH[11]]);
244- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), keyName[TmpKeyboardH[10]]);
245- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), keyName[TmpKeyboardH[9]]);
246- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), keyName[TmpKeyboardH[8]]);
247- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), keyName[TmpKeyboardH[7]]);
248- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), keyName[TmpKeyboardH[6]]);
249- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), keyName[TmpKeyboardH[5]]);
250- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), keyName[TmpKeyboardH[4]]);
251- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), keyName[TmpKeyboardH[2]]);
252- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), keyName[TmpKeyboardH[1]]);
253- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), keyName[TmpKeyboardH[0]]);
254- return TRUE;
255- }
256- return FALSE;
257-}
258-
259-LRESULT CALLBACK TabProc2(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
260-{
261- switch (msg) {
262- case WM_INITDIALOG:
263- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
264- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
265- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
266- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
267- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
268- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
269- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
270- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
271- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
272- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
273- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
274- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
275-
276- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), keyName[TmpKeyboardH[12]]);
277- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), keyName[TmpKeyboardV[11]]);
278- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), keyName[TmpKeyboardV[10]]);
279- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), keyName[TmpKeyboardV[9]]);
280- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), keyName[TmpKeyboardV[8]]);
281- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), keyName[TmpKeyboardV[7]]);
282- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), keyName[TmpKeyboardV[6]]);
283- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), keyName[TmpKeyboardV[5]]);
284- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), keyName[TmpKeyboardV[4]]);
285- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), keyName[TmpKeyboardV[2]]);
286- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), keyName[TmpKeyboardV[1]]);
287- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), keyName[TmpKeyboardV[0]]);
288- return TRUE;
289- }
290- return FALSE;
291-}
292-
293-LRESULT CALLBACK TabProc3(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
294-{
295- HWND hEditWnd;
296- int key, joy;
297-
298- switch (msg) {
299- case WM_INITDIALOG:
300- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
301- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
302- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
303- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
304- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
305- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
306- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
307- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
308- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
309- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
310- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
311- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
312-
313- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GetJoyName(TmpJoypadH[12]));
314- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), GetJoyName(TmpJoypadH[11]));
315- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), GetJoyName(TmpJoypadH[10]));
316- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), GetJoyName(TmpJoypadH[9]));
317- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), GetJoyName(TmpJoypadH[8]));
318- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), GetJoyName(TmpJoypadH[7]));
319- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), GetJoyName(TmpJoypadH[6]));
320- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), GetJoyName(TmpJoypadH[5]));
321- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), GetJoyName(TmpJoypadH[4]));
322- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), GetJoyName(TmpJoypadH[2]));
323- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), GetJoyName(TmpJoypadH[1]));
324- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), GetJoyName(TmpJoypadH[0]));
325-
326- SetTimer(hCtrl, 0, 30, NULL);
327- return TRUE;
328- case WM_TIMER:
329- if (SelectedTab != 2 || wParam != 0)
330- {
331- break;
332- }
333- hEditWnd = GetFocus();
334- key = GetDlgCtrlID(hEditWnd) - IDC_EDIT_B;
335- joy = GetJoyState();
336- if (joy < 0)
337- {
338- break;
339- }
340- SetWindowText(hEditWnd, GetJoyName(joy));
341- TmpJoypadH[key] = joy;
342- return TRUE;
343- }
344- return FALSE;
345-}
346-
347-LRESULT CALLBACK TabProc4(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
348-{
349- HWND hEditWnd;
350- int key, joy;
351-
352- switch (msg) {
353- case WM_INITDIALOG:
354- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
355- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
356- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
357- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
358- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
359- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
360- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
361- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
362- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
363- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
364- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
365- SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
366-
367- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GetJoyName(TmpJoypadH[12]));
368- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), GetJoyName(TmpJoypadV[11]));
369- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), GetJoyName(TmpJoypadV[10]));
370- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), GetJoyName(TmpJoypadV[9]));
371- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), GetJoyName(TmpJoypadV[8]));
372- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), GetJoyName(TmpJoypadV[7]));
373- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), GetJoyName(TmpJoypadV[6]));
374- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), GetJoyName(TmpJoypadV[5]));
375- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), GetJoyName(TmpJoypadV[4]));
376- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), GetJoyName(TmpJoypadV[2]));
377- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), GetJoyName(TmpJoypadV[1]));
378- SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), GetJoyName(TmpJoypadV[0]));
379-
380- SetTimer(hCtrl, 1, 30, NULL);
381- return TRUE;
382- case WM_TIMER:
383- if (SelectedTab != 3 || wParam != 1)
384- {
385- break;
386- }
387- hEditWnd = GetFocus();
388- key = GetDlgCtrlID(hEditWnd) - IDC_EDIT_B;
389- joy = GetJoyState();
390- if (joy < 0)
391- {
392- break;
393- }
394- SetWindowText(hEditWnd, GetJoyName(joy));
395- TmpJoypadV[key] = joy;
396- return TRUE;
397- }
398- return FALSE;
399-}
400-
401-LPCTSTR GetJoyName(int joy)
402-{
403- static LPCTSTR JoyStr[] = {
404- TEXT("POV1 UP"), TEXT("POV1 RIGHT"), TEXT("POV1 DOWN"), TEXT("POV1 LEFT"),
405- TEXT("POV2 UP"), TEXT("POV2 RIGHT"), TEXT("POV2 DOWN"), TEXT("POV2 LEFT"),
406- TEXT("POV3 UP"), TEXT("POV3 RIGHT"), TEXT("POV3 DOWN"), TEXT("POV3 LEFT"),
407- TEXT("POV4 UP"), TEXT("POV4 RIGHT"), TEXT("POV4 DOWN"), TEXT("POV4 LEFT"),
408- TEXT("Y -"), TEXT("X +"), TEXT("Y +"), TEXT("X -"), TEXT("Z +"), TEXT("Z -"),
409- TEXT("RY -"), TEXT("RX +"), TEXT("RY +"), TEXT("RX -"), TEXT("RZ +"), TEXT("RZ -"),
410- TEXT("Slider1 +"), TEXT("Slider1 -"), TEXT("Slider2 +"), TEXT("Slider2 -")
411- };
412- static const int JoyInt[] = {
413- WS_JOY_POV1_UP, WS_JOY_POV1_RIGHT, WS_JOY_POV1_DOWN, WS_JOY_POV1_LEFT,
414- WS_JOY_POV2_UP, WS_JOY_POV2_RIGHT, WS_JOY_POV2_DOWN, WS_JOY_POV2_LEFT,
415- WS_JOY_POV3_UP, WS_JOY_POV3_RIGHT, WS_JOY_POV3_DOWN, WS_JOY_POV3_LEFT,
416- WS_JOY_POV4_UP, WS_JOY_POV4_RIGHT, WS_JOY_POV4_DOWN, WS_JOY_POV4_LEFT,
417- WS_JOY_AXIS_Y_M, WS_JOY_AXIS_X_P, WS_JOY_AXIS_Y_P, WS_JOY_AXIS_X_M, WS_JOY_AXIS_Z_P, WS_JOY_AXIS_Z_M,
418- WS_JOY_AXIS_RY_M, WS_JOY_AXIS_RX_P, WS_JOY_AXIS_RY_P, WS_JOY_AXIS_RX_M, WS_JOY_AXIS_RZ_P, WS_JOY_AXIS_RZ_M,
419- WS_JOY_SLIDER1_P, WS_JOY_SLIDER1_M, WS_JOY_SLIDER2_P, WS_JOY_SLIDER2_M
420- };
421- static TCHAR buf[8];
422- int i;
423-
424- if (joy < 0x80)
425- {
426- _stprintf_s(buf, 8, TEXT("%d"), joy);
427- return buf;
428- }
429- for (i = 0; i < 32; i++)
430- {
431- if (joy == JoyInt[i])
432- {
433- return JoyStr[i];
434- }
435- }
436- buf[0] = 0;
437- return buf;
438-}
439-
440-int GetJoyState(void)
441-{
442- const long joyCenter = 0x7fff;
443- static int xFlag = 0;
444- static int yFlag = 0;
445- static int zFlag = 0;
446- static int rxFlag = 0;
447- static int ryFlag = 0;
448- static int rzFlag = 0;
449- static int s1Flag = 0;
450- static int s2Flag = 0;
451- HRESULT hRet;
452- int joy;
453- unsigned int i;
454- DIJOYSTATE2 js;
455- DIDEVCAPS diDevCaps;
456-
457- diDevCaps.dwSize = sizeof(DIDEVCAPS);
458- if (lpJoyDevice == NULL)
459- {
460- return -1;
461- }
462- hRet = lpJoyDevice->Poll();
463- if (FAILED(hRet))
464- {
465- hRet = lpJoyDevice->Acquire();
466- while (hRet == DIERR_INPUTLOST)
467- {
468- hRet = lpJoyDevice->Acquire();
469- }
470- return -1;
471- }
472- lpJoyDevice->GetDeviceState(sizeof(DIJOYSTATE2), &js);
473- lpJoyDevice->GetCapabilities(&diDevCaps);
474- for (i = 0; i < diDevCaps.dwButtons; i++)
475- {
476- if (js.rgbButtons[i] & 0x80)
477- {
478- return i + 1;
479- }
480- }
481- for (i = 0; i < diDevCaps.dwPOVs; i++)
482- {
483- joy = WS_JOY_POV1_UP + (i << 4);
484- if (js.rgdwPOV[i] == JOY_POVFORWARD)
485- {
486- return joy;
487- }
488- else if (js.rgdwPOV[i] == JOY_POVRIGHT)
489- {
490- return joy + 1;
491- }
492- else if (js.rgdwPOV[i] == JOY_POVBACKWARD)
493- {
494- return joy + 3;
495- }
496- else if (js.rgdwPOV[i] == JOY_POVLEFT)
497- {
498- return joy + 7;
499- }
500- }
501- if ((js.lX > joyCenter - 0x1000) && (js.lX < joyCenter + 0x1000))
502- {
503- xFlag = 1;
504- }
505- if ((js.lX > (joyCenter + 0x4000)) && xFlag)
506- {
507- xFlag = 0;
508- return WS_JOY_AXIS_X_P;
509- }
510- else if ((js.lX < (joyCenter - 0x4000)) && xFlag)
511- {
512- xFlag = 0;
513- return WS_JOY_AXIS_X_M;
514- }
515- if ((js.lY > joyCenter - 0x1000) && (js.lY < joyCenter + 0x1000))
516- {
517- yFlag = 1;
518- }
519- if ((js.lY > (joyCenter + 0x4000)) && yFlag)
520- {
521- yFlag = 0;
522- return WS_JOY_AXIS_Y_P;
523- }
524- else if ((js.lY < (joyCenter - 0x4000)) && yFlag)
525- {
526- yFlag = 0;
527- return WS_JOY_AXIS_Y_M;
528- }
529- if ((js.lZ > joyCenter - 0x1000) && (js.lZ < joyCenter + 0x1000))
530- {
531- zFlag = 1;
532- }
533- if ((js.lZ > (joyCenter + 0x4000)) && zFlag)
534- {
535- zFlag = 0;
536- return WS_JOY_AXIS_Z_P;
537- }
538- else if ((js.lZ < (joyCenter - 0x4000)) && zFlag)
539- {
540- zFlag = 0;
541- return WS_JOY_AXIS_Z_M;
542- }
543- if ((js.lRx > joyCenter - 0x1000) && (js.lRx < joyCenter + 0x1000))
544- {
545- rxFlag = 1;
546- }
547- if ((js.lRx > (joyCenter + 0x4000)) && rxFlag)
548- {
549- rxFlag = 0;
550- return WS_JOY_AXIS_RX_P;
551- }
552- else if ((js.lRx < (joyCenter - 0x4000)) && rxFlag)
553- {
554- rxFlag = 0;
555- return WS_JOY_AXIS_RX_M;
556- }
557- if ((js.lRy > joyCenter - 0x1000) && (js.lRy < joyCenter + 0x1000))
558- {
559- ryFlag = 1;
560- }
561- if ((js.lRy > (joyCenter + 0x4000)) && ryFlag)
562- {
563- ryFlag = 0;
564- return WS_JOY_AXIS_RY_P;
565- }
566- else if ((js.lRy < (joyCenter - 0x4000)) && ryFlag)
567- {
568- ryFlag = 0;
569- return WS_JOY_AXIS_RY_M;
570- }
571- if ((js.lRz > joyCenter - 0x1000) && (js.lRz < joyCenter + 0x1000))
572- {
573- rzFlag = 1;
574- }
575- if ((js.lRz > (joyCenter + 0x4000)) && rzFlag)
576- {
577- rzFlag = 0;
578- return WS_JOY_AXIS_RZ_P;
579- }
580- else if ((js.lRz < (joyCenter - 0x4000)) && rzFlag)
581- {
582- rzFlag = 0;
583- return WS_JOY_AXIS_RZ_M;
584- }
585- if ((js.rglSlider[0] > joyCenter - 0x1000) && (js.rglSlider[0] < joyCenter + 0x1000))
586- {
587- s1Flag = 1;
588- }
589- if ((js.rglSlider[0] > (joyCenter + 0x4000)) && s1Flag)
590- {
591- s1Flag = 0;
592- return WS_JOY_SLIDER1_P;
593- }
594- else if ((js.rglSlider[0] < (joyCenter - 0x4000)) && s1Flag)
595- {
596- s1Flag = 0;
597- return WS_JOY_SLIDER1_M;
598- }
599- if ((js.rglSlider[1] > joyCenter - 0x1000) && (js.rglSlider[0] < joyCenter + 0x1000))
600- {
601- s2Flag = 1;
602- }
603- if ((js.rglSlider[1] > (joyCenter + 0x4000)) && s2Flag)
604- {
605- s2Flag = 0;
606- return WS_JOY_SLIDER2_P;
607- }
608- else if ((js.rglSlider[1] < (joyCenter - 0x4000)) && s2Flag)
609- {
610- s2Flag = 0;
611- return WS_JOY_SLIDER2_M;
612- }
613- return -1;
614-}
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSMain.cpp (revision 101)
+++ oswanj/trunk/src/WSMain.cpp (nonexistent)
@@ -1,522 +0,0 @@
1-/*
2-$Date$
3-$Rev$
4-*/
5-
6-#include "../resource.h"
7-#include "WS.h"
8-#include "WSConfig.h"
9-#include "WSInput.h"
10-#include "WSDraw.h"
11-#include "WSRender.h"
12-#include "WSApu.h"
13-#include "WSFileio.h"
14-#include "WSDialog.h"
15-
16-BOOL InitApp(HINSTANCE);
17-BOOL InitInstance(HINSTANCE);
18-LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
19-LRESULT CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);
20-wchar_t* OpenWSFile(wchar_t*, DWORD);
21-void WsPause(void);
22-void SetRecentRoms(wchar_t* RomPath);
23-void SetStateInfo(void);
24-
25-HINSTANCE hInst;
26-HWND hWnd;
27-static LPCTSTR szClassName = TEXT("OswanJ"); //クラス名
28-static wchar_t RecentOfn0[512];
29-static wchar_t RecentOfn1[512];
30-static wchar_t RecentOfn2[512];
31-static wchar_t RecentOfn3[512];
32-static wchar_t RecentOfn4[512];
33-static wchar_t RecentOfn5[512];
34-wchar_t* RecentOfn[] = {RecentOfn0, RecentOfn1, RecentOfn2, RecentOfn3, RecentOfn4, RecentOfn5};
35-extern wchar_t StateName[512];
36-
37-int WINAPI wWinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPWSTR lpsCmdLine, int nCmdShow)
38-{
39- MSG msg;
40- HACCEL accel;
41-
42- if (!hPrevInst)
43- {
44- if (!InitApp(hCurInst)) return FALSE;
45- }
46- if (!InitInstance(hCurInst))
47- {
48- return FALSE;
49- }
50- hInst = hCurInst;
51- accel = LoadAccelerators(hCurInst, MAKEINTRESOURCE(IDR_ACCELERATOR1));
52- WsSetDir();
53- WsLoadEeprom();
54- ConfigCreate();
55- SetRecentRoms(NULL);
56- apuInit();
57- apuLoadSound();
58- drawInitialize(FALSE);
59- drawCreate();
60- SetDrawSize(DS_2);
61- WsInputInit(hWnd);
62- WsInputSetKeyMap(0);
63- WsSplash();
64- if (__argc > 1)
65- {
66- if (WsCreate(__wargv[1]) != -1)
67- {
68- Sleep(500);
69- Run = 1;
70- SetRecentRoms(__wargv[1]);
71- SetStateInfo();
72- }
73- }
74- while (1) {
75- if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
76- {
77- if (!GetMessage(&msg, NULL, 0, 0))
78- {
79- break;
80- }
81- if (!TranslateAccelerator(hWnd, accel, &msg)) {
82- TranslateMessage(&msg);
83- DispatchMessage(&msg);
84- }
85- }
86- if (Run)
87- {
88- WsRun();
89- }
90- else
91- {
92- Sleep(2);
93- }
94- }
95- WsSaveEeprom();
96- WsRelease();
97- drawDestroy();
98- drawFinalize();
99- apuEnd();
100- ConfigRelease();
101- return 0;
102-}
103-//ウィンドウ・クラスの登録
104-BOOL InitApp(HINSTANCE hInst)
105-{
106- WNDCLASS wc;
107- wc.style = CS_HREDRAW | CS_VREDRAW;
108- wc.lpfnWndProc = WndProc;
109- wc.cbClsExtra = 0;
110- wc.cbWndExtra = 0;
111- wc.hInstance = hInst;
112- wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
113- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
114- wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
115- wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
116- wc.lpszClassName = szClassName;
117- return (RegisterClass(&wc));
118-}
119-//ウィンドウの生成
120-BOOL InitInstance(HINSTANCE hInst)
121-{
122- hWnd = CreateWindow(szClassName, TEXT("OswanJ"),//タイトルバーにこの名前が表示されます
123- WS_OVERLAPPEDWINDOW, //ウィンドウの種類
124- CW_USEDEFAULT, //X座標
125- CW_USEDEFAULT, //Y座標
126- CW_USEDEFAULT, //幅
127- CW_USEDEFAULT, //高さ
128- NULL, //親ウィンドウのハンドル、親を作るときはNULL
129- NULL, //メニューハンドル、クラスメニューを使うときはNUL
130- hInst, //インスタンスハンドル
131- NULL);
132- if (!hWnd) return FALSE;
133- return TRUE;
134-}
135-//ウィンドウプロシージャ
136-LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
137-{
138- wchar_t RomPath[512] = {0};
139- HMENU menu;
140- WORD id;
141-
142- switch (msg)
143- {
144- case WM_CREATE:
145- break;
146- case WM_COMMAND:
147- switch (LOWORD(wp))
148- {
149- case ID_FILE_OPENROM:
150- if (OpenWSFile(RomPath, 512))
151- {
152- apuWaveClear();
153- WsRelease();
154- Run = 1;
155- WsCreate(RomPath);
156- SetRecentRoms(RomPath);
157- SetStateInfo();
158- }
159- return 0L;
160- case ID_FILE_RECENT_0:
161- case ID_FILE_RECENT_1:
162- case ID_FILE_RECENT_2:
163- case ID_FILE_RECENT_3:
164- case ID_FILE_RECENT_4:
165- case ID_FILE_RECENT_5:
166- id = LOWORD(wp) - ID_FILE_RECENT_0;
167- if (*RecentOfn[id])
168- {
169- apuWaveClear();
170- WsRelease();
171- Run = 1;
172- if (WsCreate(RecentOfn[id]) < 0)
173- {
174- wcscpy(RecentOfn[id], L"");
175- Run = 0;
176- WsSplash();
177- }
178- SetRecentRoms(RecentOfn[id]);
179- SetStateInfo();
180- }
181- return 0L;
182- case ID_PDATA_SET:
183- apuWaveClear();
184- WsRelease();
185- Run = 1;
186- WsCreate(NULL);
187- return 0L;
188- case ID_STATE_SAVE_0:
189- case ID_STATE_SAVE_1:
190- case ID_STATE_SAVE_2:
191- case ID_STATE_SAVE_3:
192- id = LOWORD(wp) - ID_STATE_SAVE_0;
193- WsSaveState(id);
194- SetStateInfo();
195- return 0L;
196- case ID_STATE_LOAD_0:
197- case ID_STATE_LOAD_1:
198- case ID_STATE_LOAD_2:
199- case ID_STATE_LOAD_3:
200- id = LOWORD(wp) - ID_STATE_LOAD_0;
201- WsLoadState(id);
202- return 0L;
203- case ID_PAUSE:
204- WsPause();
205- return 0L;
206- case ID_RESET:
207- WsReset();
208- return 0L;
209- case ID_SIZE_1:
210- menu = GetMenu(hWnd);
211- CheckMenuItem(menu, ID_SIZE_1, MF_CHECKED);
212- CheckMenuItem(menu, ID_SIZE_2, MF_UNCHECKED);
213- CheckMenuItem(menu, ID_SIZE_3, MF_UNCHECKED);
214- CheckMenuItem(menu, ID_SIZE_4, MF_UNCHECKED);
215- SetDrawSize(DS_1);
216- return 0L;
217- case ID_SIZE_2:
218- menu = GetMenu(hWnd);
219- CheckMenuItem(menu, ID_SIZE_1, MF_UNCHECKED);
220- CheckMenuItem(menu, ID_SIZE_2, MF_CHECKED);
221- CheckMenuItem(menu, ID_SIZE_3, MF_UNCHECKED);
222- CheckMenuItem(menu, ID_SIZE_4, MF_UNCHECKED);
223- SetDrawSize(DS_2);
224- return 0L;
225- case ID_SIZE_3:
226- menu = GetMenu(hWnd);
227- CheckMenuItem(menu, ID_SIZE_1, MF_UNCHECKED);
228- CheckMenuItem(menu, ID_SIZE_2, MF_UNCHECKED);
229- CheckMenuItem(menu, ID_SIZE_3, MF_CHECKED);
230- CheckMenuItem(menu, ID_SIZE_4, MF_UNCHECKED);
231- SetDrawSize(DS_3);
232- return 0L;
233- case ID_SIZE_4:
234- menu = GetMenu(hWnd);
235- CheckMenuItem(menu, ID_SIZE_1, MF_UNCHECKED);
236- CheckMenuItem(menu, ID_SIZE_2, MF_UNCHECKED);
237- CheckMenuItem(menu, ID_SIZE_3, MF_UNCHECKED);
238- CheckMenuItem(menu, ID_SIZE_4, MF_CHECKED);
239- SetDrawSize(DS_4);
240- return 0L;
241- case ID_LAYER_1:
242- case ID_LAYER_2:
243- case ID_LAYER_S:
244- id = LOWORD(wp) - ID_LAYER_1;
245- menu = GetMenu(hWnd);
246- if (Layer[id])
247- {
248- Layer[id] = 0;
249- CheckMenuItem(menu, LOWORD(wp), MF_UNCHECKED);
250- }
251- else
252- {
253- Layer[id] = 1;
254- CheckMenuItem(menu, LOWORD(wp), MF_CHECKED);
255- }
256- return 0L;
257- case ID_KERORIKAN:
258- menu = GetMenu(hWnd);
259- if (Kerorikan)
260- {
261- Kerorikan = 0;
262- CheckMenuItem(menu, LOWORD(wp), MF_UNCHECKED);
263- WsResize();
264- drawDraw();
265- }
266- else
267- {
268- Kerorikan = 1;
269- CheckMenuItem(menu, LOWORD(wp), MF_CHECKED);
270- WsResize();
271- drawDraw();
272- }
273- return 0L;
274- case ID_SOUND_1:
275- case ID_SOUND_2:
276- case ID_SOUND_3:
277- case ID_SOUND_4:
278- case ID_SOUND_5:
279- case ID_SOUND_6:
280- case ID_SOUND_7:
281- id = LOWORD(wp) - ID_SOUND_1;
282- menu = GetMenu(hWnd);
283- if (Sound[id])
284- {
285- Sound[id] = 0;
286- CheckMenuItem(menu, LOWORD(wp), MF_UNCHECKED);
287- }
288- else
289- {
290- Sound[id] = 1;
291- CheckMenuItem(menu, LOWORD(wp), MF_CHECKED);
292- }
293- return 0L;
294- case ID_SOUND_UP:
295- if (WsWaveVol < 100)
296- {
297- WsWaveVol++;
298- }
299- return 0L;
300- case ID_SOUND_DOWN:
301- if (WsWaveVol >= 1)
302- {
303- WsWaveVol--;
304- }
305- return 0L;
306- case ID_CONF_INPUT:
307- WsInputRelease();
308- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_CONFIG), hWnd, (DLGPROC)ConfProc);
309- WsInputInit(hWnd);
310- return 0L;
311- case ID_ABOUT:
312- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)AboutProc);
313- break;
314- }
315- break;
316- case WM_PAINT:
317- drawDraw();
318- break;
319- case WM_DESTROY:
320- PostQuitMessage(0);
321- return 0L;
322- default:
323- break;
324- }
325- return (DefWindowProc(hWnd, msg, wp, lp));
326-}
327-
328-//Aboutダイアログプロシージャ
329-LRESULT CALLBACK AboutProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
330-{
331- HDC hDC;
332- HFONT hFont;
333-
334- switch (msg)
335- {
336- case WM_INITDIALOG:
337- SetWindowText(GetDlgItem(hDlgWnd, IDC_TEXT_VERSION), TEXT("バージョン 0.1"));
338- break;
339- case WM_CTLCOLORSTATIC:
340- if((HWND)lp == GetDlgItem(hDlgWnd, IDC_TEXT_VERSION))
341- {
342- hDC = (HDC)wp;
343- hFont = CreateFont(
344- 18, /* フォント高さ */
345- 0, /* 文字幅 */
346- 0, /* テキストの角度 */
347- 0, /* ベースラインとx軸との角度 */
348- FW_BOLD, /* フォントの重さ(太さ) */
349- FALSE, /* イタリック体 */
350- FALSE, /* アンダーライン */
351- FALSE, /* 打ち消し線 */
352- SHIFTJIS_CHARSET, /* 文字セット */
353- OUT_DEFAULT_PRECIS, /* 出力精度 */
354- CLIP_DEFAULT_PRECIS, /* クリッピング精度 */
355- PROOF_QUALITY, /* 出力品質 */
356- FIXED_PITCH | FF_MODERN, /* ピッチとファミリー */
357- (LPCTSTR)"MS Pゴシック" /* 書体名 */
358- );
359- SelectObject(hDC, hFont);
360- SetTextColor(hDC, RGB(0, 0, 255));
361- SetBkMode(hDC, TRANSPARENT);
362- return (BOOL)(HBRUSH)GetStockObject(NULL_BRUSH);
363- }
364- return DefWindowProc(hDlgWnd, msg, wp, lp);
365- case WM_COMMAND:
366- if(HIWORD(wp) == BN_CLICKED)
367- {
368- switch (LOWORD(wp))
369- {
370- case IDOK:
371- case IDCANCEL:
372- EndDialog(hDlgWnd, LOWORD(wp));
373- return 1;
374- }
375- }
376- break;
377- }
378- return 0;
379-}
380-
381-wchar_t* OpenWSFile(wchar_t* path, DWORD max)
382-{
383- OPENFILENAMEW ofn;
384-
385- ZeroMemory(&ofn, sizeof(OPENFILENAMEW));
386- ofn.lStructSize = sizeof(OPENFILENAMEW);
387- ofn.hwndOwner = hWnd;
388- ofn.lpstrFile = path;
389- ofn.nMaxFile = max;
390- ofn.lpstrFilter = L"Wonderswan(*.ws,*.wsc)\0*.ws;*.wsc\0Wonderswan mono(*.ws)\0*.ws\0Wonderswan color(*.wsc)\0*.wsc\0\0";
391- ofn.nFilterIndex = 1;
392- ofn.lpstrFileTitle = NULL;
393- ofn.nMaxFileTitle = 0;
394- ofn.lpstrInitialDir = NULL;
395- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
396- ofn.hInstance = NULL;
397- if (GetOpenFileNameW(&ofn) == FALSE)
398- {
399- return NULL;
400- }
401- return path;
402-}
403-
404-void WsPause(void)
405-{
406- static int pause = 0;
407- HMENU menu = GetMenu(hWnd);
408-
409- if (Run)
410- {
411- pause = 1;
412- Run = 0;
413- CheckMenuItem(menu, ID_PAUSE, MF_CHECKED);
414- apuWaveClear();
415- }
416- else if (pause)
417- {
418- Run = 1;
419- pause = 0;
420- CheckMenuItem(menu, ID_PAUSE, MF_UNCHECKED);
421- }
422-}
423-
424-void SetRecentRoms(wchar_t* RomPath)
425-{
426- int i;
427- wchar_t* temp;
428- wchar_t* filename;
429- wchar_t buf[256];
430- MENUITEMINFOW minfo;
431- HMENU menu = GetMenu(hWnd);
432-
433- minfo.cbSize = sizeof(MENUITEMINFOW);
434- minfo.fMask = MIIM_STATE | MIIM_TYPE;
435- minfo.fType = MFT_STRING;
436- minfo.fState = MFS_ENABLED;
437- minfo.dwTypeData = buf;
438- if (RomPath && *RomPath)
439- {
440- for (i = 0; i < 6; i++)
441- {
442- if (wcscmp(RomPath, RecentOfn[i]) == 0)
443- {
444- temp = RecentOfn[i];
445- while (i) {
446- RecentOfn[i] = RecentOfn[i - 1];
447- i--;
448- }
449- RecentOfn[0] = temp;
450- break;
451- }
452- }
453- if (i)
454- {
455- temp = RecentOfn[5];
456- RecentOfn[5] = RecentOfn[4];
457- RecentOfn[4] = RecentOfn[3];
458- RecentOfn[3] = RecentOfn[2];
459- RecentOfn[2] = RecentOfn[1];
460- RecentOfn[1] = RecentOfn[0];
461- RecentOfn[0] = temp;
462- wcscpy(RecentOfn[0], RomPath);
463- }
464- }
465- for (i = 0; i < 6; i++)
466- {
467- if (*RecentOfn[i])
468- {
469- filename = wcsrchr(RecentOfn[i], '\\');
470- wsprintf(buf, L"&%d %s", i + 1, ++filename);
471- }
472- else
473- {
474- wsprintf(buf, L"%d", i + 1);
475- }
476- SetMenuItemInfo(menu, ID_FILE_RECENT_0 + i, FALSE, &minfo);
477- }
478-}
479-
480-void SetStateInfo(void)
481-{
482- int i;
483- wchar_t buf[512];
484- MENUITEMINFOW minfo;
485- HMENU menu = GetMenu(hWnd);
486- HANDLE file;
487- FILETIME ft, lt;
488- SYSTEMTIME st;
489-
490- minfo.cbSize = sizeof(MENUITEMINFOW);
491- minfo.fMask = MIIM_STATE | MIIM_TYPE;
492- minfo.fType = MFT_STRING;
493- minfo.fState = MFS_ENABLED;
494- minfo.dwTypeData = buf;
495- if (StateName[0])
496- {
497- for (i = 0; i < 4; i++)
498- {
499- wsprintf(buf, L"%s.%03d", StateName, i);
500- file = CreateFileW(buf, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
501- if (file != INVALID_HANDLE_VALUE)
502- {
503- GetFileTime(file, NULL, NULL, &ft);
504- FileTimeToLocalFileTime(&ft, &lt);
505- FileTimeToSystemTime(&lt, &st);
506- wsprintf(buf, L"&%d %04d/%02d/%02d %02d:%02d:%02d\tShift+F%d",
507- i + 1, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, i + 1);
508- SetMenuItemInfo(menu, ID_STATE_SAVE_0 + i, FALSE, &minfo);
509- wsprintf(buf, L"&%d %04d/%02d/%02d %02d:%02d:%02d\tF%d",
510- i + 1, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, i + 1);
511- SetMenuItemInfo(menu, ID_STATE_LOAD_0 + i, FALSE, &minfo);
512- CloseHandle(file);
513- }
514- else
515- {
516- wsprintf(buf, L"%d", i + 1);
517- SetMenuItemInfo(menu, ID_STATE_SAVE_0 + i, FALSE, &minfo);
518- SetMenuItemInfo(menu, ID_STATE_LOAD_0 + i, FALSE, &minfo);
519- }
520- }
521- }
522-}
Deleted: svn:keywords
## -1,2 +0,0 ##
-Date
-Rev
\ No newline at end of property
--- oswanj/trunk/src/WSMain.c (nonexistent)
+++ oswanj/trunk/src/WSMain.c (revision 102)
@@ -0,0 +1,522 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include "../resource.h"
7+#include "WS.h"
8+#include "WSConfig.h"
9+#include "WSInput.h"
10+#include "WSDraw.h"
11+#include "WSRender.h"
12+#include "WSApu.h"
13+#include "WSFileio.h"
14+#include "WSDialog.h"
15+
16+BOOL InitApp(HINSTANCE);
17+BOOL InitInstance(HINSTANCE);
18+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
19+LRESULT CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);
20+wchar_t* OpenWSFile(wchar_t*, DWORD);
21+void WsPause(void);
22+void SetRecentRoms(wchar_t* RomPath);
23+void SetStateInfo(void);
24+
25+HINSTANCE hInst;
26+HWND hWnd;
27+static LPCTSTR szClassName = TEXT("OswanJ"); //クラス名
28+static wchar_t RecentOfn0[512];
29+static wchar_t RecentOfn1[512];
30+static wchar_t RecentOfn2[512];
31+static wchar_t RecentOfn3[512];
32+static wchar_t RecentOfn4[512];
33+static wchar_t RecentOfn5[512];
34+wchar_t* RecentOfn[] = {RecentOfn0, RecentOfn1, RecentOfn2, RecentOfn3, RecentOfn4, RecentOfn5};
35+extern wchar_t StateName[512];
36+
37+int WINAPI wWinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPWSTR lpsCmdLine, int nCmdShow)
38+{
39+ MSG msg;
40+ HACCEL accel;
41+
42+ if (!hPrevInst)
43+ {
44+ if (!InitApp(hCurInst)) return FALSE;
45+ }
46+ if (!InitInstance(hCurInst))
47+ {
48+ return FALSE;
49+ }
50+ hInst = hCurInst;
51+ accel = LoadAccelerators(hCurInst, MAKEINTRESOURCE(IDR_ACCELERATOR1));
52+ WsSetDir();
53+ WsLoadEeprom();
54+ ConfigCreate();
55+ SetRecentRoms(NULL);
56+ apuInit();
57+ apuLoadSound();
58+ drawInitialize(FALSE);
59+ drawCreate();
60+ SetDrawSize(DS_2);
61+ WsInputInit(hWnd);
62+ WsInputSetKeyMap(0);
63+ WsSplash();
64+ if (__argc > 1)
65+ {
66+ if (WsCreate(__wargv[1]) != -1)
67+ {
68+ Sleep(500);
69+ Run = 1;
70+ SetRecentRoms(__wargv[1]);
71+ SetStateInfo();
72+ }
73+ }
74+ while (1) {
75+ if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
76+ {
77+ if (!GetMessage(&msg, NULL, 0, 0))
78+ {
79+ break;
80+ }
81+ if (!TranslateAccelerator(hWnd, accel, &msg)) {
82+ TranslateMessage(&msg);
83+ DispatchMessage(&msg);
84+ }
85+ }
86+ if (Run)
87+ {
88+ WsRun();
89+ }
90+ else
91+ {
92+ Sleep(2);
93+ }
94+ }
95+ WsSaveEeprom();
96+ WsRelease();
97+ drawDestroy();
98+ drawFinalize();
99+ apuEnd();
100+ ConfigRelease();
101+ return 0;
102+}
103+//ウィンドウ・クラスの登録
104+BOOL InitApp(HINSTANCE hInst)
105+{
106+ WNDCLASS wc;
107+ wc.style = CS_HREDRAW | CS_VREDRAW;
108+ wc.lpfnWndProc = WndProc;
109+ wc.cbClsExtra = 0;
110+ wc.cbWndExtra = 0;
111+ wc.hInstance = hInst;
112+ wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
113+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
114+ wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
115+ wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
116+ wc.lpszClassName = szClassName;
117+ return (RegisterClass(&wc));
118+}
119+//ウィンドウの生成
120+BOOL InitInstance(HINSTANCE hInst)
121+{
122+ hWnd = CreateWindow(szClassName, TEXT("OswanJ"),//タイトルバーにこの名前が表示されます
123+ WS_OVERLAPPEDWINDOW, //ウィンドウの種類
124+ CW_USEDEFAULT, //X座標
125+ CW_USEDEFAULT, //Y座標
126+ CW_USEDEFAULT, //幅
127+ CW_USEDEFAULT, //高さ
128+ NULL, //親ウィンドウのハンドル、親を作るときはNULL
129+ NULL, //メニューハンドル、クラスメニューを使うときはNUL
130+ hInst, //インスタンスハンドル
131+ NULL);
132+ if (!hWnd) return FALSE;
133+ return TRUE;
134+}
135+//ウィンドウプロシージャ
136+LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
137+{
138+ wchar_t RomPath[512] = {0};
139+ HMENU menu;
140+ WORD id;
141+
142+ switch (msg)
143+ {
144+ case WM_CREATE:
145+ break;
146+ case WM_COMMAND:
147+ switch (LOWORD(wp))
148+ {
149+ case ID_FILE_OPENROM:
150+ if (OpenWSFile(RomPath, 512))
151+ {
152+ apuWaveClear();
153+ WsRelease();
154+ Run = 1;
155+ WsCreate(RomPath);
156+ SetRecentRoms(RomPath);
157+ SetStateInfo();
158+ }
159+ return 0L;
160+ case ID_FILE_RECENT_0:
161+ case ID_FILE_RECENT_1:
162+ case ID_FILE_RECENT_2:
163+ case ID_FILE_RECENT_3:
164+ case ID_FILE_RECENT_4:
165+ case ID_FILE_RECENT_5:
166+ id = LOWORD(wp) - ID_FILE_RECENT_0;
167+ if (*RecentOfn[id])
168+ {
169+ apuWaveClear();
170+ WsRelease();
171+ Run = 1;
172+ if (WsCreate(RecentOfn[id]) < 0)
173+ {
174+ wcscpy(RecentOfn[id], L"");
175+ Run = 0;
176+ WsSplash();
177+ }
178+ SetRecentRoms(RecentOfn[id]);
179+ SetStateInfo();
180+ }
181+ return 0L;
182+ case ID_PDATA_SET:
183+ apuWaveClear();
184+ WsRelease();
185+ Run = 1;
186+ WsCreate(NULL);
187+ return 0L;
188+ case ID_STATE_SAVE_0:
189+ case ID_STATE_SAVE_1:
190+ case ID_STATE_SAVE_2:
191+ case ID_STATE_SAVE_3:
192+ id = LOWORD(wp) - ID_STATE_SAVE_0;
193+ WsSaveState(id);
194+ SetStateInfo();
195+ return 0L;
196+ case ID_STATE_LOAD_0:
197+ case ID_STATE_LOAD_1:
198+ case ID_STATE_LOAD_2:
199+ case ID_STATE_LOAD_3:
200+ id = LOWORD(wp) - ID_STATE_LOAD_0;
201+ WsLoadState(id);
202+ return 0L;
203+ case ID_PAUSE:
204+ WsPause();
205+ return 0L;
206+ case ID_RESET:
207+ WsReset();
208+ return 0L;
209+ case ID_SIZE_1:
210+ menu = GetMenu(hWnd);
211+ CheckMenuItem(menu, ID_SIZE_1, MF_CHECKED);
212+ CheckMenuItem(menu, ID_SIZE_2, MF_UNCHECKED);
213+ CheckMenuItem(menu, ID_SIZE_3, MF_UNCHECKED);
214+ CheckMenuItem(menu, ID_SIZE_4, MF_UNCHECKED);
215+ SetDrawSize(DS_1);
216+ return 0L;
217+ case ID_SIZE_2:
218+ menu = GetMenu(hWnd);
219+ CheckMenuItem(menu, ID_SIZE_1, MF_UNCHECKED);
220+ CheckMenuItem(menu, ID_SIZE_2, MF_CHECKED);
221+ CheckMenuItem(menu, ID_SIZE_3, MF_UNCHECKED);
222+ CheckMenuItem(menu, ID_SIZE_4, MF_UNCHECKED);
223+ SetDrawSize(DS_2);
224+ return 0L;
225+ case ID_SIZE_3:
226+ menu = GetMenu(hWnd);
227+ CheckMenuItem(menu, ID_SIZE_1, MF_UNCHECKED);
228+ CheckMenuItem(menu, ID_SIZE_2, MF_UNCHECKED);
229+ CheckMenuItem(menu, ID_SIZE_3, MF_CHECKED);
230+ CheckMenuItem(menu, ID_SIZE_4, MF_UNCHECKED);
231+ SetDrawSize(DS_3);
232+ return 0L;
233+ case ID_SIZE_4:
234+ menu = GetMenu(hWnd);
235+ CheckMenuItem(menu, ID_SIZE_1, MF_UNCHECKED);
236+ CheckMenuItem(menu, ID_SIZE_2, MF_UNCHECKED);
237+ CheckMenuItem(menu, ID_SIZE_3, MF_UNCHECKED);
238+ CheckMenuItem(menu, ID_SIZE_4, MF_CHECKED);
239+ SetDrawSize(DS_4);
240+ return 0L;
241+ case ID_LAYER_1:
242+ case ID_LAYER_2:
243+ case ID_LAYER_S:
244+ id = LOWORD(wp) - ID_LAYER_1;
245+ menu = GetMenu(hWnd);
246+ if (Layer[id])
247+ {
248+ Layer[id] = 0;
249+ CheckMenuItem(menu, LOWORD(wp), MF_UNCHECKED);
250+ }
251+ else
252+ {
253+ Layer[id] = 1;
254+ CheckMenuItem(menu, LOWORD(wp), MF_CHECKED);
255+ }
256+ return 0L;
257+ case ID_KERORIKAN:
258+ menu = GetMenu(hWnd);
259+ if (Kerorikan)
260+ {
261+ Kerorikan = 0;
262+ CheckMenuItem(menu, LOWORD(wp), MF_UNCHECKED);
263+ WsResize();
264+ drawDraw();
265+ }
266+ else
267+ {
268+ Kerorikan = 1;
269+ CheckMenuItem(menu, LOWORD(wp), MF_CHECKED);
270+ WsResize();
271+ drawDraw();
272+ }
273+ return 0L;
274+ case ID_SOUND_1:
275+ case ID_SOUND_2:
276+ case ID_SOUND_3:
277+ case ID_SOUND_4:
278+ case ID_SOUND_5:
279+ case ID_SOUND_6:
280+ case ID_SOUND_7:
281+ id = LOWORD(wp) - ID_SOUND_1;
282+ menu = GetMenu(hWnd);
283+ if (Sound[id])
284+ {
285+ Sound[id] = 0;
286+ CheckMenuItem(menu, LOWORD(wp), MF_UNCHECKED);
287+ }
288+ else
289+ {
290+ Sound[id] = 1;
291+ CheckMenuItem(menu, LOWORD(wp), MF_CHECKED);
292+ }
293+ return 0L;
294+ case ID_SOUND_UP:
295+ if (WsWaveVol < 100)
296+ {
297+ WsWaveVol++;
298+ }
299+ return 0L;
300+ case ID_SOUND_DOWN:
301+ if (WsWaveVol >= 1)
302+ {
303+ WsWaveVol--;
304+ }
305+ return 0L;
306+ case ID_CONF_INPUT:
307+ WsInputRelease();
308+ DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_CONFIG), hWnd, (DLGPROC)ConfProc);
309+ WsInputInit(hWnd);
310+ return 0L;
311+ case ID_ABOUT:
312+ DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)AboutProc);
313+ break;
314+ }
315+ break;
316+ case WM_PAINT:
317+ drawDraw();
318+ break;
319+ case WM_DESTROY:
320+ PostQuitMessage(0);
321+ return 0L;
322+ default:
323+ break;
324+ }
325+ return (DefWindowProc(hWnd, msg, wp, lp));
326+}
327+
328+//Aboutダイアログプロシージャ
329+LRESULT CALLBACK AboutProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
330+{
331+ HDC hDC;
332+ HFONT hFont;
333+
334+ switch (msg)
335+ {
336+ case WM_INITDIALOG:
337+ SetWindowText(GetDlgItem(hDlgWnd, IDC_TEXT_VERSION), TEXT("バージョン 0.1"));
338+ break;
339+ case WM_CTLCOLORSTATIC:
340+ if((HWND)lp == GetDlgItem(hDlgWnd, IDC_TEXT_VERSION))
341+ {
342+ hDC = (HDC)wp;
343+ hFont = CreateFont(
344+ 18, /* フォント高さ */
345+ 0, /* 文字幅 */
346+ 0, /* テキストの角度 */
347+ 0, /* ベースラインとx軸との角度 */
348+ FW_BOLD, /* フォントの重さ(太さ) */
349+ FALSE, /* イタリック体 */
350+ FALSE, /* アンダーライン */
351+ FALSE, /* 打ち消し線 */
352+ SHIFTJIS_CHARSET, /* 文字セット */
353+ OUT_DEFAULT_PRECIS, /* 出力精度 */
354+ CLIP_DEFAULT_PRECIS, /* クリッピング精度 */
355+ PROOF_QUALITY, /* 出力品質 */
356+ FIXED_PITCH | FF_MODERN, /* ピッチとファミリー */
357+ (LPCTSTR)"MS Pゴシック" /* 書体名 */
358+ );
359+ SelectObject(hDC, hFont);
360+ SetTextColor(hDC, RGB(0, 0, 255));
361+ SetBkMode(hDC, TRANSPARENT);
362+ return (BOOL)(HBRUSH)GetStockObject(NULL_BRUSH);
363+ }
364+ return DefWindowProc(hDlgWnd, msg, wp, lp);
365+ case WM_COMMAND:
366+ if(HIWORD(wp) == BN_CLICKED)
367+ {
368+ switch (LOWORD(wp))
369+ {
370+ case IDOK:
371+ case IDCANCEL:
372+ EndDialog(hDlgWnd, LOWORD(wp));
373+ return 1;
374+ }
375+ }
376+ break;
377+ }
378+ return 0;
379+}
380+
381+wchar_t* OpenWSFile(wchar_t* path, DWORD max)
382+{
383+ OPENFILENAMEW ofn;
384+
385+ ZeroMemory(&ofn, sizeof(OPENFILENAMEW));
386+ ofn.lStructSize = sizeof(OPENFILENAMEW);
387+ ofn.hwndOwner = hWnd;
388+ ofn.lpstrFile = path;
389+ ofn.nMaxFile = max;
390+ ofn.lpstrFilter = L"Wonderswan(*.ws,*.wsc)\0*.ws;*.wsc\0Wonderswan mono(*.ws)\0*.ws\0Wonderswan color(*.wsc)\0*.wsc\0\0";
391+ ofn.nFilterIndex = 1;
392+ ofn.lpstrFileTitle = NULL;
393+ ofn.nMaxFileTitle = 0;
394+ ofn.lpstrInitialDir = NULL;
395+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
396+ ofn.hInstance = NULL;
397+ if (GetOpenFileNameW(&ofn) == FALSE)
398+ {
399+ return NULL;
400+ }
401+ return path;
402+}
403+
404+void WsPause(void)
405+{
406+ static int pause = 0;
407+ HMENU menu = GetMenu(hWnd);
408+
409+ if (Run)
410+ {
411+ pause = 1;
412+ Run = 0;
413+ CheckMenuItem(menu, ID_PAUSE, MF_CHECKED);
414+ apuWaveClear();
415+ }
416+ else if (pause)
417+ {
418+ Run = 1;
419+ pause = 0;
420+ CheckMenuItem(menu, ID_PAUSE, MF_UNCHECKED);
421+ }
422+}
423+
424+void SetRecentRoms(wchar_t* RomPath)
425+{
426+ int i;
427+ wchar_t* temp;
428+ wchar_t* filename;
429+ wchar_t buf[256];
430+ MENUITEMINFOW minfo;
431+ HMENU menu = GetMenu(hWnd);
432+
433+ minfo.cbSize = sizeof(MENUITEMINFOW);
434+ minfo.fMask = MIIM_STATE | MIIM_TYPE;
435+ minfo.fType = MFT_STRING;
436+ minfo.fState = MFS_ENABLED;
437+ minfo.dwTypeData = buf;
438+ if (RomPath && *RomPath)
439+ {
440+ for (i = 0; i < 6; i++)
441+ {
442+ if (wcscmp(RomPath, RecentOfn[i]) == 0)
443+ {
444+ temp = RecentOfn[i];
445+ while (i) {
446+ RecentOfn[i] = RecentOfn[i - 1];
447+ i--;
448+ }
449+ RecentOfn[0] = temp;
450+ break;
451+ }
452+ }
453+ if (i)
454+ {
455+ temp = RecentOfn[5];
456+ RecentOfn[5] = RecentOfn[4];
457+ RecentOfn[4] = RecentOfn[3];
458+ RecentOfn[3] = RecentOfn[2];
459+ RecentOfn[2] = RecentOfn[1];
460+ RecentOfn[1] = RecentOfn[0];
461+ RecentOfn[0] = temp;
462+ wcscpy(RecentOfn[0], RomPath);
463+ }
464+ }
465+ for (i = 0; i < 6; i++)
466+ {
467+ if (*RecentOfn[i])
468+ {
469+ filename = wcsrchr(RecentOfn[i], '\\');
470+ wsprintf(buf, L"&%d %s", i + 1, ++filename);
471+ }
472+ else
473+ {
474+ wsprintf(buf, L"%d", i + 1);
475+ }
476+ SetMenuItemInfo(menu, ID_FILE_RECENT_0 + i, FALSE, &minfo);
477+ }
478+}
479+
480+void SetStateInfo(void)
481+{
482+ int i;
483+ wchar_t buf[512];
484+ MENUITEMINFOW minfo;
485+ HMENU menu = GetMenu(hWnd);
486+ HANDLE file;
487+ FILETIME ft, lt;
488+ SYSTEMTIME st;
489+
490+ minfo.cbSize = sizeof(MENUITEMINFOW);
491+ minfo.fMask = MIIM_STATE | MIIM_TYPE;
492+ minfo.fType = MFT_STRING;
493+ minfo.fState = MFS_ENABLED;
494+ minfo.dwTypeData = buf;
495+ if (StateName[0])
496+ {
497+ for (i = 0; i < 4; i++)
498+ {
499+ wsprintf(buf, L"%s.%03d", StateName, i);
500+ file = CreateFileW(buf, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
501+ if (file != INVALID_HANDLE_VALUE)
502+ {
503+ GetFileTime(file, NULL, NULL, &ft);
504+ FileTimeToLocalFileTime(&ft, &lt);
505+ FileTimeToSystemTime(&lt, &st);
506+ wsprintf(buf, L"&%d %04d/%02d/%02d %02d:%02d:%02d\tShift+F%d",
507+ i + 1, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, i + 1);
508+ SetMenuItemInfo(menu, ID_STATE_SAVE_0 + i, FALSE, &minfo);
509+ wsprintf(buf, L"&%d %04d/%02d/%02d %02d:%02d:%02d\tF%d",
510+ i + 1, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, i + 1);
511+ SetMenuItemInfo(menu, ID_STATE_LOAD_0 + i, FALSE, &minfo);
512+ CloseHandle(file);
513+ }
514+ else
515+ {
516+ wsprintf(buf, L"%d", i + 1);
517+ SetMenuItemInfo(menu, ID_STATE_SAVE_0 + i, FALSE, &minfo);
518+ SetMenuItemInfo(menu, ID_STATE_LOAD_0 + i, FALSE, &minfo);
519+ }
520+ }
521+ }
522+}
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSApu.c (nonexistent)
+++ oswanj/trunk/src/WSApu.c (revision 102)
@@ -0,0 +1,494 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include <windows.h>
7+#include <mmsystem.h>
8+#include "../resource.h"
9+#include "WSHard.h"
10+#include "WSApu.h"
11+#include "WSError.h"
12+#include "WSInput.h"
13+
14+#define BUFSIZEN 0x10000
15+#define BPSWAV 12000 // WSのHblankが12KHz
16+#define BUFSIZEW 64
17+#define BUFCOUNT 30
18+
19+unsigned long WaveMap;
20+SOUND Ch[4];
21+int VoiceOn;
22+SWEEP Swp;
23+NOISE Noise;
24+int Sound[7] = {1, 1, 1, 1, 1, 1, 1};
25+int WsWaveVol = 4;
26+
27+static unsigned char PData[4][32];
28+static unsigned char PDataN[8][BUFSIZEN];
29+static unsigned int RandData[BUFSIZEN];
30+
31+static HWAVEOUT hWaveOut;
32+static WAVEHDR *whdr[BUFCOUNT];
33+static int rBuf, wBuf, wPos;
34+
35+extern HWND hWnd;
36+extern BYTE *Page[16];
37+extern BYTE IO[0x100];
38+
39+
40+
41+void CALLBACK apuWaveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
42+{
43+ switch (uMsg)
44+ {
45+ case WOM_OPEN:
46+ break;
47+ case WOM_DONE:
48+ rBuf++;
49+ if (rBuf >= BUFCOUNT)
50+ {
51+ rBuf = 0;
52+ }
53+ break;
54+ case WOM_CLOSE:
55+ break;
56+ }
57+}
58+
59+int apuWaveCreate(void)
60+{
61+ MMRESULT result;
62+ WAVEFORMATEX wfe;
63+ int i;
64+ TCHAR msg[255];
65+
66+ rBuf = 0;
67+ wBuf = 0;
68+ wPos = 0;
69+ ZeroMemory(&wfe, sizeof(wfe));
70+ wfe.wFormatTag = WAVE_FORMAT_PCM;
71+ wfe.nChannels = 2;
72+ wfe.wBitsPerSample = 16;
73+ wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample / 8;
74+ wfe.nSamplesPerSec = BPSWAV;
75+ wfe.nAvgBytesPerSec = wfe.nSamplesPerSec * wfe.nBlockAlign;
76+ result = waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfe, (DWORD_PTR)apuWaveOutProc, (DWORD_PTR)NULL, CALLBACK_FUNCTION);
77+ if (result != MMSYSERR_NOERROR )
78+ {
79+ waveOutGetErrorText(result, msg, sizeof(msg));
80+ ErrorMsg(ERR_WAVEOUT_OPEN);
81+ }
82+ for (i = 0; i < BUFCOUNT; i++)
83+ {
84+ whdr[i] = (WAVEHDR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WAVEHDR));
85+ whdr[i]->lpData = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, BUFSIZEW * 4);
86+ whdr[i]->dwBufferLength = BUFSIZEW * 4;
87+ whdr[i]->dwFlags = 0;
88+ whdr[i]->dwLoops = 0;
89+ result = waveOutPrepareHeader(hWaveOut, whdr[i], sizeof(WAVEHDR));
90+ if (result != MMSYSERR_NOERROR )
91+ {
92+ waveOutGetErrorText(result, msg, sizeof(msg));
93+ ErrorMsg(ERR_WAVEOUT_PREPAREHEADER);
94+ }
95+ }
96+ return 0;
97+}
98+
99+void apuWaveRelease(void)
100+{
101+ int i;
102+
103+ waveOutReset(hWaveOut);
104+ for(i = 0; i < BUFCOUNT; i++)
105+ {
106+ if (whdr[i])
107+ {
108+ waveOutUnprepareHeader(hWaveOut,whdr[i],sizeof(WAVEHDR));
109+ HeapFree(GetProcessHeap(),0,whdr[i]->lpData);
110+ HeapFree(GetProcessHeap(),0,whdr[i]);
111+ whdr[i] = NULL;
112+ }
113+ }
114+ waveOutClose(hWaveOut);
115+ return;
116+}
117+
118+void apuWaveClear(void)
119+{
120+ int i;
121+
122+ waveOutReset(hWaveOut);
123+ for (i = 0; i < BUFCOUNT; i++)
124+ {
125+ ZeroMemory(whdr[i]->lpData, BUFSIZEW * 4);
126+ }
127+ rBuf = 0;
128+ wBuf = 0;
129+ wPos = 0;
130+}
131+
132+int apuInit(void)
133+{
134+ int i, j;
135+
136+ for (i = 0; i < 4; i++)
137+ {
138+ for (j = 0; j < 32; j++)
139+ {
140+ PData[i][j] = 8;
141+ }
142+ }
143+ for (i = 0; i < 8; i++)
144+ {
145+ for (j = 0; j < BUFSIZEN; j++)
146+ {
147+ PDataN[i][j] = ((apuMrand(15 - i) & 1) ? 15 : 0);
148+ }
149+ }
150+
151+ for (i = 0; i < BUFSIZEN; i++)
152+ {
153+ RandData[i] = apuMrand(15);
154+ }
155+ apuWaveCreate();
156+ return 0;
157+}
158+
159+void apuEnd(void)
160+{
161+ apuWaveRelease();
162+ apuDestroySound();
163+}
164+
165+unsigned int apuMrand(unsigned int Degree)
166+{
167+#define BIT(n) (1<<n)
168+ typedef struct
169+ {
170+ unsigned int N;
171+ int InputBit;
172+ int Mask;
173+ } POLYNOMIAL;
174+
175+ static POLYNOMIAL TblMask[]=
176+ {
177+ { 2,BIT(2) ,BIT(0)|BIT(1)},
178+ { 3,BIT(3) ,BIT(0)|BIT(1)},
179+ { 4,BIT(4) ,BIT(0)|BIT(1)},
180+ { 5,BIT(5) ,BIT(0)|BIT(2)},
181+ { 6,BIT(6) ,BIT(0)|BIT(1)},
182+ { 7,BIT(7) ,BIT(0)|BIT(1)},
183+ { 8,BIT(8) ,BIT(0)|BIT(2)|BIT(3)|BIT(4)},
184+ { 9,BIT(9) ,BIT(0)|BIT(4)},
185+ {10,BIT(10),BIT(0)|BIT(3)},
186+ {11,BIT(11),BIT(0)|BIT(2)},
187+ {12,BIT(12),BIT(0)|BIT(1)|BIT(4)|BIT(6)},
188+ {13,BIT(13),BIT(0)|BIT(1)|BIT(3)|BIT(4)},
189+ {14,BIT(14),BIT(0)|BIT(1)|BIT(4)|BIT(5)},
190+ {15,BIT(15),BIT(0)|BIT(1)},
191+ { 0, 0, 0},
192+ };
193+ static POLYNOMIAL *pTbl = TblMask;
194+ static int ShiftReg = BIT(2)-1;
195+ int XorReg = 0;
196+ int Masked;
197+
198+ if(pTbl->N != Degree)
199+ {
200+ pTbl = TblMask;
201+ while(pTbl->N) {
202+ if(pTbl->N == Degree)
203+ {
204+ break;
205+ }
206+ pTbl++;
207+ }
208+ if(!pTbl->N)
209+ {
210+ pTbl--;
211+ }
212+ ShiftReg &= pTbl->InputBit-1;
213+ if(!ShiftReg)
214+ {
215+ ShiftReg = pTbl->InputBit-1;
216+ }
217+ }
218+ Masked = ShiftReg & pTbl->Mask;
219+ while(Masked)
220+ {
221+ XorReg ^= Masked & 0x01;
222+ Masked >>= 1;
223+ }
224+ if(XorReg)
225+ {
226+ ShiftReg |= pTbl->InputBit;
227+ }
228+ else
229+ {
230+ ShiftReg &= ~pTbl->InputBit;
231+ }
232+ ShiftReg >>= 1;
233+ return ShiftReg;
234+}
235+
236+void apuSetPData(int addr, unsigned char val)
237+{
238+ int i, j;
239+
240+ i = (addr & 0x30) >> 4;
241+ j = (addr & 0x0F) << 1;
242+ PData[i][j]=(unsigned char)(val & 0x0F);
243+ PData[i][j + 1]=(unsigned char)((val & 0xF0)>>4);
244+}
245+
246+unsigned char apuVoice(void)
247+{
248+ static int index = 0, b = 0;
249+ unsigned char v;
250+
251+ if ((IO[SDMACTL] & 0x98) == 0x98) { // Hyper voice
252+ v = Page[IO[SDMASH] + b][*(WORD*)(IO + SDMASL) + index++];
253+ if ((*(WORD*)(IO + SDMASL) + index) == 0)
254+ {
255+ b++;
256+ }
257+ if (v < 0x80)
258+ {
259+ v += 0x80;
260+ }
261+ else
262+ {
263+ v -= 0x80;
264+ }
265+ if (*(WORD*)(IO+SDMACNT) <= index)
266+ {
267+ index = 0;
268+ b = 0;
269+ }
270+ return v;
271+ }
272+ else if ((IO[SDMACTL] & 0x88) == 0x80) { // DMA start
273+ IO[SND2VOL] = Page[IO[SDMASH] + b][*(WORD*)(IO + SDMASL) + index++];
274+ if ((*(WORD*)(IO + SDMASL) + index) == 0)
275+ {
276+ b++;
277+ }
278+ if (*(WORD*)(IO + SDMACNT) <= index)
279+ {
280+ IO[SDMACTL] &= 0x7F; // DMA end
281+ *(WORD*)(IO + SDMACNT) = 0;
282+ index = 0;
283+ b = 0;
284+ }
285+ }
286+ return ((VoiceOn && Sound[4]) ? IO[SND2VOL] : 0x80);
287+}
288+
289+void apuSweep(void)
290+{
291+ if ((Swp.step) && Swp.on) // sweep on
292+ {
293+ if (Swp.cnt < 0)
294+ {
295+ Swp.cnt = Swp.time;
296+ Ch[2].freq += Swp.step;
297+ Ch[2].freq &= 0x7ff;
298+ }
299+ Swp.cnt--;
300+ }
301+}
302+
303+WORD apuShiftReg(void)
304+{
305+ static int nPos = 0;
306+ // Noise counter
307+ if (++nPos >= BUFSIZEN)
308+ {
309+ nPos = 0;
310+ }
311+ return RandData[nPos];
312+}
313+
314+void apuWaveSet(void)
315+{
316+ static int point[] = {0, 0, 0, 0};
317+ static int preindex[] = {0, 0, 0, 0};
318+ int channel, index;
319+ short value, lVol[4], rVol[4];
320+ short LL, RR, vVol;
321+ static int wait = 0;
322+ short *dataAdr;
323+
324+ if (WsInputGetNowait())
325+ {
326+ wait = 1;
327+ }
328+ else if (wait)
329+ {
330+ wait = 0;
331+ apuWaveClear();
332+ }
333+ apuSweep();
334+ for (channel = 0; channel < 4; channel++)
335+ {
336+ lVol[channel] = 0;
337+ rVol[channel] = 0;
338+ if (Ch[channel].on)
339+ {
340+ if (channel == 1 && VoiceOn && Sound[4])
341+ {
342+ continue;
343+ }
344+ else if (channel == 2 && Swp.on && !Sound[5])
345+ {
346+ continue;
347+ }
348+ else if (channel == 3 && Noise.on && Sound[6])
349+ {
350+ index = (3072000 / BPSWAV) * point[3] / (2048 - Ch[3].freq);
351+ if ((index %= BUFSIZEN) == 0 && preindex[3])
352+ {
353+ point[3] = 0;
354+ }
355+ value = (short)PDataN[Noise.pattern][index] - 8;
356+ }
357+ else if (Sound[channel] == 0)
358+ {
359+ continue;
360+ }
361+ else {
362+ index = (3072000 / BPSWAV) * point[channel] / (2048 - Ch[channel].freq);
363+ if ((index %= 32) == 0 && preindex[channel])
364+ {
365+ point[channel] = 0;
366+ }
367+ value = (short)PData[channel][index] - 8;
368+ }
369+ preindex[channel] = index;
370+ point[channel]++;
371+ lVol[channel] = value * Ch[channel].volL; // -8*15=-120, 7*15=105
372+ rVol[channel] = value * Ch[channel].volR;
373+ }
374+ }
375+ vVol = ((short)apuVoice() - 0x80);
376+ // mix 16bits wave -32768 ~ +32767 32768/120 = 273
377+ LL = (lVol[0] + lVol[1] + lVol[2] + lVol[3] + vVol) * WsWaveVol;
378+ RR = (rVol[0] + rVol[1] + rVol[2] + rVol[3] + vVol) * WsWaveVol;
379+ dataAdr = (short*)(whdr[wBuf]->lpData);
380+ dataAdr[wPos * 2] = LL;
381+ dataAdr[wPos * 2 + 1] = RR;
382+ if (++wPos >= BUFSIZEW)
383+ {
384+ waveOutWrite(hWaveOut, whdr[wBuf], sizeof(WAVEHDR));
385+ wPos = 0;
386+ if (++wBuf >= BUFCOUNT)
387+ {
388+ wBuf = 0;
389+ }
390+ if (wait == 0)
391+ {
392+ while (wBuf == rBuf) // 書き込みが再生に追いついた
393+ {
394+ Sleep(1); // WaveOutのコールバック関数でrBufが更新されるまで待つ
395+ }
396+ }
397+ }
398+}
399+
400+/*
401+PlaySound()は音量調節が出来ないのでいったんメモリに読み込んで
402+プレイ時にデータを加工する
403+*/
404+static void* SSMasterBuf;
405+static void* SSPlayBuf;
406+static DWORD SSDataLen, SSHeadLen;
407+
408+void apuLoadSound(void)
409+{
410+ HINSTANCE hInst;
411+ HRSRC hRsrc;
412+ HGLOBAL hG;
413+ BYTE* wave;
414+ BYTE* tmp;
415+ DWORD wfesize;
416+
417+ hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
418+ hRsrc = FindResource(hInst, MAKEINTRESOURCE(IDR_WAVE1), TEXT("WAVE"));
419+ hG = LoadResource(hInst, hRsrc);
420+ wave = (BYTE*)LockResource(hG); //RIFFヘッダの確認
421+ tmp = wave;
422+ if (*(LPDWORD)wave != *(LPDWORD)"RIFF")
423+ {
424+ ErrorMsg(ERR_WAVERESOURCE);
425+ return;
426+ }
427+ wave += 4; //ポインタは次を指しておく
428+ wave += 4; //ポインタは次を指しておく
429+ //WAVEヘッダの確認
430+ if (*(LPDWORD)wave != *(LPDWORD)"WAVE")
431+ {
432+ ErrorMsg(ERR_WAVERESOURCE);
433+ return;
434+ }
435+ wave += 4; //ポインタは次を指しておく
436+ //fmtチャンクの確認
437+ if (*(LPDWORD)wave != *(LPDWORD)"fmt ")
438+ {
439+ ErrorMsg(ERR_WAVERESOURCE);
440+ return;
441+ }
442+ wave += 4; //ポインタは次を指しておく
443+ //fmtチャンクサイズの取得
444+ wfesize = *(DWORD *)wave;
445+ wave += 4; //ポインタは次を指しておく
446+ wave += wfesize; //WAVEFORMATEX構造体分だけポインタを進めておく
447+ //dataチャンクの確認
448+ if (*(LPDWORD)wave != *(LPDWORD)"data")
449+ {
450+ ErrorMsg(ERR_WAVERESOURCE);
451+ return;
452+ }
453+ wave += 4; //ポインタは次を指しておく
454+ //波形データのバイト数の取得
455+ SSDataLen = *(DWORD *)wave;
456+ wave += 4; //ポインタは次を指しておく
457+ SSHeadLen = wave - tmp;
458+ SSMasterBuf = malloc(SSDataLen);
459+ SSPlayBuf = malloc(SSHeadLen + SSDataLen);
460+ if (SSMasterBuf != NULL && SSPlayBuf != NULL)
461+ {
462+ memcpy(SSMasterBuf, wave, SSDataLen);
463+ memcpy(SSPlayBuf, tmp, SSHeadLen);
464+ }
465+ FreeResource(hG);
466+}
467+
468+void apuDestroySound(void)
469+{
470+ free(SSMasterBuf);
471+ SSMasterBuf = NULL;
472+ free(SSPlayBuf);
473+ SSPlayBuf = NULL;
474+}
475+
476+void apuStartupSound(void)
477+{
478+ short *src, *dst;
479+ int i;
480+ int size = SSDataLen / sizeof(short);
481+
482+ if (SSMasterBuf == NULL || SSPlayBuf == NULL)
483+ {
484+ return;
485+ }
486+ src = (short*)SSMasterBuf;
487+ dst = (short*)((BYTE*)SSPlayBuf + SSHeadLen);
488+ // マスターの音量を変更してプレイバッファーにコピー
489+ for (i = 0; i < size; i++)
490+ {
491+ *dst++ = (*src++) * WsWaveVol / 32;
492+ }
493+ PlaySound((LPCTSTR)SSPlayBuf, NULL, SND_MEMORY | SND_ASYNC);
494+}
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSError.c (nonexistent)
+++ oswanj/trunk/src/WSError.c (revision 102)
@@ -0,0 +1,17 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include <windows.h>
7+#include <tchar.h>
8+#include "WSError.h"
9+
10+void ErrorMsg(long err)
11+{
12+ TCHAR dst[512];
13+
14+ _stprintf_s(dst, 512, TEXT("%lX"), err);
15+ MessageBox(NULL, dst, TEXT("WS エラー"), MB_OK);
16+}
17+
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSDraw.c (nonexistent)
+++ oswanj/trunk/src/WSDraw.c (revision 102)
@@ -0,0 +1,370 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include "WSDraw.h"
7+#include "WS.h"
8+#include "WSInput.h"
9+#include "WSRender.h"
10+
11+extern HWND hWnd;
12+int Kerorikan = 0;
13+static enum DRAWSIZE DrawSize = DS_1; // 描画サイズ フルスクリーン、x1 x2 x3
14+static int DrawMode = 0; // 縦横フラグ 0:横
15+static LPDIRECT3D9 pD3D; // IDirect3D9インターフェイスへのポインタ
16+static LPDIRECT3DDEVICE9 pD3DDevice; // IDirect3DDevice9インターフェイスへのポインタ
17+static D3DPRESENT_PARAMETERS D3DPP; // デバイスのプレゼンテーションパラメータ
18+static LPDIRECT3DVERTEXBUFFER9 pMyVB; // Vertex Buffer
19+static LPDIRECT3DTEXTURE9 pTexture; // Texture
20+static LPDIRECT3DSURFACE9 pSurface; // Surface
21+static LPDIRECT3DTEXTURE9 pSegTexture;
22+static LPDIRECT3DSURFACE9 pSegSurface;
23+
24+// 頂点1つのデータ型
25+typedef struct {
26+ D3DVECTOR p; // 位置
27+ DWORD color; // 色
28+ D3DXVECTOR2 t; // テクスチャーの画像の位置
29+} MY_VERTEX;
30+// MY_VERTEXのフォーマット設定
31+#define MY_VERTEX_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)
32+#define SAFE_RELEASE(p) { if(p) { IDirect3D9_Release(p); (p)=NULL; } }
33+
34+//-------------------------------------------------------------
35+// レンダラーの初期化
36+// 引数
37+// isFullScreen : フルスクリーンの場合TRUE
38+// 戻り値
39+// 成功したらS_OK
40+//-------------------------------------------------------------
41+HRESULT drawInitialize(BOOL isFullScreen)
42+{
43+ D3DDISPLAYMODE d3ddm;
44+
45+ // Direct3D9オブジェクトの作成
46+ if((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
47+ {
48+ return E_FAIL; // 取得失敗
49+ }
50+ // 現在のディスプレイモードを取得
51+ if(FAILED(IDirect3D9_GetAdapterDisplayMode(pD3D, D3DADAPTER_DEFAULT, &d3ddm)))
52+ {
53+ return E_FAIL;
54+ }
55+ // デバイスのプレゼンテーションパラメータを初期化
56+ ZeroMemory(&D3DPP, sizeof(D3DPRESENT_PARAMETERS));
57+ if(isFullScreen) { // フルスクリーンの場合
58+ D3DPP.Windowed = FALSE; // フルスクリーン表示の指定
59+ D3DPP.BackBufferWidth = 800; // フルスクリーン時の横幅
60+ D3DPP.BackBufferHeight = 600; // フルスクリーン時の縦幅
61+ }
62+ else {
63+ D3DPP.Windowed = TRUE; // ウインドウ内表示の指定
64+ D3DPP.BackBufferWidth = 2016; // 224と144の最小公倍数
65+ D3DPP.BackBufferHeight = 2016;
66+ }
67+ D3DPP.BackBufferCount = 1;
68+ D3DPP.BackBufferFormat = d3ddm.Format; // カラーモードの指定
69+ D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; //
70+ D3DPP.EnableAutoDepthStencil = TRUE; // エラー対策
71+ D3DPP.AutoDepthStencilFormat = D3DFMT_D16; // エラー対策
72+ D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // 垂直同期しない
73+ // ディスプレイアダプタを表すためのデバイスを作成
74+ // 描画と頂点処理をハードウェアで行なう
75+ if(FAILED(IDirect3D9_CreateDevice(pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &D3DPP, &pD3DDevice)))
76+ {
77+ // 上記の設定が失敗したら
78+ // 描画をハードウェアで行い、頂点処理はCPUで行なう
79+ if(FAILED(IDirect3D9_CreateDevice(pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DPP, &pD3DDevice)))
80+ {
81+ // 初期化失敗
82+ MessageBox(hWnd, TEXT(" グラフィックチップが未対応です "), TEXT("Direct3D Error"), MB_OK);
83+ return E_FAIL;
84+ }
85+ }
86+ return S_OK;
87+}
88+
89+//-------------------------------------------------------------
90+// 終了処理
91+//-------------------------------------------------------------
92+void drawFinalize(void)
93+{
94+ // デバイスオブジェクトの解放
95+ SAFE_RELEASE(pD3DDevice);
96+ // DirectXGraphicsの解放
97+ SAFE_RELEASE(pD3D);
98+}
99+
100+//-------------------------------------------------------------
101+// シーンを生成
102+// 戻り値
103+// 成功したらS_OK
104+//-------------------------------------------------------------
105+HRESULT drawCreate(void)
106+{
107+ if(pD3DDevice == 0)
108+ {
109+ return E_FAIL;
110+ }
111+ drawDestroy();
112+ //--------------------------------------
113+ // オブジェクトの頂点バッファを生成
114+ //--------------------------------------
115+ // 8つの頂点からなる頂点バッファを作る(メイン4個 セグメント4個)
116+ if(FAILED(IDirect3DDevice9_CreateVertexBuffer(pD3DDevice, 8 * sizeof(MY_VERTEX), D3DUSAGE_WRITEONLY, MY_VERTEX_FVF, D3DPOOL_MANAGED, &pMyVB, NULL)))
117+ {
118+ return E_FAIL;
119+ }
120+ IDirect3DDevice9_CreateTexture(pD3DDevice, 256, 256, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &pTexture, NULL);
121+ IDirect3DTexture9_GetSurfaceLevel(pTexture, 0, &pSurface);
122+ IDirect3DDevice9_CreateTexture(pD3DDevice, 32, 1024, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &pSegTexture, NULL);
123+ IDirect3DTexture9_GetSurfaceLevel(pSegTexture, 0, &pSegSurface);
124+ //--------------------------------------
125+ // テクスチャステージの設定
126+ //--------------------------------------
127+ IDirect3DDevice9_SetTextureStageState(pD3DDevice, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
128+ IDirect3DDevice9_SetTextureStageState(pD3DDevice, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
129+ //--------------------------------------
130+ // レンダリングステートパラメータの設定
131+ //--------------------------------------
132+ // 両面描画モードの指定
133+ IDirect3DDevice9_SetRenderState(pD3DDevice, D3DRS_CULLMODE, D3DCULL_NONE);
134+ // ディザリングを行なう(高品質描画)
135+ IDirect3DDevice9_SetRenderState(pD3DDevice, D3DRS_DITHERENABLE, TRUE);
136+ // ノーライティングモード
137+ IDirect3DDevice9_SetRenderState(pD3DDevice, D3DRS_LIGHTING, FALSE);
138+ return S_OK;
139+}
140+
141+//-------------------------------------------------------------
142+// シーンの破棄
143+//-------------------------------------------------------------
144+void drawDestroy(void)
145+{
146+ SAFE_RELEASE(pSurface);
147+ SAFE_RELEASE(pTexture);
148+ SAFE_RELEASE(pSegSurface);
149+ SAFE_RELEASE(pSegTexture);
150+ SAFE_RELEASE(pMyVB);
151+}
152+
153+//-------------------------------------------------------------
154+// 描画処理
155+//-------------------------------------------------------------
156+#define MAIN_X (224.0f/256.0f)
157+#define MAIN_Y (144.0f/256.0f)
158+#define MAIN_W (2 * 224.0f/234.0f - 1.0f)
159+#define SEG_X (4 * 8.0f/32.0f)
160+#define SEG_Y (4 * 144.0f/1024.0f)
161+#define SEG_W (1.0f - 2 * 8.0f/234.0f)
162+#define KERO 0.0075f
163+void drawDraw()
164+{
165+ D3DLOCKED_RECT lockRect;
166+ int x, y, pitch;
167+ WORD *p;
168+ MY_VERTEX* v;
169+ D3DXMATRIX mat;
170+ D3DXMatrixIdentity(&mat);
171+
172+ if(pD3DDevice == 0)
173+ {
174+ return;
175+ }
176+ if(pMyVB == 0)
177+ {
178+ return;
179+ }
180+ // 画像データをテクスチャに転送
181+ IDirect3DSurface9_LockRect(pSurface, &lockRect, NULL, D3DLOCK_DISCARD);
182+ p = FrameBuffer[0] + 8;
183+ pitch = lockRect.Pitch / 2;
184+ for (y = 0; y < 144; y++)
185+ {
186+ for (x = 0; x < 224; x++)
187+ {
188+ *((WORD*)lockRect.pBits + pitch * y + x) = *p++;
189+ }
190+ p += 32;
191+ }
192+ IDirect3DSurface9_UnlockRect(pSurface);
193+ // 液晶セグメントデータをテクスチャに転送
194+ RenderSegment();
195+ IDirect3DSurface9_LockRect(pSegSurface, &lockRect, NULL, D3DLOCK_DISCARD);
196+ p = SegmentBuffer;
197+ pitch = lockRect.Pitch / 2;
198+ for (y = 0; y < 144 * 4; y++)
199+ {
200+ for (x = 0; x < 32; x++)
201+ {
202+ *((WORD*)lockRect.pBits + pitch * y + x) = *p++;
203+ }
204+ }
205+ IDirect3DSurface9_UnlockRect(pSegSurface);
206+ //頂点バッファの中身を埋める
207+ IDirect3DVertexBuffer9_Lock( pMyVB, 0, 0, (void**)&v, 0 );
208+ if (Kerorikan)
209+ {
210+ // 頂点座標の設定
211+ D3DVECTOR p[8] = {
212+ -112*KERO, 72*KERO, 0.0f,
213+ 112*KERO, 72*KERO, 0.0f,
214+ -112*KERO, -72*KERO, 0.0f,
215+ 112*KERO, -72*KERO, 0.0f,
216+ 114*KERO, 72*KERO, 0.0f,
217+ 122*KERO, 72*KERO, 0.0f,
218+ 114*KERO, -72*KERO, 0.0f,
219+ 122*KERO, -72*KERO, 0.0f
220+ };
221+ v[0].p = p[0];
222+ v[1].p = p[1];
223+ v[2].p = p[2];
224+ v[3].p = p[3];
225+ v[4].p = p[4];
226+ v[5].p = p[5];
227+ v[6].p = p[6];
228+ v[7].p = p[7];
229+ }
230+ else
231+ {
232+ // 頂点座標の設定
233+ D3DVECTOR p[8] = {
234+ -1.0f, 1.0f, 0.0f,
235+ MAIN_W, 1.0f, 0.0f,
236+ -1.0f, -1.0f, 0.0f,
237+ MAIN_W,-1.0f, 0.0f,
238+ SEG_W, 1.0f, 0.0f,
239+ 1.0f, 1.0f, 0.0f,
240+ SEG_W, -1.0f, 0.0f,
241+ 1.0f, -1.0f, 0.0f
242+ };
243+ v[0].p = p[0];
244+ v[1].p = p[1];
245+ v[2].p = p[2];
246+ v[3].p = p[3];
247+ v[4].p = p[4];
248+ v[5].p = p[5];
249+ v[6].p = p[6];
250+ v[7].p = p[7];
251+ }
252+ {
253+ // テクスチャ座標の設定
254+ D3DXVECTOR2 t[8] = {
255+ 0.0f, 0.0f,
256+ MAIN_X, 0.0f,
257+ 0.0f, MAIN_Y,
258+ MAIN_X, MAIN_Y,
259+ 0.0f, 0.0f,
260+ SEG_X, 0.0f,
261+ 0.0f, SEG_Y,
262+ SEG_X, SEG_Y
263+ };
264+ v[0].t = t[0];
265+ v[1].t = t[1];
266+ v[2].t = t[2];
267+ v[3].t = t[3];
268+ v[4].t = t[4];
269+ v[5].t = t[5];
270+ v[6].t = t[6];
271+ v[7].t = t[7];
272+ }
273+ {
274+ // 頂点カラーの設定
275+ v[0].color = v[1].color = v[2].color = v[3].color = 0xFFFFFFFFU;
276+ v[4].color = v[5].color = v[6].color = v[7].color = 0xFFFFFFFFU;
277+ }
278+ IDirect3DVertexBuffer9_Unlock(pMyVB);
279+ // 回転処理
280+ // 斜め(左atan(0.5)回転)
281+ if (Kerorikan)
282+ {
283+ D3DXMatrixRotationZ(&mat, 0.4636476f); // atanf(0.5f)だと最適化されないかもしれないので
284+ }
285+ // 縦(左90度回転)
286+ else if (DrawMode & 0x01)
287+ {
288+ D3DXMatrixRotationZ(&mat, D3DXToRadian(90));
289+ }
290+ // 描画開始宣言
291+ if(SUCCEEDED(IDirect3DDevice9_BeginScene(pD3DDevice)))
292+ {
293+ IDirect3DDevice9_Clear(pD3DDevice, 0, NULL, D3DCLEAR_TARGET, 0xFF666666, 0.0f, 0);
294+ IDirect3DDevice9_SetStreamSource(pD3DDevice, 0, pMyVB, 0, sizeof(MY_VERTEX));
295+ IDirect3DDevice9_SetFVF(pD3DDevice, MY_VERTEX_FVF);
296+ IDirect3DDevice9_SetTexture(pD3DDevice, 0, (IDirect3DBaseTexture9 *)pTexture);
297+ IDirect3DDevice9_DrawPrimitive(pD3DDevice, D3DPT_TRIANGLESTRIP, 0, 2); // 0番の頂点から三角形を2個
298+ IDirect3DDevice9_SetTexture(pD3DDevice, 0, (IDirect3DBaseTexture9 *)pSegTexture);
299+ IDirect3DDevice9_DrawPrimitive(pD3DDevice, D3DPT_TRIANGLESTRIP, 4, 2); // 4番の頂点から三角形を2個
300+ IDirect3DDevice9_SetTransform(pD3DDevice, D3DTS_VIEW, &mat);
301+ // 描画終了宣言
302+ IDirect3DDevice9_EndScene(pD3DDevice);
303+ }
304+ // 描画結果の転送
305+ if(FAILED(IDirect3DDevice9_Present(pD3DDevice, NULL, NULL, NULL, NULL)))
306+ {
307+ // デバイス消失から復帰
308+ IDirect3DDevice9_Reset(pD3DDevice, &D3DPP);
309+ }
310+}
311+
312+//-------------------------------------------------------------
313+void WsResize(void)
314+{
315+ RECT wind;
316+ RECT wind2;
317+ int lcdHeight = 144;
318+ int lcdWidth = 224 + 10; // +10はセグメント分
319+ int client_width;
320+ int client_height;
321+
322+ if (Kerorikan)
323+ {
324+ client_width = 256 * DrawSize;
325+ client_height = 256 * DrawSize;
326+ }
327+ else if (DrawMode & 0x01)
328+ {
329+ client_width = lcdHeight * DrawSize;
330+ client_height = lcdWidth * DrawSize;
331+ }
332+ else
333+ {
334+ client_width = lcdWidth * DrawSize;
335+ client_height = lcdHeight * DrawSize;
336+ }
337+ wind.top = 0;
338+ wind.left = 0;
339+ wind.right = client_width;
340+ wind.bottom = client_height;
341+ AdjustWindowRectEx(&wind, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
342+ TRUE, WS_EX_APPWINDOW | WS_EX_ACCEPTFILES);
343+ wind2 = wind;
344+ SendMessage(hWnd, WM_NCCALCSIZE, FALSE, (LPARAM) &wind2);
345+ SetWindowPos(hWnd, NULL, 0, 0,
346+ (wind.right - wind.left) + client_width - (wind2.right - wind2.left),
347+ (wind.bottom - wind.top ) + client_height - (wind2.bottom - wind2.top ),
348+ SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW);
349+}
350+
351+//-------------------------------------------------------------
352+int SetDrawMode(int Mode)
353+{
354+ if(DrawMode != Mode)
355+ {
356+ DrawMode = Mode;
357+ WsInputSetKeyMap(Mode);
358+ WsResize();
359+ }
360+ return 0;
361+}
362+
363+//-------------------------------------------------------------
364+int SetDrawSize(enum DRAWSIZE Size)
365+{
366+ DrawSize = Size;
367+ WsResize();
368+ return 0;
369+}
370+
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSInput.c (nonexistent)
+++ oswanj/trunk/src/WSInput.c (revision 102)
@@ -0,0 +1,305 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include "WSInput.h"
7+
8+int WsKeyboardH[13];
9+int WsKeyboardV[13];
10+int WsJoypadH[13];
11+int WsJoypadV[13];
12+LPDIRECTINPUTDEVICE8 lpKeyDevice;
13+LPDIRECTINPUTDEVICE8 lpJoyDevice;
14+static int* WsJoypad;
15+static int* WsKeyboard;
16+static LPDIRECTINPUT8 lpDInput;
17+static DIJOYSTATE2 js;
18+
19+BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* lpddi, LPVOID lpContext)
20+{
21+ HRESULT hRet;
22+
23+ hRet = IDirectInput8_CreateDevice(lpDInput, &(lpddi->guidInstance), &lpJoyDevice, NULL);
24+ if(FAILED(hRet)) return DIENUM_CONTINUE;
25+
26+ return DIENUM_STOP;
27+}
28+
29+int WsInputJoyInit(HWND hw)
30+{
31+ HRESULT hRet;
32+ if (lpJoyDevice != NULL)
33+ return TRUE;
34+
35+ hRet = IDirectInput8_EnumDevices(lpDInput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY);
36+ if (hRet != DI_OK){
37+ if (lpJoyDevice != NULL)
38+ {
39+ IDirectInputDevice8_Release(lpJoyDevice);
40+ lpJoyDevice = NULL;
41+ }
42+ return FALSE;
43+ }
44+ if (lpJoyDevice == NULL)
45+ {
46+ return FALSE;
47+ }
48+ hRet = IDirectInputDevice8_SetDataFormat(lpJoyDevice, &c_dfDIJoystick2);
49+ if (hRet != DI_OK){
50+ if (lpJoyDevice != NULL)
51+ {
52+ IDirectInputDevice8_Release(lpJoyDevice);
53+ lpJoyDevice = NULL;
54+ }
55+ return FALSE;
56+ }
57+ hRet = IDirectInputDevice8_SetCooperativeLevel(lpJoyDevice, hw, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
58+ if (hRet != DI_OK){
59+ if (lpJoyDevice != NULL)
60+ {
61+ IDirectInputDevice8_Release(lpJoyDevice);
62+ lpJoyDevice = NULL;
63+ }
64+ return FALSE;
65+ }
66+ IDirectInputDevice8_Acquire(lpJoyDevice);
67+
68+ return TRUE;
69+}
70+
71+int WsInputInit(HWND hw)
72+{
73+ DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8, (LPVOID*)&lpDInput, NULL);
74+ IDirectInput8_CreateDevice(lpDInput, &GUID_SysKeyboard, &lpKeyDevice, NULL);
75+ IDirectInputDevice8_SetDataFormat(lpKeyDevice, &c_dfDIKeyboard);
76+ IDirectInputDevice8_SetCooperativeLevel(lpKeyDevice, hw, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
77+ return WsInputJoyInit(hw);
78+}
79+
80+void WsInputJoyRelease(void)
81+{
82+ if (lpJoyDevice != NULL)
83+ {
84+ IDirectInputDevice8_Unacquire(lpJoyDevice);
85+ IDirectInputDevice8_Release(lpJoyDevice);
86+ lpJoyDevice = NULL;
87+ }
88+}
89+
90+void WsInputRelease(void)
91+{
92+ if (lpKeyDevice != NULL)
93+ {
94+ IDirectInputDevice8_Unacquire(lpKeyDevice);
95+ IDirectInputDevice8_Release(lpKeyDevice);
96+ lpKeyDevice = NULL;
97+ }
98+ if (lpDInput != NULL)
99+ {
100+ IDirectInput8_Release(lpDInput);
101+ lpDInput = NULL;
102+ }
103+ WsInputJoyRelease();
104+}
105+
106+#define HALFRECT JOY_POVRIGHT / 2
107+int WsInputCheckJoy(int value)
108+{
109+ int i;
110+
111+ if ((value >= 1) && (value <= 128))
112+ {
113+ return((js.rgbButtons[value - 1] & 0x80) ? 1 : 0);
114+ }
115+ if ((value & 0x1100) == 0x100)
116+ {
117+ i = (value & 0x30) >> 4;
118+ switch (value & 0x0F)
119+ {
120+ case 1:
121+ if (js.rgdwPOV[i] == JOY_POVLEFT + HALFRECT) return 1;
122+ if (js.rgdwPOV[i] == JOY_POVFORWARD) return 1;
123+ if (js.rgdwPOV[i] == JOY_POVFORWARD + HALFRECT) return 1;
124+ break;
125+ case 2:
126+ if (js.rgdwPOV[i] == JOY_POVFORWARD + HALFRECT) return 1;
127+ if (js.rgdwPOV[i] == JOY_POVRIGHT) return 1;
128+ if (js.rgdwPOV[i] == JOY_POVRIGHT + HALFRECT) return 1;
129+ break;
130+ case 4:
131+ if (js.rgdwPOV[i] == JOY_POVRIGHT + HALFRECT) return 1;
132+ if (js.rgdwPOV[i] == JOY_POVBACKWARD) return 1;
133+ if (js.rgdwPOV[i] == JOY_POVBACKWARD + HALFRECT) return 1;
134+ break;
135+ case 8:
136+ if (js.rgdwPOV[i] == JOY_POVBACKWARD + HALFRECT) return 1;
137+ if (js.rgdwPOV[i] == JOY_POVLEFT) return 1;
138+ if (js.rgdwPOV[i] == JOY_POVLEFT + HALFRECT) return 1;
139+ break;
140+ }
141+ return 0;
142+ }
143+ switch (value)
144+ {
145+ case WS_JOY_AXIS_X_P:
146+ if (js.lX > 0xC000) return 1;
147+ break;
148+ case WS_JOY_AXIS_X_M:
149+ if (js.lX < 0x4000) return 1;
150+ break;
151+ case WS_JOY_AXIS_Y_P:
152+ if (js.lY > 0xC000) return 1;
153+ break;
154+ case WS_JOY_AXIS_Y_M:
155+ if (js.lY < 0x4000) return 1;
156+ break;
157+ case WS_JOY_AXIS_Z_P:
158+ if (js.lZ > 0xC000) return 1;
159+ break;
160+ case WS_JOY_AXIS_Z_M:
161+ if (js.lZ < 0x4000) return 1;
162+ break;
163+ case WS_JOY_AXIS_RX_P:
164+ if (js.lRx > 0xC000) return 1;
165+ break;
166+ case WS_JOY_AXIS_RX_M:
167+ if (js.lRx < 0x4000) return 1;
168+ break;
169+ case WS_JOY_AXIS_RY_P:
170+ if (js.lRy > 0xC000) return 1;
171+ break;
172+ case WS_JOY_AXIS_RY_M:
173+ if (js.lRy < 0x4000) return 1;
174+ break;
175+ case WS_JOY_AXIS_RZ_P:
176+ if (js.lRz > 0xC000) return 1;
177+ break;
178+ case WS_JOY_AXIS_RZ_M:
179+ if (js.lRz < 0x4000) return 1;
180+ break;
181+ case WS_JOY_SLIDER1_P:
182+ if (js.rglSlider[0] > 0xC000) return 1;
183+ break;
184+ case WS_JOY_SLIDER1_M:
185+ if (js.rglSlider[0] < 0x4000) return 1;
186+ break;
187+ case WS_JOY_SLIDER2_P:
188+ if (js.rglSlider[1] > 0xC000) return 1;
189+ break;
190+ case WS_JOY_SLIDER2_M:
191+ if (js.rglSlider[1] < 0x4000) return 1;
192+ break;
193+ }
194+ return 0;
195+}
196+
197+WORD WsInputGetState(void)
198+{
199+ int i;
200+ HRESULT hRet;
201+ BYTE diKeys[256];
202+ WORD JoyState = 0;
203+ WORD KeyState = 0;
204+
205+ ZeroMemory(&js, sizeof(DIJOYSTATE2));
206+ ZeroMemory(diKeys, 256);
207+ if (lpKeyDevice != NULL)
208+ {
209+ hRet = IDirectInputDevice8_Acquire(lpKeyDevice);
210+ if (hRet == DI_OK || hRet == S_FALSE)
211+ {
212+ hRet = IDirectInputDevice8_GetDeviceState(lpKeyDevice, 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+ }
226+ if (lpJoyDevice != NULL)
227+ {
228+ hRet = IDirectInputDevice8_Poll(lpJoyDevice);
229+ if (FAILED(hRet))
230+ {
231+ hRet = IDirectInputDevice8_Acquire(lpJoyDevice);
232+ while (hRet == DIERR_INPUTLOST)
233+ {
234+ hRet = IDirectInputDevice8_Acquire(lpJoyDevice);
235+ }
236+ return KeyState;
237+ }
238+ hRet = IDirectInputDevice8_GetDeviceState(lpJoyDevice, sizeof(DIJOYSTATE2), &js);
239+ if (hRet == DI_OK){
240+ for (i = 0; i < 12; i++)
241+ {
242+ JoyState <<= 1;
243+ JoyState |= WsInputCheckJoy(WsJoypad[i]);
244+ }
245+ }
246+ }
247+ return JoyState | KeyState;
248+}
249+
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+ HRESULT hRet;
267+ BYTE diKeys[256];
268+ int flag = 0;
269+
270+ ZeroMemory(&js, sizeof(DIJOYSTATE2));
271+ ZeroMemory(diKeys, 256);
272+ if (lpKeyDevice != NULL)
273+ {
274+ hRet = IDirectInputDevice8_Acquire(lpKeyDevice);
275+ if (hRet == DI_OK || hRet == S_FALSE)
276+ {
277+ hRet = IDirectInputDevice8_GetDeviceState(lpKeyDevice, 256, diKeys);
278+ if (hRet == DI_OK)
279+ {
280+ if (diKeys[WsKeyboard[12]] & 0x80)
281+ {
282+ flag = 1;
283+ }
284+ }
285+ }
286+ }
287+ if (lpJoyDevice != NULL)
288+ {
289+ hRet = IDirectInputDevice8_Poll(lpJoyDevice);
290+ if (FAILED(hRet))
291+ {
292+ hRet = IDirectInputDevice8_Acquire(lpJoyDevice);
293+ while (hRet == DIERR_INPUTLOST)
294+ {
295+ hRet = IDirectInputDevice8_Acquire(lpJoyDevice);
296+ }
297+ return flag;
298+ }
299+ hRet = IDirectInputDevice8_GetDeviceState(lpJoyDevice, sizeof(DIJOYSTATE2), &js);
300+ if (hRet == DI_OK){
301+ flag |= WsInputCheckJoy(WsJoypad[12]);
302+ }
303+ }
304+ return flag;
305+}
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSDialog.c (nonexistent)
+++ oswanj/trunk/src/WSDialog.c (revision 102)
@@ -0,0 +1,614 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include "../resource.h"
7+#include "WSDialog.h"
8+#include <commctrl.h>
9+#include <tchar.h>
10+#include "WSInput.h"
11+#include "keycode.h"
12+
13+static WNDPROC OrgEditProc;
14+static HWND hTabCtrl, hTab1, hTab2, hTab3, hTab4;
15+static int TmpKeyboardH[13];
16+static int TmpKeyboardV[13];
17+static int TmpJoypadH[13];
18+static int TmpJoypadV[13];
19+static int SelectedTab;
20+
21+void WsDlgConfInit(HWND hDlg)
22+{
23+ HINSTANCE hInst;
24+ TC_ITEM tc;
25+ RECT rt;
26+ LPPOINT pt = (LPPOINT)&rt;
27+
28+ memcpy(TmpKeyboardH, WsKeyboardH, sizeof(int) * 13);
29+ memcpy(TmpKeyboardV, WsKeyboardV, sizeof(int) * 13);
30+ memcpy(TmpJoypadH, WsJoypadH, sizeof(int) * 13);
31+ memcpy(TmpJoypadV, WsJoypadV, sizeof(int) * 13);
32+ hInst = (HINSTANCE)GetWindowLong(hDlg, GWLP_HINSTANCE);
33+ hTabCtrl = GetDlgItem(hDlg, IDC_TAB1);
34+ // タブコントロールにタブシートを挿入
35+ tc.mask = TCIF_TEXT;
36+ tc.pszText = TEXT("キー横");
37+ TabCtrl_InsertItem(hTabCtrl , 0, &tc);
38+ tc.mask = TCIF_TEXT;
39+ tc.pszText = TEXT("キー縦");
40+ TabCtrl_InsertItem(hTabCtrl , 1, &tc);
41+ tc.mask = TCIF_TEXT;
42+ tc.pszText = TEXT("コントローラー横");
43+ TabCtrl_InsertItem(hTabCtrl , 2, &tc);
44+ tc.mask = TCIF_TEXT;
45+ tc.pszText = TEXT("コントローラー縦");
46+ TabCtrl_InsertItem(hTabCtrl , 3, &tc);
47+ // タブに貼り付けるダイアログを生成
48+ hTab1 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB1, hDlg, (DLGPROC)TabProc1);
49+ hTab2 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB2, hDlg, (DLGPROC)TabProc2);
50+ hTab3 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB1, hDlg, (DLGPROC)TabProc3);
51+ hTab4 = CreateDialog(hInst, (LPCTSTR)IDD_CONFIG_TAB2, hDlg, (DLGPROC)TabProc4);
52+ // タブコントロールのクライアント領域の座標を取得
53+ GetClientRect(hTabCtrl, &rt);
54+ TabCtrl_AdjustRect(hTabCtrl, FALSE, &rt);
55+ // 親ウィンドウがhDlgなのでタブのマップが必要
56+ MapWindowPoints(hTabCtrl, hDlg, pt, 2);
57+ // タブのウィンドウの位置とサイズを変更する
58+ MoveWindow(hTab1, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
59+ MoveWindow(hTab2, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
60+ MoveWindow(hTab3, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
61+ MoveWindow(hTab4, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, FALSE);
62+ // デフォルトでタブ1を表示
63+ ShowWindow(hTab1, SW_SHOW);
64+ SetFocus(GetDlgItem(hTab1, IDC_EDIT_Y1));
65+ SendMessage(GetDlgItem(hTab1, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
66+ IDirectInputDevice8_Acquire(lpKeyDevice);
67+}
68+
69+LRESULT CALLBACK ConfProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
70+{
71+ NMHDR *nm = (NMHDR *)lParam;
72+
73+ switch (msg)
74+ {
75+ case WM_INITDIALOG:
76+ WsInputInit(hDlg);
77+ WsDlgConfInit(hDlg);
78+ return TRUE;
79+ case WM_NOTIFY:
80+ // タブコントロールの選択されているタブが変更されたことを通知
81+ switch (nm->code)
82+ {
83+ case TCN_SELCHANGE:
84+ if (nm->hwndFrom == hTabCtrl)
85+ {
86+ SelectedTab = TabCtrl_GetCurSel(hTabCtrl);
87+ switch (SelectedTab)
88+ {
89+ case 0:
90+ ShowWindow(hTab1, SW_SHOW);
91+ ShowWindow(hTab2, SW_HIDE);
92+ ShowWindow(hTab3, SW_HIDE);
93+ ShowWindow(hTab4, SW_HIDE);
94+ SetFocus(GetDlgItem(hTab1, IDC_EDIT_Y1));
95+ SendMessage(GetDlgItem(hTab1, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
96+ IDirectInputDevice8_Acquire(lpKeyDevice);
97+ break;
98+ case 1:
99+ ShowWindow(hTab1, SW_HIDE);
100+ ShowWindow(hTab2, SW_SHOW);
101+ ShowWindow(hTab3, SW_HIDE);
102+ ShowWindow(hTab4, SW_HIDE);
103+ SetFocus(GetDlgItem(hTab2, IDC_EDIT_Y1));
104+ SendMessage(GetDlgItem(hTab2, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
105+ IDirectInputDevice8_Acquire(lpKeyDevice);
106+ break;
107+ case 2:
108+ ShowWindow(hTab1, SW_HIDE);
109+ ShowWindow(hTab2, SW_HIDE);
110+ ShowWindow(hTab3, SW_SHOW);
111+ ShowWindow(hTab4, SW_HIDE);
112+ SetFocus(GetDlgItem(hTab3, IDC_EDIT_Y1));
113+ SendMessage(GetDlgItem(hTab3, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
114+ break;
115+ case 3:
116+ ShowWindow(hTab1, SW_HIDE);
117+ ShowWindow(hTab2, SW_HIDE);
118+ ShowWindow(hTab3, SW_HIDE);
119+ ShowWindow(hTab4, SW_SHOW);
120+ SetFocus(GetDlgItem(hTab4, IDC_EDIT_Y1));
121+ SendMessage(GetDlgItem(hTab4, IDC_EDIT_Y1), EM_SETSEL, 0, -1);
122+ break;
123+ }
124+ return TRUE;
125+ }
126+ break;
127+ }
128+ break;
129+ case WM_COMMAND:
130+ if(HIWORD(wParam) == BN_CLICKED)
131+ {
132+ switch (LOWORD(wParam))
133+ {
134+ case IDOK:
135+ memcpy(WsKeyboardH, TmpKeyboardH, sizeof(int) * 13);
136+ memcpy(WsKeyboardV, TmpKeyboardV, sizeof(int) * 13);
137+ memcpy(WsJoypadH, TmpJoypadH, sizeof(int) * 13);
138+ memcpy(WsJoypadV, TmpJoypadV, sizeof(int) * 13);
139+ EndDialog(hDlg, LOWORD(wParam));
140+ return TRUE;
141+ case IDCANCEL:
142+ EndDialog(hDlg, LOWORD(wParam));
143+ return TRUE;
144+ }
145+ }
146+ break;
147+ case WM_DESTROY:
148+ WsInputRelease();
149+ break;
150+ }
151+ return FALSE;
152+}
153+
154+LRESULT CALLBACK EditProcKey(HWND hEditWnd, UINT msg, WPARAM wParam, LPARAM lParam)
155+{
156+ HRESULT hRet;
157+ BYTE diKeys[256];
158+ int key, i;
159+ HWND next;
160+
161+ switch (msg)
162+ {
163+ case WM_GETDLGCODE:
164+ return DLGC_WANTALLKEYS;
165+ case WM_CHAR:
166+ return 0;
167+ case WM_KEYDOWN:
168+ key = GetDlgCtrlID(hEditWnd) - IDC_EDIT_B;
169+ wParam = 0;
170+ hRet = IDirectInputDevice8_Acquire(lpKeyDevice);
171+ if (hRet == DI_OK || hRet == S_FALSE)
172+ {
173+ hRet = IDirectInputDevice8_GetDeviceState(lpKeyDevice, 256, diKeys);
174+ if (hRet == DI_OK)
175+ {
176+ for (i = 0; i < 256; i++)
177+ {
178+ if (diKeys[i] & 0x80)
179+ {
180+ SetWindowText(hEditWnd, keyName[i]);
181+ if (SelectedTab == 0)
182+ {
183+ TmpKeyboardH[key] = i;
184+ }
185+ else
186+ {
187+ TmpKeyboardV[key] = i;
188+ }
189+ next = GetNextDlgTabItem(GetParent(hEditWnd), hEditWnd, FALSE);
190+ SetFocus(next);
191+ SendMessage(next, EM_SETSEL, 0, -1);
192+ return 0;
193+ }
194+ }
195+ }
196+ }
197+ break;
198+ }
199+ return CallWindowProc(OrgEditProc, hEditWnd, msg, wParam, lParam);
200+}
201+
202+LRESULT CALLBACK EditProcJoy(HWND hEditWnd, UINT msg, WPARAM wParam, LPARAM lParam)
203+{
204+ HWND next;
205+
206+ switch (msg)
207+ {
208+ case WM_GETDLGCODE:
209+ return DLGC_WANTALLKEYS;
210+ case WM_CHAR:
211+ return 0;
212+ case WM_KEYDOWN:
213+ if (wParam == VK_TAB || wParam == VK_RETURN)
214+ {
215+ next = GetNextDlgTabItem(GetParent(hEditWnd), hEditWnd, FALSE);
216+ SetFocus(next);
217+ SendMessage(next, EM_SETSEL, 0, -1);
218+ }
219+ return 0;
220+ }
221+ return CallWindowProc(OrgEditProc, hEditWnd, msg, wParam, lParam);
222+}
223+
224+LRESULT CALLBACK TabProc1(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
225+{
226+ switch (msg) {
227+ case WM_INITDIALOG:
228+ OrgEditProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC);
229+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
230+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
231+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
232+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
233+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
234+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
235+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
236+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
237+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
238+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
239+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
240+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
241+
242+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), keyName[TmpKeyboardH[12]]);
243+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), keyName[TmpKeyboardH[11]]);
244+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), keyName[TmpKeyboardH[10]]);
245+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), keyName[TmpKeyboardH[9]]);
246+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), keyName[TmpKeyboardH[8]]);
247+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), keyName[TmpKeyboardH[7]]);
248+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), keyName[TmpKeyboardH[6]]);
249+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), keyName[TmpKeyboardH[5]]);
250+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), keyName[TmpKeyboardH[4]]);
251+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), keyName[TmpKeyboardH[2]]);
252+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), keyName[TmpKeyboardH[1]]);
253+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), keyName[TmpKeyboardH[0]]);
254+ return TRUE;
255+ }
256+ return FALSE;
257+}
258+
259+LRESULT CALLBACK TabProc2(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
260+{
261+ switch (msg) {
262+ case WM_INITDIALOG:
263+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
264+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
265+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
266+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
267+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
268+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
269+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
270+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
271+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
272+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
273+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
274+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcKey);
275+
276+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), keyName[TmpKeyboardH[12]]);
277+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), keyName[TmpKeyboardV[11]]);
278+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), keyName[TmpKeyboardV[10]]);
279+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), keyName[TmpKeyboardV[9]]);
280+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), keyName[TmpKeyboardV[8]]);
281+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), keyName[TmpKeyboardV[7]]);
282+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), keyName[TmpKeyboardV[6]]);
283+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), keyName[TmpKeyboardV[5]]);
284+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), keyName[TmpKeyboardV[4]]);
285+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), keyName[TmpKeyboardV[2]]);
286+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), keyName[TmpKeyboardV[1]]);
287+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), keyName[TmpKeyboardV[0]]);
288+ return TRUE;
289+ }
290+ return FALSE;
291+}
292+
293+LRESULT CALLBACK TabProc3(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
294+{
295+ HWND hEditWnd;
296+ int key, joy;
297+
298+ switch (msg) {
299+ case WM_INITDIALOG:
300+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
301+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
302+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
303+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
304+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
305+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
306+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
307+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
308+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
309+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
310+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
311+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
312+
313+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GetJoyName(TmpJoypadH[12]));
314+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), GetJoyName(TmpJoypadH[11]));
315+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), GetJoyName(TmpJoypadH[10]));
316+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), GetJoyName(TmpJoypadH[9]));
317+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), GetJoyName(TmpJoypadH[8]));
318+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), GetJoyName(TmpJoypadH[7]));
319+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), GetJoyName(TmpJoypadH[6]));
320+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), GetJoyName(TmpJoypadH[5]));
321+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), GetJoyName(TmpJoypadH[4]));
322+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), GetJoyName(TmpJoypadH[2]));
323+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), GetJoyName(TmpJoypadH[1]));
324+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), GetJoyName(TmpJoypadH[0]));
325+
326+ SetTimer(hCtrl, 0, 30, NULL);
327+ return TRUE;
328+ case WM_TIMER:
329+ if (SelectedTab != 2 || wParam != 0)
330+ {
331+ break;
332+ }
333+ hEditWnd = GetFocus();
334+ key = GetDlgCtrlID(hEditWnd) - IDC_EDIT_B;
335+ joy = GetJoyState();
336+ if (joy < 0)
337+ {
338+ break;
339+ }
340+ SetWindowText(hEditWnd, GetJoyName(joy));
341+ TmpJoypadH[key] = joy;
342+ return TRUE;
343+ }
344+ return FALSE;
345+}
346+
347+LRESULT CALLBACK TabProc4(HWND hCtrl, UINT msg, WPARAM wParam, LPARAM lParam)
348+{
349+ HWND hEditWnd;
350+ int key, joy;
351+
352+ switch (msg) {
353+ case WM_INITDIALOG:
354+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
355+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
356+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
357+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
358+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_Y4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
359+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X1), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
360+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X2), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
361+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X3), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
362+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_X4), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
363+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_START), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
364+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_A), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
365+ SetWindowLongPtr(GetDlgItem(hCtrl, IDC_EDIT_B), GWLP_WNDPROC, (LONG_PTR)EditProcJoy);
366+
367+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_NOWAIT), GetJoyName(TmpJoypadH[12]));
368+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y1), GetJoyName(TmpJoypadV[11]));
369+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y2), GetJoyName(TmpJoypadV[10]));
370+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y3), GetJoyName(TmpJoypadV[9]));
371+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_Y4), GetJoyName(TmpJoypadV[8]));
372+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X1), GetJoyName(TmpJoypadV[7]));
373+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X2), GetJoyName(TmpJoypadV[6]));
374+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X3), GetJoyName(TmpJoypadV[5]));
375+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_X4), GetJoyName(TmpJoypadV[4]));
376+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_START), GetJoyName(TmpJoypadV[2]));
377+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_A), GetJoyName(TmpJoypadV[1]));
378+ SetWindowText(GetDlgItem(hCtrl, IDC_EDIT_B), GetJoyName(TmpJoypadV[0]));
379+
380+ SetTimer(hCtrl, 1, 30, NULL);
381+ return TRUE;
382+ case WM_TIMER:
383+ if (SelectedTab != 3 || wParam != 1)
384+ {
385+ break;
386+ }
387+ hEditWnd = GetFocus();
388+ key = GetDlgCtrlID(hEditWnd) - IDC_EDIT_B;
389+ joy = GetJoyState();
390+ if (joy < 0)
391+ {
392+ break;
393+ }
394+ SetWindowText(hEditWnd, GetJoyName(joy));
395+ TmpJoypadV[key] = joy;
396+ return TRUE;
397+ }
398+ return FALSE;
399+}
400+
401+LPCTSTR GetJoyName(int joy)
402+{
403+ static LPCTSTR JoyStr[] = {
404+ TEXT("POV1 UP"), TEXT("POV1 RIGHT"), TEXT("POV1 DOWN"), TEXT("POV1 LEFT"),
405+ TEXT("POV2 UP"), TEXT("POV2 RIGHT"), TEXT("POV2 DOWN"), TEXT("POV2 LEFT"),
406+ TEXT("POV3 UP"), TEXT("POV3 RIGHT"), TEXT("POV3 DOWN"), TEXT("POV3 LEFT"),
407+ TEXT("POV4 UP"), TEXT("POV4 RIGHT"), TEXT("POV4 DOWN"), TEXT("POV4 LEFT"),
408+ TEXT("Y -"), TEXT("X +"), TEXT("Y +"), TEXT("X -"), TEXT("Z +"), TEXT("Z -"),
409+ TEXT("RY -"), TEXT("RX +"), TEXT("RY +"), TEXT("RX -"), TEXT("RZ +"), TEXT("RZ -"),
410+ TEXT("Slider1 +"), TEXT("Slider1 -"), TEXT("Slider2 +"), TEXT("Slider2 -")
411+ };
412+ static const int JoyInt[] = {
413+ WS_JOY_POV1_UP, WS_JOY_POV1_RIGHT, WS_JOY_POV1_DOWN, WS_JOY_POV1_LEFT,
414+ WS_JOY_POV2_UP, WS_JOY_POV2_RIGHT, WS_JOY_POV2_DOWN, WS_JOY_POV2_LEFT,
415+ WS_JOY_POV3_UP, WS_JOY_POV3_RIGHT, WS_JOY_POV3_DOWN, WS_JOY_POV3_LEFT,
416+ WS_JOY_POV4_UP, WS_JOY_POV4_RIGHT, WS_JOY_POV4_DOWN, WS_JOY_POV4_LEFT,
417+ WS_JOY_AXIS_Y_M, WS_JOY_AXIS_X_P, WS_JOY_AXIS_Y_P, WS_JOY_AXIS_X_M, WS_JOY_AXIS_Z_P, WS_JOY_AXIS_Z_M,
418+ WS_JOY_AXIS_RY_M, WS_JOY_AXIS_RX_P, WS_JOY_AXIS_RY_P, WS_JOY_AXIS_RX_M, WS_JOY_AXIS_RZ_P, WS_JOY_AXIS_RZ_M,
419+ WS_JOY_SLIDER1_P, WS_JOY_SLIDER1_M, WS_JOY_SLIDER2_P, WS_JOY_SLIDER2_M
420+ };
421+ static TCHAR buf[8];
422+ int i;
423+
424+ if (joy < 0x80)
425+ {
426+ _stprintf_s(buf, 8, TEXT("%d"), joy);
427+ return buf;
428+ }
429+ for (i = 0; i < 32; i++)
430+ {
431+ if (joy == JoyInt[i])
432+ {
433+ return JoyStr[i];
434+ }
435+ }
436+ buf[0] = 0;
437+ return buf;
438+}
439+
440+int GetJoyState(void)
441+{
442+ const long joyCenter = 0x7fff;
443+ static int xFlag = 0;
444+ static int yFlag = 0;
445+ static int zFlag = 0;
446+ static int rxFlag = 0;
447+ static int ryFlag = 0;
448+ static int rzFlag = 0;
449+ static int s1Flag = 0;
450+ static int s2Flag = 0;
451+ HRESULT hRet;
452+ int joy;
453+ unsigned int i;
454+ DIJOYSTATE2 js;
455+ DIDEVCAPS diDevCaps;
456+
457+ diDevCaps.dwSize = sizeof(DIDEVCAPS);
458+ if (lpJoyDevice == NULL)
459+ {
460+ return -1;
461+ }
462+ hRet = IDirectInputDevice8_Poll(lpJoyDevice);
463+ if (FAILED(hRet))
464+ {
465+ hRet = IDirectInputDevice8_Acquire(lpJoyDevice);
466+ while (hRet == DIERR_INPUTLOST)
467+ {
468+ hRet = IDirectInputDevice8_Acquire(lpJoyDevice);
469+ }
470+ return -1;
471+ }
472+ IDirectInputDevice8_GetDeviceState(lpJoyDevice, sizeof(DIJOYSTATE2), &js);
473+ IDirectInputDevice8_GetCapabilities(lpJoyDevice, &diDevCaps);
474+ for (i = 0; i < diDevCaps.dwButtons; i++)
475+ {
476+ if (js.rgbButtons[i] & 0x80)
477+ {
478+ return i + 1;
479+ }
480+ }
481+ for (i = 0; i < diDevCaps.dwPOVs; i++)
482+ {
483+ joy = WS_JOY_POV1_UP + (i << 4);
484+ if (js.rgdwPOV[i] == JOY_POVFORWARD)
485+ {
486+ return joy;
487+ }
488+ else if (js.rgdwPOV[i] == JOY_POVRIGHT)
489+ {
490+ return joy + 1;
491+ }
492+ else if (js.rgdwPOV[i] == JOY_POVBACKWARD)
493+ {
494+ return joy + 3;
495+ }
496+ else if (js.rgdwPOV[i] == JOY_POVLEFT)
497+ {
498+ return joy + 7;
499+ }
500+ }
501+ if ((js.lX > joyCenter - 0x1000) && (js.lX < joyCenter + 0x1000))
502+ {
503+ xFlag = 1;
504+ }
505+ if ((js.lX > (joyCenter + 0x4000)) && xFlag)
506+ {
507+ xFlag = 0;
508+ return WS_JOY_AXIS_X_P;
509+ }
510+ else if ((js.lX < (joyCenter - 0x4000)) && xFlag)
511+ {
512+ xFlag = 0;
513+ return WS_JOY_AXIS_X_M;
514+ }
515+ if ((js.lY > joyCenter - 0x1000) && (js.lY < joyCenter + 0x1000))
516+ {
517+ yFlag = 1;
518+ }
519+ if ((js.lY > (joyCenter + 0x4000)) && yFlag)
520+ {
521+ yFlag = 0;
522+ return WS_JOY_AXIS_Y_P;
523+ }
524+ else if ((js.lY < (joyCenter - 0x4000)) && yFlag)
525+ {
526+ yFlag = 0;
527+ return WS_JOY_AXIS_Y_M;
528+ }
529+ if ((js.lZ > joyCenter - 0x1000) && (js.lZ < joyCenter + 0x1000))
530+ {
531+ zFlag = 1;
532+ }
533+ if ((js.lZ > (joyCenter + 0x4000)) && zFlag)
534+ {
535+ zFlag = 0;
536+ return WS_JOY_AXIS_Z_P;
537+ }
538+ else if ((js.lZ < (joyCenter - 0x4000)) && zFlag)
539+ {
540+ zFlag = 0;
541+ return WS_JOY_AXIS_Z_M;
542+ }
543+ if ((js.lRx > joyCenter - 0x1000) && (js.lRx < joyCenter + 0x1000))
544+ {
545+ rxFlag = 1;
546+ }
547+ if ((js.lRx > (joyCenter + 0x4000)) && rxFlag)
548+ {
549+ rxFlag = 0;
550+ return WS_JOY_AXIS_RX_P;
551+ }
552+ else if ((js.lRx < (joyCenter - 0x4000)) && rxFlag)
553+ {
554+ rxFlag = 0;
555+ return WS_JOY_AXIS_RX_M;
556+ }
557+ if ((js.lRy > joyCenter - 0x1000) && (js.lRy < joyCenter + 0x1000))
558+ {
559+ ryFlag = 1;
560+ }
561+ if ((js.lRy > (joyCenter + 0x4000)) && ryFlag)
562+ {
563+ ryFlag = 0;
564+ return WS_JOY_AXIS_RY_P;
565+ }
566+ else if ((js.lRy < (joyCenter - 0x4000)) && ryFlag)
567+ {
568+ ryFlag = 0;
569+ return WS_JOY_AXIS_RY_M;
570+ }
571+ if ((js.lRz > joyCenter - 0x1000) && (js.lRz < joyCenter + 0x1000))
572+ {
573+ rzFlag = 1;
574+ }
575+ if ((js.lRz > (joyCenter + 0x4000)) && rzFlag)
576+ {
577+ rzFlag = 0;
578+ return WS_JOY_AXIS_RZ_P;
579+ }
580+ else if ((js.lRz < (joyCenter - 0x4000)) && rzFlag)
581+ {
582+ rzFlag = 0;
583+ return WS_JOY_AXIS_RZ_M;
584+ }
585+ if ((js.rglSlider[0] > joyCenter - 0x1000) && (js.rglSlider[0] < joyCenter + 0x1000))
586+ {
587+ s1Flag = 1;
588+ }
589+ if ((js.rglSlider[0] > (joyCenter + 0x4000)) && s1Flag)
590+ {
591+ s1Flag = 0;
592+ return WS_JOY_SLIDER1_P;
593+ }
594+ else if ((js.rglSlider[0] < (joyCenter - 0x4000)) && s1Flag)
595+ {
596+ s1Flag = 0;
597+ return WS_JOY_SLIDER1_M;
598+ }
599+ if ((js.rglSlider[1] > joyCenter - 0x1000) && (js.rglSlider[0] < joyCenter + 0x1000))
600+ {
601+ s2Flag = 1;
602+ }
603+ if ((js.rglSlider[1] > (joyCenter + 0x4000)) && s2Flag)
604+ {
605+ s2Flag = 0;
606+ return WS_JOY_SLIDER2_P;
607+ }
608+ else if ((js.rglSlider[1] < (joyCenter - 0x4000)) && s2Flag)
609+ {
610+ s2Flag = 0;
611+ return WS_JOY_SLIDER2_M;
612+ }
613+ return -1;
614+}
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSConfig.c (nonexistent)
+++ oswanj/trunk/src/WSConfig.c (revision 102)
@@ -0,0 +1,142 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include <windows.h>
7+#include <stdio.h>
8+#include "WSconfig.h"
9+#include "WSInput.h"
10+#include "WSFileio.h"
11+
12+extern wchar_t* RecentOfn[];
13+extern int WsWaveVol;
14+static LPCWSTR KeyName[] = {
15+ L"B", L"A", L"START", L"OPTION",
16+ L"X4", L"X3", L"X2", L"X1",
17+ L"Y4", L"Y3", L"Y2", L"Y1",
18+ L"NOWAIT"
19+};
20+
21+void ConfigCreate(void)
22+{
23+ int i;
24+
25+ /* default values */
26+ WsKeyboardH[0] = DIK_Z; // B
27+ WsKeyboardH[1] = DIK_X; // A
28+ WsKeyboardH[2] = DIK_RETURN; // START
29+ WsKeyboardH[3] = DIK_LCONTROL; // OPTION
30+ WsKeyboardH[4] = DIK_LEFT; // X4
31+ WsKeyboardH[5] = DIK_DOWN; // X3
32+ WsKeyboardH[6] = DIK_RIGHT; // X2
33+ WsKeyboardH[7] = DIK_UP; // X1
34+ WsKeyboardH[8] = DIK_A; // Y4
35+ WsKeyboardH[9] = DIK_S; // Y3
36+ WsKeyboardH[10] = DIK_D; // Y2
37+ WsKeyboardH[11] = DIK_W; // Y1
38+ WsKeyboardH[12] = DIK_SPACE; // NO WAIT
39+
40+ WsKeyboardV[0] = DIK_Z; // B
41+ WsKeyboardV[1] = DIK_X; // A
42+ WsKeyboardV[2] = DIK_RETURN; // START
43+ WsKeyboardV[3] = DIK_LCONTROL; // OPTION
44+ WsKeyboardV[4] = DIK_S; // X4
45+ WsKeyboardV[5] = DIK_D; // X3
46+ WsKeyboardV[6] = DIK_W; // X2
47+ WsKeyboardV[7] = DIK_A; // X1
48+ WsKeyboardV[8] = DIK_DOWN; // Y4
49+ WsKeyboardV[9] = DIK_RIGHT; // Y3
50+ WsKeyboardV[10] = DIK_UP; // Y2
51+ WsKeyboardV[11] = DIK_LEFT; // Y1
52+ WsKeyboardV[12] = DIK_SPACE; // NO WAIT
53+
54+ WsJoypadH[0] = 1; // B
55+ WsJoypadH[1] = 2; // A
56+ WsJoypadH[2] = 8; // START
57+ WsJoypadH[3] = 0; // OPTION
58+ WsJoypadH[4] = WS_JOY_AXIS_X_M; // X4
59+ WsJoypadH[5] = WS_JOY_AXIS_Y_P; // X3
60+ WsJoypadH[6] = WS_JOY_AXIS_X_P; // X2
61+ WsJoypadH[7] = WS_JOY_AXIS_Y_M; // X1
62+ WsJoypadH[8] = WS_JOY_POV1_LEFT; // Y4
63+ WsJoypadH[9] = WS_JOY_POV1_DOWN; // Y3
64+ WsJoypadH[10] = WS_JOY_POV1_RIGHT; // Y2
65+ WsJoypadH[11] = WS_JOY_POV1_UP; // Y1
66+ WsJoypadH[12] = 7; // NO WAIT
67+
68+ WsJoypadV[0] = 5; // B
69+ WsJoypadV[1] = 6; // A
70+ WsJoypadV[2] = 8; // START
71+ WsJoypadV[3] = 0; // OPTION
72+ WsJoypadV[4] = 1; // X4
73+ WsJoypadV[5] = 2; // X3
74+ WsJoypadV[6] = 4; // X2
75+ WsJoypadV[7] = 3; // X1
76+ WsJoypadV[8] = WS_JOY_AXIS_Y_P; // Y4
77+ WsJoypadV[9] = WS_JOY_AXIS_X_P; // Y3
78+ WsJoypadV[10] = WS_JOY_AXIS_Y_M; // Y2
79+ WsJoypadV[11] = WS_JOY_AXIS_X_M; // Y1
80+ WsJoypadV[12] = 7; // NO WAIT
81+
82+ for (i = 12; i >= 0; i--)
83+ {
84+ WsKeyboardH[i] = GetPrivateProfileIntW(L"KEY_H", KeyName[i], WsKeyboardH[i], IniPath);
85+ }
86+ for (i = 12; i >= 0; i--)
87+ {
88+ WsKeyboardV[i] = GetPrivateProfileIntW(L"KEY_V", KeyName[i], WsKeyboardV[i], IniPath);
89+ }
90+ for (i = 12; i >= 0; i--)
91+ {
92+ WsJoypadH[i] = GetPrivateProfileIntW(L"JOY_H", KeyName[i], WsJoypadH[i], IniPath);
93+ }
94+ for (i = 12; i >= 0; i--)
95+ {
96+ WsJoypadV[i] = GetPrivateProfileIntW(L"JOY_V", KeyName[i], WsJoypadV[i], IniPath);
97+ }
98+ GetPrivateProfileStringW(L"RECENT_ROMS", L"0", L"", RecentOfn[0], 512, IniPath);
99+ GetPrivateProfileStringW(L"RECENT_ROMS", L"1", L"", RecentOfn[1], 512, IniPath);
100+ GetPrivateProfileStringW(L"RECENT_ROMS", L"2", L"", RecentOfn[2], 512, IniPath);
101+ GetPrivateProfileStringW(L"RECENT_ROMS", L"3", L"", RecentOfn[3], 512, IniPath);
102+ GetPrivateProfileStringW(L"RECENT_ROMS", L"4", L"", RecentOfn[4], 512, IniPath);
103+ GetPrivateProfileStringW(L"RECENT_ROMS", L"5", L"", RecentOfn[5], 512, IniPath);
104+ WsWaveVol = GetPrivateProfileIntW(L"VOLUME", L"VOL", 4, IniPath);
105+}
106+
107+static void WritePrivateProfileIntW(LPCWSTR lpAppName, LPCWSTR lpKeyName, int nInt, LPCWSTR lpFileName)
108+{
109+ wchar_t s[32];
110+
111+ swprintf_s(s, 32, L"%d", nInt);
112+ WritePrivateProfileStringW(lpAppName, lpKeyName, s, lpFileName);
113+}
114+
115+void ConfigRelease(void)
116+{
117+ int i;
118+
119+ for (i = 12; i >= 0; i--)
120+ {
121+ WritePrivateProfileIntW(L"KEY_H", KeyName[i], WsKeyboardH[i], IniPath);
122+ }
123+ for (i = 12; i >= 0; i--)
124+ {
125+ WritePrivateProfileIntW(L"KEY_V", KeyName[i], WsKeyboardV[i], IniPath);
126+ }
127+ for (i = 12; i >= 0; i--)
128+ {
129+ WritePrivateProfileIntW(L"JOY_H", KeyName[i], WsJoypadH[i], IniPath);
130+ }
131+ for (i = 12; i >= 0; i--)
132+ {
133+ WritePrivateProfileIntW(L"JOY_V", KeyName[i], WsJoypadV[i], IniPath);
134+ }
135+ WritePrivateProfileStringW(L"RECENT_ROMS", L"0", RecentOfn[0], IniPath);
136+ WritePrivateProfileStringW(L"RECENT_ROMS", L"1", RecentOfn[1], IniPath);
137+ WritePrivateProfileStringW(L"RECENT_ROMS", L"2", RecentOfn[2], IniPath);
138+ WritePrivateProfileStringW(L"RECENT_ROMS", L"3", RecentOfn[3], IniPath);
139+ WritePrivateProfileStringW(L"RECENT_ROMS", L"4", RecentOfn[4], IniPath);
140+ WritePrivateProfileStringW(L"RECENT_ROMS", L"5", RecentOfn[5], IniPath);
141+ WritePrivateProfileIntW(L"VOLUME", L"VOL", WsWaveVol, IniPath);
142+}
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/WSFileio.c (nonexistent)
+++ oswanj/trunk/src/WSFileio.c (revision 102)
@@ -0,0 +1,480 @@
1+/*
2+$Date$
3+$Rev$
4+*/
5+
6+#include <shlwapi.h>
7+#include <stdio.h>
8+#include "WSHard.h"
9+#include "WS.h"
10+#include "WSDraw.h"
11+#include "WSFileio.h"
12+#include "WSPdata.h"
13+#include "WSError.h"
14+#include "WSRender.h"
15+#include "nec/necintrf.h"
16+
17+// ファイル操作は表などとディレクトリセパレータがかぶるのでUNICODEを使います
18+static wchar_t CurDir[512];
19+static wchar_t *SaveDir = L"RAM";
20+static wchar_t *StateDir = L"STATE";
21+static wchar_t SaveName[512]; // ".sav"
22+wchar_t StateName[512];
23+wchar_t IniPath[512];
24+
25+void WsSetDir(void)
26+{
27+ wchar_t *p;
28+
29+ wcscpy(CurDir, __wargv[0]);
30+ p = wcsrchr(CurDir, L'\\');
31+ if (p == NULL)
32+ {
33+ return;
34+ }
35+ *(++p) = 0;
36+ wcscpy(IniPath, CurDir);
37+ wcscat(IniPath, L"OswanJ.ini");
38+}
39+
40+int WsSetPdata(void)
41+{
42+ ROMBanks = 1;
43+ RAMBanks = 0;
44+ RAMSize = 0;
45+ CartKind = 0;
46+ SaveName[0] = 0;
47+ if ((ROMMap[0xFF] = (BYTE*)malloc(0x10000)) == NULL)
48+ {
49+ ErrorMsg(ERR_MALLOC);
50+ return -1;
51+ }
52+ memcpy(ROMMap[0xFF] + 0xF080, pdata, size_pdata);
53+ WsReset();
54+ SetDrawMode(0);
55+ return 0;
56+}
57+
58+int WsCreate(wchar_t *CartName)
59+{
60+ int Checksum, i, j;
61+ FILE* fp;
62+ BYTE buf[16];
63+ wchar_t* p;
64+
65+ for (i = 0; i < 256; i++)
66+ {
67+ ROMMap[i] = MemDummy;
68+ RAMMap[i] = MemDummy;
69+ }
70+ memset(IRAM, 0, sizeof(IRAM));
71+ memset(MemDummy, 0xA0, sizeof(MemDummy));
72+ memset(IO, 0, sizeof(IO));
73+ if (CartName == NULL)
74+ {
75+ return WsSetPdata();
76+ }
77+ if ((fp = _wfopen(CartName, L"rb")) == NULL)
78+ {
79+ ErrorMsg(ERR_FOPEN);
80+ return -1;
81+ }
82+ fseek(fp, -10, 2);
83+ if (fread(buf, 1, 10, fp) != 10)
84+ {
85+ ErrorMsg(ERR_FREAD_ROMINFO);
86+ return -1;
87+ }
88+ switch (buf[4])
89+ {
90+ case 1:
91+ ROMBanks = 4;
92+ break;
93+ case 2:
94+ ROMBanks = 8;
95+ break;
96+ case 3:
97+ ROMBanks = 16;
98+ break;
99+ case 4:
100+ ROMBanks = 32;
101+ break;
102+ case 5:
103+ ROMBanks = 48;
104+ break;
105+ case 6:
106+ ROMBanks = 64;
107+ break;
108+ case 7:
109+ ROMBanks = 96;
110+ break;
111+ case 8:
112+ ROMBanks = 128;
113+ break;
114+ case 9:
115+ ROMBanks = 256;
116+ break;
117+ default:
118+ ROMBanks = 0;
119+ break;
120+ }
121+ if (ROMBanks == 0)
122+ {
123+ ErrorMsg(ERR_ILLEGAL_ROMSIZE);
124+ return -1;
125+ }
126+ switch (buf[5])
127+ {
128+ case 0x01:
129+ RAMBanks = 1;
130+ RAMSize = 0x2000;
131+ CartKind = 0;
132+ break;
133+ case 0x02:
134+ RAMBanks = 1;
135+ RAMSize = 0x8000;
136+ CartKind = 0;
137+ break;
138+ case 0x03:
139+ RAMBanks = 2;
140+ RAMSize = 0x20000;
141+ CartKind = 0;
142+ break;
143+ case 0x04:
144+ RAMBanks = 4;
145+ RAMSize = 0x40000;
146+ CartKind = 0;
147+ break;
148+ case 0x10:
149+ RAMBanks = 1;
150+ RAMSize = 0x80;
151+ CartKind = CK_EEP;
152+ break;
153+ case 0x20:
154+ RAMBanks = 1;
155+ RAMSize = 0x800;
156+ CartKind = CK_EEP;
157+ break;
158+ case 0x50:
159+ RAMBanks = 1;
160+ RAMSize = 0x400;
161+ CartKind = CK_EEP;
162+ break;
163+ default:
164+ RAMBanks = 0;
165+ RAMSize = 0;
166+ CartKind = 0;
167+ break;
168+ }
169+ WsRomPatch(buf);
170+ Checksum = (int)((buf[9] << 8) + buf[8]);
171+ Checksum += (int)(buf[9] + buf[8]);
172+ for (i = ROMBanks - 1; i >= 0; i--)
173+ {
174+ fseek(fp, (ROMBanks - i) * -0x10000, 2);
175+ if ((ROMMap[0x100 - ROMBanks + i] = (BYTE*)malloc(0x10000)) != NULL)
176+ {
177+ if (fread(ROMMap[0x100 - ROMBanks + i], 1, 0x10000, fp) == 0x10000)
178+ {
179+ for (j = 0; j < 0x10000; j++)
180+ {
181+ Checksum -= ROMMap[0x100 - ROMBanks + i][j];
182+ }
183+ }
184+ else
185+ {
186+ ErrorMsg(ERR_FREAD_ROM);
187+ break;
188+ }
189+ }
190+ else
191+ {
192+ ErrorMsg(ERR_MALLOC);
193+ break;
194+ }
195+ }
196+ fclose(fp);
197+ if (i >= 0)
198+ {
199+ return -1;
200+ }
201+ if (Checksum & 0xFFFF)
202+ {
203+ //ErrorMsg(ERR_CHECKSUM);
204+ }
205+ if (RAMBanks)
206+ {
207+ for (i = 0; i < RAMBanks; i++)
208+ {
209+ if ((RAMMap[i] = (BYTE*)malloc(0x10000)) != NULL)
210+ {
211+ memset(RAMMap[i], 0x00, 0x10000);
212+ }
213+ else
214+ {
215+ ErrorMsg(ERR_MALLOC);
216+ return -1;
217+ }
218+ }
219+ }
220+ if (RAMSize)
221+ {
222+ wcscpy (SaveName, CurDir);
223+ p = wcsrchr(CartName, L'\\');
224+ if (p)
225+ {
226+ wcscat(SaveName, SaveDir);
227+ if (PathIsDirectoryW(SaveName) == FALSE)
228+ {
229+ CreateDirectoryW(SaveName, NULL);
230+ }
231+ wcscat(SaveName, p);
232+ p = wcsrchr(SaveName, L'.');
233+ if (p)
234+ {
235+ *p = 0;
236+ }
237+ wcscat(SaveName, L".sav");
238+ }
239+ else
240+ {
241+ SaveName[0] = 0;
242+ }
243+ if ((fp = _wfopen(SaveName, L"rb")) != NULL)
244+ {
245+ for (i = 0; i < RAMBanks; i++)
246+ {
247+ if (RAMSize < 0x10000)
248+ {
249+ if (fread(RAMMap[i], 1, RAMSize, fp) != (size_t)RAMSize)
250+ {
251+ ErrorMsg(ERR_FREAD_SAVE);
252+ break;
253+ }
254+ }
255+ else
256+ {
257+ if (fread(RAMMap[i], 1, 0x10000, fp) != 0x10000)
258+ {
259+ ErrorMsg(ERR_FREAD_SAVE);
260+ break;
261+ }
262+ }
263+ }
264+ fclose(fp);
265+ }
266+ }
267+ else
268+ {
269+ SaveName[0] = 0;
270+ }
271+ wcscpy (StateName, CurDir);
272+ p = wcsrchr(CartName, L'\\');
273+ if (p)
274+ {
275+ wcscat(StateName, StateDir);
276+ if (PathIsDirectoryW(StateName) == FALSE)
277+ {
278+ CreateDirectoryW(StateName, NULL);
279+ }
280+ wcscat(StateName, p);
281+ p = wcsrchr(StateName, L'.');
282+ if (p)
283+ {
284+ *p = 0;
285+ }
286+ }
287+ WsReset();
288+ SetDrawMode(buf[6] & 1); // 0:横 1:縦
289+ return 0;
290+}
291+
292+void WsRelease(void)
293+{
294+ FILE* fp;
295+ int i;
296+
297+ if (SaveName[0] != '\0')
298+ {
299+ if ((fp = _wfopen(SaveName, L"wb"))!= NULL)
300+ {
301+ for (i =0; i < RAMBanks; i++)
302+ {
303+ if (RAMSize<0x10000)
304+ {
305+ if (fwrite(RAMMap[i], 1, RAMSize, fp) != (size_t)RAMSize)
306+ {
307+ break;
308+ }
309+ }
310+ else
311+ {
312+ if (fwrite(RAMMap[i], 1, 0x10000, fp)!=0x10000)
313+ {
314+ break;
315+ }
316+ }
317+ free(RAMMap[i]);
318+ RAMMap[i] = NULL;
319+ }
320+ fclose(fp);
321+ }
322+ SaveName[0] = '\0';
323+ }
324+ for (i = 0xFF; i >= 0; i--)
325+ {
326+ if (ROMMap[i] == MemDummy)
327+ {
328+ break;
329+ }
330+ free(ROMMap[i]);
331+ ROMMap[i] = MemDummy;
332+ }
333+ StateName[0] = '\0';
334+}
335+
336+void WsLoadEeprom(void)
337+{
338+ FILE* fp;
339+ wchar_t buf[512];
340+
341+ wcscpy(buf, CurDir);
342+ wcscat(buf, L"eeprom.dat");
343+ if ((fp = _wfopen(buf, L"rb")) != NULL)
344+ {
345+ fread(IEep, sizeof(WORD), 64, fp);
346+ fclose(fp);
347+ }
348+ else
349+ {
350+ memset(IEep, 0xFF, 0x60);
351+ memset(IEep + 0x60, 0, 0x20);
352+ }
353+}
354+
355+void WsSaveEeprom(void)
356+{
357+ FILE* fp;
358+ wchar_t buf[512];
359+
360+ wcscpy(buf, CurDir);
361+ wcscat(buf, L"eeprom.dat");
362+ if ((fp = _wfopen(buf, L"wb")) != NULL)
363+ {
364+ fwrite(IEep, sizeof(WORD), 64, fp);
365+ fclose(fp);
366+ }
367+}
368+
369+#define MacroLoadNecRegisterFromFile(F,R) \
370+ fread(&value, sizeof(unsigned int), 1, fp); \
371+ nec_set_reg(R,value);
372+void WsLoadState(int num)
373+{
374+ FILE* fp;
375+ wchar_t buf[512];
376+ unsigned int value;
377+ int i;
378+
379+ wsprintf(buf, L"%s.%03d", StateName, num);
380+ if ((fp = _wfopen(buf, L"rb")) == NULL)
381+ {
382+ return;
383+ }
384+ MacroLoadNecRegisterFromFile(fp,NEC_IP);
385+ MacroLoadNecRegisterFromFile(fp,NEC_AW);
386+ MacroLoadNecRegisterFromFile(fp,NEC_BW);
387+ MacroLoadNecRegisterFromFile(fp,NEC_CW);
388+ MacroLoadNecRegisterFromFile(fp,NEC_DW);
389+ MacroLoadNecRegisterFromFile(fp,NEC_CS);
390+ MacroLoadNecRegisterFromFile(fp,NEC_DS);
391+ MacroLoadNecRegisterFromFile(fp,NEC_ES);
392+ MacroLoadNecRegisterFromFile(fp,NEC_SS);
393+ MacroLoadNecRegisterFromFile(fp,NEC_IX);
394+ MacroLoadNecRegisterFromFile(fp,NEC_IY);
395+ MacroLoadNecRegisterFromFile(fp,NEC_BP);
396+ MacroLoadNecRegisterFromFile(fp,NEC_SP);
397+ MacroLoadNecRegisterFromFile(fp,NEC_FLAGS);
398+ MacroLoadNecRegisterFromFile(fp,NEC_VECTOR);
399+ MacroLoadNecRegisterFromFile(fp,NEC_PENDING);
400+ MacroLoadNecRegisterFromFile(fp,NEC_NMI_STATE);
401+ MacroLoadNecRegisterFromFile(fp,NEC_IRQ_STATE);
402+ fread(IRAM, sizeof(BYTE), 0x10000, fp);
403+ fread(IO, sizeof(BYTE), 0x100, fp);
404+ for (i =0; i < RAMBanks; i++)
405+ {
406+ if (RAMSize < 0x10000)
407+ {
408+ fread(RAMMap[i], 1, RAMSize, fp);
409+ }
410+ else
411+ {
412+ fread(RAMMap[i], 1, 0x10000, fp);
413+ }
414+ }
415+ fread(Palette, sizeof(WORD), 16 * 16, fp);
416+ fclose(fp);
417+ WriteIO(0xC1, IO[0xC1]);
418+ WriteIO(0xC2, IO[0xC2]);
419+ WriteIO(0xC3, IO[0xC3]);
420+ WriteIO(0xC0, IO[0xC0]);
421+ for (i = 0x80; i <= 0x90; i++)
422+ {
423+ WriteIO(i, IO[i]);
424+ }
425+}
426+
427+#define MacroStoreNecRegisterToFile(F,R) \
428+ value = nec_get_reg(R); \
429+ fwrite(&value, sizeof(unsigned int), 1, fp);
430+void WsSaveState(int num)
431+{
432+ FILE* fp;
433+ wchar_t buf[512];
434+ unsigned int value;
435+ int i;
436+
437+ if (StateName[0] == '\0')
438+ {
439+ return;
440+ }
441+ wsprintf(buf, L"%s.%03d", StateName, num);
442+ if ((fp = _wfopen(buf, L"wb")) == NULL)
443+ {
444+ return;
445+ }
446+ MacroStoreNecRegisterToFile(fp,NEC_IP);
447+ MacroStoreNecRegisterToFile(fp,NEC_AW);
448+ MacroStoreNecRegisterToFile(fp,NEC_BW);
449+ MacroStoreNecRegisterToFile(fp,NEC_CW);
450+ MacroStoreNecRegisterToFile(fp,NEC_DW);
451+ MacroStoreNecRegisterToFile(fp,NEC_CS);
452+ MacroStoreNecRegisterToFile(fp,NEC_DS);
453+ MacroStoreNecRegisterToFile(fp,NEC_ES);
454+ MacroStoreNecRegisterToFile(fp,NEC_SS);
455+ MacroStoreNecRegisterToFile(fp,NEC_IX);
456+ MacroStoreNecRegisterToFile(fp,NEC_IY);
457+ MacroStoreNecRegisterToFile(fp,NEC_BP);
458+ MacroStoreNecRegisterToFile(fp,NEC_SP);
459+ MacroStoreNecRegisterToFile(fp,NEC_FLAGS);
460+ MacroStoreNecRegisterToFile(fp,NEC_VECTOR);
461+ MacroStoreNecRegisterToFile(fp,NEC_PENDING);
462+ MacroStoreNecRegisterToFile(fp,NEC_NMI_STATE);
463+ MacroStoreNecRegisterToFile(fp,NEC_IRQ_STATE);
464+ fwrite(IRAM, sizeof(BYTE), 0x10000, fp);
465+ fwrite(IO, sizeof(BYTE), 0x100, fp);
466+ for (i =0; i < RAMBanks; i++)
467+ {
468+ if (RAMSize < 0x10000)
469+ {
470+ fwrite(RAMMap[i], 1, RAMSize, fp);
471+ }
472+ else
473+ {
474+ fwrite(RAMMap[i], 1, 0x10000, fp);
475+ }
476+ }
477+ fwrite(Palette, sizeof(WORD), 16 * 16, fp);
478+ fclose(fp);
479+}
480+
Added: svn:keywords
## -0,0 +1,2 ##
+Date
+Rev
\ No newline at end of property
--- oswanj/trunk/src/nec/nec.cpp (revision 101)
+++ oswanj/trunk/src/nec/nec.cpp (nonexistent)
@@ -1,947 +0,0 @@
1-/****************************************************************************
2-
3- NEC V30MZ(V20/V30/V33) emulator
4-
5- Small changes made by toshi (Cycle count macros changed , "THROUGH" macro added)
6-
7- Small changes made by dox@space.pl (Corrected bug in NEG instruction , different AUX flag handling in some opcodes)
8-
9- (Re)Written June-September 2000 by Bryan McPhail (mish@tendril.co.uk) based
10- on code by Oliver Bergmann (Raul_Bloodworth@hotmail.com) who based code
11- on the i286 emulator by Fabrice Frances which had initial work based on
12- David Hedley's pcemu(!).
13-
14- This new core features 99% accurate cycle counts for each processor,
15- there are still some complex situations where cycle counts are wrong,
16- typically where a few instructions have differing counts for odd/even
17- source and odd/even destination memory operands.
18-
19- Flag settings are also correct for the NEC processors rather than the
20- I86 versions.
21-
22- Nb: This emulation should be faster than previous NEC cores, but
23- because the old cycle count values were far too high in many cases
24- the processor has to do more 'work' than before, so the overall effect
25- may be a slower core.
26-
27-****************************************************************************/
28-
29-
30-#include <stdio.h>
31-#include <string.h>
32-#include <windows.h>
33-
34-#define UINT8 unsigned char
35-#define UINT16 unsigned short
36-#define UINT32 unsigned int
37-#define INT8 signed char
38-#define INT16 signed short
39-#define INT32 signed int
40-
41-#include "nec.h"
42-#include "necintrf.h"
43-
44-typedef union
45-{ /* eight general registers */
46- UINT16 w[8]; /* viewed as 16 bits registers */
47- UINT8 b[16]; /* or as 8 bit registers */
48-} necbasicregs;
49-
50-typedef struct
51-{
52- necbasicregs regs;
53- UINT16 sregs[4];
54-
55- UINT16 ip;
56-
57- INT32 SignVal;
58- UINT32 AuxVal, OverVal, ZeroVal, CarryVal, ParityVal; /* 0 or non-0 valued flags */
59- UINT8 TF, IF, DF, MF; /* 0 or 1 valued flags */ /* OB[19.07.99] added Mode Flag V30 */
60- UINT32 int_vector;
61- UINT32 pending_irq;
62- UINT32 nmi_state;
63- UINT32 irq_state;
64- int (*irq_callback)(int irqline);
65-} nec_Regs;
66-
67-/***************************************************************************/
68-/* cpu state */
69-/***************************************************************************/
70-
71-int nec_ICount;
72-
73-static nec_Regs I;
74-
75-static UINT32 cpu_type;
76-static UINT32 prefix_base; /* base address of the latest prefix segment */
77-char seg_prefix; /* prefix segment indicator */
78-
79-
80-/* The interrupt number of a pending external interrupt pending NMI is 2. */
81-/* For INTR interrupts, the level is caught on the bus during an INTA cycle */
82-
83-
84-#include "necinstr.h"
85-#include "necea.h"
86-#include "necmodrm.h"
87-
88-static int no_interrupt;
89-
90-static UINT8 parity_table[256];
91-
92-/***************************************************************************/
93-
94-void nec_reset (void *param)
95-{
96- unsigned int i,j,c;
97- BREGS reg_name[8]={ AL, CL, DL, BL, AH, CH, DH, BH };
98-
99-
100- memset( &I, 0, sizeof(I) );
101-
102- no_interrupt=0;
103- I.sregs[CS] = 0xffff;
104-
105-
106- for (i = 0;i < 256; i++)
107- {
108- for (j = i, c = 0; j > 0; j >>= 1)
109- if (j & 1) c++;
110- parity_table[i] = !(c & 1);
111- }
112-
113- I.ZeroVal = I.ParityVal = 1;
114- SetMD(1); /* set the mode-flag = native mode */
115-
116- for (i = 0; i < 256; i++)
117- {
118- Mod_RM.reg.b[i] = reg_name[(i & 0x38) >> 3];
119- Mod_RM.reg.w[i] = (WREGS) ( (i & 0x38) >> 3) ;
120- }
121-
122- for (i = 0xc0; i < 0x100; i++)
123- {
124- Mod_RM.RM.w[i] = (WREGS)( i & 7 );
125- Mod_RM.RM.b[i] = (BREGS)reg_name[i & 7];
126- }
127-}
128-
129-void nec_exit (void)
130-{
131-
132-}
133-
134-
135-
136-
137-void nec_int(DWORD wektor)
138-{
139-
140- DWORD dest_seg, dest_off;
141-
142- if(I.IF)
143- {
144- i_pushf();
145- I.TF = I.IF = 0;
146- dest_off = ReadWord(wektor);
147- dest_seg = ReadWord(wektor+2);
148- PUSH(I.sregs[CS]);
149- PUSH(I.ip);
150- I.ip = (WORD)dest_off;
151- I.sregs[CS] = (WORD)dest_seg;
152- }
153-}
154-
155-static void nec_interrupt(unsigned int_num,BOOLEAN md_flag)
156-{
157- UINT32 dest_seg, dest_off;
158-
159- if (int_num == -1)
160- return;
161-
162- i_pushf();
163- I.TF = I.IF = 0;
164-
165-
166- dest_off = ReadWord((int_num)*4);
167- dest_seg = ReadWord((int_num)*4+2);
168-
169- PUSH(I.sregs[CS]);
170- PUSH(I.ip);
171- I.ip = (WORD)dest_off;
172- I.sregs[CS] = (WORD)dest_seg;
173-
174-}
175-
176-
177-/****************************************************************************/
178-/* OPCODES */
179-/****************************************************************************/
180-
181-#define OP(num,func_name) static void func_name(void)
182-
183-
184-OP( 0x00, i_add_br8 ) { DEF_br8; ADDB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
185-OP( 0x01, i_add_wr16 ) { DEF_wr16; ADDW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
186-OP( 0x02, i_add_r8b ) { DEF_r8b; ADDB; RegByte(ModRM)=dst; CLKM(2,1); }
187-OP( 0x03, i_add_r16w ) { DEF_r16w; ADDW; RegWord(ModRM)=dst; CLKM(2,1); }
188-OP( 0x04, i_add_ald8 ) { DEF_ald8; ADDB; I.regs.b[AL]=dst; CLK(1); }
189-OP( 0x05, i_add_axd16) { DEF_axd16; ADDW; I.regs.w[AW]=dst; CLK(1); }
190-OP( 0x06, i_push_es ) { PUSH(I.sregs[ES]); CLK(2); }
191-OP( 0x07, i_pop_es ) { POP(I.sregs[ES]); CLK(3); }
192-
193-OP( 0x08, i_or_br8 ) { DEF_br8; ORB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
194-OP( 0x09, i_or_wr16 ) { DEF_wr16; ORW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
195-OP( 0x0a, i_or_r8b ) { DEF_r8b; ORB; RegByte(ModRM)=dst; CLKM(2,1); }
196-OP( 0x0b, i_or_r16w ) { DEF_r16w; ORW; RegWord(ModRM)=dst; CLKM(2,1); }
197-OP( 0x0c, i_or_ald8 ) { DEF_ald8; ORB; I.regs.b[AL]=dst; CLK(1); }
198-OP( 0x0d, i_or_axd16 ) { DEF_axd16; ORW; I.regs.w[AW]=dst; CLK(1); }
199-OP( 0x0e, i_push_cs ) { PUSH(I.sregs[CS]); CLK(2); }
200-OP( 0x0f, i_pre_nec ) { UINT32 ModRM, tmp, tmp2; /* pop cs at V30MZ? */
201- switch (FETCH) {
202- case 0x10 : BITOP_BYTE; CLKS(3,3,4); tmp2 = I.regs.b[CL] & 0x7; I.ZeroVal = (tmp & (1<<tmp2)) ? 1 : 0; I.CarryVal=I.OverVal=0; break; /* Test */
203- case 0x11 : BITOP_WORD; CLKS(3,3,4); tmp2 = I.regs.b[CL] & 0xf; I.ZeroVal = (tmp & (1<<tmp2)) ? 1 : 0; I.CarryVal=I.OverVal=0; break; /* Test */
204- case 0x12 : BITOP_BYTE; CLKS(5,5,4); tmp2 = I.regs.b[CL] & 0x7; tmp &= ~(1<<tmp2); PutbackRMByte(ModRM,tmp); break; /* Clr */
205- case 0x13 : BITOP_WORD; CLKS(5,5,4); tmp2 = I.regs.b[CL] & 0xf; tmp &= ~(1<<tmp2); PutbackRMWord(ModRM,tmp); break; /* Clr */
206- case 0x14 : BITOP_BYTE; CLKS(4,4,4); tmp2 = I.regs.b[CL] & 0x7; tmp |= (1<<tmp2); PutbackRMByte(ModRM,tmp); break; /* Set */
207- case 0x15 : BITOP_WORD; CLKS(4,4,4); tmp2 = I.regs.b[CL] & 0xf; tmp |= (1<<tmp2); PutbackRMWord(ModRM,tmp); break; /* Set */
208- case 0x16 : BITOP_BYTE; CLKS(4,4,4); tmp2 = I.regs.b[CL] & 0x7; BIT_NOT; PutbackRMByte(ModRM,tmp); break; /* Not */
209- case 0x17 : BITOP_WORD; CLKS(4,4,4); tmp2 = I.regs.b[CL] & 0xf; BIT_NOT; PutbackRMWord(ModRM,tmp); break; /* Not */
210-
211- case 0x18 : BITOP_BYTE; CLKS(4,4,4); tmp2 = (FETCH) & 0x7; I.ZeroVal = (tmp & (1<<tmp2)) ? 1 : 0; I.CarryVal=I.OverVal=0; break; /* Test */
212- case 0x19 : BITOP_WORD; CLKS(4,4,4); tmp2 = (FETCH) & 0xf; I.ZeroVal = (tmp & (1<<tmp2)) ? 1 : 0; I.CarryVal=I.OverVal=0; break; /* Test */
213- case 0x1a : BITOP_BYTE; CLKS(6,6,4); tmp2 = (FETCH) & 0x7; tmp &= ~(1<<tmp2); PutbackRMByte(ModRM,tmp); break; /* Clr */
214- case 0x1b : BITOP_WORD; CLKS(6,6,4); tmp2 = (FETCH) & 0xf; tmp &= ~(1<<tmp2); PutbackRMWord(ModRM,tmp); break; /* Clr */
215- case 0x1c : BITOP_BYTE; CLKS(5,5,4); tmp2 = (FETCH) & 0x7; tmp |= (1<<tmp2); PutbackRMByte(ModRM,tmp); break; /* Set */
216- case 0x1d : BITOP_WORD; CLKS(5,5,4); tmp2 = (FETCH) & 0xf; tmp |= (1<<tmp2); PutbackRMWord(ModRM,tmp); break; /* Set */
217- case 0x1e : BITOP_BYTE; CLKS(5,5,4); tmp2 = (FETCH) & 0x7; BIT_NOT; PutbackRMByte(ModRM,tmp); break; /* Not */
218- case 0x1f : BITOP_WORD; CLKS(5,5,4); tmp2 = (FETCH) & 0xf; BIT_NOT; PutbackRMWord(ModRM,tmp); break; /* Not */
219-
220- case 0x20 : ADD4S; CLKS(7,7,2); break;
221- case 0x22 : SUB4S; CLKS(7,7,2); break;
222- case 0x26 : CMP4S; CLKS(7,7,2); break;
223- case 0x28 : ModRM = FETCH; tmp = GetRMByte(ModRM); tmp <<= 4; tmp |= I.regs.b[AL] & 0xf; I.regs.b[AL] = (I.regs.b[AL] & 0xf0) | ((tmp>>8)&0xf); tmp &= 0xff; PutbackRMByte(ModRM,tmp); CLKM(9,15); break;
224- case 0x2a : ModRM = FETCH; tmp = GetRMByte(ModRM); tmp2 = (I.regs.b[AL] & 0xf)<<4; I.regs.b[AL] = (I.regs.b[AL] & 0xf0) | (tmp&0xf); tmp = tmp2 | (tmp>>4); PutbackRMByte(ModRM,tmp); CLKM(13,19); break;
225- case 0x31 : ModRM = FETCH; ModRM=0; break;
226- case 0x33 : ModRM = FETCH; ModRM=0; break;
227- case 0x92 : CLK(2); break; /* V25/35 FINT */
228- case 0xe0 : ModRM = FETCH; ModRM=0; break;
229- case 0xf0 : ModRM = FETCH; ModRM=0; break;
230- case 0xff : ModRM = FETCH; ModRM=0; break;
231- default: break;
232- }
233-}
234-
235-OP( 0x10, i_adc_br8 ) { DEF_br8; src+=CF; ADDB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
236-OP( 0x11, i_adc_wr16 ) { DEF_wr16; src+=CF; ADDW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
237-OP( 0x12, i_adc_r8b ) { DEF_r8b; src+=CF; ADDB; RegByte(ModRM)=dst; CLKM(2,1); }
238-OP( 0x13, i_adc_r16w ) { DEF_r16w; src+=CF; ADDW; RegWord(ModRM)=dst; CLKM(2,1); }
239-OP( 0x14, i_adc_ald8 ) { DEF_ald8; src+=CF; ADDB; I.regs.b[AL]=dst; CLK(1); }
240-OP( 0x15, i_adc_axd16) { DEF_axd16; src+=CF; ADDW; I.regs.w[AW]=dst; CLK(1); }
241-OP( 0x16, i_push_ss ) { PUSH(I.sregs[SS]); CLK(2); }
242-OP( 0x17, i_pop_ss ) { POP(I.sregs[SS]); CLK(3); no_interrupt=1; }
243-
244-OP( 0x18, i_sbb_br8 ) { DEF_br8; src+=CF; SUBB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
245-OP( 0x19, i_sbb_wr16 ) { DEF_wr16; src+=CF; SUBW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
246-OP( 0x1a, i_sbb_r8b ) { DEF_r8b; src+=CF; SUBB; RegByte(ModRM)=dst; CLKM(2,1); }
247-OP( 0x1b, i_sbb_r16w ) { DEF_r16w; src+=CF; SUBW; RegWord(ModRM)=dst; CLKM(2,1); }
248-OP( 0x1c, i_sbb_ald8 ) { DEF_ald8; src+=CF; SUBB; I.regs.b[AL]=dst; CLK(1); }
249-OP( 0x1d, i_sbb_axd16) { DEF_axd16; src+=CF; SUBW; I.regs.w[AW]=dst; CLK(1); }
250-OP( 0x1e, i_push_ds ) { PUSH(I.sregs[DS]); CLK(2); }
251-OP( 0x1f, i_pop_ds ) { POP(I.sregs[DS]); CLK(3); }
252-
253-OP( 0x20, i_and_br8 ) { DEF_br8; ANDB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
254-OP( 0x21, i_and_wr16 ) { DEF_wr16; ANDW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
255-OP( 0x22, i_and_r8b ) { DEF_r8b; ANDB; RegByte(ModRM)=dst; CLKM(2,1); }
256-OP( 0x23, i_and_r16w ) { DEF_r16w; ANDW; RegWord(ModRM)=dst; CLKM(2,1); }
257-OP( 0x24, i_and_ald8 ) { DEF_ald8; ANDB; I.regs.b[AL]=dst; CLK(1); }
258-OP( 0x25, i_and_axd16) { DEF_axd16; ANDW; I.regs.w[AW]=dst; CLK(1); }
259-OP( 0x26, i_es ) { seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; }
260-OP( 0x27, i_daa ) { ADJ4(6,0x60); CLK(10); }
261-
262-OP( 0x28, i_sub_br8 ) { DEF_br8; SUBB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
263-OP( 0x29, i_sub_wr16 ) { DEF_wr16; SUBW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
264-OP( 0x2a, i_sub_r8b ) { DEF_r8b; SUBB; RegByte(ModRM)=dst; CLKM(2,1); }
265-OP( 0x2b, i_sub_r16w ) { DEF_r16w; SUBW; RegWord(ModRM)=dst; CLKM(2,1); }
266-OP( 0x2c, i_sub_ald8 ) { DEF_ald8; SUBB; I.regs.b[AL]=dst; CLK(1); }
267-OP( 0x2d, i_sub_axd16) { DEF_axd16; SUBW; I.regs.w[AW]=dst; CLK(1); }
268-OP( 0x2e, i_cs ) { seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; }
269-OP( 0x2f, i_das ) { ADJ4(-6,-0x60); CLK(10); }
270-
271-OP( 0x30, i_xor_br8 ) { DEF_br8; XORB; PutbackRMByte(ModRM,dst); CLKM(3,1); }
272-OP( 0x31, i_xor_wr16 ) { DEF_wr16; XORW; PutbackRMWord(ModRM,dst); CLKM(3,1); }
273-OP( 0x32, i_xor_r8b ) { DEF_r8b; XORB; RegByte(ModRM)=dst; CLKM(2,1); }
274-OP( 0x33, i_xor_r16w ) { DEF_r16w; XORW; RegWord(ModRM)=dst; CLKM(2,1); }
275-OP( 0x34, i_xor_ald8 ) { DEF_ald8; XORB; I.regs.b[AL]=dst; CLK(1); }
276-OP( 0x35, i_xor_axd16) { DEF_axd16; XORW; I.regs.w[AW]=dst; CLK(1); }
277-OP( 0x36, i_ss ) { seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; }
278-OP( 0x37, i_aaa ) { ADJB(6,1); CLK(9); }
279-
280-OP( 0x38, i_cmp_br8 ) { DEF_br8; SUBB; CLKM(2,1); }
281-OP( 0x39, i_cmp_wr16 ) { DEF_wr16; SUBW; CLKM(2,1); }
282-OP( 0x3a, i_cmp_r8b ) { DEF_r8b; SUBB; CLKM(2,1); }
283-OP( 0x3b, i_cmp_r16w ) { DEF_r16w; SUBW; CLKM(2,1); }
284-OP( 0x3c, i_cmp_ald8 ) { DEF_ald8; SUBB; CLK(1); }
285-OP( 0x3d, i_cmp_axd16) { DEF_axd16; SUBW; CLK(1); }
286-OP( 0x3e, i_ds ) { seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; }
287-OP( 0x3f, i_aas ) { ADJB(-6,-1); CLK(9); }
288-
289-OP( 0x40, i_inc_ax ) { IncWordReg(AW); CLK(1); }
290-OP( 0x41, i_inc_cx ) { IncWordReg(CW); CLK(1); }
291-OP( 0x42, i_inc_dx ) { IncWordReg(DW); CLK(1); }
292-OP( 0x43, i_inc_bx ) { IncWordReg(BW); CLK(1); }
293-OP( 0x44, i_inc_sp ) { IncWordReg(SP); CLK(1); }
294-OP( 0x45, i_inc_bp ) { IncWordReg(BP); CLK(1); }
295-OP( 0x46, i_inc_si ) { IncWordReg(IX); CLK(1); }
296-OP( 0x47, i_inc_di ) { IncWordReg(IY); CLK(1); }
297-
298-OP( 0x48, i_dec_ax ) { DecWordReg(AW); CLK(1); }
299-OP( 0x49, i_dec_cx ) { DecWordReg(CW); CLK(1); }
300-OP( 0x4a, i_dec_dx ) { DecWordReg(DW); CLK(1); }
301-OP( 0x4b, i_dec_bx ) { DecWordReg(BW); CLK(1); }
302-OP( 0x4c, i_dec_sp ) { DecWordReg(SP); CLK(1); }
303-OP( 0x4d, i_dec_bp ) { DecWordReg(BP); CLK(1); }
304-OP( 0x4e, i_dec_si ) { DecWordReg(IX); CLK(1); }
305-OP( 0x4f, i_dec_di ) { DecWordReg(IY); CLK(1); }
306-
307-OP( 0x50, i_push_ax ) { PUSH(I.regs.w[AW]); CLK(1); }
308-OP( 0x51, i_push_cx ) { PUSH(I.regs.w[CW]); CLK(1); }
309-OP( 0x52, i_push_dx ) { PUSH(I.regs.w[DW]); CLK(1); }
310-OP( 0x53, i_push_bx ) { PUSH(I.regs.w[BW]); CLK(1); }
311-OP( 0x54, i_push_sp ) { PUSH(I.regs.w[SP]); CLK(1); }
312-OP( 0x55, i_push_bp ) { PUSH(I.regs.w[BP]); CLK(1); }
313-OP( 0x56, i_push_si ) { PUSH(I.regs.w[IX]); CLK(1); }
314-OP( 0x57, i_push_di ) { PUSH(I.regs.w[IY]); CLK(1); }
315-
316-OP( 0x58, i_pop_ax ) { POP(I.regs.w[AW]); CLK(1); }
317-OP( 0x59, i_pop_cx ) { POP(I.regs.w[CW]); CLK(1); }
318-OP( 0x5a, i_pop_dx ) { POP(I.regs.w[DW]); CLK(1); }
319-OP( 0x5b, i_pop_bx ) { POP(I.regs.w[BW]); CLK(1); }
320-OP( 0x5c, i_pop_sp ) { POP(I.regs.w[SP]); CLK(1); }
321-OP( 0x5d, i_pop_bp ) { POP(I.regs.w[BP]); CLK(1); }
322-OP( 0x5e, i_pop_si ) { POP(I.regs.w[IX]); CLK(1); }
323-OP( 0x5f, i_pop_di ) { POP(I.regs.w[IY]); CLK(1); }
324-
325-OP( 0x60, i_pusha ) {
326- unsigned tmp=I.regs.w[SP];
327- PUSH(I.regs.w[AW]);
328- PUSH(I.regs.w[CW]);
329- PUSH(I.regs.w[DW]);
330- PUSH(I.regs.w[BW]);
331- PUSH(tmp);
332- PUSH(I.regs.w[BP]);
333- PUSH(I.regs.w[IX]);
334- PUSH(I.regs.w[IY]);
335- CLK(9);
336-}
337-OP( 0x61, i_popa ) {
338- unsigned tmp;
339- POP(I.regs.w[IY]);
340- POP(I.regs.w[IX]);
341- POP(I.regs.w[BP]);
342- POP(tmp);
343- POP(I.regs.w[BW]);
344- POP(I.regs.w[DW]);
345- POP(I.regs.w[CW]);
346- POP(I.regs.w[AW]);
347- CLK(8);
348-}
349-OP( 0x62, i_chkind ) {
350- UINT32 low,high,tmp;
351- GetModRM;
352- low = GetRMWord(ModRM);
353- high= GetnextRMWord;
354- tmp= RegWord(ModRM);
355- if (tmp<low || tmp>high) {
356- nec_interrupt(5,0);
357- CLK(7);
358- }
359- CLK(13);
360-}
361-
362-/* OP 0x64 - 0x67 is nop at V30MZ */
363-OP( 0x64, i_repnc ) { UINT32 next = FETCHOP; UINT16 c = I.regs.w[CW];
364- switch(next) { /* Segments */
365- case 0x26: seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; next = FETCHOP; CLK(2); break;
366- case 0x2e: seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; next = FETCHOP; CLK(2); break;
367- case 0x36: seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break;
368- case 0x3e: seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; next = FETCHOP; CLK(2); break;
369- }
370-
371- switch(next) {
372- case 0x6c: CLK(2); if (c) do { i_insb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
373- case 0x6d: CLK(2); if (c) do { i_insw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
374- case 0x6e: CLK(2); if (c) do { i_outsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
375- case 0x6f: CLK(2); if (c) do { i_outsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
376- case 0xa4: CLK(2); if (c) do { i_movsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
377- case 0xa5: CLK(2); if (c) do { i_movsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
378- case 0xa6: CLK(2); if (c) do { i_cmpsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
379- case 0xa7: CLK(2); if (c) do { i_cmpsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
380- case 0xaa: CLK(2); if (c) do { i_stosb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
381- case 0xab: CLK(2); if (c) do { i_stosw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
382- case 0xac: CLK(2); if (c) do { i_lodsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
383- case 0xad: CLK(2); if (c) do { i_lodsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
384- case 0xae: CLK(2); if (c) do { i_scasb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
385- case 0xaf: CLK(2); if (c) do { i_scasw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break;
386- default: nec_instruction[next]();
387- }
388- seg_prefix=FALSE;
389-}
390-
391-OP( 0x65, i_repc ) { UINT32 next = FETCHOP; UINT16 c = I.regs.w[CW];
392- switch(next) { /* Segments */
393- case 0x26: seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; next = FETCHOP; CLK(2); break;
394- case 0x2e: seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; next = FETCHOP; CLK(2); break;
395- case 0x36: seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break;
396- case 0x3e: seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; next = FETCHOP; CLK(2); break;
397- }
398-
399- switch(next) {
400- case 0x6c: CLK(2); if (c) do { i_insb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
401- case 0x6d: CLK(2); if (c) do { i_insw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
402- case 0x6e: CLK(2); if (c) do { i_outsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
403- case 0x6f: CLK(2); if (c) do { i_outsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
404- case 0xa4: CLK(2); if (c) do { i_movsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
405- case 0xa5: CLK(2); if (c) do { i_movsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
406- case 0xa6: CLK(2); if (c) do { i_cmpsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
407- case 0xa7: CLK(2); if (c) do { i_cmpsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
408- case 0xaa: CLK(2); if (c) do { i_stosb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
409- case 0xab: CLK(2); if (c) do { i_stosw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
410- case 0xac: CLK(2); if (c) do { i_lodsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
411- case 0xad: CLK(2); if (c) do { i_lodsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
412- case 0xae: CLK(2); if (c) do { i_scasb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
413- case 0xaf: CLK(2); if (c) do { i_scasw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break;
414- default: nec_instruction[next]();
415- }
416- seg_prefix=FALSE;
417-}
418-
419-OP( 0x68, i_push_d16 ) { UINT32 tmp; FETCHWORD(tmp); PUSH(tmp); CLK(1); }
420-OP( 0x69, i_imul_d16 ) { UINT32 tmp; DEF_r16w; FETCHWORD(tmp); dst = (INT32)((INT16)src)*(INT32)((INT16)tmp); I.CarryVal = I.OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); RegWord(ModRM)=(WORD)dst; CLKM(4,3);}
421-OP( 0x6a, i_push_d8 ) { UINT32 tmp = (WORD)((INT16)((INT8)FETCH)); PUSH(tmp); CLK(1); }
422-OP( 0x6b, i_imul_d8 ) { UINT32 src2; DEF_r16w; src2= (WORD)((INT16)((INT8)FETCH)); dst = (INT32)((INT16)src)*(INT32)((INT16)src2); I.CarryVal = I.OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); RegWord(ModRM)=(WORD)dst; CLKM(4,3); }
423-OP( 0x6c, i_insb ) { PutMemB(ES,I.regs.w[IY],read_port(I.regs.w[DW])); I.regs.w[IY]+= -2 * I.DF + 1; CLK(6); }
424-OP( 0x6d, i_insw ) { PutMemB(ES,I.regs.w[IY],read_port(I.regs.w[DW])); PutMemB(ES,(I.regs.w[IY]+1)&0xffff,read_port((I.regs.w[DW]+1)&0xffff)); I.regs.w[IY]+= -4 * I.DF + 2; CLK(6); }
425-OP( 0x6e, i_outsb ) { write_port(I.regs.w[DW],GetMemB(DS,I.regs.w[IX])); I.regs.w[IX]+= -2 * I.DF + 1; CLK(7); }
426-OP( 0x6f, i_outsw ) { write_port(I.regs.w[DW],GetMemB(DS,I.regs.w[IX])); write_port((I.regs.w[DW]+1)&0xffff,GetMemB(DS,(I.regs.w[IX]+1)&0xffff)); I.regs.w[IX]+= -4 * I.DF + 2; CLK(7); }
427-
428-OP( 0x70, i_jo ) { JMP( OF); CLK(1); }
429-OP( 0x71, i_jno ) { JMP(!OF); CLK(1); }
430-OP( 0x72, i_jc ) { JMP( CF); CLK(1); }
431-OP( 0x73, i_jnc ) { JMP(!CF); CLK(1); }
432-OP( 0x74, i_jz ) { JMP( ZF); CLK(1); }
433-OP( 0x75, i_jnz ) { JMP(!ZF); CLK(1); }
434-OP( 0x76, i_jce ) { JMP(CF || ZF); CLK(1); }
435-OP( 0x77, i_jnce ) { JMP(!(CF || ZF)); CLK(1); }
436-OP( 0x78, i_js ) { JMP( SF); CLK(1); }
437-OP( 0x79, i_jns ) { JMP(!SF); CLK(1); }
438-OP( 0x7a, i_jp ) { JMP( PF); CLK(1); }
439-OP( 0x7b, i_jnp ) { JMP(!PF); CLK(1); }
440-OP( 0x7c, i_jl ) { JMP((SF!=OF)&&(!ZF)); CLK(1); }
441-OP( 0x7d, i_jnl ) { JMP((ZF)||(SF==OF)); CLK(1); }
442-OP( 0x7e, i_jle ) { JMP((ZF)||(SF!=OF)); CLK(1); }
443-OP( 0x7f, i_jnle ) { JMP((SF==OF)&&(!ZF)); CLK(1); }
444-
445-OP( 0x80, i_80pre ) { UINT32 dst, src; GetModRM; dst = GetRMByte(ModRM); src = FETCH;
446- CLKM(3,1)
447- switch (ModRM & 0x38) {
448- case 0x00: ADDB; PutbackRMByte(ModRM,dst); break;
449- case 0x08: ORB; PutbackRMByte(ModRM,dst); break;
450- case 0x10: src+=CF; ADDB; PutbackRMByte(ModRM,dst); break;
451- case 0x18: src+=CF; SUBB; PutbackRMByte(ModRM,dst); break;
452- case 0x20: ANDB; PutbackRMByte(ModRM,dst); break;
453- case 0x28: SUBB; PutbackRMByte(ModRM,dst); break;
454- case 0x30: XORB; PutbackRMByte(ModRM,dst); break;
455- case 0x38: SUBB; break; /* CMP */
456- }
457-}
458-
459-OP( 0x81, i_81pre ) { UINT32 dst, src; GetModRM; dst = GetRMWord(ModRM); src = FETCH; src+= (FETCH << 8);
460- CLKM(3,1)
461- switch (ModRM & 0x38) {
462- case 0x00: ADDW; PutbackRMWord(ModRM,dst); break;
463- case 0x08: ORW; PutbackRMWord(ModRM,dst); break;
464- case 0x10: src+=CF; ADDW; PutbackRMWord(ModRM,dst); break;
465- case 0x18: src+=CF; SUBW; PutbackRMWord(ModRM,dst); break;
466- case 0x20: ANDW; PutbackRMWord(ModRM,dst); break;
467- case 0x28: SUBW; PutbackRMWord(ModRM,dst); break;
468- case 0x30: XORW; PutbackRMWord(ModRM,dst); break;
469- case 0x38: SUBW; break; /* CMP */
470- }
471-}
472-
473-OP( 0x82, i_82pre ) { UINT32 dst, src; GetModRM; dst = GetRMByte(ModRM); src = (BYTE)((INT8)FETCH);
474- CLKM(3,1)
475- switch (ModRM & 0x38) {
476- case 0x00: ADDB; PutbackRMByte(ModRM,dst); break;
477- case 0x08: ORB; PutbackRMByte(ModRM,dst); break;
478- case 0x10: src+=CF; ADDB; PutbackRMByte(ModRM,dst); break;
479- case 0x18: src+=CF; SUBB; PutbackRMByte(ModRM,dst); break;
480- case 0x20: ANDB; PutbackRMByte(ModRM,dst); break;
481- case 0x28: SUBB; PutbackRMByte(ModRM,dst); break;
482- case 0x30: XORB; PutbackRMByte(ModRM,dst); break;
483- case 0x38: SUBB; break; /* CMP */
484- }
485-}
486-
487-OP( 0x83, i_83pre ) { UINT32 dst, src; GetModRM; dst = GetRMWord(ModRM); src = (WORD)((INT16)((INT8)FETCH));
488- CLKM(3,1)
489- switch (ModRM & 0x38) {
490- case 0x00: ADDW; PutbackRMWord(ModRM,dst); break;
491- case 0x08: ORW; PutbackRMWord(ModRM,dst); break;
492- case 0x10: src+=CF; ADDW; PutbackRMWord(ModRM,dst); break;
493- case 0x18: src+=CF; SUBW; PutbackRMWord(ModRM,dst); break;
494- case 0x20: ANDW; PutbackRMWord(ModRM,dst); break;
495- case 0x28: SUBW; PutbackRMWord(ModRM,dst); break;
496- case 0x30: XORW; PutbackRMWord(ModRM,dst); break;
497- case 0x38: SUBW; break; /* CMP */
498- }
499-}
500-
501-OP( 0x84, i_test_br8 ) { DEF_br8; ANDB; CLKM(2,1); }
502-OP( 0x85, i_test_wr16 ) { DEF_wr16; ANDW; CLKM(2,1); }
503-OP( 0x86, i_xchg_br8 ) { DEF_br8; RegByte(ModRM)=dst; PutbackRMByte(ModRM,src); CLKM(5,3); }
504-OP( 0x87, i_xchg_wr16 ) { DEF_wr16; RegWord(ModRM)=dst; PutbackRMWord(ModRM,src); CLKM(5,3); }
505-
506-OP( 0x88, i_mov_br8 ) { UINT8 src; GetModRM; src = RegByte(ModRM); PutRMByte(ModRM,src); CLKM(1,1); }
507-OP( 0x89, i_mov_wr16 ) { UINT16 src; GetModRM; src = RegWord(ModRM); PutRMWord(ModRM,src); CLKM(1,1); }
508-OP( 0x8a, i_mov_r8b ) { UINT8 src; GetModRM; src = GetRMByte(ModRM); RegByte(ModRM)=src; CLKM(1,1); }
509-OP( 0x8b, i_mov_r16w ) { UINT16 src; GetModRM; src = GetRMWord(ModRM); RegWord(ModRM)=src; CLKM(1,1); }
510-OP( 0x8c, i_mov_wsreg ) { GetModRM; PutRMWord(ModRM,I.sregs[(ModRM & 0x38) >> 3]); CLKM(1,1); }
511-OP( 0x8d, i_lea ) { UINT16 ModRM = FETCH; (void)(*GetEA[ModRM])(); RegWord(ModRM)=EO; CLK(1); }
512-OP( 0x8e, i_mov_sregw ) { UINT16 src; GetModRM; src = GetRMWord(ModRM); CLKM(3,2);
513- switch (ModRM & 0x38) {
514- case 0x00: I.sregs[ES] = src; break; /* mov es,ew */
515- case 0x08: I.sregs[CS] = src; break; /* mov cs,ew */
516- case 0x10: I.sregs[SS] = src; break; /* mov ss,ew */
517- case 0x18: I.sregs[DS] = src; break; /* mov ds,ew */
518- default: ;
519- }
520- no_interrupt=1;
521-}
522-OP( 0x8f, i_popw ) { UINT16 tmp; GetModRM; POP(tmp); PutRMWord(ModRM,tmp); CLKM(3,1); }
523-OP( 0x90, i_nop ) { CLK(1);
524- /* Cycle skip for idle loops (0: NOP 1: JMP 0) */
525- if (no_interrupt==0 && nec_ICount>0 && (PEEKOP((I.sregs[CS]<<4)+I.ip))==0xeb && (PEEK((I.sregs[CS]<<4)+I.ip+1))==0xfd)
526- nec_ICount%=15;
527-}
528-OP( 0x91, i_xchg_axcx ) { XchgAWReg(CW); CLK(3); }
529-OP( 0x92, i_xchg_axdx ) { XchgAWReg(DW); CLK(3); }
530-OP( 0x93, i_xchg_axbx ) { XchgAWReg(BW); CLK(3); }
531-OP( 0x94, i_xchg_axsp ) { XchgAWReg(SP); CLK(3); }
532-OP( 0x95, i_xchg_axbp ) { XchgAWReg(BP); CLK(3); }
533-OP( 0x96, i_xchg_axsi ) { XchgAWReg(IX); CLK(3); }
534-OP( 0x97, i_xchg_axdi ) { XchgAWReg(IY); CLK(3); }
535-
536-OP( 0x98, i_cbw ) { I.regs.b[AH] = (I.regs.b[AL] & 0x80) ? 0xff : 0; CLK(1); }
537-OP( 0x99, i_cwd ) { I.regs.w[DW] = (I.regs.b[AH] & 0x80) ? 0xffff : 0; CLK(1); }
538-OP( 0x9a, i_call_far ) { UINT32 tmp, tmp2; FETCHWORD(tmp); FETCHWORD(tmp2); PUSH(I.sregs[CS]); PUSH(I.ip); I.ip = (WORD)tmp; I.sregs[CS] = (WORD)tmp2; CLK(10); }
539-OP( 0x9b, i_wait ) { ; }
540-OP( 0x9c, i_pushf ) { PUSH( CompressFlags() ); CLK(2); }
541-OP( 0x9d, i_popf ) { UINT32 tmp; POP(tmp); ExpandFlags(tmp); CLK(3);}
542-OP( 0x9e, i_sahf ) { UINT32 tmp = (CompressFlags() & 0xff00) | (I.regs.b[AH] & 0xd5); ExpandFlags(tmp); CLK(4); }
543-OP( 0x9f, i_lahf ) { I.regs.b[AH] = CompressFlags() & 0xff; CLK(2); }
544-
545-OP( 0xa0, i_mov_aldisp ) { UINT32 addr; FETCHWORD(addr); I.regs.b[AL] = GetMemB(DS, addr); CLK(1); }
546-OP( 0xa1, i_mov_axdisp ) { UINT32 addr; FETCHWORD(addr); I.regs.b[AL] = GetMemB(DS, addr); I.regs.b[AH] = GetMemB(DS, (addr+1)&0xffff); CLK(1); }
547-OP( 0xa2, i_mov_dispal ) { UINT32 addr; FETCHWORD(addr); PutMemB(DS, addr, I.regs.b[AL]); CLK(1); }
548-OP( 0xa3, i_mov_dispax ) { UINT32 addr; FETCHWORD(addr); PutMemB(DS, addr, I.regs.b[AL]); PutMemB(DS, (addr+1)&0xffff, I.regs.b[AH]); CLK(1); }
549-OP( 0xa4, i_movsb ) { UINT32 tmp = GetMemB(DS,I.regs.w[IX]); PutMemB(ES,I.regs.w[IY], tmp); I.regs.w[IY] += -2 * I.DF + 1; I.regs.w[IX] += -2 * I.DF + 1; CLK(5); }
550-OP( 0xa5, i_movsw ) { UINT32 tmp = GetMemW(DS,I.regs.w[IX]); PutMemW(ES,I.regs.w[IY], tmp); I.regs.w[IY] += -4 * I.DF + 2; I.regs.w[IX] += -4 * I.DF + 2; CLK(5); }
551-OP( 0xa6, i_cmpsb ) { UINT32 src = GetMemB(ES, I.regs.w[IY]); UINT32 dst = GetMemB(DS, I.regs.w[IX]); SUBB; I.regs.w[IY] += -2 * I.DF + 1; I.regs.w[IX] += -2 * I.DF + 1; CLK(6); }
552-OP( 0xa7, i_cmpsw ) { UINT32 src = GetMemW(ES, I.regs.w[IY]); UINT32 dst = GetMemW(DS, I.regs.w[IX]); SUBW; I.regs.w[IY] += -4 * I.DF + 2; I.regs.w[IX] += -4 * I.DF + 2; CLK(6); }
553-
554-OP( 0xa8, i_test_ald8 ) { DEF_ald8; ANDB; CLK(1); }
555-OP( 0xa9, i_test_axd16 ) { DEF_axd16; ANDW; CLK(1); }
556-OP( 0xaa, i_stosb ) { PutMemB(ES,I.regs.w[IY],I.regs.b[AL]); I.regs.w[IY] += -2 * I.DF + 1; CLK(3); }
557-OP( 0xab, i_stosw ) { PutMemW(ES,I.regs.w[IY],I.regs.w[AW]); I.regs.w[IY] += -4 * I.DF + 2; CLK(3); }
558-OP( 0xac, i_lodsb ) { I.regs.b[AL] = GetMemB(DS,I.regs.w[IX]); I.regs.w[IX] += -2 * I.DF + 1; CLK(3); }
559-OP( 0xad, i_lodsw ) { I.regs.w[AW] = GetMemW(DS,I.regs.w[IX]); I.regs.w[IX] += -4 * I.DF + 2; CLK(3); }
560-OP( 0xae, i_scasb ) { UINT32 src = GetMemB(ES, I.regs.w[IY]); UINT32 dst = I.regs.b[AL]; SUBB; I.regs.w[IY] += -2 * I.DF + 1; CLK(4); }
561-OP( 0xaf, i_scasw ) { UINT32 src = GetMemW(ES, I.regs.w[IY]); UINT32 dst = I.regs.w[AW]; SUBW; I.regs.w[IY] += -4 * I.DF + 2; CLK(4); }
562-
563-OP( 0xb0, i_mov_ald8 ) { I.regs.b[AL] = FETCH; CLK(1); }
564-OP( 0xb1, i_mov_cld8 ) { I.regs.b[CL] = FETCH; CLK(1); }
565-OP( 0xb2, i_mov_dld8 ) { I.regs.b[DL] = FETCH; CLK(1); }
566-OP( 0xb3, i_mov_bld8 ) { I.regs.b[BL] = FETCH; CLK(1); }
567-OP( 0xb4, i_mov_ahd8 ) { I.regs.b[AH] = FETCH; CLK(1); }
568-OP( 0xb5, i_mov_chd8 ) { I.regs.b[CH] = FETCH; CLK(1); }
569-OP( 0xb6, i_mov_dhd8 ) { I.regs.b[DH] = FETCH; CLK(1); }
570-OP( 0xb7, i_mov_bhd8 ) { I.regs.b[BH] = FETCH; CLK(1); }
571-
572-OP( 0xb8, i_mov_axd16 ) { I.regs.b[AL] = FETCH; I.regs.b[AH] = FETCH; CLK(1); }
573-OP( 0xb9, i_mov_cxd16 ) { I.regs.b[CL] = FETCH; I.regs.b[CH] = FETCH; CLK(1); }
574-OP( 0xba, i_mov_dxd16 ) { I.regs.b[DL] = FETCH; I.regs.b[DH] = FETCH; CLK(1); }
575-OP( 0xbb, i_mov_bxd16 ) { I.regs.b[BL] = FETCH; I.regs.b[BH] = FETCH; CLK(1); }
576-OP( 0xbc, i_mov_spd16 ) { I.regs.b[SPL] = FETCH; I.regs.b[SPH] = FETCH; CLK(1); }
577-OP( 0xbd, i_mov_bpd16 ) { I.regs.b[BPL] = FETCH; I.regs.b[BPH] = FETCH; CLK(1); }
578-OP( 0xbe, i_mov_sid16 ) { I.regs.b[IXL] = FETCH; I.regs.b[IXH] = FETCH; CLK(1); }
579-OP( 0xbf, i_mov_did16 ) { I.regs.b[IYL] = FETCH; I.regs.b[IYH] = FETCH; CLK(1); }
580-
581-OP( 0xc0, i_rotshft_bd8 ) {
582- UINT32 src, dst; UINT8 c;
583- GetModRM; src = (unsigned)GetRMByte(ModRM); dst=src;
584- c=FETCH;
585- c&=0x1f;
586- CLKM(5,3);
587- if (c) switch (ModRM & 0x38) {
588- case 0x00: do { ROL_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
589- case 0x08: do { ROR_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
590- case 0x10: do { ROLC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
591- case 0x18: do { RORC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break;
592- case 0x20: SHL_BYTE(c); I.AuxVal = 1; break;//
593- case 0x28: SHR_BYTE(c); I.AuxVal = 1; break;//
594- case 0x30: break;
595- case 0x38: SHRA_BYTE(c); break;
596- }
597-}
598-
599-OP( 0xc1, i_rotshft_wd8 ) {
600- UINT32 src, dst; UINT8 c;
601- GetModRM; src = (unsigned)GetRMWord(ModRM); dst=src;
602- c=FETCH;
603- c&=0x1f;
604- CLKM(5,3);
605- if (c) switch (ModRM & 0x38) {
606- case 0x00: do { ROL_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
607- case 0x08: do { ROR_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
608- case 0x10: do { ROLC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
609- case 0x18: do { RORC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break;
610- case 0x20: SHL_WORD(c); I.AuxVal = 1; break;
611- case 0x28: SHR_WORD(c); I.AuxVal = 1; break;
612- case 0x30: break;
613- case 0x38: SHRA_WORD(c); break;
614- }
615-}
616-
617-OP( 0xc2, i_ret_d16 ) { UINT32 count = FETCH; count += FETCH << 8; POP(I.ip); I.regs.w[SP]+=count; CLK(6); }
618-OP( 0xc3, i_ret ) { POP(I.ip); CLK(6); }
619-OP( 0xc4, i_les_dw ) { GetModRM; WORD tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; I.sregs[ES] = GetnextRMWord; CLK(6); }
620-OP( 0xc5, i_lds_dw ) { GetModRM; WORD tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; I.sregs[DS] = GetnextRMWord; CLK(6); }
621-OP( 0xc6, i_mov_bd8 ) { GetModRM; PutImmRMByte(ModRM); CLK(1); }
622-OP( 0xc7, i_mov_wd16 ) { GetModRM; PutImmRMWord(ModRM); CLK(1); }
623-
624-OP( 0xc8, i_enter ) {
625- UINT32 nb = FETCH;
626- UINT32 i,level;
627-
628- CLK(19);
629- nb += FETCH << 8;
630- level = FETCH;
631- PUSH(I.regs.w[BP]);
632- I.regs.w[BP]=I.regs.w[SP];
633- I.regs.w[SP] -= nb;
634- for (i=1;i<level;i++) {
635- PUSH(GetMemW(SS,I.regs.w[BP]-i*2));
636- CLK(4);
637- }
638- if (level) PUSH(I.regs.w[BP]);
639-}
640-OP( 0xc9, i_leave ) {
641- I.regs.w[SP]=I.regs.w[BP];
642- POP(I.regs.w[BP]);
643- CLK(2);
644-}
645-OP( 0xca, i_retf_d16 ) { UINT32 count = FETCH; count += FETCH << 8; POP(I.ip); POP(I.sregs[CS]); I.regs.w[SP]+=count; CLK(9); }
646-OP( 0xcb, i_retf ) { POP(I.ip); POP(I.sregs[CS]); CLK(8); }
647-OP( 0xcc, i_int3 ) { nec_interrupt(3,0); CLK(9); }
648-OP( 0xcd, i_int ) { nec_interrupt(FETCH,0); CLK(10); }
649-OP( 0xce, i_into ) { if (OF) { nec_interrupt(4,0); CLK(13); } else CLK(6); }
650-OP( 0xcf, i_iret ) { POP(I.ip); POP(I.sregs[CS]); i_popf(); CLK(10); }
651-
652-OP( 0xd0, i_rotshft_b ) {
653- UINT32 src, dst; GetModRM; src = (UINT32)GetRMByte(ModRM); dst=src;
654- CLKM(3,1);
655- switch (ModRM & 0x38) {
656- case 0x00: ROL_BYTE; PutbackRMByte(ModRM,(BYTE)dst); I.OverVal = (src^dst)&0x80; break;
657- case 0x08: ROR_BYTE; PutbackRMByte(ModRM,(BYTE)dst); I.OverVal = (src^dst)&0x80; break;
658- case 0x10: ROLC_BYTE; PutbackRMByte(ModRM,(BYTE)dst); I.OverVal = (src^dst)&0x80; break;
659- case 0x18: RORC_BYTE; PutbackRMByte(ModRM,(BYTE)dst); I.OverVal = (src^dst)&0x80; break;
660- case 0x20: SHL_BYTE(1); I.OverVal = (src^dst)&0x80;I.AuxVal = 1; break;
661- case 0x28: SHR_BYTE(1); I.OverVal = (src^dst)&0x80;I.AuxVal = 1; break;
662- case 0x30: break;
663- case 0x38: SHRA_BYTE(1); I.OverVal = 0; break;
664- }
665-}
666-
667-OP( 0xd1, i_rotshft_w ) {
668- UINT32 src, dst; GetModRM; src = (UINT32)GetRMWord(ModRM); dst=src;
669- CLKM(3,1);
670- switch (ModRM & 0x38) {
671- case 0x00: ROL_WORD; PutbackRMWord(ModRM,(WORD)dst); I.OverVal = (src^dst)&0x8000; break;
672- case 0x08: ROR_WORD; PutbackRMWord(ModRM,(WORD)dst); I.OverVal = (src^dst)&0x8000; break;
673- case 0x10: ROLC_WORD; PutbackRMWord(ModRM,(WORD)dst); I.OverVal = (src^dst)&0x8000; break;
674- case 0x18: RORC_WORD; PutbackRMWord(ModRM,(WORD)dst); I.OverVal = (src^dst)&0x8000; break;
675- case 0x20: SHL_WORD(1); I.AuxVal = 1;I.OverVal = (src^dst)&0x8000; break;
676- case 0x28: SHR_WORD(1); I.AuxVal = 1;I.OverVal = (src^dst)&0x8000; break;
677- case 0x30: break;
678- case 0x38: SHRA_WORD(1); I.AuxVal = 1;I.OverVal = 0; break;
679- }
680-}
681-
682-OP( 0xd2, i_rotshft_bcl ) {
683- UINT32 src, dst; UINT8 c; GetModRM; src = (UINT32)GetRMByte(ModRM); d