1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-23 22:05:09 +00:00
oot/src/libultra_code/__osContAddressCrc.c
Lucas Shaw 7e195a3562
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
2020-07-06 20:15:01 -04:00

68 lines
1.4 KiB
C

#include <ultra64.h>
#include <global.h>
#include <ultra64/controller.h>
// Valid addr up to 0x7FF
// It's the address of a block of 0x20 bytes in the mempak
// So that means the whole mempak has a 16-bit address space
u8 __osContAddressCrc(u16 addr) {
u32 addr32 = addr;
u32 ret = 0;
u32 bit;
s32 i;
for (bit = 0x400; bit; bit /= 2) {
ret *= 2;
if (addr32 & bit) {
if (ret & 0x20) {
ret ^= 0x14;
} else {
++ret;
}
} else {
if (ret & 0x20) {
ret ^= 0x15;
}
}
}
for (i = 0; i < 5; ++i) {
ret <<= 1;
if (ret & 0x20) {
ret ^= 0x15;
}
}
return ret & 0x1f;
}
u8 __osContDataCrc(u8* data) {
s32 ret;
u32 bit;
u32 byte;
ret = 0;
for (byte = 0x20; byte; --byte, ++data) {
for (bit = 0x80; bit; bit /= 2) {
ret *= 2;
if ((*data & bit) != 0) {
if ((ret & 0x100) != 0) {
ret ^= 0x84;
} else {
++ret;
}
} else {
if (ret & 0x100) {
ret ^= 0x85;
}
}
}
}
do {
ret *= 2;
if (ret & 0x100) {
ret ^= 0x85;
}
++byte;
} while (byte < 8U);
return ret;
}