cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

SixteenBitRegister.h (2147B)


      1/*
      2 * Gearboy - Nintendo Game Boy Emulator
      3 * Copyright (C) 2012  Ignacio Sanchez
      4
      5 * This program is free software: you can redistribute it and/or modify
      6 * it under the terms of the GNU General Public License as published by
      7 * the Free Software Foundation, either version 3 of the License, or
      8 * any later version.
      9
     10 * This program is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 * GNU General Public License for more details.
     14
     15 * You should have received a copy of the GNU General Public License
     16 * along with this program.  If not, see http://www.gnu.org/licenses/ 
     17 * 
     18 */
     19
     20#ifndef SIXTEENBITREGISTER_H
     21#define	SIXTEENBITREGISTER_H
     22
     23#include "definitions.h"
     24
     25class SixteenBitRegister
     26{
     27public:
     28    SixteenBitRegister() { }
     29    void SetLow(u8 low);
     30    u8 GetLow() const;
     31    void SetHigh(u8 high);
     32    u8 GetHigh() const;
     33    u8* GetHighRegister();
     34    u8* GetLowRegister();
     35    void SetValue(u16 value);
     36    u16 GetValue() const;
     37    void Increment();
     38    void Decrement();
     39
     40private:
     41    union sixteenBit
     42    {
     43        u16 v;
     44        struct 
     45        {
     46#ifdef IS_LITTLE_ENDIAN
     47            uint8_t low;
     48            uint8_t high;
     49#else
     50            uint8_t high;
     51            uint8_t low;
     52#endif
     53        };
     54    } m_Value;
     55};
     56
     57
     58inline void SixteenBitRegister::SetLow(u8 low)
     59{
     60    m_Value.low = low;
     61}
     62
     63inline u8 SixteenBitRegister::GetLow() const
     64{
     65    return m_Value.low;
     66}
     67
     68inline void SixteenBitRegister::SetHigh(u8 high)
     69{
     70    m_Value.high = high;
     71}
     72
     73inline u8 SixteenBitRegister::GetHigh() const
     74{
     75    return m_Value.high;
     76}
     77
     78inline u8* SixteenBitRegister::GetHighRegister()
     79{
     80    return &m_Value.high;
     81}
     82
     83inline u8* SixteenBitRegister::GetLowRegister()
     84{
     85    return &m_Value.low;
     86}
     87
     88inline void SixteenBitRegister::SetValue(u16 value)
     89{
     90    m_Value.v = value;
     91}
     92
     93inline u16 SixteenBitRegister::GetValue() const
     94{
     95    return m_Value.v;
     96}
     97
     98inline void SixteenBitRegister::Increment()
     99{
    100    m_Value.v++;
    101}
    102
    103inline void SixteenBitRegister::Decrement()
    104{
    105    m_Value.v--;
    106}
    107
    108#endif	/* SIXTEENBITREGISTER_H */
    109