Compare commits

..

No commits in common. "master" and "old" have entirely different histories.
master ... old

42 changed files with 1188 additions and 374 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/fptc-lib"]
path = src/fptc-lib
url = https://github.com/mgetka/fptc-lib

View File

@ -1,31 +1,40 @@
# 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). This approach should work well for general computers, like PCs and many 6th generation consoles.
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 repository contains documentation, links and example applications.
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.
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">
# Compatibility
* GNU C99 compatible
* No `make` required, entirely configurable from your compiler, or header files
# Features
* Highly compatible with compilers (C89, simple preprocessors)
* No `make` required, entirely configurable from your compiler, or a header file (`src/config/user.h`)
* Supports wide range of hardware (16-bit+, little/big endian)
* Standardized 16-bit color format (AAAARRRRGGGGBBBB, effectively 12-bit on most platforms)
* Screen coordinates are standardized
* Decent performance (Though some performance is sacrificed for standardization)
* Standardized 16-bit color format (RRRRGGGGBBBBAAAA, effectively 12-bit on most platforms)
* Implements API for floats, letting you pick between fixed point or actual float numbers
* Decent performance (Though some performance is sacrificed to standardize the interface. On DOS, it targets 30 fps on i586-class CPUs)
# Layers
A unigi app is built from different layers:
* **Headers (this repository)** - The functions to be implemented by the Platform
* **[Platform](#official-platforms)** - Implements the functions from Headers to work on a particular system
* **...** - Optionally, more layers (Like [unigi.ext](https://git.lumen.sh/Fierelier/unigi.ext))
* **App** - Your code, uses other layers for input/output. You can find examples in test/\*
# How to build
## Preparation
1. `git clone "https://git.lumen.sh/Fierelier/unigi"`
2. `git submodule update --init --recursive` (optional, required for fixed point math)
# Platforms
Platforms act as the translation layer for different systems. The idea is to minimize the amount of work it takes to port graphical applications.
## Platform: null
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.
1. `cc src/tests/draw.c -Dunigi_flag_platform_null`
## Official platforms
* **[SDL1](https://git.lumen.sh/Fierelier/unigi.platform.sdl1)** - The highly compatible SDL 1.2, works on old Linux, Windows 95+ and some consoles
* **[SDL2](https://git.lumen.sh/Fierelier/unigi.platform.sdl2)** - SDL 2.x, works on somewhat recent Linux, Windows XP+ and some consoles
* **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: dos
This platform implements DOS (MS-DOS, FreeDOS, etc.), Tested with Open Watcom.
1. `cc src/tests/draw.c -Dunigi_flag_platform_dos`
## Platform: sdl1
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.

28
main.h
View File

@ -1,28 +0,0 @@
#ifndef unigi_header_main
#define unigi_header_main
#include "structs.h"
#include "types.h"
// MAIN
unigi_type_error unigi_init();
// GRAPHICS
unigi_type_error unigi_graphics_init();
extern unigi_type_resolution_range * unigi_resolutions;
void unigi_graphics_draw(unigi_type_resolution_1d_coord index, unigi_type_color color);
void unigi_graphics_blit(unigi_type_resolution_1d_coord index, unigi_type_color * pixels, unigi_type_resolution_1d_coord length);
void unigi_graphics_flush();
// INPUT
void unigi_input_mouse_capture(unigi_type_bool captured);
unigi_type_error unigi_window_create(unigi_type_resolution resolution, char * title);
unigi_type_time_span unigi_time_get();
// TIME
#define unigi_time_clocks_per_s 1000000
void unigi_time_sleep(unigi_type_time_span ms);
void unigi_event_get(unigi_type_event * event);
// SOUND
unigi_type_error unigi_sound_init(void (* callback)(uint8_t *, size_t));
#endif

13
main.i
View File

@ -1,13 +0,0 @@
%module unigi
%{
#include <stdint.h>
#include "unigi/types.h"
#include "unigi/structs.h"
#include "unigi/main.h"
%}
%include <typemaps.i>
%include <stdint.i>
%rename("%(strip:[unigi_])s") "";
%include "unigi/types.h"
%include "unigi/structs.h"
%include "unigi/main.h"

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -e
clear
cd "$(dirname "$(realpath "$BASH_SOURCE")")"
cd ..
swig -I"$PWD" -lua unigi.ext/main.i
gcc -llua5.1 -I/usr/include/lua5.1 -I"$PWD" -lSDL unigi.ext/test/lua.c
./a.out

1
src/api/README.txt Normal file
View File

@ -0,0 +1 @@
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.

40
src/api/event.c Normal file
View File

@ -0,0 +1,40 @@
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;
}

22
src/api/graphics.c Normal file
View File

@ -0,0 +1,22 @@
#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

55
src/config/checks.h Normal file
View File

@ -0,0 +1,55 @@
#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

4
src/config/user.h Normal file
View File

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

1
src/fptc-lib Submodule

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

116
src/main.h Normal file
View File

@ -0,0 +1,116 @@
#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

11
src/platform/defs.h Normal file
View File

@ -0,0 +1,11 @@
#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

5
src/platform/dos/event.c Normal file
View File

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

342
src/platform/dos/graphics.c Normal file
View File

@ -0,0 +1,342 @@
#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"

3
src/platform/dos/input.c Normal file
View File

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

17
src/platform/dos/main.c Normal file
View File

@ -0,0 +1,17 @@
#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);
}

8
src/platform/dos/main.h Normal file
View File

@ -0,0 +1,8 @@
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;

2
src/platform/dos/time.c Normal file
View File

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

11
src/platform/main.c Normal file
View File

@ -0,0 +1,11 @@
#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

11
src/platform/main.h Normal file
View File

@ -0,0 +1,11 @@
#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

@ -0,0 +1,5 @@
#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

@ -0,0 +1,76 @@
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

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

13
src/platform/null/main.c Normal file
View File

@ -0,0 +1,13 @@
#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() {
}

8
src/platform/null/main.h Normal file
View File

@ -0,0 +1,8 @@
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;

2
src/platform/null/time.c Normal file
View File

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

25
src/platform/sdl1/event.c Normal file
View File

@ -0,0 +1,25 @@
#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

@ -0,0 +1,125 @@
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

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

15
src/platform/sdl1/main.c Normal file
View File

@ -0,0 +1,15 @@
#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();
}

8
src/platform/sdl1/main.h Normal file
View File

@ -0,0 +1,8 @@
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;

4
src/platform/sdl1/time.c Normal file
View File

@ -0,0 +1,4 @@
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);
}

