Skip to content

Commit

Permalink
Add XPM support to GXC.
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoparadox committed Feb 20, 2024
1 parent c5f2419 commit 2a901b9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion make/Makexpm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

define DIRTOXPMS

$(1)_BITMAPS := $(wildcard $(1)/*)
$(1)_BITMAPS := $(wildcard $(1)/*.bmp)

$(2)/$(1)_xpm.h: $$($(1)_BITMAPS)
# Add include guard.
Expand Down
2 changes: 1 addition & 1 deletion src/retroflt.h
Original file line number Diff line number Diff line change
Expand Up @@ -5674,7 +5674,7 @@ MERROR_RETVAL retroflat_load_bitmap(
maug_cleanup_if_not_ok();

if( RETROFLAT_FLAGS_OPAQUE != (RETROFLAT_FLAGS_OPAQUE & flags) ) {
retroflat_bitmap_dos_transparency( bmp_out );
retval = retroflat_bitmap_dos_transparency( bmp_out );
}

cleanup:
Expand Down
54 changes: 54 additions & 0 deletions src/retrogxc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void retrogxc_shutdown();

int16_t retrogxc_load_bitmap( retroflat_asset_path res_p, uint8_t flags );

int16_t retrogxc_load_xpm( retroflat_asset_path res_p, uint8_t flags );

int16_t retrogxc_blit_bitmap(
struct RETROFLAT_BITMAP* target, int16_t bitmap_idx,
uint16_t s_x, uint16_t s_y, uint16_t d_x, uint16_t d_y,
Expand Down Expand Up @@ -152,6 +154,58 @@ int16_t retrogxc_load_bitmap( retroflat_asset_path res_p, uint8_t flags ) {

/* === */

#ifdef RETROFLAT_XPM

int16_t retrogxc_load_xpm( retroflat_asset_path res_p, uint8_t flags ) {
int16_t idx = RETROGXC_ERROR_CACHE_MISS,
i = 0;
struct RETROFLAT_CACHE_BITMAP* bitmaps = NULL;

maug_mlock( gs_retrogxc_handle, bitmaps );

/* Try to find the bitmap already in the cache. */
for( i = 0 ; gs_retrogxc_sz > i ; i++ ) {
if( 0 == retroflat_cmp_asset_path( bitmaps[i].id, res_p ) ) {
idx = i;
goto cleanup;
}
}

/* Bitmap not found. */
debug_printf( RETROGXC_TRACE_LVL,
"bitmap %s not found in cache; loading...", res_p );
for( i = 0 ; gs_retrogxc_sz > i ; i++ ) {
if( retroflat_bitmap_ok( &(bitmaps[i].bitmap) ) ) {
continue;
}

if(
MERROR_OK ==
retroflat_load_xpm( res_p, &(bitmaps[i].bitmap), flags )
) {
idx = i;
debug_printf( RETROGXC_TRACE_LVL,
"bitmap %s assigned cache ID: %d", res_p, idx );
}
goto cleanup;
}

/* Still not found! */
error_printf( "unable to load bitmap; cache full?" );

cleanup:

if( NULL != bitmaps ) {
maug_munlock( gs_retrogxc_handle, bitmaps );
}

return idx;
}

/* === */

#endif /* RETROFLAT_XPM */

int16_t retrogxc_blit_bitmap(
struct RETROFLAT_BITMAP* target, int16_t bitmap_idx,
uint16_t s_x, uint16_t s_y, uint16_t d_x, uint16_t d_y,
Expand Down
4 changes: 2 additions & 2 deletions src/retroxpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ MERROR_RETVAL retroflat_load_xpm(

#ifdef RETROFLT_C

extern char* gc_xpm_filenames[];
extern char** gc_xpm_data[];
extern MAUG_CONST char* SEG_MCONST gc_xpm_filenames[];
extern MAUG_CONST char** SEG_MCONST gc_xpm_data[];

MERROR_RETVAL retroflat_load_xpm(
const char* filename, struct RETROFLAT_BITMAP* bmp_out, uint8_t flags
Expand Down

0 comments on commit 2a901b9

Please sign in to comment.