From 56fdad78b41b834e0640c9f67d893631bb5104f8 Mon Sep 17 00:00:00 2001 From: turbocat Date: Fri, 15 Apr 2022 22:29:16 +0000 Subject: [PATCH] OpenTyrian: refactoring, fixed launch from game center. git-svn-id: svn://kolibrios.org@9770 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/games/opentyrian/Makefile.linux | 5 +-- contrib/games/opentyrian/SDL/uSDL.c | 50 ------------------------ contrib/games/opentyrian/Tupfile.lua | 3 +- contrib/games/opentyrian/src/destruct.c | 8 ++-- contrib/games/opentyrian/src/game_menu.c | 6 +-- contrib/games/opentyrian/src/keyboard.c | 4 +- contrib/games/opentyrian/src/mainint.c | 14 +++---- contrib/games/opentyrian/src/network.c | 10 ++--- contrib/games/opentyrian/src/nortsong.c | 6 +-- contrib/games/opentyrian/src/opentyr.c | 38 +++++++++++------- contrib/games/opentyrian/src/opentyr.h | 8 ++-- contrib/games/opentyrian/src/setup.c | 2 +- contrib/games/opentyrian/src/tyrian2.c | 4 +- contrib/games/opentyrian/src/video.c | 5 --- 14 files changed, 58 insertions(+), 105 deletions(-) delete mode 100644 contrib/games/opentyrian/SDL/uSDL.c diff --git a/contrib/games/opentyrian/Makefile.linux b/contrib/games/opentyrian/Makefile.linux index a5440f685a..cd8bd56aa9 100644 --- a/contrib/games/opentyrian/Makefile.linux +++ b/contrib/games/opentyrian/Makefile.linux @@ -67,10 +67,9 @@ CFLAGS += -Wall \ -Wextra \ -Wno-missing-field-initializers CFLAGS += -O2 -CFLAGS += -DuSDL_Delay=SDL_Delay -LDFLAGS := -LDLIBS := +LDFLAGS := +LDLIBS := ifeq ($(WITH_NETWORK), true) SDL_CPPFLAGS := $(shell $(PKG_CONFIG) sdl SDL_net --cflags) diff --git a/contrib/games/opentyrian/SDL/uSDL.c b/contrib/games/opentyrian/SDL/uSDL.c deleted file mode 100644 index a12a22e225..0000000000 --- a/contrib/games/opentyrian/SDL/uSDL.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include - -#define asm_inline __asm__ __volatile__ - -#pragma pack(push,1) -typedef union{ - unsigned val; - struct{ - short h; - short w; - }; -}ksys_screen_t; -#pragma pack(pop) - - -static inline -void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) -{ - asm_inline( - "int $0x40" - ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) - ); -} - -static inline -ksys_screen_t _ksys_screen_size() -{ - ksys_screen_t size; - asm_inline( - "int $0x40" - :"=a"(size) - :"a"(14) - :"memory" - ); - return size; -} - -void uSDL_SetWinCenter(unsigned w, unsigned h){ - ksys_screen_t screen_size= _ksys_screen_size(); - int new_x = screen_size.w/2-w/2; - int new_y = screen_size.h/2-h/2; - _ksys_change_window(new_x, new_y, -1, -1); -} - - -void uSDL_Delay(unsigned ms){ - SDL_Delay(ms); -} diff --git a/contrib/games/opentyrian/Tupfile.lua b/contrib/games/opentyrian/Tupfile.lua index d63a216064..2a7a6cb9f2 100644 --- a/contrib/games/opentyrian/Tupfile.lua +++ b/contrib/games/opentyrian/Tupfile.lua @@ -8,7 +8,7 @@ tup.include(HELPERDIR .. "/use_gcc.lua") tup.include(HELPERDIR .. "/use_newlib.lua") --use_dynamic_stack() -- default 64K are not sufficient tup.include(HELPERDIR .. "/use_sdl_newlib.lua") -CFLAGS = CFLAGS .. [[ -UWIN32 -U_WIN32 -U__WIN32__ -D_KOLIBRI -DTYRIAN_DIR="\"."\" -DSDL_strlcpy=strncpy -D_GNU_SOURCE=1 -D_REENTRANT -DNDEBUG -Wno-missing-field-initializers ]] +CFLAGS = CFLAGS .. [[ -DTYRIAN_DIR="\"."\" -D_GNU_SOURCE=1 -D_REENTRANT -DNDEBUG -Wno-missing-field-initializers ]] LDFLAGS = LDFLAGS .. " --subsystem native" @@ -69,7 +69,6 @@ compile_gcc{ "./SDL/joystick_stub.c", "./SDL/SDL_wave.c", "./SDL/SDL_audiocvt.c", - "./SDL/uSDL.c", } link_gcc("opentyrian") diff --git a/contrib/games/opentyrian/src/destruct.c b/contrib/games/opentyrian/src/destruct.c index 1831cf1a2c..f921297b1b 100644 --- a/contrib/games/opentyrian/src/destruct.c +++ b/contrib/games/opentyrian/src/destruct.c @@ -631,7 +631,7 @@ static void JE_introScreen( void ) while (!newkey) { service_SDL_events(false); - uSDL_Delay(16); + SDL_Delay(16); } fade_black(15); @@ -684,7 +684,7 @@ static enum de_mode_t JE_modeSelect( void ) newkey = false; do { service_SDL_events(false); - uSDL_Delay(16); + SDL_Delay(16); } while(!newkey); /* See what was pressed */ @@ -1297,7 +1297,7 @@ static void JE_helpScreen( void ) do /* wait until user hits a key */ { service_SDL_events(true); - uSDL_Delay(16); + SDL_Delay(16); } while (!newkey); @@ -1320,7 +1320,7 @@ static void JE_pauseScreen( void ) do /* wait until user hits a key */ { service_SDL_events(true); - uSDL_Delay(16); + SDL_Delay(16); } while (!newkey); diff --git a/contrib/games/opentyrian/src/game_menu.c b/contrib/games/opentyrian/src/game_menu.c index 6cce2baad1..ed95d89289 100644 --- a/contrib/games/opentyrian/src/game_menu.c +++ b/contrib/games/opentyrian/src/game_menu.c @@ -1592,7 +1592,7 @@ void JE_itemScreen( void ) network_update(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } network_state_reset(); @@ -1606,7 +1606,7 @@ void JE_itemScreen( void ) JE_showVGA(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } #endif @@ -2507,7 +2507,7 @@ void JE_scaleInPicture( SDL_Surface *dst, const SDL_Surface *src ) JE_scaleBitmap(dst, src, 160 - i, 0, 160 + i - 1, 100 + roundf(i * 0.625f) - 1); JE_showVGA(); - uSDL_Delay(1); + SDL_Delay(1); } } diff --git a/contrib/games/opentyrian/src/keyboard.c b/contrib/games/opentyrian/src/keyboard.c index df3346d503..6b23a77db9 100644 --- a/contrib/games/opentyrian/src/keyboard.c +++ b/contrib/games/opentyrian/src/keyboard.c @@ -61,7 +61,7 @@ void wait_input( JE_boolean keyboard, JE_boolean mouse, JE_boolean joystick ) service_SDL_events(false); while (!((keyboard && keydown) || (mouse && mousedown) || (joystick && joydown))) { - uSDL_Delay(SDL_POLL_INTERVAL); + SDL_Delay(SDL_POLL_INTERVAL); push_joysticks_as_keyboard(); service_SDL_events(false); @@ -77,7 +77,7 @@ void wait_noinput( JE_boolean keyboard, JE_boolean mouse, JE_boolean joystick ) service_SDL_events(false); while ((keyboard && keydown) || (mouse && mousedown) || (joystick && joydown)) { - uSDL_Delay(SDL_POLL_INTERVAL); + SDL_Delay(SDL_POLL_INTERVAL); poll_joysticks(); service_SDL_events(false); diff --git a/contrib/games/opentyrian/src/mainint.c b/contrib/games/opentyrian/src/mainint.c index e58f9f37f3..ee561248d5 100644 --- a/contrib/games/opentyrian/src/mainint.c +++ b/contrib/games/opentyrian/src/mainint.c @@ -159,7 +159,7 @@ void JE_outCharGlow( JE_word x, JE_word y, const char *s ) if (levelWarningDisplay) JE_updateWarning(VGAScreen); - uSDL_Delay(16); + SDL_Delay(16); } while (!(delaycount() == 0 || ESCPressed)); @@ -803,7 +803,7 @@ void JE_nextEpisode( void ) { NETWORK_KEEP_ALIVE(); - uSDL_Delay(16); + SDL_Delay(16); } while (!JE_anyButton()); } @@ -1066,7 +1066,7 @@ void JE_doInGameSetup( void ) network_update(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } #endif @@ -1133,7 +1133,7 @@ void JE_doInGameSetup( void ) network_update(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } else { /* @@ -1150,7 +1150,7 @@ void JE_doInGameSetup( void ) service_SDL_events(false); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } VGAScreen = temp_surface; /* side-effect of game_screen */ @@ -2853,7 +2853,7 @@ void JE_pauseGame( void ) network_update(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } #endif @@ -2905,7 +2905,7 @@ void JE_pauseGame( void ) service_SDL_events(false); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } #endif diff --git a/contrib/games/opentyrian/src/network.c b/contrib/games/opentyrian/src/network.c index a2cb57bcaa..fefcb5784c 100644 --- a/contrib/games/opentyrian/src/network.c +++ b/contrib/games/opentyrian/src/network.c @@ -514,7 +514,7 @@ bool network_state_update( void ) } if (network_check() == 0) - uSDL_Delay(1); + SDL_Delay(1); } if (network_delay > 1) @@ -625,7 +625,7 @@ connect_reset: network_update(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } connect_again: @@ -671,7 +671,7 @@ connect_again: if (SDL_GetTicks() - last_out_tick > NET_RETRY) goto connect_reset; - uSDL_Delay(16); + SDL_Delay(16); } // send another packet since sometimes the network syncs without both connect packets exchanged @@ -724,14 +724,14 @@ void network_tyrian_halt( unsigned int err, bool attempt_sync ) service_SDL_events(false); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } if (err) { while (!JE_anyButton()) - uSDL_Delay(16); + SDL_Delay(16); } fade_black(10); diff --git a/contrib/games/opentyrian/src/nortsong.c b/contrib/games/opentyrian/src/nortsong.c index 133910ddd4..176386e666 100644 --- a/contrib/games/opentyrian/src/nortsong.c +++ b/contrib/games/opentyrian/src/nortsong.c @@ -76,14 +76,14 @@ void wait_delay( void ) { Sint32 delay = target - SDL_GetTicks(); if (delay > 0) - uSDL_Delay(delay); + SDL_Delay(delay); } void service_wait_delay( void ) { while (SDL_GetTicks() < target) { - uSDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target); + SDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target); service_SDL_events(false); } } @@ -93,7 +93,7 @@ void wait_delayorinput( JE_boolean keyboard, JE_boolean mouse, JE_boolean joysti service_SDL_events(true); while (SDL_GetTicks() < target && !((keyboard && keydown) || (mouse && mousedown) || (joystick && joydown))) { - uSDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target); + SDL_Delay(SDL_GetTicks() - target > SDL_POLL_INTERVAL ? SDL_POLL_INTERVAL : SDL_GetTicks() - target); push_joysticks_as_keyboard(); service_SDL_events(false); } diff --git a/contrib/games/opentyrian/src/opentyr.c b/contrib/games/opentyrian/src/opentyr.c index be0177f666..c3792e417c 100644 --- a/contrib/games/opentyrian/src/opentyr.c +++ b/contrib/games/opentyrian/src/opentyr.c @@ -55,6 +55,12 @@ #include #include +#ifdef _KOLIBRI +#include +#include +#endif + + const char *opentyrian_str = "OpenTyrian"; const char *opentyrian_version = OPENTYRIAN_VERSION; @@ -89,7 +95,7 @@ void opentyrian_menu( void ) false, false, }; - + assert(COUNTOF(menu_items) == MenuOptions_MAX); assert(COUNTOF(menu_items_disabled) == MenuOptions_MAX); @@ -151,7 +157,7 @@ void opentyrian_menu( void ) sel = MenuOptions_MAX - 1; } while (menu_items_disabled[sel]); - + JE_playSampleNum(S_CURSOR); break; case SDLK_DOWN: @@ -161,10 +167,10 @@ void opentyrian_menu( void ) sel = 0; } while (menu_items_disabled[sel]); - + JE_playSampleNum(S_CURSOR); break; - + case SDLK_LEFT: if (sel == MENU_SCALER) { @@ -175,7 +181,7 @@ void opentyrian_menu( void ) temp_scaler--; } while (!can_init_scaler(temp_scaler, fullscreen_enabled)); - + JE_playSampleNum(S_CURSOR); } break; @@ -189,11 +195,11 @@ void opentyrian_menu( void ) temp_scaler = 0; } while (!can_init_scaler(temp_scaler, fullscreen_enabled)); - + JE_playSampleNum(S_CURSOR); } break; - + case SDLK_RETURN: switch (sel) { @@ -206,7 +212,7 @@ void opentyrian_menu( void ) JE_showVGA(); fade_in = true; break; - + case MENU_FULLSCREEN: JE_playSampleNum(S_SELECT); @@ -218,7 +224,7 @@ void opentyrian_menu( void ) } set_palette(colors, 0, 255); // for switching between 8 bpp scalers break; - + case MENU_SCALER: JE_playSampleNum(S_SELECT); @@ -233,7 +239,7 @@ void opentyrian_menu( void ) set_palette(colors, 0, 255); // for switching between 8 bpp scalers } break; - + case MENU_JUKEBOX: JE_playSampleNum(S_SELECT); @@ -244,23 +250,23 @@ void opentyrian_menu( void ) JE_showVGA(); fade_in = true; break; - + case MENU_RETURN: quit = true; JE_playSampleNum(S_SPRING); break; - + case MenuOptions_MAX: assert(false); break; } break; - + case SDLK_ESCAPE: quit = true; JE_playSampleNum(S_SPRING); break; - + default: break; } @@ -280,6 +286,10 @@ int main( int argc, char *argv[] ) printf("This is free software, and you are welcome to redistribute it\n"); printf("under certain conditions. See the file GPL.txt for details.\n\n"); +#ifdef _KOLIBRI + _ksys_setcwd(dirname(argv[0])); +#endif + if (SDL_Init(0)) { printf("Failed to initialize SDL: %s\n", SDL_GetError()); diff --git a/contrib/games/opentyrian/src/opentyr.h b/contrib/games/opentyrian/src/opentyr.h index e1b52d32df..56ba40062b 100644 --- a/contrib/games/opentyrian/src/opentyr.h +++ b/contrib/games/opentyrian/src/opentyr.h @@ -60,10 +60,10 @@ extern const char *opentyrian_str; extern const char *opentyrian_version; void opentyrian_menu( void ); -#ifdef _KOLIBRI -extern void uSDL_SetWinCenter(uint w, uint h); -extern void uSDL_Delay(uint ms); -#endif +//#ifdef _KOLIBRI +//extern void uSDL_SetWinCenter(uint w, uint h); +//extern void SDL_Delay(uint ms); +//#endif #endif /* OPENTYR_H */ diff --git a/contrib/games/opentyrian/src/setup.c b/contrib/games/opentyrian/src/setup.c index 402dbe78e0..9413d9779b 100644 --- a/contrib/games/opentyrian/src/setup.c +++ b/contrib/games/opentyrian/src/setup.c @@ -84,7 +84,7 @@ void JE_textMenuWait( JE_word *waitTime, JE_boolean doGamma ) NETWORK_KEEP_ALIVE(); - uSDL_Delay(16); + SDL_Delay(16); if (*waitTime > 0) { diff --git a/contrib/games/opentyrian/src/tyrian2.c b/contrib/games/opentyrian/src/tyrian2.c index edcced21a1..83bf1e865c 100644 --- a/contrib/games/opentyrian/src/tyrian2.c +++ b/contrib/games/opentyrian/src/tyrian2.c @@ -3260,7 +3260,7 @@ bool JE_titleScreen( JE_boolean animate ) network_update(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } JE_initEpisode(SDLNet_Read16(&packet_in[0]->data[4])); @@ -3282,7 +3282,7 @@ bool JE_titleScreen( JE_boolean animate ) JE_showVGA(); network_check(); - uSDL_Delay(16); + SDL_Delay(16); } } else diff --git a/contrib/games/opentyrian/src/video.c b/contrib/games/opentyrian/src/video.c index dfe9b04284..c272699a16 100644 --- a/contrib/games/opentyrian/src/video.c +++ b/contrib/games/opentyrian/src/video.c @@ -115,11 +115,6 @@ bool init_scaler( unsigned int new_scaler, bool fullscreen ) w = surface->w; h = surface->h; -#ifdef _KOLIBRI - uSDL_SetWinCenter(w,h); -#endif - //bpp = surface->format->BitsPerPixel; - printf("initialized video: %dx%dx%d %s\n", w, h, bpp, fullscreen ? "fullscreen" : "windowed"); scaler = new_scaler;