forked from Miroirs/x49gp
Compare commits
No commits in common. "08271cf4c25d3790726f953f970d47acfd04e377" and "092b7f49af210efdd8990fa1dbfa32325bdf1d18" have entirely different histories.
08271cf4c2
...
092b7f49af
9 changed files with 54 additions and 61 deletions
14
Makefile
14
Makefile
|
@ -5,13 +5,6 @@ VERSION_MAJOR = 1
|
|||
VERSION_MINOR = 3
|
||||
PATCHLEVEL = 2
|
||||
|
||||
INSTALL_PREFIX = /usr/local
|
||||
INSTALL_BINARY_DIR = "$(INSTALL_PREFIX)"/bin
|
||||
INSTALL_DATA_DIR = "$(INSTALL_PREFIX)"/share/$(TARGET)
|
||||
INSTALL_DOC_DIR = "$(INSTALL_PREFIX)"/doc/$(TARGET)
|
||||
INSTALL_MENU_DIR = "$(INSTALL_PREFIX)"/share/applications
|
||||
INSTALL_MAN_DIR = "$(INSTALL_PREFIX)/share/man/man1"
|
||||
|
||||
#
|
||||
DEBUG_CFLAGS = -g # -pg
|
||||
OPTIM ?= 2
|
||||
|
@ -223,6 +216,13 @@ else
|
|||
endif
|
||||
|
||||
# Installation
|
||||
INSTALL_PREFIX = /usr/local
|
||||
INSTALL_BINARY_DIR = "$(INSTALL_PREFIX)"/bin
|
||||
INSTALL_DATA_DIR = "$(INSTALL_PREFIX)"/share/$(TARGET)
|
||||
INSTALL_DOC_DIR = "$(INSTALL_PREFIX)"/doc/$(TARGET)
|
||||
INSTALL_MENU_DIR = "$(INSTALL_PREFIX)"/share/applications
|
||||
INSTALL_MAN_DIR = "$(INSTALL_PREFIX)/share/man/man1"
|
||||
|
||||
dist/$(TARGET).desktop: dist/$(TARGET).desktop.in
|
||||
perl -p -e "s!TARGET!$(TARGET)!" < dist/$(TARGET).desktop.in >$@
|
||||
|
||||
|
|
2
dist/x49gpng.scd
vendored
2
dist/x49gpng.scd
vendored
|
@ -51,7 +51,7 @@ Please consult HP's manual (for their official firmware) or the documentation of
|
|||
|
||||
- *-h* *--help* print this message and exit
|
||||
- *--verbose* print out more information
|
||||
- *--datadir*[=_absolute path_] alternate datadir (default: $XDG_CONFIG_HOME/x49gpng/)
|
||||
- *--state*[=_filename_] alternate config file
|
||||
- *--50g* emulate an HP 50g (default)
|
||||
- *--49gp* emulate an HP 49g+
|
||||
- *--newrpl-keyboard* label keyboard for newRPL
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "x49gp.h"
|
||||
#include "ui.h"
|
||||
#include "options.h"
|
||||
|
||||
#define FLASH_STATE_NORMAL 0
|
||||
|
||||
|
@ -436,11 +435,11 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
|
|||
|
||||
if ( flash->size > st.st_size ) {
|
||||
fprintf( stderr, "Flash too small, rebuilding\n" );
|
||||
opt.reinit = X49GP_REINIT_FLASH_FULL;
|
||||
x49gp->startup_reinit = X49GP_REINIT_FLASH_FULL;
|
||||
}
|
||||
if ( opt.reinit >= X49GP_REINIT_FLASH ) {
|
||||
if ( x49gp->startup_reinit >= X49GP_REINIT_FLASH ) {
|
||||
|
||||
if ( opt.reinit == X49GP_REINIT_FLASH_FULL )
|
||||
if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL )
|
||||
memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size );
|
||||
|
||||
bootfd = x49gp_module_open_rodata(
|
||||
|
@ -468,7 +467,7 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
|
|||
close( bootfd );
|
||||
g_free( bootfile );
|
||||
|
||||
if ( opt.reinit == X49GP_REINIT_FLASH_FULL ) {
|
||||
if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL ) {
|
||||
/* The stock firmware expects special markers in certain
|
||||
spots across the flash. Without these, the user banks
|
||||
act up and are not usable, and PINIT apparently won't
|
||||
|
@ -486,8 +485,8 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
|
|||
|
||||
retry:
|
||||
filename = NULL;
|
||||
if ( opt.firmware != NULL )
|
||||
filename = g_strdup( opt.firmware );
|
||||
if ( x49gp->firmware != NULL )
|
||||
filename = g_strdup( x49gp->firmware );
|
||||
else
|
||||
gui_open_firmware( x49gp, &filename );
|
||||
|
||||
|
@ -497,7 +496,7 @@ retry:
|
|||
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||
/* Mark firmware as invalid if there is one */
|
||||
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||
if ( opt.firmware != NULL ) {
|
||||
if ( x49gp->firmware != NULL ) {
|
||||
fprintf( stderr, "Warning: Could not "
|
||||
"open selected firmware, "
|
||||
"falling back to bootloader "
|
||||
|
@ -515,7 +514,7 @@ retry:
|
|||
/* Mark firmware as invalid
|
||||
if there is one */
|
||||
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||
if ( opt.firmware != NULL ) {
|
||||
if ( x49gp->firmware != NULL ) {
|
||||
fprintf( stderr, "Warning: "
|
||||
"Could not read "
|
||||
"selected firmware, "
|
||||
|
@ -532,7 +531,7 @@ retry:
|
|||
} else if ( bytes_read < 16 || memcmp( phys_ram_base + flash->offset + BOOT_SIZE, "KINPOUPDATEIMAGE", 16 ) != 0 ) {
|
||||
/* Mark firmware as invalid */
|
||||
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||
if ( opt.firmware != NULL ) {
|
||||
if ( x49gp->firmware != NULL ) {
|
||||
fprintf( stderr, "Warning: "
|
||||
"Firmware is invalid, "
|
||||
"falling back to "
|
||||
|
@ -554,7 +553,7 @@ retry:
|
|||
/* Mark firmware as invalid
|
||||
if there is one */
|
||||
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||
if ( opt.firmware != NULL ) {
|
||||
if ( x49gp->firmware != NULL ) {
|
||||
fprintf( stderr, "Warning: "
|
||||
"Could not read "
|
||||
"selected firmware, "
|
||||
|
|
|
@ -285,6 +285,11 @@ int main( int argc, char** argv )
|
|||
if ( x49gp_modules_init( x49gp ) )
|
||||
exit( EXIT_FAILURE );
|
||||
|
||||
x49gp->basename = g_path_get_dirname( opt.state_filename );
|
||||
x49gp->debug_port = opt.debug_port;
|
||||
x49gp->startup_reinit = opt.reinit;
|
||||
x49gp->firmware = opt.firmware;
|
||||
|
||||
int error = x49gp_modules_load( x49gp, opt.state_filename );
|
||||
if ( error || opt.reinit >= X49GP_REINIT_REBOOT_ONLY ) {
|
||||
if ( error && error != -EAGAIN )
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "list.h"
|
||||
#include "x49gp.h"
|
||||
#include "options.h"
|
||||
|
||||
int x49gp_modules_init( x49gp_t* x49gp )
|
||||
{
|
||||
|
@ -95,22 +94,22 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
|
|||
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
||||
#endif
|
||||
|
||||
if ( g_mkdir_with_parents( opt.datadir, 0755 ) ) {
|
||||
if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) {
|
||||
error = -errno;
|
||||
fprintf( stderr, "%s:%u: g_mkdir_with_parents: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
x49gp->state = g_key_file_new();
|
||||
if ( NULL == x49gp->state ) {
|
||||
x49gp->state_filename = g_key_file_new();
|
||||
if ( NULL == x49gp->state_filename ) {
|
||||
fprintf( stderr, "%s:%u: g_key_file_new: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if ( !g_key_file_load_from_file( x49gp->state, filename, G_KEY_FILE_KEEP_COMMENTS, &gerror ) &&
|
||||
if ( !g_key_file_load_from_file( x49gp->state_filename, filename, G_KEY_FILE_KEEP_COMMENTS, &gerror ) &&
|
||||
!g_error_matches( gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT ) ) {
|
||||
fprintf( stderr, "%s:%u: g_key_file_load_from_file: %s\n", __FUNCTION__, __LINE__, gerror->message );
|
||||
g_key_file_free( x49gp->state );
|
||||
g_key_file_free( x49gp->state_filename );
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -118,7 +117,7 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
|
|||
|
||||
list_for_each_entry( module, &x49gp->modules, list )
|
||||
{
|
||||
error = module->load( module, x49gp->state );
|
||||
error = module->load( module, x49gp->state_filename );
|
||||
if ( error ) {
|
||||
if ( error == -EAGAIN )
|
||||
result = -EAGAIN;
|
||||
|
@ -155,12 +154,12 @@ int x49gp_modules_save( x49gp_t* x49gp, const char* filename )
|
|||
|
||||
list_for_each_entry( module, &x49gp->modules, list )
|
||||
{
|
||||
error = module->save( module, x49gp->state );
|
||||
error = module->save( module, x49gp->state_filename );
|
||||
if ( error )
|
||||
return error;
|
||||
}
|
||||
|
||||
data = g_key_file_to_data( x49gp->state, &length, &gerror );
|
||||
data = g_key_file_to_data( x49gp->state_filename, &length, &gerror );
|
||||
if ( NULL == data ) {
|
||||
fprintf( stderr, "%s:%u: g_key_file_to_data: %s\n", __FUNCTION__, __LINE__, gerror->message );
|
||||
return -ENOMEM;
|
||||
|
@ -214,6 +213,7 @@ int x49gp_module_unregister( x49gp_module_t* module )
|
|||
|
||||
int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep, char** path )
|
||||
{
|
||||
x49gp_t* x49gp = module->x49gp;
|
||||
int error;
|
||||
|
||||
error = x49gp_module_get_string( module, key, name, reset, valuep );
|
||||
|
@ -223,7 +223,7 @@ int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char
|
|||
return error;
|
||||
}
|
||||
|
||||
*path = g_build_filename( opt.datadir, *valuep, NULL );
|
||||
*path = g_build_filename( x49gp->basename, *valuep, NULL );
|
||||
if ( NULL == path ) {
|
||||
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||
g_free( *valuep );
|
||||
|
@ -374,8 +374,6 @@ int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** p
|
|||
int error;
|
||||
|
||||
*path = g_build_filename( x49gp->progpath, name, NULL );
|
||||
if ( opt.verbose )
|
||||
fprintf( stderr, "reading %s\n", *path );
|
||||
if ( NULL == *path ) {
|
||||
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||
return -ENOMEM;
|
||||
|
@ -388,8 +386,6 @@ int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** p
|
|||
g_free( *path );
|
||||
|
||||
*path = g_build_filename( X49GP_DATADIR, name, NULL );
|
||||
if ( opt.verbose )
|
||||
fprintf( stderr, "reading %s\n", *path );
|
||||
if ( NULL == *path ) {
|
||||
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||
return -ENOMEM;
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "gdbstub.h"
|
||||
|
||||
struct options opt = {
|
||||
.datadir = NULL,
|
||||
.config_lua_filename = NULL,
|
||||
.state_filename = NULL,
|
||||
.debug_port = 0,
|
||||
|
@ -141,7 +140,9 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
{"print-config", no_argument, &print_config_and_exit, true},
|
||||
{"verbose", no_argument, &clopt_verbose, true},
|
||||
|
||||
{"datadir", required_argument, NULL, 1 },
|
||||
{"config", required_argument, NULL, 'c' },
|
||||
|
||||
{"state", required_argument, NULL, 1 },
|
||||
|
||||
{"enable-debug", required_argument, NULL, 'D' },
|
||||
{"debug", no_argument, NULL, 'd' },
|
||||
|
@ -172,22 +173,17 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
"Valid options:\n"
|
||||
" -h --help print this message and exit\n"
|
||||
" --verbose print out more information\n"
|
||||
"\n"
|
||||
" --datadir[=<absolute path>] alternate datadir (default: $XDG_CONFIG_HOME/%s/)\n"
|
||||
"\n"
|
||||
" --state[=<filename>] alternate config file\n"
|
||||
" --50g emulate an HP 50g (default)\n"
|
||||
" --49gp emulate an HP 49g+\n"
|
||||
" --newrpl-keyboard label keyboard for newRPL\n"
|
||||
"\n"
|
||||
" -n --name[=<name>] set alternate UI name\n"
|
||||
" -t --font[=<fontname>] set alternate UI font\n"
|
||||
" -s --font-size[=<X>] scale text by X (default: 3)\n"
|
||||
" -S --display-scale[=<X>] scale LCD by X (default: 2)\n"
|
||||
"\n"
|
||||
" -D --enable-debug[=<port>] enable the debugger interface\n"
|
||||
" (default port: %u)\n"
|
||||
" -d --debug use along -D to also start the debugger immediately\n"
|
||||
"\n"
|
||||
" -f --reflash[=firmware] rebuild the flash using the supplied firmware\n"
|
||||
" (default: select one interactively)\n"
|
||||
" (implies -r for safety reasons)\n"
|
||||
|
@ -195,12 +191,11 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
" in the area beyond the firmware\n"
|
||||
" -r --reboot reboot on startup instead of continuing from the\n"
|
||||
" saved state in the state file\n\n"
|
||||
"\n"
|
||||
"The state file is formatted as INI file and contains the settings for which persistence makes sense like CPU "
|
||||
"registers, etc.\n"
|
||||
"If the state file is omitted, ~/.config/%s/state is used.\n"
|
||||
"Please consult the manual for more details on state file settings.\n",
|
||||
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, progname, DEFAULT_GDBSTUB_PORT, progname );
|
||||
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname );
|
||||
exit( EXIT_SUCCESS );
|
||||
break;
|
||||
case 'r':
|
||||
|
@ -208,7 +203,7 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
opt.reinit = X49GP_REINIT_REBOOT_ONLY;
|
||||
break;
|
||||
case 1:
|
||||
opt.datadir = strdup( optarg );
|
||||
opt.state_filename = strdup( optarg );
|
||||
break;
|
||||
case 'D':
|
||||
do_enable_debugger = true;
|
||||
|
@ -250,14 +245,9 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
}
|
||||
}
|
||||
|
||||
if ( opt.datadir == NULL ) {
|
||||
const char* user_config_dir = g_get_user_config_dir();
|
||||
opt.datadir = g_build_filename( user_config_dir, progname, NULL );
|
||||
}
|
||||
const char* user_config_dir = g_get_user_config_dir();
|
||||
|
||||
opt.config_lua_filename = g_build_filename( opt.datadir, progname, config_lua_filename, NULL );
|
||||
|
||||
opt.state_filename = g_build_filename( opt.datadir, "state", NULL );
|
||||
opt.config_lua_filename = g_build_filename( user_config_dir, progname, config_lua_filename, NULL );
|
||||
|
||||
/**********************/
|
||||
/* 1. read config.lua */
|
||||
|
@ -326,8 +316,8 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
|
||||
if ( !haz_config_file ) {
|
||||
fprintf( stderr, "\nConfiguration file %s doesn't seem to exist or is invalid!\n", opt.config_lua_filename );
|
||||
fprintf( stderr, "You can solve this by running `mkdir -p %s/ && %s --print-config >> %s`\n\n", opt.datadir, progname,
|
||||
opt.config_lua_filename );
|
||||
fprintf( stderr, "You can solve this by running `mkdir -p %s/%s && %s --print-config >> %s`\n\n", user_config_dir, progname,
|
||||
progname, opt.config_lua_filename );
|
||||
}
|
||||
|
||||
if ( do_enable_debugger ) {
|
||||
|
@ -347,4 +337,7 @@ void config_init( char* progname, int argc, char* argv[] )
|
|||
if ( do_reflash_full )
|
||||
opt.reinit = X49GP_REINIT_FLASH_FULL;
|
||||
}
|
||||
|
||||
if ( opt.state_filename == NULL )
|
||||
opt.state_filename = g_build_filename( user_config_dir, progname, "state", NULL );
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H 1
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "x49gp.h"
|
||||
|
||||
#ifndef VERSION_MAJOR
|
||||
|
@ -33,8 +31,6 @@ struct options {
|
|||
int font_size;
|
||||
char* config_lua_filename;
|
||||
bool verbose;
|
||||
|
||||
char* datadir;
|
||||
};
|
||||
|
||||
extern struct options opt;
|
||||
|
|
|
@ -826,8 +826,8 @@ static void do_start_gdb_server( GtkMenuItem* menuitem, gpointer user_data )
|
|||
{
|
||||
x49gp_t* x49gp = user_data;
|
||||
|
||||
if ( opt.debug_port != 0 && !gdbserver_isactive() ) {
|
||||
gdbserver_start( opt.debug_port );
|
||||
if ( x49gp->debug_port != 0 && !gdbserver_isactive() ) {
|
||||
gdbserver_start( x49gp->debug_port );
|
||||
gdb_handlesig( x49gp->env, 0 );
|
||||
}
|
||||
}
|
||||
|
@ -1541,7 +1541,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
g_signal_connect_swapped( G_OBJECT( menu_unmount ), "activate", G_CALLBACK( s3c2410_sdi_unmount ), x49gp );
|
||||
ui->menu_unmount = menu_unmount;
|
||||
|
||||
if ( opt.debug_port != 0 ) {
|
||||
if ( x49gp->debug_port != 0 ) {
|
||||
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), gtk_separator_menu_item_new() );
|
||||
|
||||
GtkWidget* menu_debug = gtk_menu_item_new_with_label( "Start debugger" );
|
||||
|
|
|
@ -83,9 +83,13 @@ struct __x49gp_s__ {
|
|||
|
||||
x49gp_ui_t* ui;
|
||||
|
||||
GKeyFile* state;
|
||||
GKeyFile* state_filename;
|
||||
const char* progname;
|
||||
const char* progpath;
|
||||
const char* basename;
|
||||
int debug_port;
|
||||
x49gp_reinit_t startup_reinit;
|
||||
char* firmware;
|
||||
};
|
||||
|
||||
extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle );
|
||||
|
|
Loading…
Reference in a new issue