summaryrefslogtreecommitdiff
path: root/plugins/ao/eng_psf/peops2/dma2.c
blob: 6c977429241dc562d38cefa26f4614c6354e7f9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/***************************************************************************
                            dma.c  -  description
                             -------------------
    begin                : Wed May 15 2002
    copyright            : (C) 2002 by Pete Bernert
    email                : BlackDove@addcom.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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. See also the license.txt file for *
 *   additional informations.                                              *
 *                                                                         *
 ***************************************************************************/

//*************************************************************************//
// History of changes:
//
// 2004/04/04 - Pete
// - changed plugin to emulate PS2 spu
//
// 2002/05/15 - Pete
// - generic cleanup for the Peops release
//
//*************************************************************************//

#include "../peops2/stdafx.h"

#define _IN_DMA

#include "../peops2/externals.h"
#include "../peops2/registers.h"
//#include "debug.h"
#include "../psx.h"
#include "../peops2/spu.h"

//extern uint32 psx_ram[(2*1024*1024)/4];

////////////////////////////////////////////////////////////////////////
// READ DMA (many values)
////////////////////////////////////////////////////////////////////////

EXPORT_GCC void CALLBACK SPU2readDMA4Mem(mips_cpu_context *cpu, u32 usPSXMem,int iSize)
{
    spu2_state_t *spu = cpu->spu2;
 int i;
 u16 *ram16 = (u16 *)&cpu->psx_ram[0];

 for(i=0;i<iSize;i++)
  {
   ram16[usPSXMem>>1]=spu->spuMem[spu->spuAddr2[0]];                  // spu addr 0 got by writeregister
   usPSXMem+=2;
   spu->spuAddr2[0]++;                                     // inc spu addr
   if(spu->spuAddr2[0]>0xfffff) spu->spuAddr2[0]=0;             // wrap
  }

 spu->spuAddr2[0]+=0x20; //?????
 

 spu->iSpuAsyncWait=0;

 // got from J.F. and Kanodin... is it needed?
 spu->regArea[(PS2_C0_ADMAS)>>1]=0;                         // Auto DMA complete
 spu->spuStat2[0]=0x80;                                     // DMA complete
}

EXPORT_GCC void CALLBACK SPU2readDMA7Mem(mips_cpu_context *cpu, u32 usPSXMem,int iSize)
{
    spu2_state_t *spu = cpu->spu2;
 int i;
 u16 *ram16 = (u16 *)&cpu->psx_ram[0];

 for(i=0;i<iSize;i++)
  {
   ram16[usPSXMem>>1]=spu->spuMem[spu->spuAddr2[1]];             // spu addr 1 got by writeregister
   usPSXMem+=2;
   spu->spuAddr2[1]++;                                      // inc spu addr
   if(spu->spuAddr2[1]>0xfffff) spu->spuAddr2[1]=0;              // wrap
  }

 spu->spuAddr2[1]+=0x20; //?????

 spu->iSpuAsyncWait=0;

 // got from J.F. and Kanodin... is it needed?
 spu->regArea[(PS2_C1_ADMAS)>>1]=0;                         // Auto DMA complete
 spu->spuStat2[1]=0x80;                                     // DMA complete
}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

// to investigate: do sound data updates by writedma affect spu
// irqs? Will an irq be triggered, if new data is written to
// the memory irq address?

////////////////////////////////////////////////////////////////////////
// WRITE DMA (many values)
////////////////////////////////////////////////////////////////////////

EXPORT_GCC void CALLBACK SPU2writeDMA4Mem(mips_cpu_context *cpu, u32 usPSXMem,int iSize)
{
    spu2_state_t *spu = cpu->spu2;
 int i;
 u16 *ram16 = (u16 *)&cpu->psx_ram[0];

 for(i=0;i<iSize;i++)
  {
   spu->spuMem[spu->spuAddr2[0]] = ram16[usPSXMem>>1];                 // spu addr 0 got by writeregister
   usPSXMem+=2;
   spu->spuAddr2[0]++;                                      // inc spu addr
   if(spu->spuAddr2[0]>0xfffff) spu->spuAddr2[0]=0;              // wrap
  }
 
 spu->iSpuAsyncWait=0;

 // got from J.F. and Kanodin... is it needed?
 spu->spuStat2[0]=0x80;                                     // DMA complete
}

EXPORT_GCC void CALLBACK SPU2writeDMA7Mem(mips_cpu_context *cpu, u32 usPSXMem,int iSize)
{
    spu2_state_t *spu = cpu->spu2;
 int i;
 u16 *ram16 = (u16 *)&cpu->psx_ram[0];

 for(i=0;i<iSize;i++)
  {
   spu->spuMem[spu->spuAddr2[1]] = ram16[usPSXMem>>1];           // spu addr 1 got by writeregister
   spu->spuAddr2[1]++;                                      // inc spu addr
   if(spu->spuAddr2[1]>0xfffff) spu->spuAddr2[1]=0;              // wrap
  }
 
 spu->iSpuAsyncWait=0;

 // got from J.F. and Kanodin... is it needed?
 spu->spuStat2[1]=0x80;                                     // DMA complete
}

////////////////////////////////////////////////////////////////////////
// INTERRUPTS
////////////////////////////////////////////////////////////////////////

void InterruptDMA4(mips_cpu_context *cpu) 
{
    spu2_state_t *spu = cpu->spu2;
// taken from linuzappz NULL spu2
//	spu2Rs16(CORE0_ATTR)&= ~0x30;
//	spu2Rs16(REG__1B0) = 0;
//	spu2Rs16(SPU2_STATX_WRDY_M)|= 0x80;

 spu->spuCtrl2[0]&=~0x30;
 spu->regArea[(PS2_C0_ADMAS)>>1]=0;
 spu->spuStat2[0]|=0x80;
}
                       
EXPORT_GCC void CALLBACK SPU2interruptDMA4(mips_cpu_context *cpu) 
{
 InterruptDMA4(cpu);
}

void InterruptDMA7(mips_cpu_context *cpu) 
{
    spu2_state_t *spu = cpu->spu2;
// taken from linuzappz NULL spu2
//	spu2Rs16(CORE1_ATTR)&= ~0x30;
//	spu2Rs16(REG__5B0) = 0;
//	spu2Rs16(SPU2_STATX_DREQ)|= 0x80;

 spu->spuCtrl2[1]&=~0x30;
 spu->regArea[(PS2_C1_ADMAS)>>1]=0;
 spu->spuStat2[1]|=0x80;
}

EXPORT_GCC void CALLBACK SPU2interruptDMA7(mips_cpu_context *cpu) 
{
 InterruptDMA7(cpu);
}