diff --git a/FIFO.cpp b/FIFO.cpp deleted file mode 100644 index e8525eb3..00000000 --- a/FIFO.cpp +++ /dev/null @@ -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]; -} diff --git a/FIFO.h b/FIFO.h index 98f00793..b0f4182c 100644 --- a/FIFO.h +++ b/FIFO.h @@ -21,17 +21,63 @@ #include "types.h" +template 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; }; diff --git a/GPU3D.cpp b/GPU3D.cpp index c4b7ee89..81b27058 100644 --- a/GPU3D.cpp +++ b/GPU3D.cpp @@ -20,24 +20,41 @@ #include #include "NDS.h" #include "GPU.h" +#include "FIFO.h" namespace GPU3D { +typedef struct +{ + u8 Command; + u32 Param; + +} CmdFIFOEntry; + +FIFO* CmdFIFO; +FIFO* CmdPIPE; + + bool Init() { + CmdFIFO = new FIFO(256); + CmdPIPE = new FIFO(4); + return true; } void DeInit() { - // + delete CmdFIFO; + delete CmdPIPE; } void Reset() { - // + CmdFIFO->Clear(); + CmdPIPE->Clear(); } } diff --git a/NDS.cpp b/NDS.cpp index b2d51ca7..6761e047 100644 --- a/NDS.cpp +++ b/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* IPCFIFO9; // FIFO in which the ARM9 writes +FIFO* 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(16); + IPCFIFO7 = new FIFO(16); if (!NDSCart::Init()) return false; if (!GPU::Init()) return false; diff --git a/melonDS.cbp b/melonDS.cbp index 702a9a8c..fb32d8b7 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -51,7 +51,6 @@ - diff --git a/melonDS.depend b/melonDS.depend index cce24162..9c8795b3 100644 --- a/melonDS.depend +++ b/melonDS.depend @@ -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 "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 "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