- Fixed speed.
- Fixed lags.
- Returned --res parameter

git-svn-id: svn://kolibrios.org@9097 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2021-07-29 20:23:49 +00:00
parent 7f933eb487
commit 83d5b68cdf
18 changed files with 113 additions and 40 deletions

View File

@ -43,6 +43,7 @@ OBJECTS += mame/fmopl.o
SDL_OBJ += SDL/SDL_wave.o SDL_OBJ += SDL/SDL_wave.o
SDL_OBJ += SDL/SDL_audiocvt.o SDL_OBJ += SDL/SDL_audiocvt.o
SDL_OBJ += SDL/SDL_mixer.o SDL_OBJ += SDL/SDL_mixer.o
SDL_OBJ += SDL/uSDL.o
SDL_MIX_OBJ += SDL_mixer/mixer.o SDL_MIX_OBJ += SDL_mixer/mixer.o
SDL_MIX_OBJ += SDL_mixer/music.o SDL_MIX_OBJ += SDL_mixer/music.o

View File

@ -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"
);
}

View File

@ -42,6 +42,14 @@
#define __MIX_INTERNAL_EFFECT__ #define __MIX_INTERNAL_EFFECT__
#include "effects_internal.h" #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 */ /* Magic numbers for various audio file formats */
#define RIFF 0x46464952 /* "RIFF" */ #define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */ #define WAVE 0x45564157 /* "WAVE" */
@ -300,7 +308,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len)
} }
/* Mix any playing channels... */ /* Mix any playing channels... */
sdl_ticks = SDL_GetTicks(); sdl_ticks = uSDL_GetTicks();
for ( i=0; i<num_channels; ++i ) { for ( i=0; i<num_channels; ++i ) {
if( ! mix_channel[i].paused ) { if( ! mix_channel[i].paused ) {
if ( mix_channel[i].expire > 0 && mix_channel[i].expire < sdl_ticks ) { if ( mix_channel[i].expire > 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 */ /* Queue up the audio data for this channel */
if ( which >= 0 && which < num_channels ) { if ( which >= 0 && which < num_channels ) {
Uint32 sdl_ticks = SDL_GetTicks(); Uint32 sdl_ticks = uSDL_GetTicks();
if (Mix_Playing(which)) if (Mix_Playing(which))
_Mix_channel_done_playing(which); _Mix_channel_done_playing(which);
mix_channel[which].samples = chunk->abuf; mix_channel[which].samples = chunk->abuf;
@ -888,7 +896,7 @@ int Mix_ExpireChannel(int which, int ticks)
} }
} else if ( which < num_channels ) { } else if ( which < num_channels ) {
SDL_LockAudio(); SDL_LockAudio();
mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0; mix_channel[which].expire = (ticks>0) ? ( uSDL_GetTicks() + ticks) : 0;
SDL_UnlockAudio(); SDL_UnlockAudio();
++ status; ++ 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 */ /* Queue up the audio data for this channel */
if ( which >= 0 && which < num_channels ) { if ( which >= 0 && which < num_channels ) {
Uint32 sdl_ticks = SDL_GetTicks(); Uint32 sdl_ticks = uSDL_GetTicks();
if (Mix_Playing(which)) if (Mix_Playing(which))
_Mix_channel_done_playing(which); _Mix_channel_done_playing(which);
mix_channel[which].samples = chunk->abuf; 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].fade_volume = mix_channel[which].volume;
mix_channel[which].fading = MIX_FADING_OUT; mix_channel[which].fading = MIX_FADING_OUT;
mix_channel[which].fade_length = ms; 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. */ /* only change fade_volume_reset if we're not fading. */
if (mix_channel[which].fading == MIX_NO_FADING) { if (mix_channel[which].fading == MIX_NO_FADING) {
@ -1151,7 +1159,7 @@ void Mix_CloseAudio(void)
/* Pause a particular channel (or all) */ /* Pause a particular channel (or all) */
void Mix_Pause(int which) void Mix_Pause(int which)
{ {
Uint32 sdl_ticks = SDL_GetTicks(); Uint32 sdl_ticks = uSDL_GetTicks();
if ( which == -1 ) { if ( which == -1 ) {
int i; int i;
@ -1170,7 +1178,7 @@ void Mix_Pause(int which)
/* Resume a paused channel */ /* Resume a paused channel */
void Mix_Resume(int which) void Mix_Resume(int which)
{ {
Uint32 sdl_ticks = SDL_GetTicks(); Uint32 sdl_ticks = uSDL_GetTicks();
SDL_LockAudio(); SDL_LockAudio();
if ( which == -1 ) { if ( which == -1 ) {
@ -1260,7 +1268,7 @@ int Mix_GroupCount(int tag)
int Mix_GroupOldest(int tag) int Mix_GroupOldest(int tag)
{ {
int chan = -1; int chan = -1;
Uint32 mintime = SDL_GetTicks(); Uint32 mintime = uSDL_GetTicks();
int i; int i;
for( i=0; i < num_channels; i ++ ) { for( i=0; i < num_channels; i ++ ) {
if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0 if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0

View File

@ -71,6 +71,13 @@
static SDL_AudioSpec used_mixer; static SDL_AudioSpec used_mixer;
#endif #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; int volatile music_active = 1;
static int volatile music_stopped = 0; static int volatile music_stopped = 0;
@ -761,7 +768,7 @@ void Mix_FreeMusic(Mix_Music *music)
/* Wait for any fade out to finish */ /* Wait for any fade out to finish */
while ( music->fading == MIX_FADING_OUT ) { while ( music->fading == MIX_FADING_OUT ) {
SDL_UnlockAudio(); SDL_UnlockAudio();
SDL_Delay(100); uSDL_Delay(100);
SDL_LockAudio(); SDL_LockAudio();
} }
if ( music == music_playing ) { 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 */ /* If the current music is fading out, wait for the fade to complete */
while ( music_playing && (music_playing->fading == MIX_FADING_OUT) ) { while ( music_playing && (music_playing->fading == MIX_FADING_OUT) ) {
SDL_UnlockAudio(); SDL_UnlockAudio();
SDL_Delay(100); uSDL_Delay(100);
SDL_LockAudio(); SDL_LockAudio();
} }
music_active = 1; music_active = 1;

View File

@ -22,7 +22,8 @@ compile_gcc{
-- SDL and SDL_mixer -- -- SDL and SDL_mixer --
compile_gcc{ 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", "SDL_mixer/effects_internal.c", "SDL_mixer/effect_position.c",
} }

View File

@ -650,7 +650,7 @@ boolean IN_UserInput(longword delay)
IN_ProcessEvents(); IN_ProcessEvents();
if (IN_CheckAck()) if (IN_CheckAck())
return true; return true;
SDL_Delay(5); uSDL_Delay(5);
} while (GetTimeCount() - lasttime < delay); } while (GetTimeCount() - lasttime < delay);
return(false); return(false);
} }

View File

@ -935,7 +935,7 @@ SD_SetMusicMode(SMMode mode)
SD_FadeOutMusic(); SD_FadeOutMusic();
while (SD_MusicPlaying()) while (SD_MusicPlaying())
SDL_Delay(5); uSDL_Delay(5);
switch (mode) switch (mode)
{ {
@ -1284,7 +1284,7 @@ void
SD_WaitSoundDone(void) SD_WaitSoundDone(void)
{ {
while (SD_SoundPlaying()) while (SD_SoundPlaying())
SDL_Delay(5); uSDL_Delay(5);
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -119,11 +119,17 @@ extern SMMode MusicMode;
extern int DigiMap[]; extern int DigiMap[];
extern int DigiChannel[]; 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) inline void Delay(int wolfticks)
{ {
if(wolfticks>0) SDL_Delay(wolfticks * 100 / 7); if(wolfticks>0) uSDL_Delay(wolfticks * 100/ 7);
} }
// Function prototypes // Function prototypes

View File

@ -741,7 +741,7 @@ US_LineInput(int x,int y,char *buf,const char *def,boolean escok,
cursorvis ^= true; cursorvis ^= true;
} }
else SDL_Delay(5); else uSDL_Delay(5);
if (cursorvis) if (cursorvis)
USL_XORICursor(x,y,s,cursor); 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) void US_InitRndT(int randomize)
{ {
if(randomize) if(randomize)
rndindex = (SDL_GetTicks() >> 4) & 0xff; rndindex = ( uSDL_GetTicks() >> 4) & 0xff;
else else
rndindex = 0; rndindex = 0;
} }

View File

@ -28,7 +28,7 @@ extern SDL_Color gamepal[256];
// VGA hardware routines // 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_SetVGAPlaneMode (void);
void VL_SetTextMode (void); void VL_SetTextMode (void);

View File

@ -208,3 +208,4 @@ void setcwd(char* path){
::"a"(30), "b"(1), "c"(path) ::"a"(30), "b"(1), "c"(path)
); );
} }

View File

@ -24,6 +24,17 @@
# define O_BINARY 0 # define O_BINARY 0
#endif #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) #pragma pack(1)
#if defined(_arch_dreamcast) #if defined(_arch_dreamcast)
@ -1391,7 +1402,7 @@ static inline fixed FixedMul(fixed a, fixed b)
#endif #endif
#define DEMOCOND_SDL (!DEMOCOND_ORIG) #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) #define ISPOINTER(x) ((((uintptr_t)(x)) & ~0xffff) != 0)
@ -1483,3 +1494,5 @@ static inline longword READLONGWORD(byte *&ptr)
#endif #endif
#endif #endif

View File

@ -1,6 +1,7 @@
// WL_DRAW.C // WL_DRAW.C
#include "wl_def.h" #include "wl_def.h"
#include <cstdio>
#pragma hdrstop #pragma hdrstop
#include "wl_cloudsky.h" #include "wl_cloudsky.h"
@ -1073,12 +1074,12 @@ void CalcTics (void)
if (lasttimecount > (int32_t) GetTimeCount()) if (lasttimecount > (int32_t) GetTimeCount())
lasttimecount = GetTimeCount(); // if the game was paused a LONG time 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; tics = (curtime * 7) / 100 - lasttimecount;
if(!tics) if(!tics)
{ {
// wait until end of current tic // wait until end of current tic
SDL_Delay(((lasttimecount + 1) * 100) / 7 - curtime); uSDL_Delay(((lasttimecount + 1) * 100) / 7 - curtime);
tics = 1; tics = 1;
} }

View File

@ -403,7 +403,7 @@ BJ_Breathe (void)
static int which = 0, max = 10; static int which = 0, max = 10;
int pics[2] = { L_GUYPIC, L_GUY2PIC }; int pics[2] = { L_GUYPIC, L_GUY2PIC };
SDL_Delay(5); uSDL_Delay(5);
if ((int32_t) GetTimeCount () - lastBreathTime > max) if ((int32_t) GetTimeCount () - lastBreathTime > max)
{ {

View File

@ -27,6 +27,9 @@ extern byte signon[];
extern void kolibri_set_win_center(); extern void kolibri_set_win_center();
extern char* dirname(char* path); extern char* dirname(char* path);
extern void setcwd(char* path); extern void setcwd(char* path);
extern "C"{
extern void uSDL_StartTicks(void);
}
/* /*
============================================================================= =============================================================================
@ -1126,7 +1129,7 @@ void DoJukebox(void)
#ifndef SPEAR #ifndef SPEAR
#ifndef UPLOAD #ifndef UPLOAD
start = ((SDL_GetTicks()/10)%3)*6; start = (( uSDL_GetTicks()/10)%3)*6;
#else #else
start = 0; start = 0;
#endif #endif
@ -1217,6 +1220,9 @@ static void InitGame()
printf("Unable to init SDL: %s\n", SDL_GetError()); printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1); exit(1);
} }
#ifdef _KOLIBRI
uSDL_StartTicks();
#endif
SDL_AudioInit(NULL); SDL_AudioInit(NULL);
atexit(SDL_Quit); atexit(SDL_Quit);
@ -1906,8 +1912,8 @@ void CheckParameters(int argc, char *argv[])
" --nowait Skips intro screens\n" " --nowait Skips intro screens\n"
#ifndef _KOLIBRI #ifndef _KOLIBRI
" --windowed[-mouse] Starts the game in a window [and grabs mouse]\n" " --windowed[-mouse] Starts the game in a window [and grabs mouse]\n"
" --res <width> <height> Sets the screen resolution\n"
#endif #endif
" --res <width> <height> Sets the screen resolution\n"
" (must be multiple of 320x200 or 320x240)\n" " (must be multiple of 320x200 or 320x240)\n"
" --resf <w> <h> Sets any screen resolution >= 320x200\n" " --resf <w> <h> Sets any screen resolution >= 320x200\n"
" (which may result in graphic errors)\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" " allowed: 8, 16, 24, 32, default: \"best\" depth)\n"
" --nodblbuf Don't use SDL's double buffering\n" " --nodblbuf Don't use SDL's double buffering\n"
" --extravbls <vbls> Sets a delay after each frame, which may help to\n" " --extravbls <vbls> 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 #ifndef _KOLIBRI
" --joystick <index> Use the index-th joystick if available\n" " --joystick <index> Use the index-th joystick if available\n"
" (-1 to disable joystick, default: 0)\n" " (-1 to disable joystick, default: 0)\n"

View File

@ -1956,7 +1956,7 @@ MouseSensitivity (int)
DrawMouseSens (); DrawMouseSens ();
do do
{ {
SDL_Delay(5); uSDL_Delay(5);
ReadAnyControl (&ci); ReadAnyControl (&ci);
switch (ci.dir) switch (ci.dir)
{ {
@ -2228,7 +2228,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
redraw = 0; redraw = 0;
} }
SDL_Delay(5); uSDL_Delay(5);
ReadAnyControl (&ci); ReadAnyControl (&ci);
if (type == MOUSE || type == JOYSTICK) if (type == MOUSE || type == JOYSTICK)
@ -2274,7 +2274,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
lastFlashTime = GetTimeCount(); lastFlashTime = GetTimeCount();
VW_UpdateScreen (); VW_UpdateScreen ();
} }
else SDL_Delay(5); else uSDL_Delay(5);
// //
// WHICH TYPE OF INPUT DO WE PROCESS? // 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]); while (!cust->allowed[which]);
redraw = 1; redraw = 1;
SD_PlaySound (MOVEGUN1SND); 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 (); IN_ClearKeysDown ();
break; break;
@ -2411,7 +2411,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
while (!cust->allowed[which]); while (!cust->allowed[which]);
redraw = 1; redraw = 1;
SD_PlaySound (MOVEGUN1SND); 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 (); IN_ClearKeysDown ();
break; break;
case dir_North: case dir_North:
@ -2837,7 +2837,7 @@ CP_ChangeView (int)
do do
{ {
CheckPause (); CheckPause ();
SDL_Delay(5); uSDL_Delay(5);
ReadAnyControl (&ci); ReadAnyControl (&ci);
switch (ci.dir) switch (ci.dir)
{ {
@ -3284,7 +3284,7 @@ HandleMenu (CP_iteminfo * item_i, CP_itemtype * items, void (*routine) (int w))
routine (which); routine (which);
VW_UpdateScreen (); VW_UpdateScreen ();
} }
else SDL_Delay(5); else uSDL_Delay(5);
CheckPause (); CheckPause ();
@ -3484,7 +3484,7 @@ DrawHalfStep (int x, int y)
VWB_DrawPic (x, y, C_CURSOR1PIC); VWB_DrawPic (x, y, C_CURSOR1PIC);
VW_UpdateScreen (); VW_UpdateScreen ();
SD_PlaySound (MOVEGUN1SND); 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 (); int32_t startTime = GetTimeCount ();
do do
{ {
SDL_Delay(5); uSDL_Delay(5);
ReadAnyControl (&ci); ReadAnyControl (&ci);
} }
while ((int32_t) GetTimeCount () - startTime < count && ci.dir != dir_None); while ((int32_t) GetTimeCount () - startTime < count && ci.dir != dir_None);
@ -3732,7 +3732,7 @@ Confirm (const char *string)
tick ^= 1; tick ^= 1;
lastBlinkTime = GetTimeCount(); lastBlinkTime = GetTimeCount();
} }
else SDL_Delay(5); else uSDL_Delay(5);
#ifdef SPANISH #ifdef SPANISH
} }

View File

@ -211,7 +211,7 @@ int songs[] = {
XFUNKIE_MUS, XFUNKIE_MUS,
XDEATH_MUS, XDEATH_MUS,
XGETYOU_MUS, // DON'T KNOW XGETYOU_MUS, // DON'T KNOW
ULTIMATE_MUS, // Trans Grsse ULTIMATE_MUS, // Trans Gr<EFBFBD>sse
DUNGEON_MUS, DUNGEON_MUS,
GOINGAFT_MUS, GOINGAFT_MUS,
@ -406,11 +406,11 @@ void PollControls (void)
if (demoplayback || demorecord) // demo recording and playback needs to be constant if (demoplayback || demorecord) // demo recording and playback needs to be constant
{ {
// wait up to DEMOTICS Wolf tics // wait up to DEMOTICS Wolf tics
uint32_t curtime = SDL_GetTicks(); uint32_t curtime = uSDL_GetTicks();
lasttimecount += DEMOTICS; lasttimecount += DEMOTICS;
int32_t timediff = (lasttimecount * 100) / 7 - curtime; int32_t timediff = (lasttimecount * 100) / 7 - curtime;
if(timediff > 0) if(timediff > 0)
SDL_Delay(timediff); uSDL_Delay(timediff);
if(timediff < -2 * DEMOTICS) // more than 2-times DEMOTICS behind? if(timediff < -2 * DEMOTICS) // more than 2-times DEMOTICS behind?
lasttimecount = (curtime * 7) / 100; // yes, set to current timecount lasttimecount = (curtime * 7) / 100; // yes, set to current timecount

View File

@ -669,7 +669,7 @@ void ShowArticle (char *article)
firstpage = false; firstpage = false;
} }
} }
SDL_Delay(5); uSDL_Delay(5);
LastScan = 0; LastScan = 0;
ReadAnyControl(&ci); ReadAnyControl(&ci);