Update repository for new architecture

This commit is contained in:
Fierelier 2024-06-16 13:56:54 +02:00
parent bd5b613c91
commit e0f7427413
33 changed files with 22 additions and 1182 deletions

View File

@ -1,40 +1,34 @@
# unigi # unigi
unigi (Universal Graphics & Input) is a collection of headers, that implement a cross-platform API for drawing to the screen (framebuffer or window), and taking inputs (keyboard, mouse, joypad). unigi (Universal Graphics & Input) is a collection of headers, that implement a cross-platform API for drawing to the screen (framebuffer or window), and taking inputs (keyboard, mouse, joypad).
This is achieved through platforms (See `src/platform`), which act as the translation layer for different targets. The idea is to minimize the amount of work it takes to port graphical applications. This repository contains documentation, links and example applications.
The pixel format and screen coordinates are standardized, however, the HID inputs are not. It is best to make button layouts for each platform.
<img src="assets/preview.png" title="Preview"> <img src="assets/preview.png" title="Preview">
# Features # Compatibility
* Highly compatible with compilers (C89, simple preprocessors) * Highly compatible with compilers (C89, simple preprocessors)
* No `make` required, entirely configurable from your compiler, or a header file (`src/config/user.h`) * No `make` required, entirely configurable from your compiler, or header files
* Supports wide range of hardware (16-bit+, little/big endian) * Supports wide range of hardware (16-bit+, little/big endian)
* Standardized 16-bit color format (RRRRGGGGBBBBAAAA, effectively 12-bit on most platforms) * Standardized 16-bit color format (AAAARRRRGGGGBBBB, effectively 12-bit on most platforms)
* Implements API for floats, letting you pick between fixed point or actual float numbers * Screen coordinates are standardized
* Decent performance (Though some performance is sacrificed to standardize the interface. On DOS, it targets 30 fps on i586-class CPUs) * Decent performance (Though some performance is sacrificed for standardization)
# How to build # Layers
## Preparation A unigi app is built from different layers:
1. `git clone "https://git.lumen.sh/Fierelier/unigi"` * [Headers](https://git.lumen.sh/Fierelier/unigi.headers) - The functions to be implemented by the Platform
2. `git submodule update --init --recursive` (optional, required for fixed point math) * Platform - Implements the functions from Headers to work on a particular system (see below for a list)
* ... - Optionally, more layers
* App - Your code, uses other layers for input/output
## Platform: null # Platforms
This platform has a very simple implementation, that is essentially a no-op for any possible target. It's meant for running a basic test before one makes a proper port. Platforms act as the translation layer for different systems. The idea is to minimize the amount of work it takes to port graphical applications.
1. `cc src/tests/draw.c -Dunigi_flag_platform_null`
## Platform: dos ## Official platforms
This platform implements DOS (MS-DOS, FreeDOS, etc.), Tested with Open Watcom. * [SDL1](https://git.lumen.sh/Fierelier/unigi.platform.sdl1) - The highly compatible SDL 1.2, works on old Linux and Windows 95+
1. `cc src/tests/draw.c -Dunigi_flag_platform_dos` * SDL2 (soon) - SDL 2.x, works on somewhat recent Linux and Windows XP+
* DOS (soon) - DOS (Disk Operating System), compatible with FreeDOS and MS-DOS
* PSP (soon) - PlayStation Portable gaming console
* Null (soon) - A placeholder that does "nothing", good if you want to test basic compilation for an unsupported platform
## Platform: sdl1 ## Third party platforms
This platform implements the highly compatible SDL 1.2, which runs on all sorts of versions of Linux and Windows, as well as big endian CPUs. ...
1. `cc src/tests/draw.c -Dunigi_flag_platform_sdl1 -lSDL`
## Advanced configuration
### No stdint.h
If no stdint.h is available, one must define `unigi_flag_nostdint` and also one of `unigi_flag_alu_*bit` (`*` = 8, 16, 32, 64), depending on how wide the ALU of the target CPU is.
### Fixed point numbers
If fixed point is wished instead of float, one can define `unigi_flag_fixedpoint`. This uses the external fptc-lib headers.

View File

@ -1 +0,0 @@
This holds generic implementations for certain things, likely to be the same across platforms. The files found here should only be used if you're developing a platform implementation.

View File

@ -1,40 +0,0 @@
unigi_type_event * unigi_api_event_buffer;
void * unigi_api_event_data_buffer;
unigi_type_error unigi_api_event_init() {
size_t event_biggest = 0;
size_t size;
// Misc
size = sizeof(unigi_type_event_data_none);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_unknown);
if (size > event_biggest) { event_biggest = size; }
// Window
size = sizeof(unigi_type_event_data_window_exit);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_window_focus);
if (size > event_biggest) { event_biggest = size; }
// Input
size = sizeof(unigi_type_event_data_input_keyboard_button);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_input_mouse_button);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_input_mouse_wheel);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_input_mouse_move);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_input_joypad_button);
if (size > event_biggest) { event_biggest = size; }
size = sizeof(unigi_type_event_data_input_joypad_analog);
if (size > event_biggest) { event_biggest = size; }
unigi_api_event_buffer = malloc(sizeof(unigi_type_event));
if (unigi_api_event_buffer == NULL) { return 1; }
unigi_api_event_data_buffer = malloc(event_biggest);
if (unigi_api_event_data_buffer == NULL) { return 1; }
unigi_api_event_buffer->id = unigi_enum_event_none;
unigi_api_event_buffer->data = unigi_api_event_data_buffer;
return 0;
}

View File

