maug
Quick and dirty C mini-augmentation library.
Loading...
Searching...
No Matches
retroflt.h File Reference

Abstraction layer header for retro systems. More...

#include <mtypes.h>
#include <stdarg.h>
#include <marge.h>
#include <uprintf.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_BITMAP
 Platform-specific bitmap structure. retroflat_bitmap_ok() can be used on a pointer to it to determine if a valid bitmap is loaded. More...
 
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 RETROFLAT_KB_TRACE_LVL   0
 
#define RETROFLAT_COLOR_TABLE(f)
 This macro defines all colors supported by RetroFlat for primative operations, particularly using retroflat_px().
 
#define RETROFLAT_COLOR_NULL   (-1)
 
#define RETROFLAT_COLORS_SZ   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_FLAGS_FILL   0x01
 Flag for retroflat_rect() or retroflat_ellipse(), indicating drawn shape should be filled.
 
#define RETROFLAT_FLAGS_OPAQUE   0x01
 Flag for retroflat_create_bitmap() to create a bitmap without transparency.
 
#define RETROFLAT_FLAGS_ALL_CAPS   0x02
 Flag for retroflat_string() and retroflat_string_sz() to print text in all capital letters. Non-letters are unmodified.
 
#define RETROFLAT_FLAGS_LITERAL_PATH   0x02
 Flag for retroflat_load_bitmap() to not use assets path.
 
#define RETROFLAT_FLAGS_OUTLINE   0x04
 Flag for retroflat_string() and retroflat_string_sz() to print text as outline-only.
 
#define RETROFLAT_FLAGS_SCREEN_BUFFER   0x80
 Flag for retroflat_create_bitmap() to create a WinG-backed bitmap.
 
#define RETROFLAT_FLAGS_RUNNING   0x01
 Flag indicating that retroflat_loop() should continue executing.
 
#define RETROFLAT_FLAGS_UNLOCK_FPS   0x02
 Flag indicating FPS should not be capped.
 
#define RETROFLAT_FLAGS_KEY_REPEAT   0x04
 Flag indicating keyboard repeat is enabled.
 
#define RETROFLAT_FLAGS_SCREENSAVER   0x08
 Flag indicating the current application is running as a screensaver.
 
#define RETROFLAT_FLAGS_SCALE2X   0x10
 Only supported on some platforms: Attempt to scale screen by 2X.
 
#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!)
 
#define RETROFLAT_FLAGS_SCREEN_LOCK   0x02
 
#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_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_GL_Z   -0.001
 
#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.
 
#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_PATH_MAX   256
 Maximum size allocated for asset paths.
 
#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_ASSETS_PATH_MAX   (RETROFLAT_PATH_MAX >> 1)
 Maximum size of the assets path, to allow room for appending.
 
#define NDS_OAM_ACTIVE   &oamMain
 Active sprite engine screen on Nintendo DS.
 
#define NDS_SPRITES_ACTIVE   24
 Maximum number of sprites active on-screen on Nintendo DS.
 
#define RETROFLAT_BMP_COLORS_SZ_MAX   256
 
#define retroflat_cmp_asset_path(a, b)   strncmp( a, b, RETROFLAT_PATH_MAX )
 Compare two asset paths. Return 0 if they're the same.
 
#define retroflat_buffer_bksp(buffer, buffer_cur, buffer_sz)
 Remove a character from a text buffer before cursor position.
 
#define retroflat_buffer_insert(c, buffer, buffer_cur, buffer_sz, buffer_mx)
 Insert a character into a text buffer at cursor position.
 
#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_bitmap_ok(bitmap)   (NULL != (bitmap)->b)
 Check to see if a bitmap is loaded.
 
#define retroflat_screen_w()
 Get the current screen width in pixels.
 
#define retroflat_screen_h()
 Get the current screen height in pixels.
 
#define retroflat_screen_buffer()   (&(g_retroflat_state->buffer))
 Get the direct screen buffer or the VDP buffer if a VDP is loaded.
 
#define retroflat_quit(retval_in)
 This should be called in order to quit a program using RetroFlat.
 
#define RETROFLAT_COLOR_BLACK   0
 
#define RETROFLAT_COLOR_DARKBLUE   1
 
#define RETROFLAT_COLOR_DARKGREEN   2
 
#define RETROFLAT_COLOR_TEAL   3
 
#define RETROFLAT_COLOR_DARKRED   4
 
#define RETROFLAT_COLOR_VIOLET   5
 
#define RETROFLAT_COLOR_BROWN   6
 
#define RETROFLAT_COLOR_GRAY   7
 
#define RETROFLAT_COLOR_DARKGRAY   8
 
#define RETROFLAT_COLOR_BLUE   9
 
#define RETROFLAT_COLOR_GREEN   10
 
#define RETROFLAT_COLOR_CYAN   11
 
#define RETROFLAT_COLOR_RED   12
 
#define RETROFLAT_COLOR_MAGENTA   13
 
#define RETROFLAT_COLOR_YELLOW   14
 
#define RETROFLAT_COLOR_WHITE   15
 
#define RETROFLAT_KEY_UP   0
 
#define RETROFLAT_KEY_DOWN   0
 
#define RETROFLAT_KEY_RIGHT   0
 
#define RETROFLAT_KEY_LEFT   0
 
#define RETROFLAT_KEY_A   0x41
 
#define RETROFLAT_KEY_B   0x42
 
