diff options
| author | Jesse Talavera-Greenberg <jesse@jesse.tg> | 2023-11-09 15:54:51 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-09 21:54:51 +0100 | 
| commit | 4558be0d8eb79d276c89392b9410e6edb649db95 (patch) | |
| tree | 3e2b37e31b38337adec64c5391e57ddf45af5d23 /src/GPU2D.cpp | |
| parent | 88072a02c523e26390af6bd726608b3e567f996f (diff) | |
Refactor the GPU to be object-oriented (#1873)
* Refactor GPU3D to be an object
- Who has two thumbs and is the sworn enemy of global state? This guy!
* Refactor GPU itself to be an object
- Wow, it's used in a lot of places
- Also introduce a new `Melon` namespace for a few classes
- I expect other classes will be moved into `Melon` over time
* Change signature of Renderer3D::SetRenderSettings
- Make it noexcept, and its argument const
* Remove some stray whitespace
Diffstat (limited to 'src/GPU2D.cpp')
| -rw-r--r-- | src/GPU2D.cpp | 49 | 
1 files changed, 24 insertions, 25 deletions
| diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index d1f6beb..e892116 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -85,9 +85,8 @@ using Platform::LogLevel;  namespace GPU2D  { -Unit::Unit(u32 num) +Unit::Unit(u32 num, Melon::GPU& gpu) : Num(num), GPU(gpu)  { -    Num = num;  }  void Unit::Reset() @@ -287,10 +286,10 @@ void Unit::Write8(u32 addr, u8 val)          return;      case 0x10: -        if (!Num) GPU3D::SetRenderXPos((GPU3D::RenderXPos & 0xFF00) | val); +        if (!Num) GPU.GPU3D.SetRenderXPos((GPU.GPU3D.GetRenderXPos() & 0xFF00) | val);          break;      case 0x11: -        if (!Num) GPU3D::SetRenderXPos((GPU3D::RenderXPos & 0x00FF) | (val << 8)); +        if (!Num) GPU.GPU3D.SetRenderXPos((GPU.GPU3D.GetRenderXPos() & 0x00FF) | (val << 8));          break;      } @@ -383,7 +382,7 @@ void Unit::Write16(u32 addr, u16 val)          return;      case 0x010: -        if (!Num) GPU3D::SetRenderXPos(val); +        if (!Num) GPU.GPU3D.SetRenderXPos(val);          break;      case 0x068: @@ -422,21 +421,21 @@ void Unit::Write16(u32 addr, u16 val)      case 0x026: BGRotD[0] = val; return;      case 0x028:          BGXRef[0] = (BGXRef[0] & 0xFFFF0000) | val; -        if (GPU::VCount < 192) BGXRefInternal[0] = BGXRef[0]; +        if (GPU.VCount < 192) BGXRefInternal[0] = BGXRef[0];          return;      case 0x02A:          if (val & 0x0800) val |= 0xF000;          BGXRef[0] = (BGXRef[0] & 0xFFFF) | (val << 16); -        if (GPU::VCount < 192) BGXRefInternal[0] = BGXRef[0]; +        if (GPU.VCount < 192) BGXRefInternal[0] = BGXRef[0];          return;      case 0x02C:          BGYRef[0] = (BGYRef[0] & 0xFFFF0000) | val; -        if (GPU::VCount < 192) BGYRefInternal[0] = BGYRef[0]; +        if (GPU.VCount < 192) BGYRefInternal[0] = BGYRef[0];          return;      case 0x02E:          if (val & 0x0800) val |= 0xF000;          BGYRef[0] = (BGYRef[0] & 0xFFFF) | (val << 16); -        if (GPU::VCount < 192) BGYRefInternal[0] = BGYRef[0]; +        if (GPU.VCount < 192) BGYRefInternal[0] = BGYRef[0];          return;      case 0x030: BGRotA[1] = val; return; @@ -445,21 +444,21 @@ void Unit::Write16(u32 addr, u16 val)      case 0x036: BGRotD[1] = val; return;      case 0x038:          BGXRef[1] = (BGXRef[1] & 0xFFFF0000) | val; -        if (GPU::VCount < 192) BGXRefInternal[1] = BGXRef[1]; +        if (GPU.VCount < 192) BGXRefInternal[1] = BGXRef[1];          return;      case 0x03A:          if (val & 0x0800) val |= 0xF000;          BGXRef[1] = (BGXRef[1] & 0xFFFF) | (val << 16); -        if (GPU::VCount < 192) BGXRefInternal[1] = BGXRef[1]; +        if (GPU.VCount < 192) BGXRefInternal[1] = BGXRef[1];          return;      case 0x03C:          BGYRef[1] = (BGYRef[1] & 0xFFFF0000) | val; -        if (GPU::VCount < 192) BGYRefInternal[1] = BGYRef[1]; +        if (GPU.VCount < 192) BGYRefInternal[1] = BGYRef[1];          return;      case 0x03E:          if (val & 0x0800) val |= 0xF000;          BGYRef[1] = (BGYRef[1] & 0xFFFF) | (val << 16); -        if (GPU::VCount < 192) BGYRefInternal[1] = BGYRef[1]; +        if (GPU.VCount < 192) BGYRefInternal[1] = BGYRef[1];          return;      case 0x040: @@ -541,23 +540,23 @@ void Unit::Write32(u32 addr, u32 val)          case 0x028:              if (val & 0x08000000) val |= 0xF0000000;              BGXRef[0] = val; -            if (GPU::VCount < 192) BGXRefInternal[0] = BGXRef[0]; +            if (GPU.VCount < 192) BGXRefInternal[0] = BGXRef[0];              return;          case 0x02C:              if (val & 0x08000000) val |= 0xF0000000;              BGYRef[0] = val; -            if (GPU::VCount < 192) BGYRefInternal[0] = BGYRef[0]; +            if (GPU.VCount < 192) BGYRefInternal[0] = BGYRef[0];              return;          case 0x038:              if (val & 0x08000000) val |= 0xF0000000;              BGXRef[1] = val; -            if (GPU::VCount < 192) BGXRefInternal[1] = BGXRef[1]; +            if (GPU.VCount < 192) BGXRefInternal[1] = BGXRef[1];              return;          case 0x03C:              if (val & 0x08000000) val |= 0xF0000000;              BGYRef[1] = val; -            if (GPU::VCount < 192) BGYRefInternal[1] = BGYRef[1]; +            if (GPU.VCount < 192) BGYRefInternal[1] = BGYRef[1];              return;          }      } @@ -628,15 +627,15 @@ u16* Unit::GetBGExtPal(u32 slot, u32 pal)      const u32 PaletteSize = 256 * 2;      const u32 SlotSize = PaletteSize * 16;      return (u16*)&(Num == 0 -         ? GPU::VRAMFlat_ABGExtPal -         : GPU::VRAMFlat_BBGExtPal)[slot * SlotSize + pal * PaletteSize]; +         ? GPU.VRAMFlat_ABGExtPal +         : GPU.VRAMFlat_BBGExtPal)[slot * SlotSize + pal * PaletteSize];  }  u16* Unit::GetOBJExtPal()  {      return Num == 0 -         ? (u16*)GPU::VRAMFlat_AOBJExtPal -         : (u16*)GPU::VRAMFlat_BOBJExtPal; +         ? (u16*)GPU.VRAMFlat_AOBJExtPal +         : (u16*)GPU.VRAMFlat_BOBJExtPal;  }  void Unit::CheckWindows(u32 line) @@ -698,12 +697,12 @@ void Unit::GetBGVRAM(u8*& data, u32& mask)  {      if (Num == 0)      { -        data = GPU::VRAMFlat_ABG; +        data = GPU.VRAMFlat_ABG;          mask = 0x7FFFF;      }      else      { -        data = GPU::VRAMFlat_BBG; +        data = GPU.VRAMFlat_BBG;          mask = 0x1FFFF;      }  } @@ -712,12 +711,12 @@ void Unit::GetOBJVRAM(u8*& data, u32& mask)  {      if (Num == 0)      { -        data = GPU::VRAMFlat_AOBJ; +        data = GPU.VRAMFlat_AOBJ;          mask = 0x3FFFF;      }      else      { -        data = GPU::VRAMFlat_BOBJ; +        data = GPU.VRAMFlat_BOBJ;          mask = 0x1FFFF;      }  } |