@ -1,22 +0,0 @@
#ifdef unigi_flag_api_graphics_draw_row
static inline void unigi_graphics_draw_row(unigi_type_resolution_pixel_index pixelFrom, unigi_type_resolution_pixel_index pixelTo, unigi_type_color color) {
pixelTo++;
while (pixelFrom < pixelTo) {
unigi_graphics_draw_pixel(pixelFrom,color);
pixelFrom++;
}
}
#endif
#ifdef unigi_flag_api_graphics_draw_square
static inline void unigi_graphics_draw_square(unigi_type_resolution_pixel_index pixelFrom, unigi_type_resolution_pixel_index pixelTo, unigi_type_resolution_pixel_axis height, unigi_type_color color) {
unigi_type_resolution_pixel_index row = 0;
height++;
while (row < height) {
unigi_graphics_draw_row(pixelFrom,pixelTo,color);
pixelFrom += unigi_status_resolution.width;
pixelTo += unigi_status_resolution.width;
row++;
}
}
#endif

View File

@ -1,55 +0,0 @@
#ifndef unigi_flag_platform
#define unigi_flag_exception
#error "Please define a valid platform:"
#error "* unigi_flag_platform_null"
#error "* unigi_flag_platform_dos"
#error "* unigi_flag_platform_sdl1"
//#error "* unigi_flag_platform_sdl2"
#error ""
#endif
#ifdef unigi_flag_nostdint
#ifdef unigi_flag_alu_8bit
#ifdef unigi_flag_alu_defined
#define unigi_flag_alu_errored
#endif
#define unigi_flag_alu_defined
#endif
#ifdef unigi_flag_alu_16bit
#ifdef unigi_flag_alu_defined
#define unigi_flag_alu_errored
#endif
#define unigi_flag_alu_defined
#endif
#ifdef unigi_flag_alu_32bit
#ifdef unigi_flag_alu_defined
#define unigi_flag_alu_errored
#endif
#define unigi_flag_alu_defined
#endif
#ifdef unigi_flag_alu_64bit
#ifdef unigi_flag_alu_defined
#define unigi_flag_alu_errored
#endif
#define unigi_flag_alu_defined
#endif
#ifdef unigi_flag_alu_errored
#define unigi_flag_exception
#error "You may only define one of unigi_flag_alu_*!"
#error ""
#endif
#ifndef unigi_flag_alu_defined
#define unigi_flag_exception
#error "If unigi_flag_nostdint is defined, either of these needs to be defined as well:"
#error "* unigi_flag_alu_8bit"
#error "* unigi_flag_alu_16bit"
#error "* unigi_flag_alu_32bit"
#error "* unigi_flag_alu_64bit"
#error ""
#endif
#endif

View File

@ -1,4 +0,0 @@
//#define unigi_flag_platform_null
//#define unigi_flag_nostdint
//#define unigi_flag_alu_16bit
//#define unigi_flag_fixedpoint

@ -1 +0,0 @@
Subproject commit 2e0f95d06f586fa21e79916c4018fcab4cbd002d

View File

@ -1,116 +0,0 @@
#ifndef unigi_flag_h
#define unigi_flag_h
#include "config/user.h"
#include "platform/defs.h"
#include "config/checks.h"
#ifdef unigi_flag_exception
#error "The configuration is invalid! Compilation cannot continue, fix the errors above."
#else
#include "type/int.h"
#ifndef unigi_flag_fixedpoint
#include "type/float.h"
#else
#include <sys/types.h>
#include <stdio.h>
#include "type/float_fp.h"
#endif
// Misc
typedef unigi_type_uint16 unigi_type_color;
typedef unigi_type_uint8 unigi_type_color_depth;
typedef unigi_type_uint8 unigi_type_event_enum;
typedef unigi_type_int16 unigi_type_input_joypad_analog;
// Event
struct unigi_type_event {
unigi_type_event_enum id;
void * data;
};
typedef struct unigi_type_event unigi_type_event;
#define unigi_enum_event_unknown 0
#define unigi_enum_event_none 1
#define unigi_enum_event_window_exit 2
#define unigi_enum_event_window_focus 3
#define unigi_enum_event_input_keyboard_button 4
#define unigi_enum_event_input_mouse_button 5
#define unigi_enum_event_input_mouse_wheel 6
#define unigi_enum_event_input_mouse_move 7
#define unigi_enum_event_input_joypad_button 8
#define unigi_enum_event_input_joypad_analog 9
// Platform
#include "platform/main.h"
// Misc
struct unigi_type_event_data_unknown {
unigi_type_bool none;
};
typedef struct unigi_type_event_data_unknown unigi_type_event_data_unknown;
typedef unigi_type_event_data_unknown unigi_type_event_data_none;
// Window
typedef unigi_type_event_data_none unigi_type_event_data_window_exit;
struct unigi_type_event_data_window_focus {
unigi_type_bool focused;
};
typedef struct unigi_type_event_data_window_focus unigi_type_event_data_window_focus;
// Input
struct unigi_type_event_data_input_keyboard_button {
unigi_type_input_keyboard_button button;
unigi_type_bool pressed;
};
typedef struct unigi_type_event_data_input_keyboard_button unigi_type_event_data_input_keyboard_button;
struct unigi_type_event_data_input_mouse_button {
unigi_type_input_mouse_button button;
unigi_type_bool pressed;
};
typedef struct unigi_type_event_data_input_mouse_button unigi_type_event_data_input_mouse_button;
struct unigi_type_event_data_input_mouse_wheel {
unigi_type_int8 scroll;
};
typedef struct unigi_type_event_data_input_mouse_wheel unigi_type_event_data_input_mouse_wheel;
struct unigi_type_event_data_input_mouse_move {
unigi_type_resolution_pixel_axis x;
unigi_type_resolution_pixel_axis y;
};
typedef struct unigi_type_event_data_input_mouse_move unigi_type_event_data_input_mouse_move;
struct unigi_type_event_data_input_joypad_button {
unigi_type_input_mouse_button button;
unigi_type_bool pressed;
};
typedef struct unigi_type_event_data_input_joypad_button unigi_type_event_data_input_joypad_button;
struct unigi_type_event_data_input_joypad_analog {
unigi_type_input_joypad_button axis;
unigi_type_input_joypad_analog analog;
};
typedef struct unigi_type_event_data_input_joypad_analog unigi_type_event_data_input_joypad_analog;
// Resolution
struct unigi_type_resolution {
unigi_type_resolution_pixel_axis width;
unigi_type_resolution_pixel_axis height;
unigi_type_color_depth depth;
unigi_type_bool fullscreen;
};
typedef struct unigi_type_resolution unigi_type_resolution;
struct unigi_type_resolution_range {
unigi_type_resolution * min;
unigi_type_resolution * max;
};
typedef struct unigi_type_resolution_range unigi_type_resolution_range;
unigi_type_resolution_range * unigi_status_resolutions;
unigi_type_resolution unigi_status_resolution;
// Platform main
#include "platform/main.c"
#endif
#endif

