aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/fmplayer_file_unix.c47
-rw-r--r--sdl/main.c245
-rw-r--r--sdl/osx/Info.plist24
-rw-r--r--sdl/osx/Makefile2
-rw-r--r--sdl/unix/Makefile2
-rw-r--r--sdl/win/Makefile2
6 files changed, 217 insertions, 105 deletions
diff --git a/common/fmplayer_file_unix.c b/common/fmplayer_file_unix.c
index 3360577..88f1815 100644
--- a/common/fmplayer_file_unix.c
+++ b/common/fmplayer_file_unix.c
@@ -6,6 +6,9 @@
#include <dirent.h>
#include <string.h>
#include <strings.h>
+#include <iconv.h>
+#include <locale.h>
+#include <langinfo.h>
static void *fileread(const char *path, size_t maxsize, size_t *filesize, enum fmplayer_file_error *error) {
FILE *f = 0;
@@ -126,7 +129,45 @@ void *fmplayer_path_dup(const void *path) {
return strdup(path);
}
-char *fmplayer_path_filename_sjis(const void *path) {
- (void)path;
- return 0;
+char *fmplayer_path_filename_sjis(const void *pathptr) {
+ char *path = (char *)pathptr;
+ locale_t loc = 0;
+ iconv_t ic = (iconv_t)-1;
+ char *pathbuf = 0;
+ char *fname = strrchr(path, '/');
+ if (fname) {
+ if (*fname) fname++;
+ } else {
+ fname = path;
+ }
+ // use locale from environment values (to guess filesystem path encoding)
+ loc = newlocale(LC_CTYPE_MASK, "", 0);
+ if (!loc) {
+ //perror("newlocale");
+ goto err;
+ }
+ const int pathbuflen = 160;
+ pathbuf = malloc(pathbuflen);
+ if (!pathbuf) goto err;
+ ic = iconv_open("SHIFT_JIS", nl_langinfo_l(CODESET, loc));
+ if (ic == (iconv_t)-1) {
+ //perror("iconv_open");
+ goto err;
+ }
+ char *src = fname, *dst = pathbuf;
+ size_t srcleft = strlen(fname);
+ size_t dstleft = pathbuflen;
+ if (iconv(ic, &src, &srcleft, &dst, &dstleft) == (size_t)-1) {
+ //perror("iconv");
+ goto err;
+ }
+ iconv_close(ic);
+ *dst = 0;
+ freelocale(loc);
+ return pathbuf;
+err:
+ free(pathbuf);
+ if (ic != (iconv_t)-1) iconv_close(ic);
+ if (loc) freelocale(loc);
+ return strdup(fname);
}
diff --git a/sdl/main.c b/sdl/main.c
index 004c8fb..e5bfb3e 100644
--- a/sdl/main.c
+++ b/sdl/main.c
@@ -26,7 +26,7 @@ static struct {
struct fmplayer_file *fmfile;
struct fmplayer_fft_data fftdata;
struct fmplayer_fft_input_data fftin;
- const char *currpath;
+ const char *lastopenpath;
SDL_Window *win;
SDL_AudioDeviceID adev;
struct ppz8 ppz8;
@@ -35,6 +35,7 @@ static struct {
atomic_flag fftdata_flag;
int scale;
struct fmdsp_font font16;
+ bool paused;
} g = {
.fftdata_flag = ATOMIC_FLAG_INIT,
.scale = 1,
@@ -62,16 +63,168 @@ static void openfile(const char *path) {
"cannot open file",
fmplayer_file_strerror(error),
g.win);
- return;
+ goto err;
}
- SDL_LockAudioDevice(g.adev);
+ if (g.adev) SDL_LockAudioDevice(g.adev);
fmplayer_file_free(g.fmfile);
g.fmfile = file;
fmplayer_init_work_opna(&g.work, &g.ppz8, &g.opna, &g.timer, &g.adpcmram);
fmplayer_file_load(&g.work, g.fmfile, 1);
+ if (g.fmfile->filename_sjis) {
+ fmdsp_pacc_set_filename_sjis(g.fp, g.fmfile->filename_sjis);
+ }
+ fmdsp_pacc_update_file(g.fp);
fmdsp_pacc_comment_reset(g.fp);
- SDL_UnlockAudioDevice(g.adev);
+ if (!g.adev) {
+ SDL_AudioSpec aspec = {
+ .freq = SRATE,
+ .format = AUDIO_S16SYS,
+ .channels = 2,
+ .samples = BUFLEN,
+ .callback = audiocb,
+ };
+ g.adev = SDL_OpenAudioDevice(0, 0, &aspec, 0, 0);
+ if (!g.adev) {
+ SDL_ShowSimpleMessageBox(
+ SDL_MESSAGEBOX_ERROR,
+ "cannot open audio device",
+ fmplayer_file_strerror(error),
+ g.win);
+ goto err;
+ }
+ } else {
+ SDL_UnlockAudioDevice(g.adev);
+ }
SDL_PauseAudioDevice(g.adev, 0);
+ g.paused = false;
+ // path might be the same as g.lastopenpath
+ const char *tmp = g.lastopenpath;
+ g.lastopenpath = SDL_strdup(path);
+ SDL_free((void *)tmp);
+ return;
+err:
+ fmplayer_file_free(file);
+}
+
+static void mask_set(int p, bool shift, bool control) {
+ if (!control) {
+ if (p >= 11) return;
+ static const unsigned masktbl[11] = {
+ LIBOPNA_CHAN_FM_1,
+ LIBOPNA_CHAN_FM_2,
+ LIBOPNA_CHAN_FM_3,
+ LIBOPNA_CHAN_FM_4,
+ LIBOPNA_CHAN_FM_5,
+ LIBOPNA_CHAN_FM_6,
+ LIBOPNA_CHAN_SSG_1,
+ LIBOPNA_CHAN_SSG_2,
+ LIBOPNA_CHAN_SSG_3,
+ LIBOPNA_CHAN_DRUM_ALL,
+ LIBOPNA_CHAN_ADPCM,
+ };
+ unsigned mask = masktbl[p];
+ if (shift) {
+ opna_set_mask(&g.opna, ~mask);
+ ppz8_set_mask(&g.ppz8, -1);
+ } else {
+ opna_set_mask(&g.opna, opna_get_mask(&g.opna) ^ mask);
+ }
+ } else {
+ if (p >= 8) return;
+ unsigned mask = 1u<<p;
+ if (shift) {
+ ppz8_set_mask(&g.ppz8, ~mask);
+ opna_set_mask(&g.opna, -1);
+ } else {
+ ppz8_set_mask(&g.ppz8, ppz8_get_mask(&g.ppz8) ^ mask);
+ }
+ }
+}
+
+static void handle_keydown(
+ const SDL_KeyboardEvent *key,
+ const struct pacc_vtable *pacc,
+ struct pacc_ctx *pc) {
+ // F1 to F12 scancodes are continuous
+ if (SDL_SCANCODE_F1 <= key->keysym.scancode
+ && key->keysym.scancode <= SDL_SCANCODE_F12) {
+ if (key->keysym.mod & KMOD_CTRL) {
+ fmdsp_pacc_palette(g.fp, key->keysym.scancode - SDL_SCANCODE_F1);
+ } else {
+ switch (key->keysym.scancode) {
+ case SDL_SCANCODE_F6:
+ if (g.lastopenpath) {
+ openfile(g.lastopenpath);
+ }
+ break;
+ case SDL_SCANCODE_F7:
+ if (g.adev) {
+ g.paused ^= 1;
+ g.work.paused = g.paused;
+ SDL_PauseAudioDevice(g.adev, g.paused);
+ }
+ break;
+ case SDL_SCANCODE_F11:
+ if (key->keysym.mod & KMOD_SHIFT) {
+ fmdsp_pacc_set_right_mode(
+ g.fp,
+ (fmdsp_pacc_right_mode(g.fp) + 1) % FMDSP_RIGHT_MODE_CNT);
+ } else {
+ fmdsp_pacc_set_left_mode(
+ g.fp,
+ (fmdsp_pacc_left_mode(g.fp) + 1) % FMDSP_LEFT_MODE_CNT);
+ }
+ break;
+ case SDL_SCANCODE_F12:
+ g.scale++;
+ if (g.scale > 3) g.scale = 1;
+ SDL_SetWindowSize(g.win, PC98_W*g.scale, PC98_H*g.scale);
+ pacc->viewport_scale(pc, g.scale);
+ break;
+ default:
+ break;
+ }
+ }
+ } else {
+ const bool shift = key->keysym.mod & KMOD_SHIFT;
+ const bool ctrl = key->keysym.mod & KMOD_CTRL;
+ if (SDL_SCANCODE_1 <= key->keysym.scancode
+ && key->keysym.scancode <= SDL_SCANCODE_0) {
+ mask_set(key->keysym.scancode - SDL_SCANCODE_1, shift, ctrl);
+ } else {
+ switch (key->keysym.scancode) {
+ case SDL_SCANCODE_MINUS:
+ mask_set(10, shift, ctrl);
+ break;
+ case SDL_SCANCODE_EQUALS:
+ opna_set_mask(&g.opna, ~opna_get_mask(&g.opna));
+ ppz8_set_mask(&g.ppz8, ~ppz8_get_mask(&g.ppz8));
+ break;
+ case SDL_SCANCODE_BACKSLASH:
+ opna_set_mask(&g.opna, 0);
+ ppz8_set_mask(&g.ppz8, 0);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ switch (key->keysym.scancode) {
+ default:
+ break;
+ }
+ if (key->keysym.mod & KMOD_SHIFT) {
+ switch (key->keysym.scancode) {
+ case SDL_SCANCODE_UP:
+ fmdsp_pacc_comment_scroll(g.fp, false);
+ break;
+ case SDL_SCANCODE_DOWN:
+ fmdsp_pacc_comment_scroll(g.fp, true);
+ break;
+ default:
+ break;
+ }
+ }
}
int main(int argc, char **argv) {
@@ -84,20 +237,6 @@ int main(int argc, char **argv) {
return 1;
}
- SDL_AudioSpec aspec = {
- .freq = SRATE,
- .format = AUDIO_S16SYS,
- .channels = 2,
- .samples = BUFLEN,
- .callback = audiocb,
- };
- g.adev = SDL_OpenAudioDevice(0, 0, &aspec, 0, 0);
- if (!g.adev) {
- SDL_Log("Cannot open audio device\n");
- SDL_Quit();
- return 0;
- }
-
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
@@ -191,75 +330,7 @@ int main(int argc, char **argv) {
SDL_free(e.drop.file);
break;
case SDL_KEYDOWN:
- switch (e.key.keysym.scancode) {
- case SDL_SCANCODE_F11:
- if (e.key.keysym.mod & KMOD_SHIFT) {
- fmdsp_pacc_set_right_mode(
- g.fp,
- (fmdsp_pacc_right_mode(g.fp) + 1) % FMDSP_RIGHT_MODE_CNT);
- } else {
- fmdsp_pacc_set_left_mode(
- g.fp,
- (fmdsp_pacc_left_mode(g.fp) + 1) % FMDSP_LEFT_MODE_CNT);
- }
- break;
- case SDL_SCANCODE_F12:
- g.scale++;
- if (g.scale > 3) g.scale = 1;
- SDL_SetWindowSize(g.win, PC98_W*g.scale, PC98_H*g.scale);
- pacc.viewport_scale(pc, g.scale);
- break;
- default:
- break;
- }
- if (e.key.keysym.mod & KMOD_SHIFT) {
- switch (e.key.keysym.scancode) {
- case SDL_SCANCODE_UP:
- fmdsp_pacc_comment_scroll(g.fp, false);
- break;
- case SDL_SCANCODE_DOWN:
- fmdsp_pacc_comment_scroll(g.fp, true);
- break;
- default:
- break;
- }
- }
- if (e.key.keysym.mod & KMOD_CTRL) {
- switch (e.key.keysym.scancode) {
- case SDL_SCANCODE_F1:
- fmdsp_pacc_palette(g.fp, 0);
- break;
- case SDL_SCANCODE_F2:
- fmdsp_pacc_palette(g.fp, 1);
- break;
- case SDL_SCANCODE_F3:
- fmdsp_pacc_palette(g.fp, 2);
- break;
- case SDL_SCANCODE_F4:
- fmdsp_pacc_palette(g.fp, 3);
- break;
- case SDL_SCANCODE_F5:
- fmdsp_pacc_palette(g.fp, 4);
- break;
- case SDL_SCANCODE_F6:
- fmdsp_pacc_palette(g.fp, 5);
- break;
- case SDL_SCANCODE_F7:
- fmdsp_pacc_palette(g.fp, 6);
- break;
- case SDL_SCANCODE_F8:
- fmdsp_pacc_palette(g.fp, 7);
- break;
- case SDL_SCANCODE_F9:
- fmdsp_pacc_palette(g.fp, 8);
- break;
- case SDL_SCANCODE_F10:
- fmdsp_pacc_palette(g.fp, 9);
- break;
- default:
- break;
- }
- }
+ handle_keydown(&e.key, &pacc, pc);
}
}
if (!atomic_flag_test_and_set_explicit(
diff --git a/sdl/osx/Info.plist b/sdl/osx/Info.plist
index 408d17f..4de59e7 100644
--- a/sdl/osx/Info.plist
+++ b/sdl/osx/Info.plist
@@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
- <string>fmplayersdl</string>
+ <string>98fmplayersdl</string>
<key>CFBundleIdentifier</key>
- <string>com.github.takamichih.fmplayer</string>
+ <string>com.github.takamichih.98fmplayersdl</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
@@ -15,7 +15,7 @@
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
- <string>com.github.takamichih.fmplayer.pmd</string>
+ <string>com.github.takamichih.98fmplayer.pmd</string>
</array>
</dict>
<dict>
@@ -25,7 +25,7 @@
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
- <string>com.github.takamichih.fmplayer.play6</string>
+ <string>com.github.takamichih.98fmplayer.play6</string>
</array>
</dict>
<dict>
@@ -35,7 +35,7 @@
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
- <string>com.github.takamichih.fmplayer.fmp</string>
+ <string>com.github.takamichih.98fmplayer.fmp</string>
</array>
</dict>
</array>
@@ -43,7 +43,7 @@
<array>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.pmd</string>
+ <string>com.github.takamichih.98fmplayer.pmd</string>
<key>UTTypeDescription</key>
<string>PMD music file</string>
<key>UTTypeConformsTo</key>
@@ -62,7 +62,7 @@
</dict>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.fmp</string>
+ <string>com.github.takamichih.98fmplayer.fmp</string>
<key>UTTypeDescription</key>
<string>FMP music file</string>
<key>UTTypeConformsTo</key>
@@ -81,7 +81,7 @@
</dict>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.play6</string>
+ <string>com.github.takamichih.98fmplayer.play6</string>
<key>UTTypeDescription</key>
<string>PLAY6 music file</string>
<key>UTTypeConformsTo</key>
@@ -99,7 +99,7 @@
</dict>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.pmdadpcm</string>
+ <string>com.github.takamichih.98fmplayer.pmdadpcm</string>
<key>UTTypeDescription</key>
<string>PMD ADPCM file</string>
<key>UTTypeConformsTo</key>
@@ -116,7 +116,7 @@
</dict>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.pmdpcm</string>
+ <string>com.github.takamichih.98fmplayer.pmdpcm</string>
<key>UTTypeDescription</key>
<string>PMD PCM file</string>
<key>UTTypeConformsTo</key>
@@ -133,7 +133,7 @@
</dict>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.fmpadpcm</string>
+ <string>com.github.takamichih.98fmplayer.fmpadpcm</string>
<key>UTTypeDescription</key>
<string>FMP/PPZ8 ADPCM file</string>
<key>UTTypeConformsTo</key>
@@ -150,7 +150,7 @@
</dict>
<dict>
<key>UTTypeIdentifier</key>
- <string>com.github.takamichih.fmplayer.ppz8pcm</string>
+ <string>com.github.takamichih.98fmplayer.ppz8pcm</string>
<key>UTTypeDescription</key>
<string>PPZ8 PCM file</string>
<key>UTTypeConformsTo</key>
diff --git a/sdl/osx/Makefile b/sdl/osx/Makefile
index 18ae005..b04d76e 100644
--- a/sdl/osx/Makefile
+++ b/sdl/osx/Makefile
@@ -14,7 +14,7 @@ OBJS+=opna.o opnafm.o opnassg.o opnadrum.o opnaadpcm.o opnatimer.o opnassg-sinc-
OBJS+=fmdriver_pmd.o fmdriver_fmp.o ppz8.o fmdriver_common.o
OBJS+=fmplayer_file.o fmplayer_work_opna.o fmplayer_file_unix.o fmplayer_drumrom_unix.o
OBJS+=fft.o
-TARGET:=fmplayersdl
+TARGET:=98fmplayersdl
CFLAGS:=-Wall -Wextra -O2 -g
CFLAGS+=-DPACC_GL_3
#CFLAGS+=-DPACC_GL_ES
diff --git a/sdl/unix/Makefile b/sdl/unix/Makefile
index 601dd41..1137418 100644
--- a/sdl/unix/Makefile
+++ b/sdl/unix/Makefile
@@ -13,7 +13,7 @@ OBJS+=opna.o opnafm.o opnassg.o opnadrum.o opnaadpcm.o opnatimer.o opnassg-sinc-
OBJS+=fmdriver_pmd.o fmdriver_fmp.o ppz8.o fmdriver_common.o
OBJS+=fmplayer_file.o fmplayer_work_opna.o fmplayer_file_unix.o fmplayer_drumrom_unix.o fmplayer_fontrom_unix.o
OBJS+=fft.o
-TARGET:=fmplayersdl
+TARGET:=98fmplayersdl
CFLAGS:=-Wall -Wextra -O2 -g
CFLAGS+=-DLIBOPNA_ENABLE_LEVELDATA
diff --git a/sdl/win/Makefile b/sdl/win/Makefile
index 74ddf0e..a50cb2f 100644
--- a/sdl/win/Makefile
+++ b/sdl/win/Makefile
@@ -16,7 +16,7 @@ OBJS+=opna.o opnafm.o opnassg.o opnadrum.o opnaadpcm.o opnatimer.o opnassg-sinc-
OBJS+=fmdriver_pmd.o fmdriver_fmp.o ppz8.o fmdriver_common.o
OBJS+=fmplayer_file.o fmplayer_work_opna.o fmplayer_file_win.o fmplayer_drumrom_win.o fmplayer_fontrom_win.o winfont.o
OBJS+=fft.o
-TARGET:=fmplayersdl.exe
+TARGET:=98fmplayersdl.exe
CFLAGS:=-Wall -Wextra -O2
CFLAGS+=-DLIBOPNA_ENABLE_LEVELDATA