maug
Quick and dirty C mini-augmentation library.
Data Structures | Macros | Typedefs | Functions | Variables
retroflt.h File Reference

Abstraction layer header for retro systems. More...

#include <stdarg.h>
#include <marge.h>
#include "retrosnd.h"
#include <retapis.h>
#include <retapii.h>
#include <retapid.h>
#include "retrom2d.h"
#include <retrovi2.h>
Include dependency graph for retroflt.h:

Go to the source code of this file.

Data Structures

struct  RETROFLAT_INPUT
 Struct passed to retroflat_poll_input() to hold return data. More...
 
struct  RETROFLAT_3DTEX
 
struct  RETROFLAT_ARGS
 Struct containing configuration values for a RetroFlat program. More...
 
struct  RETROFLAT_STATE
 Global singleton containing state for the current platform. More...
 

Macros

#define RETROFLAT_BITMAP_TRACE_LVL   0
 
#define RETROINPUT_TRACE_LVL   0
 
#define RETROFLAT_COLOR_TABLE(f)
 This macro defines all colors supported by RetroFlat for primative operations, particularly using retroflat_px(). More...
 
#define RETROFLAT_COLOR_NULL   (-1)
 
#define RETROFLAT_COLORS_CT   16
 
#define RETROFLAT_OK   0x00
 Certain functions return this when there was no problem.
 
#define RETROFLAT_ERROR_ENGINE   0x01
 
#define RETROFLAT_ERROR_GRAPHICS   0x02
 
#define RETROFLAT_ERROR_MOUSE   0x04
 
#define RETROFLAT_ERROR_BITMAP   0x08
 Returned if there is a problem loading or locking a ::RETROFLAT_BITMAP struct.
 
#define RETROFLAT_ERROR_TIMER   0x0f
 
#define RETROFLAT_DRAW_FLAG_FILL   0x01
 Flag for retroflat_rect() or retroflat_ellipse(), indicating drawn shape should be filled.
 
#define RETROFLAT_FONT_FLAG_ALL_CAPS   0x02
 Flag for retroflat_string() and retroflat_string_sz() to print text in all capital letters. Non-letters are unmodified. More...
 
#define RETROFLAT_MSG_FLAG_TYPE_MASK   0x07
 This mask covers all possible icon/type flags.
 
#define RETROFLAT_MSG_FLAG_ERROR   0x01
 This icon/type flag indicates an error. It will try to display messages in an urgent way with a red icon, if possible.
 
#define RETROFLAT_MSG_FLAG_INFO   0x02
 This icon/type flag indicates an informational notice. It will try to display messages in a definite way, with an i or speech bubble icon, if possible.
 
#define RETROFLAT_MSG_FLAG_WARNING   0x04
 This icon/type flag indicates a condition the user should be aware of. It will try to display messages in an urgent way with a yellow icon, if possible.
 
#define RETROFLAT_VDP_FLAG_PXLOCK   0x01
 Flag for RETROFLAT_STATE::vdp_flags indicating the VDP requires RetroFlat to pixel-lock the frame before passing it (almost always true!) More...
 
#define retroflat_vdp_available()   (NULL != g_retroflat_state->vdp_exe)
 
#define RETROFLAT_FOCUS_FLAG_ACTIVE   0x01
 
#define RETROFLAT_FOCUS_FLAG_VISIBLE   0x02
 
#define RETROFLAT_BITMAP_FLAG_OPAQUE   0x01
 Flag for retroflat_create_bitmap() or retroflat_load_bitmap() to create or load a bitmap without transparency.
 
#define RETROFLAT_BITMAP_FLAG_LITERAL_PATH   0x02
 Flag for retroflat_load_bitmap() to not use assets path.
 
#define RETROFLAT_BITMAP_FLAG_RO   0x04
 
#define RETROFLAT_BITMAP_FLAG_SCREEN_BUFFER   0x08
 Flag for retroflat_create_bitmap() to create a VRAM-backed bitmap. More...
 
#define RETROFLAT_BITMAP_FLAG_SCREEN_LOCK   0x20
 
#define RETROFLAT_BITMAP_FLAG_LOCK   0x40
 
#define RETROFLAT_INSTANCE_NULL   (0)
 Pass to retroflat_blit_bitmap() instance arg if this is not a sprite (i.e. if it is a background tile).
 
#define retroflat_instance_tile(instance)    (0 - (instance))
 Declare that a given instance ID is for a tile, rather than a sprite.
 
