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