155
src/tests/draw.c Normal file
View File

@ -0,0 +1,155 @@
#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

16
src/type/float.h Normal file
View File

@ -0,0 +1,16 @@
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)

17
src/type/float_fp.h Normal file
View File

@ -0,0 +1,17 @@
#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

30
src/type/int.h Normal file
View File

@ -0,0 +1,30 @@
#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;

127
structs.h
View File

@ -1,127 +0,0 @@
#ifndef unigi_header_structs
#define unigi_header_structs
#include "types.h"
// * EVENTS
struct unigi_type_event_none {
uint8_t none;
};
typedef struct unigi_type_event_none unigi_type_event_none;
static const unigi_type_event_enum unigi_enum_event_none = 0;
struct unigi_type_event_unknown {
uint8_t none;
};
typedef struct unigi_type_event_unknown unigi_type_event_unknown;
static const unigi_type_event_enum unigi_enum_event_unknown = 1;
static const unigi_type_event_enum unigi_enum_event_window_quit = 2;
struct unigi_type_event_window_quit {
uint8_t none;
};
typedef struct unigi_type_event_window_quit unigi_type_event_window_quit;
static const unigi_type_event_enum unigi_enum_event_window_focus = 4;
struct unigi_type_event_window_focus {
uint8_t focused;
};
typedef struct unigi_type_event_window_focus unigi_type_event_window_focus;
static const unigi_type_event_enum unigi_enum_event_window_activate = 5;
struct unigi_type_event_window_activate {
uint8_t active;
};
typedef struct unigi_type_event_window_activate unigi_type_event_window_activate;
// Keyboard
static const unigi_type_event_enum unigi_enum_event_input_keyboard = 6;
struct unigi_type_event_input_keyboard {
unigi_type_input_device device;
unigi_type_input_keyboard_button button;
unigi_type_input_button_state down;
};
typedef struct unigi_type_event_input_keyboard unigi_type_event_input_keyboard;
// Mouse
static const unigi_type_event_enum unigi_enum_event_input_mouse_button = 7;
struct unigi_type_event_input_mouse_button {
unigi_type_input_device device;
unigi_type_input_mouse_button button;
unigi_type_input_button_state down;
};
typedef struct unigi_type_event_input_mouse_button unigi_type_event_input_mouse_button;
static const unigi_type_event_enum unigi_enum_event_input_mouse_move = 8;
struct unigi_type_event_input_mouse_move {
unigi_type_input_device device;
unigi_type_input_mouse_coord_relative rel_x;
unigi_type_input_mouse_coord_relative rel_y;
unigi_type_input_mouse_coord_absolute abs_x;
unigi_type_input_mouse_coord_absolute abs_y;
};
typedef struct unigi_type_event_input_mouse_move unigi_type_event_input_mouse_move;
static const unigi_type_event_enum unigi_enum_event_input_mouse_scroll = 9;
struct unigi_type_event_input_mouse_scroll {
unigi_type_input_device device;
unigi_type_input_mouse_coord_scroll scroll_x;
unigi_type_input_mouse_coord_scroll scroll_y;
};
typedef struct unigi_type_event_input_mouse_scroll unigi_type_event_input_mouse_scroll;
// Joypad
static const unigi_type_event_enum unigi_enum_event_input_joypad_button = 10;
struct unigi_type_event_input_joypad_button {
unigi_type_input_device device;
unigi_type_input_mouse_button button;
unigi_type_input_button_state down;
};
typedef struct unigi_type_event_input_joypad_button unigi_type_event_input_joypad_button;
static const unigi_type_event_enum unigi_enum_event_input_joypad_analog = 11;
struct unigi_type_event_input_joypad_analog {
unigi_type_input_device device;
unigi_type_input_joypad_button axis;
unigi_type_input_joypad_analog x;
unigi_type_input_joypad_analog y;
};
typedef struct unigi_type_event_input_joypad_analog unigi_type_event_input_joypad_analog;
// * GRAPHICS
struct unigi_type_resolution {
unigi_type_resolution_2d_coord width;
unigi_type_resolution_2d_coord height;
unigi_type_resolution_depth depth;
};
typedef struct unigi_type_resolution unigi_type_resolution;
struct unigi_type_resolution_range {
unigi_type_resolution_2d_coord width_min;
unigi_type_resolution_2d_coord height_min;
unigi_type_resolution_2d_coord width_max;
unigi_type_resolution_2d_coord height_max;
unigi_type_resolution_depth depth_min;
unigi_type_resolution_depth depth_max;
};
typedef struct unigi_type_resolution_range unigi_type_resolution_range;
union unigi_type_event_union {
unigi_type_event_none none;
unigi_type_event_unknown unknown;
unigi_type_event_window_quit window_quit;
unigi_type_event_window_activate window_activate;
unigi_type_event_window_focus window_focus;
unigi_type_event_input_keyboard input_keyboard;
unigi_type_event_input_mouse_button input_mouse_button;
unigi_type_event_input_mouse_move input_mouse_move;
unigi_type_event_input_mouse_scroll input_mouse_scroll;
unigi_type_event_input_joypad_button input_joypad_button;
unigi_type_event_input_joypad_analog input_joypad_analog;
};
typedef union unigi_type_event_union unigi_type_event_union;
struct unigi_type_event {
unigi_type_event_enum type;
unigi_type_event_union data;
};
typedef struct unigi_type_event unigi_type_event;
#endif

