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 <io.h>
4
#include <fcntl.h>
5
#include <sys/stat.h>
6
 
7
#include "emul.h"
8
#include "vars.h"
9
#include "memory.h"
10
#include "debug.h"
11
#include "dbglabls.h"
12
#include "draw.h"
13
#include "dx.h"
14
#include "fontatm2.h"
15
#include "snapshot.h"
784 DimkaM 16
#include "sndrender/sndcounter.h"
716 lvd 17
#include "sound.h"
18
#include "sdcard.h"
784 DimkaM 19
#include "gs.h"
716 lvd 20
#include "zc.h"
21
#include "util.h"
22
#include "init.h"
784 DimkaM 23
#include "config.h"
819 DimkaM 24
#include "zxusbnet.h"
716 lvd 25
 
26
char load_errors;
27
 
28
void loadkeys(action*);
29
void loadzxkeys(CONFIG*);
30
void load_arch(const char*);
31
 
784 DimkaM 32
static unsigned load_rom(const char *path, unsigned char *bank, unsigned max_banks = 1)
716 lvd 33
{
34
   if (!*path) { norom: memset(bank, 0xFF, max_banks*PAGE); return 0; }
35
   char tmp[FILENAME_MAX]; strcpy(tmp, path);
36
   char *x = strrchr(tmp+2, ':');
37
   unsigned page = 0;
784 DimkaM 38
   if (x) { *x = 0; page = unsigned(atoi(x+1)); }
716 lvd 39
   if (max_banks == 16) page *= 16; // bank for scorp prof.rom
40
 
41
   FILE *ff = fopen(tmp, "rb");
42
 
43
   if (!ff) {
44
      errmsg("ROM file %s not found", tmp);
45
   err:
46
      load_errors = 1;
47
      goto norom;
48
   }
49
 
784 DimkaM 50
   if (fseek(ff, long(page*PAGE), SEEK_SET)) {
716 lvd 51
badrom:
52
      fclose(ff);
53
      errmsg("Incorrect ROM file: %s", path);
54
      goto err;
55
   }
56
 
784 DimkaM 57
   size_t size = fread(bank, 1, max_banks*PAGE, ff);
716 lvd 58
   if (!size || (size & (PAGE-1))) goto badrom;
59
 
60
   fclose(ff);
784 DimkaM 61
   return unsigned(size / 1024);
716 lvd 62
}
63
 
64
void load_atm_font()
65
{
66
   FILE *ff = fopen("SGEN.ROM", "rb");
67
   if (!ff)
68
   {
69
       memcpy(fontatm2, fontatm2_default, sizeof(fontatm2));
70
       return;
71
   }
72
   unsigned char font[0x800];
784 DimkaM 73
   size_t sz = fread(font, 1, 0x800, ff);
716 lvd 74
   if (sz == 0x800) {
75
      color(CONSCLR_INFO);
76
      printf("using ATM font from external SGEN.ROM\n");
77
      for (unsigned chr = 0; chr < 0x100; chr++)
78
         for (unsigned l = 0; l < 8; l++)
79
            fontatm2[chr+l*0x100] = font[chr*8+l];
80
   }
81
   fclose(ff);
82
}
83
 
784 DimkaM 84
static void load_atariset()
716 lvd 85
{
86
   memset(temp.ataricolors, 0, sizeof temp.ataricolors);
87
   if (!conf.atariset[0])
88
       return;
89
   char defs[4000]; *defs = 0; // =12*256, strlen("07:aabbccdd,")=12
90
   char keyname[80];
91
   sprintf(keyname, "atari.%s", conf.atariset);
92
   GetPrivateProfileString("COLORS", keyname, nil, defs, sizeof defs, ininame);
93
   if (!*defs)
94
       conf.atariset[0] = 0;
95
   for (char *ptr = defs; *ptr; )
96
   {
97
      if (ptr[2] != ':')
98
          return;
99
      for (int i = 0; i < 11; i++)
100
         if (i != 2 && !ishex(ptr[i]))
101
             return;
102
      unsigned index, val;
103
      sscanf(ptr, "%02X:%08X", &index, &val);
104
      temp.ataricolors[index] = val;
105
      // temp.ataricolors[(index*16 + index/16) & 0xFF] = val; // swap ink-paper
106
      ptr += 12;
107
      if (ptr [-1] != ',')
108
          return;
109
   }
110
}
111
 
784 DimkaM 112
void addpath(char *dst, const char *fname)
716 lvd 113
{
114
   if (!fname)
115
       fname = dst;
116
   else
117
       strcpy(dst, fname);
118
   if (!*fname)
119
       return; // empty filenames have special meaning
120
   if (fname[1] == ':' || (fname[0] == '\\' || fname[1] == '\\'))
121
       return; // already full name
122
 
123
   char tmp[FILENAME_MAX];
784 DimkaM 124
   GetModuleFileName(nullptr, tmp, sizeof tmp);
716 lvd 125
   char *xx = strrchr(tmp, '\\');
126
   if (*fname == '?')
127
       *xx = 0; // "?" to get exe directory
128
   else
129
       strcpy(xx+1, fname);
130
   strcpy(dst, tmp);
131
}
132
 
133
void save_nv()
134
{
784 DimkaM 135
   char line[FILENAME_MAX]; addpath(line, "CMOS");
716 lvd 136
   FILE *f0 = fopen(line, "wb");
784 DimkaM 137
   if(f0)
138
   {
139
       fwrite(cmos, 1, sizeof cmos, f0);
140
       fclose(f0);
141
   }
716 lvd 142
 
143
   addpath(line, "NVRAM");
784 DimkaM 144
   if((f0 = fopen(line, "wb")))
145
   {
146
       fwrite(nvram, 1, sizeof nvram, f0);
147
       fclose(f0);
148
   }
716 lvd 149
}
150
 
151
void load_romset(CONFIG *conf, const char *romset)
152
{
153
   char sec[0x200];
154
   sprintf(sec, "ROM.%s", romset);
155
   GetPrivateProfileString(sec, "sos", nil, conf->sos_rom_path, sizeof conf->sos_rom_path, ininame);
156
   GetPrivateProfileString(sec, "dos", nil, conf->dos_rom_path, sizeof conf->dos_rom_path, ininame);
157
   GetPrivateProfileString(sec, "128", nil, conf->zx128_rom_path, sizeof conf->zx128_rom_path, ininame);
158
   GetPrivateProfileString(sec, "sys", nil, conf->sys_rom_path, sizeof conf->sys_rom_path, ininame);
159
   addpath(conf->sos_rom_path);
160
   addpath(conf->dos_rom_path);
161
   addpath(conf->zx128_rom_path);
162
   addpath(conf->sys_rom_path);
163
}
164
 
784 DimkaM 165
static void add_presets(const char *section, const char *prefix0, unsigned *num, char **tab, unsigned char *curr)
716 lvd 166
{
167
   *num = 0;
168
   char buf[0x7F00], defval[64];
169
   GetPrivateProfileSection(section, buf, sizeof buf, ininame);
170
   GetPrivateProfileString(section, prefix0, "none", defval, sizeof defval, ininame);
171
   char *p = strchr(defval, ';');
172
   if (p) *p = 0;
173
 
174
   for (p = defval+strlen(defval)-1; p>=defval && *p == ' '; *p-- = 0);
175
 
176
   char prefix[0x200];
177
   strcpy(prefix, prefix0);
178
   strcat(prefix, ".");
784 DimkaM 179
   size_t plen = strlen(prefix);
716 lvd 180
   for (char *ptr = buf; *ptr; )
181
   {
182
      if (!strnicmp(ptr, prefix, plen))
183
      {
184
         ptr += plen;
185
         tab[*num] = setptr;
186
         while (*ptr && *ptr != '=')
187
             *setptr++ = *ptr++;
188
         *setptr++ = 0;
189
 
190
         if (!stricmp(tab[*num], defval))
191
             *curr = (unsigned char)*num;
192
         (*num)++;
193
      }
194
      while (*ptr) ptr++;
195
      ptr++;
196
   }
197
}
198
 
