From 83d5b68cdf9409cc8d6f74ca7bfb8f5f20c0b326 Mon Sep 17 00:00:00 2001 From: turbocat Date: Thu, 29 Jul 2021 20:23:49 +0000 Subject: [PATCH] Wolf3D: - Fixed speed. - Fixed lags. - Returned --res parameter git-svn-id: svn://kolibrios.org@9097 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/games/wolf3d/Makefile | 1 + contrib/games/wolf3d/SDL/uSDL.c | 29 ++++++++++++++++++++++++++ contrib/games/wolf3d/SDL_mixer/mixer.c | 24 ++++++++++++++------- contrib/games/wolf3d/SDL_mixer/music.c | 11 ++++++++-- contrib/games/wolf3d/Tupfile.lua | 3 ++- contrib/games/wolf3d/id_in.cpp | 2 +- contrib/games/wolf3d/id_sd.cpp | 4 ++-- contrib/games/wolf3d/id_sd.h | 10 +++++++-- contrib/games/wolf3d/id_us_1.cpp | 4 ++-- contrib/games/wolf3d/id_vl.h | 2 +- contrib/games/wolf3d/kolibri.cpp | 1 + contrib/games/wolf3d/wl_def.h | 15 ++++++++++++- contrib/games/wolf3d/wl_draw.cpp | 5 +++-- contrib/games/wolf3d/wl_inter.cpp | 2 +- contrib/games/wolf3d/wl_main.cpp | 12 ++++++++--- contrib/games/wolf3d/wl_menu.cpp | 20 +++++++++--------- contrib/games/wolf3d/wl_play.cpp | 6 +++--- contrib/games/wolf3d/wl_text.cpp | 2 +- 18 files changed, 113 insertions(+), 40 deletions(-) create mode 100644 contrib/games/wolf3d/SDL/uSDL.c diff --git a/contrib/games/wolf3d/Makefile b/contrib/games/wolf3d/Makefile index 612f29af9d..779458fa78 100755 --- a/contrib/games/wolf3d/Makefile +++ b/contrib/games/wolf3d/Makefile @@ -43,6 +43,7 @@ OBJECTS += mame/fmopl.o SDL_OBJ += SDL/SDL_wave.o SDL_OBJ += SDL/SDL_audiocvt.o SDL_OBJ += SDL/SDL_mixer.o +SDL_OBJ += SDL/uSDL.o SDL_MIX_OBJ += SDL_mixer/mixer.o SDL_MIX_OBJ += SDL_mixer/music.o diff --git a/contrib/games/wolf3d/SDL/uSDL.c b/contrib/games/wolf3d/SDL/uSDL.c new file mode 100644 index 0000000000..67180dc424 --- /dev/null +++ b/contrib/games/wolf3d/SDL/uSDL.c @@ -0,0 +1,29 @@ +static unsigned __starttime; + +void uSDL_StartTicks(void){ + __asm__ __volatile__ ( + "int $0x40" + :"=a"(__starttime) + :"a"(26),"b"(9) + :"memory" + ); +} + +unsigned uSDL_GetTicks(void){ + unsigned __curtime; + __asm__ __volatile__( + "int $0x40" + :"=a"(__curtime) + :"a"(26),"b"(9) + :"memory" + ); + return (__curtime-__starttime); +} + +void uSDL_Delay(unsigned time){ + __asm__ __volatile__( + "int $0x40" + ::"a"(5), "b"(time/3) + :"memory" + ); +} diff --git a/contrib/games/wolf3d/SDL_mixer/mixer.c b/contrib/games/wolf3d/SDL_mixer/mixer.c index 3a35023c32..cc03c37c68 100644 --- a/contrib/games/wolf3d/SDL_mixer/mixer.c +++ b/contrib/games/wolf3d/SDL_mixer/mixer.c @@ -42,6 +42,14 @@ #define __MIX_INTERNAL_EFFECT__ #include "effects_internal.h" +#ifdef _KOLIBRI + void uSDL_Delay(unsigned int time); + unsigned uSDL_GetTicks(); +#else + #define uSDL_Delay SDL_Delay + #define uSDL_GetTicks SDL_GetTicks +#endif + /* Magic numbers for various audio file formats */ #define RIFF 0x46464952 /* "RIFF" */ #define WAVE 0x45564157 /* "WAVE" */ @@ -300,7 +308,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len) } /* Mix any playing channels... */ - sdl_ticks = SDL_GetTicks(); + sdl_ticks = uSDL_GetTicks(); for ( i=0; i 0 && mix_channel[i].expire < sdl_ticks ) { @@ -857,7 +865,7 @@ int Mix_PlayChannelTimed(int which, Mix_Chunk *chunk, int loops, int ticks) /* Queue up the audio data for this channel */ if ( which >= 0 && which < num_channels ) { - Uint32 sdl_ticks = SDL_GetTicks(); + Uint32 sdl_ticks = uSDL_GetTicks(); if (Mix_Playing(which)) _Mix_channel_done_playing(which); mix_channel[which].samples = chunk->abuf; @@ -888,7 +896,7 @@ int Mix_ExpireChannel(int which, int ticks) } } else if ( which < num_channels ) { SDL_LockAudio(); - mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0; + mix_channel[which].expire = (ticks>0) ? ( uSDL_GetTicks() + ticks) : 0; SDL_UnlockAudio(); ++ status; } @@ -927,7 +935,7 @@ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int t /* Queue up the audio data for this channel */ if ( which >= 0 && which < num_channels ) { - Uint32 sdl_ticks = SDL_GetTicks(); + Uint32 sdl_ticks = uSDL_GetTicks(); if (Mix_Playing(which)) _Mix_channel_done_playing(which); mix_channel[which].samples = chunk->abuf; @@ -1046,7 +1054,7 @@ int Mix_FadeOutChannel(int which, int ms) mix_channel[which].fade_volume = mix_channel[which].volume; mix_channel[which].fading = MIX_FADING_OUT; mix_channel[which].fade_length = ms; - mix_channel[which].ticks_fade = SDL_GetTicks(); + mix_channel[which].ticks_fade = uSDL_GetTicks(); /* only change fade_volume_reset if we're not fading. */ if (mix_channel[which].fading == MIX_NO_FADING) { @@ -1151,7 +1159,7 @@ void Mix_CloseAudio(void) /* Pause a particular channel (or all) */ void Mix_Pause(int which) { - Uint32 sdl_ticks = SDL_GetTicks(); + Uint32 sdl_ticks = uSDL_GetTicks(); if ( which == -1 ) { int i; @@ -1170,7 +1178,7 @@ void Mix_Pause(int which) /* Resume a paused channel */ void Mix_Resume(int which) { - Uint32 sdl_ticks = SDL_GetTicks(); + Uint32 sdl_ticks = uSDL_GetTicks(); SDL_LockAudio(); if ( which == -1 ) { @@ -1260,7 +1268,7 @@ int Mix_GroupCount(int tag) int Mix_GroupOldest(int tag) { int chan = -1; - Uint32 mintime = SDL_GetTicks(); + Uint32 mintime = uSDL_GetTicks(); int i; for( i=0; i < num_channels; i ++ ) { if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0 diff --git a/contrib/games/wolf3d/SDL_mixer/music.c b/contrib/games/wolf3d/SDL_mixer/music.c index b8622ea532..bbc7700d16 100644 --- a/contrib/games/wolf3d/SDL_mixer/music.c +++ b/contrib/games/wolf3d/SDL_mixer/music.c @@ -71,6 +71,13 @@ static SDL_AudioSpec used_mixer; #endif +#ifdef _KOLIBRI + extern void uSDL_Delay(unsigned int time); + extern unsigned uSDL_GetTicks(); +#else + #define uSDL_Delay SDL_Delay + #define uSDL_GetTicks SDL_GetTicks +#endif int volatile music_active = 1; static int volatile music_stopped = 0; @@ -761,7 +768,7 @@ void Mix_FreeMusic(Mix_Music *music) /* Wait for any fade out to finish */ while ( music->fading == MIX_FADING_OUT ) { SDL_UnlockAudio(); - SDL_Delay(100); + uSDL_Delay(100); SDL_LockAudio(); } if ( music == music_playing ) { @@ -1013,7 +1020,7 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) /* If the current music is fading out, wait for the fade to complete */ while ( music_playing && (music_playing->fading == MIX_FADING_OUT) ) { SDL_UnlockAudio(); - SDL_Delay(100); + uSDL_Delay(100); SDL_LockAudio(); } music_active = 1; diff --git a/contrib/games/wolf3d/Tupfile.lua b/contrib/games/wolf3d/Tupfile.lua index c56d55b555..cee849460c 100644 --- a/contrib/games/wolf3d/Tupfile.lua +++ b/contrib/games/wolf3d/Tupfile.lua @@ -22,7 +22,8 @@ compile_gcc{ -- SDL and SDL_mixer -- compile_gcc{ - "SDL/SDL_wave.c", "SDL/SDL_audiocvt.c", "SDL/SDL_mixer.c", "SDL_mixer/mixer.c", "SDL_mixer/music.c", "SDL_mixer/load_aiff.c", "SDL_mixer/load_voc.c", + "SDL/SDL_wave.c", "SDL/SDL_audiocvt.c", "SDL/SDL_mixer.c", "SDL_mixer/mixer.c", "SDL_mixer/music.c", + "SDL_mixer/load_aiff.c", "SDL_mixer/load_voc.c", "SDL/uSDL.c", "SDL_mixer/effects_internal.c", "SDL_mixer/effect_position.c", } diff --git a/contrib/games/wolf3d/id_in.cpp b/contrib/games/wolf3d/id_in.cpp index 95f6d6e7fd..d2fb29df45 100755 --- a/contrib/games/wolf3d/id_in.cpp +++ b/contrib/games/wolf3d/id_in.cpp @@ -650,7 +650,7 @@ boolean IN_UserInput(longword delay) IN_ProcessEvents(); if (IN_CheckAck()) return true; - SDL_Delay(5); + uSDL_Delay(5); } while (GetTimeCount() - lasttime < delay); return(false); } diff --git a/contrib/games/wolf3d/id_sd.cpp b/contrib/games/wolf3d/id_sd.cpp index c85c8ae757..aaee88aeae 100755 --- a/contrib/games/wolf3d/id_sd.cpp +++ b/contrib/games/wolf3d/id_sd.cpp @@ -935,7 +935,7 @@ SD_SetMusicMode(SMMode mode) SD_FadeOutMusic(); while (SD_MusicPlaying()) - SDL_Delay(5); + uSDL_Delay(5); switch (mode) { @@ -1284,7 +1284,7 @@ void SD_WaitSoundDone(void) { while (SD_SoundPlaying()) - SDL_Delay(5); + uSDL_Delay(5); } /////////////////////////////////////////////////////////////////////////// diff --git a/contrib/games/wolf3d/id_sd.h b/contrib/games/wolf3d/id_sd.h index 540dc74ff5..d503c6c26f 100755 --- a/contrib/games/wolf3d/id_sd.h +++ b/contrib/games/wolf3d/id_sd.h @@ -119,11 +119,17 @@ extern SMMode MusicMode; extern int DigiMap[]; extern int DigiChannel[]; -#define GetTimeCount() ((SDL_GetTicks()*7)/100) +#ifdef _KOLIBRI + extern void uSDL_Delay(unsigned time); +#else + #define uSDL_Delay SDL_Delay +#endif + +#define GetTimeCount() (( uSDL_GetTicks()*7)/100) inline void Delay(int wolfticks) { - if(wolfticks>0) SDL_Delay(wolfticks * 100 / 7); + if(wolfticks>0) uSDL_Delay(wolfticks * 100/ 7); } // Function prototypes diff --git a/contrib/games/wolf3d/id_us_1.cpp b/contrib/games/wolf3d/id_us_1.cpp index 76b53f30f0..51ccbf84fa 100755 --- a/contrib/games/wolf3d/id_us_1.cpp +++ b/contrib/games/wolf3d/id_us_1.cpp @@ -741,7 +741,7 @@ US_LineInput(int x,int y,char *buf,const char *def,boolean escok, cursorvis ^= true; } - else SDL_Delay(5); + else uSDL_Delay(5); if (cursorvis) USL_XORICursor(x,y,s,cursor); @@ -772,7 +772,7 @@ US_LineInput(int x,int y,char *buf,const char *def,boolean escok, void US_InitRndT(int randomize) { if(randomize) - rndindex = (SDL_GetTicks() >> 4) & 0xff; + rndindex = ( uSDL_GetTicks() >> 4) & 0xff; else rndindex = 0; } diff --git a/contrib/games/wolf3d/id_vl.h b/contrib/games/wolf3d/id_vl.h index 55b7b84f97..19cdb778e1 100755 --- a/contrib/games/wolf3d/id_vl.h +++ b/contrib/games/wolf3d/id_vl.h @@ -28,7 +28,7 @@ extern SDL_Color gamepal[256]; // VGA hardware routines // -#define VL_WaitVBL(a) SDL_Delay((a)*8) +#define VL_WaitVBL(a) uSDL_Delay((a)*8) void VL_SetVGAPlaneMode (void); void VL_SetTextMode (void); diff --git a/contrib/games/wolf3d/kolibri.cpp b/contrib/games/wolf3d/kolibri.cpp index efcc328406..499367e127 100644 --- a/contrib/games/wolf3d/kolibri.cpp +++ b/contrib/games/wolf3d/kolibri.cpp @@ -208,3 +208,4 @@ void setcwd(char* path){ ::"a"(30), "b"(1), "c"(path) ); } + diff --git a/contrib/games/wolf3d/wl_def.h b/contrib/games/wolf3d/wl_def.h index ece6a62b05..421dcfacba 100755 --- a/contrib/games/wolf3d/wl_def.h +++ b/contrib/games/wolf3d/wl_def.h @@ -24,6 +24,17 @@ # define O_BINARY 0 #endif +#ifdef _KOLIBRI +extern "C"{ + extern void uSDL_Delay(unsigned int time); + extern unsigned uSDL_GetTicks(); +} +#else + #define uSDL_Delay SDL_Delay + #define uSDL_GetTicks SDL_GetTicks +#endif + + #pragma pack(1) #if defined(_arch_dreamcast) @@ -1391,7 +1402,7 @@ static inline fixed FixedMul(fixed a, fixed b) #endif #define DEMOCOND_SDL (!DEMOCOND_ORIG) -#define GetTicks() ((SDL_GetTicks()*7)/100) +#define GetTicks() (( uSDL_GetTicks()*7)/100) #define ISPOINTER(x) ((((uintptr_t)(x)) & ~0xffff) != 0) @@ -1483,3 +1494,5 @@ static inline longword READLONGWORD(byte *&ptr) #endif #endif + + diff --git a/contrib/games/wolf3d/wl_draw.cpp b/contrib/games/wolf3d/wl_draw.cpp index 93246389c0..e9f5d0ac87 100755 --- a/contrib/games/wolf3d/wl_draw.cpp +++ b/contrib/games/wolf3d/wl_draw.cpp @@ -1,6 +1,7 @@ // WL_DRAW.C #include "wl_def.h" +#include #pragma hdrstop #include "wl_cloudsky.h" @@ -1073,12 +1074,12 @@ void CalcTics (void) if (lasttimecount > (int32_t) GetTimeCount()) lasttimecount = GetTimeCount(); // if the game was paused a LONG time - uint32_t curtime = SDL_GetTicks(); + uint32_t curtime = uSDL_GetTicks(); tics = (curtime * 7) / 100 - lasttimecount; if(!tics) { // wait until end of current tic - SDL_Delay(((lasttimecount + 1) * 100) / 7 - curtime); + uSDL_Delay(((lasttimecount + 1) * 100) / 7 - curtime); tics = 1; } diff --git a/contrib/games/wolf3d/wl_inter.cpp b/contrib/games/wolf3d/wl_inter.cpp index 5c66555865..bd78d7b288 100755 --- a/contrib/games/wolf3d/wl_inter.cpp +++ b/contrib/games/wolf3d/wl_inter.cpp @@ -403,7 +403,7 @@ BJ_Breathe (void) static int which = 0, max = 10; int pics[2] = { L_GUYPIC, L_GUY2PIC }; - SDL_Delay(5); + uSDL_Delay(5); if ((int32_t) GetTimeCount () - lastBreathTime > max) { diff --git a/contrib/games/wolf3d/wl_main.cpp b/contrib/games/wolf3d/wl_main.cpp index 91f4c2fdc7..2e828ee3bd 100755 --- a/contrib/games/wolf3d/wl_main.cpp +++ b/contrib/games/wolf3d/wl_main.cpp @@ -27,6 +27,9 @@ extern byte signon[]; extern void kolibri_set_win_center(); extern char* dirname(char* path); extern void setcwd(char* path); +extern "C"{ + extern void uSDL_StartTicks(void); +} /* ============================================================================= @@ -1126,7 +1129,7 @@ void DoJukebox(void) #ifndef SPEAR #ifndef UPLOAD - start = ((SDL_GetTicks()/10)%3)*6; + start = (( uSDL_GetTicks()/10)%3)*6; #else start = 0; #endif @@ -1217,6 +1220,9 @@ static void InitGame() printf("Unable to init SDL: %s\n", SDL_GetError()); exit(1); } +#ifdef _KOLIBRI + uSDL_StartTicks(); +#endif SDL_AudioInit(NULL); atexit(SDL_Quit); @@ -1906,8 +1912,8 @@ void CheckParameters(int argc, char *argv[]) " --nowait Skips intro screens\n" #ifndef _KOLIBRI " --windowed[-mouse] Starts the game in a window [and grabs mouse]\n" - " --res Sets the screen resolution\n" #endif + " --res Sets the screen resolution\n" " (must be multiple of 320x200 or 320x240)\n" " --resf Sets any screen resolution >= 320x200\n" " (which may result in graphic errors)\n" @@ -1916,7 +1922,7 @@ void CheckParameters(int argc, char *argv[]) " allowed: 8, 16, 24, 32, default: \"best\" depth)\n" " --nodblbuf Don't use SDL's double buffering\n" " --extravbls Sets a delay after each frame, which may help to\n" - " reduce flickering (unit is currently 8 ms, default: 0)\n" + " reduce flickering (unit is currently 8 ms, default: 2)\n" #ifndef _KOLIBRI " --joystick Use the index-th joystick if available\n" " (-1 to disable joystick, default: 0)\n" diff --git a/contrib/games/wolf3d/wl_menu.cpp b/contrib/games/wolf3d/wl_menu.cpp index e2a3b1bfef..90f8685c14 100755 --- a/contrib/games/wolf3d/wl_menu.cpp +++ b/contrib/games/wolf3d/wl_menu.cpp @@ -1956,7 +1956,7 @@ MouseSensitivity (int) DrawMouseSens (); do { - SDL_Delay(5); + uSDL_Delay(5); ReadAnyControl (&ci); switch (ci.dir) { @@ -2228,7 +2228,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin redraw = 0; } - SDL_Delay(5); + uSDL_Delay(5); ReadAnyControl (&ci); if (type == MOUSE || type == JOYSTICK) @@ -2274,7 +2274,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin lastFlashTime = GetTimeCount(); VW_UpdateScreen (); } - else SDL_Delay(5); + else uSDL_Delay(5); // // WHICH TYPE OF INPUT DO WE PROCESS? @@ -2397,7 +2397,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin while (!cust->allowed[which]); redraw = 1; SD_PlaySound (MOVEGUN1SND); - while (ReadAnyControl (&ci), ci.dir != dir_None) SDL_Delay(5); + while (ReadAnyControl (&ci), ci.dir != dir_None) uSDL_Delay(5); IN_ClearKeysDown (); break; @@ -2411,7 +2411,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin while (!cust->allowed[which]); redraw = 1; SD_PlaySound (MOVEGUN1SND); - while (ReadAnyControl (&ci), ci.dir != dir_None) SDL_Delay(5); + while (ReadAnyControl (&ci), ci.dir != dir_None) uSDL_Delay(5); IN_ClearKeysDown (); break; case dir_North: @@ -2837,7 +2837,7 @@ CP_ChangeView (int) do { CheckPause (); - SDL_Delay(5); + uSDL_Delay(5); ReadAnyControl (&ci); switch (ci.dir) { @@ -3284,7 +3284,7 @@ HandleMenu (CP_iteminfo * item_i, CP_itemtype * items, void (*routine) (int w)) routine (which); VW_UpdateScreen (); } - else SDL_Delay(5); + else uSDL_Delay(5); CheckPause (); @@ -3484,7 +3484,7 @@ DrawHalfStep (int x, int y) VWB_DrawPic (x, y, C_CURSOR1PIC); VW_UpdateScreen (); SD_PlaySound (MOVEGUN1SND); - SDL_Delay(1); //Fixed too long delay in the menu + uSDL_Delay(1); //Fixed too long delay in the menu } @@ -3526,7 +3526,7 @@ TicDelay (int count) int32_t startTime = GetTimeCount (); do { - SDL_Delay(5); + uSDL_Delay(5); ReadAnyControl (&ci); } while ((int32_t) GetTimeCount () - startTime < count && ci.dir != dir_None); @@ -3732,7 +3732,7 @@ Confirm (const char *string) tick ^= 1; lastBlinkTime = GetTimeCount(); } - else SDL_Delay(5); + else uSDL_Delay(5); #ifdef SPANISH } diff --git a/contrib/games/wolf3d/wl_play.cpp b/contrib/games/wolf3d/wl_play.cpp index 8cddd9cd87..0b8c63b506 100755 --- a/contrib/games/wolf3d/wl_play.cpp +++ b/contrib/games/wolf3d/wl_play.cpp @@ -211,7 +211,7 @@ int songs[] = { XFUNKIE_MUS, XDEATH_MUS, XGETYOU_MUS, // DON'T KNOW - ULTIMATE_MUS, // Trans Gr”sse + ULTIMATE_MUS, // Trans Gr�sse DUNGEON_MUS, GOINGAFT_MUS, @@ -406,11 +406,11 @@ void PollControls (void) if (demoplayback || demorecord) // demo recording and playback needs to be constant { // wait up to DEMOTICS Wolf tics - uint32_t curtime = SDL_GetTicks(); + uint32_t curtime = uSDL_GetTicks(); lasttimecount += DEMOTICS; int32_t timediff = (lasttimecount * 100) / 7 - curtime; if(timediff > 0) - SDL_Delay(timediff); + uSDL_Delay(timediff); if(timediff < -2 * DEMOTICS) // more than 2-times DEMOTICS behind? lasttimecount = (curtime * 7) / 100; // yes, set to current timecount diff --git a/contrib/games/wolf3d/wl_text.cpp b/contrib/games/wolf3d/wl_text.cpp index 03a437df59..2b5b96ecd3 100755 --- a/contrib/games/wolf3d/wl_text.cpp +++ b/contrib/games/wolf3d/wl_text.cpp @@ -669,7 +669,7 @@ void ShowArticle (char *article) firstpage = false; } } - SDL_Delay(5); + uSDL_Delay(5); LastScan = 0; ReadAnyControl(&ci);