| 1 | /***************************************************************************\r |
| 2 | dma.c - description\r |
| 3 | -------------------\r |
| 4 | begin : Wed May 15 2002\r |
| 5 | copyright : (C) 2002 by Pete Bernert\r |
| 6 | email : BlackDove@addcom.de\r |
| 7 | ***************************************************************************/\r |
| 8 | /***************************************************************************\r |
| 9 | * *\r |
| 10 | * This program is free software; you can redistribute it and/or modify *\r |
| 11 | * it under the terms of the GNU General Public License as published by *\r |
| 12 | * the Free Software Foundation; either version 2 of the License, or *\r |
| 13 | * (at your option) any later version. See also the license.txt file for *\r |
| 14 | * additional informations. *\r |
| 15 | * *\r |
| 16 | ***************************************************************************/\r |
| 17 | \r |
| 18 | #include "stdafx.h"\r |
| 19 | \r |
| 20 | #define _IN_DMA\r |
| 21 | \r |
| 22 | #include "externals.h"\r |
| 23 | \r |
| 24 | ////////////////////////////////////////////////////////////////////////\r |
| 25 | // READ DMA (one value)\r |
| 26 | ////////////////////////////////////////////////////////////////////////\r |
| 27 | \r |
| 28 | unsigned short CALLBACK SPUreadDMA(void)\r |
| 29 | {\r |
| 30 | unsigned short s=spuMem[spuAddr>>1];\r |
| 31 | spuAddr+=2;\r |
| 32 | if(spuAddr>0x7ffff) spuAddr=0;\r |
| 33 | \r |
| 34 | return s;\r |
| 35 | }\r |
| 36 | \r |
| 37 | ////////////////////////////////////////////////////////////////////////\r |
| 38 | // READ DMA (many values)\r |
| 39 | ////////////////////////////////////////////////////////////////////////\r |
| 40 | \r |
| 41 | void CALLBACK SPUreadDMAMem(unsigned short *pusPSXMem, int iSize,\r |
| 42 | unsigned int cycles)\r |
| 43 | {\r |
| 44 | int i;\r |
| 45 | \r |
| 46 | do_samples_if_needed(cycles);\r |
| 47 | \r |
| 48 | for(i=0;i<iSize;i++)\r |
| 49 | {\r |
| 50 | *pusPSXMem++=spuMem[spuAddr>>1]; // spu addr got by writeregister\r |
| 51 | spuAddr+=2; // inc spu addr\r |
| 52 | if(spuAddr>0x7ffff) spuAddr=0; // wrap\r |
| 53 | }\r |
| 54 | }\r |
| 55 | \r |
| 56 | ////////////////////////////////////////////////////////////////////////\r |
| 57 | ////////////////////////////////////////////////////////////////////////\r |
| 58 | ////////////////////////////////////////////////////////////////////////\r |
| 59 | \r |
| 60 | // to investigate: do sound data updates by writedma affect spu\r |
| 61 | // irqs? Will an irq be triggered, if new data is written to\r |
| 62 | // the memory irq address?\r |
| 63 | \r |
| 64 | ////////////////////////////////////////////////////////////////////////\r |
| 65 | // WRITE DMA (one value)\r |
| 66 | ////////////////////////////////////////////////////////////////////////\r |
| 67 | \r |
| 68 | void CALLBACK SPUwriteDMA(unsigned short val)\r |
| 69 | {\r |
| 70 | spuMem[spuAddr>>1] = val; // spu addr got by writeregister\r |
| 71 | \r |
| 72 | spuAddr+=2; // inc spu addr\r |
| 73 | if(spuAddr>0x7ffff) spuAddr=0; // wrap\r |
| 74 | }\r |
| 75 | \r |
| 76 | ////////////////////////////////////////////////////////////////////////\r |
| 77 | // WRITE DMA (many values)\r |
| 78 | ////////////////////////////////////////////////////////////////////////\r |
| 79 | \r |
| 80 | void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize,\r |
| 81 | unsigned int cycles)\r |
| 82 | {\r |
| 83 | int i;\r |
| 84 | \r |
| 85 | do_samples_if_needed(cycles);\r |
| 86 | \r |
| 87 | if(spuAddr + iSize*2 < 0x80000)\r |
| 88 | {\r |
| 89 | memcpy(&spuMem[spuAddr>>1], pusPSXMem, iSize*2);\r |
| 90 | spuAddr += iSize*2;\r |
| 91 | return;\r |
| 92 | }\r |
| 93 | \r |
| 94 | for(i=0;i<iSize;i++)\r |
| 95 | {\r |
| 96 | spuMem[spuAddr>>1] = *pusPSXMem++; // spu addr got by writeregister\r |
| 97 | spuAddr+=2; // inc spu addr\r |
| 98 | spuAddr&=0x7ffff; // wrap\r |
| 99 | }\r |
| 100 | }\r |
| 101 | \r |
| 102 | ////////////////////////////////////////////////////////////////////////\r |