roo_e/roo_e/roo_e.h

124 lines
3 KiB
C

/*
* Roo/E, the Kangaroo Punch Portable GUI Toolkit
* Copyright (C) 2026 Scott Duensing
*
* http://kangaroopunch.com
*
*
* This file is part of Roo/E.
*
* Roo/E is free software: you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Roo/E 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 Affero General Public License
* along with Roo/E. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ROO_E_H
#define ROO_E_H
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <dlfcn.h>
#include <dirent.h>
#include <math.h>
#include <ctype.h>
#include "pthread.h"
#include "stbds.h"
#include "util.h"
#include "stddclmr.h"
// This is weird being here, but we have to expose a lot of it via DXE_EXPORT.
#ifdef __DJGPP__
#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#include <bios.h>
#include <conio.h>
#include <sys/farptr.h>
#include <sys/nearptr.h>
#endif
#ifdef MEMWATCH
#include "memwatch/memwatch.h"
#endif
#define ROO_CONSTRUCTOR void __attribute__((constructor))
#define ROO_DESTRUCTOR void __attribute__((destructor))
// Allocation helpers. ***TODO*** Check for failure.
#define NEW(t,v) (v)=(t*)malloc(sizeof(t))
#define DEL(v) {if(v) {free(v); v=NULL;}}
// Some helper defines.
#define DIVISIBLE_BY_EIGHT(x) ((((x) >> 3) << 3) == (x))
#define HIGH_BYTE(b) ((uint8_t)(((b) & 0xFF00) >> 8))
#define LOW_BYTE(b) ((uint8_t)((b) & 0x00FF))
// Return codes.
#define SUCCESS 0
#define FAIL 1
#ifndef va_copy
#if defined(__GNUC__) || defined(__clang__)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#else
#define va_copy(dest, src) (dest = src)
#endif
#endif
typedef struct RooNamedPointerS {
char *name;
void *pointer;
} RooNamedPointerT;
typedef struct RooAppThreadS {
pthread_t thread;
volatile bool running;
int argc;
char **argv;
int result;
RooNamedPointerT *namedPointer;
} RooAppThreadT;
typedef enum {
ROO_STOP_EXITING = 0, // App quit
ROO_STOP_SHUTDOWN, // Roo/E shutdown
ROO_STOP_COUNT
} RooStopReasonT;
typedef enum {
ROO_ABORT_NONE = 0, // Don't abort stopping the app
ROO_ABORT_CANCEL, // Try to keep the app alive
ROO_ABORT_COUNT
} RooAbortReasonT;
void logClose(void);
uint8_t logOpen(char *filename, uint8_t append);
void logOpenByHandle(FILE *handle);
void logWrite(char *format, ...);
void logWriteToFileOnly(char *format, ...);
RooAppThreadT *rooStartApp(const char *appName, int argc, char *argv[]);
RooAbortReasonT rooStopApp(RooAppThreadT **threadPointer, RooStopReasonT reason);
#endif // ROO_E_H