ripped out X11 code

This commit is contained in:
Gwenhael Le Moine 2023-09-13 13:11:52 +02:00
parent e8b179534a
commit 5d91092d1a
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
10 changed files with 94 additions and 5006 deletions

View file

@ -1,8 +1,5 @@
# Makefile to build x48ng without autotools
# possible values: x11, sdl1
GUI ?= x11
VERSION_MAJOR = 0
VERSION_MINOR = 13
PATCHLEVEL = 0
@ -14,14 +11,8 @@ CC = gcc
CFLAGS = -g -O2 -I./src/ -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL)
LIBS = -lm
ifeq ($(GUI), x11)
CFLAGS += $(shell pkg-config --cflags x11 xext) -D_GNU_SOURCE=1 -DGUI_IS_X11=1
LIBS += $(shell pkg-config --libs x11 xext)
endif
ifeq ($(GUI), sdl1)
CFLAGS += $(shell pkg-config --cflags SDL_gfx sdl12_compat) -DGUI_IS_SDL1=1
LIBS += $(shell pkg-config --libs SDL_gfx sdl12_compat)
endif
CFLAGS += $(shell pkg-config --cflags SDL_gfx sdl12_compat)
LIBS += $(shell pkg-config --libs SDL_gfx sdl12_compat)
FULL_WARNINGS = no
ifeq ($(FULL_WARNINGS), yes)
@ -39,7 +30,6 @@ DOTOS = src/main.o \
src/romio.o \
src/timer.o \
src/error_handling.o \
src/x48_resources.o \
src/x48_lcd.o \
src/x48.o
@ -100,6 +90,3 @@ install: all
install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/applications
sed "s|@PREFIX@|$(PREFIX)|g" dist/x48ng.desktop > $(DESTDIR)$(PREFIX)/share/applications/x48ng.desktop
install -m 755 -d -- $(DESTDIR)/etc/X11/app-defaults
install -c -m 644 dist/X48NG.ad $(DESTDIR)/etc/X11/app-defaults/X48NG

39
dist/X48NG.ad vendored
View file

@ -1,39 +0,0 @@
!
! X11 related stuff
!
*iconic: False
*visual: Default
*mono: False
*gray: False
*monoIcon: False
*useXShm: True
*smallLabelFont: -*-fixed-bold-r-normal-*-14-*-*-*-*-*-iso8859-1
*mediumLabelFont: -*-fixed-bold-r-normal-*-15-*-*-*-*-*-iso8859-1
*largeLabelFont: -*-fixed-medium-r-normal-*-20-*-*-*-*-*-iso8859-1
*connectionFont: -*-fixed-medium-r-normal-*-12-*-*-*-*-*-iso8859-1
!
! informative stuff
!
*verbose: False
*printVersion: False
*printCopyright: False
*printWarranty: False
!
! resources controlling the connections
!
*useTerminal: True
*useSerial: False
*serialLine: /dev/ttyS0
!
! stuff controlling initialization
!
*completeInitialize: False
*resetOnStartup: False
*romFileName: rom.dump
*homeDirectory: .x48ng

View file

@ -2427,11 +2427,6 @@ inline void schedule( void ) {
if ( got_alarm ) {
got_alarm = 0;
#if defined( GUI_IS_X11 )
if ( disp.display_update )
refresh_display();
#endif
get_ui_event();
}
}

View file

