Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[merge conflicts] update libchdr based on latest upstream #163

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LIBCHDR_INCFLAGS = \
-I$(DEPS_DIR)/flac-1.3.2/include \
-I$(DEPS_DIR)/flac-1.3.2/src/libFLAC/include \
-I$(DEPS_DIR)/lzma-16.04/C \
-I$(DEPS_DIR)/libchdr
-I$(DEPS_DIR)/include
LIBCHDR_SOURCES_C = \
$(DEPS_DIR)/crypto/md5.c \
$(DEPS_DIR)/crypto/sha1.c \
Expand Down Expand Up @@ -57,11 +57,11 @@ LIBCHDR_SOURCES_C = \
$(DEPS_DIR)/lzma-16.04/C/LzmaEnc.c \
$(DEPS_DIR)/lzma-16.04/C/LzmaLib.c \
$(DEPS_DIR)/lzma-16.04/C/Sort.c \
$(DEPS_DIR)/libchdr/bitstream.c \
$(DEPS_DIR)/libchdr/cdrom.c \
$(DEPS_DIR)/libchdr/chd.c \
$(DEPS_DIR)/libchdr/flac.c \
$(DEPS_DIR)/libchdr/huffman.c
$(DEPS_DIR)/libchdr/libchdr_bitstream.c \
$(DEPS_DIR)/libchdr/libchdr_cdrom.c \
$(DEPS_DIR)/libchdr/libchdr_chd.c \
$(DEPS_DIR)/libchdr/libchdr_flac.c \
$(DEPS_DIR)/libchdr/libchdr_huffman.c

ZLIB_INCFLAGS = -I$(DEPS_DIR)/zlib
ZLIB_SOURCES_C = \
Expand Down
85 changes: 43 additions & 42 deletions deps/libchdr/bitstream.h → deps/include/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
217 changes: 109 additions & 108 deletions deps/libchdr/cdrom.h → deps/include/libchdr/cdrom.h
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

cdrom.h

Generic MAME cd-rom implementation

***************************************************************************/

#pragma once

#ifndef __CDROM_H__
#define __CDROM_H__

#include <stdint.h>

#include <retro_inline.h>

/***************************************************************************
CONSTANTS
***************************************************************************/

// tracks are padded to a multiple of this many frames
extern const uint32_t CD_TRACK_PADDING;

#define CD_MAX_TRACKS (99) /* AFAIK the theoretical limit */
#define CD_MAX_SECTOR_DATA (2352)
#define CD_MAX_SUBCODE_DATA (96)

#define CD_FRAME_SIZE (CD_MAX_SECTOR_DATA + CD_MAX_SUBCODE_DATA)
#define CD_FRAMES_PER_HUNK (8)

#define CD_METADATA_WORDS (1+(CD_MAX_TRACKS * 6))

enum
{
CD_TRACK_MODE1 = 0, /* mode 1 2048 bytes/sector */
CD_TRACK_MODE1_RAW, /* mode 1 2352 bytes/sector */
CD_TRACK_MODE2, /* mode 2 2336 bytes/sector */
CD_TRACK_MODE2_FORM1, /* mode 2 2048 bytes/sector */
CD_TRACK_MODE2_FORM2, /* mode 2 2324 bytes/sector */
CD_TRACK_MODE2_FORM_MIX, /* mode 2 2336 bytes/sector */
CD_TRACK_MODE2_RAW, /* mode 2 2352 bytes / sector */
CD_TRACK_AUDIO, /* redbook audio track 2352 bytes/sector (588 samples) */

CD_TRACK_RAW_DONTCARE /* special flag for cdrom_read_data: just return me whatever is there */
};

enum
{
CD_SUB_NORMAL = 0, /* "cooked" 96 bytes per sector */
CD_SUB_RAW, /* raw uninterleaved 96 bytes per sector */
CD_SUB_NONE /* no subcode data stored */
};

#define CD_FLAG_GDROM 0x00000001 // disc is a GD-ROM, all tracks should be stored with GD-ROM metadata
#define CD_FLAG_GDROMLE 0x00000002 // legacy GD-ROM, with little-endian CDDA data

/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/

// ECC utilities
int ecc_verify(const uint8_t *sector);
void ecc_generate(uint8_t *sector);
void ecc_clear(uint8_t *sector);



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

static INLINE uint32_t msf_to_lba(uint32_t msf)
{
return ( ((msf&0x00ff0000)>>16) * 60 * 75) + (((msf&0x0000ff00)>>8) * 75) + ((msf&0x000000ff)>>0);
}

