aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/types/circbuf.c
blob: 03982547b2db4be951ee22f6ff15de59a4b78314 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "circbuf.h"


// Read a byte from a circular buffer, or zero if the buffer is empty.
u8 circbuf_read(CircBuf *buf) {
    if (buf->front != buf->back) {
        return buf->mem[buf->front++];
    } else {
        return 0;
    }
}

// Write a byte to a circular buffer if the buffer is not full.
void circbuf_write(CircBuf *buf, u8 byte) {
    if (((buf->back+1)&0xff) != buf->front) {
        buf->mem[buf->back++] = byte;
    }
}

// Clear a circular buffer.
void circbuf_clear(CircBuf *buf) {
    buf->front = 0;
    buf->back = 0;
}