sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

crc.c (914B)


      1 #include "libultra_internal.h"
      2 
      3 u8 __osContAddressCrc(u16 addr) {
      4     u8 temp;
      5     u8 temp2;
      6     int i;
      7     temp = 0;
      8     for (i = 0; i < 16; i++) {
      9         if (temp & 0x10) {
     10             temp2 = 21;
     11         } else {
     12             temp2 = 0;
     13         }
     14 
     15         temp <<= 1;
     16         temp |= (u8)((addr & 0x400) ? 1 : 0);
     17         addr <<= 1;
     18         temp ^= temp2;
     19     }
     20     return temp & 0x1f;
     21 }
     22 
     23 u8 __osContDataCrc(u8 *data) {
     24     u8 temp;
     25     u8 temp2;
     26     int i;
     27     int j;
     28     temp = 0;
     29     for (i = 0; i <= 32; i++, data++) {
     30         for (j = 7; j >= 0; j--) {
     31             if (temp & 0x80) {
     32                 temp2 = 133;
     33             } else {
     34                 temp2 = 0;
     35             }
     36             temp <<= 1;
     37             if (i == 32) {
     38                 temp &= -1;
     39             } else {
     40                 temp |= ((*data & (1 << j)) ? 1 : 0);
     41             }
     42             temp ^= temp2;
     43         }
     44     }
     45     return temp;
     46 }