| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | /*====================================================================
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    filename:     gdsp_interface.h | 
					
						
							|  |  |  |    project:      GCemu | 
					
						
							|  |  |  |    created:      2004-6-18 | 
					
						
							|  |  |  |    mail:		  duddie@walla.com | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Copyright (c) 2005 Duddie & Tratax | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    This program 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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    This program 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 this program; if not, write to the Free Software | 
					
						
							|  |  |  |    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    ====================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2009-04-06 18:47:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | #include "Thread.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-06 18:47:21 +00:00
										 |  |  | #include "MemoryUtil.h"
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-01 20:06:24 +00:00
										 |  |  | #include "DSPCore.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | #include "DSPHost.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | #include "DSPTables.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-08 17:58:58 +00:00
										 |  |  | #include "DSPAnalyzer.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | #include "DSPAccelerator.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-28 10:24:44 +00:00
										 |  |  | #include "DSPInterpreter.h"
 | 
					
						
							|  |  |  | #include "DSPHWInterface.h"
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | void gdsp_do_dma(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Common::CriticalSection g_CriticalSection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | static volatile u16 gdsp_mbox[2][2]; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | u16 gdsp_ifx_regs[256]; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void gdsp_ifx_init() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-05 15:46:47 +00:00
										 |  |  | 	for (int i = 0; i < 256; i++) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		gdsp_ifx_regs[i] = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gdsp_mbox[0][0] = 0; | 
					
						
							|  |  |  | 	gdsp_mbox[0][1] = 0; | 
					
						
							|  |  |  | 	gdsp_mbox[1][0] = 0; | 
					
						
							|  |  |  | 	gdsp_mbox[1][1] = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | u32 gdsp_mbox_peek(u8 mbx) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Enter(); | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | 	u32 value = ((gdsp_mbox[mbx][0] << 16) | gdsp_mbox[mbx][1]); | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Leave(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	return value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_mbox_write_h(u8 mbx, u16 val) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Enter(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	gdsp_mbox[mbx][0] = val & 0x7fff; | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Leave(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_mbox_write_l(u8 mbx, u16 val) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Enter(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	gdsp_mbox[mbx][1]  = val; | 
					
						
							|  |  |  | 	gdsp_mbox[mbx][0] |= 0x8000; | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Leave(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 15:12:12 +00:00
										 |  |  | #if defined(_DEBUG) || defined(DEBUGFAST)
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	if (mbx == GDSP_MBOX_DSP) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-07 15:12:52 +00:00
										 |  |  | 		NOTICE_LOG(DSP_MAIL, "DSP(WM) B:%i M:0x%08x (pc=0x%04x)", mbx, gdsp_mbox_peek(GDSP_MBOX_DSP), g_dsp.pc); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-07-07 15:12:52 +00:00
										 |  |  | 		NOTICE_LOG(DSP_MAIL, "CPU(WM) B:%i M:0x%08x (pc=0x%04x)", mbx, gdsp_mbox_peek(GDSP_MBOX_CPU), g_dsp.pc); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | u16 gdsp_mbox_read_h(u8 mbx) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 	return gdsp_mbox[mbx][0];  // TODO: mask away the top bit?
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | u16 gdsp_mbox_read_l(u8 mbx) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Enter(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-09 13:03:41 +00:00
										 |  |  | 	u16 val = gdsp_mbox[mbx][1]; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	gdsp_mbox[mbx][0] &= ~0x8000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-05 15:46:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	if (DSPHost_OnThread()) | 
					
						
							| 
									
										
										
										
											2009-04-08 20:38:23 +00:00
										 |  |  | 		g_CriticalSection.Leave(); | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 15:12:12 +00:00
										 |  |  | #if defined(_DEBUG) || defined(DEBUGFAST)
 | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 	if (mbx == GDSP_MBOX_DSP) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-07 15:12:52 +00:00
										 |  |  | 		NOTICE_LOG(DSP_MAIL, "DSP(RM) B:%i M:0x%08x (pc=0x%04x)", mbx, gdsp_mbox_peek(GDSP_MBOX_DSP), g_dsp.pc); | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-07-07 15:12:52 +00:00
										 |  |  | 		NOTICE_LOG(DSP_MAIL, "CPU(RM) B:%i M:0x%08x (pc=0x%04x)", mbx, gdsp_mbox_peek(GDSP_MBOX_CPU), g_dsp.pc); | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif	
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-05 15:46:47 +00:00
										 |  |  | 	return val; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_ifx_write(u16 addr, u16 val) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (addr & 0xff) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	    case 0xfb: // DIRQ
 | 
					
						
							|  |  |  | 		    if (val & 0x1) | 
					
						
							| 
									
										
										
										
											2009-06-28 10:00:25 +00:00
										 |  |  | 			    DSPHost_InterruptRequest(); | 
					
						
							| 
									
										
										
										
											2009-07-10 11:19:47 +00:00
										 |  |  | 			else  | 
					
						
							|  |  |  | 				ERROR_LOG(DSPLLE, "Unknown Interrupt Request pc=%04x (%04x)", g_dsp.pc, val); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case 0xfc: // DMBH
 | 
					
						
							|  |  |  | 		    gdsp_mbox_write_h(GDSP_MBOX_DSP, val); | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case 0xfd: // DMBL
 | 
					
						
							|  |  |  | 		    gdsp_mbox_write_l(GDSP_MBOX_DSP, val); | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 	    case 0xfe:  // CMBH
 | 
					
						
							|  |  |  | 		    return gdsp_mbox_write_h(GDSP_MBOX_CPU, val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case 0xff:  // CMBL
 | 
					
						
							|  |  |  | 		    return gdsp_mbox_write_l(GDSP_MBOX_CPU, val); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	    case 0xcb: // DSBL
 | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    gdsp_ifx_regs[addr & 0xFF] = val; | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | 		    gdsp_do_dma(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		    gdsp_ifx_regs[DSP_DSCR] &= ~0x0004; | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 		case 0xd3:   // ZeldaUnk (accelerator WRITE)
 | 
					
						
							| 
									
										
										
										
											2009-07-15 15:12:42 +00:00
										 |  |  | 		   	NOTICE_LOG(DSPLLE, "Write To ZeldaUnk pc=%04x (%04x)", g_dsp.pc, val); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 			dsp_write_aram_d3(val); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-03 11:15:17 +00:00
										 |  |  | 		case 0xde: | 
					
						
							|  |  |  | 			//if (val)
 | 
					
						
							|  |  |  | 			//	PanicAlert("Gain written: %04x", val);   // BMX XXX does, and sounds HORRIBLE.
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	    case 0xcd: | 
					
						
							|  |  |  | 	    case 0xce: | 
					
						
							|  |  |  | 	    case 0xcf: | 
					
						
							|  |  |  | 	    case 0xc9: | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    gdsp_ifx_regs[addr & 0xFF] = val; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    default: | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 			if ((addr & 0xff) >= 0xa0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 22:49:32 +00:00
										 |  |  | 				if (pdlabels[(addr & 0xFF) - 0xa0].name && pdlabels[(addr & 0xFF) - 0xa0].description) { | 
					
						
							| 
									
										
										
										
											2009-07-05 16:18:17 +00:00
										 |  |  | 		   			INFO_LOG(DSPLLE, "%04x MW %s (%04x)", g_dsp.pc, pdlabels[(addr & 0xFF) - 0xa0].name, val); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 		   			ERROR_LOG(DSPLLE, "%04x MW %04x (%04x)", g_dsp.pc, addr, val); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 		   	    ERROR_LOG(DSPLLE, "%04x MW %04x (%04x)", g_dsp.pc, addr, val); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    gdsp_ifx_regs[addr & 0xFF] = val; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		    break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | u16 gdsp_ifx_read(u16 addr) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (addr & 0xff) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-06-21 12:09:17 +00:00
										 |  |  | 	    case 0xfc:  // DMBH
 | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    return gdsp_mbox_read_h(GDSP_MBOX_DSP); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-05 13:07:38 +00:00
										 |  |  | 	    case 0xfd:  // DMBL
 | 
					
						
							|  |  |  | 		    return gdsp_mbox_read_l(GDSP_MBOX_DSP); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 12:09:17 +00:00
										 |  |  | 	    case 0xfe:  // CMBH
 | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    return gdsp_mbox_read_h(GDSP_MBOX_CPU); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 12:09:17 +00:00
										 |  |  | 	    case 0xff:  // CMBL
 | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    return gdsp_mbox_read_l(GDSP_MBOX_CPU); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	    case 0xc9: | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    return gdsp_ifx_regs[addr & 0xFF]; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 12:09:17 +00:00
										 |  |  | 	    case 0xdd:  // ADPCM Accelerator reads
 | 
					
						
							|  |  |  | 		    return dsp_read_accelerator(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case 0xd3: | 
					
						
							| 
									
										
										
										
											2009-07-15 15:12:42 +00:00
										 |  |  | 			NOTICE_LOG(DSPLLE, "Read from ZeldaUnk pc=%04x", g_dsp.pc); | 
					
						
							| 
									
										
										
										
											2009-06-21 12:09:17 +00:00
										 |  |  | 		    return dsp_read_aram_d3(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	    default: | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 			if ((addr & 0xff) >= 0xa0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 22:49:32 +00:00
										 |  |  | 				if (pdlabels[(addr & 0xFF) - 0xa0].name && pdlabels[(addr & 0xFF) - 0xa0].description) { | 
					
						
							| 
									
										
										
										
											2009-07-05 16:18:17 +00:00
										 |  |  | 	   				INFO_LOG(DSPLLE, "%04x MR %s (%04x)", g_dsp.pc, pdlabels[(addr & 0xFF) - 0xa0].name, gdsp_ifx_regs[addr & 0xFF]); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2009-07-05 16:18:17 +00:00
										 |  |  | 	   				ERROR_LOG(DSPLLE, "%04x MR %04x (%04x)", g_dsp.pc, addr, gdsp_ifx_regs[addr & 0xFF]); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2009-07-05 16:18:17 +00:00
										 |  |  |    				ERROR_LOG(DSPLLE, "%04x MR %04x (%04x)", g_dsp.pc, addr, gdsp_ifx_regs[addr & 0xFF]); | 
					
						
							| 
									
										
										
										
											2009-06-21 08:39:21 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-02 16:15:52 +00:00
										 |  |  | 		    return gdsp_ifx_regs[addr & 0xFF]; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_idma_in(u16 dsp_addr, u32 addr, u32 size) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-06 18:47:21 +00:00
										 |  |  | 	UnWriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-06 18:47:21 +00:00
										 |  |  | 	u8* dst = ((u8*)g_dsp.iram); | 
					
						
							| 
									
										
										
										
											2009-06-12 15:47:41 +00:00
										 |  |  | 	for (u32 i = 0; i < size; i += 2) | 
					
						
							| 
									
										
										
										
											2009-04-09 13:03:41 +00:00
										 |  |  | 	{  | 
					
						
							| 
									
										
										
										
											2009-04-05 15:46:47 +00:00
										 |  |  | 		// TODO : this may be different on Wii.
 | 
					
						
							| 
									
										
										
										
											2009-04-09 13:03:41 +00:00
										 |  |  | 		*(u16*)&dst[dsp_addr + i] = Common::swap16(*(const u16*)&g_dsp.cpu_ram[(addr + i) & 0x0fffffff]); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-06 18:47:21 +00:00
										 |  |  | 	WriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); | 
					
						
							| 
									
										
										
										
											2009-07-14 08:30:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	g_dsp.iram_crc = DSPHost_CodeLoaded(g_dsp.cpu_ram + (addr & 0x0fffffff), size); | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-10 11:19:47 +00:00
										 |  |  | 	NOTICE_LOG(DSPLLE, "*** Copy new UCode from 0x%08x to 0x%04x (crc: %8x)", addr, dsp_addr, g_dsp.iram_crc); | 
					
						
							| 
									
										
										
										
											2009-07-10 15:00:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-14 08:30:23 +00:00
										 |  |  | 	DSPAnalyzer::Analyze(); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_idma_out(u16 dsp_addr, u32 addr, u32 size) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-09 12:54:35 +00:00
										 |  |  | 	ERROR_LOG(DSPLLE, "*** idma_out IRAM_DSP (0x%04x) -> RAM (0x%08x) : size (0x%08x)", dsp_addr / 2, addr, size); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 12:09:17 +00:00
										 |  |  | // TODO: These should eat clock cycles.
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_ddma_in(u16 dsp_addr, u32 addr, u32 size) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if ((addr & 0x7FFFFFFF) > 0x01FFFFFF) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-09 12:54:35 +00:00
										 |  |  | 		ERROR_LOG(DSPLLE, "*** ddma_in read from invalid addr (0x%08x)", addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | 	u8* dst = ((u8*)g_dsp.dram); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | 	for (u32 i = 0; i < size; i += 2) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-04-09 13:03:41 +00:00
										 |  |  | 		*(u16*)&dst[dsp_addr + i] = Common::swap16(*(const u16*)&g_dsp.cpu_ram[(addr + i) & 0x7FFFFFFF]); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-09 12:54:35 +00:00
										 |  |  | 	INFO_LOG(DSPLLE, "*** ddma_in RAM (0x%08x) -> DRAM_DSP (0x%04x) : size (0x%08x)", addr, dsp_addr / 2, size); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | void gdsp_ddma_out(u16 dsp_addr, u32 addr, u32 size) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if ((addr & 0x7FFFFFFF) > 0x01FFFFFF) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-09 12:54:35 +00:00
										 |  |  | 		ERROR_LOG(DSPLLE, "*** gdsp_ddma_out to invalid addr (0x%08x)", addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-09 13:03:41 +00:00
										 |  |  | 	const u8* src = ((const u8*)g_dsp.dram); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | 	for (u32 i = 0; i < size; i += 2) | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-04-09 13:03:41 +00:00
										 |  |  | 		*(u16*)&g_dsp.cpu_ram[(addr + i) & 0x7FFFFFFF] = Common::swap16(*(const u16*)&src[dsp_addr + i]); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-09 12:54:35 +00:00
										 |  |  | 	INFO_LOG(DSPLLE, "*** ddma_out DRAM_DSP (0x%04x) -> RAM (0x%08x) : size (0x%08x)", dsp_addr / 2, addr, size); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 16:23:40 +00:00
										 |  |  | void gdsp_do_dma() | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-30 03:27:31 +00:00
										 |  |  | 	u16 ctl; | 
					
						
							|  |  |  | 	u32 addr; | 
					
						
							|  |  |  | 	u16 dsp_addr; | 
					
						
							|  |  |  | 	u16 len; | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	addr = (gdsp_ifx_regs[DSP_DSMAH] << 16) | gdsp_ifx_regs[DSP_DSMAL]; | 
					
						
							|  |  |  | 	ctl = gdsp_ifx_regs[DSP_DSCR]; | 
					
						
							|  |  |  | 	dsp_addr = gdsp_ifx_regs[DSP_DSPA] * 2; | 
					
						
							|  |  |  | 	len = gdsp_ifx_regs[DSP_DSBL]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((ctl > 3) || (len > 0x4000)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-09 12:54:35 +00:00
										 |  |  | 		ERROR_LOG(DSPLLE, "DMA ERROR pc: %04x ctl: %04x addr: %08x da: %04x size: %04x", g_dsp.pc, ctl, addr, dsp_addr, len); | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 		exit(0); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-10-01 15:12:12 +00:00
										 |  |  | #if defined(_DEBUG) || defined(DEBUGFAST)
 | 
					
						
							| 
									
										
										
										
											2009-07-14 08:30:23 +00:00
										 |  |  | 	NOTICE_LOG(DSPLLE, "DMA pc: %04x ctl: %04x addr: %08x da: %04x size: %04x", g_dsp.pc, ctl, addr, dsp_addr, len); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 09:10:32 +00:00
										 |  |  | 	switch (ctl & 0x3) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	    case (DSP_CR_DMEM | DSP_CR_TO_CPU): | 
					
						
							|  |  |  | 		    gdsp_ddma_out(dsp_addr, addr, len); | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case (DSP_CR_DMEM | DSP_CR_FROM_CPU): | 
					
						
							|  |  |  | 		    gdsp_ddma_in(dsp_addr, addr, len); | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case (DSP_CR_IMEM | DSP_CR_TO_CPU): | 
					
						
							|  |  |  | 		    gdsp_idma_out(dsp_addr, addr, len); | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	    case (DSP_CR_IMEM | DSP_CR_FROM_CPU): | 
					
						
							|  |  |  | 		    gdsp_idma_in(dsp_addr, addr, len); | 
					
						
							|  |  |  | 		    break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |