include/mgba-util/circle-buffer.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef CIRCLE_BUFFER_H
7#define CIRCLE_BUFFER_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13struct CircleBuffer {
14 void* data;
15 size_t capacity;
16 size_t size;
17 void* readPtr;
18 void* writePtr;
19};
20
21void CircleBufferInit(struct CircleBuffer* buffer, unsigned capacity);
22void CircleBufferDeinit(struct CircleBuffer* buffer);
23size_t CircleBufferSize(const struct CircleBuffer* buffer);
24size_t CircleBufferCapacity(const struct CircleBuffer* buffer);
25void CircleBufferClear(struct CircleBuffer* buffer);
26int CircleBufferWrite8(struct CircleBuffer* buffer, int8_t value);
27int CircleBufferWrite16(struct CircleBuffer* buffer, int16_t value);
28int CircleBufferWrite32(struct CircleBuffer* buffer, int32_t value);
29size_t CircleBufferWrite(struct CircleBuffer* buffer, const void* input, size_t length);
30int CircleBufferRead8(struct CircleBuffer* buffer, int8_t* value);
31int CircleBufferRead16(struct CircleBuffer* buffer, int16_t* value);
32int CircleBufferRead32(struct CircleBuffer* buffer, int32_t* value);
33size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length);
34size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length);
35
36CXX_GUARD_END
37
38#endif