Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
716 lvd 1
#include "std.h"
2
 
3
#include "resource.h"
4
 
5
#include "emul.h"
6
#include "vars.h"
7
#include "dx.h"
8
#include "memory.h"
9
 
10
#include "util.h"
11
 
12
unsigned char wavhdr[]= {
13
   0x52,0x49,0x46,0x46,0xcc,0xf6,0x3e,0x00,
14
   0x57,0x41,0x56,0x45,0x66,0x6d,0x74,0x20,
15
   0x10,0x00,0x00,0x00,0x01,0x00,0x02,0x00,
16
   0x22,0x56,0x00,0x00,0x88,0x58,0x01,0x00,
17
   0x04,0x00,0x10,0x00,0x64,0x61,0x74,0x61,
18
   0xa8,0xf6,0x3e,0x00
19
};
20
#pragma pack(1)
21
static struct
22
{
23
   unsigned short sig;
24
   unsigned char stereo;
25
   unsigned short start;
26
   unsigned ayfq;
27
   unsigned char intfq;
28
   unsigned short year;
29
   unsigned rawsize;
30
} vtxheader;
31
#pragma pack()
32
bool silence(unsigned pos)
33
{
34
   return !(vtxbuf[pos+8] | vtxbuf[pos+9] | vtxbuf[pos+10]) ||
35
          (vtxbuf[pos+7] & 0x3F) == 0x3F;
36
}
37
INT_PTR CALLBACK VtxDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp);
38
unsigned vtxyear, vtxchip;
39
char vtxname[200], vtxauthor[200], vtxsoft[200], vtxtracker[200], vtxcomm[200];
40
 