199
void load_ula_preset()
200
{
201
   if (conf.ula_preset >= num_ula) return;
202
   char line[128], name[64];
203
   sprintf(name, "PRESET.%s", ulapreset[conf.ula_preset]);
204
   static char defaults[] = "71680,17989,224,50,32,0,0,0,0,0,320,240,24,32,384,288,48,64";
205
   GetPrivateProfileString("ULA", name, defaults, line, sizeof line, ininame);
206
   unsigned t1, t2, t3, t4, t5;
784 DimkaM 207
   sscanf(line, "%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u", &/*conf.frame*/frametime/*Alone Coder*/, &conf.paper,
716 lvd 208
       &conf.t_line, &conf.intfq, &conf.intlen, &t1, &t2, &t3, &t4, &t5,
209
       &conf.mcx_small, &conf.mcy_small, &conf.b_top_small, &conf.b_left_small,
210
       &conf.mcx_full, &conf.mcy_full, &conf.b_top_full, &conf.b_left_full);
211
   conf.even_M1 = (unsigned char)t1; conf.border_4T = (unsigned char)t2;
212
   conf.floatbus = (unsigned char)t3; conf.floatdos = (unsigned char)t4;
213
   conf.portff = t5 & 1;
214
 
215
   if(conf.mcx_small < 256)
216
       conf.mcx_small = 256;
217
   if(conf.mcy_small < 192)
218
       conf.mcy_small = 192;
219
 
220
   if(conf.mcx_full < 256)
221
       conf.mcx_full = 256;
222
   if(conf.mcy_full < 192)
223
       conf.mcy_full = 192;
224
 
225
   if(conf.b_left_full & 7)
226
   {
227
       err_printf("PRESET.%s:b_left_full not multiple of 8\n", ulapreset[conf.ula_preset]);
228
       exit();
229
   }
230
}
231
 
232
void load_ay_stereo()
233
{
234
   char line[128], name[64]; sprintf(name, "STEREO.%s", aystereo[conf.sound.ay_stereo]);
235
   GetPrivateProfileString("AY", name, "100,10,66,66,10,100", line, sizeof line, ininame);
236
   unsigned *stereo = conf.sound.ay_stereo_tab;
784 DimkaM 237
   sscanf(line, "%u,%u,%u,%u,%u,%u", stereo+0, stereo+1, stereo+2, stereo+3, stereo+4, stereo+5);
716 lvd 238
}
239
 
240
void load_ay_vols()
241
{
242
   char line[512] = { 0 };
243
   static char defaults[] = "0000,0340,04C0,06F2,0A44,0F13,1510,227E,289F,414E,5B21,7258,905E,B550,D7A0,FFFF";
244
   char name[64]; sprintf(name, "VOLTAB.%s", ayvols[conf.sound.ay_vols]);
245
   GetPrivateProfileString("AY", name, defaults, line, sizeof line, ininame);
246
   if (line[74] != ',') strcpy(line, defaults);
247
   if (line[79] == ',') { // YM
248
      for (int i = 0; i < 32; i++)
249
         sscanf(line+i*5, "%X", &conf.sound.ay_voltab[i]);
250
   } else { // AY
784 DimkaM 251
       for(int i = 0; i < 16; i++)
252
       {
253
           sscanf(line + i * 5, "%X", &conf.sound.ay_voltab[2 * i]);
254
           conf.sound.ay_voltab[2 * i + 1] = conf.sound.ay_voltab[2 * i];
255
       }
716 lvd 256
   }
257
}
258
 
