diff --git a/Makefile b/Makefile index e20a632..8466855 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,6 @@ 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/gui.c b/src/gui.c index 1916c22..6d3a309 100644 --- a/src/gui.c +++ b/src/gui.c @@ -317,7 +317,81 @@ void button_draw_all( Button* buttons ) } } -bool gui_refresh() +void SDL__display_show() +{ + SDL_SetRenderDrawColor( renderer, colors.faceplate.r, colors.faceplate.g, colors.faceplate.b, colors.faceplate.a ); + SDL_RenderClear( renderer ); + + 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 = colors.lcd_pixoff.r; + G = colors.lcd_pixoff.g; + B = colors.lcd_pixoff.b; + } else if ( hp48pixel == '\1' ) { + R = colors.lcd_pixgray1.r; + G = colors.lcd_pixgray1.g; + B = colors.lcd_pixgray1.b; + } else if ( hp48pixel == '\2' ) { + R = colors.lcd_pixgray2.r; + G = colors.lcd_pixgray2.g; + B = colors.lcd_pixgray2.b; + } else if ( hp48pixel == '\3' ) { + R = colors.lcd_pixon.r; + G = colors.lcd_pixon.g; + B = colors.lcd_pixon.b; + } + + // 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 ); +} + +bool gui_events() { SDL_Event event; @@ -604,8 +678,8 @@ bool gui_refresh() case SDL_SCANCODE_J: release_VAR(); break; - case SDL_SCANCODE_K: - case SDL_SCANCODE_UP: + case SDL_SCANCODE_K: + case SDL_SCANCODE_UP: release_UP(); break; case SDL_SCANCODE_L: @@ -621,15 +695,15 @@ bool gui_refresh() release_EVAL(); break; case SDL_SCANCODE_P: - case SDL_SCANCODE_LEFT: + case SDL_SCANCODE_LEFT: release_LEFT(); break; case SDL_SCANCODE_Q: - case SDL_SCANCODE_DOWN: + case SDL_SCANCODE_DOWN: release_DOWN(); break; case SDL_SCANCODE_R: - case SDL_SCANCODE_RIGHT: + case SDL_SCANCODE_RIGHT: release_RIGHT(); break; case SDL_SCANCODE_S: diff --git a/src/gui.h b/src/gui.h index a48b509..53756ea 100644 --- a/src/gui.h +++ b/src/gui.h @@ -90,7 +90,9 @@ extern bool SDL_ready; extern void button_draw_all( /*BITMAP *bmp,*/ Button* buttons ); -extern bool gui_refresh(); +extern void SDL__display_show( void ); + +extern bool gui_events(); extern void gui_init( void ); extern void gui_exit( void ); #endif diff --git a/src/gui_display.c b/src/gui_display.c deleted file mode 100644 index ce1a59a..0000000 --- a/src/gui_display.c +++ /dev/null @@ -1,82 +0,0 @@ -#include - -#include -#include - -#include "display.h" -#include "gui.h" -#include "gui_buttons.h" - -void SDL__display_show() -{ - SDL_SetRenderDrawColor( renderer, colors.faceplate.r, colors.faceplate.g, colors.faceplate.b, colors.faceplate.a ); - SDL_RenderClear( renderer ); - - 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 = colors.lcd_pixoff.r; - G = colors.lcd_pixoff.g; - B = colors.lcd_pixoff.b; - } else if ( hp48pixel == '\1' ) { - R = colors.lcd_pixgray1.r; - G = colors.lcd_pixgray1.g; - B = colors.lcd_pixgray1.b; - } else if ( hp48pixel == '\2' ) { - R = colors.lcd_pixgray2.r; - G = colors.lcd_pixgray2.g; - B = colors.lcd_pixgray2.b; - } else if ( hp48pixel == '\3' ) { - R = colors.lcd_pixon.r; - G = colors.lcd_pixon.g; - B = colors.lcd_pixon.b; - } - - // 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 deleted file mode 100644 index c42f275..0000000 --- a/src/gui_display.h +++ /dev/null @@ -1,6 +0,0 @@ -#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 a509e5d..141d66d 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,6 @@ #include "emulator.h" #include "gui.h" #include "display.h" -#include "gui_display.h" unsigned int currentTime; @@ -38,7 +37,7 @@ static inline void mainloop() SDL__display_show(); } - if ( !gui_refresh() ) + if ( !gui_events() ) return; }