maug
Quick and dirty C mini-augmentation library.
Loading...
Searching...
No Matches
retroflt.h
Go to the documentation of this file.
1
2#ifndef RETROFLT_H
3#define RETROFLT_H
4
9
10#ifdef RETROFLAT_OPENGL
11# define RETROFLAT_BMP_TEX
12#endif /* RETROFLAT_OPENGL */
13
19typedef int16_t retroflat_tile_t;
20
22
42
163
276
277/* === Generic Includes and Defines === */
278
279#ifndef RETROFLAT_BITMAP_TRACE_LVL
280# define RETROFLAT_BITMAP_TRACE_LVL 0
281#endif /* !RETROFLAT_BITMAP_TRACE_LVL */
282
283#ifndef RETROFLAT_KB_TRACE_LVL
284# define RETROFLAT_KB_TRACE_LVL 0
285#endif /* !RETROFLAT_KB_TRACE_LVL */
286
287#include <stdarg.h>
288
289#include <marge.h>
290
295
306#define RETROFLAT_COLOR_TABLE( f ) \
307 f( 0, black, BLACK, 0, 0, 0, BLACK, BLACK ) \
308 f( 1, darkblue, DARKBLUE, 0, 0, 170, CYAN, BLACK ) \
309 f( 2, darkgreen, DARKGREEN, 0, 170, 0, CYAN, BLACK ) \
310 f( 3, teal, TEAL, 0, 170, 170, CYAN, CYAN ) \
311 f( 4, darkred, DARKRED, 170, 0, 0, MAGENTA, BLACK ) \
312 f( 5, violet, VIOLET, 170, 0, 170, MAGENTA, BLACK ) \
313 f( 6, brown, BROWN, 170, 85, 0, CYAN, MAGENTA ) \
314 f( 7, gray, GRAY, 170, 170, 170, WHITE, BLACK ) \
315 f( 8, darkgray, DARKGRAY, 85, 85, 85, WHITE, BLACK ) \
316 f( 9, blue, BLUE, 85, 85, 255, CYAN, WHITE ) \
317 f( 10, green, GREEN, 85, 255, 85, CYAN, CYAN ) \
318 f( 11, cyan, CYAN, 85, 255, 255, CYAN, CYAN ) \
319 f( 12, red, RED, 255, 85, 85, MAGENTA, WHITE ) \
320 f( 13, magenta, MAGENTA, 255, 85, 255, MAGENTA, MAGENTA ) \
321 f( 14, yellow, YELLOW, 255, 255, 85, CYAN, MAGENTA ) \
322 f( 15, white, WHITE, 255, 255, 255, WHITE, WHITE )
323
325typedef int8_t RETROFLAT_COLOR;
326
327# define RETROFLAT_COLOR_NULL (-1)
328
329# define RETROFLAT_COLORS_SZ 16
330
332
333/* TODO: Mouse is broken under DOS/Allegro. */
334#if defined( RETROFLAT_OS_UNIX ) || defined( RETROFLAT_OS_WIN )
335#define RETROFLAT_MOUSE
336#endif /* RETROFLAT_OS_WIN || RETROFLAT_OS_WIN */
337
343
345#define RETROFLAT_OK 0x00
346#define RETROFLAT_ERROR_ENGINE 0x01
347#define RETROFLAT_ERROR_GRAPHICS 0x02
348#define RETROFLAT_ERROR_MOUSE 0x04
349
354#define RETROFLAT_ERROR_BITMAP 0x08
355#define RETROFLAT_ERROR_TIMER 0x0f
356 /* maug_retroflt_retval */
358
368
373#define RETROFLAT_FLAGS_FILL 0x01
374
379#define RETROFLAT_FLAGS_OPAQUE 0x01
380
387#define RETROFLAT_FLAGS_ALL_CAPS 0x02
388
392#define RETROFLAT_FLAGS_LITERAL_PATH 0x02
393
400#define RETROFLAT_FLAGS_SCREEN_BUFFER 0x80
401 /* maug_retroflt_drawing */
403
409
415#define RETROFLAT_FLAGS_RUNNING 0x01
416
421#define RETROFLAT_FLAGS_UNLOCK_FPS 0x02
422
427#define RETROFLAT_FLAGS_KEY_REPEAT 0x04
428
433#define RETROFLAT_FLAGS_SCREENSAVER 0x08
434
438#define RETROFLAT_FLAGS_WAIT_FOR_FPS 0x20
439 /* maug_retroflt_flags */
441
448
450#define RETROFLAT_MSG_FLAG_TYPE_MASK 0x07
451
456#define RETROFLAT_MSG_FLAG_ERROR 0x01
457
463#define RETROFLAT_MSG_FLAG_INFO 0x02
464
470#define RETROFLAT_MSG_FLAG_WARNING 0x04
471 /* maug_retroflt_msg_flags */
473
474struct RETROFLAT_STATE;
475
487
495#define RETROFLAT_VDP_FLAG_PXLOCK 0x01
496
509 /* maug_retroflt_vdp */
511
512typedef MERROR_RETVAL (*retroflat_proc_resize_t)(
513 uint16_t new_w, uint16_t new_h, void* data );
514
519
520#define RETROSND_ARGS_FLAG_LIST_DEVS 0x01
521
523
549
553#define RETROFLAT_FLAGS_LOCK 0x01
554
555#define RETROFLAT_FLAGS_SCREEN_LOCK 0x02
556
557#define RETROFLAT_FLAGS_BITMAP_RO 0x04
558
564#define RETROFLAT_INSTANCE_NULL (0)
565
570#define retroflat_instance_tile( instance ) \
571 (instance * -1)
572
577#ifndef RETROFLAT_BITMAP_EXT
578# define RETROFLAT_BITMAP_EXT "bmp"
579#endif /* !RETROFLAT_BITMAP_EXT */
580
581#ifndef RETROFLAT_OPENGL_BPP
582# define RETROFLAT_OPENGL_BPP 32
583#endif /* !RETROFLAT_OPENGL_BPP */
584
585#ifndef RETROFLAT_TILE_W
586# define RETROFLAT_TILE_W 16
587#endif /* !RETROFLAT_TILE_W */
588
589#ifndef RETROFLAT_TILE_W_BITS
590# define RETROFLAT_TILE_W_BITS 4
591#endif /* !RETROFLAT_TILE_W_BITS */
592
593#ifndef RETROFLAT_TILE_H
594# define RETROFLAT_TILE_H 16
595#endif /* !RETROFLAT_TILE_H */
596
597#ifndef RETROFLAT_TILE_H_BITS
598# define RETROFLAT_TILE_H_BITS 4
599#endif /* !RETROFLAT_TILE_H_BITS */
600
601/* Transparency background color: black by default, to match Allegro. */
602#ifndef RETROFLAT_TXP_R
608# define RETROFLAT_TXP_R 0x00
609#endif /* !RETROFLAT_TXP_R */
610
611#ifndef RETROFLAT_TXP_G
617# define RETROFLAT_TXP_G 0x00
618#endif /* !RETROFLAT_TXP_G */
619
620#ifndef RETROFLAT_TXP_B
626# define RETROFLAT_TXP_B 0x00
627#endif /* !RETROFLAT_TXP_B */
628
629#ifndef RETROFLAT_TXP_PAL_IDX
630# define RETROFLAT_TXP_PAL_IDX 0
631#endif /* !RETROFLAT_TXP_PAL_IDX */
632 /* maug_retroflt_bitmap */
634
635#ifndef RETROFLAT_DEFAULT_SCREEN_W
636# define RETROFLAT_DEFAULT_SCREEN_W 320
637#endif /* RETROFLAT_DEFAULT_SCREEN_W */
638
639#ifndef RETROFLAT_DEFAULT_SCREEN_H
640# define RETROFLAT_DEFAULT_SCREEN_H 200
641#endif /* RETROFLAT_DEFAULT_SCREEN_H */
642
643#define retroflat_on_resize( w, h ) \
644 g_retroflat_state->screen_w = w; \
645 g_retroflat_state->screen_h = h;
646
651
652#ifndef RETROFLAT_LINE_THICKNESS
657# define RETROFLAT_LINE_THICKNESS 1
658#endif /* !RETROFLAT_LINE_THICKNESS */
659
660#define RETROFLAT_PI 3.14159
661 /* maug_retroflt_drawing */
663
668
669#ifndef RETROFLAT_FPS
674# define RETROFLAT_FPS 30
675#endif /* !RETROFLAT_FPS */
676
677#define retroflat_fps_next() (1000 / RETROFLAT_FPS)
678
679#ifndef RETROFLAT_WINDOW_CLASS
684# define RETROFLAT_WINDOW_CLASS "RetroFlatWindowClass"
685#endif /* !RETROFLAT_WINDOW_CLASS */
686
687#ifndef RETROFLAT_WIN_FRAME_TIMER_ID
692# define RETROFLAT_WIN_FRAME_TIMER_ID 6001
693#endif /* !RETROFLAT_WIN_FRAME_TIMER_ID */
694
695#ifndef RETROFLAT_WIN_LOOP_TIMER_ID
700# define RETROFLAT_WIN_LOOP_TIMER_ID 6002
701#endif /* !RETROFLAT_WIN_LOOP_TIMER_ID */
702
703#ifndef RETROFLAT_MSG_MAX
708# define RETROFLAT_MSG_MAX 4096
709#endif /* !RETROFLAT_MSG_MAX */
710
711#define RETROFLAT_PATH_MAX MAUG_PATH_MAX
712
713#ifndef RETROFLAT_TITLE_MAX
714# define RETROFLAT_TITLE_MAX 255
715#endif /* !RETROFLAT_TITLE_MAX */
716
717#ifndef RETROFLAT_VDP_ARGS_SZ_MAX
721# define RETROFLAT_VDP_ARGS_SZ_MAX 255
722#endif /* !RETROFLAT_VDP_ARGS_SZ_MAX */
723
724#if defined( RETROFLAT_API_SDL2 )
725# if !defined( NO_RETROFLAT_RESIZABLE )
726# define RETROFLAT_WIN_FLAGS SDL_WINDOW_RESIZABLE
727# else
728# define RETROFLAT_WIN_FLAGS 0
729# endif /* !NO_RETROFLAT_RESIZABLE */
730#endif /* RETROFLAT_API_SDL2 */
731
732#if defined( RETROFLAT_API_SDL1 )
733# define RETROFLAT_SDL_CC_FLAGS (SDL_RLEACCEL | SDL_SRCCOLORKEY)
734#elif defined( RETROFLAT_API_SDL2 )
735# define RETROFLAT_SDL_CC_FLAGS (SDL_TRUE)
736#endif /* RETROFLAT_API_SDL1 || RETROFLAT_API_SDL2 */
737
738#ifdef RETROFLAT_OS_DOS
739# define RETROFLAT_PATH_SEP '\\'
740#else
742# define RETROFLAT_PATH_SEP '/'
743#endif /* RETROFLAT_OS_DOS */
744
746#define RETROFLAT_ASSETS_PATH_MAX (RETROFLAT_PATH_MAX >> 1)
747
748#ifndef RETROFLAT_BMP_COLORS_SZ_MAX
749# define RETROFLAT_BMP_COLORS_SZ_MAX 256
750#endif /* !RETROFLAT_BMP_COLORS_SZ_MAX */
751 /* maug_retroflt_compiling */
753
754#define retroflat_wait_for_frame() \
755 (g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_WAIT_FOR_FPS)
756
757#define retroflat_is_waiting_for_frame() \
758 (RETROFLAT_FLAGS_WAIT_FOR_FPS == \
759 (g_retroflat_state->retroflat_flags & RETROFLAT_FLAGS_WAIT_FOR_FPS))
760
767
771typedef char retroflat_asset_path[RETROFLAT_PATH_MAX];
772
776#define retroflat_cmp_asset_path( a, b ) strncmp( a, b, RETROFLAT_PATH_MAX )
777
778#define retroflat_assign_asset_path( tgt, src ) \
779 maug_strncpy( tgt, src, RETROFLAT_PATH_MAX )
780
781#define retroflat_assign_asset_trim_ext( tgt, src ) \
782 maug_snprintf( tgt, RETROFLAT_PATH_MAX, "%s", src ); \
783 if( NULL != strrchr( tgt, '.' ) ) { \
784 *(strrchr( tgt, '.' )) = '\0'; \
785 }
786 /* maug_retroflt_assets */
788
792typedef void (*retroflat_loop_iter)(void* data);
793
799
803#define retroflat_buffer_bksp( buffer, buffer_cur, buffer_sz ) \
804 if( 0 < buffer_cur ) { \
805 if( buffer_cur < buffer_sz ) { \
806 memmove( \
807 &(buffer[(buffer_cur) - 1]), \
808 &(buffer[buffer_cur]), \
809 (buffer_sz) - (buffer_cur) ); \
810 } \
811 buffer_cur--; \
812 buffer_sz--; \
813 buffer[buffer_sz] = '\0'; \
814 }
815
819#define retroflat_buffer_insert( c, buffer, buffer_cur, buffer_sz, buffer_mx ) \
820 if( buffer_sz + 1 < buffer_mx ) { \
821 if( buffer_cur < buffer_sz ) { \
822 memmove( \
823 &(buffer[(buffer_cur) + 1]), \
824 &(buffer[buffer_cur]), \
825 (buffer_sz) - (buffer_cur) ); \
826 } \
827 buffer[buffer_cur] = c; \
828 buffer_cur++; \
829 buffer_sz++; \
830 buffer[buffer_sz] = '\0'; \
831 }
832
833#define RETROFLAT_INPUT_MOD_SHIFT 0x01
834
835#define RETROFLAT_INPUT_MOD_ALT 0x02
836
837#define RETROFLAT_INPUT_MOD_CTRL 0x04
838
839#define RETROFLAT_INPUT_FORCE_UPPER 0x08
840
853 uint8_t key_flags;
854};
855 /* maug_retroflt_input */
857
864
865typedef int8_t retroflat_dir4_t;
866
867typedef int8_t retroflat_dir8_t;
868
869#define RETROFLAT_DIR4_NONE (-1)
870#define RETROFLAT_DIR4_NORTH 0
871#define RETROFLAT_DIR4_EAST 1
872#define RETROFLAT_DIR4_SOUTH 2
873#define RETROFLAT_DIR4_WEST 3
874
875#define RETROFLAT_DIR8_NONE (-1)
876#define RETROFLAT_DIR8_NORTH 0
877#define RETROFLAT_DIR8_EAST 2
878#define RETROFLAT_DIR8_SOUTH 4
879#define RETROFLAT_DIR8_WEST 6
880
881#define retroflat_dir8_reverse( dir ) \
882 ((dir + 4) % 8)
883
884#define retroflat_dir8_bounce( dir ) \
885 ((dir + 2) % 8)
886 /* maug_retroflt_dir */
888
889#if defined( RETROFLAT_BMP_TEX ) || defined( DOCUMENTATION )
890
892
893#define retroflat_bitmap_has_flags( bmp, f ) \
894 (NULL != (bmp) && (f) == ((f) & (bmp)->tex.flags))
895 /* maug_retroflt_bitmap */
897
902
904 uint8_t flags;
905 MAUG_MHANDLE bytes_h;
906 uint8_t* bytes;
907 uint32_t bpp;
908 uint32_t sz;
909 uint8_t* px;
910 uint32_t id;
911 size_t w;
912 size_t h;
913};
914 /* maug_retro3d_util */
916
931
935#define retroflat_2d_px( ... ) retro3d_texture_px( __VA_ARGS__ )
936
937#define retroflat_2d_line( ... ) retrosoft_line( __VA_ARGS__ )
938
939#define retroflat_2d_rect( ... ) retrosoft_rect( __VA_ARGS__ )
940
941#define retroflat_2d_bitmap_ok( ... ) retro3d_texture_ok( __VA_ARGS__ )
942
943#define retroflat_2d_bitmap_w( ... ) retro3d_texture_w( __VA_ARGS__ )
944
945#define retroflat_2d_bitmap_h( ... ) retro3d_texture_h( __VA_ARGS__ )
946
947#define retroflat_2d_blit_bitmap( ... ) retro3d_texture_blit( __VA_ARGS__ )
948
949#define retroflat_2d_blit_win( src, d_x, d_y ) \
950 retro3d_draw_window( src, d_x, d_y )
951
952#define retroflat_2d_lock_bitmap( ... ) \
953 retro3d_texture_lock( __VA_ARGS__ )
954
955#define retroflat_2d_release_bitmap( ... ) \
956 retro3d_texture_release( __VA_ARGS__ )
957
958#define retroflat_2d_load_bitmap( ... ) \
959 retro3d_texture_load_bitmap( __VA_ARGS__ )
960
961#define retroflat_2d_create_bitmap( ... ) \
962 retro3d_texture_create( __VA_ARGS__ )
963
964#define retroflat_2d_destroy_bitmap( ... ) \
965 retro3d_texture_destroy( __VA_ARGS__ )
966
967#else
968
969#define retroflat_bitmap_has_flags( bmp, f ) \
970 (NULL != (bmp) && (f) == ((f) & (bmp)->flags))
971
972#define retroflat_2d_px( ... ) retroflat_px( __VA_ARGS__ )
973
974#define retroflat_2d_line( ... ) retroflat_line( __VA_ARGS__ )
975
976#define retroflat_2d_rect( ... ) retroflat_rect( __VA_ARGS__ )
977
978#define retroflat_2d_bitmap_ok( ... ) retroflat_bitmap_ok( __VA_ARGS__ )
979
980#define retroflat_2d_bitmap_w( ... ) retroflat_bitmap_w( __VA_ARGS__ )
981
982#define retroflat_2d_bitmap_h( ... ) retroflat_bitmap_h( __VA_ARGS__ )
983
984#define retroflat_2d_blit_win( src, d_x, d_y ) \
985 retroflat_blit_bitmap( NULL, (src), 0, 0, d_x, d_y, \
986 (win)->gui->w, (win)->gui->h, 0 )
987
988#define retroflat_2d_blit_bitmap( ... ) retroflat_blit_bitmap( __VA_ARGS__ )
989
990#define retroflat_2d_lock_bitmap( ... ) \
991 retroflat_draw_lock( __VA_ARGS__ )
992
993#define retroflat_2d_release_bitmap( ... ) \
994 retroflat_draw_release( __VA_ARGS__ )
995
996#define retroflat_2d_load_bitmap( ... ) retroflat_load_bitmap( __VA_ARGS__ )
997
998#define retroflat_2d_create_bitmap( ... ) retroflat_create_bitmap( __VA_ARGS__ )
999
1000#define retroflat_2d_destroy_bitmap( ... ) \
1001 retroflat_destroy_bitmap( __VA_ARGS__ )
1002
1003#endif /* RETROFLAT_3D || DOCUMENTATION */
1004
1011typedef size_t retroflat_pxxy_t;
1012
1013struct RETROFLAT_ARGS;
1014
1015#ifndef API_TRACE_LVL
1016# define API_TRACE_LVL 0
1017#endif /* !API_TRACE_LVL */
1018
1019#ifndef NO_RETROSND
1020
1048
1049#ifndef RETROSND_TRACE_LVL
1050# define RETROSND_TRACE_LVL 0
1051#endif /* !RETROSND_TRACE_LVL */
1052
1053#ifndef RETROSND_REG_TRACE_LVL
1054# define RETROSND_REG_TRACE_LVL 0
1055#endif /* !RETROSND_REG_TRACE_LVL */
1056
1062
1067#define RETROSND_FLAG_INIT 0x01
1068 /* maug_retrosnd_flags */
1070
1071#define RETROSND_VOICE_BREATH 122
1072
1073#define RETROSND_VOICE_SEASHORE 123
1074
1075#define RETROSND_VOICE_BIRD_TWEET 124
1076
1077#define RETROSND_VOICE_PHONE_RING 125
1078
1079#define RETROSND_VOICE_HELICOPTER 126
1080
1081#define RETROSND_VOICE_APPLAUSE 127
1082
1087#define RETROSND_VOICE_GUNSHOT 128
1088
1089#define RETROSND_CHANNEL_CT 8
1090
1100
1104void retrosnd_set_sf_bank( const char* filename_in );
1105
1106void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice );
1107
1108void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val );
1109
1110void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel );
1111
1112void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel );
1113
1114MERROR_RETVAL retrosnd_midi_play_smf( const char* filename );
1115
1116uint8_t retrosnd_midi_is_playing_smf();
1117
1118void retrosnd_shutdown();
1119 /* maug_retrosnd */
1121
1122#endif /* !NO_RETROSND */
1123
1124/* === OS-Specific Includes and Defines === */
1125
1126#if defined( RETROFLAT_OS_WIN ) && !defined( MAUG_WINDOWS_H )
1127# include <windows.h>
1128# define MAUG_WINDOWS_H
1129#endif /* !MAUG_WINDOWS_H */
1130
1131/* TODO: Migrate all platform-specific parts below to retapid.h. */
1132#include <retapid.h>
1133
1134typedef maug_ms_t retroflat_ms_t;
1135
1136#ifdef RETROFLAT_BMP_TEX
1137typedef struct RETROFLAT_3DTEX retroflat_blit_t;
1138#else
1139typedef struct RETROFLAT_BITMAP retroflat_blit_t;
1140#endif
1141
1148typedef void (*retroflat_px_cb)(
1149 retroflat_blit_t* target, const RETROFLAT_COLOR color_idx,
1150 size_t x, size_t y, uint8_t flags );
1151
1152/* === Structures === */
1153
1160 char* title;
1163 uint8_t flags;
1166# ifdef RETROFLAT_API_PC_BIOS
1168 uint8_t screen_mode;
1169# elif !defined( RETROFLAT_NO_CLI_SZ )
1170 int screen_w;
1177# endif /* RETROFLAT_API_PC_BIOS */
1178 uint8_t snd_flags;
1179# if defined( RETROSND_API_SDL1 ) || defined( RETROSND_API_SDL2 )
1180# elif defined( RETROSND_API_WINMM )
1181 UINT snd_dev_id;
1182# elif defined( RETROSND_API_PC_BIOS )
1183 uint16_t snd_io_base;
1184 uint8_t snd_driver;
1185# elif defined( RETROSND_API_ALSA )
1186 uint8_t snd_client;
1187 uint8_t snd_port;
1188# else
1189# pragma message( "warning: sound args not specified" )
1190# endif /* RETROSND_API_WINMM */
1191};
1192
1203
1216 int16_t screen_x;
1222 int16_t screen_y;
1228 int16_t world_x;
1234 int16_t world_y;
1240 int16_t world_w;
1246 int16_t world_h;
1252 uint16_t screen_w;
1258 uint16_t screen_h;
1287 int16_t world_tile_x;
1288 int16_t world_tile_y;
1289#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1290 MAUG_MHANDLE refresh_grid_h;
1302#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1303};
1304
1305# define retroflat_screen_colors() (g_retroflat_state->screen_colors)
1306
1307#ifndef DOCUMENTATION
1308
1309# define retroflat_viewport_world_x_generic() \
1310 (g_retroflat_state->viewport.world_x)
1311
1312# define retroflat_viewport_world_y_generic() \
1313 (g_retroflat_state->viewport.world_y)
1314
1315# define retroflat_viewport_world_tile_x_generic() \
1316 (g_retroflat_state->viewport.world_tile_x)
1317
1318# define retroflat_viewport_world_tile_y_generic() \
1319 (g_retroflat_state->viewport.world_tile_y)
1320
1321# define retroflat_viewport_world_w_generic() \
1322 (g_retroflat_state->viewport.world_w)
1323
1324# define retroflat_viewport_world_h_generic() \
1325 (g_retroflat_state->viewport.world_h)
1326
1327# define retroflat_viewport_screen_tile_w_generic() \
1328 (g_retroflat_state->viewport.screen_tile_w)
1329
1330# define retroflat_viewport_screen_tile_h_generic() \
1331 (g_retroflat_state->viewport.screen_tile_h)
1332
1333# define retroflat_viewport_screen_w_generic() \
1334 (g_retroflat_state->viewport.screen_w)
1335
1336# define retroflat_viewport_screen_h_generic() \
1337 (g_retroflat_state->viewport.screen_h)
1338
1339# define retroflat_viewport_screen_w_remainder_generic() \
1340 (g_retroflat_state->viewport.screen_w_remainder)
1341
1342# define retroflat_viewport_screen_h_remainder_generic() \
1343 (g_retroflat_state->viewport.screen_h_remainder)
1344
1345# define retroflat_viewport_set_world_generic( w, h ) \
1346 debug_printf( 1, "setting viewport size to %d x %d...", \
1347 (int16_t)(w), (int16_t)(h) ); \
1348 (g_retroflat_state->viewport.world_w) = w; \
1349 (g_retroflat_state->viewport.world_h) = h;
1350
1351# define retroflat_viewport_set_world_pos_generic( x, y ) \
1352 debug_printf( 1, "setting viewport world pos to %d, %d...", x, y ); \
1353 (g_retroflat_state->viewport.world_x) = x; \
1354 (g_retroflat_state->viewport.world_y) = y; \
1355 (g_retroflat_state->viewport.world_tile_x) = (x) >> RETROFLAT_TILE_W_BITS; \
1356 (g_retroflat_state->viewport.world_tile_y) = (y) >> RETROFLAT_TILE_H_BITS;
1357
1358# define retroflat_viewport_set_pos_size_generic( x_px, y_px, w_px, h_px ) \
1359 g_retroflat_state->viewport.screen_x = (x_px); \
1360 g_retroflat_state->viewport.screen_y = (y_px); \
1361 g_retroflat_state->viewport.screen_tile_w = \
1362 ((w_px) / RETROFLAT_TILE_W); \
1363 g_retroflat_state->viewport.screen_tile_h = \
1364 ((h_px) / RETROFLAT_TILE_H); \
1365 /* We're not adding the extra room here since this won't be used for
1366 * indexing or allocation but rather pixel detection.
1367 */ \
1368 g_retroflat_state->viewport.screen_w = \
1369 ((w_px) / RETROFLAT_TILE_W) * RETROFLAT_TILE_W; \
1370 g_retroflat_state->viewport.screen_h = \
1371 ((h_px) / RETROFLAT_TILE_H) * RETROFLAT_TILE_H; \
1372 g_retroflat_state->viewport.screen_w_remainder = \
1373 (x_px) + (w_px) - g_retroflat_state->viewport.screen_w; \
1374 g_retroflat_state->viewport.screen_h_remainder = \
1375 (y_px) + (h_px) - g_retroflat_state->viewport.screen_h;
1376
1377#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1378
1379# define retroflat_viewport_lock_refresh_generic() \
1380 if( NULL == g_retroflat_state->viewport.refresh_grid ) { \
1381 maug_mlock( \
1382 g_retroflat_state->viewport.refresh_grid_h, \
1383 g_retroflat_state->viewport.refresh_grid ); \
1384 maug_cleanup_if_null_lock( retroflat_tile_t*, \
1385 g_retroflat_state->viewport.refresh_grid ); \
1386 }
1387
1388# define retroflat_viewport_unlock_refresh_generic() \
1389 if( NULL != g_retroflat_state->viewport.refresh_grid ) { \
1390 maug_munlock( \
1391 g_retroflat_state->viewport.refresh_grid_h, \
1392 g_retroflat_state->viewport.refresh_grid ); \
1393 }
1394
1395# define _retroflat_viewport_refresh_tile_x( x_px ) \
1396 (((x_px) + RETROFLAT_TILE_W) >> RETROFLAT_TILE_W_BITS)
1397
1398# define _retroflat_viewport_refresh_tile_y( y_px ) \
1399 (((y_px) + RETROFLAT_TILE_H) >> RETROFLAT_TILE_H_BITS)
1400
1401# define retroflat_viewport_set_refresh_generic( x_px, y_px, tid ) \
1402 assert( NULL != g_retroflat_state->viewport.refresh_grid ); \
1403 if( \
1404 /* Expand the range by -1 to account for just off-screen tile. */ \
1405 -(RETROFLAT_TILE_W) <= x_px && -(RETROFLAT_TILE_H) <= y_px && \
1406 retroflat_screen_w() > x_px && \
1407 retroflat_screen_h() > y_px \
1408 ) { \
1409 assert( 0 < g_retroflat_state->viewport.screen_tile_w ); \
1410 assert( 0 <= (((y_px) + RETROFLAT_TILE_H) >> RETROFLAT_TILE_H_BITS) ); \
1411 assert( 0 <= (((x_px) + RETROFLAT_TILE_W) >> RETROFLAT_TILE_W_BITS) ); \
1412 g_retroflat_state->viewport.refresh_grid[ \
1413 /* Add +1 tile to make off-screen "-1" tile positive. */ \
1414 ((_retroflat_viewport_refresh_tile_y( y_px ) + 1) * \
1415 (g_retroflat_state->viewport.screen_tile_w + 2)) + \
1416 (_retroflat_viewport_refresh_tile_x( x_px ) + 1)] = tid; \
1417 }
1418
1419# define retroflat_viewport_tile_is_stale( x_px, y_px, tile_id ) \
1420 ((tile_id) != \
1421 g_retroflat_state->viewport.refresh_grid[ \
1422 ((_retroflat_viewport_refresh_tile_y( y_px ) + 1) * \
1423 (g_retroflat_state->viewport.screen_tile_w + 2)) + \
1424 (_retroflat_viewport_refresh_tile_x( x_px ) + 1)])
1425
1426#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1427
1428uint8_t retroflat_viewport_move_x_generic( int16_t x );
1429
1430uint8_t retroflat_viewport_move_y_generic( int16_t y );
1431
1432uint8_t retroflat_viewport_focus_generic(
1433 size_t x1, size_t y1, size_t range, size_t speed );
1434
1435# define retroflat_viewport_screen_x_generic( world_x ) \
1436 (g_retroflat_state->viewport.screen_x + \
1437 ((world_x) - retroflat_viewport_world_x()))
1438
1439# define retroflat_viewport_screen_y_generic( world_y ) \
1440 (g_retroflat_state->viewport.screen_y + \
1441 ((world_y) - retroflat_viewport_world_y()))
1442
1443#endif /* !DOCUMENTATION */
1444
1445#if defined( RETROFLAT_SOFT_VIEWPORT ) || defined( DOCUMENTATION )
1446
1447# ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1448 /* These clamp world coordinates to tile borders to allow refresh grid to
1449 * function properly (smooth-scrolling tiles will always be in motion).
1450 */
1451
1456# define retroflat_viewport_world_x() \
1457 ((retroflat_viewport_world_x_generic() \
1458 >> RETROFLAT_TILE_W_BITS) << RETROFLAT_TILE_W_BITS)
1459
1464# define retroflat_viewport_world_y() \
1465 ((retroflat_viewport_world_y_generic() \
1466 >> RETROFLAT_TILE_H_BITS) << RETROFLAT_TILE_H_BITS)
1467# else
1468# define retroflat_viewport_world_x() retroflat_viewport_world_x_generic()
1469# define retroflat_viewport_world_y() retroflat_viewport_world_y_generic()
1470#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1471
1472# define retroflat_viewport_world_tile_x() \
1473 retroflat_viewport_world_tile_x_generic()
1474# define retroflat_viewport_world_tile_y() \
1475 retroflat_viewport_world_tile_y_generic()
1476
1481# define retroflat_viewport_world_w() \
1482 retroflat_viewport_world_w_generic()
1483
1488# define retroflat_viewport_world_h() \
1489 retroflat_viewport_world_h_generic()
1490
1495# define retroflat_viewport_screen_tile_w() \
1496 retroflat_viewport_screen_tile_w_generic()
1497
1502# define retroflat_viewport_screen_tile_h() \
1503 retroflat_viewport_screen_tile_h_generic()
1504
1509# define retroflat_viewport_screen_w() \
1510 retroflat_viewport_screen_w_generic()
1511
1516# define retroflat_viewport_screen_h() \
1517 retroflat_viewport_screen_h_generic()
1518
1524# define retroflat_viewport_screen_w_remainder() \
1525 retroflat_viewport_screen_w_remainder_generic()
1526
1532# define retroflat_viewport_screen_h_remainder() \
1533 retroflat_viewport_screen_h_remainder_generic()
1534
1542# define retroflat_viewport_set_world( w, h ) \
1543 retroflat_viewport_set_world_generic( w, h )
1544
1549# define retroflat_viewport_set_world_pos( x, y ) \
1550 retroflat_viewport_set_world_pos_generic( x, y )
1551
1557# define retroflat_viewport_set_pos_size( x_px, y_px, w_px, h_px ) \
1558 retroflat_viewport_set_pos_size_generic( x_px, y_px, w_px, h_px )
1559
1560#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1561
1569# define retroflat_viewport_lock_refresh() \
1570 retroflat_viewport_lock_refresh_generic()
1571
1579# define retroflat_viewport_unlock_refresh() \
1580 retroflat_viewport_unlock_refresh_generic()
1581
1593# define retroflat_viewport_set_refresh( x, y, tid ) \
1594 retroflat_viewport_set_refresh_generic( x, y, tid )
1595
1596#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1597
1610# define retroflat_viewport_focus( x1, y1, range, speed ) \
1611 retroflat_viewport_focus_generic( x1, y1, range, speed )
1612
1617# define retroflat_viewport_screen_x( world_x ) \
1618 retroflat_viewport_screen_x_generic( world_x )
1619
1624# define retroflat_viewport_screen_y( world_y ) \
1625 retroflat_viewport_screen_y_generic( world_y )
1626
1627# ifndef RETROFLAT_VIEWPORT_OVERRIDE_MOVE
1628# define retroflat_viewport_move_x( x ) \
1629 retroflat_viewport_move_x_generic( x )
1630
1631# define retroflat_viewport_move_y( y ) \
1632 retroflat_viewport_move_y_generic( y )
1633# endif /* !RETROFLAT_VIEWPORT_OVERRIDE_MOVE */
1634
1635#endif /* RETROFLAT_SOFT_VIEWPORT || DOCUMENTATION */
1636
1638
1645#define retroflat_heartbeat_set( len, max ) \
1646 g_retroflat_state->heartbeat_max = max; \
1647 g_retroflat_state->heartbeat_len = len;
1648
1653#define retroflat_heartbeat() (g_retroflat_state->heartbeat_frame)
1654
1661#define retroflat_heartbeat_update() \
1662 /* Update the heartbeat animation frame. */ \
1663 if( g_retroflat_state->heartbeat_next <= retroflat_get_ms() ) { \
1664 g_retroflat_state->heartbeat_frame++; \
1665 if( \
1666 g_retroflat_state->heartbeat_frame >= \
1667 g_retroflat_state->heartbeat_max \
1668 ) { \
1669 g_retroflat_state->heartbeat_frame = 0; \
1670 } \
1671 g_retroflat_state->heartbeat_next = \
1672 retroflat_get_ms() + g_retroflat_state->heartbeat_len; \
1673 }
1674
1682 /* TODO: Set this up in the initialization function! */
1683 /* TODO: We probably need more of these. */
1684 size_t sz;
1685 size_t offset_pal;
1686 size_t offset_tex_pal;
1687
1688 void* loop_data;
1689 MERROR_RETVAL retval;
1692 char config_path[RETROFLAT_PATH_MAX + 1];
1693 char assets_path[RETROFLAT_ASSETS_PATH_MAX + 1];
1696 int scale;
1697
1698# if defined( RETROFLAT_VDP ) || defined( DOCUMENTATION ) || \
1699defined( RETROVDP_C )
1705# ifdef RETROFLAT_OS_WIN
1706 HMODULE vdp_exe;
1707# else
1709 void* vdp_exe;
1710# endif /* RETROFLAT_OS_WIN */
1719 uint8_t vdp_flags;
1720# endif /* RETROFLAT_VDP || DOCUMENTATION || RETROVDP_C */
1721
1722 /* These are used by VDP so should be standardized/not put in plat-spec! */
1723
1724 struct RETROFLAT_VIEWPORT viewport;
1725
1741 size_t screen_w;
1743 size_t screen_h;
1746
1747 /* WARNING: The VDP requires the state specifier to be the same size
1748 * as the one it was compiled for! Do not modify above here!
1749 */
1750
1751 /* TODO: Put these in a platform-specific struct of some kind to maintain
1752 * consistent state struct size for VDP?
1753 */
1754
1755 retroflat_ms_t heartbeat_next;
1773
1774 retroflat_proc_resize_t on_resize;
1775 void* on_resize_data;
1776
1777#ifndef RETROFLAT_OPENGL
1779 RETROFLAT_COLOR_DEF palette[RETROFLAT_COLORS_SZ];
1780#endif /* !RETROFLAT_OPENGL */
1781
1782 retroflat_loop_iter loop_iter;
1783 retroflat_loop_iter frame_iter;
1784
1785 struct RETROFLAT_PLATFORM platform;
1786
1787# if defined( RETROFLAT_3D )
1788 /* This allows native colors to be used for things like glColor3fv while
1789 * these colors are used to manipulate textures passed through
1790 * retroflat_bitmap_*()
1791 */
1792 uint8_t tex_palette[RETROFLAT_COLORS_SZ][3];
1793# endif /* RETROFLAT_OPENGL */
1794
1795#ifndef NO_RETROSND
1796 struct RETROFLAT_SOUND sound;
1797#endif /* !NO_RETROSND */
1798};
1799
1800/* === Translation Module === */
1801
1802/* Declare the prototypes so that internal functions can call each other. */
1803
1804# ifdef retroflat_loop
1805MERROR_RETVAL retroflat_loop_generic(
1806 retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void* data );
1807# else
1814 retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void* data );
1815# endif /* retroflat_loop */
1816
1824 uint8_t flags, const char* title, const char* format, ... );
1825
1833MERROR_RETVAL retroflat_init( int argc, char* argv[], struct RETROFLAT_ARGS* args );
1834
1841void retroflat_shutdown( int retval );
1842
1843# if defined( RETROFLAT_VDP ) || defined( DOCUMENTATION )
1848
1852MERROR_RETVAL retroflat_vdp_call( const char* proc_name );
1853 /* maug_retroflt_vdp */
1855# endif /* RETROFLAT_VDP || DOCUMENTATION */
1856
1857void retroflat_set_title( const char* format, ... );
1858
1859retroflat_ms_t retroflat_get_ms();
1860
1861uint32_t retroflat_get_rand();
1862
1863# if !defined( RETROFLAT_NO_KEYBOARD )
1864char retroflat_vk_to_ascii( RETROFLAT_IN_KEY k, uint8_t flags );
1865# endif /* !RETROFLAT_NO_KEYBOARD */
1866
1871
1883 const char* filename, struct RETROFLAT_BITMAP* bmp_out, uint8_t flags );
1884
1885MERROR_RETVAL retroflat_create_bitmap(
1886 size_t w, size_t h, struct RETROFLAT_BITMAP* bmp_out, uint8_t flags );
1887
1894
1909 struct RETROFLAT_BITMAP* target, struct RETROFLAT_BITMAP* src,
1910 size_t s_x, size_t s_y, int16_t d_x, int16_t d_y, size_t w, size_t h,
1911 int16_t instance );
1912
1920#define retroflat_constrain_px( x, y, bmp, retact ) \
1921 if( \
1922 x >= retroflat_bitmap_w( bmp ) || y >= retroflat_bitmap_h( bmp ) \
1923 ) { retact; }
1924 /* maug_retroflt_bitmap */
1926
1931
1942
1943MERROR_RETVAL retroflat_draw_release( struct RETROFLAT_BITMAP* bmp );
1944
1945void retroflat_px(
1946 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1947 size_t x, size_t y, uint8_t flags );
1948
1949#ifdef RETROFLAT_SOFT_SHAPES
1950# ifdef RETROFLAT_OPENGL
1951/* Make sure we're not passing NULL to openGL texture drawers... they can't
1952 * handle that!
1953 */
1954# define retroflat_rect( t, c, x, y, w, h, f ) \
1955 assert( NULL != t ); \
1956 retrosoft_rect( t, c, x, y, w, h, f );
1957# define retroflat_ellipse( t, c, x, y, w, h, f ) \
1958 assert( NULL != t ); \
1959 retrosoft_ellipse( t, c, x, y, w, h, f )
1960# else
1961# define retroflat_rect( t, c, x, y, w, h, f ) \
1962 retrosoft_rect( t, c, x, y, w, h, f )
1963# define retroflat_ellipse( t, c, x, y, w, h, f ) \
1964 retrosoft_ellipse( t, c, x, y, w, h, f )
1965# endif /* RETROFLAT_3D */
1966#else
1967
1979 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1980 int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags );
1981
1993 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1994 int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags );
1995
1996#endif /* RETROFLAT_SOFT_SHAPES */
1997
1998#ifdef RETROFLAT_SOFT_LINES
1999# define retroflat_line( t, c, x1, y1, x2, y2, f ) \
2000 retrosoft_line( t, c, x1, y1, x2, y2, f )
2001#else
2002
2015 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
2016 int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t flags );
2017
2018#endif /* RETROFLAT_SOFT_LINES */
2019
2020void retroflat_cursor( struct RETROFLAT_BITMAP* target, uint8_t flags );
2021
2035 struct RETROFLAT_BITMAP* target, const char* str, size_t str_sz,
2036 const char* font_str, size_t* w_out, size_t* h_out, uint8_t flags );
2037
2056 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
2057 const char* str, int str_sz, const char* font_str, int16_t x_orig, int16_t y_orig,
2058 uint8_t flags );
2059
2060/* TODO: Documentation! */
2061void retroflat_get_palette( uint8_t idx, uint32_t* rgb );
2062
2063MERROR_RETVAL retroflat_set_palette( uint8_t idx, uint32_t rgb );
2064 /* maug_retroflt_bitmap */
2066
2077 retroflat_proc_resize_t on_resize_in, void* data_in );
2078
2084
2089
2095RETROFLAT_IN_KEY retroflat_poll_input( struct RETROFLAT_INPUT* input );
2096 /* maug_retroflt_input */
2098
2099#ifdef RETROFLT_C
2100
2101MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8] =
2102 { 0, 1, 1, 1, 0, -1, -1, -1 };
2103MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y[8] =
2104 { -1, -1, 0, 1, 1, 1, 0, -1 };
2105
2106MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x[4] =
2107 { 0, 1, 0, -1 };
2108MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y[4] =
2109 { -1, 0, 1, 0 };
2110
2111MAUG_MHANDLE g_retroflat_state_h = (MAUG_MHANDLE)NULL;
2112struct RETROFLAT_STATE* g_retroflat_state = NULL;
2113
2114# define RETROFLAT_COLOR_TABLE_CONSTS( idx, name_l, name_u, r, g, b, cgac, cgad ) \
2115 MAUG_CONST RETROFLAT_COLOR RETROFLAT_COLOR_ ## name_u = idx;
2116
2117RETROFLAT_COLOR_TABLE( RETROFLAT_COLOR_TABLE_CONSTS )
2118
2119# define RETROFLAT_COLOR_TABLE_NAMES( idx, name_l, name_u, r, g, b, cgac, cgad ) \
2120 #name_u,
2121
2122MAUG_CONST char* SEG_MCONST gc_retroflat_color_names[] = {
2123 RETROFLAT_COLOR_TABLE( RETROFLAT_COLOR_TABLE_NAMES )
2124};
2125
2126/* Callback table is down below, after the statically-defined callbacks. */
2127
2128/* === Function Definitions === */
2129
2130MERROR_RETVAL retroflat_build_filename_path(
2131 const char* filename_in,
2132 char* buffer_out, size_t buffer_out_sz, uint8_t flags
2133) {
2134 MERROR_RETVAL retval = MERROR_OK;
2135
2136 assert( 1 < buffer_out_sz );
2137
2138 /* Build the path to the bitmap. */
2139 memset( buffer_out, '\0', buffer_out_sz );
2140 if(
2143 ) {
2144 /* TODO: Error checking. */
2145 maug_snprintf( buffer_out, buffer_out_sz - 1, "%s", filename_in );
2146 } else {
2147 /* TODO: Error checking. */
2148 maug_snprintf( buffer_out, buffer_out_sz - 1, "%s%c%s.%s",
2149 g_retroflat_state->assets_path, RETROFLAT_PATH_SEP,
2150 filename_in, RETROFLAT_BITMAP_EXT );
2151 }
2152
2153 return retval;
2154}
2155
2156/* === */
2157
2158# if (defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES ) || \
2159 defined( RETROFLAT_3D ))
2160/* RETROSOFT_PRESENT is different from RETROFLAT_SOFT_SHAPES in that it only
2161 * indicates that the retrosoft library is loaded, not that it is the default
2162 * for drawing primatives!
2163 */
2164# define RETROSOFT_PRESENT
2165# endif
2166
2167# if defined( RETROFLAT_3D )
2168# if !defined( MAUG_NO_AUTO_C )
2169# define RETRO3D_C
2170# define RETRO3DP_C
2171# define RETROFP_C
2172# endif /* MAUG_NO_AUTO_C */
2173# include <retro3dp.h>
2174# include <retro3d.h>
2175# include <retro3du.h>
2176# include <retapi3.h>
2177# endif /* RETROFLAT_3D */
2178
2179# ifdef RETROSOFT_PRESENT
2180# if !defined( MAUG_NO_AUTO_C )
2181# define RETROSFT_C
2182# endif /* !MAUG_NO_AUTO_C */
2183# define RETROSOFT_PRESENT
2184# include <retrosft.h>
2185# endif /* RETROFLAT_SOFT_SHAPES */
2186
2187# if defined( RETROFLAT_VDP ) && defined( RETROFLAT_OS_UNIX )
2188# include <dlfcn.h>
2189# endif
2190
2191/* Still inside RETROFLT_C! */
2192
2193/* === */
2194
2195#ifndef RETROFLAT_NO_GENERIC_LOOP
2196
2197MERROR_RETVAL retroflat_loop_generic(
2198 retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void* data
2199) {
2200 MERROR_RETVAL retval = MERROR_OK;
2201 retroflat_ms_t next = 0,
2202 now = 0;
2203
2204 g_retroflat_state->loop_iter = (retroflat_loop_iter)loop_iter;
2205 g_retroflat_state->loop_data = (void*)data;
2206 g_retroflat_state->frame_iter = (retroflat_loop_iter)frame_iter;
2207
2208 if(
2210 (g_retroflat_state->retroflat_flags & RETROFLAT_FLAGS_RUNNING)
2211 ) {
2212 /* Main loop is already running, so we're just changing the iter call
2213 * and leaving!
2214 */
2215 debug_printf( 1, "main loop already running!" );
2216 goto cleanup;
2217 }
2218
2219 g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_RUNNING;
2220 do {
2221 if(
2222 /* Not waiting for the next frame? */
2224 (RETROFLAT_FLAGS_WAIT_FOR_FPS & g_retroflat_state->retroflat_flags) &&
2225 /* Inter-frame loop present? */
2226 NULL != g_retroflat_state->loop_iter
2227 ) {
2228 /* Run the loop iter as many times as possible. */
2229 g_retroflat_state->loop_iter( g_retroflat_state->loop_data );
2230 }
2231 if(
2233 (RETROFLAT_FLAGS_UNLOCK_FPS & g_retroflat_state->retroflat_flags) &&
2234 retroflat_get_ms() < next
2235 ) {
2236 /* Sleep/low power for a bit. */
2237 continue;
2238 }
2239
2241
2242 if( NULL != g_retroflat_state->frame_iter ) {
2243 /* Run the frame iterator once per FPS tick. */
2244 g_retroflat_state->frame_iter( g_retroflat_state->loop_data );
2245 }
2246 /* Reset wait-for-frame flag AFTER frame callback. */
2247 g_retroflat_state->retroflat_flags &= ~RETROFLAT_FLAGS_WAIT_FOR_FPS;
2248 now = retroflat_get_ms();
2249 if( now + retroflat_fps_next() > now ) {
2250 next = now + retroflat_fps_next();
2251 } else {
2252 /* Rollover protection. */
2253 /* TODO: Add difference from now/next to 0 here. */
2254 next = 0;
2255 }
2256 } while(
2258 (RETROFLAT_FLAGS_RUNNING & g_retroflat_state->retroflat_flags)
2259 );
2260 retval = g_retroflat_state->retval;
2261
2262cleanup:
2263
2264 /* This should be set by retroflat_quit(). */
2265 return retval;
2266}
2267
2268#endif /* !RETROFLAT_NO_GENERIC_LOOP */
2269
2270/* === */
2271
2272# if !defined( RETROFLAT_NO_KEYBOARD )
2273
2274char retroflat_vk_to_ascii( RETROFLAT_IN_KEY k, uint8_t flags ) {
2275 char c = 0;
2276 char offset_lower = 0;
2277
2278 if( RETROFLAT_INPUT_MOD_SHIFT != (RETROFLAT_INPUT_MOD_SHIFT & flags) ) {
2279 /* Shift is *not* being held down. */
2280
2281 if( RETROFLAT_KEY_A <= k && RETROFLAT_KEY_Z >= k ) {
2282 if(
2283 RETROFLAT_INPUT_FORCE_UPPER !=
2284 (RETROFLAT_INPUT_FORCE_UPPER & flags)
2285 ) {
2286 /* Key is alphabetical and we're not forcing uppercase. */
2287 offset_lower = 0x20;
2288 }
2289 } else {
2290 offset_lower = 1;
2291 }
2292 }
2293
2294 switch( k ) {
2295 case RETROFLAT_KEY_A: c = 0x41 + offset_lower; break;
2296 case RETROFLAT_KEY_B: c = 0x42 + offset_lower; break;
2297 case RETROFLAT_KEY_C: c = 0x43 + offset_lower; break;
2298 case RETROFLAT_KEY_D: c = 0x44 + offset_lower; break;
2299 case RETROFLAT_KEY_E: c = 0x45 + offset_lower; break;
2300 case RETROFLAT_KEY_F: c = 0x46 + offset_lower; break;
2301 case RETROFLAT_KEY_G: c = 0x47 + offset_lower; break;
2302 case RETROFLAT_KEY_H: c = 0x48 + offset_lower; break;
2303 case RETROFLAT_KEY_I: c = 0x49 + offset_lower; break;
2304 case RETROFLAT_KEY_J: c = 0x4a + offset_lower; break;
2305 case RETROFLAT_KEY_K: c = 0x4b + offset_lower; break;
2306 case RETROFLAT_KEY_L: c = 0x4c + offset_lower; break;
2307 case RETROFLAT_KEY_M: c = 0x4d + offset_lower; break;
2308 case RETROFLAT_KEY_N: c = 0x4e + offset_lower; break;
2309 case RETROFLAT_KEY_O: c = 0x4f + offset_lower; break;
2310 case RETROFLAT_KEY_P: c = 0x50 + offset_lower; break;
2311 case RETROFLAT_KEY_Q: c = 0x51 + offset_lower; break;
2312 case RETROFLAT_KEY_R: c = 0x52 + offset_lower; break;
2313 case RETROFLAT_KEY_S: c = 0x53 + offset_lower; break;
2314 case RETROFLAT_KEY_T: c = 0x54 + offset_lower; break;
2315 case RETROFLAT_KEY_U: c = 0x55 + offset_lower; break;
2316 case RETROFLAT_KEY_V: c = 0x56 + offset_lower; break;
2317 case RETROFLAT_KEY_W: c = 0x57 + offset_lower; break;
2318 case RETROFLAT_KEY_X: c = 0x58 + offset_lower; break;
2319 case RETROFLAT_KEY_Y: c = 0x59 + offset_lower; break;
2320 case RETROFLAT_KEY_Z: c = 0x60 + offset_lower; break;
2321 case RETROFLAT_KEY_0: c = offset_lower ? 0x30 : ')'; break;
2322 case RETROFLAT_KEY_1: c = offset_lower ? 0x31 : '!'; break;
2323 case RETROFLAT_KEY_2: c = offset_lower ? 0x32 : '@'; break;
2324 case RETROFLAT_KEY_3: c = offset_lower ? 0x33 : '#'; break;
2325 case RETROFLAT_KEY_4: c = offset_lower ? 0x34 : '$'; break;
2326 case RETROFLAT_KEY_5: c = offset_lower ? 0x35 : '%'; break;
2327 case RETROFLAT_KEY_6: c = offset_lower ? 0x36 : '^'; break;
2328 case RETROFLAT_KEY_7: c = offset_lower ? 0x37 : '&'; break;
2329 case RETROFLAT_KEY_8: c = offset_lower ? 0x38 : '*'; break;
2330 case RETROFLAT_KEY_9: c = offset_lower ? 0x39 : '('; break;
2331 case RETROFLAT_KEY_SPACE: c = ' '; break;
2332 case RETROFLAT_KEY_BKSP: c = 0x08; break;
2333 case RETROFLAT_KEY_ENTER: c = '\n'; break;
2334 case RETROFLAT_KEY_SEMICOLON: c = offset_lower ? ';' : ':'; break;
2335 case RETROFLAT_KEY_DASH: c = offset_lower ? '-' : '_'; break;
2336 case RETROFLAT_KEY_SLASH: c = offset_lower ? '/' : '?'; break;
2337 case RETROFLAT_KEY_PERIOD: c = offset_lower ? '.' : '>'; break;
2338 case RETROFLAT_KEY_COMMA: c = offset_lower ? ',' : '<'; break;
2339 case RETROFLAT_KEY_QUOTE: c = offset_lower ? '\'' : '"'; break;
2340 case RETROFLAT_KEY_EQUALS: c = offset_lower ? '=' : '+'; break;
2341 case RETROFLAT_KEY_BACKSLASH: c = offset_lower ? '\\' : '|'; break;
2342 case RETROFLAT_KEY_BRACKETL: c = offset_lower ? '[' : '{'; break;
2343 case RETROFLAT_KEY_BRACKETR: c = offset_lower ? ']' : '}'; break;
2344#ifndef RETROFLAT_API_PC_BIOS
2345 /* TODO: FIXME in DOS! */
2346 case RETROFLAT_KEY_GRAVE: c = offset_lower ? '`' : '~'; break;
2347#endif /* !RETROFLAT_API_PC_BIOS */
2348 }
2349
2350 debug_printf( RETROFLAT_KB_TRACE_LVL, "0x%02x", c );
2351
2352 return c;
2353}
2354
2355#endif /* !RETROFLAT_NO_KEYBOARD */
2356
2357/* === */
2358
2359/* TODO: Migrate all platform-specific parts below to retapif.h. */
2360#include <retapif.h>
2361
2362/* === */
2363
2364# ifndef RETROFLAT_NO_CLI
2365
2366# ifdef RETROSND_ARGS
2367
2368static MERROR_RETVAL retrosnd_cli_rsl(
2369 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2370) {
2371 if(
2372 0 <= arg_c &&
2373 0 == strncmp( MAUG_CLI_SIGIL "rsl", arg, MAUG_CLI_SIGIL_SZ + 4 )
2374 ) {
2375 args->snd_flags |= RETROSND_ARGS_FLAG_LIST_DEVS;
2376 }
2377 return MERROR_OK;
2378}
2379
2380static MERROR_RETVAL retrosnd_cli_rsd(
2381 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2382) {
2383 MERROR_RETVAL retval = MERROR_OK;
2384# if defined( RETROSND_API_PC_BIOS ) || defined( RETROSND_API_ALSA )
2385 char* env_var = NULL;
2386 size_t i = 0;
2387# elif defined( RETROSND_API_ALSA )
2388 char* env_var = NULL;
2389# elif defined( RETROSND_API_WINMM )
2390 char* env_var = NULL;
2391# endif /* RETROSND_API_PC_BIOS || RETROSND_API_ALSA */
2392
2393 if( 0 > arg_c ) {
2394# ifdef RETROSND_API_PC_BIOS
2395 if( NULL != env_var ) {
2396 env_var = getenv( "MAUG_MIDI_DOS" );
2397
2398 /* Return MERROR_OK since this isn't fatal and will just cause sound
2399 * init to fail later.
2400 */
2401 maug_cleanup_if_null_msg(
2402 char*, env_var, MERROR_OK, "MAUG_MIDI_DOS variable not found!" );
2403
2404 debug_printf( 2, "env: MAUG_MIDI_DOS: %s", env_var );
2405
2406 /* Turn comma separator into NULL split. */
2407 for( i = 0 ; maug_strlen( env_var ) > i ; i++ ) {
2408 if( ',' == env_var[i] ) {
2409 /* Split into two null-terminated strings. */
2410 env_var[i] = '\0';
2411 }
2412 }
2413
2414 if( 0 == strcmp( env_var, "mpu" ) ) {
2415 debug_printf( 3, "selecting MIDI driver: mpu" );
2416 args->snd_driver = 2;
2417 } else if( 0 == strcmp( env_var, "gus" ) ) {
2418 debug_printf( 3, "selecting MIDI driver: gus" );
2419 args->snd_driver = 4;
2420 } else if( 0 == strcmp( env_var, "adlib" ) ) {
2421 debug_printf( 3, "selecting MIDI driver: adlib" );
2422 args->snd_driver = 8;
2423 }
2424 /* TODO: Maug replacement for C99 crutch. */
2425 args->snd_io_base = strtoul( &(env_var[i]), NULL, 16 );
2426 debug_printf( 3, "setting MIDI I/O base: %u", args->snd_io_base );
2427 } else {
2428 /* default */
2429 debug_printf( 3, "default MIDI driver: adlib" );
2430 args->snd_driver = 8;
2431 args->snd_io_base = 0x388;
2432 }
2433
2434# elif defined( RETROSND_API_ALSA )
2435 if( 0 == args->snd_client ) {
2436 env_var = getenv( "MAUG_MIDI_ALSA" );
2437
2438 /* Return MERROR_OK since this isn't fatal and will just cause sound
2439 * init to fail later.
2440 */
2441 maug_cleanup_if_null_msg(
2442 char*, env_var, MERROR_OK, "MAUG_MIDI_ALSA variable not found!" );
2443
2444 debug_printf( 2, "env: MAUG_MIDI_ALSA: %s", env_var );
2445
2446 for( i = 0 ; maug_strlen( env_var ) > i ; i++ ) {
2447 if( ':' == env_var[i] ) {
2448 /* Split into two null-terminated strings. */
2449 env_var[i] = '\0';
2450 }
2451 }
2452
2453 args->snd_client = atoi( env_var );
2454 args->snd_port = atoi( &(env_var[i]) );
2455 debug_printf( 3, "setting MIDI device to: %u:%u",
2456 args->snd_client, args->snd_port );
2457 }
2458
2459# elif defined( RETROSND_API_WINMM )
2460 env_var = getenv( "MAUG_MIDI_WIN" );
2461
2462 /* Return MERROR_OK since this isn't fatal and will just cause sound
2463 * init to fail later.
2464 */
2465 maug_cleanup_if_null_msg(
2466 char*, env_var, MERROR_OK, "MAUG_MIDI_WIN variable not found!" );
2467
2468 debug_printf( 2, "env: MAUG_MIDI_WIN: %s", env_var );
2469
2470 if( NULL != env_var ) {
2471 args->snd_dev_id = atoi( env_var );
2472 } else {
2473 args->snd_dev_id = 0;
2474 }
2475 debug_printf( 3, "setting MIDI device to: %u", args->snd_dev_id );
2476
2477# endif /* RETROSND_API_PC_BIOS || RETROSND_API_ALSA || RETROSND_API_WINMM */
2478 } else if(
2479 0 == strncmp( MAUG_CLI_SIGIL "rsd", arg, MAUG_CLI_SIGIL_SZ + 4 )
2480 ) {
2481 /* The next arg must be the new var. */
2482 } else {
2483# ifdef RETROSND_API_PC_BIOS
2484 /* TODO: Parse device. */
2485# elif defined( RETROSND_API_ALSA )
2486 /* TODO: Parse device. */
2487# elif defined( RETROSND_API_WINMM )
2488 debug_printf( 3, "setting MIDI device to rsd arg: %s", arg );
2489 args->snd_dev_id = atoi( arg );
2490# endif /* RETROSND_API_PC_BIOS || RETROSND_API_ALSA || RETROSND_API_WINMM */
2491 }
2492
2493# if defined( RETROSND_API_PC_BIOS ) || defined( RETROSND_API_ALSA )
2494cleanup:
2495# elif defined( RETROSND_API_ALSA )
2496cleanup:
2497# elif defined( RETROSND_API_WINMM )
2498cleanup:
2499# endif /* RETROSND_API_PC_BIOS || RETROSND_API_ALSA */
2500
2501 return retval;
2502}
2503
2504# endif /* RETROSND_ARGS */
2505
2506# if !defined( RETROFLAT_API_PC_BIOS ) && !defined( RETROFLAT_NO_CLI_SZ )
2507
2508static MERROR_RETVAL retroflat_cli_rfs(
2509 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2510) {
2511 if( 0 < arg_c ) {
2512 g_retroflat_state->scale = atoi( arg );
2513 debug_printf( 3, "screen scale set to: %d",
2514 g_retroflat_state->scale );
2515 }
2516 return MERROR_OK;
2517}
2518
2519static MERROR_RETVAL retroflat_cli_rfx(
2520 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2521) {
2522 if( 0 > arg_c ) {
2523 if( 0 == args->screen_w ) {
2524 args->screen_x = 0;
2525 }
2526 } else if(
2527 0 == strncmp( MAUG_CLI_SIGIL "rfx", arg, MAUG_CLI_SIGIL_SZ + 4 )
2528 ) {
2529 /* The next arg must be the new var. */
2530 } else {
2531 args->screen_x = atoi( arg );
2532 }
2533 return MERROR_OK;
2534}
2535
2536static MERROR_RETVAL retroflat_cli_rfy(
2537 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2538) {
2539 if( 0 > arg_c ) {
2540 if( 0 == args->screen_h ) {
2541 args->screen_y = 0;
2542 }
2543 } else if(
2544 0 == strncmp( MAUG_CLI_SIGIL "rfy", arg, MAUG_CLI_SIGIL_SZ + 4 )
2545 ) {
2546 /* The next arg must be the new var. */
2547 } else {
2548 args->screen_y = atoi( arg );
2549 }
2550 return MERROR_OK;
2551}
2552
2553static MERROR_RETVAL retroflat_cli_rfw(
2554 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2555) {
2556 if( 0 > arg_c ) {
2557 if( 0 == args->screen_w ) {
2558 args->screen_w = RETROFLAT_DEFAULT_SCREEN_W;
2559 }
2560 } else if(
2561 0 == strncmp( MAUG_CLI_SIGIL "rfw", arg, MAUG_CLI_SIGIL_SZ + 4 )
2562 ) {
2563 /* The next arg must be the new var. */
2564 } else {
2565 args->screen_w = atoi( arg );
2566 }
2567 return MERROR_OK;
2568}
2569
2570static MERROR_RETVAL retroflat_cli_rfh(
2571 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2572) {
2573 if( 0 > arg_c ) {
2574 if( 0 == args->screen_h ) {
2575 args->screen_h = RETROFLAT_DEFAULT_SCREEN_H;
2576 }
2577 } else if(
2578 0 == strncmp( MAUG_CLI_SIGIL "rfh", arg, MAUG_CLI_SIGIL_SZ + 4 )
2579 ) {
2580 /* The next arg must be the new var. */
2581 } else {
2582 args->screen_h = atoi( arg );
2583 }
2584 return MERROR_OK;
2585}
2586
2587# endif /* !RETROFLAT_API_PC_BIOS && !RETROFLAT_NO_CLI_SZ */
2588
2589# ifdef RETROFLAT_VDP
2590static MERROR_RETVAL retroflat_cli_vdp(
2591 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2592) {
2593 if( 0 == strncmp( MAUG_CLI_SIGIL "vdp", arg, MAUG_CLI_SIGIL_SZ + 4 ) ) {
2594 /* Next arg is VDP args str. */
2595 } else {
2596 maug_strncpy( g_retroflat_state->vdp_args, arg, RETROFLAT_VDP_ARGS_SZ_MAX );
2597 debug_printf( 1, "VDP args: %s", g_retroflat_state->vdp_args );
2598 }
2599 return MERROR_OK;
2600}
2601# endif /* RETROFLAT_VDP */
2602
2603static MERROR_RETVAL retroflat_cli_u(
2604 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2605) {
2606 if( 0 > arg_c ) {
2607 args->flags &= ~RETROFLAT_FLAGS_UNLOCK_FPS;
2608 } else if(
2609 0 == strncmp( MAUG_CLI_SIGIL "rfu", arg, MAUG_CLI_SIGIL_SZ + 4 )
2610 ) {
2611 debug_printf( 1, "unlocking FPS..." );
2612 args->flags |= RETROFLAT_FLAGS_UNLOCK_FPS;
2613 }
2614 return MERROR_OK;
2615}
2616
2617#endif /* !RETROFLAT_NO_CLI */
2618
2619/* === */
2620
2621/* Still inside RETROFLT_C! */
2622
2623int retroflat_init( int argc, char* argv[], struct RETROFLAT_ARGS* args ) {
2624
2625 /* = Declare Init Vars = */
2626
2627 int retval = 0;
2628
2629 /* = Begin Init Procedure = */
2630
2631# ifdef RETROFLAT_COMMIT_HASH
2632 debug_printf( 1, "retroflat commit: " RETROFLAT_COMMIT_HASH );
2633# endif /* RETROFLAT_COMMIT_HASH */
2634
2635 debug_printf( 1, "retroflat: initializing..." );
2636
2637 /* System sanity checks. */
2638 assert( 2 <= sizeof( MERROR_RETVAL ) );
2639 assert( 4 == sizeof( uint32_t ) );
2640 assert( 4 == sizeof( int32_t ) );
2641 assert( 2 == sizeof( uint16_t ) );
2642 assert( 2 == sizeof( int16_t ) );
2643 assert( 1 == sizeof( uint8_t ) );
2644 assert( 1 == sizeof( int8_t ) );
2645 assert( NULL != args );
2646 assert( 1 << RETROFLAT_TILE_W_BITS == RETROFLAT_TILE_W );
2647 assert( 1 << RETROFLAT_TILE_H_BITS == RETROFLAT_TILE_H );
2648
2649 debug_printf( 1, "retroflat: MFIX_PRECISION: %f", MFIX_PRECISION );
2650
2651 debug_printf( 1, "retroflat: allocating state (" SIZE_T_FMT " bytes)...",
2652 sizeof( struct RETROFLAT_STATE ) );
2653
2654 debug_printf( 1, "retroflat: size_t is (" SIZE_T_FMT " bytes)...",
2655 sizeof( size_t ) );
2656
2657 debug_printf( 1, "retroflat: ssize_t is (" SIZE_T_FMT " bytes)...",
2658 sizeof( ssize_t ) );
2659
2660 debug_printf( 1, "retroflat: off_t is (" SIZE_T_FMT " bytes)...",
2661 sizeof( off_t ) );
2662
2663 g_retroflat_state_h = maug_malloc( 1, sizeof( struct RETROFLAT_STATE ) );
2664 if( (MAUG_MHANDLE)NULL == g_retroflat_state_h ) {
2666 "Error", "Could not allocate global state!" );
2667 retval = MERROR_ALLOC;
2668 goto cleanup;
2669 }
2670
2671 maug_mlock( g_retroflat_state_h, g_retroflat_state );
2672 if( (MAUG_MHANDLE)NULL == g_retroflat_state ) {
2674 "Error", "Could not lock global state!" );
2675 retval = MERROR_ALLOC;
2676 goto cleanup;
2677 }
2678 maug_mzero( g_retroflat_state, sizeof( struct RETROFLAT_STATE ) );
2679
2680 retroflat_heartbeat_set( 1000, 2 );
2681
2682# ifndef RETROFLAT_NO_CLI
2683
2684 debug_printf( 1, "retroflat: parsing args..." );
2685
2686 /* All platforms: add command-line args based on compile definitons. */
2687
2688# ifdef RETROSND_ARGS
2689 retval = maug_add_arg( MAUG_CLI_SIGIL "rsd", MAUG_CLI_SIGIL_SZ + 4,
2690 "Select MIDI device", 0, (maug_cli_cb)retrosnd_cli_rsd, args );
2691 maug_cleanup_if_not_ok();
2692 retval = maug_add_arg( MAUG_CLI_SIGIL "rsl", MAUG_CLI_SIGIL_SZ + 4,
2693 "List MIDI devices", 0, (maug_cli_cb)retrosnd_cli_rsl, args );
2694 maug_cleanup_if_not_ok();
2695# endif /* RETROSND_ARGS */
2696
2697# ifdef RETROFLAT_SCREENSAVER
2698 retval = maug_add_arg( MAUG_CLI_SIGIL "p", MAUG_CLI_SIGIL_SZ + 2,
2699 "Preview screensaver", 0, (maug_cli_cb)retroflat_cli_p, args );
2700 maug_cleanup_if_not_ok();
2701 retval = maug_add_arg( MAUG_CLI_SIGIL "s", MAUG_CLI_SIGIL_SZ + 2,
2702 "Launch screensaver", 0, (maug_cli_cb)retroflat_cli_s, args );
2703 maug_cleanup_if_not_ok();
2704# endif /* RETROFLAT_SCREENSAVER */
2705
2706# ifdef RETROFLAT_API_PC_BIOS
2707 retval = maug_add_arg( MAUG_CLI_SIGIL "rfm", MAUG_CLI_SIGIL_SZ + 4,
2708 "Set the screen mode.", 0,
2709 (maug_cli_cb)retroflat_cli_rfm, args );
2710 maug_cleanup_if_not_ok();
2711# elif !defined( RETROFLAT_NO_CLI_SZ )
2712 /* Set default. */
2713 g_retroflat_state->scale = 1;
2714 retval = maug_add_arg( MAUG_CLI_SIGIL "rfs", MAUG_CLI_SIGIL_SZ + 4,
2715 "Set screen scale factor.", 0,
2716 (maug_cli_cb)retroflat_cli_rfs, args );
2717 maug_cleanup_if_not_ok();
2718 retval = maug_add_arg( MAUG_CLI_SIGIL "rfx", MAUG_CLI_SIGIL_SZ + 4,
2719 "Set the screen X position.", 0,
2720 (maug_cli_cb)retroflat_cli_rfx, args );
2721 maug_cleanup_if_not_ok();
2722 retval = maug_add_arg( MAUG_CLI_SIGIL "rfy", MAUG_CLI_SIGIL_SZ + 4,
2723 "Set the screen Y position.", 0,
2724 (maug_cli_cb)retroflat_cli_rfy, args );
2725 maug_cleanup_if_not_ok();
2726 retval = maug_add_arg( MAUG_CLI_SIGIL "rfw", MAUG_CLI_SIGIL_SZ + 4,
2727 "Set the screen width.", 0,
2728 (maug_cli_cb)retroflat_cli_rfw, args );
2729 maug_cleanup_if_not_ok();
2730 retval = maug_add_arg( MAUG_CLI_SIGIL "rfh", MAUG_CLI_SIGIL_SZ + 4,
2731 "Set the screen height.", 0,
2732 (maug_cli_cb)retroflat_cli_rfh, args );
2733 maug_cleanup_if_not_ok();
2734# endif /* !RETROFLAT_NO_CLI_SZ */
2735
2736# ifdef RETROFLAT_VDP
2737 retval = maug_add_arg( MAUG_CLI_SIGIL "vdp", MAUG_CLI_SIGIL_SZ + 4,
2738 "Pass a string of args to the VDP.", 0,
2739 (maug_cli_cb)retroflat_cli_vdp, args );
2740 maug_cleanup_if_not_ok();
2741# endif /* RETROFLAT_VDP */
2742
2743 retval = maug_add_arg( MAUG_CLI_SIGIL "rfu", MAUG_CLI_SIGIL_SZ + 4,
2744 "Unlock FPS.", 0,
2745 (maug_cli_cb)retroflat_cli_u, args );
2746 maug_cleanup_if_not_ok();
2747
2748 /* Parse command line args. */
2749 retval = maug_parse_args( argc, argv );
2750 maug_cleanup_if_not_ok();
2751
2752# else
2753
2754 args->screen_w = RETROFLAT_DEFAULT_SCREEN_W;
2755 args->screen_h = RETROFLAT_DEFAULT_SCREEN_H;
2756
2757# endif /* !RETROFLAT_NO_CLI */
2758
2759 if(
2761 ) {
2762 g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_UNLOCK_FPS;
2763 }
2764
2765 debug_printf( 1, "retroflat: setting config..." );
2766
2767 /* Set the assets path. */
2768 memset( g_retroflat_state->assets_path, '\0', RETROFLAT_ASSETS_PATH_MAX );
2769 if( NULL != args->assets_path ) {
2770 maug_strncpy( g_retroflat_state->assets_path,
2772 }
2773
2774# if defined( RETROFLAT_SCREENSAVER )
2775 if(
2777 (RETROFLAT_FLAGS_SCREENSAVER & args->flags)
2778 ) {
2779 g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_SCREENSAVER;
2780 }
2781# endif /* RETROFLAT_SCREENSAVER */
2782
2783# if !defined( RETROFLAT_NO_CLI_SZ )
2784 /* Setup intended screen size. */
2785 g_retroflat_state->screen_v_w = args->screen_w;
2786 g_retroflat_state->screen_v_h = args->screen_h;
2787 g_retroflat_state->screen_w = args->screen_w;
2788 g_retroflat_state->screen_h = args->screen_h;
2789# endif /* RETROFLAT_NO_CLI_SZ */
2790
2791 /* == Platform-Specific Init == */
2792
2793 retval = retroflat_init_platform( argc, argv, args );
2794 maug_cleanup_if_not_ok();
2795
2796 debug_printf( 3, "screen initialized with: " SIZE_T_FMT "x" SIZE_T_FMT
2797 " pixels with " SIZE_T_FMT " colors",
2798 retroflat_screen_w(), retroflat_screen_h(), retroflat_screen_colors() );
2799
2800 /* Setup the refresh grid, if requested, only after screen space has been
2801 * determined by the platform!
2802 */
2803 assert( 0 < retroflat_screen_w() );
2804 assert( 0 < retroflat_screen_h() );
2805 assert( 0 < retroflat_screen_colors() );
2806
2807 /* This is intended as a default and can be modified by calling this macro
2808 * again later.
2809 */
2810 retroflat_viewport_set_pos_size(
2812
2813#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
2814 debug_printf( 1, "allocating refresh grid (%d tiles...)",
2815 g_retroflat_state->viewport.screen_tile_w *
2816 g_retroflat_state->viewport.screen_tile_h );
2817 g_retroflat_state->viewport.refresh_grid_h = maug_malloc(
2818 (g_retroflat_state->viewport.screen_tile_w + 2) *
2819 (g_retroflat_state->viewport.screen_tile_h + 2),
2820 sizeof( retroflat_tile_t ) );
2821 maug_cleanup_if_null_alloc( MAUG_MHANDLE,
2822 g_retroflat_state->viewport.refresh_grid_h );
2823#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
2824
2825# ifdef RETROFLAT_VDP
2826# if defined( RETROFLAT_OS_UNIX )
2827 g_retroflat_state->vdp_exe = dlopen(
2828 "./" RETROFLAT_VDP_LIB_NAME ".so", RTLD_LAZY );
2829# elif defined( RETROFLAT_OS_WIN )
2830 g_retroflat_state->vdp_exe = LoadLibrary(
2831 "./" RETROFLAT_VDP_LIB_NAME ".dll" );
2832# else
2833# error "dlopen undefined!"
2834# endif /* RETROFLAT_OS_UNIX */
2835
2836 if( !(g_retroflat_state->vdp_exe) ) {
2837 error_printf( "not loading VDP" );
2838 /* Skip creating the buffer or trying to run the init proc. */
2839 goto skip_vdp;
2840 }
2841
2842 /* Create intermediary screen buffer. */
2843 debug_printf( 1, "creating VDP buffer, " SIZE_T_FMT " x " SIZE_T_FMT,
2844 g_retroflat_state->screen_v_w, g_retroflat_state->screen_v_h );
2845 g_retroflat_state->vdp_buffer =
2846 calloc( 1, sizeof( struct RETROFLAT_BITMAP ) );
2847 maug_cleanup_if_null_alloc(
2848 struct RETROFLAT_BITMAP*, g_retroflat_state->vdp_buffer );
2849 retval = retroflat_create_bitmap(
2850 g_retroflat_state->screen_v_w, g_retroflat_state->screen_v_h,
2851 g_retroflat_state->vdp_buffer, RETROFLAT_FLAGS_OPAQUE );
2852 maug_cleanup_if_not_ok();
2853
2854 debug_printf( 1, "initializing VDP..." );
2855 retval = retroflat_vdp_call( "retroflat_vdp_init" );
2856
2857skip_vdp:
2858
2859# endif /* RETROFLAT_VDP */
2860
2861# ifdef RETROFLAT_3D
2862 retro3d_platform_init();
2863# endif /* RETROFLAT_3D */
2864
2865# if !defined( RETROFLAT_NO_BLANK_INIT ) && !defined( RETROFLAT_3D )
2866 retroflat_draw_lock( NULL );
2868 NULL, RETROFLAT_COLOR_BLACK, 0, 0,
2871 retroflat_draw_release( NULL );
2872# endif /* !RETROFLAT_NO_BLANK_INIT */
2873
2874cleanup:
2875
2876 return retval;
2877}
2878
2879/* === */
2880
2881void retroflat_shutdown( int retval ) {
2882
2883 debug_printf( 1, "retroflat shutdown called..." );
2884
2885#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
2886 if( (MAUG_MHANDLE)NULL != g_retroflat_state->viewport.refresh_grid_h ) {
2887 maug_mfree( g_retroflat_state->viewport.refresh_grid_h );
2888 }
2889#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
2890
2891# if defined( RETROFLAT_VDP )
2892 if( NULL != g_retroflat_state->vdp_exe ) {
2893 retroflat_vdp_call( "retroflat_vdp_shutdown" );
2894# ifdef RETROFLAT_OS_UNIX
2895 dlclose( g_retroflat_state->vdp_exe );
2896# elif defined( RETROFLAT_OS_WIN )
2897 FreeLibrary( g_retroflat_state->vdp_exe );
2898# else
2899# error "dlclose undefined!"
2900# endif /* RETROFLAT_OS_UNIX || RETROFLAT_OS_WIN */
2901 }
2902
2903 if( NULL != g_retroflat_state->vdp_buffer ) {
2904 debug_printf( 1, "destroying VPD buffer..." );
2905 retroflat_destroy_bitmap( g_retroflat_state->vdp_buffer );
2906 free( g_retroflat_state->vdp_buffer );
2907 }
2908# endif /* RETROFLAT_VDP */
2909
2910 /* === Platform-Specific Shutdown === */
2911
2912#ifdef RETROFLAT_3D
2913 retro3d_platform_shutdown();
2914#endif /* RETROFLAT_3D */
2915
2916 retroflat_shutdown_platform( retval );
2917
2918 maug_munlock( g_retroflat_state_h, g_retroflat_state );
2919 maug_mfree( g_retroflat_state );
2920
2921}
2922
2923/* === */
2924
2925# ifdef RETROFLAT_VDP
2926
2927MERROR_RETVAL retroflat_vdp_call( const char* proc_name ) {
2928 MERROR_RETVAL retval = MERROR_OK;
2930# ifdef RETROFLAT_OS_WIN
2931 char proc_name_ex[256];
2932# endif /* RETROFLAT_OS_WIN */
2933
2934 if( NULL == g_retroflat_state->vdp_exe ) {
2935 goto cleanup;
2936 }
2937
2938# ifdef RETROFLAT_OS_UNIX
2939 vdp_proc = dlsym( g_retroflat_state->vdp_exe, proc_name );
2940# elif defined( RETROFLAT_OS_WIN )
2941 /* Append a _ to the proc_name because Watcom? Windows? */
2942 maug_snprintf( proc_name_ex, 255, "%s_", proc_name );
2943 vdp_proc = (retroflat_vdp_proc_t)GetProcAddress(
2944 g_retroflat_state->vdp_exe, proc_name_ex );
2945# else
2946# error "dlsym undefined!"
2947# endif
2948 if( (retroflat_vdp_proc_t)NULL == vdp_proc ) {
2949 goto cleanup;
2950 }
2951
2952# ifdef RETROFLAT_OS_WIN
2953 retroflat_draw_lock( g_retroflat_state->vdp_buffer );
2954# endif /* RETROFLAT_OS_WIN */
2955
2956 if(
2957 /* Don't pxlock before init can set the flag! */
2958 0 == strcmp( "retroflat_vdp_flip", proc_name ) &&
2960 (RETROFLAT_VDP_FLAG_PXLOCK & g_retroflat_state->vdp_flags)
2961 ) {
2962 retroflat_vdp_lock( &(g_retroflat_state->buffer) );
2963 retroflat_vdp_lock( g_retroflat_state->vdp_buffer );
2964 }
2965
2966 retval = vdp_proc( g_retroflat_state );
2967
2968 if(
2969 0 == strcmp( "retroflat_vdp_flip", proc_name ) &&
2971 (RETROFLAT_VDP_FLAG_PXLOCK & g_retroflat_state->vdp_flags)
2972 ) {
2973 retroflat_vdp_release( &(g_retroflat_state->buffer) );
2974 retroflat_vdp_release( g_retroflat_state->vdp_buffer );
2975 }
2976
2977# ifdef RETROFLAT_OS_WIN
2978 retroflat_draw_release( g_retroflat_state->vdp_buffer );
2979# endif /* RETROFLAT_OS_WIN */
2980
2981cleanup:
2982 return retval;
2983}
2984
2985# endif /* RETROFLAT_VDP */
2986
2987/* === */
2988
2989#if 0
2990
2991void retroflat_cursor( struct RETROFLAT_BITMAP* target, uint8_t flags ) {
2992#if 0
2993 char mouse_str[11] = "";
2994
2995 maug_snprintf(
2996 mouse_str, 10, "%02d, %02d", g_retroflat_state->last_mouse_x, g_retroflat_state->last_mouse_y );
2997
2999 target, RETROFLAT_COLOR_BLACK,
3000 mouse_str, 10, NULL, 0, 0, 0 );
3002 target, RETROFLAT_COLOR_BLACK,
3003 g_retroflat_state->last_mouse_x - 5, g_retroflat_state->last_mouse_y - 5, 10, 10, 0 );
3004#endif
3005}
3006
3007#endif
3008
3009/* === */
3010
3012 retroflat_proc_resize_t on_resize_in, void* data_in
3013) {
3014 g_retroflat_state->on_resize = on_resize_in;
3015 g_retroflat_state->on_resize_data = data_in;
3016}
3017
3018/* === */
3019
3020uint8_t retroflat_viewport_move_x_generic( int16_t x ) {
3021 int16_t new_world_x = g_retroflat_state->viewport.world_x + x;
3022
3023 /* Keep the viewport in the world arena. */
3024 if(
3025 0 <= new_world_x &&
3026 g_retroflat_state->viewport.world_w >= new_world_x +
3027 g_retroflat_state->viewport.screen_w
3028 ) {
3029 g_retroflat_state->viewport.world_x += x;
3030 g_retroflat_state->viewport.world_tile_x += x >> RETROFLAT_TILE_W_BITS;
3031 return 1;
3032 }
3033
3034 return 0;
3035}
3036
3037/* === */
3038
3039uint8_t retroflat_viewport_move_y_generic( int16_t y ) {
3040 int16_t new_world_y = g_retroflat_state->viewport.world_y + y;
3041
3042 /* Keep the viewport in the world arena. */
3043 if(
3044 0 <= new_world_y &&
3045 g_retroflat_state->viewport.world_h >= new_world_y +
3046 g_retroflat_state->viewport.screen_h
3047 ) {
3048 g_retroflat_state->viewport.world_y += y;
3049 g_retroflat_state->viewport.world_tile_y += y >> RETROFLAT_TILE_H_BITS;
3050 return 1;
3051 }
3052
3053 return 0;
3054}
3055
3056/* === */
3057
3058uint8_t retroflat_viewport_focus_generic(
3059 size_t x1, size_t y1, size_t range, size_t speed
3060) {
3061 uint8_t moved = 0,
3062 new_moved = 0;
3063 int16_t new_pt = 0;
3064
3065# define _retroflat_viewport_focus_dir( n, xy, wh, gl, pm, dir, range, speed ) \
3066 new_pt = n - retroflat_viewport_world_ ## xy(); \
3067 if( new_pt gl (retroflat_screen_ ## wh() >> 1) pm range ) { \
3068 new_moved = retroflat_viewport_move_ ## xy( \
3069 gc_retroflat_offsets8_ ## xy[RETROFLAT_DIR8_ ## dir] * speed ); \
3070 if( !moved && new_moved ) { \
3071 moved = new_moved; \
3072 } \
3073 }
3074
3075 _retroflat_viewport_focus_dir( x1, x, w, <, -, WEST, range, speed );
3076 _retroflat_viewport_focus_dir( x1, x, w, >, +, EAST, range, speed );
3077 _retroflat_viewport_focus_dir( y1, y, h, <, -, NORTH, range, speed );
3078 _retroflat_viewport_focus_dir( y1, y, h, >, +, SOUTH, range, speed );
3079
3080 return moved;
3081}
3082
3083/* === */
3084
3085#elif !defined( RETROVDP_C ) /* End of RETROFLT_C */
3086
3091
3092extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8];
3093extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y[8];
3094extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x[4];
3095extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y[4];
3096
3098
3099#define RETROFLAT_COLOR_TABLE_CONSTS( idx, name_l, name_u, r, g, b, cgac, cgad ) \
3100 extern MAUG_CONST RETROFLAT_COLOR RETROFLAT_COLOR_ ## name_u;
3101
3102RETROFLAT_COLOR_TABLE( RETROFLAT_COLOR_TABLE_CONSTS )
3103
3104extern MAUG_CONST char* SEG_MCONST gc_retroflat_color_names[];
3105
3106 extern struct RETROFLAT_STATE* g_retroflat_state;
3107# if defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
3108 extern HINSTANCE g_retroflat_instance;
3109 extern int g_retroflat_cmd_show;
3110# endif /* RETROFLAT_API_WIN16 || RETROFLAT_API_WIN32 */
3111
3112# if (defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES ) || \
3113 defined( RETROFLAT_3D ))
3114# define RETROSOFT_PRESENT
3115# endif
3116
3117# ifdef RETROFLAT_3D
3118# include <retro3dp.h>
3119# include <retro3d.h>
3120# include <retro3du.h>
3121# endif /* RETROFLAT_3D */
3122
3123# ifdef RETROSOFT_PRESENT
3124# include <retrosft.h>
3125# endif /* RETROFLAT_SOFT_SHAPES */
3126
3134
3135#endif /* RETROFLT_C */
3136
3137#ifdef RETROFLAT_XPM
3138#include <retroxpm.h>
3139#endif /* RETROFLAT_XPM */
3140
3141#ifdef RETROVDP_C
3142
3143/* Declarations for VDP sources. */
3144
3145#endif /* RETROVDP_C */
3146 /* maug_retroflt */
3148
3149#endif /* RETROFLT_H */
3150
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:771
#define RETROFLAT_BITMAP_EXT
The filename suffix to be appended with a "." to filenames passed to retroflat_load_bitmap()....
Definition retroflt.h:578
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:325
#define RETROFLAT_COLOR_TABLE(f)
This macro defines all colors supported by RetroFlat for primative operations, particularly using ret...
Definition retroflt.h:306
#define RETROFLAT_VDP_ARGS_SZ_MAX
Definition retroflt.h:721
#define RETROFLAT_ASSETS_PATH_MAX
Maximum size of the assets path, to allow room for appending.
Definition retroflt.h:746
#define RETROFLAT_PATH_SEP
The valid path separator on the target platform.
Definition retroflt.h:742
void(* retroflat_px_cb)(retroflat_blit_t *target, const RETROFLAT_COLOR color_idx, size_t x, size_t y, uint8_t flags)
Type of callback function used to produce pixels on a surface.
Definition retroflt.h:1148
#define retroflat_heartbeat_update()
Check and update RETROFLAT_STATE::heartbeat_frame. This should be called in the API HAL on every iter...
Definition retroflt.h:1661
void retroflat_shutdown(int retval)
Deinitialize RetroFlat and its underlying layers. This should be called once at the end of the progra...
retroflat_px_cb g_retroflat_px
Directly addressable callback to produce pixels on a surface.
#define retroflat_heartbeat_set(len, max)
Set parameters for the RETROFLAT_STATE::heartbeat_frame.
Definition retroflt.h:1645
void retroflat_resize_v()
Platform-specific function to resize virtual screen to match physical window size.
size_t retroflat_pxxy_t
Type used for surface pixel coordinates.
Definition retroflt.h:1011
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 RETROFLAT_FLAGS_LITERAL_PATH
Flag for retroflat_load_bitmap() to not use assets path.
Definition retroflt.h:392
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:379
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:373
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:433
#define RETROFLAT_FLAGS_UNLOCK_FPS
Flag indicating FPS should not be capped.
Definition retroflt.h:421
#define RETROFLAT_FLAGS_RUNNING
Flag indicating that retroflat_loop() should continue executing.
Definition retroflt.h:415
#define RETROFLAT_FLAGS_WAIT_FOR_FPS
Do not execute any more inter-frame loops until next frame.
Definition retroflt.h:438
RETROFLAT_IN_KEY retroflat_poll_input(struct RETROFLAT_INPUT *input)
Poll input devices (keyboard/mouse) and return the latest event.
#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:456
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:508
#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:495
void(* retroflat_loop_iter)(void *data)
Prototype for the main loop function passed to retroflat_loop().
Definition retroflt.h:792
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.
int16_t retroflat_tile_t
Value for an individual tile in a RETROTILE_LAYER.
Definition retroflt.h:19
#define retroflat_screen_h()
Get the current screen height in pixels.
Definition retpltd.h:38
#define retroflat_screen_w()
Get the current screen width in pixels.
Definition retpltd.h:35
Tools for drawing shape primatives.
Definition retroflt.h:903
Struct containing configuration values for a RetroFlat program.
Definition retroflt.h:1155
char * config_path
Relative path of local config file (if not using registry).
Definition retroflt.h:1165
char * assets_path
Relative path under which bitmap assets are stored.
Definition retroflt.h:1162
int screen_h
Desired screen or window height in pixels.
Definition retroflt.h:1172
char * title
Title to set for the main program Window if applicable on the target platform.
Definition retroflt.h:1160
int screen_y
Desired window Y position in pixels.
Definition retroflt.h:1176
int screen_x
Desired window X position in pixels.
Definition retroflt.h:1174
Platform-specific bitmap structure. retroflat_bitmap_ok() can be used on a pointer to it to determine...
Definition retpltd.h:21
uint8_t flags
Platform-specific bitmap flags.
Definition retpltd.h:25
Struct passed to retroflat_poll_input() to hold return data.
Definition retroflt.h:842
int mouse_y
Y-coordinate of the mouse pointer in pixels if the returned event is a mouse click.
Definition retroflt.h:852
int mouse_x
X-coordinate of the mouse pointer in pixels if the returned event is a mouse click.
Definition retroflt.h:847
Global singleton containing state for the current platform.
Definition retroflt.h:1681
char vdp_args[RETROFLAT_VDP_ARGS_SZ_MAX]
CLI args passed with -vdp to the RetroFlat VDP API.
Definition retroflt.h:1717
size_t screen_h
The screen height as seen by the system, after scaling.
Definition retroflt.h:1743
uint8_t vdp_flags
Flags set by the RetroFlat VDP API.
Definition retroflt.h:1719
size_t screen_v_w
The screen width as seen by our program, before scaling.
Definition retroflt.h:1732
size_t screen_colors
The number of colors the screen is capable of displaying.
Definition retroflt.h:1745
uint8_t retroflat_flags
Global Flags indicating current system status.
Definition retroflt.h:1691
uint8_t heartbeat_max
When RETROFLAT_STATE::heartbeat_frame reaches this value, it will reset to 0.
Definition retroflt.h:1772
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:1704
uint8_t heartbeat_frame
Simple iteration loop that can be used to time e.g. perpetual sprite animations. Modify parameters wi...
Definition retroflt.h:1767
size_t screen_w
The screen width as seen by the system, after scaling.
Definition retroflt.h:1741
struct RETROFLAT_BITMAP buffer
Off-screen buffer bitmap.
Definition retroflt.h:1695
void * vdp_exe
A handle for the loaded RetroFlat VDP API module.
Definition retroflt.h:1709
RETROFLAT_COLOR_DEF palette[RETROFLAT_COLORS_SZ]
Index of available colors, initialized on platform init.
Definition retroflt.h:1779
uint16_t heartbeat_len
Number of ms to stay on current value of RETROFLAT_STATE::heartbeat_frame before incrementing....
Definition retroflt.h:1761
void * vdp_data
Pointer to data defined by the RetroFlat VDP API for its use.
Definition retroflt.h:1715
size_t screen_v_h
The screen height as seen by our program, before scaling.
Definition retroflt.h:1739
The viewport data struct.
Definition retroflt.h:1210
uint16_t screen_w_remainder
Difference between viewport width and screen width in pixels. Should only be retrieved through retrof...
Definition retroflt.h:1265
int16_t screen_x
X position of the viewport in real screen memory in pixels. Should only be retrieved through retrofla...
Definition retroflt.h:1216
uint16_t screen_h_remainder
Difference between viewport height and screen height in pixels. Should only be retrieved through retr...
Definition retroflt.h:1272
retroflat_tile_t * refresh_grid
A grid of tile values representing the last-drawn values on-screen.
Definition retroflt.h:1301
uint16_t screen_h
Viewport height in pixels. Should only be retrieved through retroflat_viewport_screen_w() and set thr...
Definition retroflt.h:1258
int16_t world_w
The width of the entire world tilemap in pixels. Should only be retrieved through retroflat_viewport_...
Definition retroflt.h:1240
int16_t screen_tile_w
The number of tiles across that fit in the viewport. Should only be retrieved through retroflat_viewp...
Definition retroflt.h:1279
int16_t screen_tile_h
The number of tiles high that fit in the viewport. Should only be retrieved through retroflat_viewpor...
Definition retroflt.h:1286
int16_t world_h
The height of the entire world tilemap in pixels. Should only be retrieved through retroflat_viewport...
Definition retroflt.h:1246
int16_t world_y
The Y offset, in pixels, of the viewport on the world tilemap. Should only be retrieved through retro...
Definition retroflt.h:1234
int16_t screen_y
Y position of the viewport in real screen memory in pixels. Should only be retrieved through retrofla...
Definition retroflt.h:1222
uint16_t screen_w
Viewport width in pixels. Should only be retrieved through retroflat_viewport_screen_w() and set thro...
Definition retroflt.h:1252
int16_t world_x
The X offset, in pixels, of the viewport on the world tilemap. Should only be retrieved through retro...
Definition retroflt.h:1228