BESM6: Have makefile search for one of several potential FONTNAME fonts in several potential FONTPATH directories.

Fix besm6_panel to use FONTFILE when building with SDL 1.2,
Fix besm6_panel compile issues on Windows
Provide FONTFILE name via either -DFONTFILE OR via a #define in a generated besm6_panel_font.h
This commit is contained in:
Mark Pizzolato 2015-01-06 06:48:59 -08:00 committed by Leo Broukhis
parent bd260dd523
commit 703c5697be
2 changed files with 52 additions and 35 deletions

View file

@ -28,6 +28,16 @@
* the sale, use or other dealings in this Software without prior written
* authorization from Leonid Broukhis and Serge Vakulenko.
*/
#if defined (HAVE_LIBSDL)
#if !defined (FONTFILE)
#include "besm6_panel_font.h"
#endif /* !defined (FONTFILE) */
#if !defined (FONTFILE)
#undef HAVE_LIBSDL
#endif /* !defined (FONTFILE) */
#endif /* defined (HAVE_LIBSDL) */
#ifdef HAVE_LIBSDL
#include "besm6_defs.h"
@ -50,7 +60,6 @@
#define QUOTE(x) _QUOTE(x)
/* Data and functions that don't depend on SDL version */
static char *font_path;
static TTF_Font *font_big;
static TTF_Font *font_small;
static SDL_Color foreground;
@ -99,13 +108,14 @@ static void render_utf8 (TTF_Font *font, int x, int y, int halign, char *message
static SDL_Surface *sprite_from_data (int width, int height,
const unsigned char *data)
{
SDL_Surface *sprite, *optimized;
unsigned *s, r, g, b, y, x;
SDL_Surface *sprite;
unsigned *s, r, g, b;
int y, x;
sprite = SDL_CreateRGBSurface (SDL_SWSURFACE,
width, height, DEPTH, 0, 0, 0, 0);
/*
optimized = SDL_DisplayFormat (sprite);
SDL_Surface *optimized = SDL_DisplayFormat (sprite);
SDL_FreeSurface (sprite);
sprite = optimized;
*/
@ -337,7 +347,7 @@ static void draw_brz_static (int top)
/*
* Закрываем графическое окно.
*/
void besm6_close_panel ()
void besm6_close_panel (void)
{
if (! screen)
return;
@ -356,7 +366,7 @@ static SDL_Texture *sdlTexture;
/*
* Начальная инициализация графического окна и шрифтов.
*/
static void init_panel ()
static void init_panel (void)
{
if (sim_switches & SWMASK('Q'))
return;
@ -430,8 +440,10 @@ void (*sim_vm_init)() = init_panel;
/*
* Обновляем графическое окно.
*/
void besm6_draw_panel ()
void besm6_draw_panel (void)
{
SDL_Event event;
if (! screen)
return;
@ -448,7 +460,6 @@ void besm6_draw_panel ()
SDL_RenderPresent (sdlRenderer);
/* Exit SIMH when window closed.*/
SDL_Event event;
if (SDL_PollEvent (&event) && event.type == SDL_QUIT)
longjmp (cpu_halt, SCPE_STOP);
}
@ -458,7 +469,7 @@ void besm6_draw_panel ()
/*
* Начальная инициализация графического окна и шрифтов.
*/
static void init_panel ()
static void init_panel (void)
{
if (sim_switches & SWMASK('Q'))
return;
@ -484,22 +495,12 @@ static void init_panel ()
exit (1);
}
/* Find font file */
if (ftw (FONTPATH1, probe_font, 255) <= 0 &&
ftw (FONTPATH2, probe_font, 255) <= 0 &&
ftw (FONTPATH3, probe_font, 255) <= 0) {
fprintf(stderr, "SDL: couldn't find font %s in directory %s\n",
FONTNAME, FONTPATH1);
besm6_close_panel();
exit (1);
}
/* Open the font file with the requested point size */
font_big = TTF_OpenFont (font_path, 16);
font_small = TTF_OpenFont (font_path, 9);
font_big = TTF_OpenFont (QUOTE(FONTFILE), 16);
font_small = TTF_OpenFont (QUOTE(FONTFILE), 9);
if (! font_big || ! font_small) {
fprintf(stderr, "SDL: couldn't load font %s: %s\n",
FONTNAME, TTF_GetError());
QUOTE(FONTFILE), TTF_GetError());
besm6_close_panel();
exit (1);
}
@ -543,7 +544,7 @@ void besm6_draw_panel ()
#endif /* SDL_MAJOR_VERSION */
#else /* HAVE_LIBSDL */
void besm6_draw_panel ()
void besm6_draw_panel (void)
{
}
#endif /* HAVE_LIBSDL */

View file

@ -1167,25 +1167,41 @@ SSEM_OPT = -I ${SSEMD}
BESM6D = BESM6
BESM6 = ${BESM6D}/besm6_cpu.c ${BESM6D}/besm6_sys.c ${BESM6D}/besm6_mmu.c \
${BESM6D}/besm6_arith.c ${BESM6D}/besm6_disk.c ${BESM6D}/besm6_drum.c \
${BESM6D}/besm6_tty.c ${BESM6D}/besm6_panel.c ${BESM6D}/besm6_printer.c \
${BESM6D}/besm6_punch.c
${BESM6D}/besm6_arith.c ${BESM6D}/besm6_disk.c ${BESM6D}/besm6_drum.c \
${BESM6D}/besm6_tty.c ${BESM6D}/besm6_panel.c ${BESM6D}/besm6_printer.c \
${BESM6D}/besm6_punch.c
ifeq (,$(and ${VIDEO_LDFLAGS}, ${FONTFILE}))
ifneq (,$(and ${VIDEO_LDFLAGS}, $(findstring besm6,$(MAKECMDGOALS))))
$(info ***)
$(info *** BESM-6 video not used: please specify a font file with FONTFILE=pathname to enable the panel display)
$(info ***)
ifneq (,${VIDEO_LDFLAGS})
ifeq (,${FONTFILE})
FONTPATH += /usr/share/fonts /usr/share/fonts/truetype /usr/lib/jvm /System/Library/Frameworks/JavaVM.framework/Versions
FONTNAME += LucidaSansRegular.ttf FreeSans.ttf
$(info font paths are: $(FONTPATH))
$(info font names are: $(FONTNAME))
find_fontfile = $(strip $(firstword $(foreach dir,$(strip $(FONTPATH)),$(wildcard $(dir)/$(1))$(wildcard $(dir)/*/$(1))$(wildcard $(dir)/*/*/$(1))$(wildcard $(dir)/*/*/*/$(1)))))
find_font = $(strip $(firstword $(foreach font,$(strip $(FONTNAME)),$(call find_fontfile,$(font)))))
ifneq (,$(call find_font))
FONTFILE=$(call find_font)
else
$(info ***)
$(info *** BESM-6 video panel disabled.)
$(info *** To enable the panel display please specify one of:)
$(info *** a font path with FONTNAME=path)
$(info *** a font name with FONTNAME=fontname.ttf)
$(info *** a font file with FONTFILE=path/fontname.ttf)
$(info ***)
endif
endif
BESM6_OPT = -I ${BESM6D} -DUSE_INT64
endif
ifeq (,$(and ${VIDEO_LDFLAGS}, ${FONTFILE}))
BESM6_OPT = -I ${BESM6D} -DUSE_INT64
else ifneq (,$(and $(findstring SDL2,${VIDEO_LDFLAGS}),$(call find_include,SDL2/SDL_ttf),$(call find_lib,SDL2_ttf)))
$(info using libSDL2_ttf: $(call find_lib,SDL2_ttf) $(call find_include,SDL2/SDL_ttf))
BESM6_OPT = -I ${BESM6D} -DFONTFILE=${FONTFILE} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL2_ttf
BESM6_OPT = -I ${BESM6D} -DFONTFILE=${FONTFILE} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL2_ttf
else ifneq (,$(and $(call find_include,SDL/SDL_ttf),$(call find_lib,SDL_ttf)))
$(info using libSDL_ttf: $(call find_lib,SDL_ttf) $(call find_include,SDL/SDL_ttf))
BESM6_OPT = -I ${BESM6D} -DFONTFILE=${FONTFILE} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL_ttf
BESM6_OPT = -I ${BESM6D} -DFONTFILE=${FONTFILE} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL_ttf
else
BESM6_OPT = -I ${BESM6D} -DUSE_INT64
BESM6_OPT = -I ${BESM6D} -DUSE_INT64
endif
###