| 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 | #include "registers.h"\r |
| 24 | \r |
| 25 | static void set_dma_end(int iSize, unsigned int cycles)\r |
| 26 | {\r |
| 27 | // this must be > psxdma.c dma irq\r |
| 28 | // Road Rash also wants a considerable delay, maybe because of fifo?\r |
| 29 | cycles += iSize * 20; // maybe\r |
| 30 | cycles |= 1; // indicates dma is active\r |
| 31 | spu.cycles_dma_end = cycles;\r |
| 32 | }\r |
| 33 | \r |
| 34 | ////////////////////////////////////////////////////////////////////////\r |
| 35 | // READ DMA (many values)\r |
| 36 | ////////////////////////////////////////////////////////////////////////\r |
| 37 | \r |
| 38 | void CALLBACK SPUreadDMAMem(unsigned short *pusPSXMem, int iSize,\r |
| 39 | unsigned int cycles)\r |
| 40 | {\r |
| 41 | unsigned int addr = spu.spuAddr, irq_addr = regAreaGet(H_SPUirqAddr) << 3;\r |
| 42 | int i, irq;\r |
| 43 | \r |
| 44 | do_samples_if_needed(cycles, 1, 2);\r |
| 45 | irq = addr <= irq_addr && irq_addr < addr + iSize*2;\r |
| 46 | \r |
| 47 | for(i = 0; i < iSize; i++)\r |
| 48 | {\r |
| 49 | *pusPSXMem++ = *(unsigned short *)(spu.spuMemC + addr);\r |
| 50 | addr += 2;\r |
| 51 | addr &= 0x7fffe;\r |
| 52 | }\r |
| 53 | if (irq && (spu.spuCtrl & CTRL_IRQ))\r |
| 54 | log_unhandled("rdma spu irq: %x/%x+%x\n", irq_addr, spu.spuAddr, iSize * 2);\r |
| 55 | spu.spuAddr = addr;\r |
| 56 | set_dma_end(iSize, cycles);\r |
| 57 | }\r |
| 58 | \r |
| 59 | ////////////////////////////////////////////////////////////////////////\r |
| 60 | // WRITE DMA (many values)\r |
| 61 | ////////////////////////////////////////////////////////////////////////\r |
| 62 | \r |
| 63 | void CALLBACK SPUwriteDMAMem(unsigned short *pusPSXMem, int iSize,\r |
| 64 | unsigned int cycles)\r |
| 65 | {\r |
| 66 | unsigned int addr = spu.spuAddr, irq_addr = regAreaGet(H_SPUirqAddr) << 3;\r |
| 67 | int i, irq;\r |
| 68 | \r |
| 69 | do_samples_if_needed(cycles, 1, 2);\r |
| 70 | spu.bMemDirty = 1;\r |
| 71 | irq = addr <= irq_addr && irq_addr < addr + iSize*2;\r |
| 72 | \r |
| 73 | if (addr + iSize*2 < 0x80000)\r |
| 74 | {\r |
| 75 | memcpy(spu.spuMemC + addr, pusPSXMem, iSize*2);\r |
| 76 | addr += iSize*2;\r |
| 77 | }\r |
| 78 | else\r |
| 79 | {\r |
| 80 | irq |= irq_addr < ((addr + iSize*2) & 0x7ffff);\r |
| 81 | for (i = 0; i < iSize; i++)\r |
| 82 | {\r |
| 83 | *(unsigned short *)(spu.spuMemC + addr) = *pusPSXMem++;\r |
| 84 | addr += 2;\r |
| 85 | addr &= 0x7fffe;\r |
| 86 | }\r |
| 87 | }\r |
| 88 | if (irq && (spu.spuCtrl & CTRL_IRQ)) // unhandled because need to implement delay\r |
| 89 | log_unhandled("wdma spu irq: %x/%x+%x\n", irq_addr, spu.spuAddr, iSize * 2);\r |
| 90 | spu.spuAddr = addr;\r |
| 91 | set_dma_end(iSize, cycles);\r |
| 92 | }\r |
| 93 | \r |
| 94 | ////////////////////////////////////////////////////////////////////////\r |