259
void load_config(const char *fname)
260
{
261
   char line[FILENAME_MAX];
262
   load_errors = 0;
263
 
784 DimkaM 264
   GetModuleFileName(nullptr, ininame, sizeof ininame);
716 lvd 265
   strlwr(ininame); *(unsigned*)(strstr(ininame, ".exe")+1) = WORD4('i','n','i',0);
266
 
267
   if (fname && *fname) {
268
      char *dst = strrchr(ininame, '\\');
269
      if (strchr(fname, '/') || strchr(fname, '\\')) dst = ininame; else dst++;
270
      strcpy(dst, fname);
271
   }
272
   color(CONSCLR_DEFAULT); printf("ini: ");
273
   color(CONSCLR_INFO);    printf("%s\n", ininame);
274
 
784 DimkaM 275
   if (GetFileAttributes(ininame) == INVALID_FILE_ATTRIBUTES) errexit("config file not found");
716 lvd 276
 
277
   static const char* misc = "MISC";
278
   static const char* video = "VIDEO";
279
   static const char* ula = "ULA";
819 DimkaM 280
   static const char* beta128 = "Beta128";
281
   static const char* USBZXNET = "USBZXNET";
716 lvd 282
   static const char* leds = "LEDS";
283
   static const char* sound = "SOUND";
284
   static const char* input = "INPUT";
285
   static const char* colors = "COLORS";
286
   static const char* ay = "AY";
287
   static const char* saa1099 = "SAA1099";
288
   static const char* hdd = "HDD";
289
   static const char* rom = "ROM";
290
   static const char* ngs = "NGS";
291
   static const char* zc = "ZC";
292
 
293
   #ifdef MOD_MONITOR
294
   addpath(conf.sos_labels_path, "sos.l");
295
   #endif
296
 
297
   GetPrivateProfileString("*", "UNREAL", nil, line, sizeof line, ininame);
784 DimkaM 298
   unsigned a,b,c;
716 lvd 299
   sscanf(line, "%u.%u.%u", &a, &b, &c);
300
   if ((((a << 8U) | b) != VER_HL) || (c != (VER_A & 0x7F)))
301
       errexit("wrong ini-file version");
302
 
303
   GetPrivateProfileString(misc, "Help",  "help_eng.html", helpname, sizeof helpname, ininame);
304
   addpath(helpname);
305
 
306
   if (GetPrivateProfileInt(misc, "HideConsole", 0, ininame))
307
   {
308
       FreeConsole();
309
       nowait = 1;
310
   }
311
 
784 DimkaM 312
   conf.ConfirmExit = u8(GetPrivateProfileInt(misc, "ConfirmExit", 0, ininame));
716 lvd 313
 
784 DimkaM 314
   conf.sleepidle = u8(GetPrivateProfileInt(misc, "ShareCPU", 0, ininame));
315
   conf.highpriority = u8(GetPrivateProfileInt(misc, "HighPriority", 0, ininame));
716 lvd 316
   GetPrivateProfileString(misc, "SyncMode", "SOUND", line, sizeof line, ininame);
317
   conf.SyncMode = SM_SOUND;
318
   if(!strnicmp(line, "SOUND", 5))
319
       conf.SyncMode = SM_SOUND;
320
   else if(!strnicmp(line, "VIDEO", 5))
321
       conf.SyncMode = SM_VIDEO;
322
   else if(!strnicmp(line, "TSC", 3))
323
       conf.SyncMode = SM_TSC;
324
   conf.HighResolutionTimer = GetPrivateProfileInt(misc, "HighResolutionTimer", 0, ininame);
784 DimkaM 325
   conf.tape_traps = u8(GetPrivateProfileInt(misc, "TapeTraps", 1, ininame));
326
   conf.tape_autostart = u8(GetPrivateProfileInt(misc, "TapeAutoStart", 1, ininame));
327
   conf.EFF7_mask = u8(GetPrivateProfileInt(misc, "EFF7mask", 0, ininame));
716 lvd 328
 
329
   GetPrivateProfileString(rom, "ATM1", nil, conf.atm1_rom_path, sizeof conf.atm1_rom_path, ininame);
330
   GetPrivateProfileString(rom, "ATM2", nil, conf.atm2_rom_path, sizeof conf.atm2_rom_path, ininame);
331
   GetPrivateProfileString(rom, "ATM3", nil, conf.atm3_rom_path, sizeof conf.atm3_rom_path, ininame);
332
   GetPrivateProfileString(rom, "SCORP", nil, conf.scorp_rom_path, sizeof conf.scorp_rom_path, ininame);
333
   GetPrivateProfileString(rom, "PROFROM", nil, conf.prof_rom_path, sizeof conf.prof_rom_path, ininame);
334
   GetPrivateProfileString(rom, "PROFI", nil, conf.profi_rom_path, sizeof conf.profi_rom_path, ininame);
335
//[vv]   GetPrivateProfileString(rom, "KAY", nil, conf.kay_rom_path, sizeof conf.kay_rom_path, ininame);
336
   GetPrivateProfileString(rom, "PLUS3", nil, conf.plus3_rom_path, sizeof conf.plus3_rom_path, ininame);
337
   GetPrivateProfileString(rom, "QUORUM", nil, conf.quorum_rom_path, sizeof conf.quorum_rom_path, ininame);
338
   #ifdef MOD_GSZ80
339
   GetPrivateProfileString(rom, "GS", nil, conf.gs_rom_path, sizeof conf.gs_rom_path, ininame);
340
   addpath(conf.gs_rom_path);
341
   #endif
342
   addpath(conf.atm1_rom_path);
343
   addpath(conf.atm2_rom_path);
344
   addpath(conf.atm3_rom_path);
345
   addpath(conf.scorp_rom_path);
346
   addpath(conf.prof_rom_path);
347
   addpath(conf.profi_rom_path);
348
   addpath(conf.plus3_rom_path);
349
   addpath(conf.quorum_rom_path);
350
//[vv]   addpath(conf.kay_rom_path);
351
 
352
   GetPrivateProfileString(rom, "ROMSET", "default", line, sizeof line, ininame);
784 DimkaM 353
   if(*line)
354
   {
355
       load_romset(&conf, line); conf.use_romset = 1;
356
   }
357
   else
358
   {
359
       conf.use_romset = 0;
360
   }
716 lvd 361
 
784 DimkaM 362
   conf.smuc = u8(GetPrivateProfileInt(misc, "SMUC", 0, ininame));
716 lvd 363
   GetPrivateProfileString(misc, "CMOS", nil, line, sizeof line, ininame);
364
   conf.cmos = 0;
365
   if (!strnicmp(line, "DALLAS", 6)) conf.cmos=1;
366
   if (!strnicmp(line, "512Bu1", 6)) conf.cmos=2;
784 DimkaM 367
   conf.cache = u8(GetPrivateProfileInt(misc, "Cache", 0, ininame));
716 lvd 368
   if (conf.cache && conf.cache!=16 && conf.cache!=32) conf.cache = 0;
369
   GetPrivateProfileString(misc, "HIMEM", nil, line, sizeof line, ininame);
370
   conf.mem_model = MM_PENTAGON;
371
   unsigned i; //Alone Coder 0.36.7
372
   for (/*unsigned*/ i = 0; i < N_MM_MODELS; i++)
373
      if (!strnicmp(line, mem_model[i].shortname, strlen(mem_model[i].shortname)))
374
         conf.mem_model = mem_model[i].Model;
375
   conf.ramsize = GetPrivateProfileInt(misc, "RamSize", 128, ininame);
376
   conf.Sna128Lock = GetPrivateProfileInt(misc, "Sna128Lock", 1, ininame);
377
 
378
   GetPrivateProfileString(misc, "DIR", nil, conf.workdir, sizeof conf.workdir, ininame);
379
 
380
   GetCurrentDirectory(_countof(line), line);
381
   SetCurrentDirectory(conf.workdir);
382
   GetCurrentDirectory(_countof(temp.SnapDir), temp.SnapDir);
383
   SetCurrentDirectory(line);
384
   strcpy(temp.RomDir, temp.SnapDir);
385
   strcpy(temp.HddDir, temp.SnapDir);
741 DimkaM 386
   strcpy(temp.SdDir, temp.SnapDir);
716 lvd 387
 
388
   conf.reset_rom = RM_SOS;
389
   GetPrivateProfileString(misc, "RESET", nil, line, sizeof line, ininame);
390
   if (!strnicmp(line, "DOS", 3)) conf.reset_rom = RM_DOS;
391
   if (!strnicmp(line, "MENU", 4)) conf.reset_rom = RM_128;
392
   if (!strnicmp(line, "SYS", 3)) conf.reset_rom = RM_SYS;
393
 
394
   GetPrivateProfileString(misc, "Modem", nil, line, sizeof line, ininame);
395
   conf.modem_port = 0;
396
 
397
   sscanf(line, "COM%d", &conf.modem_port);
398
 
399
   conf.paper = GetPrivateProfileInt(ula, "Paper", 17989, ininame);
400
   conf.t_line = GetPrivateProfileInt(ula, "Line", 224, ininame);
401
   conf.intfq = GetPrivateProfileInt(ula, "int", 50, ininame);
402
   conf.intlen = GetPrivateProfileInt(ula, "intlen", 32, ininame);
403
   /*conf.frame*/frametime/*Alone Coder*/ = GetPrivateProfileInt(ula, "Frame", 71680, ininame);
784 DimkaM 404
   conf.border_4T = u8(GetPrivateProfileInt(ula, "4TBorder", 0, ininame));
405
   conf.even_M1 = u8(GetPrivateProfileInt(ula, "EvenM1", 0, ininame));
406
   conf.floatbus = u8(GetPrivateProfileInt(ula, "FloatBus", 0, ininame));
407
   conf.floatdos = u8(GetPrivateProfileInt(ula, "FloatDOS", 0, ininame));
716 lvd 408
   conf.portff = GetPrivateProfileInt(ula, "PortFF", 0, ininame) != 0;
409
   conf.mcx_small = GetPrivateProfileInt(ula, "mcx_small", 320, ininame);
410
   conf.mcy_small = GetPrivateProfileInt(ula, "mcy_small", 240, ininame);
411
   conf.b_top_small = GetPrivateProfileInt(ula, "b_top_small", 24, ininame);
412
   conf.b_left_small = GetPrivateProfileInt(ula, "b_left_small", 32, ininame);
413
   conf.mcx_full = GetPrivateProfileInt(ula, "mcx_full", 384, ininame);
414
   conf.mcy_full = GetPrivateProfileInt(ula, "mcy_full", 288, ininame);
415
   conf.b_top_full = GetPrivateProfileInt(ula, "b_top_full", 48, ininame);
416
   conf.b_left_full = GetPrivateProfileInt(ula, "b_left_full", 64, ininame);
417
 
784 DimkaM 418
   conf.ula_preset=u8(-1U);
716 lvd 419
   add_presets(ula, "preset", &num_ula, ulapreset, &conf.ula_preset);
420
 
421
   load_ula_preset();
422
 
784 DimkaM 423
   conf.atm.mem_swap = u8(GetPrivateProfileInt(ula, "AtmMemSwap", 0, ininame));
424
   conf.use_comp_pal = u8(GetPrivateProfileInt(ula, "UsePalette", 1, ininame));
425
   conf.profi_monochrome = u8(GetPrivateProfileInt(ula, "ProfiMonochrome", 0, ininame));
426
   conf.ula_plus = GetPrivateProfileInt(ula, "ULAPlus", 0, ininame) != 0;
716 lvd 427
 
784 DimkaM 428
   conf.flashcolor = u8(GetPrivateProfileInt(video, "FlashColor", 0, ininame));
429
   conf.frameskip = u8(GetPrivateProfileInt(video, "SkipFrame", 0, ininame));
430
   conf.flip = (conf.SyncMode == SM_VIDEO) ? 1 : u8(GetPrivateProfileInt(video, "VSync", 0, ininame));
431
   conf.fullscr = u8(GetPrivateProfileInt(video, "FullScr", 1, ininame));
716 lvd 432
   conf.refresh = GetPrivateProfileInt(video, "Refresh", 0, ininame);
784 DimkaM 433
   conf.frameskipmax = u8(GetPrivateProfileInt(video, "SkipFrameMaxSpeed", 33, ininame));
434
   conf.updateb = u8(GetPrivateProfileInt(video, "Update", 1, ininame));
435
   conf.ch_size = u8(GetPrivateProfileInt(video, "ChunkSize", 0, ininame));
436
   conf.noflic = u8(GetPrivateProfileInt(video, "NoFlic", 0, ininame));
437
   conf.alt_nf = u8(GetPrivateProfileInt(video, "AltNoFlic", 0, ininame));
716 lvd 438
   conf.scanbright = GetPrivateProfileInt(video, "ScanIntens", 66, ininame);
784 DimkaM 439
   conf.pixelscroll = u8(GetPrivateProfileInt(video, "PixelScroll", 0, ininame));
440
   conf.detect_video = u8(GetPrivateProfileInt(video, "DetectModel", 1, ininame));
716 lvd 441
   conf.fontsize = 8;
442
 
784 DimkaM 443
   conf.videoscale = u8(GetPrivateProfileInt(video, "scale", 2, ininame));
716 lvd 444
 
784 DimkaM 445
   conf.rsm.mix_frames = u8(GetPrivateProfileInt(video, "rsm.frames", 8, ininame));
716 lvd 446
   GetPrivateProfileString(video, "rsm.mode", nil, line, sizeof line, ininame);
447
   conf.rsm.mode = RSM_FIR0;
448
   if (!strnicmp(line, "FULL", 4)) conf.rsm.mode = RSM_FIR0;
449
   if (!strnicmp(line, "2C", 2)) conf.rsm.mode = RSM_FIR1;
450
   if (!strnicmp(line, "3C", 2)) conf.rsm.mode = RSM_FIR2;
451
   if (!strnicmp(line, "SIMPLE", 6)) conf.rsm.mode = RSM_SIMPLE;
452
 
453
   GetPrivateProfileString(video, "AtariPreset", nil, conf.atariset, sizeof conf.atariset, ininame);
454
 
455
   GetPrivateProfileString(video, video, nil, line, sizeof line, ininame);
456
   conf.render = 0;
457
   for (i = 0; renders[i].func; i++)
458
      if (!strnicmp(line, renders[i].nick, strlen(renders[i].nick)))
459
         conf.render = i;
460
 
461
   GetPrivateProfileString(video, "driver", nil, line, sizeof line, ininame);
462
   conf.driver = DRIVER_DDRAW;
463
   for (i = 0; drivers[i].nick; i++)
464
      if (!strnicmp(line, drivers[i].nick, strlen(drivers[i].nick)))
465
         conf.driver = i;
466
 
784 DimkaM 467
   conf.fast_sl = u8(GetPrivateProfileInt(video, "fastlines", 0, ininame));
716 lvd 468
 
469
   GetPrivateProfileString(video, "Border", nil, line, sizeof line, ininame);
470
   conf.bordersize = 1;
471
   if (!strnicmp(line, "none", 4))
472
       conf.bordersize = 0;
473
   else if (!strnicmp(line, "small", 5))
474
       conf.bordersize = 1;
475
   else if (!strnicmp(line, "wide", 4))
476
       conf.bordersize = 2;
477
   conf.minres = GetPrivateProfileInt(video, "MinRes", 0, ininame);
478
 
479
   GetPrivateProfileString(video, "Hide", nil, line, sizeof line, ininame);
480
   char *ptr = strchr(line, ';'); if (ptr) *ptr = 0;
481
   for (ptr = line;;)
482
   {
784 DimkaM 483
      size_t max = renders_count - 1;
716 lvd 484
      for (i = 0; renders[i].func; i++)
485
      {
784 DimkaM 486
         size_t sl = strlen(renders[i].nick);
716 lvd 487
         if (!strnicmp(ptr, renders[i].nick, sl) && !isalnum(ptr[sl]))
488
         {
489
            ptr += sl;
490
            memcpy(&renders[i], &renders[i+1], (sizeof *renders) * (max-i));
491
            break;
492
         }
493
      }
494
      if (!*ptr++)
495
          break;
496
   }
497
 
498
   GetPrivateProfileString(video, "ScrShotDir", ".", conf.scrshot_dir, sizeof(conf.scrshot_dir), ininame);
499
 
500
   GetPrivateProfileString(video, "ScrShot", nil, line, sizeof line, ininame);
501
   conf.scrshot = 0;
502
   if(!strnicmp(line, "scr", 3))
503
       conf.scrshot = 0;
504
   else if(!strnicmp(line, "bmp", 3))
505
       conf.scrshot = 1;
506
   else if(!strnicmp(line, "png", 3))
507
       conf.scrshot = 2;
508
 
509
   GetPrivateProfileString(video, "ffmpeg.exec", "ffmpeg.exe", conf.ffmpeg.exec, sizeof conf.ffmpeg.exec, ininame);
510
   GetPrivateProfileString(video, "ffmpeg.parm", nil, conf.ffmpeg.parm, sizeof conf.ffmpeg.parm, ininame);
511
   GetPrivateProfileString(video, "ffmpeg.vout", "video#.avi", conf.ffmpeg.vout, sizeof conf.ffmpeg.vout, ininame);
784 DimkaM 512
   conf.ffmpeg.newcons = i8(GetPrivateProfileInt(video, "ffmpeg.newconsole", 1, ininame));
716 lvd 513
 
784 DimkaM 514
   conf.trdos_present = u8(GetPrivateProfileInt(beta128, "beta128", 1, ininame));
515
   conf.trdos_traps = u8(GetPrivateProfileInt(beta128, "Traps", 1, ininame));
516
   conf.wd93_nodelay = u8(GetPrivateProfileInt(beta128, "Fast", 1, ininame));
517
   conf.trdos_interleave = u8(GetPrivateProfileInt(beta128, "IL", 1, ininame)-1);
716 lvd 518
   if (conf.trdos_interleave > 2) conf.trdos_interleave = 0;
784 DimkaM 519
   conf.fdd_noise = u8(GetPrivateProfileInt(beta128, "Noise", 0, ininame));
716 lvd 520
   GetPrivateProfileString(beta128, "BOOT", nil, conf.appendboot, sizeof conf.appendboot, ininame);
521
   addpath(conf.appendboot);
759 dimkam 522
   conf.trdos_IORam=GetPrivateProfileInt(beta128, "RamPageFddIO", 0, ininame); //временный код, потом надо удалить
819 DimkaM 523
   conf.wiznet=GetPrivateProfileInt(USBZXNET, "WizNet", 0, ininame);
820 DimkaM 524
   GetPrivateProfileString(misc, "ColdRAM", "0000FFFF", conf.cold_ram_pat, sizeof conf.cold_ram_pat, ininame);
759 dimkam 525
 
784 DimkaM 526
   conf.led.enabled = u8(GetPrivateProfileInt(leds, "leds", 1, ininame));
527
   conf.led.flash_ay_kbd = u8(GetPrivateProfileInt(leds, "KBD_AY", 1, ininame));
528
   conf.led.perf_t = u8(GetPrivateProfileInt(leds, "PerfShowT", 0, ininame));
716 lvd 529
   conf.led.bandBpp = GetPrivateProfileInt(leds, "BandBpp", 512, ininame);
530
   if (conf.led.bandBpp != 64 && conf.led.bandBpp != 128 && conf.led.bandBpp != 256 && conf.led.bandBpp != 512) conf.led.bandBpp = 512;
531
 
532
   static char nm[] = "AY\0Perf\0LOAD\0Input\0Time\0OSW\0MemBand";
533
   char *n2 = nm;
534
   for (i = 0; i < NUM_LEDS; i++) {
535
      GetPrivateProfileString(leds, n2, nil, line, sizeof line, ininame);
784 DimkaM 536
      int x, y;
537
      unsigned z; unsigned r; n2 += strlen(n2) + 1;
538
      if (sscanf(line, "%u:%d,%d", &z, &x, &y) != 3) r = 0;
716 lvd 539
      else r = (x & 0xFFFF) + ((y << 16) & 0x7FFFFFFF) + z*0x80000000;
540
      *(&conf.led.ay+i) = r;
541
   }
542
 
543
   conf.sound.do_sound = do_sound_none;
544
   GetPrivateProfileString(sound, "SoundDrv", nil, line, sizeof line, ininame);
545
   if (!strnicmp(line, "wave", 4)) {
546
      conf.sound.do_sound = do_sound_wave;
547
      conf.soundbuffer = GetPrivateProfileInt(sound, "SoundBuffer", 0, ininame);
548
      if (!conf.soundbuffer) conf.soundbuffer = 6;
549
      if (conf.soundbuffer >= MAXWQSIZE) conf.soundbuffer = MAXWQSIZE-1;
550
   }
551
   if (!strnicmp(line, "ds", 2)) {
552
      conf.sound.do_sound = do_sound_ds;
553
//      conf.soundbuffer = GetPrivateProfileInt(sound, "DSoundBuffer", 1000, ininame);
554
//      conf.soundbuffer *= 4; // 16-bit, stereo
555
   }
556
 
784 DimkaM 557
   conf.sound.enabled = u8(GetPrivateProfileInt(sound, "Enabled", 1, ininame));
716 lvd 558
   #ifdef MOD_GS
784 DimkaM 559
   conf.sound.gsreset = u8(GetPrivateProfileInt(sound, "GSReset", 0, ininame));
716 lvd 560
   #endif
561
   conf.sound.fq = GetPrivateProfileInt(sound, "Fq", 44100, ininame);
784 DimkaM 562
   conf.sound.dsprimary = u8(GetPrivateProfileInt(sound, "DSPrimary", 0, ininame));
716 lvd 563
 
564
   conf.gs_type = 0;
565
#ifdef MOD_GS
566
   GetPrivateProfileString(sound, "GSTYPE", nil, line, sizeof line, ininame);
567
   #ifdef MOD_GSZ80
568
   if (!strnicmp(line, "Z80", 3)) conf.gs_type = 1;
569
   #endif
570
   #ifdef MOD_GSBASS
571
   if (!strnicmp(line, "BASS", 4)) conf.gs_type = 2;
572
   #endif
573
   conf.gs_ramsize = GetPrivateProfileInt(ngs, "RamSize", 2048, ininame);
574
#endif
575
 
784 DimkaM 576
   conf.soundfilter = u8(GetPrivateProfileInt(sound, "SoundFilter", 0, ininame)); //Alone Coder 0.36.4
577
   conf.RejectDC = u8(GetPrivateProfileInt(sound, "RejectDC", 1, ininame));
716 lvd 578
 
784 DimkaM 579
   conf.sound.beeper_vol = int(GetPrivateProfileInt(sound, "BeeperVol", 4000, ininame));
580
   conf.sound.micout_vol = int(GetPrivateProfileInt(sound, "MicOutVol", 1000, ininame));
581
   conf.sound.micin_vol = int(GetPrivateProfileInt(sound, "MicInVol", 1000, ininame));
582
   conf.sound.ay_vol = int(GetPrivateProfileInt(sound, "AYVol", 4000, ininame));
583
   conf.sound.covoxFB = int(GetPrivateProfileInt(sound, "CovoxFB", 0, ininame));
584
   conf.sound.covoxFB_vol = int(GetPrivateProfileInt(sound, "CovoxFBVol", 8192, ininame));
585
   conf.sound.covoxDD = int(GetPrivateProfileInt(sound, "CovoxDD", 0, ininame));
586
   conf.sound.covoxDD_vol = int(GetPrivateProfileInt(sound, "CovoxDDVol", 4000, ininame));
587
   conf.sound.sd = int(GetPrivateProfileInt(sound, "SD", 0, ininame));
588
   conf.sound.sd_vol = int(GetPrivateProfileInt(sound, "SDVol", 4000, ininame));
745 DimkaM 589
   //conf.sound.saa1099 = GetPrivateProfileInt(sound, "Saa1099", 0, ininame);
590
   conf.sound.saa1099 = SAA_NONE;
591
   GetPrivateProfileString(sound, "Saa1099", 0, line, sizeof line, ininame);
592
   if(!strnicmp(line, "ZXM", 3))
593
       conf.sound.saa1099 = SAA_ZXM;
594
   else if(!strnicmp(line, "TFMpro", 6))
595
       conf.sound.saa1099 = SAA_TFM_PRO;
716 lvd 596
 
597
   #ifdef MOD_GS
784 DimkaM 598
   conf.sound.gs_vol = int(GetPrivateProfileInt(sound, "GSVol", 8000, ininame));
716 lvd 599
   #endif
600
 
601
   #ifdef MOD_GSBASS
784 DimkaM 602
   conf.sound.bass_vol = int(GetPrivateProfileInt(sound, "BASSVol", 8000, ininame));
716 lvd 603
   #endif
604
 
605
   conf.sound.saa1099fq = GetPrivateProfileInt(saa1099, "Fq", 8000000, ininame);
606
 
607
   add_presets(ay, "VOLTAB", &num_ayvols, ayvols, &conf.sound.ay_vols);
608
   add_presets(ay, "STEREO", &num_aystereo, aystereo, &conf.sound.ay_stereo);
609
   conf.sound.ayfq = GetPrivateProfileInt(ay, "Fq", 1774400, ininame);
610
 
611
   GetPrivateProfileString(ay, "Chip", nil, line, sizeof line, ininame);
612
   conf.sound.ay_chip = SNDCHIP::CHIP_YM;
613
   if (!strnicmp(line, "AY", 2)) conf.sound.ay_chip = SNDCHIP::CHIP_AY;
614
   if (!strnicmp(line, "YM2203", 6)) conf.sound.ay_chip = SNDCHIP::CHIP_YM2203;else //Dexus
615
   if (!strnicmp(line, "YM", 2)) conf.sound.ay_chip = SNDCHIP::CHIP_YM;
616
 
784 DimkaM 617
   conf.sound.ay_samples = u8(GetPrivateProfileInt(ay, "UseSamples", 0, ininame));
716 lvd 618
 
619
   GetPrivateProfileString(ay, "Scheme", nil, line, sizeof line, ininame);
620
   conf.sound.ay_scheme = AY_SCHEME_NONE;
621
   if (!strnicmp(line, "default", 7)) conf.sound.ay_scheme = AY_SCHEME_SINGLE;
800 DimkaM 622
   if(!strnicmp(line, "FULLER", 6)) conf.sound.ay_scheme = AY_SCHEME_FULLER;
716 lvd 623
   if (!strnicmp(line, "PSEUDO", 6)) conf.sound.ay_scheme = AY_SCHEME_PSEUDO;
624
   if (!strnicmp(line, "QUADRO", 6)) conf.sound.ay_scheme = AY_SCHEME_QUADRO;
625
   if (!strnicmp(line, "POS", 3)) conf.sound.ay_scheme = AY_SCHEME_POS;
626
   if (!strnicmp(line, "CHRV", 4)) conf.sound.ay_scheme = AY_SCHEME_CHRV;
627
 
628
   GetPrivateProfileString(input, "ZXKeyMap", "default", conf.zxkeymap, sizeof conf.zxkeymap, ininame);
629
   for (i = 0; i < zxk_maps_count; i++)
630
   {
631
      if (!strnicmp(conf.zxkeymap, zxk_maps[i].name, strlen(zxk_maps[i].name)))
632
      {
633
          conf.input.active_zxk = &zxk_maps[i];
634
          break;
635
      }
636
   }
637
 
638
   if(!conf.input.active_zxk)
639
   {
640
       errmsg("Invalid keyboard layout '%s' specified, default used", conf.zxkeymap);
641
       conf.input.active_zxk = &zxk_maps[0]; // default
642
   }
643
 
644
   GetPrivateProfileString(input, "KeybLayout", "default", line, sizeof(line), ininame);
645
   ptr = strtok(line, " ;");
646
   strcpy(conf.keyset, ptr ? ptr : line);
647
 
648
   GetPrivateProfileString(input, "Mouse", nil, line, sizeof line, ininame);
649
   conf.input.mouse = 0;
650
   if (!strnicmp(line, "KEMPSTON", 8)) conf.input.mouse = 1;
651
   if (!strnicmp(line, "AY", 2)) conf.input.mouse = 2;
652
//0.36.6 from 0.35b2
653
   GetPrivateProfileString(input, "Wheel", nil, line, sizeof line, ininame);
654
   conf.input.mousewheel = MOUSE_WHEEL_NONE;
655
   if (!strnicmp(line, "KEMPSTON", 8)) conf.input.mousewheel = MOUSE_WHEEL_KEMPSTON;
656
   if (!strnicmp(line, "KEYBOARD", 8)) conf.input.mousewheel = MOUSE_WHEEL_KEYBOARD;
657
//~
784 DimkaM 658
   conf.input.joymouse = u8(GetPrivateProfileInt(input, "JoyMouse", 0, ininame));
659
   conf.input.mousescale = i8(GetPrivateProfileInt(input, "MouseScale", 0, ininame));
660
   conf.input.mouseswap = u8(GetPrivateProfileInt(input, "SwapMouse", 0, ininame));
661
   conf.input.kjoy = u8(GetPrivateProfileInt(input, "KJoystick", 1, ininame));
662
   conf.input.fjoy = GetPrivateProfileInt(input, "FJoystick", 1, ininame) != 0;
663
   conf.input.keymatrix = u8(GetPrivateProfileInt(input, "Matrix", 1, ininame));
664
   conf.input.firedelay = u8(GetPrivateProfileInt(input, "FireRate", 1, ininame));
665
   conf.input.altlock = u8(GetPrivateProfileInt(input, "AltLock", 1, ininame));
666
   conf.input.paste_hold = u8(GetPrivateProfileInt(input, "HoldDelay", 2, ininame));
667
   conf.input.paste_release = u8(GetPrivateProfileInt(input, "ReleaseDelay", 5, ininame));
668
   conf.input.paste_newline = u8(GetPrivateProfileInt(input, "NewlineDelay", 20, ininame));
669
   conf.input.keybpcmode = u8(GetPrivateProfileInt(input, "KeybPCMode", 0, ininame));
670
   conf.atm.xt_kbd = u8(GetPrivateProfileInt(input, "ATMKBD", 0, ininame));
716 lvd 671
   conf.input.JoyId = GetPrivateProfileInt(input, "Joy", 0, ininame);
672
 
673
   GetPrivateProfileString(input, "Fire", "0", line, sizeof line, ininame);
674
   conf.input.firenum = 0; conf.input.fire = 0;
675
   zxkeymap *active_zxk = conf.input.active_zxk;
676
   for (i = 0; i < active_zxk->zxk_size; i++)
677
      if (!stricmp(line, active_zxk->zxk[i].name))
678
      {  conf.input.firenum = i; break; }
679
 
680
   char buff[0x7000];
681
   GetPrivateProfileSection(colors, buff, sizeof buff, ininame);
682
   GetPrivateProfileString(colors, "color", "default", line, sizeof line, ininame);
683
   conf.pal = 0;
684
 
685
   for (i = 1, ptr = buff; i < _countof(pals); ptr += strlen(ptr)+1)
686
   {
687
      if (!*ptr)
688
          break;
689
      if (!isalnum(*ptr) || !strnicmp(ptr, "color=", 6))
690
          continue;
691
      char *ptr1 = strchr(ptr, '=');
692
      if (!ptr1)
693
          continue;
694
      *ptr1 = 0; strcpy(pals[i].name, ptr); ptr = ptr1+1;
695
      sscanf(ptr, "%02X,%02X,%02X,%02X,%02X,%02X:%X,%X,%X;%X,%X,%X;%X,%X,%X",
696
         &pals[i].ZZ,  &pals[i].ZN,  &pals[i].NN,
697
         &pals[i].NB,  &pals[i].BB,  &pals[i].ZB,
698
         &pals[i].r11, &pals[i].r12, &pals[i].r13,
699
         &pals[i].r21, &pals[i].r22, &pals[i].r23,
700
         &pals[i].r31, &pals[i].r32, &pals[i].r33);
701
 
702
      pals[i].r11 = min(pals[i].r11, 256U);
703
      pals[i].r12 = min(pals[i].r12, 256U);
704
      pals[i].r13 = min(pals[i].r13, 256U);
705
 
706
      pals[i].r21 = min(pals[i].r21, 256U);
707
      pals[i].r22 = min(pals[i].r22, 256U);
708
      pals[i].r23 = min(pals[i].r23, 256U);
709
 
710
      pals[i].r31 = min(pals[i].r31, 256U);
711
      pals[i].r32 = min(pals[i].r32, 256U);
712
      pals[i].r33 = min(pals[i].r33, 256U);
713
 
714
      if (!strnicmp(line, pals[i].name, strlen(pals[i].name)))
715
          conf.pal = i;
716
      i++;
717
   }
718
   conf.num_pals = i;
719
 
720
   GetPrivateProfileString(hdd, "SCHEME", nil, line, sizeof line, ininame);
721
   conf.ide_scheme = IDE_NONE;
722
   if(!strnicmp(line, "ATM", 3))
723
       conf.ide_scheme = IDE_ATM;
724
   else if(!strnicmp(line, "NEMO-DIVIDE", 11))
725
       conf.ide_scheme = IDE_NEMO_DIVIDE;
726
   else if(!strnicmp(line, "NEMO-A8", 7))
727
       conf.ide_scheme = IDE_NEMO_A8;
728
   else if(!strnicmp(line, "NEMO", 4))
729
       conf.ide_scheme = IDE_NEMO;
730
   else if(!strnicmp(line, "SMUC", 4))
731
       conf.ide_scheme = IDE_SMUC;
732
   else if(!strnicmp(line, "PROFI", 5))
733
       conf.ide_scheme = IDE_PROFI;
734
   else if(!strnicmp(line, "DIVIDE", 6))
735
       conf.ide_scheme = IDE_DIVIDE;
736
 
784 DimkaM 737
   conf.ide_skip_real = u8(GetPrivateProfileInt(hdd, "SkipReal", 0, ininame));
716 lvd 738
   GetPrivateProfileString(hdd, "CDROM", "SPTI", line, sizeof line, ininame);
739
   conf.cd_aspi = !strnicmp(line, "ASPI", 4) ? 1 : 0;
740
 
741
   for (int ide_device = 0; ide_device < 2; ide_device++)
742
   {
743
      char param[32];
744
      sprintf(param, "LBA%d", ide_device);
745
 
746
      GetPrivateProfileString(hdd, param, "0", line, sizeof(line), ininame);
784 DimkaM 747
      conf.ide[ide_device].lba = strtoull(line, nullptr, 10);
716 lvd 748
      sprintf(param, "CHS%d", ide_device);
749
      GetPrivateProfileString(hdd, param, "0/0/0", line, sizeof line, ininame);
750
      unsigned c, h, s;
751
 
752
      sscanf(line, "%u/%u/%u", &c, &h, &s);
753
      if(h > 16)
754
      {
755
          sprintf(line, "HDD%d heads count > 16 : %u\n", ide_device, h);
756
          errexit(line);
757
      }
758
      if(s > 63)
759
      {
760
          sprintf(line, "error HDD%d sectors count > 63 : %u\n", ide_device, s);
761
          errexit(line);
762
      }
763
      if(c > 16383)
764
      {
765
          sprintf(line, "error HDD%d cylinders count > 16383 : %u\n", ide_device, c);
766
          errexit(line);
767
      }
768
 
769
      conf.ide[ide_device].c = c;
770
      conf.ide[ide_device].h = h;
771
      conf.ide[ide_device].s = s;
772
 
773
      sprintf(param, "Image%d", ide_device);
774
      GetPrivateProfileString(hdd, param, nil, conf.ide[ide_device].image, sizeof conf.ide[ide_device].image, ininame);
775
 
776
      if(conf.ide[ide_device].image[0] &&
777
         conf.ide[ide_device].image[0] != '<')
778
          addpath(conf.ide[ide_device].image);
779
 
780
      sprintf(param, "HD%dRO", ide_device);
781
      conf.ide[ide_device].readonly = (BYTE)GetPrivateProfileInt(hdd, param, 0, ininame);
782
      sprintf(param, "CD%d", ide_device);
783
      conf.ide[ide_device].cd = (BYTE)GetPrivateProfileInt(hdd, param, 0, ininame);
784
 
785
      if(!conf.ide[ide_device].cd &&
786
         conf.ide[ide_device].lba == 0 &&
787
         conf.ide[ide_device].image[0] &&
788
         conf.ide[ide_device].image[0] != '<')
789
      {
790
          int file = open(conf.ide[ide_device].image, O_RDONLY | O_BINARY, S_IREAD);
791
          if(file >= 0)
792
          {
793
              __int64 sz = _filelengthi64(file);
794
              close(file);
795
              conf.ide[ide_device].lba = unsigned(sz / 512);
796
          }
797
      }
798
   }
799
 
800
   addpath(line, "CMOS");
801
   FILE *f0 = fopen(line, "rb");
802
   if (f0)
803
   {
804
     fread(cmos, 1, sizeof cmos, f0);
805
     fclose(f0);
806
   }
807
   else
808
       cmos[0x11] = 0xAA;
809
 
810
   addpath(line, "NVRAM");
811
   if ((f0 = fopen(line, "rb")))
812
   {
813
        fread(nvram, 1, sizeof nvram, f0);
814
        fclose(f0);
815
   }
816
 
817
   if(conf.gs_type == 1) // z80gs mode
818
   {
784 DimkaM 819
       GetPrivateProfileString(ngs, "SDCARD", nullptr, conf.ngs_sd_card_path, _countof(conf.ngs_sd_card_path), ininame);
716 lvd 820
       addpath(conf.ngs_sd_card_path);
821
       if(conf.ngs_sd_card_path[0])
822
           printf("NGS SDCARD=`%s'\n", conf.ngs_sd_card_path);
823
   }
824
 
784 DimkaM 825
   conf.zc = u8(GetPrivateProfileInt(misc, "ZC", 0, ininame));
716 lvd 826
   if(conf.zc)
827
   {
784 DimkaM 828
       GetPrivateProfileString(zc, "SDCARD", nullptr, conf.zc_sd_card_path, _countof(conf.zc_sd_card_path), ininame);
716 lvd 829
       addpath(conf.zc_sd_card_path);
830
       if(conf.zc_sd_card_path[0])
831
           printf("ZC SDCARD=`%s'\n", conf.zc_sd_card_path);
752 DimkaM 832
       conf.sd_delay = GetPrivateProfileInt(zc, "SDDelay", 1000, ininame);
716 lvd 833
   }
834
 
835
   GetPrivateProfileString("AUTOLOAD", "DefaultDrive", nil, line, sizeof(line), ininame);
836
   if(!strnicmp(line, "Auto", 4))
784 DimkaM 837
       DefaultDrive = -1U;
716 lvd 838
   else if(!strnicmp(line, "A", 1))
839
       DefaultDrive = 0;
840
   else if(!strnicmp(line, "B", 1))
841
       DefaultDrive = 1;
842
   else if(!strnicmp(line, "C", 1))
843
       DefaultDrive = 2;
844
   else if(!strnicmp(line, "D", 1))
845
       DefaultDrive = 3;
846
 
847
   load_arch(ininame);
848
   loadkeys(ac_main);
849
#ifdef MOD_MONITOR
850
   loadkeys(ac_main_xt);
851
   loadkeys(ac_regs);
852
   loadkeys(ac_trace);
853
   loadkeys(ac_mem);
854
#endif
855
   temp.scale = GetPrivateProfileInt(video, "winscale", 1, ininame);
856
}
857
 