View File

@ -1,11 +0,0 @@
#ifdef unigi_flag_platform_null
#define unigi_flag_platform "null"
#endif
#ifdef unigi_flag_platform_sdl1
#define unigi_flag_platform "sdl1"
#endif
#ifdef unigi_flag_platform_dos
#define unigi_flag_platform "dos"
#endif

View File

@ -1,5 +0,0 @@
#define unigi_event_init unigi_api_event_init
#include "../../api/event.c"
unigi_type_event * unigi_event_get() {
return unigi_api_event_buffer;
}

View File

@ -1,342 +0,0 @@
#include <dos.h>
#define unigi_platform_palette_dos_colors 216
unigi_type_uint8 unigi_platform_palette_dos[unigi_platform_palette_dos_colors * 3] = {
00, 00, 00,
00, 00, 12,
00, 00, 25,
00, 00, 38,
00, 00, 51,
00, 00, 63,
00, 12, 00,
00, 12, 12,
00, 12, 25,
00, 12, 38,
00, 12, 51,
00, 12, 63,
00, 25, 00,
00, 25, 12,
00, 25, 25,
00, 25, 38,
00, 25, 51,
00, 25, 63,
00, 38, 00,
00, 38, 12,
00, 38, 25,
00, 38, 38,
00, 38, 51,
00, 38, 63,
00, 51, 00,
00, 51, 12,
00, 51, 25,
00, 51, 38,
00, 51, 51,
00, 51, 63,
00, 63, 00,
00, 63, 12,
00, 63, 25,
00, 63, 38,
00, 63, 51,
00, 63, 63,
12, 00, 00,
12, 00, 12,
12, 00, 25,
12, 00, 38,
12, 00, 51,
12, 00, 63,
12, 12, 00,
12, 12, 12,
12, 12, 25,
12, 12, 38,
12, 12, 51,
12, 12, 63,
12, 25, 00,
12, 25, 12,
12, 25, 25,
12, 25, 38,
12, 25, 51,
12, 25, 63,
12, 38, 00,
12, 38, 12,
12, 38, 25,
12, 38, 38,
12, 38, 51,
12, 38, 63,
12, 51, 00,
12, 51, 12,
12, 51, 25,
12, 51, 38,
12, 51, 51,
12, 51, 63,
12, 63, 00,
12, 63, 12,
12, 63, 25,
12, 63, 38,
12, 63, 51,
12, 63, 63,
25, 00, 00,
25, 00, 12,
25, 00, 25,
25, 00, 38,
25, 00, 51,
25, 00, 63,
25, 12, 00,
25, 12, 12,
25, 12, 25,
25, 12, 38,
25, 12, 51,
25, 12, 63,
25, 25, 00,
25, 25, 12,
25, 25, 25,
25, 25, 38,
25, 25, 51,
25, 25, 63,
25, 38, 00,
25, 38, 12,
25, 38, 25,
25, 38, 38,
25, 38, 51,
25, 38, 63,
25, 51, 00,
25, 51, 12,
25, 51, 25,
25, 51, 38,
25, 51, 51,
25, 51, 63,
25, 63, 00,
25, 63, 12,
25, 63, 25,
25, 63, 38,
25, 63, 51,
25, 63, 63,
38, 00, 00,
38, 00, 12,
38, 00, 25,
38, 00, 38,
38, 00, 51,
38, 00, 63,
38, 12, 00,
38, 12, 12,
38, 12, 25,
38, 12, 38,
38, 12, 51,
38, 12, 63,
38, 25, 00,
38, 25, 12,
38, 25, 25,
38, 25, 38,
38, 25, 51,
38, 25, 63,
38, 38, 00,
38, 38, 12,
38, 38, 25,
38, 38, 38,
38, 38, 51,
38, 38, 63,
38, 51, 00,
38, 51, 12,
38, 51, 25,
38, 51, 38,
38, 51, 51,
38, 51, 63,
38, 63, 00,
38, 63, 12,
38, 63, 25,
38, 63, 38,
38, 63, 51,
38, 63, 63,
51, 00, 00,
51, 00, 12,
51, 00, 25,
51, 00, 38,
51, 00, 51,
51, 00, 63,
51, 12, 00,
51, 12, 12,
51, 12, 25,
51, 12, 38,
51, 12, 51,
51, 12, 63,
51, 25, 00,
51, 25, 12,
51, 25, 25,
51, 25, 38,
51, 25, 51,
51, 25, 63,
51, 38, 00,
51, 38, 12,
51, 38, 25,
51, 38, 38,
51, 38, 51,
51, 38, 63,
51, 51, 00,
51, 51, 12,
51, 51, 25,
51, 51, 38,
51, 51, 51,
51, 51, 63,
51, 63, 00,
51, 63, 12,
51, 63, 25,
51, 63, 38,
51, 63, 51,
51, 63, 63,
63, 00, 00,
63, 00, 12,
63, 00, 25,
63, 00, 38,
63, 00, 51,
63, 00, 63,
63, 12, 00,
63, 12, 12,
63, 12, 25,
63, 12, 38,
63, 12, 51,
63, 12, 63,
63, 25, 00,
63, 25, 12,
63, 25, 25,
63, 25, 38,
63, 25, 51,
63, 25, 63,
63, 38, 00,
63, 38, 12,
63, 38, 25,
63, 38, 38,
63, 38, 51,
63, 38, 63,
63, 51, 00,
63, 51, 12,
63, 51, 25,
63, 51, 38,
63, 51, 51,
63, 51, 63,
63, 63, 00,
63, 63, 12,
63, 63, 25,
63, 63, 38,
63, 63, 51,
63, 63, 63
};
unigi_type_uint8 unigi_platform_palette[65536];
static inline void unigi_platform_color_16_to_32(unigi_type_uint16 color16,unigi_type_uint8 * r, unigi_type_uint8 * g, unigi_type_uint8 * b, unigi_type_uint8 * a) {
*r = (color16 >> 12) & 0xF;
*g = (color16 >> 8) & 0xF;
*b = (color16 >> 4) & 0xF;
*a = color16 & 0xF;
*r = *r << 4;
*g = *g << 4;
*b = *b << 4;
*a = *a << 4;
}
unigi_type_uint8 unigi_platform_color_find(unigi_type_uint8 r, unigi_type_uint8 g, unigi_type_uint8 b) {
unigi_type_uint8 color = 0;
unigi_type_uint16 index = 0;
unigi_type_uint16 smallestDiff = 32767;
r /= 4; g /= 4; b /= 4;
while (index < unigi_platform_palette_dos_colors * 3) {
unigi_type_uint16 diff = abs(r - unigi_platform_palette_dos[index]) +
abs(g - unigi_platform_palette_dos[index + 1]) +
abs(b - unigi_platform_palette_dos[index + 2]);
if (diff < smallestDiff) {
smallestDiff = diff;
color = index / 3;
}
index += 3;
}
return color;
}
#include <stdio.h>
unigi_type_error unigi_graphics_init() {
// Create palette
unigi_type_uint32 index = 0;
while (index < 65536) {
unigi_type_uint8 r,g,b,a;
unigi_platform_color_16_to_32(index,&r,&g,&b,&a);
if (index % 500 == 0) {
printf("Generating palette %ld ...\r",index);
fflush(stdout);
}
unigi_platform_palette[index] = unigi_platform_color_find(r,g,b);
index++;
}
// Create a list of compatible resolutions
unigi_status_resolutions = malloc(sizeof(unigi_type_resolution_range) * 2);
if (unigi_status_resolutions == NULL) { return 1; }
unigi_status_resolutions[0].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[0].min == NULL) { return 1; }
unigi_status_resolutions[0].min->width = 320;
unigi_status_resolutions[0].min->height = 200;
unigi_status_resolutions[0].min->depth = 8;
unigi_status_resolutions[0].min->fullscreen = 1;
unigi_status_resolutions[0].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[0].max == NULL) { return 1; }
unigi_status_resolutions[0].max->width = 320;
unigi_status_resolutions[0].max->height = 200;
unigi_status_resolutions[0].max->depth = 8;
unigi_status_resolutions[0].max->fullscreen = 1;
// End the list with a resolution range where all values are set to 0
unigi_status_resolutions[1].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[1].min == NULL) { return 1; }
unigi_status_resolutions[1].min->width = 0;
unigi_status_resolutions[1].min->height = 0;
unigi_status_resolutions[1].min->depth = 0;
unigi_status_resolutions[1].min->fullscreen = 0;
unigi_status_resolutions[1].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[1].max == NULL) { return 1; }
unigi_status_resolutions[1].max->width = 0;
unigi_status_resolutions[1].max->height = 0;
unigi_status_resolutions[1].max->depth = 0;
unigi_status_resolutions[1].max->fullscreen = 0;
return 0;
}
void outportb(unsigned short port, unsigned char value) {
__asm {
mov dx, port
mov al, value
out dx, al
}
}
unigi_type_error unigi_graphics_mode(unigi_type_resolution * resolution, char * title) {
unigi_type_uint16 color;
union REGS inregs, outregs;
unigi_status_resolution.width = 320;
unigi_status_resolution.height = 240;
unigi_status_resolution.depth = 8;
unigi_status_resolution.fullscreen = 1;
inregs.h.ah = 0;
inregs.h.al = 0x13;
int86(0x10,&inregs,&outregs);
outportb(0x03C8, 0);
for (color = 0; color < unigi_platform_palette_dos_colors * 3; color++) {
if (color % 16 == 0) delay(1);
outportb(0x03C9, unigi_platform_palette_dos[color]);
}
return 0;
}
static inline void unigi_graphics_draw_pixel(unigi_type_resolution_pixel_index pixel, unigi_type_color color) { // This is horribly slow, for now
unsigned char far *unigi_platform_vidbuf = (unsigned char far *)0xA0000000L;
unigi_platform_vidbuf[pixel] = unigi_platform_palette[color];
}
static inline void unigi_graphics_flush() {
}
#define unigi_flag_api_graphics_draw_row
#define unigi_flag_api_graphics_draw_square
#include "../../api/graphics.c"

