the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 117 lines 3.8 kB view raw
1/* SCE CONFIDENTIAL 2PlayStation(R)3 Programmer Tool Runtime Library 430.001 3* Copyright (C) 2007 Sony Computer Entertainment Inc. 4* All Rights Reserved. 5*/ 6 7/* common headers */ 8#include "spu_assert.h" 9#include <cell/dma.h> 10#include <cell/spurs/job_queue.h> 11 12extern CellSpursJobContext2* g_pSpursJobContext; 13 14class DmaData_SPU 15{ 16public: 17 static const bool sc_verbose = false; 18 19 static int roundUpDMASize(int size) 20 { 21 return (size + 0x0f) & (~0x0f); 22 } 23 24 static void get(void* dest, uintptr_t ea, unsigned int dmaSize) 25 { 26 spu_assert((ea % 0x10) == 0); // make sure we're 16 byte aligned 27 spu_assert((uint32_t(dest) % 0x10) == 0); // make sure we're 16 byte aligned 28 spu_assert((dmaSize % 0x10) == 0); // and that the transfer is a multiple of 16 bytes 29 spu_assert(ea >256*1024); // and that we're not targetting SPU memory 30 // start memory transfer 31 if(sc_verbose) 32 spu_print("DMA PPU->SPU start: 0x%08x -> 0x%08x : size : %d bytes : tag %d .... ", (unsigned int)ea, (unsigned int)dest, dmaSize, g_pSpursJobContext->dmaTag); 33 34 cellDmaLargeGet(dest, ea, dmaSize, g_pSpursJobContext->dmaTag, 0, 0); 35 } 36 37 static void getUnaligned(void* dest, uintptr_t ea, unsigned int dmaSize) 38 { 39 spu_assert(ea >256*1024); // and that we're not targetting SPU memory 40 // start memory transfer 41 if(sc_verbose) 42 spu_print("DMA PPU->SPU start: 0x%08x -> 0x%08x : size : %d bytes : tag %d .... ", (unsigned int)ea, (unsigned int)dest, dmaSize, g_pSpursJobContext->dmaTag); 43 44 cellDmaUnalignedGet(dest, ea, dmaSize, g_pSpursJobContext->dmaTag, 0, 0); 45 } 46 47 48 static uint32_t getValue32(uintptr_t ea) 49 { 50 return cellDmaGetUint32(ea, g_pSpursJobContext->dmaTag, 0, 0); 51 } 52 static uint32_t getValue16(uintptr_t ea) 53 { 54 return cellDmaGetUint16(ea, g_pSpursJobContext->dmaTag, 0, 0); 55 } 56 static uint32_t getValue64(uintptr_t ea) 57 { 58 return cellDmaGetUint64(ea, g_pSpursJobContext->dmaTag, 0, 0); 59 } 60 61 62 static void wait() 63 { 64 cellDmaWaitTagStatusAll(1 << g_pSpursJobContext->dmaTag); 65 if(sc_verbose) 66 spu_print("DMA PPU->SPU done!\n"); 67 } 68 69 static void getAndWait(void* dest, uintptr_t ea, unsigned int dmaSize) 70 { 71 get(dest, ea, dmaSize); 72 wait(); 73 } 74 75 static void getAndWaitUnaligned(void* dest, uintptr_t ea, unsigned int dmaSize) 76 { 77 getUnaligned(dest, ea, dmaSize); 78 wait(); 79 } 80 81 static void put(void* src, uintptr_t ea, unsigned int dmaSize) 82 { 83 if(sc_verbose) 84 spu_print("DMA SPU->PPU start: 0x%08x -> 0x%08x : size : %d bytes .... ", (unsigned int)src, (unsigned int)ea, dmaSize); 85 spu_assert((ea % 0x10) == 0); // make sure we're 16 byte aligned 86 spu_assert((uint32_t(src) % 0x10) == 0); // make sure we're 16 byte aligned 87 spu_assert((dmaSize % 0x10) == 0); // and that the transfer is a multiple of 16 bytes 88 spu_assert(ea >256*1024); // and that we're not targetting SPU memory 89 cellDmaLargePut(src, ea, dmaSize, g_pSpursJobContext->dmaTag, 0, 0); 90 } 91 92 static void putAndWait(void* src, uintptr_t ea, unsigned int dmaSize) 93 { 94 put(src, ea, dmaSize); 95 wait(); 96 } 97 static void putAndWaitUnaligned(void* src, uintptr_t ea, unsigned int dmaSize) 98 { 99 if(sc_verbose) 100 spu_print("DMA SPU->PPU : 0x%08x -> 0x%08x : size : %d bytes\n", (unsigned int)src, (unsigned int)ea, dmaSize); 101 spu_assert((ea % 0x10) == 0); // make sure we're 16 byte aligned 102 spu_assert((uint32_t(src) % 0x10) == 0); // make sure we're 16 byte aligned 103 spu_assert((dmaSize % 0x10) == 0); // and that the transfer is a multiple of 16 bytes 104 spu_assert(ea >256*1024); // and that we're not targetting SPU memory 105 cellDmaUnalignedPut(src, ea, dmaSize, g_pSpursJobContext->dmaTag, 0, 0); 106 cellDmaWaitTagStatusAll(1 << g_pSpursJobContext->dmaTag); 107 if(sc_verbose) 108 spu_print("DMA SPU->PPU complete\n"); 109 } 110 111 static void putValue32(uint32_t val, uintptr_t ea) 112 { 113 cellDmaPutUint32(val, ea, g_pSpursJobContext->dmaTag, 0, 0); 114 } 115 116}; 117