Subversion Repositories pentevo

Rev

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

  1. #include "std.h"
  2. #include <time.h>
  3.  
  4. #include "emul.h"
  5. #include "vars.h"
  6. #include "config.h"
  7. #include "dx.h"
  8. #include "draw.h"
  9. #include "iehelp.h"
  10. #include "gs.h"
  11. #include "leds.h"
  12. #include "tape.h"
  13. #include "emulkeys.h"
  14. #include "sshot_png.h"
  15. #include "init.h"
  16. #include "snapshot.h"
  17. #include "savesnd.h"
  18. #include "fdd.h"
  19. #include "z80/tables.h"
  20. #include "dbgbpx.h"
  21.  
  22. #include "util.h"
  23. #include "zxusbnet.h"
  24.  
  25. static void cpu_info()
  26. {
  27.    char idstr[64];
  28.    idstr[0] = 0;
  29.  
  30.    fillCpuString(idstr);
  31.  
  32.    trim(idstr);
  33.  
  34.    unsigned cpuver = cpuid(1,0);
  35.    unsigned features = cpuid(1,1);
  36.    temp.mmx = (features >> 23) & 1;
  37.    temp.sse = (features >> 25) & 1;
  38.    temp.sse2 = (features >> 26) & 1;
  39.  
  40.    unsigned features_apm = 0;
  41.    bool features_apm_supported = false;
  42.    unsigned max_ext_id = cpuid(0x80000000, 0);
  43.    if(max_ext_id >= 0x80000007)
  44.    {
  45.        features_apm_supported = true;
  46.        features_apm = cpuid(0x80000007,1);
  47.    }
  48.  
  49.    temp.cpufq = GetCPUFrequency();
  50.  
  51.    color(CONSCLR_HARDITEM); printf("cpu: ");
  52.  
  53.    color(CONSCLR_HARDINFO);
  54.    printf("%s ", idstr);
  55.  
  56.    color(CONSCLR_HARDITEM);
  57.    printf("%u.%u.%u [MMX:%s,SSE:%s,SSE2:%s,TSCINV:%s] ",
  58.       (cpuver>>8) & 0x0F, (cpuver>>4) & 0x0F, cpuver & 0x0F,
  59.       temp.mmx ? "YES" : "NO",
  60.       temp.sse ? "YES" : "NO",
  61.       temp.sse2 ? "YES" : "NO",
  62.       features_apm_supported ? ((features_apm & (1 << 8)) ? "YES" : "NO") : "UNK");
  63.  
  64.    color(CONSCLR_HARDINFO);
  65.    printf("TSC at %u MHz\n", unsigned(temp.cpufq/1000000U));
  66.  
  67. #ifdef MOD_SSE2
  68.    if (!temp.sse2) {
  69.       color(CONSCLR_WARNING);
  70.       printf("warning: this is an SSE2 build, recompile or download non-P4 version\n");
  71.    }
  72. #else //MOD_SSE2
  73.    if (temp.sse2) {
  74.       color(CONSCLR_WARNING);
  75.       printf("warning: SSE2 disabled in compile-time, recompile or download P4 version\n");
  76.    }
  77. #endif
  78. }
  79.  
  80. static void restrict_version(char legacy)
  81. {
  82.     (void)legacy;
  83. //   color(CONSCLR_WARNING);
  84. //   printf ("WARNING: Windows 95/98/Me is not fully supported.\n");
  85.    temp.win9x=1; //Dexus
  86.    color();
  87.  
  88. /*   static const char vererror[] = "unsupported OS version";
  89.  
  90.    if (!legacy) errexit(vererror);
  91.  
  92.    #ifdef MOD_9X
  93.    static const char verwarning[] =
  94.       "detected windows version is not supported\r\n"
  95.       "by current version of UnrealSpeccy and untested.\r\n\r\n"
  96.       "you may click 'YES' to continue on your own risk.\r\n"
  97.       "in this case you will experience crashes under\r\n"
  98.       "some conditions. it's an OS-specific problem, please\r\n"
  99.       "don't report it and consider using NT-based system";
  100.    if (MessageBox(0, verwarning, vererror, MB_ICONERROR | MB_YESNO | MB_DEFBUTTON2) == IDNO) errexit(vererror);
  101.    #endif
  102. */
  103. }
  104.  
  105. void init_all(int argc, char **argv)
  106. {
  107. //   printf("%s\n", __FUNCTION__);
  108.    cpu_info();
  109.  
  110.    char *config = nullptr, legacy = 0;
  111.    for (int i = 0; i < argc; i++) {
  112.       if (argv[i][0] != '/' && argv[i][0] != '-') continue;
  113.       if(!stricmp(argv[i] + 1, "i") && i + 1 < argc)
  114.       {
  115.           config = argv[i + 1];
  116.           i++;
  117.       }
  118.       #ifdef MOD_9X
  119.       if (argv[i][1] == '9') legacy = 1;
  120.       #endif
  121.    }
  122.  
  123.    temp.Minimized = false;
  124.    temp.win9x=0; //Dexus
  125.    if (GetVersion() >> 31) restrict_version(legacy);
  126.  
  127.    init_z80tables();
  128.    video_permanent_tables();
  129.    init_ie_help();
  130.    load_config(config);
  131.    {//clear memory
  132.            unsigned char *tptr=RAM_BASE_M;
  133.            char * a;
  134.            union{
  135.                         unsigned long long int l;
  136.                         unsigned char b[8];
  137.            }pattern;
  138.            int i=0;
  139.            pattern.l=strtoul(conf.cold_ram_pat,&a,16);
  140.            int j=(a-conf.cold_ram_pat)>>sizeof(conf.cold_ram_pat[0]);
  141.            srand((unsigned int)time(NULL));
  142.            while(tptr!=(RAM_BASE_M + MAX_RAM_PAGES*PAGE)){
  143.                    if((rand()&0xff03)==0) *tptr=(unsigned char)(rand()&0xff);
  144.                    else *tptr=pattern.b[i];
  145.                    tptr++;
  146.                    if((++i)==j)i=0;
  147.            }
  148.    }
  149.    //make_samples();
  150.    init_leds();
  151.    init_tape();
  152.    init_hdd_cd();
  153.    start_dx();
  154.    set_priority();
  155.    applyconfig();
  156.    main_reset();
  157.    autoload();
  158.    init_bpx();
  159.    temp.PngSupport = PngInit();
  160.    //if(conf.wiznet){
  161.    //     Wiz5300_Init();
  162.    //}
  163.  
  164.    if(!temp.PngSupport)
  165.    {
  166.        color(CONSCLR_WARNING);
  167.        printf("warning: libpng12.dll not found or wrong version -> png support disabled\n");
  168.        if(conf.scrshot == 2) // ┴√ы т√сЁрэ Єшя ёъЁшэ°юЄют .png
  169.        {
  170.            conf.scrshot = 1; // ╟рьхэр эр .bmp (Є.ъ. юЄёєЄёЄтєхЄ libpng)
  171.        }
  172.    }
  173.    temp.ZlibSupport = ZlibInit();
  174.    if(!temp.ZlibSupport)
  175.    {
  176.        color(CONSCLR_WARNING);
  177.        printf("warning: zlib1.dll not found or wrong version -> csw 2.0 support disabled\n");
  178.    }
  179.    temp.LastSnapName[0] = 0;
  180.    load_errors = 0;
  181.    trd_toload = 0;
  182.    *(DWORD*)trd_loaded = 0; // clear loaded flags, don't see autoload'ed images
  183.  
  184.    for (; argc; argc--, argv++)
  185.    {
  186.       if (**argv == '-' || **argv == '/')
  187.       {
  188.           if(argc > 1 && !stricmp(argv[0] + 1, "i"))
  189.           {
  190.               argc--;
  191.               argv++;
  192.           }
  193.          continue;
  194.       }
  195.  
  196.       char fname[0x200], *temp;
  197.       GetFullPathName(*argv, sizeof fname, fname, &temp);
  198.  
  199.       trd_toload = DefaultDrive; // auto-select
  200.       if(!loadsnap(fname))
  201.       {
  202.           errmsg("error loading <%s>", *argv);
  203.           load_errors = 1;
  204.       }
  205.    }
  206.  
  207.    if (load_errors) {
  208.       int code = MessageBox(wnd, "Some files, specified in\r\ncommand line, failed to load\r\n\r\nContinue emulation?", "File loading error", MB_YESNO | MB_ICONWARNING);
  209.       if (code != IDYES) exit();
  210.    }
  211.  
  212.    SetCurrentDirectory(conf.workdir);
  213.    if(conf.HighResolutionTimer)
  214.        timeBeginPeriod(1);
  215. }
  216.  
  217. void __declspec(noreturn) exit()
  218. {
  219. //   EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_ENABLED);
  220. #ifdef _DEBUG
  221.    if(!normal_exit)
  222.    {
  223.        __debugbreak();
  224.    }
  225. #endif
  226.    exitflag = 1;
  227.    if (savesndtype)
  228.        savesnddialog();  //stop saving sound
  229.    if(videosaver_state)
  230.        main_savevideo(); //stop saving video
  231.  
  232.    if(!normal_exit)
  233.        done_fdd(false);
  234.    done_tape();
  235.    done_dx();
  236.    done_gs();
  237.    done_leds();
  238.    save_nv();
  239.    modem.close();
  240.    done_ie_help();
  241.    done_bpx();
  242.    PngDone();
  243.    ZlibDone();
  244.  
  245.    if(conf.HighResolutionTimer)
  246.        timeEndPeriod(1);
  247.    if (ay[1].Chip2203) YM2203Shutdown(ay[1].Chip2203); //Dexus
  248.    if (ay[0].Chip2203) YM2203Shutdown(ay[0].Chip2203); //Dexus
  249.    color();
  250.    printf("\nsee you later!\n");
  251.    if (!nowait)
  252.    {
  253.        SetConsoleTitle("press a key...");
  254.        FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
  255.        getch();
  256.    }
  257.    fflush(stdout);
  258.    SetConsoleCtrlHandler(ConsoleHandler, FALSE);
  259.    exit(0);
  260. }
  261.