@ -257,10 +257,6 @@ void do_shutdown( void ) {
if ( device.display_touched ) {
device.display_touched = 0;
update_display();
#if defined( GUI_IS_X11 )
if ( disp.display_update )
refresh_display();
#endif
}
stop_timer( RUN_TIMER );
@ -282,11 +278,6 @@ void do_shutdown( void ) {
if ( got_alarm ) {
got_alarm = 0;
#if defined( GUI_IS_X11 )
if ( disp.display_update )
refresh_display();
#endif
ticks = get_t1_t2();
if ( saturn.t2_ctrl & 0x01 )
saturn.timer2 = ticks.t2_ticks;

View file

@ -14,7 +14,6 @@
#include "options.h"
#include "hp48.h"
#include "x48.h"
#include "x48_resources.h"
char* progname;
@ -34,7 +33,6 @@ void signal_handler( int sig ) {
}
}
int parse_args( int argc, char* argv[] ) {
int option_index;
char c = '?';
@ -72,14 +70,10 @@ int parse_args( int argc, char* argv[] ) {
"\t-V --verbose :\n\t\t be verbose\n"
"\t-t --use-terminal\n"
"\t-s --use-serial\n"
"\t-i --initialize :\n\t\t initialize the config and content of x48ng's home\n"
"\t-i --initialize :\n\t\t initialize the config and content of "
"x48ng's home\n"
"\t-R --reset\n"
"\t-T --throttle :\n\t\t try to emulate real speed\n"
"\t-n --netbook :\n\t\t horizontal GUI\n"
"\t-g --gray :\n\t\t grayscale GUI\n"
"\t-m --mono :\n\t\t monochrome GUI\n"
"\t-x --use-xshm\n"
;
"\t-T --throttle :\n\t\t try to emulate real speed\n";
while ( c != EOF ) {
c = getopt_long( argc, argv, optstring, long_options, &option_index );
@ -99,9 +93,50 @@ int parse_args( int argc, char* argv[] ) {
exit( 0 );
break;
case 'v':
show_version();
show_copyright();
show_warranty();
fprintf( stdout, "\nx48ng %d.%d.%d", VERSION_MAJOR,
VERSION_MINOR, PATCHLEVEL );
fprintf( stdout, "\n\
COPYRIGHT\n\
\n\
x48ng is an Emulator for the HP-48 Handheld Calculator.\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2 of the License, or\n\
(at your option) any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n" );
fprintf( stdout, "\n\
NO WARRANTY\n\
\n\
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n\
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n\
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n\
PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n\
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n\
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n\
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n\
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n\
REPAIR OR CORRECTION.\n\
\n\
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n\
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n\
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n\
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n\
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n\
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n\
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n\
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n\
POSSIBILITY OF SUCH DAMAGES.\n\n" );
break;
case 'V':
verbose = 1;
@ -144,10 +179,10 @@ int parse_args( int argc, char* argv[] ) {
}
if ( optind < argc ) {
fprintf(stderr, "Invalid arguments : ");
fprintf( stderr, "Invalid arguments : " );
while ( optind < argc )
fprintf(stderr, "%s\n", argv[ optind++ ]);
fprintf(stderr, "\n");
fprintf( stderr, "%s\n", argv[ optind++ ] );
fprintf( stderr, "\n" );
}
return ( optind );
@ -170,29 +205,9 @@ int main( int argc, char** argv ) {
/**********/
parse_args( argc, argv );
#if defined( GUI_IS_X11 )
/*
* save command line options
*/
/* save_options( argc, argv ); */
/*
* Open up the display
*/
if ( InitDisplay( argc, argv ) < 0 )
{
fprintf( stderr, "cannot InitDisplay" );
exit( 1 );
}
#elif defined( GUI_IS_SDL1 )
// SDL Initialization
SDLInit();
// Global parameter initialization
get_resources();
#endif
/*
* initialize emulator stuff
*/
@ -201,16 +216,7 @@ int main( int argc, char** argv ) {
/*
* Create the HP-48 window
*/
#if defined( GUI_IS_X11 )
if ( CreateWindows( argc, argv ) < 0 ) {
fprintf( stderr, "can\'t create window\n" );
exit( 1 );
}
init_annunc();
#elif defined( GUI_IS_SDL1 )
SDLCreateHP();
#endif
serial_init();

3924
src/x48.c

File diff suppressed because it is too large Load diff

301
src/x48.h
View file

@ -3,19 +3,9 @@
#include "hp48.h" /* word_20, word_4 */
#if defined( GUI_IS_X11 )
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#elif defined( GUI_IS_SDL1 )
#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <SDL/SDL_rotozoom.h>
#endif
// Colors
#define WHITE 0
@ -106,9 +96,6 @@
#define UPDATE_MENU 1
#define UPDATE_DISP 2
#if defined( GUI_IS_X11 )
#define COLOR( c ) ( colors[ ( c ) ].xcolor.pixel )
#elif defined( GUI_IS_SDL1 )
#define _KEYBOARD_HEIGHT \
( buttons_gx[ LAST_BUTTON ].y + buttons_gx[ LAST_BUTTON ].h )
#define _KEYBOARD_WIDTH \
@ -129,7 +116,6 @@
#define _KEYBOARD_OFFSET_X SIDE_SKIP
#define _KEYBOARD_OFFSET_Y ( TOP_SKIP + DISPLAY_HEIGHT + DISP_KBD_SKIP )
#endif // SDL1
/* #ifndef _HP_H */
/* #define _HP_H 1 */
@ -253,205 +239,6 @@ static unsigned char gx_green_bitmap[] = {
/* #endif /\* !_HP_H *\/ */
#if defined( GUI_IS_X11 )
/* #ifndef _ICON_H */
/* #define _ICON_H 1 */
#define hp48_icon_width 32
#define hp48_icon_height 64
static unsigned char hp48_icon_bitmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff,
0x07, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x07, 0xff, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x63, 0x8c, 0x31, 0xc6,
0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x03, 0x8c, 0x31, 0xc6, 0x03, 0x8c, 0x31, 0xc6,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0x30, 0x0c, 0xc3,
0xe3, 0x30, 0x0c, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xe3, 0x30, 0x0c, 0xc3, 0xe3, 0x30, 0x0c, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe3, 0x30, 0x0c, 0xc3, 0xe3, 0x30, 0x0c, 0xc3,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0x30, 0x0c, 0xc3,
0xe3, 0x30, 0x0c, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
#define hp48_top_width 32
#define hp48_top_height 30
static unsigned char hp48_top_bitmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff,
0x07, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x07, 0xff, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff };
#define hp48_bottom_width 32
#define hp48_bottom_height 64
static unsigned char hp48_bottom_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x63, 0x8c, 0x31, 0xc6,
0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x03, 0x8c, 0x31, 0xc6, 0x03, 0x8c, 0x31, 0xc6,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0x30, 0x0c, 0xc3,
0xe3, 0x30, 0x0c, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xe3, 0x30, 0x0c, 0xc3, 0xe3, 0x30, 0x0c, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe3, 0x30, 0x0c, 0xc3, 0xe3, 0x30, 0x0c, 0xc3,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0x30, 0x0c, 0xc3,
0xe3, 0x30, 0x0c, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
#define hp48_logo_width 13
#define hp48_logo_height 4
static unsigned char hp48_logo_bitmap[] = { 0x00, 0x00, 0x00, 0x00,
0xf8, 0x1f, 0xf8, 0x1f };
#define hp48_text_width 29
#define hp48_text_height 7
static unsigned char hp48_text_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xfe, 0x1f };
#define hp48_disp_width 29
#define hp48_disp_height 21
static unsigned char hp48_disp_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x1f,
0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f,
0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f,
0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f,
0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f };
#define hp48_keys_width 30
#define hp48_keys_height 61
static unsigned char hp48_keys_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9c, 0x73, 0xce, 0x39, 0x9c, 0x73, 0xce, 0x39, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x9c, 0x73, 0xce, 0x39, 0x9c, 0x73, 0xce, 0x39,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x73, 0xce, 0x39,
0x9c, 0x73, 0xce, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9c, 0x73, 0xce, 0x39, 0x9c, 0x73, 0xce, 0x39, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x73, 0xce, 0x39, 0xfc, 0x73, 0xce, 0x39,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xcf, 0xf3, 0x3c,
0x1c, 0xcf, 0xf3, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xcf, 0xf3, 0x3c, 0x00, 0xcf, 0xf3, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xf3, 0x3c, 0x00, 0xcf, 0xf3, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xcf, 0xf3, 0x3c,
0x1c, 0xcf, 0xf3, 0x3c };
#define hp48_orange_width 5
#define hp48_orange_height 53
static unsigned char hp48_orange_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c };
#define hp48_blue_width 5
#define hp48_blue_height 57
static unsigned char hp48_blue_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c };
#define hp48_on_width 25
#define hp48_on_height 19
static unsigned char hp48_on_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x00,
0x00, 0x00, 0x13, 0x01, 0x00, 0x80, 0x12, 0x01, 0x80, 0x48, 0x12,
0x01, 0x80, 0xc8, 0xe7, 0x00, 0x00, 0x05, 0x12, 0x01, 0x00, 0x02,
0x12, 0x01, 0x00, 0x05, 0x12, 0x01, 0x80, 0x08, 0xe2, 0x00 };
#define hp48_top_gx_width 32
#define hp48_top_gx_height 30
static unsigned char hp48_top_gx_bitmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x08, 0xff, 0xe1,
0x07, 0x08, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x63, 0x8c, 0x31, 0xc6, 0x63, 0x8c, 0x31, 0xc6, 0xff, 0xff, 0xff, 0xff };
#define hp48_logo_gx_width 16
#define hp48_logo_gx_height 4
static unsigned char hp48_logo_gx_bitmap[] = { 0x00, 0x00, 0x00, 0x00,
0xf8, 0xf7, 0xf8, 0xf7 };
#define hp48_text_gx_width 29
#define hp48_text_gx_height 7
static unsigned char hp48_text_gx_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f };
#define hp48_green_gx_width 29
#define hp48_green_gx_height 57
static unsigned char hp48_green_gx_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00 };
/* #endif /\* !_ICON_H *\/ */
#endif // X11
/* #ifndef _ANNUNC_H */
/* #define _ANNUNC_H 1 */
@ -1132,91 +919,24 @@ static letter_t small_font[] = {
/* #endif /\* !_SMALL_H *\/ */
#if defined( GUI_IS_X11 )
typedef struct color_t {
const char* name;
int r, g, b;
int mono_rgb;
int gray_rgb;
XColor xcolor;
} color_t;
typedef struct keypad_t {
unsigned int width;
unsigned int height;
Pixmap pixmap;
} keypad_t;
typedef struct disp_t {
unsigned int w, h;
Window win;
GC gc;
short mapped;
int offset;
int lines;
int display_update;
XShmSegmentInfo disp_info;
XImage* disp_image;
XShmSegmentInfo menu_info;
XImage* menu_image;
} disp_t;
typedef struct button_t {
const char* name;
short pressed;
short extra;
int code;
int x, y;
unsigned int w, h;
int lc;
const char* label;
short font_size;
unsigned int lw, lh;
unsigned char* lb;
const char* letter;
const char* left;
short is_menu;
const char* right;
const char* sub;
Pixmap map;
Pixmap down;
Window xwin;
} button_t;
typedef struct ann_struct {
int bit;
int x;
int y;
unsigned int width;
unsigned int height;
unsigned char* bits;
Pixmap pixmap;
} ann_struct_t;
#elif defined( GUI_IS_SDL1 )
typedef struct color_t {
const char* name;
int r, g, b;
} color_t;
typedef struct keypad_t {
unsigned int width;
unsigned int height;
} keypad_t;
typedef struct disp_t {
unsigned int w, h;
short mapped;
int offset;
int lines;
} disp_t;
typedef struct button_t {
@ -1264,22 +984,14 @@ typedef struct SDLWINDOW {
SDL_Surface *oldsurf, *surf;
int x, y;
} SDLWINDOW_t;
#endif
extern color_t* colors;
extern disp_t disp;
extern ann_struct_t ann_tbl[];
#if defined( GUI_IS_X11 )
extern int shm_flag;
extern Display* dpy;
extern int screen;
#elif defined( GUI_IS_SDL1 )
extern unsigned int ARGBColors[ BLACK + 1 ];
extern SDL_Surface* sdlwindow;
extern SDL_Surface* sdlsurface;
#endif
/*************************/
/* Functions' prototypes */
@ -1303,18 +1015,6 @@ extern void draw_annunc( void ); /* x48_lcd.c */
extern void redraw_annunc( void ); /* x48_lcd.c */
/* #endif /\* !_DEVICE_H *\/ */
#if defined( GUI_IS_X11 )
extern int InitDisplay( int argc, char** argv );
extern void save_options( int argc, char** argv );
extern void refresh_icon( void );
extern void refresh_display( void );
extern void init_annunc( void ); /* lcd.c */
extern int CreateWindows( int argc, char** argv );
#elif defined( GUI_IS_SDL1 )
extern void SDLCreateHP( void );
extern void SDLInit( void );
extern void SDLDrawAnnunc( char* annunc );
@ -1359,6 +1059,5 @@ extern void SDLMessageBox( int w, int h, const char* title, const char* text[],
unsigned color, unsigned colortext, int center );
extern void SDLEventWaitClickOrKey( void );
extern void SDLShowInformation( void );
#endif
#endif /* !_X48_GUI_H */

View file

@ -3,11 +3,6 @@
#include <string.h>
#include <unistd.h>
#if defined( GUI_IS_X11 )
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#endif
#include "hp48.h"
#include "hp48emu.h"
#include "timer.h"
@ -34,96 +29,6 @@ ann_struct_t ann_tbl[] = {
{ ANN_IO, 241, 4, ann_io_width, ann_io_height, ann_io_bitmap },
{ 0 } };
#if defined( GUI_IS_X11 )
Pixmap nibble_maps[ 16 ];
unsigned char nibbles[ 16 ][ 2 ] = {
{ 0x00, 0x00 }, /* ---- */
{ 0x03, 0x03 }, /* *--- */
{ 0x0c, 0x0c }, /* -*-- */
{ 0x0f, 0x0f }, /* **-- */
{ 0x30, 0x30 }, /* --*- */
{ 0x33, 0x33 }, /* *-*- */
{ 0x3c, 0x3c }, /* -**- */
{ 0x3f, 0x3f }, /* ***- */
{ 0xc0, 0xc0 }, /* ---* */
{ 0xc3, 0xc3 }, /* *--* */
{ 0xcc, 0xcc }, /* -*-* */
{ 0xcf, 0xcf }, /* **-* */
{ 0xf0, 0xf0 }, /* --** */
{ 0xf3, 0xf3 }, /* *-** */
{ 0xfc, 0xfc }, /* -*** */
{ 0xff, 0xff } /* **** */
};
static unsigned char nibble_bitmap[ 16 ];
static inline void init_nibble_maps( void ) {
int i;
for ( i = 0; i < 16; i++ ) {
nibble_maps[ i ] =
XCreateBitmapFromData( dpy, disp.win, ( char* )nibbles[ i ], 8, 2 );
}
if ( shm_flag ) {
if ( disp.disp_image->bitmap_bit_order == MSBFirst ) {
nibble_bitmap[ 0x0 ] = 0x00; /* ---- */
nibble_bitmap[ 0x1 ] = 0xc0; /* *--- */
nibble_bitmap[ 0x2 ] = 0x30; /* -*-- */
nibble_bitmap[ 0x3 ] = 0xf0; /* **-- */
nibble_bitmap[ 0x4 ] = 0x0c; /* --*- */
nibble_bitmap[ 0x5 ] = 0xcc; /* *-*- */
nibble_bitmap[ 0x6 ] = 0x3c; /* -**- */
nibble_bitmap[ 0x7 ] = 0xfc; /* ***- */
nibble_bitmap[ 0x8 ] = 0x03; /* ---* */
nibble_bitmap[ 0x9 ] = 0xc3; /* *--* */
nibble_bitmap[ 0xa ] = 0x33; /* -*-* */
nibble_bitmap[ 0xb ] = 0xf3; /* **-* */
nibble_bitmap[ 0xc ] = 0x0f; /* --** */
nibble_bitmap[ 0xd ] = 0xcf; /* *-** */
nibble_bitmap[ 0xe ] = 0x3f; /* -*** */
nibble_bitmap[ 0xf ] = 0xff; /* **** */
} else {
nibble_bitmap[ 0x0 ] = 0x00; /* ---- */
nibble_bitmap[ 0x1 ] = 0x03; /* *--- */
nibble_bitmap[ 0x2 ] = 0x0c; /* -*-- */
nibble_bitmap[ 0x3 ] = 0x0f; /* **-- */
nibble_bitmap[ 0x4 ] = 0x30; /* --*- */
nibble_bitmap[ 0x5 ] = 0x33; /* *-*- */
nibble_bitmap[ 0x6 ] = 0x3c; /* -**- */
nibble_bitmap[ 0x7 ] = 0x3f; /* ***- */
nibble_bitmap[ 0x8 ] = 0xc0; /* ---* */
nibble_bitmap[ 0x9 ] = 0xc3; /* *--* */
nibble_bitmap[ 0xa ] = 0xcc; /* -*-* */
nibble_bitmap[ 0xb ] = 0xcf; /* **-* */
nibble_bitmap[ 0xc ] = 0xf0; /* --** */
nibble_bitmap[ 0xd ] = 0xf3; /* *-** */
nibble_bitmap[ 0xe ] = 0xfc; /* -*** */
nibble_bitmap[ 0xf ] = 0xff; /* **** */
}
}
}
static inline void draw_nibble( int c, int r, int val ) {
int x, y;
x = ( c * 8 ) + 5;
if ( r <= display.lines )
x -= disp.offset;
y = ( r * 2 ) + 20;
val &= 0x0f;
if ( val != lcd_buffer[ r ][ c ] ) {
XCopyPlane( dpy, nibble_maps[ val ], disp.win, disp.gc, 0, 0, 8, 2, x,
y, 1 );
lcd_buffer[ r ][ c ] = val;
}
if ( val != lcd_buffer[ r ][ c ] )
lcd_buffer[ r ][ c ] = val;
}
#elif defined( GUI_IS_SDL1 )
static inline void init_nibble_maps( void ) {}
static inline void draw_nibble( int c, int r, int val ) {
@ -144,7 +49,6 @@ static inline void draw_nibble( int c, int r, int val ) {
SDLDrawNibble( x, y, val );
}
#endif
static inline void draw_row( long addr, int row ) {
int i, v;
@ -162,221 +66,6 @@ static inline void draw_row( long addr, int row ) {
}
}
#if defined( GUI_IS_X11 )
void update_display( void ) {
int i, j;
long addr;
static int old_offset = -1;
static int old_lines = -1;
int addr_pad;
int val, line_pad, line_length;
word_20 data_addr, data_addr_2;
if ( !disp.mapped ) {
refresh_icon();
return;
}
if ( display.on ) {
addr = display.disp_start;
if ( shm_flag ) {
data_addr = 0;
data_addr_2 = disp.disp_image->bytes_per_line;
line_length = NIBBLES_PER_ROW;
if ( display.offset > 3 )
line_length += 2;
line_pad = 2 * disp.disp_image->bytes_per_line - line_length;
addr_pad = display.nibs_per_line - line_length;
for ( i = 0; i <= display.lines; i++ ) {
for ( j = 0; j < line_length; j++ ) {
val = read_nibble( addr++ );
disp.disp_image->data[ data_addr++ ] = nibble_bitmap[ val ];
disp.disp_image->data[ data_addr_2++ ] =
nibble_bitmap[ val ];
}
addr += addr_pad;
data_addr += line_pad;
data_addr_2 += line_pad;
}
disp.display_update |= UPDATE_DISP;
} else {
if ( display.offset != old_offset ) {
memset(
disp_buf, 0xf0,
( size_t )( ( display.lines + 1 ) * NIBS_PER_BUFFER_ROW ) );
memset(
lcd_buffer, 0xf0,
( size_t )( ( display.lines + 1 ) * NIBS_PER_BUFFER_ROW ) );
old_offset = display.offset;
}
if ( display.lines != old_lines ) {
memset( &disp_buf[ 56 ][ 0 ], 0xf0,
( size_t )( 8 * NIBS_PER_BUFFER_ROW ) );
memset( &lcd_buffer[ 56 ][ 0 ], 0xf0,
( size_t )( 8 * NIBS_PER_BUFFER_ROW ) );
old_lines = display.lines;
}
for ( i = 0; i <= display.lines; i++ ) {
draw_row( addr, i );
addr += display.nibs_per_line;
}
}
if ( i < DISP_ROWS ) {
addr = display.menu_start;
if ( shm_flag ) {
data_addr = 0;
data_addr_2 = disp.menu_image->bytes_per_line;
line_pad =
2 * disp.menu_image->bytes_per_line - NIBBLES_PER_ROW;
for ( ; i < DISP_ROWS; i++ ) {
for ( j = 0; j < NIBBLES_PER_ROW; j++ ) {
val = read_nibble( addr++ );
disp.menu_image->data[ data_addr++ ] =
nibble_bitmap[ val ];
disp.menu_image->data[ data_addr_2++ ] =
nibble_bitmap[ val ];
}
data_addr += line_pad;
data_addr_2 += line_pad;
}
disp.display_update |= UPDATE_MENU;
} else {
for ( ; i < DISP_ROWS; i++ ) {
draw_row( addr, i );
addr += NIBBLES_PER_ROW;
}
}
}
} else {
if ( shm_flag ) {
memset( disp.disp_image->data, 0,
( size_t )( disp.disp_image->bytes_per_line *
disp.disp_image->height ) );
memset( disp.menu_image->data, 0,
( size_t )( disp.menu_image->bytes_per_line *
disp.menu_image->height ) );
disp.display_update = UPDATE_DISP | UPDATE_MENU;
} else {
memset( disp_buf, 0xf0, sizeof( disp_buf ) );
for ( i = 0; i < 64; i++ ) {
for ( j = 0; j < NIBBLES_PER_ROW; j++ ) {
draw_nibble( j, i, 0x00 );
}
}
}
}
}
void redraw_display( void ) {
XClearWindow( dpy, disp.win );
memset( disp_buf, 0, sizeof( disp_buf ) );
memset( lcd_buffer, 0, sizeof( lcd_buffer ) );
update_display();
}
void disp_draw_nibble( word_20 addr, word_4 val ) {
long offset;
int shm_addr;
int x, y;
offset = ( addr - display.disp_start );
x = offset % display.nibs_per_line;
if ( x < 0 || x > 35 )
return;
if ( display.nibs_per_line != 0 ) {
y = offset / display.nibs_per_line;
if ( y < 0 || y > 63 )
return;
if ( shm_flag ) {
shm_addr = ( 2 * y * disp.disp_image->bytes_per_line ) + x;
disp.disp_image->data[ shm_addr ] = nibble_bitmap[ val ];
disp.disp_image
->data[ shm_addr + disp.disp_image->bytes_per_line ] =
nibble_bitmap[ val ];
disp.display_update |= UPDATE_DISP;
} else {
if ( val != disp_buf[ y ][ x ] ) {
disp_buf[ y ][ x ] = val;
draw_nibble( x, y, val );
}
}
} else {
if ( shm_flag ) {
shm_addr = x;
for ( y = 0; y < display.lines; y++ ) {
disp.disp_image->data[ shm_addr ] = nibble_bitmap[ val ];
shm_addr += disp.disp_image->bytes_per_line;
disp.disp_image->data[ shm_addr ] = nibble_bitmap[ val ];
shm_addr += disp.disp_image->bytes_per_line;
}
disp.display_update |= UPDATE_DISP;
} else {
for ( y = 0; y < display.lines; y++ ) {
if ( val != disp_buf[ y ][ x ] ) {
disp_buf[ y ][ x ] = val;
draw_nibble( x, y, val );
}
}
}
}
}
void menu_draw_nibble( word_20 addr, word_4 val ) {
long offset;
int shm_addr;
int x, y;
offset = ( addr - display.menu_start );
if ( shm_flag ) {
shm_addr =
2 * ( offset / NIBBLES_PER_ROW ) * disp.menu_image->bytes_per_line +
( offset % NIBBLES_PER_ROW );
disp.menu_image->data[ shm_addr ] = nibble_bitmap[ val ];
disp.menu_image->data[ shm_addr + disp.menu_image->bytes_per_line ] =
nibble_bitmap[ val ];
disp.display_update |= UPDATE_MENU;
} else {
x = offset % NIBBLES_PER_ROW;
y = display.lines + ( offset / NIBBLES_PER_ROW ) + 1;
if ( val != disp_buf[ y ][ x ] ) {
disp_buf[ y ][ x ] = val;
draw_nibble( x, y, val );
}
}
}
void draw_annunc( void ) {
int val;
val = display.annunc;
if ( val == last_annunc_state )
return;
last_annunc_state = val;
for ( int i = 0; ann_tbl[ i ].bit; i++ ) {
if ( ( ann_tbl[ i ].bit & val ) == ann_tbl[ i ].bit )
XCopyPlane( dpy, ann_tbl[ i ].pixmap, disp.win, disp.gc, 0, 0,
ann_tbl[ i ].width, ann_tbl[ i ].height, ann_tbl[ i ].x,
ann_tbl[ i ].y, 1 );
else
XClearArea( dpy, disp.win, ann_tbl[ i ].x, ann_tbl[ i ].y,
ann_tbl[ i ].width, ann_tbl[ i ].height, False );
}
refresh_icon();
}
void init_annunc( void ) {
for ( int i = 0; ann_tbl[ i ].bit; i++ )
ann_tbl[ i ].pixmap =
XCreateBitmapFromData( dpy, disp.win, ( char* )ann_tbl[ i ].bits,
ann_tbl[ i ].width, ann_tbl[ i ].height );
}
#elif defined( GUI_IS_SDL1 )
void update_display( void ) {
int i, j;
long addr;
@ -485,7 +174,6 @@ void draw_annunc( void ) {
SDLDrawAnnunc( sdl_annuncstate );
}
#endif
void redraw_annunc( void ) {
last_annunc_state = -1;

View file

@ -1,368 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include "options.h"
#include "error_handling.h"
#include "x48_resources.h"
#if defined( GUI_IS_X11 )
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
char* res_name;
char* res_class;
XrmDatabase rdb = ( XrmDatabase )0;
void usage( void ) {
fprintf( stdout, "\n\
%s Version %d.%d.%d\n\
\n\
usage:\n\t%s [-options ...]\n\
\n\
where options include:\n\
-help print out this message\n\
-display <displayname> X server to contact\n\
-name <string> set application name to <string>\n\
-title <string> set window title to <string>\n\
-geometry <geometry> position of window\n\
-iconGeom <geometry> position of icon window\n\
-iconic start iconic\n\
-visual <visualname> use visual <visualname>\n\
-mono force monochrome\n\
-gray force grayscale\n\
-monoIcon force monochrome icon\n\
-smallFont <fontname> <fontname> to draw small labels (MTH - DEL)\n\
-mediumFont <fontname> <fontname> to draw medium label (ENTER)\n\
-largeFont <fontname> <fontname> to draw large labels (Numbers)\n\
-connFont <fontname> <fontname> to display wire & IR connections\n\
-/+xshm turn on/off XShm extension\n\
-version print out version information\n\
-copyright print out copyright information\n\
-warranty print out warranty information\n\
-verbose run verbosive\n\
-/+terminal turn on/off pseudo terminal interface\n\
-/+serial turn on/off serial interface\n\
-line <devicename> use serial line <devicename> for IR connection\n\
-reset perform a reset (PC = 0) on startup\n\
-initialize force initialization x48ng from ROM-dump\n\
-rom <filename> if initializing, read ROM from <filename>\n\
-home <directory> use directory ~/<directory> to save x48ng files\n\
-xrm <resource> set Xresource <resource>\n\
-/+throttle turn off/on speed emulation\n\
-/+netbook turn off/on netbook layout\n\
\n",
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname );
fflush( stdout );
exit( 1 );
}
void show_version( void ) {
fprintf( stdout, "\n\
%s Version %d.%d.%d",
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL );
}
void show_copyright( void ) {
fprintf( stdout, "\n\
COPYRIGHT\n\
\n\
x48ng is an Emulator for the HP-48 Handheld Calculator.\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation; either version 2 of the License, or\n\
(at your option) any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n" );
}
void show_warranty( void ) {
fprintf( stdout, "\n\
NO WARRANTY\n\
\n\
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n\
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n\
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n\
PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n\
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n\
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n\
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n\
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n\
REPAIR OR CORRECTION.\n\
\n\
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n\
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n\
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n\
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n\
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n\
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n\
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n\
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n\
POSSIBILITY OF SUCH DAMAGES.\n\n" );
}
char* get_string_resource_from_db( XrmDatabase db, char* name, char* class ) {
XrmValue value;
char* type;
char full_name[ 1024 ], full_class[ 1024 ];
strcpy( full_name, res_name );
strcat( full_name, "." );
strcat( full_name, name );
strcpy( full_class, res_class );
strcat( full_class, "." );
strcat( full_class, class );
if ( XrmGetResource( db, full_name, full_class, &type, &value ) ) {
char* str = ( char* )malloc( value.size + 1 );
strncpy( str, ( char* )value.addr, value.size );
str[ value.size ] = 0;
return str;
}
return ( char* )0;
}
char* get_string_resource( char* name, char* class ) {
return get_string_resource_from_db( rdb, name, class );
}
int get_boolean_resource( char* name, char* class ) {
char *tmp, buf[ 100 ];
char* s = get_string_resource( name, class );
char* os = s;
if ( !s )
return 0;
for ( tmp = buf; *s; s++ )
*tmp++ = isupper( *s ) ? tolower( *s ) : *s;
*tmp = 0;
free( os );
if ( !strcmp( buf, "on" ) || !strcmp( buf, "true" ) ||
!strcmp( buf, "yes" ) )
return 1;
if ( !strcmp( buf, "off" ) || !strcmp( buf, "false" ) ||
!strcmp( buf, "no" ) )
return 0;
fprintf( stderr, "%s must be boolean, not %s.\n", name, buf );
return 0;
}
int get_integer_resource( char* name, char* class ) {
int val;
char c, *s = get_string_resource( name, class );
if ( !s )
return 0;
if ( 1 == sscanf( s, " %d %c", &val, &c ) ) {
free( s );
return val;
}
fprintf( stderr, "%s must be an integer, not %s.\n", name, s );
free( s );
return 0;
}
unsigned int get_pixel_resource( char* name, char* class, Display* dpy,
Colormap cmap ) {
XColor color;
char* s = get_string_resource( name, class );
if ( !s )
goto DEFAULT;
if ( !XParseColor( dpy, cmap, s, &color ) ) {
fprintf( stderr, "can't parse color %s\n", s );
goto DEFAULT;
}
if ( !XAllocColor( dpy, cmap, &color ) ) {
fprintf( stderr, "couldn't allocate color %s\n", s );
goto DEFAULT;
}
free( s );
return color.pixel;
DEFAULT:
if ( s )
free( s );
return ( strcmp( class, "Background" )
? WhitePixel( dpy, DefaultScreen( dpy ) )
: BlackPixel( dpy, DefaultScreen( dpy ) ) );
}
static Visual* pick_visual_of_class( Display* dpy, int visual_class,
unsigned int* depth ) {
XVisualInfo vi_in, *vi_out;
int out_count;
vi_in.class = visual_class;
vi_in.screen = DefaultScreen( dpy );
vi_out = XGetVisualInfo( dpy, VisualClassMask | VisualScreenMask, &vi_in,
&out_count );
if ( vi_out ) { /* choose the 'best' one, if multiple */
int i, best;
Visual* visual;
for ( i = 0, best = 0; i < out_count; i++ )
if ( vi_out[ i ].depth > vi_out[ best ].depth )
best = i;
visual = vi_out[ best ].visual;
*depth = vi_out[ best ].depth;
XFree( ( char* )vi_out );
return visual;
} else {
*depth = DefaultDepth( dpy, DefaultScreen( dpy ) );
return DefaultVisual( dpy, DefaultScreen( dpy ) );
}
}
static Visual* id_to_visual( Display* dpy, int id, unsigned int* depth ) {
XVisualInfo vi_in, *vi_out;
int out_count;
vi_in.screen = DefaultScreen( dpy );
vi_in.visualid = id;
vi_out = XGetVisualInfo( dpy, VisualScreenMask | VisualIDMask, &vi_in,
&out_count );
if ( vi_out ) {
Visual* v = vi_out[ 0 ].visual;
*depth = vi_out[ 0 ].depth;
XFree( ( char* )vi_out );
return v;
}
return 0;
}
Visual* get_visual_resource( Display* dpy, char* name, char* class,
unsigned int* depth ) {
char c;
char *tmp, *s;
int vclass;
int id;
s = get_string_resource( name, class );
if ( s )
for ( tmp = s; *tmp; tmp++ )
if ( isupper( *tmp ) )
*tmp = tolower( *tmp );
if ( !s || !strcmp( s, "default" ) )
vclass = -1;
else if ( !strcmp( s, "staticgray" ) )
vclass = StaticGray;
else if ( !strcmp( s, "staticcolor" ) )
vclass = StaticColor;
else if ( !strcmp( s, "truecolor" ) )
vclass = TrueColor;
else if ( !strcmp( s, "grayscale" ) )
vclass = GrayScale;
else if ( !strcmp( s, "pseudocolor" ) )
vclass = PseudoColor;
else if ( !strcmp( s, "directcolor" ) )
vclass = DirectColor;
else if ( 1 == sscanf( s, " %d %c", &id, &c ) )
vclass = -2;
else if ( 1 == sscanf( s, " 0x%x %c", &id, &c ) )
vclass = -2;
else {
fprintf( stderr, "unrecognized visual \"%s\".\n", s );
vclass = -1;
}
if ( s )
free( s );
if ( vclass == -1 ) {
*depth = DefaultDepth( dpy, DefaultScreen( dpy ) );
return DefaultVisual( dpy, DefaultScreen( dpy ) );
} else if ( vclass == -2 ) {
Visual* v = id_to_visual( dpy, id, depth );
if ( v )
return v;
fprintf( stderr, "no visual with id 0x%x.\n", id );
*depth = DefaultDepth( dpy, DefaultScreen( dpy ) );
return DefaultVisual( dpy, DefaultScreen( dpy ) );
} else
return pick_visual_of_class( dpy, vclass, depth );
}
XFontStruct* get_font_resource( Display* dpy, char* name, char* class ) {
char* s;
XFontStruct* f = ( XFontStruct* )0;
s = get_string_resource( name, class );
if ( s )
f = XLoadQueryFont( dpy, s );
else {
char errbuf[ 1024 ];
sprintf( errbuf, "can\'t get resource \'%s\'", name );
fatal_exit( errbuf, "" );
}
if ( f == ( XFontStruct* )0 ) {
char errbuf[ 1024 ];
char fixbuf[ 1024 ];
sprintf( errbuf, "can\'t load font \'%s\'", s );
sprintf( fixbuf, "Please change resource \'%s\'", name );
fatal_exit( errbuf, fixbuf );
}
return f;
}
void get_resources( void ) {
verbose = 0;
useTerminal = 1;
useSerial = 0;
initialize = 0;
resetOnStartup = 0;
netbook = 0;
throttle = 0;
if ( get_boolean_resource( "printVersion", "PrintVersion" ) )
show_version();
if ( get_boolean_resource( "printCopyright", "PrintCopyright" ) )
show_copyright();
if ( get_boolean_resource( "printWarranty", "PrintWarranty" ) )
show_warranty();
verbose = get_boolean_resource( "verbose", "Verbose" );
useXShm = get_boolean_resource( "useXShm", "UseXShm" );
useTerminal = get_boolean_resource( "useTerminal", "UseTerminal" );
useSerial = get_boolean_resource( "useSerial", "UseSerial" );
serialLine = get_string_resource( "serialLine", "SerialLine" );
initialize =
get_boolean_resource( "completeInitialize", "CompleteInitialize" );
resetOnStartup = get_boolean_resource( "resetOnStartup", "ResetOnStartup" );
romFileName = get_string_resource( "romFileName", "RomFileName" );
homeDirectory = get_string_resource( "homeDirectory", "HomeDirectory" );
netbook = get_boolean_resource( "netbook", "Netbook" );
throttle = get_boolean_resource( "throttle", "Throttle" );
}
#elif defined( GUI_IS_SDL1 )
void get_resources( void ) {
verbose = 0;
useTerminal = 1;
useSerial = 0;
initialize = 0;
resetOnStartup = 0;
throttle = 0;
serialLine = "/dev/ttyS0";
romFileName = "rom.dump";
// Have homeDirectory in the user's home
homeDirectory = ".x48ng"; // live files are stored in ~/.x48ng
}
#endif

View file

@ -1,31 +0,0 @@
#ifndef _RESOURCES_H
#define _RESOURCES_H 1
#if defined( GUI_IS_X11 )
#include <X11/Xlib.h>
#include <X11/Xresource.h>
extern char* progname;
extern char* res_name;
extern char* res_class;
extern XrmDatabase rdb;
extern void usage( void );
extern void show_version( void );
extern void show_copyright( void );
extern void show_warranty( void );
extern char* get_string_resource_from_db( XrmDatabase db, char* name,
char* class );
extern char* get_string_resource( char* name, char* class );
extern int get_boolean_resource( char* name, char* class );
extern Visual* get_visual_resource( Display* dpy, char* name, char* class,
unsigned int* depth );
extern XFontStruct* get_font_resource( Display* dpy, char* res_name,
char* res_class );
#endif
extern void get_resources( void );
#endif /* !_RESOURCES_H */