split SDL__display_show() otu of display
This commit is contained in:
parent
284f64c69f
commit
31533e8725
8 changed files with 110 additions and 94 deletions
1
Makefile
1
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 \
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
#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 );
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ];
|
||||
|
|
|
@ -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
|
||||
|
|
93
src/gui_display.c
Normal file
93
src/gui_display.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
#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 );
|
||||
}
|
6
src/gui_display.h
Normal file
6
src/gui_display.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __GUI_DISPLAY_H
|
||||
#define __GUI_DISPLAY_H
|
||||
|
||||
extern void SDL__display_show( void );
|
||||
|
||||
#endif
|
|
@ -6,6 +6,7 @@
|
|||
#include "emulator.h"
|
||||
#include "gui.h"
|
||||
#include "display.h"
|
||||
#include "gui_display.h"
|
||||
|
||||
unsigned int currentTime;
|
||||
|
||||
|
|
Loading…
Reference in a new issue