41
void savesnddialog()
42
{
43
   OnExitGui(); //Alone Coder
44
   unsigned end; //Alone Coder 0.36.7
45
   if (savesndtype) {
46
      if (savesndtype == 1) { // wave
47
         unsigned fsize = ftell(savesnd);
48
         fseek(savesnd, 0, SEEK_SET);
49
         fsize -= sizeof wavhdr;
50
         *(unsigned*)(wavhdr+4) = fsize+0x2c-8;
51
         *(unsigned*)(wavhdr+0x28) = fsize;
52
         fwrite(wavhdr, 1, sizeof wavhdr, savesnd);
53
         MessageBox(wnd, "WAV save done", "Save sound", MB_ICONINFORMATION);
54
      } else { // vtx
55
         savesndtype = 0;
56
         unsigned char *newb = (unsigned char*)malloc(vtxbuffilled);
57
         for (/*unsigned*/ end = 0; end < (int)vtxbuffilled && silence(end); end += 14);
58
         vtxbuffilled -= end; memcpy(vtxbuf, vtxbuf+end, vtxbuffilled);
59
         for (end = vtxbuffilled; end && silence(end-14); end -= 14);
60
         vtxbuffilled = end;
61
         int nrec = vtxbuffilled/14;
62
         for (int i = 0; i < nrec; i++)
63
            for (int j = 0; j < 14; j++)
64
               newb[j*nrec+i] = vtxbuf[i*14+j];
65
         free(vtxbuf);
66
         FILE *ff = fopen("vtx.tmp", "wb");
67
         if (!ff) return;
68
         fwrite(newb, 1, vtxbuffilled, ff);
69
         fclose(ff);
70
         STARTUPINFO si = { sizeof si };
71
         si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE;
72
         PROCESS_INFORMATION pi;
73
         char Parh[] = "lha a vtx.lzh vtx.tmp";
74
         if (CreateProcess(0, Parh, 0, 0, 0, 0, 0, 0, &si, &pi))
75
         {
76
            WaitForSingleObject(pi.hProcess, 5000);
77
            CloseHandle(pi.hProcess);
78
            CloseHandle(pi.hThread);
79
            DeleteFile("vtx.tmp");
80
         }
81
         else
82
         {
83
            DeleteFile("vtx.tmp");
84
            MessageBox(wnd, "LHA.EXE not found in %PATH%", 0, MB_ICONERROR);
85
            return;
86
         }
87
         ff = fopen("vtx.lzh", "rb"); if (!ff) return;
88
         fseek(ff, 0x22, SEEK_SET);
89
         unsigned packed = fread(newb, 1, vtxbuffilled, ff)-1;
90
         fclose(ff); DeleteFile("vtx.lzh");
91
         DialogBox(hIn, MAKEINTRESOURCE(IDD_VTX), wnd, VtxDlg);
92
         vtxheader.sig = (vtxchip & 1) ? WORD2('y','m') : WORD2('a','y');
93
         static unsigned char ste[] = { 1, 2, 0 };
94
         vtxheader.stereo = ste[vtxchip/2];
95
         vtxheader.ayfq = conf.sound.ayfq;
96
         vtxheader.intfq = 50;
97
         vtxheader.year = vtxyear;
98
         vtxheader.rawsize = vtxbuffilled;
99
         fwrite(&vtxheader, 1, 0x10, savesnd);
100
         fwrite(vtxname, 1, strlen(vtxname)+1, savesnd);
101
         fwrite(vtxauthor, 1, strlen(vtxauthor)+1, savesnd);
102
         fwrite(vtxsoft, 1, strlen(vtxsoft)+1, savesnd);
103
         fwrite(vtxtracker, 1, strlen(vtxtracker)+1, savesnd);
104
         fwrite(vtxcomm, 1, strlen(vtxcomm)+1, savesnd);
105
         fwrite(newb, 1, packed, savesnd);
106
      }
107
      fclose(savesnd);
108
      savesndtype = 0;
109
   } else {
110
      OPENFILENAME ofn = { 0 };
111
      char sndsavename[0x200]; *sndsavename = 0;
112
 
113
      ofn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME);
114
      ofn.lpstrFilter = "All sound (WAV)\0*.wav\0AY sound (VTX)\0*.vtx\0";
115
      ofn.lpstrFile = sndsavename; ofn.nMaxFile = sizeof sndsavename;
116
      ofn.lpstrTitle = "Save Sound";
117
      ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
118
      ofn.hwndOwner = wnd;
119
      ofn.nFilterIndex = 1;
120
      if (GetSaveFileName(&ofn)) {
121
         char *name = sndsavename; for (char *x = name; *x; x++) if (*x == '\\') name = x+1;
122
         if (!strchr(name, '.')) {
123
            if (ofn.nFilterIndex == 1) strcat(sndsavename, ".wav");
124
            else strcat(sndsavename, ".vtx");
125
         }
126
         savesnd = fopen(ofn.lpstrFile, "wb");
127
         if (!savesnd) MessageBox(wnd, "Can't create file", 0, MB_ICONERROR);
128
         else if (ofn.nFilterIndex == 2) { // vtx
129
            savesndtype = 2;
130
            vtxbuf = 0;
131
         } else { // wave. all params, except fq are fixed: 16bit,stereo
132
            *(unsigned*)(wavhdr+0x18) = conf.sound.fq; // fq
133
            *(unsigned*)(wavhdr+0x1C) = conf.sound.fq*4; // bitrate
134
            fwrite(wavhdr, 1, 44, savesnd); // header
135
            savesndtype = 1;
136
         }
137
      }
138
   }
139
   eat();
140
   OnExitGui(); //Alone Coder
141
}
142
 
