rethink options' names; prepare for more models (potentially 40g and 49g)
This commit is contained in:
parent
168a1e31d5
commit
b20008d615
4 changed files with 72 additions and 67 deletions
64
src/config.c
64
src/config.c
|
@ -15,17 +15,17 @@
|
||||||
static config_t config = {
|
static config_t config = {
|
||||||
.progname = ( char* )"ui48",
|
.progname = ( char* )"ui48",
|
||||||
|
|
||||||
.gx = true,
|
.model = MODEL_48GX,
|
||||||
.verbose = false,
|
.verbose = false,
|
||||||
.leave_shift_keys = false,
|
.shiftless = false,
|
||||||
|
|
||||||
.frontend = -1,
|
.frontend = FRONTEND_SDL,
|
||||||
|
|
||||||
.mono = false,
|
.mono = false,
|
||||||
.gray = false,
|
.gray = false,
|
||||||
|
|
||||||
.hide_chrome = false,
|
.chromeless = false,
|
||||||
.show_ui_fullscreen = false,
|
.fullscreen = false,
|
||||||
.scale = 1.0,
|
.scale = 1.0,
|
||||||
|
|
||||||
.tiny = false,
|
.tiny = false,
|
||||||
|
@ -40,35 +40,35 @@ config_t* config_init( int argc, char* argv[] )
|
||||||
int option_index;
|
int option_index;
|
||||||
int c = '?';
|
int c = '?';
|
||||||
|
|
||||||
int clopt_gx = -1;
|
int clopt_model = -1;
|
||||||
int clopt_verbose = -1;
|
int clopt_verbose = -1;
|
||||||
int clopt_leave_shift_keys = -1;
|
int clopt_shiftless = -1;
|
||||||
int clopt_frontend = -1;
|
int clopt_frontend = -1;
|
||||||
int clopt_mono = -1;
|
int clopt_mono = -1;
|
||||||
int clopt_gray = -1;
|
int clopt_gray = -1;
|
||||||
int clopt_hide_chrome = -1;
|
int clopt_chromeless = -1;
|
||||||
int clopt_show_ui_fullscreen = -1;
|
int clopt_fullscreen = -1;
|
||||||
double clopt_scale = -1.0;
|
double clopt_scale = -1.0;
|
||||||
|
|
||||||
int clopt_tiny = -1;
|
int clopt_tiny = -1;
|
||||||
int clopt_small = -1;
|
int clopt_small = -1;
|
||||||
|
|
||||||
const char* optstring = "c:hvVtsirT";
|
const char* optstring = "h";
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h' },
|
{"help", no_argument, NULL, 'h' },
|
||||||
|
|
||||||
{"gx", no_argument, &clopt_gx, true },
|
{"48sx", no_argument, &clopt_model, MODEL_48SX },
|
||||||
{"sx", no_argument, &clopt_gx, false },
|
{"48gx", no_argument, &clopt_model, MODEL_48GX },
|
||||||
{"verbose", no_argument, &clopt_verbose, true },
|
{"verbose", no_argument, &clopt_verbose, true },
|
||||||
{"leave-shift-keys", no_argument, &clopt_leave_shift_keys, true },
|
{"shiftless", no_argument, &clopt_shiftless, true },
|
||||||
{"gui", no_argument, &clopt_frontend, FRONTEND_SDL },
|
{"gui", no_argument, &clopt_frontend, FRONTEND_SDL },
|
||||||
{"tui", no_argument, &clopt_frontend, FRONTEND_NCURSES},
|
{"tui", no_argument, &clopt_frontend, FRONTEND_NCURSES},
|
||||||
{"tui-small", no_argument, NULL, 6110 },
|
{"tui-small", no_argument, NULL, 6110 },
|
||||||
{"tui-tiny", no_argument, NULL, 6120 },
|
{"tui-tiny", no_argument, NULL, 6120 },
|
||||||
{"mono", no_argument, &clopt_mono, true },
|
{"mono", no_argument, &clopt_mono, true },
|
||||||
{"gray", no_argument, &clopt_gray, true },
|
{"gray", no_argument, &clopt_gray, true },
|
||||||
{"no-chrome", no_argument, &clopt_hide_chrome, true },
|
{"chromeless", no_argument, &clopt_chromeless, true },
|
||||||
{"fullscreen", no_argument, &clopt_show_ui_fullscreen, true },
|
{"fullscreen", no_argument, &clopt_fullscreen, true },
|
||||||
{"scale", required_argument, NULL, 7110 },
|
{"scale", required_argument, NULL, 7110 },
|
||||||
|
|
||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
|
@ -77,27 +77,27 @@ config_t* config_init( int argc, char* argv[] )
|
||||||
const char* help_text = "usage: %s [options]\n"
|
const char* help_text = "usage: %s [options]\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" -h --help what you are reading\n"
|
" -h --help what you are reading\n"
|
||||||
" --gui use graphical (SDL2) front-end (default: true)\n"
|
" --gui graphical (SDL2) front-end (default: true)\n"
|
||||||
" --tui use text front-end (default: false)\n"
|
" --tui text front-end (default: false)\n"
|
||||||
" --tui-small use text small front-end (2×2 pixels per character) (default: "
|
" --tui-small text small front-end (2×2 pixels per character) (default: "
|
||||||
"false)\n"
|
"false)\n"
|
||||||
" --tui-tiny use text tiny front-end (2×4 pixels per character) (default: "
|
" --tui-tiny text tiny front-end (2×4 pixels per character) (default: "
|
||||||
"false)\n"
|
"false)\n"
|
||||||
" --no-chrome only display the LCD (default: "
|
" --chromeless only show display (default: "
|
||||||
"false)\n"
|
"false)\n"
|
||||||
" --fullscreen make the UI fullscreen "
|
" --fullscreen make the UI fullscreen "
|
||||||
"(default: false)\n"
|
"(default: false)\n"
|
||||||
" --scale=<number> make the UI scale <number> times "
|
" --scale=<n> make the UI scale <n> times "
|
||||||
"(default: 1.0)\n"
|
"(default: 1.0)\n"
|
||||||
" --mono make the UI monochrome (default: "
|
" --mono make the UI monochrome (default: "
|
||||||
"false)\n"
|
"false)\n"
|
||||||
" --gray make the UI grayscale (default: "
|
" --gray make the UI grayscale (default: "
|
||||||
"false)\n"
|
"false)\n"
|
||||||
" --gx make the GUI looks like a HP 48GX (default: "
|
" --48gx make the GUI looks like a HP 48GX (default: "
|
||||||
"auto)\n"
|
"auto)\n"
|
||||||
" --sx make the GUI looks like a HP 48SX (default: "
|
" --48sx make the GUI looks like a HP 48SX (default: "
|
||||||
"auto)\n"
|
"auto)\n"
|
||||||
" --leave-shift-keys _not_ mapping the shift keys to let them free for numbers (default: "
|
" --shiftless don't map the shift keys to let them free for numbers (default: "
|
||||||
"false)\n";
|
"false)\n";
|
||||||
|
|
||||||
while ( c != EOF ) {
|
while ( c != EOF ) {
|
||||||
|
@ -136,14 +136,14 @@ config_t* config_init( int argc, char* argv[] )
|
||||||
/****************************************************/
|
/****************************************************/
|
||||||
if ( clopt_verbose != -1 )
|
if ( clopt_verbose != -1 )
|
||||||
config.verbose = clopt_verbose;
|
config.verbose = clopt_verbose;
|
||||||
if ( clopt_gx != -1 )
|
if ( clopt_model != -1 )
|
||||||
config.gx = clopt_gx;
|
config.model = clopt_model;
|
||||||
if ( clopt_frontend != -1 )
|
if ( clopt_frontend != -1 )
|
||||||
config.frontend = clopt_frontend;
|
config.frontend = clopt_frontend;
|
||||||
if ( clopt_hide_chrome != -1 )
|
if ( clopt_chromeless != -1 )
|
||||||
config.hide_chrome = clopt_hide_chrome;
|
config.chromeless = clopt_chromeless;
|
||||||
if ( clopt_show_ui_fullscreen != -1 )
|
if ( clopt_fullscreen != -1 )
|
||||||
config.show_ui_fullscreen = clopt_show_ui_fullscreen;
|
config.fullscreen = clopt_fullscreen;
|
||||||
if ( clopt_scale > 0.0 )
|
if ( clopt_scale > 0.0 )
|
||||||
config.scale = clopt_scale;
|
config.scale = clopt_scale;
|
||||||
if ( clopt_mono != -1 )
|
if ( clopt_mono != -1 )
|
||||||
|
@ -154,8 +154,8 @@ config_t* config_init( int argc, char* argv[] )
|
||||||
config.tiny = clopt_tiny;
|
config.tiny = clopt_tiny;
|
||||||
if ( clopt_gray != -1 )
|
if ( clopt_gray != -1 )
|
||||||
config.gray = clopt_gray;
|
config.gray = clopt_gray;
|
||||||
if ( clopt_leave_shift_keys != -1 )
|
if ( clopt_shiftless != -1 )
|
||||||
config.leave_shift_keys = clopt_leave_shift_keys;
|
config.shiftless = clopt_shiftless;
|
||||||
|
|
||||||
return &config;
|
return &config;
|
||||||
}
|
}
|
||||||
|
|
13
src/config.h
13
src/config.h
|
@ -6,19 +6,24 @@
|
||||||
#define FRONTEND_SDL 1
|
#define FRONTEND_SDL 1
|
||||||
#define FRONTEND_NCURSES 2
|
#define FRONTEND_NCURSES 2
|
||||||
|
|
||||||
|
#define MODEL_48SX 485
|
||||||
|
#define MODEL_48GX 486
|
||||||
|
/* #define MODEL_40G 406 */
|
||||||
|
/* #define MODEL_49G 496 */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* progname;
|
char* progname;
|
||||||
|
|
||||||
bool gx;
|
int model;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool leave_shift_keys;
|
bool shiftless;
|
||||||
|
|
||||||
int frontend;
|
int frontend;
|
||||||
bool mono;
|
bool mono;
|
||||||
bool gray;
|
bool gray;
|
||||||
|
|
||||||
bool hide_chrome;
|
bool chromeless;
|
||||||
bool show_ui_fullscreen;
|
bool fullscreen;
|
||||||
double scale;
|
double scale;
|
||||||
|
|
||||||
bool tiny;
|
bool tiny;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "ui_inner.h"
|
#include "ui_inner.h"
|
||||||
|
|
||||||
#define COLORS ( config.gx ? colors_gx : colors_sx )
|
#define COLORS ( config.model == MODEL_48GX ? colors_gx : colors_sx )
|
||||||
#define BUTTONS ( config.gx ? buttons_gx : buttons_sx )
|
#define BUTTONS ( config.model == MODEL_48GX ? buttons_gx : buttons_sx )
|
||||||
|
|
||||||
#define LCD_OFFSET_X 1
|
#define LCD_OFFSET_X 1
|
||||||
#define LCD_OFFSET_Y 1
|
#define LCD_OFFSET_Y 1
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "ui_inner.h"
|
#include "ui_inner.h"
|
||||||
|
|
||||||
#define COLORS ( config.gx ? colors_gx : colors_sx )
|
#define COLORS ( config.model == MODEL_48GX ? colors_gx : colors_sx )
|
||||||
#define BUTTONS ( config.gx ? buttons_gx : buttons_sx )
|
#define BUTTONS ( config.model == MODEL_48GX ? buttons_gx : buttons_sx )
|
||||||
|
|
||||||
#define KEYBOARD_HEIGHT ( BUTTONS[ LAST_HPKEY ].y + BUTTONS[ LAST_HPKEY ].h )
|
#define KEYBOARD_HEIGHT ( BUTTONS[ LAST_HPKEY ].y + BUTTONS[ LAST_HPKEY ].h )
|
||||||
#define KEYBOARD_WIDTH ( BUTTONS[ LAST_HPKEY ].x + BUTTONS[ LAST_HPKEY ].w )
|
#define KEYBOARD_WIDTH ( BUTTONS[ LAST_HPKEY ].x + BUTTONS[ LAST_HPKEY ].w )
|
||||||
|
@ -395,11 +395,11 @@ static int sdlkey_to_hpkey( SDL_Keycode k )
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
return HPKEY_ON;
|
return HPKEY_ON;
|
||||||
case SDLK_LSHIFT:
|
case SDLK_LSHIFT:
|
||||||
if ( !config.leave_shift_keys )
|
if ( !config.shiftless )
|
||||||
return HPKEY_SHL;
|
return HPKEY_SHL;
|
||||||
break;
|
break;
|
||||||
case SDLK_RSHIFT:
|
case SDLK_RSHIFT:
|
||||||
if ( !config.leave_shift_keys )
|
if ( !config.shiftless )
|
||||||
return HPKEY_SHR;
|
return HPKEY_SHR;
|
||||||
break;
|
break;
|
||||||
case SDLK_F2:
|
case SDLK_F2:
|
||||||
|
@ -514,12 +514,12 @@ static void _draw_header( void )
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
// insert the HP Logo
|
// insert the HP Logo
|
||||||
if ( config.gx )
|
if ( config.model == MODEL_48GX )
|
||||||
x -= 6;
|
x -= 6;
|
||||||
|
|
||||||
__draw_bitmap( x, 10, hp_width, hp_height, hp_bitmap, LOGO, LOGO_BACK );
|
__draw_bitmap( x, 10, hp_width, hp_height, hp_bitmap, LOGO, LOGO_BACK );
|
||||||
|
|
||||||
if ( !config.gx ) {
|
if ( config.model == MODEL_48SX ) {
|
||||||
__draw_line( display_offset_x, 9, display_offset_x + hp_width - 1, 9, FRAME );
|
__draw_line( display_offset_x, 9, display_offset_x + hp_width - 1, 9, FRAME );
|
||||||
__draw_line( display_offset_x - 1, 10, display_offset_x - 1, 10 + hp_height - 1, FRAME );
|
__draw_line( display_offset_x - 1, 10, display_offset_x - 1, 10 + hp_height - 1, FRAME );
|
||||||
__draw_line( display_offset_x, 10 + hp_height, display_offset_x + hp_width - 1, 10 + hp_height, FRAME );
|
__draw_line( display_offset_x, 10 + hp_height, display_offset_x + hp_width - 1, 10 + hp_height, FRAME );
|
||||||
|
@ -527,7 +527,7 @@ static void _draw_header( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the name of it
|
// write the name of it
|
||||||
if ( config.gx ) {
|
if ( config.model == MODEL_48GX ) {
|
||||||
x = display_offset_x + DISPLAY_WIDTH - gx_128K_ram_width + gx_128K_ram_x_hot + 2;
|
x = display_offset_x + DISPLAY_WIDTH - gx_128K_ram_width + gx_128K_ram_x_hot + 2;
|
||||||
y = 10 + gx_128K_ram_y_hot;
|
y = 10 + gx_128K_ram_y_hot;
|
||||||
__draw_bitmap( x, y, gx_128K_ram_width, gx_128K_ram_height, gx_128K_ram_bitmap, LABEL, DISP_PAD );
|
__draw_bitmap( x, y, gx_128K_ram_width, gx_128K_ram_height, gx_128K_ram_bitmap, LABEL, DISP_PAD );
|
||||||
|
@ -679,8 +679,8 @@ static void _draw_key( int hpkey )
|
||||||
static void _draw_keypad( void )
|
static void _draw_keypad( void )
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
int pw = config.gx ? 58 : 44;
|
int pw = config.model == MODEL_48GX ? 58 : 44;
|
||||||
int ph = config.gx ? 48 : 9;
|
int ph = config.model == MODEL_48GX ? 48 : 9;
|
||||||
int left_label_width, right_label_width;
|
int left_label_width, right_label_width;
|
||||||
int space_char_width = SmallTextWidth( " ", 1 );
|
int space_char_width = SmallTextWidth( " ", 1 );
|
||||||
int total_top_labels_width;
|
int total_top_labels_width;
|
||||||
|
@ -691,7 +691,7 @@ static void _draw_keypad( void )
|
||||||
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x;
|
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x;
|
||||||
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_ascent - small_descent;
|
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_ascent - small_descent;
|
||||||
|
|
||||||
if ( config.gx ) {
|
if ( config.model == MODEL_48GX ) {
|
||||||
x -= 6;
|
x -= 6;
|
||||||
y -= 6;
|
y -= 6;
|
||||||
} else
|
} else
|
||||||
|
@ -705,7 +705,7 @@ static void _draw_keypad( void )
|
||||||
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x + BUTTONS[ i ].w;
|
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x + BUTTONS[ i ].w;
|
||||||
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y + BUTTONS[ i ].h;
|
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y + BUTTONS[ i ].h;
|
||||||
|
|
||||||
if ( config.gx ) {
|
if ( config.model == MODEL_48GX ) {
|
||||||
x += 3;
|
x += 3;
|
||||||
y += 1;
|
y += 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -826,7 +826,7 @@ static void _draw_background_LCD( void ) { __draw_rect( display_offset_x, displa
|
||||||
// Show the hp key which is being pressed
|
// Show the hp key which is being pressed
|
||||||
static void _show_key( int hpkey )
|
static void _show_key( int hpkey )
|
||||||
{
|
{
|
||||||
if ( config.hide_chrome || hpkey < 0 )
|
if ( config.chromeless || hpkey < 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SDL_SetRenderTarget( renderer, main_texture );
|
SDL_SetRenderTarget( renderer, main_texture );
|
||||||
|
@ -1049,7 +1049,7 @@ void ui_start_sdl( config_t* conf )
|
||||||
width = ( BUTTONS[ LAST_HPKEY ].x + BUTTONS[ LAST_HPKEY ].w ) + 2 * SIDE_SKIP;
|
width = ( BUTTONS[ LAST_HPKEY ].x + BUTTONS[ LAST_HPKEY ].w ) + 2 * SIDE_SKIP;
|
||||||
height = display_offset_y + DISPLAY_HEIGHT + DISP_KBD_SKIP + BUTTONS[ LAST_HPKEY ].y + BUTTONS[ LAST_HPKEY ].h + BOTTOM_SKIP;
|
height = display_offset_y + DISPLAY_HEIGHT + DISP_KBD_SKIP + BUTTONS[ LAST_HPKEY ].y + BUTTONS[ LAST_HPKEY ].h + BOTTOM_SKIP;
|
||||||
|
|
||||||
if ( config.hide_chrome ) {
|
if ( config.chromeless ) {
|
||||||
display_offset_x = 0;
|
display_offset_x = 0;
|
||||||
display_offset_y = 0;
|
display_offset_y = 0;
|
||||||
width = DISPLAY_WIDTH;
|
width = DISPLAY_WIDTH;
|
||||||
|
@ -1057,7 +1057,7 @@ void ui_start_sdl( config_t* conf )
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI;
|
uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
if ( config.show_ui_fullscreen )
|
if ( config.fullscreen )
|
||||||
window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
else
|
else
|
||||||
window_flags |= SDL_WINDOW_RESIZABLE;
|
window_flags |= SDL_WINDOW_RESIZABLE;
|
||||||
|
@ -1081,7 +1081,7 @@ void ui_start_sdl( config_t* conf )
|
||||||
|
|
||||||
apply_contrast();
|
apply_contrast();
|
||||||
|
|
||||||
if ( !config.hide_chrome ) {
|
if ( !config.chromeless ) {
|
||||||
int cut = BUTTONS[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19;
|
int cut = BUTTONS[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19;
|
||||||
|
|
||||||
create_buttons_textures();
|
create_buttons_textures();
|
||||||
|
|
Loading…
Reference in a new issue