1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 21:40:03 +00:00
oot/src/code/z_ss_sram.c
Tharo f9d96d9f73
Fix most compiler warnings in the boot and code segments (#674)
* Less warnings in boot & code segments

* few more warnings gone

* Ran formatter

* z_view warning gone

* -> 1

* f31 -> 31

* Remove function casts

* Few more small improvements

* Separate declaration and assignment in func_80091738 and Item_Give

Co-authored-by: Thar0 <maximilianc64@gmail.com>
2021-02-13 19:49:40 -05:00

53 lines
2.1 KiB
C

#include "ultra64.h"
#include "global.h"
typedef struct {
/* 0x00 */ OSPiHandle piHandle;
/* 0x74 */ OSIoMesg ioMesg;
/* 0x8C */ OSMesgQueue mesgQ;
} SsSramContext; // size = 0xA4
SsSramContext sSsSramContext = { 0 };
void SsSram_Init(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed) {
u32 prevInt;
OSPiHandle* handle = &sSsSramContext.piHandle;
if ((u32)OS_PHYSICAL_TO_K1(addr) != (*handle).baseAddress) {
sSsSramContext.piHandle.type = handleType;
(*handle).baseAddress = OS_PHYSICAL_TO_K1(addr);
sSsSramContext.piHandle.latency = handleLatency;
sSsSramContext.piHandle.pulse = handlePulse;
sSsSramContext.piHandle.pageSize = handlePageSize;
sSsSramContext.piHandle.relDuration = handleRelDuration;
sSsSramContext.piHandle.domain = handleDomain;
sSsSramContext.piHandle.speed = handleSpeed;
bzero(&sSsSramContext.piHandle.transferInfo, sizeof(__OSTranxInfo));
prevInt = __osDisableInt();
sSsSramContext.piHandle.next = __osPiTable;
__osPiTable = &sSsSramContext.piHandle;
__osRestoreInt(prevInt);
sSsSramContext.ioMesg.hdr.pri = 0;
sSsSramContext.ioMesg.hdr.retQueue = &sSsSramContext.mesgQ;
sSsSramContext.ioMesg.devAddr = addr;
}
}
void SsSram_Dma(void* dramAddr, size_t size, s32 direction) {
OSMesg mesg;
osCreateMesgQueue(&sSsSramContext.mesgQ, &mesg, 1);
sSsSramContext.ioMesg.dramAddr = dramAddr;
sSsSramContext.ioMesg.size = size;
osWritebackDCache(dramAddr, size);
osEPiStartDma(&sSsSramContext.piHandle, &sSsSramContext.ioMesg, direction);
osRecvMesg(&sSsSramContext.mesgQ, &mesg, OS_MESG_BLOCK);
osInvalDCache(dramAddr, size);
}
void SsSram_ReadWrite(u32 addr, void* dramAddr, size_t size, s32 direction) {
osSyncPrintf("ssSRAMReadWrite:%08x %08x %08x %d\n", addr, dramAddr, size, direction);
SsSram_Init(addr, DEVICE_TYPE_SRAM, 1, 5, 0xD, 2, 0xC, 0);
SsSram_Dma(dramAddr, size, direction);
}