22extern void SetDmaWrite(s32 chan);
23extern void SetDmaRead(s32 chan);
25extern u32 DmaStop(u32 core);
28s32 BlockTransWriteFrom(u8 *iopaddr, u32 size, s32 chan, u16 mode, u8 *startaddr)
33 BlockTransBuff[core] = 0;
34 BlockTransSize[core] = size;
35 BlockTransAddr[core] = (u32)iopaddr;
40 offset = startaddr - iopaddr;
42 if((u32)offset > size)
44 if(mode & SD_TRANS_LOOP)
47 BlockTransBuff[core] = 1;
55 if(offset & 1023) offset += 1024;
57 iopaddr += (BlockTransSize[core] * BlockTransBuff[core]) + offset;
59 if(U16_REGISTER_READ(SD_CORE_ATTR(core)) & SD_DMA_IN_PROCESS)
return -1;
60 if(U32_REGISTER_READ(SD_DMA_CHCR(core)) & SD_DMA_START)
return -1;
62 U16_REGISTER_WRITEAND(SD_CORE_ATTR(core), 0xFFCF);
64 U16_REGISTER_WRITE(SD_A_TSA_HI(core), 0);
65 U16_REGISTER_WRITE(SD_A_TSA_LO(core), 0);
67 U16_REGISTER_WRITE(U16_REGISTER(0x1B0+(core*1024)), 1 << core);
71 U32_REGISTER_WRITE(SD_DMA_ADDR(core), (u32)iopaddr);
72 U16_REGISTER_WRITE(SD_DMA_MODE(core), 0x10);
73 U16_REGISTER_WRITE(SD_DMA_SIZE(core), (size/64)+((size&63)>0));
74 U32_REGISTER_WRITE(SD_DMA_CHCR(core), SD_DMA_CS | SD_DMA_START | SD_DMA_DIR_IOP2SPU);
79s32 BlockTransWrite(u8 *iopaddr, u32 size, s32 chan)
83 BlockTransBuff[core] = 0;
84 BlockTransSize[core] = size;
85 BlockTransAddr[core] = (u32)iopaddr;
87 if(U16_REGISTER_READ(SD_CORE_ATTR(core)) & SD_DMA_IN_PROCESS)
return -1;
88 if(U32_REGISTER_READ(SD_DMA_CHCR(core)) & SD_DMA_START)
return -1;
90 U16_REGISTER_WRITEAND(SD_CORE_ATTR(core), 0xFFCF);
92 U16_REGISTER_WRITE(SD_A_TSA_HI(core), 0);
93 U16_REGISTER_WRITE(SD_A_TSA_LO(core), 0);
95 U16_REGISTER_WRITE(U16_REGISTER(0x1B0+(core*1024)), 1 << core);
99 U32_REGISTER_WRITE(SD_DMA_ADDR(core), (u32)iopaddr);
100 U16_REGISTER_WRITE(SD_DMA_MODE(core), 0x10);
101 U16_REGISTER_WRITE(SD_DMA_SIZE(core), (size/64)+((size&63)>0));
102 U32_REGISTER_WRITE(SD_DMA_CHCR(core), SD_DMA_CS | SD_DMA_START | SD_DMA_DIR_IOP2SPU);
108s32 BlockTransRead(u8 *iopaddr, u32 size, s32 chan, s16 mode)
114 BlockTransBuff[core] = 0;
115 BlockTransSize[core] = size;
116 BlockTransAddr[core] = (u32)iopaddr;
118 if(U16_REGISTER_READ(SD_CORE_ATTR(core)) & SD_DMA_IN_PROCESS)
return -1;
119 if(U32_REGISTER_READ(SD_DMA_CHCR(core)) & SD_DMA_START)
return -1;
121 U16_REGISTER_WRITEAND(SD_CORE_ATTR(core), 0xFFCF);
123 U16_REGISTER_WRITE(SD_A_TSA_HI(core), 0);
124 U16_REGISTER_WRITE(SD_A_TSA_LO(core), ((mode & 0xF00) << 1) + 0x400);
126 U16_REGISTER_WRITE(U16_REGISTER(0x1AE + (core*1024)), (mode & 0xF000) >> 11);
132 U16_REGISTER_WRITE(U16_REGISTER(0x1B0+(core*1024)), 4);
136 U32_REGISTER_WRITE(SD_DMA_ADDR(core), (u32)iopaddr);
137 U16_REGISTER_WRITE(SD_DMA_MODE(core), 0x10);
138 U16_REGISTER_WRITE(SD_DMA_SIZE(core), (size/64)+((size&63)>0));
139 U32_REGISTER_WRITE(SD_DMA_CHCR(core), SD_DMA_CS | SD_DMA_START | SD_DMA_DIR_SPU2IOP);
146int sceSdBlockTrans(s16 chan, u16 mode, u8 *iopaddr, u32 size, ...)
148 int transfer_dir = mode & 3;
156 TransIntrData[core].mode = 0x100 | core;
158 if(mode & SD_TRANS_LOOP)
160 TransIntrData[core].mode |= SD_TRANS_LOOP << 8;
164 if(BlockTransWrite(iopaddr, _size, core) >= 0)
171 TransIntrData[core].mode = 0x300 | core;
173 if(mode & SD_TRANS_LOOP)
175 TransIntrData[core].mode |= SD_TRANS_LOOP << 8;
179 if(BlockTransRead(iopaddr, _size, chan, mode) >= 0)
186 return DmaStop(core);
190 case SD_TRANS_WRITE_FROM:
195 va_start(alist, size);
196 startaddr = va_arg(alist, u8*);
199 TransIntrData[core].mode = 0x100 | core;
201 if(mode & SD_TRANS_LOOP)
203 TransIntrData[core].mode |= SD_TRANS_LOOP << 8;
207 if(BlockTransWriteFrom(iopaddr, _size, core, mode, startaddr) >= 0)
217u32 sceSdBlockTransStatus(s16 chan, s16 flag)
225 if(U16_REGISTER_READ(U16_REGISTER(0x1B0 + (chan * 1024))) == 0)
228 retval = U32_REGISTER_READ(SD_DMA_ADDR(chan));
230 retval = (BlockTransBuff[chan] << 24) | (retval & 0xFFFFFF);