use a system font

This commit is contained in:
Gwenhael Le Moine 2023-05-11 16:58:52 +02:00
parent b7a7c607ee
commit 37266dae69
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
5 changed files with 382 additions and 380 deletions

View file

@ -1,6 +1,7 @@
CC = gcc CC = gcc
LIBS = $(shell pkg-config --libs sdl2 SDL2_ttf)
CFLAGS = -Wall -Werror -O3 -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=missing-braces -Wno-error=incompatible-pointer-types CFLAGS = -Wall -Werror -O3 -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=missing-braces -Wno-error=incompatible-pointer-types
LIBS += $(shell pkg-config --libs sdl2 SDL2_ttf) CFLAGS += -DSDL_TTF=1 #-DFONT_FILENAME="/usr/share/fonts/TTF/unifont.ttf"
.PHONY: all clean clean-all pretty-code install .PHONY: all clean clean-all pretty-code install

BIN
dist/FreeSans.ttf vendored

Binary file not shown.

View file

@ -44,8 +44,8 @@
extern SDL_Renderer* renderer; extern SDL_Renderer* renderer;
extern SDL_Texture* faceplateTexture; extern SDL_Texture* faceplateTexture;
#ifdef SDL_TTF #ifdef SDL_TTF
extern TTF_Font* ArialFonte; extern TTF_Font* ttffont;
extern TTF_Font* ArialFonte2; extern TTF_Font* ttffont2;
#endif #endif
SDL_Surface* surfA[ 49 ]; SDL_Surface* surfA[ 49 ];
@ -133,7 +133,7 @@ void drawText( int index, int x, int y, int btn_w, int btn_h ) {
void gui_initKeyboard( Button* calcbuttons ) { void gui_initKeyboard( Button* calcbuttons ) {
printf( "init texts\n" ); printf( "init texts\n" );
#ifdef SDL_TTF #ifdef SDL_TTF
if ( ArialFonte == NULL ) { if ( ttffont == NULL ) {
printf( "init texts error Font NULL\n" ); printf( "init texts error Font NULL\n" );
return; return;
} }
@ -150,7 +150,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
SDL_Surface* s = NULL; SDL_Surface* s = NULL;
SDL_Texture* t = NULL; SDL_Texture* t = NULL;
if ( buttons->text && strcmp( buttons->text, "" ) != 0 ) { if ( buttons->text && strcmp( buttons->text, "" ) != 0 ) {
s = TTF_RenderText_Blended( ArialFonte, buttons->text, s = TTF_RenderUTF8_Blended( ttffont, buttons->text,
couleurBlanche ); couleurBlanche );
if ( s ) { if ( s ) {
t = SDL_CreateTextureFromSurface( renderer, s ); t = SDL_CreateTextureFromSurface( renderer, s );
@ -170,7 +170,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
SDL_Surface* s = NULL; SDL_Surface* s = NULL;
SDL_Texture* t = NULL; SDL_Texture* t = NULL;
if ( buttons->textB && strcmp( buttons->textB, "" ) != 0 ) { if ( buttons->textB && strcmp( buttons->textB, "" ) != 0 ) {
s = TTF_RenderText_Blended( ArialFonte2, buttons->textB, s = TTF_RenderUTF8_Blended( ttffont2, buttons->textB,
couleurPurple ); couleurPurple );
if ( s ) { if ( s ) {
t = SDL_CreateTextureFromSurface( renderer, s ); t = SDL_CreateTextureFromSurface( renderer, s );
@ -188,7 +188,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
SDL_Surface* s = NULL; SDL_Surface* s = NULL;
SDL_Texture* t = NULL; SDL_Texture* t = NULL;
if ( buttons->textC && strcmp( buttons->textC, "" ) != 0 ) { if ( buttons->textC && strcmp( buttons->textC, "" ) != 0 ) {
s = TTF_RenderText_Blended( ArialFonte2, buttons->textC, s = TTF_RenderUTF8_Blended( ttffont2, buttons->textC,
couleurGreen ); couleurGreen );
if ( s ) { if ( s ) {
t = SDL_CreateTextureFromSurface( renderer, s ); t = SDL_CreateTextureFromSurface( renderer, s );
@ -206,7 +206,7 @@ void gui_initKeyboard( Button* calcbuttons ) {
SDL_Surface* s = NULL; SDL_Surface* s = NULL;
SDL_Texture* t = NULL; SDL_Texture* t = NULL;
if ( buttons->textD && strcmp( buttons->textD, "" ) != 0 ) { if ( buttons->textD && strcmp( buttons->textD, "" ) != 0 ) {
s = TTF_RenderText_Blended( ArialFonte2, buttons->textD, s = TTF_RenderUTF8_Blended( ttffont2, buttons->textD,
couleurYellow ); couleurYellow );
if ( s ) { if ( s ) {
t = SDL_CreateTextureFromSurface( renderer, s ); t = SDL_CreateTextureFromSurface( renderer, s );

View file

@ -28,7 +28,8 @@
#ifndef __GUI_H #ifndef __GUI_H
#define __GUI_H #define __GUI_H
#define SDL_TTF /* #define SDL_TTF */
#define FONT_FILENAME "/usr/share/fonts/TTF/unifont.ttf"
#include "types.h" #include "types.h"

View file

@ -59,8 +59,8 @@ SDL_Texture* tex2Target = NULL;
SDL_Texture* faceplateTexture = NULL; SDL_Texture* faceplateTexture = NULL;
#ifdef SDL_TTF #ifdef SDL_TTF
TTF_Font* ArialFonte = NULL; TTF_Font* ttffont = NULL;
TTF_Font* ArialFonte2 = NULL; TTF_Font* ttffont2 = NULL;
#endif #endif
SDL_TimerID my_timer0_id; SDL_TimerID my_timer0_id;
@ -197,65 +197,65 @@ static int fullscreen = FALSE;
static void parse_args( int argc, char* argv[] ) { static void parse_args( int argc, char* argv[] ) {
while ( --argc ) { while ( --argc ) {
argv++; argv++;
if ( argv[ 0 ][ 0 ] == '-' ) { if ( argv[ 0 ][ 0 ] == '-' ) {
switch ( argv[ 0 ][ 1 ] ) { switch ( argv[ 0 ][ 1 ] ) {
case 'f': case 'f':
fullscreen = TRUE; fullscreen = TRUE;
break; break;
case 'w': case 'w':
fullscreen = FALSE; fullscreen = FALSE;
break; break;
} }
} }
} }
} }
static void program_init( void ) { static void program_init( void ) {
if ( SDL_Init( SDL_INIT_VIDEO | IMG_INIT_PNG | SDL_INIT_TIMER ) < 0 ) { if ( SDL_Init( SDL_INIT_VIDEO | IMG_INIT_PNG | SDL_INIT_TIMER ) < 0 ) {
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
return; return;
} }
#ifdef SDL_TTF #ifdef SDL_TTF
if ( TTF_Init() == -1 ) { if ( TTF_Init() == -1 ) {
fprintf( stderr, "Erreur d'initialisation de TTF_Init : %s\n", fprintf( stderr, "Erreur d'initialisation de TTF_Init : %s\n",
TTF_GetError() ); TTF_GetError() );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
ArialFonte = TTF_OpenFont( "FreeSans.ttf", 14 ); ttffont = TTF_OpenFont( FONT_FILENAME, 14 );
ArialFonte2 = TTF_OpenFont( "FreeSans.ttf", 10 ); ttffont2 = TTF_OpenFont( FONT_FILENAME, 10 );
#endif #endif
window = SDL_CreateWindow( "jsEmu48", SDL_WINDOWPOS_UNDEFINED, window = SDL_CreateWindow( "jsEmu48", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if ( window == NULL ) { if ( window == NULL ) {
printf( "Window could not be created! SDL_Error: %s\n", printf( "Window could not be created! SDL_Error: %s\n",
SDL_GetError() ); SDL_GetError() );
return; return;
} }
renderer = SDL_CreateRenderer( renderer = SDL_CreateRenderer(
window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if ( renderer == NULL ) { if ( renderer == NULL ) {
printf( "Erreur lors de la creation d'un renderer : %s", printf( "Erreur lors de la creation d'un renderer : %s",
SDL_GetError() ); SDL_GetError() );
return; return;
} }
tex2Target = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, tex2Target = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, 504, 1124 ); SDL_TEXTUREACCESS_TARGET, 504, 1124 );
texTarget = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, texTarget = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING, 504, 1124 ); SDL_TEXTUREACCESS_STREAMING, 504, 1124 );
/* /*
SDL_Surface * faceplate = IMG_Load("48face5.png"); SDL_Surface * faceplate = IMG_Load("48face5.png");
if(faceplate) { if(faceplate) {
//printf("init text2 %s\n", buttons->text); //printf("init text2 %s\n", buttons->text);
faceplateTexture = SDL_CreateTextureFromSurface( renderer, faceplate faceplateTexture = SDL_CreateTextureFromSurface( renderer, faceplate
); );
}*/ }*/
@ -280,7 +280,7 @@ void start_timers() {
// my_timer0_id = SDL_AddTimer(100, my_callbackfunc0, NULL); // gui_update // my_timer0_id = SDL_AddTimer(100, my_callbackfunc0, NULL); // gui_update
// my_timer1_id = SDL_AddTimer(50, my_callbackfunc1, NULL); // display // my_timer1_id = SDL_AddTimer(50, my_callbackfunc1, NULL); // display
// my_timer2_id = SDL_AddTimer(1000, my_callbackfunc2, NULL); // cpu real // my_timer2_id = SDL_AddTimer(1000, my_callbackfunc2, NULL); // cpu real
//speed my_timer3_id = SDL_AddTimer(62, my_callbackfunc3, NULL); // timer1 //speed my_timer3_id = SDL_AddTimer(62, my_callbackfunc3, NULL); // timer1
// my_timer4_id = SDL_AddTimer(500, my_callbackfunc4, NULL); // timer2 // my_timer4_id = SDL_AddTimer(500, my_callbackfunc4, NULL); // timer2
} }
@ -293,8 +293,8 @@ static void program_exit( void ) {
SDL_RemoveTimer(my_timer4_id); SDL_RemoveTimer(my_timer4_id);
*/ */
#ifdef SDL_TTF #ifdef SDL_TTF
TTF_CloseFont( ArialFonte ); TTF_CloseFont( ttffont );
TTF_CloseFont( ArialFonte2 ); TTF_CloseFont( ttffont2 );
TTF_Quit(); TTF_Quit();
#endif #endif
SDL_DestroyRenderer( renderer ); SDL_DestroyRenderer( renderer );
@ -308,390 +308,390 @@ boolean refreshSDL() {
while ( SDL_PollEvent( &event ) ) while ( SDL_PollEvent( &event ) )
// if(SDL_PollEvent(&event)) // if(SDL_PollEvent(&event))
{ {
switch ( event.type ) { switch ( event.type ) {
case SDL_MOUSEBUTTONUP: { case SDL_MOUSEBUTTONUP: {
// printf("mouse up %d %d\n", event.button.x, event.button.y); // printf("mouse up %d %d\n", event.button.x, event.button.y);
pcalc_up( event.button.x, event.button.y, 1 ); pcalc_up( event.button.x, event.button.y, 1 );
} break; } break;
case SDL_MOUSEBUTTONDOWN: { case SDL_MOUSEBUTTONDOWN: {
// printf("mouse down %d %d\n", event.button.x, event.button.y); // printf("mouse down %d %d\n", event.button.x, event.button.y);
pcalc_down( event.button.x, event.button.y, 1 ); pcalc_down( event.button.x, event.button.y, 1 );
} break; } break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
printf( "%d %d\n", event.key.keysym.sym, printf( "%d %d\n", event.key.keysym.sym,
event.key.keysym.scancode ); event.key.keysym.scancode );
pcalc_kb_down( event.key.keysym.scancode ); pcalc_kb_down( event.key.keysym.scancode );
switch ( event.key.keysym.scancode ) { switch ( event.key.keysym.scancode ) {
case SDL_SCANCODE_ESCAPE: case SDL_SCANCODE_ESCAPE:
kbd_on_pressed(); kbd_on_pressed();
break; break;
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_RETURN:
case SDL_SCANCODE_KP_ENTER: case SDL_SCANCODE_KP_ENTER:
kbd_key_pressed( 4, 4 ); kbd_key_pressed( 4, 4 );
break; break;
case SDL_SCANCODE_BACKSPACE: case SDL_SCANCODE_BACKSPACE:
kbd_key_pressed( 4, 0 ); kbd_key_pressed( 4, 0 );
break; break;
case SDL_SCANCODE_LEFT: case SDL_SCANCODE_LEFT:
kbd_key_pressed( 6, 2 ); kbd_key_pressed( 6, 2 );
break; break;
case SDL_SCANCODE_RIGHT: case SDL_SCANCODE_RIGHT:
kbd_key_pressed( 6, 0 ); kbd_key_pressed( 6, 0 );
break; break;
case SDL_SCANCODE_UP: case SDL_SCANCODE_UP:
kbd_key_pressed( 7, 1 ); kbd_key_pressed( 7, 1 );
break; break;
case SDL_SCANCODE_DOWN: case SDL_SCANCODE_DOWN:
kbd_key_pressed( 6, 1 ); kbd_key_pressed( 6, 1 );
break; break;
case SDL_SCANCODE_KP_PLUS: case SDL_SCANCODE_KP_PLUS:
kbd_key_pressed( 0, 0 ); kbd_key_pressed( 0, 0 );
break; break;
case SDL_SCANCODE_KP_MINUS: case SDL_SCANCODE_KP_MINUS:
kbd_key_pressed( 1, 0 ); kbd_key_pressed( 1, 0 );
break; break;
case SDL_SCANCODE_KP_MULTIPLY: case SDL_SCANCODE_KP_MULTIPLY:
kbd_key_pressed( 2, 0 ); kbd_key_pressed( 2, 0 );
break; break;
case SDL_SCANCODE_KP_DIVIDE: case SDL_SCANCODE_KP_DIVIDE:
kbd_key_pressed( 3, 0 ); kbd_key_pressed( 3, 0 );
break; break;
case SDL_SCANCODE_A: case SDL_SCANCODE_A:
kbd_key_pressed( 1, 4 ); kbd_key_pressed( 1, 4 );
break; break;
case SDL_SCANCODE_B: case SDL_SCANCODE_B:
kbd_key_pressed( 8, 4 ); kbd_key_pressed( 8, 4 );
break; break;
case SDL_SCANCODE_C: case SDL_SCANCODE_C:
kbd_key_pressed( 8, 3 ); kbd_key_pressed( 8, 3 );
break; break;
case SDL_SCANCODE_D: case SDL_SCANCODE_D:
kbd_key_pressed( 8, 2 ); kbd_key_pressed( 8, 2 );
break; break;
case SDL_SCANCODE_E: case SDL_SCANCODE_E:
kbd_key_pressed( 8, 1 ); kbd_key_pressed( 8, 1 );
break; break;
case SDL_SCANCODE_F: case SDL_SCANCODE_F:
kbd_key_pressed( 8, 0 ); kbd_key_pressed( 8, 0 );
break; break;
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
kbd_key_pressed( 2, 4 ); kbd_key_pressed( 2, 4 );
break; break;
case SDL_SCANCODE_H: case SDL_SCANCODE_H:
kbd_key_pressed( 7, 4 ); kbd_key_pressed( 7, 4 );
break; break;
case SDL_SCANCODE_I: case SDL_SCANCODE_I:
kbd_key_pressed( 7, 3 ); kbd_key_pressed( 7, 3 );
break; break;
case SDL_SCANCODE_J: case SDL_SCANCODE_J:
kbd_key_pressed( 7, 2 ); kbd_key_pressed( 7, 2 );
break; break;
case SDL_SCANCODE_K: case SDL_SCANCODE_K:
kbd_key_pressed( 7, 1 ); kbd_key_pressed( 7, 1 );
break; break;
case SDL_SCANCODE_L: case SDL_SCANCODE_L:
kbd_key_pressed( 7, 0 ); kbd_key_pressed( 7, 0 );
break; break;
case SDL_SCANCODE_M: case SDL_SCANCODE_M:
kbd_key_pressed( 0, 4 ); kbd_key_pressed( 0, 4 );
break; break;
case SDL_SCANCODE_N: case SDL_SCANCODE_N:
kbd_key_pressed( 6, 4 ); kbd_key_pressed( 6, 4 );
break; break;
case SDL_SCANCODE_O: case SDL_SCANCODE_O:
kbd_key_pressed( 6, 3 ); kbd_key_pressed( 6, 3 );
break; break;
case SDL_SCANCODE_P: case SDL_SCANCODE_P:
kbd_key_pressed( 6, 2 ); kbd_key_pressed( 6, 2 );
break; break;
case SDL_SCANCODE_Q: case SDL_SCANCODE_Q:
kbd_key_pressed( 6, 1 ); kbd_key_pressed( 6, 1 );
break; break;
case SDL_SCANCODE_R: case SDL_SCANCODE_R:
kbd_key_pressed( 6, 0 ); kbd_key_pressed( 6, 0 );
break; break;
case SDL_SCANCODE_S: case SDL_SCANCODE_S:
kbd_key_pressed( 3, 4 ); kbd_key_pressed( 3, 4 );
break; break;
case SDL_SCANCODE_T: case SDL_SCANCODE_T:
kbd_key_pressed( 5, 4 ); kbd_key_pressed( 5, 4 );
break; break;
case SDL_SCANCODE_U: case SDL_SCANCODE_U:
kbd_key_pressed( 5, 3 ); kbd_key_pressed( 5, 3 );
break; break;
case SDL_SCANCODE_V: case SDL_SCANCODE_V:
kbd_key_pressed( 5, 2 ); kbd_key_pressed( 5, 2 );
break; break;
case SDL_SCANCODE_W: case SDL_SCANCODE_W:
kbd_key_pressed( 5, 1 ); kbd_key_pressed( 5, 1 );
break; break;
case SDL_SCANCODE_X: case SDL_SCANCODE_X:
kbd_key_pressed( 5, 0 ); kbd_key_pressed( 5, 0 );
break; break;
case SDL_SCANCODE_Y: case SDL_SCANCODE_Y:
kbd_key_pressed( 4, 3 ); kbd_key_pressed( 4, 3 );
break; break;
case SDL_SCANCODE_Z: case SDL_SCANCODE_Z:
kbd_key_pressed( 4, 2 ); kbd_key_pressed( 4, 2 );
break; break;
default: default:
break; break;
} }
break; break;
case SDL_KEYUP: case SDL_KEYUP:
pcalc_kb_up( event.key.keysym.scancode ); pcalc_kb_up( event.key.keysym.scancode );
switch ( event.key.keysym.scancode ) { switch ( event.key.keysym.scancode ) {
case SDL_SCANCODE_ESCAPE: case SDL_SCANCODE_ESCAPE:
kbd_on_released(); kbd_on_released();
break; break;
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_RETURN:
case SDL_SCANCODE_KP_ENTER: case SDL_SCANCODE_KP_ENTER:
kbd_key_released( 4, 4 ); kbd_key_released( 4, 4 );
break; break;
case SDL_SCANCODE_BACKSPACE: case SDL_SCANCODE_BACKSPACE:
kbd_key_released( 4, 0 ); kbd_key_released( 4, 0 );
break; break;
case SDL_SCANCODE_LEFT: case SDL_SCANCODE_LEFT:
kbd_key_released( 6, 2 ); kbd_key_released( 6, 2 );
break; break;
case SDL_SCANCODE_RIGHT: case SDL_SCANCODE_RIGHT:
kbd_key_released( 6, 0 ); kbd_key_released( 6, 0 );
break; break;
case SDL_SCANCODE_UP: case SDL_SCANCODE_UP:
kbd_key_released( 7, 1 ); kbd_key_released( 7, 1 );
break; break;
case SDL_SCANCODE_DOWN: case SDL_SCANCODE_DOWN:
kbd_key_released( 6, 1 ); kbd_key_released( 6, 1 );
break; break;
case SDL_SCANCODE_KP_PLUS: case SDL_SCANCODE_KP_PLUS:
kbd_key_released( 0, 0 ); kbd_key_released( 0, 0 );
break; break;
case SDL_SCANCODE_KP_MINUS: case SDL_SCANCODE_KP_MINUS:
kbd_key_released( 1, 0 ); kbd_key_released( 1, 0 );
break; break;
case SDL_SCANCODE_KP_MULTIPLY: case SDL_SCANCODE_KP_MULTIPLY:
kbd_key_released( 2, 0 ); kbd_key_released( 2, 0 );
break; break;
case SDL_SCANCODE_KP_DIVIDE: case SDL_SCANCODE_KP_DIVIDE:
kbd_key_released( 3, 0 ); kbd_key_released( 3, 0 );
break; break;
case SDL_SCANCODE_A: case SDL_SCANCODE_A:
kbd_key_released( 1, 4 ); kbd_key_released( 1, 4 );
break; break;
case SDL_SCANCODE_B: case SDL_SCANCODE_B:
kbd_key_released( 8, 4 ); kbd_key_released( 8, 4 );
break; break;
case SDL_SCANCODE_C: case SDL_SCANCODE_C:
kbd_key_released( 8, 3 ); kbd_key_released( 8, 3 );
break; break;
case SDL_SCANCODE_D: case SDL_SCANCODE_D:
kbd_key_released( 8, 2 ); kbd_key_released( 8, 2 );
break; break;
case SDL_SCANCODE_E: case SDL_SCANCODE_E:
kbd_key_released( 8, 1 ); kbd_key_released( 8, 1 );
break; break;
case SDL_SCANCODE_F: case SDL_SCANCODE_F:
kbd_key_released( 8, 0 ); kbd_key_released( 8, 0 );
break; break;
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
kbd_key_released( 2, 4 ); kbd_key_released( 2, 4 );
break; break;
case SDL_SCANCODE_H: case SDL_SCANCODE_H:
kbd_key_released( 7, 4 ); kbd_key_released( 7, 4 );
break; break;
case SDL_SCANCODE_I: case SDL_SCANCODE_I:
kbd_key_released( 7, 3 ); kbd_key_released( 7, 3 );
break; break;
case SDL_SCANCODE_J: case SDL_SCANCODE_J:
kbd_key_released( 7, 2 ); kbd_key_released( 7, 2 );
break; break;
case SDL_SCANCODE_K: case SDL_SCANCODE_K:
kbd_key_released( 7, 1 ); kbd_key_released( 7, 1 );
break; break;
case SDL_SCANCODE_L: case SDL_SCANCODE_L:
kbd_key_released( 7, 0 ); kbd_key_released( 7, 0 );
break; break;
case SDL_SCANCODE_M: case SDL_SCANCODE_M:
kbd_key_released( 0, 4 ); kbd_key_released( 0, 4 );
break; break;
case SDL_SCANCODE_N: case SDL_SCANCODE_N:
kbd_key_released( 6, 4 ); kbd_key_released( 6, 4 );
break; break;
case SDL_SCANCODE_O: case SDL_SCANCODE_O:
kbd_key_released( 6, 3 ); kbd_key_released( 6, 3 );
break; break;
case SDL_SCANCODE_P: case SDL_SCANCODE_P:
kbd_key_released( 6, 2 ); kbd_key_released( 6, 2 );
break; break;
case SDL_SCANCODE_Q: case SDL_SCANCODE_Q:
kbd_key_released( 6, 1 ); kbd_key_released( 6, 1 );
break; break;
case SDL_SCANCODE_R: case SDL_SCANCODE_R:
kbd_key_released( 6, 0 ); kbd_key_released( 6, 0 );
break; break;
case SDL_SCANCODE_S: case SDL_SCANCODE_S:
kbd_key_released( 3, 4 ); kbd_key_released( 3, 4 );
break; break;
case SDL_SCANCODE_T: case SDL_SCANCODE_T:
kbd_key_released( 5, 4 ); kbd_key_released( 5, 4 );
break; break;
case SDL_SCANCODE_U: case SDL_SCANCODE_U:
kbd_key_released( 5, 3 ); kbd_key_released( 5, 3 );
break; break;
case SDL_SCANCODE_V: case SDL_SCANCODE_V:
kbd_key_released( 5, 2 ); kbd_key_released( 5, 2 );
break; break;
case SDL_SCANCODE_W: case SDL_SCANCODE_W:
kbd_key_released( 5, 1 ); kbd_key_released( 5, 1 );
break; break;
case SDL_SCANCODE_X: case SDL_SCANCODE_X:
kbd_key_released( 5, 0 ); kbd_key_released( 5, 0 );
break; break;
case SDL_SCANCODE_Y: case SDL_SCANCODE_Y:
kbd_key_released( 4, 3 ); kbd_key_released( 4, 3 );
break; break;
case SDL_SCANCODE_Z: case SDL_SCANCODE_Z:
kbd_key_released( 4, 2 ); kbd_key_released( 4, 2 );
break; break;
default: default:
break; break;
} }
/* /*
case SDLK_LEFT: case SDLK_LEFT:
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
kbd_key_released (1, 3); kbd_key_released (1, 3);
break; break;
case SDLK_UP: case SDLK_UP:
break; break;
case SDLK_DOWN: case SDLK_DOWN:
break; break;
case SDLK_ESCAPE: case SDLK_ESCAPE:
break; break;
*/ */
break; break;
case SDL_USEREVENT: { case SDL_USEREVENT: {
printf( "SDL_USEREVENT\n" ); printf( "SDL_USEREVENT\n" );
// if(event.user.code == 1) // if(event.user.code == 1)
// void (*p) (void*) = event.user.data1; // void (*p) (void*) = event.user.data1;
// p(event.user.data2); // p(event.user.data2);
} break; } break;
case SDL_QUIT: { case SDL_QUIT: {
please_exit = TRUE; please_exit = TRUE;
// emulator_state = EMULATOR_STOP; // emulator_state = EMULATOR_STOP;
return FALSE; return FALSE;
} }
} }
} }
return TRUE; return TRUE;
} }
void mainloop() { void mainloop() {
if ( please_exit == TRUE ) { if ( please_exit == TRUE ) {
printf( "please exit\n" ); printf( "please exit\n" );
return; return;
} }
if ( SDL_ready == TRUE ) { if ( SDL_ready == TRUE ) {
currentTime = SDL_GetTicks(); currentTime = SDL_GetTicks();
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
currentTime_emu = currentTime; currentTime_emu = currentTime;
emuframecount = 0; emuframecount = 0;
do { do {
emuframecount++; emuframecount++;
emulator_run(); emulator_run();
currentTime_emu = SDL_GetTicks() - currentTime; currentTime_emu = SDL_GetTicks() - currentTime;
} while ( currentTime_emu < 2 ); } while ( currentTime_emu < 2 );
// printf("EMU emuframecount = %d | time = %d\n", emuframecount, // printf("EMU emuframecount = %d | time = %d\n", emuframecount,
// currentTime_emu); // currentTime_emu);
#else #else
emulator_run(); emulator_run();
#endif #endif
/* /*
framecount++; framecount++;
if (currentTime >= lastTime_timer_fps + 1000) { if (currentTime >= lastTime_timer_fps + 1000) {
//printf("Report(2) %dmsec: %d\n", delay_timer2, currentTime - //printf("Report(2) %dmsec: %d\n", delay_timer2, currentTime -
lastTime_timer2); lastTime_timer_fps = currentTime; printf("FPS = %d\n", lastTime_timer2); lastTime_timer_fps = currentTime; printf("FPS = %d\n",
framecount); framecount = 0; framecount); framecount = 0;
} }
*/ */
// printf("mainloop() currentTime = %d\n", currentTime); // printf("mainloop() currentTime = %d\n", currentTime);
#if 1 #if 1
// true_speed_proc // true_speed_proc
if ( currentTime > lastTime_timer2 + delay_timer2 ) { if ( currentTime > lastTime_timer2 + delay_timer2 ) {
// printf("Report(2) %dmsec: %d\n", delay_timer2, currentTime - // printf("Report(2) %dmsec: %d\n", delay_timer2, currentTime -
// lastTime_timer2); // lastTime_timer2);
lastTime_timer2 = currentTime; lastTime_timer2 = currentTime;
true_speed_proc(); true_speed_proc();
} }
// display_update // display_update
if ( currentTime > lastTime_timer1 + delay_timer1 ) { if ( currentTime > lastTime_timer1 + delay_timer1 ) {
// printf("Report(1) %dmsec: %d\n", delay_timer1, currentTime - // printf("Report(1) %dmsec: %d\n", delay_timer1, currentTime -
// lastTime_timer1); // lastTime_timer1);
lastTime_timer1 = currentTime; lastTime_timer1 = currentTime;
display_update(); display_update();
} }
// timer1 // timer1
if ( currentTime > lastTime_timer3 + delay_timer3 ) { if ( currentTime > lastTime_timer3 + delay_timer3 ) {
// printf("Report(3) %dmsec: %d\n", delay_timer3, currentTime - // printf("Report(3) %dmsec: %d\n", delay_timer3, currentTime -
// lastTime_timer3); // lastTime_timer3);
lastTime_timer3 = currentTime; lastTime_timer3 = currentTime;
timer1_update(); timer1_update();
} }
// timer2 // timer2
if ( currentTime > lastTime_timer4 + delay_timer4 ) { if ( currentTime > lastTime_timer4 + delay_timer4 ) {
// printf("Report(4) %dmsec: %d\n", delay_timer4, currentTime - // printf("Report(4) %dmsec: %d\n", delay_timer4, currentTime -
// lastTime_timer4); // lastTime_timer4);
lastTime_timer4 = currentTime; lastTime_timer4 = currentTime;
timer2_update(); timer2_update();
} }
// display show // display show
if ( currentTime > lastTime_timer5 + delay_timer5 ) { if ( currentTime > lastTime_timer5 + delay_timer5 ) {
lastTime_timer5 = currentTime; lastTime_timer5 = currentTime;
display_show(); display_show();
} }
#endif #endif
if ( refreshSDL() == FALSE ) { if ( refreshSDL() == FALSE ) {
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
printf( "emscripten_cancel_main_loop\n" ); printf( "emscripten_cancel_main_loop\n" );
emscripten_cancel_main_loop(); emscripten_cancel_main_loop();
#endif #endif
return; return;
} }
} }
} }
@ -714,7 +714,7 @@ int main( int argc, char* argv[] ) {
#else #else
printf( "NO emscripten_set_main_loop\n" ); printf( "NO emscripten_set_main_loop\n" );
while ( please_exit == FALSE ) while ( please_exit == FALSE )
mainloop(); mainloop();
#endif #endif
/* /*