5#define RETROFLAT_LINE_X 0
6#define RETROFLAT_LINE_Y 1
8#ifndef RETROSOFT_TRACE_LVL
9# define RETROSOFT_TRACE_LVL 0
18void retrosoft_shutdown();
22 int x1,
int y1,
int x2,
int y2, uint8_t flags );
26 int x,
int y,
int w,
int h, uint8_t flags );
28void retrosoft_ellipse(
30 int x,
int y,
int w,
int h, uint8_t flags );
32void retrosoft_ellipse(
34 int x,
int y,
int w,
int h, uint8_t flags );
36void retrosoft_string_sz(
38 const char* font_str,
size_t* w_out,
size_t* h_out, uint8_t flags );
42 const char* str,
size_t str_sz,
const char* font_str,
int x_orig,
int y_orig,
49# ifndef RETROFLAT_NO_STRING
52gc_font_bmps[RETROFLAT_COLORS_SZ][RETROSOFT_SETS_COUNT][RETROSOFT_GLYPHS_COUNT];
57# ifndef RETROFLAT_NO_STRING
66 const char* glyph_dots = gc_font8x8[set_idx][glyph_idx];
69 retval = retroflat_create_bitmap(
70 RETROSOFT_GLYPH_W_SZ, RETROSOFT_GLYPH_H_SZ, bmp, 0 );
71 maug_cleanup_if_not_ok();
77 retroflat_px_lock( bmp );
80 for( y = 0 ; RETROSOFT_GLYPH_H_SZ > y ; y++ ) {
81 for( x = 0 ; RETROSOFT_GLYPH_W_SZ > x ; x++ ) {
82 if( 1 == ((glyph_dots[y] >> x) & 0x01) ) {
83 retroflat_px( bmp, color, x, y, 0 );
88 retroflat_px_release( bmp );
89 retroflat_draw_release( bmp );
108# ifndef RETROFLAT_NO_STRING
113# ifdef RETROSOFT_PRELOAD_COLORS
114 for( h = 0 ; RETROFLAT_COLORS_SZ > h ; h++ ) {
115 debug_printf( RETROSOFT_TRACE_LVL,
116 "loading glyphs in %s...", gc_retroflat_color_names[h] );
118 for( i = 0 ; RETROSOFT_SETS_COUNT > i ; i++ ) {
119 for( j = 0 ; RETROSOFT_GLYPHS_COUNT > j ; j++ ) {
120 debug_printf( RETROSOFT_TRACE_LVL,
121 "loading glyph " SIZE_T_FMT
"...", j );
122 retval = retrosoft_load_glyph( h, i, j, &(gc_font_bmps[h][i][j]) );
123 maug_cleanup_if_not_ok();
126# ifdef RETROSOFT_PRELOAD_COLORS
141void retrosoft_shutdown() {
142# ifndef RETROFLAT_NO_STRING
148 debug_printf( RETROSOFT_TRACE_LVL,
"retrosoft shutdown called..." );
150# ifndef RETROFLAT_NO_STRING
152#ifdef RETROSOFT_PRELOAD_COLORS
153 for( h = 0 ; RETROFLAT_COLORS_SZ > h ; h++ ) {
155 for( i = 0 ; RETROSOFT_SETS_COUNT > i ; i++ ) {
156 for( j = 0 ; RETROSOFT_GLYPHS_COUNT > j ; j++ ) {
157 debug_printf( RETROSOFT_TRACE_LVL,
158 "destroying glyph " SIZE_T_FMT
"...", j );
162#ifdef RETROSOFT_PRELOAD_COLORS
171void retrosoft_line_strategy(
172 int x1,
int y1,
int x2,
int y2,
173 uint8_t* p_for_axis, uint8_t* p_off_axis, int16_t dist[2],
174 int16_t start[2], int16_t end[2], int16_t iter[2],
175 int16_t* p_inc, int16_t* p_delta
179 if( abs( y2 - y1 ) < abs( x2 - x1 ) ) {
181 start[RETROFLAT_LINE_X] = x2;
182 start[RETROFLAT_LINE_Y] = y2;
183 end[RETROFLAT_LINE_X] = x1;
184 end[RETROFLAT_LINE_Y] = y1;
185 *p_for_axis = RETROFLAT_LINE_X;
187 start[RETROFLAT_LINE_X] = x1;
188 start[RETROFLAT_LINE_Y] = y1;
189 end[RETROFLAT_LINE_X] = x2;
190 end[RETROFLAT_LINE_Y] = y2;
191 *p_for_axis = RETROFLAT_LINE_X;
195 start[RETROFLAT_LINE_X] = x2;
196 start[RETROFLAT_LINE_Y] = y2;
197 end[RETROFLAT_LINE_X] = x1;
198 end[RETROFLAT_LINE_Y] = y1;
199 *p_for_axis = RETROFLAT_LINE_Y;
201 start[RETROFLAT_LINE_X] = x1;
202 start[RETROFLAT_LINE_Y] = y1;
203 end[RETROFLAT_LINE_X] = x2;
204 end[RETROFLAT_LINE_Y] = y2;
205 *p_for_axis = RETROFLAT_LINE_Y;
210 *p_off_axis = 1 - *p_for_axis;
211 iter[RETROFLAT_LINE_X] = start[RETROFLAT_LINE_X];
212 iter[RETROFLAT_LINE_Y] = start[RETROFLAT_LINE_Y];
213 dist[RETROFLAT_LINE_X] = end[RETROFLAT_LINE_X] - start[RETROFLAT_LINE_X];
214 dist[RETROFLAT_LINE_Y] = end[RETROFLAT_LINE_Y] - start[RETROFLAT_LINE_Y];
217 *p_delta = (2 * dist[*p_off_axis]) - dist[*p_for_axis];
218 if( 0 > dist[*p_off_axis] ) {
220 dist[*p_off_axis] *= -1;
228#if defined( RETROFLAT_OPENGL ) || \
229 defined( RETROFLAT_API_PC_BIOS ) || \
230 defined( RETROFLAT_SOFT_LINES )
234 int x1,
int y1,
int x2,
int y2, uint8_t
flags
237 uint8_t for_axis = 0,
248 if( NULL == target ) {
252 retroflat_px_lock( target );
254 retrosoft_line_strategy(
256 &for_axis, &off_axis, dist, start, end, iter, &inc, &delta );
259 iter[for_axis] = start[for_axis] ;
260 end[for_axis] > iter[for_axis] ;
272 iter[RETROFLAT_LINE_X], iter[RETROFLAT_LINE_Y], 0 );
277 iter[off_axis] += inc;
278 delta += (2 * (dist[off_axis] - dist[for_axis]));
280 delta += (2 * dist[off_axis]);
284 retroflat_px_release( target );
293 int x,
int y,
int w,
int h, uint8_t
flags
298 if( NULL == target ) {
302 retroflat_px_lock( target );
306 for( y_iter = y ; y_iter < y + h ; y_iter++ ) {
307 for( x_iter = x ; x_iter < x + w ; x_iter++ ) {
309 retroflat_px( target, color_idx, x_iter, y_iter, 0 );
315#ifdef RETROFLAT_SOFT_LINES
316 retrosoft_line( target, color_idx, x, y, x + w, y, 0 );
317 retrosoft_line( target, color_idx, x + w, y, x + w, y + h, 0 );
318 retrosoft_line( target, color_idx, x + w, y + h, x, y + h, 0 );
319 retrosoft_line( target, color_idx, x, y + h, x, y, 0 );
329 retroflat_px_release( target );
334void retrosoft_ellipse(
336 int x,
int y,
int w,
int h, uint8_t
flags
349 if( NULL == target ) {
353 retroflat_px_lock( target );
357 for( i = 100 ; 2 *
RETROFP_PI + 100 > i ; i += 100 ) {
360 px_x1 = x + (w / 2) + retrofp_cos( i_prev, w / 2 );
361 px_y1 = y + (h / 2) + retrofp_sin( i_prev, h / 2 );
362 px_x2 = x + (w / 2) + retrofp_cos( i, w / 2 );
363 px_y2 = y + (h / 2) + retrofp_sin( i, h / 2 );
408 retroflat_px_release( target );
411# ifndef RETROFLAT_NO_STRING
415void retrosoft_string_sz(
417 const char* font_str,
size_t* w_out,
size_t* h_out, uint8_t
flags
421 str_sz = maug_strlen( str );
424 *w_out = RETROSOFT_GLYPH_W_SZ * str_sz;
425 *h_out = RETROSOFT_GLYPH_H_SZ;
430void retrosoft_string(
432 const char* str,
size_t str_sz,
const char* font_str,
int x_orig,
int y_orig,
440 str_sz = maug_strlen( str );
443 for( i = 0 ; str_sz > i ; i++ ) {
445 if(
'\0' == str[i] ) {
450 glyph_idx = str[i] -
' ';
452#if defined( RETROFLAT_API_SDL2 ) && !defined( RETROSOFT_PRELOAD_COLORS )
455 SDL_SetSurfaceColorMod(
456 gc_font_bmps[RETROFLAT_COLOR_WHITE][0][glyph_idx].surface,
457 g_retroflat_state->
palette[color].r,
458 g_retroflat_state->
palette[color].g,
459 g_retroflat_state->
palette[color].b );
461 gc_font_bmps[RETROFLAT_COLOR_WHITE][0][glyph_idx].texture );
462 gc_font_bmps[RETROFLAT_COLOR_WHITE][0][glyph_idx].texture =
463 SDL_CreateTextureFromSurface(
464 g_retroflat_state->
buffer.renderer,
465 gc_font_bmps[RETROFLAT_COLOR_WHITE][0][glyph_idx].surface );
469 target, &(gc_font_bmps[
470#ifdef RETROSOFT_PRELOAD_COLORS
473 RETROFLAT_COLOR_WHITE
475 ][0][glyph_idx]), 0, 0, x, y_orig,
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19
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...
#define RETROFLAT_INSTANCE_NULL
Pass to retroflat_blit_bitmap() instance arg if this is not a sprite (i.e. if it is a background tile...
Definition retroflt.h:567
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:307
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,...
#define RETROFLAT_FLAGS_FILL
Flag for retroflat_rect() or retroflat_ellipse(), indicating drawn shape should be filled.
Definition retroflt.h:355
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 RETROFP_PI
Fixed-point representation of Pi (3.141).
Definition retrofp.h:17
#define retroflat_screen_buffer()
Get the direct screen buffer or the VDP buffer if a VDP is loaded.
Definition retpltd.h:41
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 RETROFLAT_BITMAP buffer
Off-screen buffer bitmap.
Definition retroflt.h:1272
RETROFLAT_COLOR_DEF palette[RETROFLAT_COLORS_SZ]
Index of available colors, initialized on platform init.
Definition retroflt.h:1270