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
5#ifdef RETROFLAT_OPENGL
6# define RETROFLAT_BMP_TEX
7#endif /* RETROFLAT_OPENGL */
8
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 RETROINPUT_TRACE_LVL
284# define RETROINPUT_TRACE_LVL 0
285#endif /* !RETROINPUT_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
384#define RETROFLAT_FLAGS_LITERAL_PATH 0x02
385
390#define RETROFLAT_FLAGS_BITMAP_SILENT 0x04
391
398#define RETROFLAT_FLAGS_ALL_CAPS 0x02
399
406#define RETROFLAT_FLAGS_SCREEN_BUFFER 0x80
407 /* maug_retroflt_drawing */
409
416#define RETROFLAT_FLAGS_RUNNING 0x01
417
423#define RETROFLAT_FLAGS_UNLOCK_FPS 0x02
424
430#define RETROFLAT_FLAGS_KEY_REPEAT 0x04
431
437#define RETROFLAT_FLAGS_SCREENSAVER 0x08
438
443#define RETROFLAT_FLAGS_WAIT_FOR_FPS 0x20
444
451
455#define RETROFLAT_MSG_FLAG_TYPE_MASK 0x07
456
461#define RETROFLAT_MSG_FLAG_ERROR 0x01
462
468#define RETROFLAT_MSG_FLAG_INFO 0x02
469
475#define RETROFLAT_MSG_FLAG_WARNING 0x04
476 /* maug_retroflt_msg_api */
478
479struct RETROFLAT_STATE;
480
492
500#define RETROFLAT_VDP_FLAG_PXLOCK 0x01
501
514 /* maug_retroflt_vdp */
516
517typedef MERROR_RETVAL (*retroflat_proc_resize_t)(
518 uint16_t new_w, uint16_t new_h, void* data );
519
524
525#define RETROSND_ARGS_FLAG_LIST_DEVS 0x01
526
528
554
558#define RETROFLAT_FLAGS_LOCK 0x08
559
560#define RETROFLAT_FLAGS_SCREEN_LOCK 0x02
561
562#define RETROFLAT_FLAGS_BITMAP_RO 0x04
563
569#define RETROFLAT_INSTANCE_NULL (0)
570
575#define retroflat_instance_tile( instance ) \
576 (instance * -1)
577
582#ifndef RETROFLAT_BITMAP_EXT
583# define RETROFLAT_BITMAP_EXT "bmp"
584#endif /* !RETROFLAT_BITMAP_EXT */
585
586#ifndef RETROFLAT_OPENGL_BPP
587# define RETROFLAT_OPENGL_BPP 32
588#endif /* !RETROFLAT_OPENGL_BPP */
589
590#ifndef RETROFLAT_TILE_W
591# define RETROFLAT_TILE_W 16
592#endif /* !RETROFLAT_TILE_W */
593
594#ifndef RETROFLAT_TILE_W_BITS
595# define RETROFLAT_TILE_W_BITS 4
596#endif /* !RETROFLAT_TILE_W_BITS */
597
598#ifndef RETROFLAT_TILE_H
599# define RETROFLAT_TILE_H 16
600#endif /* !RETROFLAT_TILE_H */
601
602#ifndef RETROFLAT_TILE_H_BITS
603# define RETROFLAT_TILE_H_BITS 4
604#endif /* !RETROFLAT_TILE_H_BITS */
605
606/* Transparency background color: black by default, to match Allegro. */
607#ifndef RETROFLAT_TXP_R
613# define RETROFLAT_TXP_R 0x00
614#endif /* !RETROFLAT_TXP_R */
615
616#ifndef RETROFLAT_TXP_G
622# define RETROFLAT_TXP_G 0x00
623#endif /* !RETROFLAT_TXP_G */
624
625#ifndef RETROFLAT_TXP_B
631# define RETROFLAT_TXP_B 0x00
632#endif /* !RETROFLAT_TXP_B */
633
634#ifndef RETROFLAT_TXP_PAL_IDX
635# define RETROFLAT_TXP_PAL_IDX 0
636#endif /* !RETROFLAT_TXP_PAL_IDX */
637 /* maug_retroflt_bitmap */
639
640#ifndef RETROFLAT_DEFAULT_SCREEN_W
641# define RETROFLAT_DEFAULT_SCREEN_W 320
642#endif /* RETROFLAT_DEFAULT_SCREEN_W */
643
644#ifndef RETROFLAT_DEFAULT_SCREEN_H
645# define RETROFLAT_DEFAULT_SCREEN_H 200
646#endif /* RETROFLAT_DEFAULT_SCREEN_H */
647
648#define retroflat_on_resize( w, h ) \
649 g_retroflat_state->screen_w = w; \
650 g_retroflat_state->screen_h = h;
651
656
657#ifndef RETROFLAT_LINE_THICKNESS
662# define RETROFLAT_LINE_THICKNESS 1
663#endif /* !RETROFLAT_LINE_THICKNESS */
664
665#define RETROFLAT_PI 3.14159
666 /* maug_retroflt_drawing */
668
673
674#ifndef RETROFLAT_FPS
679# define RETROFLAT_FPS 30
680#endif /* !RETROFLAT_FPS */
681
682#define retroflat_fps_next() (1000 / RETROFLAT_FPS)
683
684#ifndef RETROFLAT_WINDOW_CLASS
689# define RETROFLAT_WINDOW_CLASS "RetroFlatWindowClass"
690#endif /* !RETROFLAT_WINDOW_CLASS */
691
692#ifndef RETROFLAT_WIN_FRAME_TIMER_ID
697# define RETROFLAT_WIN_FRAME_TIMER_ID 6001
698#endif /* !RETROFLAT_WIN_FRAME_TIMER_ID */
699
700#ifndef RETROFLAT_WIN_LOOP_TIMER_ID
705# define RETROFLAT_WIN_LOOP_TIMER_ID 6002
706#endif /* !RETROFLAT_WIN_LOOP_TIMER_ID */
707
708#ifndef RETROFLAT_MSG_MAX
713# define RETROFLAT_MSG_MAX 4096
714#endif /* !RETROFLAT_MSG_MAX */
715
716#ifndef RETROFLAT_TITLE_MAX
717# define RETROFLAT_TITLE_MAX 255
718#endif /* !RETROFLAT_TITLE_MAX */
719
720#ifndef RETROFLAT_VDP_ARGS_SZ_MAX
724# define RETROFLAT_VDP_ARGS_SZ_MAX 255
725#endif /* !RETROFLAT_VDP_ARGS_SZ_MAX */
726
727#if defined( RETROFLAT_API_SDL2 )
728# if !defined( NO_RETROFLAT_RESIZABLE )
729# define RETROFLAT_WIN_FLAGS SDL_WINDOW_RESIZABLE
730# else
731# define RETROFLAT_WIN_FLAGS 0
732# endif /* !NO_RETROFLAT_RESIZABLE */
733#endif /* RETROFLAT_API_SDL2 */
734
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)
739#endif /* RETROFLAT_API_SDL1 || RETROFLAT_API_SDL2 */
740
741#ifdef RETROFLAT_OS_DOS
742# define RETROFLAT_PATH_SEP '\\'
743#else
745# define RETROFLAT_PATH_SEP '/'
746#endif /* RETROFLAT_OS_DOS */
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
764typedef void (*retroflat_loop_iter)(void* data);
765
771
775#define retroflat_buffer_bksp( buffer, buffer_cur, buffer_sz ) \
776 if( 0 < buffer_cur ) { \
777 if( buffer_cur < buffer_sz ) { \
778 memmove( \
779 &(buffer[(buffer_cur) - 1]), \
780 &(buffer[buffer_cur]), \
781 (buffer_sz) - (buffer_cur) ); \
782 } \
783 buffer_cur--; \
784 buffer_sz--; \
785 buffer[buffer_sz] = '\0'; \
786 }
787
791#define retroflat_buffer_insert( c, buffer, buffer_cur, buffer_sz, buffer_mx ) \
792 if( buffer_sz + 1 < buffer_mx ) { \
793 if( buffer_cur < buffer_sz ) { \
794 memmove( \
795 &(buffer[(buffer_cur) + 1]), \
796 &(buffer[buffer_cur]), \
797 (buffer_sz) - (buffer_cur) ); \
798 } \
799 buffer[buffer_cur] = c; \
800 buffer_cur++; \
801 buffer_sz++; \
802 buffer[buffer_sz] = '\0'; \
803 }
804
805#define RETROFLAT_INPUT_MOD_SHIFT 0x01
806
807#define RETROFLAT_INPUT_MOD_ALT 0x02
808
809#define RETROFLAT_INPUT_MOD_CTRL 0x04
810
811#define RETROFLAT_INPUT_FORCE_UPPER 0x08
812
825 uint8_t key_flags;
826};
827 /* maug_retroflt_input */
829
836
837typedef int8_t retroflat_dir4_t;
838
839typedef int8_t retroflat_dir8_t;
840
841#define RETROFLAT_DIR4_NONE (-1)
842#define RETROFLAT_DIR4_NORTH 0
843#define RETROFLAT_DIR4_EAST 1
844#define RETROFLAT_DIR4_SOUTH 2
845#define RETROFLAT_DIR4_WEST 3
846
847#define RETROFLAT_DIR8_NONE (-1)
848#define RETROFLAT_DIR8_NORTH 0
849#define RETROFLAT_DIR8_EAST 2
850#define RETROFLAT_DIR8_SOUTH 4
851#define RETROFLAT_DIR8_WEST 6
852
853#define retroflat_dir4_rotate_cw( dir ) \
854 ((dir + 1) % 4)
855
856#define retroflat_dir8_reverse( dir ) \
857 ((dir + 4) % 8)
858
859#define retroflat_dir8_bounce( dir ) \
860 ((dir + 2) % 8)
861 /* maug_retroflt_dir */
863
870typedef size_t retroflat_pxxy_t;
871
872#define PXXY_FMT SIZE_T_FMT
873
874struct RETROFLAT_ARGS;
875
876#ifndef RETRO2D_TRACE_LVL
877# define RETRO2D_TRACE_LVL 0
878#endif /* !RETRO2D_TRACE_LVL */
879
880#ifndef RETROFLAT_NO_SOUND
881
909
910#ifndef RETROSND_TRACE_LVL
911# define RETROSND_TRACE_LVL 0
912#endif /* !RETROSND_TRACE_LVL */
913
914#ifndef RETROSND_REG_TRACE_LVL
915# define RETROSND_REG_TRACE_LVL 0
916#endif /* !RETROSND_REG_TRACE_LVL */
917
923
928#define RETROSND_FLAG_INIT 0x01
929 /* maug_retrosnd_flags */
931
932#define RETROSND_VOICE_BREATH 122
933
934#define RETROSND_VOICE_SEASHORE 123
935
936#define RETROSND_VOICE_BIRD_TWEET 124
937
938#define RETROSND_VOICE_PHONE_RING 125
939
940#define RETROSND_VOICE_HELICOPTER 126
941
942#define RETROSND_VOICE_APPLAUSE 127
943
948#define RETROSND_VOICE_GUNSHOT 128
949
950#define RETROSND_CHANNEL_CT 8
951
961
965void retrosnd_set_sf_bank( const char* filename_in );
966
967void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice );
968
969void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val );
970
971void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel );
972
973void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel );
974
975MERROR_RETVAL retrosnd_midi_play_smf( const char* filename );
976
977uint8_t retrosnd_midi_is_playing_smf();
978
979void retrosnd_shutdown();
980 /* maug_retrosnd */
982
983#endif /* !RETROFLAT_NO_SOUND */
984
985/* === Platform-specific APIs === */
986
987/* The first call to these headers should just establish definitions (macros, defines, prototypes,
988 * typedefs, etc). The later call below should then define function bodies.
989 */
990#ifndef RETROFLAT_NO_SOUND
991# include <retapis.h>
992#endif /* !RETROFLAT_NO_SOUND */
993#include <retapii.h>
994
995/* === End platform-specific APIs === */
996
1001
1002# if defined( RETROFLAT_NO_KEYBOARD )
1003# define retroflat_case_key( key, pad ) case pad:
1004# define retroflat_or_key( input, key, pad ) ((input) == (pad))
1005# elif defined( RETROFLAT_NO_PAD )
1006# define retroflat_case_key( key, pad ) case key:
1007# define retroflat_or_key( input, key, pad ) ((input) == (key))
1008# else
1016# define retroflat_case_key( key, pad ) case pad: case key:
1017# define retroflat_or_key( input, key, pad ) \
1018 (((input) == (pad)) || ((input) == (key)))
1019# endif
1020 /* maug_retroflt_input */
1022
1023/* === OS-Specific Includes and Defines === */
1024
1025#if defined( RETROFLAT_OS_WIN ) && !defined( MAUG_WINDOWS_H )
1026# include <windows.h>
1027# define MAUG_WINDOWS_H
1028#endif /* !MAUG_WINDOWS_H */
1029
1030#if defined( RETROFLAT_BMP_TEX ) || defined( DOCUMENTATION )
1031
1033 uint8_t flags;
1034 MAUG_MHANDLE bytes_h;
1035 uint8_t* bytes;
1036 uint32_t bpp;
1037 uint32_t sz;
1038 uint8_t* px;
1039 uint32_t id;
1040 size_t w;
1041 size_t h;
1042};
1043
1044#endif /* RETROFLAT_BMP_TEX */
1045
1046/* TODO: Migrate all platform-specific parts below to retapid.h. */
1047#include <retapid.h>
1048
1049#ifndef retroflat_system_task
1055# define retroflat_system_task()
1056#endif /* !retroflat_system_task */
1057
1058typedef maug_ms_t retroflat_ms_t;
1059
1060#include "retrom2d.h"
1061
1062/* === Structures === */
1063
1064/* TODO: Break the args into API-specific headers. */
1065
1068 uint8_t flags;
1073 char* title;
1078# if !defined( RETROFLAT_NO_CLI_SZ )
1079 int screen_w;
1086 int screen_scale;
1087 int joystick_id;
1088# endif /* RETROFLAT_NO_CLI_SZ */
1089 struct RETROFLAT_PLATFORM_ARGS platform;
1090# ifndef RETROFLAT_NO_SOUND
1091 struct RETROFLAT_SOUND_ARGS sound;
1092# endif /* !RETROFLAT_NO_SOUND */
1093};
1094
1105
1118 int16_t screen_x;
1124 int16_t screen_y;
1130 int16_t world_x;
1136 int16_t world_y;
1142 int16_t world_w;
1148 int16_t world_h;
1154 uint16_t screen_w;
1160 uint16_t screen_h;
1189 int16_t world_tile_x;
1190 int16_t world_tile_y;
1191#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1192 MAUG_MHANDLE refresh_grid_h;
1204#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1205};
1206
1207# define retroflat_screen_colors() (g_retroflat_state->screen_colors)
1208
1209#ifndef DOCUMENTATION
1210
1211# define retroflat_viewport_world_x_generic() \
1212 (g_retroflat_state->viewport.world_x)
1213
1214# define retroflat_viewport_world_y_generic() \
1215 (g_retroflat_state->viewport.world_y)
1216
1217# define retroflat_viewport_world_tile_x_generic() \
1218 (g_retroflat_state->viewport.world_tile_x)
1219
1220# define retroflat_viewport_world_tile_y_generic() \
1221 (g_retroflat_state->viewport.world_tile_y)
1222
1223# define retroflat_viewport_world_w_generic() \
1224 (g_retroflat_state->viewport.world_w)
1225
1226# define retroflat_viewport_world_h_generic() \
1227 (g_retroflat_state->viewport.world_h)
1228
1229# define retroflat_viewport_screen_tile_w_generic() \
1230 (g_retroflat_state->viewport.screen_tile_w)
1231
1232# define retroflat_viewport_screen_tile_h_generic() \
1233 (g_retroflat_state->viewport.screen_tile_h)
1234
1235# define retroflat_viewport_screen_w_generic() \
1236 (g_retroflat_state->viewport.screen_w)
1237
1238# define retroflat_viewport_screen_h_generic() \
1239 (g_retroflat_state->viewport.screen_h)
1240
1241# define retroflat_viewport_screen_w_remainder_generic() \
1242 (g_retroflat_state->viewport.screen_w_remainder)
1243
1244# define retroflat_viewport_screen_h_remainder_generic() \
1245 (g_retroflat_state->viewport.screen_h_remainder)
1246
1247# define retroflat_viewport_set_world_generic( w, h ) \
1248 debug_printf( 1, "setting viewport size to %d x %d...", \
1249 (int16_t)(w), (int16_t)(h) ); \
1250 (g_retroflat_state->viewport.world_w) = w; \
1251 (g_retroflat_state->viewport.world_h) = h;
1252
1253# define retroflat_viewport_set_world_pos_generic( x, y ) \
1254 debug_printf( 1, "setting viewport world pos to %d, %d...", x, y ); \
1255 (g_retroflat_state->viewport.world_x) = x; \
1256 (g_retroflat_state->viewport.world_y) = y; \
1257 (g_retroflat_state->viewport.world_tile_x) = (x) >> RETROFLAT_TILE_W_BITS; \
1258 (g_retroflat_state->viewport.world_tile_y) = (y) >> RETROFLAT_TILE_H_BITS;
1259
1260# define retroflat_viewport_set_pos_size_generic( x_px, y_px, w_px, h_px ) \
1261 g_retroflat_state->viewport.screen_x = (x_px); \
1262 g_retroflat_state->viewport.screen_y = (y_px); \
1263 g_retroflat_state->viewport.screen_tile_w = \
1264 ((w_px) / RETROFLAT_TILE_W); \
1265 g_retroflat_state->viewport.screen_tile_h = \
1266 ((h_px) / RETROFLAT_TILE_H); \
1267 /* We're not adding the extra room here since this won't be used for
1268 * indexing or allocation but rather pixel detection.
1269 */ \
1270 g_retroflat_state->viewport.screen_w = \
1271 ((w_px) / RETROFLAT_TILE_W) * RETROFLAT_TILE_W; \
1272 g_retroflat_state->viewport.screen_h = \
1273 ((h_px) / RETROFLAT_TILE_H) * RETROFLAT_TILE_H; \
1274 g_retroflat_state->viewport.screen_w_remainder = \
1275 (x_px) + (w_px) - g_retroflat_state->viewport.screen_w; \
1276 g_retroflat_state->viewport.screen_h_remainder = \
1277 (y_px) + (h_px) - g_retroflat_state->viewport.screen_h;
1278
1279#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1280
1281# define retroflat_viewport_lock_refresh_generic() \
1282 if( NULL == g_retroflat_state->viewport.refresh_grid ) { \
1283 maug_mlock( \
1284 g_retroflat_state->viewport.refresh_grid_h, \
1285 g_retroflat_state->viewport.refresh_grid ); \
1286 maug_cleanup_if_null_lock( retroflat_tile_t*, \
1287 g_retroflat_state->viewport.refresh_grid ); \
1288 }
1289
1290# define retroflat_viewport_unlock_refresh_generic() \
1291 if( NULL != g_retroflat_state->viewport.refresh_grid ) { \
1292 maug_munlock( \
1293 g_retroflat_state->viewport.refresh_grid_h, \
1294 g_retroflat_state->viewport.refresh_grid ); \
1295 }
1296
1297# define _retroflat_viewport_refresh_tile_x( x_px ) \
1298 (((x_px) + RETROFLAT_TILE_W) >> RETROFLAT_TILE_W_BITS)
1299
1300# define _retroflat_viewport_refresh_tile_y( y_px ) \
1301 (((y_px) + RETROFLAT_TILE_H) >> RETROFLAT_TILE_H_BITS)
1302
1303# define retroflat_viewport_set_refresh_generic( x_px, y_px, tid ) \
1304 assert( NULL != g_retroflat_state->viewport.refresh_grid ); \
1305 if( \
1306 /* Expand the range by -1 to account for just off-screen tile. */ \
1307 -(RETROFLAT_TILE_W) <= x_px && -(RETROFLAT_TILE_H) <= y_px && \
1308 retroflat_screen_w() > x_px && \
1309 retroflat_screen_h() > y_px \
1310 ) { \
1311 assert( 0 < g_retroflat_state->viewport.screen_tile_w ); \
1312 assert( 0 <= (((y_px) + RETROFLAT_TILE_H) >> RETROFLAT_TILE_H_BITS) ); \
1313 assert( 0 <= (((x_px) + RETROFLAT_TILE_W) >> RETROFLAT_TILE_W_BITS) ); \
1314 g_retroflat_state->viewport.refresh_grid[ \
1315 /* Add +1 tile to make off-screen "-1" tile positive. */ \
1316 ((_retroflat_viewport_refresh_tile_y( y_px ) + 1) * \
1317 (g_retroflat_state->viewport.screen_tile_w + 2)) + \
1318 (_retroflat_viewport_refresh_tile_x( x_px ) + 1)] = tid; \
1319 }
1320
1321# define retroflat_viewport_tile_is_stale( x_px, y_px, tile_id ) \
1322 ((tile_id) != \
1323 g_retroflat_state->viewport.refresh_grid[ \
1324 ((_retroflat_viewport_refresh_tile_y( y_px ) + 1) * \
1325 (g_retroflat_state->viewport.screen_tile_w + 2)) + \
1326 (_retroflat_viewport_refresh_tile_x( x_px ) + 1)])
1327
1328#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1329
1330uint8_t retroflat_viewport_move_x_generic( int16_t x );
1331
1332uint8_t retroflat_viewport_move_y_generic( int16_t y );
1333
1334uint8_t retroflat_viewport_focus_generic(
1335 size_t x1, size_t y1, size_t range, size_t speed );
1336
1337# define retroflat_viewport_screen_x_generic( world_x ) \
1338 (g_retroflat_state->viewport.screen_x + \
1339 ((world_x) - retroflat_viewport_world_x()))
1340
1341# define retroflat_viewport_screen_y_generic( world_y ) \
1342 (g_retroflat_state->viewport.screen_y + \
1343 ((world_y) - retroflat_viewport_world_y()))
1344
1345#endif /* !DOCUMENTATION */
1346
1347#if defined( RETROFLAT_SOFT_VIEWPORT ) || defined( DOCUMENTATION )
1348
1349# ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1350 /* These clamp world coordinates to tile borders to allow refresh grid to
1351 * function properly (smooth-scrolling tiles will always be in motion).
1352 */
1353
1358# define retroflat_viewport_world_x() \
1359 ((retroflat_viewport_world_x_generic() \
1360 >> RETROFLAT_TILE_W_BITS) << RETROFLAT_TILE_W_BITS)
1361
1366# define retroflat_viewport_world_y() \
1367 ((retroflat_viewport_world_y_generic() \
1368 >> RETROFLAT_TILE_H_BITS) << RETROFLAT_TILE_H_BITS)
1369# else
1370# define retroflat_viewport_world_x() retroflat_viewport_world_x_generic()
1371# define retroflat_viewport_world_y() retroflat_viewport_world_y_generic()
1372#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1373
1374# define retroflat_viewport_world_tile_x() \
1375 retroflat_viewport_world_tile_x_generic()
1376# define retroflat_viewport_world_tile_y() \
1377 retroflat_viewport_world_tile_y_generic()
1378
1383# define retroflat_viewport_world_w() \
1384 retroflat_viewport_world_w_generic()
1385
1390# define retroflat_viewport_world_h() \
1391 retroflat_viewport_world_h_generic()
1392
1397# define retroflat_viewport_screen_tile_w() \
1398 retroflat_viewport_screen_tile_w_generic()
1399
1404# define retroflat_viewport_screen_tile_h() \
1405 retroflat_viewport_screen_tile_h_generic()
1406
1411# define retroflat_viewport_screen_w() \
1412 retroflat_viewport_screen_w_generic()
1413
1418# define retroflat_viewport_screen_h() \
1419 retroflat_viewport_screen_h_generic()
1420
1426# define retroflat_viewport_screen_w_remainder() \
1427 retroflat_viewport_screen_w_remainder_generic()
1428
1434# define retroflat_viewport_screen_h_remainder() \
1435 retroflat_viewport_screen_h_remainder_generic()
1436
1444# define retroflat_viewport_set_world( w, h ) \
1445 retroflat_viewport_set_world_generic( w, h )
1446
1451# define retroflat_viewport_set_world_pos( x, y ) \
1452 retroflat_viewport_set_world_pos_generic( x, y )
1453
1459# define retroflat_viewport_set_pos_size( x_px, y_px, w_px, h_px ) \
1460 retroflat_viewport_set_pos_size_generic( x_px, y_px, w_px, h_px )
1461
1462#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
1463
1471# define retroflat_viewport_lock_refresh() \
1472 retroflat_viewport_lock_refresh_generic()
1473
1481# define retroflat_viewport_unlock_refresh() \
1482 retroflat_viewport_unlock_refresh_generic()
1483
1495# define retroflat_viewport_set_refresh( x, y, tid ) \
1496 retroflat_viewport_set_refresh_generic( x, y, tid )
1497
1498#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
1499
1512# define retroflat_viewport_focus( x1, y1, range, speed ) \
1513 retroflat_viewport_focus_generic( x1, y1, range, speed )
1514
1519# define retroflat_viewport_screen_x( world_x ) \
1520 retroflat_viewport_screen_x_generic( world_x )
1521
1526# define retroflat_viewport_screen_y( world_y ) \
1527 retroflat_viewport_screen_y_generic( world_y )
1528
1529# ifndef RETROFLAT_VIEWPORT_OVERRIDE_MOVE
1530# define retroflat_viewport_move_x( x ) \
1531 retroflat_viewport_move_x_generic( x )
1532
1533# define retroflat_viewport_move_y( y ) \
1534 retroflat_viewport_move_y_generic( y )
1535# endif /* !RETROFLAT_VIEWPORT_OVERRIDE_MOVE */
1536
1537#endif /* RETROFLAT_SOFT_VIEWPORT || DOCUMENTATION */
1538
1540
1547#define retroflat_heartbeat_set( len, max ) \
1548 g_retroflat_state->heartbeat_max = max; \
1549 g_retroflat_state->heartbeat_len = len;
1550
1555#define retroflat_heartbeat() (g_retroflat_state->heartbeat_frame)
1556
1563#define retroflat_heartbeat_update() \
1564 /* Update the heartbeat animation frame. */ \
1565 if( g_retroflat_state->heartbeat_next <= retroflat_get_ms() ) { \
1566 g_retroflat_state->heartbeat_frame++; \
1567 if( \
1568 g_retroflat_state->heartbeat_frame >= \
1569 g_retroflat_state->heartbeat_max \
1570 ) { \
1571 g_retroflat_state->heartbeat_frame = 0; \
1572 } \
1573 g_retroflat_state->heartbeat_next = \
1574 retroflat_get_ms() + g_retroflat_state->heartbeat_len; \
1575 }
1576
1584 /* TODO: Set this up in the initialization function! */
1585 /* TODO: We probably need more of these. */
1586 size_t sz;
1587 size_t offset_pal;
1588 size_t offset_tex_pal;
1589
1590 void* loop_data;
1591 MERROR_RETVAL retval;
1594 char config_path[MAUG_PATH_SZ_MAX + 1];
1595 char assets_path[MAUG_PATH_SZ_MAX + 1];
1597 struct RETROFLAT_BITMAP buffer;
1598 int scale;
1599
1600# if defined( RETROFLAT_VDP ) || defined( DOCUMENTATION ) || \
1601defined( RETROVDP_C )
1606 struct RETROFLAT_BITMAP* vdp_buffer;
1607# ifdef RETROFLAT_OS_WIN
1608 HMODULE vdp_exe;
1609# else
1611 void* vdp_exe;
1612# endif /* RETROFLAT_OS_WIN */
1621 uint8_t vdp_flags;
1622# endif /* RETROFLAT_VDP || DOCUMENTATION || RETROVDP_C */
1623
1624 /* These are used by VDP so should be standardized/not put in plat-spec! */
1625
1626 struct RETROFLAT_VIEWPORT viewport;
1627
1643 size_t screen_w;
1645 size_t screen_h;
1648
1649 /* WARNING: The VDP requires the state specifier to be the same size
1650 * as the one it was compiled for! Do not modify above here!
1651 */
1652
1653 /* TODO: Put these in a platform-specific struct of some kind to maintain
1654 * consistent state struct size for VDP?
1655 */
1656
1657 retroflat_ms_t heartbeat_next;
1675
1676 retroflat_proc_resize_t on_resize;
1677 void* on_resize_data;
1678
1679#ifndef RETROFLAT_BMP_TEX
1681 RETROFLAT_COLOR_DEF palette[RETROFLAT_COLORS_SZ];
1682#endif /* !RETROFLAT_BMP_TEX */
1683
1684 retroflat_loop_iter loop_iter;
1685 retroflat_loop_iter frame_iter;
1686
1687 struct RETROFLAT_PLATFORM platform;
1688
1689# if defined( RETROFLAT_BMP_TEX )
1690 /* This allows native colors to be used for things like glColor3fv while
1691 * these colors are used to manipulate textures passed through
1692 * retroflat_bitmap_*().
1693 */
1694 RETROFLAT_TEX_COLOR_DEF tex_palette[RETROFLAT_COLORS_SZ];
1695# endif /* RETROFLAT_BMP_TEX */
1696
1697 struct RETROFLAT_INPUT_STATE input;
1698
1699# ifndef RETROFLAT_NO_SOUND
1700 struct RETROFLAT_SOUND_STATE sound;
1701# endif /* !RETROFLAT_NO_SOUND */
1702};
1703
1704/* === Translation Module === */
1705
1706/* Declare the prototypes so that internal functions can call each other. */
1707
1708# ifdef retroflat_loop
1709MERROR_RETVAL retroflat_loop_generic(
1710 retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void* data );
1711# else
1718 retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void* data );
1719# endif /* retroflat_loop */
1720
1725
1733 uint8_t flags, const char* title, const char* format, ... );
1734 /* maug_retroflt_msg_api */
1736
1744MERROR_RETVAL retroflat_init( int argc, char* argv[], struct RETROFLAT_ARGS* args );
1745
1752void retroflat_shutdown( int retval );
1753
1754# if defined( RETROFLAT_VDP ) || defined( DOCUMENTATION )
1759
1763MERROR_RETVAL retroflat_vdp_call( const char* proc_name );
1764 /* maug_retroflt_vdp */
1766# endif /* RETROFLAT_VDP || DOCUMENTATION */
1767
1768RETROFLAT_IN_KEY retroflat_repeat_input(
1769 RETROFLAT_IN_KEY key_out, struct RETROFLAT_INPUT* input,
1770 RETROFLAT_IN_KEY* prev_input, int* prev_delay );
1771
1772void retroflat_set_title( const char* format, ... );
1773
1774retroflat_ms_t retroflat_get_ms();
1775
1776uint32_t retroflat_get_rand();
1777
1778# if !defined( RETROFLAT_NO_KEYBOARD )
1779char retroflat_vk_to_ascii( RETROFLAT_IN_KEY k, uint8_t flags );
1780# endif /* !RETROFLAT_NO_KEYBOARD */
1781
1786
1798 const char* filename, struct RETROFLAT_BITMAP* bmp_out, uint8_t flags );
1799
1800MERROR_RETVAL retroflat_create_bitmap(
1801 size_t w, size_t h, struct RETROFLAT_BITMAP* bmp_out, uint8_t flags );
1802
1808void retroflat_destroy_bitmap( struct RETROFLAT_BITMAP* bitmap );
1809
1826 struct RETROFLAT_BITMAP* target, struct RETROFLAT_BITMAP* src,
1827 size_t s_x, size_t s_y, int16_t d_x, int16_t d_y, size_t w, size_t h,
1828 int16_t instance );
1829
1837#define retroflat_constrain_px( x, y, bmp, retact ) \
1838 if( \
1839 x >= retroflat_bitmap_w( bmp ) || y >= retroflat_bitmap_h( bmp ) \
1840 ) { retact; }
1841 /* maug_retroflt_bitmap */
1843
1848
1858MERROR_RETVAL retroflat_draw_lock( struct RETROFLAT_BITMAP* bmp );
1859
1860MERROR_RETVAL retroflat_draw_release( struct RETROFLAT_BITMAP* bmp );
1861
1862void retroflat_px(
1863 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1864 size_t x, size_t y, uint8_t flags );
1865
1866#ifdef RETROFLAT_SOFT_SHAPES
1867# ifdef RETROFLAT_OPENGL
1868/* Make sure we're not passing NULL to openGL texture drawers... they can't
1869 * handle that!
1870 */
1871# define retroflat_rect( t, c, x, y, w, h, f ) \
1872 assert( NULL != t ); \
1873 retrosoft_rect( t, c, x, y, w, h, f );
1874# define retroflat_ellipse( t, c, x, y, w, h, f ) \
1875 assert( NULL != t ); \
1876 retrosoft_ellipse( t, c, x, y, w, h, f )
1877# else
1878# define retroflat_rect( t, c, x, y, w, h, f ) \
1879 retrosoft_rect( t, c, x, y, w, h, f )
1880# define retroflat_ellipse( t, c, x, y, w, h, f ) \
1881 retrosoft_ellipse( t, c, x, y, w, h, f )
1882# endif /* RETROFLAT_3D */
1883#else
1884
1896 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1897 int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags );
1898
1910 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1911 int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags );
1912
1913#endif /* RETROFLAT_SOFT_SHAPES */
1914
1915#ifdef RETROFLAT_SOFT_LINES
1916# define retroflat_line( t, c, x1, y1, x2, y2, f ) \
1917 retrosoft_line( t, c, x1, y1, x2, y2, f )
1918#else
1919
1932 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1933 int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t flags );
1934
1935#endif /* RETROFLAT_SOFT_LINES */
1936
1937void retroflat_cursor( struct RETROFLAT_BITMAP* target, uint8_t flags );
1938
1952 struct RETROFLAT_BITMAP* target, const char* str, size_t str_sz,
1953 const char* font_str, size_t* w_out, size_t* h_out, uint8_t flags );
1954
1973 struct RETROFLAT_BITMAP* target, const RETROFLAT_COLOR color,
1974 const char* str, int str_sz, const char* font_str, int16_t x_orig, int16_t y_orig,
1975 uint8_t flags );
1976
1977/* TODO: Documentation! */
1978void retroflat_get_palette( uint8_t idx, uint32_t* rgb );
1979
1980MERROR_RETVAL retroflat_set_palette( uint8_t idx, uint32_t rgb );
1981 /* maug_retroflt_bitmap */
1983
1994 retroflat_proc_resize_t on_resize_in, void* data_in );
1995
2001
2006
2012RETROFLAT_IN_KEY retroflat_poll_input( struct RETROFLAT_INPUT* input );
2013 /* maug_retroflt_input */
2015
2016#ifdef RETROFLT_C
2017
2018MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8] =
2019 { 0, 1, 1, 1, 0, -1, -1, -1 };
2020MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y[8] =
2021 { -1, -1, 0, 1, 1, 1, 0, -1 };
2022
2023MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x[4] =
2024 { 0, 1, 0, -1 };
2025MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y[4] =
2026 { -1, 0, 1, 0 };
2027
2028MAUG_MHANDLE SEG_MGLOBAL g_retroflat_state_h = (MAUG_MHANDLE)NULL;
2029struct RETROFLAT_STATE* SEG_MGLOBAL g_retroflat_state = NULL;
2030
2031# define RETROFLAT_COLOR_TABLE_CONSTS( idx, name_l, name_u, r, g, b, cgac, cgad ) \
2032 MAUG_CONST RETROFLAT_COLOR SEG_MCONST RETROFLAT_COLOR_ ## name_u = idx;
2033
2034RETROFLAT_COLOR_TABLE( RETROFLAT_COLOR_TABLE_CONSTS )
2035
2036# define RETROFLAT_COLOR_TABLE_NAMES( idx, name_l, name_u, r, g, b, cgac, cgad ) \
2037 #name_u,
2038
2039MAUG_CONST char* SEG_MCONST gc_retroflat_color_names[] = {
2040 RETROFLAT_COLOR_TABLE( RETROFLAT_COLOR_TABLE_NAMES )
2041};
2042
2043/* Callback table is down below, after the statically-defined callbacks. */
2044
2045/* === Function Definitions === */
2046
2047MERROR_RETVAL retroflat_build_filename_path(
2048 const char* filename_in,
2049 char* buffer_out, size_t buffer_out_sz, uint8_t flags
2050) {
2051 MERROR_RETVAL retval = MERROR_OK;
2052
2053 assert( 1 < buffer_out_sz );
2054
2055 /* Build the path to the bitmap. */
2056 maug_mzero( buffer_out, buffer_out_sz );
2057 if(
2060 ) {
2061 /* TODO: Error checking. */
2062 maug_snprintf( buffer_out, buffer_out_sz - 1, "%s", filename_in );
2063 } else {
2064 /* TODO: Error checking. */
2065 maug_snprintf( buffer_out, buffer_out_sz - 1, "%s%c%s.%s",
2066 g_retroflat_state->assets_path, RETROFLAT_PATH_SEP,
2067 filename_in, RETROFLAT_BITMAP_EXT );
2068 }
2069
2070 return retval;
2071}
2072
2073/* === */
2074
2075# if (defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES ) || \
2076 defined( RETROFLAT_3D ))
2077/* RETROSOFT_PRESENT is different from RETROFLAT_SOFT_SHAPES in that it only
2078 * indicates that the retrosoft library is loaded, not that it is the default
2079 * for drawing primatives!
2080 */
2081# define RETROSOFT_PRESENT
2082# endif
2083
2084# if defined( RETROFLAT_3D )
2085# if !defined( MAUG_NO_AUTO_C )
2086# define RETRO3D_C
2087# define RETRO3DP_C
2088# define RETROFP_C
2089# endif /* MAUG_NO_AUTO_C */
2090# include <retro3dp.h>
2091# include <retro3d.h>
2092# include <retro3du.h>
2093# include <retapi3.h>
2094# endif /* RETROFLAT_3D */
2095
2096# ifdef RETROSOFT_PRESENT
2097# if !defined( MAUG_NO_AUTO_C )
2098# define RETROSFT_C
2099# endif /* !MAUG_NO_AUTO_C */
2100# define RETROSOFT_PRESENT
2101# include <retrosft.h>
2102# endif /* RETROFLAT_SOFT_SHAPES */
2103
2104# ifndef RETROFLAT_NO_SOUND
2105# include <retapis.h>
2106# endif /* !RETROFLAT_NO_SOUND */
2107
2108# include <retapii.h>
2109
2110# if defined( RETROFLAT_VDP ) && defined( RETROFLAT_OS_UNIX )
2111# include <dlfcn.h>
2112# endif
2113
2114/* Still inside RETROFLT_C! */
2115
2116/* === */
2117
2118#ifndef RETROFLAT_NO_GENERIC_LOOP
2119
2120MERROR_RETVAL retroflat_loop_generic(
2121 retroflat_loop_iter frame_iter, retroflat_loop_iter loop_iter, void* data
2122) {
2123 MERROR_RETVAL retval = MERROR_OK;
2124 retroflat_ms_t next = 0,
2125 now = 0;
2126
2127 g_retroflat_state->loop_iter = (retroflat_loop_iter)loop_iter;
2128 g_retroflat_state->loop_data = (void*)data;
2129 g_retroflat_state->frame_iter = (retroflat_loop_iter)frame_iter;
2130
2131 if(
2133 (g_retroflat_state->retroflat_flags & RETROFLAT_FLAGS_RUNNING)
2134 ) {
2135 /* Main loop is already running, so we're just changing the iter call
2136 * and leaving!
2137 */
2138 debug_printf( 1, "main loop already running!" );
2139 goto cleanup;
2140 }
2141
2142 g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_RUNNING;
2143 do {
2145
2146 if(
2147 /* Not waiting for the next frame? */
2149 (RETROFLAT_FLAGS_WAIT_FOR_FPS & g_retroflat_state->retroflat_flags) &&
2150 /* Inter-frame loop present? */
2151 NULL != g_retroflat_state->loop_iter
2152 ) {
2153 /* Run the loop iter as many times as possible. */
2154 g_retroflat_state->loop_iter( g_retroflat_state->loop_data );
2155 }
2156 if(
2158 (RETROFLAT_FLAGS_UNLOCK_FPS & g_retroflat_state->retroflat_flags) &&
2159 retroflat_get_ms() < next
2160 ) {
2161 /* Sleep/low power for a bit. */
2162 continue;
2163 }
2164
2166
2167 if( NULL != g_retroflat_state->frame_iter ) {
2168 /* Run the frame iterator once per FPS tick. */
2169 g_retroflat_state->frame_iter( g_retroflat_state->loop_data );
2170 }
2171 /* Reset wait-for-frame flag AFTER frame callback. */
2172 g_retroflat_state->retroflat_flags &= ~RETROFLAT_FLAGS_WAIT_FOR_FPS;
2173 now = retroflat_get_ms();
2174 if( now + retroflat_fps_next() > now ) {
2175 next = now + retroflat_fps_next();
2176 } else {
2177 /* Rollover protection. */
2178 /* TODO: Add difference from now/next to 0 here. */
2179 next = 0;
2180 }
2181 } while(
2183 (RETROFLAT_FLAGS_RUNNING & g_retroflat_state->retroflat_flags)
2184 );
2185 retval = g_retroflat_state->retval;
2186
2187cleanup:
2188
2189 /* This should be set by retroflat_quit(). */
2190 return retval;
2191}
2192
2193#endif /* !RETROFLAT_NO_GENERIC_LOOP */
2194
2195/* === */
2196
2197# if !defined( RETROFLAT_NO_KEYBOARD )
2198
2199char retroflat_vk_to_ascii( RETROFLAT_IN_KEY k, uint8_t flags ) {
2200 char c = 0;
2201 char offset_lower = 0;
2202
2203 if( RETROFLAT_INPUT_MOD_SHIFT != (RETROFLAT_INPUT_MOD_SHIFT & flags) ) {
2204 /* Shift is *not* being held down. */
2205
2206 if( RETROFLAT_KEY_A <= k && RETROFLAT_KEY_Z >= k ) {
2207 if(
2208 RETROFLAT_INPUT_FORCE_UPPER !=
2209 (RETROFLAT_INPUT_FORCE_UPPER & flags)
2210 ) {
2211 /* Key is alphabetical and we're not forcing uppercase. */
2212 offset_lower = 0x20;
2213 }
2214 } else {
2215 offset_lower = 1;
2216 }
2217 }
2218
2219 switch( k ) {
2220 case RETROFLAT_KEY_A: c = 0x41 + offset_lower; break;
2221 case RETROFLAT_KEY_B: c = 0x42 + offset_lower; break;
2222 case RETROFLAT_KEY_C: c = 0x43 + offset_lower; break;
2223 case RETROFLAT_KEY_D: c = 0x44 + offset_lower; break;
2224 case RETROFLAT_KEY_E: c = 0x45 + offset_lower; break;
2225 case RETROFLAT_KEY_F: c = 0x46 + offset_lower; break;
2226 case RETROFLAT_KEY_G: c = 0x47 + offset_lower; break;
2227 case RETROFLAT_KEY_H: c = 0x48 + offset_lower; break;
2228 case RETROFLAT_KEY_I: c = 0x49 + offset_lower; break;
2229 case RETROFLAT_KEY_J: c = 0x4a + offset_lower; break;
2230 case RETROFLAT_KEY_K: c = 0x4b + offset_lower; break;
2231 case RETROFLAT_KEY_L: c = 0x4c + offset_lower; break;
2232 case RETROFLAT_KEY_M: c = 0x4d + offset_lower; break;
2233 case RETROFLAT_KEY_N: c = 0x4e + offset_lower; break;
2234 case RETROFLAT_KEY_O: c = 0x4f + offset_lower; break;
2235 case RETROFLAT_KEY_P: c = 0x50 + offset_lower; break;
2236 case RETROFLAT_KEY_Q: c = 0x51 + offset_lower; break;
2237 case RETROFLAT_KEY_R: c = 0x52 + offset_lower; break;
2238 case RETROFLAT_KEY_S: c = 0x53 + offset_lower; break;
2239 case RETROFLAT_KEY_T: c = 0x54 + offset_lower; break;
2240 case RETROFLAT_KEY_U: c = 0x55 + offset_lower; break;
2241 case RETROFLAT_KEY_V: c = 0x56 + offset_lower; break;
2242 case RETROFLAT_KEY_W: c = 0x57 + offset_lower; break;
2243 case RETROFLAT_KEY_X: c = 0x58 + offset_lower; break;
2244 case RETROFLAT_KEY_Y: c = 0x59 + offset_lower; break;
2245 case RETROFLAT_KEY_Z: c = 0x60 + offset_lower; break;
2246 case RETROFLAT_KEY_0: c = offset_lower ? 0x30 : ')'; break;
2247 case RETROFLAT_KEY_1: c = offset_lower ? 0x31 : '!'; break;
2248 case RETROFLAT_KEY_2: c = offset_lower ? 0x32 : '@'; break;
2249 case RETROFLAT_KEY_3: c = offset_lower ? 0x33 : '#'; break;
2250 case RETROFLAT_KEY_4: c = offset_lower ? 0x34 : '$'; break;
2251 case RETROFLAT_KEY_5: c = offset_lower ? 0x35 : '%'; break;
2252 case RETROFLAT_KEY_6: c = offset_lower ? 0x36 : '^'; break;
2253 case RETROFLAT_KEY_7: c = offset_lower ? 0x37 : '&'; break;
2254 case RETROFLAT_KEY_8: c = offset_lower ? 0x38 : '*'; break;
2255 case RETROFLAT_KEY_9: c = offset_lower ? 0x39 : '('; break;
2256 case RETROFLAT_KEY_SPACE: c = ' '; break;
2257 case RETROFLAT_KEY_BKSP: c = 0x08; break;
2258 case RETROFLAT_KEY_ENTER: c = '\n'; break;
2259 case RETROFLAT_KEY_SEMICOLON: c = offset_lower ? ';' : ':'; break;
2260 case RETROFLAT_KEY_DASH: c = offset_lower ? '-' : '_'; break;
2261 case RETROFLAT_KEY_SLASH: c = offset_lower ? '/' : '?'; break;
2262 case RETROFLAT_KEY_PERIOD: c = offset_lower ? '.' : '>'; break;
2263 case RETROFLAT_KEY_COMMA: c = offset_lower ? ',' : '<'; break;
2264 case RETROFLAT_KEY_QUOTE: c = offset_lower ? '\'' : '"'; break;
2265 case RETROFLAT_KEY_EQUALS: c = offset_lower ? '=' : '+'; break;
2266 case RETROFLAT_KEY_BACKSLASH: c = offset_lower ? '\\' : '|'; break;
2267 case RETROFLAT_KEY_BRACKETL: c = offset_lower ? '[' : '{'; break;
2268 case RETROFLAT_KEY_BRACKETR: c = offset_lower ? ']' : '}'; break;
2269#ifndef RETROFLAT_API_PC_BIOS
2270 /* TODO: FIXME in DOS! */
2271 case RETROFLAT_KEY_GRAVE: c = offset_lower ? '`' : '~'; break;
2272#endif /* !RETROFLAT_API_PC_BIOS */
2273 }
2274
2275 debug_printf( RETROINPUT_TRACE_LVL, "0x%02x", c );
2276
2277 return c;
2278}
2279
2280#endif /* !RETROFLAT_NO_KEYBOARD */
2281
2282/* === */
2283
2284/* TODO: Migrate all platform-specific parts below to retapif.h. */
2285#include <retapif.h>
2286
2287/* === */
2288
2289# ifndef RETROFLAT_NO_CLI
2290
2291# if !defined( RETROFLAT_NO_SOUND ) && defined( RETROSND_ARGS )
2292
2293static MERROR_RETVAL retrosnd_cli_rsl(
2294 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2295) {
2296 if(
2297 0 <= arg_c &&
2298 0 == strncmp( MAUG_CLI_SIGIL "rsl", arg, MAUG_CLI_SIGIL_SZ + 4 )
2299 ) {
2300 args->sound.flags |= RETROSND_ARGS_FLAG_LIST_DEVS;
2301 }
2302 return MERROR_OK;
2303}
2304
2305# endif /* !RETROFLAT_NO_SOUND && RETROSND_ARGS */
2306
2307# if !defined( RETROFLAT_API_PC_BIOS ) && !defined( RETROFLAT_NO_CLI_SZ )
2308
2309static MERROR_RETVAL retroflat_cli_rfs(
2310 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2311) {
2312 if( 1 < arg_c ) {
2313 args->screen_scale = atoi( arg );
2314 debug_printf( 3, "screen scale arg set to: %d", args->screen_scale );
2315 }
2316 return MERROR_OK;
2317}
2318
2319static MERROR_RETVAL retroflat_cli_rfx(
2320 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2321) {
2322 if( 0 > arg_c ) {
2323 if( 0 == args->screen_w ) {
2324 args->screen_x = 0;
2325 }
2326 } else if(
2327 0 == strncmp( MAUG_CLI_SIGIL "rfx", arg, MAUG_CLI_SIGIL_SZ + 4 )
2328 ) {
2329 /* The next arg must be the new var. */
2330 } else {
2331 args->screen_x = atoi( arg );
2332 }
2333 return MERROR_OK;
2334}
2335
2336static MERROR_RETVAL retroflat_cli_rfy(
2337 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2338) {
2339 if( 0 > arg_c ) {
2340 if( 0 == args->screen_h ) {
2341 args->screen_y = 0;
2342 }
2343 } else if(
2344 0 == strncmp( MAUG_CLI_SIGIL "rfy", arg, MAUG_CLI_SIGIL_SZ + 4 )
2345 ) {
2346 /* The next arg must be the new var. */
2347 } else {
2348 args->screen_y = atoi( arg );
2349 }
2350 return MERROR_OK;
2351}
2352
2353static MERROR_RETVAL retroflat_cli_rfw(
2354 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2355) {
2356 if( 0 > arg_c ) {
2357 if( 0 == args->screen_w ) {
2358 args->screen_w = RETROFLAT_DEFAULT_SCREEN_W;
2359 debug_printf( 1, "setting arg screen_w to default %d:",
2360 args->screen_w );
2361 }
2362 } else if(
2363 0 == strncmp( MAUG_CLI_SIGIL "rfw", arg, MAUG_CLI_SIGIL_SZ + 4 )
2364 ) {
2365 /* The next arg must be the new var. */
2366 } else {
2367 args->screen_w = atoi( arg );
2368 debug_printf( 1, "setting arg screen_w to: %d",
2369 args->screen_w );
2370 }
2371 return MERROR_OK;
2372}
2373
2374static MERROR_RETVAL retroflat_cli_rfh(
2375 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2376) {
2377 if( 0 > arg_c ) {
2378 if( 0 == args->screen_h ) {
2379 args->screen_h = RETROFLAT_DEFAULT_SCREEN_H;
2380 debug_printf( 1, "setting arg screen_h to default: %d",
2381 args->screen_h );
2382 }
2383 } else if(
2384 0 == strncmp( MAUG_CLI_SIGIL "rfh", arg, MAUG_CLI_SIGIL_SZ + 4 )
2385 ) {
2386 /* The next arg must be the new var. */
2387 } else {
2388 args->screen_h = atoi( arg );
2389 debug_printf( 1, "setting arg screen_h to: %d",
2390 args->screen_h );
2391 }
2392 return MERROR_OK;
2393}
2394
2395# endif /* !RETROFLAT_API_PC_BIOS && !RETROFLAT_NO_CLI_SZ */
2396
2397# ifdef RETROFLAT_VDP
2398static MERROR_RETVAL retroflat_cli_vdp(
2399 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2400) {
2401 if( 0 == strncmp( MAUG_CLI_SIGIL "vdp", arg, MAUG_CLI_SIGIL_SZ + 4 ) ) {
2402 /* Next arg is VDP args str. */
2403 } else {
2404 maug_strncpy( g_retroflat_state->vdp_args, arg, RETROFLAT_VDP_ARGS_SZ_MAX );
2405 debug_printf( 1, "VDP args: %s", g_retroflat_state->vdp_args );
2406 }
2407 return MERROR_OK;
2408}
2409# endif /* RETROFLAT_VDP */
2410
2411static MERROR_RETVAL retroflat_cli_u(
2412 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2413) {
2414 if( 0 > arg_c ) {
2415 args->flags &= ~RETROFLAT_FLAGS_UNLOCK_FPS;
2416 } else if(
2417 0 == strncmp( MAUG_CLI_SIGIL "rfu", arg, MAUG_CLI_SIGIL_SZ + 4 )
2418 ) {
2419 debug_printf( 1, "unlocking FPS..." );
2420 args->flags |= RETROFLAT_FLAGS_UNLOCK_FPS;
2421 }
2422 return MERROR_OK;
2423}
2424
2425# ifndef RETROFLAT_NO_PAD
2426
2427static MERROR_RETVAL retroflat_cli_rfj(
2428 const char* arg, ssize_t arg_c, struct RETROFLAT_ARGS* args
2429) {
2430 if( 0 > arg_c ) {
2431 args->joystick_id = -1;
2432 debug_printf( 1, "setting arg joystick_id to default: %d",
2433 args->joystick_id );
2434 } else if(
2435 0 == strncmp( MAUG_CLI_SIGIL "rfj", arg, MAUG_CLI_SIGIL_SZ + 4 )
2436 ) {
2437 /* The next arg must be the new var. */
2438 } else {
2439 args->joystick_id = atoi( arg );
2440 debug_printf( 1, "setting arg joystick_id to: %d",
2441 args->joystick_id );
2442 }
2443 return MERROR_OK;
2444}
2445
2446# endif /* !RETROFLAT_NO_PAD */
2447
2448#endif /* !RETROFLAT_NO_CLI */
2449
2450/* === */
2451
2452/* Still inside RETROFLT_C! */
2453
2454int retroflat_init( int argc, char* argv[], struct RETROFLAT_ARGS* args ) {
2455
2456 /* = Declare Init Vars = */
2457
2458 int retval = 0;
2459
2460 /* = Begin Init Procedure = */
2461
2462# ifdef RETROFLAT_COMMIT_HASH
2463 debug_printf( 1, "retroflat commit: " RETROFLAT_COMMIT_HASH );
2464# endif /* RETROFLAT_COMMIT_HASH */
2465
2466 debug_printf( 1, "retroflat: initializing..." );
2467
2468 /* System sanity checks. */
2469 assert( 2 <= sizeof( MERROR_RETVAL ) );
2470 assert( 4 == sizeof( uint32_t ) );
2471 assert( 4 == sizeof( int32_t ) );
2472 assert( 2 == sizeof( uint16_t ) );
2473 assert( 2 == sizeof( int16_t ) );
2474 assert( 1 == sizeof( uint8_t ) );
2475 assert( 1 == sizeof( int8_t ) );
2476 assert( NULL != args );
2477 assert( 1 << RETROFLAT_TILE_W_BITS == RETROFLAT_TILE_W );
2478 assert( 1 << RETROFLAT_TILE_H_BITS == RETROFLAT_TILE_H );
2479
2480 debug_printf( 1, "initializing drawing routines..." );
2481
2482 /* Initialize 2D callbacks depending on if we're in 2D or 3D mode.
2483 * Please see retrom2d.h for more information.
2484 */
2485# if defined( RETROFLAT_BMP_TEX )
2486 retroflat_2d_px = (retroflat_px_cb)retro3d_texture_px;
2487 retroflat_2d_line = (retroflat_line_cb)retrosoft_line;
2488 retroflat_2d_rect = (retroflat_rect_cb)retrosoft_rect;
2489 retroflat_2d_blit_bitmap = (retroflat_blit_bitmap_cb)retro3d_texture_blit;
2490 retroflat_2d_load_bitmap =
2491 (retroflat_load_bitmap_cb)retro3d_texture_load_bitmap;
2492 retroflat_2d_create_bitmap =
2493 (retroflat_create_bitmap_cb)retro3d_texture_create;
2494# else
2495 retroflat_2d_px = (retroflat_px_cb)retroflat_px;
2496# ifdef RETROFLAT_SOFT_SHAPES
2497 /* TODO: Work retrosoft routines to use retroflat_blit_t */
2498 retroflat_2d_line = (retroflat_line_cb)retrosoft_line;
2499 retroflat_2d_rect = (retroflat_rect_cb)retrosoft_rect;
2500# else
2501 retroflat_2d_line = (retroflat_line_cb)retroflat_line;
2502 retroflat_2d_rect = (retroflat_rect_cb)retroflat_rect;
2503# endif /* RETROFLAT_SOFT_SHAPES */
2504 retroflat_2d_blit_bitmap = (retroflat_blit_bitmap_cb)retroflat_blit_bitmap;
2505 retroflat_2d_load_bitmap = (retroflat_load_bitmap_cb)retroflat_load_bitmap;
2506 retroflat_2d_create_bitmap =
2507 (retroflat_create_bitmap_cb)retroflat_create_bitmap;
2508# endif /* RETROFLAT_BMP_TEX */
2509
2510 debug_printf( 1, "retroflat: MFIX_PRECISION: %f", MFIX_PRECISION );
2511
2512 debug_printf( 1, "retroflat: allocating state (" SIZE_T_FMT " bytes)...",
2513 sizeof( struct RETROFLAT_STATE ) );
2514
2515 debug_printf( 1, "retroflat: size_t is (" SIZE_T_FMT " bytes)...",
2516 sizeof( size_t ) );
2517
2518 debug_printf( 1, "retroflat: ssize_t is (" SIZE_T_FMT " bytes)...",
2519 sizeof( ssize_t ) );
2520
2521 debug_printf( 1, "retroflat: off_t is (" SIZE_T_FMT " bytes)...",
2522 sizeof( off_t ) );
2523
2524 debug_printf( 1, "initializing global state..." );
2525
2526 g_retroflat_state_h = maug_malloc( 1, sizeof( struct RETROFLAT_STATE ) );
2527 if( (MAUG_MHANDLE)NULL == g_retroflat_state_h ) {
2529 "Error", "Could not allocate global state!" );
2530 retval = MERROR_ALLOC;
2531 goto cleanup;
2532 }
2533
2534 maug_mlock( g_retroflat_state_h, g_retroflat_state );
2535 if( NULL == g_retroflat_state ) {
2537 "Error", "Could not lock global state!" );
2538 retval = MERROR_ALLOC;
2539 goto cleanup;
2540 }
2541 maug_mzero( g_retroflat_state, sizeof( struct RETROFLAT_STATE ) );
2542
2543 retroflat_heartbeat_set( 1000, 2 );
2544
2545 debug_printf( 1, "initializing platform filesystem..." );
2546 retval = mfile_plt_init();
2547 maug_cleanup_if_not_ok();
2548
2549# ifndef RETROFLAT_NO_CLI
2550
2551 debug_printf( 1, "retroflat: parsing args..." );
2552
2553 /* All platforms: add command-line args based on compile definitons. */
2554
2555 retval = maug_add_arg(
2556 MAUG_CLI_SIGIL "h", MAUG_CLI_SIGIL_SZ + 2, "Display command-line help",
2557 26, maug_cli_h, NULL );
2558
2559# if !defined( RETROFLAT_NO_SOUND ) && defined( RETROSND_ARGS )
2560 retval = maug_add_arg( MAUG_CLI_SIGIL "rsd", MAUG_CLI_SIGIL_SZ + 4,
2561 "Select MIDI device", 0, (maug_cli_cb)retrosnd_cli_rsd, args );
2562 maug_cleanup_if_not_ok();
2563 retval = maug_add_arg( MAUG_CLI_SIGIL "rsl", MAUG_CLI_SIGIL_SZ + 4,
2564 "List MIDI devices", 0, (maug_cli_cb)retrosnd_cli_rsl, args );
2565 maug_cleanup_if_not_ok();
2566# endif /* !RETROFLAT_NO_SOUND && RETROSND_ARGS */
2567
2568# ifdef RETROFLAT_SCREENSAVER
2569 retval = maug_add_arg( MAUG_CLI_SIGIL "p", MAUG_CLI_SIGIL_SZ + 2,
2570 "Preview screensaver", 0, (maug_cli_cb)retroflat_cli_p, args );
2571 maug_cleanup_if_not_ok();
2572 retval = maug_add_arg( MAUG_CLI_SIGIL "s", MAUG_CLI_SIGIL_SZ + 2,
2573 "Launch screensaver", 0, (maug_cli_cb)retroflat_cli_s, args );
2574 maug_cleanup_if_not_ok();
2575# endif /* RETROFLAT_SCREENSAVER */
2576
2577# ifdef RETROFLAT_API_PC_BIOS
2578 retval = maug_add_arg( MAUG_CLI_SIGIL "rfm", MAUG_CLI_SIGIL_SZ + 4,
2579 "Set the screen mode.", 0,
2580 (maug_cli_cb)retroflat_cli_rfm, args );
2581 maug_cleanup_if_not_ok();
2582# elif !defined( RETROFLAT_NO_CLI_SZ )
2583 retval = maug_add_arg( MAUG_CLI_SIGIL "rfs", MAUG_CLI_SIGIL_SZ + 4,
2584 "Set screen scale factor.", 0,
2585 (maug_cli_cb)retroflat_cli_rfs, args );
2586 maug_cleanup_if_not_ok();
2587 retval = maug_add_arg( MAUG_CLI_SIGIL "rfx", MAUG_CLI_SIGIL_SZ + 4,
2588 "Set the screen X position.", 0,
2589 (maug_cli_cb)retroflat_cli_rfx, args );
2590 maug_cleanup_if_not_ok();
2591 retval = maug_add_arg( MAUG_CLI_SIGIL "rfy", MAUG_CLI_SIGIL_SZ + 4,
2592 "Set the screen Y position.", 0,
2593 (maug_cli_cb)retroflat_cli_rfy, args );
2594 maug_cleanup_if_not_ok();
2595 retval = maug_add_arg( MAUG_CLI_SIGIL "rfw", MAUG_CLI_SIGIL_SZ + 4,
2596 "Set the screen width.", 0,
2597 (maug_cli_cb)retroflat_cli_rfw, args );
2598 maug_cleanup_if_not_ok();
2599 retval = maug_add_arg( MAUG_CLI_SIGIL "rfh", MAUG_CLI_SIGIL_SZ + 4,
2600 "Set the screen height.", 0,
2601 (maug_cli_cb)retroflat_cli_rfh, args );
2602 maug_cleanup_if_not_ok();
2603# endif /* !RETROFLAT_NO_CLI_SZ */
2604
2605# ifdef RETROFLAT_VDP
2606 retval = maug_add_arg( MAUG_CLI_SIGIL "vdp", MAUG_CLI_SIGIL_SZ + 4,
2607 "Pass a string of args to the VDP.", 0,
2608 (maug_cli_cb)retroflat_cli_vdp, args );
2609 maug_cleanup_if_not_ok();
2610# endif /* RETROFLAT_VDP */
2611
2612 retval = maug_add_arg( MAUG_CLI_SIGIL "rfu", MAUG_CLI_SIGIL_SZ + 4,
2613 "Unlock FPS.", 0,
2614 (maug_cli_cb)retroflat_cli_u, args );
2615 maug_cleanup_if_not_ok();
2616
2617# ifndef RETROFLAT_NO_PAD
2618 retval = maug_add_arg( MAUG_CLI_SIGIL "rfj", MAUG_CLI_SIGIL_SZ + 4,
2619 "Specify joystick ID to use.", 0,
2620 (maug_cli_cb)retroflat_cli_rfj, args );
2621 maug_cleanup_if_not_ok();
2622# endif /* !RETROFLAT_NO_PAD */
2623
2624 /* Parse command line args. */
2625 retval = maug_parse_args( argc, argv );
2626 maug_cleanup_if_not_ok();
2627
2628# else
2629
2630 if( 0 == args->screen_w ) {
2631 args->screen_w = RETROFLAT_DEFAULT_SCREEN_W;
2632 debug_printf( 1, "setting arg screen_w to default: %d",
2633 args->screen_w );
2634 }
2635 if( 0 == args->screen_h ) {
2636 args->screen_h = RETROFLAT_DEFAULT_SCREEN_H;
2637 debug_printf( 1, "setting arg screen_h to default: %d",
2638 args->screen_h );
2639 }
2640 args->joystick_id = -1;
2641
2642# endif /* !RETROFLAT_NO_CLI */
2643
2644# if !defined( RETROFLAT_NO_CLI_SZ )
2645 /* Set default, so that this is never zero, to avoid division by zero. */
2646 if( 0 < args->screen_scale ) {
2647 debug_printf( 1, "setting screen scale to: %d", args->screen_scale );
2648 g_retroflat_state->scale = args->screen_scale;
2649 } else {
2650 debug_printf( 1, "setting screen scale to default: 1" );
2651 g_retroflat_state->scale = 1;
2652 }
2653# endif /* !RETROFLAT_NO_CLI_SZ */
2654
2655 if(
2657 ) {
2658 g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_UNLOCK_FPS;
2659 }
2660
2661 debug_printf( 1, "retroflat: setting config..." );
2662
2663 /* Set the assets path. */
2664 maug_mzero( g_retroflat_state->assets_path, MAUG_PATH_SZ_MAX + 1 );
2665 if( NULL != args->assets_path ) {
2666 maug_strncpy( g_retroflat_state->assets_path,
2668 }
2669
2670# if defined( RETROFLAT_SCREENSAVER )
2671 if(
2673 (RETROFLAT_FLAGS_SCREENSAVER & args->flags)
2674 ) {
2675 g_retroflat_state->retroflat_flags |= RETROFLAT_FLAGS_SCREENSAVER;
2676 }
2677# endif /* RETROFLAT_SCREENSAVER */
2678
2679# if !defined( RETROFLAT_NO_CLI_SZ )
2680 /* Setup intended screen size. */
2681 g_retroflat_state->screen_v_w = args->screen_w;
2682 g_retroflat_state->screen_v_h = args->screen_h;
2683 g_retroflat_state->screen_w = args->screen_w *
2684 g_retroflat_state->scale;
2685 g_retroflat_state->screen_h = args->screen_h *
2686 g_retroflat_state->scale;
2687# endif /* RETROFLAT_NO_CLI_SZ */
2688
2689 /* == Platform-Specific Init == */
2690
2691 debug_printf( 3, "attempting to initialize platform with: "
2692 SIZE_T_FMT "x" SIZE_T_FMT " pixels (scaled to " SIZE_T_FMT "x" SIZE_T_FMT
2693 ")",
2694 g_retroflat_state->screen_v_w, g_retroflat_state->screen_v_h,
2695 g_retroflat_state->screen_w, g_retroflat_state->screen_h );
2696
2697 retval = retroflat_init_platform( argc, argv, args );
2698 maug_cleanup_if_not_ok();
2699
2700 retval = retroflat_init_input( args );
2701 maug_cleanup_if_not_ok();
2702
2703 debug_printf( 3, "screen initialized with: " SIZE_T_FMT "x" SIZE_T_FMT
2704 " pixels (scaled to " SIZE_T_FMT "x" SIZE_T_FMT
2705 ") with " SIZE_T_FMT " colors",
2706 g_retroflat_state->screen_v_w, g_retroflat_state->screen_v_h,
2707 g_retroflat_state->screen_w, g_retroflat_state->screen_h,
2708 retroflat_screen_colors() );
2709
2710 /* Setup the refresh grid, if requested, only after screen space has been
2711 * determined by the platform!
2712 */
2713 maug_cleanup_if_eq(
2714 (size_t)0, retroflat_screen_w(), SIZE_T_FMT, MERROR_GUI );
2715 maug_cleanup_if_eq(
2716 (size_t)0, retroflat_screen_h(), SIZE_T_FMT, MERROR_GUI );
2717 maug_cleanup_if_eq(
2718 (size_t)0, retroflat_screen_colors(), SIZE_T_FMT, MERROR_GUI );
2719
2720 /* This is intended as a default and can be modified by calling this macro
2721 * again later.
2722 */
2723 retroflat_viewport_set_pos_size(
2724 0, 0, retroflat_screen_w(), retroflat_screen_h() );
2725
2726#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
2727 debug_printf( 1, "allocating refresh grid (%d tiles...)",
2728 g_retroflat_state->viewport.screen_tile_w *
2729 g_retroflat_state->viewport.screen_tile_h );
2730 g_retroflat_state->viewport.refresh_grid_h = maug_malloc(
2731 (g_retroflat_state->viewport.screen_tile_w + 2) *
2732 (g_retroflat_state->viewport.screen_tile_h + 2),
2733 sizeof( retroflat_tile_t ) );
2734 maug_cleanup_if_null_alloc( MAUG_MHANDLE,
2735 g_retroflat_state->viewport.refresh_grid_h );
2736#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
2737
2738# ifdef RETROFLAT_VDP
2739# if defined( RETROFLAT_OS_UNIX )
2740 g_retroflat_state->vdp_exe = dlopen(
2741 "./" RETROFLAT_VDP_LIB_NAME ".so", RTLD_LAZY );
2742# elif defined( RETROFLAT_OS_WIN )
2743 g_retroflat_state->vdp_exe = LoadLibrary(
2744 "./" RETROFLAT_VDP_LIB_NAME ".dll" );
2745# else
2746# error "dlopen undefined!"
2747# endif /* RETROFLAT_OS_UNIX */
2748
2749 if( !(g_retroflat_state->vdp_exe) ) {
2750 error_printf( "not loading VDP" );
2751 /* Skip creating the buffer or trying to run the init proc. */
2752 goto skip_vdp;
2753 }
2754
2755 /* Create intermediary screen buffer. */
2756 debug_printf( 1, "creating VDP buffer, " SIZE_T_FMT " x " SIZE_T_FMT,
2757 g_retroflat_state->screen_v_w, g_retroflat_state->screen_v_h );
2758 g_retroflat_state->vdp_buffer =
2759 calloc( 1, sizeof( struct RETROFLAT_BITMAP ) );
2760 maug_cleanup_if_null_alloc(
2761 struct RETROFLAT_BITMAP*, g_retroflat_state->vdp_buffer );
2762 retval = retroflat_create_bitmap(
2763 g_retroflat_state->screen_v_w, g_retroflat_state->screen_v_h,
2764 g_retroflat_state->vdp_buffer, RETROFLAT_FLAGS_OPAQUE );
2765 maug_cleanup_if_not_ok();
2766
2767 debug_printf( 1, "initializing VDP..." );
2768 retval = retroflat_vdp_call( "retroflat_vdp_init" );
2769
2770skip_vdp:
2771
2772# endif /* RETROFLAT_VDP */
2773
2774# ifdef RETROFLAT_3D
2775 retro3d_platform_init();
2776# endif /* RETROFLAT_3D */
2777
2778# if !defined( RETROFLAT_NO_BLANK_INIT ) && !defined( RETROFLAT_3D )
2779 retroflat_draw_lock( NULL );
2781 NULL, RETROFLAT_COLOR_BLACK, 0, 0,
2782 retroflat_screen_w(), retroflat_screen_h(),
2784 retroflat_draw_release( NULL );
2785# endif /* !RETROFLAT_NO_BLANK_INIT */
2786
2787cleanup:
2788
2789 return retval;
2790}
2791
2792/* === */
2793
2794void retroflat_shutdown( int retval ) {
2795
2796 debug_printf( 1, "retroflat shutdown called..." );
2797
2798#ifndef RETROFLAT_NO_VIEWPORT_REFRESH
2799 if(
2800 NULL != g_retroflat_state &&
2801 (MAUG_MHANDLE)NULL != g_retroflat_state->viewport.refresh_grid_h
2802 ) {
2803 maug_mfree( g_retroflat_state->viewport.refresh_grid_h );
2804 }
2805#endif /* !RETROFLAT_NO_VIEWPORT_REFRESH */
2806
2807# if defined( RETROFLAT_VDP )
2808 if( NULL != g_retroflat_state->vdp_exe ) {
2809 retroflat_vdp_call( "retroflat_vdp_shutdown" );
2810# ifdef RETROFLAT_OS_UNIX
2811 dlclose( g_retroflat_state->vdp_exe );
2812# elif defined( RETROFLAT_OS_WIN )
2813 FreeLibrary( g_retroflat_state->vdp_exe );
2814# else
2815# error "dlclose undefined!"
2816# endif /* RETROFLAT_OS_UNIX || RETROFLAT_OS_WIN */
2817 }
2818
2819 if( NULL != g_retroflat_state->vdp_buffer ) {
2820 debug_printf( 1, "destroying VPD buffer..." );
2821 retroflat_destroy_bitmap( g_retroflat_state->vdp_buffer );
2822 free( g_retroflat_state->vdp_buffer );
2823 }
2824# endif /* RETROFLAT_VDP */
2825
2826 /* === Platform-Specific Shutdown === */
2827
2828#ifdef RETROFLAT_3D
2829 retro3d_platform_shutdown();
2830#endif /* RETROFLAT_3D */
2831
2832 retroflat_shutdown_platform( retval );
2833
2834 maug_munlock( g_retroflat_state_h, g_retroflat_state );
2835 maug_mfree( g_retroflat_state_h );
2836
2837}
2838
2839/* === */
2840
2841RETROFLAT_IN_KEY retroflat_repeat_input(
2842 RETROFLAT_IN_KEY key_out, struct RETROFLAT_INPUT* input,
2843 RETROFLAT_IN_KEY* prev_input, int* prev_delay
2844) {
2845
2846 /* Add a slight debounce for gamepad button repeat. */
2847 if( 0 < (*prev_delay) ) {
2848 debug_printf(
2849 RETROINPUT_TRACE_LVL,
2850 "repeat delay: %d", (*prev_delay) );
2851 (*prev_delay)--;
2852 }
2853
2854 /* If nothing else happened and repeat is enabled and a joypad button is
2855 * down, then emulate repeat for it.
2856 */
2857 if(
2858 0 == key_out &&
2860 (RETROFLAT_FLAGS_KEY_REPEAT & g_retroflat_state->retroflat_flags) &&
2861 /* There is an input to repeat. */
2862 0 != *prev_input &&
2863 /* Delay countdown reached. */
2864 0 == *prev_delay
2865 ) {
2866 key_out = *prev_input;
2867 *prev_delay = 1;
2868 debug_printf( RETROINPUT_TRACE_LVL, "repeat: %d", key_out );
2869 }
2870
2871 return key_out;
2872}
2873
2874/* === */
2875
2876# ifdef RETROFLAT_VDP
2877
2878MERROR_RETVAL retroflat_vdp_call( const char* proc_name ) {
2879 MERROR_RETVAL retval = MERROR_OK;
2881# ifdef RETROFLAT_OS_WIN
2882 char proc_name_ex[256];
2883# endif /* RETROFLAT_OS_WIN */
2884
2885 if( NULL == g_retroflat_state->vdp_exe ) {
2886 goto cleanup;
2887 }
2888
2889# ifdef RETROFLAT_OS_UNIX
2890 vdp_proc = dlsym( g_retroflat_state->vdp_exe, proc_name );
2891# elif defined( RETROFLAT_OS_WIN )
2892 /* Append a _ to the proc_name because Watcom? Windows? */
2893 maug_snprintf( proc_name_ex, 255, "%s_", proc_name );
2894 vdp_proc = (retroflat_vdp_proc_t)GetProcAddress(
2895 g_retroflat_state->vdp_exe, proc_name_ex );
2896# else
2897# error "dlsym undefined!"
2898# endif
2899 if( (retroflat_vdp_proc_t)NULL == vdp_proc ) {
2900 goto cleanup;
2901 }
2902
2903# ifdef RETROFLAT_OS_WIN
2904 retroflat_draw_lock( g_retroflat_state->vdp_buffer );
2905# endif /* RETROFLAT_OS_WIN */
2906
2907 if(
2908 /* Don't pxlock before init can set the flag! */
2909 0 == strcmp( "retroflat_vdp_flip", proc_name ) &&
2911 (RETROFLAT_VDP_FLAG_PXLOCK & g_retroflat_state->vdp_flags)
2912 ) {
2913 retroflat_vdp_lock( &(g_retroflat_state->buffer) );
2914 retroflat_vdp_lock( g_retroflat_state->vdp_buffer );
2915 }
2916
2917 retval = vdp_proc( g_retroflat_state );
2918
2919 if(
2920 0 == strcmp( "retroflat_vdp_flip", proc_name ) &&
2922 (RETROFLAT_VDP_FLAG_PXLOCK & g_retroflat_state->vdp_flags)
2923 ) {
2924 retroflat_vdp_release( &(g_retroflat_state->buffer) );
2925 retroflat_vdp_release( g_retroflat_state->vdp_buffer );
2926 }
2927
2928# ifdef RETROFLAT_OS_WIN
2929 retroflat_draw_release( g_retroflat_state->vdp_buffer );
2930# endif /* RETROFLAT_OS_WIN */
2931
2932cleanup:
2933 return retval;
2934}
2935
2936# endif /* RETROFLAT_VDP */
2937
2938/* === */
2939
2940#if 0
2941
2942void retroflat_cursor( struct RETROFLAT_BITMAP* target, uint8_t flags ) {
2943#if 0
2944 char mouse_str[11] = "";
2945
2946 maug_snprintf(
2947 mouse_str, 10, "%02d, %02d", g_retroflat_state->last_mouse_x, g_retroflat_state->last_mouse_y );
2948
2950 target, RETROFLAT_COLOR_BLACK,
2951 mouse_str, 10, NULL, 0, 0, 0 );
2953 target, RETROFLAT_COLOR_BLACK,
2954 g_retroflat_state->last_mouse_x - 5, g_retroflat_state->last_mouse_y - 5, 10, 10, 0 );
2955#endif
2956}
2957
2958#endif
2959
2960/* === */
2961
2963 retroflat_proc_resize_t on_resize_in, void* data_in
2964) {
2965 g_retroflat_state->on_resize = on_resize_in;
2966 g_retroflat_state->on_resize_data = data_in;
2967}
2968
2969/* === */
2970
2971uint8_t retroflat_viewport_move_x_generic( int16_t x ) {
2972 int16_t new_world_x = g_retroflat_state->viewport.world_x + x;
2973
2974 /* Keep the viewport in the world arena. */
2975 if(
2976 0 <= new_world_x &&
2977 g_retroflat_state->viewport.world_w >= new_world_x +
2978 g_retroflat_state->viewport.screen_w
2979 ) {
2980 g_retroflat_state->viewport.world_x += x;
2981 g_retroflat_state->viewport.world_tile_x += x >> RETROFLAT_TILE_W_BITS;
2982 return 1;
2983 }
2984
2985 return 0;
2986}
2987
2988/* === */
2989
2990uint8_t retroflat_viewport_move_y_generic( int16_t y ) {
2991 int16_t new_world_y = g_retroflat_state->viewport.world_y + y;
2992
2993 /* Keep the viewport in the world arena. */
2994 if(
2995 0 <= new_world_y &&
2996 g_retroflat_state->viewport.world_h >= new_world_y +
2997 g_retroflat_state->viewport.screen_h
2998 ) {
2999 g_retroflat_state->viewport.world_y += y;
3000 g_retroflat_state->viewport.world_tile_y += y >> RETROFLAT_TILE_H_BITS;
3001 return 1;
3002 }
3003
3004 return 0;
3005}
3006
3007/* === */
3008
3009uint8_t retroflat_viewport_focus_generic(
3010 size_t x1, size_t y1, size_t range, size_t speed
3011) {
3012 uint8_t moved = 0,
3013 new_moved = 0;
3014 int16_t new_pt = 0;
3015
3016# define _retroflat_viewport_focus_dir( n, xy, wh, gl, pm, dir, range, speed ) \
3017 new_pt = n - retroflat_viewport_world_ ## xy(); \
3018 if( new_pt gl (retroflat_screen_ ## wh() >> 1) pm range ) { \
3019 new_moved = retroflat_viewport_move_ ## xy( \
3020 gc_retroflat_offsets8_ ## xy[RETROFLAT_DIR8_ ## dir] * speed ); \
3021 if( !moved && new_moved ) { \
3022 moved = new_moved; \
3023 } \
3024 }
3025
3026 _retroflat_viewport_focus_dir( x1, x, w, <, -, WEST, range, speed );
3027 _retroflat_viewport_focus_dir( x1, x, w, >, +, EAST, range, speed );
3028 _retroflat_viewport_focus_dir( y1, y, h, <, -, NORTH, range, speed );
3029 _retroflat_viewport_focus_dir( y1, y, h, >, +, SOUTH, range, speed );
3030
3031 return moved;
3032}
3033
3034/* === */
3035
3036#ifdef RETROFLAT_LOAD_BITMAP_GENERIC
3037
3038/* This is a generic function that uses the callback
3039 * retroflat_load_bitmap_px_cb(), which should be defined by the
3040 * platform-specific API to draw the loaded bitmap onto a native canvas.
3041 */
3042
3044 const char* filename, struct RETROFLAT_BITMAP* bmp_out, uint8_t flags
3045) {
3046 char filename_path[MAUG_PATH_SZ_MAX + 1];
3047 MERROR_RETVAL retval = MERROR_OK;
3048 mfile_t bmp_file;
3049 struct MFMT_STRUCT_BMPFILE header_bmp;
3050 uint8_t bmp_flags = 0;
3051
3052 assert( NULL != bmp_out );
3053 maug_mzero( bmp_out, sizeof( struct RETROFLAT_BITMAP ) );
3054 retval = retroflat_build_filename_path(
3055 filename, filename_path, MAUG_PATH_SZ_MAX + 1, flags );
3056 maug_cleanup_if_not_ok();
3057 debug_printf( 1, "retroflat: loading bitmap: %s", filename_path );
3058
3059 bmp_out->flags = flags;
3060
3061 /* Open the bitmap file. */
3062 retval = mfile_open_read( filename_path, &bmp_file );
3063 maug_cleanup_if_not_ok();
3064
3065 /* mfmt file detection system. */
3066 maug_mzero( &header_bmp, sizeof( struct MFMT_STRUCT_BMPFILE ) );
3067 header_bmp.magic[0] = 'B';
3068 header_bmp.magic[1] = 'M';
3069 header_bmp.info.sz = 40;
3070
3071 retval = mfmt_read_bmp_header(
3072 (struct MFMT_STRUCT*)&header_bmp,
3073 &bmp_file, 0, mfile_get_sz( &bmp_file ), &bmp_flags );
3074 maug_cleanup_if_not_ok();
3075
3076 retval = retroflat_create_bitmap(
3077 header_bmp.info.width, header_bmp.info.height, bmp_out, flags );
3078 maug_cleanup_if_not_ok();
3079
3080 retroflat_draw_lock( bmp_out );
3081
3082 retval = mfmt_read_bmp_px_cb(
3083 (struct MFMT_STRUCT*)&header_bmp,
3084 &bmp_file,
3085 header_bmp.px_offset,
3086 mfile_get_sz( &bmp_file ) - header_bmp.px_offset,
3087 bmp_flags,
3088 retroflat_load_bitmap_px_cb,
3089 bmp_out );
3090 maug_cleanup_if_not_ok();
3091
3092 retroflat_draw_release( bmp_out );
3093
3094cleanup:
3095
3096 mfile_close( &bmp_file );
3097
3098 return retval;
3099}
3100
3101#endif /* RETROFLAT_LOAD_BITMAP_GENERIC */
3102
3103#elif !defined( RETROVDP_C ) /* End of RETROFLT_C */
3104
3109
3110extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8];
3111extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_y[8];
3112extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_x[4];
3113extern MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets4_y[4];
3114
3116
3117#define RETROFLAT_COLOR_TABLE_CONSTS( idx, name_l, name_u, r, g, b, cgac, cgad ) \
3118 extern MAUG_CONST RETROFLAT_COLOR SEG_MCONST RETROFLAT_COLOR_ ## name_u;
3119
3120RETROFLAT_COLOR_TABLE( RETROFLAT_COLOR_TABLE_CONSTS )
3121
3122extern MAUG_CONST char* SEG_MCONST gc_retroflat_color_names[];
3123
3124extern struct RETROFLAT_STATE* SEG_MGLOBAL g_retroflat_state;
3125
3126# if (defined( RETROFLAT_SOFT_SHAPES ) || defined( RETROFLAT_SOFT_LINES ) || \
3127 defined( RETROFLAT_3D ))
3128# define RETROSOFT_PRESENT
3129# endif
3130
3131# ifdef RETROFLAT_3D
3132# include <retro3dp.h>
3133# include <retro3d.h>
3134# include <retro3du.h>
3135# endif /* RETROFLAT_3D */
3136
3137# ifdef RETROSOFT_PRESENT
3138# include <retrosft.h>
3139# endif /* RETROFLAT_SOFT_SHAPES */
3140
3141/* Second retapis.h include for function bodies not needed. */
3142
3143/* Second retapii.h include for function bodies not needed. */
3144
3145#endif /* RETROFLT_C */
3146
3147#ifdef RETROFLAT_XPM
3148#include <retroxpm.h>
3149#endif /* RETROFLAT_XPM */
3150
3151#ifdef RETROVDP_C
3152
3153/* Declarations for VDP sources. */
3154
3155#endif /* RETROVDP_C */
3156 /* maug_retroflt */
3158
3159#endif /* RETROFLT_H */
3160
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
MERROR_RETVAL mfmt_read_bmp_px_cb(struct MFMT_STRUCT *header, mfile_t *p_file_in, uint32_t px_offset, off_t file_sz, uint8_t flags, mfmt_read_1px_cb px_cb, void *px_cb_data)
Read mfmt_bitmap pixels and process them using a callback.
#define MAUG_PATH_SZ_MAX
Maximum size allocated for asset paths.
Definition mfile.h:35
MERROR_RETVAL mfile_open_read(const char *filename, mfile_t *p_file)
Open a file and read it into memory or memory-map it.
void mfile_close(mfile_t *p_file)
Close a file opened with mfile_open_read().
#define RETROFLAT_BITMAP_EXT
The filename suffix to be appended with a "." to filenames passed to retroflat_load_bitmap()....
Definition retroflt.h:583
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 ...
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 ...
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:724
#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:384
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() or retroflat_load_bitmap() to create or load a bitmap without tran...
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 ::RETROFLA...
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.
RETROFLAT_IN_KEY retroflat_poll_input(struct RETROFLAT_INPUT *input)
Poll input devices (keyboard/mouse) and return the latest event.
void retroflat_message(uint8_t flags, const char *title, const char *format,...)
Display a message in a dialog box and/or on stderr.
#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:461
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:513
#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:500
#define RETROFLAT_FLAGS_SCREENSAVER
Flag indicating the current application is running as a screensaver.
Definition retroflt.h:437
#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:1563
void retroflat_shutdown(int retval)
Deinitialize RetroFlat and its underlying layers. This should be called once at the end of the progra...
#define RETROFLAT_FLAGS_UNLOCK_FPS
Flag indicating FPS should not be capped.
Definition retroflt.h:423
#define retroflat_heartbeat_set(len, max)
Set parameters for the RETROFLAT_STATE::heartbeat_frame.
Definition retroflt.h:1547
#define retroflat_system_task()
Platform-specific task that should be called on every iteration of the generic loop....
Definition retroflt.h:1055
void(* retroflat_loop_iter)(void *data)
Prototype for the main loop function passed to retroflat_loop().
Definition retroflt.h:764
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:870
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....
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...
#define RETROFLAT_FLAGS_RUNNING
Flag indicating that retroflat_loop() should continue executing.
Definition retroflt.h:416
#define RETROFLAT_FLAGS_WAIT_FOR_FPS
Do not execute any more inter-frame loops until next frame.
Definition retroflt.h:443
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_KEY_REPEAT
Flag indicating keyboard repeat is enabled.
Definition retroflt.h:430
void retrosoft_rect(retroflat_blit_t *target, const RETROFLAT_COLOR color_idx, int x, int y, int w, int h, uint8_t flags)
Draw a rectangle at the given coordinates, with the given dimensions.
void retrosoft_line(retroflat_blit_t *target, RETROFLAT_COLOR color, int x1, int y1, int x2, int y2, uint8_t flags)
Draw a line from x1, y1 to x2, y2.
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
Lower-level retargetable 3D engine wrapper.
Tools for drawing shape primatives.
Definition mfmt.h:124
Generic image description struct.
Definition mfmt.h:69
Definition retroflt.h:1032
Struct containing configuration values for a RetroFlat program.
Definition retroflt.h:1067
char * config_path
Relative path of local config file (if not using registry).
Definition retroflt.h:1077
char * assets_path
Relative path under which bitmap assets are stored.
Definition retroflt.h:1075
int screen_h
Desired screen or window height in pixels.
Definition retroflt.h:1081
char * title
Title to set for the main program Window if applicable on the target platform.
Definition retroflt.h:1073
int screen_y
Desired window Y position in pixels.
Definition retroflt.h:1085
int screen_x
Desired window X position in pixels.
Definition retroflt.h:1083
Struct passed to retroflat_poll_input() to hold return data.
Definition retroflt.h:814
int mouse_y
Y-coordinate of the mouse pointer in pixels if the returned event is a mouse click.
Definition retroflt.h:824
int mouse_x
X-coordinate of the mouse pointer in pixels if the returned event is a mouse click.
Definition retroflt.h:819
Global singleton containing state for the current platform.
Definition retroflt.h:1583
char vdp_args[RETROFLAT_VDP_ARGS_SZ_MAX]
CLI args passed with -vdp to the RetroFlat VDP API.
Definition retroflt.h:1619
size_t screen_h
The screen height as seen by the system, after scaling.
Definition retroflt.h:1645
uint8_t vdp_flags
Flags set by the RetroFlat VDP API.
Definition retroflt.h:1621
size_t screen_v_w
The screen width as seen by our program, before scaling.
Definition retroflt.h:1634
size_t screen_colors
The number of colors the screen is capable of displaying.
Definition retroflt.h:1647
uint8_t retroflat_flags
maug_retroflt_flags indicating current system status.
Definition retroflt.h:1593
uint8_t heartbeat_max
When RETROFLAT_STATE::heartbeat_frame reaches this value, it will reset to 0.
Definition retroflt.h:1674
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:1606
uint8_t heartbeat_frame
Simple iteration loop that can be used to time e.g. perpetual sprite animations. Modify parameters wi...
Definition retroflt.h:1669
size_t screen_w
The screen width as seen by the system, after scaling.
Definition retroflt.h:1643
struct RETROFLAT_BITMAP buffer
Off-screen buffer bitmap.
Definition retroflt.h:1597
void * vdp_exe
A handle for the loaded RetroFlat VDP API module.
Definition retroflt.h:1611
RETROFLAT_COLOR_DEF palette[RETROFLAT_COLORS_SZ]
Index of available colors, initialized on platform init.
Definition retroflt.h:1681
uint16_t heartbeat_len
Number of ms to stay on current value of RETROFLAT_STATE::heartbeat_frame before incrementing....
Definition retroflt.h:1663
void * vdp_data
Pointer to data defined by the RetroFlat VDP API for its use.
Definition retroflt.h:1617
size_t screen_v_h
The screen height as seen by our program, before scaling.
Definition retroflt.h:1641
The viewport data struct.
Definition retroflt.h:1112
uint16_t screen_w_remainder
Difference between viewport width and screen width in pixels. Should only be retrieved through retrof...
Definition retroflt.h:1167
int16_t screen_x
X position of the viewport in real screen memory in pixels. Should only be retrieved through retrofla...
Definition retroflt.h:1118
uint16_t screen_h_remainder
Difference between viewport height and screen height in pixels. Should only be retrieved through retr...
Definition retroflt.h:1174
retroflat_tile_t * refresh_grid
A grid of tile values representing the last-drawn values on-screen.
Definition retroflt.h:1203
uint16_t screen_h
Viewport height in pixels. Should only be retrieved through retroflat_viewport_screen_w() and set thr...
Definition retroflt.h:1160
int16_t world_w
The width of the entire world tilemap in pixels. Should only be retrieved through retroflat_viewport_...
Definition retroflt.h:1142
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:1181
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:1188
int16_t world_h
The height of the entire world tilemap in pixels. Should only be retrieved through retroflat_viewport...
Definition retroflt.h:1148
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:1136
int16_t screen_y
Y position of the viewport in real screen memory in pixels. Should only be retrieved through retrofla...
Definition retroflt.h:1124
uint16_t screen_w
Viewport width in pixels. Should only be retrieved through retroflat_viewport_screen_w() and set thro...
Definition retroflt.h:1154
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:1130