merge ui.c & ui_sdl2.c; ui communicate with emulator through functions defined in emulator.h

This commit is contained in:
Gwenhael Le Moine 2024-09-12 13:18:42 +02:00
parent ce5bec821d
commit ed0cd5cfa5
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
8 changed files with 1133 additions and 1275 deletions

View file

@ -7,7 +7,6 @@ PKG_CONFIG ?= pkg-config
MAKEFLAGS +=-j$(NUM_CORES) -l$(NUM_CORES)
DOTOS = src/ui.o \
src/ui_sdl2.o \
src/config.o \
src/emulator.o \
src/main.o

View file

@ -1,6 +1,11 @@
#include "emulator.h"
hpkey_t keyboard[ 49 ] = {
typedef struct hpkey_t {
int code;
bool pressed;
} hpkey_t;
static hpkey_t keyboard[ 49 ] = {
/* From top left to bottom right */
{0x14, 0},
{0x84, 0},
@ -61,7 +66,46 @@ hpkey_t keyboard[ 49 ] = {
{0x00, 0},
};
saturn_t saturn;
display_t display;
static int contrast = 10;
int annunciators_bits[ NB_ANNUNCIATORS ] = { ANN_LEFT, ANN_RIGHT, ANN_ALPHA, ANN_BATTERY, ANN_BUSY, ANN_IO };
void press_key( int hpkey )
{
// Check not already pressed (may be important: avoids a useless do_kbd_int)
if ( keyboard[ hpkey ].pressed )
return;
keyboard[ hpkey ].pressed = true;
}
void release_key( int hpkey )
{
// Check not already released (not critical)
if ( !keyboard[ hpkey ].pressed )
return;
keyboard[ hpkey ].pressed = false;
}
bool is_key_pressed( int hpkey ) { return keyboard[ hpkey ].pressed; }
unsigned char get_annunciators( void ) { return 255; }
bool get_display_state( void ) { return true; }
void get_lcd_buffer( int* target )
{
for ( int i = 0; i < ( LCD_WIDTH * LCD_HEIGHT ); ++i )
target[ i ] = i % 2;
}
int get_contrast( void ) { return contrast; }
void init_emulator( void )
{
// nop;
}
void exit_emulator( void )
{
// nop;
}

View file

@ -78,41 +78,20 @@
#define ANN_BUSY 0x90
#define ANN_IO 0xa0
// LCD
#define NIBBLES_PER_ROW 34
#define LCD_WIDTH 131
#define LCD_HEIGHT 64
typedef unsigned char word_4;
typedef unsigned char word_8;
typedef long word_20;
void press_key( int hpkey );
void release_key( int hpkey );
bool is_key_pressed( int hpkey );
typedef struct hpkey_t {
int code;
bool pressed;
} hpkey_t;
typedef struct display_t {
int on;
long disp_start;
long disp_end;
int offset;
int lines;
int nibs_per_line;
int contrast;
long menu_start;
long menu_end;
} display_t;
typedef struct saturn_t {
word_8 annunc;
} saturn_t;
extern hpkey_t keyboard[ 49 ];
extern saturn_t saturn;
extern display_t display;
extern int annunciators_bits[ NB_ANNUNCIATORS ];
void init_emulator( void );
void exit_emulator( void );
unsigned char get_annunciators( void );
bool get_display_state( void );
void get_lcd_buffer( int* target );
int get_contrast( void );
#endif /* !_EMULATOR_H */

View file

@ -1,13 +1,14 @@
#include <stdbool.h>
#include "emulator.h"
#include "ui.h"
int main( int argc, char** argv )
{
// start_emulator();
init_emulator();
/* (G)UI */
start_UI( config_init( argc, argv ) );
ui_start( config_init( argc, argv ) );
while ( true ) {
ui_update_LCD();

1082
src/ui.c

File diff suppressed because it is too large Load diff

View file

@ -4,49 +4,19 @@
#include "config.h"
#include "emulator.h"
#define DISP_ROWS 64
#define NIBS_PER_BUFFER_ROW ( NIBBLES_PER_ROW + 2 )
/*************/
/* variables */
/*************/
extern int last_annunc_state;
extern unsigned char lcd_nibbles_buffer[ DISP_ROWS ][ NIBS_PER_BUFFER_ROW ];
/*************/
/* functions */
/*************/
extern void init_sdl2_ui( config_t* config );
extern void sdl2_ui_stop( void );
/*************************************************/
/* public API: if it's there it's used elsewhere */
/*************************************************/
/*************************/
/* used in: emu_memory.c */
/*************************/
extern void ( *ui_disp_draw_nibble )( word_20 addr, word_4 val );
extern void ( *ui_menu_draw_nibble )( word_20 addr, word_4 val );
extern void ui_get_event( void );
extern void ui_adjust_contrast( void );
/*****************************************/
/* used in: emu_emulate.c */
/*****************************************/
extern void ( *ui_get_event )( void );
extern void ( *ui_adjust_contrast )( void );
extern void ( *ui_draw_annunc )( void );
/*****************************************************/
/* used in: emu_emulate.c, debugger.c */
/*****************************************************/
extern void ( *ui_update_LCD )( void );
extern void ( *ui_refresh_LCD )( void );
extern void ui_update_LCD( void );
/*******************/
/* used in: main.c */
/*******************/
extern void ui_stop( void );
extern void start_UI( config_t* config );
extern void ui_start( config_t* config );
extern void close_and_exit( void );

View file

@ -99,6 +99,5 @@ extern ann_struct_t ann_tbl[ NB_ANNUNCIATORS ];
/*************/
extern int SmallTextWidth( const char* string, unsigned int length );
extern int BigTextWidth( const char* string, unsigned int length );
extern void ui_init_LCD( void );
#endif /* _UI_INNER_H */

File diff suppressed because it is too large Load diff