Subversion Repositories pentevo

Rev

Rev 798 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "std.h"
  2.  
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include <sys/stat.h>
  6.  
  7. #include "resource.h"
  8. #include "emul.h"
  9. #include "vars.h"
  10. #include "config.h"
  11. #include "draw.h"
  12. #include "dx.h"
  13. #include "dxrend.h"
  14. #include "dxr_advm.h"
  15. #include "dxr_rsm.h"
  16. #include "fntsrch.h"
  17. #include "tape.h"
  18. #include "snapshot.h"
  19. #include "leds.h"
  20. #include "sdcard.h"
  21. #include "zc.h"
  22. #include "gs.h"
  23. #include "gui.h"
  24.  
  25. #include "util.h"
  26.  
  27. void setcheck(int ID, unsigned char state)
  28. {
  29.    CheckDlgButton(dlg, ID, state ? BST_CHECKED : BST_UNCHECKED);
  30. }
  31.  
  32. unsigned char getcheck(int ID)
  33. {
  34.    return (IsDlgButtonChecked(dlg, ID) == BST_CHECKED);
  35. }
  36.  
  37.  
  38. #ifdef MOD_SETTINGS
  39.  
  40. static CONFIG c1;
  41. static char dlgok = 0;
  42.  
  43. const char *lastpage;
  44.  
  45. static char rset_list[0x800];
  46.  
  47. static char compare_rset(char *rname)
  48. {
  49.    CONFIG c2; load_romset(&c2, rname);
  50.    if (stricmp(c2.sos_rom_path, c1.sos_rom_path)) return 0;
  51.    if (stricmp(c2.dos_rom_path, c1.dos_rom_path)) return 0;
  52.    if (stricmp(c2.sys_rom_path, c1.sys_rom_path)) return 0;
  53.    if (stricmp(c2.zx128_rom_path, c1.zx128_rom_path)) return 0;
  54.    return 1;
  55. }
  56.  
  57. static void find_romset()
  58. {
  59.    HWND box = GetDlgItem(dlg, IDC_ROMSET); int cur = -1, i = 0;
  60.    for (char *dst = rset_list; *dst; dst += strlen(dst)+1, i++)
  61.       if (compare_rset(dst)) cur = i;
  62.    SendMessage(box, CB_SETCURSEL, cur, 0);
  63. }
  64.  
  65. static char select_romfile(char *dstname)
  66. {
  67.    char fname[FILENAME_MAX];
  68.    fname[0] = 0;
  69. /*
  70.    strcpy(fname, dstname);
  71.    char *x = strrchr(fname+2, ':');
  72.    if(x)
  73.        *x = 0;
  74. */
  75.    OPENFILENAME ofn = { };
  76.    ofn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME);
  77.    ofn.hwndOwner = dlg;
  78.    ofn.lpstrFilter = "ROM image (*.ROM)\0*.ROM\0All files\0*.*\0";
  79.    ofn.lpstrFile = fname;
  80.    ofn.nMaxFile = _countof(fname);
  81.    ofn.lpstrTitle = "Select ROM";
  82.    ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  83.    ofn.lpstrInitialDir   = temp.RomDir;
  84.    if (!GetOpenFileName(&ofn))
  85.        return 0;
  86.    strcpy(dstname, fname);
  87.    strcpy(temp.RomDir, ofn.lpstrFile);
  88.    char *Ptr = strrchr(temp.RomDir, '\\');
  89.    if(Ptr)
  90.     *Ptr = 0;
  91.    return 1;
  92. }
  93.  
  94. static char *MemDlg_get_bigrom()
  95. {
  96.    if (c1.mem_model == MM_ATM450) return c1.atm1_rom_path;
  97.    if (c1.mem_model == MM_ATM710) return c1.atm2_rom_path;
  98.    if (c1.mem_model == MM_ATM3) return c1.atm3_rom_path;
  99.    if (c1.mem_model == MM_PROFI) return c1.profi_rom_path;
  100.    if (c1.mem_model == MM_SCORP) return c1.scorp_rom_path;
  101.    if (c1.mem_model == MM_PROFSCORP) return c1.prof_rom_path;
  102.  //[vv] kay-1024 эх шьхы ёЄрэфрЁЄэющ Ёрёъырфъш ╧╟╙ (Ёрёъырфър яхЁхъы■ўрырё№ фцрьяхЁюь J5)
  103. //   if (c1.mem_model == MM_KAY) return c1.kay_rom_path;
  104.    if (c1.mem_model == MM_PLUS3) return c1.plus3_rom_path;
  105.    if (c1.mem_model == MM_QUORUM) return c1.quorum_rom_path;
  106.    return nullptr;
  107. }
  108.  
  109. static void change_rompage(int dx, int reload)
  110. {
  111.    int x = int(SendDlgItemMessage(dlg, IDC_ROMPAGE, CB_GETCURSEL, 0, 0));
  112.    static char *pgs[] = { c1.sos_rom_path, c1.zx128_rom_path, c1.dos_rom_path, c1.sys_rom_path };
  113.    char *ptr = pgs[x];
  114.    if (reload)
  115.        select_romfile(ptr);
  116.    if (dx) {
  117.       char *x = strrchr(ptr+2, ':');
  118.       unsigned pg = 0;
  119.       if (!x) x = ptr + strlen(ptr); else { *x = 0; pg = unsigned(atoi(x+1)); }
  120.       FILE *ff = fopen(ptr, "rb");
  121.       long sz = 0;
  122.       if(ff)
  123.       {
  124.           fseek(ff, 0, SEEK_END);
  125.           sz = ftell(ff) / PAGE;
  126.           fclose(ff);
  127.       }
  128.       if ((int(pg)+dx) < sz) {
  129.          pg = unsigned(int(pg) + dx);
  130.          SendDlgItemMessage(dlg, IDC_ROMSET, CB_SETCURSEL, 0, 0);
  131.       }
  132.       sprintf(x, ":%u", pg);
  133.    }
  134.    SendDlgItemMessage(dlg, IDE_ROMNAME, WM_SETTEXT, 0, (LPARAM)ptr);
  135.    find_romset();
  136. }
  137.  
  138. static void change_rombank(int dx, int reload)
  139. {
  140.    char *romname = MemDlg_get_bigrom();
  141.  
  142.    char line[512];
  143.  
  144.    strcpy(line, romname);
  145.  
  146.    char *x = strrchr(line+2, ':');
  147.  
  148.    unsigned pg = 0;
  149.    if (!x)
  150.        x = line + strlen(line);
  151.    else
  152.    {
  153.        *x = 0;
  154.        pg = unsigned(atoi(x+1));
  155.    }
  156.  
  157.    if (reload)
  158.    {
  159.        if (!select_romfile(line))
  160.            return;
  161.        x = line + strlen(line);
  162.    }
  163.  
  164.    FILE *ff = fopen(line, "rb");
  165.    long sz = 0;
  166.    if (ff)
  167.    {
  168.        fseek(ff, 0, SEEK_END);
  169.        sz = ftell(ff);
  170.        fclose(ff);
  171.    }
  172.    
  173.    if (!sz || (sz & 0xFFFF))
  174.    {
  175.        err: MessageBox(dlg, "Invalid ROM size", "error", MB_ICONERROR | MB_OK);
  176.        return;
  177.    }
  178.  
  179.    sz /= 1024;
  180.  
  181.    if ((c1.mem_model == MM_SCORP || c1.mem_model == MM_PROFI || c1.mem_model == MM_KAY) && sz != 64)
  182.        goto err;
  183.    if ((c1.mem_model == MM_ATM710 || c1.mem_model == MM_ATM3) && sz != 64 && sz != 128 && sz != 256 && sz != 512 && sz != 1024)
  184.        goto err;
  185.    if (c1.mem_model == MM_PROFSCORP && sz != 128 && sz != 256 && sz != 512 && sz != 1024)
  186.        goto err;
  187.  
  188.    if ((int(pg)+dx) < sz/256)
  189.        pg = unsigned(int(pg) + dx);
  190.    if (sz > 256)
  191.        sprintf(x, ":%u", pg);
  192.    strcpy(romname, line);
  193.    SendDlgItemMessage(dlg, IDE_BIGROM, WM_SETTEXT, 0, (LPARAM)romname);
  194.  
  195.    sprintf(line, "Loaded ROM size: %ldK", sz);
  196.    if (c1.mem_model == MM_PROFSCORP && sz > 256)
  197.        sprintf(line, "Loaded ROM size: %ld*256K", sz/256);
  198.    SetDlgItemText(dlg, IDC_TOTAL_ROM, line);
  199.    ShowWindow(GetDlgItem(dlg, IDC_TOTAL_ROM), SW_SHOW);
  200. }
  201.  
  202. static void reload_roms()
  203. {
  204.    unsigned i = 0, n = unsigned(SendDlgItemMessage(dlg, IDC_ROMSET, CB_GETCURSEL, 0, 0));
  205.    char *dst; //Alone Coder 0.36.7
  206.    for (/*char * */dst = rset_list; *dst && i < n; i++, dst += strlen(dst)+1);
  207.    if (!*dst) return;
  208.    load_romset(&c1, dst);
  209.    change_rompage(0,0);
  210. }
  211.  
  212. static void MemDlg_set_visible()
  213. {
  214.    int vis = !c1.use_romset? SW_SHOW : SW_HIDE;
  215.    ShowWindow(GetDlgItem(dlg, IDE_BIGROM), vis);
  216.    ShowWindow(GetDlgItem(dlg, IDB_ROMSEL_S), vis);
  217.    if (c1.mem_model != MM_PROFSCORP) vis = SW_HIDE; // todo: scorp+smuc
  218.    ShowWindow(GetDlgItem(dlg, IDC_FILEBANK), vis);
  219.    vis = c1.use_romset? SW_SHOW : SW_HIDE;
  220.    ShowWindow(GetDlgItem(dlg, IDC_ROMSET), vis);
  221.    ShowWindow(GetDlgItem(dlg, IDC_ROMPAGE), vis);
  222.    ShowWindow(GetDlgItem(dlg, IDE_ROMNAME), vis);
  223.    ShowWindow(GetDlgItem(dlg, IDC_FILEPAGE), vis);
  224.    ShowWindow(GetDlgItem(dlg, IDB_ROMSEL_P), vis);
  225.    ShowWindow(GetDlgItem(dlg, IDC_TOTAL_ROM), SW_HIDE);
  226. }
  227.  
  228. static void mem_set_sizes()
  229. {
  230.    unsigned mems = mem_model[c1.mem_model].availRAMs;
  231.    unsigned best = mem_model[c1.mem_model].defaultRAM;
  232.  
  233.    EnableWindow(GetDlgItem(dlg, IDC_RAM128),  (mems & RAM_128)?  1:0);
  234.    EnableWindow(GetDlgItem(dlg, IDC_RAM256),  (mems & RAM_256)?  1:0);
  235.    EnableWindow(GetDlgItem(dlg, IDC_RAM512),  (mems & RAM_512)?  1:0);
  236.    EnableWindow(GetDlgItem(dlg, IDC_RAM1024), (mems & RAM_1024)? 1:0);
  237.    EnableWindow(GetDlgItem(dlg, IDC_RAM4096), (mems & RAM_4096)? 1:0);
  238.  
  239.    char ok = 1;
  240.    if (getcheck(IDC_RAM128) && !(mems & RAM_128))  ok = 0;
  241.    if (getcheck(IDC_RAM256) && !(mems & RAM_256))  ok = 0;
  242.    if (getcheck(IDC_RAM512) && !(mems & RAM_512))  ok = 0;
  243.    if (getcheck(IDC_RAM1024)&& !(mems & RAM_1024)) ok = 0;
  244.    if (getcheck(IDC_RAM4096)&& !(mems & RAM_4096)) ok = 0;
  245.  
  246.    if (!ok) {
  247.       setcheck(IDC_RAM128, 0);
  248.       setcheck(IDC_RAM256, 0);
  249.       setcheck(IDC_RAM512, 0);
  250.       setcheck(IDC_RAM1024,0);
  251.       setcheck(IDC_RAM4096,0);
  252.       if (best == 128) setcheck(IDC_RAM128);
  253.       if (best == 256) setcheck(IDC_RAM256);
  254.       if (best == 512) setcheck(IDC_RAM512);
  255.       if (best == 1024)setcheck(IDC_RAM1024);
  256.       if (best == 4096)setcheck(IDC_RAM4096);
  257.    }
  258.  
  259.    char *romname = MemDlg_get_bigrom();
  260.    EnableWindow(GetDlgItem(dlg, IDC_SINGLE_ROM), romname? 1 : 0);
  261.    if (romname) SetDlgItemText(dlg, IDE_BIGROM, romname);
  262.    else
  263.    {
  264.        c1.use_romset = 1;
  265.        setcheck(IDC_CUSTOM_ROM, 1);
  266.        setcheck(IDC_SINGLE_ROM, 0);
  267.    }
  268.  
  269.    int cache_ok = (c1.mem_model == MM_ATM450)? 0 : 1;
  270.    EnableWindow(GetDlgItem(dlg, IDC_CACHE0), cache_ok);
  271.    EnableWindow(GetDlgItem(dlg, IDC_CACHE16), cache_ok);
  272.    EnableWindow(GetDlgItem(dlg, IDC_CACHE32), cache_ok);
  273.  
  274.    MemDlg_set_visible();
  275. }
  276.  
  277. static INT_PTR CALLBACK MemDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  278. {
  279.    ::dlg = dlg; char bf[0x800];
  280.    static char lock = 0;
  281.  
  282.    if (msg == WM_INITDIALOG) {
  283.       HWND box = GetDlgItem(dlg, IDC_MEM);
  284.       for (unsigned i = 0; i < N_MM_MODELS; i++)
  285.          SendMessage(box, CB_ADDSTRING, 0, (LPARAM)mem_model[i].fullname);
  286.  
  287.       box = GetDlgItem(dlg, IDC_ROMPAGE);
  288.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"BASIC48");
  289.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"BASIC128");
  290.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"TR-DOS");
  291.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"SERVICE");
  292.       SendMessage(box, CB_SETCURSEL, 0, 0);
  293.  
  294.       GetPrivateProfileSectionNames(bf, sizeof bf, ininame);
  295.       box = GetDlgItem(dlg, IDC_ROMSET);
  296.       char *dst = rset_list;
  297.       for (char *p = bf; *p; p += strlen(p)+1) {
  298.          if ((*(unsigned*)p | 0x20202020) != WORD4('r','o','m','.')) continue;
  299.          strcpy(dst, p+4); dst += strlen(dst)+1;
  300.          char line[128]; GetPrivateProfileString(p, "title", p+4, line, sizeof line, ininame);
  301.          SendMessage(box, CB_ADDSTRING, 0, (LPARAM)line);
  302.       }
  303.       *dst = 0;
  304.    }
  305.    if (!lock && msg == WM_COMMAND) {
  306.       unsigned id = LOWORD(wp), code = HIWORD(wp);
  307.       if (code == BN_CLICKED) {
  308.           if(id == IDC_SINGLE_ROM)
  309.           {
  310.               c1.use_romset = 0;
  311.               MemDlg_set_visible();
  312.           }
  313.           if(id == IDC_CUSTOM_ROM)
  314.           {
  315.               c1.use_romset = 1;
  316.               MemDlg_set_visible();
  317.           }
  318.          if (id == IDB_ROMSEL_P) change_rompage(0,1);
  319.          if (id == IDB_ROMSEL_S) change_rombank(0,1);
  320.       }
  321.       if (code == CBN_SELCHANGE) {
  322.          if (id == IDC_ROMSET) reload_roms();
  323.          if (id == IDC_ROMPAGE) change_rompage(0,0);
  324.          if(id == IDC_MEM)
  325.          {
  326.              c1.mem_model = (MEM_MODEL)SendDlgItemMessage(dlg, IDC_MEM, CB_GETCURSEL, 0, 0);
  327.              lock = 1;
  328.              mem_set_sizes();
  329.              lock = 0;
  330.          }
  331.       }
  332.       return 1;
  333.    }
  334.    if (msg != WM_NOTIFY) return 0;
  335.    NM_UPDOWN *nud = (NM_UPDOWN*)lp;
  336.    if (nud->hdr.code == UDN_DELTAPOS) {
  337.       if (wp == IDC_FILEPAGE) change_rompage(nud->iDelta > 0 ? 1 : -1, 0);
  338.       if (wp == IDC_FILEBANK) change_rombank(nud->iDelta > 0 ? 1 : -1, 0);
  339.       return TRUE; // don't chage up-down state
  340.    }
  341.    NMHDR *nm = (NMHDR*)lp;
  342.    if (nm->code == PSN_KILLACTIVE) {
  343.       if (getcheck(IDC_CACHE0)) c1.cache = 0;
  344.       if (getcheck(IDC_CACHE16)) c1.cache = 16;
  345.       if (getcheck(IDC_CACHE32)) c1.cache = 32;
  346.  
  347.       if (getcheck(IDC_CMOS_NONE)) c1.cmos = 0;
  348.       if (getcheck(IDC_CMOS_DALLAS)) c1.cmos = 1;
  349.       if (getcheck(IDC_CMOS_RUS)) c1.cmos = 2;
  350.  
  351.       if (getcheck(IDC_RAM128)) c1.ramsize = 128;
  352.       if (getcheck(IDC_RAM256)) c1.ramsize = 256;
  353.       if (getcheck(IDC_RAM512)) c1.ramsize = 512;
  354.       if (getcheck(IDC_RAM1024))c1.ramsize = 1024;
  355.       if (getcheck(IDC_RAM4096))c1.ramsize = 4096;
  356.  
  357.       c1.smuc = getcheck(IDC_SMUC);
  358.    }
  359.    if (nm->code == PSN_SETACTIVE) {
  360.       lock = 1;
  361.       SendDlgItemMessage(dlg, IDC_MEM, CB_SETCURSEL, c1.mem_model, 0);
  362.       setcheck(IDC_RAM128, (c1.ramsize == 128));
  363.       setcheck(IDC_RAM256, (c1.ramsize == 256));
  364.       setcheck(IDC_RAM512, (c1.ramsize == 512));
  365.       setcheck(IDC_RAM1024,(c1.ramsize == 1024));
  366.       setcheck(IDC_RAM4096,(c1.ramsize == 4096));
  367.       setcheck(IDC_SINGLE_ROM, !c1.use_romset);
  368.       setcheck(IDC_CUSTOM_ROM, c1.use_romset);
  369.       find_romset();
  370.  
  371.       setcheck(IDC_CACHE0,  (c1.cache == 0));
  372.       setcheck(IDC_CACHE16, (c1.cache == 16));
  373.       setcheck(IDC_CACHE32, (c1.cache == 32));
  374.  
  375.       setcheck(IDC_CMOS_NONE, (c1.cmos == 0));
  376.       setcheck(IDC_CMOS_DALLAS, (c1.cmos == 1));
  377.       setcheck(IDC_CMOS_RUS, (c1.cmos == 2));
  378.  
  379.       setcheck(IDC_SMUC, c1.smuc);
  380.  
  381.       mem_set_sizes();
  382.       lock = 0;
  383.  
  384.       lastpage = "MEMORY";
  385.    }
  386.    if (nm->code == PSN_APPLY) dlgok = 1;
  387.    if (nm->code == PSN_RESET) dlgok = 0;
  388.    return 1;
  389. }
  390.  
  391. static int getint(int ID) {
  392.    HWND wnd = GetDlgItem(dlg, ID);
  393.    char bf[64]; SendMessage(wnd, WM_GETTEXT, sizeof bf, (LPARAM)bf);
  394.    return atoi(bf);
  395. }
  396. static void setint(int ID, int num) {
  397.    HWND wnd = GetDlgItem(dlg, ID);
  398.    char bf[64]; sprintf(bf, "%d", num);
  399.    SendMessage(wnd, WM_SETTEXT, 0, (LPARAM)bf);
  400. }
  401.  
  402. static INT_PTR CALLBACK UlaDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  403. {
  404.    ::dlg = dlg;
  405.    NMHDR *nm = (NMHDR*)lp;
  406.    static volatile char block=0;
  407.    if (msg == WM_INITDIALOG) {
  408.       HWND box = GetDlgItem(dlg, IDC_ULAPRESET);
  409.       for (unsigned i = 0; i < num_ula; i++)
  410.          SendMessage(box, CB_ADDSTRING, 0, (LPARAM)ulapreset[i]);
  411.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"<custom>");
  412.    }
  413.    if (msg == WM_COMMAND && !block) {
  414.       unsigned id = LOWORD(wp), code = HIWORD(wp);
  415.       if ((code == EN_CHANGE && (id==IDE_FRAME || id==IDE_LINE || id==IDE_INT || id==IDE_INT_LEN || id==IDE_PAPER))
  416.           || (code == BN_CLICKED && (id==IDC_EVENM1 || id==IDC_4TBORDER || id==IDC_FLOAT_BUS || id==IDC_FLOAT_DOS || id==IDC_PORT_FF)))
  417.       {
  418.          c1.ula_preset = u8(-1U);
  419.          SendDlgItemMessage(dlg, IDC_ULAPRESET, CB_SETCURSEL, num_ula, 0);
  420.       }
  421.       if (code == CBN_SELCHANGE) {
  422.          if (id == IDC_ULAPRESET) {
  423.             unsigned pre = unsigned(SendDlgItemMessage(dlg, IDC_ULAPRESET, CB_GETCURSEL, 0, 0));
  424.             if (pre == num_ula) pre = -1U;
  425.             c1.ula_preset = (unsigned char)pre;
  426.             if (pre == -1U) return 1;
  427.             CONFIG tmp = conf;
  428.             conf.ula_preset = (unsigned char)pre; load_ula_preset();
  429.             c1.frame = /*conf.frame*/frametime/*Alone Coder*/;
  430.             c1.intfq = conf.intfq;
  431.             c1.intlen = conf.intlen;
  432.             c1.t_line = conf.t_line;
  433.             c1.paper = conf.paper;
  434.             c1.even_M1 = conf.even_M1;
  435.             c1.border_4T = conf.border_4T;
  436.             c1.floatbus = conf.floatbus;
  437.             c1.floatdos = conf.floatdos;
  438.             c1.portff = conf.portff;
  439.             conf = tmp;
  440.             goto refresh;
  441.          }
  442.       }
  443.       return 1;
  444.    }
  445.    if (msg != WM_NOTIFY) return 0;
  446.    if (nm->code == PSN_KILLACTIVE) {
  447.       c1.frame = unsigned(getint(IDE_FRAME));
  448.       c1.t_line = unsigned(getint(IDE_LINE));
  449.       c1.paper = unsigned(getint(IDE_PAPER));
  450.       c1.intfq = unsigned(getint(IDE_INT));
  451.       c1.intlen = unsigned(getint(IDE_INT_LEN));
  452.       c1.nopaper = unsigned(getcheck(IDC_NOPAPER));
  453.       c1.even_M1 = getcheck(IDC_EVENM1);
  454.       c1.border_4T = getcheck(IDC_4TBORDER);
  455.       c1.floatbus = getcheck(IDC_FLOAT_BUS);
  456.       c1.floatdos = getcheck(IDC_FLOAT_DOS);
  457.       c1.portff = getcheck(IDC_PORT_FF) != 0;
  458.       if(c1.mem_model == MM_PROFI)
  459.       {
  460.            c1.profi_monochrome = getcheck(IDC_PROFI_MONOCHROME);
  461.       }
  462.       if (c1.mem_model == MM_ATM710 || c1.mem_model == MM_ATM3 || c1.mem_model == MM_ATM450 || c1.mem_model == MM_PROFI)
  463.       {
  464.           c1.use_comp_pal = getcheck(IDC_ATMPAL);
  465.       }
  466.       if (c1.mem_model == MM_ATM710 || c1.mem_model == MM_ATM3 || c1.mem_model == MM_ATM450)
  467.       {
  468.          c1.atm.mem_swap = getcheck(IDC_ATM_SWAP);
  469.       }
  470.       c1.ula_plus = getcheck(IDC_ULA_PLUS);
  471.    }
  472.    if (nm->code == PSN_SETACTIVE) {
  473. refresh:
  474.       SendDlgItemMessage(dlg, IDC_ULAPRESET, CB_SETCURSEL, c1.ula_preset<num_ula? c1.ula_preset : num_ula, 0);
  475.       block=1;
  476.       setint(IDE_FRAME, int(c1.frame));
  477.       setint(IDE_LINE, int(c1.t_line));
  478.       setint(IDE_PAPER, int(c1.paper));
  479.       setint(IDE_INT, int(c1.intfq));
  480.       setint(IDE_INT_LEN, int(c1.intlen));
  481.       setcheck(IDC_NOPAPER, u8(c1.nopaper));
  482.       setcheck(IDC_EVENM1, c1.even_M1);
  483.       setcheck(IDC_4TBORDER, c1.border_4T);
  484.       setcheck(IDC_FLOAT_BUS, c1.floatbus);
  485.       setcheck(IDC_FLOAT_DOS, c1.floatdos);
  486.       setcheck(IDC_PORT_FF, c1.portff);
  487.  
  488.       BOOL en_atm =  (c1.mem_model == MM_ATM710 || c1.mem_model == MM_ATM3 || c1.mem_model == MM_ATM450);
  489.       BOOL en_profi =  (c1.mem_model == MM_PROFI);
  490.       EnableWindow(GetDlgItem(dlg, IDC_ATM_SWAP), en_atm);
  491.       EnableWindow(GetDlgItem(dlg, IDC_PROFI_MONOCHROME), en_profi);
  492.       EnableWindow(GetDlgItem(dlg, IDC_ATMPAL), en_atm || en_profi);
  493.       setcheck(IDC_PROFI_MONOCHROME, en_profi ? c1.profi_monochrome : 0);
  494.       setcheck(IDC_ATM_SWAP, en_atm ? c1.atm.mem_swap : 0);
  495.       setcheck(IDC_ATMPAL, (en_atm || en_profi) ? c1.use_comp_pal : 0);
  496.       setcheck(IDC_ULA_PLUS, c1.ula_plus);
  497.  
  498.       block=0;
  499.       lastpage = "ULA";
  500.       return 1;
  501.    }
  502.    if (nm->code == PSN_APPLY) dlgok = 1;
  503.    if (nm->code == PSN_RESET) dlgok = 0;
  504.    return 1;
  505. }
  506.  
  507. static void HddDlg_set_active()
  508. {
  509.    int enable = (c1.ide_scheme != 0);
  510.    EnableWindow(GetDlgItem(dlg, IDB_HDD0), enable);
  511.    EnableWindow(GetDlgItem(dlg, IDE_HDD0_CHS), enable);
  512.    EnableWindow(GetDlgItem(dlg, IDE_HDD0_LBA), enable);
  513.    EnableWindow(GetDlgItem(dlg, IDC_HDD0_RO), enable);
  514.    EnableWindow(GetDlgItem(dlg, IDB_HDD1), enable);
  515.    EnableWindow(GetDlgItem(dlg, IDE_HDD1_CHS), enable);
  516.    EnableWindow(GetDlgItem(dlg, IDE_HDD1_LBA), enable);
  517.    EnableWindow(GetDlgItem(dlg, IDC_HDD1_RO), enable);
  518.    if (!enable) return;
  519. }
  520.  
  521. static void HddDlg_show_info(int device)
  522. {
  523.    unsigned c = c1.ide[device].c, h = c1.ide[device].h, s = c1.ide[device].s;
  524.    u64 l = c1.ide[device].lba;
  525.    DWORD readonly = 0;
  526.    if (!*c1.ide[device].image) readonly = 1;
  527.    if (*c1.ide[device].image == '<') {
  528.       unsigned drive = find_hdd_device(c1.ide[device].image);
  529.       if (drive < MAX_PHYS_HD_DRIVES + MAX_PHYS_CD_DRIVES) {
  530.          c = ((unsigned short*)phys[drive].idsector)[1];
  531.          h = ((unsigned short*)phys[drive].idsector)[3];
  532.          s = ((unsigned short*)phys[drive].idsector)[6];
  533.          l = *(unsigned*)(phys[drive].idsector+60*2); // lba28
  534.          if(*((u16*)(phys[drive].idsector+83*2)) & (1<<10))
  535.          {
  536.              l = *(u64*)(phys[drive].idsector+100*2); // lba48
  537.          }
  538.          if (!l) l = c*h*s;
  539.          readonly = 1;
  540.       }
  541.    }
  542.    HWND edit_l = GetDlgItem(dlg, device? IDE_HDD1_LBA : IDE_HDD0_LBA);
  543.    HWND edit_c = GetDlgItem(dlg, device? IDE_HDD1_CHS : IDE_HDD0_CHS);
  544.    SendMessage(edit_l, EM_SETREADONLY, readonly, 0);
  545.    SendMessage(edit_c, EM_SETREADONLY, readonly, 0);
  546.  
  547.    SetDlgItemText(dlg, device? IDE_HDD1 : IDE_HDD0, c1.ide[device].image);
  548.    char textbuf[512];
  549.    *textbuf = 0; if (*c1.ide[device].image) sprintf(textbuf, "%I64u", l);
  550.    SetWindowText(edit_l, textbuf);
  551.    *textbuf = 0; if (*c1.ide[device].image) sprintf(textbuf, "%u/%u/%u", c,h,s);
  552.    SetWindowText(edit_c, textbuf);
  553. }
  554.  
  555. static void HddDlg_select_image(int device)
  556. {
  557.    HMENU selmenu = CreatePopupMenu();
  558.    AppendMenu(selmenu, MF_STRING, 1, "Select image file...");
  559.    AppendMenu(selmenu, MF_STRING, 2, "Remove device");
  560.    unsigned max, drive; char textbuf[512];
  561.    for (max = drive = 0; drive < n_phys; drive++) {
  562.  
  563.       if (phys[drive].type == ATA_NTHDD)
  564.          sprintf(textbuf, "HDD %u: %s, %u Mb", phys[drive].spti_id, phys[drive].viewname, phys[drive].hdd_size / (2*1024));
  565.  
  566.       else if (phys[drive].type == ATA_SPTI_CD)
  567.          sprintf(textbuf, "CD-ROM %u: %s", phys[drive].spti_id, phys[drive].viewname);
  568.  
  569.       else if (phys[drive].type == ATA_ASPI_CD)
  570.          sprintf(textbuf, "CD-ROM %u.%u: %s", phys[drive].adapterid, phys[drive].targetid, phys[drive].viewname);
  571.  
  572.       else continue;
  573.  
  574.       if (!max) AppendMenu(selmenu, MF_SEPARATOR, 0, nullptr);
  575.       max++;
  576.       AppendMenu(selmenu, MF_STRING, drive + 8, textbuf);
  577.    }
  578.  
  579.    RECT rc; GetWindowRect(GetDlgItem(dlg, device? IDB_HDD1 : IDB_HDD0), &rc);
  580.    int code = TrackPopupMenu(selmenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTBUTTON, rc.left, rc.bottom, 0, dlg, nullptr);
  581.    DestroyMenu(selmenu);
  582.    if (!code) return;
  583.  
  584.    if (code == 2) { // remove
  585.       *c1.ide[device].image = 0;
  586.       HddDlg_show_info(device);
  587.       return;
  588.    }
  589.  
  590.    if (code >= 8)
  591.    { // physical device
  592.       if(MessageBox(dlg, "All volumes on drive will be dismounted\n", "Warning",
  593.           MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
  594.           return;
  595.       strcpy(c1.ide[device].image, phys[code-8].viewname);
  596.       HddDlg_show_info(device);
  597.       return;
  598.    }
  599.  
  600.    // open HDD image
  601.    OPENFILENAME fn = { };
  602. /*
  603.    strcpy(textbuf, c1.ide[device].image);
  604.    if (textbuf[0] == '<') *textbuf = 0;
  605. */
  606.    textbuf[0] = 0;
  607.    fn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME);
  608.    fn.hwndOwner = dlg;
  609.    fn.lpstrFilter = "Hard disk drive image (*.HDD)\0*.HDD\0";
  610.    fn.lpstrFile = textbuf;
  611.    fn.nMaxFile = _countof(textbuf);
  612.    fn.lpstrTitle = "Select image file for HDD emulator";
  613.    fn.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  614.    fn.lpstrInitialDir   = temp.HddDir;
  615.    if (!GetOpenFileName(&fn))
  616.        return;
  617.    strcpy(temp.HddDir, fn.lpstrFile);
  618.    char *Ptr = strrchr(temp.HddDir, '\\');
  619.    if(Ptr)
  620.     *Ptr = 0;
  621.  
  622.    int file = open(textbuf, O_RDONLY | O_BINARY, S_IREAD);
  623.    if(file < 0)
  624.        return;
  625.    __int64 sz = _filelengthi64(file);
  626.    close(file);
  627.  
  628.    strcpy(c1.ide[device].image, textbuf);
  629.    c1.ide[device].c = 0;
  630.    c1.ide[device].h = 0;
  631.    c1.ide[device].s = 0;
  632.    c1.ide[device].lba = unsigned(sz / 512);
  633.    HddDlg_show_info(device);
  634. }
  635.  
  636. static void HddDlg_show_size(unsigned id, unsigned sectors)
  637. {
  638.    unsigned __int64 sz = ((unsigned __int64)sectors) << 9;
  639.    char num[64]; int ptr = 0, tri = 0;
  640.    for (;;) {
  641.       num[ptr++] = char((unsigned char)(sz % 10) + '0');
  642.       sz /= 10; if (!sz) break;
  643.       if(++tri == 3)
  644.       {
  645.           num[ptr++] = ',';
  646.           tri = 0;
  647.       }
  648.    }
  649.    char dst[64]; dst[0] = '-'; dst[1] = ' ';
  650.    int k; //Alone Coder 0.36.7
  651.    for (/*int*/ k = 2; ptr; k++) dst[k] = num[--ptr];
  652.    strcpy(dst+k, " bytes");
  653.    SetDlgItemText(dlg, id, dst);
  654. }
  655.  
  656. static INT_PTR CALLBACK HddDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  657. {
  658.    ::dlg = dlg;
  659.    NMHDR *nm = (NMHDR*)lp;
  660.    static volatile char block=0;
  661.    if (msg == WM_INITDIALOG)
  662.    {
  663.       HWND box = GetDlgItem(dlg, IDC_IDESCHEME);
  664.       ComboBox_AddString(box, "NONE");
  665.       ComboBox_AddString(box, "ATM");
  666.       ComboBox_AddString(box, "NEMO");
  667.       ComboBox_AddString(box, "NEMO (A8)");
  668.       ComboBox_AddString(box, "NEMO (DIVIDE)");
  669.       ComboBox_AddString(box, "SMUC");
  670.       ComboBox_AddString(box, "PROFI");
  671.       ComboBox_AddString(box, "DIVIDE");
  672.       ComboBox_SetItemData(box, 0, (LPARAM)IDE_NONE);
  673.       ComboBox_SetItemData(box, 1, (LPARAM)IDE_ATM);
  674.       ComboBox_SetItemData(box, 2, (LPARAM)IDE_NEMO);
  675.       ComboBox_SetItemData(box, 3, (LPARAM)IDE_NEMO_A8);
  676.       ComboBox_SetItemData(box, 4, (LPARAM)IDE_NEMO_DIVIDE);
  677.       ComboBox_SetItemData(box, 5, (LPARAM)IDE_SMUC);
  678.       ComboBox_SetItemData(box, 6, (LPARAM)IDE_PROFI);
  679.       ComboBox_SetItemData(box, 7, (LPARAM)IDE_DIVIDE);
  680.    }
  681.    if (msg == WM_COMMAND && !block)
  682.    {
  683.       unsigned id = LOWORD(wp), code = HIWORD(wp);
  684.       if (code == CBN_SELCHANGE && id == IDC_IDESCHEME)
  685.       {
  686.          HWND box = GetDlgItem(dlg, IDC_IDESCHEME);
  687.          int Idx = ComboBox_GetCurSel(box);
  688.          c1.ide_scheme = (IDE_SCHEME)ComboBox_GetItemData(box, Idx);
  689.          HddDlg_set_active();
  690.       }
  691.       if (id == IDB_HDD0) HddDlg_select_image(0);
  692.       if (id == IDB_HDD1) HddDlg_select_image(1);
  693.  
  694.       if (code == EN_CHANGE)
  695.       {
  696.          char bf[64]; unsigned c=0, h=0, s=0, l=0;
  697.          GetWindowText((HWND)lp, bf, sizeof bf);
  698.          sscanf(bf, "%u/%u/%u", &c, &h, &s);
  699.          sscanf(bf, "%u", &l);
  700.          switch (id)
  701.          {
  702.             case IDE_HDD0_CHS: HddDlg_show_size(IDS_HDD0_CHS, c*h*s); break;
  703.             case IDE_HDD0_LBA: HddDlg_show_size(IDS_HDD0_LBA, l); break;
  704.             case IDE_HDD1_CHS: HddDlg_show_size(IDS_HDD1_CHS, c*h*s); break;
  705.             case IDE_HDD1_LBA: HddDlg_show_size(IDS_HDD1_LBA, l); break;
  706.          }
  707.       }
  708.  
  709.       return 1;
  710.    }
  711.    if (msg != WM_NOTIFY) return 0;
  712.    if (nm->code == PSN_KILLACTIVE) {
  713.       // ide_scheme read in CBN_SELCHANGE
  714.       // image read in 'select drive/image' button click
  715.       c1.ide[0].readonly = getcheck(IDC_HDD0_RO);
  716.       c1.ide[1].readonly = getcheck(IDC_HDD1_RO);
  717.       for (unsigned device = 0; device < 2; device++)
  718.          if (*c1.ide[device].image && *c1.ide[device].image != '<') {
  719.             char textbuf[64];
  720.             GetDlgItemText(dlg, device? IDE_HDD1_LBA : IDE_HDD0_LBA, textbuf, sizeof textbuf);
  721.             sscanf(textbuf, "%llu", &c1.ide[device].lba);
  722.             GetDlgItemText(dlg, device? IDE_HDD1_CHS : IDE_HDD0_CHS, textbuf, sizeof textbuf);
  723.             sscanf(textbuf, "%u/%u/%u", &c1.ide[device].c, &c1.ide[device].h, &c1.ide[device].s);
  724.          }
  725.  
  726.    }
  727.    if (nm->code == PSN_SETACTIVE)
  728.    {
  729.       block=1;
  730.       HWND box = GetDlgItem(dlg, IDC_IDESCHEME);
  731.       int Cnt = ComboBox_GetCount(box);
  732.       for(int i = 0; i < Cnt; i++)
  733.       {
  734.           ULONG_PTR Data = (ULONG_PTR)ComboBox_GetItemData(box, i);
  735.           if(Data == c1.ide_scheme)
  736.           {
  737.               ComboBox_SetCurSel(box, i);
  738.               break;
  739.           }
  740.       }
  741.       HddDlg_set_active();
  742.       block=0;
  743.       setcheck(IDC_HDD0_RO, c1.ide[0].readonly);
  744.       setcheck(IDC_HDD1_RO, c1.ide[1].readonly);
  745.       HddDlg_show_info(0);
  746.       HddDlg_show_info(1);
  747.       lastpage = "HDD";
  748.       return 1;
  749.    }
  750.    if (nm->code == PSN_APPLY) dlgok = 1;
  751.    if (nm->code == PSN_RESET) dlgok = 0;
  752.    return 1;
  753. }
  754.  
  755. static INT_PTR CALLBACK EFF7Dlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  756. {
  757.     (void)wp;
  758.  
  759.    ::dlg = dlg;
  760.    NMHDR *nm = (NMHDR*)lp;
  761.    if (msg != WM_NOTIFY) return 0;
  762.    static int bits[] = { IDC_BIT0, IDC_BIT1, IDC_BIT2, IDC_BIT3,
  763.                          IDC_BIT4, IDC_BIT5, IDC_BIT6, IDC_BIT7 };
  764.    static int lock[] = { IDC_LOCK0, IDC_LOCK1, IDC_LOCK2, IDC_LOCK3,
  765.                          IDC_LOCK4, IDC_LOCK5, IDC_LOCK6, IDC_LOCK7 };
  766.    if (nm->code == PSN_KILLACTIVE) {
  767.       u8 mask = 0, eff7 = 0;
  768.       for (unsigned i = 0; i < 8; i++) {
  769.          if (getcheck(lock[i])) mask |= (1<<i);
  770.          if (getcheck(bits[i])) eff7 |= (1<<i);
  771.       }
  772.       c1.EFF7_mask = mask;
  773.       comp.pEFF7 = eff7;
  774.    }
  775.    if (nm->code == PSN_SETACTIVE) {
  776.       for (unsigned i = 0; i < 8; i++) {
  777.          setcheck(lock[i], c1.EFF7_mask & (1<<i));
  778.          setcheck(bits[i], comp.pEFF7 & (1<<i));
  779.       }
  780.       lastpage = "EFF7";
  781.       return 1;
  782.    }
  783.    if (nm->code == PSN_APPLY) dlgok = 1;
  784.    if (nm->code == PSN_RESET) dlgok = 0;
  785.    return 1;
  786. }
  787.  
  788. static INT_PTR CALLBACK ChipDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  789. {
  790.     (void)wp;
  791.    ::dlg = dlg;
  792.    if (msg == WM_INITDIALOG) {
  793.       unsigned i; HWND aybox;
  794.  
  795.       aybox = GetDlgItem(dlg, IDC_CHIP_BUS);
  796.       for (i = 0; i < SNDCHIP::CHIP_MAX; i++)
  797.          SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)SNDCHIP::get_chipname((SNDCHIP::CHIP_TYPE)i));
  798.  
  799.       aybox = GetDlgItem(dlg, IDC_CHIP_SCHEME);
  800.       for (i = 0; i < AY_SCHEME_MAX; i++)
  801.          SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)ay_schemes[i]);
  802.  
  803.       aybox = GetDlgItem(dlg, IDC_CHIP_VOL);
  804.       for (unsigned char UCi = 0; UCi < num_ayvols; UCi++) //Alone Coder
  805.          SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)ayvols[UCi]); //Alone Coder
  806.  
  807.       aybox = GetDlgItem(dlg, IDC_CHIP_STEREO);
  808.       for (i = 0; i < num_aystereo; i++)
  809.          SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)aystereo[i]);
  810.  
  811.       aybox = GetDlgItem(dlg, IDC_CHIP_CLK);
  812.       SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)"1774400");
  813.       SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)"3500000");
  814.       SendMessage(aybox, CB_ADDSTRING, 0, (LPARAM)"1750000");
  815.    }
  816.    if (msg != WM_NOTIFY) return 0;
  817.    NMHDR *nm = (NMHDR*)lp;
  818.    if (nm->code == PSN_KILLACTIVE) {
  819.       c1.sound.ayfq = unsigned(getint(IDC_CHIP_CLK));
  820.       c1.sound.ay_chip = (unsigned char)SendDlgItemMessage(dlg, IDC_CHIP_BUS, CB_GETCURSEL, 0, 0);
  821.       c1.sound.ay_scheme = (unsigned char)SendDlgItemMessage(dlg, IDC_CHIP_SCHEME, CB_GETCURSEL, 0, 0);
  822.       c1.sound.ay_vols = (unsigned char)SendDlgItemMessage(dlg, IDC_CHIP_VOL, CB_GETCURSEL, 0, 0);
  823.       c1.sound.ay_stereo = (unsigned char)SendDlgItemMessage(dlg, IDC_CHIP_STEREO, CB_GETCURSEL, 0, 0);
  824.       c1.sound.ay_samples = getcheck(IDC_CHIP_DIGITAL);
  825.    }
  826.    if (nm->code == PSN_SETACTIVE) {
  827.       setint(IDC_CHIP_CLK, int(c1.sound.ayfq));
  828.       SendDlgItemMessage(dlg, IDC_CHIP_BUS, CB_SETCURSEL, c1.sound.ay_chip, 0);
  829.       SendDlgItemMessage(dlg, IDC_CHIP_SCHEME, CB_SETCURSEL, c1.sound.ay_scheme, 0);
  830.       SendDlgItemMessage(dlg, IDC_CHIP_VOL, CB_SETCURSEL, c1.sound.ay_vols, 0);
  831.       SendDlgItemMessage(dlg, IDC_CHIP_STEREO, CB_SETCURSEL, c1.sound.ay_stereo, 0);
  832.       setcheck(IDC_CHIP_DIGITAL, c1.sound.ay_samples);
  833.       lastpage = "AY";
  834.    }
  835.    if (nm->code == PSN_APPLY) dlgok = 1;
  836.    if (nm->code == PSN_RESET) dlgok = 0;
  837.    return 1;
  838. }
  839.  
  840. static INT_PTR CALLBACK fir_dlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  841. {
  842.     (void)lp;
  843.    ::dlg = dlg;
  844.    if (msg == WM_INITDIALOG) {
  845.       setcheck(IDC_SIMPLE, (c1.rsm.mode == RSM_SIMPLE));
  846.       setcheck(IDC_FIR0, (c1.rsm.mode == RSM_FIR0));
  847.       setcheck(IDC_FIR1, (c1.rsm.mode == RSM_FIR1));
  848.       setcheck(IDC_FIR2, (c1.rsm.mode == RSM_FIR2));
  849.       SendDlgItemMessage(dlg, IDC_FRAMES, TBM_SETRANGE, 0, MAKELONG(2,8));
  850.       SendDlgItemMessage(dlg, IDC_FRAMES, TBM_SETPOS, 1, c1.rsm.mix_frames);
  851.    enable_slider:
  852.       BOOL en = !getcheck(IDC_SIMPLE);
  853.       EnableWindow(GetDlgItem(dlg, IDC_FRAMES), en);
  854.       EnableWindow(GetDlgItem(dlg, IDC_FRAMES_BOX), en);
  855.       return 0;
  856.    }
  857.    if (msg == WM_SYSCOMMAND && (wp & 0xFFF0) == SC_CLOSE) EndDialog(dlg, 0);
  858.    if (msg != WM_COMMAND) return 0;
  859.    unsigned id = LOWORD(wp), code = HIWORD(wp);
  860.    if (id == IDCANCEL) EndDialog(dlg, 0);
  861.    if (id == IDOK) {
  862.       if (getcheck(IDC_SIMPLE)) c1.rsm.mode = RSM_SIMPLE;
  863.       if (getcheck(IDC_FIR0)) c1.rsm.mode = RSM_FIR0;
  864.       if (getcheck(IDC_FIR1)) c1.rsm.mode = RSM_FIR1;
  865.       if (getcheck(IDC_FIR2)) c1.rsm.mode = RSM_FIR2;
  866.       c1.rsm.mix_frames = (unsigned char)SendDlgItemMessage(dlg, IDC_FRAMES, TBM_GETPOS, 0, 0);
  867.       EndDialog(dlg, 0);
  868.    }
  869.    if (code == BN_CLICKED && (id == IDC_FIR0 || id == IDC_FIR1 || id == IDC_FIR2 || id == IDC_SIMPLE)) goto enable_slider;
  870.    return 0;
  871. }
  872.  
  873. static INT_PTR CALLBACK VideoDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  874. {
  875.    ::dlg = dlg; unsigned id, code;
  876.    int i; //Alone Coder 0.36.7
  877.    if (msg == WM_INITDIALOG)
  878.    {
  879.       HWND box = GetDlgItem(dlg, IDC_VIDEOFILTER);
  880.       for (/*int*/ i = 0; renders[i].func; i++)
  881.          SendMessage(box, CB_ADDSTRING, 0, (LPARAM)renders[i].name);
  882.       SendMessage(box, CB_SETCURSEL, c1.render, 0);
  883.       box = GetDlgItem(dlg, IDC_RENDER);
  884.       for (i = 0; drivers[i].name; i++)
  885.          SendMessage(box, CB_ADDSTRING, 0, (LPARAM)drivers[i].name);
  886.       SendMessage(box, CB_SETCURSEL, c1.driver, 0);
  887.       box = GetDlgItem(dlg, IDC_PALETTE);
  888.       for (i = 0; i < (int)c1.num_pals; i++)
  889.          SendMessage(box, CB_ADDSTRING, 0, (LPARAM)pals[i].name);
  890.       SendMessage(box, CB_SETCURSEL, c1.pal, 0);
  891.       box = GetDlgItem(dlg, IDC_FONTHEIGHT);
  892.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"5pix, scroll");
  893.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"6pix, scroll");
  894.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"7pix, scroll");
  895.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"8pix, scroll");
  896.       SendMessage(box, CB_ADDSTRING, 0, (LPARAM)"8pix, fixed");
  897.       unsigned index = c1.fontsize - 5;
  898.       if (!c1.pixelscroll && index == 3) index++;
  899.       SendMessage(box, CB_SETCURSEL, index, 0);
  900.  
  901.       SendDlgItemMessage(dlg, IDC_SCRSHOT, CB_ADDSTRING, 0, (LPARAM)"scr");
  902.       SendDlgItemMessage(dlg, IDC_SCRSHOT, CB_ADDSTRING, 0, (LPARAM)"bmp");
  903.       SendDlgItemMessage(dlg, IDC_SCRSHOT, CB_ADDSTRING, 0, (LPARAM)"png");
  904.       SendDlgItemMessage(dlg, IDC_SCRSHOT, CB_SETCURSEL, conf.scrshot, 0);
  905.  
  906.       goto filter_changed;
  907.    }
  908.    if (msg == WM_COMMAND) {
  909.       id = LOWORD(wp);
  910.       code = HIWORD(wp);
  911.       if (id == IDC_FONT) { font_setup(dlg); return 1; }
  912.       if (id == IDC_FIR) { DialogBox(hIn, MAKEINTRESOURCE(IDD_FIR), dlg, fir_dlg); return 1; }
  913.       if ((id == IDC_NOFLIC || id == IDC_FAST_SL) && code == BN_CLICKED) goto filter_changed;
  914.       if (code == CBN_SELCHANGE && id == IDC_VIDEOFILTER) {
  915.    filter_changed:
  916.          unsigned filt_n = unsigned(SendDlgItemMessage(dlg, IDC_VIDEOFILTER, CB_GETCURSEL, 0, 0));
  917.          DWORD f = renders[filt_n].flags;
  918.          RENDER_FUNC rend = renders[filt_n].func;
  919.  
  920.          int sh = (f & (RF_USE32AS16 | RF_USEC32)) ? SW_SHOW : SW_HIDE;
  921.          ShowWindow(GetDlgItem(dlg, IDC_CH_TITLE), sh);
  922.          ShowWindow(GetDlgItem(dlg, IDC_CH2), sh);
  923.          ShowWindow(GetDlgItem(dlg, IDC_CH4), sh);
  924.          ShowWindow(GetDlgItem(dlg, IDC_CH_AUTO), sh);
  925.          sh = !sh;
  926.          ShowWindow(GetDlgItem(dlg, IDC_B_TITLE), sh);
  927.          ShowWindow(GetDlgItem(dlg, IDC_B0), sh);
  928.          ShowWindow(GetDlgItem(dlg, IDC_B1), sh);
  929.          ShowWindow(GetDlgItem(dlg, IDC_B2), sh);
  930.  
  931.          sh = (f & RF_BORDER)? SW_HIDE : SW_SHOW;
  932.          ShowWindow(GetDlgItem(dlg, IDC_FLASH), sh);
  933.  
  934.          sh = (((f & (RF_DRIVER | RF_8BPCH | RF_USEFONT)) == RF_DRIVER) || (rend == render_tv) || (rend == render_advmame))? SW_SHOW : SW_HIDE;
  935.          ShowWindow(GetDlgItem(dlg, IDC_NOFLIC), sh);
  936.  
  937.          if (!(f & RF_2X) || getcheck(IDC_FAST_SL) || !getcheck(IDC_NOFLIC)) sh = SW_HIDE;
  938.          ShowWindow(GetDlgItem(dlg, IDC_ALT_NOFLIC), sh);
  939.  
  940.          sh = (f & (RF_USEFONT)) ? SW_SHOW : SW_HIDE;
  941.          ShowWindow(GetDlgItem(dlg, IDC_FNTTITLE), sh);
  942.          ShowWindow(GetDlgItem(dlg, IDC_FONTHEIGHT), sh);
  943.          ShowWindow(GetDlgItem(dlg, IDC_FONT), sh);
  944.  
  945.          sh = (f & RF_DRIVER)? SW_SHOW : SW_HIDE;
  946.          ShowWindow(GetDlgItem(dlg, IDC_REND_TITLE), sh);
  947.          ShowWindow(GetDlgItem(dlg, IDC_RENDER), sh);
  948.  
  949.          sh = (rend == render_rsm)? SW_SHOW : SW_HIDE;
  950.          ShowWindow(GetDlgItem(dlg, IDC_FIR), sh);
  951.  
  952.          sh = (f & RF_2X) && (f & (RF_DRIVER | RF_USEC32))? SW_SHOW : SW_HIDE;
  953.          ShowWindow(GetDlgItem(dlg, IDC_FAST_SL), sh);
  954.  
  955.          sh = (rend == render_advmame) ? SW_SHOW : SW_HIDE;
  956.          ShowWindow(GetDlgItem(dlg, IDC_VIDEOSCALE), sh);
  957.          ShowWindow(GetDlgItem(dlg, IDC_VSCALE_TITLE1), sh);
  958.          ShowWindow(GetDlgItem(dlg, IDC_VSCALE_TITLE2), sh);
  959.          ShowWindow(GetDlgItem(dlg, IDC_VSCALE_TITLE3), sh);
  960.       }
  961.       return 1;
  962.    }
  963.  
  964.    if (msg != WM_NOTIFY) return 0;
  965.    NMHDR *nm = (NMHDR*)lp;
  966.  
  967.    if (nm->code == PSN_KILLACTIVE)
  968.    {
  969.       unsigned index = unsigned(SendDlgItemMessage(dlg, IDC_FONTHEIGHT, CB_GETCURSEL, 0, 0));
  970.       c1.pixelscroll = (index == 4)? 0 : 1;
  971.       c1.fontsize = (index == 4)? 8 : index + 5;
  972.       c1.render = unsigned(SendDlgItemMessage(dlg, IDC_VIDEOFILTER, CB_GETCURSEL, 0, 0));
  973.       c1.driver = unsigned(SendDlgItemMessage(dlg, IDC_RENDER, CB_GETCURSEL, 0, 0));
  974.       c1.frameskip = u8(getint(IDE_SKIP1));
  975.       c1.minres = unsigned(getint(IDE_MINX));
  976.       c1.frameskipmax = u8(getint(IDE_SKIP2));
  977.       c1.scanbright = unsigned(getint(IDE_SCBRIGHT));
  978.       c1.fast_sl = getcheck(IDC_FAST_SL);
  979.       c1.scrshot = int(SendDlgItemMessage(dlg, IDC_SCRSHOT, CB_GETCURSEL, 0, 0));
  980.       c1.flip = (conf.SyncMode == SM_VIDEO) ? 1 : getcheck(IDC_FLIP);
  981.       c1.updateb = getcheck(IDC_UPDB);
  982.       c1.pal = unsigned(SendDlgItemMessage(dlg, IDC_PALETTE, CB_GETCURSEL, 0, 0));
  983.       c1.flashcolor = getcheck(IDC_FLASH);
  984.       c1.noflic = getcheck(IDC_NOFLIC);
  985.       c1.alt_nf = getcheck(IDC_ALT_NOFLIC);
  986.       if (getcheck(IDC_B0)) c1.bordersize = 0;
  987.       if (getcheck(IDC_B1)) c1.bordersize = 1;
  988.       if (getcheck(IDC_B2)) c1.bordersize = 2;
  989.       if (getcheck(IDC_CH_AUTO)) c1.ch_size = 0;
  990.       if (getcheck(IDC_CH2)) c1.ch_size = 2;
  991.       if (getcheck(IDC_CH4)) c1.ch_size = 4;
  992.       c1.videoscale = (unsigned char)(SendDlgItemMessage(dlg, IDC_VIDEOSCALE, TBM_GETPOS, 0, 0));
  993.    }
  994.  
  995.    if (nm->code == PSN_SETACTIVE)
  996.    {
  997.       setint(IDE_SKIP1, c1.frameskip);
  998.       setint(IDE_SKIP2, c1.frameskipmax);
  999.       setint(IDE_MINX, int(c1.minres));
  1000.       setint(IDE_SCBRIGHT, int(c1.scanbright));
  1001.  
  1002.       SendDlgItemMessage(dlg, IDC_SCRSHOT, CB_SETCURSEL, c1.scrshot, 0);
  1003.  
  1004.       setcheck(IDC_FLIP, c1.flip);
  1005.       setcheck(IDC_UPDB, c1.updateb);
  1006.       setcheck(IDC_FLASH, c1.flashcolor);
  1007.       setcheck(IDC_NOFLIC, c1.noflic);
  1008.       setcheck(IDC_ALT_NOFLIC, c1.alt_nf);
  1009.       setcheck(IDC_FAST_SL, c1.fast_sl);
  1010.  
  1011.       SendDlgItemMessage(dlg, IDC_VIDEOSCALE, TBM_SETRANGE, 0, MAKELONG(1,4));
  1012.       SendDlgItemMessage(dlg, IDC_VIDEOSCALE, TBM_SETPOS, 1, c1.videoscale);
  1013.  
  1014.       SendDlgItemMessage(dlg, IDC_B0, BM_SETCHECK, c1.bordersize==0 ? BST_CHECKED : BST_UNCHECKED, 0);
  1015.       SendDlgItemMessage(dlg, IDC_B1, BM_SETCHECK, c1.bordersize==1 ? BST_CHECKED : BST_UNCHECKED, 0);
  1016.       SendDlgItemMessage(dlg, IDC_B2, BM_SETCHECK, c1.bordersize==2 ? BST_CHECKED : BST_UNCHECKED, 0);
  1017.  
  1018.       SendDlgItemMessage(dlg, IDC_CH_AUTO, BM_SETCHECK, c1.ch_size==0 ? BST_CHECKED : BST_UNCHECKED, 0);
  1019.       SendDlgItemMessage(dlg, IDC_CH2, BM_SETCHECK, c1.ch_size==2 ? BST_CHECKED : BST_UNCHECKED, 0);
  1020.       SendDlgItemMessage(dlg, IDC_CH4, BM_SETCHECK, c1.ch_size==4 ? BST_CHECKED : BST_UNCHECKED, 0);
  1021.       lastpage = "VIDEO";
  1022.       goto filter_changed;
  1023.    }
  1024.    if (nm->code == PSN_APPLY) dlgok = 1;
  1025.    if (nm->code == PSN_RESET) dlgok = 0;
  1026.    return 1;
  1027. }
  1028.  
  1029. #ifdef MOD_GSBASS
  1030. void SaveModDlg(HWND dlg)
  1031. {
  1032.     char fname[FILENAME_MAX];
  1033.     strncpy(fname, (char*)gs.mod, 20);
  1034.     fname[20] = 0;
  1035.     static const char *InvalidChars = "|<>?/\\\":*";
  1036.     for(char *ptr = fname; *ptr; ptr++)
  1037.     {
  1038.         if((*(u8*)ptr < ' ') || (strchr(InvalidChars, *ptr) != nullptr))
  1039.         {
  1040.             *ptr = ' ';
  1041.         }
  1042.     }
  1043.  
  1044.     OPENFILENAME ofn = { };
  1045.     ofn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME);
  1046.     ofn.lpstrFilter = "Amiga music module (MOD)\0*.mod\0";
  1047.     ofn.lpstrFile = fname;
  1048.     ofn.nMaxFile = _countof(fname);
  1049.     ofn.lpstrTitle = "Save music from GS";
  1050.     ofn.lpstrDefExt = "mod";
  1051.     ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_ENABLESIZING;
  1052.     ofn.hwndOwner = dlg;
  1053.     ofn.nFilterIndex = 1;
  1054.     if(GetSaveFileName(&ofn))
  1055.     {
  1056.         gs.debug_save_mod(fname);
  1057.     }
  1058. }
  1059. #endif // MOD_GSBASS
  1060.  
  1061. static struct
  1062. {
  1063.    unsigned ID;
  1064.    int *value;
  1065. } slider[] = {
  1066.    { IDC_SND_BEEPER,  &c1.sound.beeper_vol  },
  1067.    { IDC_SND_MICOUT,  &c1.sound.micout_vol  },
  1068.    { IDC_SND_MICIN,   &c1.sound.micin_vol   },
  1069.    { IDC_SND_AY,      &c1.sound.ay_vol      },
  1070.    { IDC_SND_COVOXFB, &c1.sound.covoxFB_vol },
  1071.    { IDC_SND_COVOXDD, &c1.sound.covoxDD_vol },
  1072.    { IDC_SND_SD,      &c1.sound.sd_vol      },
  1073.    { IDC_SND_BASS,    &c1.sound.bass_vol    },
  1074.    { IDC_SND_GS,      &c1.sound.gs_vol      },
  1075. };
  1076.  
  1077. static INT_PTR CALLBACK SoundDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1078. {
  1079.    ::dlg = dlg;
  1080.    if (msg == WM_INITDIALOG)
  1081.    {
  1082.       BOOL savemod = FALSE, reset = FALSE, fx_vol = FALSE, bass_vol = FALSE;
  1083. //      unsigned here_soundfilter = 1; //Alone Coder 0.36.4
  1084.       #ifdef MOD_GS
  1085.       if (c1.gs_type)
  1086.       {
  1087.          reset = TRUE;
  1088.  
  1089.          #ifdef MOD_GSZ80
  1090.          if (c1.gs_type == 1) fx_vol = TRUE;
  1091.          #endif
  1092.  
  1093.          #ifdef MOD_GSBASS
  1094.          if (c1.gs_type == 2) {
  1095.             fx_vol = bass_vol = TRUE;
  1096.             if (gs.mod && gs.modsize) savemod = TRUE;
  1097.          }
  1098.          #endif
  1099.       }
  1100.       #endif
  1101.  
  1102. //      EnableWindow(GetDlgItem(dlg, IDC_SOUNDFILTER), here_soundfilter); //Alone Coder 0.36.4
  1103.  
  1104.       EnableWindow(GetDlgItem(dlg, IDC_GSRESET), reset);
  1105.       EnableWindow(GetDlgItem(dlg, IDB_SAVEMOD), savemod);
  1106.       EnableWindow(GetDlgItem(dlg, IDC_GS_TITLE), fx_vol);
  1107.       EnableWindow(GetDlgItem(dlg, IDC_SND_GS), fx_vol);
  1108.       EnableWindow(GetDlgItem(dlg, IDC_SND_BASS), bass_vol);
  1109.       EnableWindow(GetDlgItem(dlg, IDC_BASS_TITLE), bass_vol);
  1110.    }
  1111.    if (msg == WM_COMMAND && LOWORD(wp) == IDC_NOSOUND) {
  1112.       c1.sound.enabled = !getcheck(IDC_NOSOUND);
  1113. upd:  for (size_t i = 0; i < sizeof slider/sizeof*slider; i++) {
  1114.          SendDlgItemMessage(dlg, slider[i].ID, TBM_SETRANGE, 0, MAKELONG(0,8192));
  1115.          SendDlgItemMessage(dlg, slider[i].ID, TBM_SETPOS, 1, c1.sound.enabled ? *slider[i].value : 0);
  1116.          SendDlgItemMessage(dlg, slider[i].ID, WM_ENABLE, c1.sound.enabled, 0);
  1117.       }
  1118.       return 1;
  1119.    }
  1120.  
  1121. #ifdef MOD_GSBASS
  1122.    if((msg == WM_COMMAND) && (LOWORD(wp) == IDB_SAVEMOD) && (HIWORD(wp) == BN_CLICKED))
  1123.    {
  1124.        SaveModDlg(dlg);
  1125.        return 1;
  1126.    }
  1127. #endif
  1128.  
  1129.    if (msg != WM_NOTIFY) return 0;
  1130.    NMHDR *nm = (NMHDR*)lp;
  1131.    if (nm->code == PSN_KILLACTIVE) {
  1132.       if ((c1.sound.enabled = (IsDlgButtonChecked(dlg, IDC_NOSOUND) != BST_CHECKED)))
  1133.          for (size_t i = 0; i < sizeof slider/sizeof*slider; i++)
  1134.             *slider[i].value = int(SendDlgItemMessage(dlg, slider[i].ID, TBM_GETPOS, 0, 0));
  1135.       c1.sound.gsreset = getcheck(IDC_GSRESET);
  1136.       c1.soundfilter = getcheck(IDC_SOUNDFILTER); //Alone Coder 0.36.4
  1137.    }
  1138.    if (nm->code == PSN_SETACTIVE) {
  1139.       setcheck(IDC_NOSOUND, !c1.sound.enabled);
  1140.       setcheck(IDC_GSRESET, c1.sound.gsreset);
  1141.       setcheck(IDC_SOUNDFILTER, c1.soundfilter); //Alone Coder 0.36.4
  1142.       lastpage = "SOUND";
  1143.       goto upd;
  1144.    }
  1145.    if (nm->code == PSN_APPLY) dlgok = 1;
  1146.    if (nm->code == PSN_RESET) dlgok = 0;
  1147.    return 1;
  1148. }
  1149.  
  1150. static INT_PTR CALLBACK TapeDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1151. {
  1152.     (void)wp;
  1153.     ::dlg = dlg;
  1154.     if(msg == WM_INITDIALOG)
  1155.     {
  1156.         find_tape_index();
  1157.         for(unsigned i = 0; i < tape_infosize; i++)
  1158.         {
  1159.             SendDlgItemMessage(dlg, IDC_TAPE, LB_ADDSTRING, 0, (LPARAM)tapeinfo[i].desc);
  1160.         }
  1161.     }
  1162.     if(msg != WM_NOTIFY) return 0;
  1163.     NMHDR *nm = (NMHDR*)lp;
  1164.     if(nm->code == PSN_KILLACTIVE)
  1165.     {
  1166.         unsigned Idx = unsigned(SendDlgItemMessage(dlg, IDC_TAPE, LB_GETCURSEL, 0, 0));
  1167.         if(Idx != -1U && Idx != comp.tape.index)
  1168.         {
  1169.             comp.tape.index = Idx;
  1170.             comp.tape.play_pointer = tape_image + tapeinfo[comp.tape.index].pos;
  1171.         }
  1172.  
  1173.         c1.tape_autostart = getcheck(IDC_TAPE_AUTOSTART);
  1174.         c1.tape_traps = getcheck(IDC_TAPE_TRAPS);
  1175.     }
  1176.     if(nm->code == PSN_SETACTIVE)
  1177.     {
  1178.         SendDlgItemMessage(dlg, IDC_TAPE, LB_SETCURSEL, comp.tape.index, 0);
  1179.         setcheck(IDC_TAPE_AUTOSTART, c1.tape_autostart);
  1180.         setcheck(IDC_TAPE_TRAPS, c1.tape_traps);
  1181.         lastpage = "TAPE";
  1182.     }
  1183.     if(nm->code == PSN_APPLY) dlgok = 1;
  1184.     if(nm->code == PSN_RESET) dlgok = 0;
  1185.     return 1;
  1186. }
  1187.  
  1188.  
  1189. static void FillModemList(HWND box)
  1190. {
  1191.    ComboBox_AddString(box, "NONE");
  1192.    for (unsigned port = 1; port < 256; port++)
  1193.    {
  1194.       HANDLE hPort;
  1195.       if (modem.open_port == port)
  1196.           hPort = modem.hPort;
  1197.       else
  1198.       {
  1199.          char portName[11];
  1200.          _snprintf(portName, _countof(portName), "\\\\.\\COM%u", port);
  1201.  
  1202.          hPort = CreateFile(portName, 0, 0, nullptr, OPEN_EXISTING, 0, nullptr);
  1203.          if (hPort == INVALID_HANDLE_VALUE)
  1204.              continue;
  1205.       }
  1206.  
  1207.       struct
  1208.       {
  1209.          COMMPROP comm;
  1210.          char xx[4000];
  1211.       } b;
  1212.  
  1213.       b.comm.wPacketLength = sizeof(b);
  1214.       b.comm.dwProvSpec1 = COMMPROP_INITIALIZED;
  1215.       if (GetCommProperties(hPort, &b.comm) && b.comm.dwProvSubType == PST_MODEM)
  1216.       {
  1217.          MODEMDEVCAPS *mc = (MODEMDEVCAPS*)&b.comm.wcProvChar;
  1218.          char vendor[0x100], model[0x100];
  1219.  
  1220.          int vsize = int(mc->dwModemManufacturerSize / sizeof(WCHAR));
  1221.          WideCharToMultiByte(CP_ACP, 0, (WCHAR*)(PCHAR(mc) + mc->dwModemManufacturerOffset), vsize, vendor, sizeof vendor, nullptr, nullptr);
  1222.          vendor[vsize] = 0;
  1223.  
  1224.          int msize = int(mc->dwModemModelSize / sizeof(WCHAR));
  1225.          WideCharToMultiByte(CP_ACP, 0, (WCHAR*)(PCHAR(mc) + mc->dwModemModelOffset), msize, model, sizeof model, nullptr, nullptr);
  1226.          model[msize] = 0;
  1227.          char line[0x200];
  1228.          _snprintf(line, _countof(line), "COM%u: %s %s", port, vendor, model);
  1229.          ComboBox_AddString(box, line);
  1230.       }
  1231.       else
  1232.       {
  1233.          char portName[11];
  1234.          _snprintf(portName, _countof(portName), "COM%u:", port);
  1235.          ComboBox_AddString(box, portName);
  1236.       }
  1237.       if (modem.open_port != port)
  1238.           CloseHandle(hPort);
  1239.    }
  1240. }
  1241.  
  1242. static void SelectModem(HWND box)
  1243. {
  1244.    if (!c1.modem_port)
  1245.    {
  1246.        ComboBox_SetCurSel(box, 0);
  1247.        return;
  1248.    }
  1249.  
  1250.    char line[0x200];
  1251.    int Cnt = ComboBox_GetCount(box);
  1252.    for (int i = 0; i < Cnt; i++)
  1253.    {
  1254.       ComboBox_GetLBText(box, i, line);
  1255.       int Port = 0;
  1256.       sscanf(line, "COM%d", &Port);
  1257.       if (Port == c1.modem_port)
  1258.       {
  1259.          SendMessage(box, CB_SETCURSEL, i, 0);
  1260.          ComboBox_SetCurSel(box, i);
  1261.          return;
  1262.       }
  1263.    }
  1264. }
  1265.  
  1266. static int GetModemPort(HWND box)
  1267. {
  1268.    int index = ComboBox_GetCurSel(box);
  1269.    if (!index)
  1270.        return 0;
  1271.  
  1272.    char line[0x200];
  1273.    ComboBox_GetLBText(box, index, line);
  1274.    int Port = 0;
  1275.    sscanf(line, "COM%d", &Port);
  1276.    return Port;
  1277. }
  1278.  
  1279. static INT_PTR CALLBACK InputDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1280. {
  1281.     (void)wp;
  1282.    ::dlg = dlg; char names[0x2000];
  1283.    if (msg == WM_INITDIALOG) {
  1284.       zxkeymap *active_zxk = conf.input.active_zxk;
  1285.       for (unsigned i = 0; i < active_zxk->zxk_size; i++)
  1286.          SendDlgItemMessage(dlg, IDC_FIREKEY, CB_ADDSTRING, 0, (LPARAM)active_zxk->zxk[i].name);
  1287.       GetPrivateProfileSectionNames(names, sizeof names, ininame);
  1288.       for (char *ptr = names; *ptr; ptr += strlen(ptr)+1)
  1289.          if (!strnicmp(ptr, "ZX.KEYS.", sizeof("ZX.KEYS.")-1)) {
  1290.             char line[0x200]; GetPrivateProfileString(ptr, "Name", ptr, line, sizeof line, ininame);
  1291.             SendDlgItemMessage(dlg, IDC_KLAYOUT, CB_ADDSTRING, 0, (LPARAM)line);
  1292.          }
  1293.       FillModemList(GetDlgItem(dlg, IDC_MODEM));
  1294.    }
  1295.    if (msg != WM_NOTIFY) return 0;
  1296.    NMHDR *nm = (NMHDR*)lp;
  1297.    if (nm->code == PSN_KILLACTIVE) {
  1298.       if (getcheck(IDC_MOUSE_NONE)) c1.input.mouse = 0;
  1299.       if (getcheck(IDC_MOUSE_KEMPSTON)) c1.input.mouse = 1;
  1300.       if (getcheck(IDC_MOUSE_AY)) c1.input.mouse = 2;
  1301.       if (getcheck(IDC_WHEEL_NONE)) c1.input.mousewheel = MOUSE_WHEEL_NONE;
  1302.       if (getcheck(IDC_WHEEL_KEYBOARD)) c1.input.mousewheel = MOUSE_WHEEL_KEYBOARD;
  1303.       if (getcheck(IDC_WHEEL_KEMPSTON)) c1.input.mousewheel = MOUSE_WHEEL_KEMPSTON;
  1304.       c1.input.keybpcmode = getcheck(IDC_PC_LAYOUT);
  1305.       c1.input.mouseswap = getcheck(IDC_MOUSESWAP);
  1306.       c1.input.kjoy = getcheck(IDC_KJOY);
  1307.       c1.input.fjoy = getcheck(IDC_FJOY);
  1308.       c1.input.keymatrix = getcheck(IDC_KEYMATRIX);
  1309.       c1.input.mousescale = (char)(SendDlgItemMessage(dlg, IDC_MOUSESCALE, TBM_GETPOS, 0, 0) - 3);
  1310.       c1.input.joymouse = getcheck(IDC_JOYMOUSE);
  1311.       c1.input.firenum = unsigned(SendDlgItemMessage(dlg, IDC_FIREKEY, CB_GETCURSEL, 0, 0));
  1312.       c1.input.fire = getcheck(IDC_AUTOFIRE);
  1313.       c1.input.firedelay = u8(getint(IDE_FIRERATE));
  1314.       c1.input.altlock = getcheck(IDC_ALTLOCK);
  1315.       c1.input.paste_hold = u8(getint(IDE_HOLD_DELAY));
  1316.       c1.input.paste_release = u8(getint(IDE_RELEASE_DELAY));
  1317.       c1.input.paste_newline = u8(getint(IDE_NEWLINE_DELAY));
  1318.       c1.atm.xt_kbd = getcheck(IDC_ATM_KBD);
  1319.       c1.modem_port = GetModemPort(GetDlgItem(dlg, IDC_MODEM));
  1320.       GetPrivateProfileSectionNames(names, sizeof names, ininame);
  1321.       int n = int(SendDlgItemMessage(dlg, IDC_KLAYOUT, CB_GETCURSEL, 0, 0)), i = 0;
  1322.       for (char *ptr = names; *ptr; ptr += strlen(ptr)+1)
  1323.          if (!strnicmp(ptr, "ZX.KEYS.", sizeof("ZX.KEYS.")-1)) {
  1324.             if (i == n) strcpy(c1.keyset, ptr+sizeof("ZX.KEYS.")-1);
  1325.             i++;
  1326.          }
  1327.    }
  1328.    if (nm->code == PSN_SETACTIVE) {
  1329.       setcheck(IDC_MOUSE_NONE, c1.input.mouse == 0);
  1330.       setcheck(IDC_MOUSE_KEMPSTON, c1.input.mouse == 1);
  1331.       setcheck(IDC_MOUSE_AY, c1.input.mouse == 2);
  1332.       setcheck(IDC_PC_LAYOUT, c1.input.keybpcmode);
  1333.       setcheck(IDC_WHEEL_NONE, c1.input.mousewheel == MOUSE_WHEEL_NONE);
  1334.       setcheck(IDC_WHEEL_KEYBOARD, c1.input.mousewheel == MOUSE_WHEEL_KEYBOARD);
  1335.       setcheck(IDC_WHEEL_KEMPSTON, c1.input.mousewheel == MOUSE_WHEEL_KEMPSTON);
  1336.       setcheck(IDC_MOUSESWAP, c1.input.mouseswap);
  1337.       setcheck(IDC_KJOY, c1.input.kjoy);
  1338.       setcheck(IDC_FJOY, c1.input.fjoy);
  1339.       setcheck(IDC_KEYMATRIX, c1.input.keymatrix);
  1340.       setcheck(IDC_JOYMOUSE, c1.input.joymouse);
  1341.       setcheck(IDC_AUTOFIRE, c1.input.fire);
  1342.       setcheck(IDC_ALTLOCK, c1.input.altlock);
  1343.       setcheck(IDC_ATM_KBD, c1.atm.xt_kbd);
  1344.       SendDlgItemMessage(dlg, IDC_MOUSESCALE, TBM_SETRANGE, 0, MAKELONG(0,6));
  1345.       SendDlgItemMessage(dlg, IDC_MOUSESCALE, TBM_SETPOS, 1, c1.input.mousescale+3);
  1346.       SendDlgItemMessage(dlg, IDC_FIREKEY, CB_SETCURSEL, c1.input.firenum, 0);
  1347.       setint(IDE_FIRERATE, c1.input.firedelay);
  1348.       setint(IDE_HOLD_DELAY, c1.input.paste_hold);
  1349.       setint(IDE_RELEASE_DELAY, c1.input.paste_release);
  1350.       setint(IDE_NEWLINE_DELAY, c1.input.paste_newline);
  1351.       SelectModem(GetDlgItem(dlg, IDC_MODEM));
  1352.       GetPrivateProfileSectionNames(names, sizeof names, ininame);
  1353.       int i = 0;
  1354.       for (char *ptr = names; *ptr; ptr += strlen(ptr)+1)
  1355.          if (!strnicmp(ptr, "ZX.KEYS.", sizeof("ZX.KEYS.")-1)) {
  1356.             if (!strnicmp(c1.keyset, ptr+sizeof("ZX.KEYS.")-1, strlen(c1.keyset)))
  1357.                SendDlgItemMessage(dlg, IDC_KLAYOUT, CB_SETCURSEL, i, 0);
  1358.             i++;
  1359.          }
  1360.       lastpage = "INPUT";
  1361.    }
  1362.    if (nm->code == PSN_APPLY) dlgok = 1;
  1363.    if (nm->code == PSN_RESET) dlgok = 0;
  1364.    return 1;
  1365. }
  1366.  
  1367. static INT_PTR CALLBACK LedsDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1368. {
  1369.    static int ids[NUM_LEDS][3] = {
  1370.      { IDC_LED_AY, IDC_LED_AY_X, IDC_LED_AY_Y },
  1371.      { IDC_LED_PERF, IDC_LED_PERF_X, IDC_LED_PERF_Y },
  1372.      { IDC_LED_LOAD, IDC_LED_ROM_X, IDC_LED_ROM_Y },
  1373.      { IDC_LED_INPUT, IDC_LED_INPUT_X, IDC_LED_INPUT_Y },
  1374.      { IDC_LED_TIME, IDC_LED_TIME_X, IDC_LED_TIME_Y },
  1375.      { IDC_LED_DEBUG, IDC_LED_DEBUG_X, IDC_LED_DEBUG_Y },
  1376.      { IDC_LED_MEMBAND, IDC_LED_MEMBAND_X, IDC_LED_MEMBAND_Y }
  1377.    };
  1378.    static volatile char block=0;
  1379.    ::dlg = dlg;
  1380.    if (msg == WM_USER || (!block && msg == WM_COMMAND && (HIWORD(wp)==EN_CHANGE || HIWORD(wp)==BN_CLICKED)))
  1381.    {
  1382.       unsigned char ld_on = getcheck(IDC_LED_ON);
  1383.       c1.led.enabled = ld_on;
  1384.       c1.led.perf_t = getcheck(IDC_PERF_T);
  1385.       c1.led.flash_ay_kbd = getcheck(IDC_LED_AYKBD);
  1386.       for (unsigned i = 0; i < NUM_LEDS; i++) {
  1387.          char b1[16], b2[16];
  1388.          SendDlgItemMessage(dlg, ids[i][1], WM_GETTEXT, sizeof b1, (LPARAM)b1);
  1389.          SendDlgItemMessage(dlg, ids[i][2], WM_GETTEXT, sizeof b2, (LPARAM)b2);
  1390.          if (!*b1 || !*b2) continue; // skip first notification with empty controls
  1391.          unsigned a = unsigned(atoi(b1) & 0xFFFF) + unsigned((atoi(b2) & 0x7FFF) << 16);
  1392.          if (IsDlgButtonChecked(dlg, ids[i][0]) == BST_CHECKED) a |= 0x80000000;
  1393.          unsigned char x = ld_on && (a & 0x80000000);
  1394.          EnableWindow(GetDlgItem(dlg, ids[i][0]), ld_on);
  1395.          EnableWindow(GetDlgItem(dlg, ids[i][1]), x);
  1396.          EnableWindow(GetDlgItem(dlg, ids[i][2]), x);
  1397.          (&c1.led.ay)[i] = a;
  1398.       }
  1399.       EnableWindow(GetDlgItem(dlg, IDC_LED_AYKBD), (ld_on && hndKbdDev));
  1400.       EnableWindow(GetDlgItem(dlg, IDC_PERF_T), ld_on && (c1.led.perf & 0x80000000));
  1401.       EnableWindow(GetDlgItem(dlg, IDC_LED_BPP), ld_on && (c1.led.memband & 0x80000000));
  1402.  
  1403.       #ifndef MOD_MONITOR
  1404.       c1.led.osw &= 0x7FFFFFFF;
  1405.       EnableWindow(GetDlgItem(dlg, IDC_LED_DEBUG), 0);
  1406.       #endif
  1407.  
  1408.       #ifndef MOD_MEMBAND_LED
  1409.       c1.led.memband &= 0x7FFFFFFF;
  1410.       EnableWindow(GetDlgItem(dlg, IDC_LED_MEMBAND), 0);
  1411.       #endif
  1412.    }
  1413.    if (msg != WM_NOTIFY) return 0;
  1414.    NMHDR *nm = (NMHDR*)lp;
  1415.    if (nm->code == PSN_KILLACTIVE) {
  1416.       unsigned pos = unsigned(SendDlgItemMessage(dlg, IDC_LED_BPP, TBM_GETPOS, 0, 0));
  1417.       if (pos == 0) c1.led.bandBpp = 64;
  1418.       else if (pos == 1) c1.led.bandBpp = 128;
  1419.       else if (pos == 2) c1.led.bandBpp = 256;
  1420.       else c1.led.bandBpp = 512;
  1421.    }
  1422.    if (nm->code == PSN_SETACTIVE) {
  1423.       block = 1;
  1424.       setcheck(IDC_LED_ON, c1.led.enabled);
  1425.       setcheck(IDC_LED_AYKBD, c1.led.flash_ay_kbd);
  1426.       setcheck(IDC_PERF_T, c1.led.perf_t);
  1427.       unsigned pos = 3;
  1428.       if (c1.led.bandBpp == 64) pos = 0;
  1429.       if (c1.led.bandBpp == 128) pos = 1;
  1430.       if (c1.led.bandBpp == 256) pos = 2;
  1431.       SendDlgItemMessage(dlg, IDC_LED_BPP, TBM_SETRANGE, 0, MAKELONG(0,3));
  1432.       SendDlgItemMessage(dlg, IDC_LED_BPP, TBM_SETPOS, 1, pos);
  1433.       for (unsigned i = 0; i < NUM_LEDS; i++) {
  1434.          unsigned a = (&c1.led.ay)[i];
  1435.          char bf[16]; sprintf(bf, "%d", (signed short)(a & 0xFFFF));
  1436.          SendDlgItemMessage(dlg, ids[i][1], WM_SETTEXT, 0, (LPARAM)bf);
  1437.          sprintf(bf, "%d", (signed short)(((a >> 16) & 0x7FFF) + ((a >> 15) & 0x8000)));
  1438.          SendDlgItemMessage(dlg, ids[i][2], WM_SETTEXT, 0, (LPARAM)bf);
  1439.          setcheck(ids[i][0], a >> 31);
  1440.       }
  1441.       LedsDlg(dlg, WM_USER, 0, 0);
  1442.       block = 0;
  1443.       lastpage = "LEDS";
  1444.    }
  1445.  
  1446.    if (nm->code == PSN_APPLY) dlgok = 1;
  1447.    if (nm->code == PSN_RESET) dlgok = 0;
  1448.    return 1;
  1449. }
  1450.  
  1451. static INT_PTR CALLBACK BetaDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1452. {
  1453.    ::dlg = dlg;
  1454.    unsigned ID = LOWORD(wp);
  1455.    if (msg == WM_INITDIALOG)
  1456.    {
  1457.       setcheck(IDC_DISK_TRAPS, c1.trdos_traps);
  1458.    }
  1459.    if (msg == WM_COMMAND)
  1460.    {
  1461.       unsigned disk;
  1462.       switch (ID)
  1463.       {
  1464.          case IDB_INS_A: disk = 0; goto load;
  1465.          case IDB_INS_B: disk = 1; goto load;
  1466.          case IDB_INS_C: disk = 2; goto load;
  1467.          case IDB_INS_D: disk = 3; goto load;
  1468.          load:
  1469.             if (!comp.fdd[disk].test())
  1470.                 return 1;
  1471.             opensnap(disk+1);
  1472.             c1.trdos_wp[disk] = conf.trdos_wp[disk];
  1473.             goto reload;
  1474.  
  1475.          case IDB_REM_A: disk = 0; goto remove;
  1476.          case IDB_REM_B: disk = 1; goto remove;
  1477.          case IDB_REM_C: disk = 2; goto remove;
  1478.          case IDB_REM_D: disk = 3; goto remove;
  1479.          remove:
  1480.             if (!comp.fdd[disk].test())
  1481.                 return 1;
  1482.             comp.wd.Eject(disk);
  1483.             c1.trdos_wp[disk] = conf.trdos_wp[disk];
  1484.             goto reload;
  1485.  
  1486.          case IDB_SAVE_A: savesnap(0); goto reload;
  1487.          case IDB_SAVE_B: savesnap(1); goto reload;
  1488.          case IDB_SAVE_C: savesnap(2); goto reload;
  1489.          case IDB_SAVE_D: savesnap(3); goto reload;
  1490.  
  1491.          case IDC_BETA128:
  1492.             c1.trdos_present = getcheck(IDC_BETA128);
  1493.             goto reload;
  1494.  
  1495.          case IDC_DISK_TRAPS:
  1496.             c1.trdos_traps = getcheck(IDC_DISK_TRAPS); break;
  1497.  
  1498.          case IDC_DISK_NODELAY:
  1499.             c1.wd93_nodelay = getcheck(IDC_DISK_NODELAY); break;
  1500.       }
  1501.    }
  1502.    if (msg != WM_NOTIFY) return 0;
  1503.    {NMHDR *nm = (NMHDR*)lp;
  1504.    if (nm->code == PSN_KILLACTIVE) {
  1505.       c1.trdos_present = getcheck(IDC_BETA128);
  1506.       c1.trdos_traps = getcheck(IDC_DISK_TRAPS);
  1507.       c1.wd93_nodelay = getcheck(IDC_DISK_NODELAY);
  1508.       c1.trdos_wp[0] = getcheck(IDC_WPA);
  1509.       c1.trdos_wp[1] = getcheck(IDC_WPB);
  1510.       c1.trdos_wp[2] = getcheck(IDC_WPC);
  1511.       c1.trdos_wp[3] = getcheck(IDC_WPD);
  1512.    }
  1513.    if (nm->code == PSN_SETACTIVE) { lastpage = "Beta128"; goto reload; }
  1514.    if (nm->code == PSN_APPLY) dlgok = 1;
  1515.    if (nm->code == PSN_RESET) dlgok = 0;
  1516.    return 1;}
  1517. reload:
  1518.    SendDlgItemMessage(dlg, IDE_DISK_A, WM_SETTEXT, 0, (LPARAM)comp.fdd[0].name);
  1519.    SendDlgItemMessage(dlg, IDE_DISK_B, WM_SETTEXT, 0, (LPARAM)comp.fdd[1].name);
  1520.    SendDlgItemMessage(dlg, IDE_DISK_C, WM_SETTEXT, 0, (LPARAM)comp.fdd[2].name);
  1521.    SendDlgItemMessage(dlg, IDE_DISK_D, WM_SETTEXT, 0, (LPARAM)comp.fdd[3].name);
  1522.    setcheck(IDC_BETA128, c1.trdos_present);
  1523.    setcheck(IDC_DISK_TRAPS, c1.trdos_traps);
  1524.    setcheck(IDC_DISK_NODELAY, c1.wd93_nodelay);
  1525.    setcheck(IDC_WPA, c1.trdos_wp[0]);
  1526.    setcheck(IDC_WPB, c1.trdos_wp[1]);
  1527.    setcheck(IDC_WPC, c1.trdos_wp[2]);
  1528.    setcheck(IDC_WPD, c1.trdos_wp[3]);
  1529.    BOOL on = getcheck(IDC_BETA128);
  1530.    EnableWindow(GetDlgItem(dlg, IDC_DISK_TRAPS), on);
  1531.    EnableWindow(GetDlgItem(dlg, IDC_DISK_NODELAY), on);
  1532.  
  1533.    EnableWindow(GetDlgItem(dlg, IDB_INS_A), on);
  1534.    EnableWindow(GetDlgItem(dlg, IDB_INS_B), on);
  1535.    EnableWindow(GetDlgItem(dlg, IDB_INS_C), on);
  1536.    EnableWindow(GetDlgItem(dlg, IDB_INS_D), on);
  1537.  
  1538.    EnableWindow(GetDlgItem(dlg, IDB_REM_A), on);
  1539.    EnableWindow(GetDlgItem(dlg, IDB_REM_B), on);
  1540.    EnableWindow(GetDlgItem(dlg, IDB_REM_C), on);
  1541.    EnableWindow(GetDlgItem(dlg, IDB_REM_D), on);
  1542.  
  1543.    EnableWindow(GetDlgItem(dlg, IDB_SAVE_A), on && comp.fdd[0].rawdata);
  1544.    EnableWindow(GetDlgItem(dlg, IDB_SAVE_B), on && comp.fdd[1].rawdata);
  1545.    EnableWindow(GetDlgItem(dlg, IDB_SAVE_C), on && comp.fdd[2].rawdata);
  1546.    EnableWindow(GetDlgItem(dlg, IDB_SAVE_D), on && comp.fdd[3].rawdata);
  1547.  
  1548.    ShowWindow(GetDlgItem(dlg, IDC_MODA), comp.fdd[0].optype? SW_SHOW : SW_HIDE);
  1549.    ShowWindow(GetDlgItem(dlg, IDC_MODB), comp.fdd[1].optype? SW_SHOW : SW_HIDE);
  1550.    ShowWindow(GetDlgItem(dlg, IDC_MODC), comp.fdd[2].optype? SW_SHOW : SW_HIDE);
  1551.    ShowWindow(GetDlgItem(dlg, IDC_MODD), comp.fdd[3].optype? SW_SHOW : SW_HIDE);
  1552.    return 1;
  1553. }
  1554.  
  1555. // Ngs=true/Zc=false
  1556. static bool OpenSdImage(bool Ngs)
  1557. {
  1558.    OPENFILENAME fn = { };
  1559.  
  1560.    char SdImage[FILENAME_MAX];
  1561.    SdImage[0] = 0;
  1562.  
  1563.    fn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME);
  1564.    fn.hwndOwner = dlg;
  1565.    fn.lpstrFilter = "SD card image (*.*)\0*.*\0";
  1566.    fn.lpstrFile = SdImage;
  1567.    fn.nMaxFile = _countof(SdImage);
  1568.    fn.lpstrTitle = "Select SD card image";
  1569.    fn.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  1570.    fn.lpstrInitialDir   = temp.SdDir;
  1571.    if (!GetOpenFileName(&fn))
  1572.        return false;
  1573.    strcpy(temp.SdDir, fn.lpstrFile);
  1574.    char *Ptr = strrchr(temp.SdDir, '\\');
  1575.    if(Ptr)
  1576.     *Ptr = 0;
  1577.  
  1578.    int file = open(SdImage, O_RDONLY | O_BINARY, S_IREAD);
  1579.    if(file < 0)
  1580.        return false;
  1581.    __int64 sz = _filelengthi64(file);
  1582.    close(file);
  1583.  
  1584.    strcpy(Ngs ? c1.ngs_sd_card_path : c1.zc_sd_card_path, SdImage);
  1585.    return true;
  1586. }
  1587.  
  1588. static void NgsDlgSetEnable()
  1589. {
  1590.     bool on = (c1.gs_type != 0);
  1591.     EnableWindow(GetDlgItem(dlg, IDC_COMBO_GS_RAM_SIZE), on);
  1592.     EnableWindow(GetDlgItem(dlg, IDB_SD_NGS), on);
  1593. }
  1594.  
  1595. static INT_PTR CALLBACK NgsDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1596. {
  1597.    ::dlg = dlg;
  1598.     switch(msg)
  1599.     {
  1600.     case WM_INITDIALOG:
  1601.     {
  1602.         HWND CbGsType = GetDlgItem(dlg, IDC_COMBO_GS_TYPE);
  1603.         ComboBox_AddString(CbGsType, "None"); // 0
  1604.         ComboBox_AddString(CbGsType, "Z80"); // 1
  1605.         ComboBox_AddString(CbGsType, "Bass"); // 2
  1606.  
  1607.         HWND CbGsRamSize = GetDlgItem(dlg, IDC_COMBO_GS_RAM_SIZE);
  1608.         ComboBox_AddString(CbGsRamSize, "512"); // 0
  1609.         ComboBox_AddString(CbGsRamSize, "2048"); // 1
  1610.         ComboBox_AddString(CbGsRamSize, "4096"); // 2
  1611.  
  1612.         return TRUE;
  1613.     }
  1614.  
  1615.     case WM_COMMAND:
  1616.         {
  1617.             unsigned id = LOWORD(wp);
  1618.             unsigned nc = HIWORD(wp);
  1619.             if ((id == IDB_SD_NGS) && (nc == BN_CLICKED))
  1620.             {
  1621.                 if(OpenSdImage(true))
  1622.                 {
  1623.                     SetDlgItemText(dlg, IDE_SD_NGS, c1.ngs_sd_card_path);
  1624.                 }
  1625.                 return TRUE;
  1626.             }
  1627.  
  1628.             if((id == IDC_COMBO_GS_TYPE) && (nc == CBN_SELCHANGE))
  1629.             {
  1630.                 c1.gs_type = u8(ComboBox_GetCurSel(HWND(lp)));
  1631.  
  1632.                 NgsDlgSetEnable();
  1633.                 return TRUE;
  1634.             }
  1635.  
  1636.             if((id == IDC_COMBO_GS_RAM_SIZE) && (nc == CBN_SELCHANGE))
  1637.             {
  1638.                 int GsRamSize = ComboBox_GetCurSel(HWND(lp));
  1639.                 switch(GsRamSize)
  1640.                 {
  1641.                 case 0:
  1642.                     c1.gs_ramsize = 512;
  1643.                     break;
  1644.                 case 1:
  1645.                     c1.gs_ramsize = 2048;
  1646.                     break;
  1647.                 case 2:
  1648.                     c1.gs_ramsize = 4096;
  1649.                     break;
  1650.                 }
  1651.                 return TRUE;
  1652.             }
  1653.         }
  1654.         return FALSE;
  1655.  
  1656.     case WM_NOTIFY:
  1657.     break;
  1658.  
  1659.     default:
  1660.         return FALSE;
  1661.     }
  1662.  
  1663.     // WM_NOTIFY
  1664.     const NMHDR *nm = (const NMHDR *)lp;
  1665.     if(nm->code == PSN_KILLACTIVE)
  1666.     {
  1667.     }
  1668.  
  1669.     if(nm->code == PSN_SETACTIVE)
  1670.     {
  1671.         lastpage = "NGS";
  1672.         SetDlgItemText(dlg, IDE_SD_NGS, c1.ngs_sd_card_path);
  1673.  
  1674.  
  1675.         ComboBox_SetCurSel(GetDlgItem(dlg, IDC_COMBO_GS_TYPE), c1.gs_type);
  1676.  
  1677.         switch(c1.gs_ramsize)
  1678.         {
  1679.         case 512:
  1680.             ComboBox_SetCurSel(GetDlgItem(dlg, IDC_COMBO_GS_RAM_SIZE), 0);
  1681.             break;
  1682.         case 2048:
  1683.             ComboBox_SetCurSel(GetDlgItem(dlg, IDC_COMBO_GS_RAM_SIZE), 1);
  1684.             break;
  1685.         case 4096:
  1686.             ComboBox_SetCurSel(GetDlgItem(dlg, IDC_COMBO_GS_RAM_SIZE), 2);
  1687.             break;
  1688.         }
  1689.  
  1690.         NgsDlgSetEnable();
  1691.  
  1692.         return TRUE;
  1693.     }
  1694.  
  1695.     if(nm->code == PSN_APPLY) dlgok = 1;
  1696.     if(nm->code == PSN_RESET) dlgok = 0;
  1697.  
  1698.     return TRUE;
  1699. }
  1700.  
  1701. static void ZcDlgEnableControls()
  1702. {
  1703.     EnableWindow(GetDlgItem(dlg, IDE_SD_ZC), c1.zc);
  1704.     EnableWindow(GetDlgItem(dlg, IDB_SD_ZC), c1.zc);
  1705. }
  1706.  
  1707. static INT_PTR CALLBACK ZcDlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  1708. {
  1709.    ::dlg = dlg;
  1710.     switch(msg)
  1711.     {
  1712.     case WM_INITDIALOG:
  1713.         return TRUE;
  1714.  
  1715.     case WM_COMMAND:
  1716.         {
  1717.             unsigned id = LOWORD(wp);
  1718.             unsigned nc = HIWORD(wp);
  1719.             if ((id == IDB_SD_ZC) && (nc == BN_CLICKED)) // ═рцрЄшх ъэюяъш [...]
  1720.             {
  1721.                 if(OpenSdImage(false))
  1722.                 {
  1723.                     SetDlgItemText(dlg, IDE_SD_ZC, c1.zc_sd_card_path);
  1724.                 }
  1725.                 return TRUE;
  1726.             }
  1727.             if((id == IDC_ZC_ENABLED) && (nc == BN_CLICKED))
  1728.             {
  1729.                 c1.zc = getcheck(IDC_ZC_ENABLED);
  1730.                 ZcDlgEnableControls();
  1731.                 return TRUE;
  1732.             }
  1733.         }
  1734.         return FALSE;
  1735.  
  1736.     case WM_NOTIFY:
  1737.     break;
  1738.  
  1739.     default:
  1740.         return FALSE;
  1741.     }
  1742.  
  1743.     // WM_NOTIFY
  1744.     const NMHDR *nm = (const NMHDR *)lp;
  1745.     if(nm->code == PSN_KILLACTIVE)
  1746.     {
  1747.     }
  1748.  
  1749.     if(nm->code == PSN_SETACTIVE)
  1750.     {
  1751.         lastpage = "ZC";
  1752.         SetDlgItemText(dlg, IDE_SD_ZC, c1.zc_sd_card_path);
  1753.         setcheck(IDC_ZC_ENABLED, c1.zc);
  1754.  
  1755.         ZcDlgEnableControls();
  1756.         return TRUE;
  1757.     }
  1758.  
  1759.     if(nm->code == PSN_APPLY) dlgok = 1;
  1760.     if(nm->code == PSN_RESET) dlgok = 0;
  1761.  
  1762.     return TRUE;
  1763. }
  1764.  
  1765.  
  1766. void setup_dlg()
  1767. {
  1768.    PROPSHEETPAGE psp[18] = { };
  1769.    PROPSHEETPAGE *ps = psp;
  1770.  
  1771.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_MEM);
  1772.    ps->pszTitle      = "MEMORY";
  1773.    ps->pfnDlgProc    = MemDlg;
  1774.    ps++;
  1775.  
  1776.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_VIDEO);
  1777.    ps->pszTitle      = "VIDEO";
  1778.    ps->pfnDlgProc    = VideoDlg;
  1779.    ps++;
  1780.  
  1781.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_ULA);
  1782.    ps->pszTitle      = "ULA";
  1783.    ps->pfnDlgProc    = UlaDlg;
  1784.    ps++;
  1785.  
  1786.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_HDD);
  1787.    ps->pszTitle      = "HDD";
  1788.    ps->pfnDlgProc    = HddDlg;
  1789.    ps++;
  1790.  
  1791.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_EFF7);
  1792.    ps->pszTitle      = "EFF7";
  1793.    ps->pfnDlgProc    = EFF7Dlg;
  1794.    ps++;
  1795.  
  1796.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_CHIP);
  1797.    ps->pszTitle      = "AY";
  1798.    ps->pfnDlgProc    = ChipDlg;
  1799.    ps++;
  1800.  
  1801.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_SOUND);
  1802.    ps->pszTitle      = "SOUND";
  1803.    ps->pfnDlgProc    = SoundDlg;
  1804.    ps++;
  1805.  
  1806.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_INPUT);
  1807.    ps->pszTitle      = "INPUT";
  1808.    ps->pfnDlgProc    = InputDlg;
  1809.    ps++;
  1810.  
  1811.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_TAPE);
  1812.    ps->pszTitle      = "TAPE";
  1813.    ps->pfnDlgProc    = TapeDlg;
  1814.    ps++;
  1815.  
  1816.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_BETA128);
  1817.    ps->pszTitle      = "Beta128";
  1818.    ps->pfnDlgProc    = BetaDlg;
  1819.    ps++;
  1820.  
  1821.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_LEDS);
  1822.    ps->pszTitle      = "LEDS";
  1823.    ps->pfnDlgProc    = LedsDlg;
  1824.    ps++;
  1825.  
  1826.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_SETTINGS_NGS);
  1827.    ps->pszTitle      = "NGS";
  1828.    ps->pfnDlgProc    = NgsDlg;
  1829.    ps++;
  1830.  
  1831.    ps->pszTemplate   = MAKEINTRESOURCE(IDD_SETTINGS_ZC);
  1832.    ps->pszTitle      = "ZC";
  1833.    ps->pfnDlgProc    = ZcDlg;
  1834.    ps++;
  1835.  
  1836.  
  1837.    PROPSHEETHEADER psh = { sizeof(PROPSHEETHEADER) };
  1838.    psh.dwFlags          = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | (lastpage ? PSH_USEPSTARTPAGE : 0);
  1839.    psh.hwndParent       = wnd;
  1840.    psh.hInstance        = hIn;
  1841.    psh.pszIcon          = MAKEINTRESOURCE(IDI_ICON2);
  1842.    psh.pszCaption       = "Emulation Settings";
  1843.    psh.ppsp             = (LPCPROPSHEETPAGE)&psp;
  1844.    psh.pStartPage       = lastpage;
  1845.    psh.nPages           = UINT(ps - psp);
  1846.  
  1847.    for (unsigned i = 0; i < psh.nPages; i++) {
  1848.       psp[i].dwSize = sizeof(PROPSHEETPAGE);
  1849.       psp[i].hInstance = hIn;
  1850.       psp[i].dwFlags = PSP_USETITLE;
  1851.    }
  1852.  
  1853.    OnEnterGui();
  1854.    // temp.rflags = RF_MONITOR; set_video();
  1855.  
  1856.    bool MemModelChanged = false;
  1857.    bool NgsSdImageChanged = false;
  1858.    bool ZcSdImageChanged = false;
  1859.    c1 = conf; PropertySheet(&psh);
  1860.    if (dlgok) {
  1861.            if(conf.render != c1.render)
  1862.                temp.scale = 1;
  1863.            if(conf.mem_model != c1.mem_model)
  1864.                MemModelChanged = true;
  1865.            if(strcmp(conf.ngs_sd_card_path, c1.ngs_sd_card_path) != 0)
  1866.                NgsSdImageChanged = true;
  1867.            if(strcmp(conf.zc_sd_card_path, c1.zc_sd_card_path) != 0)
  1868.                ZcSdImageChanged = true;
  1869.  
  1870. #ifdef MOD_GSZ80
  1871.            if(conf.gs_type == 1 && c1.gs_type != 1)
  1872.            {
  1873.                done_gs();
  1874.            }
  1875. #endif // MOD_GSZ80
  1876.  
  1877. #ifdef MOD_GSBASS
  1878.            if(conf.gs_type == 2 && c1.gs_type != 2)
  1879.            {
  1880.                reset_gs();
  1881.            }
  1882. #endif // MOD_GSBASS
  1883.  
  1884.            conf = c1;
  1885.            frametime = conf.frame; //Alone Coder 0.36.5
  1886.    };
  1887.  
  1888.    eat();
  1889.    SendMessage(wnd, WM_SETFOCUS, (WPARAM)wnd, 0); // show cursor for 'kempston on mouse'
  1890.  
  1891.    if(dlgok)
  1892.    {
  1893.        applyconfig(false);
  1894.    }
  1895.  
  1896.    OnExitGui();
  1897.  
  1898.    extern void main_reset();
  1899.    if(MemModelChanged)
  1900.    {
  1901.        main_reset();
  1902.    }
  1903.    else
  1904.    {
  1905.        if(NgsSdImageChanged)
  1906.        {
  1907.            SdCard.Reset();
  1908.        }
  1909.        if(ZcSdImageChanged)
  1910.        {
  1911.            Zc.Reset();
  1912.        }
  1913.    }
  1914. }
  1915.  
  1916. #endif
  1917.