mirror of
https://github.com/AppleWin/AppleWin.git
synced 2024-12-23 00:30:17 +00:00
More main-loop reduction & removal of redundant globals.
Fixed JoyUpdateButtonLatch() to debounce in 5mecs instead of 5secs! SpkrToggle() was using redundant global ('cyclenum') when using the PC speaker. . I reworked the code (as it looked out-of-date), but probably better to just remove all the PC speaker support.
This commit is contained in:
parent
0db62489f9
commit
8c019bcd35
@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "DiskImage.h"
|
||||
#include "Frame.h"
|
||||
#include "Harddisk.h"
|
||||
#include "Joystick.h"
|
||||
#include "Log.h"
|
||||
#include "Memory.h"
|
||||
#include "Mockingboard.h"
|
||||
@ -61,8 +62,6 @@ TCHAR *g_pAppTitle = TITLE_APPLE_2E_ENHANCED;
|
||||
|
||||
eApple2Type g_Apple2Type = A2TYPE_APPLE2EENHANCED;
|
||||
|
||||
DWORD cumulativecycles = 0; // Wraps after ~1hr 9mins
|
||||
DWORD cyclenum = 0; // Used by SpkrToggle() for non-wave sound
|
||||
bool g_bFullSpeed = false;
|
||||
|
||||
//Pravets 8A/C variables
|
||||
@ -76,7 +75,6 @@ HINSTANCE g_hInstance = (HINSTANCE)0;
|
||||
AppMode_e g_nAppMode = MODE_LOGO;
|
||||
static bool g_bLoadedSaveState = false;
|
||||
|
||||
static int lastmode = MODE_LOGO;
|
||||
TCHAR g_sProgramDir[MAX_PATH] = TEXT(""); // Directory of where AppleWin executable resides
|
||||
TCHAR g_sDebugDir [MAX_PATH] = TEXT(""); // TODO: Not currently used
|
||||
TCHAR g_sScreenShotDir[MAX_PATH] = TEXT(""); // TODO: Not currently used
|
||||
@ -115,17 +113,6 @@ CSpeech g_Speech;
|
||||
|
||||
//===========================================================================
|
||||
|
||||
#define DBG_CALC_FREQ 0
|
||||
#if DBG_CALC_FREQ
|
||||
const UINT MAX_CNT = 256;
|
||||
double g_fDbg[MAX_CNT];
|
||||
UINT g_nIdx = 0;
|
||||
double g_fMeanPeriod,g_fMeanFreq;
|
||||
ULONGLONG g_nPerfFreq = 0;
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool GetLoadedSaveStateFlag(void)
|
||||
{
|
||||
return g_bLoadedSaveState;
|
||||
@ -227,15 +214,15 @@ void ContinueExecution(void)
|
||||
if (nCyclesToExecute < 0)
|
||||
nCyclesToExecute = 0;
|
||||
|
||||
cyclenum = CpuExecute(nCyclesToExecute);
|
||||
g_dwCyclesThisFrame += cyclenum;
|
||||
const DWORD uActualCyclesExecuted = CpuExecute(nCyclesToExecute);
|
||||
g_dwCyclesThisFrame += uActualCyclesExecuted;
|
||||
|
||||
DiskUpdatePosition(cyclenum);
|
||||
JoyUpdatePosition();
|
||||
DiskUpdatePosition(uActualCyclesExecuted);
|
||||
JoyUpdateButtonLatch(nExecutionPeriodUsec); // Button latch time is independent of CPU clock frequency
|
||||
|
||||
SpkrUpdate(cyclenum);
|
||||
sg_SSC.CommUpdate(cyclenum);
|
||||
PrintUpdate(cyclenum);
|
||||
SpkrUpdate(uActualCyclesExecuted);
|
||||
sg_SSC.CommUpdate(uActualCyclesExecuted);
|
||||
PrintUpdate(uActualCyclesExecuted);
|
||||
|
||||
//
|
||||
|
||||
@ -249,23 +236,6 @@ void ContinueExecution(void)
|
||||
if (!g_bFullSpeed)
|
||||
{
|
||||
SysClk_WaitTimer();
|
||||
|
||||
#if DBG_CALC_FREQ
|
||||
if (g_nPerfFreq)
|
||||
{
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&nTime1);
|
||||
LONGLONG nTimeDiff = nTime1 - nTime0;
|
||||
double fTime = (double)nTimeDiff / (double)(LONGLONG)g_nPerfFreq;
|
||||
|
||||
g_fDbg[g_nIdx] = fTime;
|
||||
g_nIdx = (g_nIdx+1) & (MAX_CNT-1);
|
||||
g_fMeanPeriod = 0.0;
|
||||
for(UINT n=0; n<MAX_CNT; n++)
|
||||
g_fMeanPeriod += g_fDbg[n];
|
||||
g_fMeanPeriod /= (double)MAX_CNT;
|
||||
g_fMeanFreq = 1.0 / g_fMeanPeriod;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -942,11 +912,6 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
|
||||
|
||||
LogFileOutput("AppleWin version: %s\n", VERSIONSTRING);
|
||||
|
||||
#if DBG_CALC_FREQ
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&g_nPerfFreq);
|
||||
if(g_fh) fprintf(g_fh, "Performance frequency = %d\n",g_nPerfFreq);
|
||||
#endif
|
||||
|
||||
//-----
|
||||
|
||||
// Initialize COM - so we can use CoCreateInstance
|
||||
|
@ -13,8 +13,6 @@ extern TCHAR *g_pAppTitle;
|
||||
|
||||
extern eApple2Type g_Apple2Type;
|
||||
|
||||
extern DWORD cumulativecycles;
|
||||
extern DWORD cyclenum;
|
||||
extern bool g_bFullSpeed;
|
||||
|
||||
//Pravets 8A/C only variables
|
||||
|
@ -176,16 +176,18 @@ void RequestDebugger()
|
||||
*
|
||||
***/
|
||||
|
||||
unsigned __int64 g_nCycleIrqStart;
|
||||
unsigned __int64 g_nCycleIrqEnd;
|
||||
UINT g_nCycleIrqTime;
|
||||
#ifdef _DEBUG
|
||||
static unsigned __int64 g_nCycleIrqStart;
|
||||
static unsigned __int64 g_nCycleIrqEnd;
|
||||
static UINT g_nCycleIrqTime;
|
||||
|
||||
UINT g_nIdx = 0;
|
||||
const UINT BUFFER_SIZE = 4096; // 80 secs
|
||||
UINT g_nBuffer[BUFFER_SIZE];
|
||||
UINT g_nMean = 0;
|
||||
UINT g_nMin = 0xFFFFFFFF;
|
||||
UINT g_nMax = 0;
|
||||
static UINT g_nIdx = 0;
|
||||
static const UINT BUFFER_SIZE = 4096; // 80 secs
|
||||
static UINT g_nBuffer[BUFFER_SIZE];
|
||||
static UINT g_nMean = 0;
|
||||
static UINT g_nMin = 0xFFFFFFFF;
|
||||
static UINT g_nMax = 0;
|
||||
#endif
|
||||
|
||||
static __forceinline void DoIrqProfiling(DWORD uCycles)
|
||||
{
|
||||
@ -352,7 +354,9 @@ static __forceinline void NMI(ULONG& uExecutedCycles, UINT& uExtraCycles, BOOL&
|
||||
{
|
||||
// NMI signals are only serviced once
|
||||
g_bNmiFlank = FALSE;
|
||||
#ifdef _DEBUG
|
||||
g_nCycleIrqStart = g_nCumulativeCycles + uExecutedCycles;
|
||||
#endif
|
||||
PUSH(regs.pc >> 8)
|
||||
PUSH(regs.pc & 0xFF)
|
||||
EF_TO_AF
|
||||
@ -369,7 +373,9 @@ static __forceinline void IRQ(ULONG& uExecutedCycles, UINT& uExtraCycles, BOOL&
|
||||
if(g_bmIRQ && !(regs.ps & AF_INTERRUPT))
|
||||
{
|
||||
// IRQ signals are deasserted when a specific r/w operation is done on device
|
||||
#ifdef _DEBUG
|
||||
g_nCycleIrqStart = g_nCumulativeCycles + uExecutedCycles;
|
||||
#endif
|
||||
PUSH(regs.pc >> 8)
|
||||
PUSH(regs.pc & 0xFF)
|
||||
EF_TO_AF
|
||||
|
@ -45,7 +45,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
#include "Configuration\PropertySheet.h"
|
||||
|
||||
#define BUTTONTIME 5000 // TODO: Describe this magic number
|
||||
#define BUTTONTIME 5000 // This is the latch (debounce) time in usecs for the joystick buttons
|
||||
|
||||
enum {DEVICE_NONE=0, DEVICE_JOYSTICK, DEVICE_KEYBOARD, DEVICE_MOUSE};
|
||||
|
||||
@ -82,7 +82,7 @@ static POINT keyvalue[9] = {{PDL_MIN,PDL_MAX}, {PDL_CENTRAL,PDL_MAX}, {PDL
|
||||
{PDL_MIN,PDL_CENTRAL},{PDL_CENTRAL,PDL_CENTRAL},{PDL_MAX,PDL_CENTRAL},
|
||||
{PDL_MIN,PDL_MIN}, {PDL_CENTRAL,PDL_MIN}, {PDL_MAX,PDL_MIN}};
|
||||
|
||||
static DWORD buttonlatch[3] = {0,0,0};
|
||||
static int buttonlatch[3] = {0,0,0};
|
||||
static BOOL joybutton[3] = {0,0,0};
|
||||
|
||||
static int joyshrx[2] = {8,8};
|
||||
@ -703,11 +703,19 @@ void JoySetPosition(int xvalue, int xrange, int yvalue, int yrange)
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
void JoyUpdatePosition()
|
||||
|
||||
// Update the latch (debounce) time for each button
|
||||
void JoyUpdateButtonLatch(const UINT nExecutionPeriodUsec)
|
||||
{
|
||||
if (buttonlatch[0]) --buttonlatch[0];
|
||||
if (buttonlatch[1]) --buttonlatch[1];
|
||||
if (buttonlatch[2]) --buttonlatch[2];
|
||||
for (UINT i=0; i<3; i++)
|
||||
{
|
||||
if (buttonlatch[i])
|
||||
{
|
||||
buttonlatch[i] -= nExecutionPeriodUsec;
|
||||
if (buttonlatch[i] < 0)
|
||||
buttonlatch[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -15,7 +15,7 @@ void JoyReset();
|
||||
void JoySetButton(eBUTTON,eBUTTONSTATE);
|
||||
BOOL JoySetEmulationType(HWND,DWORD,int, const bool bMousecardActive);
|
||||
void JoySetPosition(int,int,int,int);
|
||||
void JoyUpdatePosition();
|
||||
void JoyUpdateButtonLatch(const UINT nExecutionPeriodUsec);
|
||||
BOOL JoyUsingMouse();
|
||||
BOOL JoyUsingKeyboard();
|
||||
BOOL JoyUsingKeyboardCursors();
|
||||
|
@ -479,7 +479,9 @@ BYTE __stdcall SpkrToggle (WORD, WORD, BYTE, BYTE, ULONG nCyclesLeft)
|
||||
if (lastcyclenum)
|
||||
{
|
||||
toggles++;
|
||||
DWORD delta = cyclenum-lastcyclenum;
|
||||
//DWORD delta = cyclenum-lastcyclenum; // [TC: 14/09/2014] Looks broken, since 'cyclenum' is cycles executed in previous call to CpuExecute()
|
||||
CpuCalcCycles(nCyclesLeft);
|
||||
DWORD delta = (DWORD)g_nCumulativeCycles - lastcyclenum;
|
||||
|
||||
// DETERMINE WHETHER WE ARE PLAYING A SOUND EFFECT
|
||||
if (directio &&
|
||||
@ -493,7 +495,8 @@ BYTE __stdcall SpkrToggle (WORD, WORD, BYTE, BYTE, ULONG nCyclesLeft)
|
||||
lastdelta[0] = delta;
|
||||
totaldelta += delta;
|
||||
}
|
||||
lastcyclenum = cyclenum;
|
||||
//lastcyclenum = cyclenum;
|
||||
lastcyclenum = (DWORD)g_nCumulativeCycles;
|
||||
|
||||
}
|
||||
|
||||
@ -610,7 +613,7 @@ void SpkrUpdate_Timer()
|
||||
nSamplesUsed = Spkr_SubmitWaveBuffer_FullSpeed(g_pSpeakerBuffer, g_nBufferIdx);
|
||||
|
||||
_ASSERT(nSamplesUsed <= g_nBufferIdx);
|
||||
memmove(g_pSpeakerBuffer, &g_pSpeakerBuffer[nSamplesUsed], g_nBufferIdx-nSamplesUsed); // FIXME-TC: _Size * 2
|
||||
memmove(g_pSpeakerBuffer, &g_pSpeakerBuffer[nSamplesUsed], g_nBufferIdx-nSamplesUsed); // FIXME-TC: _Size * 2 (GH#213?)
|
||||
g_nBufferIdx -= nSamplesUsed;
|
||||
}
|
||||
}
|
||||
|
@ -2106,7 +2106,7 @@ void VideoBenchmark () {
|
||||
DWORD executedcycles = CpuExecute(103);
|
||||
cycles -= executedcycles;
|
||||
DiskUpdatePosition(executedcycles);
|
||||
JoyUpdatePosition();
|
||||
JoyUpdateButtonLatch(executedcycles);
|
||||
}
|
||||
}
|
||||
if (cycle & 1)
|
||||
|
Loading…
Reference in New Issue
Block a user