Skip to content

Commit

Permalink
EP128: add context menu and options
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Oct 25, 2020
1 parent a0009cb commit 1e52ebe
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 18 deletions.
2 changes: 1 addition & 1 deletion targets/ep128/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TARGET = ep128
PRG_TARGET = xep128
EMU_DESCRIPTION = Enterprise 128

SRCS_TARGET_xep128 = enterprise128.c cpu.c z180.c nick.c dave.c input_devices.c exdos_wd.c sdext.c rtc.c printer.c zxemu.c primoemu.c emu_rom_interface.c epnet.c apu.c roms.c emu_monitor.c fileio.c snapshot.c
SRCS_TARGET_xep128 = enterprise128.c cpu.c z180.c nick.c dave.c input_devices.c exdos_wd.c sdext.c rtc.c printer.c zxemu.c primoemu.c emu_rom_interface.c epnet.c apu.c roms.c emu_monitor.c fileio.c snapshot.c ui.c
SRCS_COMMON_xep128 = emutools.c emutools_files.c emutools_config.c emutools_gui.c emutools_hid.c z80.c z80_dasm.c emutools_socketapi.c lodepng.c
CFLAGS_TARGET_xep128 = $(SDL2_CFLAGS) $(MATH_CFLAGS) $(SOCKET_CFLAGS) $(XEMUGUI_CFLAGS) $(READLINE_CFLAGS)
LDFLAGS_TARGET_xep128 = $(SDL2_LIBS) $(MATH_LIBS) $(SOCKET_LIBS) $(XEMUGUI_LIBS) $(READLINE_LIBS)
Expand Down
10 changes: 6 additions & 4 deletions targets/ep128/enterprise128.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "xemu/emutools_gui.h"
#include "xemu/emutools_hid.h"
#include "xemu/z80.h"

#include "enterprise128.h"

#include "dave.h"
#include "nick.h"
#include "sdext.h"
Expand All @@ -48,9 +50,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */


//static Uint32 *ep_pixels;
static const int _cpu_speeds[4] = { 4000000, 6000000, 7120000, 10000000 };
static int _cpu_speed_index = 0;
static unsigned int ticks;
//static const int _cpu_speeds[4] = { 4000000, 6000000, 7120000, 10000000 };
//static int _cpu_speed_index = 0;
//static unsigned int ticks;
int paused = 0;
static int cpu_cycles_for_dave_sync = 0;
//static int td_balancer;
Expand Down Expand Up @@ -382,7 +384,7 @@ int main (int argc, char *argv[])
#ifdef CONFIG_EPNET_SUPPORT
epnet_init(NULL);
#endif
ticks = SDL_GetTicks();
//ticks = SDL_GetTicks();
balancer = 0;
set_cpu_clock((int)(xemucfg_get_ranged_float("clock", 1.0, 12.0) * 1000000.0));
audio_start();
Expand Down
2 changes: 0 additions & 2 deletions targets/ep128/enterprise128.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ extern int set_cpu_clock ( int hz );
extern int paused;
extern time_t unix_time;

#define VARALIGN MAXALIGNED

#define CONFIG_USE_LODEPNG
#define CONFIG_EXDOS_SUPPORT
#ifdef XEMU_HAS_SOCKET_API
Expand Down
11 changes: 3 additions & 8 deletions targets/ep128/input_devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "xemu/emutools_hid.h"
#include "enterprise128.h"
#include "dave.h"
#include "ui.h"

#include "input_devices.h"