143
INT_PTR CALLBACK VtxDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
144
{
145
   if (msg == WM_INITDIALOG) {
146
      static char chips[] = "ABC AY\0ABC YM\0ACB AY\0ACB YM\0MONO AY\0MONO YM\0";
147
      for (char *str = chips; *str; str += strlen(str)+1)
148
         SendDlgItemMessage(dlg, IDC_VTXCHIP, CB_ADDSTRING, 0, (LPARAM)str);
149
      unsigned c = ((conf.sound.ay_voltab[8] == conf.sound.ay_voltab[9])?0:1) /* + (conf.ay_preset>2?0:conf.ay_preset*2) */;
150
      SendDlgItemMessage(dlg, IDC_VTXCHIP, CB_SETCURSEL, c, 0);
151
      SetFocus(GetDlgItem(dlg, IDE_VTXNAME));
152
      return 1;
153
   }
154
   if ((msg == WM_SYSCOMMAND && (wp & 0xFFF0) == SC_CLOSE) ||
155
       (msg == WM_COMMAND && LOWORD(wp) == IDOK))
156
   {
157
      SendDlgItemMessage(dlg, IDE_VTXNAME, WM_GETTEXT, sizeof vtxname, (LPARAM)vtxname);
158
      SendDlgItemMessage(dlg, IDE_VTXAUTH, WM_GETTEXT, sizeof vtxauthor, (LPARAM)vtxauthor);
159
      SendDlgItemMessage(dlg, IDE_VTXSOFT, WM_GETTEXT, sizeof vtxsoft, (LPARAM)vtxsoft);
160
      SendDlgItemMessage(dlg, IDE_VTXTRACK, WM_GETTEXT, sizeof vtxtracker, (LPARAM)vtxtracker);
161
      SendDlgItemMessage(dlg, IDE_VTXCOMM, WM_GETTEXT, sizeof vtxcomm, (LPARAM)vtxcomm);
162
      vtxchip = SendDlgItemMessage(dlg, IDC_VTXCHIP, CB_GETCURSEL, 0, 0);
163
      char xx[20]; SendDlgItemMessage(dlg, IDE_VTXYEAR, WM_GETTEXT, sizeof xx, (LPARAM)xx);
164
      vtxyear = atoi(xx);
165
      EndDialog(dlg, 1);
166
   }
167
   return 0;
168
}
169
 
170
int dopoke(int really)
171
{
172
   for (unsigned char *ptr = snbuf; *ptr; ) {
173
      while (*ptr == ' ' || *ptr == ':' || *ptr == ';' || *ptr == ',') ptr++;
174
      unsigned num = 0;
175
      while (isdigit(*ptr)) num = num*10 + (*ptr++ - '0');
176
      if (num < 0x4000 || num > 0xFFFF) return ptr-snbuf+1;
177
      while (*ptr == ' ' || *ptr == ':' || *ptr == ';' || *ptr == ',') ptr++;
178
      unsigned val = 0;
179
      while (isdigit(*ptr)) val = val*10 + (*ptr++ - '0');
180
      if (val > 0xFF) return ptr-snbuf+1;
181
      while (*ptr == ' ' || *ptr == ':' || *ptr == ';' || *ptr == ',') ptr++;
182
      if (really)
183
          cpu.DirectWm(num, val);
184
   }
185
   return 0;
186
}
187
 
188
INT_PTR CALLBACK pokedlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
189
{
190
   if (msg == WM_INITDIALOG) {
191
      SetFocus(GetDlgItem(dlg, IDE_POKE));
192
      return 1;
193
   }
194
   if ((msg == WM_COMMAND && wp == IDCANCEL) ||
195
       (msg == WM_SYSCOMMAND && (wp & 0xFFF0) == SC_CLOSE)) EndDialog(dlg, 0);
196
   if (msg == WM_COMMAND && LOWORD(wp) == IDOK)
197
   {
198
      SendDlgItemMessage(dlg, IDE_POKE, WM_GETTEXT, /*sizeof snbuf*/640*480*4, (LPARAM)snbuf); //Alone Coder 0.36.5
199
          int r = dopoke(0);
200
      if (r) MessageBox(dlg, "Incorrect format", 0, MB_ICONERROR),
201
             SendDlgItemMessage(dlg, IDE_POKE, EM_SETSEL, r, r);
202
      else dopoke(1), EndDialog(dlg, 0);
203
   }
204
   return 0;
205
}