void Log::Print(LogLevel type, LogColor color, char identifier, const char* svc, const char* msg) { if (enabled == false) { return; } if ((type & logLevel) == 0) { return; } while (queue > 0)Sleep(1); queue++; char time[9]; _strtime(time); SetConsoleTextColor(LogColor_DarkGrey); printf("%s", time); fprintf(fileStream, "%s", time); SetConsoleTextColor(color); printf(" %c ", identifier); fprintf(fileStream, " %c ", identifier); SetConsoleTextColor(LogColor_White); printf("%s: ", svc); fprintf(fileStream, "%s: ", svc); SetConsoleTextColor(color); printf("%s\r\n", msg); fprintf(fileStream, "%s\r\n", msg); fflush(fileStream); queue--; }
int Computer::interpreter(bool debug) { Debug d(&memory, ®isters); int STATE = 1; uByte nByte = 0; while (STATE) { Clear(); COORD coord; coord.X = 0; coord.Y = 0; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); // читаем слово for (int i = 0; i < sizeof(Word); ++i) RC.rc[i] = memory.b[registers.PSW.IP * 4 + i]; if (registers.PSW.TF) Trace(); Operations code = static_cast<Operations>(RC.Code); d.printIP(); d.printFlugs(); cout << endl; d.printMemoryByte(); if (instructions.find(code) != instructions.end()) { STATE = (*instructions[code])(); if (STATE != 2) ++registers.PSW.IP; // изменение IP } else { SetConsoleTextColor(15, 12); cerr << "IP: " << registers.PSW.IP << " [ ERORR: Unknown command code: 0x" << code << " ]"<< endl; STATE = 0; SetConsoleTextColor(7, 0); } } return 0; }
SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) { // Hopefully two threads won't call this simultaneously right at the start! if ( !g_bSpewCSInitted ) { InitializeCriticalSection( &g_SpewCS ); g_bSpewCSInitted = true; } WORD old; SpewRetval_t retVal; EnterCriticalSection( &g_SpewCS ); { if (( type == SPEW_MESSAGE ) || (type == SPEW_LOG )) { old = SetConsoleTextColor( 1, 1, 1, 0 ); retVal = SPEW_CONTINUE; } else if( type == SPEW_WARNING ) { old = SetConsoleTextColor( 1, 1, 0, 1 ); retVal = SPEW_CONTINUE; } else if( type == SPEW_ASSERT ) { old = SetConsoleTextColor( 1, 0, 0, 1 ); retVal = SPEW_DEBUGGER; #ifdef MPI // VMPI workers don't want to bring up dialogs and suchlike. if ( g_bUseMPI && !g_bMPIMaster ) { VMPI_HandleCrash( pMsg, true ); exit( 0 ); } #endif } else if( type == SPEW_ERROR ) { old = SetConsoleTextColor( 1, 0, 0, 1 ); retVal = SPEW_ABORT; // doesn't matter.. we exit below so we can return an errorlevel (which dbg.dll doesn't do). } else { old = SetConsoleTextColor( 1, 1, 1, 1 ); retVal = SPEW_CONTINUE; } if ( !g_bSuppressPrintfOutput || type == SPEW_ERROR ) printf( "%s", pMsg ); OutputDebugString( pMsg ); if ( type == SPEW_ERROR ) { printf( "\n" ); OutputDebugString( "\n" ); } if( g_pLogFile ) { CmdLib_FPrintf( g_pLogFile, "%s", pMsg ); g_pFileSystem->Flush( g_pLogFile ); } // Dispatch to other spew hooks. FOR_EACH_LL( g_ExtraSpewHooks, i ) g_ExtraSpewHooks[i]( pMsg ); RestoreConsoleTextColor( old ); } LeaveCriticalSection( &g_SpewCS ); if ( type == SPEW_ERROR ) { CmdLib_Exit( 1 ); } return retVal; }
SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) { // Hopefully two threads won't call this simultaneously right at the start! if ( !g_bSpewCSInitted ) { InitializeCriticalSection( &g_SpewCS ); g_bSpewCSInitted = true; } WORD old; SpewRetval_t retVal; EnterCriticalSection( &g_SpewCS ); { if (( type == SPEW_MESSAGE ) || (type == SPEW_LOG )) { Color c = GetSpewOutputColor(); if ( c.r() != 255 || c.g() != 255 || c.b() != 255 ) { // custom color old = SetConsoleTextColor( c.r(), c.g(), c.b(), c.a() ); } else { old = SetConsoleTextColor( 1, 1, 1, 0 ); } retVal = SPEW_CONTINUE; } else if( type == SPEW_WARNING ) { old = SetConsoleTextColor( 1, 1, 0, 1 ); retVal = SPEW_CONTINUE; } else if( type == SPEW_ASSERT ) { old = SetConsoleTextColor( 1, 0, 0, 1 ); retVal = SPEW_DEBUGGER; #ifdef MPI // VMPI workers don't want to bring up dialogs and suchlike. // They need to have a special function installed to handle // the exceptions and write the minidumps. // Install the function after VMPI_Init with a call: // SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); if ( g_bUseMPI && !g_bMPIMaster && !Plat_IsInDebugSession() ) { // Generating an exception and letting the // installed handler handle it ::RaiseException ( 0, // dwExceptionCode EXCEPTION_NONCONTINUABLE, // dwExceptionFlags 0, // nNumberOfArguments, NULL // const ULONG_PTR* lpArguments ); // Never get here (non-continuable exception) VMPI_HandleCrash( pMsg, NULL, true ); exit( 0 ); } #endif } else if( type == SPEW_ERROR ) { old = SetConsoleTextColor( 1, 0, 0, 1 ); retVal = SPEW_ABORT; // doesn't matter.. we exit below so we can return an errorlevel (which dbg.dll doesn't do). } else { old = SetConsoleTextColor( 1, 1, 1, 1 ); retVal = SPEW_CONTINUE; } if ( !g_bSuppressPrintfOutput || type == SPEW_ERROR ) printf( "%s", pMsg ); OutputDebugString( pMsg ); if ( type == SPEW_ERROR ) { printf( "\n" ); OutputDebugString( "\n" ); } if( g_pLogFile ) { CmdLib_FPrintf( g_pLogFile, "%s", pMsg ); g_pFileSystem->Flush( g_pLogFile ); } // Dispatch to other spew hooks. FOR_EACH_LL( g_ExtraSpewHooks, i ) g_ExtraSpewHooks[i]( pMsg ); RestoreConsoleTextColor( old ); } LeaveCriticalSection( &g_SpewCS ); if ( type == SPEW_ERROR ) { CmdLib_Exit( 1 ); } return retVal; }
int main() { // Variables Initialization: p_player.teleport = false; p_player.p_size = 4; p_player.a_state_size = p_player.p_size; srand(time(NULL)); MapCreation(m_map); SetEnterTeleport(§or); SetExitTeleport(); // Game Loop: while(!over){ tl_start = GetTickCount(); // Updates: HandleKeyboard(); //Wall in face? if(m_map[p_player.x-1][p_player.y] == '|') over = true; //Teleporter in face? if(m_map[p_player.x-1][p_player.y] == 'O'){ m_map[t_enter.x][t_enter.y] = '|'; p_player.teleport = true; p_player.old_x = p_player.x; p_player.old_y = p_player.y; switch(sector){ case 1: points += 20; break; case 2: points += 5; break; case 3: points += 10; break; } //Display points: SetCursorPosition(25,16); printf("Pts:["); SetConsoleTextColor(2); printf("%d", points); SetConsoleTextColor(7); printf("]"); SetEnterTeleport(§or); } //Teleport? if(p_player.teleport){ if(p_player.a_state_size != 0){ m_map[p_player.old_x + p_player.a_state_size - 1][p_player.old_y] = '-'; p_player.a_state_size--; } if(p_player.a_state_size == 0){ p_player.teleport = false; p_player.a_state_size = p_player.p_size; m_map[t_exit.x][t_exit.y] = '|'; SetExitTeleport(); } } //Display: for(j = 0; j < mapYsize; j++){ for(i = 0; i < mapXsize; i++){ if(map_buffer[i][j] != m_map[i][j]){ SetCursorPosition(i, j); if(m_map[i][j] == 'O'){ SetConsoleTextColor(9); }else if(m_map[i][j] == 167){ SetConsoleTextColor(11); } printf("%c", m_map[i][j]); SetConsoleTextColor(7); } } } //FPS Timer: tl_end = GetTickCount(); tl_elapsed = ( tl_end - tl_start ); //If we need we stop a moment the Fps: if(tl_elapsed < fps) Sleep(fps - tl_elapsed); MapBuffering(map_buffer, m_map); } system("cls"); printf("Game over: You got %d pts\n", points); system("pause"); return 0; }