From 2a901b98ecaf2359338fc7b3bd634bd2c1d3c82c Mon Sep 17 00:00:00 2001 From: indigoparadox Date: Mon, 19 Feb 2024 21:55:16 -0500 Subject: [PATCH] Add XPM support to GXC. --- make/Makexpm.inc | 2 +- src/retroflt.h | 2 +- src/retrogxc.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ src/retroxpm.h | 4 ++-- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/make/Makexpm.inc b/make/Makexpm.inc index 8dbb7255..eb500155 100644 --- a/make/Makexpm.inc +++ b/make/Makexpm.inc @@ -3,7 +3,7 @@ define DIRTOXPMS -$(1)_BITMAPS := $(wildcard $(1)/*) +$(1)_BITMAPS := $(wildcard $(1)/*.bmp) $(2)/$(1)_xpm.h: $$($(1)_BITMAPS) # Add include guard. diff --git a/src/retroflt.h b/src/retroflt.h index fdd03c06..fd8332c3 100644 --- a/src/retroflt.h +++ b/src/retroflt.h @@ -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: diff --git a/src/retrogxc.h b/src/retrogxc.h index d4a5c6df..26e740d0 100644 --- a/src/retrogxc.h +++ b/src/retrogxc.h @@ -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, @@ -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, diff --git a/src/retroxpm.h b/src/retroxpm.h index 96cec518..c22e85f8 100644 --- a/src/retroxpm.h +++ b/src/retroxpm.h @@ -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