View File

@ -1,46 +0,0 @@
#include "unigi/main.h"
#include "unigi.platform.sdl1/main.c"
uint32_t seed = 1337;
uint32_t example_random() {
seed = (seed * 1103515245 + 12345) & 0x7FFFFFFF;
return seed;
}
int main(int argc, char *argv[]) {
unigi_init();
unigi_type_event event;
unigi_type_resolution res;
res.width = 320;
res.height = 240;
res.depth = 32;
unigi_type_color pixels[res.width * res.height];
unigi_type_resolution_2d_coord x;
unigi_type_resolution_2d_coord y;
unigi_type_resolution_1d_coord max = res.width * res.height;
uint32_t t = 0;
uint32_t t2 = 0;
unigi_graphics_init();
unigi_window_create(res,"game");
while (1) {
unigi_event_get(&event);
if (event.type == unigi_enum_event_input_keyboard) {
exit(0);
}
for (y = 0; y < res.height; y++) {
for (x = 0; x < res.width; x++) {
//unigi_graphics_draw((y * res.width) + x,(t + (x ^ y)) + y);
//unigi_graphics_draw((((y * res.width) + x) + t) % max,(t + (x ^ y)) + y);
pixels[(((y * res.width) + x) + t) % max] = (t + (x ^ y)) + y;
}
t2++;
}
unigi_graphics_blit(0,pixels,res.width * res.height);
unigi_graphics_flush();
t++;
}
return 0;
}

