261#ifndef RETROFLAT_BITMAP_TRACE_LVL
262# define RETROFLAT_BITMAP_TRACE_LVL 0
265#ifndef RETROFLAT_KB_TRACE_LVL
266# define RETROFLAT_KB_TRACE_LVL 0
288#define RETROFLAT_COLOR_TABLE( f ) \
289 f( 0, black, BLACK, 0, 0, 0, BLACK, BLACK ) \
290 f( 1, darkblue, DARKBLUE, 0, 0, 170, CYAN, BLACK ) \
291 f( 2, darkgreen, DARKGREEN, 0, 170, 0, CYAN, BLACK ) \
292 f( 3, teal, TEAL, 0, 170, 170, CYAN, CYAN ) \
293 f( 4, darkred, DARKRED, 170, 0, 0, MAGENTA, BLACK ) \
294 f( 5, violet, VIOLET, 170, 0, 170, MAGENTA, BLACK ) \
295 f( 6, brown, BROWN, 170, 85, 0, CYAN, MAGENTA ) \
296 f( 7, gray, GRAY, 170, 170, 170, WHITE, BLACK ) \
297 f( 8, darkgray, DARKGRAY, 85, 85, 85, WHITE, BLACK ) \
298 f( 9, blue, BLUE, 85, 85, 255, CYAN, WHITE ) \
299 f( 10, green, GREEN, 85, 255, 85, CYAN, CYAN ) \
300 f( 11, cyan, CYAN, 85, 255, 255, CYAN, CYAN ) \
301 f( 12, red, RED, 255, 85, 85, MAGENTA, WHITE ) \
302 f( 13, magenta, MAGENTA, 255, 85, 255, MAGENTA, MAGENTA ) \
303 f( 14, yellow, YELLOW, 255, 255, 85, CYAN, MAGENTA ) \
304 f( 15, white, WHITE, 255, 255, 255, WHITE, WHITE )
309# define RETROFLAT_COLOR_NULL (-1)
311# define RETROFLAT_COLORS_SZ 16
316#if defined( RETROFLAT_OS_UNIX ) || defined( RETROFLAT_OS_WIN )
317#define RETROFLAT_MOUSE
327#define RETROFLAT_OK 0x00
328#define RETROFLAT_ERROR_ENGINE 0x01
329#define RETROFLAT_ERROR_GRAPHICS 0x02
330#define RETROFLAT_ERROR_MOUSE 0x04
336#define RETROFLAT_ERROR_BITMAP 0x08
337#define RETROFLAT_ERROR_TIMER 0x0f
355#define RETROFLAT_FLAGS_FILL 0x01
361#define RETROFLAT_FLAGS_OPAQUE 0x01
369#define RETROFLAT_FLAGS_ALL_CAPS 0x02
374#define RETROFLAT_FLAGS_LITERAL_PATH 0x02
376#ifndef RETROFLAT_NO_STRING
383#define RETROFLAT_FLAGS_OUTLINE 0x04
392#define RETROFLAT_FLAGS_SCREEN_BUFFER 0x80
398#define RETROFLAT_FLAGS_VIEWPORT_REFRESH 0x20
413#define RETROFLAT_FLAGS_RUNNING 0x01
419#define RETROFLAT_FLAGS_UNLOCK_FPS 0x02
425#define RETROFLAT_FLAGS_KEY_REPEAT 0x04
431#define RETROFLAT_FLAGS_SCREENSAVER 0x08
436#define RETROFLAT_FLAGS_SCALE2X 0x10
441#define RETROFLAT_FLAGS_WAIT_FOR_FPS 0x20
453#define RETROFLAT_MSG_FLAG_TYPE_MASK 0x07
459#define RETROFLAT_MSG_FLAG_ERROR 0x01
466#define RETROFLAT_MSG_FLAG_INFO 0x02
473#define RETROFLAT_MSG_FLAG_WARNING 0x04
498#define RETROFLAT_VDP_FLAG_PXLOCK 0x01
516 uint16_t new_w, uint16_t new_h,
void* data );
523#define RETROSND_ARGS_FLAG_LIST_DEVS 0x01
556#define RETROFLAT_FLAGS_LOCK 0x01
558#define RETROFLAT_FLAGS_SCREEN_LOCK 0x02
560#define RETROFLAT_FLAGS_BITMAP_RO 0x04
567#define RETROFLAT_INSTANCE_NULL (0)
569#define retroflat_instance_tile( instance ) \
576#ifndef RETROFLAT_BITMAP_EXT
577# define RETROFLAT_BITMAP_EXT "bmp"
580#ifndef RETROFLAT_OPENGL_BPP
581# define RETROFLAT_OPENGL_BPP 32
584#ifndef RETROFLAT_TILE_W
585# define RETROFLAT_TILE_W 16
588#ifndef RETROFLAT_TILE_W_BITS
589# define RETROFLAT_TILE_W_BITS 4
592#ifndef RETROFLAT_TILE_H
593# define RETROFLAT_TILE_H 16
596#ifndef RETROFLAT_TILE_H_BITS
597# define RETROFLAT_TILE_H_BITS 4
601#ifndef RETROFLAT_TXP_R
607# define RETROFLAT_TXP_R 0x00
610#ifndef RETROFLAT_TXP_G
616# define RETROFLAT_TXP_G 0x00
619#ifndef RETROFLAT_TXP_B
625# define RETROFLAT_TXP_B 0x00
628#ifndef RETROFLAT_TXP_PAL_IDX
629# define RETROFLAT_TXP_PAL_IDX 0
634#ifndef RETROFLAT_DEFAULT_SCREEN_W
635# define RETROFLAT_DEFAULT_SCREEN_W 320
638#ifndef RETROFLAT_DEFAULT_SCREEN_H
639# define RETROFLAT_DEFAULT_SCREEN_H 200
642#ifndef RETROFLAT_GL_Z
643# define RETROFLAT_GL_Z -0.001
646#define retroflat_on_resize( w, h ) \
647 g_retroflat_state->screen_w = w; \
648 g_retroflat_state->screen_h = h;
655#ifndef RETROFLAT_LINE_THICKNESS
660# define RETROFLAT_LINE_THICKNESS 1
663#define RETROFLAT_PI 3.14159
677# define RETROFLAT_FPS 30
680#define retroflat_fps_next() (1000 / RETROFLAT_FPS)
682#ifndef RETROFLAT_WINDOW_CLASS
687# define RETROFLAT_WINDOW_CLASS "RetroFlatWindowClass"
690#ifndef RETROFLAT_WIN_FRAME_TIMER_ID
695# define RETROFLAT_WIN_FRAME_TIMER_ID 6001
698#ifndef RETROFLAT_WIN_LOOP_TIMER_ID
703# define RETROFLAT_WIN_LOOP_TIMER_ID 6002
706#ifndef RETROFLAT_MSG_MAX
711# define RETROFLAT_MSG_MAX 4096
714#define RETROFLAT_PATH_MAX MAUG_PATH_MAX
716#ifndef RETROFLAT_TITLE_MAX
717# define RETROFLAT_TITLE_MAX 255
720#ifndef RETROFLAT_VDP_ARGS_SZ_MAX
724# define RETROFLAT_VDP_ARGS_SZ_MAX 255
727#if defined( RETROFLAT_API_SDL2 )
728# if !defined( NO_RETROFLAT_RESIZABLE )
729# define RETROFLAT_WIN_FLAGS SDL_WINDOW_RESIZABLE
731# define RETROFLAT_WIN_FLAGS 0
735#if defined( RETROFLAT_API_SDL1 )
736# define RETROFLAT_SDL_CC_FLAGS (SDL_RLEACCEL | SDL_SRCCOLORKEY)
737#elif defined( RETROFLAT_API_SDL2 )
738# define RETROFLAT_SDL_CC_FLAGS (SDL_TRUE)
741#ifdef RETROFLAT_OS_DOS
742# define RETROFLAT_PATH_SEP '\\'
745# define RETROFLAT_PATH_SEP '/'
749#define RETROFLAT_ASSETS_PATH_MAX (RETROFLAT_PATH_MAX >> 1)
751#ifndef RETROFLAT_BMP_COLORS_SZ_MAX
752# define RETROFLAT_BMP_COLORS_SZ_MAX 256
757#define retroflat_wait_for_frame() \
758 (g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_WAIT_FOR_FPS)
760#define retroflat_is_waiting_for_frame() \
761 (RETROFLAT_FLAGS_WAIT_FOR_FPS == \
762 (g_retroflat_state->retroflat_flags & RETROFLAT_FLAGS_WAIT_FOR_FPS))
779#define retroflat_cmp_asset_path( a, b ) strncmp( a, b, RETROFLAT_PATH_MAX )
797#define retroflat_buffer_bksp( buffer, buffer_cur, buffer_sz ) \
798 if( 0 < buffer_cur ) { \
799 if( buffer_cur < buffer_sz ) { \
801 &(buffer[(buffer_cur) - 1]), \
802 &(buffer[buffer_cur]), \
803 (buffer_sz) - (buffer_cur) ); \
807 buffer[buffer_sz] = '\0'; \
813#define retroflat_buffer_insert( c, buffer, buffer_cur, buffer_sz, buffer_mx ) \
814 if( buffer_sz + 1 < buffer_mx ) { \
815 if( buffer_cur < buffer_sz ) { \
817 &(buffer[(buffer_cur) + 1]), \
818 &(buffer[buffer_cur]), \
819 (buffer_sz) - (buffer_cur) ); \
821 buffer[buffer_cur] = c; \
824 buffer[buffer_sz] = '\0'; \
827#define RETROFLAT_INPUT_MOD_SHIFT 0x01
829#define RETROFLAT_INPUT_MOD_ALT 0x02
831#define RETROFLAT_INPUT_MOD_CTRL 0x04
833#define RETROFLAT_INPUT_FORCE_UPPER 0x08
859#define RETROFLAT_DIR4_NORTH 0
860#define RETROFLAT_DIR4_EAST 1
861#define RETROFLAT_DIR4_SOUTH 2
862#define RETROFLAT_DIR4_WEST 3
864#define RETROFLAT_DIR8_NORTH 0
865#define RETROFLAT_DIR8_EAST 2
866#define RETROFLAT_DIR8_SOUTH 4
867#define RETROFLAT_DIR8_WEST 6
869#define retroflat_dir8_reverse( dir ) \
872#define retroflat_dir8_bounce( dir ) \
877#ifdef RETROFLAT_OPENGL
878struct RETROFLAT_GLTEX {
879 MAUG_MHANDLE bytes_h;
922#ifndef RETROSND_TRACE_LVL
923# define RETROSND_TRACE_LVL 0
926#ifndef RETROSND_REG_TRACE_LVL
927# define RETROSND_REG_TRACE_LVL 0
940#define RETROSND_FLAG_INIT 0x01
944#define RETROSND_VOICE_BREATH 122
946#define RETROSND_VOICE_SEASHORE 123
948#define RETROSND_VOICE_BIRD_TWEET 124
950#define RETROSND_VOICE_PHONE_RING 125
952#define RETROSND_VOICE_HELICOPTER 126
954#define RETROSND_VOICE_APPLAUSE 127
960#define RETROSND_VOICE_GUNSHOT 128
962#define RETROSND_CHANNEL_CT 8
979void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice );
981void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val );
983void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel );
985void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel );
989uint8_t retrosnd_midi_is_playing_smf();
991void retrosnd_shutdown();
999#if defined( RETROFLAT_OS_WIN ) && !defined( MAUG_WINDOWS_H )
1000# include <windows.h>
1001# define MAUG_WINDOWS_H
1007typedef maug_ms_t retroflat_ms_t;
1023# ifdef RETROFLAT_API_PC_BIOS
1025 uint8_t screen_mode;
1026# elif !defined( RETROFLAT_NO_CLI_SZ )
1036# if defined( RETROSND_API_SDL1 ) || defined( RETROSND_API_SDL2 )
1037# elif defined( RETROSND_API_WINMM )
1039# elif defined( RETROSND_API_PC_BIOS )
1040 uint16_t snd_io_base;
1042# elif defined( RETROSND_API_ALSA )
1046# pragma message( "warning: sound args not specified" )
1057typedef int16_t retroflat_tile_t;
1068 int16_t screen_tile_w;
1069 int16_t screen_tile_h;
1070 MAUG_MHANDLE refresh_grid_h;
1071 retroflat_tile_t* refresh_grid;
1074#ifndef DOCUMENTATION
1076# define retroflat_viewport_world_x_generic() \
1077 (g_retroflat_state->viewport.world_x)
1079# define retroflat_viewport_world_y_generic() \
1080 (g_retroflat_state->viewport.world_y)
1082# define retroflat_viewport_world_w_generic() \
1083 (g_retroflat_state->viewport.world_w)
1085# define retroflat_viewport_world_h_generic() \
1086 (g_retroflat_state->viewport.world_h)
1088# define retroflat_viewport_screen_tile_w_generic() \
1089 (g_retroflat_state->viewport.screen_tile_w)
1091# define retroflat_viewport_screen_tile_h_generic() \
1092 (g_retroflat_state->viewport.screen_tile_h)
1094# define retroflat_viewport_set_world_generic( w, h ) \
1095 (g_retroflat_state->viewport.world_w) = w; \
1096 (g_retroflat_state->viewport.world_h) = h;
1098# define retroflat_viewport_set_world_pos_generic( x, y ) \
1099 (g_retroflat_state->viewport.world_x) = x; \
1100 (g_retroflat_state->viewport.world_y) = y;
1102# define retroflat_viewport_lock_refresh_generic() \
1103 if( NULL == g_retroflat_state->viewport.refresh_grid ) { \
1105 g_retroflat_state->viewport.refresh_grid_h, \
1106 g_retroflat_state->viewport.refresh_grid ); \
1107 maug_cleanup_if_null_lock( retroflat_tile_t*, \
1108 g_retroflat_state->viewport.refresh_grid ); \
1111# define retroflat_viewport_unlock_refresh_generic() \
1112 if( NULL != g_retroflat_state->viewport.refresh_grid ) { \
1114 g_retroflat_state->viewport.refresh_grid_h, \
1115 g_retroflat_state->viewport.refresh_grid ); \
1118# define _retroflat_viewport_refresh_tile_x( x_px ) \
1119 (((x_px) + RETROFLAT_TILE_W) >> RETROFLAT_TILE_W_BITS)
1121# define _retroflat_viewport_refresh_tile_y( y_px ) \
1122 (((y_px) + RETROFLAT_TILE_H) >> RETROFLAT_TILE_H_BITS)
1124# define retroflat_viewport_set_refresh_generic( x_px, y_px, tid ) \
1125 assert( NULL != g_retroflat_state->viewport.refresh_grid ); \
1128 -(RETROFLAT_TILE_W) <= x_px && -(RETROFLAT_TILE_H) <= y_px && \
1129 retroflat_screen_w() > x_px && \
1130 retroflat_screen_h() > y_px \
1132 assert( 0 < g_retroflat_state->viewport.screen_tile_w ); \
1133 assert( 0 <= (((y_px) + RETROFLAT_TILE_H) >> RETROFLAT_TILE_H_BITS) ); \
1134 assert( 0 <= (((x_px) + RETROFLAT_TILE_W) >> RETROFLAT_TILE_W_BITS) ); \
1135 g_retroflat_state->viewport.refresh_grid[ \
1137 (_retroflat_viewport_refresh_tile_y( y_px ) * \
1138 g_retroflat_state->viewport.screen_tile_w) + \
1139 _retroflat_viewport_refresh_tile_x( x_px )] = tid; \
1142# define retroflat_viewport_tile_is_stale( x_px, y_px, tile_id ) \
1144 g_retroflat_state->viewport.refresh_grid[ \
1145 (_retroflat_viewport_refresh_tile_y( y_px ) * \
1146 g_retroflat_state->viewport.screen_tile_w) + \
1147 _retroflat_viewport_refresh_tile_x( x_px )])
1149uint8_t retroflat_viewport_move_x_generic( int16_t x );
1151uint8_t retroflat_viewport_move_y_generic( int16_t y );
1153uint8_t retroflat_viewport_focus_generic(
1154 size_t x1,
size_t y1,
size_t range,
size_t speed );
1156# define retroflat_viewport_screen_x_generic( world_x ) \
1157 ((world_x) - retroflat_viewport_world_x())
1159# define retroflat_viewport_screen_y_generic( world_y ) \
1160 ((world_y) - retroflat_viewport_world_y())
1164#if defined( RETROFLAT_SOFT_VIEWPORT ) || defined( DOCUMENTATION )
1166# ifdef RETROFLAT_VIEWPORT_ADAPT
1170# define retroflat_viewport_world_x() \
1171 ((retroflat_viewport_world_x_generic() \
1172 >> RETROFLAT_TILE_W_BITS) << RETROFLAT_TILE_W_BITS)
1173# define retroflat_viewport_world_y() \
1174 ((retroflat_viewport_world_y_generic() \
1175 >> RETROFLAT_TILE_H_BITS) << RETROFLAT_TILE_H_BITS)
1178# define retroflat_viewport_world_x() retroflat_viewport_world_x_generic()
1181# define retroflat_viewport_world_y() retroflat_viewport_world_y_generic()
1185# define retroflat_viewport_world_w() \
1186 retroflat_viewport_world_w_generic()
1189# define retroflat_viewport_world_h() \
1190 retroflat_viewport_world_h_generic()
1192# define retroflat_viewport_screen_tile_w() \
1193 retroflat_viewport_screen_tile_w_generic()
1195# define retroflat_viewport_screen_tile_h() \
1196 retroflat_viewport_screen_tile_h_generic()
1204# define retroflat_viewport_set_world( w, h ) \
1205 retroflat_viewport_set_world_generic( w, h )
1207# define retroflat_viewport_set_world_pos( x, y ) \
1208 retroflat_viewport_set_world_pos_generic( x, y )
1210# define retroflat_viewport_lock_refresh() \
1211 retroflat_viewport_lock_refresh_generic()
1213# define retroflat_viewport_unlock_refresh() \
1214 retroflat_viewport_unlock_refresh_generic()
1216# define retroflat_viewport_set_refresh( x, y, tid ) \
1217 retroflat_viewport_set_refresh_generic( x, y, tid )
1231# define retroflat_viewport_focus( x1, y1, range, speed ) \
1232 retroflat_viewport_focus_generic( x1, y1, range, speed )
1238# define retroflat_viewport_screen_x( world_x ) \
1239 retroflat_viewport_screen_x_generic( world_x )
1245# define retroflat_viewport_screen_y( world_y ) \
1246 retroflat_viewport_screen_y_generic( world_y )
1248# ifndef RETROFLAT_VIEWPORT_OVERRIDE_MOVE
1249# define retroflat_viewport_move_x( x ) \
1250 retroflat_viewport_move_x_generic( x )
1252# define retroflat_viewport_move_y( y ) \
1253 retroflat_viewport_move_y_generic( y )
1266 char config_path[RETROFLAT_PATH_MAX + 1];
1274# if defined( RETROFLAT_VDP ) || defined( DOCUMENTATION ) || \
1275defined( RETROVDP_C )
1281# ifdef RETROFLAT_OS_WIN
1332 retroflat_proc_resize_t on_resize;
1333 void* on_resize_data;
1335# if defined( RETROFLAT_OPENGL )
1336 uint8_t tex_palette[RETROFLAT_COLORS_SZ][3];
1339 struct RETROFLAT_PLATFORM platform;
1342 struct RETROFLAT_SOUND sound;
1350# ifdef retroflat_loop
1370 uint8_t flags,
const char* title,
const char* format, ... );
1389# if defined( RETROFLAT_VDP ) || defined( DOCUMENTATION )
1403void retroflat_set_title(
const char* format, ... );
1405retroflat_ms_t retroflat_get_ms();
1407uint32_t retroflat_get_rand();
1409# if !defined( RETROFLAT_NO_KEYBOARD )
1410char retroflat_vk_to_ascii( RETROFLAT_IN_KEY k, uint8_t flags );
1456 size_t s_x,
size_t s_y, int16_t d_x, int16_t d_y,
size_t w,
size_t h,
1466#define retroflat_constrain_px( x, y, bmp, retact ) \
1468 x >= retroflat_bitmap_w( bmp ) || y >= retroflat_bitmap_h( bmp ) \
1493 size_t x,
size_t y, uint8_t flags );
1495#ifdef RETROFLAT_SOFT_SHAPES
1496# ifdef RETROFLAT_OPENGL
1500# define retroflat_rect( t, c, x, y, w, h, f ) \
1501 assert( NULL != t ); \
1502 retrosoft_rect( t, c, x, y, w, h, f );
1503# define retroflat_ellipse( t, c, x, y, w, h, f ) \
1504 assert( NULL != t ); \
1505 retrosoft_ellipse( t, c, x, y, w, h, f )
1507# define retroflat_rect( t, c, x, y, w, h, f ) \
1508 retrosoft_rect( t, c, x, y, w, h, f )
1509# define retroflat_ellipse( t, c, x, y, w, h, f ) \
1510 retrosoft_ellipse( t, c, x, y, w, h, f )
1526 int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags );
1540 int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags );
1544#ifdef RETROFLAT_SOFT_LINES
1545# define retroflat_line( t, c, x1, y1, x2, y2, f ) \
1546 retrosoft_line( t, c, x1, y1, x2, y2, f )
1562 int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t flags );
1582 const char* font_str,
size_t* w_out,
size_t* h_out, uint8_t flags );
1603 const char* str,
int str_sz,
const char* font_str, int16_t x_orig, int16_t y_orig,
1607void retroflat_get_palette( uint8_t idx, uint32_t* rgb );
1609MERROR_RETVAL retroflat_set_palette( uint8_t idx, uint32_t rgb );
1623 retroflat_proc_resize_t on_resize_in,
void* data_in );
1647MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8] =
1648 { 0, 1, 1, 1, 0, -1, -1, -1 };
1649MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y[8] =
1650 { -1, -1, 0, 1, 1, 1, 0, -1 };
1652MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x[4] =
1654MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y[4] =
1657MAUG_MHANDLE g_retroflat_state_h = (MAUG_MHANDLE)NULL;
1660# define RETROFLAT_COLOR_TABLE_CONSTS( idx, name_l, name_u, r, g, b, cgac, cgad ) \
1661 MAUG_CONST RETROFLAT_COLOR RETROFLAT_COLOR_ ## name_u = idx;
1665# define RETROFLAT_COLOR_TABLE_NAMES( idx, name_l, name_u, r, g, b, cgac, cgad ) \
1668MAUG_CONST
char* SEG_MCONST gc_retroflat_color_names[] = {
1677 const char* filename_in,
1678 char* buffer_out,
size_t buffer_out_sz, uint8_t flags
1682 assert( 1 < buffer_out_sz );
1685 memset( buffer_out,
'\0', buffer_out_sz );
1691 maug_snprintf( buffer_out, buffer_out_sz - 1,
"%s", filename_in );
1694 maug_snprintf( buffer_out, buffer_out_sz - 1,
"%s%c%s.%s",
1704# if (defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES )) \
1705 && !defined( MAUG_NO_AUTO_C )
1709# include <retrosft.h>
1712# if defined( RETROFLAT_OPENGL ) && !defined( MAUG_NO_AUTO_C )
1718# include <retrosft.h>
1721# if defined( RETROFLAT_VDP ) && defined( RETROFLAT_OS_UNIX )
1729#ifndef RETROFLAT_NO_GENERIC_LOOP
1735 retroflat_ms_t next = 0,
1739 g_retroflat_state->loop_data = (
void*)data;
1749 debug_printf( 1,
"main loop already running!" );
1760 NULL != g_retroflat_state->loop_iter
1763 g_retroflat_state->loop_iter( g_retroflat_state->loop_data );
1768 retroflat_get_ms() < next
1773 if( NULL != g_retroflat_state->frame_iter ) {
1775 g_retroflat_state->frame_iter( g_retroflat_state->loop_data );
1779 now = retroflat_get_ms();
1780 if( now + retroflat_fps_next() > now ) {
1781 next = now + retroflat_fps_next();
1791 retval = g_retroflat_state->retval;
1803# if !defined( RETROFLAT_NO_KEYBOARD )
1805char retroflat_vk_to_ascii( RETROFLAT_IN_KEY k, uint8_t flags ) {
1807 char offset_lower = 0;
1809 if( RETROFLAT_INPUT_MOD_SHIFT != (RETROFLAT_INPUT_MOD_SHIFT & flags) ) {
1812 if( RETROFLAT_KEY_A <= k && RETROFLAT_KEY_Z >= k ) {
1814 RETROFLAT_INPUT_FORCE_UPPER !=
1815 (RETROFLAT_INPUT_FORCE_UPPER & flags)
1818 offset_lower = 0x20;
1826 case RETROFLAT_KEY_A: c = 0x41 + offset_lower;
break;
1827 case RETROFLAT_KEY_B: c = 0x42 + offset_lower;
break;
1828 case RETROFLAT_KEY_C: c = 0x43 + offset_lower;
break;
1829 case RETROFLAT_KEY_D: c = 0x44 + offset_lower;
break;
1830 case RETROFLAT_KEY_E: c = 0x45 + offset_lower;
break;
1831 case RETROFLAT_KEY_F: c = 0x46 + offset_lower;
break;
1832 case RETROFLAT_KEY_G: c = 0x47 + offset_lower;
break;
1833 case RETROFLAT_KEY_H: c = 0x48 + offset_lower;
break;
1834 case RETROFLAT_KEY_I: c = 0x49 + offset_lower;
break;
1835 case RETROFLAT_KEY_J: c = 0x4a + offset_lower;
break;
1836 case RETROFLAT_KEY_K: c = 0x4b + offset_lower;
break;
1837 case RETROFLAT_KEY_L: c = 0x4c + offset_lower;
break;
1838 case RETROFLAT_KEY_M: c = 0x4d + offset_lower;
break;
1839 case RETROFLAT_KEY_N: c = 0x4e + offset_lower;
break;
1840 case RETROFLAT_KEY_O: c = 0x4f + offset_lower;
break;
1841 case RETROFLAT_KEY_P: c = 0x50 + offset_lower;
break;
1842 case RETROFLAT_KEY_Q: c = 0x51 + offset_lower;
break;
1843 case RETROFLAT_KEY_R: c = 0x52 + offset_lower;
break;
1844 case RETROFLAT_KEY_S: c = 0x53 + offset_lower;
break;
1845 case RETROFLAT_KEY_T: c = 0x54 + offset_lower;
break;
1846 case RETROFLAT_KEY_U: c = 0x55 + offset_lower;
break;
1847 case RETROFLAT_KEY_V: c = 0x56 + offset_lower;
break;
1848 case RETROFLAT_KEY_W: c = 0x57 + offset_lower;
break;
1849 case RETROFLAT_KEY_X: c = 0x58 + offset_lower;
break;
1850 case RETROFLAT_KEY_Y: c = 0x59 + offset_lower;
break;
1851 case RETROFLAT_KEY_Z: c = 0x60 + offset_lower;
break;
1852 case RETROFLAT_KEY_0: c = offset_lower ? 0x30 :
')';
break;
1853 case RETROFLAT_KEY_1: c = offset_lower ? 0x31 :
'!';
break;
1854 case RETROFLAT_KEY_2: c = offset_lower ? 0x32 :
'@';
break;
1855 case RETROFLAT_KEY_3: c = offset_lower ? 0x33 :
'#';
break;
1856 case RETROFLAT_KEY_4: c = offset_lower ? 0x34 :
'$';
break;
1857 case RETROFLAT_KEY_5: c = offset_lower ? 0x35 :
'%';
break;
1858 case RETROFLAT_KEY_6: c = offset_lower ? 0x36 :
'^';
break;
1859 case RETROFLAT_KEY_7: c = offset_lower ? 0x37 :
'&';
break;
1860 case RETROFLAT_KEY_8: c = offset_lower ? 0x38 :
'*';
break;
1861 case RETROFLAT_KEY_9: c = offset_lower ? 0x39 :
'(';
break;
1862 case RETROFLAT_KEY_SPACE: c =
' ';
break;
1863 case RETROFLAT_KEY_BKSP: c = 0x08;
break;
1864 case RETROFLAT_KEY_ENTER: c =
'\n';
break;
1865 case RETROFLAT_KEY_SEMICOLON: c = offset_lower ?
';' :
':';
break;
1866 case RETROFLAT_KEY_DASH: c = offset_lower ?
'-' :
'_';
break;
1867 case RETROFLAT_KEY_SLASH: c = offset_lower ?
'/' :
'?';
break;
1868 case RETROFLAT_KEY_PERIOD: c = offset_lower ?
'.' :
'>';
break;
1869 case RETROFLAT_KEY_COMMA: c = offset_lower ?
',' :
'<';
break;
1870 case RETROFLAT_KEY_QUOTE: c = offset_lower ?
'\'' :
'"';
break;
1871 case RETROFLAT_KEY_EQUALS: c = offset_lower ?
'=' :
'+';
break;
1872 case RETROFLAT_KEY_BACKSLASH: c = offset_lower ?
'\\' :
'|';
break;
1873 case RETROFLAT_KEY_BRACKETL: c = offset_lower ?
'[' :
'{';
break;
1874 case RETROFLAT_KEY_BRACKETR: c = offset_lower ?
']' :
'}';
break;
1875#ifndef RETROFLAT_API_PC_BIOS
1877 case RETROFLAT_KEY_GRAVE: c = offset_lower ?
'`' :
'~';
break;
1881 debug_printf( RETROFLAT_KB_TRACE_LVL,
"0x%02x", c );
1895# ifndef RETROFLAT_NO_CLI
1897# ifdef RETROSND_ARGS
1906 args->snd_flags |= RETROSND_ARGS_FLAG_LIST_DEVS;
1915# if defined( RETROSND_API_PC_BIOS ) || defined( RETROSND_API_ALSA )
1916 char* env_var = NULL;
1918# elif defined( RETROSND_API_ALSA )
1919 char* env_var = NULL;
1920# elif defined( RETROSND_API_WINMM )
1921 char* env_var = NULL;
1925# ifdef RETROSND_API_PC_BIOS
1926 if( NULL != env_var ) {
1927 env_var = getenv(
"MAUG_MIDI_DOS" );
1932 maug_cleanup_if_null_msg(
1933 char*, env_var, MERROR_OK,
"MAUG_MIDI_DOS variable not found!" );
1935 debug_printf( 2,
"env: MAUG_MIDI_DOS: %s", env_var );
1938 for( i = 0 ; maug_strlen( env_var ) > i ; i++ ) {
1939 if(
',' == env_var[i] ) {
1945 if( 0 == strcmp( env_var,
"mpu" ) ) {
1946 debug_printf( 3,
"selecting MIDI driver: mpu" );
1947 args->snd_driver = 2;
1948 }
else if( 0 == strcmp( env_var,
"gus" ) ) {
1949 debug_printf( 3,
"selecting MIDI driver: gus" );
1950 args->snd_driver = 4;
1951 }
else if( 0 == strcmp( env_var,
"adlib" ) ) {
1952 debug_printf( 3,
"selecting MIDI driver: adlib" );
1953 args->snd_driver = 8;
1956 args->snd_io_base = strtoul( &(env_var[i]), NULL, 16 );
1957 debug_printf( 3,
"setting MIDI I/O base: %u", args->snd_io_base );
1960 debug_printf( 3,
"default MIDI driver: adlib" );
1961 args->snd_driver = 8;
1962 args->snd_io_base = 0x388;
1965# elif defined( RETROSND_API_ALSA )
1966 if( 0 == args->snd_client ) {
1967 env_var = getenv(
"MAUG_MIDI_ALSA" );
1972 maug_cleanup_if_null_msg(
1973 char*, env_var, MERROR_OK,
"MAUG_MIDI_ALSA variable not found!" );
1975 debug_printf( 2,
"env: MAUG_MIDI_ALSA: %s", env_var );
1977 for( i = 0 ; maug_strlen( env_var ) > i ; i++ ) {
1978 if(
':' == env_var[i] ) {
1984 args->snd_client = atoi( env_var );
1985 args->snd_port = atoi( &(env_var[i]) );
1986 debug_printf( 3,
"setting MIDI device to: %u:%u",
1987 args->snd_client, args->snd_port );
1990# elif defined( RETROSND_API_WINMM )
1991 env_var = getenv(
"MAUG_MIDI_WIN" );
1996 maug_cleanup_if_null_msg(
1997 char*, env_var, MERROR_OK,
"MAUG_MIDI_WIN variable not found!" );
1999 debug_printf( 2,
"env: MAUG_MIDI_WIN: %s", env_var );
2001 if( NULL != env_var ) {
2002 args->snd_dev_id = atoi( env_var );
2004 args->snd_dev_id = 0;
2006 debug_printf( 3,
"setting MIDI device to: %u", args->snd_dev_id );
2014# ifdef RETROSND_API_PC_BIOS
2016# elif defined( RETROSND_API_ALSA )
2018# elif defined( RETROSND_API_WINMM )
2019 debug_printf( 3,
"setting MIDI device to rsd arg: %s", arg );
2020 args->snd_dev_id = atoi( arg );
2024# if defined( RETROSND_API_PC_BIOS ) || defined( RETROSND_API_ALSA )
2026# elif defined( RETROSND_API_ALSA )
2028# elif defined( RETROSND_API_WINMM )
2037# if !defined( RETROFLAT_API_PC_BIOS ) && !defined( RETROFLAT_NO_CLI_SZ )
2043 if( 0 == args->screen_w ) {
2077 if( 0 == args->screen_w ) {
2078 args->screen_w = RETROFLAT_DEFAULT_SCREEN_W;
2085 args->screen_w = atoi( arg );
2095 args->
screen_h = RETROFLAT_DEFAULT_SCREEN_H;
2109# ifdef RETROFLAT_VDP
2113 if( 0 == strncmp(
MAUG_CLI_SIGIL "vdp", arg, MAUG_CLI_SIGIL_SZ + 4 ) ) {
2117 debug_printf( 1,
"VDP args: %s", g_retroflat_state->
vdp_args );
2127 args->flags &= ~RETROFLAT_FLAGS_UNLOCK_FPS;
2131 debug_printf( 1,
"unlocking FPS..." );
2151# ifdef RETROFLAT_COMMIT_HASH
2152 debug_printf( 1,
"retroflat commit: " RETROFLAT_COMMIT_HASH );
2155 debug_printf( 1,
"retroflat: initializing..." );
2158 assert( 4 ==
sizeof( uint32_t ) );
2159 assert( 4 ==
sizeof( int32_t ) );
2160 assert( 2 ==
sizeof( uint16_t ) );
2161 assert( 2 ==
sizeof( int16_t ) );
2162 assert( 1 ==
sizeof( uint8_t ) );
2163 assert( 1 ==
sizeof( int8_t ) );
2164 assert( NULL != args );
2165 assert( 1 << RETROFLAT_TILE_W_BITS == RETROFLAT_TILE_W );
2166 assert( 1 << RETROFLAT_TILE_H_BITS == RETROFLAT_TILE_H );
2168 debug_printf( 1,
"retroflat: allocating state (" SIZE_T_FMT
" bytes)...",
2171 debug_printf( 1,
"retroflat: size_t is (" SIZE_T_FMT
" bytes)...",
2174 debug_printf( 1,
"retroflat: ssize_t is (" SIZE_T_FMT
" bytes)...",
2175 sizeof( ssize_t ) );
2177 debug_printf( 1,
"retroflat: off_t is (" SIZE_T_FMT
" bytes)...",
2180 g_retroflat_state_h = maug_malloc( 1,
sizeof(
struct RETROFLAT_STATE ) );
2181 if( (MAUG_MHANDLE)NULL == g_retroflat_state_h ) {
2183 "Error",
"Could not allocate global state!" );
2184 retval = MERROR_ALLOC;
2188 maug_mlock( g_retroflat_state_h, g_retroflat_state );
2189 if( (MAUG_MHANDLE)NULL == g_retroflat_state ) {
2191 "Error",
"Could not lock global state!" );
2192 retval = MERROR_ALLOC;
2197# ifndef RETROFLAT_NO_CLI
2199 debug_printf( 1,
"retroflat: parsing args..." );
2203# ifdef RETROSND_ARGS
2205 "Select MIDI device", 0, (maug_cli_cb)retrosnd_cli_rsd, args );
2206 maug_cleanup_if_not_ok();
2208 "List MIDI devices", 0, (maug_cli_cb)retrosnd_cli_rsl, args );
2209 maug_cleanup_if_not_ok();
2212# ifdef RETROFLAT_SCREENSAVER
2214 "Preview screensaver", 0, (maug_cli_cb)retroflat_cli_p, args );
2215 maug_cleanup_if_not_ok();
2217 "Launch screensaver", 0, (maug_cli_cb)retroflat_cli_s, args );
2218 maug_cleanup_if_not_ok();
2221# ifdef RETROFLAT_API_PC_BIOS
2223 "Set the screen mode.", 0,
2224 (maug_cli_cb)retroflat_cli_rfm, args );
2225 maug_cleanup_if_not_ok();
2226# elif !defined( RETROFLAT_NO_CLI_SZ )
2228 "Set the screen X position.", 0,
2229 (maug_cli_cb)retroflat_cli_rfx, args );
2230 maug_cleanup_if_not_ok();
2232 "Set the screen Y position.", 0,
2233 (maug_cli_cb)retroflat_cli_rfy, args );
2234 maug_cleanup_if_not_ok();
2236 "Set the screen width.", 0,
2237 (maug_cli_cb)retroflat_cli_rfw, args );
2238 maug_cleanup_if_not_ok();
2240 "Set the screen height.", 0,
2241 (maug_cli_cb)retroflat_cli_rfh, args );
2242 maug_cleanup_if_not_ok();
2245# ifdef RETROFLAT_VDP
2247 "Pass a string of args to the VDP.", 0,
2248 (maug_cli_cb)retroflat_cli_vdp, args );
2249 maug_cleanup_if_not_ok();
2254 (maug_cli_cb)retroflat_cli_u, args );
2255 maug_cleanup_if_not_ok();
2258 retval = maug_parse_args( argc, argv );
2259 maug_cleanup_if_not_ok();
2263 args->screen_w = RETROFLAT_DEFAULT_SCREEN_W;
2264 args->
screen_h = RETROFLAT_DEFAULT_SCREEN_H;
2274 debug_printf( 1,
"retroflat: setting config..." );
2279 maug_strncpy( g_retroflat_state->assets_path,
2283# if defined( RETROFLAT_SCREENSAVER )
2292# if !defined( RETROFLAT_NO_CLI_SZ )
2295 g_retroflat_state->
screen_v_w = args->screen_w;
2300 debug_printf( 1,
"setting window scale to 2x..." );
2301 g_retroflat_state->
screen_w = args->screen_w * 2;
2304 g_retroflat_state->
screen_w = args->screen_w;
2309# ifdef RETROFLAT_OPENGL
2310 debug_printf( 1,
"setting up texture palette..." );
2311# define RETROFLAT_COLOR_TABLE_TEX( idx, name_l, name_u, r, g, b, cgac, cgad ) \
2312 g_retroflat_state->tex_palette[idx][0] = r; \
2313 g_retroflat_state->tex_palette[idx][1] = g; \
2314 g_retroflat_state->tex_palette[idx][2] = b;
2320 retval = retroflat_init_platform( argc, argv, args );
2321 maug_cleanup_if_not_ok();
2334 g_retroflat_state->viewport.screen_tile_w =
2337 g_retroflat_state->viewport.screen_tile_h =
2340 debug_printf( 1,
"allocating refresh grid (%d tiles...)",
2341 g_retroflat_state->viewport.screen_tile_w *
2342 g_retroflat_state->viewport.screen_tile_h );
2343 g_retroflat_state->viewport.refresh_grid_h = maug_malloc(
2344 g_retroflat_state->viewport.screen_tile_w *
2345 g_retroflat_state->viewport.screen_tile_h,
2346 sizeof( retroflat_tile_t ) );
2347 maug_cleanup_if_null_alloc( MAUG_MHANDLE,
2348 g_retroflat_state->viewport.refresh_grid_h );
2351# if defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES )
2352 retval = retrosoft_init();
2353 maug_cleanup_if_not_ok();
2356# if defined( RETROFLAT_OPENGL )
2357 retval = retrosoft_init();
2358 maug_cleanup_if_not_ok();
2359# ifndef RETROFLAT_NO_STRING
2360 retval = retroglu_init_glyph_tex();
2361 maug_cleanup_if_not_ok();
2365# ifdef RETROFLAT_VDP
2366# if defined( RETROFLAT_OS_UNIX )
2367 g_retroflat_state->
vdp_exe = dlopen(
2368 "./" RETROFLAT_VDP_LIB_NAME
".so", RTLD_LAZY );
2369# elif defined( RETROFLAT_OS_WIN )
2370 g_retroflat_state->
vdp_exe = LoadLibrary(
2371 "./" RETROFLAT_VDP_LIB_NAME
".dll" );
2373# error "dlopen undefined!"
2376 if( !(g_retroflat_state->
vdp_exe) ) {
2377 error_printf(
"not loading VDP" );
2383 debug_printf( 1,
"creating VDP buffer, " SIZE_T_FMT
" x " SIZE_T_FMT,
2387 maug_cleanup_if_null_alloc(
2389 retval = retroflat_create_bitmap(
2392 maug_cleanup_if_not_ok();
2394 debug_printf( 1,
"initializing VDP..." );
2401# if !defined( RETROFLAT_NO_BLANK_INIT ) && !defined( RETROFLAT_OPENGL )
2404 NULL, RETROFLAT_COLOR_BLACK, 0, 0,
2407 retroflat_draw_release( NULL );
2419 debug_printf( 1,
"retroflat shutdown called..." );
2421 if( (MAUG_MHANDLE)NULL != g_retroflat_state->viewport.refresh_grid_h ) {
2422 maug_mfree( g_retroflat_state->viewport.refresh_grid_h );
2425# if defined( RETROFLAT_VDP )
2426 if( NULL != g_retroflat_state->
vdp_exe ) {
2428# ifdef RETROFLAT_OS_UNIX
2429 dlclose( g_retroflat_state->
vdp_exe );
2430# elif defined( RETROFLAT_OS_WIN )
2431 FreeLibrary( g_retroflat_state->
vdp_exe );
2433# error "dlclose undefined!"
2437 if( NULL != g_retroflat_state->
vdp_buffer ) {
2438 debug_printf( 1,
"destroying VPD buffer..." );
2444# if defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES ) || \
2445defined( RETROFLAT_OPENGL )
2446 debug_printf( 1,
"calling retrosoft shutdown..." );
2447 retrosoft_shutdown();
2450# if defined( RETROFLAT_OPENGL ) && !defined( RETROFLAT_NO_STRING )
2451 debug_printf( 1,
"destroying GL glyphs..." );
2452 retroglu_destroy_glyph_tex();
2457 retroflat_shutdown_platform( retval );
2459 maug_munlock( g_retroflat_state_h, g_retroflat_state );
2460 maug_mfree( g_retroflat_state );
2466# ifdef RETROFLAT_VDP
2471# ifdef RETROFLAT_OS_WIN
2472 char proc_name_ex[256];
2475 if( NULL == g_retroflat_state->
vdp_exe ) {
2479# ifdef RETROFLAT_OS_UNIX
2480 vdp_proc = dlsym( g_retroflat_state->
vdp_exe, proc_name );
2481# elif defined( RETROFLAT_OS_WIN )
2483 maug_snprintf( proc_name_ex, 255,
"%s_", proc_name );
2485 g_retroflat_state->
vdp_exe, proc_name_ex );
2487# error "dlsym undefined!"
2493# ifdef RETROFLAT_OS_WIN
2499 0 == strcmp(
"retroflat_vdp_flip", proc_name ) &&
2503 retroflat_vdp_lock( &(g_retroflat_state->
buffer) );
2504 retroflat_vdp_lock( g_retroflat_state->
vdp_buffer );
2507 retval = vdp_proc( g_retroflat_state );
2510 0 == strcmp(
"retroflat_vdp_flip", proc_name ) &&
2514 retroflat_vdp_release( &(g_retroflat_state->
buffer) );
2515 retroflat_vdp_release( g_retroflat_state->
vdp_buffer );
2518# ifdef RETROFLAT_OS_WIN
2519 retroflat_draw_release( g_retroflat_state->
vdp_buffer );
2534 char mouse_str[11] =
"";
2537 mouse_str, 10,
"%02d, %02d", g_retroflat_state->last_mouse_x, g_retroflat_state->last_mouse_y );
2540 target, RETROFLAT_COLOR_BLACK,
2541 mouse_str, 10, NULL, 0, 0, 0 );
2543 target, RETROFLAT_COLOR_BLACK,
2544 g_retroflat_state->last_mouse_x - 5, g_retroflat_state->last_mouse_y - 5, 10, 10, 0 );
2552#ifndef RETROFLAT_NO_STRING
2554# if defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
2556# define retroflat_win_create_font( flags, font_str ) \
2557 CreateFont( 10, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, \
2558 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, \
2559 DEFAULT_QUALITY, DEFAULT_PITCH, \
2560 (NULL == font_str || '\0' == font_str[0] ? "Arial" : font_str) );
2566 const char* font_str,
size_t* w_out,
size_t* h_out, uint8_t flags
2568# if defined( RETROFLAT_OPENGL )
2569# elif defined( RETROFLAT_SOFT_SHAPES )
2570# elif defined( RETROFLAT_API_ALLEGRO )
2571 FONT* font_data = NULL;
2572 int font_loaded = 0;
2573# elif defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
2579 if( NULL == target ) {
2583# if defined( RETROFLAT_OPENGL )
2585 retrosoft_string_sz( target, str, str_sz, font_str, w_out, h_out, flags );
2587# elif defined( RETROFLAT_SOFT_SHAPES )
2589 retrosoft_string_sz( target, str, str_sz, font_str, w_out, h_out, flags );
2591# elif defined( RETROFLAT_API_ALLEGRO )
2595 if( NULL == font_str ||
'\0' == font_str[0] ) {
2599 font_data = load_font( font_str, NULL, NULL );
2601 if( NULL == font_data ) {
2603 "Error",
"Unable to load font: %s", font_str );
2607 *w_out = text_length( font_data, str );
2608 *h_out = text_height( font_data );
2612 if( font_loaded && NULL != font_data ) {
2613 destroy_font( font_data );
2616# elif defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
2620 assert( (HBITMAP)NULL != target->b );
2621 assert( retroflat_bitmap_locked( target ) );
2623 font = retroflat_win_create_font( flags, font_str );
2624 old_font = SelectObject( target->hdc_b, font );
2626 GetTextExtentPoint( target->hdc_b, str, str_sz, &sz );
2632 SelectObject( target->hdc_b, old_font );
2635# pragma message( "warning: string sz not implemented" )
2643 const char* str,
int str_sz,
const char* font_str, int16_t x_orig, int16_t y_orig,
2646# if defined( RETROFLAT_OPENGL )
2647 float aspect_ratio = 0,
2650# elif defined( RETROFLAT_SOFT_SHAPES )
2651# elif defined( RETROFLAT_API_ALLEGRO )
2652 FONT* font_data = NULL;
2653 int font_loaded = 0;
2654# elif defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
2661 if( RETROFLAT_COLOR_NULL == color ) {
2665# if !defined( RETROFLAT_OPENGL )
2666 if( NULL == target ) {
2672 str_sz = maug_strlen( str );
2675# if defined( RETROFLAT_OPENGL )
2682 screen_x, screen_y, 0,
2683 g_retroflat_state->
palette[color], str, str_sz, font_str, flags );
2690 target, color, str, str_sz, font_str, x_orig, y_orig, flags );
2693# elif defined( RETROFLAT_SOFT_SHAPES )
2696 target, color, str, str_sz, font_str, x_orig, y_orig, flags );
2698# elif defined( RETROFLAT_API_ALLEGRO )
2702 if( NULL == font_str ||
'\0' == font_str[0] ) {
2706 font_data = load_font( font_str, NULL, NULL );
2708 if( NULL == font_data ) {
2710 "Error",
"Unable to load font: %s", font_str );
2714 textout_ex( target->b, font_data, str, x_orig, y_orig, color, -1 );
2717 if( font_loaded && NULL != font_data ) {
2718 destroy_font( font_data );
2721# elif defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
2725 assert( (HBITMAP)NULL != target->b );
2727 assert( retroflat_bitmap_locked( target ) );
2730 str_sz = maug_strlen( str );
2732 memset( &sz,
'\0',
sizeof( SIZE ) );
2734 font = retroflat_win_create_font( flags, font_str );
2735 old_font = SelectObject( target->hdc_b, font );
2737 GetTextExtentPoint( target->hdc_b, str, str_sz, &sz );
2740 rect.right = (x_orig + sz.cx);
2741 rect.bottom = (y_orig + sz.cy);
2743 SetTextColor( target->hdc_b, g_retroflat_state->
palette[color] );
2744 SetBkMode( target->hdc_b, TRANSPARENT );
2746 DrawText( target->hdc_b, str, str_sz, &rect, 0 );
2750 SelectObject( target->hdc_b, old_font );
2752 SetBkMode( target->hdc_b, OPAQUE );
2753 SetTextColor( target->hdc_b,
2754 g_retroflat_state->
palette[RETROFLAT_COLOR_BLACK] );
2757# pragma message( "warning: string not implemented" )
2766 retroflat_proc_resize_t on_resize_in,
void* data_in
2768 g_retroflat_state->on_resize = on_resize_in;
2769 g_retroflat_state->on_resize_data = data_in;
2774uint8_t retroflat_viewport_move_x_generic( int16_t x ) {
2775 int16_t new_world_x = g_retroflat_state->viewport.world_x + x;
2777 g_retroflat_state->viewport.
screen_x += x;
2784 g_retroflat_state->viewport.world_x += x;
2793uint8_t retroflat_viewport_move_y_generic( int16_t y ) {
2794 int16_t new_world_y = g_retroflat_state->viewport.world_y + y;
2796 g_retroflat_state->viewport.
screen_y += y;
2803 g_retroflat_state->viewport.world_y += y;
2812uint8_t retroflat_viewport_focus_generic(
2813 size_t x1,
size_t y1,
size_t range,
size_t speed
2819# define _retroflat_viewport_focus_dir( n, xy, wh, gl, pm, dir, range, speed ) \
2820 new_pt = n - retroflat_viewport_world_ ## xy(); \
2821 if( new_pt gl (retroflat_screen_ ## wh() >> 1) pm range ) { \
2822 new_moved = retroflat_viewport_move_ ## xy( \
2823 gc_retroflat_offsets8_ ## xy[RETROFLAT_DIR8_ ## dir] * speed ); \
2824 if( !moved && new_moved ) { \
2825 moved = new_moved; \
2829 _retroflat_viewport_focus_dir( x1, x, w, <, -, WEST, range, speed );
2830 _retroflat_viewport_focus_dir( x1, x, w, >, +, EAST, range, speed );
2831 _retroflat_viewport_focus_dir( y1, y, h, <, -, NORTH, range, speed );
2832 _retroflat_viewport_focus_dir( y1, y, h, >, +, SOUTH, range, speed );
2839#elif !defined( RETROVDP_C )
2846extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8];
2847extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y[8];
2848extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x[4];
2849extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y[4];
2853#define RETROFLAT_COLOR_TABLE_CONSTS( idx, name_l, name_u, r, g, b, cgac, cgad ) \
2854 extern MAUG_CONST RETROFLAT_COLOR RETROFLAT_COLOR_ ## name_u;
2858extern MAUG_CONST
char* SEG_MCONST gc_retroflat_color_names[];
2861# if defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
2862 extern HINSTANCE g_retroflat_instance;
2863 extern int g_retroflat_cmd_show;
2868# if (defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES)) \
2869 && !defined( MAUG_NO_AUTO_C )
2871# include <retrosft.h>
2874# if defined( RETROFLAT_OPENGL ) && !defined( MAUG_NO_AUTO_C )
2877# include <retrosft.h>
2883#include <retroxpm.h>
MERROR_RETVAL maug_add_arg(const char *arg, int arg_sz, const char *help, int help_sz, maug_cli_cb arg_cb, void *data)
Add a command-line argument to the built-in parser.
#define MAUG_CLI_SIGIL
Default flag to prepend to CLI arguments. Is "/" on Windows/DOS and "-" on other platforms....
Definition marge.h:39
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19
#define maug_mzero(ptr, sz)
Zero the block of memory pointed to by ptr.
Definition mmem.h:62
char retroflat_asset_path[RETROFLAT_PATH_MAX]
Path/name used to load an asset from disk.
Definition retroflt.h:774
#define RETROFLAT_BITMAP_EXT
The filename suffix to be appended with a "." to filenames passed to retroflat_load_bitmap()....
Definition retroflt.h:577
MERROR_RETVAL retroflat_blit_bitmap(struct RETROFLAT_BITMAP *target, struct RETROFLAT_BITMAP *src, size_t s_x, size_t s_y, int16_t d_x, int16_t d_y, size_t w, size_t h, int16_t instance)
Blit the contents of a RETROFLAT_BITMAP onto another RETROFLAT_BITMAP.
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 th...
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 th...
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:307
#define RETROFLAT_COLOR_TABLE(f)
This macro defines all colors supported by RetroFlat for primative operations, particularly using ret...
Definition retroflt.h:288
#define RETROFLAT_VDP_ARGS_SZ_MAX
Definition retroflt.h:724
#define RETROFLAT_ASSETS_PATH_MAX
Maximum size of the assets path, to allow room for appending.
Definition retroflt.h:749
#define RETROFLAT_PATH_SEP
The valid path separator on the target platform.
Definition retroflt.h:745
#define RETROFLAT_FLAGS_LITERAL_PATH
Flag for retroflat_load_bitmap() to not use assets path.
Definition retroflt.h:374
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.
#define RETROFLAT_FLAGS_OPAQUE
Flag for retroflat_create_bitmap() to create a bitmap without transparency.
Definition retroflt.h:361
#define RETROFLAT_FLAGS_VIEWPORT_REFRESH
Flag for args->flags, indicating that a viewport tile refresh grid should be allocated and used.
Definition retroflt.h:398
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,...
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_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.
#define RETROFLAT_FLAGS_FILL
Flag for retroflat_rect() or retroflat_ellipse(), indicating drawn shape should be filled.
Definition retroflt.h:355
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_...
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.
#define RETROFLAT_FLAGS_SCREENSAVER
Flag indicating the current application is running as a screensaver.
Definition retroflt.h:431
#define RETROFLAT_FLAGS_UNLOCK_FPS
Flag indicating FPS should not be capped.
Definition retroflt.h:419
#define RETROFLAT_FLAGS_SCALE2X
Only supported on some platforms: Attempt to scale screen by 2X.
Definition retroflt.h:436
#define RETROFLAT_FLAGS_RUNNING
Flag indicating that retroflat_loop() should continue executing.
Definition retroflt.h:413
#define RETROFLAT_FLAGS_WAIT_FOR_FPS
Do not execute any more inter-frame loops until next frame.
Definition retroflt.h:441
#define RETROFLAT_MSG_FLAG_ERROR
This icon/type flag indicates an error. It will try to display messages in an urgent way with a red i...
Definition retroflt.h:459
MERROR_RETVAL retroflat_vdp_call(const char *proc_name)
Call a function from the retroflat VDP.
MERROR_RETVAL(* retroflat_vdp_proc_t)(struct RETROFLAT_STATE *)
VDP function called from the VDP library.
Definition retroflt.h:511
#define RETROFLAT_VDP_FLAG_PXLOCK
Flag for RETROFLAT_STATE::vdp_flags indicating the VDP requires RetroFlat to pixel-lock the frame bef...
Definition retroflt.h:498
void retroflat_shutdown(int retval)
Deinitialize RetroFlat and its underlying layers. This should be called once at the end of the progra...
void(* retroflat_loop_iter)(void *data)
Prototype for the main loop function passed to retroflat_loop().
Definition retroflt.h:786
void retroflat_resize_v()
Platform-specific function to resize virtual screen to match physical window size.
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....
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 pr...
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).
#define retroglu_push_overlay(x, y, x_f, y_f, aspect_f)
Push current projection modelview and prepare useful parameters for drawing a textured overlay.
Definition retroglu.h:241
#define retroglu_pop_overlay()
Restore projection modelview previously pushed using retroglu_push().
Definition retroglu.h:274
void retrosnd_set_sf_bank(const char *filename_in)
Set the name of the voice bank filename to use.
MERROR_RETVAL retrosnd_init(struct RETROFLAT_ARGS *args)
Initialize retrosnd engine.
#define retroflat_screen_h()
Get the current screen height in pixels.
Definition retpltd.h:38
#define retroflat_screen_buffer()
Get the direct screen buffer or the VDP buffer if a VDP is loaded.
Definition retpltd.h:41
#define retroflat_screen_w()
Get the current screen width in pixels.
Definition retpltd.h:35
Contains functions and macros for working with fixed-point numbers.
Library of tools for working with RetroFlat and OpenGL.
Struct containing configuration values for a RetroFlat program.
Definition retroflt.h:1012
char * config_path
Relative path of local config file (if not using registry).
Definition retroflt.h:1022
char * assets_path
Relative path under which bitmap assets are stored.
Definition retroflt.h:1019
int screen_h
Desired screen or window height in pixels.
Definition retroflt.h:1029
char * title
Title to set for the main program Window if applicable on the target platform.
Definition retroflt.h:1017
int screen_y
Desired window Y position in pixels.
Definition retroflt.h:1033
int screen_x
Desired window X position in pixels.
Definition retroflt.h:1031
Platform-specific bitmap structure. retroflat_bitmap_ok() can be used on a pointer to it to determine...
Definition retpltd.h:21
Global singleton containing state for the current platform.
Definition retroflt.h:1261
char vdp_args[RETROFLAT_VDP_ARGS_SZ_MAX]
CLI args passed with -vdp to the RetroFlat VDP API.
Definition retroflt.h:1293
size_t screen_h
The screen height as seen by the system, after scaling.
Definition retroflt.h:1319
uint8_t vdp_flags
Flags set by the RetroFlat VDP API.
Definition retroflt.h:1295
size_t screen_v_w
The screen width as seen by our program, before scaling.
Definition retroflt.h:1308
uint8_t retroflat_flags
Global Flags indicating current system status.
Definition retroflt.h:1265
struct RETROFLAT_BITMAP * vdp_buffer
A buffer assembled and passed to the RetroFlat VDP API for it to modify, or NULL if no VDP is loaded.
Definition retroflt.h:1280
size_t screen_w
The screen width as seen by the system, after scaling.
Definition retroflt.h:1317
struct RETROFLAT_BITMAP buffer
Off-screen buffer bitmap.
Definition retroflt.h:1272
void * vdp_exe
A handle for the loaded RetroFlat VDP API module.
Definition retroflt.h:1285
RETROFLAT_COLOR_DEF palette[RETROFLAT_COLORS_SZ]
Index of available colors, initialized on platform init.
Definition retroflt.h:1270
void * vdp_data
Pointer to data defined by the RetroFlat VDP API for its use.
Definition retroflt.h:1291
size_t screen_v_h
The screen height as seen by our program, before scaling.
Definition retroflt.h:1315
Definition retroflt.h:1059
int16_t screen_x
X position of the viewport in real screen memory in pixels.
Definition retroflt.h:1061
int16_t screen_y
Y position of the viewport in real screen memory in pixels.
Definition retroflt.h:1063