diff --git a/Makefile b/Makefile index 6c16b67..31a8ab0 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ DOTOS = src/main.o \ src/hp48emu_actions.o \ src/hp48emu_memory.o \ src/hp48emu_register.o \ + src/options.o \ src/romio.o \ src/timer.o \ src/x48_errors.o \ diff --git a/src/hp48_device.c b/src/hp48_device.c index 7754fef..01066e9 100644 --- a/src/hp48_device.c +++ b/src/hp48_device.c @@ -180,53 +180,6 @@ unsigned char nibbles[ 16 ][ 2 ] = { }; static unsigned char nibble_bitmap[ 16 ]; - -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; /* **** */ - } - } -} #endif ann_struct_t ann_tbl[] = { @@ -275,40 +228,93 @@ void init_display( void ) { memset( lcd_buffer, 0xf0, sizeof( lcd_buffer ) ); #if defined( GUI_IS_X11 ) - init_nibble_maps(); + /* init nibble_maps */ + 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; /* **** */ + } + } #endif } +#if defined( GUI_IS_X11 ) static inline void draw_nibble( int c, int r, int val ) { int x, y; -#if defined( GUI_IS_X11 ) x = ( c * 8 ) + 5; -#elif defined( GUI_IS_SDL1 ) - x = ( c * 4 ); // x: start in pixels -#endif + if ( r <= display.lines ) x -= disp.offset; -#if defined( GUI_IS_X11 ) y = ( r * 2 ) + 20; -#elif defined( GUI_IS_SDL1 ) - y = r; // y: start in pixels -#endif + val &= 0x0f; if ( val != lcd_buffer[ r ][ c ] ) { -#if defined( GUI_IS_X11 ) XCopyPlane( dpy, nibble_maps[ val ], disp.win, disp.gc, 0, 0, 8, 2, x, y, 1 ); -#endif + lcd_buffer[ r ][ c ] = val; + } + if ( val != lcd_buffer[ r ][ c ] ) + lcd_buffer[ r ][ c ] = val; +} +#elif defined( GUI_IS_SDL1 ) +static inline void draw_nibble( int c, int r, int val ) { + int x, y; + + x = ( c * 4 ); // x: start in pixels + + if ( r <= display.lines ) + x -= disp.offset; + y = r; // y: start in pixels + + val &= 0x0f; + if ( val != lcd_buffer[ r ][ c ] ) { lcd_buffer[ r ][ c ] = val; } if ( val != lcd_buffer[ r ][ c ] ) lcd_buffer[ r ][ c ] = val; -#if defined( GUI_IS_SDL1 ) SDLDrawNibble( x, y, val ); -#endif } +#endif static inline void draw_row( long addr, int row ) { int i, v; diff --git a/src/hp48_init.c b/src/hp48_init.c index ab0f8c6..55cc4f8 100644 --- a/src/hp48_init.c +++ b/src/hp48_init.c @@ -7,10 +7,10 @@ #include #include +#include "options.h" #include "hp48.h" #include "hp48emu.h" #include "romio.h" -#include "x48_resources.h" #define X48_MAGIC 0x48503438 #define NR_CONFIG 8 diff --git a/src/hp48_serial.c b/src/hp48_serial.c index 60f30c2..7902b8c 100644 --- a/src/hp48_serial.c +++ b/src/hp48_serial.c @@ -7,10 +7,10 @@ #include #include +#include "options.h" #include "hp48.h" #include "hp48emu.h" -#include "x48.h" -#include "x48_resources.h" +#include "x48.h" /* ShowConnections() */ static int wire_fd; static int ir_fd; diff --git a/src/hp48emu_memory.c b/src/hp48emu_memory.c index c459e83..9947dd0 100644 --- a/src/hp48emu_memory.c +++ b/src/hp48emu_memory.c @@ -8,7 +8,7 @@ #include "hp48emu.h" #include "romio.h" #include "x48.h" -#include "x48_resources.h" +#include "options.h" extern int device_check; extern short port1_is_ram; diff --git a/src/main.c b/src/main.c index b46a670..b63792e 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ #include #include +#include "options.h" #include "hp48.h" #include "x48.h" #include "x48_resources.h" diff --git a/src/options.c b/src/options.c new file mode 100644 index 0000000..77cf508 --- /dev/null +++ b/src/options.c @@ -0,0 +1,12 @@ +#include "options.h" + +int verbose; +int useTerminal; +int useSerial; +int throttle; +int initialize; +int resetOnStartup; + +char* serialLine; +char* romFileName; +char* homeDirectory; diff --git a/src/options.h b/src/options.h new file mode 100644 index 0000000..4bd3b60 --- /dev/null +++ b/src/options.h @@ -0,0 +1,15 @@ +#ifndef _OPTIONS_H +#define _OPTIONS_H 1 + +extern int verbose; +extern int useTerminal; +extern int useSerial; +extern int throttle; +extern int initialize; +extern int resetOnStartup; + +extern char* serialLine; +extern char* romFileName; +extern char* homeDirectory; + +#endif /* !_OPTIONS_H */ diff --git a/src/x48.c b/src/x48.c index da57ab7..0f09a39 100644 --- a/src/x48.c +++ b/src/x48.c @@ -12,6 +12,7 @@ #include #endif +#include "options.h" #include "hp48.h" #include "romio.h" #include "x48.h" @@ -1681,8 +1682,8 @@ sdltohpkeymap_t sdltohpkeymap[] = { { ( SDLKey )0, ( SDLKey )0 } }; #endif -void adjust_contrast( int contrast ) { #if defined( GUI_IS_X11 ) +void adjust_contrast( int contrast ) { int gray = 0; int r = 0, g = 0, b = 0; unsigned long old; @@ -1741,12 +1742,14 @@ void adjust_contrast( int contrast ) { refresh_icon(); } } +} #elif defined( GUI_IS_SDL1 ) +void adjust_contrast( int contrast ) { SDLCreateColors(); SDLCreateAnnunc(); redraw_display(); -#endif } +#endif int SmallTextWidth( const char* string, unsigned int length ) { int i, w; @@ -5746,10 +5749,10 @@ int button_released( int b ) { return 0; } +#if defined( GUI_IS_X11 ) static int button_release_all( void ) { for ( int b = BUTTON_A; b <= LAST_BUTTON; b++ ) if ( buttons[ b ].pressed ) { -#if defined( GUI_IS_X11 ) int code = buttons[ b ].code; if ( code == 0x8000 ) { int i; @@ -5763,17 +5766,24 @@ static int button_release_all( void ) { } buttons[ b ].pressed = 0; DrawButton( b ); -#elif defined( GUI_IS_SDL1 ) - button_released( b ); -#endif } return 0; } +#elif defined( GUI_IS_SDL1 ) +static int button_release_all( void ) { + for ( int b = BUTTON_A; b <= LAST_BUTTON; b++ ) + if ( buttons[ b ].pressed ) { + button_released( b ); + } + return 0; +} +#endif + +#if defined( GUI_IS_X11 ) void ShowConnections( char* wire, char* ir ) { char name[ 128 ]; -#if defined( GUI_IS_X11 ) int x, y, w, h; int conn_top; XFontStruct* finfo; @@ -5791,7 +5801,7 @@ void ShowConnections( char* wire, char* ir ) { conn_top = DISPLAY_OFFSET_Y + DISPLAY_HEIGHT + 18; XTextExtents( finfo, "TEST", ( int )strlen( "TEST" ), &dir, &fa, &fd, - &xchar ); + &xchar ); w = DISPLAY_WIDTH; h = fa + fd; @@ -5817,19 +5827,22 @@ void ShowConnections( char* wire, char* ir ) { x = DISPLAY_OFFSET_X; y = conn_top; XCopyArea( dpy, pix, keypad.pixmap, gc, 0, 0, w, h, x, - y ); /* FIXME keypad? */ + y ); /* FIXME keypad? */ DrawKeypad( &keypad ); XFreePixmap( dpy, pix ); XFreeFont( dpy, finfo ); -#elif defined( GUI_IS_SDL1 ) - fprintf( stderr, "%s\n", name ); -#endif } +#elif defined( GUI_IS_SDL1 ) +void ShowConnections( char* wire, char* ir ) { + char name[ 128 ]; + fprintf( stderr, "%s\n", name ); +} +#endif -int get_ui_event( void ) { #if defined( GUI_IS_X11 ) +int get_ui_event( void ) { XEvent xev; XClientMessageEvent* cm; int i, wake, bufs = 2; @@ -5867,602 +5880,602 @@ int get_ui_event( void ) { switch ( ( int )xev.type ) { - case KeyPress: + case KeyPress: + release_pending = 0; + if ( ( xev.xkey.time - last_release_time ) <= 1 ) { release_pending = 0; - if ( ( xev.xkey.time - last_release_time ) <= 1 ) { - release_pending = 0; - break; - } - - i = XLookupString( &xev.xkey, buf, bufs, &sym, NULL ); - wake = decode_key( &xev, sym, buf, i ); - first_key = 1; break; + } - case KeyRelease: + i = XLookupString( &xev.xkey, buf, bufs, &sym, NULL ); + wake = decode_key( &xev, sym, buf, i ); + first_key = 1; + break; - i = XLookupString( &xev.xkey, buf, bufs, &sym, NULL ); - first_key = 0; - release_pending = 1; - last_release_time = xev.xkey.time; - memcpy( &release_event, &xev, sizeof( XKeyEvent ) ); - break; + case KeyRelease: - case NoExpose: + i = XLookupString( &xev.xkey, buf, bufs, &sym, NULL ); + first_key = 0; + release_pending = 1; + last_release_time = xev.xkey.time; + memcpy( &release_event, &xev, sizeof( XKeyEvent ) ); + break; - break; + case NoExpose: - case Expose: + break; - if ( xev.xexpose.count == 0 ) { - if ( xev.xexpose.window == disp.win ) { - DrawDisp(); - } else if ( xev.xexpose.window == iconW ) { - DrawIcon(); - } else if ( xev.xexpose.window == mainW ) { - DrawKeypad( &keypad ); - } else + case Expose: + + if ( xev.xexpose.count == 0 ) { + if ( xev.xexpose.window == disp.win ) { + DrawDisp(); + } else if ( xev.xexpose.window == iconW ) { + DrawIcon(); + } else if ( xev.xexpose.window == mainW ) { + DrawKeypad( &keypad ); + } else for ( i = BUTTON_A; i <= LAST_BUTTON; i++ ) { if ( xev.xexpose.window == buttons[ i ].xwin ) { DrawButton( i ); break; } } - } - break; - case UnmapNotify: + } + break; + case UnmapNotify: - disp.mapped = 0; - break; + disp.mapped = 0; + break; - case MapNotify: + case MapNotify: - if ( !disp.mapped ) { - disp.mapped = 1; - update_display(); - redraw_annunc(); - } - break; + if ( !disp.mapped ) { + disp.mapped = 1; + update_display(); + redraw_annunc(); + } + break; - case ButtonPress: + case ButtonPress: - if ( xev.xbutton.subwindow == disp.win ) { - if ( xev.xbutton.button == Button2 ) { - if ( xev.xbutton.subwindow == disp.win ) { - int x; - int flag = 0; - char* paste_in = XFetchBuffer( dpy, &x, 0 ); + if ( xev.xbutton.subwindow == disp.win ) { + if ( xev.xbutton.button == Button2 ) { + if ( xev.xbutton.subwindow == disp.win ) { + int x; + int flag = 0; + char* paste_in = XFetchBuffer( dpy, &x, 0 ); - char* p = paste_in; - if ( x > MAX_PASTE ) { - x = 0; - printf( "input too long. limit is %d " - "characters\n", - MAX_PASTE ); - } - paste_count = 0; - paste_size = 0; - while ( x-- ) { - char c = *p++; - switch ( c ) { - case '.': - paste[ paste_size++ ] = - BUTTON_PERIOD; - break; - case '0': - paste[ paste_size++ ] = BUTTON_0; - break; - case '1': - paste[ paste_size++ ] = BUTTON_1; - break; - case '2': - paste[ paste_size++ ] = BUTTON_2; - break; - case '3': - paste[ paste_size++ ] = BUTTON_3; - break; - case '4': - paste[ paste_size++ ] = BUTTON_4; - break; - case '5': - paste[ paste_size++ ] = BUTTON_5; - break; - case '6': - paste[ paste_size++ ] = BUTTON_6; - break; - case '7': - paste[ paste_size++ ] = BUTTON_7; - break; - case '8': - paste[ paste_size++ ] = BUTTON_8; - break; - case '9': - paste[ paste_size++ ] = BUTTON_9; - break; - case '\n': - paste[ paste_size++ ] = BUTTON_SHR; - paste[ paste_size++ ] = - BUTTON_PERIOD; - break; - case '!': - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_DEL; - break; - case '+': - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = BUTTON_PLUS; - break; - case '-': - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = - BUTTON_MINUS; - break; - case '*': - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = BUTTON_MUL; - break; - case '/': - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = BUTTON_DIV; - break; - case ' ': - paste[ paste_size++ ] = 47; - break; - case '(': - paste[ paste_size++ ] = BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_DIV; - break; - case '[': - paste[ paste_size++ ] = BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_MUL; - break; - case '<': - if ( x > 1 && *p == '<' ) { - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = - BUTTON_MINUS; - x--; - p++; - } else { - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = - BUTTON_2; - } - break; - case '{': - paste[ paste_size++ ] = BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_PLUS; - break; - case ')': - case ']': - case '}': - paste[ paste_size++ ] = - BUTTON_RIGHT; - break; - case '>': - if ( x > 1 && *p == '>' ) { - paste[ paste_size++ ] = - BUTTON_RIGHT; - paste[ paste_size++ ] = - BUTTON_RIGHT; - paste[ paste_size++ ] = - BUTTON_RIGHT; - x--; - p++; - } else { - paste[ paste_size++ ] = - BUTTON_ALPHA; - paste[ paste_size++ ] = - BUTTON_SHR; - paste[ paste_size++ ] = - BUTTON_2; - } - break; - case '#': - paste[ paste_size++ ] = BUTTON_SHR; - paste[ paste_size++ ] = BUTTON_DIV; - break; - case '_': - paste[ paste_size++ ] = BUTTON_SHR; - paste[ paste_size++ ] = BUTTON_MUL; - break; - case '"': - if ( flag & 1 ) { - flag &= ~1; - paste[ paste_size++ ] = - BUTTON_RIGHT; - } else { - flag |= 1; - paste[ paste_size++ ] = - BUTTON_SHR; - paste[ paste_size++ ] = - BUTTON_MINUS; - } - break; - case ':': - if ( flag & 2 ) { - flag &= ~2; - paste[ paste_size++ ] = - BUTTON_RIGHT; - } else { - flag |= 2; - paste[ paste_size++ ] = - BUTTON_SHR; - paste[ paste_size++ ] = - BUTTON_PLUS; - } - break; - case '\'': - if ( flag & 4 ) { - flag &= ~4; - paste[ paste_size++ ] = - BUTTON_RIGHT; - } else { - flag |= 4; - paste[ paste_size++ ] = - BUTTON_COLON; - } - break; - case 'a': - case 'A': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_A; - break; - case 'b': - case 'B': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_B; - break; - case 'c': - case 'C': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_C; - break; - case 'd': - case 'D': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_D; - break; - case 'e': - case 'E': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_E; - break; - case 'f': - case 'F': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_F; - break; - case 'g': - case 'G': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_MTH; - break; - case 'h': - case 'H': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_PRG; - break; - case 'i': - case 'I': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_CST; - break; - case 'j': - case 'J': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_VAR; - break; - case 'k': - case 'K': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_UP; - break; - case 'l': - case 'L': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_NXT; - break; - - case 'm': - case 'M': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = - BUTTON_COLON; - break; - case 'n': - case 'N': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_STO; - break; - case 'o': - case 'O': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_EVAL; - break; - case 'p': - case 'P': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_LEFT; - break; - case 'q': - case 'Q': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_DOWN; - break; - case 'r': - case 'R': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = - BUTTON_RIGHT; - break; - case 's': - case 'S': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_SIN; - break; - case 't': - case 'T': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_COS; - break; - case 'u': - case 'U': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_TAN; - break; - case 'v': - case 'V': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_SQRT; - break; - case 'w': - case 'W': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = - BUTTON_POWER; - break; - case 'x': - case 'X': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_INV; - break; - case 'y': - case 'Y': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_NEG; - break; - case 'z': - case 'Z': - paste[ paste_size++ ] = - BUTTON_ALPHA; - if ( islower( c ) ) - paste[ paste_size++ ] = - BUTTON_SHL; - paste[ paste_size++ ] = BUTTON_EEX; - break; - default: - printf( "unknown %c %d\n", c, *p ); - break; - } - } - if ( paste_in ) - XFree( paste_in ); - if ( paste_size ) { - return 1; - } + char* p = paste_in; + if ( x > MAX_PASTE ) { + x = 0; + printf( "input too long. limit is %d " + "characters\n", + MAX_PASTE ); } - } - } else { - if ( xev.xbutton.button == Button1 || - xev.xbutton.button == Button2 || - xev.xbutton.button == Button3 ) { - for ( i = BUTTON_A; i <= LAST_BUTTON; i++ ) { - if ( xev.xbutton.subwindow == - buttons[ i ].xwin ) { - if ( buttons[ i ].pressed ) { - if ( xev.xbutton.button == Button3 ) { - button_released( i ); - DrawButton( i ); - } + paste_count = 0; + paste_size = 0; + while ( x-- ) { + char c = *p++; + switch ( c ) { + case '.': + paste[ paste_size++ ] = + BUTTON_PERIOD; + break; + case '0': + paste[ paste_size++ ] = BUTTON_0; + break; + case '1': + paste[ paste_size++ ] = BUTTON_1; + break; + case '2': + paste[ paste_size++ ] = BUTTON_2; + break; + case '3': + paste[ paste_size++ ] = BUTTON_3; + break; + case '4': + paste[ paste_size++ ] = BUTTON_4; + break; + case '5': + paste[ paste_size++ ] = BUTTON_5; + break; + case '6': + paste[ paste_size++ ] = BUTTON_6; + break; + case '7': + paste[ paste_size++ ] = BUTTON_7; + break; + case '8': + paste[ paste_size++ ] = BUTTON_8; + break; + case '9': + paste[ paste_size++ ] = BUTTON_9; + break; + case '\n': + paste[ paste_size++ ] = BUTTON_SHR; + paste[ paste_size++ ] = + BUTTON_PERIOD; + break; + case '!': + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_DEL; + break; + case '+': + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = BUTTON_PLUS; + break; + case '-': + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = + BUTTON_MINUS; + break; + case '*': + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = BUTTON_MUL; + break; + case '/': + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = BUTTON_DIV; + break; + case ' ': + paste[ paste_size++ ] = 47; + break; + case '(': + paste[ paste_size++ ] = BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_DIV; + break; + case '[': + paste[ paste_size++ ] = BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_MUL; + break; + case '<': + if ( x > 1 && *p == '<' ) { + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = + BUTTON_MINUS; + x--; + p++; } else { - last_button = i; - button_pressed( i ); - wake = 1; - first_key = 1; - DrawButton( i ); + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = + BUTTON_2; } break; + case '{': + paste[ paste_size++ ] = BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_PLUS; + break; + case ')': + case ']': + case '}': + paste[ paste_size++ ] = + BUTTON_RIGHT; + break; + case '>': + if ( x > 1 && *p == '>' ) { + paste[ paste_size++ ] = + BUTTON_RIGHT; + paste[ paste_size++ ] = + BUTTON_RIGHT; + paste[ paste_size++ ] = + BUTTON_RIGHT; + x--; + p++; + } else { + paste[ paste_size++ ] = + BUTTON_ALPHA; + paste[ paste_size++ ] = + BUTTON_SHR; + paste[ paste_size++ ] = + BUTTON_2; + } + break; + case '#': + paste[ paste_size++ ] = BUTTON_SHR; + paste[ paste_size++ ] = BUTTON_DIV; + break; + case '_': + paste[ paste_size++ ] = BUTTON_SHR; + paste[ paste_size++ ] = BUTTON_MUL; + break; + case '"': + if ( flag & 1 ) { + flag &= ~1; + paste[ paste_size++ ] = + BUTTON_RIGHT; + } else { + flag |= 1; + paste[ paste_size++ ] = + BUTTON_SHR; + paste[ paste_size++ ] = + BUTTON_MINUS; + } + break; + case ':': + if ( flag & 2 ) { + flag &= ~2; + paste[ paste_size++ ] = + BUTTON_RIGHT; + } else { + flag |= 2; + paste[ paste_size++ ] = + BUTTON_SHR; + paste[ paste_size++ ] = + BUTTON_PLUS; + } + break; + case '\'': + if ( flag & 4 ) { + flag &= ~4; + paste[ paste_size++ ] = + BUTTON_RIGHT; + } else { + flag |= 4; + paste[ paste_size++ ] = + BUTTON_COLON; + } + break; + case 'a': + case 'A': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_A; + break; + case 'b': + case 'B': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_B; + break; + case 'c': + case 'C': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_C; + break; + case 'd': + case 'D': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_D; + break; + case 'e': + case 'E': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_E; + break; + case 'f': + case 'F': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_F; + break; + case 'g': + case 'G': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_MTH; + break; + case 'h': + case 'H': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_PRG; + break; + case 'i': + case 'I': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_CST; + break; + case 'j': + case 'J': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_VAR; + break; + case 'k': + case 'K': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_UP; + break; + case 'l': + case 'L': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_NXT; + break; + + case 'm': + case 'M': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = + BUTTON_COLON; + break; + case 'n': + case 'N': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_STO; + break; + case 'o': + case 'O': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_EVAL; + break; + case 'p': + case 'P': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_LEFT; + break; + case 'q': + case 'Q': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_DOWN; + break; + case 'r': + case 'R': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = + BUTTON_RIGHT; + break; + case 's': + case 'S': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_SIN; + break; + case 't': + case 'T': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_COS; + break; + case 'u': + case 'U': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_TAN; + break; + case 'v': + case 'V': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_SQRT; + break; + case 'w': + case 'W': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = + BUTTON_POWER; + break; + case 'x': + case 'X': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_INV; + break; + case 'y': + case 'Y': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_NEG; + break; + case 'z': + case 'Z': + paste[ paste_size++ ] = + BUTTON_ALPHA; + if ( islower( c ) ) + paste[ paste_size++ ] = + BUTTON_SHL; + paste[ paste_size++ ] = BUTTON_EEX; + break; + default: + printf( "unknown %c %d\n", c, *p ); + break; } } + if ( paste_in ) + XFree( paste_in ); + if ( paste_size ) { + return 1; + } } } - break; - - case ButtonRelease: - - first_key = 0; - if ( xev.xbutton.button == Button1 ) { - button_release_all(); - } - if ( xev.xbutton.button == Button2 ) { - if ( last_button >= 0 ) { - button_released( last_button ); - DrawButton( last_button ); + } else { + if ( xev.xbutton.button == Button1 || + xev.xbutton.button == Button2 || + xev.xbutton.button == Button3 ) { + for ( i = BUTTON_A; i <= LAST_BUTTON; i++ ) { + if ( xev.xbutton.subwindow == + buttons[ i ].xwin ) { + if ( buttons[ i ].pressed ) { + if ( xev.xbutton.button == Button3 ) { + button_released( i ); + DrawButton( i ); + } + } else { + last_button = i; + button_pressed( i ); + wake = 1; + first_key = 1; + DrawButton( i ); + } + break; + } } - last_button = -1; } - break; + } + break; - case FocusOut: - first_key = 0; + case ButtonRelease: + + first_key = 0; + if ( xev.xbutton.button == Button1 ) { button_release_all(); - break; - - case MappingNotify: - - switch ( xev.xmapping.request ) { - case MappingModifier: - case MappingKeyboard: - XRefreshKeyboardMapping( &xev.xmapping ); - break; - case MappingPointer: - default: - break; + } + if ( xev.xbutton.button == Button2 ) { + if ( last_button >= 0 ) { + button_released( last_button ); + DrawButton( last_button ); } + last_button = -1; + } + break; + + case FocusOut: + first_key = 0; + button_release_all(); + break; + + case MappingNotify: + + switch ( xev.xmapping.request ) { + case MappingModifier: + case MappingKeyboard: + XRefreshKeyboardMapping( &xev.xmapping ); break; - - case EnterNotify: - case LeaveNotify: - - break; - - case ClientMessage: - - cm = ( XClientMessageEvent* )&xev; - - if ( cm->message_type == wm_protocols ) { - if ( cm->data.l[ 0 ] == wm_delete_window ) { - /* - * Quit selected from window managers menu - */ - exit_x48( 1 ); - } - - if ( cm->data.l[ 0 ] == wm_save_yourself ) { - save_command_line(); - } - } - break; - + case MappingPointer: default: - - case KeymapNotify: - case ConfigureNotify: - case ReparentNotify: break; + } + break; + + case EnterNotify: + case LeaveNotify: + + break; + + case ClientMessage: + + cm = ( XClientMessageEvent* )&xev; + + if ( cm->message_type == wm_protocols ) { + if ( cm->data.l[ 0 ] == wm_delete_window ) { + /* + * Quit selected from window managers menu + */ + exit_x48( 1 ); + } + + if ( cm->data.l[ 0 ] == wm_save_yourself ) { + save_command_line(); + } + } + break; + + default: + + case KeymapNotify: + case ConfigureNotify: + case ReparentNotify: + break; } } } while ( first_key > 1 ); - if ( first_key ) { + if ( first_key ) first_key++; - } + return wake; - +} #elif defined( GUI_IS_SDL1 ) - +int get_ui_event( void ) { SDL_Event event; int hpkey; int rv; @@ -6653,7 +6666,5 @@ int get_ui_event( void ) { #endif return 1; -#endif - - return 0; /* this is never reached */ } +#endif diff --git a/src/x48_resources.c b/src/x48_resources.c index 38f5efc..e2e2498 100644 --- a/src/x48_resources.c +++ b/src/x48_resources.c @@ -4,34 +4,20 @@ #include #include +#include "options.h" #include "x48_errors.h" #include "x48_resources.h" -int verbose; -int useTerminal; -int useSerial; -int useXShm; -int netbook; -int throttle; -int initialize; -int resetOnStartup; -#if defined( GUI_IS_X11 ) -char* serialLine; -char* romFileName; -char* homeDirectory; -char* res_name; -char* res_class; -#elif defined( GUI_IS_SDL1 ) -char serialLine[ 1024 ]; -char romFileName[ 1024 ]; -char homeDirectory[ 1024 ]; -#endif - #if defined( GUI_IS_X11 ) #include #include #include +int useXShm; +int netbook; +char* res_name; +char* res_class; + XrmDatabase rdb = ( XrmDatabase )0; void usage( void ) { @@ -330,7 +316,6 @@ XFontStruct* get_font_resource( Display* dpy, char* name, char* class ) { } return f; } -#endif void get_resources( void ) { verbose = 0; @@ -341,7 +326,6 @@ void get_resources( void ) { netbook = 0; throttle = 0; -#if defined( GUI_IS_X11 ) if ( get_boolean_resource( "printVersion", "PrintVersion" ) ) show_version(); if ( get_boolean_resource( "printCopyright", "PrintCopyright" ) ) @@ -366,10 +350,21 @@ void get_resources( void ) { netbook = get_boolean_resource( "netbook", "Netbook" ); throttle = get_boolean_resource( "throttle", "Throttle" ); +} #elif defined( GUI_IS_SDL1 ) - strcpy( serialLine, "/dev/ttyS0" ); +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 - strcpy( homeDirectory, ".x48ng" ); // live files are stored in ~/.x48ng -#endif + homeDirectory = ".x48ng"; // live files are stored in ~/.x48ng } +#endif diff --git a/src/x48_resources.h b/src/x48_resources.h index d6014d9..5e2b357 100644 --- a/src/x48_resources.h +++ b/src/x48_resources.h @@ -4,27 +4,10 @@ #if defined( GUI_IS_X11 ) #include #include -#endif -extern int verbose; -extern int useTerminal; -extern int useSerial; extern int useXShm; extern int netbook; -extern int throttle; -extern int initialize; -extern int resetOnStartup; -#if defined( GUI_IS_X11 ) -extern char* serialLine; -extern char* romFileName; -extern char* homeDirectory; -#elif defined( GUI_IS_SDL1 ) -extern char serialLine[]; -extern char romFileName[]; -extern char homeDirectory[]; -#endif -#if defined( GUI_IS_X11 ) extern char* progname; extern char* res_name; extern char* res_class;