📄 instruction.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_INSTRUCTION_H#define DXR3PLAYER_DVD_VM_INSTRUCTION_H//------------------------------------------------------------------------------#include <cstdio>//------------------------------------------------------------------------------namespace dvd { namespace vm {//------------------------------------------------------------------------------template <typename T>class BitExtractor{public: static const unsigned fullMask = ~(T)0; static unsigned getBits(T x, unsigned from, unsigned numBits);};//------------------------------------------------------------------------------/** * Base structure for an operand. */struct Operand{public: /** * The high-order byte. */ unsigned char high; /** * The low-order byte. */ unsigned char low;public: /** * Get the high-order byte of the operand */ unsigned getHigh() const; /** * Get the low-order byte of the operand */ unsigned getLow() const; /** * Get the 16-bit value of the operand. */ unsigned getValue() const; /** * Print the operand as a series of hexadecimal numbers */ void printHex(FILE* f) const;protected: /** * Get certain bits of the value */ unsigned getBits(unsigned from, unsigned numBits) const; /** * Get certain bits of the high-order byte. */ unsigned getHighBits(unsigned from, unsigned numBits) const; /** * Get certain bits of the low-order byte. */ unsigned getLowBits(unsigned from, unsigned numBits) const;};//------------------------------------------------------------------------------/** * The first operand. It adds some functions to extract the subfields. */struct Operand1 : public Operand{ /** * Get the CR1 value */ unsigned getCR1() const; /** * Get the PTTN value for JumpVTS_PTT */ unsigned getPTTN() const; /** * Get the TTN value for JumpSS VTSM */ unsigned getTTN() const; /** * Get the PGCN value for JumpSS_VMGM and CallSS_VMGM */ unsigned getPGCN() const; /** * Get the AF value for SetSTN. */ bool isAF() const; /** * Get the SR1 value for SetSTN */ unsigned getSR1() const; /** * Get the SRS value. */ unsigned getSRS() const; /** * Get the SVAL value */ unsigned getSVAL() const; /** * Get the AVAL value for SetSTN */ unsigned getAVAL() const; /** * Get the SRD value for Set */ unsigned getSRD() const; /** * Get the CR1 value for Set */ unsigned getSetCR1() const;};//------------------------------------------------------------------------------/** * The second operand. It adds some functions to extract the subfields. */struct Operand2 : public Operand{ typedef enum jumpCallType_t { FP = 0, VMGM_MENU = 1, VTSM = 2, VMGM_PGCN = 3 }; /** * Get the CR2 value. */ unsigned getCR2() const; /** * Get the CVAL value. */ unsigned getCVAL() const; /** * Get the TTN value for JumpTT, JumpVTS_TT, JumpVTS_PTT */ unsigned getTTN() const; /** * Get the VTS for JumpSS_VTSM */ unsigned getVTS() const; /** * Get the Jump/Call type. */ jumpCallType_t getJumpCallType() const; /** * Get the menu for JumpSS/CallSS */ unsigned getMenu() const; /** * Get the RSM cell for CallSS */ unsigned getRSMCell() const; /** * Get the SF value for SetSTN */ bool isSF() const; /** * Get the SR2 value for SetSTN */ unsigned getSR2() const; /** * Get SVAL value for SetSTN */ unsigned getSVAL() const; /** * Get the NF value for SetSTN */ bool isNF() const; /** * Get the SR3 value for SetSTN */ unsigned getSR3() const; /** * Get NVAL value for SetSTN */ unsigned getNVAL() const; /** * Get the PGCN value for SetNVTMR */ unsigned getPGCN() const; /** * Get the MF value for SetGPRMMD */ bool isMF() const; /** * Get the SRD value for SetGPRMMD */ unsigned getSRD() const; /** * Get the SRS value for SetAMXMD and SetHL_BTNN */ unsigned getSRS() const;};//------------------------------------------------------------------------------/** * The third operand. It adds some functions to extract the subfields. */struct Operand3 : public Operand{ /** * Link type. */ typedef enum link_t { LINK_NOP = 0x00, TOPCELL = 0x01, NEXTCELL = 0x02, PREVCELL = 0x03, TOPPG = 0x05, NEXTPG = 0x06, PREVPG = 0x07, TOPPGC = 0x09, NEXTPGC = 0x0a, PREVPGC = 0x0b, GOUPPGC = 0x0c, TAILPGC = 0x0d, RSM = 0x10 }; /** * Get the line number */ unsigned getLineNumber() const; /** * Get the LVL value */ unsigned getLVL() const; /** * Get the HLBN value. */ unsigned getHLBN() const; /** * Get the link type */ link_t getLinkType() const; /** * Get the PGCN value. */ unsigned getPGCN() const; /** * Get the PTTN value. */ unsigned getPTTN() const; /** * Get the PGN value */ unsigned getPGN() const; /** * Get the CN value */ unsigned getCN() const; /** * Get the CR1 value */ unsigned getCR1() const; /** * Get the CR2 value */ unsigned getCR2() const; /** * Get the CVAL value */ unsigned getCVAL() const;};//------------------------------------------------------------------------------struct Instruction { typedef enum type_t { SPECIAL = 0, BRANCH = 1, SETSYSREG = 2, SET = 3, SETCLNK = 4, CSETCLNK = 5, CMPSETLNK = 6 }; typedef enum setType_t { STN = 1, NVTMR = 2, GPRMMD = 3, AMXMD = 4, HL_BTNN = 6 }; typedef enum setOp_t { SET_NONE = 0, MOV = 1, SWP = 2, ADD = 3, SUB = 4, MUL = 5, DIV = 6, MOD = 7, RND = 8, AND = 9, OR = 10, XOR = 11 }; typedef enum cmpOp_t { CMP_NONE = 0, BC = 1, EQ = 2, NE = 3, GE = 4, GT = 5, LE = 6, LT = 7 }; typedef enum specCmd_t { NOP = 0, GOTO = 1, BREAK = 2, SETTMPPLVL = 3 }; typedef enum linkCmd_t { LINK_NOP = 0, LINKSUBSET = 1, LINKPGCN = 4, LINKPTTN = 5, LINKPGN = 6, LINKCN = 7 }; typedef enum jumpCallCmd_t { JUMPCALL_NOP = 0, EXIT = 1, JUMPTT = 2, JUMPVTS_TT = 3, JUMPVTS_PTT = 5, JUMPSS = 6, CALLSS = 8 };private: /** * Print the name of a register. */ static void printRegister(FILE* f, unsigned registerNumber); /** * Print a comparison operator */ static void printComparison(FILE* f, cmpOp_t cmpOp); /** * Print a button highlight clause */ static void printHighlightButton(FILE* f, unsigned button); /** * Print a condition. */ static bool printCondition(FILE* f, cmpOp_t cmpOp, unsigned value1, bool isDirect2, unsigned value2);public: unsigned char _set : 4; unsigned char direct : 1; unsigned char type : 3; unsigned char cmd : 4; unsigned char cmp : 3; unsigned char dircmp : 1; Operand1 operand1; Operand2 operand2; Operand3 operand3;public: /** * Get the type. */ type_t getType() const; /** * Get if the instruction is direct or not */ bool isDirect() const; /** * Get the set type */ setType_t getSetType() const; /** * Get the set operator */ setOp_t getSetOp() const; /** * Get if the second argument of a comparison is direct or not */ bool isCmpDirect() const; /** * Get the comparison operator. */ cmpOp_t getCmpOp() const; /** * Get the special command. */ specCmd_t getSpecCmd() const; /** * Get the link command. */ linkCmd_t getLinkCmd() const; /** * Get the jump/call command. */ jumpCallCmd_t getJumpCallCmd() const; /** * Get the CR1 value. */ unsigned getCR1() const; /** * Get the SRD value. */ unsigned getSRD() const; /** * Print the instruction as a sequence of hexadecimal numbers */ void printHex(FILE* f) const; /** * Print the instruction as an assembly instruction. */ void printAssembly(FILE* f) const;private: /** * Print the instruction as a special instruction. */ void printSpecial(FILE* f) const; /** * Print the instruction as a branching instruction. */ void printBranch(FILE* f) const; /** * Print the instruction as a link instruction w/o the condition */ void printLinkUnconditionally(FILE* f) const; /** * Print the instruction as a link instruction. */ void printLink(FILE* f) const; /** * Print the link subset part of the instruction. */ void printLinkSubset(FILE* f) const; /** * Print the instruction as a jump/call instruction. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -