BOOL UploadGAR (void) { FILE *GAR; char filename[MAX_PATH]; int i; if (!PromptFile(topHWnd,"Game Action Replay RAM file (gar.bin)\0gar.bin\0\0",filename,NULL,Path_PLUG,"Please select a valid Game Action Replay data file...","gar.bin",FALSE)) return FALSE; if ((GAR = fopen(filename,"rb")) == NULL) { MessageBox(topHWnd,"Unable to open GAR data file!",MSGBOX_TITLE,MB_OK | MB_ICONERROR); return FALSE; } OpenStatus(topHWnd); InitPort(); StatusText("Resetting CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading initialization plugin..."); if (!LoadPlugin("garset.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running initialization plugin..."); RunCode(); Sleep(SLEEP_LONG); StatusText("Loading upload plugin..."); if (!LoadPlugin("garup.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running upload plugin..."); RunCode(); StatusText("Uploading from data file..."); BYTE a[256]; for (i = 0; i < 8; i++) { fread(&a,256,1,GAR); if (!WriteBlock(a, 256)) { fclose(GAR); CloseStatus(); return FALSE; } StatusPercent((i*100)/8); } StatusPercent(100); StatusText("...done!"); fclose(GAR); StatusText("Upload complete!"); StatusOK(); ResetNES(RESET_COPYMODE); return TRUE; }
BOOL DownloadGAR (void) { FILE *GAR; char filename[MAX_PATH]; int i; if (!PromptFile(topHWnd,"Game Action Replay RAM file (gar_d.bin)\0gar_d.bin\0\0",filename,NULL,Path_PLUG,"Please specify where to save Game Action Replay RAM data...","gar_d.bin",TRUE)) return FALSE; if ((GAR = fopen(filename,"wb")) == NULL) { MessageBox(topHWnd,"Unable to open file for output!",MSGBOX_TITLE,MB_OK | MB_ICONERROR); return FALSE; } OpenStatus(topHWnd); InitPort(); StatusText("Resetting CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading initialization plugin..."); if (!LoadPlugin("garset.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running initialization plugin..."); RunCode(); Sleep(SLEEP_LONG); StatusText("Loading download plugin..."); if (!LoadPlugin("gardn.bin")) { fclose(GAR); CloseStatus(); return FALSE; } StatusText("Running download plugin..."); RunCode(); StatusText("Saving to file..."); for (i = 0; i < 0x800; i++) { BYTE n; if (!ReadByte(n)) { fclose(GAR); CloseStatus(); return FALSE; } fwrite(&n,1,1,GAR); if (!(i & 0x7)) StatusPercent((i*100)/2048); } fclose(GAR); StatusText("Download complete!"); StatusOK(); ResetNES(RESET_COPYMODE); return TRUE; }
C4Value AulTest::RunExpr(const char *expr) { std::string code = "return "; code += expr; code += ';'; return RunCode(code.c_str()); }
TEST_F(AulTest, Loops) { EXPECT_EQ(C4VInt(5), RunCode("var i = 0; do ++i; while (i < 5); return i;")); EXPECT_EQ(C4VInt(5), RunCode("var i = 0; while (i < 5) ++i; return i;")); EXPECT_EQ(C4VInt(5), RunCode("for(var i = 0; i < 5; ++i); return i;")); EXPECT_EQ(C4VInt(6), RunCode("var i = 0, b; do { b = i++ >= 5; } while (!b); return i;")); EXPECT_EQ(C4VInt(6), RunCode("var i = 0, b; while (!b) { b = i++ >= 5; } return i;")); EXPECT_EQ(C4Value(), RunCode("var a = [], sum; for(var i in a) sum += i; return sum;")); EXPECT_EQ(C4VInt(1), RunCode("var a = [1], sum; for(var i in a) sum += i; return sum;")); EXPECT_EQ(C4VInt(6), RunCode("var a = [1,2,3], sum; for(var i in a) sum += i; return sum;")); }
bool PythonInterpCtrl::DispatchCode(const wxString &code) { if(m_pyinterp->IsJobRunning()) return false; m_code=code; // if (RunCode(wxString(code.c_str()))) if (RunCode(wxString(code))) { m_codectrl->Enable(false); // wxCommandEvent pe(wxEVT_PY_NOTIFY_UI_CODEOK,0); // ::wxPostEvent(this,pe); } return true; }
TEST_F(AulTest, Locals) { EXPECT_EQ(C4VInt(42), RunCode("local i = 42; func Main() { return i; }", false)); EXPECT_EQ(C4VInt(42), RunCode("local i; func Main() { i = 42; return i; }", false)); EXPECT_EQ(C4VInt(42), RunCode("func Main() { local i = 42; return i; }", false)); EXPECT_EQ(C4VInt(42), RunCode("local i = [42]; func Main() { return i[0]; }", false)); EXPECT_EQ(C4VInt(42), RunCode("local p = { i = 42 }; func Main() { return p.i; }", false)); EXPECT_EQ(C4VInt(42), RunCode("local p1 = { i = 42 }, p2 = new p1 {}; func Main() { return p2.i; }", false)); }
TEST_F(AulTest, ValueReturn) { // Make sure primitive value returns work. EXPECT_EQ(C4VNull, RunCode("return;")); EXPECT_EQ(C4VNull, RunExpr("nil")); EXPECT_EQ(C4Value(true), RunExpr("true")); EXPECT_EQ(C4Value(false), RunExpr("false")); EXPECT_EQ(C4VInt(42), RunExpr("42")); EXPECT_EQ(C4VString("Hello World!"), RunExpr("\"Hello World!\"")); // Make sure array returns work. EXPECT_EQ(C4VArray(), RunExpr("[]")); EXPECT_EQ( C4VArray(C4VInt(0), C4VNull, C4VArray(C4VInt(1)), C4VString("Hi")), RunExpr("[0, nil, [1], \"Hi\"]")); // Make sure proplist returns work. EXPECT_EQ(C4VPropList(), RunExpr("{}")); EXPECT_EQ( C4VPropList("a", C4VInt(1), "b", C4VArray()), RunExpr("{\"a\": 1, \"b\"=[]}")); }
/** * @brief 评测函数 * 通过对比输出文件进行评测 * * @param exe 已编译好的可执行文件名 * @param stdinput 标准输入文件名 * @param stdoutput 标准输出文件名 * @param cs 用于接收代码状态的引用 * @return 若评测结果为ACCEPTED则返回true,其它一律返回false */ bool CNBUTOJCore::Judge(const char *exe, const char *stdinput, const char *stdoutput, const __int64 lim_time, const SIZE_T lim_memo, CodeState &cs, bool bPause) { cs.exe_time = RUN_NO_TIME; cs.exe_memory = RUN_NO_MEMO; /** 几个文件路径 */ string newexe = string(TEMP_PATH) + exe; string exeoutput = string(TEMP_PATH) + string(".output"); /** 检测标准输出文件 */ if(!FileExists(stdoutput)) { cs.state = SYSTEM_ERROR; strcpy(cs.err_code, "Wrong std output file."); return false; } /** 最大文件大小 */ struct _stat stdoutputinfo; _stat(stdoutput, &stdoutputinfo); DWORD maxSize = stdoutputinfo.st_size * 2; /** 运行代码 */ PROCESS_INFORMATION ProcInfo; HANDLE hInput, hOutput; HANDLE hProcess = RunCode(newexe.c_str(), stdinput, exeoutput.c_str(), cs, hInput, hOutput, ProcInfo); ReleaseIOHandle(hInput, hOutput); /** 若代码运行不成功 */ if(NULL == hProcess) { if(bPause) system("pause"); //ReleaseIOHandle(hInput, hOutput); ClearUp(newexe.c_str(), exeoutput.c_str(), ProcInfo); return false; } /** 监视若有异常 */ if(!WatchCode(hProcess, lim_time, lim_memo, maxSize, exeoutput.c_str(), cs, ProcInfo)) { if(cs.state == NState::TIME_LIMIT_EXCEEDED_1 || cs.state == NState::TIME_LIMIT_EXCEEDED_2) { cs.exe_time = lim_time; } if(bPause) system("pause"); //ReleaseIOHandle(hInput, hOutput); ClearUp(newexe.c_str(), exeoutput.c_str(), ProcInfo); return false; } /** 释放输入输出文件句柄 */ //ReleaseIOHandle(hInput, hOutput); /** 判断代码正误 */ int t = 10; while(!_IsRight(stdoutput, exeoutput.c_str(), cs) && t--) { /** SYSTEM错误的话 */ if(cs.state == SYSTEM_ERROR) { Sleep(10); continue; } if(bPause) system("pause"); //ReleaseIOHandle(hInput, hOutput); ClearUp(newexe.c_str(), exeoutput.c_str(), ProcInfo); return false; } ClearUp(newexe.c_str(), exeoutput.c_str(), ProcInfo); //cs.state = ACCEPTED; return true; }
BOOL CMD_DUMPCART (void) { int dtype = 2; int rbyte = 0, rcount = 0; PPlugin plugin; char *path, *ext; char filename[MAX_PATH]; char fnamebuf[MAX_PATH]; int cmode, battery, bytes, numk; int mapper,submapper=0; int nes2=0, wram=0, vram=0; BYTE ctype; WORD nblks; char Status[256]; FILE *CRC, *DATA; // select board name plugin = PromptPlugin(PLUG_STD); if (plugin == NULL) return FALSE; mapper = plugin->num; PromptTitle = "Choose a ROM filename (omit extension)"; if (!Prompt(topHWnd)) return FALSE; strcpy(filename,PromptResult); OpenStatus(topHWnd); StatusText("Resetting USB CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Unloading any existing plugin..."); if (!LoadPlugin("clear.bin")) { CloseStatus(); return FALSE; } RunCode(); Sleep(SLEEP_SHORT); StatusText("Resetting USB CopyNES..."); ResetNES(RESET_COPYMODE); StatusText("Loading plugin..."); if (!LoadPlugin(plugin->file)) { CloseStatus(); return FALSE; } StatusText("Running plugin..."); RunCode(); Sleep(SLEEP_LONG); if (SaveCRC) CRC = fopen(strjoin3(fnamebuf,Path_CRC,filename,".txt"),"wb"); cmode = 0; if (!ReadByte((BYTE *)&cmode)) // mirroring { CloseStatus(); return FALSE; } battery = 0; while (1) { // for the first 'header' byte, wait longer than usual // since the plugin might be busy doing size detection, which can take a while int s; if (!ReadByteEx((BYTE *)&nblks,10,TRUE) || !ReadByte((BYTE *)&nblks+1)) { CloseStatus(); return FALSE; } bytes = nblks << 8; numk = bytes / 1024; if (!ReadByte(&ctype)) { CloseStatus(); return FALSE; } if (ctype == 0) break; switch (ctype) { case 1: ext = ".prg"; if(numk >= 4096) nes2 = 1; path = Path_PRG; sprintf(Status,"Dumping %iK PRG ROM...",numk); break; case 2: ext = ".chr"; if(numk >= 2048) nes2 = 1; path = Path_CHR; sprintf(Status,"Dumping %iK CHR ROM...",numk); break; case 3: ext = ".sav"; path = Path_WRAM; sprintf(Status,"Dumping %iK WRAM/VRAM...",numk); battery = 1; break; case 4: rbyte = nblks / 4; continue; case 5: nes2 = 1; wram = nblks & 0xFF; vram = nblks >> 8; if(wram & 0xF0) battery = 1; if(vram & 0xF0) battery = 1; sprintf(Status,"Non battery WRAM size: %i Bytes...", ((wram & 0x0f)?64 << (wram & 0x0F):0)); StatusText(Status); sprintf(Status,"battery WRAM size: %i Bytes...", ((wram >> 4)?64 << (wram & 0x0F):0)); StatusText(Status); sprintf(Status,"Non battery VRAM size: %i Bytes...", ((vram & 0x0f)?64 << (vram & 0x0F):0)); StatusText(Status); sprintf(Status,"battery VRAM size: %i Bytes...", ((vram >> 4)?64 << (vram & 0x0F):0)); StatusText(Status); continue; case 6: //Mapper number override by plugin. mapper = nblks & 0xFFF; submapper = (nblks & 0xF000) >> 12; sprintf(Status,"Mapper number: %i, submapper: %i...",mapper,submapper); StatusText(Status); if((mapper > 255) || (submapper > 0)) nes2 = 1; continue; case 255: sprintf(Status,"."); continue; //Prevent timeout. default:StatusText("Unknown block type %i! Aborting...",ctype); StatusOK(); return FALSE; break; } StatusText(Status); DATA = fopen(strjoin3(fnamebuf,path,filename,ext),"w+b"); if (DATA == NULL) { StatusText("Unable to open output file!"); StatusOK(); return FALSE; } for (s = 0; s < numk; s++) { int a; BYTE n; for (a = 0; a < 1024; a++) { if (!ReadByte(&n)) { CloseStatus(); return FALSE; } fwrite(&n,1,1,DATA); } if (rbyte) { rcount++; if (rbyte <= rcount) { rcount = 0; StatusText("Resetting USB CopyNES as requested by plugin..."); ResetNES(RESET_COPYMODE); StatusText("Reloading plugin..."); LoadPlugin(plugin->file); StatusText("Rerunning plugin..."); RunCode(); rbyte = 0; if (!ReadByte((BYTE *)&rbyte) || !ReadByte((BYTE *)&rbyte+1)) { CloseStatus(); return FALSE; } rbyte /= 4; } } StatusPercent((s*100)/numk); DoEvents(); } StatusPercent(100); StatusText("...done!"); if (SaveCRC) fprintf(CRC,"%s%s %08X\n",filename,ext,GetCRC(DATA)); fclose(DATA); } if (SaveCRC) fclose(CRC); StatusText("Dump complete!"); StatusOK(); ResetNES(RESET_COPYMODE); { int scrn4 = (cmode & 0x2) >> 1; int mirror = (~cmode & 0x1); int mcon = (cmode & 0x4) >> 2; if (plugin->num == 9999) return TRUE; WriteNES(filename,mapper,battery,mirror,scrn4,nes2,wram,vram,submapper,0); if (MakeUnif == 1) WriteUNIF(filename,plugin->name,battery,mirror,scrn4,mcon); if (SaveFiles == 0) { unlink(strjoin3(fnamebuf,Path_CHR,filename,".chr")); unlink(strjoin3(fnamebuf,Path_PRG,filename,".prg")); } } return TRUE; }
void PerfectForward(T && t){ RunCode(std::forward<T>(t)); }
TEST_F(AulTest, Eval) { EXPECT_EQ(C4VInt(42), RunExpr("eval(\"42\")")); EXPECT_EQ(C4VInt(42), RunCode("local i = 42; func Main() { return eval(\"this.i\"); }", false)); EXPECT_EQ(C4VInt(42), RunCode("local i; func Main() { eval(\"this.i = 42\"); return i; }", false)); }