summaryrefslogtreecommitdiff
path: root/src/libultra_code/__osContRamWrite.c
diff options
context:
space:
mode:
authorLucas Shaw <49287729+shawlucas@users.noreply.github.com>2020-07-06 17:15:01 -0700
committerGitHub <noreply@github.com>2020-07-06 20:15:01 -0400
commit7e195a35621e629f47be7ebd70f91775a01498da (patch)
treef2f1ef0440bce50131dd18547ee63ab268be42f0 /src/libultra_code/__osContRamWrite.c
parente6ca2dfd70ef4f76af85b8492e67fb17b1e4dc71 (diff)
Matched most remaining libultra files (#221)
* osPfsIsPlug.c and osContSetCh.c OK * update * __osPfsGetStatus.c OK * removed unused asm * Updated all libultra controller files to use new structs instead of the temporary structs. Added os_pfs.h * controller updates * fixed header guard * Made suggested changes * guLookAt.c OK * commit * __osPfsSelectBank.c OK * osPfsDeleteFile.c OK * pfsreadwritefile.c OK * osPfsFreeBlocks.c OK * cleaned up ospfsfreeblocks * started pfsinitpak.c * pfsallocatefile.c OK * contpfs.c decompiled with 1 non matching * osPfsFindFile.c OK * pfsinitpak.c decompiled. one non-matching * Actually fixed merge conflict * sins.c OK * cosf.c sinf.c and sins.c OK * moved osAfterPreNMI to its own file. Renamed code_801031F0 to contquery.c * pfschecker.c OK * final update and rename * Removed makefile testing thing that i accidentally added * Made suggested changes
Diffstat (limited to 'src/libultra_code/__osContRamWrite.c')
-rw-r--r--src/libultra_code/__osContRamWrite.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/libultra_code/__osContRamWrite.c b/src/libultra_code/__osContRamWrite.c
new file mode 100644
index 000000000..d26ca579e
--- /dev/null
+++ b/src/libultra_code/__osContRamWrite.c
@@ -0,0 +1,68 @@
+#include <ultra64.h>
+#include <ultra64/controller.h>
+#include <global.h>
+
+s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 force) {
+ s32 ret = 0;
+ s32 i;
+ u8* ptr;
+ s32 retry = 2;
+ u8 crc;
+
+ if ((force != PFS_FORCE) && (address < PFS_LABEL_AREA) && (address != 0)) {
+ return 0;
+ }
+
+ __osSiGetAccess();
+
+ do {
+ ptr = (u8*)(&pifMempakBuf);
+
+ if (__osContLastPoll != CONT_CMD_WRITE_MEMPACK || __osPfsLastChannel != channel) {
+ __osContLastPoll = CONT_CMD_WRITE_MEMPACK;
+ __osPfsLastChannel = channel;
+
+ // clang-format off
+ for (i = 0; i < channel; i++) { *ptr++ = 0; }
+ // clang-format on
+
+ pifMempakBuf.status = 1;
+
+ ((__OSContRamHeader*)ptr)->unk_00 = 0xff;
+ ((__OSContRamHeader*)ptr)->txsize = 35;
+ ((__OSContRamHeader*)ptr)->rxsize = 1;
+ ((__OSContRamHeader*)ptr)->poll = CONT_CMD_WRITE_MEMPACK;
+ ((__OSContRamHeader*)ptr)->datacrc = 0xff;
+
+ ptr[sizeof(__OSContRamHeader)] = CONT_CMD_END;
+ } else {
+ ptr += channel;
+ }
+ ((__OSContRamHeader*)ptr)->hi = address >> 3;
+ ((__OSContRamHeader*)ptr)->lo = ((address << 5) | __osContAddressCrc(address));
+
+ bcopy(buffer, ((__OSContRamHeader*)ptr)->data, BLOCKSIZE);
+
+ ret = __osSiRawStartDma(OS_WRITE, &pifMempakBuf);
+ crc = __osContDataCrc(buffer);
+ osRecvMesg(mq, (OSMesg*)NULL, OS_MESG_BLOCK);
+
+ ret = __osSiRawStartDma(OS_READ, &pifMempakBuf);
+ osRecvMesg(mq, (OSMesg*)NULL, OS_MESG_BLOCK);
+
+ ret = ((((__OSContRamHeader*)ptr)->rxsize & 0xC0) >> 4);
+ if (!ret) {
+ if (crc != ((__OSContRamHeader*)ptr)->datacrc) {
+ if ((ret = __osPfsGetStatus(mq, channel))) {
+ break;
+ } else {
+ ret = PFS_ERR_CONTRFAIL;
+ }
+ }
+ } else {
+ ret = PFS_ERR_NOPACK;
+ }
+ } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0));
+ __osSiRelAccess();
+ return ret;
+}