Expand Down Expand Up @@ -544,14 +545,8 @@ int emu_kbd(SDL_Keysym sym, int press)
// HID needs this to be defined, it's up to the emulator if it uses or not ...
int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
{
#if 0
if (!pressed && pos == -2 && key == 0 && handled == SDL_BUTTON_RIGHT) {
DEBUGGUI("UI: handler has been called." NL);
if (xemugui_popup(menu_main)) {
DEBUGPRINT("UI: oops, POPUP does not worked :(" NL);
}
}
#endif
if (!pressed && pos == -2 && key == 0 && handled == SDL_BUTTON_RIGHT)
ui_enter();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion targets/ep128/nick.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int nick_addressing_init ( Uint32 *pixels_buffer, int line_size )
void screenshot ( void )
{
if (!xemu_screenshot_png(
"@", "screenshot.png",
NULL, NULL,
1,
2,
NULL, // Allow function to figure it out ;)
Expand Down
131 changes: 131 additions & 0 deletions targets/ep128/ui.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2020 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */


#include "xemu/emutools.h"
#include "xemu/emutools_gui.h"
#include "xemu/emutools_files.h"
#include "xemu/emutools_hid.h"

#include "ui.h"

#include "enterprise128.h"
#include "nick.h"
#include "cpu.h"
#include "exdos_wd.h"


static void ui_hard_reset ( void )
{
ep_reset();
}


#ifdef XEMU_FILES_SCREENSHOT_SUPPORT
static void ui_screenshot ( void )
{
// register_screenshot_request = 1;
screenshot();
}
#endif

#if 0
static void ui_set_scale_filtering ( const struct menu_st *m, int *query )
{
static char enabled[2] = "0";
XEMUGUI_RETURN_CHECKED_ON_QUERY(query, (enabled[0] & 1));
enabled[0] ^= 1;
SDL_SetHint("SDL_HINT_RENDER_SCALE_QUALITY", enabled);
}
#endif

#ifdef CONFIG_EXDOS_SUPPORT
static void ui_attach_disk ( void )
{
char fnbuf[PATH_MAX + 1];
static char dir[PATH_MAX + 1] = "";
if (!xemugui_file_selector(
XEMUGUI_FSEL_OPEN | XEMUGUI_FSEL_FLAG_STORE_DIR,
"Select floppy disk image to attach",
dir,
fnbuf,
sizeof fnbuf
))
wd_attach_disk_image(fnbuf);
else
DEBUGPRINT("UI: file selection for floppy mount was cancalled." NL);
}
#endif


/**** MENU SYSTEM ****/


static const struct menu_st menu_display[] = {
{ "Fullscreen", XEMUGUI_MENUID_CALLABLE, xemugui_cb_windowsize, (void*)0 },
{ "Window - 100%", XEMUGUI_MENUID_CALLABLE, xemugui_cb_windowsize, (void*)1 },
{ "Window - 200%", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_SEPARATOR, xemugui_cb_windowsize, (void*)2 },
{ "Enable mouse grab + emu", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_set_mouse_grab, NULL },
// { "Enable scale filtering", XEMUGUI_MENUID_CALLABLE |
// XEMUGUI_MENUFLAG_QUERYBACK, ui_set_scale_filtering, NULL },
{ NULL }
};
static const struct menu_st menu_debug[] = {
{ "OSD key debugger", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_osd_key_debugger, NULL },
// { "Dump memory info file", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ui_dump_memory },
{ "Browse system folder", XEMUGUI_MENUID_CALLABLE, xemugui_cb_native_os_prefdir_browser, NULL },
{ NULL }
};
static const struct menu_st menu_reset[] = {
// { "Reset C65", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, reset_into_c65_mode },
// { "Reset into C64 mode", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, reset_into_c64_mode },
{ "Reset", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ep_reset },
{ "Hard reset", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ui_hard_reset },
{ NULL }
};
static const struct menu_st menu_main[] = {
{ "Display", XEMUGUI_MENUID_SUBMENU, NULL, menu_display },
{ "Reset", XEMUGUI_MENUID_SUBMENU, NULL, menu_reset },
{ "Debug", XEMUGUI_MENUID_SUBMENU, NULL, menu_debug },
#ifdef CONFIG_EXDOS_SUPPORT
{ "Attach floppy", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ui_attach_disk },
#endif
// { "Attach D81", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ui_attach_d81_by_browsing },
// { "Run PRG directly", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ui_run_prg_by_browsing },
#ifdef XEMU_FILES_SCREENSHOT_SUPPORT
{ "Screenshot", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, ui_screenshot },
#endif
#ifdef XEMU_ARCH_WIN
{ "System console", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_sysconsole, NULL },
#endif
{ "About", XEMUGUI_MENUID_CALLABLE, xemugui_cb_about_window, NULL },
{ "Quit", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_quit_if_sure, NULL },
{ NULL }
};


void ui_enter ( void )
{
DEBUGGUI("UI: handler has been called." NL);
if (xemugui_popup(menu_main)) {
DEBUGPRINT("UI: oops, POPUP does not worked :(" NL);
}
}
23 changes: 23 additions & 0 deletions targets/ep128/ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2020 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

#ifndef XEMU_EP128_UI_H_INCLUDED
#define XEMU_EP128_UI_H_INCLUDED

extern void ui_enter ( void );

#endif
3 changes: 3 additions & 0 deletions targets/ep128/xemu-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#ifndef XEMU_ARCH_HTML
#define XEMU_USE_LODEPNG
#define XEMU_FILES_SCREENSHOT_SUPPORT
#define HAVE_XEMU_EXEC_API
#endif

#define CONFIG_EMSCRIPTEN_OK

#define VARALIGN MAXALIGNED
9 changes: 7 additions & 2 deletions xemu/emutools_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ struct menu_st {
const void *user_data;
};

extern int is_xemungui_ok;
extern int is_xemungui_ok;

extern int xemugui_init ( const char *name );
extern void xemugui_shutdown ( void );
extern int xemugui_iteration ( void );
extern int xemugui_file_selector ( int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size );

extern int xemugui_popup ( const struct menu_st desc[] );
extern int xemugui_info ( int sdl_class, const char *msg );

Expand All @@ -86,4 +85,10 @@ extern void xemugui_cb_sysconsole ( const struct menu_st *m, int *query );
#endif
extern void xemugui_cb_windowsize ( const struct menu_st *m, int *query );

#ifdef HAVE_XEMU_EXEC_API
extern void xemugui_cb_native_os_prefdir_browser( const struct menu_st *m, int *query );
#endif
extern void xemugui_cb_osd_key_debugger ( const struct menu_st *m, int *query );
extern void xemugui_cb_set_mouse_grab ( const struct menu_st *m, int *query );

#endif
25 changes: 25 additions & 0 deletions xemu/gui/popular_user_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,28 @@ void xemugui_cb_windowsize ( const struct menu_st *m, int *query )
#endif
xemu_set_screen_mode(mode_spec);
}

#ifdef HAVE_XEMU_EXEC_API
#include "xemu/emutools_files.h"
void xemugui_cb_native_os_prefdir_browser ( const struct menu_st *m, int *query )
{
if (!query)
xemuexec_open_native_file_browser(sdl_pref_dir);
}
#endif

#include "xemu/emutools_hid.h"
void xemugui_cb_osd_key_debugger ( const struct menu_st *m, int *query )
{
XEMUGUI_RETURN_CHECKED_ON_QUERY(query, hid_show_osd_keys);
hid_show_osd_keys = !hid_show_osd_keys;
OSD(-1, -1, "OSD key debugger has been %sABLED", hid_show_osd_keys ? "EN" : "DIS");
}

void xemugui_cb_set_mouse_grab ( const struct menu_st *m, int *query )
{
XEMUGUI_RETURN_CHECKED_ON_QUERY(query, allow_mouse_grab);
allow_mouse_grab = !allow_mouse_grab;
if (allow_mouse_grab)
OSD(-1, -1, "ENABLED. Left click to activate!");
}

1 comment on commit 1e52ebe

@lgblgblgb
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#197 to have UI context menu.

Please sign in to comment.