View File

@ -1,3 +0,0 @@
unigi_type_error unigi_input_init() {
return 0;
}

View File

@ -1,17 +0,0 @@
#include <stdlib.h>
#include "input.c"
#include "graphics.c"
#include "event.c"
#include "time.c"
unigi_type_error unigi_init() {
if (unigi_event_init() != 0) { return 1; }
return 0;
}
void unigi_close() {
union REGS inregs, outregs;
inregs.h.ah = 0;
inregs.h.al = 0x03;
int86(0x10,&inregs,&outregs);
}

View File

@ -1,8 +0,0 @@
char unigi_platform[] = "null";
typedef unigi_type_uint8 unigi_type_error;
typedef unigi_type_uint32 unigi_type_time;
typedef unigi_type_uint16 unigi_type_resolution_pixel_axis;
typedef unigi_type_uint32 unigi_type_resolution_pixel_index;
typedef unigi_type_uint8 unigi_type_input_keyboard_button;
typedef unigi_type_uint8 unigi_type_input_mouse_button;
typedef unigi_type_uint8 unigi_type_input_joypad_button;

View File

@ -1,2 +0,0 @@
unigi_type_time unigi_time_clock() { return 0; }
void unigi_time_sleep(unigi_type_time time) { }

View File

@ -1,11 +0,0 @@
#ifdef unigi_flag_platform_null
#include "null/main.c"
#endif
#ifdef unigi_flag_platform_sdl1
#include "sdl1/main.c"
#endif
#ifdef unigi_flag_platform_dos
#include "dos/main.c"
#endif

