void CagerInstance::Update(){ clock_t iT=clock(); clock_t iDiff=iT-m_iLastUpdate; if(iDiff>(CLOCKS_PER_SEC/30.3f)){ std::list<Player*>::iterator it; for(it=m_xPlayers.begin();it!=m_xPlayers.end();++it){ Player *pxPlayer=(*it); pxPlayer->Update(iDiff); if(pxPlayer->ShouldShutdown()){ it=m_xPlayers.erase(it); m_pxChat->Leave(pxPlayer); pxPlayer->PreDisconnect(); delete pxPlayer; if(it==m_xPlayers.end()){ break; } }else if(pxPlayer->NeedFullSnapshot()){ Snapshot(pxPlayer,true); } } m_iLastUpdate=iT; } iT=clock(); iDiff=iT-m_iLastSnapshot; if(iDiff>(CLOCKS_PER_SEC/10.0f)){ Snapshot(); m_iLastSnapshot=iT; } }
void Solver<Dtype>::Solve(const char* resume_file) { Caffe::set_mode(Caffe::Brew(param_.solver_mode())); if (param_.solver_mode() && param_.has_device_id()) { Caffe::SetDevice(param_.device_id()); } Caffe::set_phase(Caffe::TRAIN); LOG(INFO) << "Solving " << net_->name(); PreSolve(); iter_ = 0; if (resume_file) { LOG(INFO) << "Restoring previous solver status from " << resume_file; Restore(resume_file); } // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. vector<Blob<Dtype>*> bottom_vec; while (iter_++ < param_.max_iter()) { Dtype loss = net_->ForwardBackward(bottom_vec); ComputeUpdateValue(); net_->Update(); // Notify the info monitors by its interval for (int i = 0; i < info_.size(); ++i) { info_[i].get()->Iter(loss, iter_); } // Display // if (param_.display() && iter_ % param_.display() == 0) { // Handle the loss printing to info monitor installed. // LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss; //} if (param_.test_interval() && iter_ % param_.test_interval() == 0) { // We need to set phase to test before running. Caffe::set_phase(Caffe::TEST); Test(); Caffe::set_phase(Caffe::TRAIN); } // Check if we need to do snapshot if (param_.snapshot() && iter_ % param_.snapshot() == 0) { Snapshot(); } } // After the optimization is done, always do a snapshot. iter_--; Snapshot(); LOG(INFO) << "Optimization Done."; }
void FeedbackSolver<Dtype>::Solve(const char* resume_file) { Caffe::set_mode(Caffe::Brew(param_.solver_mode())); if (param_.solver_mode() == SolverParameter_SolverMode_GPU && param_.has_device_id()) { Caffe::SetDevice(param_.device_id()); } Caffe::set_phase(Caffe::TRAIN); LOG(INFO) << "Solving " << net_->name(); PreSolve(); iter_ = 0; resume_file = NULL; if (resume_file ) { LOG(INFO) << "Restoring previous solver status from " << resume_file; Restore(resume_file); } // Run a test pass before doing any training to avoid waiting a potentially // very long time (param_.test_interval() training iterations) to report that // there's not enough memory to run the test net and crash, etc.; and to gauge // the effect of the first training iterations. if (param_.test_interval()) { Test(); } // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. vector<Blob<Dtype>*> bottom_vec; while (iter_++ < param_.max_iter()) { Dtype loss = net_->FeedbackForwardBackward(bottom_vec, param_.top_k()); ComputeUpdateValue(); net_->Update(); if (param_.display() && iter_ % param_.display() == 0) { LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss; } if (param_.test_interval() && iter_ % param_.test_interval() == 0) { Test(); } // Check if we need to do snapshot if (param_.snapshot() && iter_ % param_.snapshot() == 0) { Snapshot(); } } // After the optimization is done, always do a snapshot. iter_--; Snapshot(); LOG(INFO) << "Optimization Done."; }
FenceTime::Snapshot FenceTime::getSnapshot() const { // Quick check without the lock. nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed); if (signalTime != Fence::SIGNAL_TIME_PENDING) { return Snapshot(signalTime); } // Do the full check with the lock. std::lock_guard<std::mutex> lock(mMutex); signalTime = mSignalTime.load(std::memory_order_relaxed); if (signalTime != Fence::SIGNAL_TIME_PENDING) { return Snapshot(signalTime); } return Snapshot(mFence); }
void Solver<Dtype>::Solve(const char* resume_file) { LOG(INFO) << "Solving " << net_->name(); LOG(INFO) << "Learning Rate Policy: " << param_.lr_policy(); if (resume_file) { LOG(INFO) << "Restoring previous solver status from " << resume_file; Restore(resume_file); } // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. Step(param_.max_iter() - iter_); // If we haven't already, save a snapshot after optimization, unless // overridden by setting snapshot_after_train := false if (param_.snapshot_after_train() && (!param_.snapshot() || iter_ % param_.snapshot() != 0)) { Snapshot(); } // After the optimization is done, run an additional train and test pass to // display the train and test loss/outputs if appropriate (based on the // display and test_interval settings, respectively). Unlike in the rest of // training, for the train net we only run a forward pass as we've already // updated the parameters "max_iter" times -- this final pass is only done to // display the loss, which is computed in the forward pass. if (param_.display() && iter_ % param_.display() == 0) { Dtype loss; net_->ForwardPrefilled(&loss); LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss; } if (param_.test_interval() && iter_ % param_.test_interval() == 0) { TestAll(); } LOG(INFO) << "Optimization Done."; }
void MMSBModel::Solve(const char* resume_file) { LOG(INFO) << "Solving MMSB"; iter_ = 0; //if (resume_file) { // LOG(INFO) << "Restoring previous model status from " << resume_file; // Restore(resume_file); // LOG(INFO) << "Restoration done."; //} else { InitModelState(); //} const int start_iter = iter_; start_time_ = std::clock(); for (; iter_ < param_.solver_param().max_iter(); ++iter_) { /// Save a snapshot if needed. //if (param_.solver_param().snapshot() && iter_ > start_iter && // iter_ % param_.solver_param().snapshot() == 0) { // Snapshot(); // SnapshotVis(); //} /// Test if needed //if (param_.solver_param().test_interval() // && iter_ % param_.solver_param().test_interval() == 0 // && (iter_ > 0 || param_.solver_param().test_initialization())) { // //clock_t start_test = std::clock(); // Test(); // //LOG(INFO) << "test time " << (std::clock() - start_test) / (float)CLOCKS_PER_SEC; //} /// Sample mini-batch //clock_t start_data = std::clock(); SampleMinibatch(train_batch_vertices_, train_batch_links_, train_batch_size_); //LOG(INFO) << "data time " << (std::clock() - start_data) / (float)CLOCKS_PER_SEC; /// local step //clock_t start_sample = std::clock(); if (param_.solver_param().sampler_type() == mmsb::SamplerType::MHSampler) { MHSample(); // O(1) sampler } else { GibbsSample(); // O(K) sampler } //LOG(INFO) << "sample time " << (std::clock() - start_sample) / (float)CLOCKS_PER_SEC; /// global step //clock_t start_vi = std::clock(); VIComputeGrads(); VIUpdate(); //LOG(INFO) << "vi time " << (std::clock() - start_vi) / (float)CLOCKS_PER_SEC; } if (param_.solver_param().snapshot_after_train()) { Snapshot(); } if (param_.solver_param().test_interval() && iter_ % param_.solver_param().test_interval() == 0) { Test(); } }
bool Solver::Solve(const char* resume_file) { LOG(INFO) << "Solving " << net_->name(); LOG(INFO) << "Learning Rate Policy: " << param_.lr_policy(); // Initialize to false every time we start solving. requested_early_exit_ = false; if (resume_file != nullptr) { LOG(INFO) << "Restoring previous solver status from " << resume_file; Restore(resume_file); } callback_soft_barrier(); if (Caffe::restored_iter() != -1) { iter_ = Caffe::restored_iter(); iterations_restored_ = iter_; // for correct benchmarking iterations_last_ = -1; } // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. int start_iter = iter_; Step(param_.max_iter() - iter_); // If we haven't already, save a snapshot after optimization, unless // overridden by setting snapshot_after_train := false if (param_.snapshot_after_train() && (!param_.snapshot() || iter_ % param_.snapshot() != 0)) { if (Caffe::root_solver()) { Snapshot(); } } Caffe::set_restored_iter(-1); iterations_restored_ = 0; iterations_last_ = 0; if (requested_early_exit_) { LOG(INFO) << "Optimization stopped early."; return true; } // After the optimization is done, run an additional train and test pass to // display the train and test loss/outputs if appropriate (based on the // display and test_interval settings, respectively). Unlike in the rest of // training, for the train net we only run a forward pass as we've already // updated the parameters "max_iter" times -- this final pass is only done to // display the loss, which is computed in the forward pass. if (this->display()) { int average_loss = this->param_.average_loss(); float loss; net_->Forward(&loss); UpdateSmoothedLoss(loss, start_iter, average_loss); LOG_IF(INFO, Caffe::root_solver()) << "Iteration " << iter_ << ", loss = " << smoothed_loss_; } if (param_.test_interval() && iter_ % param_.test_interval() == 0) { bool use_multi_gpu_testing = Caffe::solver_count() > 1; TestAll(0, use_multi_gpu_testing); callback_soft_barrier(); } return false; }
void Solver<Dtype>::Step(int iters) { vector<Blob<Dtype>*> bottom_vec; const int start_iter = iter_; const int stop_iter = iter_ + iters; int average_loss = this->param_.average_loss(); vector<Dtype> losses; Dtype smoothed_loss = 0; for (; iter_ < stop_iter; ++iter_) { Messenger::SendMessage("SOLVER_ITER_CHANGED", &iter_); if (param_.test_interval() && iter_ % param_.test_interval() == 0 && (iter_ > 0 || param_.test_initialization())) { TestAll(); } const bool display = param_.display() && iter_ % param_.display() == 0; net_->set_debug_info(display && param_.debug_info()); Dtype loss = net_->ForwardBackward(bottom_vec); if (losses.size() < average_loss) { losses.push_back(loss); int size = losses.size(); smoothed_loss = (smoothed_loss * (size - 1) + loss) / size; } else { int idx = (iter_ - start_iter) % average_loss; smoothed_loss += (loss - losses[idx]) / average_loss; losses[idx] = loss; } if (display) { LOG(INFO) << "Iteration " << iter_ << ", loss = " << smoothed_loss; const vector<Blob<Dtype>*>& result = net_->output_blobs(); int score_index = 0; for (int j = 0; j < result.size(); ++j) { const Dtype* result_vec = result[j]->cpu_data(); const string& output_name = net_->blob_names()[net_->output_blob_indices()[j]]; const Dtype loss_weight = net_->blob_loss_weights()[net_->output_blob_indices()[j]]; for (int k = 0; k < result[j]->count(); ++k) { ostringstream loss_msg_stream; if (loss_weight) { loss_msg_stream << " (* " << loss_weight << " = " << loss_weight * result_vec[k] << " loss)"; } LOG(INFO) << " Train net output #" << score_index++ << ": " << output_name << " = " << result_vec[k] << loss_msg_stream.str(); } } } ComputeUpdateValue(); net_->Update(); // Save a snapshot if needed. if (param_.snapshot() && (iter_ + 1) % param_.snapshot() == 0) { Snapshot(); } } }
IndexMetaInfo::Snapshot & IndexMetaInfo::getCreateSnapshot(uint32_t idx) { while (idx >= _snapshots.size()) { _snapshots.push_back(Snapshot()); } return _snapshots[idx]; }
TEST(GetSecondLast, NonEmpty) { History history; std::vector<CorrelationAircraft> aircraft; time_t timestamp; Snapshot snapshot = Snapshot(&aircraft, timestamp); history.AddSnapshot(&snapshot); EXPECT_EQ(history.GetLast(), &snapshot); }
// Ejects a module (fully qualified path) via process id void Injector::EjectLib(DWORD ProcID, const std::wstring& Path) { // Grab a new snapshot of the process EnsureCloseHandle Snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcID)); if (Snapshot == INVALID_HANDLE_VALUE) throw std::runtime_error("Could not get module snapshot for remote process.");; // Get the HMODULE of the desired library MODULEENTRY32W ModEntry = { sizeof(ModEntry) }; bool Found = false; BOOL bMoreMods = Module32FirstW(Snapshot, &ModEntry); for (; bMoreMods; bMoreMods = Module32NextW(Snapshot, &ModEntry)) { std::wstring ModuleName(ModEntry.szModule); std::wstring ExePath(ModEntry.szExePath); Found = (ModuleName == Path || ExePath == Path); if (Found) break; } if (!Found) throw std::runtime_error("Could not find module in remote process.");; // Get a handle for the target process. EnsureCloseHandle Process(OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION, // For CreateRemoteThread FALSE, ProcID)); if (!Process) throw std::runtime_error("Could not get handle to process."); // Get the real address of LoadLibraryW in Kernel32.dll HMODULE hKernel32 = GetModuleHandle(TEXT("Kernel32")); if (hKernel32 == NULL) throw std::runtime_error("Could not get handle to Kernel32."); PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE) GetProcAddress(hKernel32, "FreeLibrary"); if (pfnThreadRtn == NULL) throw std::runtime_error("Could not get pointer to FreeLibrary."); // Create a remote thread that calls FreeLibrary() EnsureCloseHandle Thread(CreateRemoteThread(Process, NULL, 0, pfnThreadRtn, ModEntry.modBaseAddr, 0, NULL)); if (!Thread) throw std::runtime_error("Could not create thread in remote process."); // Wait for the remote thread to terminate WaitForSingleObject(Thread, INFINITE); // Get thread exit code DWORD ExitCode; if (!GetExitCodeThread(Thread,&ExitCode)) throw std::runtime_error("Could not get thread exit code."); // Check LoadLibrary succeeded and returned a module base if(!ExitCode) throw std::runtime_error("Call to FreeLibrary in remote process failed."); }
IndexMetaInfo::Snapshot IndexMetaInfo::getSnapshot(uint64_t syncToken) const { IndexMetaInfo *self = const_cast<IndexMetaInfo *>(this); SnapItr itr = self->findSnapshot(syncToken); if (itr == _snapshots.end()) { return Snapshot(); } return *itr; }
IndexMetaInfo::Snapshot IndexMetaInfo::getBestSnapshot() const { int idx = _snapshots.size() - 1; while (idx >= 0 && !_snapshots[idx].valid) { --idx; } if (idx >= 0) { return _snapshots[idx]; } else { return Snapshot(); } }
void tdf008_createDataSetFromScratch() { // We create an empty data frame of 100 entries ROOT::Experimental::TDataFrame tdf(100); // We now fill it with random numbers TRandom3 rnd(1); auto tdf_1 = tdf.Define("rnd", [&rnd](){return rnd.Gaus();}); // We plot these numbers auto hgaus = tdf_1.Histo1D("rnd"); // And we write out the dataset on disk tdf_1.Snapshot("randomNumbers", "tdf008_createDataSetFromScratch.root"); }
void Session::Reset() { UserValues.clear(); AssetStates.clear(); Snapshots.clear(); QueueHistory.clear(); AssetsHistory.clear(); ValuesHistories.clear(); ValuesHistoryNames.clear(); ValuesChanges.clear(); Bookmarks.clear(); // create the zeroth step so we can go back in history to the start Snapshots.push_back(Snapshot(0, 0, 0)); CurrentSnapshot = 1; ValuesChanged = true; AssetsChanged = true; }
int Prediction::AddAircraft(CorrelationAircraft *aircraft) { int status = 0; if (aircraft == NULL) { status = 1; } else { // Empty Snapshot if (_current_snapshot->GetAircraft()->empty()) { std::vector<CorrelationAircraft> aircraft_list; aircraft_list.push_back(*aircraft); *_current_snapshot = Snapshot(&aircraft_list, aircraft->GetTime()); // gets first aircraft's timestamp } else { _current_snapshot->GetAircraft()->push_back(*aircraft); } } return status; }
void JoinCascador::Train(DataSet& pos, DataSet& neg) { this->pos = &pos; this->neg = &neg; const int start_of_stage = current_stage_idx; for (int t = start_of_stage; t < T; t++) { current_stage_idx = t; if (current_stage_idx != start_of_stage) { current_cart_idx = -1; } LOG("Train %d th stages", t + 1); TIMER_BEGIN btcarts[t].Train(pos, neg); LOG("End of train %d th stages, costs %.4lf s", t + 1, TIMER_NOW); TIMER_END LOG("Snapshot current Training Status"); Snapshot(); } }
void SnapshotsFile::_processDirectory(const QString& sessionId, const QDir& rootDir, QMap<QString,Snapshot>& snapshotList) const { if (!rootDir.exists()) { return; } QDirIterator dit(rootDir.absolutePath(), QDir::NoFilter); while (dit.hasNext()) { dit.next(); // skip "." and ".." entries if (dit.fileName() == "." || dit.fileName() == "..") { continue; } QString fileName = dit.fileInfo().fileName(); if (dit.fileInfo().isFile()) { if (fileName.endsWith(SUFFIX)) { QString strippedFileName = fileName.left( fileName.length() - SUFFIX.length()); if ( !snapshotList.contains( strippedFileName ) ){ snapshotList.insert(strippedFileName, Snapshot(strippedFileName)); } QString dirName = rootDir.dirName(); if ( dirName == BASE_DIR ){ QDateTime lastModify = dit.fileInfo().lastModified(); QString lastModifyStr = lastModify.toString("ddd MMMM d yyyy"); snapshotList[strippedFileName].setCreatedDate( lastModifyStr ); QString description = read( sessionId, Carta::State::CartaObject::SNAPSHOT_INFO, strippedFileName); snapshotList[strippedFileName].setDescription( description ); } else { //Add in the state interfaces QString rootName = rootDir.dirName(); snapshotList[strippedFileName].setState(rootName, true); } } } else if (dit.fileInfo().isDir()){ QString subDirPath = dit.fileInfo().absoluteFilePath(); QDir subDir( subDirPath ); _processDirectory( sessionId, subDir, snapshotList); } } }
void Solver<Dtype>::Solve(Net<Dtype>* net) { net_ = net; LOG(INFO) << "Solving " << net_->name(); PreSolve(); iter_ = 0; // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. vector<Blob<Dtype>*> bottom_vec; while (iter_++ < param_.max_iter()) { Dtype loss = net_->ForwardBackward(bottom_vec); ComputeUpdateValue(); net_->Update(); // Check if we need to do snapshot if (param_.snapshot() > 0 && iter_ % param_.snapshot() == 0) { Snapshot(false); } if (param_.display()) { LOG(ERROR) << "Iteration " << iter_ << ", loss = " << loss; } } LOG(INFO) << "Optimization Done."; }
bool ParticleSimulator::Simulate(float endtime, float delta, bool bdebug) { ParticleFactory* factory = ParticleFactory::getInstance(); float snapTime = delta; bool bSuccess = true; for (set<MovingParticle*>::iterator it = factory->activeSet.begin(); it != factory->activeSet.end(); ++it) { (*it)->updateEvent(); } { vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); } int iter = 0; while (time < endtime) { iter++; vector<Snapshot> shots = Snapshot::TakeSnapshot(time); //temporary MovingParticle* p = MovingParticle::getNextEvent(); if (p == NULL) break; if (p->getEvent().t > endtime) break; if (p->id == 255) p->id += 0; for (set<MovingParticle*>::iterator it = factory->activeSet.begin(); it != factory->activeSet.end(); ++it) { (*it)->update(p->getEvent().t - time); } time = p->getEvent().t; if (p->applyEvent() == false) break; p->getEvent().print(); MovingParticle::removeUnstable(); if (time >= snapTime) { vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); snapTime += delta; } MovingParticle::quickFinish(); if (bdebug && MovingParticle::sanityCheck() == false) { printf("Violation of sanity check found at %f.\n", time); vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); bSuccess = false; break; } //find closed regions vector<vector<MovingParticle*>> regions = MovingParticle::clusterParticles(); for (int i = 0; i < regions.size(); ++i) { //if (clockWise(regions[i]) > 0) { vector<MovingParticle*> tr = MovingParticle::traceBackPolygon(regions[i]); vector<vector<MovingParticle*>> areas = MovingParticle::closedRegions(tr); for (int j = 0; j < areas.size(); ++j) { Snapshot shot(0.0f, areas[j]); if (find(closedRegions.begin(), closedRegions.end(), shot) == closedRegions.end()) { closedRegions.push_back(shot); } } //if (tr.size() > 10) //forget small ones { Snapshot shot(0.0f, tr); if (find(traces.begin(), traces.end(), shot) == traces.end()) { traces.push_back(Snapshot(0, tr)); polygons.push_back(Snapshot(time, regions[i])); } } } } doneEvents.push_back(p->getEvent()); //for (set<MovingParticle*>::iterator it = factory->updateQueue.begin(); it != factory->updateQueue.end(); ++it) for (set<MovingParticle*>::iterator it = factory->activeSet.begin(); it != factory->activeSet.end(); ++it) { (*it)->updateEvent(); } factory->updateQueue.clear(); } for (int i = 0; i < factory->particles.size(); ++i) { MovingParticle* p = factory->particles[i]; if (p->bActive == false && p->time > p->init_event_time && p->init_event_time >= 0) { printf("%d %f %f %f %d\n", p->id, p->created, p->time, p->init_event_time, p->event.type); } } return bSuccess; }
void S9xProcessEvents (bool8 block) { static fd_set fds; static struct timeval tv = { 0, 0 }; /* if (joypads[0] & SNES_TL_MASK && joypads[0] & SNES_TR_MASK) S9xExit(); */ if (!is_graphics) { while (True) { char c; if (read (0, &c, 1) >= 0) if (c == '\n') { S9xGraphicsMode (); Settings.Paused ^= 1; return; } } } while (block || XPending (ourdisp)) { XEvent event; XNextEvent (ourdisp, &event); block = FALSE; uint8 byte1 = 0; uint8 byte2 = 0; uint8 byte3 = 0; uint8 byte4 = 0; switch (event.type) { case KeyPress: case KeyRelease: { int key; switch (key = XKeycodeToKeysym (ourdisp, event.xkey.keycode, 0)) { case XK_k: case XK_Right: byte2 = 1; break; case XK_h: case XK_Left: byte2 = 2; break; case XK_j: case XK_n: case XK_Down: byte2 = 4; break; case XK_u: case XK_Up: byte2 = 8; break; case XK_Return: byte2 = 16; break; // Start case XK_space: byte2 = 32; break; // Select case XK_period: case XK_t: case XK_d: byte1 = 128; break; // A case XK_slash: case XK_y: case XK_c: byte2 = 128; break; // B case XK_m: case XK_e: case XK_s: byte1 = 64; break; // X case XK_comma: case XK_r: case XK_x: byte2 = 64; break; // Y case XK_v: case XK_q: case XK_a: byte1 = 32; break; // TL case XK_b: case XK_w: case XK_z: byte1 = 16; break; // TR case XK_KP_4: byte4 = 1; break; case XK_KP_6: byte4 = 2; break; case XK_KP_2: byte4 = 4; break; case XK_KP_8: byte4 = 8; break; case XK_KP_Enter: byte4 = 16; break; // Start case XK_KP_Add: byte4 = 32; break; // Select case XK_Prior: byte3 = 128; break; // A case XK_Next: byte4 = 128; break; // B case XK_Home: byte3 = 64; break; // X case XK_End: byte4 = 64; break; // Y case XK_Insert: byte3 = 32; break; // TL case XK_Delete: byte3 = 16; break; // TR case XK_Escape: S9xExit (); break; case XK_0: if (event.type == KeyPress) Settings.DisableHDMA = !Settings.DisableHDMA; break; case XK_1: if (event.type == KeyPress) Settings.BG_Forced ^= 1; break; case XK_2: if (event.type == KeyPress) Settings.BG_Forced ^= 2; break; case XK_3: if (event.type == KeyPress) Settings.BG_Forced ^= 4; break; case XK_4: if (event.type == KeyPress) Settings.BG_Forced ^= 8; break; case XK_5: if (event.type == KeyPress) Settings.BG_Forced ^= 16; break; case XK_6: if (event.type == KeyPress) Settings.SwapJoypads = !Settings.SwapJoypads; break; case XK_9: if (event.type == KeyPress) if (Settings.SixteenBit) Settings.Transparency = !Settings.Transparency; break; case XK_8: if (event.type == KeyPress) Settings.BGLayering = !Settings.BGLayering; break; case XK_7: if (event.type == KeyPress) S9xNextController (); break; case XK_minus: if (event.type == KeyPress) { if (Settings.SkipFrames <= 1) Settings.SkipFrames = AUTO_FRAMERATE; else if (Settings.SkipFrames != AUTO_FRAMERATE) Settings.SkipFrames--; } break; case XK_equal: case XK_plus: if (event.type == KeyPress) { if (Settings.SkipFrames == AUTO_FRAMERATE) Settings.SkipFrames = 1; else if (Settings.SkipFrames < 10) Settings.SkipFrames++; } break; case XK_BackSpace: if (event.type == KeyPress) { Settings.DisableGraphicWindows = !Settings.DisableGraphicWindows; } break; case XK_Scroll_Lock: case XK_Pause: case XK_Break: if (event.type == KeyPress) { if (Settings.Paused) S9xGraphicsMode (); else S9xTextMode (); Settings.Paused ^= 1; } break; /* case XK_Tab: if (event.type == KeyPress) superscope_turbo = !superscope_turbo; break; case XK_grave: superscope_pause = event.type == KeyPress; break; */ case XK_F1: #ifdef DEBUGGER if (event.type == KeyPress && (event.xkey.state & Mod1Mask)) { CPU.Flags |= DEBUG_MODE_FLAG; break; } #endif // Fall... case XK_F2: if (event.type == KeyPress && (event.xkey.state & Mod1Mask)) { S9xLoadSnapshot (S9xChooseFilename (TRUE)); break; } // Fall... case XK_F3: if (event.type == KeyPress && (event.xkey.state & Mod1Mask)) { Snapshot (S9xChooseFilename (FALSE)); break; } // Fall... case XK_F4: case XK_F5: case XK_F6: case XK_F7: case XK_F8: case XK_F9: case XK_F10: case XK_F11: case XK_F12: if (event.type == KeyPress) { if (!(event.xkey.state & (ShiftMask | Mod1Mask))) { if (key == XK_F11) { S9xLoadSnapshot (S9xChooseFilename (TRUE)); break; } else if (key == XK_F12) { Snapshot (S9xChooseFilename (FALSE)); break; } char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (Memory.ROMFilename, drive, dir, def, ext); sprintf (filename, "%s%s%s.%03d", S9xGetSnapshotDirectory (), SLASH_STR, def, key - XK_F1); S9xLoadSnapshot (filename); } else if (event.xkey.state & Mod1Mask) { if (key >= XK_F4) S9xToggleSoundChannel (key - XK_F4); } else { char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (Memory.ROMFilename, drive, dir, def, ext); sprintf (filename, "%s%s%s.%03d", S9xGetSnapshotDirectory (), SLASH_STR, def, key - XK_F1); Snapshot (filename); } } break; } if (event.type == KeyPress) { joypads [0] |= byte1; joypads [0] |= (byte2 << 8); joypads [1] |= byte3; joypads [1] |= (byte4 << 8); } else { joypads [0] &= ~byte1; joypads [0] &= ~(byte2 << 8); joypads [1] &= ~byte3; joypads [1] &= ~(byte4 << 8); } break; } #if 0 case ButtonPress: mouse_buttons = (event.xbutton.state | (1 << event.xbutton.button)) & 0x1f; break; case ButtonRelease: mouse_buttons = (event.xbutton.state & ~(1 << event.xbutton.button)) & 0x1f; break; #endif } } }
void Solver<Dtype>::Test(const int test_net_id) { CHECK(Caffe::root_solver()); LOG(INFO) << "Iteration " << iter_ << ", Testing net (#" << test_net_id << ")"; CHECK_NOTNULL(test_nets_[test_net_id].get())-> ShareTrainedLayersWith(net_.get()); vector<Dtype> test_score; vector<int> test_score_output_id; const shared_ptr<Net<Dtype> >& test_net = test_nets_[test_net_id]; Dtype loss = 0; for (int i = 0; i < param_.test_iter(test_net_id); ++i) { SolverAction::Enum request = GetRequestedAction(); // Check to see if stoppage of testing/training has been requested. while (request != SolverAction::NONE) { if (SolverAction::SNAPSHOT == request) { Snapshot(); } else if (SolverAction::STOP == request) { requested_early_exit_ = true; } request = GetRequestedAction(); } if (requested_early_exit_) { // break out of test loop. break; } Dtype iter_loss; const vector<Blob<Dtype>*>& result = test_net->Forward(&iter_loss); if (param_.test_compute_loss()) { loss += iter_loss; } if (i == 0) { for (int j = 0; j < result.size(); ++j) { const Dtype* result_vec = result[j]->cpu_data(); for (int k = 0; k < result[j]->count(); ++k) { test_score.push_back(result_vec[k]); test_score_output_id.push_back(j); } } } else { int idx = 0; for (int j = 0; j < result.size(); ++j) { const Dtype* result_vec = result[j]->cpu_data(); for (int k = 0; k < result[j]->count(); ++k) { test_score[idx++] += result_vec[k]; } } } } if (requested_early_exit_) { LOG(INFO) << "Test interrupted."; return; } if (param_.test_compute_loss()) { loss /= param_.test_iter(test_net_id); LOG(INFO) << "Test loss: " << loss; } for (int i = 0; i < test_score.size(); ++i) { const int output_blob_index = test_net->output_blob_indices()[test_score_output_id[i]]; const string& output_name = test_net->blob_names()[output_blob_index]; const Dtype loss_weight = test_net->blob_loss_weights()[output_blob_index]; ostringstream loss_msg_stream; const Dtype mean_score = test_score[i] / param_.test_iter(test_net_id); if (loss_weight) { loss_msg_stream << " (* " << loss_weight << " = " << loss_weight * mean_score << " loss)"; } LOG(INFO) << " Test net output #" << i << ": " << output_name << " = " << mean_score << loss_msg_stream.str(); } }
void Solver<Dtype>::Step(int iters) { const int start_iter = iter_; const int stop_iter = iter_ + iters; int average_loss = this->param_.average_loss(); losses_.clear(); smoothed_loss_ = 0; while (iter_ < stop_iter) { // zero-init the params net_->ClearParamDiffs(); if (param_.test_interval() && iter_ % param_.test_interval() == 0 && (iter_ > 0 || param_.test_initialization()) && Caffe::root_solver()) { TestAll(); if (requested_early_exit_) { // Break out of the while loop because stop was requested while testing. break; } } for (int i = 0; i < callbacks_.size(); ++i) { callbacks_[i]->on_start(); } const bool display = param_.display() && iter_ % param_.display() == 0; net_->set_debug_info(display && param_.debug_info()); // accumulate the loss and gradient Dtype loss = 0; for (int i = 0; i < param_.iter_size(); ++i) { loss += net_->ForwardBackward(); } loss /= param_.iter_size(); // average the loss across iterations for smoothed reporting UpdateSmoothedLoss(loss, start_iter, average_loss); if (display) { LOG_IF(INFO, Caffe::root_solver()) << "Iteration " << iter_ << ", loss = " << smoothed_loss_; const vector<Blob<Dtype>*>& result = net_->output_blobs(); int score_index = 0; for (int j = 0; j < result.size(); ++j) { const Dtype* result_vec = result[j]->cpu_data(); const string& output_name = net_->blob_names()[net_->output_blob_indices()[j]]; const Dtype loss_weight = net_->blob_loss_weights()[net_->output_blob_indices()[j]]; for (int k = 0; k < result[j]->count(); ++k) { ostringstream loss_msg_stream; if (loss_weight) { loss_msg_stream << " (* " << loss_weight << " = " << loss_weight * result_vec[k] << " loss)"; } LOG_IF(INFO, Caffe::root_solver()) << " Train net output #" << score_index++ << ": " << output_name << " = " << result_vec[k] << loss_msg_stream.str(); } } } for (int i = 0; i < callbacks_.size(); ++i) { callbacks_[i]->on_gradients_ready(); } ApplyUpdate(); // Increment the internal iter_ counter -- its value should always indicate // the number of times the weights have been updated. ++iter_; SolverAction::Enum request = GetRequestedAction(); // Save a snapshot if needed. if ((param_.snapshot() && iter_ % param_.snapshot() == 0 && Caffe::root_solver()) || (request == SolverAction::SNAPSHOT)) { Snapshot(); } if (SolverAction::STOP == request) { requested_early_exit_ = true; // Break out of training loop. break; } } }
void Solver<Dtype>::Solve(const char* resume_file) { Caffe::set_phase(Caffe::TRAIN); LOG(INFO) << "Solving " << net_->name(); PreSolve(); iter_ = 0; if (resume_file) { LOG(INFO) << "Restoring previous solver status from " << resume_file; Restore(resume_file); } // Remember the initial iter_ value; will be non-zero if we loaded from a // resume_file above. const int start_iter = iter_; // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. vector<Blob<Dtype>*> bottom_vec; for (; iter_ < param_.max_iter(); ++iter_) { // Save a snapshot if needed. if (param_.snapshot() && iter_ > start_iter && iter_ % param_.snapshot() == 0) { Snapshot(); } if (param_.test_interval() && iter_ % param_.test_interval() == 0 && (iter_ > 0 || param_.test_initialization())) { TestAll(); } const bool display = param_.display() && iter_ % param_.display() == 0; net_->set_debug_info(display && param_.debug_info()); net_->set_sample_print(display && param_.debug_info() && param_.sample_print()); Dtype loss = net_->ForwardBackward(bottom_vec); if (display) { LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss; const vector<Blob<Dtype>*>& result = net_->output_blobs(); int score_index = 0; for (int j = 0; j < result.size(); ++j) { const Dtype* result_vec = result[j]->cpu_data(); const string& output_name = net_->blob_names()[net_->output_blob_indices()[j]]; const Dtype loss_weight = net_->blob_loss_weights()[net_->output_blob_indices()[j]]; for (int k = 0; k < result[j]->count(); ++k) { ostringstream loss_msg_stream; if (loss_weight) { loss_msg_stream << " (* " << loss_weight << " = " << loss_weight * result_vec[k] << " loss)"; } LOG(INFO) << " Train net output #" << score_index++ << ": " << output_name << " = " << result_vec[k] << loss_msg_stream.str(); } } } ComputeUpdateValue(); net_->Update(); } // Always save a snapshot after optimization, unless overridden by setting // snapshot_after_train := false. if (param_.snapshot_after_train()) { Snapshot(); } // After the optimization is done, run an additional train and test pass to // display the train and test loss/outputs if appropriate (based on the // display and test_interval settings, respectively). Unlike in the rest of // training, for the train net we only run a forward pass as we've already // updated the parameters "max_iter" times -- this final pass is only done to // display the loss, which is computed in the forward pass. if (param_.display() && iter_ % param_.display() == 0) { Dtype loss; net_->Forward(bottom_vec, &loss); LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss; } if (param_.test_interval() && iter_ % param_.test_interval() == 0) { TestAll(); } LOG(INFO) << "Optimization Done."; }
bool Solver::Test(const int test_net_id, const int iters, bool use_multi_gpu) { LOG_IF(INFO, Caffe::root_solver()) << "Iteration " << iter_ << ", Testing net (#" << test_net_id << ")"; if (!test_nets_[test_net_id]->trained_layers_shared()) { CHECK_NOTNULL(test_nets_[test_net_id].get())->ShareTrainedLayersWith(net_.get()); } vector<float> test_score; vector<int> test_score_output_id; const shared_ptr<Net>& test_net = test_nets_[test_net_id]; test_net->set_solver(this); float loss = 0.F; const int test_iterations = iters > 0 ? iters : param_.test_iter(test_net_id); for (int i = 0; i < test_iterations; ++i) { SolverAction::Enum request = GetRequestedAction(); // Check to see if stoppage of testing/training has been requested. while (request != SolverAction::NONE) { if (SolverAction::SNAPSHOT == request) { Snapshot(); } else if (SolverAction::STOP == request) { requested_early_exit_ = true; } request = GetRequestedAction(); } if (requested_early_exit_) { LOG(INFO) << "Test interrupted."; Finalize(); return true; } float iter_loss; const vector<Blob*>& result = test_net->Forward(&iter_loss); if (param_.test_compute_loss()) { loss += iter_loss; } if (i == 0) { for (int j = 0; j < result.size(); ++j) { for (int k = 0; k < result[j]->count(); ++k) { test_score.push_back(result[j]->data_at(k)); test_score_output_id.push_back(j); } } } else { int idx = 0; for (int j = 0; j < result.size(); ++j) { for (int k = 0; k < result[j]->count(); ++k) { test_score[idx++] += result[j]->data_at(k); } } } } if (use_multi_gpu) { callback_soft_barrier(); // now we've done, transfer results for (int i = 0; i < root_callbacks_.size(); ++i) { root_callbacks_[i]->saveTestResults(loss, test_score); } callback_soft_barrier(); float global_loss = 0.F; vector<float> global_scores(test_score.size()); // aggregate test results from all solvers for (int i = 0; i < root_callbacks_.size(); ++i) { root_callbacks_[i]->aggregateTestResults(&global_loss, &global_scores); } callback_soft_barrier(); loss = global_loss; for (int i = 0; i < test_score.size(); ++i) { test_score[i] = global_scores[i]; } } if (param_.test_compute_loss()) { loss /= param_.test_iter(test_net_id); LOG(INFO) << "Test loss: " << loss; } for (int i = 0; i < test_score.size(); ++i) { const int output_blob_index = test_net->output_blob_indices()[test_score_output_id[i]]; const string& output_name = test_net->blob_names()[output_blob_index]; const float loss_weight = test_net->blob_loss_weights()[output_blob_index]; ostringstream loss_msg_stream; const float mean_score = test_score[i] / test_iterations / Caffe::solver_count(); if (loss_weight) { loss_msg_stream << " (* " << loss_weight << " = " << (loss_weight * mean_score) << " loss)"; } LOG_IF(INFO, Caffe::root_solver()) << " Test net output #" << i << ": " << output_name << " = " << mean_score << loss_msg_stream.str(); } return false; }
Snapshot ParametersReal::itemAsSnapshot( Index i, Monitor& monitor ) { if (i>maxindex) return Snapshot(); //TODO: throw std::runtime_error("Not Implemented"); }
Snapshot ParametersReal::getSnapshot( const wchar_t* name, Monitor& monitor ) { if (!monitor) return Snapshot(); //TODO: throw std::runtime_error("Not Implemented"); }
void S9xDoHBlankProcessing () { #ifdef CPU_SHUTDOWN CPU.WaitCounter++; #endif switch (CPU.WhichEvent) { case HBLANK_START_EVENT: if (IPPU.HDMA && CPU.V_Counter <= PPU.ScreenHeight) IPPU.HDMA = S9xDoHDMA (IPPU.HDMA); break; case HBLANK_END_EVENT: S9xSuperFXExec (); #ifndef STORM if (Settings.SoundSync) S9xGenerateSound (); #endif CPU.Cycles -= Settings.H_Max; IAPU.NextAPUTimerPos -= (Settings.H_Max * 10000L); if (IAPU.APUExecuting) { APU.Cycles -= Settings.H_Max; #ifdef MK_APU S9xCatchupCount(); #endif } else APU.Cycles = 0; CPU.NextEvent = -1; ICPU.Scanline++; if (++CPU.V_Counter >= (Settings.PAL ? SNES_MAX_PAL_VCOUNTER : SNES_MAX_NTSC_VCOUNTER)) { CPU.V_Counter = 0; Memory.FillRAM[0x213F]^=0x80; PPU.RangeTimeOver = 0; CPU.NMIActive = FALSE; ICPU.Frame++; PPU.HVBeamCounterLatched = 0; CPU.Flags |= SCAN_KEYS_FLAG; S9xStartHDMA (); } if (PPU.VTimerEnabled && !PPU.HTimerEnabled && CPU.V_Counter == PPU.IRQVBeamPos) { S9xSetIRQ (PPU_V_BEAM_IRQ_SOURCE); } if (CPU.V_Counter == PPU.ScreenHeight + FIRST_VISIBLE_LINE) { // Start of V-blank S9xEndScreenRefresh (); IPPU.HDMA = 0; // Bits 7 and 6 of $4212 are computed when read in S9xGetPPU. #ifndef OPTI missing.dma_this_frame = 0; #endif // OPTI IPPU.MaxBrightness = PPU.Brightness; PPU.ForcedBlanking = (Memory.FillRAM [0x2100] >> 7) & 1; if(!PPU.ForcedBlanking){ PPU.OAMAddr = PPU.SavedOAMAddr; { uint8 tmp = 0; if(PPU.OAMPriorityRotation) tmp = (PPU.OAMAddr&0xFE)>>1; if((PPU.OAMFlip&1) || PPU.FirstSprite!=tmp){ PPU.FirstSprite=tmp; IPPU.OBJChanged=TRUE; } } PPU.OAMFlip = 0; } Memory.FillRAM[0x4210] = 0x80 |Model->_5A22; if (Memory.FillRAM[0x4200] & 0x80) { CPU.NMIActive = TRUE; CPU.Flags |= NMI_FLAG; CPU.NMICycleCount = CPU.NMITriggerPoint; } #ifdef OLD_SNAPSHOT_CODE if (CPU.Flags & SAVE_SNAPSHOT_FLAG) { CPU.Flags &= ~SAVE_SNAPSHOT_FLAG; Registers.PC = CPU.PC - CPU.PCBase; S9xPackStatus (); S9xAPUPackStatus (); Snapshot (NULL); } #endif }
void Solver<Dtype>::Solve(const char* resume_file) { Caffe::set_mode(Caffe::Brew(param_.solver_mode())); if (param_.solver_mode() && param_.has_device_id()) { Caffe::SetDevice(param_.device_id()); } Caffe::set_phase(Caffe::TRAIN); LOG(INFO)<< "Solving " << net_->name(); PreSolve(); iter_ = 0; if (resume_file) { LOG(INFO)<< "Restoring previous solver status from " << resume_file; Restore(resume_file); } // For a network that is trained by the solver, no bottom or top vecs // should be given, and we will just provide dummy vecs. vector<Blob<Dtype>*> bottom_vec; timeval start_t, finish_t, tmp_t; gettimeofday(&start_t, NULL); gettimeofday(&tmp_t, NULL); int pic_counts = 0; int pos_triplets = 0; int triplets_count = 0; while (iter_++ < param_.max_iter()) { Dtype loss = net_->ForwardBackward(bottom_vec); ComputeUpdateValue(); net_->Update(); pic_counts += Caffe::mutable_name2id().size(); pos_triplets += Caffe::mutable_pos_triplets(); triplets_count += Caffe::mutable_triplets().size(); if (param_.display() && iter_ % param_.display() == 0) { gettimeofday(&finish_t, NULL); long int time_cost = (finish_t.tv_sec - tmp_t.tv_sec) * 1000000 + (finish_t.tv_usec - tmp_t.tv_usec); LOG(INFO)<< "Iteration " << iter_ << ", loss = " << loss << ", image counts: " << (pic_counts * 1.0 / param_.display()) << ", triplets count: " << (triplets_count * 1.0 / param_.display()) << ", positive triplet: " << (pos_triplets * 1.0 / param_.display()) << ", cost time = " << (time_cost / 1000.0) << "ms"; gettimeofday(&tmp_t, NULL); pic_counts = 0; pos_triplets = 0; triplets_count = 0; } if (param_.test_interval() && iter_ % param_.test_interval() == 0) { // We need to set phase to test before running. Caffe::set_phase(Caffe::TEST); Test(); Caffe::set_phase(Caffe::TRAIN); } // Check if we need to do snapshot if (param_.snapshot() && iter_ % param_.snapshot() == 0) { Snapshot(); } } // After the optimization is done, always do a snapshot. iter_--; Snapshot(); LOG(INFO)<< "Optimization Done."; }
void S9xProcessEvents (bool8 block) { static char prev_keystate[128]; extern volatile char key[128]; #ifdef GRIP_SUPPORT ReadGrip (); #endif #ifdef SIDEWINDER_SUPPORT if (num_sidewinders) ReadSidewinders (); #endif char key1[128]; char *keystate = (char *) key1; int fn = 0; memcpy (key1, (char *) key, sizeof (key1)); #undef KEY_DOWN #define KEY_DOWN(a) (keystate[a]) #undef KEY_PRESS #define KEY_PRESS(a) (keystate[a] && !prev_keystate[a]) #undef KEY_WASPRESSED #define KEY_WASPRESSED(a) (prev_keystate[a] && !keystate[a]) #undef PROCESS_KEY #define PROCESS_KEY(k, b, v)\ if (KEY_PRESS(k)) b |= v;\ if (KEY_WASPRESSED(k)) b &= ~v; if (KEY_PRESS (SCANCODE_ESCAPE)) S9xExit (); // Joypad 1: PROCESS_KEY(SCANCODE_K, joypads [0], SNES_RIGHT_MASK) PROCESS_KEY(SCANCODE_CURSORRIGHT, joypads [0], SNES_RIGHT_MASK) PROCESS_KEY(SCANCODE_H, joypads [0], SNES_LEFT_MASK) PROCESS_KEY(SCANCODE_CURSORLEFT, joypads [0], SNES_LEFT_MASK) PROCESS_KEY(SCANCODE_N, joypads [0], SNES_DOWN_MASK) PROCESS_KEY(SCANCODE_J, joypads [0], SNES_DOWN_MASK) PROCESS_KEY(SCANCODE_CURSORDOWN, joypads [0], SNES_DOWN_MASK) PROCESS_KEY(SCANCODE_U, joypads [0], SNES_UP_MASK) PROCESS_KEY(SCANCODE_CURSORUP, joypads [0], SNES_UP_MASK) PROCESS_KEY(SCANCODE_ENTER, joypads [0], SNES_START_MASK) PROCESS_KEY(SCANCODE_SPACE, joypads [0], SNES_SELECT_MASK) PROCESS_KEY(SCANCODE_A, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_V, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_Q, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_Z, joypads [0], SNES_TR_MASK) PROCESS_KEY(SCANCODE_B, joypads [0], SNES_TR_MASK) PROCESS_KEY(SCANCODE_W, joypads [0], SNES_TR_MASK) PROCESS_KEY(SCANCODE_S, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_M, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_E, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_X, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_COMMA, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_R, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_D, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_PERIOD, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_T, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_C, joypads [0], SNES_B_MASK) PROCESS_KEY(SCANCODE_SLASH, joypads [0], SNES_B_MASK) PROCESS_KEY(SCANCODE_Y, joypads [0], SNES_B_MASK) // Joypad 2: // PROCESS_KEY(SCANCODE_CURSORRIGHT, joypads [1], SNES_RIGHT_MASK) // PROCESS_KEY(SCANCODE_CURSORLEFT, joypads [1], SNES_LEFT_MASK) // PROCESS_KEY(SCANCODE_CURSORDOWN, joypads [1], SNES_DOWN_MASK) // PROCESS_KEY(SCANCODE_CURSORUP, joypads [1], SNES_UP_MASK) PROCESS_KEY(SCANCODE_KEYPADENTER, joypads [0], SNES_START_MASK) PROCESS_KEY(SCANCODE_KEYPADPLUS, joypads [0], SNES_SELECT_MASK) PROCESS_KEY(SCANCODE_INSERT, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_REMOVE, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_HOME, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_END, joypads [0], SNES_B_MASK) PROCESS_KEY(SCANCODE_PAGEUP, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_PAGEDOWN, joypads [0], SNES_TR_MASK) if (KEY_PRESS (SCANCODE_0)) Settings.DisableHDMA = !Settings.DisableHDMA; if (KEY_PRESS (SCANCODE_1)) PPU.BG_Forced ^= 1; if (KEY_PRESS (SCANCODE_2)) PPU.BG_Forced ^= 2; if (KEY_PRESS (SCANCODE_3)) PPU.BG_Forced ^= 4; if (KEY_PRESS (SCANCODE_4)) PPU.BG_Forced ^= 8; if (KEY_PRESS (SCANCODE_5)) PPU.BG_Forced ^= 16; if (KEY_PRESS (SCANCODE_6)) Settings.SwapJoypads = !Settings.SwapJoypads; if (KEY_PRESS (SCANCODE_7)) { if (IPPU.Controller == SNES_SUPERSCOPE) show_mouse (NULL); S9xNextController (); if (IPPU.Controller == SNES_SUPERSCOPE) show_mouse (screen); } if (KEY_PRESS (SCANCODE_8)) Settings.BGLayering = !Settings.BGLayering; if (KEY_PRESS (SCANCODE_9)) if (Settings.SixteenBit) Settings.Transparency = !Settings.Transparency; if (KEY_PRESS(SCANCODE_TAB)) superscope_turbo = !superscope_turbo; PROCESS_KEY(SCANCODE_GRAVE, superscope_pause, 1); if (KEY_PRESS(SCANCODE_F1)) fn = 1; if (KEY_PRESS(SCANCODE_F2)) fn = 2; if (KEY_PRESS(SCANCODE_F3)) fn = 3; if (KEY_PRESS(SCANCODE_F4)) fn = 4; if (KEY_PRESS(SCANCODE_F5)) fn = 5; if (KEY_PRESS(SCANCODE_F6)) fn = 6; if (KEY_PRESS(SCANCODE_F7)) fn = 7; if (KEY_PRESS(SCANCODE_F8)) fn = 8; if (KEY_PRESS(SCANCODE_F9)) fn = 9; if (KEY_PRESS(SCANCODE_F10)) fn = 10; if (KEY_PRESS(SCANCODE_F11)) fn = 11; if (KEY_PRESS(SCANCODE_F12)) fn = 12; if (fn > 0) { if (!KEY_DOWN(SCANCODE_LEFTALT) && !KEY_DOWN(SCANCODE_LEFTSHIFT)) { if (fn == 11) { S9xLoadSnapshot (S9xChooseFilename (TRUE)); } else if (fn == 12) { Snapshot (S9xChooseFilename (FALSE)); } else { char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (Memory.ROMFilename, drive, dir, def, ext); sprintf (filename, "%s%s%s.%03d", S9xGetSnapshotDirectory (), SLASH_STR, def, fn - 1); S9xLoadSnapshot (filename); } } else if (KEY_DOWN(SCANCODE_LEFTALT)) { if (fn >= 4) S9xToggleSoundChannel (fn - 4); #ifdef DEBUGGER else if (fn == 1) CPU.Flags |= DEBUG_MODE_FLAG; #endif else if (fn == 2) S9xLoadSnapshot (S9xChooseFilename (TRUE)); else if (fn == 3) Snapshot (S9xChooseFilename (FALSE)); } else { char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (Memory.ROMFilename, drive, dir, def, ext); sprintf (filename, "%s%s%s.%03d", S9xGetSnapshotDirectory (), SLASH_STR, def, fn - 1); Snapshot (filename); } } if (KEY_PRESS (SCANCODE_BREAK) || KEY_PRESS (SCANCODE_BREAK_ALTERNATIVE) || KEY_PRESS (SCANCODE_SCROLLLOCK)) Settings.Paused ^= 1; if (KEY_PRESS (SCANCODE_PRINTSCREEN)) SaveScreenshot (); if (KEY_PRESS (SCANCODE_MINUS)) { if (Settings.SkipFrames <= 1) Settings.SkipFrames = AUTO_FRAMERATE; else if (Settings.SkipFrames != AUTO_FRAMERATE) Settings.SkipFrames--; } if (KEY_PRESS (SCANCODE_EQUAL)) { if (Settings.SkipFrames == AUTO_FRAMERATE) Settings.SkipFrames = 1; else if (Settings.SkipFrames < 10) Settings.SkipFrames++; } memcpy (prev_keystate, keystate, sizeof (prev_keystate)); if (block) __dpmi_yield (); }