int main(int argc, char **argv) { Machine *machine = initMachine(512, testCodes, sizeof(testCodes) / sizeof(int), 2); if (machine != NULL) { runMachine(machine); printf("\nResult: %d\n", machine->result); destroyMachine(machine); return 0; } else { return 1; } }
Common::Error HugoEngine::run() { s_Engine = this; initGraphics(320, 200, false); _mouse = new MouseHandler(this); _inventory = new InventoryHandler(this); _route = new Route(this); _sound = new SoundHandler(this); // Setup mixer syncSoundSettings(); _text = new TextHandler(this); _topMenu = new TopMenu(this); switch (_gameVariant) { case kGameVariantH1Win: // H1 Win _file = new FileManager_v1w(this); _scheduler = new Scheduler_v1w(this); _intro = new intro_v1w(this); _screen = new Screen_v1w(this); _parser = new Parser_v1w(this); _object = new ObjectHandler_v1w(this); _normalTPS = 9; break; case kGameVariantH2Win: _file = new FileManager_v2w(this); _scheduler = new Scheduler_v1w(this); _intro = new intro_v2w(this); _screen = new Screen_v1w(this); _parser = new Parser_v1w(this); _object = new ObjectHandler_v1w(this); _normalTPS = 9; break; case kGameVariantH3Win: _file = new FileManager_v2w(this); _scheduler = new Scheduler_v1w(this); _intro = new intro_v3w(this); _screen = new Screen_v1w(this); _parser = new Parser_v1w(this); _object = new ObjectHandler_v1w(this); _normalTPS = 9; break; case kGameVariantH1Dos: // H1 DOS _file = new FileManager_v1d(this); _scheduler = new Scheduler_v1d(this); _intro = new intro_v1d(this); _screen = new Screen_v1d(this); _parser = new Parser_v1d(this); _object = new ObjectHandler_v1d(this); _normalTPS = 8; break; case kGameVariantH2Dos: _file = new FileManager_v2d(this); _scheduler = new Scheduler_v2d(this); _intro = new intro_v2d(this); _screen = new Screen_v1d(this); _parser = new Parser_v2d(this); _object = new ObjectHandler_v2d(this); _normalTPS = 8; break; case kGameVariantH3Dos: _file = new FileManager_v3d(this); _scheduler = new Scheduler_v3d(this); _intro = new intro_v3d(this); _screen = new Screen_v1d(this); _parser = new Parser_v3d(this); _object = new ObjectHandler_v3d(this); _normalTPS = 9; break; } if (!loadHugoDat()) return Common::kUnknownError; // Use Windows-looking mouse cursor _screen->setCursorPal(); _screen->resetInventoryObjId(); _scheduler->initCypher(); initStatus(); // Initialize game status initConfig(); // Initialize user's config if (!_status._doQuitFl) { initialize(); resetConfig(); // Reset user's config initMachine(); // Start the state machine _status._viewState = kViewIntroInit; int16 loadSlot = Common::ConfigManager::instance().getInt("save_slot"); if (loadSlot >= 0) { _status._skipIntroFl = true; _file->restoreGame(loadSlot); } else { _file->saveGame(0, "New Game"); } } while (!_status._doQuitFl) { _screen->drawBoundaries(); g_system->updateScreen(); runMachine(); // Handle input Common::Event event; while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: _parser->keyHandler(event); break; case Common::EVENT_MOUSEMOVE: _mouse->setMouseX(event.mouse.x); _mouse->setMouseY(event.mouse.y); break; case Common::EVENT_LBUTTONUP: _mouse->setLeftButton(); break; case Common::EVENT_RBUTTONUP: _mouse->setRightButton(); break; case Common::EVENT_QUIT: _status._doQuitFl = true; break; default: break; } } if (_status._helpFl) { _status._helpFl = false; _file->instructions(); } _mouse->mouseHandler(); // Mouse activity - adds to display list _screen->displayList(kDisplayDisplay); // Blit the display list to screen _status._doQuitFl |= shouldQuit(); // update game quit flag } return Common::kNoError; }
int main (int argc, const char * argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s <binary>\n", argv[0]); return USAGE; } FILE *f = fopen(argv[1], "rb"); if (f == NULL) { fprintf(stderr, "Could not open file: %s\n", argv[1]); return FILEIO; } // Get length of file fseek(f, 0, SEEK_END); long int len = ftell(f); fseek(f, 0, SEEK_SET); // Allocate buffer for file unsigned char *bin = (unsigned char*)malloc(len * sizeof(*bin)); // Read file into buffer fread(bin, 1, len, f); fclose(f); state st = runMachine(bin, (uint32_t)len); free(bin); switch (st) { case HALT: #ifdef DEBUG fprintf(stderr, "\n---\nProgram halted normally.\n"); #endif return NORMAL; case FAIL: #ifdef DEBUG fprintf(stderr, "\n---\nProgram entered a failure mode and has been halted.\n"); #endif return FAILURE; case MEM: #ifdef DEBUG fprintf(stderr, "\n---\nProgram exceeded memory usage.\n"); #endif return MEMORY; case INTERN: #ifdef DEBUG fprintf(stderr, "\n---\nInternal error encountered.\n"); #endif return INTERNAL; // Prevent compiler warning case RUN: break; } #ifdef DEBUG fprintf(stderr, "\n---\nInternal error encountered: impossible exit code returned: %d\n", st); #endif return INTERNAL; }