View File

@ -1,11 +0,0 @@
#ifdef unigi_flag_platform_null
#include "null/main.h"
#endif
#ifdef unigi_flag_platform_sdl1
#include "sdl1/main.h"
#endif
#ifdef unigi_flag_platform_dos
#include "dos/main.h"
#endif

View File

@ -1,5 +0,0 @@
#define unigi_event_init unigi_api_event_init
#include "../../api/event.c"
unigi_type_event * unigi_event_get() {
return unigi_api_event_buffer;
}

View File

@ -1,76 +0,0 @@
unigi_type_error unigi_graphics_init() {
// Create a list of compatible resolutions
unigi_status_resolutions = malloc(sizeof(unigi_type_resolution_range) * 4);
if (unigi_status_resolutions == NULL) { return 1; }
unigi_status_resolutions[0].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[0].min == NULL) { return 1; }
unigi_status_resolutions[0].min->width = 640;
unigi_status_resolutions[0].min->height = 480;
unigi_status_resolutions[0].min->depth = 0; // 0 indicates unknown
unigi_status_resolutions[0].min->fullscreen = 0;
unigi_status_resolutions[0].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[0].max == NULL) { return 1; }
unigi_status_resolutions[0].max->width = 640;
unigi_status_resolutions[0].max->height = 480;
unigi_status_resolutions[0].max->depth = 0;
unigi_status_resolutions[0].max->fullscreen = 0;
unigi_status_resolutions[1].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[1].min == NULL) { return 1; }
unigi_status_resolutions[1].min->width = 800;
unigi_status_resolutions[1].min->height = 600;
unigi_status_resolutions[1].min->depth = 0;
unigi_status_resolutions[1].min->fullscreen = 0;
unigi_status_resolutions[1].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[1].max == NULL) { return 1; }
unigi_status_resolutions[1].max->width = 800;
unigi_status_resolutions[1].max->height = 600;
unigi_status_resolutions[1].max->depth = 0;
unigi_status_resolutions[1].max->fullscreen = 0;
unigi_status_resolutions[2].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[2].min == NULL) { return 1; }
unigi_status_resolutions[2].min->width = 1024;
unigi_status_resolutions[2].min->height = 768;
unigi_status_resolutions[2].min->depth = 0;
unigi_status_resolutions[2].min->fullscreen = 0;
unigi_status_resolutions[2].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[2].max == NULL) { return 1; }
unigi_status_resolutions[2].max->width = 1024;
unigi_status_resolutions[2].max->height = 768;
unigi_status_resolutions[2].max->depth = 0;
unigi_status_resolutions[2].max->fullscreen = 0;
// End the list with a resolution range where all values are set to 0
unigi_status_resolutions[3].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[3].min == NULL) { return 1; }
unigi_status_resolutions[3].min->width = 0;
unigi_status_resolutions[3].min->height = 0;
unigi_status_resolutions[3].min->depth = 0;
unigi_status_resolutions[3].min->fullscreen = 0;
unigi_status_resolutions[3].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[3].max == NULL) { return 1; }
unigi_status_resolutions[3].max->width = 0;
unigi_status_resolutions[3].max->height = 0;
unigi_status_resolutions[3].max->depth = 0;
unigi_status_resolutions[3].max->fullscreen = 0;
return 0;
}
unigi_type_error unigi_graphics_mode(unigi_type_resolution * resolution, char * title) {
unigi_status_resolution.width = resolution -> width;
unigi_status_resolution.height = resolution -> height;
unigi_status_resolution.depth = resolution -> depth;
unigi_status_resolution.fullscreen = resolution -> fullscreen;
return 0;
}
static inline void unigi_graphics_draw_pixel(unigi_type_resolution_pixel_index pixel, unigi_type_color color) {
}
static inline void unigi_graphics_flush() {
}
#define unigi_flag_api_graphics_draw_row
#define unigi_flag_api_graphics_draw_square
#include "../../api/graphics.c"

