From 0d9978228b9226d16ba8272a03dd7e6c9ad83b3d Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 16 Dec 2024 14:52:54 +1300 Subject: Implement a toggleable keyboard on the lower screen --- arm9/source/types/circbuf.c | 20 ++++++++++++++++++++ arm9/source/types/circbuf.h | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 arm9/source/types/circbuf.c create mode 100644 arm9/source/types/circbuf.h (limited to 'arm9/source/types') diff --git a/arm9/source/types/circbuf.c b/arm9/source/types/circbuf.c new file mode 100644 index 0000000..532a5a0 --- /dev/null +++ b/arm9/source/types/circbuf.c @@ -0,0 +1,20 @@ +#include "circbuf.h" + +u8 cb_read_byte(CircBuf *buf) { + if (buf->front != buf->back) { + return buf->mem[buf->front++]; + } else { + return 0; + } +} + +void cb_write_byte(CircBuf *buf, u8 byte) { + if (((buf->back+1)&0xff) != buf->front) { + buf->mem[buf->back++] = byte; + } +} + +void cb_clear(CircBuf *buf) { + buf->front = 0; + buf->back = 0; +} diff --git a/arm9/source/types/circbuf.h b/arm9/source/types/circbuf.h new file mode 100644 index 0000000..305f8bf --- /dev/null +++ b/arm9/source/types/circbuf.h @@ -0,0 +1,16 @@ +#include + +#ifndef CIRCBUF_H_ + #define CIRCBUF_H_ + + typedef struct { + u8 mem[256]; + u8 front; // start of buffer, read from here until back + u8 back; // end of buffer, write past here until front + } CircBuf; + + u8 cb_read_byte(CircBuf *buf); + void cb_write_byte(CircBuf *buf, u8 byte); + void cb_clear(CircBuf *buf); + +#endif -- cgit v1.2.3-70-g09d2