#define RETROFLAT_BITMAP_EXT   "bmp"
 The filename suffix to be appended with a "." to filenames passed to retroflat_load_bitmap(). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_OPENGL_BPP   32
 
#define RETROFLAT_TILE_W   16
 
#define RETROFLAT_TILE_W_BITS   4
 
#define RETROFLAT_TILE_H   16
 
#define RETROFLAT_TILE_H_BITS   4
 
#define RETROFLAT_TXP_R   0x00
 Compiler-define-overridable constant indicating the Red value of the transparency color on platforms that support it (mainly Win16/SDL). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_TXP_G   0x00
 Compiler-define-overridable constant indicating the Green value of the transparency color on platforms that support it (mainly Win16/SDL). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_TXP_B   0x00
 Compiler-define-overridable constant indicating the Blue value of the transparency color on platforms that support it (mainly Win16/SDL). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_TXP_PAL_IDX   0
 
#define RETROFLAT_DEFAULT_SCREEN_W   320
 
#define RETROFLAT_DEFAULT_SCREEN_H   200
 
#define RETROFLAT_DEFAULT_SCREEN_SCALE   1
 
#define retroflat_on_resize(w, h)
 
#define RETROFLAT_LINE_THICKNESS   1
 Line drawing thickness (only works on some platforms). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_PI   3.14159
 
#define RETROFLAT_FPS   30
 Target Frames Per Second. More...
 
#define retroflat_fps_next()   (1000 / RETROFLAT_FPS)
 
#define RETROFLAT_WINDOW_CLASS   "RetroFlatWindowClass"
 Unique window class to use on some platforms (e.g. Win32). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_WIN_FRAME_TIMER_ID   6001
 Unique ID for the timer that execute frame draws in Win16/Win32. Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_WIN_LOOP_TIMER_ID   6002
 Unique ID for the timer that execute loop ticks in Win16/Win32. Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_MSG_MAX   4096
 Maximum number of characters possible in a message using retroflat_message(). Is a RetroFlat Compiler Definitions.
 
#define RETROFLAT_TITLE_MAX   255
 
#define RETROFLAT_VDP_ARGS_SZ_MAX   255
 
#define RETROFLAT_PATH_SEP   '/'
 The valid path separator on the target platform.
 
#define RETROFLAT_COLORS_CT_MAX   256
 
#define RETROFLAT_TIMER_CT_MAX   10
 
#define retroflat_wait_for_frame()    (g_retroflat_state->retroflat_flags |= RETROFLAT_STATE_FLAG_WAIT_FOR_FPS)
 
#define retroflat_is_waiting_for_frame()
 
#define retroflat_buffer_bksp(buffer, buffer_cur, buffer_sz)
 Remove a character from a text buffer before cursor position. More...
 
#define retroflat_buffer_insert(c, buffer, buffer_cur, buffer_sz, buffer_mx)
 Insert a character into a text buffer at cursor position. More...
 
#define RETROFLAT_INPUT_MOD_SHIFT   0x01
 
#define RETROFLAT_INPUT_MOD_ALT   0x02
 
#define RETROFLAT_INPUT_MOD_CTRL   0x04
 
#define RETROFLAT_INPUT_FORCE_UPPER   0x08
 
#define RETROFLAT_DIR4_NONE   (-1)
 
#define RETROFLAT_DIR4_NORTH   0
 
#define RETROFLAT_DIR4_EAST   1
 
#define RETROFLAT_DIR4_SOUTH   2
 
#define RETROFLAT_DIR4_WEST   3
 
#define RETROFLAT_DIR8_NONE   (-1)
 
#define RETROFLAT_DIR8_NORTH   0
 
#define RETROFLAT_DIR8_EAST   2
 
#define RETROFLAT_DIR8_SOUTH   4
 
#define RETROFLAT_DIR8_WEST   6
 
#define retroflat_dir4_rotate_cw(dir)    ((dir + 1) % 4)
 
#define retroflat_dir8_reverse(dir)    ((dir + 4) % 8)
 
#define retroflat_dir8_bounce(dir)    ((dir + 2) % 8)
 
#define retroflat_outside_rect(x, y, rx, ry, rw, rh)
 
#define PXXY_FMT   "%d"
 
#define PXXY_MAX   INT16_MAX
 
#define RETRO2D_TRACE_LVL   0
 
#define RETRO2D_DRAW_TRACE_LVL   0
 
#define RETRO2D_LOCK_TRACE_LVL   0
 
