From 31533e87255dfcf59f86634405a0d4c4fca823fc Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sat, 13 Apr 2024 14:13:24 +0200 Subject: [PATCH] split SDL__display_show() otu of display --- Makefile | 1 + src/display.c | 90 +-------------------------------------------- src/display.h | 6 ++- src/gui.c | 5 ++- src/gui.h | 2 - src/gui_display.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ src/gui_display.h | 6 +++ src/main.c | 1 + 8 files changed, 110 insertions(+), 94 deletions(-) create mode 100644 src/gui_display.c create mode 100644 src/gui_display.h diff --git a/Makefile b/Makefile index 1bc56a5..291af04 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ dist/hpemu: src/bus.o \ src/main.o \ src/opcodes.o \ src/gui_buttons.o \ + src/gui_display.o \ src/files.o \ src/ports.o \ src/rpl.o \ diff --git a/src/display.c b/src/display.c index 5d71c40..f6dc134 100644 --- a/src/display.c +++ b/src/display.c @@ -1,8 +1,5 @@ #include -#include -#include - #include "types.h" #include "bus.h" #include "gui_buttons.h" @@ -25,16 +22,10 @@ static address cur_adr; static bool in_menu; static byte off_line; static int off_cnt; -static bool shouldRender = false; +bool shouldRender = false; static int screen_draw_count = 0; static bool drawGS = false; -extern SDL_Renderer* renderer; -extern SDL_Window* window; -extern SDL_Texture* texTarget; -extern SDL_Texture* tex2Target; -extern SDL_Texture* faceplateTexture; - static address draw_lcd_line( address adr, int y ) { int bit = 0; @@ -148,82 +139,3 @@ void display_update( void ) } else if ( off_cnt <= 7 ) /* Display is off and still fading */ off_cnt = 8; } - -void SDL__display_show() -{ - SDL_SetRenderDrawColor( renderer, 48, 68, 90, 0xFF ); // bleu foncé - SDL_RenderClear( renderer ); - - if ( faceplateTexture ) { - SDL_Rect r3 = { 8, 0, 504, 1124 }; - SDL_RenderCopy( renderer, faceplateTexture, NULL, &r3 ); - } - - if ( shouldRender == true ) { - shouldRender = false; - - int pitch, w, h; - Uint32* pixels; - int access; - Uint32 format; - - if ( SDL_QueryTexture( texTarget, &format, &access, &w, &h ) != 0 ) - printf( "error\n" ); - - if ( SDL_LockTexture( texTarget, NULL, ( void** )&pixels, &pitch ) != 0 ) - printf( "SDL_LockTexture: %s.\n", SDL_GetError() ); - - SDL_PixelFormat* pixelFormat = SDL_AllocFormat( format ); - - // do stuff - for ( int y = 0; y < LCD_HEIGHT; y++ ) { - for ( int x = 0; x < LCD_WIDTH; x++ ) { - int R = 0; - int G = 0; - int B = 0; - - byte hp48pixel = lcdScreenGS[ x + y * LCD_WIDTH ]; - - if ( hp48pixel == '\0' ) { - R = 119; - G = 153; - B = 136; - } else if ( hp48pixel == '\1' ) { - R = 71; // 200; - G = 134; // 20; - B = 145; // 20; - } else if ( hp48pixel == '\2' ) { - R = 13; // 20; - G = 108; // 200; - B = 111; // 20; - } else if ( hp48pixel == '\3' ) { - R = 37; - G = 61; - B = 84; - } - - // Now you want to format the color to a correct format that SDL - // can use. Basically we convert our RGB color to a hex-like BGR - // color. - Uint32 color = SDL_MapRGB( pixelFormat, R, G, B ); - - // Before setting the color, we need to know where we have to - // place it. - Uint32 pixelPosition = y * ( pitch / sizeof( unsigned int ) ) + x; - - pixels[ pixelPosition ] = color; - } - } - - SDL_UnlockTexture( texTarget ); - } - - // Show rendered to texture - SDL_Rect r1 = { 0, 0, LCD_WIDTH, LCD_HEIGHT }; - SDL_Rect r2 = { LCD_X * UI_SCALE, LCD_Y * UI_SCALE, LCD_WIDTH * UI_SCALE, LCD_HEIGHT * UI_SCALE }; - SDL_RenderCopyEx( renderer, texTarget, &r1, &r2, 0, NULL, SDL_FLIP_NONE ); - - button_draw_all( calc_buttons ); - - SDL_RenderPresent( renderer ); -} diff --git a/src/display.h b/src/display.h index bcc53aa..ce5271f 100644 --- a/src/display.h +++ b/src/display.h @@ -5,6 +5,9 @@ #include "types.h" +#define LCD_WIDTH 131 +#define LCD_HEIGHT 64 + extern address menu_base; extern address display_base; extern address display_line_offset; @@ -12,8 +15,9 @@ extern byte display_line_count; extern byte display_height; extern byte display_offset; extern bool display_enable; +extern bool shouldRender; +extern byte lcdScreenGS[]; extern void display_update( void ); -extern void SDL__display_show( void ); #endif diff --git a/src/gui.c b/src/gui.c index 7636ad9..b4b2548 100644 --- a/src/gui.c +++ b/src/gui.c @@ -10,6 +10,9 @@ #include "files.h" #include "gui.h" #include "emulator.h" +#include "display.h" + +#define PANEL_FLAG_VISIBLE 0x01 extern SDL_Renderer* renderer; extern SDL_Texture* faceplateTexture; @@ -28,8 +31,6 @@ SDL_Texture* label_Rshift[ 49 ]; SDL_Surface* surfD[ 49 ]; SDL_Texture* label_below[ 49 ]; -#define PANEL_FLAG_VISIBLE 0x01 - static inline void drawText( int index, int x, int y, int btn_w, int btn_h ) { SDL_Surface* letterSurface = surfA[ index ]; diff --git a/src/gui.h b/src/gui.h index fde7499..c3fd61c 100644 --- a/src/gui.h +++ b/src/gui.h @@ -15,8 +15,6 @@ #define LCD_X UI_PADDING #define LCD_Y ( UI_PADDING + ANNUNC_HEIGHT ) -#define LCD_WIDTH 131 -#define LCD_HEIGHT 64 #define UI_K_WIDTH_1 19 #define UI_K_HEIGHT_1 10 diff --git a/src/gui_display.c b/src/gui_display.c new file mode 100644 index 0000000..c56e4ca --- /dev/null +++ b/src/gui_display.c @@ -0,0 +1,93 @@ +#include + +#include +#include + +#include "display.h" +#include "gui.h" +#include "gui_buttons.h" + +extern SDL_Renderer* renderer; +extern SDL_Window* window; +extern SDL_Texture* texTarget; +extern SDL_Texture* tex2Target; +extern SDL_Texture* faceplateTexture; + +void SDL__display_show() +{ + SDL_SetRenderDrawColor( renderer, 48, 68, 90, 0xFF ); // bleu foncé + SDL_RenderClear( renderer ); + + if ( faceplateTexture ) { + SDL_Rect r3 = { 8, 0, 504, 1124 }; + SDL_RenderCopy( renderer, faceplateTexture, NULL, &r3 ); + } + + if ( shouldRender == true ) { + shouldRender = false; + + int pitch, w, h; + Uint32* pixels; + int access; + Uint32 format; + + if ( SDL_QueryTexture( texTarget, &format, &access, &w, &h ) != 0 ) + printf( "error\n" ); + + if ( SDL_LockTexture( texTarget, NULL, ( void** )&pixels, &pitch ) != 0 ) + printf( "SDL_LockTexture: %s.\n", SDL_GetError() ); + + SDL_PixelFormat* pixelFormat = SDL_AllocFormat( format ); + + // do stuff + for ( int y = 0; y < LCD_HEIGHT; y++ ) { + for ( int x = 0; x < LCD_WIDTH; x++ ) { + int R = 0; + int G = 0; + int B = 0; + + byte hp48pixel = lcdScreenGS[ x + y * LCD_WIDTH ]; + + if ( hp48pixel == '\0' ) { + R = 119; + G = 153; + B = 136; + } else if ( hp48pixel == '\1' ) { + R = 71; // 200; + G = 134; // 20; + B = 145; // 20; + } else if ( hp48pixel == '\2' ) { + R = 13; // 20; + G = 108; // 200; + B = 111; // 20; + } else if ( hp48pixel == '\3' ) { + R = 37; + G = 61; + B = 84; + } + + // Now you want to format the color to a correct format that SDL + // can use. Basically we convert our RGB color to a hex-like BGR + // color. + Uint32 color = SDL_MapRGB( pixelFormat, R, G, B ); + + // Before setting the color, we need to know where we have to + // place it. + Uint32 pixelPosition = y * ( pitch / sizeof( unsigned int ) ) + x; + + pixels[ pixelPosition ] = color; + } + } + + SDL_UnlockTexture( texTarget ); + } + + // Show rendered to texture + SDL_Rect r1 = { 0, 0, LCD_WIDTH, LCD_HEIGHT }; + SDL_Rect r2 = { LCD_X * UI_SCALE, LCD_Y * UI_SCALE, LCD_WIDTH * UI_SCALE, LCD_HEIGHT * UI_SCALE }; + SDL_RenderCopyEx( renderer, texTarget, &r1, &r2, 0, NULL, SDL_FLIP_NONE ); + + button_draw_all( calc_buttons ); + + SDL_RenderPresent( renderer ); +} diff --git a/src/gui_display.h b/src/gui_display.h new file mode 100644 index 0000000..c42f275 --- /dev/null +++ b/src/gui_display.h @@ -0,0 +1,6 @@ +#ifndef __GUI_DISPLAY_H +#define __GUI_DISPLAY_H + +extern void SDL__display_show( void ); + +#endif diff --git a/src/main.c b/src/main.c index a09320f..e0214f5 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #include "emulator.h" #include "gui.h" #include "display.h" +#include "gui_display.h" unsigned int currentTime;