4 * Copyright (C) 2007 ziggy
6 * This program 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.
11 * This program 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.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #define RSP_Z64_VERSION 0x020000
27 #define RSP_PLUGIN_API_VERSION 0x020000
29 static void (*l_DebugCallback)(void *, int, const char *) = NULL;
30 static void *l_DebugCallContext = NULL;
31 static bool l_PluginInit = false;
36 FILE * fp = fopen("rsp.dump", "w");
38 fwrite(rdram, 8*1024, 1024, fp);
39 fwrite(rsp_dmem, 0x2000, 1, fp);
40 fwrite(rsp.ext.MI_INTR_REG, 4, 1, fp);
42 fwrite(rsp.ext.SP_MEM_ADDR_REG, 4, 1, fp);
43 fwrite(rsp.ext.SP_DRAM_ADDR_REG, 4, 1, fp);
44 fwrite(rsp.ext.SP_RD_LEN_REG, 4, 1, fp);
45 fwrite(rsp.ext.SP_WR_LEN_REG, 4, 1, fp);
46 fwrite(rsp.ext.SP_STATUS_REG, 4, 1, fp);
47 fwrite(rsp.ext.SP_DMA_FULL_REG, 4, 1, fp);
48 fwrite(rsp.ext.SP_DMA_BUSY_REG, 4, 1, fp);
49 fwrite(rsp.ext.SP_PC_REG, 4, 1, fp);
50 fwrite(rsp.ext.SP_SEMAPHORE_REG, 4, 1, fp);
52 fwrite(rsp.ext.DPC_START_REG, 4, 1, fp);
53 fwrite(rsp.ext.DPC_END_REG, 4, 1, fp);
54 fwrite(rsp.ext.DPC_CURRENT_REG, 4, 1, fp);
55 fwrite(rsp.ext.DPC_STATUS_REG, 4, 1, fp);
56 fwrite(rsp.ext.DPC_CLOCK_REG, 4, 1, fp);
57 fwrite(rsp.ext.DPC_BUFBUSY_REG, 4, 1, fp);
58 fwrite(rsp.ext.DPC_PIPEBUSY_REG, 4, 1, fp);
59 fwrite(rsp.ext.DPC_TMEM_REG, 4, 1, fp);
64 void log(m64p_msg_level level, const char *msg, ...)
69 vsnprintf(buf, 1023, msg, args);
74 l_DebugCallback(l_DebugCallContext, level, buf);
82 /* DLL-exported functions */
83 EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle CoreLibHandle, void *Context,
84 void (*DebugCallback)(void *, int, const char *))
88 return M64ERR_ALREADY_INIT;
90 ///* first thing is to set the callback function for debug info */
91 l_DebugCallback = DebugCallback;
92 l_DebugCallContext = Context;
94 ///* this plugin doesn't use any Core library functions (ex for Configuration), so no need to keep the CoreLibHandle */
97 return M64ERR_SUCCESS;
100 EXPORT m64p_error CALL PluginShutdown(void)
103 return M64ERR_NOT_INIT;
105 ///* reset some local variable */
106 l_DebugCallback = NULL;
107 l_DebugCallContext = NULL;
110 return M64ERR_SUCCESS;
113 EXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *PluginType, int *PluginVersion, int *APIVersion, const char **PluginNamePtr, int *Capabilities)
115 /* set version info */
116 if (PluginType != NULL)
117 *PluginType = M64PLUGIN_RSP;
119 if (PluginVersion != NULL)
120 *PluginVersion = RSP_Z64_VERSION;
122 if (APIVersion != NULL)
123 *APIVersion = RSP_PLUGIN_API_VERSION;
125 if (PluginNamePtr != NULL)
126 *PluginNamePtr = "Z64 RSP Plugin";
128 if (Capabilities != NULL)
133 return M64ERR_SUCCESS;
136 EXPORT unsigned int CALL DoRspCycles(unsigned int Cycles)
138 //#define VIDEO_HLE_ALLOWED
139 //#define AUDIO_HLE_ALLOWED
141 #if defined (AUDIO_HLE_ALLOWED) || defined (VIDEO_HLE_ALLOWED)
142 unsigned int TaskType = *(unsigned int *)(z64_rspinfo.DMEM + 0xFC0);
145 #ifdef VIDEO_HLE_ALLOWED
149 while (SDL_PollEvent(&event)) {
150 switch (event.type) {
152 switch (event.key.keysym.sym) {
154 printf("Dumping !\n");
165 if (z64_rspinfo.ProcessDlistList != NULL) {
166 z64_rspinfo.ProcessDlistList();
168 *z64_rspinfo.SP_STATUS_REG |= (0x0203);
169 if ((*z64_rspinfo.SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) {
170 *z64_rspinfo.MI_INTR_REG |= R4300i_SP_Intr;
171 z64_rspinfo.CheckInterrupts();
174 *z64_rspinfo.DPC_STATUS_REG &= ~0x0002;
179 #ifdef AUDIO_HLE_ALLOWED
181 if (z64_rspinfo.ProcessAlistList != NULL) {
182 z64_rspinfo.ProcessAlistList();
184 *z64_rspinfo.SP_STATUS_REG |= (0x0203);
185 if ((*z64_rspinfo.SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) {
186 *z64_rspinfo.MI_INTR_REG |= R4300i_SP_Intr;
187 z64_rspinfo.CheckInterrupts();
193 if (z64_rspinfo.CheckInterrupts==NULL)
194 log(M64MSG_WARNING, "Emulator doesn't provide CheckInterrupts routine");
195 return rsp_execute(0x100000);
199 EXPORT void CALL InitiateRSP(RSP_INFO Rsp_Info, unsigned int *CycleCount)
201 log(M64MSG_STATUS, "INITIATE RSP");
203 memset(((UINT32*)z64_rspinfo.DMEM), 0, 0x2000);
204 //*CycleCount = 0; //Causes segfault, doesn't seem to be used anyway
207 EXPORT void CALL RomClosed(void)
209 extern int rsp_gen_cache_hit;
210 extern int rsp_gen_cache_miss;
211 log(M64MSG_STATUS, "cache hit %d miss %d %g%%", rsp_gen_cache_hit, rsp_gen_cache_miss,
212 rsp_gen_cache_miss*100.0f/rsp_gen_cache_hit);
213 rsp_gen_cache_hit = rsp_gen_cache_miss = 0;
219 for(i=0; i<0x140;i++) {
221 op = (0x12<<26) | (0x10 << 21) | (i&0x3f);
223 op = (0x3a<<26) | ((i&0x1f)<<11);
225 op = (0x32<<26) | ((i&0x1f)<<11);
227 op = (0x12<<26) | ((i&0x1f)<<21);
229 op = (0<<26) | (i&0x3f);
233 char s[128], s2[128];
234 rsp_dasm_one(s, 0x800, op);
235 //rsp_dasm_one(s2, 0x800, op2);
237 printf("%10g %10g %7d\t%30s\n"
238 /*"%10g %10g %7d\t%30s\n"*/,
239 rsptimings[i]/(rspcounts[i]*1.0f), rsptimings[i]*(1.0f), rspcounts[i], s//,
240 //timings[k]/1.0f/counts[k], counts[k], s2
245 //rsp_init(z64_rspinfo);