Files
Cesarus85--ringfall-mjolnir-vr/source/memory/crc.c
T
2026-07-14 16:07:35 -07:00

111 lines
1.9 KiB
C

/*
CRC.C
symbols in this file:
001088D0 0010:
_crc_new (0000)
001088E0 0040:
_code_001088e0 (0000)
00108920 0080:
_crc_checksum_buffer (0000)
0027D2E4 000f:
??_C@_0P@JPGOHOCM@buffer_size?$DO?$DN0?$AA@ (0000)
0027D2F4 001c:
??_C@_0BM@FPJPBIIF@c?3?2halo?2SOURCE?2memory?2crc?4c?$AA@ (0000)
00456220 0401:
_bss_00456220 (0000)
*/
/* ---------- headers */
#include "cseries.h"
#include "memory/crc.h"
/* ---------- constants */
/* ---------- macros */
/* ---------- structures */
#pragma pack(push, 1)
struct crc_globals
{
unsigned long table[256];
boolean initialized;
};
#pragma pack(pop)
/* ---------- prototypes */
/* ---------- globals */
#pragma bss_seg(".bss")
struct crc_globals crc_state;
#pragma bss_seg()
/* ---------- public code */
void crc_new(unsigned long *crc_reference)
{
*crc_reference = 0xFFFFFFFF;
}
/* Initializes the CRC-32 lookup table; the private function has no surviving PDB name. */
__declspec(noinline) static void code_001088e0(unsigned long *crc_table)
{
unsigned long byte_index;
long byte_count;
byte_index = 0;
byte_count = 256;
do
{
unsigned long crc = byte_index;
long bit_count;
bit_count = 8;
do
{
if (crc & 1)
crc = (crc >> 1) ^ 0xEDB88320;
else
crc >>= 1;
} while (--bit_count);
*crc_table = crc;
byte_index++;
crc_table++;
} while (--byte_count);
}
void crc_checksum_buffer(unsigned long *crc_reference, void const *buffer, long buffer_size)
{
unsigned long crc;
unsigned long table_index;
match_assert("c:\\halo\\SOURCE\\memory\\crc.c", 42, buffer_size>=0);
if (!crc_state.initialized)
{
code_001088e0(crc_state.table);
crc_state.initialized = TRUE;
}
crc = *crc_reference;
if (buffer_size > 0)
{
do
{
table_index = (*(byte const *)buffer ^ crc) & 0xFF;
table_index = crc_state.table[table_index];
crc >>= 8;
buffer = (byte const *)buffer + 1;
crc ^= table_index;
} while (--buffer_size);
}
*crc_reference = crc;
}
/* ---------- private code */