Commit 6532757d authored by CeRiAl's avatar CeRiAl

modifications to make it compile with emscripten

parent 48ce93e1
final compile:
==============
/home/cerial/Development/emscripten/em++ -O2 -o dosbox.html dosbox.o cpu/libcpu.a debug/libdebug.a dos/libdos.a fpu/libfpu.a hardware/libhardware.a gui/libgui.a ints/libints.a misc/libmisc.a shell/libshell.a hardware/serialport/libserial.a libs/gui_tk/libgui_tk.a -lGL
diff for emscripten:
====================
diff --git a/em_sdl-config b/em_sdl-config
new file mode 100755
index 0000000..8812103
--- /dev/null
+++ b/em_sdl-config
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+prefix=
+exec_prefix=
+exec_prefix_set=no
+
+usage="\
+Usage: em_sdl-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]"
+
+if test $# -eq 0; then
+ echo "${usage}" 1>&2
+ exit 1
+fi
+
+while test $# -gt 0; do
+ case "$1" in
+ -*=*) optarg=`echo "$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) optarg= ;;
+ esac
+
+ case $1 in
+ --prefix=*)
+ prefix=$optarg
+ if test $exec_prefix_set = no ; then
+ exec_prefix=$optarg
+ fi
+ ;;
+ --prefix)
+ echo $prefix
+ ;;
+ --exec-prefix=*)
+ exec_prefix=$optarg
+ exec_prefix_set=yes
+ ;;
+ --exec-prefix)
+ echo $exec_prefix
+ ;;
+ --version)
+ echo 1.2.14
+ ;;
+ --cflags)
+ echo
+ ;;
+ --libs)
+ echo
+ ;;
+ --static-libs)
+ echo
+ ;;
+ *)
+ echo "${usage}" 1>&2
+ exit 1
+ ;;
+ esac
+ shift
+done
+
diff --git a/system/include/SDL/SDL_cpuinfo.h b/system/include/SDL/SDL_cpuinfo.h
index 7fb39ed..b3e5e5f 100644
--- a/system/include/SDL/SDL_cpuinfo.h
+++ b/system/include/SDL/SDL_cpuinfo.h
@@ -50,16 +50,16 @@
#endif
#endif
#ifdef __MMX__
-#include <mmintrin.h>
+//#include <mmintrin.h>
#endif
#ifdef __3dNOW__
#include <mm3dnow.h>
#endif
#ifdef __SSE__
-#include <xmmintrin.h>
+//#include <xmmintrin.h>
#endif
#ifdef __SSE2__
-#include <emmintrin.h>
+//#include <emmintrin.h>
#endif
#endif
diff --git a/tools/shared.py b/tools/shared.py
index 5a9860d..024fc1e 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -717,6 +717,7 @@ class Building:
env['HOST_CXXFLAGS'] = "-W" #if set to nothing, CXXFLAGS is used, which we don't want
env['PKG_CONFIG_LIBDIR'] = path_from_root('system', 'local', 'lib', 'pkgconfig') + os.path.pathsep + path_from_root('system', 'lib', 'pkgconfig')
env['PKG_CONFIG_PATH'] = os.environ.get ('EM_PKG_CONFIG_PATH') or ''
+ env['SDL_CONFIG'] = path_from_root('em_sdl-config') # Override the sdl-config utility in the SDL dev package
return env
@staticmethod
...@@ -4899,7 +4899,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ...@@ -4899,7 +4899,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#include "SDL.h" #include "SDL.h"
void blah(){ void blah(){
#if SDL_MINOR_VERSION != 2 #if SDL_MINOR_VERSION != 3
#error "Only SDL 1.2 supported" #error "Only SDL 1.2 supported"
#endif #endif
; ;
......
...@@ -34,13 +34,13 @@ ...@@ -34,13 +34,13 @@
CDROM_Interface_SDL::CDROM_Interface_SDL(void) { CDROM_Interface_SDL::CDROM_Interface_SDL(void) {
driveID = 0; driveID = 0;
oldLeadOut = 0; oldLeadOut = 0;
cd = 0; // cd = 0;
} }
CDROM_Interface_SDL::~CDROM_Interface_SDL(void) { CDROM_Interface_SDL::~CDROM_Interface_SDL(void) {
StopAudio(); StopAudio();
SDL_CDClose(cd); // SDL_CDClose(cd);
cd = 0; // cd = 0;
} }
bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) { bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
...@@ -48,14 +48,14 @@ bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) { ...@@ -48,14 +48,14 @@ bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
strcpy(buffer,path); strcpy(buffer,path);
upcase(buffer); upcase(buffer);
int num = SDL_CDNumDrives(); int num = 0; //SDL_CDNumDrives();
if ((forceCD>=0) && (forceCD<num)) { if ((forceCD>=0) && (forceCD<num)) {
driveID = forceCD; driveID = forceCD;
cd = SDL_CDOpen(driveID); // cd = SDL_CDOpen(driveID);
SDL_CDStatus(cd); // SDL_CDStatus(cd);
return true; return true;
}; };
/*
const char* cdname = 0; const char* cdname = 0;
for (int i=0; i<num; i++) { for (int i=0; i<num; i++) {
cdname = SDL_CDName(i); cdname = SDL_CDName(i);
...@@ -66,28 +66,36 @@ bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) { ...@@ -66,28 +66,36 @@ bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
return true; return true;
}; };
}; };
*/
return false; return false;
} }
bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) { bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {
return false;
/*
if (CD_INDRIVE(SDL_CDStatus(cd))) { if (CD_INDRIVE(SDL_CDStatus(cd))) {
stTrack = 1; stTrack = 1;
end = cd->numtracks; end = cd->numtracks;
FRAMES_TO_MSF(cd->track[cd->numtracks].offset,&leadOut.min,&leadOut.sec,&leadOut.fr); FRAMES_TO_MSF(cd->track[cd->numtracks].offset,&leadOut.min,&leadOut.sec,&leadOut.fr);
} }
return CD_INDRIVE(SDL_CDStatus(cd)); return CD_INDRIVE(SDL_CDStatus(cd));
*/
} }
bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) { bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
return false;
/*
if (CD_INDRIVE(SDL_CDStatus(cd))) { if (CD_INDRIVE(SDL_CDStatus(cd))) {
FRAMES_TO_MSF(cd->track[track-1].offset,&start.min,&start.sec,&start.fr); FRAMES_TO_MSF(cd->track[track-1].offset,&start.min,&start.sec,&start.fr);
attr = cd->track[track-1].type<<4;//sdl uses 0 for audio and 4 for data. instead of 0x00 and 0x40 attr = cd->track[track-1].type<<4;//sdl uses 0 for audio and 4 for data. instead of 0x00 and 0x40
} }
return CD_INDRIVE(SDL_CDStatus(cd)); return CD_INDRIVE(SDL_CDStatus(cd));
*/
} }
bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) { bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) {
return false;
/*
if (CD_INDRIVE(SDL_CDStatus(cd))) { if (CD_INDRIVE(SDL_CDStatus(cd))) {
track = cd->cur_track; track = cd->cur_track;
index = cd->cur_track; index = cd->cur_track;
...@@ -96,17 +104,26 @@ bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, ...@@ -96,17 +104,26 @@ bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track,
FRAMES_TO_MSF(cd->cur_frame+cd->track[track].offset,&absPos.min,&absPos.sec,&absPos.fr); FRAMES_TO_MSF(cd->cur_frame+cd->track[track].offset,&absPos.min,&absPos.sec,&absPos.fr);
} }
return CD_INDRIVE(SDL_CDStatus(cd)); return CD_INDRIVE(SDL_CDStatus(cd));
*/
} }
bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause){ bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause){
return false;
/*
if (CD_INDRIVE(SDL_CDStatus(cd))) { if (CD_INDRIVE(SDL_CDStatus(cd))) {
playing = (cd->status==CD_PLAYING); playing = (cd->status==CD_PLAYING);
pause = (cd->status==CD_PAUSED); pause = (cd->status==CD_PAUSED);
} }
return CD_INDRIVE(SDL_CDStatus(cd)); return CD_INDRIVE(SDL_CDStatus(cd));
*/
} }
bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) { bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
mediaPresent = false;
mediaChanged = false;
trayOpen = false;
return true;
/*
SDL_CDStatus(cd); SDL_CDStatus(cd);
mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR); mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR);
mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset); mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset);
...@@ -114,34 +131,47 @@ bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChan ...@@ -114,34 +131,47 @@ bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChan
oldLeadOut = cd->track[cd->numtracks].offset; oldLeadOut = cd->track[cd->numtracks].offset;
if (mediaChanged) SDL_CDStatus(cd); if (mediaChanged) SDL_CDStatus(cd);
return true; return true;
*/
} }
bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) { bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) {
return false;
/*
// Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?) // Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
SDL_CDClose(cd); SDL_CDClose(cd);
cd = SDL_CDOpen(driveID); cd = SDL_CDOpen(driveID);
bool success = (SDL_CDPlay(cd,start+150,len)==0); bool success = (SDL_CDPlay(cd,start+150,len)==0);
return success; return success;
*/
} }
bool CDROM_Interface_SDL::PauseAudio(bool resume) { bool CDROM_Interface_SDL::PauseAudio(bool resume) {
return false;
/*
bool success; bool success;
if (resume) success = (SDL_CDResume(cd)==0); if (resume) success = (SDL_CDResume(cd)==0);
else success = (SDL_CDPause (cd)==0); else success = (SDL_CDPause (cd)==0);
return success; return success;
*/
} }
bool CDROM_Interface_SDL::StopAudio(void) { bool CDROM_Interface_SDL::StopAudio(void) {
return false;
/*
// Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?) // Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
SDL_CDClose(cd); SDL_CDClose(cd);
cd = SDL_CDOpen(driveID); cd = SDL_CDOpen(driveID);
bool success = (SDL_CDStop(cd)==0); bool success = (SDL_CDStop(cd)==0);
return success; return success;
*/
} }
bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload) { bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload) {
return false;
/*
bool success = (SDL_CDEject(cd)==0); bool success = (SDL_CDEject(cd)==0);
return success; return success;
*/
} }
int CDROM_GetMountType(char* path, int forceCD) { int CDROM_GetMountType(char* path, int forceCD) {
...@@ -158,18 +188,20 @@ int CDROM_GetMountType(char* path, int forceCD) { ...@@ -158,18 +188,20 @@ int CDROM_GetMountType(char* path, int forceCD) {
upcase(buffer); upcase(buffer);
#endif #endif
int num = SDL_CDNumDrives(); int num = 0; //SDL_CDNumDrives();
// If cd drive is forced then check if its in range and return 0 // If cd drive is forced then check if its in range and return 0
if ((forceCD>=0) && (forceCD<num)) { if ((forceCD>=0) && (forceCD<num)) {
LOG(LOG_ALL,LOG_ERROR)("CDROM: Using drive %d",forceCD); LOG(LOG_ALL,LOG_ERROR)("CDROM: Using drive %d",forceCD);
return 0; return 0;
} }
/*
// compare names // compare names
for (int i=0; i<num; i++) { for (int i=0; i<num; i++) {
cdName = SDL_CDName(i); cdName = SDL_CDName(i);
if (strcmp(buffer,cdName)==0) return 0; if (strcmp(buffer,cdName)==0) return 0;
}; };
*/
// Detect ISO // Detect ISO
struct stat file_stat; struct stat file_stat;
......
...@@ -83,7 +83,7 @@ private: ...@@ -83,7 +83,7 @@ private:
bool Open (void); bool Open (void);
void Close (void); void Close (void);
SDL_CD* cd; // SDL_CD* cd;
int driveID; int driveID;
Uint32 oldLeadOut; Uint32 oldLeadOut;
}; };
......
...@@ -184,22 +184,30 @@ bool CDROM_Interface_Image::GetUPC(unsigned char& attr, char* upc) ...@@ -184,22 +184,30 @@ bool CDROM_Interface_Image::GetUPC(unsigned char& attr, char* upc)
bool CDROM_Interface_Image::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) bool CDROM_Interface_Image::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut)
{ {
return false;
/*
stTrack = 1; stTrack = 1;
end = (int)(tracks.size() - 1); end = (int)(tracks.size() - 1);
FRAMES_TO_MSF(tracks[tracks.size() - 1].start + 150, &leadOut.min, &leadOut.sec, &leadOut.fr); FRAMES_TO_MSF(tracks[tracks.size() - 1].start + 150, &leadOut.min, &leadOut.sec, &leadOut.fr);
return true; return true;
*/
} }
bool CDROM_Interface_Image::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) bool CDROM_Interface_Image::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr)
{ {
return false;
/*
if (track < 1 || track > (int)tracks.size()) return false; if (track < 1 || track > (int)tracks.size()) return false;
FRAMES_TO_MSF(tracks[track - 1].start + 150, &start.min, &start.sec, &start.fr); FRAMES_TO_MSF(tracks[track - 1].start + 150, &start.min, &start.sec, &start.fr);
attr = tracks[track - 1].attr; attr = tracks[track - 1].attr;
return true; return true;
*/
} }
bool CDROM_Interface_Image::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) bool CDROM_Interface_Image::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos)
{ {
return false;
/*
int cur_track = GetTrack(player.currFrame); int cur_track = GetTrack(player.currFrame);
if (cur_track < 1) return false; if (cur_track < 1) return false;
track = (unsigned char)cur_track; track = (unsigned char)cur_track;
...@@ -208,6 +216,7 @@ bool CDROM_Interface_Image::GetAudioSub(unsigned char& attr, unsigned char& trac ...@@ -208,6 +216,7 @@ bool CDROM_Interface_Image::GetAudioSub(unsigned char& attr, unsigned char& trac
FRAMES_TO_MSF(player.currFrame + 150, &absPos.min, &absPos.sec, &absPos.fr); FRAMES_TO_MSF(player.currFrame + 150, &absPos.min, &absPos.sec, &absPos.fr);
FRAMES_TO_MSF(player.currFrame - tracks[track - 1].start + 150, &relPos.min, &relPos.sec, &relPos.fr); FRAMES_TO_MSF(player.currFrame - tracks[track - 1].start + 150, &relPos.min, &relPos.sec, &relPos.fr);
return true; return true;
*/
} }
bool CDROM_Interface_Image::GetAudioStatus(bool& playing, bool& pause) bool CDROM_Interface_Image::GetAudioStatus(bool& playing, bool& pause)
...@@ -652,6 +661,8 @@ bool CDROM_Interface_Image::GetCueKeyword(string &keyword, istream &in) ...@@ -652,6 +661,8 @@ bool CDROM_Interface_Image::GetCueKeyword(string &keyword, istream &in)
bool CDROM_Interface_Image::GetCueFrame(int &frames, istream &in) bool CDROM_Interface_Image::GetCueFrame(int &frames, istream &in)
{ {
return false;
/*
string msf; string msf;
in >> msf; in >> msf;
int min, sec, fr; int min, sec, fr;
...@@ -659,6 +670,7 @@ bool CDROM_Interface_Image::GetCueFrame(int &frames, istream &in) ...@@ -659,6 +670,7 @@ bool CDROM_Interface_Image::GetCueFrame(int &frames, istream &in)
frames = MSF_TO_FRAMES(min, sec, fr); frames = MSF_TO_FRAMES(min, sec, fr);
return success; return success;
*/
} }
bool CDROM_Interface_Image::GetCueString(string &str, istream &in) bool CDROM_Interface_Image::GetCueString(string &str, istream &in)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "cdrom.h" #include "cdrom.h"
#include "support.h" #include "support.h"
#if defined (LINUX) #if defined (XLINUX)
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <linux/cdrom.h> #include <linux/cdrom.h>
......
...@@ -874,6 +874,7 @@ static Bit16u MSCDEX_IOCTL_Input(PhysPt buffer,Bit8u drive_unit) { ...@@ -874,6 +874,7 @@ static Bit16u MSCDEX_IOCTL_Input(PhysPt buffer,Bit8u drive_unit) {
TMSF pos; TMSF pos;
mscdex->GetCurrentPos(drive_unit,pos); mscdex->GetCurrentPos(drive_unit,pos);
Bit8u addr_mode = mem_readb(buffer+1); Bit8u addr_mode = mem_readb(buffer+1);
/*
if (addr_mode==0) { // HSG if (addr_mode==0) { // HSG
Bit32u frames=MSF_TO_FRAMES(pos.min, pos.sec, pos.fr); Bit32u frames=MSF_TO_FRAMES(pos.min, pos.sec, pos.fr);
if (frames<150) MSCDEX_LOG("MSCDEX: Get position: invalid position %d:%d:%d", pos.min, pos.sec, pos.fr); if (frames<150) MSCDEX_LOG("MSCDEX: Get position: invalid position %d:%d:%d", pos.min, pos.sec, pos.fr);
...@@ -885,9 +886,10 @@ static Bit16u MSCDEX_IOCTL_Input(PhysPt buffer,Bit8u drive_unit) { ...@@ -885,9 +886,10 @@ static Bit16u MSCDEX_IOCTL_Input(PhysPt buffer,Bit8u drive_unit) {
mem_writeb(buffer+4,pos.min); mem_writeb(buffer+4,pos.min);
mem_writeb(buffer+5,0x00); mem_writeb(buffer+5,0x00);
} else { } else {
*/
MSCDEX_LOG("MSCDEX: Get position: invalid address mode %x",addr_mode); MSCDEX_LOG("MSCDEX: Get position: invalid address mode %x",addr_mode);
return 0x03; // invalid function return 0x03; // invalid function
} // }
}break; }break;
case 0x06 : /* Get Device status */ case 0x06 : /* Get Device status */
mem_writed(buffer+1,mscdex->GetDeviceStatus(drive_unit)); mem_writed(buffer+1,mscdex->GetDeviceStatus(drive_unit));
......
...@@ -107,11 +107,13 @@ public: ...@@ -107,11 +107,13 @@ public:
// Show list of cdroms // Show list of cdroms
if (cmd->FindExist("-cd",false)) { if (cmd->FindExist("-cd",false)) {
int num = SDL_CDNumDrives(); int num = 0; //SDL_CDNumDrives();
WriteOut(MSG_Get("PROGRAM_MOUNT_CDROMS_FOUND"),num); WriteOut(MSG_Get("PROGRAM_MOUNT_CDROMS_FOUND"),num);
/*
for (int i=0; i<num; i++) { for (int i=0; i<num; i++) {
WriteOut("%2d. %s\n",i,SDL_CDName(i)); WriteOut("%2d. %s\n",i,SDL_CDName(i));
}; };
*/
return; return;
} }
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
/* $Id: dosbox.cpp,v 1.150 2009-11-03 20:17:42 qbix79 Exp $ */ /* $Id: dosbox.cpp,v 1.150 2009-11-03 20:17:42 qbix79 Exp $ */
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
...@@ -125,6 +128,116 @@ Bit32s ticksDone; ...@@ -125,6 +128,116 @@ Bit32s ticksDone;
Bit32u ticksScheduled; Bit32u ticksScheduled;
bool ticksLocked; bool ticksLocked;
#ifdef EMSCRIPTEN
static Bitu em_mainloop(void) {
Bits ret;
if (PIC_RunQueue()) {
ret=(*cpudecoder)();
if (GCC_UNLIKELY(ret<0)) return 1;
if (ret>0) {
Bitu blah=(*CallBack_Handlers[ret])();
if (GCC_UNLIKELY(blah)) return blah;
}
#if C_DEBUG
if (DEBUG_ExitLoop()) return 0;
#endif
} else {
GFX_Events();
if (ticksRemain>0) {
TIMER_AddTick();
ticksRemain--;
} else goto increaseticks;
}
return 0;
increaseticks:
if (GCC_UNLIKELY(ticksLocked)) {
ticksRemain=5;
/* Reset any auto cycle guessing for this frame */
ticksLast = GetTicks();
ticksAdded = 0;
ticksDone = 0;
ticksScheduled = 0;
} else {
Bit32u ticksNew;
ticksNew=GetTicks();
ticksScheduled += ticksAdded;
if (ticksNew > ticksLast) {
ticksRemain = ticksNew-ticksLast;
ticksLast = ticksNew;
ticksDone += ticksRemain;
if ( ticksRemain > 20 ) {
ticksRemain = 20;
}
ticksAdded = ticksRemain;
if (CPU_CycleAutoAdjust && !CPU_SkipCycleAutoAdjust) {
if (ticksScheduled >= 250 || ticksDone >= 250 || (ticksAdded > 15 && ticksScheduled >= 5) ) {
if(ticksDone < 1) ticksDone = 1; // Protect against div by zero
/* ratio we are aiming for is around 90% usage*/
Bit32s ratio = (ticksScheduled * (CPU_CyclePercUsed*90*1024/100/100)) / ticksDone;
Bit32s new_cmax = CPU_CycleMax;
Bit64s cproc = (Bit64s)CPU_CycleMax * (Bit64s)ticksScheduled;
if (cproc > 0) {
/* ignore the cycles added due to the io delay code in order
to have smoother auto cycle adjustments */
double ratioremoved = (double) CPU_IODelayRemoved / (double) cproc;
if (ratioremoved < 1.0) {
ratio = (Bit32s)((double)ratio * (1 - ratioremoved));
/* Don't allow very high ratio which can cause us to lock as we don't scale down
* for very low ratios. High ratio might result because of timing resolution */
if (ticksScheduled >= 250 && ticksDone < 10 && ratio > 20480)
ratio = 20480;
Bit64s cmax_scaled = (Bit64s)CPU_CycleMax * (Bit64s)ratio;
if (ratio <= 1024)
new_cmax = (Bit32s)(cmax_scaled / (Bit64s)1024);
else
new_cmax = (Bit32s)(1 + (CPU_CycleMax >> 1) + cmax_scaled / (Bit64s)2048);
}
}
if (new_cmax<CPU_CYCLES_LOWER_LIMIT)
new_cmax=CPU_CYCLES_LOWER_LIMIT;
/* ratios below 1% are considered to be dropouts due to
temporary load imbalance, the cycles adjusting is skipped */
if (ratio>10) {
/* ratios below 12% along with a large time since the last update
has taken place are most likely caused by heavy load through a
different application, the cycles adjusting is skipped as well */
if ((ratio>120) || (ticksDone<700)) {
CPU_CycleMax = new_cmax;
if (CPU_CycleLimit > 0) {
if (CPU_CycleMax>CPU_CycleLimit) CPU_CycleMax = CPU_CycleLimit;
}
}
}
CPU_IODelayRemoved = 0;
ticksDone = 0;
ticksScheduled = 0;
} else if (ticksAdded > 15) {
/* ticksAdded > 15 but ticksScheduled < 5, lower the cycles
but do not reset the scheduled/done ticks to take them into
account during the next auto cycle adjustment */
CPU_CycleMax /= 3;
if (CPU_CycleMax < CPU_CYCLES_LOWER_LIMIT)
CPU_CycleMax = CPU_CYCLES_LOWER_LIMIT;
}
}
} else {
ticksAdded = 0;
SDL_Delay(1);
ticksDone -= GetTicks() - ticksNew;
if (ticksDone < 0)
ticksDone = 0;
}
}
return 0;
}
static Bitu Normal_Loop(void) {
emscripten_set_main_loop((void (*)())(em_mainloop), 30, 0);
return 0;
}
#else
static Bitu Normal_Loop(void) { static Bitu Normal_Loop(void) {
Bits ret; Bits ret;
while (1) { while (1) {
...@@ -229,6 +342,7 @@ increaseticks: ...@@ -229,6 +342,7 @@ increaseticks:
} }
return 0; return 0;
} }
#endif
void DOSBOX_SetLoop(LoopHandler * handler) { void DOSBOX_SetLoop(LoopHandler * handler) {
loop=handler; loop=handler;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
...@@ -693,7 +694,7 @@ public: ...@@ -693,7 +694,7 @@ public:
if (abs(event->jaxis.value)<25000) return 0; if (abs(event->jaxis.value)<25000) return 0;
return CreateAxisBind(event->jaxis.axis,event->jaxis.value>0); return CreateAxisBind(event->jaxis.axis,event->jaxis.value>0);
} else if (event->type==SDL_JOYBUTTONDOWN) { } else if (event->type==SDL_JOYBUTTONDOWN) {
if (event->button.which!=stick) return 0; if (event->button.button!=stick) return 0;
#if defined (REDUCE_JOYSTICK_POLLING) #if defined (REDUCE_JOYSTICK_POLLING)
return CreateButtonBind(event->jbutton.button%button_wrap); return CreateButtonBind(event->jbutton.button%button_wrap);
#else #else
...@@ -2243,7 +2244,8 @@ static void InitializeJoysticks(void) { ...@@ -2243,7 +2244,8 @@ static void InitializeJoysticks(void) {
static void CreateBindGroups(void) { static void CreateBindGroups(void) {
bindgroups.clear(); bindgroups.clear();
new CKeyBindGroup(SDLK_LAST); // new CKeyBindGroup(SDLK_LAST);
new CKeyBindGroup(SDL_NUM_SCANCODES);
if (joytype != JOY_NONE) { if (joytype != JOY_NONE) {
#if defined (REDUCE_JOYSTICK_POLLING) #if defined (REDUCE_JOYSTICK_POLLING)
// direct access to the SDL joystick, thus removed from the event handling // direct access to the SDL joystick, thus removed from the event handling
......
...@@ -1743,7 +1743,8 @@ int main(int argc, char* argv[]) { ...@@ -1743,7 +1743,8 @@ int main(int argc, char* argv[]) {
#if SDL_VERSION_ATLEAST(1, 2, 14) #if SDL_VERSION_ATLEAST(1, 2, 14)
putenv(const_cast<char*>("SDL_DISABLE_LOCK_KEYS=1")); putenv(const_cast<char*>("SDL_DISABLE_LOCK_KEYS=1"));
#endif #endif
if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_CDROM // if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_CDROM
if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER
|SDL_INIT_NOPARACHUTE |SDL_INIT_NOPARACHUTE
) < 0 ) E_Exit("Can't init SDL %s",SDL_GetError()); ) < 0 ) E_Exit("Can't init SDL %s",SDL_GetError());
sdl.inited = true; sdl.inited = true;
......