858
void autoload()
859
{
860
   static char autoload[] = "AUTOLOAD";
861
   char line[512];
862
 
784 DimkaM 863
   for (unsigned disk = 0; disk < 4; disk++) {
864
      char key[8]; sprintf(key, "disk%c", int('A'+disk));
716 lvd 865
      GetPrivateProfileString(autoload, key, nil, line, sizeof line, ininame);
866
      if (!*line) continue;
867
      addpath(line);
868
      trd_toload = disk;
869
      if (!loadsnap(line)) errmsg("failed to autoload <%s>", line);
870
   }
871
 
872
   GetPrivateProfileString(autoload, "snapshot", nil, line, sizeof line, ininame);
873
   if (!*line) return;
874
   addpath(line);
875
   if (!loadsnap(line)) { color(CONSCLR_ERROR); printf("failed to start snapshot <%s>\n", line); }
876
}
877
 
784 DimkaM 878
static void apply_memory()
716 lvd 879
{
880
   #ifdef MOD_GSZ80
881
   if (conf.gs_type == 1)
882
   {
883
       if(load_rom(conf.gs_rom_path, ROM_GS_M, 32) != 512) // 512k rom
884
       {
885
           errmsg("invalid ROM size for NGS (need 512kb), NGS disabled\n");
886
           conf.gs_type = 0;
887
       }
888
   }
889
   #endif
890
 
891
   if (conf.ramsize != 128 && conf.ramsize != 256 && conf.ramsize != 512 && conf.ramsize != 1024 && conf.ramsize != 4096)
892
      conf.ramsize = 0;
893
   if (!(mem_model[conf.mem_model].availRAMs & conf.ramsize)) {
894
      conf.ramsize = mem_model[conf.mem_model].defaultRAM;
895
      color(CONSCLR_ERROR);
784 DimkaM 896
      printf("invalid RAM size for %s, using default (%uK)\n",
716 lvd 897
         mem_model[conf.mem_model].fullname, conf.ramsize);
898
   }
899
 
900
   switch(conf.mem_model)
901
   {
902
   case MM_ATM710:
903
   case MM_ATM3:
904
      base_sos_rom = ROM_BASE_M + 0*PAGE;
905
      base_dos_rom = ROM_BASE_M + 1*PAGE;
906
      base_128_rom = ROM_BASE_M + 2*PAGE;
907
      base_sys_rom = ROM_BASE_M + 3*PAGE;
908
   break;
909
 
910
   case MM_ATM450:
911
   case MM_PROFI:
912
      base_sys_rom = ROM_BASE_M + 0*PAGE;
913
      base_dos_rom = ROM_BASE_M + 1*PAGE;
914
      base_128_rom = ROM_BASE_M + 2*PAGE;
915
      base_sos_rom = ROM_BASE_M + 3*PAGE;
916
   break;
917
 
918
   case MM_PLUS3:
919
      base_128_rom = ROM_BASE_M + 0*PAGE;
920
      base_sys_rom = ROM_BASE_M + 1*PAGE;
921
      base_dos_rom = ROM_BASE_M + 2*PAGE;
922
      base_sos_rom = ROM_BASE_M + 3*PAGE;
923
   break;
924
 
925
   case MM_QUORUM:
926
      base_sys_rom = ROM_BASE_M + 0*PAGE;
927
      base_dos_rom = ROM_BASE_M + 1*PAGE;
928
      base_128_rom = ROM_BASE_M + 2*PAGE;
929
      base_sos_rom = ROM_BASE_M + 3*PAGE;
930
   break;
931
 
932
/*
933
   case MM_KAY:
934
      base_128_rom = ROM_BASE_M + 0*PAGE;
935
      base_sos_rom = ROM_BASE_M + 1*PAGE;
936
      base_dos_rom = ROM_BASE_M + 2*PAGE;
937
      base_sys_rom = ROM_BASE_M + 3*PAGE;
938
   break;
939
*/
940
 
941
   default:
942
      base_128_rom = ROM_BASE_M + 0*PAGE;
943
      base_sos_rom = ROM_BASE_M + 1*PAGE;
944
      base_sys_rom = ROM_BASE_M + 2*PAGE;
945
      base_dos_rom = ROM_BASE_M + 3*PAGE;
946
   }
947
 
948
   unsigned romsize;
949
   if (conf.use_romset)
950
   {
951
      if (!load_rom(conf.sos_rom_path, base_sos_rom))
952
          errexit("failed to load BASIC48 ROM");
953
      if (!load_rom(conf.zx128_rom_path, base_128_rom) && conf.reset_rom == RM_128)
954
          conf.reset_rom = RM_SOS;
955
      if (!load_rom(conf.dos_rom_path, base_dos_rom))
956
          conf.trdos_present = 0;
957
      if (!load_rom(conf.sys_rom_path, base_sys_rom) && conf.reset_rom == RM_SYS)
958
          conf.reset_rom = RM_SOS;
959
      romsize = 64;
960
   }
961
   else
962
   {
963
      if (conf.mem_model == MM_ATM710 || conf.mem_model == MM_ATM3)
964
      {
965
         romsize = load_rom(conf.mem_model == MM_ATM710 ? conf.atm2_rom_path : conf.atm3_rom_path, ROM_BASE_M, 64);
966
         if (romsize != 64 && romsize != 128 && romsize != 512 && romsize != 1024)
967
            errexit("invalid ROM size for ATM bios");
968
         unsigned char *lastpage = ROM_BASE_M + (romsize - 64) * 1024;
969
         base_sos_rom = lastpage + 0*PAGE;
970
         base_dos_rom = lastpage + 1*PAGE;
971
         base_128_rom = lastpage + 2*PAGE;
972
         base_sys_rom = lastpage + 3*PAGE;
973
      }
974
      else if (conf.mem_model == MM_PROFSCORP)
975
      {
976
         romsize = load_rom(conf.prof_rom_path, ROM_BASE_M, 16);
977
         if (romsize != 64 && romsize != 128 && romsize != 256)
978
            errexit("invalid PROF-ROM size");
979
      }
980
      else
981
      {
784 DimkaM 982
         const char *romname = nullptr;
716 lvd 983
         switch(conf.mem_model)
984
         {
985
         case MM_PROFI: romname = conf.profi_rom_path; break;
986
         case MM_SCORP: romname = conf.scorp_rom_path; break;
987
//[vv]         case MM_KAY: romname = conf.kay_rom_path; break;
988
         case MM_ATM450: romname = conf.atm1_rom_path; break;
989
         case MM_PLUS3: romname = conf.plus3_rom_path; break;
990
         case MM_QUORUM: romname = conf.quorum_rom_path; break;
991
 
992
         default:
993
             errexit("ROMSET should be defined for this memory model");
994
         }
995
 
996
         romsize = load_rom(romname, ROM_BASE_M, 64);
997
         if (romsize != 64)
998
             errexit("invalid ROM filesize");
999
      }
1000
   }
1001
 
1002
   if (conf.mem_model == MM_PROFSCORP)
1003
   {
1004
      temp.profrom_mask = 0;
1005
      if (romsize == 128)
1006
          temp.profrom_mask = 1;
1007
      if (romsize == 256)
1008
          temp.profrom_mask = 3;
1009
 
1010
      comp.profrom_bank &= temp.profrom_mask;
1011
      set_scorp_profrom(0);
1012
   }
1013
 
1014
#ifdef MOD_MONITOR
1015
   load_labels(conf.sos_labels_path, base_sos_rom, 0x4000);
1016
#endif
1017
 
784 DimkaM 1018
   temp.gs_ram_mask = u8((conf.gs_ramsize-1) >> 4);
1019
   temp.ram_mask = u8((conf.ramsize-1) >> 4);
1020
   temp.rom_mask = u8((romsize-1) >> 4);
716 lvd 1021
   set_banks();
1022
 
1023
   for(unsigned i = 0; i < CpuMgr.GetCount(); i++)
1024
   {
1025
       Z80 &cpu = CpuMgr.Cpu(i);
1026
       cpu.dbgchk = isbrk(cpu);
1027
   }
1028
}
1029
 
