rethink options' names; prepare for more models (potentially 40g and 49g)

This commit is contained in:
Gwenhael Le Moine 2024-09-12 19:08:23 +02:00
parent 168a1e31d5
commit b20008d615
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 72 additions and 67 deletions

View file

@ -15,17 +15,17 @@
static config_t config = {
.progname = ( char* )"ui48",
.gx = true,
.model = MODEL_48GX,
.verbose = false,
.leave_shift_keys = false,
.shiftless = false,
.frontend = -1,
.frontend = FRONTEND_SDL,
.mono = false,
.gray = false,
.hide_chrome = false,
.show_ui_fullscreen = false,
.chromeless = false,
.fullscreen = false,
.scale = 1.0,
.tiny = false,
@ -40,35 +40,35 @@ config_t* config_init( int argc, char* argv[] )
int option_index;
int c = '?';
int clopt_gx = -1;
int clopt_model = -1;
int clopt_verbose = -1;
int clopt_leave_shift_keys = -1;
int clopt_shiftless = -1;
int clopt_frontend = -1;
int clopt_mono = -1;
int clopt_gray = -1;
int clopt_hide_chrome = -1;
int clopt_show_ui_fullscreen = -1;
int clopt_chromeless = -1;
int clopt_fullscreen = -1;
double clopt_scale = -1.0;
int clopt_tiny = -1;
int clopt_small = -1;
const char* optstring = "c:hvVtsirT";
const char* optstring = "h";
struct option long_options[] = {
{"help", no_argument, NULL, 'h' },
{"gx", no_argument, &clopt_gx, true },
{"sx", no_argument, &clopt_gx, false },
{"48sx", no_argument, &clopt_model, MODEL_48SX },
{"48gx", no_argument, &clopt_model, MODEL_48GX },
{"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 },
{"tui", no_argument, &clopt_frontend, FRONTEND_NCURSES},
{"tui-small", no_argument, NULL, 6110 },
{"tui-tiny", no_argument, NULL, 6120 },
{"mono", no_argument, &clopt_mono, true },
{"gray", no_argument, &clopt_gray, true },
{"no-chrome", no_argument, &clopt_hide_chrome, true },
{"fullscreen", no_argument, &clopt_show_ui_fullscreen, true },
{"chromeless", no_argument, &clopt_chromeless, true },
{"fullscreen", no_argument, &clopt_fullscreen, true },
{"scale", required_argument, NULL, 7110 },
{0, 0, 0, 0 }
@ -77,27 +77,27 @@ config_t* config_init( int argc, char* argv[] )
const char* help_text = "usage: %s [options]\n"
"options:\n"
" -h --help what you are reading\n"
" --gui use graphical (SDL2) front-end (default: true)\n"
" --tui use text front-end (default: false)\n"
" --tui-small use text small front-end (2×2 pixels per character) (default: "
" --gui graphical (SDL2) front-end (default: true)\n"
" --tui text front-end (default: false)\n"
" --tui-small text small front-end (2×2 pixels per character) (default: "
"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"
" --no-chrome only display the LCD (default: "
" --chromeless only show display (default: "
"false)\n"
" --fullscreen make the UI fullscreen "
"(default: false)\n"
" --scale=<number> make the UI scale <number> times "
" --scale=<n> make the UI scale <n> times "
"(default: 1.0)\n"
" --mono make the UI monochrome (default: "
"false)\n"
" --gray make the UI grayscale (default: "
"false)\n"
" --gx make the GUI looks like a HP 48GX (default: "
" --48gx make the GUI looks like a HP 48GX (default: "
"auto)\n"
" --sx make the GUI looks like a HP 48SX (default: "
" --48sx make the GUI looks like a HP 48SX (default: "
"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";
while ( c != EOF ) {
@ -136,14 +136,14 @@ config_t* config_init( int argc, char* argv[] )
/****************************************************/
if ( clopt_verbose != -1 )
config.verbose = clopt_verbose;
if ( clopt_gx != -1 )
config.gx = clopt_gx;
if ( clopt_model != -1 )
config.model = clopt_model;
if ( clopt_frontend != -1 )
config.frontend = clopt_frontend;
if ( clopt_hide_chrome != -1 )
config.hide_chrome = clopt_hide_chrome;
if ( clopt_show_ui_fullscreen != -1 )
config.show_ui_fullscreen = clopt_show_ui_fullscreen;
if ( clopt_chromeless != -1 )
config.chromeless = clopt_chromeless;
if ( clopt_fullscreen != -1 )
config.fullscreen = clopt_fullscreen;
if ( clopt_scale > 0.0 )
config.scale = clopt_scale;
if ( clopt_mono != -1 )
@ -154,8 +154,8 @@ config_t* config_init( int argc, char* argv[] )
config.tiny = clopt_tiny;
if ( clopt_gray != -1 )
config.gray = clopt_gray;
if ( clopt_leave_shift_keys != -1 )
config.leave_shift_keys = clopt_leave_shift_keys;
if ( clopt_shiftless != -1 )
config.shiftless = clopt_shiftless;
return &config;
}

View file

@ -6,19 +6,24 @@
#define FRONTEND_SDL 1
#define FRONTEND_NCURSES 2
#define MODEL_48SX 485
#define MODEL_48GX 486
/* #define MODEL_40G 406 */
/* #define MODEL_49G 496 */
typedef struct {
char* progname;
bool gx;
int model;
bool verbose;
bool leave_shift_keys;
bool shiftless;
int frontend;
bool mono;
bool gray;
bool hide_chrome;
bool show_ui_fullscreen;
bool chromeless;
bool fullscreen;
double scale;
bool tiny;

View file

@ -19,8 +19,8 @@
#include "ui.h"
#include "ui_inner.h"
#define COLORS ( config.gx ? colors_gx : colors_sx )
#define BUTTONS ( config.gx ? buttons_gx : buttons_sx )
#define COLORS ( config.model == MODEL_48GX ? colors_gx : colors_sx )
#define BUTTONS ( config.model == MODEL_48GX ? buttons_gx : buttons_sx )
#define LCD_OFFSET_X 1
#define LCD_OFFSET_Y 1

View file

@ -7,8 +7,8 @@
#include "ui.h"
#include "ui_inner.h"
#define COLORS ( config.gx ? colors_gx : colors_sx )
#define BUTTONS ( config.gx ? buttons_gx : buttons_sx )
#define COLORS ( config.model == MODEL_48GX ? colors_gx : colors_sx )
#define BUTTONS ( config.model == MODEL_48GX ? buttons_gx : buttons_sx )
#define KEYBOARD_HEIGHT ( BUTTONS[ LAST_HPKEY ].y + BUTTONS[ LAST_HPKEY ].h )
#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:
return HPKEY_ON;
case SDLK_LSHIFT:
if ( !config.leave_shift_keys )
if ( !config.shiftless )
return HPKEY_SHL;
break;
case SDLK_RSHIFT:
if ( !config.leave_shift_keys )
if ( !config.shiftless )
return HPKEY_SHR;
break;
case SDLK_F2:
@ -514,12 +514,12 @@ static void _draw_header( void )
int y;
// insert the HP Logo
if ( config.gx )
if ( config.model == MODEL_48GX )
x -= 6;
__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 - 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 );
@ -527,7 +527,7 @@ static void _draw_header( void )
}
// 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;
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 );
@ -679,8 +679,8 @@ static void _draw_key( int hpkey )
static void _draw_keypad( void )
{
int x, y;
int pw = config.gx ? 58 : 44;
int ph = config.gx ? 48 : 9;
int pw = config.model == MODEL_48GX ? 58 : 44;
int ph = config.model == MODEL_48GX ? 48 : 9;
int left_label_width, right_label_width;
int space_char_width = SmallTextWidth( " ", 1 );
int total_top_labels_width;
@ -691,7 +691,7 @@ static void _draw_keypad( void )
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x;
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_ascent - small_descent;
if ( config.gx ) {
if ( config.model == MODEL_48GX ) {
x -= 6;
y -= 6;
} else
@ -705,7 +705,7 @@ static void _draw_keypad( void )
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x + BUTTONS[ i ].w;
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y + BUTTONS[ i ].h;
if ( config.gx ) {
if ( config.model == MODEL_48GX ) {
x += 3;
y += 1;
} 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
static void _show_key( int hpkey )
{
if ( config.hide_chrome || hpkey < 0 )
if ( config.chromeless || hpkey < 0 )
return;
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;
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_y = 0;
width = DISPLAY_WIDTH;
@ -1057,7 +1057,7 @@ void ui_start_sdl( config_t* conf )
}
uint32_t window_flags = SDL_WINDOW_ALLOW_HIGHDPI;
if ( config.show_ui_fullscreen )
if ( config.fullscreen )
window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
else
window_flags |= SDL_WINDOW_RESIZABLE;
@ -1081,7 +1081,7 @@ void ui_start_sdl( config_t* conf )
apply_contrast();
if ( !config.hide_chrome ) {
if ( !config.chromeless ) {
int cut = BUTTONS[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19;
create_buttons_textures();