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