// ==================================================================================================== // Main // ==================================================================================================== int main(int argc, const char* argv[]) { /* * Delete old updater */ if (file_exists("updater_old.exe")) { DeleteFile("updater_old.exe"); } // Download UpdateInfo.ini printf("Searching for updates..\n"); DownloadThreadInfo* pUpdateInfo = DownloadFile("http://hive-mind.eu/fastdl/data/freschi/UpdateInfo.ini", "UpdateInfo.ini"); while (!pUpdateInfo->bFinished) { Sleep(50); } // Read UpdateInfo.ini // Read: Latest Version Number std::string _s_latest_rev = CIniFile::GetValue("VersionNumber", "Latest", "UpdateInfo.ini"); int latest_rev; try { latest_rev = std::stoi(_s_latest_rev); } catch (...) { printf("Failed to parse UpdateInfo.ini\n"); getchar(); return 0; } std::string latest_rev_name = CIniFile::GetValue("VersionName", "Latest", "UpdateInfo.ini"); printf("Latest Version: %s (Revision Number: %i)\n", latest_rev_name.c_str(), latest_rev); // Current Version int client_rev; std::string client_rev_s; try { client_rev_s = CIniFile::GetValue("VersionName", "Current", "Updater.ini"); client_rev = std::stoi(CIniFile::GetValue("VersionNumber", "Current", "Updater.ini")); } catch (...) { // either update.ini is corrupt or doesnt exist client_rev_s = "[Unknown]"; client_rev = 0; } printf("Installed Version: %s (Revision Number: %i)\n", client_rev_s.c_str(), client_rev); printf("\n\n"); // Redownload everything? bool reinstall_all = false; if (client_rev >= latest_rev) { printf("Client is up-to-date!\n"); printf("Press enter if you wish to reinstall everything...\n"); std::getchar(); reinstall_all = true; } // Check if update is required bool bUpdatedUpdater = false; if (client_rev < latest_rev || reinstall_all) { // Update Required if (!file_exists("Updater.ini")) CIniFile::Create("Updater.ini"); ClearConsole(); // Collect file revisions char buf[48]; sprintf(buf, "Version_r%i", latest_rev); std::vector<CIniFile::Record> files = CIniFile::GetSection(std::string(buf), "UpdateInfo.ini"); for (std::vector<CIniFile::Record>::iterator it = files.begin(); it != files.end(); ++it) { CIniFile::Record rec = *it; // Create directory if (rec.Value == "directory") { CreateDirectory(rec.Key.c_str(), NULL); continue; } // Check File Revision // required and latest ClearConsole(); quick_header_1(latest_rev_name, latest_rev); printf("Checking File %s\n", rec.Key.c_str()); int revision_required = GetFileRevision(rec.Value); int revision_present = GetFileRevision(CIniFile::GetValue(rec.Key, "FileRevisions", "Updater.ini")); // Needs update? if (revision_required > revision_present || reinstall_all || !file_exists(rec.Key)) { char download_url[512]; sprintf(download_url, "http://hive-mind.eu/fastdl/data/freschi/r%i/%s", revision_required, rec.Key.c_str()); std::string saveas = rec.Key; // Utility so Updater can update itself if (saveas == "Updater.exe") { saveas = "updater_new.exe"; bUpdatedUpdater = true; } // Download File DownloadThreadInfo* pUpdateInfo = DownloadFile(std::string(download_url), saveas); while (!pUpdateInfo->bFinished) { ClearConsole(); quick_header_1(latest_rev_name, latest_rev); if (pUpdateInfo->size_total <= 1000) { printf("Downloading %s ...\n", rec.Key.c_str()); } else { printf("Downloading %s (%s/%s)\n\n", rec.Key.c_str(), readable_fs(pUpdateInfo->size_downloaded).c_str(), readable_fs(pUpdateInfo->size_total).c_str()); // Progress Bar printf(" [ "); int ab = 50; // anzahl der balken int pr_re = 100 / ab; // ein balken = pre_re % int pr = (int)pUpdateInfo->progress; for (int i = 0; i < ab; i++) { if (pr >= (i * pr_re)) { printf("="); } else { printf(" "); } } printf(" ] %i %% ", pr); } // short pause Sleep(75); } // Save new File Revision CIniFile::SetValue(rec.Key, rec.Value, "FileRevisions", "Updater.ini"); } } // Done! Change UpdateInfo.ini CIniFile::SetValue("VersionNumber", to_string(latest_rev), "Current", "Updater.ini"); CIniFile::SetValue("VersionName", latest_rev_name, "Current", "Updater.ini"); // Tell user ClearConsole(); printf("Client is up-to-date!\n"); printf("Press enter to quit..\n"); } // Updater-Update if (bUpdatedUpdater) { MoveFile("Updater.exe", "updater_old.exe"); MoveFile("updater_new.exe", "Updater.exe"); } // Done std::getchar(); return 0; }
void DoConsoleCommand() { // Get command text TCHAR command[32]; GetWindowText(m_hwndConsoleEdit, command, 32); SendMessage(m_hwndConsoleEdit, WM_SETTEXT, 0, (LPARAM) _T("")); // Clear command if (command[0] == 0) return; // Nothing to do // Echo command to the log TCHAR buffer[36]; ::GetWindowText(m_hwndConsolePrompt, buffer, 14); ConsoleView_Print(buffer); wsprintf(buffer, _T(" %s\r\n"), command); ConsoleView_Print(buffer); BOOL okUpdateAllViews = FALSE; // Flag - need to update all debug views CProcessor* pProc = ConsoleView_GetCurrentProcessor(); // Execute the command switch (command[0]) { case _T('h'): ConsoleView_ShowHelp(); break; case _T('c'): // Clear log ClearConsole(); break; case _T('r'): // Register operations if (command[1] == 0) // Print all registers { for (int r = 0; r < 8; r++) { LPCTSTR name = REGISTER_NAME[r]; WORD value = pProc->GetReg(r); PrintRegister(name, value); } PrintRegister(_T("PS"), pProc->GetPSW()); } else if (command[1] >= _T('0') && command[1] <= _T('7')) // "r0".."r7" { int r = command[1] - _T('0'); LPCTSTR name = REGISTER_NAME[r]; if (command[2] == 0) // "rN" - show register N { WORD value = pProc->GetReg(r); PrintRegister(name, value); } else if (command[2] == _T('=') || command[2] == _T(' ')) // "rN=XXXXXX" - set register N to value XXXXXX { WORD value; if (! ParseOctalValue(command + 3, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { pProc->SetReg(r, value); PrintRegister(name, value); okUpdateAllViews = TRUE; } } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); } else if (command[1] == _T('p') && command[2] == _T('s')) // "rps" { if (command[3] == 0) // "rps" - show PSW { WORD value = pProc->GetPSW(); PrintRegister(_T("PS"), value); } else if (command[3] == _T('=') || command[3] == _T(' ')) // "rps=XXXXXX" - set PSW to value XXXXXX { WORD value; if (! ParseOctalValue(command + 4, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { pProc->SetPSW(value); PrintRegister(_T("PS"), value); okUpdateAllViews = TRUE; } } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); break; case _T('s'): // Step if (command[1] == 0) // "s" - Step Into, execute one instruction { PrintDisassemble(pProc, pProc->GetPC(), TRUE, FALSE); //pProc->Execute(); g_pBoard->DebugTicks(); okUpdateAllViews = TRUE; } else if (command[1] == _T('o')) // "so" - Step Over { int instrLength = PrintDisassemble(pProc, pProc->GetPC(), TRUE, FALSE); WORD bpaddress = (WORD)(pProc->GetPC() + instrLength * 2); Emulator_SetCPUBreakpoint(bpaddress); Emulator_Start(); } break; case _T('d'): // Disassemble case _T('D'): // Disassemble, short format { BOOL okShort = (command[0] == _T('D')); if (command[1] == 0) // "d" - disassemble at current address PrintDisassemble(pProc, pProc->GetPC(), FALSE, okShort); else if (command[1] >= _T('0') && command[1] <= _T('7')) // "dXXXXXX" - disassemble at address XXXXXX { WORD value; if (! ParseOctalValue(command + 1, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { PrintDisassemble(pProc, value, FALSE, okShort); } } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); } break; case _T('u'): SaveMemoryDump(pProc); break; case _T('m'): if (command[1] == 0) // "m" - dump memory at current address { PrintMemoryDump(pProc, pProc->GetPC(), 8); } else if (command[1] >= _T('0') && command[1] <= _T('7')) // "mXXXXXX" - dump memory at address XXXXXX { WORD value; if (! ParseOctalValue(command + 1, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { PrintMemoryDump(pProc, value, 8); } } else if (command[1] == _T('r') && command[2] >= _T('0') && command[2] <= _T('7')) // "mrN" - dump memory at address from register N { int r = command[2] - _T('0'); WORD address = pProc->GetReg(r); PrintMemoryDump(pProc, address, 8); } else if (command[1] == _T('o')) { ConsoleView_GotoMonitor(); } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); break; //TODO: "mXXXXXX YYYYYY" - set memory cell at XXXXXX to value YYYYYY //TODO: "mrN YYYYYY" - set memory cell at address from rN to value YYYYYY case _T('g'): if (command[1] == 0) { Emulator_Start(); } else { WORD value; if (! ParseOctalValue(command + 1, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { Emulator_SetCPUBreakpoint(value); Emulator_Start(); } } break; #if !defined(PRODUCT) case _T('t'): { BOOL okTrace = !g_pBoard->GetTrace(); g_pBoard->SetTrace(okTrace); if (okTrace) ConsoleView_Print(_T(" Trace is ON.\r\n")); else { ConsoleView_Print(_T(" Trace is OFF.\r\n")); DebugLogCloseFile(); } } break; #endif default: ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); break; } PrintConsolePrompt(); if (okUpdateAllViews) { MainWindow_UpdateAllViews(); } }
int main() { char c = 'O'; char blank = ' '; int code0 = 0; int code1 = 0; int px = 0; int py = 0; int screenWidth = 0; int screenHeight = 0; GetWH(&screenWidth, &screenHeight); COORD position; position.X = px = screenWidth / 2; position.Y = py = screenHeight / 2; /* Output the char at initial position. */ SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position); std::cout << c; while(true) { code0 = (int)_getch(); /* Press ESC to quit. */ if(code0 == 27) { break; } code1 = (int)_getch(); switch(code1) { case KEY_UP: py = imax(0, py - 1); break; case KEY_LEFT: px = imax(0, px - 1); break; case KEY_RIGHT: px= imin(screenWidth, px + 1); break; case KEY_DOWN: py = imin(screenHeight, py + 1); break; default: break; } ClearConsole(); position.X = px; position.Y = py; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position); /* Output the char at the new position. */ std::cout << c; } return 0; }