Subversion Repositories pentevo

Rev

Rev 716 | Blame | Last modification | View Log | Download | RSS feed

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "sound.h"
  6. #include "draw.h"
  7. #include "dx.h"
  8. #include "dxr_rsm.h"
  9. #include "leds.h"
  10. #include "memory.h"
  11. #include "snapshot.h"
  12. #include "emulkeys.h"
  13. #include "vs1001.h"
  14. #include "z80.h"
  15.  
  16. #include "util.h"
  17.  
  18. void spectrum_frame()
  19. {
  20.    if (!temp.inputblock || input.keymode != K_INPUT::KM_DEFAULT)
  21.       input.make_matrix();
  22.  
  23.    init_snd_frame();
  24.    init_frame();
  25.  
  26.    if(cpu.dbgchk)
  27.    {
  28.        cpu.SetDbgMemIf();
  29.        z80dbg::z80loop();
  30.    }
  31.    else
  32.    {
  33.        cpu.SetFastMemIf();
  34.        z80fast::z80loop();
  35.    }
  36.    if (modem.open_port)
  37.        modem.io();
  38.  
  39.    flush_snd_frame();
  40.    flush_frame();
  41.    showleds();
  42.  
  43.    if (!cpu.iff1 || // int disabled in CPU
  44.         ((conf.mem_model == MM_ATM710 || conf.mem_model == MM_ATM3) && !(comp.pFF77 & 0x20))) // int disabled by ATM hardware
  45.    {
  46.       unsigned char *mp = am_r(cpu.pc);
  47.       if (cpu.halted)
  48.       {
  49.           strcpy(statusline, "CPU HALTED");
  50.           statcnt = 10;
  51.       }
  52.       if (*(unsigned short*)mp == WORD2(0x18,0xFE) ||
  53.           ((*mp == 0xC3) && *(unsigned short*)(mp+1) == (unsigned short)cpu.pc))
  54.       {
  55.          strcpy(statusline, "CPU STOPPED");
  56.          statcnt = 10;
  57.       }
  58.    }
  59.  
  60.    comp.t_states += conf.frame;
  61.    cpu.t -= conf.frame;
  62.    cpu.eipos -= conf.frame;
  63.    comp.frame_counter++;
  64. }
  65.  
  66. static void do_idle()
  67. {
  68.    if(conf.SyncMode != SM_TSC)
  69.        return;
  70.  
  71.    static unsigned long long last_cpu = rdtsc();
  72.  
  73.    unsigned long long cpu = rdtsc();
  74.    if(conf.sleepidle && ((cpu-last_cpu) < temp.ticks_frame))
  75.    {
  76.        ULONG Delay = ULONG(((temp.ticks_frame - (cpu-last_cpu)) * 1000ULL) / temp.cpufq);
  77.  
  78.        if(Delay > 5)
  79.        {
  80.            Sleep(Delay-1);
  81.        }
  82.    }
  83.  
  84.    for (cpu = rdtsc(); (cpu-last_cpu) < temp.ticks_frame; cpu = rdtsc())
  85.    {
  86.       asm_pause();
  87.    }
  88.    last_cpu = rdtsc();
  89. }
  90.  
  91. // version before frame resampler
  92. //uncommented by Alone Coder
  93. /*
  94. void mainloop()
  95. {
  96.    unsigned char skipped = 0;
  97.    for (;;)
  98.    {
  99.       if (skipped < temp.frameskip)
  100.       {
  101.           skipped++;
  102.           temp.vidblock = 1;
  103.       }
  104.       else
  105.           skipped = temp.vidblock = 0;
  106.  
  107.       temp.sndblock = !conf.sound.enabled;
  108.       temp.inputblock = 0; //temp.vidblock; //Alone Coder
  109.       spectrum_frame();
  110.  
  111.       // message handling before flip (they paint to rbuf)
  112.       if (!temp.inputblock)
  113.           dispatch(conf.atm.xt_kbd ? ac_main_xt : ac_main);
  114.       if (!temp.vidblock)
  115.           flip();
  116.       if (!temp.sndblock)
  117.       {
  118.           do_sound();
  119.           Vs1001.Play();
  120.  
  121. //          if(conf.sound.do_sound != do_sound_ds)
  122.           do_idle();
  123.       }
  124.    }
  125. }
  126. */
  127.  
  128. void mainloop(const bool &Exit)
  129. {
  130. //   printf("%s\n", __FUNCTION__);
  131.    unsigned char skipped = 0;
  132.    for (;!Exit;)
  133.    {
  134.       if (skipped < temp.frameskip)
  135.       {
  136.           skipped++;
  137.           temp.vidblock = 1;
  138.       }
  139.       else
  140.           skipped = temp.vidblock = 0;
  141.  
  142.       if (!temp.vidblock)
  143.           flip();
  144.  
  145.       for (unsigned f = rsm.needframes[rsm.frame]; f; f--)
  146.       {
  147.          temp.sndblock = !conf.sound.enabled;
  148.          temp.inputblock = temp.vidblock && conf.sound.enabled;
  149.          spectrum_frame();
  150.          //VideoSaver();
  151.          if(videosaver_state)
  152.             savevideo_gfx();
  153.  
  154.          // message handling before flip (they paint to rbuf)
  155.          if (!temp.inputblock)
  156.          {
  157.              dispatch(conf.atm.xt_kbd ? ac_main_xt : ac_main);
  158.          }
  159.          if (!temp.sndblock)
  160.          {
  161.              if(videosaver_state)
  162.                 savevideo_snd();
  163.              do_sound();
  164.              Vs1001.Play();
  165.          }
  166.          if (rsm.mix_frames > 1)
  167.          {
  168.             memcpy(rbuf_s + rsm.rbuf_dst * rb2_offs, rbuf, temp.scx * temp.scy / 4);
  169.             if (++rsm.rbuf_dst == rsm.mix_frames)
  170.                 rsm.rbuf_dst = 0;
  171.          }
  172.          if (!temp.sndblock)
  173.          {
  174.               do_idle();
  175.          }
  176.       }
  177.  
  178.       if (++rsm.frame == rsm.period)
  179.           rsm.frame = 0;
  180.  
  181.    }
  182.    correct_exit();
  183. }
  184.