Skip to content

Commit

Permalink
libchdr: Update to latest upstream
Browse files Browse the repository at this point in the history
Update libchdr based from latest upstream sources. Fixes some issues as noted.

- Latest upstream commit: https://github.com/rtissera/libchdr/tree/6117d59d00ef8620de4cff4d6ecae46368cae881

- Fix #301
- Specific commit that fixes above problem: rtissera/libchdr@e1acac6
  • Loading branch information
negativeExponent committed Jun 5, 2020
1 parent 7973b25 commit 9c659ff
Show file tree
Hide file tree
Showing 11 changed files with 2,118 additions and 2,100 deletions.
63 changes: 35 additions & 28 deletions deps/libchdr/bitstream.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
bitstream.c
Expand All @@ -11,15 +11,17 @@
#include "bitstream.h"
#include <stdlib.h>

//**************************************************************************
// INLINE FUNCTIONS
//**************************************************************************
/***************************************************************************
* INLINE FUNCTIONS
***************************************************************************
*/

int bitstream_overflow(struct bitstream* bitstream) { return ((bitstream->doffset - bitstream->bits / 8) > bitstream->dlength); }

//-------------------------------------------------
// create_bitstream - constructor
//-------------------------------------------------
/*-------------------------------------------------
* create_bitstream - constructor
*-------------------------------------------------
*/

struct bitstream* create_bitstream(const void *src, uint32_t srclength)
{
Expand All @@ -33,17 +35,18 @@ struct bitstream* create_bitstream(const void *src, uint32_t srclength)
}


//-----------------------------------------------------
// bitstream_peek - fetch the requested number of bits
// but don't advance the input pointer
//-----------------------------------------------------
/*-----------------------------------------------------
* bitstream_peek - fetch the requested number of bits
* but don't advance the input pointer
*-----------------------------------------------------
*/

uint32_t bitstream_peek(struct bitstream* bitstream, int numbits)
{
if (numbits == 0)
return 0;

// fetch data if we need more
/* fetch data if we need more */
if (numbits > bitstream->bits)
{
while (bitstream->bits <= 24)
Expand All @@ -55,15 +58,16 @@ uint32_t bitstream_peek(struct bitstream* bitstream, int numbits)
}
}

// return the data
/* return the data */
return bitstream->buffer >> (32 - numbits);
}


//-----------------------------------------------------
// bitstream_remove - advance the input pointer by the
// specified number of bits
//-----------------------------------------------------
/*-----------------------------------------------------
* bitstream_remove - advance the input pointer by the
* specified number of bits
*-----------------------------------------------------
*/

void bitstream_remove(struct bitstream* bitstream, int numbits)
{
Expand All @@ -72,9 +76,10 @@ void bitstream_remove(struct bitstream* bitstream, int numbits)
}


//-----------------------------------------------------
// bitstream_read - fetch the requested number of bits
//-----------------------------------------------------
/*-----------------------------------------------------
* bitstream_read - fetch the requested number of bits
*-----------------------------------------------------
*/

uint32_t bitstream_read(struct bitstream* bitstream, int numbits)
{
Expand All @@ -84,9 +89,10 @@ uint32_t bitstream_read(struct bitstream* bitstream, int numbits)
}


//-------------------------------------------------
// read_offset - return the current read offset
//-------------------------------------------------
/*-------------------------------------------------
* read_offset - return the current read offset
*-------------------------------------------------
*/

uint32_t bitstream_read_offset(struct bitstream* bitstream)
{
Expand All @@ -101,9 +107,10 @@ uint32_t bitstream_read_offset(struct bitstream* bitstream)
}


//-------------------------------------------------
// flush - flush to the nearest byte
//-------------------------------------------------
/*-------------------------------------------------
* flush - flush to the nearest byte
*-------------------------------------------------
*/

uint32_t bitstream_flush(struct bitstream* bitstream)
{
Expand Down
85 changes: 43 additions & 42 deletions deps/libchdr/bitstream.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
bitstream.h
Helper classes for reading/writing at the bit level.
***************************************************************************/

#pragma once

#ifndef __BITSTREAM_H__
#define __BITSTREAM_H__

#include <stdint.h>

//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************

// helper class for reading from a bit buffer
struct bitstream
{
uint32_t buffer; // current bit accumulator
int bits; // number of bits in the accumulator
const uint8_t * read; // read pointer
uint32_t doffset; // byte offset within the data
uint32_t dlength; // length of the data
};

struct bitstream* create_bitstream(const void *src, uint32_t srclength);
int bitstream_overflow(struct bitstream* bitstream);
uint32_t bitstream_read_offset(struct bitstream* bitstream);

uint32_t bitstream_read(struct bitstream* bitstream, int numbits);
uint32_t bitstream_peek(struct bitstream* bitstream, int numbits);
void bitstream_remove(struct bitstream* bitstream, int numbits);
uint32_t bitstream_flush(struct bitstream* bitstream);


#endif
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
bitstream.h
Helper classes for reading/writing at the bit level.
***************************************************************************/

#pragma once

#ifndef __BITSTREAM_H__
#define __BITSTREAM_H__

#include <stdint.h>

/***************************************************************************
* TYPE DEFINITIONS
***************************************************************************
*/

/* helper class for reading from a bit buffer */
struct bitstream
{
uint32_t buffer; /* current bit accumulator */
int bits; /* number of bits in the accumulator */
const uint8_t * read; /* read pointer */
uint32_t doffset; /* byte offset within the data */
uint32_t dlength; /* length of the data */
};

struct bitstream* create_bitstream(const void *src, uint32_t srclength);
int bitstream_overflow(struct bitstream* bitstream);
uint32_t bitstream_read_offset(struct bitstream* bitstream);

uint32_t bitstream_read(struct bitstream* bitstream, int numbits);
uint32_t bitstream_peek(struct bitstream* bitstream, int numbits);
void bitstream_remove(struct bitstream* bitstream, int numbits);
uint32_t bitstream_flush(struct bitstream* bitstream);


#endif
Loading

0 comments on commit 9c659ff

Please sign in to comment.