rework FIFO crap so it can also be used for the GXFIFO crapo.
This commit is contained in:
parent
0562410de2
commit
2b7fac05c7
72
FIFO.cpp
72
FIFO.cpp
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2017 StapleButter
|
||||
|
||||
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/.
|
||||
*/
|
||||
|
||||
#include "FIFO.h"
|
||||
|
||||
|
||||
FIFO::FIFO(u32 num)
|
||||
{
|
||||
NumEntries = num;
|
||||
Entries = new u32[num];
|
||||
Clear();
|
||||
}
|
||||
|
||||
FIFO::~FIFO()
|
||||
{
|
||||
delete[] Entries;
|
||||
}
|
||||
|
||||
void FIFO::Clear()
|
||||
{
|
||||
NumOccupied = 0;
|
||||
ReadPos = 0;
|
||||
WritePos = 0;
|
||||
Entries[ReadPos] = 0;
|
||||
}
|
||||
|
||||
void FIFO::Write(u32 val)
|
||||
{
|
||||
if (IsFull()) return;
|
||||
|
||||
Entries[WritePos] = val;
|
||||
|
||||
WritePos++;
|
||||
if (WritePos >= NumEntries)
|
||||
WritePos = 0;
|
||||
|
||||
NumOccupied++;
|
||||
}
|
||||
|
||||
u32 FIFO::Read()
|
||||
{
|
||||
u32 ret = Entries[ReadPos];
|
||||
if (IsEmpty())
|
||||
return ret;
|
||||
|
||||
ReadPos++;
|
||||
if (ReadPos >= NumEntries)
|
||||
ReadPos = 0;
|
||||
|
||||
NumOccupied--;
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 FIFO::Peek()
|
||||
{
|
||||
return Entries[ReadPos];
|
||||
}
|
60
FIFO.h
60
FIFO.h
|
@ -21,17 +21,63 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
template<typename T>
|
||||
class FIFO
|
||||
{
|
||||
public:
|
||||
FIFO(u32 num);
|
||||
~FIFO();
|
||||
FIFO(u32 num)
|
||||
{
|
||||
NumEntries = num;
|
||||
Entries = new T[num];
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear();
|
||||
~FIFO()
|
||||
{
|
||||
delete[] Entries;
|
||||
}
|
||||
|
||||
void Write(u32 val);
|
||||
u32 Read();
|
||||
u32 Peek();
|
||||
|
||||
void Clear()
|
||||
{
|
||||
NumOccupied = 0;
|
||||
ReadPos = 0;
|
||||
WritePos = 0;
|
||||
memset(&Entries[ReadPos], 0, sizeof(T));
|
||||
}
|
||||
|
||||
|
||||
void Write(u32 val)
|
||||
{
|
||||
if (IsFull()) return;
|
||||
|
||||
Entries[WritePos] = val;
|
||||
|
||||
WritePos++;
|
||||
if (WritePos >= NumEntries)
|
||||
WritePos = 0;
|
||||
|
||||
NumOccupied++;
|
||||
}
|
||||
|
||||
T Read()
|
||||
{
|
||||
T ret = Entries[ReadPos];
|
||||
if (IsEmpty())
|
||||
return ret;
|
||||
|
||||
ReadPos++;
|
||||
if (ReadPos >= NumEntries)
|
||||
ReadPos = 0;
|
||||
|
||||
NumOccupied--;
|
||||
return ret;
|
||||
}
|
||||
|
||||
T Peek()
|
||||
{
|
||||
return Entries[ReadPos];
|
||||
}
|
||||
|
||||
u32 Level() { return NumOccupied; }
|
||||
bool IsEmpty() { return NumOccupied == 0; }
|
||||
|
@ -39,7 +85,7 @@ public:
|
|||
|
||||
private:
|
||||
u32 NumEntries;
|
||||
u32* Entries;
|
||||
T* Entries;
|
||||
u32 NumOccupied;
|
||||
u32 ReadPos, WritePos;
|
||||
};
|
||||
|
|
21
GPU3D.cpp
21
GPU3D.cpp
|
@ -20,24 +20,41 @@
|
|||
#include <string.h>
|
||||
#include "NDS.h"
|
||||
#include "GPU.h"
|
||||
#include "FIFO.h"
|
||||
|
||||
|
||||
namespace GPU3D
|
||||
{
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 Command;
|
||||
u32 Param;
|
||||
|
||||
} CmdFIFOEntry;
|
||||
|
||||
FIFO<CmdFIFOEntry>* CmdFIFO;
|
||||
FIFO<CmdFIFOEntry>* CmdPIPE;
|
||||
|
||||
|
||||
bool Init()
|
||||
{
|
||||
CmdFIFO = new FIFO<CmdFIFOEntry>(256);
|
||||
CmdPIPE = new FIFO<CmdFIFOEntry>(4);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeInit()
|
||||
{
|
||||
//
|
||||
delete CmdFIFO;
|
||||
delete CmdPIPE;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
//
|
||||
CmdFIFO->Clear();
|
||||
CmdPIPE->Clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
8
NDS.cpp
8
NDS.cpp
|
@ -91,8 +91,8 @@ u32 DMA9Fill[4];
|
|||
|
||||
u16 IPCSync9, IPCSync7;
|
||||
u16 IPCFIFOCnt9, IPCFIFOCnt7;
|
||||
FIFO* IPCFIFO9; // FIFO in which the ARM9 writes
|
||||
FIFO* IPCFIFO7;
|
||||
FIFO<u32>* IPCFIFO9; // FIFO in which the ARM9 writes
|
||||
FIFO<u32>* IPCFIFO7;
|
||||
|
||||
u16 DivCnt;
|
||||
u32 DivNumerator[2];
|
||||
|
@ -125,8 +125,8 @@ bool Init()
|
|||
DMAs[6] = new DMA(1, 2);
|
||||
DMAs[7] = new DMA(1, 3);
|
||||
|
||||
IPCFIFO9 = new FIFO(16);
|
||||
IPCFIFO7 = new FIFO(16);
|
||||
IPCFIFO9 = new FIFO<u32>(16);
|
||||
IPCFIFO7 = new FIFO<u32>(16);
|
||||
|
||||
if (!NDSCart::Init()) return false;
|
||||
if (!GPU::Init()) return false;
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
<Unit filename="CP15.h" />
|
||||
<Unit filename="DMA.cpp" />
|
||||
<Unit filename="DMA.h" />
|
||||
<Unit filename="FIFO.cpp" />
|
||||
<Unit filename="FIFO.h" />
|
||||
<Unit filename="GPU.cpp" />
|
||||
<Unit filename="GPU.h" />
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
1481161027 c:\documents\sources\melonds\types.h
|
||||
|
||||
1486502137 source:c:\documents\sources\melonds\nds.cpp
|
||||
1486503537 source:c:\documents\sources\melonds\nds.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
|
@ -80,7 +80,7 @@
|
|||
|
||||
1486502258 c:\documents\sources\melonds\spi.h
|
||||
|
||||
1486163389 source:c:\documents\sources\melonds\spi.cpp
|
||||
1486502498 source:c:\documents\sources\melonds\spi.cpp
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
"NDS.h"
|
||||
|
@ -105,7 +105,7 @@
|
|||
1486501225 source:c:\documents\sources\melonds\fifo.cpp
|
||||
"FIFO.h"
|
||||
|
||||
1486501199 c:\documents\sources\melonds\fifo.h
|
||||
1486503492 c:\documents\sources\melonds\fifo.h
|
||||
"types.h"
|
||||
|
||||
1486309616 source:c:\documents\sources\melonds\dma.cpp
|
||||
|
|
Loading…
Reference in New Issue