PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
common.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#include <kernel.h>
17#include <sifrpc.h>
18
19#include "slib.h"
20#include "smod.h"
21
22#include "common.h"
23
24struct smem_buf smem_buf ALIGNED(64);
25
26/* Do not link to memcmp() from libc, so we only depend on libkernel. */
27int __memcmp(const void *s1, const void *s2, unsigned int length)
28{
29 const char *a = s1;
30 const char *b = s2;
31
32 while (length--) {
33 if (*a++ != *b++)
34 return 1;
35 }
36
37 return 0;
38}
39
40int smem_write_word(void *address, u32 value)
41{
43 void *pDestRounded;
44 int result;
46
47 pDestRounded=(void*)(((u32)address)&0xFFFFFFC0);
48 SyncDCache(&smem_buf, smem_buf.bytes+64);
49 if((result=SifRpcGetOtherData(&RData, pDestRounded, &smem_buf, 64, 0))>=0)
50 {
51 *(u32*)UNCACHED_SEG((&smem_buf.bytes[((u32)address&0x3F)]))=value;
52
53 dmat.src=&smem_buf;
54 dmat.dest=pDestRounded;
55 dmat.size=64;
56 dmat.attr=0;
57 SifSetDma(&dmat, 1);
58 }
59
60 return result;
61}