#define retroflat_case_key(key, pad)   case pad: case key:
 Specify cases for a select() on the result of retroflat_poll_input() for keyboard or game pad as available. More...
 
#define retroflat_or_key(input, key, pad)    (((input) == (pad)) || ((input) == (key)))
 
#define retroflat_system_task()
 Platform-specific task that should be called on every iteration of the generic loop. This prevents having to define a platform-specific loop just to add a single call.
 
#define retroflat_get_assets_path()   (g_retroflat_state->assets_path)
 
#define retroflat_blank(target, color)
 
#define retroflat_soft_quit(retval)
 Call the quit callback if defined and only try to quit if the callback doesn't return MERROR_PREEMPT. More...
 
#define RETROFLAT_COLOR_TABLE_CONSTS(idx, name_l, name_u, r, g, b, cgac, cgad)    extern MAUG_CONST RETROFLAT_COLOR SEG_MCONST RETROFLAT_COLOR_ ## name_u;
 

Typedefs

typedef int16_t retroflat_tile_t
 Value for an individual tile in a RETROTILE_LAYER. More...
 
typedef int16_t retrotile_coord_t
 
typedef int8_t RETROFLAT_COLOR
 Defines an index in the platform-specific color-table.
 
typedef MERROR_RETVAL(* retroflat_vdp_proc_t) (struct RETROFLAT_STATE *)
 VDP function called from the VDP library. More...
 
typedef MERROR_RETVAL(* retroflat_proc_resize_t) (uint16_t new_w, uint16_t new_h, void *data)
 
typedef MERROR_RETVAL(* retroflat_proc_focus_t) (uint8_t flags, void *data)
 
typedef MERROR_RETVAL(* retroflat_proc_quit_t) (void *data)
 Callback to call when window closing is attempted. Should return MERROR_PREEMPT to defer or MERROR_OK to continue closing.
 
typedef void(* retroflat_loop_iter) (void *data)
 Prototype for the main loop function passed to retroflat_loop().
 
typedef int8_t retroflat_dir4_t
 
typedef int8_t retroflat_dir8_t
 
typedef int16_t retroflat_pxxy_t
 Type used for surface pixel coordinates. More...
 
typedef maug_ms_t retroflat_ms_t
 
typedef void(* retroflat_timer_cb_t) (retroflat_ms_t time, void *data)
 

Functions

uint32_t retroflat_get_rand (void)
 
retroflat_ms_t retroflat_get_ms (void)
 
MERROR_RETVAL retroflat_loop (retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void *data)
 This should be called once in the main body of the program in order to enter the main loop. The main loop will continuously call loop_iter with data as an argument until retroflat_quit() is called.
 
MERROR_RETVAL retroflat_build_filename_path (const maug_path filename_in, const char *filename_ext, char *buffer_out, size_t buffer_out_sz, uint8_t flags)
 
void retroflat_message (uint8_t flags, const char *title, const char *format,...)
 Display a message in a dialog box and/or on stderr. More...
 
MERROR_RETVAL retroflat_init (int argc, char *argv[], struct RETROFLAT_ARGS *args)
 Initialize RetroFlat and its underlying layers. This should be called once at the beginning of the program and should quit if the return value indicates any failures. More...
 
void retroflat_shutdown (int retval)
 Deinitialize RetroFlat and its underlying layers. This should be called once at the end of the program, after retroflat_loop(). More...
 
MERROR_RETVAL retroflat_vdp_call (const char *proc_name)
 Call a function from the retroflat VDP.
 
uint8_t * retroflat_vdp_get_vdp_in (void)
 
uint8_t * retroflat_vdp_get_vdp_out (void)
 
RETROFLAT_IN_KEY retroflat_repeat_input (RETROFLAT_IN_KEY key_out, struct RETROFLAT_INPUT *input, RETROFLAT_IN_KEY *prev_input, int *prev_delay)
 
void retroflat_set_title (const char *format,...)
 
char retroflat_vk_to_ascii (RETROFLAT_IN_KEY k, uint8_t flags)
 
MERROR_RETVAL retroflat_load_bitmap (const char *filename, struct RETROFLAT_BITMAP *bmp_out, uint8_t flags)
 Load a bitmap into the given ::RETROFLAT_BITMAP structure if it is available. Bitmaps are subject to the limitations enumerated in RetroFlat Bitmap API. More...
 
MERROR_RETVAL retroflat_create_bitmap (retroflat_pxxy_t w, retroflat_pxxy_t h, struct RETROFLAT_BITMAP *bmp_out, uint8_t flags)
 