static INLINE uint32_t lba_to_msf(uint32_t lba)
{
uint8_t m, s, f;

m = lba / (60 * 75);
lba -= m * (60 * 75);
s = lba / 75;
f = lba % 75;

return ((m / 10) << 20) | ((m % 10) << 16) |
((s / 10) << 12) | ((s % 10) << 8) |
((f / 10) << 4) | ((f % 10) << 0);
}

// segacd needs it like this.. investigate
// Angelo also says PCE tracks often start playing at the
// wrong address.. related?
static INLINE uint32_t lba_to_msf_alt(int lba)
{
uint32_t ret = 0;

ret |= ((lba / (60 * 75))&0xff)<<16;
ret |= (((lba / 75) % 60)&0xff)<<8;
ret |= ((lba % 75)&0xff)<<0;

return ret;
}

#endif // __CDROM_H__
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************

cdrom.h

Generic MAME cd-rom implementation

***************************************************************************/

#pragma once

#ifndef __CDROM_H__
#define __CDROM_H__

#include <stdint.h>


/***************************************************************************
CONSTANTS
***************************************************************************/

/* tracks are padded to a multiple of this many frames */
extern const uint32_t CD_TRACK_PADDING;

#define CD_MAX_TRACKS (99) /* AFAIK the theoretical limit */
#define CD_MAX_SECTOR_DATA (2352)
#define CD_MAX_SUBCODE_DATA (96)

#define CD_FRAME_SIZE (CD_MAX_SECTOR_DATA + CD_MAX_SUBCODE_DATA)
#define CD_FRAMES_PER_HUNK (8)

#define CD_METADATA_WORDS (1+(CD_MAX_TRACKS * 6))

enum
{
CD_TRACK_MODE1 = 0, /* mode 1 2048 bytes/sector */
CD_TRACK_MODE1_RAW, /* mode 1 2352 bytes/sector */
CD_TRACK_MODE2, /* mode 2 2336 bytes/sector */
CD_TRACK_MODE2_FORM1, /* mode 2 2048 bytes/sector */
CD_TRACK_MODE2_FORM2, /* mode 2 2324 bytes/sector */
CD_TRACK_MODE2_FORM_MIX, /* mode 2 2336 bytes/sector */
CD_TRACK_MODE2_RAW, /* mode 2 2352 bytes / sector */
CD_TRACK_AUDIO, /* redbook audio track 2352 bytes/sector (588 samples) */

CD_TRACK_RAW_DONTCARE /* special flag for cdrom_read_data: just return me whatever is there */
};

enum
{
CD_SUB_NORMAL = 0, /* "cooked" 96 bytes per sector */
CD_SUB_RAW, /* raw uninterleaved 96 bytes per sector */
CD_SUB_NONE /* no subcode data stored */
};

#define CD_FLAG_GDROM 0x00000001 /* disc is a GD-ROM, all tracks should be stored with GD-ROM metadata */
#define CD_FLAG_GDROMLE 0x00000002 /* legacy GD-ROM, with little-endian CDDA data */

/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/

/* ECC utilities */
int ecc_verify(const uint8_t *sector);
void ecc_generate(uint8_t *sector);
void ecc_clear(uint8_t *sector);



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

static inline uint32_t msf_to_lba(uint32_t msf)
{
return ( ((msf&0x00ff0000)>>16) * 60 * 75) + (((msf&0x0000ff00)>>8) * 75) + ((msf&0x000000ff)>>0);
}

static inline uint32_t lba_to_msf(uint32_t lba)
{
uint8_t m, s, f;

m = lba / (60 * 75);
lba -= m * (60 * 75);
s = lba / 75;
f = lba % 75;

return ((m / 10) << 20) | ((m % 10) << 16) |
((s / 10) << 12) | ((s % 10) << 8) |
((f / 10) << 4) | ((f % 10) << 0);
}

/**
* segacd needs it like this.. investigate
* Angelo also says PCE tracks often start playing at the
* wrong address.. related?
**/
static inline uint32_t lba_to_msf_alt(int lba)
{
uint32_t ret = 0;

ret |= ((lba / (60 * 75))&0xff)<<16;
ret |= (((lba / 75) % 60)&0xff)<<8;
ret |= ((lba % 75)&0xff)<<0;

return ret;
}

#endif /* __CDROM_H__ */
Loading