diff options
-rw-r--r-- | fmdsp/fmdsp.c | 41 | ||||
-rw-r--r-- | fmdsp/fmdsp.h | 1 | ||||
-rw-r--r-- | fmdsp/fmdsp_sprites.h | 126 | ||||
-rw-r--r-- | gtk/main.c | 18 | ||||
-rw-r--r-- | win32/main.c | 32 |
5 files changed, 211 insertions, 7 deletions
diff --git a/fmdsp/fmdsp.c b/fmdsp/fmdsp.c index 1da0adf..4c16f5e 100644 --- a/fmdsp/fmdsp.c +++ b/fmdsp/fmdsp.c @@ -46,10 +46,9 @@ static void vramblit_key(uint8_t *vram, int x, int y, } void fmdsp_init(struct fmdsp *fmdsp, const struct fmdsp_font *font98) { - for (int i = 0; i < FMDSP_PALETTE_COLORS; i++) { - fmdsp->palette[i*3+0] = s_palettes[0][i*3+0]; - fmdsp->palette[i*3+1] = s_palettes[0][i*3+1]; - fmdsp->palette[i*3+2] = s_palettes[0][i*3+2]; + for (int i = 0; i < FMDSP_PALETTE_COLORS*3; i++) { + fmdsp->palette[i] = 0;//s_palettes[0][i]; + fmdsp->target_palette[i] = s_palettes[0][i]; } fmdsp->font98 = font98; } @@ -181,6 +180,39 @@ void fmdsp_vram_init(struct fmdsp *fmdsp, } } +enum { + FADEDELTA = 16 +}; + +void fmdsp_palette_set(struct fmdsp *fmdsp, int p) { + if (p < 0) return; + if (p >= PALETTE_NUM) return; + for (int i = 0; i < FMDSP_PALETTE_COLORS*3; i++) { + fmdsp->target_palette[i] = s_palettes[p][i]; + } +} + +static void fmdsp_palette_fade(struct fmdsp *fmdsp) { + for (int i = 0; i < FMDSP_PALETTE_COLORS*3; i++) { + uint8_t p = fmdsp->palette[i]; + uint8_t t = fmdsp->target_palette[i]; + if (p < t) { + if ((p + FADEDELTA) < t) { + p += FADEDELTA; + } else { + p = t; + } + } else if (p > t) { + if (p > (t + FADEDELTA)) { + p -= FADEDELTA; + } else { + p = t; + } + } + fmdsp->palette[i] = p; + } +} + void fmdsp_update(struct fmdsp *fmdsp, const struct fmdriver_work *work, uint8_t *vram) { for (int t = 0; t < 10; t++) { @@ -220,6 +252,7 @@ void fmdsp_update(struct fmdsp *fmdsp, vramblit_color(vram, BAR_X+BAR_W*(track->ticks>>2), TRACK_H*t+BAR_Y, s_bar, BAR_W, BAR_H, 7); } + fmdsp_palette_fade(fmdsp); } void fmdsp_vrampalette(struct fmdsp *fmdsp, const uint8_t *vram, uint8_t *vram32, int stride) { diff --git a/fmdsp/fmdsp.h b/fmdsp/fmdsp.h index a7b245a..f123138 100644 --- a/fmdsp/fmdsp.h +++ b/fmdsp/fmdsp.h @@ -32,6 +32,7 @@ void fmdsp_vram_init(struct fmdsp *fmdsp, void fmdsp_update(struct fmdsp *fmdsp, const struct fmdriver_work *work, uint8_t *vram); void fmdsp_vrampalette(struct fmdsp *fmdsp, const uint8_t *vram, uint8_t *vram32, int stride); void fmdsp_font_from_fontrom(uint8_t *font, const uint8_t *fontrom); +void fmdsp_palette_set(struct fmdsp *fmdsp, int p); #ifdef __cplusplus } #endif diff --git a/fmdsp/fmdsp_sprites.h b/fmdsp/fmdsp_sprites.h index 1fe6c13..ded3591 100644 --- a/fmdsp/fmdsp_sprites.h +++ b/fmdsp/fmdsp_sprites.h @@ -37,7 +37,22 @@ enum { PLAYING_H = 9, }; -static const uint8_t s_palettes[1][FMDSP_PALETTE_COLORS*3] = { +enum { + PALETTE_NUM = 10 +}; + +#define LCDWR 181 +#define LCDWG 192 +#define LCDWB 12 +#define LCDBR 70 +#define LCDBG 124 +#define LCDBB 108 +#define LCD(C) \ + (LCDWR*(C)+LCDBR*(255-C))/256, \ + (LCDWG*(C)+LCDBG*(255-C))/256, \ + (LCDWB*(C)+LCDBB*(255-C))/256 + +static const uint8_t s_palettes[PALETTE_NUM][FMDSP_PALETTE_COLORS*3] = { { 0, 0, 0, 170, 170, 153, @@ -48,9 +63,116 @@ static const uint8_t s_palettes[1][FMDSP_PALETTE_COLORS*3] = { 136, 255, 68, 51, 51, 238, 0, 187, 255, - } + }, + { + 0, 0, 0, + 187, 187, 170, + 136, 170, 255, + 85, 85, 153, + 204, 204, 187, + 136, 136, 119, + 153, 255, 119, + 102, 85, 255, + 0, 204, 255, + }, + { + 0, 0, 0, + 255, 102, 0, + 255, 170, 0, + 102, 68, 51, + 153, 136, 102, + 119, 85, 68, + 255, 221, 85, + 255, 102, 0, + 255, 85, 0, + }, + { + 0, 0, 0, + 170, 170, 153, + 170, 153, 255, + 85, 51, 102, + 204, 204, 187, + 102, 102, 85, + 119, 255, 34, + 136, 68, 221, + 0, 187, 255, + }, + { + 0, 0, 0, + 187, 187, 170, + 102, 153, 255, + 85, 68, 136, + 255, 255, 238, + 119, 119, 102, + 255, 68, 0, + 85, 85, 255, + 255, 119, 255, + }, + { + 0, 0, 0, + 255, 51, 119, + 255, 187, 0, + 85, 85, 68, + 119, 119, 102, + 102, 102, 102, + 255, 221, 0, + 255, 0, 51, + 255, 0, 51, + }, + { + 102, 170, 238, + 0, 17, 136, + 0, 51, 136, + 153, 221, 255, + 153, 221, 255, + 119, 187, 255, + 0, 51, 136, + 34, 102, 187, + 0, 85, 204, + }, + { + 0, 0, 0, + 170, 170, 136, + 102, 153, 255, + 17, 0, 51, + 170, 170, 153, + 51, 51, 51, + 85, 255, 68, + 34, 17, 255, + 0, 170, 255, + }, + { + LCD(255), + LCD(72), + LCD(0), + LCD(182), + LCD(0), + LCD(145), + LCD(218), + LCD(109), + LCD(218), + }, + { + LCD(255), + LCD(72), + LCD(0), + LCD(182), + LCD(145), + LCD(145), + LCD(0), + LCD(109), + LCD(0), + }, }; +#undef LCDWR +#undef LCDWG +#undef LCDWB +#undef LCDBR +#undef LCDBG +#undef LCDBB +#undef LCD + static const uint8_t s_track[TNAME_W*TNAME_H] = { 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, @@ -425,6 +425,20 @@ static void destroynothing(gpointer p) { (void)p; } +static gboolean key_press_cb(GtkWidget *w, + GdkEvent *e, + gpointer ptr) { + (void)w; + (void)ptr; + if (GDK_KEY_F1 <= e->key.keyval && e->key.keyval <= GDK_KEY_F10) { + if (e->key.state & GDK_CONTROL_MASK) { + fmdsp_palette_set(&g.fmdsp, e->key.keyval - GDK_KEY_F1); + return TRUE; + } + } + return FALSE; +} + int main(int argc, char **argv) { load_fontrom(); gtk_init(&argc, &argv); @@ -472,7 +486,9 @@ int main(int argc, char **argv) { fmdsp_vram_init(&g.fmdsp, &g.work, g.vram); g.vram32_stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, PC98_W); g.vram32 = malloc((g.vram32_stride*PC98_H)*4); - + + g_signal_connect(w, "key-press-event", G_CALLBACK(key_press_cb), 0); + gtk_widget_add_events(w, GDK_KEY_PRESS_MASK); gtk_widget_show_all(w); gtk_widget_add_tick_callback(w, tick_cb, drawarea, destroynothing); gtk_main(); diff --git a/win32/main.c b/win32/main.c index 07ef1bd..5add23f 100644 --- a/win32/main.c +++ b/win32/main.c @@ -500,6 +500,34 @@ static LRESULT on_copydata(HWND hwnd, HWND hwndfrom, COPYDATASTRUCT *cds) { return TRUE; } +static void on_syskey(HWND hwnd, UINT vk, BOOL down, int repeat, UINT scan) { + if (down) { + if (vk == VK_F10) { + if (GetKeyState(VK_CONTROL) & 0x8000U) { + fmdsp_palette_set(&g.fmdsp, 9); + return; + } + } + FORWARD_WM_SYSKEYDOWN(hwnd, vk, repeat, scan, DefWindowProc); + } else { + FORWARD_WM_SYSKEYUP(hwnd, vk, repeat, scan, DefWindowProc); + } +} + +static void on_key(HWND hwnd, UINT vk, BOOL down, int repeat, UINT scan) { + if (down) { + if (VK_F1 <= vk && vk <= VK_F12) { + if (GetKeyState(VK_CONTROL) & 0x8000U) { + fmdsp_palette_set(&g.fmdsp, vk - VK_F1); + return; + } + } + FORWARD_WM_KEYDOWN(hwnd, vk, repeat, scan, DefWindowProc); + } else { + FORWARD_WM_KEYUP(hwnd, vk, repeat, scan, DefWindowProc); + } +} + static LRESULT CALLBACK wndproc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { @@ -514,6 +542,10 @@ static LRESULT CALLBACK wndproc( #ifdef ENABLE_WM_DROPFILES HANDLE_MSG(hwnd, WM_DROPFILES, on_dropfiles); #endif // ENABLE_WM_DROPFILES + HANDLE_MSG(hwnd, WM_KEYDOWN, on_key); + HANDLE_MSG(hwnd, WM_KEYUP, on_key); + HANDLE_MSG(hwnd, WM_SYSKEYDOWN, on_syskey); + HANDLE_MSG(hwnd, WM_SYSKEYUP, on_syskey); } return DefWindowProc(hwnd, msg, wParam, lParam); } |