Browse code

Updating in_2sf to use a newish version of DeSmuME, 0.9.9 from SVN. Somewhat cleaned up as well, but not everything because it's a pain in the ass.

Naram Qashat authored on 2013/04/18 17:22:55
Showing 1 changed files
... ...
@@ -18,18 +18,14 @@
18 18
 */
19 19
 
20 20
 #include <cstring>
21
-
22 21
 #include "FIFO.h"
23 22
 #include "armcpu.h"
24
-//#include "debug.h"
25 23
 #include "mem.h"
26 24
 #include "MMU.h"
27 25
 #include "NDSSystem.h"
28
-//#include "gfx3d.h"
29 26
 
30 27
 // ========================================================= IPC FIFO
31
-IPC_FIFO ipc_fifo[2];		// 0 - ARM9
32
-							// 1 - ARM7
28
+IPC_FIFO ipc_fifo[2]; // 0 - ARM9, 1 - ARM7
33 29
 
34 30
 void IPC_FIFOinit(uint8_t proc)
35 31
 {
... ...
@@ -40,8 +36,9 @@ void IPC_FIFOinit(uint8_t proc)
40 36
 void IPC_FIFOsend(uint8_t proc, uint32_t val)
41 37
 {
42 38
 	uint16_t cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
43
-	if (!(cnt_l & IPCFIFOCNT_FIFOENABLE)) return;			// FIFO disabled
44
-	uint8_t	proc_remote = proc ^ 1;
39
+	if (!(cnt_l & IPCFIFOCNT_FIFOENABLE))
40
+		return; // FIFO disabled
41
+	uint8_t proc_remote = proc ^ 1;
45 42
 
46 43
 	if (ipc_fifo[proc].size > 15)
47 44
 	{
... ...
@@ -52,20 +49,18 @@ void IPC_FIFOsend(uint8_t proc, uint32_t val)
52 49
 
53 50
 	uint16_t cnt_r = T1ReadWord(MMU.MMU_MEM[proc_remote][0x40], 0x184);
54 51
 
55
-	//LOG("IPC%s send FIFO 0x%08X size %03i (l 0x%X, tail %02i) (r 0x%X, tail %02i)\n",
56
-	//	proc?"7":"9", val, ipc_fifo[proc].size, cnt_l, ipc_fifo[proc].tail, cnt_r, ipc_fifo[proc^1].tail);
57
-
58
-	cnt_l &= 0xBFFC;		// clear send empty bit & full
59
-	cnt_r &= 0xBCFF;		// set recv empty bit & full
52
+	cnt_l &= 0xBFFC; // clear send empty bit & full
53
+	cnt_r &= 0xBCFF; // set recv empty bit & full
60 54
 	ipc_fifo[proc].buf[ipc_fifo[proc].tail] = val;
61
-	ipc_fifo[proc].tail++;
62
-	ipc_fifo[proc].size++;
63
-	if (ipc_fifo[proc].tail > 15) ipc_fifo[proc].tail = 0;
55
+	++ipc_fifo[proc].tail;
56
+	++ipc_fifo[proc].size;
57
+	if (ipc_fifo[proc].tail > 15)
58
+		ipc_fifo[proc].tail = 0;
64 59
 
65 60
 	if (ipc_fifo[proc].size > 15)
66 61
 	{
67
-		cnt_l |= IPCFIFOCNT_SENDFULL;		// set send full bit
68
-		cnt_r |= IPCFIFOCNT_RECVFULL;		// set recv full bit
62
+		cnt_l |= IPCFIFOCNT_SENDFULL; // set send full bit
63
+		cnt_r |= IPCFIFOCNT_RECVFULL; // set recv full bit
69 64
 	}
70 65
 
71 66
 	T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
... ...
@@ -80,12 +75,13 @@ void IPC_FIFOsend(uint8_t proc, uint32_t val)
80 75
 uint32_t IPC_FIFOrecv(uint8_t proc)
81 76
 {
82 77
 	uint16_t cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
83
-	if (!(cnt_l & IPCFIFOCNT_FIFOENABLE)) return 0;									// FIFO disabled
84
-	uint8_t	proc_remote = proc ^ 1;
78
+	if (!(cnt_l & IPCFIFOCNT_FIFOENABLE))
79
+		return 0; // FIFO disabled
80
+	uint8_t proc_remote = proc ^ 1;
85 81
 
86 82
 	uint32_t val = 0;
87 83
 
88
-	if ( ipc_fifo[proc_remote].size == 0 )		// remote FIFO error
84
+	if (!ipc_fifo[proc_remote].size) // remote FIFO error
89 85
 	{
90 86
 		cnt_l |= IPCFIFOCNT_FIFOERROR;
91 87
 		T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
... ...
@@ -94,19 +90,16 @@ uint32_t IPC_FIFOrecv(uint8_t proc)
94 90
 
95 91
 	uint16_t cnt_r = T1ReadWord(MMU.MMU_MEM[proc_remote][0x40], 0x184);
96 92
 
97
-	cnt_l &= 0xBCFF;		// clear send full bit & empty
98
-	cnt_r &= 0xBFFC;		// set recv full bit & empty
93
+	cnt_l &= 0xBCFF; // clear send full bit & empty
94
+	cnt_r &= 0xBFFC; // set recv full bit & empty
99 95
 
100 96
 	val = ipc_fifo[proc_remote].buf[ipc_fifo[proc_remote].head];
101
-	ipc_fifo[proc_remote].head++;
102
-	ipc_fifo[proc_remote].size--;
103
-	if (ipc_fifo[proc_remote].head > 15) ipc_fifo[proc_remote].head = 0;
104
-
105
-	//LOG("IPC%s recv FIFO 0x%08X size %03i (l 0x%X, tail %02i) (r 0x%X, tail %02i)\n",
106
-	//	proc?"7":"9", val, ipc_fifo[proc].size, cnt_l, ipc_fifo[proc].tail, cnt_r, ipc_fifo[proc^1].tail);
107
-
97
+	++ipc_fifo[proc_remote].head;
98
+	--ipc_fifo[proc_remote].size;
99
+	if (ipc_fifo[proc_remote].head > 15)
100
+		ipc_fifo[proc_remote].head = 0;
108 101
 
109
-	if ( ipc_fifo[proc_remote].size == 0 )		// FIFO empty
102
+	if (!ipc_fifo[proc_remote].size) // FIFO empty
110 103
 	{
111 104
 		cnt_l |= IPCFIFOCNT_RECVEMPTY;
112 105
 		cnt_r |= IPCFIFOCNT_SENDEMPTY;
... ...
@@ -129,14 +122,14 @@ void IPC_FIFOcnt(uint8_t proc, uint16_t val)
129 122
 	uint16_t cnt_r = T1ReadWord(MMU.MMU_MEM[proc^1][0x40], 0x184);
130 123
 
131 124
 	if (val & IPCFIFOCNT_FIFOERROR)
132
-	{
133
-		//at least SPP uses this, maybe every retail game
125
+		// at least SPP uses this, maybe every retail game
134 126
 		cnt_l &= ~IPCFIFOCNT_FIFOERROR;
135
-	}
136 127
 
137 128
 	if (val & IPCFIFOCNT_SENDCLEAR)
138 129
 	{
139
-		ipc_fifo[proc].head = 0; ipc_fifo[proc].tail = 0; ipc_fifo[proc].size = 0;
130
+		ipc_fifo[proc].head = 0;
131
+		ipc_fifo[proc].tail = 0;
132
+		ipc_fifo[proc].size = 0;
140 133
 
141 134
 		cnt_l |= IPCFIFOCNT_SENDEMPTY;
142 135
 		cnt_r |= IPCFIFOCNT_RECVEMPTY;
... ...
@@ -150,159 +143,15 @@ void IPC_FIFOcnt(uint8_t proc, uint16_t val)
150 143
 
151 144
 	// IPCFIFOCNT_SENDIRQEN may have been set (and/or the fifo may have been cleared) so we may need to trigger this irq
152 145
 	// (this approach is used by libnds fifo system on occasion in fifoInternalSend, and began happening frequently for value32 with r4326)
153
-	if (cnt_l & IPCFIFOCNT_SENDIRQEN)
154
-		if (cnt_l & IPCFIFOCNT_SENDEMPTY)
155
-			NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_SENDEMPTY);
146
+	if ((cnt_l & IPCFIFOCNT_SENDIRQEN) && (cnt_l & IPCFIFOCNT_SENDEMPTY))
147
+		NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_SENDEMPTY);
156 148
 
157 149
 	// IPCFIFOCNT_RECVIRQEN may have been set so we may need to trigger this irq
158
-	if(cnt_l & IPCFIFOCNT_RECVIRQEN)
159
-		if (!(cnt_l & IPCFIFOCNT_RECVEMPTY))
160
-			NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_RECVNONEMPTY);
150
+	if ((cnt_l & IPCFIFOCNT_RECVIRQEN) && !(cnt_l & IPCFIFOCNT_RECVEMPTY))
151
+		NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_RECVNONEMPTY);
161 152
 
162 153
 	T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
163 154
 	T1WriteWord(MMU.MMU_MEM[proc^1][0x40], 0x184, cnt_r);
164 155
 
165 156
 	NDS_Reschedule();
166 157
 }
167
-
168
-// ========================================================= GFX FIFO
169
-//GFX_PIPE	gxPIPE;
170
-//GFX_FIFO	gxFIFO;
171
-
172
-/*void GFX_PIPEclear()
173
-{
174
-	gxPIPE.head = 0;
175
-	gxPIPE.tail = 0;
176
-	gxPIPE.size = 0;
177
-}*/
178
-
179
-/*void GFX_FIFOclear()
180
-{
181
-	gxFIFO.head = 0;
182
-	gxFIFO.tail = 0;
183
-	gxFIFO.size = 0;
184
-}*/
185
-
186
-/*static void GXF_FIFO_handleEvents()
187
-{
188
-	bool low = gxFIFO.size <= 127;
189
-	bool lowchange = MMU_new.gxstat.fifo_low ^ low;
190
-	MMU_new.gxstat.fifo_low = low;
191
-	if(low) triggerDma(EDMAMode_GXFifo);
192
-
193
-	bool empty = gxFIFO.size == 0;
194
-	bool emptychange = MMU_new.gxstat.fifo_empty ^ empty;
195
-	MMU_new.gxstat.fifo_empty = empty;
196
-
197
-	if(emptychange||lowchange) NDS_Reschedule();
198
-}*/
199
-
200
-/*void GFX_FIFOsend(uint8_t cmd, uint32_t param)
201
-{
202
-	if(cmd==0x41) {
203
-		//int zzz=9;
204
-	}
205
-
206
-	//INFO("gxFIFO: send 0x%02X = 0x%08X (size %03i/0x%02X) gxstat 0x%08X\n", cmd, param, gxFIFO.size, gxFIFO.size, gxstat);
207
-	//printf("fifo recv: %02X: %08X upto:%d\n",cmd,param,gxFIFO.size+1);
208
-
209
-	//TODO - WOAH ! NOT HANDLING A TOO-BIG FIFO RIGHT NOW!
210
-	//if (gxFIFO.size > 255)
211
-	//{
212
-	//	GXF_FIFO_handleEvents();
213
-	//	//NEED TO HANDLE THIS!!!!!!!!!!!!!!!!!!!!!!!!!!
214
-
215
-	//	//gxstat |= 0x08000000;			// busy
216
-	//	NDS_RescheduleGXFIFO(1);
217
-	//	//INFO("ERROR: gxFIFO is full (cmd 0x%02X = 0x%08X) (prev cmd 0x%02X = 0x%08X)\n", cmd, param, gxFIFO.cmd[255], gxFIFO.param[255]);
218
-	//	return;
219
-	//}
220
-
221
-
222
-	gxFIFO.cmd[gxFIFO.tail] = cmd;
223
-	gxFIFO.param[gxFIFO.tail] = param;
224
-	gxFIFO.tail++;
225
-	gxFIFO.size++;
226
-	if (gxFIFO.tail > HACK_GXIFO_SIZE-1) gxFIFO.tail = 0;
227
-
228
-	if(gxFIFO.size>=HACK_GXIFO_SIZE) {
229
-		printf("--FIFO FULL-- : %d\n",gxFIFO.size);
230
-	}
231
-
232
-	//gxstat |= 0x08000000;		// set busy flag
233
-
234
-	GXF_FIFO_handleEvents();
235
-
236
-	NDS_RescheduleGXFIFO(1);
237
-}*/
238
-
239
-// this function used ONLY in gxFIFO
240
-/*bool GFX_PIPErecv(uint8_t *cmd, uint32_t *param)
241
-{
242
-	//gxstat &= 0xF7FFFFFF;		// clear busy flag
243
-
244
-	if (gxFIFO.size == 0)
245
-	{
246
-		GXF_FIFO_handleEvents();
247
-		return false;
248
-	}
249
-
250
-	*cmd = gxFIFO.cmd[gxFIFO.head];
251
-	*param = gxFIFO.param[gxFIFO.head];
252
-
253
-	gxFIFO.head++;
254
-	gxFIFO.size--;
255
-	if (gxFIFO.head > HACK_GXIFO_SIZE-1) gxFIFO.head = 0;
256
-
257
-	GXF_FIFO_handleEvents();
258
-
259
-	return true;
260
-}*/
261
-
262
-/*void GFX_FIFOcnt(uint32_t val)
263
-{
264
-	////INFO("gxFIFO: write cnt 0x%08X (prev 0x%08X) FIFO size %03i PIPE size %03i\n", val, gxstat, gxFIFO.size, gxPIPE.size);
265
-
266
-	if (val & (1<<29))		// clear? (only in homebrew?)
267
-	{
268
-		GFX_PIPEclear();
269
-		GFX_FIFOclear();
270
-		return;
271
-	}
272
-
273
-	//zeromus says: what happened to clear stack?
274
-	//if (val & (1<<15))		// projection stack pointer reset
275
-	//{
276
-	//	gfx3d_ClearStack();
277
-	//	val &= 0xFFFF5FFF;		// clear reset (bit15) & stack level (bit13)
278
-	//}
279
-
280
-	T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x600, val);
281
-}*/
282
-
283
-// ========================================================= DISP FIFO
284
-//DISP_FIFO	disp_fifo;
285
-
286
-/*void DISP_FIFOinit()
287
-{
288
-	memset(&disp_fifo, 0, sizeof(DISP_FIFO));
289
-}*/
290
-
291
-/*void DISP_FIFOsend(uint32_t val)
292
-{
293
-	//INFO("DISP_FIFO send value 0x%08X (head 0x%06X, tail 0x%06X)\n", val, disp_fifo.head, disp_fifo.tail);
294
-	disp_fifo.buf[disp_fifo.tail] = val;
295
-	disp_fifo.tail++;
296
-	if (disp_fifo.tail > 0x5FFF)
297
-		disp_fifo.tail = 0;
298
-}*/
299
-
300
-/*uint32_t DISP_FIFOrecv()
301
-{
302
-	//if (disp_fifo.tail == disp_fifo.head) return 0; // FIFO is empty
303
-	uint32_t val = disp_fifo.buf[disp_fifo.head];
304
-	disp_fifo.head++;
305
-	if (disp_fifo.head > 0x5FFF)
306
-		disp_fifo.head = 0;
307
-	return val;
308
-}*/
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,308 @@
1
+/*
2
+	Copyright 2006 yopyop
3
+	Copyright 2007 shash
4
+	Copyright 2007-2012 DeSmuME team
5
+
6
+	This file is free software: you can redistribute it and/or modify
7
+	it under the terms of the GNU General Public License as published by
8
+	the Free Software Foundation, either version 2 of the License, or
9
+	(at your option) any later version.
10
+
11
+	This file is distributed in the hope that it will be useful,
12
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+	GNU General Public License for more details.
15
+
16
+	You should have received a copy of the GNU General Public License
17
+	along with the this software.  If not, see <http://www.gnu.org/licenses/>.
18
+*/
19
+
20
+#include <cstring>
21
+
22
+#include "FIFO.h"
23
+#include "armcpu.h"
24
+//#include "debug.h"
25
+#include "mem.h"
26
+#include "MMU.h"
27
+#include "NDSSystem.h"
28
+//#include "gfx3d.h"
29
+
30
+// ========================================================= IPC FIFO
31
+IPC_FIFO ipc_fifo[2];		// 0 - ARM9
32
+							// 1 - ARM7
33
+
34
+void IPC_FIFOinit(uint8_t proc)
35
+{
36
+	memset(&ipc_fifo[proc], 0, sizeof(IPC_FIFO));
37
+	T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, 0x00000101);
38
+}
39
+
40
+void IPC_FIFOsend(uint8_t proc, uint32_t val)
41
+{
42
+	uint16_t cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
43
+	if (!(cnt_l & IPCFIFOCNT_FIFOENABLE)) return;			// FIFO disabled
44
+	uint8_t	proc_remote = proc ^ 1;
45
+
46
+	if (ipc_fifo[proc].size > 15)
47
+	{
48
+		cnt_l |= IPCFIFOCNT_FIFOERROR;
49
+		T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
50
+		return;
51
+	}
52
+
53
+	uint16_t cnt_r = T1ReadWord(MMU.MMU_MEM[proc_remote][0x40], 0x184);
54
+
55
+	//LOG("IPC%s send FIFO 0x%08X size %03i (l 0x%X, tail %02i) (r 0x%X, tail %02i)\n",
56
+	//	proc?"7":"9", val, ipc_fifo[proc].size, cnt_l, ipc_fifo[proc].tail, cnt_r, ipc_fifo[proc^1].tail);
57
+
58
+	cnt_l &= 0xBFFC;		// clear send empty bit & full
59
+	cnt_r &= 0xBCFF;		// set recv empty bit & full
60
+	ipc_fifo[proc].buf[ipc_fifo[proc].tail] = val;
61
+	ipc_fifo[proc].tail++;
62
+	ipc_fifo[proc].size++;
63
+	if (ipc_fifo[proc].tail > 15) ipc_fifo[proc].tail = 0;
64
+
65
+	if (ipc_fifo[proc].size > 15)
66
+	{
67
+		cnt_l |= IPCFIFOCNT_SENDFULL;		// set send full bit
68
+		cnt_r |= IPCFIFOCNT_RECVFULL;		// set recv full bit
69
+	}
70
+
71
+	T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
72
+	T1WriteWord(MMU.MMU_MEM[proc_remote][0x40], 0x184, cnt_r);
73
+
74
+	if (cnt_r & IPCFIFOCNT_RECVIRQEN)
75
+		NDS_makeIrq(proc_remote, IRQ_BIT_IPCFIFO_RECVNONEMPTY);
76
+
77
+	NDS_Reschedule();
78
+}
79
+
80
+uint32_t IPC_FIFOrecv(uint8_t proc)
81
+{
82
+	uint16_t cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
83
+	if (!(cnt_l & IPCFIFOCNT_FIFOENABLE)) return 0;									// FIFO disabled
84
+	uint8_t	proc_remote = proc ^ 1;
85
+
86
+	uint32_t val = 0;
87
+
88
+	if ( ipc_fifo[proc_remote].size == 0 )		// remote FIFO error
89
+	{
90
+		cnt_l |= IPCFIFOCNT_FIFOERROR;
91
+		T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
92
+		return 0;
93
+	}
94
+
95
+	uint16_t cnt_r = T1ReadWord(MMU.MMU_MEM[proc_remote][0x40], 0x184);
96
+
97
+	cnt_l &= 0xBCFF;		// clear send full bit & empty
98
+	cnt_r &= 0xBFFC;		// set recv full bit & empty
99
+
100
+	val = ipc_fifo[proc_remote].buf[ipc_fifo[proc_remote].head];
101
+	ipc_fifo[proc_remote].head++;
102
+	ipc_fifo[proc_remote].size--;
103
+	if (ipc_fifo[proc_remote].head > 15) ipc_fifo[proc_remote].head = 0;
104
+
105
+	//LOG("IPC%s recv FIFO 0x%08X size %03i (l 0x%X, tail %02i) (r 0x%X, tail %02i)\n",
106
+	//	proc?"7":"9", val, ipc_fifo[proc].size, cnt_l, ipc_fifo[proc].tail, cnt_r, ipc_fifo[proc^1].tail);
107
+
108
+
109
+	if ( ipc_fifo[proc_remote].size == 0 )		// FIFO empty
110
+	{
111
+		cnt_l |= IPCFIFOCNT_RECVEMPTY;
112
+		cnt_r |= IPCFIFOCNT_SENDEMPTY;
113
+
114
+		if (cnt_r & IPCFIFOCNT_SENDIRQEN)
115
+			NDS_makeIrq(proc_remote, IRQ_BIT_IPCFIFO_SENDEMPTY);
116
+	}
117
+
118
+	T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
119
+	T1WriteWord(MMU.MMU_MEM[proc_remote][0x40], 0x184, cnt_r);
120
+
121
+	NDS_Reschedule();
122
+
123
+	return val;
124
+}
125
+
126
+void IPC_FIFOcnt(uint8_t proc, uint16_t val)
127
+{
128
+	uint16_t cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
129
+	uint16_t cnt_r = T1ReadWord(MMU.MMU_MEM[proc^1][0x40], 0x184);
130
+
131
+	if (val & IPCFIFOCNT_FIFOERROR)
132
+	{
133
+		//at least SPP uses this, maybe every retail game
134
+		cnt_l &= ~IPCFIFOCNT_FIFOERROR;
135
+	}
136
+
137
+	if (val & IPCFIFOCNT_SENDCLEAR)
138
+	{
139
+		ipc_fifo[proc].head = 0; ipc_fifo[proc].tail = 0; ipc_fifo[proc].size = 0;
140
+
141
+		cnt_l |= IPCFIFOCNT_SENDEMPTY;
142
+		cnt_r |= IPCFIFOCNT_RECVEMPTY;
143
+
144
+		cnt_l &= ~IPCFIFOCNT_SENDFULL;
145
+		cnt_r &= ~IPCFIFOCNT_RECVFULL;
146
+	}
147
+
148
+	cnt_l &= ~IPCFIFOCNT_WRITEABLE;
149
+	cnt_l |= val & IPCFIFOCNT_WRITEABLE;
150
+
151
+	// IPCFIFOCNT_SENDIRQEN may have been set (and/or the fifo may have been cleared) so we may need to trigger this irq
152
+	// (this approach is used by libnds fifo system on occasion in fifoInternalSend, and began happening frequently for value32 with r4326)
153
+	if (cnt_l & IPCFIFOCNT_SENDIRQEN)
154
+		if (cnt_l & IPCFIFOCNT_SENDEMPTY)
155
+			NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_SENDEMPTY);
156
+
157
+	// IPCFIFOCNT_RECVIRQEN may have been set so we may need to trigger this irq
158
+	if(cnt_l & IPCFIFOCNT_RECVIRQEN)
159
+		if (!(cnt_l & IPCFIFOCNT_RECVEMPTY))
160
+			NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_RECVNONEMPTY);
161
+
162
+	T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l);
163
+	T1WriteWord(MMU.MMU_MEM[proc^1][0x40], 0x184, cnt_r);
164
+
165
+	NDS_Reschedule();
166
+}
167
+
168
+// ========================================================= GFX FIFO
169
+//GFX_PIPE	gxPIPE;
170
+//GFX_FIFO	gxFIFO;
171
+
172
+/*void GFX_PIPEclear()
173
+{
174
+	gxPIPE.head = 0;
175
+	gxPIPE.tail = 0;
176
+	gxPIPE.size = 0;
177
+}*/
178
+
179
+/*void GFX_FIFOclear()
180
+{
181
+	gxFIFO.head = 0;
182
+	gxFIFO.tail = 0;
183
+	gxFIFO.size = 0;
184
+}*/
185
+
186
+/*static void GXF_FIFO_handleEvents()
187
+{
188
+	bool low = gxFIFO.size <= 127;
189
+	bool lowchange = MMU_new.gxstat.fifo_low ^ low;
190
+	MMU_new.gxstat.fifo_low = low;
191
+	if(low) triggerDma(EDMAMode_GXFifo);
192
+
193
+	bool empty = gxFIFO.size == 0;
194
+	bool emptychange = MMU_new.gxstat.fifo_empty ^ empty;
195
+	MMU_new.gxstat.fifo_empty = empty;
196
+
197
+	if(emptychange||lowchange) NDS_Reschedule();
198
+}*/
199
+
200
+/*void GFX_FIFOsend(uint8_t cmd, uint32_t param)
201
+{
202
+	if(cmd==0x41) {
203
+		//int zzz=9;
204
+	}
205
+
206
+	//INFO("gxFIFO: send 0x%02X = 0x%08X (size %03i/0x%02X) gxstat 0x%08X\n", cmd, param, gxFIFO.size, gxFIFO.size, gxstat);
207
+	//printf("fifo recv: %02X: %08X upto:%d\n",cmd,param,gxFIFO.size+1);
208
+
209
+	//TODO - WOAH ! NOT HANDLING A TOO-BIG FIFO RIGHT NOW!
210
+	//if (gxFIFO.size > 255)
211
+	//{
212
+	//	GXF_FIFO_handleEvents();
213
+	//	//NEED TO HANDLE THIS!!!!!!!!!!!!!!!!!!!!!!!!!!
214
+
215
+	//	//gxstat |= 0x08000000;			// busy
216
+	//	NDS_RescheduleGXFIFO(1);
217
+	//	//INFO("ERROR: gxFIFO is full (cmd 0x%02X = 0x%08X) (prev cmd 0x%02X = 0x%08X)\n", cmd, param, gxFIFO.cmd[255], gxFIFO.param[255]);
218
+	//	return;
219
+	//}
220
+
221
+
222
+	gxFIFO.cmd[gxFIFO.tail] = cmd;
223
+	gxFIFO.param[gxFIFO.tail] = param;
224
+	gxFIFO.tail++;
225
+	gxFIFO.size++;
226
+	if (gxFIFO.tail > HACK_GXIFO_SIZE-1) gxFIFO.tail = 0;
227
+
228
+	if(gxFIFO.size>=HACK_GXIFO_SIZE) {
229
+		printf("--FIFO FULL-- : %d\n",gxFIFO.size);
230
+	}
231
+
232
+	//gxstat |= 0x08000000;		// set busy flag
233
+
234
+	GXF_FIFO_handleEvents();
235
+
236
+	NDS_RescheduleGXFIFO(1);
237
+}*/
238
+
239
+// this function used ONLY in gxFIFO
240
+/*bool GFX_PIPErecv(uint8_t *cmd, uint32_t *param)
241
+{
242
+	//gxstat &= 0xF7FFFFFF;		// clear busy flag
243
+
244
+	if (gxFIFO.size == 0)
245
+	{
246
+		GXF_FIFO_handleEvents();
247
+		return false;
248
+	}
249
+
250
+	*cmd = gxFIFO.cmd[gxFIFO.head];
251
+	*param = gxFIFO.param[gxFIFO.head];
252
+
253
+	gxFIFO.head++;
254
+	gxFIFO.size--;
255
+	if (gxFIFO.head > HACK_GXIFO_SIZE-1) gxFIFO.head = 0;
256
+
257
+	GXF_FIFO_handleEvents();
258
+
259
+	return true;
260
+}*/
261
+
262
+/*void GFX_FIFOcnt(uint32_t val)
263
+{
264
+	////INFO("gxFIFO: write cnt 0x%08X (prev 0x%08X) FIFO size %03i PIPE size %03i\n", val, gxstat, gxFIFO.size, gxPIPE.size);
265
+
266
+	if (val & (1<<29))		// clear? (only in homebrew?)
267
+	{
268
+		GFX_PIPEclear();
269
+		GFX_FIFOclear();
270
+		return;
271
+	}
272
+
273
+	//zeromus says: what happened to clear stack?
274
+	//if (val & (1<<15))		// projection stack pointer reset
275
+	//{
276
+	//	gfx3d_ClearStack();
277
+	//	val &= 0xFFFF5FFF;		// clear reset (bit15) & stack level (bit13)
278
+	//}
279
+
280
+	T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x600, val);
281
+}*/
282
+
283
+// ========================================================= DISP FIFO
284
+//DISP_FIFO	disp_fifo;
285
+
286
+/*void DISP_FIFOinit()
287
+{
288
+	memset(&disp_fifo, 0, sizeof(DISP_FIFO));
289
+}*/
290
+
291
+/*void DISP_FIFOsend(uint32_t val)
292
+{
293
+	//INFO("DISP_FIFO send value 0x%08X (head 0x%06X, tail 0x%06X)\n", val, disp_fifo.head, disp_fifo.tail);
294
+	disp_fifo.buf[disp_fifo.tail] = val;
295
+	disp_fifo.tail++;
296
+	if (disp_fifo.tail > 0x5FFF)
297
+		disp_fifo.tail = 0;
298
+}*/
299
+
300
+/*uint32_t DISP_FIFOrecv()
301
+{
302
+	//if (disp_fifo.tail == disp_fifo.head) return 0; // FIFO is empty
303
+	uint32_t val = disp_fifo.buf[disp_fifo.head];
304
+	disp_fifo.head++;
305
+	if (disp_fifo.head > 0x5FFF)
306
+		disp_fifo.head = 0;
307
+	return val;
308
+}*/