FreeRTOS Emulator with SDL2 Based Graphics and Input Library
1.0
A POSIX wrapper to run FreeRTOS on an x86 machine with some basic input and output libraries aimed at making teaching FreeRTOS simpler.
|
Utilities required by other gfx_XXX files. More...
#include <assert.h>
#include <dirent.h>
#include <libgen.h>
#include <pthread.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include "gfx_print.h"
#include "gfx_utils.h"
#include "EmulatorConfig.h"
#include <stdatomic.h>
Classes | |
struct | ring_buf |
Macros | |
#define | _GNU_SOURCE |
#define | CAST_RBUF(rbuf) ((struct ring_buf*)rbuf) |
#define | INCLUDE_DIR_NAMES 0b1 |
Functions | |
int | gfxUtilIsCurGLThread (void) |
Checks if the calling thread is the thread that currently holds the GL context. More... | |
void | gfxUtilSetGLThread (void) |
The calling thread is registered as holding the current GL context. More... | |
char * | gfxUtilPrependPath (const char *path, char *file) |
Prepends a path string to a filename. More... | |
char * | gfxUtilGetBinFolderPath (char *bin_path) |
Gets the execution folder of the current program, assumes that program is executing from a folder "bin". More... | |
const char * | gfxUtilFindResourceDirectory (void) |
Returns the lopcation of the resource directory. More... | |
FILE * | gfxUtilFindResource (char *resource_name, const char *mode) |
Searches for a file in the RESOURCES_DIRECTORY and returns a FILE * if found. More... | |
char * | gfxUtilFindResourcePath (char *resource_name) |
Similar to gfxUtilFindResource() only returning the file's path instead of the opened FILE's reference. More... | |
rbuf_handle_t | gfxRbufInit (size_t item_size, size_t item_count) |
Initialized a ring buffer object with a certain number of objects of a given size. More... | |
rbuf_handle_t | gfxRbufInitStatic (size_t item_size, size_t item_count, void *buffer) |
Initialized a ring buffer object with a certain number of objects of a given size into a statically allocated buffer. More... | |
void | gfxRbufFree (rbuf_handle_t rbuf) |
Frees a ring buffer. More... | |
void | gfxRbufReset (rbuf_handle_t rbuf) |
Resets the ring buffer to it's initial state. More... | |
int | gfxRbufPutBuffer (rbuf_handle_t rbuf) |
Used when a reference to the next buffer item is already filled, incrementing the next buffer item should an item need to be retrieved. More... | |
int | gfxRbufPut (rbuf_handle_t rbuf, void *data) |
Fills the next available buffer slot, if a slot is free. More... | |
int | gfxRbufFPut (rbuf_handle_t rbuf, void *data) |
Fills the next available buffer, overwriting data if the ring buffer is full. More... | |
void * | gfxRbufGetBuffer (rbuf_handle_t rbuf) |
Returns a reference to the data of the next ring buffer entry. More... | |
int | gfxRbufGet (rbuf_handle_t rbuf, void *data) |
Returns a copy of the next buffer item's data. More... | |
unsigned char | gfxRbufEmpty (rbuf_handle_t rbuf) |
Checks if the buffer is empty or not. More... | |
unsigned char | gfxRbufFull (rbuf_handle_t rbuf) |
Checks if the buffer is full. More... | |
size_t | gfxRbufSize (rbuf_handle_t rbuf) |
Returns the number of elements currently stored in the ring buffer. More... | |
size_t | gfxRbufCapacity (rbuf_handle_t rbuf) |
Returns the maximum number of elements that the ring buffer can store. More... | |
Utilities required by other gfx_XXX files.
---------------------------------------------------------------------- Copyright (C) Alexander Hoffman, 2019 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. ----------------------------------------------------------------------
#define _GNU_SOURCE |
#define CAST_RBUF | ( | rbuf | ) | ((struct ring_buf*)rbuf) |
#define INCLUDE_DIR_NAMES 0b1 |
size_t gfxRbufCapacity | ( | rbuf_handle_t | rbuf | ) |
Returns the maximum number of elements that the ring buffer can store.
rbuf | Handle to the ring buffer |
unsigned char gfxRbufEmpty | ( | rbuf_handle_t | rbuf | ) |
Checks if the buffer is empty or not.
rbuf | Handle to the ring buffer |
int gfxRbufFPut | ( | rbuf_handle_t | rbuf, |
void * | data | ||
) |
Fills the next available buffer, overwriting data if the ring buffer is full.
rbuf | Handle to the ring buffer |
data | Reference to the data to be copied into the buffer |
void gfxRbufFree | ( | rbuf_handle_t | rbuf | ) |
Frees a ring buffer.
rbuf | Handle to the ring buffer |
unsigned char gfxRbufFull | ( | rbuf_handle_t | rbuf | ) |
Checks if the buffer is full.
rbuf | Handle to the ring buffer |
int gfxRbufGet | ( | rbuf_handle_t | rbuf, |
void * | data | ||
) |
Returns a copy of the next buffer item's data.
rbuf | Handle to the ring buffer |
data | A reference to the allocated memory region into which the data should be copied |
void* gfxRbufGetBuffer | ( | rbuf_handle_t | rbuf | ) |
Returns a reference to the data of the next ring buffer entry.
Because only a reference is returned the contents of the buffer entry cannot be guarenteed
rbuf | Handle to the ring buffer |
rbuf_handle_t gfxRbufInit | ( | size_t | item_size, |
size_t | item_count | ||
) |
Initialized a ring buffer object with a certain number of objects of a given size.
item_size | The size, in bytes, of each ring buffer item |
item_count | The maximum number of items to be stored in the ring buffer |
rbuf_handle_t gfxRbufInitStatic | ( | size_t | item_size, |
size_t | item_count, | ||
void * | buffer | ||
) |
Initialized a ring buffer object with a certain number of objects of a given size into a statically allocated buffer.
item_size | The size, in bytes, of each ring buffer item |
item_count | The maximum number of items to be stored in the ring buffer |
buffer | Reference to the statically allocated memory region that is to be used for storing the ring buffer |
int gfxRbufPut | ( | rbuf_handle_t | rbuf, |
void * | data | ||
) |
Fills the next available buffer slot, if a slot is free.
rbuf | Handle to the ring buffer |
data | Reference to the data to be copied into the buffer |
int gfxRbufPutBuffer | ( | rbuf_handle_t | rbuf | ) |
Used when a reference to the next buffer item is already filled, incrementing the next buffer item should an item need to be retrieved.
rbuf | Handle to the ring buffer |
void gfxRbufReset | ( | rbuf_handle_t | rbuf | ) |
Resets the ring buffer to it's initial state.
rbuf | Handle to the ring buffer |
size_t gfxRbufSize | ( | rbuf_handle_t | rbuf | ) |
Returns the number of elements currently stored in the ring buffer.
rbuf | Handle to the ring buffer |
FILE* gfxUtilFindResource | ( | char * | resource_name, |
const char * | mode | ||
) |
Searches for a file in the RESOURCES_DIRECTORY and returns a FILE * if found.
resource_name | Name of the file to be found |
mode | The reading mode to be used when opening the file, eg. "rw" |
const char* gfxUtilFindResourceDirectory | ( | void | ) |
Returns the lopcation of the resource directory.
char* gfxUtilFindResourcePath | ( | char * | resource_name | ) |
Similar to gfxUtilFindResource() only returning the file's path instead of the opened FILE's reference.
The found filename is stored in a statically allocated buffer and can be overwritten by subsequent calls to the functions
resource_name | Name of the file to be found |
char* gfxUtilGetBinFolderPath | ( | char * | bin_path | ) |
Gets the execution folder of the current program, assumes that program is executing from a folder "bin".
bin_path | The program's binary's location, usually argv[0] |
int gfxUtilIsCurGLThread | ( | void | ) |
Checks if the calling thread is the thread that currently holds the GL context.
char* gfxUtilPrependPath | ( | const char * | path, |
char * | file | ||
) |
Prepends a path string to a filename.
path | Path string to be prepended |
file | Filename to which the path string should be prepended |
void gfxUtilSetGLThread | ( | void | ) |
The calling thread is registered as holding the current GL context.