View File

@ -1,82 +0,0 @@
#include "unigi/main.h"
#include "unigi.platform.sdl1/main.c"
#include "unigi.ext/main.c"
uint32_t seed = 1337;
uint32_t example_random() {
seed = (seed * 1103515245 + 12345) & 0x7FFFFFFF;
return seed;
}
int main(int argc, char *argv[]) {
unigi_init();
unigi_type_event event;
unigi_type_resolution res;
res.width = 320;
res.height = 240;
res.depth = 32;
unigi_ext_type_texture buf;
buf.width = res.width;
buf.height = res.height;
buf.lq_color = 0x0000;
unigi_type_color buf_pixels[res.width * res.height];
buf.pixels = buf_pixels;
unigi_ext_type_texture tex;
unigi_type_color tex_pixels[6];
tex.width = 3;
tex.height = 2;
tex.lq_color = 0x0000;
tex_pixels[0] = 0xFF00;
tex_pixels[1] = 0xF0F0;
tex_pixels[2] = 0xF00F;
tex_pixels[3] = 0xFFF0;
tex_pixels[4] = 0xF0FF;
tex_pixels[5] = 0xFF0F;
tex.pixels = tex_pixels;
unigi_ext_type_rect tex_bounds;
tex_bounds.x1 = 0;
tex_bounds.y1 = 0;
tex_bounds.x2 = 3;
tex_bounds.y2 = 2;
unigi_ext_type_rect buf_bounds;
buf_bounds.x1 = 10;
buf_bounds.y1 = 10;
buf_bounds.x2 = 61;
buf_bounds.y2 = 41;
unigi_type_resolution_2d_coord x;
unigi_type_resolution_2d_coord y;
unigi_type_resolution_1d_coord max = res.width * res.height;
uint32_t t = 0;
uint32_t t2 = 0;
unigi_graphics_init();
unigi_window_create(res,"game");
while (1) {
unigi_event_get(&event);
if (event.type == unigi_enum_event_input_keyboard) {
exit(0);
}
for (y = 0; y < res.height; y++) {
for (x = 0; x < res.width; x++) {
//unigi_graphics_draw((y * res.width) + x,(t + (x ^ y)) + y);
//unigi_graphics_draw((((y * res.width) + x) + t) % max,(t + (x ^ y)) + y);
buf.pixels[(((y * res.width) + x) + t) % max] = (t + (x ^ y)) + y;
}
t2++;
}
unigi_ext_texture_draw(tex,buf,tex_bounds,buf_bounds);
unigi_graphics_blit(0,buf.pixels,res.width * res.height);
unigi_graphics_flush();
t++;
}
return 0;
}

View File

@ -1,18 +0,0 @@
#include "unigi/main.h"
#include "unigi.platform.sdl1/main.c"
#include "unigi/main_wrap.c"
#if LUA_VERSION_NUM < 503
#include <lualib.h>
#endif
int main(int argc, char *argv[]) {
lua_State *L = luaL_newstate();
assert(L != NULL);
luaL_openlibs(L);
luaopen_unigi(L); // Load the wrapped module
luaL_loadfile(L, "mods/main/script/main.lua");
lua_pcall(L, 0, 0, 0);
return 0;
}

30
types.h
View File

@ -1,30 +0,0 @@
#ifndef unigi_header_types
#define unigi_header_types
#include <stdint.h>
// Main
typedef uint8_t unigi_type_bool;
// Events
typedef uint8_t unigi_type_error;
typedef uint8_t unigi_type_event_enum;
// Graphics
typedef uint16_t unigi_type_resolution_2d_coord;
typedef uint32_t unigi_type_resolution_1d_coord;
typedef uint8_t unigi_type_resolution_depth;
typedef uint16_t unigi_type_color;
// Input
typedef uint8_t unigi_type_input_device;
typedef uint8_t unigi_type_input_button_state;
typedef uint8_t unigi_type_input_keyboard_button;
typedef uint8_t unigi_type_input_mouse_button;
typedef int32_t unigi_type_input_mouse_coord_relative;
typedef uint16_t unigi_type_input_mouse_coord_absolute;
typedef uint8_t unigi_type_input_mouse_coord_scroll;
typedef uint8_t unigi_type_input_joypad_button;
typedef int16_t unigi_type_input_joypad_analog;
// Time
typedef uint32_t unigi_type_time_span;
#endif