1030
 
784 DimkaM 1031
void applyconfig(bool Init)
716 lvd 1032
{
784 DimkaM 1033
#ifdef MOD_GS
1034
    init_gs(Init);
1035
#endif
716 lvd 1036
//   printf("%s\n", __FUNCTION__);
1037
 
1038
   //[vv] disable turbo
1039
   comp.pEFF7 |= EFF7_GIGASCREEN;
1040
 
1041
//Alone Coder 0.36.4
1042
   conf.frame = frametime;
1043
   cpu.SetTpi(conf.frame);
1044
/*
1045
   if ((conf.mem_model == MM_PENTAGON)&&(comp.pEFF7 & EFF7_GIGASCREEN))
1046
       conf.frame = 71680;
1047
*/
1048
//~Alone Coder
1049
   temp.ticks_frame = (unsigned)(temp.cpufq / double(conf.intfq) + 1.0);
1050
   loadzxkeys(&conf);
1051
   apply_memory();
1052
 
1053
   temp.snd_frame_ticks = (conf.sound.fq << TICK_FF) / conf.intfq;
1054
   temp.snd_frame_samples = temp.snd_frame_ticks >> TICK_FF;
1055
   temp.frameskip = conf.sound.enabled? conf.frameskip : conf.frameskipmax;
1056
 
1057
   input.firedelay = 1; // if conf.input.fire changed
1058
   input.clear_zx();
1059
 
1060
   modem.open(conf.modem_port);
1061
 
1062
   load_atariset();
1063
   apply_video();
1064
   apply_sound();
1065
 
1066
   hdd.dev[0].configure(conf.ide+0);
1067
   hdd.dev[1].configure(conf.ide+1);
1068
   if (conf.atm.xt_kbd) input.atm51.clear();
1069
 
1070
   if(conf.gs_type == 1)
1071
   {
1072
       SdCard.Close();
1073
       SdCard.Open(conf.ngs_sd_card_path);
1074
   }
1075
 
1076
   if(conf.zc)
1077
   {
1078
       Zc.Close();
1079
       Zc.Open(conf.zc_sd_card_path);
1080
   }
819 DimkaM 1081
        if(conf.wiznet){
1082
                comp.wiznet.p83=0;
1083
                comp.wiznet.p82=0;
1084
                comp.wiznet.p81=0;
1085
                Wiz5300_Close();
1086
                Wiz5300_Init();
1087
        }
716 lvd 1088
 
1089
   setpal(0);
1090
}
1091
 
