2016-12-05 10:02:29 -07:00
|
|
|
/*
|
2024-06-15 09:01:19 -06:00
|
|
|
Copyright 2016-2024 melonDS team
|
2016-12-05 10:02:29 -07:00
|
|
|
|
|
|
|
This file is part of melonDS.
|
|
|
|
|
|
|
|
melonDS 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 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GPU2D_H
|
|
|
|
#define GPU2D_H
|
|
|
|
|
2020-12-06 09:40:16 -07:00
|
|
|
#include "types.h"
|
|
|
|
#include "Savestate.h"
|
|
|
|
|
2023-11-25 10:32:09 -07:00
|
|
|
namespace melonDS
|
2023-11-09 13:54:51 -07:00
|
|
|
{
|
|
|
|
class GPU;
|
|
|
|
|
2021-02-27 14:25:27 -07:00
|
|
|
namespace GPU2D
|
|
|
|
{
|
|
|
|
|
|
|
|
class Unit
|
2016-12-05 10:02:29 -07:00
|
|
|
{
|
2017-01-17 20:03:19 -07:00
|
|
|
public:
|
2023-11-09 13:54:51 -07:00
|
|
|
// take a reference to the GPU so we can access its state
|
|
|
|
// and ensure that it's not null
|
2023-11-25 10:32:09 -07:00
|
|
|
Unit(u32 num, melonDS::GPU& gpu);
|
2023-11-29 07:23:11 -07:00
|
|
|
virtual ~Unit() = default;
|
2021-02-27 14:25:27 -07:00
|
|
|
Unit(const Unit&) = delete;
|
|
|
|
Unit& operator=(const Unit&) = delete;
|
2021-02-09 15:38:51 -07:00
|
|
|
|
2017-01-17 20:03:19 -07:00
|
|
|
void Reset();
|
2016-12-05 15:17:03 -07:00
|
|
|
|
2018-10-17 18:31:01 -06:00
|
|
|
void DoSavestate(Savestate* file);
|
|
|
|
|
2018-12-18 09:04:42 -07:00
|
|
|
void SetEnabled(bool enable) { Enabled = enable; }
|
2016-12-05 15:17:03 -07:00
|
|
|
|
2017-01-17 20:03:19 -07:00
|
|
|
u8 Read8(u32 addr);
|
|
|
|
u16 Read16(u32 addr);
|
|
|
|
u32 Read32(u32 addr);
|
|
|
|
void Write8(u32 addr, u8 val);
|
|
|
|
void Write16(u32 addr, u16 val);
|
|
|
|
void Write32(u32 addr, u32 val);
|
2016-12-05 15:17:03 -07:00
|
|
|
|
2023-12-12 03:07:22 -07:00
|
|
|
bool UsesFIFO() const
|
2017-06-26 03:02:10 -06:00
|
|
|
{
|
|
|
|
if (((DispCnt >> 16) & 0x3) == 3)
|
|
|
|
return true;
|
|
|
|
if ((CaptureCnt & (1<<25)) && ((CaptureCnt >> 29) & 0x3) != 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleFIFO(u32 offset, u32 num);
|
|
|
|
|
2017-02-10 07:24:46 -07:00
|
|
|
void VBlank();
|
2020-12-06 09:40:16 -07:00
|
|
|
virtual void VBlankEnd();
|
2016-12-06 09:32:51 -07:00
|
|
|
|
2017-04-08 19:35:32 -06:00
|
|
|
void CheckWindows(u32 line);
|
|
|
|
|
2017-02-27 13:26:11 -07:00
|
|
|
u16* GetBGExtPal(u32 slot, u32 pal);
|
2019-09-05 03:42:08 -06:00
|
|
|
u16* GetOBJExtPal();
|
2017-02-27 13:26:11 -07:00
|
|
|
|
2023-12-12 03:07:22 -07:00
|
|
|
void GetBGVRAM(u8*& data, u32& mask) const;
|
|
|
|
void GetOBJVRAM(u8*& data, u32& mask) const;
|
2020-12-06 09:40:16 -07:00
|
|
|
|
2021-02-27 14:25:27 -07:00
|
|
|
void UpdateMosaicCounters(u32 line);
|
2023-12-12 03:07:22 -07:00
|
|
|
void CalculateWindowMask(u32 line, u8* windowMask, const u8* objWindow);
|
2021-02-27 14:25:27 -07:00
|
|
|
|
2017-01-17 20:03:19 -07:00
|
|
|
u32 Num;
|
2018-12-18 09:04:42 -07:00
|
|
|
bool Enabled;
|
2017-01-18 09:57:12 -07:00
|
|
|
|
2017-06-26 03:02:10 -06:00
|
|
|
u16 DispFIFO[16];
|
|
|
|
u32 DispFIFOReadPtr;
|
|
|
|
u32 DispFIFOWritePtr;
|
|
|
|
|
2017-03-20 15:18:35 -06:00
|
|
|
u16 DispFIFOBuffer[256];
|
|
|
|
|
2017-01-18 09:57:12 -07:00
|
|
|
u32 DispCnt;
|
|
|
|
u16 BGCnt[4];
|
|
|
|
|
2017-01-20 07:27:56 -07:00
|
|
|
u16 BGXPos[4];
|
|
|
|
u16 BGYPos[4];
|
|
|
|
|
2017-03-03 18:22:58 -07:00
|
|
|
s32 BGXRef[2];
|
|
|
|
s32 BGYRef[2];
|
|
|
|
s32 BGXRefInternal[2];
|
|
|
|
s32 BGYRefInternal[2];
|
2017-02-01 17:18:03 -07:00
|
|
|
s16 BGRotA[2];
|
|
|
|
s16 BGRotB[2];
|
|
|
|
s16 BGRotC[2];
|
|
|
|
s16 BGRotD[2];
|
|
|
|
|
2017-04-08 19:35:32 -06:00
|
|
|
u8 Win0Coords[4];
|
|
|
|
u8 Win1Coords[4];
|
|
|
|
u8 WinCnt[4];
|
2018-11-25 11:13:23 -07:00
|
|
|
u32 Win0Active;
|
|
|
|
u32 Win1Active;
|
2017-04-08 19:35:32 -06:00
|
|
|
|
2017-07-23 07:31:09 -06:00
|
|
|
u8 BGMosaicSize[2];
|
|
|
|
u8 OBJMosaicSize[2];
|
2017-07-23 10:36:00 -06:00
|
|
|
u8 BGMosaicY, BGMosaicYMax;
|
2019-09-14 17:31:09 -06:00
|
|
|
u8 OBJMosaicYCount, OBJMosaicY, OBJMosaicYMax;
|
|
|
|
|
2017-03-02 11:00:19 -07:00
|
|
|
u16 BlendCnt;
|
2017-07-15 19:47:44 -06:00
|
|
|
u16 BlendAlpha;
|
2017-03-01 13:42:06 -07:00
|
|
|
u8 EVA, EVB;
|
|
|
|
u8 EVY;
|
|
|
|
|
2020-12-09 14:45:16 -07:00
|
|
|
bool CaptureLatch;
|
2017-03-01 13:42:06 -07:00
|
|
|
u32 CaptureCnt;
|
2017-01-20 19:36:14 -07:00
|
|
|
|
2017-03-01 12:23:41 -07:00
|
|
|
u16 MasterBrightness;
|
2023-11-09 13:54:51 -07:00
|
|
|
private:
|
2023-11-25 10:32:09 -07:00
|
|
|
melonDS::GPU& GPU;
|
2021-02-27 14:25:27 -07:00
|
|
|
};
|
2017-03-01 12:23:41 -07:00
|
|
|
|
2021-02-27 14:25:27 -07:00
|
|
|
class Renderer2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Renderer2D() {}
|
2020-12-06 09:40:16 -07:00
|
|
|
|
2021-02-27 14:25:27 -07:00
|
|
|
virtual void DrawScanline(u32 line, Unit* unit) = 0;
|
|
|
|
virtual void DrawSprites(u32 line, Unit* unit) = 0;
|
|
|
|
|
|
|
|
virtual void VBlankEnd(Unit* unitA, Unit* unitB) = 0;
|
2020-12-06 09:40:16 -07:00
|
|
|
|
2021-02-27 14:25:27 -07:00
|
|
|
void SetFramebuffer(u32* unitA, u32* unitB)
|
|
|
|
{
|
|
|
|
Framebuffer[0] = unitA;
|
|
|
|
Framebuffer[1] = unitB;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
u32* Framebuffer[2];
|
|
|
|
|
|
|
|
Unit* CurUnit;
|
2020-12-06 09:40:16 -07:00
|
|
|
};
|
2017-02-27 13:26:11 -07:00
|
|
|
|
2021-02-27 14:25:27 -07:00
|
|
|
}
|
|
|
|
|
2023-11-25 10:32:09 -07:00
|
|
|
}
|
2016-12-05 10:02:29 -07:00
|
|
|
#endif
|