View File

@ -1,3 +0,0 @@
unigi_type_error unigi_input_init() {
return 0;
}

View File

@ -1,13 +0,0 @@
#include <stdlib.h>
#include "input.c"
#include "graphics.c"
#include "event.c"
#include "time.c"
unigi_type_error unigi_init() {
if (unigi_event_init() != 0) { return 1; }
return 0;
}
void unigi_close() {
}

View File

@ -1,8 +0,0 @@
char unigi_platform[] = "null";
typedef unigi_type_uint8 unigi_type_error;
typedef unigi_type_uint32 unigi_type_time;
typedef unigi_type_uint16 unigi_type_resolution_pixel_axis;
typedef unigi_type_uint32 unigi_type_resolution_pixel_index;
typedef unigi_type_uint8 unigi_type_input_keyboard_button;
typedef unigi_type_uint8 unigi_type_input_mouse_button;
typedef unigi_type_uint8 unigi_type_input_joypad_button;

View File

@ -1,2 +0,0 @@
unigi_type_time unigi_time_clock() { return 0; }
void unigi_time_sleep(unigi_type_time time) { }

View File

@ -1,25 +0,0 @@
#define unigi_event_init unigi_api_event_init
#include "../../api/event.c"
unigi_type_event * unigi_event_get() {
SDL_Event event;
if (SDL_PollEvent(&event) != 1) {
unigi_api_event_buffer->id = unigi_enum_event_none;
goto rtn;
} else if (event.type == SDL_QUIT) {
unigi_api_event_buffer->id = unigi_enum_event_window_exit;
goto rtn;
} else if (
event.type == SDL_KEYDOWN ||
event.type == SDL_KEYUP
) {
unigi_api_event_buffer->id = unigi_enum_event_input_keyboard_button;
unigi_type_event_data_input_keyboard_button * data = (unigi_type_event_data_input_keyboard_button *)unigi_api_event_buffer->data;
data->button = event.key.keysym.sym;
data->pressed = (event.type == SDL_KEYDOWN);
goto rtn;
}
unigi_api_event_buffer->id = unigi_enum_event_unknown;
rtn:;
return unigi_api_event_buffer;
}

View File

@ -1,125 +0,0 @@
SDL_Surface * unigi_platform_surface;
SDL_PixelFormat * unigi_platform_status_format;
unigi_type_uint8 * unigi_platform_palette;
static inline void unigi_platform_color_16_to_32(unigi_type_uint16 color16,unigi_type_uint8 * r, unigi_type_uint8 * g, unigi_type_uint8 * b, unigi_type_uint8 * a) {
*r = (color16 >> 12) & 0xF;
*g = (color16 >> 8) & 0xF;
*b = (color16 >> 4) & 0xF;
*a = color16 & 0xF;
*r = *r << 4;
*g = *g << 4;
*b = *b << 4;
*a = *a << 4;
}
unigi_type_error unigi_graphics_init() {
printf("[PLATFORM:SDL1] Initializing video...\n");
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("[PLATFORM:SDL1] %s\n",SDL_GetError());
return 1;
}
const SDL_VideoInfo * vidInfo = SDL_GetVideoInfo();
if (vidInfo == NULL) { return 1; }
unigi_type_color_depth bpp = vidInfo->vfmt->BitsPerPixel;
unigi_platform_status_format = vidInfo->vfmt;
unigi_platform_palette = malloc((bpp / 8) * 65536);
if (unigi_platform_palette == NULL) { return 1; }
unigi_type_uint8 r,g,b,a;
unigi_type_uint32 sdlcolor;
unigi_type_uint8 * sdlcolor8;
unigi_type_uint32 index;
index = 0;
while (index < 65536) {
unigi_platform_color_16_to_32((unigi_type_uint16)index,&r,&g,&b,&a);
sdlcolor = SDL_MapRGBA(unigi_platform_status_format,r,g,b,a);
sdlcolor8 = (unigi_type_uint8 *)&sdlcolor;
unigi_type_color_depth i;
for(i = 0; i < bpp/8; i++)
{
unigi_platform_palette[(index * (bpp/8)) + i] = sdlcolor8[i];
}
index++;
}
// Create a list of compatible resolutions
unigi_status_resolutions = malloc(sizeof(unigi_type_resolution_range) * 2);
if (unigi_status_resolutions == NULL) { return 1; }
unigi_status_resolutions[0].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[0].min == NULL) { return 1; }
unigi_status_resolutions[0].min->width = 128;
unigi_status_resolutions[0].min->height = 64;
unigi_status_resolutions[0].min->depth = bpp;
unigi_status_resolutions[0].min->fullscreen = 0;
unigi_status_resolutions[0].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[0].max == NULL) { return 1; }
unigi_status_resolutions[0].max->width = 4096;
unigi_status_resolutions[0].max->height = 4096;
unigi_status_resolutions[0].max->depth = bpp;
unigi_status_resolutions[0].max->fullscreen = 0;
// End the list with a resolution range where all values are set to 0
unigi_status_resolutions[1].min = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[1].min == NULL) { return 1; }
unigi_status_resolutions[1].min->width = 0;
unigi_status_resolutions[1].min->height = 0;
unigi_status_resolutions[1].min->depth = 0;
unigi_status_resolutions[1].min->fullscreen = 0;
unigi_status_resolutions[1].max = malloc(sizeof(unigi_type_resolution));
if (unigi_status_resolutions[1].max == NULL) { return 1; }
unigi_status_resolutions[1].max->width = 0;
unigi_status_resolutions[1].max->height = 0;
unigi_status_resolutions[1].max->depth = 0;
unigi_status_resolutions[1].max->fullscreen = 0;
return 0;
}
unigi_type_error unigi_graphics_mode(unigi_type_resolution * resolution, char * title) {
printf("[PLATFORM:SDL1] Setting video mode...\n");
unigi_platform_surface = SDL_SetVideoMode(resolution->width,resolution->height,resolution->depth,SDL_SWSURFACE);
if (unigi_platform_surface == NULL) { return 1; }
SDL_WM_SetCaption(title,NULL);
unigi_status_resolution.width = resolution->width;
unigi_status_resolution.height = resolution->height;
unigi_status_resolution.depth = resolution->depth;
unigi_status_resolution.fullscreen = resolution->fullscreen;
return 0;
}
static inline void unigi_graphics_draw_pixel(unigi_type_resolution_pixel_index pixel, unigi_type_color color) {
unigi_type_uint8 * pixels1 = (unigi_type_uint8 *)(unigi_platform_surface->pixels);
unigi_type_uint8 * palette1 = (unigi_type_uint8 *)unigi_platform_palette;
unigi_type_uint16 * pixels2 = (unigi_type_uint16 *)(unigi_platform_surface->pixels);
unigi_type_uint16 * palette2 = (unigi_type_uint16 *)unigi_platform_palette;
unigi_type_uint32 * pixels4 = (unigi_type_uint32 *)(unigi_platform_surface->pixels);
unigi_type_uint32 * palette4 = (unigi_type_uint32 *)unigi_platform_palette;
if (unigi_status_resolution.depth < 24) {
if (unigi_status_resolution.depth == 8) {
pixels1[pixel] = palette1[color];
} else {
pixels2[pixel] = palette2[color];
}
} else {
if (unigi_status_resolution.depth == 24) {
memcpy(
pixels1 + (pixel * 3),
palette1 + (color * 3),
3
);
} else {
pixels4[pixel] = palette4[color];
}
}
}
static inline void unigi_graphics_flush() {
SDL_Flip(unigi_platform_surface);
}
#define unigi_flag_api_graphics_draw_row
#define unigi_flag_api_graphics_draw_square
#include "../../api/graphics.c"

