Subversion Repositories pentevo

Rev

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

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