Subversion Repositories pentevo

Rev

Rev 921 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "std.h"
  2.  
  3. #include "resource.h"
  4. #include "emul.h"
  5. #include "vars.h"
  6. #include "config.h"
  7. #include "draw.h"
  8. #include "dx.h"
  9. #include "debug.h"
  10. #include "memory.h"
  11. #include "sndrender/sndcounter.h"
  12. #include "sound.h"
  13. #include "savesnd.h"
  14. #include "tape.h"
  15. #include "gui.h"
  16. #include "leds.h"
  17. #include "snapshot.h"
  18. #include "fdd.h"
  19. #include "init.h"
  20. #include "z80.h"
  21. #include "emulkeys.h"
  22. #include "funcs.h"
  23. #include "util.h"
  24. #include "input.h"
  25. #include "zxusbnet.h"
  26.  
  27. void main_pause()
  28. {
  29.    text_i(rbuf+temp.scx/2-8,"pause",0x0F); flip();
  30.  
  31.    pause = 1;
  32.    sound_stop();
  33.    updatebitmap();
  34.    active = 0;
  35.    adjust_mouse_cursor();
  36.  
  37.    while (!process_msgs()) Sleep(10);
  38.    eat();
  39.  
  40.    active = 1; adjust_mouse_cursor();
  41.    sound_play();
  42.    pause = 0;
  43. }
  44.  
  45. void main_debug()
  46. {
  47.    Z80 &cpu = CpuMgr.Cpu();
  48.  
  49.    cpu.dbgchk = 1;
  50.    cpu.dbgbreak = 1;
  51.    dbgbreak = 1;
  52. }
  53.  
  54. enum { FIX_FRAME = 0, FIX_LINE, FIX_PAPER, FIX_NOPAPER, FIX_HWNC, FIX_LAST };
  55. static const char *fix_titles[FIX_LAST] = {
  56.    "%d t-states / int",
  57.    "%d t-states / line",
  58.    "paper starts at %d",
  59.    "border only: %d",
  60.    "hardware mc: %d"
  61. };
  62.  
  63.  
  64. static unsigned char whatfix = 0, whatsnd = 0;
  65. static unsigned char fixmode = u8(-1U);
  66. static int mul0 = 100, mul1 = 1000;
  67.  
  68. static void chfix(int dx)
  69. {
  70.    if (!fixmode) {
  71.       unsigned value;
  72.       switch (whatfix) {
  73.          case FIX_FRAME: value = (conf.frame = unsigned(int(conf.frame) + dx)); break;
  74.          case FIX_LINE: value = (conf.t_line = unsigned(int(conf.t_line) + dx)); break;
  75.          case FIX_PAPER: value = (conf.paper = unsigned(int(conf.paper) + dx)); break;
  76.          case FIX_NOPAPER: value = (conf.nopaper ^= dx?1:0); break;
  77.          case FIX_HWNC: value = (comp.pEFF7 ^= dx?EFF7_HWMC:0)? 1 : 0; break;
  78.          default: return;
  79.       }
  80.       video_timing_tables();
  81.       apply_sound(); // t/frame affects AY engine!
  82.       sprintf(statusline, fix_titles[whatfix], value); statcnt=50;
  83.       if (dx) conf.ula_preset = u8(-1U);
  84.       return;
  85.    }
  86.    if (fixmode != 1) return;
  87.  
  88.    dx = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
  89.  
  90.    *statusline = 0; statcnt = 50;
  91.    switch (whatsnd) {
  92.       case 0:
  93.          conf.sound.ay_stereo = u8(int(conf.sound.ay_stereo)+dx+int(num_aystereo)) % num_aystereo;
  94.          sprintf(statusline, "Stereo preset: %s", aystereo[conf.sound.ay_stereo]);
  95.          break;
  96.       case 1:
  97.          if (dx) conf.sound.ay_samples ^= 1;
  98.          sprintf(statusline, "Digital Soundchip: %s", conf.sound.ay_samples? "yes" : "no");
  99.          break;
  100.       case 2:
  101.          conf.sound.ay_vols = u8(int(conf.sound.ay_vols)+int(num_ayvols)+dx) % num_ayvols;
  102.          sprintf(statusline, "Chip Table: %s", ayvols[conf.sound.ay_vols]);
  103.          break;
  104.       case 3:
  105.          conf.pal = unsigned(int(conf.pal)+dx);
  106.          if (conf.pal == conf.num_pals) conf.pal = 0;
  107.          if (conf.pal == -1U) conf.pal = conf.num_pals-1;
  108.          sprintf(statusline, "Palette: %s", pals[conf.pal].name);
  109.          video_color_tables();
  110.          return;
  111.    }
  112.    apply_sound();
  113. }
  114.  
  115. void main_selectfix()
  116. {
  117.    if (!fixmode) whatfix = (whatfix+1) % FIX_LAST;
  118.    fixmode = 0; mul0 = 1; mul1 = 10;
  119.    if(whatfix == FIX_FRAME)
  120.    {
  121.        mul0 = 100;
  122.        mul1 = 1000;
  123.    }
  124.    chfix(0);
  125. }
  126.  
  127. void main_selectsnd()
  128. {
  129.    if (fixmode==1) whatsnd = (whatsnd+1) & 3;
  130.    fixmode = 1;
  131.    chfix(0);
  132. }
  133.  
  134. void main_incfix() { chfix(mul0); }
  135. void main_decfix() { chfix(-mul0); }
  136. void main_incfix10() { chfix(mul1); }
  137. void main_decfix10() { chfix(-mul1); }
  138.  
  139. void main_leds()
  140. {
  141.    conf.led.enabled ^= 1;
  142.    sprintf(statusline, "leds %s", conf.led.enabled ? "on" : "off"); statcnt = 50;
  143. }
  144.  
  145. void main_maxspeed()
  146. {
  147.    conf.sound.enabled ^= 1;
  148.    temp.frameskip = conf.sound.enabled? conf.frameskip : conf.frameskipmax;
  149.    if (conf.sound.enabled) sound_play(); else sound_stop();
  150.    sprintf(statusline, "Max speed: %s", conf.sound.enabled ? "NO" : "YES"); statcnt = 50;
  151. }
  152.  
  153. // select filter / driver through gui dialog ----------------------------
  154.  
  155. static INT_PTR CALLBACK filterdlg(HWND dlg, UINT msg, WPARAM wp, LPARAM lp)
  156. {
  157.    if (msg == WM_INITDIALOG)
  158.    {
  159.       HWND box = GetDlgItem(dlg, IDC_LISTBOX); int i;
  160.  
  161.       if (lp) {
  162.          for (i = 0; drivers[i].name; i++)
  163.             SendMessage(box, LB_ADDSTRING, 0, (LPARAM)drivers[i].name);
  164.          SendMessage(box, LB_SETCURSEL, conf.driver, 0);
  165.          SetWindowText(dlg, "Select driver for rendering");
  166.       } else {
  167.          for (i = 0; renders[i].name; i++)
  168.             SendMessage(box, LB_ADDSTRING, 0, (LPARAM)renders[i].name);
  169.          SendMessage(box, LB_SETCURSEL, conf.render, 0);
  170.       }
  171.  
  172.       RECT rcw, cli; GetWindowRect(box, &rcw); GetClientRect(box, &cli);
  173.       RECT rcd; GetWindowRect(dlg, &rcd);
  174.  
  175.       int nc_width = (rcw.right - rcw.left) - (cli.right - cli.left);
  176.       int nc_height = (rcw.bottom - rcw.top) - (cli.bottom - cli.top);
  177.       int dlg_w = (rcd.right - rcd.left) - (rcw.right - rcw.left);
  178.       int dlg_h = (rcd.bottom - rcd.top) - (rcw.bottom - rcw.top);
  179.       nc_width += 300;
  180.       nc_height += i*SendMessage(box, LB_GETITEMHEIGHT, 0, 0);
  181.       dlg_w += nc_width; dlg_h += nc_height;
  182.       SetWindowPos(box, nullptr, 0, 0, nc_width, nc_height, SWP_NOZORDER | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_SHOWWINDOW);
  183.  
  184.       GetWindowRect(wnd, &rcw);
  185.       SetWindowPos(dlg, nullptr,
  186.          rcw.left + ((rcw.right-rcw.left)-dlg_w)/2,
  187.          rcw.top + ((rcw.bottom-rcw.top)-dlg_h)/2,
  188.          dlg_w, dlg_h, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_SHOWWINDOW);
  189.  
  190.       SetFocus(box);
  191.       return FALSE;
  192.    }
  193.  
  194.    if ((msg == WM_COMMAND && wp == IDCANCEL) ||
  195.        (msg == WM_SYSCOMMAND && (wp & 0xFFF0) == SC_CLOSE))
  196.    {
  197.        EndDialog(dlg, -1);
  198.        return TRUE;
  199.    }
  200.  
  201.    if (msg == WM_COMMAND)
  202.    {
  203.       int control = LOWORD(wp);
  204.       if (control == IDOK || (control == IDC_LISTBOX && HIWORD(wp) == LBN_DBLCLK))
  205.       {
  206.          EndDialog(dlg, SendDlgItemMessage(dlg, IDC_LISTBOX, LB_GETCURSEL, 0, 0));
  207.          return TRUE;
  208.       }
  209.    }
  210.    return FALSE;
  211. }
  212.  
  213. void main_selectfilter()
  214. {
  215.    OnEnterGui();
  216.    INT_PTR index = DialogBoxParam(hIn, MAKEINTRESOURCE(IDD_FILTER_DIALOG), wnd, filterdlg, 0);
  217.    eat();
  218.    if (index < 0)
  219.    {
  220.        OnExitGui();
  221.        return;
  222.    }
  223.    OnExitGui(false);
  224.    conf.render = unsigned(index);
  225.    sprintf(statusline, "Video: %s", renders[index].name); statcnt = 50;
  226.    apply_video(); eat();
  227. }
  228.  
  229. void main_selectdriver()
  230. {
  231.    if (!(temp.rflags & RF_DRIVER)) {
  232.      strcpy(statusline, "Not available for this filter"); statcnt = 50;
  233.      return;
  234.    }
  235.  
  236.    OnEnterGui();
  237.    INT_PTR index = DialogBoxParam(hIn, MAKEINTRESOURCE(IDD_FILTER_DIALOG), wnd, filterdlg, 1);
  238.    eat();
  239.  
  240.    if (index < 0)
  241.    {
  242.        OnExitGui();
  243.        return;
  244.    }
  245.    OnExitGui(false);
  246.    conf.driver = unsigned(index);
  247.    sprintf(statusline, "Render to: %s", drivers[index].name); statcnt = 50;
  248.    apply_video();
  249.    eat();
  250. }
  251.  
  252. // ----------------------------------------------------------------------
  253.  
  254. void main_poke()
  255. {
  256.    OnEnterGui();
  257.    DialogBox(hIn, MAKEINTRESOURCE(IDD_POKE), wnd, pokedlg);
  258.    eat();
  259.    OnExitGui();
  260. }
  261.  
  262. void main_starttape()
  263. {
  264.    //if (comp.tape.play_pointer) stop_tape(); else start_tape();
  265.    (!comp.tape.stopped) ? stop_tape() : start_tape();
  266. }
  267.  
  268. void main_tapebrowser()
  269. {
  270. #ifdef MOD_SETTINGS
  271.     lastpage = "TAPE";
  272.     setup_dlg();
  273. #endif
  274. }
  275.  
  276. #ifndef MOD_SETTINGS
  277. void setup_dlg() {}
  278. #endif
  279.  
  280. static const char *getrom(ROM_MODE page)
  281. {
  282.    switch (page) {
  283.       case RM_128: return "Basic 128";
  284.       case RM_SYS: return "Service ROM";
  285.       case RM_DOS: return "TR-DOS";
  286.       case RM_SOS: return "Basic 48";
  287.       case RM_CACHE: return "Cache";
  288.    }
  289.    return "???";
  290. }
  291.  
  292. static void m_reset(ROM_MODE page)
  293. {
  294.    load_atm_font();
  295.  
  296.    sprintf(statusline, "Reset to %s", getrom(page)); statcnt = 50;
  297.    input.buffer_enabled = false;    //DimkaM disable ps/2 access
  298.    input.buffer.Empty();
  299.    nmi_pending = 0;
  300.    cpu.nmi_in_progress = false;
  301.    reset(page);
  302. }
  303. void main_reset128() { m_reset(RM_128); }
  304. void main_resetsys() { m_reset(RM_SYS); }
  305. void main_reset48() { m_reset(RM_SOS); comp.p7FFD = 0x30; comp.pEFF7 |= EFF7_LOCKMEM; /*Alone Coder*/}
  306. void main_resetbas() { m_reset(RM_SOS); }
  307. void main_resetdos() { if (conf.trdos_present) m_reset(RM_DOS); }
  308. void main_resetcache() { if (conf.cache) m_reset(RM_CACHE); }
  309. void main_reset() { m_reset((ROM_MODE)conf.reset_rom); }
  310.  
  311. void m_nmi(ROM_MODE page)
  312. {
  313.         if(conf.mem_model == MM_ATM710 && bankr[(cpu.pc >> 14) & 3] >= RAM_BASE_M+PAGE*MAX_RAM_PAGES){
  314.                 return;
  315.         }
  316.    set_mode(page);
  317.    sprintf(statusline, "NMI to %s", getrom(page)); statcnt = 50;
  318.    comp.p00 = 0; // quorum
  319.    cpu.sp -= 2;
  320.    if(cpu.DbgMemIf->rm(cpu.pc) == 0x76) // nmi on halt command
  321.        cpu.pc++;
  322.    cpu.DbgMemIf->wm(cpu.sp, cpu.pcl);
  323.    cpu.DbgMemIf->wm(cpu.sp+1, cpu.pch);
  324.    cpu.pc = 0x66; cpu.iff1 = cpu.halted = 0;
  325. }
  326.  
  327. void main_nmi()
  328. {
  329.     nmi_pending  = 1;
  330.         trdos_in_nmi = comp.flags&CF_TRDOS;
  331.     if(conf.mem_model != MM_ATM3)
  332.         m_nmi(RM_NOCHANGE);
  333. }
  334.  
  335. void main_nmidos()
  336. {
  337.  if((conf.mem_model == MM_PROFSCORP || conf.mem_model == MM_SCORP) &&
  338.    !(comp.flags & CF_TRDOS) && cpu.pc < 0x4000)
  339.  {
  340.      nmi_pending = conf.frame * 50; // 50 * 20ms
  341.      return;
  342.  }
  343.  m_nmi(RM_DOS);
  344. }
  345.  
  346. void main_nmicache() { m_nmi(RM_CACHE); }
  347.  
  348. static void qsave(const char *fname) {
  349.    char xx[0x200]; addpath(xx, fname);
  350.    FILE *ff = fopen(xx, "wb");
  351.    if (ff) {
  352.        if(writeSNA(ff))
  353.        {
  354.            sprintf(statusline, "Quick save to %s", fname);
  355.            statcnt = 30;
  356.        }
  357.       fclose(ff);
  358.    }
  359. }
  360. void qsave1() { qsave("qsave1.sna"); }
  361. void qsave2() { qsave("qsave2.sna"); }
  362. void qsave3() { qsave("qsave3.sna"); }
  363.  
  364. static void qload(const char *fname) {
  365.    char xx[0x200]; addpath(xx, fname);
  366.    if(loadsnap(xx))
  367.    {
  368.        sprintf(statusline, "Quick load from %s", fname);
  369.        statcnt = 30;
  370.    }
  371. }
  372. void qload1() { qload("qsave1.sna"); }
  373. void qload2() { qload("qsave2.sna"); }
  374. void qload3() { qload("qsave3.sna"); }
  375.  
  376. void main_keystick()
  377. {
  378.    input.keymode = (input.keymode == K_INPUT::KM_KEYSTICK)? K_INPUT::KM_DEFAULT : K_INPUT::KM_KEYSTICK;
  379. }
  380.  
  381. void main_autofire()
  382. {
  383.    conf.input.fire ^= 1;
  384.    input.firedelay = 1;
  385.    sprintf(statusline, "autofire %s", conf.input.fire ? "on" : "off");
  386.    statcnt = 30;
  387. }
  388.  
  389. void main_save()
  390. {
  391.    sound_stop();
  392.    if (conf.cmos)
  393.        save_nv();
  394.    unsigned char optype = 0;
  395.    for (int i = 0; i < 4; i++)
  396.    {
  397.       if (!comp.fdd[i].test())
  398.           return;
  399.       optype |= comp.fdd[i].optype;
  400.    }
  401.  
  402.    if(!optype)
  403.    {
  404.        sprintf(statusline, "all saved");
  405.        statcnt = 30;
  406.    }
  407. }
  408.  
  409. void main_fullscr()
  410. {
  411.     if(!(temp.rflags & (RF_GDI | RF_OVR | RF_CLIP | RF_D3D)))
  412.     {
  413.         sprintf(statusline, "only for overlay/gdi/nonexclusive modes");
  414.         statcnt = 30;
  415.     }
  416.    else
  417.    {
  418.        conf.fullscr ^= 1;
  419.        apply_video();
  420.    }
  421. }
  422.  
  423. void main_mouse()
  424. {
  425.    conf.lockmouse ^= 1;
  426.    adjust_mouse_cursor();
  427.    sprintf(statusline, "mouse %slocked", conf.lockmouse ? nil : "un");
  428.    statcnt = 30;
  429. }
  430.  
  431. void main_help() { showhelp(); }
  432. void mon_help() { showhelp("monitor_keys"); }
  433.  
  434. void main_atmkbd()
  435. {
  436.    conf.atm.xt_kbd ^= 1;
  437.    if (conf.atm.xt_kbd) sprintf(statusline, "ATM mode on. emulator hotkeys disabled");
  438.    else sprintf(statusline, "ATM mode off");
  439.    statcnt = 50;
  440. }
  441.  
  442. void main_pastetext() { input.paste(); }
  443.  
  444. void wnd_resize(int scale)
  445. {
  446.    if (conf.fullscr)
  447.    {
  448.        sprintf(statusline, "impossible in fullscreen mode");
  449.        statcnt = 50;
  450.        return;
  451.    }
  452.  
  453.    if (!scale)
  454.    {
  455.        ShowWindow(wnd, SW_MAXIMIZE);
  456.        return;
  457.    }
  458.  
  459.    ShowWindow(wnd, SW_RESTORE);
  460.    LONG style = GetWindowLong(wnd, GWL_STYLE);
  461.    RECT rc = { 0, 0, LONG(temp.ox) * scale, LONG(temp.oy) * scale };
  462.    AdjustWindowRect(&rc, DWORD(style), 0);
  463.    SetWindowPos(wnd, nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  464.    if(temp.rflags & RF_2X)
  465.        scale *= 2;
  466.    else if(temp.rflags & RF_3X)
  467.        scale *= 3;
  468.    else if(temp.rflags & RF_4X)
  469.        scale *= 4;
  470.    sprintf(statusline, "scale: %dx", scale);
  471.    statcnt = 50;
  472. }
  473.  
  474. void main_size1() { wnd_resize(1); }
  475. void main_size2() { wnd_resize(2); }
  476. void main_sizem() { wnd_resize(0); }
  477.  
  478. static void SetBorderSize(unsigned BorderSize)
  479. {
  480. // 0 - none
  481. // 1 - small
  482. // 2 - full
  483.    if(BorderSize > 2)
  484.    {
  485.        return;
  486.    }
  487.    conf.bordersize = u8(BorderSize);
  488.    apply_video();
  489. }
  490.  
  491. void main_border_none() { SetBorderSize(0); }
  492. void main_border_small() { SetBorderSize(1); }
  493. void main_border_full() { SetBorderSize(2); }
  494.  
  495.  
  496. void correct_exit()
  497. {
  498.    sound_stop();
  499.    if(conf.wiznet) Wiz5300_Close();
  500.  
  501.    if(!done_fdd(true))
  502.        return;
  503.  
  504.    nowait = 1;
  505.    normal_exit = true;
  506.    exit();
  507. }
  508.  
  509. void opensnap()
  510. {
  511.    OnEnterGui();
  512.    opensnap(0);
  513.    eat();
  514.    OnExitGui();
  515. }
  516.  
  517. void savesnap()
  518. {
  519.    OnEnterGui();
  520.    savesnap(-1);
  521.    eat();
  522.    OnExitGui();
  523. }
  524.