View File

@ -1,3 +0,0 @@
unigi_type_error unigi_input_init() {
return 0;
}

View File

@ -1,15 +0,0 @@
#include <stdlib.h>
#include <SDL/SDL.h>
#include "input.c"
#include "graphics.c"
#include "event.c"
#include "time.c"
unigi_type_error unigi_init() {
if (unigi_event_init() != 0) { return 1; }
return 0;
}
void unigi_close() {
SDL_Quit();
}

View File

@ -1,8 +0,0 @@
char unigi_platform[] = "sdl1";
typedef unigi_type_uint8 unigi_type_error;
typedef unigi_type_uint32 unigi_type_time;
typedef unigi_type_uint16 unigi_type_resolution_pixel_axis;
typedef unigi_type_uint32 unigi_type_resolution_pixel_index;
typedef unigi_type_uint8 unigi_type_input_keyboard_button;
typedef unigi_type_uint8 unigi_type_input_mouse_button;
typedef unigi_type_uint8 unigi_type_input_joypad_button;

View File

@ -1,4 +0,0 @@
unigi_type_time unigi_time_clock() { return (unigi_type_time)SDL_GetTicks() * 1000; }
void unigi_time_sleep(unigi_type_time microseconds) {
SDL_Delay(microseconds/1000);
}

View File

