1 /* 2 * This file is part of libsidplayfp, a SID player engine. 3 * 4 * Copyright 2011-2019 Leandro Nini <drfiemost@users.sourceforge.net> 5 * Copyright 2007-2010 Antti Lankila 6 * Copyright 2000 Simon White 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef FLAGS_H 24 #define FLAGS_H 25 26 #include <stdint.h> 27 28 namespace libsidplayfp 29 { 30 31 /** 32 * Processor Status Register 33 */ 34 class Flags 35 { 36 private: 37 bool C; ///< Carry 38 bool Z; ///< Zero 39 bool I; ///< Interrupt disabled 40 bool D; ///< Decimal 41 bool V; ///< Overflow 42 bool N; ///< Negative 43 44 public: reset()45 inline void reset() 46 { 47 C = Z = I = D = V = N = false; 48 } 49 50 /** 51 * Set N and Z flag values. 52 * 53 * @param value to set flags from 54 */ setNZ(uint8_t value)55 inline void setNZ(uint8_t value) 56 { 57 Z = value == 0; 58 N = value & 0x80; 59 } 60 61 /** 62 * Get status register value. 63 */ get()64 inline uint8_t get() 65 { 66 uint8_t sr = 0; 67 68 if (C) sr |= 0x01; 69 if (Z) sr |= 0x02; 70 if (I) sr |= 0x04; 71 if (D) sr |= 0x08; 72 if (V) sr |= 0x40; 73 if (N) sr |= 0x80; 74 75 return sr; 76 } 77 78 /** 79 * Set status register value. 80 */ set(uint8_t sr)81 inline void set(uint8_t sr) 82 { 83 C = sr & 0x01; 84 Z = sr & 0x02; 85 I = sr & 0x04; 86 D = sr & 0x08; 87 V = sr & 0x40; 88 N = sr & 0x80; 89 } 90 getN()91 inline bool getN() const { return N; } getC()92 inline bool getC() const { return C; } getD()93 inline bool getD() const { return D; } getZ()94 inline bool getZ() const { return Z; } getV()95 inline bool getV() const { return V; } getI()96 inline bool getI() const { return I; } 97 setN(bool f)98 inline void setN(bool f) { N = f; } setC(bool f)99 inline void setC(bool f) { C = f; } setD(bool f)100 inline void setD(bool f) { D = f; } setZ(bool f)101 inline void setZ(bool f) { Z = f; } setV(bool f)102 inline void setV(bool f) { V = f; } setI(bool f)103 inline void setI(bool f) { I = f; } 104 }; 105 106 } 107 108 #endif 109