1092
void load_arch(const char *fname)
1093
{
1094
   GetPrivateProfileString("ARC", "SkipFiles", nil, skiparc, sizeof skiparc, fname);
1095
   char *p; //Alone Coder 0.36.7
1096
   for (/*char * */p = skiparc;;) {
1097
      char *nxt = strchr(p, ';');
1098
      if (!nxt) break;
1099
      *nxt = 0; p = nxt+1;
1100
   }
1101
   p[strlen(p)+1] = 0;
1102
 
1103
   GetPrivateProfileSection("ARC", arcbuffer, sizeof arcbuffer, fname);
1104
   for (char *x = arcbuffer; *x; ) {
1105
      char *newx = x + strlen(x)+1;
1106
      char *y = strchr(x, '=');
1107
      if (!y) {
1108
ignore_line:
784 DimkaM 1109
         memcpy(x, newx, sizeof arcbuffer - size_t(newx-arcbuffer));
716 lvd 1110
      } else {
1111
         *y = 0; if (!stricmp(x, "SkipFiles")) goto ignore_line;
1112
         x = newx;
1113
      }
1114
   }
1115
}
1116
 
1117
void loadkeys(action *table)
1118
{
1119
   unsigned num[0x300], i = 0;
1120
   unsigned j; //Alone Coder 0.36.7
1121
   if (!table->name)
1122
       return; // empty table (can't sort)
1123
   for (action *p = table; p->name; p++, i++)
1124
   {
1125
      char line[0x400];
1126
      GetPrivateProfileString("SYSTEM.KEYS", p->name, "`", line, sizeof line, ininame);
1127
      if (*line == '`')
1128
      {
1129
         errmsg("keydef for %s not found", p->name);
1130
         load_errors = 1;
1131
bad_key:
784 DimkaM 1132
         p->k1 = 0xFE;
1133
         p->k2 = 0xFF;
1134
         p->k3 = 0xFD;
716 lvd 1135
         continue;
1136
      }
1137
      char *s = strchr(line, ';');
1138
      if(s)
1139
          *s = 0;
1140
      p->k1 = p->k2 = p->k3 = p->k4 = 0; num[i] = 0;
1141
      for (s = line;;)
1142
      {
1143
         while (*s == ' ') s++;
1144
         if (!*s)
1145
             break;
1146
         char *s1 = s;
1147
         while (isalnum(*s))
1148
             s++;
1149
         for (j = 0; j < pckeys_count; j++)
1150
         {
784 DimkaM 1151
            if ((int)strlen(pckeys[j].name)==s-s1 && !strnicmp(s1, pckeys[j].name, size_t(s-s1)))
716 lvd 1152
            {
1153
               switch (num[i])
1154
               {
1155
                  case 0: p->k1 = pckeys[j].virtkey; break;
1156
                  case 1: p->k2 = pckeys[j].virtkey; break;
1157
                  case 2: p->k3 = pckeys[j].virtkey; break;
1158
                  case 3: p->k4 = pckeys[j].virtkey; break;
1159
                  default:
1160
                     color(CONSCLR_ERROR);
1161
                     printf("warning: too many keys in %s=%s\n", p->name, line);
1162
                     load_errors = 1;
1163
               }
1164
               num[i]++;
1165
               break;
1166
            }
1167
         }
1168
         if (j == pckeys_count)
1169
         {
1170
            color(CONSCLR_ERROR);
1171
            char x = *s; *s = 0;
1172
            printf("bad key: %s\n", s1); *s = x;
1173
            load_errors = 1;
1174
         }
1175
      }
1176
      if (!num[i])
1177
          goto bad_key;
1178
   }
1179
 
1180
   // sort keys
1181
   for (unsigned k = 0; k < i-1; k++)
1182
   {
1183
      unsigned max = k;
1184
      for (unsigned l = k+1; l < i; l++)
1185
         if (num[l] > num[max])
1186
             max = l;
1187
 
1188
      action tmp = table[k];
1189
      table[k] = table[max];
1190
      table[max] = tmp;
1191
 
1192
      unsigned tm = num[k];
1193
      num[k] = num[max];
1194
      num[max] = tm;
1195
   }
1196
}
1197
 
1198
void loadzxkeys(CONFIG *conf)
1199
{
1200
   char section[0x200];
1201
   sprintf(section, "ZX.KEYS.%s", conf->keyset);
1202
   char line[0x300];
1203
   char *s; //Alone Coder 0.36.7
1204
   unsigned k; //Alone Coder 0.36.7
1205
   zxkeymap *active_zxk = conf->input.active_zxk;
1206
 
1207
   for (unsigned i = 0; i < VK_MAX; i++)
1208
   {
1209
      inports[i].port1 = inports[i].port2 = &input.kjoy;
1210
      inports[i].mask1 = inports[i].mask2 = 0xFF;
1211
      for (unsigned j = 0; j < pckeys_count; j++)
1212
      {
1213
         if (pckeys[j].virtkey == i)
1214
         {
1215
            GetPrivateProfileString(section, pckeys[j].name, "", line, sizeof line, ininame);
1216
            s = strtok(line, " ;");
1217
            if(s)
1218
            {
1219
               for(k = 0; k < active_zxk->zxk_size; k++)
1220
               {
1221
                  if (!stricmp(s, active_zxk->zxk[k].name))
1222
                  {
1223
                     inports[i].port1 = active_zxk->zxk[k].port;
1224
                     inports[i].mask1 = active_zxk->zxk[k].mask;
1225
                     switch(i)
1226
                     {
1227
                     case DIK_CONTROL:
1228
                         inports[DIK_LCONTROL].port1 = active_zxk->zxk[k].port;
1229
                         inports[DIK_LCONTROL].mask1 = active_zxk->zxk[k].mask;
1230
                         inports[DIK_RCONTROL].port1 = active_zxk->zxk[k].port;
1231
                         inports[DIK_RCONTROL].mask1 = active_zxk->zxk[k].mask;
1232
                     break;
1233
 
1234
                     case DIK_SHIFT:
1235
                         inports[DIK_LSHIFT].port1 = active_zxk->zxk[k].port;
1236
                         inports[DIK_LSHIFT].mask1 = active_zxk->zxk[k].mask;
1237
                         inports[DIK_RSHIFT].port1 = active_zxk->zxk[k].port;
1238
                         inports[DIK_RSHIFT].mask1 = active_zxk->zxk[k].mask;
1239
                     break;
1240
 
1241
                     case DIK_MENU:
1242
                         inports[DIK_LMENU].port1 = active_zxk->zxk[k].port;
1243
                         inports[DIK_LMENU].mask1 = active_zxk->zxk[k].mask;
1244
                         inports[DIK_RMENU].port1 = active_zxk->zxk[k].port;
1245
                         inports[DIK_RMENU].mask1 = active_zxk->zxk[k].mask;
1246
                     break;
1247
                     }
1248
                     break;
1249
                  }
1250
               }
1251
            }
784 DimkaM 1252
            s = strtok(nullptr, " ;");
716 lvd 1253
            if(s)
1254
            {
1255
               for (k = 0; k < active_zxk->zxk_size; k++)
1256
               {
1257
                  if (!stricmp(s, active_zxk->zxk[k].name))
1258
                  {
1259
                     inports[i].port2 = active_zxk->zxk[k].port;
1260
                     inports[i].mask2 = active_zxk->zxk[k].mask;
1261
 
1262
                     switch(i)
1263
                     {
1264
                     case DIK_CONTROL:
1265
                         inports[DIK_LCONTROL].port2 = active_zxk->zxk[k].port;
1266
                         inports[DIK_LCONTROL].mask2 = active_zxk->zxk[k].mask;
1267
                         inports[DIK_RCONTROL].port2 = active_zxk->zxk[k].port;
1268
                         inports[DIK_RCONTROL].mask2 = active_zxk->zxk[k].mask;
1269
                     break;
1270
 
1271
                     case DIK_SHIFT:
1272
                         inports[DIK_LSHIFT].port2 = active_zxk->zxk[k].port;
1273
                         inports[DIK_LSHIFT].mask2 = active_zxk->zxk[k].mask;
1274
                         inports[DIK_RSHIFT].port2 = active_zxk->zxk[k].port;
1275
                         inports[DIK_RSHIFT].mask2 = active_zxk->zxk[k].mask;
1276
                     break;
1277
 
1278
                     case DIK_MENU:
1279
                         inports[DIK_LMENU].port2 = active_zxk->zxk[k].port;
1280
                         inports[DIK_LMENU].mask2 = active_zxk->zxk[k].mask;
1281
                         inports[DIK_RMENU].port2 = active_zxk->zxk[k].port;
1282
                         inports[DIK_RMENU].mask2 = active_zxk->zxk[k].mask;
1283
                     break;
1284
                     }
1285
                     break;
1286
                  }
1287
               }
1288
            }
1289
            break;
1290
         }
1291
      }
1292
   }
1293
}