#define RETROFLAT_KEY_C   0x43
 
#define RETROFLAT_KEY_D   0x44
 
#define RETROFLAT_KEY_E   0x45
 
#define RETROFLAT_KEY_F   0x46
 
#define RETROFLAT_KEY_G   0x47
 
#define RETROFLAT_KEY_H   0x48
 
#define RETROFLAT_KEY_I   0x49
 
#define RETROFLAT_KEY_J   0x4a
 
#define RETROFLAT_KEY_K   0x4b
 
#define RETROFLAT_KEY_L   0x4c
 
#define RETROFLAT_KEY_M   0x4d
 
#define RETROFLAT_KEY_N   0x4e
 
#define RETROFLAT_KEY_O   0x4f
 
#define RETROFLAT_KEY_P   0x50
 
#define RETROFLAT_KEY_Q   0x51
 
#define RETROFLAT_KEY_R   0x52
 
#define RETROFLAT_KEY_S   0x53
 
#define RETROFLAT_KEY_T   0x54
 
#define RETROFLAT_KEY_U   0x55
 
#define RETROFLAT_KEY_V   0x56
 
#define RETROFLAT_KEY_W   0x57
 
#define RETROFLAT_KEY_X   0x58
 
#define RETROFLAT_KEY_Y   0x59
 
#define RETROFLAT_KEY_Z   0x60
 
#define RETROFLAT_KEY_0   0x30
 
#define RETROFLAT_KEY_1   0x31
 
#define RETROFLAT_KEY_2   0x32
 
#define RETROFLAT_KEY_3   0x33
 
#define RETROFLAT_KEY_4   0x34
 
#define RETROFLAT_KEY_5   0x35
 
#define RETROFLAT_KEY_6   0x36
 
#define RETROFLAT_KEY_7   0x37
 
#define RETROFLAT_KEY_8   0x38
 
#define RETROFLAT_KEY_9   0x39
 
#define RETROFLAT_KEY_TAB   0
 
#define RETROFLAT_KEY_SPACE   0
 
#define RETROFLAT_KEY_ESC   0
 
#define RETROFLAT_KEY_ENTER   0
 
#define RETROFLAT_KEY_HOME   0
 
#define RETROFLAT_KEY_END   0
 
#define RETROFLAT_MOUSE_B_LEFT   0
 
#define RETROFLAT_MOUSE_B_RIGHT   0
 
#define RETROFLAT_COLOR_TABLE_CONSTS(idx, name_l, name_u, r, g, b, cgac, cgad)    extern MAUG_CONST RETROFLAT_COLOR RETROFLAT_COLOR_ ## name_u;
 

Typedefs

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.
 
typedef MERROR_RETVAL(* retroflat_proc_resize_t) (uint16_t new_w, uint16_t new_h, void *data)
 
typedef char retroflat_asset_path[RETROFLAT_PATH_MAX]
 Path/name used to load an asset from disk.
 
typedef void(* retroflat_loop_iter) (void *data)
 Prototype for the main loop function passed to retroflat_loop().
 
typedef int RETROFLAT_COLOR_DEF
 

Functions

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.
 
void retroflat_message (uint8_t flags, const char *title, const char *format,...)
 Display a message in a dialog box and/or on stderr.
 
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.
 
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().
 
MERROR_RETVAL retroflat_vdp_call (const char *proc_name)
 Call a function from the retroflat VDP.
 
void retroflat_set_title (const char *format,...)
 
retroflat_ms_t retroflat_get_ms ()
 
uint32_t retroflat_get_rand ()
 
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.
 
MERROR_RETVAL retroflat_create_bitmap (size_t w, size_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).
 
void retroflat_blit_bitmap (struct RETROFLAT_BITMAP *target, struct RETROFLAT_BITMAP *src, int s_x, int s_y, int d_x, int d_y, int16_t w, int16_t h)
 Blit the contents of a RETROFLAT_BITMAP onto another RETROFLAT_BITMAP.
 
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.
 
MERROR_RETVAL retroflat_draw_release (struct RETROFLAT_BITMAP *bmp)
 
void retroflat_px (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, int16_t x, int16_t y, uint8_t flags)
 
void retroflat_rect (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags)
 Draw a rectangle onto the target RETROFLAT_BITMAP.
 
void retroflat_ellipse (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags)
 Draw an ellipse onto the target RETROFLAT_BITMAP.
 
void retroflat_line (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t flags)
 Draw a straight line onto the target RETROFLAT_BITMAP.
 
void retroflat_cursor (struct RETROFLAT_BITMAP *target, uint8_t flags)
 
void retroflat_string_sz (struct RETROFLAT_BITMAP *target, const char *str, size_t str_sz, const char *font_str, size_t *w_out, size_t *h_out, uint8_t flags)
 Get the size in pixels of a text string when drawn with a given font by retroflat_string().
 
void retroflat_string (struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, const char *str, int str_sz, const char *font_str, int16_t x_orig, int16_t y_orig, uint8_t flags)
 Draw a text string at the specified location in the specified font and color on the target RETROFLAT_BITMAP.
 
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)
 
void retroflat_resize_v ()
 
RETROFLAT_IN_KEY retroflat_poll_input (struct RETROFLAT_INPUT *input)
 Poll input devices (keyboard/mouse) and return the latest event.
 

Variables

MAUG_CONST char *SEG_MCONST gc_retroflat_color_names []
 
struct RETROFLAT_STATEg_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.