Skip to content

Commit

Permalink
Added BSD patch script support
Browse files Browse the repository at this point in the history
Most commands implemented
Very few cmds pending (low usage)
  • Loading branch information
bucanero committed Mar 13, 2020
1 parent 4821406 commit bd2aa1a
Show file tree
Hide file tree
Showing 5 changed files with 1,285 additions and 5 deletions.
72 changes: 72 additions & 0 deletions include/crc_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**********************************************************************
*
* Filename: crc.h
*
* Description: Slow and fast implementations of the CRC standards.
*
*
* Copyright (c) 2000 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/

#ifndef CRC_H_INCLUDED
#define CRC_H_INCLUDED


#include <stdint.h>


#ifdef __cplusplus
extern "C" {
#endif


typedef struct
{
uint8_t bandwidth;
uint32_t polynomial;
uint32_t initial_value;
uint32_t output_xor;
uint8_t reflection_input;
uint8_t reflection_output;
} custom_crc_t;

/* ---------- Defines for 16-bit CRC/XMODEM calculation (Not reflected) --------------------------------------------------------- */
#define CRC_16_RESULT_WIDTH 16u
#define CRC_16_POLYNOMIAL 0x1021u
#define CRC_16_INIT_VALUE 0x0000u
#define CRC_16_XOR_VALUE 0x0000u

// 16-bit CCITT
//#define CRC_16_INIT_VALUE 0xFFFFu

/* ---------- Defines for 32-bit CRC/CCITT calculation (Reflected) -------------------------------------------------------------- */
#define CRC_32_RESULT_WIDTH 32u
#define CRC_32_POLYNOMIAL 0x04C11DB7u
#define CRC_32_INIT_VALUE 0xFFFFFFFFu
#define CRC_32_XOR_VALUE 0xFFFFFFFFu


/**
* This function makes a CRC16 calculation on Length data bytes
*
* RETURN VALUE: 16 bit result of CRC calculation
*/
uint16_t crc16_hash(const uint8_t* message, int nBytes, uint16_t Init, uint16_t Poly, uint8_t RefIn, uint8_t RefOut);

/**
* This function makes a CRC32 calculation on Length data bytes
*
* RETURN VALUE: 32 bit result of CRC calculation
*/
uint32_t crc32_hash(const uint8_t* message, int nBytes, uint32_t Init, uint32_t Poly, uint8_t RefIn, uint8_t RefOut);


#ifdef __cplusplus
}
#endif


#endif // CRC_H_INCLUDED
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#define APOLLO_VERSION "0.9.1" //Apollo PS3 version (about menu)
#define APOLLO_VERSION "1.0.0" //Apollo PS3 version (about menu)

#define MENU_TITLE_OFF 30 //Offset of menu title text from menu mini icon
#define MENU_ICON_OFF 70 //X Offset to start printing menu mini icon
Expand Down
4 changes: 2 additions & 2 deletions sfo.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<sfo>
<value name="APP_VER" type="string">
00.91
01.00
</value>
<value name="ATTRIBUTE" type="integer">
133
Expand Down Expand Up @@ -34,6 +34,6 @@
NP0APOLLO
</value>
<value name="VERSION" type="string">
00.91
01.00
</value>
</sfo>
135 changes: 135 additions & 0 deletions source/crc_util.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**********************************************************************
*
* Filename: crc.c
*
* Description: Slow and fast implementations of the CRC standards.
*
* Notes: The parameters for each supported CRC standard are
* defined in the header file crc.h. The implementations
* here should stand up to further additions to that list.
*
*
* Copyright (c) 2000 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/

#include <stdio.h>
#include "crc_util.h"


#define TOPBIT(W) (1 << (W - 1))
#define REFLECT_DATA(X) ((uint8_t) reflect((X), 8))
#define REFLECT_REMAINDER16(X) ((uint16_t) reflect((X), CRC_16_RESULT_WIDTH))
#define REFLECT_REMAINDER32(X) ((uint32_t) reflect((X), CRC_32_RESULT_WIDTH))


uint32_t reflect(uint32_t data, uint8_t nBits)
{
uint32_t reflection = 0;
uint8_t bit;
/*
* Reflect the data about the center bit.
*/
for (bit = 0; bit < nBits; ++bit)
{
/*
* If the LSB bit is set, set the reflection of it.
*/
if (data & 0x01)
{
reflection |= (1 << ((nBits - 1) - bit));
}

data = (data >> 1);
}

return (reflection);

} /* reflect() */

uint16_t crc16_hash(const uint8_t* message, int nBytes, uint16_t Init, uint16_t Poly, uint8_t RefIn, uint8_t RefOut)
{
uint16_t remainder = Init;
int byte;
uint8_t bit;

/*
* Perform modulo-2 division, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
/*
* Bring the next byte into the remainder.
*/
remainder ^= ((RefIn ? REFLECT_DATA(message[byte]) : message[byte]) << (CRC_16_RESULT_WIDTH - 8));

/*
* Perform modulo-2 division, a bit at a time.
*/
for (bit = 8; bit > 0; --bit)
{
/*
* Try to divide the current data bit.
*/
if (remainder & TOPBIT(CRC_16_RESULT_WIDTH))
{
remainder = (remainder << 1) ^ Poly;
}
else
{
remainder = (remainder << 1);
}
}
}

/*
* The final remainder is the CRC result.
*/
return (RefOut ? REFLECT_REMAINDER16(remainder) : remainder);

} /* crc16() */


uint32_t crc32_hash(const uint8_t* message, int nBytes, uint32_t Init, uint32_t Poly, uint8_t RefIn, uint8_t RefOut)
{
uint32_t remainder = Init;
int byte;
uint8_t bit;

/*
* Perform modulo-2 division, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
/*
* Bring the next byte into the remainder.
*/
remainder ^= ((RefIn ? REFLECT_DATA(message[byte]) : message[byte]) << (CRC_32_RESULT_WIDTH - 8));

/*
* Perform modulo-2 division, a bit at a time.
*/
for (bit = 8; bit > 0; --bit)
{
/*
* Try to divide the current data bit.
*/
if (remainder & TOPBIT(CRC_32_RESULT_WIDTH))
{
remainder = (remainder << 1) ^ Poly;
}
else
{
remainder = (remainder << 1);
}
}
}

/*
* The final remainder is the CRC result.
*/
return (RefOut ? REFLECT_REMAINDER32(remainder) : remainder);

} /* crc32() */
Loading

0 comments on commit bd2aa1a

Please sign in to comment.