@ -1,155 +0,0 @@
#include "../main.h"
#ifndef unigi_flag_exception
#include <stdio.h>
#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef max
#define max(x, y) ((x) > (y) ? (x) : (y))
#endif
unigi_type_uint32 seed = 1337;
unigi_type_uint32 example_random() {
seed = (seed * 1103515245 + 12345) & 0x7FFFFFFF;
return seed;
}
int main_shelled() {
size_t resolution_index = 0;
unigi_type_resolution_pixel_index smallestValidSize = 0 - 1;
unigi_type_resolution smallestValidRes;
smallestValidRes.width = 0;
if (unigi_init() > 0) { return 1; }
if (unigi_graphics_init() > 0) { return 1; }
while (1) {
unigi_type_resolution_range * range = &unigi_status_resolutions[resolution_index];
if (
range->min->width == 0 &&
range->min->height == 0 &&
range->min->depth == 0 &&
range->min->fullscreen == 0 &&
range->max->width == 0 &&
range->max->height == 0 &&
range->max->depth == 0 &&
range->max->fullscreen == 0
) {
break;
}
// Get smallest resolution between 320x200 and 800x600
if (
range->max->width >= 320 &&
range->max->height >= 200 &&
range->min->width <= 800 &&
range->min->height <= 600
) {
unigi_type_resolution_pixel_index size;
unigi_type_resolution_pixel_axis smallestWidth = min(
max(range->min->width,320),
min(range->max->width,800)
);
unigi_type_resolution_pixel_axis smallestHeight = min(
max(range->min->height,200),
min(range->max->height,600)
);
printf("Found valid resolution: %ix%ix%i\n",smallestWidth,smallestHeight,range->min->depth);
size = (unigi_type_resolution_pixel_index)smallestWidth * smallestHeight;
if (size < smallestValidSize) {
smallestValidRes.width = smallestWidth;
smallestValidRes.height = smallestHeight;
smallestValidRes.depth = range->min->depth;
smallestValidRes.fullscreen = range->min->fullscreen;
smallestValidSize = size;
}
}
++resolution_index;
}
if (smallestValidRes.width == 0) {
printf("No valid resolutions found.\n");
return 1;
}
printf("* Using smallest resolution: %ix%ix%i\n",
smallestValidRes.width,
smallestValidRes.height,
smallestValidRes.depth
);
unigi_graphics_mode(&smallestValidRes,"unigi test");
unigi_input_init();
while (1) {
unigi_type_resolution_pixel_axis startX;
unigi_type_resolution_pixel_axis startY;
unigi_type_resolution_pixel_axis width;
unigi_type_resolution_pixel_axis height;
unigi_type_resolution_pixel_index startIndex;
unigi_type_resolution_pixel_index stopIndex;
unigi_type_resolution_pixel_index prog;
unigi_type_resolution_pixel_axis ind;
while (1) {
unigi_type_event * event = unigi_event_get();
if (event->id == unigi_enum_event_none) { break; }
if (event->id == unigi_enum_event_window_exit) {
unigi_close();
return 0;
}
if (event->id == unigi_enum_event_input_keyboard_button) {
unigi_close();
return 0;
}
}
// Draw some random squares on the screen
startX = example_random() % (unigi_status_resolution.width);
startY = example_random() % (unigi_status_resolution.height);
width = example_random() % (unigi_status_resolution.width - startX);
height = example_random() % (unigi_status_resolution.height - startY);
startIndex = startX + (unigi_status_resolution.width * startY);
stopIndex = startIndex + width;
unigi_graphics_draw_square(startIndex,stopIndex,height,example_random() % 65535);
// Draw a simple test pattern, and demonstrate how to use floats
prog = unigi_float_2int(unigi_float_mul(
unigi_float_make(unigi_status_resolution.width),
unigi_float_div(unigi_float_make(1),unigi_float_make(40))
));
ind = 0;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xF00F);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xFF0F);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0x0F0F);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0x0FFF);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0x00FF);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xF0FF);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0x0000);
ind++;
unigi_graphics_draw_square(prog * ind,prog * (ind + 1),unigi_status_resolution.height,0xFFFF);
ind++;
unigi_graphics_flush();
unigi_time_sleep(33000); // Wait 33ms
}
return 0;
}
int main() {
int rtn = main_shelled();
unigi_close();
return rtn;
}
#endif

View File

@ -1,16 +0,0 @@
typedef float unigi_type_float;
#define unigi_float_make(A) ((unigi_type_float)A)
#define unigi_float_2int(A) ((unigi_type_int32)A)
#define unigi_float_add(A,B) (A + B)
#define unigi_float_sub(A,B) (A - B)
#define unigi_float_mul(A,B) (A * B)
#define unigi_float_div(A,B) (A / B)
//#define unigi_float_scan fpt_scan
//#define unigi_float_str fpt_str
#define unigi_float_sqrt sqrtf
#define unigi_float_sin sin
#define unigi_float_cos cosf
#define unigi_float_tan tanf
#define unigi_float_exp exp
#define unigi_float_log log
#define unigi_float_pow(A,B) (A ^ B)

View File

@ -1,17 +0,0 @@
#include "../fptc-lib/src/fptc.h"
typedef fpt unigi_type_float;
#define unigi_float_make fl2fpt
#define unigi_float_2int fpt2i
#define unigi_float_add fpt_add
#define unigi_float_sub fpt_sub
#define unigi_float_mul fpt_mul
#define unigi_float_div fpt_div
#define unigi_float_scan fpt_scan
#define unigi_float_str fpt_str
#define unigi_float_sqrt fpt_sqrt
#define unigi_float_sin fpt_sin
#define unigi_float_cos fpt_cos
#define unigi_float_tan fpt_tan
#define unigi_float_exp fpt_exp
#define unigi_float_log fpt_ln
#define unigi_float_pow fpt_pow

View File

@ -1,30 +0,0 @@
#ifndef unigi_flag_nostdint
#include <stdint.h>
typedef int8_t unigi_type_int8;
typedef uint8_t unigi_type_uint8;
typedef int16_t unigi_type_int16;
typedef uint16_t unigi_type_uint16;
typedef int32_t unigi_type_int32;
typedef uint32_t unigi_type_uint32;
#else
typedef signed char unigi_type_int8;
typedef unsigned char unigi_type_uint8;
typedef signed short unigi_type_int16;
typedef unsigned short unigi_type_uint16;
#ifndef unigi_flag_alu_64bit // On 8-bit, 16-bit and 32-bit C compilers, long is usually 32 bits.
typedef signed long unigi_type_int32;
typedef unsigned long unigi_type_uint32;
#else
typedef signed int unigi_type_int32;
typedef unsigned int unigi_type_uint32;
#endif
// Define *int*_t for fptc-lib
typedef unigi_type_int8 int8_t;
typedef unigi_type_uint8 uint8_t;
typedef unigi_type_int16 int16_t;
typedef unigi_type_uint16 uint16_t;
typedef unigi_type_int32 int32_t;
typedef unigi_type_uint32 uint32_t;
#endif
typedef unigi_type_uint8 unigi_type_bool;