2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-10-02 06:56:10 +00:00
|
|
|
#ifndef CIRCLE_BUFFER_H
|
|
|
|
#define CIRCLE_BUFFER_H
|
|
|
|
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/common.h>
|
2013-10-02 06:56:10 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_START
|
|
|
|
|
2024-04-13 06:27:37 +00:00
|
|
|
struct mCircleBuffer {
|
2013-10-02 06:56:10 +00:00
|
|
|
void* data;
|
2014-07-21 06:56:12 +00:00
|
|
|
size_t capacity;
|
|
|
|
size_t size;
|
2013-10-02 06:56:10 +00:00
|
|
|
void* readPtr;
|
|
|
|
void* writePtr;
|
|
|
|
};
|
|
|
|
|
2024-04-13 06:27:37 +00:00
|
|
|
void mCircleBufferInit(struct mCircleBuffer* buffer, unsigned capacity);
|
|
|
|
void mCircleBufferDeinit(struct mCircleBuffer* buffer);
|
|
|
|
size_t mCircleBufferSize(const struct mCircleBuffer* buffer);
|
|
|
|
size_t mCircleBufferCapacity(const struct mCircleBuffer* buffer);
|
|
|
|
void mCircleBufferClear(struct mCircleBuffer* buffer);
|
|
|
|
int mCircleBufferWrite8(struct mCircleBuffer* buffer, int8_t value);
|
|
|
|
int mCircleBufferWrite16(struct mCircleBuffer* buffer, int16_t value);
|
|
|
|
int mCircleBufferWrite32(struct mCircleBuffer* buffer, int32_t value);
|
|
|
|
size_t mCircleBufferWrite(struct mCircleBuffer* buffer, const void* input, size_t length);
|
|
|
|
size_t mCircleBufferWriteTruncate(struct mCircleBuffer* buffer, const void* input, size_t length);
|
|
|
|
int mCircleBufferRead8(struct mCircleBuffer* buffer, int8_t* value);
|
|
|
|
int mCircleBufferRead16(struct mCircleBuffer* buffer, int16_t* value);
|
|
|
|
int mCircleBufferRead32(struct mCircleBuffer* buffer, int32_t* value);
|
|
|
|
size_t mCircleBufferRead(struct mCircleBuffer* buffer, void* output, size_t length);
|
|
|
|
size_t mCircleBufferDump(const struct mCircleBuffer* buffer, void* output, size_t length, size_t offset);
|
2013-10-02 06:56:10 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_END
|
|
|
|
|
2013-10-02 06:56:10 +00:00
|
|
|
#endif
|