📄 state.h
字号:
//// Copyright (c) 2002 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_DVD_VM_STATE_H#define DXR3PLAYER_DVD_VM_STATE_H//------------------------------------------------------------------------------#include "GPRM.h"#include "SPRM.h"#include "Position.h"#include "dvd/DVD.h"#include "dvd/IFO.h"#include "dvd/PGC.h"//------------------------------------------------------------------------------namespace dvd {class DVD;}//------------------------------------------------------------------------------namespace dvd { namespace vm {//------------------------------------------------------------------------------/** * The state of the virtual machine. */class State{private: /** * The saved state. */ struct Saved { /// The highlighted button number unsigned highlightedButtonNumber; /// The position Position position; /// Construct the saved state explicit Saved(const State& state); /// Save the saved state into the given file bool save(FILE* f) const; /// Load the saved state from the given file bool load(FILE* f); }; /** * The DVD the state belongs to. */ const DVD* dvd; /** * The general-purpose register file */ GPRM gprm; /** * The system parameter register file */ SPRM sprm; /** * The position within the DVD. */ Position position; /** * The saved state. */ Saved saved;public: /** * Construct the state. */ explicit State(DVD* dvd); /** * Reset the state. */ void reset(); /** * Get the DVD the state belongs to. */ const DVD* getDVD() const; /** * Get the general-purpose register file for reading. */ const GPRM& getGPRM() const; /** * Get the value of the general-purpose register with the given * number. */ unsigned getGPRValue(size_t index) const; /** * Get the general-purpose register file for writing. */ GPRM& getGPRM(); /** * Set the value of the general-purpose register with the given * number. */ void setGPRValue(size_t index, unsigned value); /** * Get the system parameter register file for reading. */ const SPRM& getSPRM() const; /** * Get the value of the system parameter register with the given * index. */ unsigned getSPRValue(size_t index) const; /** * Get the value of the system parameter register with the given * name. */ unsigned getSPRValue(SPRM::registerName_t name) const; /** * Get the system parameter register file for writing. */ SPRM& getSPRM(); /** * Set the value of the system parameter register with the given * index. */ void setSPRValue(size_t index, unsigned value); /** * Set the value of the system parameter register with the given * name. */ void setSPRValue(SPRM::registerName_t name, unsigned value); /** * Set the highlighted button number (the value will be shifted * appropriately). */ void setHighlightedButtonNumber(unsigned buttonNo); /** * Get the register with the given number for reading. * * @param registerNumber the number of the register. From 0-15 it * refers to the general-purpose registers, from 128-151 it refers * to system parameter registers. Other numbers are invalid, and * besides a log message, the GPR with number (registerNumber%16) * is returned. */ const Register& getRegister(size_t registerNumber) const; /** * Get the value of the register with the given number. */ unsigned getValue(size_t registerNumber) const; /** * Get the register with the given number. * * @param registerNumber the number of the register. From 0-15 it * refers to the general-purpose registers, from 128-151 it refers * to system parameter registers. Other numbers are invalid, and * besides a log message, the GPR with number (registerNumber%16) * is returned. */ Register& getRegister(size_t registerNumber); /** * Set the value of the register with the given number. */ void setValue(size_t registerNumber, unsigned value); /** * Get the position of the state. */ const Position& getPosition() const; /** * Set the position. It will also setup the position registers. */ void setPosition(const Position& from); /** * Set the sector number. */ void setSectorNumber(size_t sectorNumber); /** * Save the state. */ void save(unsigned cell = 0); /** * Resume the state. */ bool resume(); /** * Save the state to the given file. * * @return if saving has succeeded */ bool save(FILE* f) const; /** * Load the state from the given file. * * @return if resuming has succeeded */ bool load(FILE* f); /** * Update the state without copying some non-essential registers. */ void updateEssential(const State& state); /** * Update only the non-essential registers. */ void updateNonEssential(const State& state);private: /** * Setup the position registers based on the current position. */ bool setPositionRegisters();};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline const DVD* State::getDVD() const{ return dvd;}//------------------------------------------------------------------------------inline const GPRM& State::getGPRM() const{ return gprm;}//------------------------------------------------------------------------------inline unsigned State::getGPRValue(size_t index) const{ return getGPRM().getValue(index);}//------------------------------------------------------------------------------inline GPRM& State::getGPRM(){ return gprm;}//------------------------------------------------------------------------------inline void State::setGPRValue(size_t index, unsigned value){ getGPRM().setValue(index, value);}//------------------------------------------------------------------------------inline const SPRM& State::getSPRM() const{ return sprm;}//------------------------------------------------------------------------------inline unsigned State::getSPRValue(size_t index) const{ return getSPRM().getValue(index);} //------------------------------------------------------------------------------inline unsigned State::getSPRValue(SPRM::registerName_t name) const{ return getSPRM().getValue(name);}//------------------------------------------------------------------------------inline SPRM& State::getSPRM(){ return sprm;}//------------------------------------------------------------------------------inline void State::setSPRValue(size_t index, unsigned value){ getSPRM().setValue(index, value);} //------------------------------------------------------------------------------inline void State::setSPRValue(SPRM::registerName_t name, unsigned value){ getSPRM().setValue(name, value);}//------------------------------------------------------------------------------inline void State::setHighlightedButtonNumber(unsigned buttonNo){ setSPRValue(SPRM::highlightedButtonNumber, buttonNo<<10);}//------------------------------------------------------------------------------inline unsigned State::getValue(size_t registerNumber) const{ return getRegister(registerNumber).getValue();}//------------------------------------------------------------------------------inline void State::setValue(size_t registerNumber, unsigned value){ getRegister(registerNumber).setValue(value);}//------------------------------------------------------------------------------inline const Position& State::getPosition() const{ return position;}//------------------------------------------------------------------------------inline void State::setSectorNumber(size_t sectorNumber){ position.setSectorNumber(sectorNumber);}//------------------------------------------------------------------------------} /* namespace dvd::vm */ } /* namespace dvd *///------------------------------------------------------------------------------#endif // DXR3PLAYER_DVD_VM_STATE_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -