Commit 83797cfd authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Cleanups

parent e1c77719
......@@ -19,6 +19,29 @@
#include "MACkeymap.h"
#include "vkbd.i"
extern int MOUSE_EMULATED;
extern int SHOWKEY;
/* Forward declarations */
int app_init(void);
int app_free(void);
int app_render(int poll);
void Emu_init(void);
void Emu_uninit(void);
void minivmac_main_exit(void);
void emu_reset(void);
void RunEmulatedTicksToTrueTime(void);
void ScreenUpdate(void);
int InitOSGLU(int argc, char **argv);
void retro_poll_event(int joyon);
void retro_key_up(int key);
void retro_key_down(int key);
void retro_loop(void);
/* Variables */
#ifdef _WIN32
char slash = '\\';
#else
......@@ -58,22 +81,8 @@ char RPATH[512];
int pauseg=0;
int want_quit=0;
int minivmac_kbdtype=0;
extern int MOUSE_EMULATED;
extern int SHOWKEY;
/* Forward declarations */
int app_init(void);
int app_free(void);
int app_render(int poll);
void Emu_init(void);
void Emu_uninit(void);
void minivmac_main_exit(void);
void emu_reset(void);
int CROP_WIDTH;
int CROP_HEIGHT;
int VIRTUAL_WIDTH;
......
......@@ -13,12 +13,17 @@
#include <libretro.h>
#include <libretro-core.h>
extern void filebrowser_init();
extern void filebrowser_free();
/* Forward declarations */
extern void filebrowser_init(void);
extern void filebrowser_free(void);
extern void Screen_SetFullUpdate(int scr);
extern void vkbd_key(int key,int pressed);
extern void app_vkb_handle();
extern void app_vkb_handle(void);
int UnInitOSGLU(void);
/* Variables */
extern char Core_Key_Sate[512];
extern char Core_old_Key_Sate[512];
......
......@@ -40,6 +40,15 @@
extern char RETRO_ROM[512];
extern char RETRO_DIR[512];
/* Forward declarations */
void DoEmulateOneTick(void);
blnr InitEmulation(void);
void DoEmulateExtraTime(void);
void retro_sound(void);
int RunOnEndOfSixtieth(void);
void RunEmulatedTicksToTrueTime(void);
void retro_audio_cb(short l, short r);
/* --- some simple utilities --- */
GLOBALPROC MyMoveBytes(anyp srcPtr, anyp destPtr, si5b byteCount)
......@@ -1149,32 +1158,28 @@ GLOBALOSGLUPROC DoneWithDrawingForTick(void)
}
//retro loop
void retro_loop(){
if(DSKLOAD==1){
(void) Sony_Insert1(RPATH, falseblnr);
DSKLOAD=0;
}
void retro_loop(void)
{
if(DSKLOAD==1)
{
(void) Sony_Insert1(RPATH, falseblnr);
DSKLOAD=0;
}
//CheckForSystemEvents();
//CheckForSavedTasks();
if (ForceMacOff) {
return;
}
//CheckForSystemEvents();
//CheckForSavedTasks();
if (ForceMacOff)
return;
RunOnEndOfSixtieth();
DoEmulateExtraTime();
RunOnEndOfSixtieth();
DoEmulateExtraTime();
#if 0
if (0/*CurSpeedStopped*/) {
return;//WaitForTheNextEvent();
} else {
DoEmulateExtraTime();
RunOnEndOfSixtieth();
}
if (0/*CurSpeedStopped*/)
return;//WaitForTheNextEvent();
DoEmulateExtraTime();
RunOnEndOfSixtieth();
#endif
}
/* --- time, date, location --- */
......@@ -1196,27 +1201,28 @@ LOCALVAR ui5b LastTimeUsec;
LOCALPROC GetCurrentTicks(void)
{
struct timeval t;
struct timeval t;
gettimeofday(&t, NULL);
if (! HaveTimeDelta) {
time_t Current_Time;
struct tm *s;
gettimeofday(&t, NULL);
if (! HaveTimeDelta)
{
time_t Current_Time;
struct tm *s;
(void) time(&Current_Time);
s = localtime(&Current_Time);
TimeDelta = Date2MacSeconds(s->tm_sec, s->tm_min, s->tm_hour,
s->tm_mday, 1 + s->tm_mon, 1900 + s->tm_year) - t.tv_sec;
(void) time(&Current_Time);
s = localtime(&Current_Time);
TimeDelta = Date2MacSeconds(s->tm_sec, s->tm_min, s->tm_hour,
s->tm_mday, 1 + s->tm_mon, 1900 + s->tm_year) - t.tv_sec;
#if 0 /* how portable is this ? */
CurMacDelta = ((ui5b)(s->tm_gmtoff) & 0x00FFFFFF)
| ((s->tm_isdst ? 0x80 : 0) << 24);
CurMacDelta = ((ui5b)(s->tm_gmtoff) & 0x00FFFFFF)
| ((s->tm_isdst ? 0x80 : 0) << 24);
#endif
HaveTimeDelta = trueblnr;
}
HaveTimeDelta = trueblnr;
}
NewMacDateInSeconds = t.tv_sec + TimeDelta;
LastTimeSec = (ui5b)t.tv_sec;
LastTimeUsec = (ui5b)t.tv_usec;
NewMacDateInSeconds = t.tv_sec + TimeDelta;
LastTimeSec = (ui5b)t.tv_sec;
LastTimeUsec = (ui5b)t.tv_usec;
}
#define MyInvTimeStep 16626 /* TicksPerSecond / 60.14742 */
......@@ -1226,11 +1232,12 @@ LOCALVAR ui5b NextTimeUsec;
LOCALPROC IncrNextTime(void)
{
NextTimeUsec += MyInvTimeStep;
if (NextTimeUsec >= TicksPerSecond) {
NextTimeUsec -= TicksPerSecond;
NextTimeSec += 1;
}
NextTimeUsec += MyInvTimeStep;
if (NextTimeUsec >= TicksPerSecond)
{
NextTimeUsec -= TicksPerSecond;
NextTimeSec += 1;
}
}
LOCALPROC InitNextTime(void)
......@@ -1259,19 +1266,25 @@ LOCALPROC UpdateTrueEmulatedTime(void)
GetCurrentTicks();
TimeDiff = GetTimeDiff();
if (TimeDiff >= 0) {
if (TimeDiff > 4 * MyInvTimeStep) {
/* emulation interrupted, forget it */
++TrueEmulatedTime;
InitNextTime();
} else {
if (TimeDiff >= 0)
{
if (TimeDiff > 4 * MyInvTimeStep)
{
/* emulation interrupted, forget it */
++TrueEmulatedTime;
InitNextTime();
}
else
{
do {
++TrueEmulatedTime;
IncrNextTime();
TimeDiff -= TicksPerSecond;
} while (TimeDiff >= 0);
}
} else if (TimeDiff < - 2 * MyInvTimeStep) {
}
else if (TimeDiff < - 2 * MyInvTimeStep)
{
/* clock goofed if ever get here, reset */
InitNextTime();
}
......@@ -1279,12 +1292,12 @@ LOCALPROC UpdateTrueEmulatedTime(void)
LOCALFUNC blnr CheckDateTime(void)
{
if (CurMacDateInSeconds != NewMacDateInSeconds) {
CurMacDateInSeconds = NewMacDateInSeconds;
return trueblnr;
} else {
return falseblnr;
}
if (CurMacDateInSeconds != NewMacDateInSeconds)
{
CurMacDateInSeconds = NewMacDateInSeconds;
return trueblnr;
}
return falseblnr;
}
LOCALFUNC blnr InitLocationDat(void)
......@@ -1338,131 +1351,142 @@ LOCALPROC MySound_Start0(void)
GLOBALFUNC tpSoundSamp MySound_BeginWrite(ui4r n, ui4r *actL)
{
ui4b ToFillLen = kAllBuffLen - (TheWriteOffset - ThePlayOffset);
ui4b WriteBuffContig =
kOneBuffLen - (TheWriteOffset & kOneBuffMask);
ui4b ToFillLen = kAllBuffLen - (TheWriteOffset - ThePlayOffset);
ui4b WriteBuffContig =
kOneBuffLen - (TheWriteOffset & kOneBuffMask);
if (WriteBuffContig < n) {
n = WriteBuffContig;
}
if (ToFillLen < n) {
/* overwrite previous buffer */
TheWriteOffset -= kOneBuffLen;
}
if (WriteBuffContig < n)
n = WriteBuffContig;
if (ToFillLen < n)
{
/* overwrite previous buffer */
TheWriteOffset -= kOneBuffLen;
}
*actL = n;
return TheSoundBuffer + (TheWriteOffset & kAllBuffMask);
*actL = n;
return TheSoundBuffer + (TheWriteOffset & kAllBuffMask);
}
LOCALVAR blnr wantplaying = falseblnr;
GLOBALPROC MySound_EndWrite(ui4r actL)
{
TheWriteOffset += actL;
TheWriteOffset += actL;
if (0 == (TheWriteOffset & kOneBuffMask)) {
/* just finished a block */
if (0 == (TheWriteOffset & kOneBuffMask))
{
/* just finished a block */
if (wantplaying) {
TheFillOffset = TheWriteOffset;
retro_sound();
if (wantplaying)
{
TheFillOffset = TheWriteOffset;
retro_sound();
} else if (((TheWriteOffset - ThePlayOffset) >> kLnOneBuffLen) < 12) {
/* just wait */
} else {
TheFillOffset = TheWriteOffset;
wantplaying = trueblnr;
retro_sound();
}
}
}
else if (((TheWriteOffset - ThePlayOffset) >> kLnOneBuffLen) < 12)
{
/* just wait */
}
else
{
TheFillOffset = TheWriteOffset;
wantplaying = trueblnr;
retro_sound();
}
}
}
blnr MySound_EndWrite0(ui4r actL)
{
blnr v;
blnr v;
TheWriteOffset += actL;
TheWriteOffset += actL;
if (0 != (TheWriteOffset & kOneBuffMask)) {
v = falseblnr;
} else {
/* just finished a block */
if (0 != (TheWriteOffset & kOneBuffMask))
v = falseblnr;
else
{
/* just finished a block */
TheFillOffset = TheWriteOffset;
TheFillOffset = TheWriteOffset;
v = trueblnr; //retro_sound();
}
v = trueblnr; //retro_sound();
}
return v;
return v;
}
LOCALPROC MySound_SecondNotify0(void)
{
if (MinFilledSoundBuffs > DesiredMinFilledSoundBuffs) {
++CurEmulatedTime;
} else if (MinFilledSoundBuffs < DesiredMinFilledSoundBuffs) {
--CurEmulatedTime;
}
MinFilledSoundBuffs = kSoundBuffers;
if (MinFilledSoundBuffs > DesiredMinFilledSoundBuffs)
++CurEmulatedTime;
else if (MinFilledSoundBuffs < DesiredMinFilledSoundBuffs)
--CurEmulatedTime;
MinFilledSoundBuffs = kSoundBuffers;
}
#define SOUND_SAMPLERATE 22255 /* = round(7833600 * 2 / 704) */
#endif
void retro_sound(){
void retro_sound(void)
{
#if MySoundEnabled
ui3p NextPlayPtr;
ui4b PlayNowSize = 0;
ui4b MaskedFillOffset = ThePlayOffset & kOneBuffMask;
ui3p NextPlayPtr;
ui4b PlayNowSize = 0;
ui4b MaskedFillOffset = ThePlayOffset & kOneBuffMask;
if (MaskedFillOffset != 0) {
/* take care of left overs */
PlayNowSize = kOneBuffLen - MaskedFillOffset;
NextPlayPtr = TheSoundBuffer + (ThePlayOffset & kAllBuffMask);
} else if (0 != ((TheFillOffset - ThePlayOffset) >> kLnOneBuffLen)) {
PlayNowSize = kOneBuffLen;
NextPlayPtr = TheSoundBuffer + (ThePlayOffset & kAllBuffMask);
}
if (MaskedFillOffset != 0)
{
/* take care of left overs */
PlayNowSize = kOneBuffLen - MaskedFillOffset;
NextPlayPtr = TheSoundBuffer + (ThePlayOffset & kAllBuffMask);
}
else if (0 != ((TheFillOffset - ThePlayOffset) >> kLnOneBuffLen))
{
PlayNowSize = kOneBuffLen;
NextPlayPtr = TheSoundBuffer + (ThePlayOffset & kAllBuffMask);
}
if (0 != PlayNowSize) {
int i;
if (0 != PlayNowSize)
{
int i;
unsigned char * sptr=NextPlayPtr;
signed short rsnd=0;
unsigned char * sptr=NextPlayPtr;
signed short rsnd=0;
for(i=0;i<PlayNowSize;i++){
rsnd=(signed short int) ( ((int)(*sptr++))-128)<<8;
if(rsnd!=0)retro_audio_cb(rsnd,rsnd);
}
ThePlayOffset += PlayNowSize;
for(i=0;i<PlayNowSize;i++)
{
rsnd=(signed short int) ( ((int)(*sptr++))-128)<<8;
}
#endif
if(rsnd!=0)retro_audio_cb(rsnd,rsnd);
}
ThePlayOffset += PlayNowSize;
}
#endif
}
/* --- basic dialogs --- */
LOCALPROC CheckSavedMacMsg(void)
{
/* called only on quit, if error saved but not yet reported */
if (nullpr != SavedBriefMsg) {
char briefMsg0[ClStrMaxLength + 1];
char longMsg0[ClStrMaxLength + 1];
/* called only on quit, if error saved but not yet reported */
if (nullpr != SavedBriefMsg)
{
char briefMsg0[ClStrMaxLength + 1];
char longMsg0[ClStrMaxLength + 1];
NativeStrFromCStr(briefMsg0, SavedBriefMsg);
NativeStrFromCStr(longMsg0, SavedLongMsg);
NativeStrFromCStr(briefMsg0, SavedBriefMsg);
NativeStrFromCStr(longMsg0, SavedLongMsg);
fprintf(stderr, "%s\n", briefMsg0);
fprintf(stderr, "%s\n", longMsg0);
fprintf(stderr, "%s\n", briefMsg0);
fprintf(stderr, "%s\n", longMsg0);
SavedBriefMsg = nullpr;
}
SavedBriefMsg = nullpr;
}
}
/* --- clipboard --- */
......@@ -1494,11 +1518,11 @@ LOCALFUNC blnr Screen_Init(void)
return 1;
}
enum
{
kMagStateNormal,
enum {
kMagStateNormal,
kNumMagStates
kNumMagStates
};
#define kMagStateAuto kNumMagStates
......@@ -1508,9 +1532,10 @@ LOCALVAR ui4b RestoreMouseH;
LOCALVAR ui4b RestoreMouseV;
#if VarFullScreen && EnableMagnify
enum {
kWinStateWindowed,
kNumWinStates
enum
{
kWinStateWindowed,
kNumWinStates
};
#endif
......@@ -1534,73 +1559,73 @@ LOCALPROC CheckForSavedTasks(void)
LOCALFUNC blnr ScanCommandLine(void)
{
char *pa;
int i = 1;
char *pa;
int i = 1;
label_retry:
if (i < my_argc) {
pa = my_argv[i++];
if ('-' == pa[0]) {
if ((0 == strcmp(pa, "--display"))
|| (0 == strcmp(pa, "-display")))
{
if (i < my_argc) {
display_name = my_argv[i++];
goto label_retry;
}
} else
if ((0 == strcmp(pa, "--rom"))
|| (0 == strcmp(pa, "-r")))
{
if (i < my_argc) {
rom_path = my_argv[i++];
goto label_retry;
}
} else
if (0 == strcmp(pa, "-n"))
{
if (i < my_argc) {
n_arg = my_argv[i++];
goto label_retry;
}
} else
if (0 == strcmp(pa, "-d"))
{
if (i < my_argc) {
d_arg = my_argv[i++];
goto label_retry;
}
} else
if (i < my_argc) {
pa = my_argv[i++];
if ('-' == pa[0]) {
if ((0 == strcmp(pa, "--display"))
|| (0 == strcmp(pa, "-display")))
{
if (i < my_argc) {
display_name = my_argv[i++];
goto label_retry;
}
} else
if ((0 == strcmp(pa, "--rom"))
|| (0 == strcmp(pa, "-r")))
{
if (i < my_argc) {
rom_path = my_argv[i++];
goto label_retry;
}
} else
if (0 == strcmp(pa, "-n"))
{
if (i < my_argc) {
n_arg = my_argv[i++];
goto label_retry;
}
} else
if (0 == strcmp(pa, "-d"))
{
if (i < my_argc) {
d_arg = my_argv[i++];
goto label_retry;
}
} else
#ifndef UsingAlsa
#define UsingAlsa 0
#endif
#if UsingAlsa
if ((0 == strcmp(pa, "--alsadev"))
|| (0 == strcmp(pa, "-alsadev")))
{
if (i < my_argc) {
alsadev_name = my_argv[i++];
goto label_retry;
}
} else
if ((0 == strcmp(pa, "--alsadev"))
|| (0 == strcmp(pa, "-alsadev")))
{
if (i < my_argc) {
alsadev_name = my_argv[i++];
goto label_retry;
}
} else
#endif
#if 0
if (0 == strcmp(pa, "-l")) {
SpeedValue = 0;
goto label_retry;
} else
if (0 == strcmp(pa, "-l")) {
SpeedValue = 0;
goto label_retry;
} else
#endif
{
MacMsg(kStrBadArgTitle, kStrBadArgMessage, falseblnr);
}
} else {
(void) Sony_Insert1(pa, falseblnr);
goto label_retry;
}
}