void SuperFX::reset() { create(SuperFX::Enter, system.cpu_frequency); instruction_counter = 0; for(unsigned n = 0; n < 16; n++) regs.r[n] = 0x0000; regs.sfr = 0x0000; regs.pbr = 0x00; regs.rombr = 0x00; regs.rambr = 0; regs.cbr = 0x0000; regs.scbr = 0x00; regs.scmr = 0x00; regs.colr = 0x00; regs.por = 0x00; regs.bramr = 0; regs.vcr = 0x04; regs.cfgr = 0x00; regs.clsr = 0; regs.pipeline = 0x01; //nop regs.ramaddr = 0x0000; regs.reset(); memory_reset(); timing_reset(); }
void SuperFX::reset() { GSU::reset(); create(SuperFX::Enter, system.cpu_frequency()); instruction_counter = 0; memory_reset(); timing_reset(); }
void sCPU::reset() { CPU::reset(); //note: some registers are not fully reset by SNES regs.pc = 0x000000; regs.x.h = 0x00; regs.y.h = 0x00; regs.s.h = 0x01; regs.d = 0x0000; regs.db = 0x00; regs.p = 0x34; regs.e = 1; regs.mdr = 0x00; regs.wai = false; update_table(); mmio_reset(); dma_reset(); timing_reset(); apu_port[0] = 0x00; apu_port[1] = 0x00; apu_port[2] = 0x00; apu_port[3] = 0x00; }
void main_loop(){ if(!taskmng_isavail()) return; taskmng_rol(); if (np2oscfg.NOWAIT) { pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; if (framecnt >= np2oscfg.DRAW_SKIP) { processwait(0); } } else { // nowait auto skip framecnt = 1; if (timing_getcount()) { processwait(0); } } } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { pccore_exec(framecnt == 0); framecnt++; } else { processwait(np2oscfg.DRAW_SKIP); } } else { // auto skip if (!waitcnt) { UINT cnt; pccore_exec(framecnt == 0); framecnt++; cnt = timing_getcount(); if (framecnt > cnt) { waitcnt = framecnt; if (framemax > 1) { framemax--; } } else if (framecnt >= framemax) { if (framemax < 12) { framemax++; } if (cnt >= 12) { timing_reset(); } else { timing_setcount(cnt - framecnt); } framereset(0); } } else { processwait(waitcnt); waitcnt = framecnt; } } }
static void add_timing_string(string_t *str, struct timing *timing, const char *name) { str_printfa(str, ", %u %s:%llu/%llu/%llu/%llu", timing_get_count(timing), name, (unsigned long long)timing_get_min(timing)/1000, (unsigned long long)timing_get_avg(timing)/1000, (unsigned long long)timing_get_95th(timing)/1000, (unsigned long long)timing_get_max(timing)/1000); timing_reset(timing); }
void CPU::reset() { create(Enter, system.cpu_frequency()); coprocessors.reset(); PPUcounter::reset(); //note: some registers are not fully reset by SNES regs.pc = 0x000000; regs.x.h = 0x00; regs.y.h = 0x00; regs.s.h = 0x01; regs.d = 0x0000; regs.db = 0x00; regs.p = 0x34; regs.e = 1; regs.mdr = 0x00; regs.wai = false; update_table(); mmio_reset(); dma_reset(); timing_reset(); }
static void process_reffile (char *reffile) { FILE *rfp, *hfp; char line[16384], uttid[4096], file[4096], lc_uttid[4096]; int32 i, k; dagnode_t ref[MAX_UTT_LEN]; int32 nref, noov, nhyp; int32 tot_err, tot_ref, tot_corr, tot_oov, tot_hyp; dag_t *dag; dpnode_t retval; timing_t *tm; char *latdir, *hypfile; if ((rfp = fopen(reffile, "r")) == NULL) E_FATAL("fopen(%s,r) failed\n", reffile); latdir = (char *) cmd_ln_access ("-latdir"); hypfile = (char *) cmd_ln_access ("-hyp"); if ((! latdir) && (! hypfile)) E_FATAL("Both -latdir and -hyp arguments missing\n"); if (latdir && hypfile) E_FATAL("-latdir and -hyp arguments are mutually exclusive\n"); hfp = NULL; if (hypfile) { if ((hfp = fopen(hypfile, "r")) == NULL) E_FATAL("fopen(%s,r) failed\n", hypfile); } tot_err = 0; tot_ref = 0; tot_hyp = 0; tot_corr = 0; tot_oov = 0; tm = timing_new ("Utt"); while (fgets(line, sizeof(line), rfp) != NULL) { timing_reset (tm); timing_start (tm); if ((nref = refline2wds (line, ref, &noov, uttid)) < 0) E_FATAL("Bad line in file %s: %s\n", reffile, line); /* Read lattice or hypfile, whichever is specified */ if (latdir) { sprintf (file, "%s/%s.lat", latdir, uttid); dag = dag_load (file); if (! dag) { /* Try lower casing uttid */ strcpy (lc_uttid, uttid); lcase (lc_uttid); sprintf (file, "%s/%s.lat", latdir, lc_uttid); dag = dag_load (file); } } else { if (fgets(line, sizeof(line), hfp) == NULL) E_FATAL("Premature EOF(%s) at uttid %s\n", hypfile, uttid); dag = hypline2dag (uttid, line); } if (dag) { /* Append sentinel silwid node to end of DAG */ dag_append_sentinel (dag, silwid); /* Find best path (returns #errors/#correct and updates *nhyp) */ retval = dp (uttid, dict, oovbegin, ref, nref, dag, &nhyp, 0); dag_destroy (dag); } else { retval.c = 0; retval.e = nref-1; nhyp = 0; } timing_stop (tm); tot_ref += nref-1; tot_hyp += nhyp; tot_err += retval.e; tot_corr += retval.c; tot_oov += noov; printf("(%s) << %d ref; %d %.1f%% oov; %d hyp; %d %.1f%% corr; %d %.1f%% err; %.1fs CPU >>\n", uttid, nref-1, noov, (nref > 1) ? (noov * 100.0) / (nref-1) : 0.0, nhyp, retval.c, (nref > 1) ? (retval.c * 100.0) / (nref-1) : 0.0, retval.e, (nref > 1) ? (retval.e * 100.0) / (nref-1) : 0.0, tm->t_cpu); printf("== %7d ref; %5d %5.1f%% oov; %7d hyp; %7d %5.1f%% corr; %6d %5.1f%% err; %5.1fs CPU; %s\n", tot_ref, tot_oov, (tot_ref > 0) ? (tot_oov * 100.0) / tot_ref : 0.0, tot_hyp, tot_corr, (tot_ref > 0) ? (tot_corr * 100.0) / tot_ref : 0.0, tot_err, (tot_ref > 0) ? (tot_err * 100.0) / tot_ref : 0.0, tm->t_tot_cpu, uttid); fflush (stderr); fflush (stdout); } fclose (rfp); if (hfp) fclose (hfp); printf("SUMMARY: %d ref; %d %.3f%% oov; %d hyp; %d %.3f%% corr; %d %.3f%% err; %.1fs CPU\n", tot_ref, tot_oov, (tot_ref > 0) ? (tot_oov * 100.0) / tot_ref : 0.0, tot_hyp, tot_corr, (tot_ref > 0) ? (tot_corr * 100.0) / tot_ref : 0.0, tot_err, (tot_ref > 0) ? (tot_err * 100.0) / tot_ref : 0.0, tm->t_tot_cpu); }
int main(int argc, char *argv[]) { lexicon_t *lex; model_def_t *omdef; model_def_t *dmdef; uint32 n_stream; const uint32 *veclen; uint32 ts_off; uint32 ts_cnt; FILE *fp; timing_t *all_timer= NULL; timing_t *km_timer= NULL; timing_t *var_timer= NULL; timing_t *em_timer= NULL; if (main_initialize(argc, argv, &lex, &omdef, &dmdef) != S3_SUCCESS) { return -1; } km_timer = timing_get("km"); var_timer = timing_get("var"); em_timer = timing_get("em"); all_timer = timing_get("all"); n_stream = feat_n_stream(); veclen = feat_vecsize(); if (strcmp((const char *)cmd_ln_access("-gthobj"), "state") == 0) { ts_off = *(uint32 *)cmd_ln_access("-tsoff"); if (cmd_ln_access("-tscnt") == NULL) { ts_cnt = omdef->n_tied_state - ts_off; } else { ts_cnt = *(uint32 *)cmd_ln_access("-tscnt"); } if (ts_off + ts_cnt > omdef->n_tied_state) { E_FATAL("Too many tied states specified\n"); } n_tot_frame = 0; if (all_timer) timing_reset(all_timer); if (km_timer) timing_reset(km_timer); if (var_timer) timing_reset(var_timer); if (em_timer) timing_reset(em_timer); if (all_timer) timing_start(all_timer); if (init_state((const char *)cmd_ln_access("-segdmpfn"), (const char *)cmd_ln_access("-segidxfn"), *(int32 *)cmd_ln_access("-ndensity"), n_stream, veclen, *(int32 *)cmd_ln_access("-reest"), (const char *)cmd_ln_access("-mixwfn"), (const char *)cmd_ln_access("-meanfn"), (const char *)cmd_ln_access("-varfn"), ts_off, ts_cnt, omdef->n_tied_state, (dmdef != NULL ? dmdef->n_tied_state : omdef->n_tied_state)) != S3_SUCCESS) { E_ERROR("Unable to train [%u %u]\n", ts_off, ts_off+ts_cnt-1); } if (all_timer) timing_stop(all_timer); if (n_tot_frame > 0) { E_INFO("TOTALS:"); if (km_timer) { E_INFOCONT(" km %4.3fx %4.3e", km_timer->t_cpu / (n_tot_frame * 0.01), (km_timer->t_cpu > 0 ? km_timer->t_elapsed / km_timer->t_cpu : 0.0)); } if (var_timer) { E_INFOCONT(" var %4.3fx %4.3e", var_timer->t_cpu / (n_tot_frame * 0.01), (var_timer->t_cpu > 0 ? var_timer->t_elapsed / var_timer->t_cpu : 0.0)); } if (em_timer) { E_INFOCONT(" em %4.3fx %4.3e", em_timer->t_cpu / (n_tot_frame * 0.01), (em_timer->t_cpu > 0 ? em_timer->t_elapsed / em_timer->t_cpu : 0.0)); } if (all_timer) { E_INFOCONT(" all %4.3fx %4.3e", all_timer->t_cpu / (n_tot_frame * 0.01), (all_timer->t_cpu > 0 ? all_timer->t_elapsed / all_timer->t_cpu : 0.0)); } E_INFOCONT("\n"); } if (cmd_ln_access("-tsrngfn") != NULL) { fp = fopen((const char *)cmd_ln_access("-tsrngfn"), "w"); if (fp == NULL) { E_FATAL_SYSTEM("Unable to open %s for reading", (const char *)cmd_ln_access("-tsrngfn")); } fprintf(fp, "%d %d\n", ts_off, ts_cnt); } else if (ts_cnt != omdef->n_tied_state) { E_WARN("Subset of tied states specified, but no -tsrngfn arg"); } } else if (strcmp((const char *)cmd_ln_access("-gthobj"), "single") == 0) { n_tot_frame = 0; if (all_timer) timing_reset(all_timer); if (km_timer) timing_reset(km_timer); if (var_timer) timing_reset(var_timer); if (em_timer) timing_reset(em_timer); if (all_timer) timing_start(all_timer); if (init_state((const char *)cmd_ln_access("-segdmpfn"), NULL, /* No index -> single class dump file */ *(int32 *)cmd_ln_access("-ndensity"), n_stream, veclen, *(int32 *)cmd_ln_access("-reest"), (const char *)cmd_ln_access("-mixwfn"), (const char *)cmd_ln_access("-meanfn"), (const char *)cmd_ln_access("-varfn"), 0, 1, 1, 1) != S3_SUCCESS) { E_ERROR("Unable to train\n"); } if (all_timer) timing_stop(all_timer); if (n_tot_frame > 0) { E_INFO("TOTALS:"); if (km_timer) { E_INFOCONT(" km %4.3fx %4.3e", km_timer->t_cpu / (n_tot_frame * 0.01), (km_timer->t_cpu > 0 ? km_timer->t_elapsed / km_timer->t_cpu : 0.0)); } if (var_timer) { E_INFOCONT(" var %4.3fx %4.3e", var_timer->t_cpu / (n_tot_frame * 0.01), (var_timer->t_cpu > 0 ? var_timer->t_elapsed / var_timer->t_cpu : 0.0)); } if (em_timer) { E_INFOCONT(" em %4.3fx %4.3e", em_timer->t_cpu / (n_tot_frame * 0.01), (em_timer->t_cpu > 0 ? em_timer->t_elapsed / em_timer->t_cpu : 0.0)); } if (all_timer) { E_INFOCONT(" all %4.3fx %4.3e", all_timer->t_cpu / (n_tot_frame * 0.01), (all_timer->t_cpu > 0 ? all_timer->t_elapsed / all_timer->t_cpu : 0.0)); } E_INFOCONT("\n"); } } return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wc; MSG msg; HWND hWnd; int i; #ifdef OPENING_WAIT UINT32 tick; #endif _MEM_INIT(); GetModuleFileName(NULL, modulefile, NELEMENTS(modulefile)); dosio_init(); file_setcd(modulefile); np2arg_analize(); initload(); memdbg_readini(); skbdwin_readini(); rand_setseed((unsigned)time(NULL)); if ((hWnd = FindWindow(szClassName, NULL)) != NULL) { ShowWindow(hWnd, SW_RESTORE); SetForegroundWindow(hWnd); dosio_term(); return(FALSE); } hInst = hInstance; hPrev = hPreInst; TRACEINIT(); if (np2oscfg.KEYBOARD >= KEY_TYPEMAX) { // ver0.28 int keytype = GetKeyboardType(1); if ((keytype & 0xff00) == 0x0d00) { np2oscfg.KEYBOARD = KEY_PC98; } else if (!keytype) { np2oscfg.KEYBOARD = KEY_KEY101; } else { np2oscfg.KEYBOARD = KEY_KEY106; } } keystat_initialize(); if (!hPreInst) { wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); wc.lpszClassName = szClassName; if (!RegisterClass(&wc)) { return(FALSE); } } memdbg_initialize(hInstance); skbdwin_initialize(hInstance); mousemng_initialize(); hWnd = CreateWindowEx(0, szClassName, szAppCaption, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, np2oscfg.winx, np2oscfg.winy, 640, 400, NULL, NULL, hInstance, NULL); hWndMain = hWnd; scrnmng_initialize(); xmenu_setroltate(0); xmenu_setdispmode(np2cfg.DISPSYNC); xmenu_setraster(np2cfg.RASTER); xmenu_setwaitflg(np2oscfg.NOWAIT); xmenu_setframe(np2oscfg.DRAW_SKIP); xmenu_setkey(0); xmenu_setxshift(0); xmenu_setf12copy(np2oscfg.F12COPY); xmenu_setbeepvol(np2cfg.BEEP_VOL); xmenu_setsound(np2cfg.SOUND_SW); xmenu_setjastsound(np2oscfg.jastsnd); xmenu_setmotorflg(np2cfg.MOTOR); xmenu_setextmem(np2cfg.EXTMEM); xmenu_setmouse(np2oscfg.MOUSE_SW); xmenu_setbtnmode(np2cfg.BTN_MODE); xmenu_setbtnrapid(np2cfg.BTN_RAPID); xmenu_setmsrapid(np2cfg.MOUSERAPID); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); #ifdef OPENING_WAIT tick = GetTickCount(); #endif sysmenu_initialize(); xmenu_initialize(); DrawMenuBar(hWnd); // ver0.30 if (file_attr_c(np2help) == (short)-1) { EnableMenuItem(GetMenu(hWnd), IDM_HELP, MF_GRAYED); } scrnmode = 0; if (np2arg.fullscreen) { scrnmode |= SCRNMODE_FULLSCREEN; } if (np2cfg.RASTER) { scrnmode |= SCRNMODE_HIGHCOLOR; } if (scrnmng_create(scrnmode) != SUCCESS) { scrnmode ^= SCRNMODE_FULLSCREEN; if (scrnmng_create(scrnmode) != SUCCESS) { MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), szAppCaption, MB_OK | MB_ICONSTOP); return(FALSE); } } soundmng_initialize(); if (np2oscfg.MOUSE_SW) { // ver0.30 mousemng_enable(MOUSEPROC_SYSTEM); } commng_initialize(); sysmng_initialize(); joy_init(); pccore_init(); S98_init(); #ifdef OPENING_WAIT while((GetTickCount() - tick) < OPENING_WAIT); #endif scrndraw_redraw(); pccore_reset(); np2opening = 0; // れじうむ #if defined(SUPPORT_RESUME) if (np2oscfg.resume) { int id; id = flagload(str_sav, str_resume, FALSE); if (id == IDYES) { for (i=0; i<4; i++) np2arg.disk[i] = NULL; } else if (id == IDCANCEL) { DestroyWindow(hWnd); mousemng_disable(MOUSEPROC_WINUI); S98_trash(); pccore_term(); soundmng_deinitialize(); scrnmng_destroy(); TRACETERM(); dosio_term(); return(0); } } #endif // リセットしてから… コマンドラインのディスク挿入。 // ver0.29 for (i=0; i<4; i++) { if (np2arg.disk[i]) { diskdrv_readyfdd((REG8)i, np2arg.disk[i], 0); } } memdbg_create(); skbdwin_create(); while(1) { if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) { break; } if ((msg.message != WM_SYSKEYDOWN) && (msg.message != WM_SYSKEYUP)) { TranslateMessage(&msg); } DispatchMessage(&msg); } else { if (np2oscfg.NOWAIT) { joy_flash(); mousemng_sync(); pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; if (framecnt >= np2oscfg.DRAW_SKIP) { processwait(0); } } else { // nowait auto skip framecnt = 1; if (timing_getcount()) { processwait(0); } } } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { joy_flash(); mousemng_sync(); pccore_exec(framecnt == 0); framecnt++; } else { processwait(np2oscfg.DRAW_SKIP); } } else { // auto skip if (!waitcnt) { UINT cnt; joy_flash(); mousemng_sync(); pccore_exec(framecnt == 0); framecnt++; cnt = timing_getcount(); if (framecnt > cnt) { waitcnt = framecnt; if (framemax > 1) { framemax--; } } else if (framecnt >= framemax) { if (framemax < 12) { framemax++; } if (cnt >= 12) { timing_reset(); } else { timing_setcount(cnt - framecnt); } framereset(); } } else { processwait(waitcnt); waitcnt = framecnt; } } } } pccore_cfgupdate(); mousemng_disable(MOUSEPROC_WINUI); S98_trash(); #if defined(SUPPORT_RESUME) if (np2oscfg.resume) { flagsave(str_sav); } else { flagdelete(str_sav); } #endif pccore_term(); memdbg_destroy(); skbdwin_destroy(); soundmng_deinitialize(); scrnmng_destroy(); if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); memdbg_writeini(); skbdwin_writeini(); } skbdwin_deinitialize(); TRACETERM(); _MEM_USED("report.txt"); dosio_term(); return static_cast<int>(msg.wParam); }
int main(int argc, char *argv[]) { Rect wRect; EventRecord event; UINT t; GrafPtr saveport; Point pt; dosio_init(); file_setcd(target); InitToolBox(); macossub_init(); initload(); MenuBarInit(); TRACEINIT(); keystat_initialize(); SetRect(&wRect, np2oscfg.posx, np2oscfg.posy, 100, 100); #if !defined(SUPPORT_PC9821) hWndMain = NewWindow(0, &wRect, "\pNeko Project II", FALSE, noGrowDocProc, (WindowPtr)-1, TRUE, 0); #else hWndMain = NewWindow(0, &wRect, "\pNeko Project 21", FALSE, noGrowDocProc, (WindowPtr)-1, TRUE, 0); #endif if (!hWndMain) { TRACETERM(); macossub_term(); dosio_term(); return(0); } scrnmng_initialize(); SizeWindow(hWndMain, 640, 400, TRUE); ShowWindow(hWndMain); menu_setrotate(0); menu_setdispmode(np2cfg.DISPSYNC); menu_setraster(np2cfg.RASTER); menu_setwaitflg(np2oscfg.NOWAIT); menu_setframe(np2oscfg.DRAW_SKIP); menu_setkey(0); menu_setxshift(0); menu_setf11key(np2oscfg.F11KEY); menu_setf12key(np2oscfg.F12KEY); menu_setbeepvol(np2cfg.BEEP_VOL); menu_setsound(np2cfg.SOUND_SW); menu_setjastsnd(np2oscfg.jastsnd); menu_setmotorflg(np2cfg.MOTOR); menu_setextmem(np2cfg.EXTMEM); menu_setdispclk(np2oscfg.DISPCLK); menu_setbtnrapid(np2cfg.BTN_RAPID); menu_setbtnmode(np2cfg.BTN_MODE); scrnmode = 0; if (scrnmng_create(scrnmode) != SUCCESS) { TRACETERM(); macossub_term(); dosio_term(); DisposeWindow(hWndMain); return(0); } np2open(); t = GETTICK(); while((GETTICK() - t) < 100) { if (WaitNextEvent(everyEvent, &event, 0, 0)) { eventproc(&event); } } commng_initialize(); sysmng_initialize(); mackbd_initialize(); pccore_init(); S98_init(); mousemng_initialize(); if (np2oscfg.MOUSE_SW) { // ver0.30 mousemng_enable(MOUSEPROC_SYSTEM); } // scrndraw_redraw(); pccore_reset(); #if defined(SUPPORT_RESUME) if (np2oscfg.resume) { flagload(np2resumeext, FALSE); } #endif SetEventMask(everyEvent); np2running = TRUE; while(np2running) { if (WaitNextEvent(everyEvent, &event, 0, 0)) { eventproc(&event); } else { if (np2oscfg.NOWAIT) { mackbd_callback(); mousemng_callback(); pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; if (framecnt >= np2oscfg.DRAW_SKIP) { processwait(0); } } else { // nowait auto skip framecnt = 1; if (timing_getcount()) { processwait(0); } } } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { mackbd_callback(); mousemng_callback(); pccore_exec(framecnt == 0); framecnt++; } else { processwait(np2oscfg.DRAW_SKIP); } } else { // auto skip if (!waitcnt) { UINT cnt; mackbd_callback(); mousemng_callback(); pccore_exec(framecnt == 0); framecnt++; cnt = timing_getcount(); if (framecnt > cnt) { waitcnt = framecnt; if (framemax > 1) { framemax--; } } else if (framecnt >= framemax) { if (framemax < 12) { framemax++; } if (cnt >= 12) { timing_reset(); } else { timing_setcount(cnt - framecnt); } framereset(); } } else { processwait(waitcnt); waitcnt = framecnt; } } } } GetPort(&saveport); #if TARGET_API_MAC_CARBON SetPortWindowPort(hWndMain); #else SetPort(hWndMain); #endif pt.h = 0; pt.v = 0; LocalToGlobal(&pt); SetPort(saveport); if ((np2oscfg.posx != pt.h) || (np2oscfg.posy != pt.v)) { np2oscfg.posx = pt.h; np2oscfg.posy = pt.v; sysmng_update(SYS_UPDATEOSCFG); } np2running = FALSE; pccore_cfgupdate(); #if defined(SUPPORT_RESUME) if (np2oscfg.resume) { flagsave(np2resumeext); } else { flagdelete(np2resumeext); } #endif pccore_term(); S98_trash(); mousemng_disable(MOUSEPROC_SYSTEM); scrnmng_destroy(); if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); } TRACETERM(); macossub_term(); dosio_term(); DisposeWindow(hWndMain); (void)argc; (void)argv; return(0); }
int SDL_main(int argc, char **argv) { int pos; char *p; int id; pos = 1; while(pos < argc) { p = argv[pos++]; if ((!milstr_cmp(p, "-h")) || (!milstr_cmp(p, "--help"))) { usage(argv[0]); goto np2main_err1; } else { printf("error command: %s\n", p); goto np2main_err1; } } dosio_init(); file_setcd(datadir); initload(); TRACEINIT(); if (fontmng_init() != SUCCESS) { goto np2main_err2; } inputmng_init(); keystat_initialize(); if (sysmenu_create() != SUCCESS) { goto np2main_err3; } mousemng_initialize(); scrnmng_initialize(); if (scrnmng_create(FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT) != SUCCESS) { goto np2main_err4; } sdlkbd_initialize(); // this must be after SDL_VIDEO initialized soundmng_initialize(); commng_initialize(); sysmng_initialize(); taskmng_initialize(); pccore_init(); S98_init(); mousemng_hidecursor(); scrndraw_redraw(); pccore_reset(); if (np2oscfg.resume) { id = flagload(str_sav, str_resume, FALSE); if (id == DID_CANCEL) { goto np2main_err5; } } while(taskmng_isavail()) { taskmng_rol(); if (np2oscfg.NOWAIT) { pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; if (framecnt >= np2oscfg.DRAW_SKIP) { processwait(0); } } else { // nowait auto skip framecnt = 1; if (timing_getcount()) { processwait(0); } } } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { pccore_exec(framecnt == 0); framecnt++; } else { processwait(np2oscfg.DRAW_SKIP); } } else { // auto skip if (!waitcnt) { UINT cnt; pccore_exec(framecnt == 0); framecnt++; cnt = timing_getcount(); if (framecnt > cnt) { waitcnt = framecnt; if (framemax > 1) { framemax--; } } else if (framecnt >= framemax) { if (framemax < 12) { framemax++; } if (cnt >= 12) { timing_reset(); } else { timing_setcount(cnt - framecnt); } framereset(0); } } else { processwait(waitcnt); waitcnt = framecnt; } } } pccore_cfgupdate(); if (np2oscfg.resume) { flagsave(str_sav); } else { flagdelete(str_sav); } pccore_term(); S98_trash(); soundmng_deinitialize(); if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); } scrnmng_destroy(); sysmenu_destroy(); TRACETERM(); SDL_Quit(); dosio_term(); return(SUCCESS); np2main_err5: pccore_term(); S98_trash(); soundmng_deinitialize(); np2main_err4: scrnmng_destroy(); np2main_err3: sysmenu_destroy(); np2main_err2: TRACETERM(); SDL_Quit(); dosio_term(); np2main_err1: return(FAILURE); }
/* * Find Viterbi alignment. */ static void align_utt (char *sent, /* In: Reference transcript */ float32 **mfc, /* In: MFC cepstra for input utterance */ int32 nfr, /* In: #frames of input */ char *ctlspec, /* In: Utt specifiction from control file */ char *uttid) /* In: Utterance id, for logging and other use */ { static float32 **feat = NULL; static int32 w; static int32 topn; static gauden_dist_t ***dist; static int32 *senscr; static s3senid_t *sen_active; static int8 *mgau_active; static char *s2stsegdir; static char *stsegdir; static char *phsegdir; static char *wdsegdir; int32 i, s, sid, gid, n_sen_active, best; char *arg; align_stseg_t *stseg; align_phseg_t *phseg; align_wdseg_t *wdseg; if (! feat) { /* One-time allocation of necessary intermediate variables */ /* Allocate space for a feature vector */ feat = (float32 **) ckd_calloc (n_feat, sizeof(float32 *)); for (i = 0; i < n_feat; i++) feat[i] = (float32 *) ckd_calloc (featlen[i], sizeof(float32)); /* Allocate space for top-N codeword density values in a codebook */ w = feat_window_size (); /* #MFC vectors needed on either side of current frame to compute one feature vector */ topn = *((int32 *) cmd_ln_access("-topn")); if (topn > g->n_density) { E_ERROR("-topn argument (%d) > #density codewords (%d); set to latter\n", topn, g->n_density); topn = g->n_density; } dist = (gauden_dist_t ***) ckd_calloc_3d (g->n_mgau, n_feat, topn, sizeof(gauden_dist_t)); /* Space for one frame of senone scores, and per frame active flags */ senscr = (int32 *) ckd_calloc (sen->n_sen, sizeof(int32)); sen_active = (s3senid_t *) ckd_calloc (sen->n_sen, sizeof(s3senid_t)); mgau_active = (int8 *) ckd_calloc (g->n_mgau, sizeof(int8)); /* Note various output directories */ s2stsegdir = NULL; stsegdir = NULL; phsegdir = NULL; wdsegdir = NULL; if ((arg = (char *) cmd_ln_access ("-s2stsegdir")) != NULL) s2stsegdir = (char *) ckd_salloc (arg); if ((arg = (char *) cmd_ln_access ("-stsegdir")) != NULL) stsegdir = (char *) ckd_salloc (arg); if ((arg = (char *) cmd_ln_access ("-phsegdir")) != NULL) phsegdir = (char *) ckd_salloc (arg); if ((arg = (char *) cmd_ln_access ("-wdsegdir")) != NULL) wdsegdir = (char *) ckd_salloc (arg); } /* HACK HACKA HACK BHIKSHA if (nfr <= (w<<1)) { E_ERROR("Utterance %s < %d frames (%d); ignored\n", uttid, (w<<1)+1, nfr); return; } END HACK HACKA HACK */ cyctimer_reset_all (); counter_reset_all (); timing_reset (tm_utt); timing_start (tm_utt); cyctimer_resume (tmr_utt); /* AGC and CMN */ arg = (char *) cmd_ln_access ("-cmn"); if (strcmp (arg, "current") == 0) norm_mean (mfc-4, nfr+8, cepsize); /* -4 HACKA HACK */ arg = (char *) cmd_ln_access ("-agc"); if (strcmp (arg, "max") == 0) agc_max (mfc, nfr); if (align_build_sent_hmm (sent) != 0) { align_destroy_sent_hmm (); cyctimer_pause (tmr_utt); E_ERROR("No sentence HMM; no alignment for %s\n", uttid); return; } align_start_utt (uttid); /* * A feature vector for frame f depends on input MFC vectors [f-w..f+w]. Hence * the feature vector corresponding to the first w and last w input frames is * undefined. We define them by simply replicating the first and last true * feature vectors (presumably silence regions). */ for (i = 0; i < nfr; i++) { cyctimer_resume (tmr_utt); /* Compute feature vector for current frame from input speech cepstra */ /* HACK HACKA HACK BHIKSHA if (i < w) feat_cep2feat (mfc+w, feat); else if (i >= nfr-w) feat_cep2feat (mfc+(nfr-w-1), feat); else END HACK HACKA HACK */ feat_cep2feat (mfc+i, feat); /* * Evaluate gaussian density codebooks and senone scores for input codeword. * Evaluate only active codebooks and senones. */ /* Obtain active senone flags */ cyctimer_resume (tmr_senone); align_sen_active (sen_active, sen->n_sen); /* Flag all CI senones to active if interpolating */ if (interp) { for (s = 0; s < mdef->n_ci_sen; s++) sen_active[s] = 1; } /* Turn active flags into list (for faster access) */ n_sen_active = 0; for (s = 0; s < mdef->n_sen; s++) { if (sen_active[s]) sen_active[n_sen_active++] = s; } cyctimer_pause (tmr_senone); /* Flag all active mixture-gaussian codebooks */ cyctimer_resume (tmr_gauden); for (gid = 0; gid < g->n_mgau; gid++) mgau_active[gid] = 0; for (s = 0; s < n_sen_active; s++) { sid = sen_active[s]; mgau_active[sen->mgau[sid]] = 1; } /* Compute topn gaussian density values (for active codebooks) */ for (gid = 0; gid < g->n_mgau; gid++) if (mgau_active[gid]) gauden_dist (g, gid, topn, feat, dist[gid]); cyctimer_pause (tmr_gauden); /* Evaluate active senones */ cyctimer_resume (tmr_senone); best = (int32) 0x80000000; for (s = 0; s < n_sen_active; s++) { sid = sen_active[s]; senscr[sid] = senone_eval (sen, sid, dist[sen->mgau[sid]], topn); if (best < senscr[sid]) best = senscr[sid]; } if (interp) { for (s = 0; s < n_sen_active; s++) { if ((sid = sen_active[s]) >= mdef->n_ci_sen) interp_cd_ci (interp, senscr, sid, mdef->cd2cisen[sid]); } } /* Normalize senone scores (interpolation above can only lower best score) */ for (s = 0; s < n_sen_active; s++) { sid = sen_active[s]; senscr[sid] -= best; } senscale[i] = best; cyctimer_pause (tmr_senone); /* Step alignment one frame forward */ cyctimer_resume (tmr_align); align_frame (senscr); cyctimer_pause (tmr_align); cyctimer_pause (tmr_utt); } timing_stop (tm_utt); printf ("\n"); /* Wind up alignment for this utterance */ if (align_end_utt (&stseg, &phseg, &wdseg) < 0) E_ERROR("Final state not reached; no alignment for %s\n\n", uttid); else { if (s2stsegdir) write_s2stseg (s2stsegdir, stseg, uttid, ctlspec); if (stsegdir) write_stseg (stsegdir, stseg, uttid, ctlspec); if (phsegdir) write_phseg (phsegdir, phseg, uttid, ctlspec); if (wdsegdir) write_wdseg (wdsegdir, wdseg, uttid, ctlspec); if (outsentfp) write_outsent (outsentfp, wdseg, uttid); } align_destroy_sent_hmm (); cyctimer_print_all_norm (stdout, nfr*0.01, tmr_utt); counter_print_all (stdout); printf("EXECTIME: %5d frames, %7.2f sec CPU, %6.2f xRT; %7.2f sec elapsed, %6.2f xRT\n", nfr, tm_utt->t_cpu, tm_utt->t_cpu * 100.0 / nfr, tm_utt->t_elapsed, tm_utt->t_elapsed * 100.0 / nfr); tot_nfr += nfr; }
/* * Quantize pt[0..n_pt-1][0..veclen-1] into cb[0..vqsize-1][0..veclen-1] (where * vqsize < n_pt, presumably). Do this with the following iterative procedure: * 1. Choose an initial VQ codebook by selecting vqsize random points from pt. * 2. Map each point in pt to the "nearest" codebook entry (currently based on * Euclidean distance. * 3. Re-estimate each VQ entry by taking the centroid of all pt entries mapped * to it in step 2. * 4. Repeat steps 2 and 3 until the "total error stabilizes". * In the end, replace each point in pt with the nearest VQ value. * Return value: final total error. */ static float64 vq (float32 **pt, float32 **cb, int32 n_pt, int32 vqsize, int32 veclen) { int32 p, c, i, iter, bestc, *pt2cb, *n_newcb; float64 d, bestdist, err, prev_err; float32 **newcb; E_INFO("Clustering %d points into %d\n", n_pt, vqsize); /* Allocate some temporary variables */ pt2cb = (int32 *) ckd_calloc (n_pt, sizeof(int32)); newcb = (float32 **)ckd_calloc_2d (vqsize, veclen, sizeof(float32)); n_newcb = (int32 *) ckd_calloc (vqsize, sizeof(int32)); /* Choose an initial codebook */ vq_init (pt, cb, n_pt, vqsize, veclen); for (iter = 0;; iter++) { timing_start (tmg); /* Map each point to closest codebook entry (using Euclidean distance metric) */ err = 0.0; for (p = 0; p < n_pt; p++) { bestdist = 1e+200; for (c = 0; c < vqsize; c++) { d = vecdist (pt[p], cb[c], veclen); if (d < bestdist) { bestdist = d; bestc = c; } } pt2cb[p] = bestc; err += bestdist; } /* Update codebook entries with centroid of mapped points */ for (c = 0; c < vqsize; c++) { for (i = 0; i < veclen; i++) newcb[c][i] = 0.0; n_newcb[c] = 0; } for (p = 0; p < n_pt; p++) { c = pt2cb[p]; for (i = 0; i < veclen; i++) newcb[c][i] += pt[p][i]; n_newcb[c]++; } for (c = 0; c < vqsize; c++) { if (n_newcb[c] == 0) E_ERROR("Nothing mapped to codebook entry %d; entry not updated\n", c); else { float64 t; t = 1.0 / n_newcb[c]; for (i = 0; i < veclen; i++) cb[c][i] = newcb[c][i] * t; } } timing_stop (tmg); E_INFO("%4d: Error = %e, %.2f sec CPU, %.2f sec elapsed\n", iter, err, tmg->t_cpu, tmg->t_elapsed); timing_reset (tmg); /* Check if VQ codebook converged */ if (iter > 10) { if ((err == 0.0) || ((prev_err - err)/prev_err < 0.002)) break; } prev_err = err; } /* Replace points with nearest VQ entries created */ for (p = 0; p < n_pt; p++) { c = pt2cb[p]; for (i = 0; i < veclen; i++) pt[p][i] = cb[c][i]; } ckd_free (pt2cb); ckd_free_2d ((void **) newcb); ckd_free (n_newcb); return err; }
/* Decode the given mfc file and write result to matchfp and matchsegfp */ static void decode_utt (char *uttid, FILE *matchfp, FILE *matchsegfp) { char dagfile[1024]; hyp_t *h, *hyp; char *latdir, *latext; int32 nfrm, ascr, lscr; timing_reset (tm_utt); timing_start (tm_utt); latdir = (char *) cmd_ln_access ("-inlatdir"); latext = (char *) cmd_ln_access ("-latext"); if (latdir) sprintf (dagfile, "%s/%s.%s", latdir, uttid, latext); else sprintf (dagfile, "%s.%s", uttid, latext); if ((nfrm = dag_load (dagfile)) >= 0) { hyp = dag_search (uttid); if ( *((int32 *) cmd_ln_access("-backtrace")) ) log_hyp_detailed (stdout, hyp, uttid, "BP", "bp"); /* Total scaled acoustic score and LM score */ ascr = lscr = 0; for (h = hyp; h; h = h->next) { ascr += h->ascr; lscr += h->lscr; } printf ("BSTPTH: "); log_hypstr (stdout, hyp, uttid, ascr+lscr); printf ("BSTXCT: "); log_hypseg (uttid, stdout, hyp, nfrm); lm_cache_stats_dump (); lm_cache_reset (); } else { E_ERROR("DAG search (%s) failed\n", uttid); hyp = NULL; } /* Log recognition output to the standard match and matchseg files */ if (matchfp) log_hypstr (matchfp, hyp, uttid, 0); if (matchsegfp) log_hypseg (uttid, matchsegfp, hyp, nfrm); dag_destroy (); timing_stop (tm_utt); printf ("%s: TMR: %5d Frm", uttid, nfrm); if (nfrm > 0) { printf (" %6.2f xEl", tm_utt->t_elapsed * 100.0 / nfrm); printf (" %6.2f xCPU", tm_utt->t_cpu * 100.0 / nfrm); } printf ("\n"); fflush (stdout); tot_nfr += nfrm; }
/* Main program. */ int main(void) { int i, j, n_samples, max_n, step_n; int array_size; int radix; test_item_t a[N_ITEMS], test_array[N_ITEMS]; test_item_t *timing_array, *copy_array; timing_t *t; /* Assign random values to the key of each array element. */ rand_array(a, N_ITEMS, 100); /* Now test quicksort(). */ memcpy(test_array, a, sizeof(test_array)); printf("array before quicksort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); quicksort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp); printf("array after quicksort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); /* Now test mergesort0(). */ memcpy(test_array, a, sizeof(test_array)); printf("array before mergesort0\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); mergesort0(test_array, N_ITEMS, sizeof(test_item_t), item_cmp); printf("array after mergesort0\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); /* Now test mergesort(). */ memcpy(test_array, a, sizeof(test_array)); printf("array before mergesort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); mergesort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp); printf("array after mergesort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); /* Now test radix sort. */ memcpy(test_array, a, sizeof(test_array)); printf("array before radixsort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); radixsort(test_array, N_ITEMS, sizeof(test_item_t), get_value, 10); printf("array after radixsort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); /* Now test heapsort. */ memcpy(test_array, a, sizeof(test_array)); printf("array before heapsort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); heapsort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp); printf("array after heapsort\n = "); print_array(test_array, N_ITEMS); printf("\n\n"); /* Time the quicksort and mergesort sorting functions. */ printf("Enter the number of samples to use: "); scanf("%d", &n_samples); printf("Enter the maximum array length to sort: "); scanf("%d", &max_n); printf("Enter the step size for array lengths: "); scanf("%d", &step_n); t = timing_alloc(5); /* Five different sorting algorithms. */ printf("\nResults (n, qsort, quicksort, mergesort, mergesort0, heapsort) (msec)\n" ); for(i = step_n; i <= max_n; i += step_n) { array_size = i * sizeof(test_item_t); timing_array = malloc(array_size); copy_array = malloc(array_size); rand_array(copy_array, i, MAX_VALUE); timing_reset(t); for(j = 0; j < n_samples; j++) { memcpy(timing_array, copy_array, array_size); timing_start(); qsort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,0); memcpy(timing_array, copy_array, array_size); timing_start(); quicksort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,1); memcpy(timing_array, copy_array, array_size); timing_start(); mergesort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,2); memcpy(timing_array, copy_array, array_size); timing_start(); mergesort0(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,3); memcpy(timing_array, copy_array, array_size); timing_start(); heapsort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,4); } printf("%d", i); timing_print(t,"\t%.2f",n_samples); putchar('\n'); free(timing_array); free(copy_array); } timing_free(t); /* Time radix sort on the largest array, using different radix sizes. */ printf("\nRadix Sort Results. Using n = %d\n", max_n); printf("(radix, time)\n"); array_size = max_n * sizeof(test_item_t); timing_array = malloc(array_size); copy_array = malloc(array_size); rand_array(copy_array, max_n, MAX_VALUE); for(radix = 2; radix <= max_n; radix <<= 1) { timer_reset(); for(j = 0; j < n_samples; j++) { memcpy(timing_array, copy_array, array_size); timer_start(); radixsort(timing_array, max_n, sizeof(test_item_t), get_value, radix); timer_stop(); } printf("%d", radix); timer_print("\t%.2f", n_samples); putchar('\n'); } free(timing_array); free(copy_array); return 0; }
int main(void) { NP2MAIN np2main; #ifndef NOSERIAL serial_init(57600); usleep(20000); printf("Serial OK\n"); #endif maple_init(); dc_setup_ta(); init_arm(); __dc_avail = true; dc_savedtimes = 0; dc_joyinput = 0; dc_mouseaxis1 = 0; dc_mouseaxis2 = 0; ui_init(); dosio_init(); file_setcd(modulefile); initload(); TRACEINIT(); keystat_initialize(); mousemng_initialize(); scrnmng_initialize(); UINT8 scrnmode = 0; if (scrnmng_create(scrnmode) != SUCCESS) { return -1; } softkbddc_initialize(); dckbd_bindinit(); dckbd_bindcur(np2oscfg.bindcur); dckbd_bindbtn(np2oscfg.bindbtn); soundmng_initialize(); commng_initialize(); sysmng_initialize(); taskmng_initialize(); joymng_initialize(); pccore_init(); S98_init(); pccore_reset(); scrndraw_redraw(); np2main.uFrameCount = 0; np2main.uWaitCount = 0; np2main.uFrameMax = 1; #if 0 if (np2oscfg.resume) { id = flagload(str_sav, str_resume, FALSE); if (id == DID_CANCEL) { DestroyWindow(hWnd); goto np2main_err4; } } #endif while (dcsys_task()) { if (np2oscfg.NOWAIT) { exec1frame(np2main); if (np2oscfg.DRAW_SKIP) { // nowait frame skip if (np2main.uFrameCount >= np2oscfg.DRAW_SKIP) { processwait(np2main, 0); } } else { // nowait auto skip if (timing_getcount()) { processwait(np2main, 0); } } } else if (np2oscfg.DRAW_SKIP) { // frame skip if (np2main.uFrameCount < np2oscfg.DRAW_SKIP) { exec1frame(np2main); } else { processwait(np2main, np2oscfg.DRAW_SKIP); } } else { // auto skip if (!np2main.uWaitCount) { exec1frame(np2main); const UINT uCount = timing_getcount(); if (np2main.uFrameCount > uCount) { np2main.uWaitCount = np2main.uFrameCount; if (np2main.uFrameMax > 1) { np2main.uFrameMax--; } } else if (np2main.uFrameCount >= np2main.uFrameMax) { if (np2main.uFrameMax < MAX_FRAMESKIP) { np2main.uFrameMax++; } if (uCount >= MAX_FRAMESKIP) { timing_reset(); } else { timing_setcount(uCount - np2main.uFrameCount); } framereset(np2main, 0); } } else { processwait(np2main, np2main.uWaitCount); np2main.uWaitCount = np2main.uFrameCount; } } } pccore_cfgupdate(); #if 0 if (np2oscfg.resume) { flagsave(str_sav); } else { flagdelete(str_sav); } #endif pccore_term(); S98_trash(); scrnmng_destroy(); if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); } TRACETERM(); dosio_term(); #ifdef NOSERIAL (*(void(**)(int))0x8c0000e0)(1); while (1) { } #endif return 0; }