reduce the number of #ifdef X11/SDL1

This commit is contained in:
Gwenhael Le Moine 2023-09-07 16:01:46 +02:00
parent 008077ad4a
commit 48cc5e941c
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 1233 additions and 996 deletions

View file

@ -11,7 +11,7 @@
#include "hp48.h"
#include "hp48emu.h"
#include "timer.h"
#include "x48.h"
#include "x48.h" /* adjust_contrast(); ann_struct_t; DISP_ROWS; NIBS_PER_BUFFER_ROW */
saturn_t saturn;
@ -78,6 +78,16 @@ display_t display;
unsigned char disp_buf[ DISP_ROWS ][ NIBS_PER_BUFFER_ROW ];
unsigned char lcd_buffer[ DISP_ROWS ][ NIBS_PER_BUFFER_ROW ];
ann_struct_t ann_tbl[] = {
{ ANN_LEFT, 16, 4, ann_left_width, ann_left_height, ann_left_bitmap },
{ ANN_RIGHT, 61, 4, ann_right_width, ann_right_height, ann_right_bitmap },
{ ANN_ALPHA, 106, 4, ann_alpha_width, ann_alpha_height, ann_alpha_bitmap },
{ ANN_BATTERY, 151, 4, ann_battery_width, ann_battery_height,
ann_battery_bitmap },
{ ANN_BUSY, 196, 4, ann_busy_width, ann_busy_height, ann_busy_bitmap },
{ ANN_IO, 241, 4, ann_io_width, ann_io_height, ann_io_bitmap },
{ 0 } };
#if defined( GUI_IS_X11 )
Pixmap nibble_maps[ 16 ];
@ -101,55 +111,8 @@ unsigned char nibbles[ 16 ][ 2 ] = {
};
static unsigned char nibble_bitmap[ 16 ];
#endif
ann_struct_t ann_tbl[] = {
{ ANN_LEFT, 16, 4, ann_left_width, ann_left_height, ann_left_bitmap },
{ ANN_RIGHT, 61, 4, ann_right_width, ann_right_height, ann_right_bitmap },
{ ANN_ALPHA, 106, 4, ann_alpha_width, ann_alpha_height, ann_alpha_bitmap },
{ ANN_BATTERY, 151, 4, ann_battery_width, ann_battery_height,
ann_battery_bitmap },
{ ANN_BUSY, 196, 4, ann_busy_width, ann_busy_height, ann_busy_bitmap },
{ ANN_IO, 241, 4, ann_io_width, ann_io_height, ann_io_bitmap },
{ 0 } };
void init_display( void ) {
display.on = ( int )( saturn.disp_io & 0x8 ) >> 3;
display.disp_start = ( saturn.disp_addr & 0xffffe );
display.offset = ( saturn.disp_io & 0x7 );
disp.offset = 2 * display.offset;
display.lines = ( saturn.line_count & 0x3f );
if ( display.lines == 0 )
display.lines = 63;
disp.lines = 2 * display.lines;
if ( disp.lines < 110 )
disp.lines = 110;
if ( display.offset > 3 )
display.nibs_per_line =
( NIBBLES_PER_ROW + saturn.line_offset + 2 ) & 0xfff;
else
display.nibs_per_line =
( NIBBLES_PER_ROW + saturn.line_offset ) & 0xfff;
display.disp_end =
display.disp_start + ( display.nibs_per_line * ( display.lines + 1 ) );
display.menu_start = saturn.menu_addr;
display.menu_end = saturn.menu_addr + 0x110;
display.contrast = saturn.contrast_ctrl;
display.contrast |= ( ( saturn.disp_test & 0x1 ) << 4 );
display.annunc = saturn.annunc;
memset( disp_buf, 0xf0, sizeof( disp_buf ) );
memset( lcd_buffer, 0xf0, sizeof( lcd_buffer ) );
#if defined( GUI_IS_X11 )
/* init nibble_maps */
static inline void init_nibble_maps( void ) {
int i;
for ( i = 0; i < 16; i++ ) {
@ -194,10 +157,8 @@ void init_display( void ) {
nibble_bitmap[ 0xf ] = 0xff; /* **** */
}
}
#endif
}
#if defined( GUI_IS_X11 )
static inline void draw_nibble( int c, int r, int val ) {
int x, y;
@ -217,6 +178,8 @@ static inline void draw_nibble( int c, int r, int val ) {
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 ) {
int x, y;
@ -253,26 +216,22 @@ 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;
#if defined( GUI_IS_X11 )
int addr_pad;
int val, line_pad, line_length;
word_20 data_addr, data_addr_2;
#endif
if ( !disp.mapped ) {
#if defined( GUI_IS_X11 )
refresh_icon();
#endif
return;
}
if ( display.on ) {
addr = display.disp_start;
#if defined( GUI_IS_X11 )
if ( shm_flag ) {
data_addr = 0;
data_addr_2 = disp.disp_image->bytes_per_line;
@ -294,7 +253,6 @@ void update_display( void ) {
}
disp.display_update |= UPDATE_DISP;
} else {
#endif
if ( display.offset != old_offset ) {
memset(
disp_buf, 0xf0,
@ -315,12 +273,10 @@ void update_display( void ) {
draw_row( addr, i );
addr += display.nibs_per_line;
}
#if defined( GUI_IS_X11 )
}
#endif
if ( i < DISP_ROWS ) {
addr = display.menu_start;
#if defined( GUI_IS_X11 )
if ( shm_flag ) {
data_addr = 0;
data_addr_2 = disp.menu_image->bytes_per_line;
@ -339,17 +295,13 @@ void update_display( void ) {
}
disp.display_update |= UPDATE_MENU;
} else {
#endif
for ( ; i < DISP_ROWS; i++ ) {
draw_row( addr, i );
addr += NIBBLES_PER_ROW;
}
#if defined( GUI_IS_X11 )
}
#endif
}
} else {
#if defined( GUI_IS_X11 )
if ( shm_flag ) {
memset( disp.disp_image->data, 0,
( size_t )( disp.disp_image->bytes_per_line *
@ -359,23 +311,19 @@ void update_display( void ) {
disp.menu_image->height ) );
disp.display_update = UPDATE_DISP | UPDATE_MENU;
} else {
#endif
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 );
}
}
#if defined( GUI_IS_X11 )
}
#endif
}
}
void redraw_display( void ) {
#if defined( GUI_IS_X11 )
XClearWindow( dpy, disp.win );
#endif
memset( disp_buf, 0, sizeof( disp_buf ) );
memset( lcd_buffer, 0, sizeof( lcd_buffer ) );
update_display();
@ -383,9 +331,7 @@ void redraw_display( void ) {
void disp_draw_nibble( word_20 addr, word_4 val ) {
long offset;
#if defined( GUI_IS_X11 )
int shm_addr;
#endif
int x, y;
offset = ( addr - display.disp_start );
@ -396,7 +342,6 @@ void disp_draw_nibble( word_20 addr, word_4 val ) {
y = offset / display.nibs_per_line;
if ( y < 0 || y > 63 )
return;
#if defined( GUI_IS_X11 )
if ( shm_flag ) {
shm_addr = ( 2 * y * disp.disp_image->bytes_per_line ) + x;
disp.disp_image->data[ shm_addr ] = nibble_bitmap[ val ];
@ -405,16 +350,12 @@ void disp_draw_nibble( word_20 addr, word_4 val ) {
nibble_bitmap[ val ];
disp.display_update |= UPDATE_DISP;
} else {
#endif
if ( val != disp_buf[ y ][ x ] ) {
disp_buf[ y ][ x ] = val;
draw_nibble( x, y, val );
}
#if defined( GUI_IS_X11 )
}
#endif
} else {
#if defined( GUI_IS_X11 )
if ( shm_flag ) {
shm_addr = x;
for ( y = 0; y < display.lines; y++ ) {
@ -425,28 +366,22 @@ void disp_draw_nibble( word_20 addr, word_4 val ) {
}
disp.display_update |= UPDATE_DISP;
} else {
#endif
for ( y = 0; y < display.lines; y++ ) {
if ( val != disp_buf[ y ][ x ] ) {
disp_buf[ y ][ x ] = val;
draw_nibble( x, y, val );
}
}
#if defined( GUI_IS_X11 )
}
#endif
}
}
void menu_draw_nibble( word_20 addr, word_4 val ) {
long offset;
#if defined( GUI_IS_X11 )
int shm_addr;
#endif
int x, y;
offset = ( addr - display.menu_start );
#if defined( GUI_IS_X11 )
if ( shm_flag ) {
shm_addr =
2 * ( offset / NIBBLES_PER_ROW ) * disp.menu_image->bytes_per_line +
@ -456,16 +391,13 @@ void menu_draw_nibble( word_20 addr, word_4 val ) {
nibble_bitmap[ val ];
disp.display_update |= UPDATE_MENU;
} else {
#endif
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 );
}
#if defined( GUI_IS_X11 )
}
#endif
}
void draw_annunc( void ) {
@ -477,11 +409,7 @@ void draw_annunc( void ) {
return;
last_annunc_state = val;
#if defined( GUI_IS_SDL1 )
char sdl_annuncstate[ 6 ];
#endif
for ( int i = 0; ann_tbl[ i ].bit; i++ ) {
#if defined( GUI_IS_X11 )
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,
@ -490,28 +418,171 @@ void draw_annunc( void ) {
XClearArea( dpy, disp.win, ann_tbl[ i ].x, ann_tbl[ i ].y,
ann_tbl[ i ].width, ann_tbl[ i ].height, False );
#elif defined( GUI_IS_SDL1 )
sdl_annuncstate[ i ] =
( ( ann_tbl[ i ].bit & val ) == ann_tbl[ i ].bit ) ? 1 : 0;
#endif
}
#if defined( GUI_IS_X11 )
refresh_icon();
#elif defined( GUI_IS_SDL1 )
SDLDrawAnnunc( sdl_annuncstate );
#endif
}
#if defined( GUI_IS_X11 )
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;
static int old_offset = -1;
static int old_lines = -1;
if ( !disp.mapped )
return;
if ( display.on ) {
addr = display.disp_start;
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;
for ( ; i < DISP_ROWS; i++ ) {
draw_row( addr, i );
addr += NIBBLES_PER_ROW;
}
}
} 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 ) {
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 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 ( val != disp_buf[ y ][ x ] ) {
disp_buf[ y ][ x ] = val;
draw_nibble( x, y, val );
}
} 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 x, y;
offset = ( addr - display.menu_start );
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;
char sdl_annuncstate[ 6 ];
for ( int i = 0; ann_tbl[ i ].bit; i++ ) {
sdl_annuncstate[ i ] =
( ( ann_tbl[ i ].bit & val ) == ann_tbl[ i ].bit ) ? 1 : 0;
}
SDLDrawAnnunc( sdl_annuncstate );
}
#endif
void redraw_annunc( void ) {
last_annunc_state = -1;
draw_annunc();
}
void init_display( void ) {
display.on = ( int )( saturn.disp_io & 0x8 ) >> 3;
display.disp_start = ( saturn.disp_addr & 0xffffe );
display.offset = ( saturn.disp_io & 0x7 );
disp.offset = 2 * display.offset;
display.lines = ( saturn.line_count & 0x3f );
if ( display.lines == 0 )
display.lines = 63;
disp.lines = 2 * display.lines;
if ( disp.lines < 110 )
disp.lines = 110;
if ( display.offset > 3 )
display.nibs_per_line =
( NIBBLES_PER_ROW + saturn.line_offset + 2 ) & 0xfff;
else
display.nibs_per_line =
( NIBBLES_PER_ROW + saturn.line_offset ) & 0xfff;
display.disp_end =
display.disp_start + ( display.nibs_per_line * ( display.lines + 1 ) );
display.menu_start = saturn.menu_addr;
display.menu_end = saturn.menu_addr + 0x110;
display.contrast = saturn.contrast_ctrl;
display.contrast |= ( ( saturn.disp_test & 0x1 ) << 4 );
display.annunc = saturn.annunc;
memset( disp_buf, 0xf0, sizeof( disp_buf ) );
memset( lcd_buffer, 0xf0, sizeof( lcd_buffer ) );
init_nibble_maps();
}

View file

@ -4,7 +4,7 @@
#include "hp48.h"
#include "hp48emu.h"
#include "timer.h"
#include "x48.h"
#include "x48.h" /* disp; refresh_display(); get_ui_event() */
extern int throttle;

View file

@ -6,7 +6,7 @@
#include "hp48emu.h"
#include "romio.h"
#include "timer.h"
#include "x48.h"
#include "x48.h" /* disp; refresh_display(); get_ui_event() */
static int interrupt_called = 0;
extern long nibble_masks[ 16 ];

View file

@ -7,7 +7,7 @@
#include "hp48.h"
#include "hp48emu.h"
#include "romio.h"
#include "x48.h"
#include "x48.h" /* disp */
#include "options.h"
extern int device_check;

1878
src/x48.c

File diff suppressed because it is too large Load diff

View file

@ -1130,44 +1130,35 @@ static letter_t small_font[] = {
/* #endif /\* !_SMALL_H *\/ */
#if defined( GUI_IS_X11 )
typedef struct color_t {
const char* name;
int r, g, b;
#if defined( GUI_IS_X11 )
int mono_rgb;
int gray_rgb;
XColor xcolor;
#endif
} color_t;
extern color_t* colors;
typedef struct keypad_t {
unsigned int width;
unsigned int height;
#if defined( GUI_IS_X11 )
Pixmap pixmap;
#endif
} keypad_t;
typedef struct disp_t {
unsigned int w, h;
#if defined( GUI_IS_X11 )
Window win;
GC gc;
#endif
short mapped;
int offset;
int lines;
#if defined( GUI_IS_X11 )
int display_update;
XShmSegmentInfo disp_info;
XImage* disp_image;
XShmSegmentInfo menu_info;
XImage* menu_image;
#endif
} disp_t;
extern disp_t disp;
typedef struct button_t {
const char* name;
@ -1191,15 +1182,66 @@ typedef struct button_t {
const char* right;
const char* sub;
#if defined( GUI_IS_X11 )
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 {
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;
SDL_Surface* surfaceup;
SDL_Surface* surfacedown;
int __dummy;
#endif
} button_t;
// This mimicks the structure formerly lcd.c, except with SDL surfaces instead
@ -1212,22 +1254,20 @@ typedef struct ann_struct {
unsigned int height;
unsigned char* bits;
#if defined( GUI_IS_X11 )
Pixmap pixmap;
#elif defined( GUI_IS_SDL1 )
SDL_Surface* surfaceon;
SDL_Surface* surfaceoff;
#endif
} ann_struct_t;
extern ann_struct_t ann_tbl[];
#if defined( GUI_IS_SDL1 )
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;