diff options
author | Takamichi Horikawa <takamichiho@gmail.com> | 2017-09-20 23:26:07 +0900 |
---|---|---|
committer | Takamichi Horikawa <takamichiho@gmail.com> | 2017-09-20 23:26:07 +0900 |
commit | aa27f073c63cb8120e9debebb627c6282870397a (patch) | |
tree | 07ecb85419120bbe1804f094ee3824ecf0243c67 | |
parent | 96d11d0e5bd23b6a7128f48dfc6233132c6166c6 (diff) |
fmplayer common: move font.rom loading to common
-rw-r--r-- | common/fmplayer_common.h | 4 | ||||
-rw-r--r-- | common/fmplayer_drumrom.h | 10 | ||||
-rw-r--r-- | common/fmplayer_drumrom_unix.c | 2 | ||||
-rw-r--r-- | common/fmplayer_drumrom_win.c | 2 | ||||
-rw-r--r-- | common/fmplayer_fontrom.h | 9 | ||||
-rw-r--r-- | common/fmplayer_fontrom_unix.c | 48 |
6 files changed, 69 insertions, 6 deletions
diff --git a/common/fmplayer_common.h b/common/fmplayer_common.h index c4f58af..4bd2885 100644 --- a/common/fmplayer_common.h +++ b/common/fmplayer_common.h @@ -18,8 +18,4 @@ void fmplayer_init_work_opna( void *adpcm_ram ); -struct opna_drum; -bool fmplayer_drum_rom_load(struct opna_drum *drum); -bool fmplayer_drum_loaded(void); - #endif // MYON_FMPLAYER_COMMON_H_INCLUDED diff --git a/common/fmplayer_drumrom.h b/common/fmplayer_drumrom.h new file mode 100644 index 0000000..f1c1d2a --- /dev/null +++ b/common/fmplayer_drumrom.h @@ -0,0 +1,10 @@ +#ifndef MYON_FMPLAYER_DRUMROM_H_INCLUDED +#define MYON_FMPLAYER_DRUMROM_H_INCLUDED + +#include <stdbool.h> + +struct opna_drum; +bool fmplayer_drum_rom_load(struct opna_drum *drum); +bool fmplayer_drum_loaded(void); + +#endif // MYON_FMPLAYER_DRUMROM_H_INCLUDED diff --git a/common/fmplayer_drumrom_unix.c b/common/fmplayer_drumrom_unix.c index 9111616..587be20 100644 --- a/common/fmplayer_drumrom_unix.c +++ b/common/fmplayer_drumrom_unix.c @@ -1,4 +1,4 @@ -#include "fmplayer_common.h" +#include "fmplayer_drumrom.h" #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/common/fmplayer_drumrom_win.c b/common/fmplayer_drumrom_win.c index c3c4e36..0021530 100644 --- a/common/fmplayer_drumrom_win.c +++ b/common/fmplayer_drumrom_win.c @@ -1,4 +1,4 @@ -#include "fmplayer_common.h" +#include "fmplayer_drumrom.h" #include "libopna/opnadrum.h" #define WIN32_LEAN_AND_MEAN #include <windows.h> diff --git a/common/fmplayer_fontrom.h b/common/fmplayer_fontrom.h new file mode 100644 index 0000000..7a67133 --- /dev/null +++ b/common/fmplayer_fontrom.h @@ -0,0 +1,9 @@ +#ifndef MYON_FMPLAYER_FONTROM_H_INCLUDED +#define MYON_FMPLAYER_FONTROM_H_INCLUDED + +struct fmdsp_font; + +// always succeeds +void fmplayer_font_rom_load(struct fmdsp_font *font); + +#endif // MYON_FMPLAYER_FONTROM_H_INCLUDED diff --git a/common/fmplayer_fontrom_unix.c b/common/fmplayer_fontrom_unix.c new file mode 100644 index 0000000..bac8a81 --- /dev/null +++ b/common/fmplayer_fontrom_unix.c @@ -0,0 +1,48 @@ +#include "fmplayer_fontrom.h" +#include "fmdsp/font.h" +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +#include "fmdsp/fontrom_shinonome.inc" + +#define DATADIR "/.local/share/fmplayer/" + +static struct { + uint8_t fontrombuf[FONT_ROM_FILESIZE]; +} g; + +void fmplayer_font_rom_load(struct fmdsp_font *font) { + const char *path = "font.rom"; + const char *home = getenv("HOME"); + char *dpath = 0; + FILE *f = 0; + fmdsp_font_from_font_rom(font, g.fontrombuf); + if (home) { + const char *datadir = DATADIR; + dpath = malloc(strlen(home)+strlen(datadir)+strlen(path)+1); + if (dpath) { + strcpy(dpath, home); + strcat(dpath, datadir); + strcat(dpath, path); + path = dpath; + } + } + f = fopen(path, "r"); + free(dpath); + if (!f) goto err; + if (fseek(f, 0, SEEK_END) != 0) goto err; + long size = ftell(f); + if (size != FONT_ROM_FILESIZE) goto err; + if (fseek(f, 0, SEEK_SET) != 0) goto err; + if (fread(g.fontrombuf, 1, FONT_ROM_FILESIZE, f) != FONT_ROM_FILESIZE) { + goto err; + } + fclose(f); + return; + +err: + if (f) fclose(f); + fmdsp_font_from_font_rom(font, fmdsp_shinonome_font_rom); +} |