void retroflat_destroy_bitmap (struct RETROFLAT_BITMAP *bitmap)
 Unload a bitmap from a ::RETROFLAT_BITMAP struct. The struct, itself, is not freed (in case it is on the stack). More...
 
MERROR_RETVAL retroflat_blit_bitmap (struct RETROFLAT_BITMAP *target, struct RETROFLAT_BITMAP *src, retroflat_pxxy_t s_x, retroflat_pxxy_t s_y, retroflat_pxxy_t d_x, retroflat_pxxy_t d_y, retroflat_pxxy_t w, retroflat_pxxy_t h, int16_t instance)
 Blit the contents of a ::RETROFLAT_BITMAP onto another ::RETROFLAT_BITMAP. More...
 
MERROR_RETVAL retroflat_draw_lock (struct RETROFLAT_BITMAP *bmp)
 Lock a bitmap for drawing. This will be done automatically if necessary and not called explicitly, but performance should improve if done before a batch of drawing operations. More...
 
MERROR_RETVAL retroflat_draw_release (struct RETROFLAT_BITMAP *bmp)
 
void retroflat_px (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, retroflat_pxxy_t x, retroflat_pxxy_t y, uint8_t flags)
 
void retroflat_rect (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, retroflat_pxxy_t x, retroflat_pxxy_t y, retroflat_pxxy_t w, retroflat_pxxy_t h, uint8_t flags)
 Draw a rectangle onto the target ::RETROFLAT_BITMAP. More...
 
void retroflat_ellipse (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, retroflat_pxxy_t x, retroflat_pxxy_t y, retroflat_pxxy_t w, retroflat_pxxy_t h, uint8_t flags)
 Draw an ellipse onto the target ::RETROFLAT_BITMAP. More...
 
void retroflat_line (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, retroflat_pxxy_t x1, retroflat_pxxy_t y1, retroflat_pxxy_t x2, retroflat_pxxy_t y2, uint8_t flags)
 Draw a straight line onto the target ::RETROFLAT_BITMAP. More...
 
void retroflat_cursor (struct RETROFLAT_BITMAP *target, uint8_t flags)
 
void retroflat_get_palette (uint8_t idx, uint32_t *rgb)
 
MERROR_RETVAL retroflat_set_palette (uint8_t idx, uint32_t rgb)
 
void retroflat_set_proc_resize (retroflat_proc_resize_t on_resize_in, void *data_in)
 Set the procedure to call when the window is resized (on platforms that support resizing). More...
 
ssize_t retroflat_timer_add (retroflat_ms_t time, retroflat_timer_cb_t cb, void *data)
 Add a timer callback to be executed at the given time. More...
 
void retroflat_set_proc_focus (retroflat_proc_focus_t on_focus_in, void *data_in)
 Set the procedure to call when the window gains or loses focus (on platforms that support multitasking). More...
 
void retroflat_set_proc_quit (retroflat_proc_quit_t on_quit_in, void *data_in)
 Set the procedure to call when the window is attempted to be closed (on platforms that support windows). More...
 
uint8_t retroflat_focus_platform (void)
 Platform-specific function to get current focus flags for the generic loop.
 
void retroflat_resize_v (void)
 Platform-specific function to resize virtual screen to match physical window size.
 
void retroflat_timer_handle (void)
 This should be called in the API HAL on every iteration of the main loop (this is done automatically in the generic main loop).
 
RETROFLAT_IN_KEY retroflat_poll_input (struct RETROFLAT_INPUT *input)
 Poll input devices (keyboard/mouse) and return the latest event. More...
 

Variables

MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x [8]
 
MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y [8]
 
MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x [4]
 
MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y [4]
 
MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x_tile [4]
 
MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y_tile [4]
 
MAUG_CONST char *SEG_MCONST gc_retroflat_color_names []
 
struct RETROFLAT_STATE *SEG_MGLOBAL g_retroflat_state
 

Detailed Description

Abstraction layer header for retro systems.

RetroFlat is a compatibility layer for making graphical programs that work on Win16 (32-bit via OpenWatcom's Win386), MS-DOS (32-bit via DOS/32a or DOS4GW via Allegro), and possibly other platforms in the future.

To use, define RETROFLT_C before including this header from your main.c.

You may include this header in other .c files, as well, but RETROFLT_C should ONLY be declared ONCE in the entire program.

maug.h should also be included before this header.