diff --git a/desmume/src/FIFO.c b/desmume/src/FIFO.c new file mode 100644 index 000000000..ef299ad99 --- /dev/null +++ b/desmume/src/FIFO.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + This file is part of DeSmuME + + DeSmuME 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 2 of the License, or + (at your option) any later version. + + DeSmuME 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 DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "FIFO.h" + +void FIFOInit(FIFO * fifo) +{ + unsigned long i; + + fifo->begin = 0; + fifo->end = 0; + for(i = 0; i<0x2000; ++i) + fifo->data[i] = 0; + fifo->full = FALSE; + fifo->empty = TRUE; + fifo->error = FALSE; +} + +void FIFOAdd(FIFO * fifo, unsigned long v) +{ + if(fifo->full) + { + fifo->error = TRUE; + return; + } + fifo->data[fifo->end] = v; + fifo->end = (fifo->end + 1)& 0x1FFF; + fifo->full = (fifo->end == fifo->begin); + fifo->empty = FALSE; +} + +unsigned long FIFOValue(FIFO * fifo) +{ + if(fifo->empty) + { + fifo->error = TRUE; + return 0; + } + unsigned long v = fifo->data[fifo->begin]; + fifo->begin = (fifo->begin + 1)& 0x1FFF; + fifo->empty = (fifo->begin == fifo->end); + return v; +} diff --git a/desmume/src/FIFO.h b/desmume/src/FIFO.h new file mode 100644 index 000000000..2fa05277e --- /dev/null +++ b/desmume/src/FIFO.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + This file is part of DeSmuME + + DeSmuME 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 2 of the License, or + (at your option) any later version. + + DeSmuME 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 DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef FIFO_H +#define FIFO_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + unsigned long data[0x2000]; + unsigned long begin; + unsigned long end; + BOOL full; + BOOL empty; + BOOL error; +} FIFO; + +void FIFOInit(FIFO * fifo); +void FIFOAdd(FIFO * fifo, unsigned long v); +unsigned long FIFOValue(FIFO * fifo); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/desmume/src/Makefile.am b/desmume/src/Makefile.am index 41f71e4d6..5ac336049 100644 --- a/desmume/src/Makefile.am +++ b/desmume/src/Makefile.am @@ -5,7 +5,7 @@ libdesmume_a_SOURCES = \ arm_instructions.cpp arm_instructions.hpp \ bios.cpp bios.hpp cp15.cpp cp15.hpp \ Disassembler.cpp Disassembler.hpp \ - FIFO.cpp FIFO.hpp \ + FIFO.c FIFO.h \ GPU.cpp GPU.hpp debug.c debug.h \ MMU.cpp MMU.hpp NDSSystem.cpp NDSSystem.hpp \ thumb_instructions.cpp thumb_instructions.hpp