void ShowHelp(void) { #define ID_HELP_TEXT 10020 #define ID_DOS_TEXT 300 CONST CHAR* src; DWORD src_count, charsWritten; HGLOBAL res_data; HANDLE handle; HRSRC hSrc; ShowCopyright(); hSrc = FindResourceA(NULL, MAKEINTRESOURCEA(ID_HELP_TEXT),MAKEINTRESOURCEA(ID_DOS_TEXT)); if (!hSrc) return; src_count = SizeofResource(NULL, hSrc); res_data = LoadResource(NULL, hSrc); if (!res_data) return; src = (char*) LockResource(res_data); if (!src) return; if ((handle=GetStdHandle(STD_ERROR_HANDLE)) != INVALID_HANDLE_VALUE) WriteConsoleA(handle, src, src_count, &charsWritten, NULL); }
void main(int argc, char *argv[]) { int n; memset(startdir,0,sizeof(startdir)); memset(cfgfilename,0,sizeof(cfgfilename)); ArgInit(argc, argv); VideoInit(); ShowCopyright(argc, argv); // CheckIfLocked(); ShowSysInfo(); ShowEnvInfo(); ShowMainMenu(); ShowMemory(); // CheckVersion(); ValidateConfig(); l1: ShowMemory(); SelectMainMenu(); l2: switch(mainmenu_sel) { case 0: ShowKernelMenu(); if(keycode==F2) { ShowMemory(); mainmenu_sel=1; goto l2; } else break; case 1: ShowExtenderMenu(); if(keycode==F1) { ShowMemory(); mainmenu_sel=0; goto l2; } else break; case 2: CreateConfig(); break; case 3: RestoreConfig();break; case 4: id32=id32_old; ClearConfigName(); break; case 5: DiscardExit(); break; case 6: ApplyExit(); break; } goto l1; }
int main(int argc, char** argv) { struct BENCHMARK_TEST_PARAM Test; struct BENCHMARK_TRANSFER_PARAM* ReadTest = NULL; struct BENCHMARK_TRANSFER_PARAM* WriteTest = NULL; int key; if (argc == 1) { ShowHelp(); return -1; } ShowCopyright(); // NOTE: This is the log level for the benchmark application. // #if defined __ERROR_H__ usb_log_set_level(255); #endif SetTestDefaults(&Test); // Load the command line arguments. if (ParseBenchmarkArgs(&Test, argc, argv) < 0) return -1; // Initialize the critical section used for locking // the volatile members of the transfer params in order // to update/modify the running statistics. // InitializeCriticalSection(&DisplayCriticalSection); // Initialize the library. usb_init(); // Find all busses. usb_find_busses(); // Find all connected devices. usb_find_devices(); if (Test.UseList) { if (GetTestDeviceFromList(&Test) < 0) goto Done; } else { // Open a benchmark device. see Bench_Open(). Test.DeviceHandle = Bench_Open(Test.Vid, Test.Pid, Test.Intf, Test.Altf, &Test.Device); } if (!Test.DeviceHandle || !Test.Device) { CONERR("device %04X:%04X not found!\n",Test.Vid, Test.Pid); goto Done; } // If "NoTestSelect" appears in the command line then don't send the control // messages for selecting the test type. // if (!Test.NoTestSelect) { if (Bench_SetTestType(Test.DeviceHandle, Test.TestType, Test.Intf) != 1) { CONERR("setting bechmark test type #%d!\n%s\n", Test.TestType, usb_strerror()); goto Done; } } CONMSG("Benchmark device %04X:%04X opened..\n",Test.Vid, Test.Pid); // If reading from the device create the read transfer param. This will also create // a thread in a suspended state. // if (Test.TestType & TestTypeRead) { ReadTest = CreateTransferParam(&Test, Test.Ep | USB_ENDPOINT_DIR_MASK); if (!ReadTest) goto Done; } // If writing to the device create the write transfer param. This will also create // a thread in a suspended state. // if (Test.TestType & TestTypeWrite) { WriteTest = CreateTransferParam(&Test, Test.Ep); if (!WriteTest) goto Done; } // Set configuration #1. if (usb_set_configuration(Test.DeviceHandle, 1) < 0) { CONERR("setting configuration #%d!\n%s\n",1,usb_strerror()); goto Done; } // Claim_interface Test.Intf (Default is #0) if (usb_claim_interface(Test.DeviceHandle, Test.Intf) < 0) { CONERR("claiming interface #%d!\n%s\n", Test.Intf, usb_strerror()); goto Done; } // Set the alternate setting (Default is #0) if (usb_set_altinterface(Test.DeviceHandle, Test.Altf) < 0) { CONERR("selecting alternate setting #%d on interface #%d!\n%s\n", Test.Altf, Test.Intf, usb_strerror()); goto Done; } else { if (Test.Altf > 0) { CONDBG("selected alternate setting #%d on interface #%d\n",Test.Altf, Test.Intf); } } if (Test.Verify) { if (ReadTest && WriteTest) { if (CreateVerifyBuffer(&Test, WriteTest->Ep.wMaxPacketSize) < 0) goto Done; } else if (ReadTest) { if (CreateVerifyBuffer(&Test, ReadTest->Ep.wMaxPacketSize) < 0) goto Done; } } ShowTestInfo(&Test); ShowTransferInfo(ReadTest); ShowTransferInfo(WriteTest); CONMSG0("\nWhile the test is running:\n"); CONMSG0("Press 'Q' to quit\n"); CONMSG0("Press 'T' for test details\n"); CONMSG0("Press 'I' for status information\n"); CONMSG0("Press 'R' to reset averages\n"); CONMSG0("\nPress 'Q' to exit, any other key to begin.."); key = _getch(); CONMSG0("\n"); if (key=='Q' || key=='q') goto Done; // Set the thread priority and start it. if (ReadTest) { SetThreadPriority(ReadTest->ThreadHandle, Test.Priority); ResumeThread(ReadTest->ThreadHandle); } // Set the thread priority and start it. if (WriteTest) { SetThreadPriority(WriteTest->ThreadHandle, Test.Priority); ResumeThread(WriteTest->ThreadHandle); } while (!Test.IsCancelled) { Sleep(Test.Refresh); if (_kbhit()) { // A key was pressed. key = _getch(); switch (key) { case 'Q': case 'q': Test.IsUserAborted = TRUE; Test.IsCancelled = TRUE; break; case 'T': case 't': ShowTestInfo(&Test); break; case 'I': case 'i': // LOCK the display critical section EnterCriticalSection(&DisplayCriticalSection); // Print benchmark test details. ShowTransferInfo(ReadTest); ShowTransferInfo(WriteTest); // UNLOCK the display critical section LeaveCriticalSection(&DisplayCriticalSection); break; case 'R': case 'r': // LOCK the display critical section EnterCriticalSection(&DisplayCriticalSection); // Reset the running status. ResetRunningStatus(ReadTest); ResetRunningStatus(WriteTest); // UNLOCK the display critical section LeaveCriticalSection(&DisplayCriticalSection); break; } // Only one key at a time. while (_kbhit()) _getch(); } // If the read test should be running and it isn't, cancel the test. if ((ReadTest) && !ReadTest->IsRunning) { Test.IsCancelled = TRUE; break; } // If the write test should be running and it isn't, cancel the test. if ((WriteTest) && !WriteTest->IsRunning) { Test.IsCancelled = TRUE; break; } // Print benchmark stats if (ReadTest) ShowRunningStatus(ReadTest); else ShowRunningStatus(WriteTest); } // Wait for the transfer threads to complete gracefully if it // can be done in 10ms. All of the code from this point to // WaitForTestTransfer() is not required. It is here only to // improve response time when the test is cancelled. // Sleep(10); // If the thread is still running, abort and reset the endpoint. if ((ReadTest) && ReadTest->IsRunning) usb_resetep(Test.DeviceHandle, ReadTest->Ep.bEndpointAddress); // If the thread is still running, abort and reset the endpoint. if ((WriteTest) && WriteTest->IsRunning) usb_resetep(Test.DeviceHandle, WriteTest->Ep.bEndpointAddress); // Small delay incase usb_resetep() was called. Sleep(10); // WaitForTestTransfer will not return until the thread // has exited. WaitForTestTransfer(ReadTest); WaitForTestTransfer(WriteTest); // Print benchmark detailed stats ShowTestInfo(&Test); if (ReadTest) ShowTransferInfo(ReadTest); if (WriteTest) ShowTransferInfo(WriteTest); Done: if (Test.DeviceHandle) { usb_close(Test.DeviceHandle); Test.DeviceHandle = NULL; } if (Test.VerifyBuffer) { free(Test.VerifyBuffer); Test.VerifyBuffer = NULL; } FreeTransferParam(&ReadTest); FreeTransferParam(&WriteTest); DeleteCriticalSection(&DisplayCriticalSection); CONMSG0("Press any key to exit.."); _getch(); CONMSG0("\n"); return 0; }
void ArgInit(int argc, char *argv[]) { int n,m; int argn=18; char *args[] = { "bs", "bc", "b", "u", "q", "s", "da", "de", "dr", "ds", "d", "vx", "v2", "v1", "v0", "v", "h", "?" }; execargn=1; if(argc>=2) { for(n=1; n<argc; n++) { if(*argv[n]=='-' || *argv[n]=='/') { for(m=0; m<argn; m++) { if(stricmp(argv[n]+1, args[m])==0) switch(m) { case 0: execargn++; // -BS bindtype=1; goto l0; case 1: execargn++; // -BC bindtype=2; goto l0; case 2: execargn++; // -B bindtype=0; goto l0; case 3: execargn++; // -U bind=FALSE; goto l0; case 4: execargn++; // -Q quiet=TRUE; silent=FALSE; goto l0; case 5: execargn++; // -S quiet=TRUE; silent=TRUE; goto l0; case 6: execargn++; // -DA advanced=FALSE; goto l0; case 7: execargn++; // -DE encode=FALSE; goto l0; case 8: execargn++; // -DR strip=FALSE; goto l0; case 9: execargn++; // -DS smart=FALSE; goto l0; case 10: execargn++; // -D smart=FALSE; strip=FALSE; encode=FALSE; advanced=FALSE; goto l0; case 11: // -VX & -V2 case 12: execargn++; verbose=TRUE; verbxtra=TRUE; goto l0; case 13: execargn++; // -V1 verbose=TRUE; verbxtra=TRUE; nocount=TRUE; goto l0; case 14: execargn++; // -V0 verbose=TRUE; nocount=TRUE; goto l0; case 15: execargn++; // -V verbose=TRUE; goto l0; case 16: case 17: ShowCopyright(); goto l1; } } ShowCopyright(); err_arg(argv[n]); } l0: argn=18; } } ShowCopyright(); if(argc<2 || execargn>=argc) { l1: Print("SC/32A fatal: syntax is SC [commands] [options] <execname.xxx>\n\n"); Print("Commands:\n"); Print("---------\n"); Print("/B Bind DOS/32A to produced LC Executable\n"); Print("/BS Bind STUB/32A to produced LC Executable\n"); Print("/BC Bind STUB/32C to produced LC Executable\n"); Print("/U Produce Unbound Linear Compressed Executable\n\n"); Print("Options:\n"); Print("--------\n"); Print("/D Turn off all optimization features\n"); Print("/DA Disable Advanced preprocessing of Executable\n"); Print("/DE Disable Encoding of LC Executable (no compression)\n"); Print("/DR Disable Removing of post-zero areas from Executable\n"); Print("/DS Disable Smart Encoding when compressing Executable\n"); Print("/V[0|1|2] Verbose mode (displays additional information)\n"); Print("/Q Quiet mode (partially disables console output)\n"); Print("/S Silent mode (totally disables console output)\n"); Print("/H or /? This help\n"); exit(0); } }