diff --git a/fellow/SRC/WinFellow.Core.Tests/CustomChipset/RegistersUtilityTest.cpp b/fellow/SRC/WinFellow.Core.Tests/CustomChipset/RegistersUtilityTest.cpp index 30db33ba..a26c3d90 100644 --- a/fellow/SRC/WinFellow.Core.Tests/CustomChipset/RegistersUtilityTest.cpp +++ b/fellow/SRC/WinFellow.Core.Tests/CustomChipset/RegistersUtilityTest.cpp @@ -1,5 +1,5 @@ #include "catch/catch_amalgamated.hpp" -#include "Core.h" +#include "VirtualHost/Core.h" using namespace CustomChipset; diff --git a/fellow/SRC/WinFellow.Core/Core.cpp b/fellow/SRC/WinFellow.Core/Core.cpp deleted file mode 100644 index aefa7d19..00000000 --- a/fellow/SRC/WinFellow.Core/Core.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "Core.h" - -Core::Core() : - Registers(), - RegisterUtility(Registers) -{ -} - -Core::~Core() -{ -} diff --git a/fellow/SRC/WinFellow.Core/CustomChipset/Sound/Sound.h b/fellow/SRC/WinFellow.Core/CustomChipset/Sound/Sound.h new file mode 100644 index 00000000..f4b7bbc6 --- /dev/null +++ b/fellow/SRC/WinFellow.Core/CustomChipset/Sound/Sound.h @@ -0,0 +1,191 @@ +#pragma once + +/*=========================================================================*/ +/* Fellow */ +/* */ +/* Sound emulation */ +/* */ +/* Author: Petter Schau */ +/* */ +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2, or (at your option) */ +/* any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*=========================================================================*/ + +#include +#include "CustomChipset/Sound/SoundConfiguration.h" +#include "WavFileWriter.h" + +using namespace CustomChipset; + +constexpr uint32_t MAX_BUFFER_SAMPLES = 65536; + +class Sound +{ +private: + WavFileWriter _wavFileWriter; + + sound_emulations _emulation; + sound_rates _rate; + bool _isStereo; + bool _is16Bits; + bool _wavCapture; + sound_filters _filter; + sound_notifications _notification; + int _volume; + bool _deviceFound; + + /*===========================================================================*/ + /* Buffer data */ + /*===========================================================================*/ + + uint32_t _currentBuffer; + int16_t _left[2][MAX_BUFFER_SAMPLES], _right[2][MAX_BUFFER_SAMPLES]; /* Samplebuffer, 16-b.signed */ + uint32_t _bufferLength; /* Current buffer length in ms */ + uint32_t _bufferSampleCount; /* Current number of samples in the buffer */ + uint32_t _bufferSampleCountMax; /* Maximum capacity of the buffer */ + + /*===========================================================================*/ + /* Run-time data */ + /*===========================================================================*/ + + uint32_t audiocounter; /* Used in 22050/44100 to decide samples */ + uint32_t audioodd; /* Used for skipping samples in 22050 */ + uint32_t _framecounter; /* Count frames, and then play */ + uint32_t _scale; + + double _filterValue45 = 0.857270436755215389; // 7000 Hz at 45454 Hz samplingrate + double _filterValue33 = 0.809385175167476725; // 7000 Hz at 33100 Hz samplingrate + double _filterValue22 = 0.727523105310746957; // 7000 Hz at 22005 Hz samplingrate + double _filterValue15 = 0.639362082983339100; // 7000 Hz at 15650 Hz samplingrate + + double _amplitudeDiv45 = 7.035; + double _amplitudeDiv33 = 5.25; + double _amplitudeDiv22 = 3.67; + double _amplitudeDiv15 = 2.773; + double _lastRight = 0.0000000000; + double _lastLeft = 0.0000000000; + + /*===========================================================================*/ + /* Audio-registers */ + /*===========================================================================*/ + + uint32_t _audpt[4]; /* Sample-DMA pointer */ + uint32_t _audlen[4]; /* Length */ + uint32_t _audper[4]; /* Used directly, NOTE: translated value */ + uint32_t _audvol[4]; /* Volume, possibly not reloaded by state-machine */ + uint32_t _auddat[4]; /* Last data word set by DMA or CPU */ + bool _auddatSet[4]; /* Set TRUE whenever auddat is written */ + + /*===========================================================================*/ + /* Internal variables used by state-machine */ + /*===========================================================================*/ + + uint32_t _audlenw[4]; /* Length counter */ + uint32_t _audpercounter[4]; /* Period counter */ + uint32_t _auddatw[4]; /* Sample currently output, 16-bit signed */ + uint32_t _audstate[4]; /* Current state for the channel */ + uint32_t _audvolw[4]; /* Current volume, reloaded at some points */ + uint32_t _audptw[4]; /* Current dma-pointer, reloaded at some points */ + + /*===========================================================================*/ + /* Translation tables */ + /*===========================================================================*/ + + uint32_t _periodTable[65536]; + int16_t _volumes[256][64]; + uint32_t _audioIrqMask[4] = {0x0080, 0x0100, 0x0200, 0x0400}; + uint32_t _audioDmaconMask[4] = {0x1, 0x2, 0x4, 0x8}; + + uint32_t GetChannelNumber(uint32_t address); + + void ExecuteState(uint32_t channel); + void State0(uint32_t channel); + void State1(uint32_t channel); + void State2(uint32_t channel); + void State3(uint32_t channel); + void State4(uint32_t channel); + void State5(uint32_t channel); + void State6(uint32_t channel); + + void LowPass(uint32_t count, int16_t *bufferLeft, int16_t *bufferRight); + uint32_t ChannelUpdate(uint32_t channel, int16_t *bufferLeft, int16_t *bufferRight, uint32_t count, bool halfscale, bool odd); + void FrequencyHandler(); + + sound_rates GetRate(); + uint32_t GetRateReal(); + uint32_t GetBufferLength(); + int GetVolume(); + + void SetBufferSampleCount(uint32_t sampleCount); + uint32_t GetBufferSampleCount(); + void SetBufferSampleCountMax(uint32_t sampleCountMax); + uint32_t GetBufferSampleCountMax(); + void SetDeviceFound(bool deviceFound); + bool GetDeviceFound(); + void SetScale(uint32_t scale); + uint32_t GetScale(); + + void SetSampleVolume(uint8_t sampleIn, uint8_t volume, int16_t sampleOut); + int16_t GetSampleVolume(int8_t sampleIn, uint8_t volume); + void SetPeriodValue(uint32_t period, uint32_t value); + uint32_t GetPeriodValue(uint32_t period); + + void VolumeTableInitialize(bool isStereo); + void PeriodTableInitialize(uint32_t outputRate); + void PlaybackInitialize(); + + void IOHandlersInstall(); + void IORegistersClear(); + void CopyBufferOverrunToCurrentBuffer(uint32_t availableSamples, uint32_t previousBuffer); + +public: + void SetEmulation(sound_emulations emulation); + sound_emulations GetEmulation(); + void SetIsStereo(bool isStereo); + bool GetIsStereo(); + void SetIs16Bits(bool is16Bits); + bool GetIs16Bits(); + void SetFilter(sound_filters filter); + sound_filters GetFilter(); + void SetWAVDump(bool wavCapture); + bool GetWAVDump(); + void SetNotification(sound_notifications notification); + sound_notifications GetNotification(); + void SetRate(sound_rates rate); + void SetBufferLength(uint32_t ms); + + void ChannelKill(uint32_t channel); + void ChannelEnable(uint32_t channel); + + void SetAudXpth(uint16_t data, uint32_t address); + void SetAudXptl(uint16_t data, uint32_t address); + void SetAudXlen(uint16_t data, uint32_t address); + void SetAudXper(uint16_t data, uint32_t address); + void SetAudXvol(uint16_t data, uint32_t address); + void SetAudXdat(uint16_t data, uint32_t address); + + void SetVolume(int volume); + + void EndOfLine(); + void HardReset(); + void EmulationStart(); + void EmulationStop(); + void Startup(); + void Shutdown(); + + Sound(); + ~Sound(); +}; diff --git a/fellow/SRC/WinFellow.Core/CustomChipset/Sound/SoundConfiguration.h b/fellow/SRC/WinFellow.Core/CustomChipset/Sound/SoundConfiguration.h new file mode 100644 index 00000000..f4b23bf8 --- /dev/null +++ b/fellow/SRC/WinFellow.Core/CustomChipset/Sound/SoundConfiguration.h @@ -0,0 +1,9 @@ +#pragma once + +namespace CustomChipset +{ + typedef enum { SOUND_15650, SOUND_22050, SOUND_31300, SOUND_44100 } sound_rates; + typedef enum { SOUND_NONE, SOUND_PLAY, SOUND_EMULATE } sound_emulations; + typedef enum { SOUND_FILTER_ORIGINAL, SOUND_FILTER_ALWAYS, SOUND_FILTER_NEVER } sound_filters; + typedef enum { SOUND_DSOUND_NOTIFICATION, SOUND_MMTIMER_NOTIFICATION } sound_notifications; +} diff --git a/fellow/SRC/WinFellow.Core/CustomChipset/Sound/WavFileWriter.h b/fellow/SRC/WinFellow.Core/CustomChipset/Sound/WavFileWriter.h new file mode 100644 index 00000000..b117203d --- /dev/null +++ b/fellow/SRC/WinFellow.Core/CustomChipset/Sound/WavFileWriter.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include "CustomChipset/Sound/SoundConfiguration.h" + +class WavFileWriter +{ +private: + FILE *_wavFile; + char _filename[256]; + uint32_t _serial; + CustomChipset::sound_rates _rate; + uint32_t _rateReal; + bool _isStereo; + bool _is16Bits; + uint32_t _fileLength; + uint32_t _sampleCount; + + void Mono8BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount); + void Stereo8BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount); + void Mono16BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount); + void Stereo16BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount); + void HeaderWrite(); + void LengthUpdate(); + void FileInit(CustomChipset::sound_rates rate, bool is16Bits, bool isStereo, uint32_t sampleRate); + +public: + void Play(int16_t *left, int16_t *right, uint32_t sampleCount); + void EmulationStart(CustomChipset::sound_rates rate, bool is16Bits, bool isStereo, uint32_t sampleRate); + void EmulationStop(); + void Startup(); + void Shutdown(); + + WavFileWriter(); + ~WavFileWriter(); +}; diff --git a/fellow/SRC/WinFellow.Core/Driver/Drivers.h b/fellow/SRC/WinFellow.Core/Driver/Drivers.h new file mode 100644 index 00000000..a7f0218e --- /dev/null +++ b/fellow/SRC/WinFellow.Core/Driver/Drivers.h @@ -0,0 +1,8 @@ +#pragma once +#include "Driver/ISoundDriver.h" + +class Drivers +{ +public: + ISoundDriver* SoundDriver; +}; diff --git a/fellow/SRC/WinFellow.Core/Driver/ISoundDriver.h b/fellow/SRC/WinFellow.Core/Driver/ISoundDriver.h new file mode 100644 index 00000000..a7d96760 --- /dev/null +++ b/fellow/SRC/WinFellow.Core/Driver/ISoundDriver.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include "Driver/SoundDriverRuntimeConfiguration.h" + +class ISoundDriver +{ +public: + virtual void Play(int16_t *leftBuffer, int16_t *rightBuffer, uint32_t sampleCount) = 0; + virtual void PollBufferPosition() = 0; + virtual bool SetCurrentSoundDeviceVolume(int volume) = 0; + + virtual bool EmulationStart(SoundDriverRuntimeConfiguration runtimeConfiguration) = 0; + virtual void EmulationStop() = 0; + + virtual bool IsInitialized() = 0; + + ISoundDriver() = default; + virtual ~ISoundDriver() = default; +}; diff --git a/fellow/SRC/WinFellow.Core/Driver/SoundDriverRuntimeConfiguration.h b/fellow/SRC/WinFellow.Core/Driver/SoundDriverRuntimeConfiguration.h new file mode 100644 index 00000000..4f452f6e --- /dev/null +++ b/fellow/SRC/WinFellow.Core/Driver/SoundDriverRuntimeConfiguration.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include "CustomChipset/Sound/SoundConfiguration.h" + +struct SoundDriverRuntimeConfiguration +{ + CustomChipset::sound_emulations PlaybackMode; + CustomChipset::sound_rates PlaybackRate; + CustomChipset::sound_filters FilterMode; + CustomChipset::sound_notifications NotificationMode; + bool IsStereo; + bool Is16Bits; + int Volume; + uint32_t ActualSampleRate; + uint32_t MaximumBufferSampleCount; +}; diff --git a/fellow/SRC/WinFellow.Core/NullDriver/Sound/NullSound.cpp b/fellow/SRC/WinFellow.Core/NullDriver/Sound/NullSound.cpp new file mode 100644 index 00000000..0a1b69aa --- /dev/null +++ b/fellow/SRC/WinFellow.Core/NullDriver/Sound/NullSound.cpp @@ -0,0 +1,32 @@ +#include "NullSound.h" + +void NullSound::Play(int16_t *leftBuffer, int16_t *rightBuffer, uint32_t sampleCount) +{ +} + +void NullSound::PollBufferPosition() +{ +} + +bool NullSound::SetCurrentSoundDeviceVolume(int volume) +{ + return true; +} + +void NullSound::HardReset() +{ +} + +bool NullSound::EmulationStart(SoundDriverRuntimeConfiguration runtimeConfiguration) +{ + return true; +} + +void NullSound::EmulationStop() +{ +} + +bool NullSound::IsInitialized() +{ + return true; +} diff --git a/fellow/SRC/WinFellow.Core/NullDriver/Sound/NullSound.h b/fellow/SRC/WinFellow.Core/NullDriver/Sound/NullSound.h new file mode 100644 index 00000000..619a4424 --- /dev/null +++ b/fellow/SRC/WinFellow.Core/NullDriver/Sound/NullSound.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Driver/ISoundDriver.h" + +class NullSound : public ISoundDriver +{ +public: + void Play(int16_t* leftBuffer, int16_t* rightBuffer, uint32_t sampleCount) override; + void PollBufferPosition() override; + bool SetCurrentSoundDeviceVolume(int volume) override; + + void HardReset(); + bool EmulationStart(SoundDriverRuntimeConfiguration runtimeConfiguration) override; + void EmulationStop() override; + bool IsInitialized() override; + + NullSound() = default; + virtual ~NullSound() = default; +}; \ No newline at end of file diff --git a/fellow/SRC/WinFellow.Core/VirtualHost/Core.cpp b/fellow/SRC/WinFellow.Core/VirtualHost/Core.cpp new file mode 100644 index 00000000..93f0e6ab --- /dev/null +++ b/fellow/SRC/WinFellow.Core/VirtualHost/Core.cpp @@ -0,0 +1,12 @@ +#include "VirtualHost/Core.h" + +// For the time being this has to be a singleton +Core _core = Core(); + +Core::Core() : Registers(), RegisterUtility(Registers), Drivers() +{ +} + +Core::~Core() +{ +} diff --git a/fellow/SRC/WinFellow.Core/Core.h b/fellow/SRC/WinFellow.Core/VirtualHost/Core.h similarity index 65% rename from fellow/SRC/WinFellow.Core/Core.h rename to fellow/SRC/WinFellow.Core/VirtualHost/Core.h index 243fd102..b072e2f8 100644 --- a/fellow/SRC/WinFellow.Core/Core.h +++ b/fellow/SRC/WinFellow.Core/VirtualHost/Core.h @@ -1,5 +1,7 @@ #pragma once +#include "Driver/Drivers.h" +#include "CustomChipset/Sound/Sound.h" #include "CustomChipset/Registers.h" #include "CustomChipset/RegisterUtility.h" @@ -8,7 +10,12 @@ class Core public: CustomChipset::Registers Registers; CustomChipset::RegisterUtility RegisterUtility; + Drivers Drivers; + + Sound *Sound; Core(); ~Core(); }; + +extern Core _core; diff --git a/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj b/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj index dec61164..c09791d1 100644 --- a/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj +++ b/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj @@ -27,14 +27,22 @@ - + + + + + + + + - + + 17.0 diff --git a/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj.filters b/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj.filters index ddcca0d3..8dbffcfc 100644 --- a/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj.filters +++ b/fellow/SRC/WinFellow.Core/WinFellow.Core.vcxproj.filters @@ -4,23 +4,66 @@ {f111653b-f438-4cdf-b795-9e0d0d94046e} + + {bed135ae-c425-4693-bf9c-910120ca8a7c} + + + {1dbf3373-7ddb-4fe4-bf8d-f24b1431a434} + + + {b47fa094-e13d-4cc1-8ac8-0e00113219af} + + + {852a5a3f-973b-4671-908d-06a2252bd18e} + + + {29b4dd9a-9e1c-4a2c-b6c7-80ed23d761f9} + - CustomChipset CustomChipset + + Driver + + + Driver + + + NullDriver\Sound + + + CustomChipset\Sound + + + Driver + + + VirtualHost + + + CustomChipset\Sound + + + CustomChipset\Sound + - CustomChipset CustomChipset + + NullDriver\Sound + + + VirtualHost + \ No newline at end of file diff --git a/fellow/SRC/WinFellow.Hardfile.Tests/WinFellow.Hardfile.Tests.vcxproj b/fellow/SRC/WinFellow.Hardfile.Tests/WinFellow.Hardfile.Tests.vcxproj index eb8be752..8b0acd9e 100644 --- a/fellow/SRC/WinFellow.Hardfile.Tests/WinFellow.Hardfile.Tests.vcxproj +++ b/fellow/SRC/WinFellow.Hardfile.Tests/WinFellow.Hardfile.Tests.vcxproj @@ -154,7 +154,7 @@ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - xcopy testdata\* $(OutDir)\testdata\ /S /D /R /Y + xcopy testdata\* "$(OutDir)testdata\" /S /D /R /Y @@ -184,7 +184,7 @@ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - xcopy testdata\* $(OutDir)\testdata\ /S /D /R /Y + xcopy testdata\* "$(OutDir)testdata\" /S /D /R /Y @@ -250,7 +250,7 @@ UseLinkTimeCodeGeneration - xcopy testdata\* $(OutDir)\testdata\ /S /D /R /Y + xcopy testdata\* "$(OutDir)testdata\" /S /D /R /Y @@ -285,7 +285,7 @@ UseLinkTimeCodeGeneration - xcopy testdata\* $(OutDir)\testdata\ /S /D /R /Y + xcopy testdata\* "$(OutDir)testdata\" /S /D /R /Y diff --git a/fellow/SRC/WinFellow/C/BLIT.C b/fellow/SRC/WinFellow/C/BLIT.C index 7887043d..1840a520 100644 --- a/fellow/SRC/WinFellow/C/BLIT.C +++ b/fellow/SRC/WinFellow/C/BLIT.C @@ -19,7 +19,7 @@ #include "CpuIntegration.h" #include "chipset.h" #include "interrupt.h" -#include "CoreHost.h" +#include "VirtualHost/Core.h" using namespace CustomChipset; @@ -205,7 +205,7 @@ void blitterOperationLog() { if (F) { fprintf(F, "%.7d\t%.3d\t%.3d\t%.4X\t%.4X\t%.4X\t%.4X\t%.6X\t%.6X\t%.6X\t%.6X\t%.4X\t%.4X\t%.4X\t%.4X\t%.4X\t%.4X\t%.4X\t%d\t%d\n", - draw_frame_count, busGetRasterY(), busGetRasterX(), (blitter.bltcon >> 16) & 0xffff, blitter.bltcon & 0xffff, blitter.bltafwm & 0xffff, blitter.bltalwm & 0xffff, blitter.bltapt, blitter.bltbpt, blitter.bltcpt, blitter.bltdpt, blitter.bltamod & 0xffff, blitter.bltbmod & 0xffff, blitter.bltcmod & 0xffff, blitter.bltdmod & 0xffff, blitter.bltadat & 0xffff, blitter.bltbdat & 0xffff, blitter.bltcdat & 0xffff, blitter.height, blitter.width); + draw_frame_count, busGetRasterY(), busGetRasterX(), (blitter.bltcon >> 16) & 0xffff, blitter.bltcon & 0xffff, blitter.bltafwm & 0xffff, blitter.bltalwm & 0xffff, blitter.bltapt, blitter.bltbpt, blitter.bltcpt, blitter.bltdpt, blitter.bltamod & 0xffff, blitter.bltbmod & 0xffff, blitter.bltcmod & 0xffff, blitter.bltdmod & 0xffff, blitter.bltadat & 0xffff, blitter.bltbdat & 0xffff, blitter.bltcdat & 0xffff, blitter.height, blitter.width); fclose(F); } } @@ -1132,14 +1132,14 @@ void blitterLineMode() { if (blitter.bltcon & 0x00000002) { - if (single_dot) - { - bltadat_local = 0; - } - else - { - single_dot = TRUE; - } + if (single_dot) + { + bltadat_local = 0; + } + else + { + single_dot = TRUE; + } } } @@ -1180,26 +1180,26 @@ void blitterLineMode() if (!x_independent) { - if (x_inc) - { - blitterLineIncreaseX(blit_a_shift_local, bltcpt_local); - } - else - { - blitterLineDecreaseX(blit_a_shift_local, bltcpt_local); - } + if (x_inc) + { + blitterLineIncreaseX(blit_a_shift_local, bltcpt_local); + } + else + { + blitterLineDecreaseX(blit_a_shift_local, bltcpt_local); + } } else { - if (y_inc) - { - blitterLineIncreaseY(bltcpt_local, blitter.bltcmod); - } - else - { - blitterLineDecreaseY(bltcpt_local, blitter.bltcmod); - } - single_dot = FALSE; + if (y_inc) + { + blitterLineIncreaseY(bltcpt_local, blitter.bltcmod); + } + else + { + blitterLineDecreaseY(bltcpt_local, blitter.bltcmod); + } + single_dot = FALSE; } } decision_is_signed = ((int16_t)decision_variable < 0); @@ -1209,22 +1209,22 @@ void blitterLineMode() // decrease/increase y if (y_inc) { - blitterLineIncreaseY(bltcpt_local, blitter.bltcmod); + blitterLineIncreaseY(bltcpt_local, blitter.bltcmod); } else { - blitterLineDecreaseY(bltcpt_local, blitter.bltcmod); + blitterLineDecreaseY(bltcpt_local, blitter.bltcmod); } } else { if (x_inc) { - blitterLineIncreaseX(blit_a_shift_local, bltcpt_local); + blitterLineIncreaseX(blit_a_shift_local, bltcpt_local); } else { - blitterLineDecreaseX(blit_a_shift_local, bltcpt_local); + blitterLineDecreaseX(blit_a_shift_local, bltcpt_local); } } bltdpt_local = bltcpt_local; @@ -1803,16 +1803,16 @@ static void blitterFillTableInit() for (fc = 0; fc < 2; fc++) for (i = 0; i < 256; i++) { - fc_tmp = fc; - data = i; - for (bit = 0; bit < 8; bit++) - { - if (mode == 0) data |= fc_tmp << bit; - else data ^= fc_tmp << bit; - if ((i & (0x1 << bit))) fc_tmp = (fc_tmp == 1) ? 0 : 1; - } - blit_fill[mode][fc][i][0] = (uint8_t)fc_tmp; - blit_fill[mode][fc][i][1] = (uint8_t)data; + fc_tmp = fc; + data = i; + for (bit = 0; bit < 8; bit++) + { + if (mode == 0) data |= fc_tmp << bit; + else data ^= fc_tmp << bit; + if ((i & (0x1 << bit))) fc_tmp = (fc_tmp == 1) ? 0 : 1; + } + blit_fill[mode][fc][i][0] = (uint8_t)fc_tmp; + blit_fill[mode][fc][i][1] = (uint8_t)data; } } @@ -2007,8 +2007,8 @@ void verifyMinterms() char s[40]; for (a_dat = 0; a_dat < 256; a_dat++) for (b_dat = 0; b_dat < 256; b_dat++) - for (c_dat = 0; c_dat < 256; c_dat++) - minterm_had_error |= (correctMinterms(minterm, a_dat, b_dat, c_dat) != optimizedMinterms(minterm, a_dat, b_dat, c_dat)); + for (c_dat = 0; c_dat < 256; c_dat++) + minterm_had_error |= (correctMinterms(minterm, a_dat, b_dat, c_dat) != optimizedMinterms(minterm, a_dat, b_dat, c_dat)); if (minterm_had_error) { sprintf(s, "Minterm %X was %s", minterm, (minterm_had_error) ? "incorrect" : "correct"); diff --git a/fellow/SRC/WinFellow/C/BUS.C b/fellow/SRC/WinFellow/C/BUS.C index 4b8216da..3ab779a6 100644 --- a/fellow/SRC/WinFellow/C/BUS.C +++ b/fellow/SRC/WinFellow/C/BUS.C @@ -34,8 +34,6 @@ #include "graph.h" #include "floppy.h" #include "kbd.h" -#include "sound.h" -#include "kbd.h" #include "sprite.h" #include "timer.h" #include "draw.h" @@ -76,7 +74,7 @@ void busEndOfLine() /* Handles graphics planar to chunky conversion */ /* and updates the graphics emulation for a new line */ /*==============================================================*/ - graphEndOfLine(); + graphEndOfLine(); spriteEndOfLine(busGetRasterY()); /*==============================================================*/ @@ -92,7 +90,7 @@ void busEndOfLine() /*==============================================================*/ /* Update the sound emulation */ /*==============================================================*/ - soundEndOfLine(); + _core.Sound->EndOfLine(); /*==============================================================*/ /* Handle keyboard events */ @@ -120,15 +118,13 @@ void busEndOfFrame() /*==============================================================*/ /* Draw the frame in the host buffer */ /*==============================================================*/ - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_LINEEXACT) - drawEndOfFrame(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_LINEEXACT) drawEndOfFrame(); - /*==============================================================*/ - /* Handle keyboard events */ - /*==============================================================*/ + /*==============================================================*/ + /* Handle keyboard events */ + /*==============================================================*/ #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) - kbdDrvEOFHandler(); + if (RP.GetHeadlessMode()) kbdDrvEOFHandler(); #endif kbdEventEOFHandler(); @@ -201,8 +197,7 @@ void busEndOfFrame() eolEvent.cycle = busGetCyclesInThisLine() - 1; busInsertEventWithNullCheck(&eolEvent); - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.EndOfFrame(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.EndOfFrame(); automator.EndOfFrame(); @@ -214,7 +209,7 @@ void busEndOfFrame() void busRemoveEvent(bus_event *ev) { BOOLE found = FALSE; - for (bus_event* tmp = bus.events; tmp != nullptr; tmp = tmp->next) + for (bus_event *tmp = bus.events; tmp != nullptr; tmp = tmp->next) { if (tmp == ev) { @@ -255,15 +250,17 @@ void busInsertEventWithNullCheck(bus_event *ev) void busInsertEvent(bus_event *ev) { bus_event *tmp_prev = nullptr; - for (bus_event* tmp = bus.events; tmp != nullptr; tmp = tmp->next) + for (bus_event *tmp = bus.events; tmp != nullptr; tmp = tmp->next) { - if (ev->cycle < tmp->cycle) + if (ev->cycle < tmp->cycle) { ev->next = tmp; ev->prev = tmp_prev; tmp->prev = ev; - if (tmp_prev == nullptr) bus.events = ev; /* In front */ - else tmp_prev->next = ev; + if (tmp_prev == nullptr) + bus.events = ev; /* In front */ + else + tmp_prev->next = ev; return; } tmp_prev = tmp; @@ -281,7 +278,6 @@ bus_event *busPopEvent() return tmp; } - #ifdef ENABLE_BUS_EVENT_LOGGING FILE *BUSLOG = NULL; @@ -377,24 +373,24 @@ void busRun68000Fast() { while (!fellow_request_emulation_stop) { - while (bus.events->cycle >= cpuEvent.cycle) - { + while (bus.events->cycle >= cpuEvent.cycle) + { #ifdef ENABLE_BUS_EVENT_LOGGING - busEventLog(&cpuEvent); + busEventLog(&cpuEvent); #endif - busSetCycle(cpuEvent.cycle); - cpuIntegrationExecuteInstructionEventHandler68000Fast(); - } - do - { - bus_event *e = busPopEvent(); + busSetCycle(cpuEvent.cycle); + cpuIntegrationExecuteInstructionEventHandler68000Fast(); + } + do + { + bus_event *e = busPopEvent(); #ifdef ENABLE_BUS_EVENT_LOGGING - busEventLog(e); + busEventLog(e); #endif - busSetCycle(e->cycle); - e->handler(); - } while (bus.events->cycle < cpuEvent.cycle && !fellow_request_emulation_stop); + busSetCycle(e->cycle); + e->handler(); + } while (bus.events->cycle < cpuEvent.cycle && !fellow_request_emulation_stop); } } else @@ -415,24 +411,24 @@ void busRunGeneric() { while (!fellow_request_emulation_stop) { - while (bus.events->cycle >= cpuEvent.cycle) - { + while (bus.events->cycle >= cpuEvent.cycle) + { #ifdef ENABLE_BUS_EVENT_LOGGING - busEventLog(&cpuEvent); + busEventLog(&cpuEvent); #endif - busSetCycle(cpuEvent.cycle); - cpuEvent.handler(); - } - do - { - bus_event *e = busPopEvent(); + busSetCycle(cpuEvent.cycle); + cpuEvent.handler(); + } + do + { + bus_event *e = busPopEvent(); #ifdef ENABLE_BUS_EVENT_LOGGING - busEventLog(e); + busEventLog(e); #endif - busSetCycle(e->cycle); - e->handler(); - } while (bus.events->cycle < cpuEvent.cycle && !fellow_request_emulation_stop); + busSetCycle(e->cycle); + e->handler(); + } while (bus.events->cycle < cpuEvent.cycle && !fellow_request_emulation_stop); } } else @@ -450,8 +446,7 @@ busRunHandlerFunc busGetRunHandler() { if (cpuGetModelMajor() <= 1) { - if (cpuIntegrationGetSpeed() == 4) - return busRun68000Fast; + if (cpuIntegrationGetSpeed() == 4) return busRun68000Fast; } return busRunGeneric; } @@ -470,25 +465,25 @@ void busDebugStepOneInstruction() { while (!fellow_request_emulation_stop) { - if (bus.events->cycle >= cpuEvent.cycle) - { + if (bus.events->cycle >= cpuEvent.cycle) + { #ifdef ENABLE_BUS_EVENT_LOGGING - busEventLog(&cpuEvent); + busEventLog(&cpuEvent); #endif - busSetCycle(cpuEvent.cycle); - cpuEvent.handler(); - return; - } - do - { - bus_event *e = busPopEvent(); + busSetCycle(cpuEvent.cycle); + cpuEvent.handler(); + return; + } + do + { + bus_event *e = busPopEvent(); #ifdef ENABLE_BUS_EVENT_LOGGING - busEventLog(e); + busEventLog(e); #endif - busSetCycle(e->cycle); - e->handler(); - } while (bus.events->cycle < cpuEvent.cycle && !fellow_request_emulation_stop); + busSetCycle(e->cycle); + e->handler(); + } while (bus.events->cycle < cpuEvent.cycle && !fellow_request_emulation_stop); } } else @@ -508,10 +503,12 @@ void busClearEvent(bus_event *ev, busEventHandler handlerFunc) ev->handler = handlerFunc; } -void busDetermineCpuInstructionEventHandler() { - if (cpuGetModelMajor() <= 1) { +void busDetermineCpuInstructionEventHandler() +{ + if (cpuGetModelMajor() <= 1) + { if (cpuIntegrationGetSpeed() == 4) - cpuEvent.handler = cpuIntegrationExecuteInstructionEventHandler68000Fast; + cpuEvent.handler = cpuIntegrationExecuteInstructionEventHandler68000Fast; else cpuEvent.handler = cpuIntegrationExecuteInstructionEventHandler68000General; } @@ -549,7 +546,7 @@ void busInitializePalLongFrame() pal_long_frame.max_cycles_in_line = 227; pal_long_frame.lines_in_this_frame = 313; pal_long_frame.max_lines_in_frame = 314; - pal_long_frame.cycles_in_this_frame = 313*227; + pal_long_frame.cycles_in_this_frame = 313 * 227; } void busInitializePalShortFrame() { @@ -557,7 +554,7 @@ void busInitializePalShortFrame() pal_short_frame.max_cycles_in_line = 227; pal_short_frame.lines_in_this_frame = 312; pal_short_frame.max_lines_in_frame = 314; - pal_short_frame.cycles_in_this_frame = 312*227; + pal_short_frame.cycles_in_this_frame = 312 * 227; } void busInitializeScreenLimits() diff --git a/fellow/SRC/WinFellow/C/CONFIG.C b/fellow/SRC/WinFellow/C/CONFIG.C index 673d3a5f..a4a47221 100644 --- a/fellow/SRC/WinFellow/C/CONFIG.C +++ b/fellow/SRC/WinFellow/C/CONFIG.C @@ -34,13 +34,11 @@ #include "floppy.h" #include "fmem.h" #include "gameport.h" -#include "sound.h" #include "graph.h" #include "draw.h" #include "blit.h" #include "fellow.h" #include "ListTree.h" -#include "eventid.h" #include "fswrap.h" #include "config.h" #include "fellow/api/module/IHardfileHandler.h" @@ -55,10 +53,12 @@ #include "KBDDRV.H" #include "../automation/Automator.h" +#include "VirtualHost/Core.h" using namespace fellow::api::module; +using namespace CustomChipset; -ini *cfg_initdata; /* CONFIG copy of initialization data */ +ini *cfg_initdata; /* CONFIG copy of initialization data */ /*============================================================================*/ /* The actual cfgManager instance */ @@ -66,7 +66,6 @@ ini *cfg_initdata; /* CONFIG copy of initialization data */ cfgManager cfg_manager; - /*============================================================================*/ /* Configuration */ /*============================================================================*/ @@ -91,20 +90,19 @@ char *cfgGetDescription(cfg *config) return config->m_description; } - /*============================================================================*/ /* Floppy disk configuration property access */ /*============================================================================*/ void cfgSetDiskImage(cfg *config, uint32_t index, char *diskimage) { - if (index < 4) + if (index < 4) { strncpy(&(config->m_diskimage[index][0]), diskimage, CFG_FILENAME_LENGTH); } } -char *cfgGetDiskImage(cfg *config, uint32_t index) +char *cfgGetDiskImage(cfg *config, uint32_t index) { if (index < 4) { @@ -159,7 +157,8 @@ BOOLE cfgGetDiskFast(cfg *config) void cfgSetLastUsedDiskDir(cfg *config, char *directory) { - if(directory != nullptr) { + if (directory != nullptr) + { strncpy(config->m_lastuseddiskdir, directory, CFG_FILENAME_LENGTH); } } @@ -169,7 +168,6 @@ char *cfgGetLastUsedDiskDir(cfg *config) return config->m_lastuseddiskdir; } - /*============================================================================*/ /* Memory configuration property access */ /*============================================================================*/ @@ -397,7 +395,6 @@ DISPLAYDRIVER cfgGetDisplayDriver(cfg *config) return config->m_displaydriver; } - /*===========================================================================*/ /* Graphics emulation configuration property access */ /*===========================================================================*/ @@ -492,72 +489,71 @@ GRAPHICSEMULATIONMODE cfgGetGraphicsEmulationMode(cfg *config) return config->m_graphicsemulationmode; } - /*============================================================================*/ /* Sound configuration property access */ /*============================================================================*/ -void cfgSetSoundEmulation(cfg *config, sound_emulations soundemulation) +void cfgSetSoundEmulation(cfg *config, sound_emulations soundemulation) { config->m_soundemulation = soundemulation; } -sound_emulations cfgGetSoundEmulation(cfg *config) +sound_emulations cfgGetSoundEmulation(cfg *config) { return config->m_soundemulation; } -void cfgSetSoundRate(cfg *config, sound_rates soundrate) +void cfgSetSoundRate(cfg *config, sound_rates soundrate) { config->m_soundrate = soundrate; } -sound_rates cfgGetSoundRate(cfg *config) +sound_rates cfgGetSoundRate(cfg *config) { return config->m_soundrate; } -void cfgSetSoundStereo(cfg *config, bool soundstereo) +void cfgSetSoundStereo(cfg *config, bool soundstereo) { config->m_soundstereo = soundstereo; } -bool cfgGetSoundStereo(cfg *config) +bool cfgGetSoundStereo(cfg *config) { return config->m_soundstereo; } -void cfgSetSound16Bits(cfg *config, bool sound16bits) +void cfgSetSound16Bits(cfg *config, bool sound16bits) { config->m_sound16bits = sound16bits; } -bool cfgGetSound16Bits(cfg *config) +bool cfgGetSound16Bits(cfg *config) { return config->m_sound16bits; } -void cfgSetSoundFilter(cfg *config, sound_filters soundfilter) +void cfgSetSoundFilter(cfg *config, sound_filters soundfilter) { config->m_soundfilter = soundfilter; } -sound_filters cfgGetSoundFilter(cfg *config) +sound_filters cfgGetSoundFilter(cfg *config) { return config->m_soundfilter; } -void cfgSetSoundVolume(cfg *config, const uint32_t soundvolume) +void cfgSetSoundVolume(cfg *config, const uint32_t soundvolume) { config->m_soundvolume = soundvolume; } -uint32_t cfgGetSoundVolume(cfg *config) +uint32_t cfgGetSoundVolume(cfg *config) { return config->m_soundvolume; } -void cfgSetSoundWAVDump(cfg *config, BOOLE soundWAVdump) +void cfgSetSoundWAVDump(cfg *config, BOOLE soundWAVdump) { config->m_soundWAVdump = soundWAVdump; } @@ -611,7 +607,6 @@ uint32_t cfgGetCPUSpeed(cfg *config) return config->m_CPUspeed; } - /*============================================================================*/ /* Custom chipset configuration property access */ /*============================================================================*/ @@ -666,7 +661,7 @@ void cfgHardfileRemove(cfg *config, uint32_t index) } free(listNode(node)); listFree(node); -} +} void cfgHardfilesFree(cfg *config) { @@ -691,7 +686,6 @@ void cfgHardfileChange(cfg *config, cfg_hardfile *hardfile, uint32_t index) *hf = *hardfile; } - /*============================================================================*/ /* Filesystem configuration property access */ /*============================================================================*/ @@ -753,14 +747,15 @@ BOOLE cfgGetFilesystemAutomountDrives(cfg *config) return config->m_automount_drives; } -void cfgSetFilesystemDeviceNamePrefix(cfg* config, char* prefix) +void cfgSetFilesystemDeviceNamePrefix(cfg *config, char *prefix) { - if (prefix != nullptr) { + if (prefix != nullptr) + { strncpy(config->m_filesystem_device_name_prefix, prefix, CFG_FILENAME_LENGTH); } } -char* cfgGetFilesystemDeviceNamePrefix(cfg* config) +char *cfgGetFilesystemDeviceNamePrefix(cfg *config) { return config->m_filesystem_device_name_prefix; } @@ -786,7 +781,6 @@ gameport_inputs cfgGetGameport(cfg *config, uint32_t index) return GP_NONE; } - /*============================================================================*/ /* GUI configuration property access */ /*============================================================================*/ @@ -801,7 +795,6 @@ bool cfgGetUseGUI(cfg *config) return config->m_useGUI; } - /*============================================================================*/ /* Various configuration property access */ /*============================================================================*/ @@ -822,7 +815,7 @@ bool cfgGetMeasureSpeed(cfg *config) void cfgSetDefaults(cfg *config) { - if(config == nullptr) return; + if (config == nullptr) return; /*==========================================================================*/ /* Default configuration version and description */ @@ -872,7 +865,7 @@ void cfgSetDefaults(cfg *config) cfgSetScreenDrawLEDs(config, true); cfgSetDeinterlace(config, true); cfgSetDisplayDriver(config, DISPLAYDRIVER_DIRECTDRAW); -// cfgSetDisplayDriver(config, DISPLAYDRIVER_DIRECT3D11); + // cfgSetDisplayDriver(config, DISPLAYDRIVER_DIRECT3D11); /*==========================================================================*/ /* Default graphics emulation configuration */ @@ -908,7 +901,6 @@ void cfgSetDefaults(cfg *config) cfgSetCPUType(config, M68000); cfgSetCPUSpeed(config, 4); - /*==========================================================================*/ /* Default custom chipset configuration */ /*==========================================================================*/ @@ -916,14 +908,12 @@ void cfgSetDefaults(cfg *config) cfgSetBlitterFast(config, FALSE); cfgSetECS(config, false); - /*==========================================================================*/ /* Default hardfile configuration */ /*==========================================================================*/ cfgHardfilesFree(config); - /*==========================================================================*/ /* Default filesystem configuration */ /*==========================================================================*/ @@ -932,7 +922,6 @@ void cfgSetDefaults(cfg *config) cfgSetFilesystemAutomountDrives(config, FALSE); cfgSetFilesystemDeviceNamePrefix(config, "FS"); - /*==========================================================================*/ /* Default game port configuration */ /*==========================================================================*/ @@ -940,14 +929,12 @@ void cfgSetDefaults(cfg *config) cfgSetGameport(config, 0, GP_MOUSE0); cfgSetGameport(config, 1, GP_NONE); - /*==========================================================================*/ /* Default GUI configuration */ /*==========================================================================*/ cfgSetUseGUI(config, true); - /*==========================================================================*/ /* Default various configuration */ /*==========================================================================*/ @@ -958,7 +945,6 @@ void cfgSetDefaults(cfg *config) cfgSetConfigChangedSinceLastSave(config, FALSE); } - /*============================================================================*/ /* Read specific options from a string */ /* These verify the options, or at least return a default value on error */ @@ -1018,8 +1004,8 @@ static char *cfgGetGameportToString(gameport_inputs gameport) { switch (gameport) { - case GP_NONE: return "none"; - case GP_MOUSE0: return "mouse"; + case GP_NONE: return "none"; + case GP_MOUSE0: return "mouse"; case GP_ANALOG0: return "joy0"; case GP_ANALOG1: return "joy1"; case GP_JOYKEY0: return "kbd1"; @@ -1044,7 +1030,7 @@ static cpu_integration_models cfgGetCPUTypeFromString(char *value) } if (stricmp(value, "68020/68881") == 0) { - return M68020; /* Unsupp */ + return M68020; /* Unsupp */ } if (stricmp(value, "68ec20") == 0) { @@ -1069,11 +1055,11 @@ static char *cfgGetCPUTypeToString(cpu_integration_models cputype) { switch (cputype) { - case M68000: return "68000"; - case M68010: return "68010"; - case M68020: return "68020"; + case M68000: return "68000"; + case M68010: return "68010"; + case M68020: return "68020"; case M68EC20: return "68ec20"; - case M68030: return "68030"; + case M68030: return "68030"; case M68EC30: return "68ec30"; } return "68000"; @@ -1114,7 +1100,7 @@ static char *cfgGetSoundNotificationToString(sound_notifications soundnotificati { switch (soundnotification) { - case SOUND_DSOUND_NOTIFICATION: return "directsound"; + case SOUND_DSOUND_NOTIFICATION: return "directsound"; case SOUND_MMTIMER_NOTIFICATION: return "mmtimer"; } return "mmtimer"; @@ -1130,10 +1116,7 @@ static sound_emulations cfgGetSoundEmulationFromString(char *value) { return SOUND_EMULATE; } - if (stricmp(value, "normal") == 0 || - stricmp(value, "exact") == 0 || - stricmp(value, "good") == 0 || - stricmp(value, "best") == 0) + if (stricmp(value, "normal") == 0 || stricmp(value, "exact") == 0 || stricmp(value, "good") == 0 || stricmp(value, "best") == 0) { return SOUND_PLAY; } @@ -1144,24 +1127,20 @@ static char *cfgGetSoundEmulationToString(sound_emulations soundemulation) { switch (soundemulation) { - case SOUND_NONE: return "none"; + case SOUND_NONE: return "none"; case SOUND_EMULATE: return "interrupts"; - case SOUND_PLAY: return "normal"; + case SOUND_PLAY: return "normal"; } return "none"; } static bool cfgGetSoundStereoFromString(char *value) { - if (stricmp(value, "mono") == 0 || - stricmp(value, "m") == 0 || - stricmp(value, "1") == 0) + if (stricmp(value, "mono") == 0 || stricmp(value, "m") == 0 || stricmp(value, "1") == 0) { return false; } - if ((stricmp(value, "stereo") == 0) || - (stricmp(value, "s") == 0) || - (stricmp(value, "2") == 0)) + if ((stricmp(value, "stereo") == 0) || (stricmp(value, "s") == 0) || (stricmp(value, "2") == 0)) { return true; } @@ -1235,9 +1214,9 @@ static char *cfgGetSoundFilterToString(sound_filters filter) { switch (filter) { - case SOUND_FILTER_NEVER: return "never"; + case SOUND_FILTER_NEVER: return "never"; case SOUND_FILTER_ORIGINAL: return "original"; - case SOUND_FILTER_ALWAYS: return "always"; + case SOUND_FILTER_ALWAYS: return "always"; } return "original"; } @@ -1282,15 +1261,15 @@ static DISPLAYSCALE cfgGetDisplayScaleFromString(char *value) return DISPLAYSCALE_1X; // Default } -static char* cfgGetDisplayScaleToString(DISPLAYSCALE displayscale) +static char *cfgGetDisplayScaleToString(DISPLAYSCALE displayscale) { switch (displayscale) { case DISPLAYSCALE_AUTO: return "auto"; - case DISPLAYSCALE_1X: return "single"; - case DISPLAYSCALE_2X: return "double"; - case DISPLAYSCALE_3X: return "triple"; - case DISPLAYSCALE_4X: return "quadruple"; + case DISPLAYSCALE_1X: return "single"; + case DISPLAYSCALE_2X: return "double"; + case DISPLAYSCALE_3X: return "triple"; + case DISPLAYSCALE_4X: return "quadruple"; } return "single"; } @@ -1312,10 +1291,8 @@ static char *cfgGetDisplayDriverToString(DISPLAYDRIVER displaydriver) { switch (displaydriver) { - case DISPLAYDRIVER_DIRECTDRAW: - return "directdraw"; - case DISPLAYDRIVER_DIRECT3D11: - return "direct3d11"; + case DISPLAYDRIVER_DIRECTDRAW: return "directdraw"; + case DISPLAYDRIVER_DIRECT3D11: return "direct3d11"; } return "directdraw"; } @@ -1333,7 +1310,7 @@ static DISPLAYSCALE_STRATEGY cfgGetDisplayScaleStrategyFromString(char *value) return DISPLAYSCALE_STRATEGY_SOLID; // Default } -static char* cfgGetDisplayScaleStrategyToString(DISPLAYSCALE_STRATEGY displayscalestrategy) +static char *cfgGetDisplayScaleStrategyToString(DISPLAYSCALE_STRATEGY displayscalestrategy) { switch (displayscalestrategy) { @@ -1345,28 +1322,23 @@ static char* cfgGetDisplayScaleStrategyToString(DISPLAYSCALE_STRATEGY displaysca static uint32_t cfgGetColorBitsFromString(char *value) { - if ((stricmp(value, "8bit") == 0) || - (stricmp(value, "8") == 0)) + if ((stricmp(value, "8bit") == 0) || (stricmp(value, "8") == 0)) { return 16; // Fallback to 16 bits, 8 bit support is removed } - if ((stricmp(value, "15bit") == 0) || - (stricmp(value, "15") == 0)) + if ((stricmp(value, "15bit") == 0) || (stricmp(value, "15") == 0)) { return 15; } - if ((stricmp(value, "16bit") == 0) || - (stricmp(value, "16") == 0)) + if ((stricmp(value, "16bit") == 0) || (stricmp(value, "16") == 0)) { return 16; } - if ((stricmp(value, "24bit") == 0) || - (stricmp(value, "24") == 0)) + if ((stricmp(value, "24bit") == 0) || (stricmp(value, "24") == 0)) { return 24; } - if ((stricmp(value, "32bit") == 0) || - (stricmp(value, "32") == 0)) + if ((stricmp(value, "32bit") == 0) || (stricmp(value, "32") == 0)) { return 32; } @@ -1386,18 +1358,12 @@ static char *cfgGetColorBitsToString(uint32_t colorbits) static bool cfgGetECSFromString(char *value) { - if ((stricmp(value, "ocs") == 0) || - (stricmp(value, "0") == 0)) + if ((stricmp(value, "ocs") == 0) || (stricmp(value, "0") == 0)) { return false; } - if ((stricmp(value, "ecs agnes") == 0) || - (stricmp(value, "ecs denise") == 0) || - (stricmp(value, "ecs") == 0) || - (stricmp(value, "aga") == 0) || - (stricmp(value, "2") == 0) || - (stricmp(value, "3") == 0) || - (stricmp(value, "4") == 0)) + if ((stricmp(value, "ecs agnes") == 0) || (stricmp(value, "ecs denise") == 0) || (stricmp(value, "ecs") == 0) || (stricmp(value, "aga") == 0) || + (stricmp(value, "2") == 0) || (stricmp(value, "3") == 0) || (stricmp(value, "4") == 0)) { return true; } @@ -1409,19 +1375,23 @@ static const char *cfgGetECSToString(bool chipset_ecs) return (chipset_ecs) ? "ecs" : "ocs"; } -void cfgSetConfigAppliedOnce(cfg *config, BOOLE bApplied) { +void cfgSetConfigAppliedOnce(cfg *config, BOOLE bApplied) +{ config->m_config_applied_once = bApplied; } -BOOLE cfgGetConfigAppliedOnce(cfg *config) { +BOOLE cfgGetConfigAppliedOnce(cfg *config) +{ return config->m_config_applied_once; } -void cfgSetConfigChangedSinceLastSave(cfg *config, BOOLE bChanged) { +void cfgSetConfigChangedSinceLastSave(cfg *config, BOOLE bChanged) +{ config->m_config_changed_since_save = bChanged; } -BOOLE cfgGetConfigChangedSinceLastSave(cfg *config) { +BOOLE cfgGetConfigChangedSinceLastSave(cfg *config) +{ return config->m_config_changed_since_save; } @@ -1442,10 +1412,8 @@ static char *cfgGetGraphicsEmulationModeToString(GRAPHICSEMULATIONMODE graphicse { switch (graphicsemulationmode) { - case GRAPHICSEMULATIONMODE_LINEEXACT: - return "lineexact"; - case GRAPHICSEMULATIONMODE_CYCLEEXACT: - return "cycleexact"; + case GRAPHICSEMULATIONMODE_LINEEXACT: return "lineexact"; + case GRAPHICSEMULATIONMODE_CYCLEEXACT: return "cycleexact"; } return "lineexact"; } @@ -1456,15 +1424,15 @@ static char *cfgGetGraphicsEmulationModeToString(GRAPHICSEMULATIONMODE graphicse void cfgSynopsis(cfg *config) { - fprintf(stderr, - "Synopsis: WinFellow.exe [-h] | [[-f configfile] | [-s option=value]]*\n\n" - "Command-line options:\n" - "-h : Print this command-line symmary, then stop.\n" - "-f configfile : Specify configuration file to use.\n" - "-s option=value : Set option to value. Legal options listed below.\n"); + fprintf( + stderr, + "Synopsis: WinFellow.exe [-h] | [[-f configfile] | [-s option=value]]*\n\n" + "Command-line options:\n" + "-h : Print this command-line symmary, then stop.\n" + "-f configfile : Specify configuration file to use.\n" + "-s option=value : Set option to value. Legal options listed below.\n"); } - /*============================================================================*/ /* Set configuration option */ /* Returns TRUE if the option was recognized */ @@ -1472,11 +1440,11 @@ void cfgSynopsis(cfg *config) BOOLE cfgSetOption(cfg *config, char *optionstr) { - char* value = strchr(optionstr, '='); + char *value = strchr(optionstr, '='); BOOLE result = (value != nullptr); if (result) { - char* option = optionstr; + char *option = optionstr; *value++ = '\0'; /* Standard configuration options */ @@ -1518,48 +1486,39 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) { cfgSetLastUsedDiskDir(config, value); } - else if ((stricmp(option, "fellow.floppy0_enabled") == 0) || - (stricmp(option, "floppy0_enabled") == 0)) + else if ((stricmp(option, "fellow.floppy0_enabled") == 0) || (stricmp(option, "floppy0_enabled") == 0)) { cfgSetDiskEnabled(config, 0, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy1_enabled") == 0) || - (stricmp(option, "floppy1_enabled") == 0)) - { + else if ((stricmp(option, "fellow.floppy1_enabled") == 0) || (stricmp(option, "floppy1_enabled") == 0)) + { cfgSetDiskEnabled(config, 1, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy2_enabled") == 0) || - (stricmp(option, "floppy2_enabled") == 0)) + else if ((stricmp(option, "fellow.floppy2_enabled") == 0) || (stricmp(option, "floppy2_enabled") == 0)) { cfgSetDiskEnabled(config, 2, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy3_enabled") == 0) || - (stricmp(option, "floppy3_enabled") == 0)) + else if ((stricmp(option, "fellow.floppy3_enabled") == 0) || (stricmp(option, "floppy3_enabled") == 0)) { cfgSetDiskEnabled(config, 3, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy_fast_dma") == 0) || - (stricmp(option, "floppy_fast_dma") == 0)) + else if ((stricmp(option, "fellow.floppy_fast_dma") == 0) || (stricmp(option, "floppy_fast_dma") == 0)) { cfgSetDiskFast(config, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy0_readonly") == 0) || - (stricmp(option, "floppy0_readonly") == 0)) + else if ((stricmp(option, "fellow.floppy0_readonly") == 0) || (stricmp(option, "floppy0_readonly") == 0)) { cfgSetDiskReadOnly(config, 0, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy1_readonly") == 0) || - (stricmp(option, "floppy1_readonly") == 0)) - { + else if ((stricmp(option, "fellow.floppy1_readonly") == 0) || (stricmp(option, "floppy1_readonly") == 0)) + { cfgSetDiskReadOnly(config, 1, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy2_readonly") == 0) || - (stricmp(option, "floppy2_readonly") == 0)) + else if ((stricmp(option, "fellow.floppy2_readonly") == 0) || (stricmp(option, "floppy2_readonly") == 0)) { cfgSetDiskReadOnly(config, 2, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.floppy3_readonly") == 0) || - (stricmp(option, "floppy3_readonly") == 0)) + else if ((stricmp(option, "fellow.floppy3_readonly") == 0) || (stricmp(option, "floppy3_readonly") == 0)) { cfgSetDiskReadOnly(config, 3, cfgGetBOOLEFromString(value)); } @@ -1603,13 +1562,11 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) { cfgSetSoundVolume(config, cfgGetUint32FromString(value)); } - else if ((stricmp(option, "fellow.sound_wav") == 0) || - (stricmp(option, "sound_wav") == 0)) + else if ((stricmp(option, "fellow.sound_wav") == 0) || (stricmp(option, "sound_wav") == 0)) { cfgSetSoundWAVDump(config, cfgGetBOOLEFromString(value)); } - else if ((stricmp(option, "fellow.sound_filter") == 0) || - (stricmp(option, "sound_filter") == 0)) + else if ((stricmp(option, "fellow.sound_filter") == 0) || (stricmp(option, "sound_filter") == 0)) { cfgSetSoundFilter(config, cfgGetSoundFilterFromString(value)); } @@ -1623,15 +1580,15 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) } else if (stricmp(option, "chipmem_size") == 0) { - cfgSetChipSize(config, cfgGetUint32FromString(value)*262144); + cfgSetChipSize(config, cfgGetUint32FromString(value) * 262144); } else if (stricmp(option, "fastmem_size") == 0) { - cfgSetFastSize(config, cfgGetUint32FromString(value)*1048576); + cfgSetFastSize(config, cfgGetUint32FromString(value) * 1048576); } else if (stricmp(option, "bogomem_size") == 0) { - cfgSetBogoSize(config, cfgGetUint32FromString(value)*262144); + cfgSetBogoSize(config, cfgGetUint32FromString(value) * 262144); } else if (stricmp(option, "kickstart_rom_file") == 0) { @@ -1648,7 +1605,7 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) else if (stricmp(option, "kickstart_rom_crc32") == 0) { uint32_t crc32; - sscanf(value,"%lX", &crc32); + sscanf(value, "%lX", &crc32); cfgSetKickCRC32(config, crc32); } else if (stricmp(option, "kickstart_key_file") == 0) @@ -1671,8 +1628,7 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) { cfgSetScreenHeight(config, cfgGetUint32FromString(value)); } - else if ((stricmp(option, "fellow.gfx_refresh") == 0) || - (stricmp(option, "gfx_refresh") == 0)) + else if ((stricmp(option, "fellow.gfx_refresh") == 0) || (stricmp(option, "gfx_refresh") == 0)) { cfgSetScreenRefresh(config, cfgGetUint32FromString(value)); } @@ -1728,13 +1684,11 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) { cfgSetFrameskipRatio(config, cfgGetUint32FromString(value)); } - else if ((stricmp(option, "fellow.gfx_deinterlace") == 0) || - (stricmp(option, "gfx_deinterlace") == 0)) + else if ((stricmp(option, "fellow.gfx_deinterlace") == 0) || (stricmp(option, "gfx_deinterlace") == 0)) { cfgSetDeinterlace(config, cfgGetboolFromString(value)); } - else if ((stricmp(option, "fellow.measure_speed") == 0) || - (stricmp(option, "measure_speed") == 0)) + else if ((stricmp(option, "fellow.measure_speed") == 0) || (stricmp(option, "measure_speed") == 0)) { cfgSetMeasureSpeed(config, cfgGetboolFromString(value)); } @@ -1750,53 +1704,53 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) if ((nextpos = strchr(curpos, ',')) == nullptr) { - return FALSE; /* Access */ + return FALSE; /* Access */ } *nextpos = '\0'; if (stricmp(curpos, "ro") == 0) { - hf.readonly = TRUE; + hf.readonly = TRUE; } else if (stricmp(curpos, "rw") == 0) { - hf.readonly = FALSE; + hf.readonly = FALSE; } else { - return FALSE; + return FALSE; } curpos = nextpos + 1; if ((nextpos = strchr(curpos, ',')) == nullptr) { - return FALSE; /* Secs */ + return FALSE; /* Secs */ } *nextpos = '\0'; hf.sectorspertrack = atoi(curpos); curpos = nextpos + 1; if ((nextpos = strchr(curpos, ',')) == nullptr) { - return FALSE; /* Surfaces */ + return FALSE; /* Surfaces */ } *nextpos = '\0'; hf.surfaces = atoi(curpos); curpos = nextpos + 1; if ((nextpos = strchr(curpos, ',')) == nullptr) { - return FALSE; /* Reserved */ + return FALSE; /* Reserved */ } *nextpos = '\0'; hf.reservedblocks = atoi(curpos); curpos = nextpos + 1; if ((nextpos = strchr(curpos, ',')) == nullptr) { - return FALSE; /* Blocksize */ + return FALSE; /* Blocksize */ } *nextpos = '\0'; hf.bytespersector = atoi(curpos); curpos = nextpos + 1; if ((nextpos = strchr(curpos, ',')) != nullptr) { - return FALSE; /* Filename */ + return FALSE; /* Filename */ } strncpy(hf.filename, curpos, CFG_FILENAME_LENGTH); @@ -1820,36 +1774,35 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) if ((nextpos = strchr(curpos, ',')) == nullptr) { - return FALSE; /* Access */ + return FALSE; /* Access */ } *nextpos = '\0'; if (stricmp(curpos, "ro") == 0) { - fs.readonly = TRUE; + fs.readonly = TRUE; } else if (stricmp(curpos, "rw") == 0) { - fs.readonly = FALSE; + fs.readonly = FALSE; } else { - return FALSE; + return FALSE; } curpos = nextpos + 1; if ((nextpos = strchr(curpos, ':')) == nullptr) { - return FALSE; /* Volname */ + return FALSE; /* Volname */ } *nextpos = '\0'; strncpy(fs.volumename, curpos, 64); curpos = nextpos + 1; - strncpy(fs.rootpath, curpos, CFG_FILENAME_LENGTH); /* Rootpath */ + strncpy(fs.rootpath, curpos, CFG_FILENAME_LENGTH); /* Rootpath */ cfgFilesystemAdd(config, &fs); } - else if ((stricmp(option, "fellow.map_drives") == 0) || - (stricmp(option, "fellow.win32.map_drives") == 0) || - (stricmp(option, "win32.map_drives") == 0) || - (stricmp(option, "map_drives") == 0)) + else if ( + (stricmp(option, "fellow.map_drives") == 0) || (stricmp(option, "fellow.win32.map_drives") == 0) || (stricmp(option, "win32.map_drives") == 0) || + (stricmp(option, "map_drives") == 0)) { cfgSetFilesystemAutomountDrives(config, cfgGetBOOLEFromString(value)); } @@ -1857,64 +1810,85 @@ BOOLE cfgSetOption(cfg *config, char *optionstr) { cfgSetFilesystemDeviceNamePrefix(config, value); } - else if (stricmp(option, "use_debugger") == 0) { /* Unsupported */ + else if (stricmp(option, "use_debugger") == 0) + { /* Unsupported */ } - else if (stricmp(option, "log_illegal_mem") == 0) { /* Unsupported */ + else if (stricmp(option, "log_illegal_mem") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfx_correct_aspect") == 0) { /* Unsupported */ + else if (stricmp(option, "gfx_correct_aspect") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfx_center_vertical") == 0) { /* Unsupported */ + else if (stricmp(option, "gfx_center_vertical") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfx_center_horizontal") == 0) { /* Unsupported */ + else if (stricmp(option, "gfx_center_horizontal") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfx_fullscreen_picasso") == 0) { /* Unsupported */ + else if (stricmp(option, "gfx_fullscreen_picasso") == 0) + { /* Unsupported */ } - else if (stricmp(option, "z3mem_size") == 0) { /* Unsupported */ + else if (stricmp(option, "z3mem_size") == 0) + { /* Unsupported */ } - else if (stricmp(option, "a3000mem_size") == 0) { /* Unsupported */ + else if (stricmp(option, "a3000mem_size") == 0) + { /* Unsupported */ } - else if (stricmp(option, "sound_min_buff") == 0) { /* Unsupported */ + else if (stricmp(option, "sound_min_buff") == 0) + { /* Unsupported */ } - else if (stricmp(option, "sound_max_buff") == 0) { /* Unsupported */ + else if (stricmp(option, "sound_max_buff") == 0) + { /* Unsupported */ } - else if (stricmp(option, "accuracy") == 0) { /* Unsupported */ + else if (stricmp(option, "accuracy") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfx_32bit_blits") == 0) { /* Unsupported */ + else if (stricmp(option, "gfx_32bit_blits") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfx_test_speed") == 0) { /* Unsupported */ + else if (stricmp(option, "gfx_test_speed") == 0) + { /* Unsupported */ } - else if (stricmp(option, "gfxlib_replacement") == 0) { /* Unsupported */ + else if (stricmp(option, "gfxlib_replacement") == 0) + { /* Unsupported */ } - else if (stricmp(option, "bsdsocket_emu") == 0) { /* Unsupported */ + else if (stricmp(option, "bsdsocket_emu") == 0) + { /* Unsupported */ } - else if (stricmp(option, "parallel_on_demand") == 0) { /* Unsupported */ + else if (stricmp(option, "parallel_on_demand") == 0) + { /* Unsupported */ } - else if (stricmp(option, "serial_on_demand") == 0) { /* Unsupported */ + else if (stricmp(option, "serial_on_demand") == 0) + { /* Unsupported */ } - else if (stricmp(option, "kickshifter") == 0) { /* Unsupported */ + else if (stricmp(option, "kickshifter") == 0) + { /* Unsupported */ } - else if (stricmp(option, "enforcer") == 0) { /* Unsupported */ + else if (stricmp(option, "enforcer") == 0) + { /* Unsupported */ } - else if (stricmp(option, "cpu_compatible") == 0) { /* Static support */ + else if (stricmp(option, "cpu_compatible") == 0) + { /* Static support */ } - else if (stricmp(option, "cpu_24bit_addressing") == 0) { /* Redundant */ + else if (stricmp(option, "cpu_24bit_addressing") == 0) + { /* Redundant */ } else #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) + if (RP.GetHeadlessMode()) + { + if (stricmp(option, "gfx_offset_left") == 0) { - if (stricmp(option, "gfx_offset_left") == 0) - { - RP.SetClippingOffsetLeft(cfgGetUint32FromString(value)); - } - else if (stricmp(option, "gfx_offset_top") == 0) - { - RP.SetClippingOffsetTop(cfgGetUint32FromString(value)); - } + RP.SetClippingOffsetLeft(cfgGetUint32FromString(value)); } - else + else if (stricmp(option, "gfx_offset_top") == 0) + { + RP.SetClippingOffsetTop(cfgGetUint32FromString(value)); + } + } + else #endif - result = FALSE; + result = FALSE; } else { @@ -1960,11 +1934,11 @@ BOOLE cfgSaveOptions(cfg *config, FILE *cfgfile) fprintf(cfgfile, "bogomem_size=%u\n", cfgGetBogoSize(config) / 262144); fprintf(cfgfile, "kickstart_rom_file=%s\n", cfgGetKickImage(config)); fprintf(cfgfile, "kickstart_rom_file_ext=%s\n", cfgGetKickImageExtended(config)); - if(strcmp(cfgGetKickDescription(config), "") != 0) + if (strcmp(cfgGetKickDescription(config), "") != 0) { fprintf(cfgfile, "kickstart_rom_description=%s\n", cfgGetKickDescription(config)); } - if(cfgGetKickCRC32(config) != 0) + if (cfgGetKickCRC32(config) != 0) { fprintf(cfgfile, "kickstart_rom_crc32=%X\n", cfgGetKickCRC32(config)); } @@ -1995,13 +1969,7 @@ BOOLE cfgSaveOptions(cfg *config, FILE *cfgfile) for (uint32_t i = 0; i < cfgGetHardfileCount(config); i++) { cfg_hardfile hf = cfgGetHardfile(config, i); - fprintf(cfgfile, "hardfile=%s,%u,%u,%u,%u,%s\n", - (hf.readonly) ? "ro" : "rw", - hf.sectorspertrack, - hf.surfaces, - hf.reservedblocks, - hf.bytespersector, - hf.filename); + fprintf(cfgfile, "hardfile=%s,%u,%u,%u,%u,%s\n", (hf.readonly) ? "ro" : "rw", hf.sectorspertrack, hf.surfaces, hf.reservedblocks, hf.bytespersector, hf.filename); } for (uint32_t i = 0; i < cfgGetFilesystemCount(config); i++) { @@ -2061,7 +2029,6 @@ void cfgUpgradeConfig(cfg *config) } } - /*============================================================================*/ /* Remove unwanted newline chars on the end of a string */ /*============================================================================*/ @@ -2069,14 +2036,12 @@ void cfgUpgradeConfig(cfg *config) static void cfgStripTrailingNewlines(char *line) { size_t length = strlen(line); - while ((length > 0) && - ((line[length - 1] == '\n') || (line[length - 1] == '\r'))) + while ((length > 0) && ((line[length - 1] == '\n') || (line[length - 1] == '\r'))) { line[--length] = '\0'; } } - /*============================================================================*/ /* Load configuration from file */ /*============================================================================*/ @@ -2100,7 +2065,8 @@ bool cfgLoadFromFilename(cfg *config, const char *filename, const bool bIsPreset fileopsResolveVariables(filename, newfilename); - if(!bIsPreset) { + if (!bIsPreset) + { fellowAddLog("cfg: loading configuration filename %s...\n", filename); // remove existing hardfiles @@ -2127,7 +2093,6 @@ bool cfgLoadFromFilename(cfg *config, const char *filename, const bool bIsPreset return result; } - /*============================================================================*/ /* Save configuration to file */ /*============================================================================*/ @@ -2139,7 +2104,7 @@ static BOOLE cfgSaveToFile(cfg *config, FILE *cfgfile) BOOLE cfgSaveToFilename(cfg *config, char *filename) { - FILE* cfgfile = fopen(filename, "w"); + FILE *cfgfile = fopen(filename, "w"); BOOLE result = (cfgfile != nullptr); if (result) { @@ -2158,7 +2123,7 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) int i; fellowAddLog("cfg: list of commandline parameters: "); - for(i=1; i < argc; i++) + for (i = 1; i < argc; i++) { fellowAddLog("%s ", argv[i]); } @@ -2179,7 +2144,7 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) i++; if (i < argc) { - RP.SetHeadlessMode(true); + RP.SetHeadlessMode(true); RP.SetHostID(argv[i]); } i++; @@ -2198,7 +2163,7 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) { i++; if (i < argc) - { + { uint32_t lEscapeKey = atoi(argv[i]); lEscapeKey = kbddrv_DIK_to_symbol[lEscapeKey]; RP.SetEscapeKey(lEscapeKey); @@ -2209,7 +2174,7 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) { i++; if (i < argc) - { + { RP.SetEscapeKeyHoldTime(atoi(argv[i])); } i++; @@ -2240,7 +2205,7 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) if (i < argc) { fellowAddLog("cfg: configuration file: %s\n", argv[i]); - if(!cfgLoadFromFilename(config, argv[i], false)) + if (!cfgLoadFromFilename(config, argv[i], false)) { fellowAddLog("cfg: ERROR using -f option, failed reading configuration file %s\n", argv[i]); } @@ -2280,8 +2245,7 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) i++; if (i < argc) { - if (!cfgSetOption(config, argv[i])) - fellowAddLog("cfg: -s option, unrecognized setting %s\n", argv[i]); + if (!cfgSetOption(config, argv[i])) fellowAddLog("cfg: -s option, unrecognized setting %s\n", argv[i]); i++; } else @@ -2298,7 +2262,6 @@ static BOOLE cfgParseCommandLine(cfg *config, int argc, char *argv[]) return TRUE; } - /*============================================================================*/ /* struct cfgManager property access functions */ /*============================================================================*/ @@ -2323,8 +2286,8 @@ cfg *cfgManagerGetCopyOfCurrentConfig(cfgManager *configmanager) { cfg *newconfig = static_cast(malloc(sizeof(cfg))); memcpy(newconfig, configmanager->m_currentconfig, sizeof(cfg)); - newconfig->m_filesystems = listCopy(configmanager->m_currentconfig->m_filesystems, sizeof(cfg_filesys )); - newconfig->m_hardfiles = listCopy(configmanager->m_currentconfig->m_hardfiles, sizeof(cfg_hardfile)); + newconfig->m_filesystems = listCopy(configmanager->m_currentconfig->m_filesystems, sizeof(cfg_filesys)); + newconfig->m_hardfiles = listCopy(configmanager->m_currentconfig->m_hardfiles, sizeof(cfg_hardfile)); return newconfig; } @@ -2334,7 +2297,6 @@ void cfgManagerUseDefaultConfiguration(cfgManager *configmanager) configmanager->m_currentconfig = configmanager->m_currentconfig; } - /*============================================================================*/ /* struct cfgManager utility functions */ /* Returns TRUE if reset is needed to activate the config changes */ @@ -2346,7 +2308,6 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) uint32_t i; BOOLE needreset = FALSE; - /*==========================================================================*/ /* Floppy configuration */ /*==========================================================================*/ @@ -2359,7 +2320,6 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) } floppySetFastDMA(cfgGetDiskFast(config)); - /*==========================================================================*/ /* Memory configuration */ /*==========================================================================*/ @@ -2374,7 +2334,6 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) needreset |= memorySetAddress32Bit(cfgGetAddress32Bit(config)); needreset |= rtcSetEnabled(cfgGetRtc(config)) == true; - /*==========================================================================*/ /* Screen configuration */ /*==========================================================================*/ @@ -2383,11 +2342,11 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) drawSetFPSCounterEnabled(cfgGetMeasureSpeed(config)); drawSetFrameskipRatio(cfgGetFrameskipRatio(config)); #ifdef RETRO_PLATFORM - // internal clipping values in RetroPlatform headless mode are configured by + // internal clipping values in RetroPlatform headless mode are configured by // RetroPlatform::RegisterRetroPlatformScreenMode, skip configuration - if(!RP.GetHeadlessMode()) + if (!RP.GetHeadlessMode()) #endif - drawSetInternalClip(draw_rect(cfgGetClipLeft(config), cfgGetClipTop(config), cfgGetClipRight(config), cfgGetClipBottom(config))); + drawSetInternalClip(draw_rect(cfgGetClipLeft(config), cfgGetClipTop(config), cfgGetClipRight(config), cfgGetClipBottom(config))); drawSetOutputClip(draw_rect(cfgGetClipLeft(config), cfgGetClipTop(config), cfgGetClipRight(config), cfgGetClipBottom(config))); drawSetDisplayScale(cfgGetDisplayScale(config)); drawSetDisplayScaleStrategy(cfgGetDisplayScaleStrategy(config)); @@ -2395,33 +2354,29 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) drawSetDeinterlace(cfgGetDeinterlace(config)); drawSetDisplayDriver(cfgGetDisplayDriver(config)); drawSetGraphicsEmulationMode(cfgGetGraphicsEmulationMode(config)); - + if (cfgGetScreenWindowed(config)) { drawSetWindowedMode(cfgGetScreenWidth(config), cfgGetScreenHeight(config)); } else { - drawSetFullScreenMode(cfgGetScreenWidth(config), - cfgGetScreenHeight(config), - cfgGetScreenColorBits(config), - cfgGetScreenRefresh(config)); + drawSetFullScreenMode(cfgGetScreenWidth(config), cfgGetScreenHeight(config), cfgGetScreenColorBits(config), cfgGetScreenRefresh(config)); } /*==========================================================================*/ /* Sound configuration */ /*==========================================================================*/ - soundSetEmulation(cfgGetSoundEmulation(config)); - soundSetRate(cfgGetSoundRate(config)); - soundSetStereo(cfgGetSoundStereo(config)); - soundSet16Bits(cfgGetSound16Bits(config)); - soundSetFilter(cfgGetSoundFilter(config)); - soundSetVolume(cfgGetSoundVolume(config)); - soundSetWAVDump(cfgGetSoundWAVDump(config)); - soundSetNotification(cfgGetSoundNotification(config)); - soundSetBufferLength(cfgGetSoundBufferLength(config)); - + _core.Sound->SetEmulation(cfgGetSoundEmulation(config)); + _core.Sound->SetRate(cfgGetSoundRate(config)); + _core.Sound->SetIsStereo(cfgGetSoundStereo(config)); + _core.Sound->SetIs16Bits(cfgGetSound16Bits(config)); + _core.Sound->SetFilter(cfgGetSoundFilter(config)); + _core.Sound->SetVolume(cfgGetSoundVolume(config)); + _core.Sound->SetWAVDump(cfgGetSoundWAVDump(config)); + _core.Sound->SetNotification(cfgGetSoundNotification(config)); + _core.Sound->SetBufferLength(cfgGetSoundBufferLength(config)); /*==========================================================================*/ /* CPU configuration */ @@ -2430,7 +2385,6 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) needreset |= cpuIntegrationSetModel(cfgGetCPUType(config)); cpuIntegrationSetSpeed(cfgGetCPUSpeed(config)); - /*==========================================================================*/ /* Custom chipset configuration */ /*==========================================================================*/ @@ -2438,7 +2392,6 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) blitterSetFast(cfgGetBlitterFast(config)); needreset |= chipsetSetECS(cfgGetECS(config)); - /*==========================================================================*/ /* Hardfile configuration */ /*==========================================================================*/ @@ -2479,8 +2432,7 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) /* Filesystem configuration */ /*==========================================================================*/ - if ((cfgGetUseAutoconfig(config) != ffilesysGetEnabled()) || - (cfgGetFilesystemAutomountDrives(config) != ffilesysGetAutomountDrives())) + if ((cfgGetUseAutoconfig(config) != ffilesysGetEnabled()) || (cfgGetFilesystemAutomountDrives(config) != ffilesysGetAutomountDrives())) { needreset = TRUE; ffilesysClear(); @@ -2499,8 +2451,8 @@ BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager) ffilesys.status = FFILESYS_INSERTED; if (!ffilesysCompareFilesys(ffilesys, i)) { - needreset = TRUE; - ffilesysSetFilesys(ffilesys, i); + needreset = TRUE; + ffilesysSetFilesys(ffilesys, i); } } for (i = cfgGetFilesystemCount(config); i < FFILESYS_MAX_DEVICES; i++) @@ -2541,13 +2493,15 @@ void cfgManagerStartup(cfgManager *configmanager, int argc, char *argv[]) cfg *config = cfgManagerGetNewConfig(configmanager); cfgParseCommandLine(config, argc, argv); #ifdef RETRO_PLATFORM - if(!RP.GetHeadlessMode()) { + if (!RP.GetHeadlessMode()) + { #endif - if(!cfgGetConfigAppliedOnce(config)) { - // load configuration that the initdata contains - cfg_initdata = iniManagerGetCurrentInitdata(&ini_manager); - cfgLoadFromFilename(config, iniGetCurrentConfigurationFilename(cfg_initdata), false); - } + if (!cfgGetConfigAppliedOnce(config)) + { + // load configuration that the initdata contains + cfg_initdata = iniManagerGetCurrentInitdata(&ini_manager); + cfgLoadFromFilename(config, iniGetCurrentConfigurationFilename(cfg_initdata), false); + } #ifdef RETRO_PLATFORM } #endif diff --git a/fellow/SRC/WinFellow/C/FELLOW.C b/fellow/SRC/WinFellow/C/FELLOW.C index 43f42260..f437d666 100644 --- a/fellow/SRC/WinFellow/C/FELLOW.C +++ b/fellow/SRC/WinFellow/C/FELLOW.C @@ -33,9 +33,7 @@ #include "CpuModule.h" #include "CpuIntegration.h" #include "fmem.h" -#include "eventid.h" #include "floppy.h" -#include "sound.h" #include "gameport.h" #include "kbd.h" #include "graph.h" @@ -62,13 +60,12 @@ #include "fellow/api/Services.h" #include "fellow/api/VM.h" -#include "CoreHost.h" +#include "VirtualHost/Core.h" +#include "VirtualHost/CoreFactory.h" using namespace fellow::api::module; using namespace fellow::api; -Core _core = Core(); - BOOLE fellow_request_emulation_stop; /*============================================================================*/ @@ -77,15 +74,16 @@ BOOLE fellow_request_emulation_stop; BOOLE fellow_pre_start_reset; -void fellowSetPreStartReset(BOOLE reset) { +void fellowSetPreStartReset(BOOLE reset) +{ fellow_pre_start_reset = reset; } -BOOLE fellowGetPreStartReset() { +BOOLE fellowGetPreStartReset() +{ return fellow_pre_start_reset; } - /*============================================================================*/ /* setjmp support */ /*============================================================================*/ @@ -93,32 +91,32 @@ BOOLE fellowGetPreStartReset() { static jmp_buf fellow_runtime_error_env; static fellow_runtime_error_codes fellow_runtime_error_code; -void fellowSetRuntimeErrorCode(fellow_runtime_error_codes error_code) { +void fellowSetRuntimeErrorCode(fellow_runtime_error_codes error_code) +{ fellow_runtime_error_code = error_code; } - -static fellow_runtime_error_codes fellowGetRuntimeErrorCode() { +static fellow_runtime_error_codes fellowGetRuntimeErrorCode() +{ return fellow_runtime_error_code; } - /*============================================================================*/ /* The run-time log */ /*============================================================================*/ #define WRITE_LOG_BUF_SIZE 512 -void fellowAddLog2(char* msg) +void fellowAddLog2(char *msg) { Service->Log.AddLog2(msg); } -void fellowAddLog(const char* format, ...) +void fellowAddLog(const char *format, ...) { char buffer[WRITE_LOG_BUF_SIZE]; va_list parms; - + va_start(parms, format); _vsnprintf(buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); va_end(parms); @@ -134,15 +132,9 @@ void fellowAddLogRequester(FELLOW_REQUESTER_TYPE type, const char *format, ...) switch (type) { - case FELLOW_REQUESTER_TYPE_INFO: - uType = MB_ICONINFORMATION; - break; - case FELLOW_REQUESTER_TYPE_WARN: - uType = MB_ICONWARNING; - break; - case FELLOW_REQUESTER_TYPE_ERROR: - uType = MB_ICONERROR; - break; + case FELLOW_REQUESTER_TYPE_INFO: uType = MB_ICONINFORMATION; break; + case FELLOW_REQUESTER_TYPE_WARN: uType = MB_ICONWARNING; break; + case FELLOW_REQUESTER_TYPE_ERROR: uType = MB_ICONERROR; break; } va_start(parms, format); @@ -156,7 +148,7 @@ void fellowAddLogRequester(FELLOW_REQUESTER_TYPE type, const char *format, ...) wguiRequester(buffer, uType); } -void fellowAddTimelessLog(const char *format,...) +void fellowAddTimelessLog(const char *format, ...) { char buffer[WRITE_LOG_BUF_SIZE]; va_list parms; @@ -170,7 +162,7 @@ void fellowAddTimelessLog(const char *format,...) char *fellowGetVersionString() { - char *result = (char *) malloc(strlen(FELLOWVERSION)+ 12); + char *result = (char *)malloc(strlen(FELLOWVERSION) + 12); if (!result) { @@ -178,35 +170,37 @@ char *fellowGetVersionString() } #ifdef X64 - sprintf(result, "%s - %d bit", FELLOWVERSION, 64); + sprintf(result, "%s - %d bit", FELLOWVERSION, 64); #else - sprintf(result, "%s - %d bit", FELLOWVERSION, 32); + sprintf(result, "%s - %d bit", FELLOWVERSION, 32); #endif return result; } - /*============================================================================*/ /* Runtime Error Check */ /*============================================================================*/ -static void fellowRuntimeErrorCheck() { - switch (fellowGetRuntimeErrorCode()) { +static void fellowRuntimeErrorCheck() +{ + switch (fellowGetRuntimeErrorCode()) + { case FELLOW_RUNTIME_ERROR_CPU_PC_BAD_BANK: - fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, - "A serious emulation runtime error occured:\nThe emulated CPU entered Amiga memory that can not hold\nexecutable data. Emulation could not continue."); + fellowAddLogRequester( + FELLOW_REQUESTER_TYPE_ERROR, + "A serious emulation runtime error occured:\nThe emulated CPU entered Amiga memory that can not hold\nexecutable data. Emulation could not continue."); break; } fellowSetRuntimeErrorCode(FELLOW_RUNTIME_ERROR_NO_ERROR); } - /*============================================================================*/ /* Softreset */ /*============================================================================*/ -void fellowSoftReset() { +void fellowSoftReset() +{ memorySoftReset(); interruptSoftReset(); HardfileHandler->HardReset(); @@ -215,7 +209,7 @@ void fellowSoftReset() { kbdHardReset(); gameportHardReset(); busSoftReset(); - soundHardReset(); + _core.Sound->HardReset(); blitterHardReset(); copperHardReset(); floppyHardReset(); @@ -224,15 +218,15 @@ void fellowSoftReset() { ffilesysHardReset(); memoryHardResetPost(); fellowSetPreStartReset(FALSE); - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.SoftReset(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.SoftReset(); } /*============================================================================*/ /* Hardreset */ /*============================================================================*/ -void fellowHardReset() { +void fellowHardReset() +{ memoryHardReset(); interruptHardReset(); HardfileHandler->HardReset(); @@ -241,7 +235,7 @@ void fellowHardReset() { kbdHardReset(); gameportHardReset(); busHardReset(); - soundHardReset(); + _core.Sound->HardReset(); blitterHardReset(); copperHardReset(); floppyHardReset(); @@ -251,8 +245,7 @@ void fellowHardReset() { memoryHardResetPost(); cpuIntegrationHardReset(); fellowSetPreStartReset(FALSE); - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.HardReset(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.HardReset(); } /*============================================================================*/ @@ -260,12 +253,13 @@ void fellowHardReset() { /* Emulation will stop at the beginning of the next frame */ /*============================================================================*/ -void fellowRequestEmulationStop() { +void fellowRequestEmulationStop() +{ fellow_request_emulation_stop = TRUE; } - -void fellowRequestEmulationStopClear() { +void fellowRequestEmulationStopClear() +{ fellow_request_emulation_stop = FALSE; } @@ -273,7 +267,8 @@ void fellowRequestEmulationStopClear() { /* Controls the process of starting actual emulation */ /*============================================================================*/ -BOOLE fellowEmulationStart() { +BOOLE fellowEmulationStart() +{ fellowRequestEmulationStopClear(); iniEmulationStart(); memoryEmulationStart(); @@ -288,40 +283,37 @@ BOOLE fellowEmulationStart() { gameportEmulationStart(); BOOLE result = drawEmulationStartPost(); graphEmulationStart(); - soundEmulationStart(); + _core.Sound->EmulationStart(); busEmulationStart(); floppyEmulationStart(); ffilesysEmulationStart(); timerEmulationStart(); #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) - RP.EmulationStart(); + if (RP.GetHeadlessMode()) RP.EmulationStart(); #endif - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.EmulationStart(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.EmulationStart(); uart.EmulationStart(); HardfileHandler->EmulationStart(); - + return result && memoryGetKickImageOK(); } - /*============================================================================*/ /* Controls the process of halting actual emulation */ /*============================================================================*/ -void fellowEmulationStop() { +void fellowEmulationStop() +{ #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) - RP.EmulationStop(); + if (RP.GetHeadlessMode()) RP.EmulationStop(); #endif HardfileHandler->EmulationStop(); timerEmulationStop(); ffilesysEmulationStop(); floppyEmulationStop(); busEmulationStop(); - soundEmulationStop(); + _core.Sound->EmulationStop(); gameportEmulationStop(); kbdEmulationStop(); drawEmulationStop(); @@ -334,8 +326,7 @@ void fellowEmulationStop() { interruptEmulationStop(); memoryEmulationStop(); iniEmulationStop(); - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.EmulationStop(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.EmulationStop(); uart.EmulationStop(); } @@ -346,16 +337,15 @@ void fellowEmulationStop() { /* FellowEmulationStop() will be called elsewhere */ /*============================================================================*/ -void fellowRun() { +void fellowRun() +{ if (fellowGetPreStartReset()) fellowHardReset(); - fellowSetRuntimeErrorCode((fellow_runtime_error_codes) setjmp(fellow_runtime_error_env)); - if (fellowGetRuntimeErrorCode() == FELLOW_RUNTIME_ERROR_NO_ERROR) - busRun(); + fellowSetRuntimeErrorCode((fellow_runtime_error_codes)setjmp(fellow_runtime_error_env)); + if (fellowGetRuntimeErrorCode() == FELLOW_RUNTIME_ERROR_NO_ERROR) busRun(); fellowRequestEmulationStopClear(); fellowRuntimeErrorCheck(); } - /*============================================================================*/ /* Steps one CPU instruction */ /*============================================================================*/ @@ -367,7 +357,7 @@ void fellowStepOne() { fellowHardReset(); } - fellowSetRuntimeErrorCode((fellow_runtime_error_codes) setjmp(fellow_runtime_error_env)); + fellowSetRuntimeErrorCode((fellow_runtime_error_codes)setjmp(fellow_runtime_error_env)); if (fellowGetRuntimeErrorCode() == FELLOW_RUNTIME_ERROR_NO_ERROR) { busDebugStepOneInstruction(); @@ -376,7 +366,6 @@ void fellowStepOne() fellowRuntimeErrorCheck(); } - /*============================================================================*/ /* Steps over a CPU instruction */ /*============================================================================*/ @@ -393,7 +382,7 @@ void fellowStepOver() { fellowHardReset(); } - + fellowSetRuntimeErrorCode((fellow_runtime_error_codes)setjmp(fellow_runtime_error_env)); if (fellowGetRuntimeErrorCode() == FELLOW_RUNTIME_ERROR_NO_ERROR) { @@ -408,15 +397,15 @@ void fellowStepOver() fellowRuntimeErrorCheck(); } - /*============================================================================*/ /* Run until we crash or is exited in debug-mode */ /*============================================================================*/ -void fellowRunDebug(uint32_t breakpoint) { +void fellowRunDebug(uint32_t breakpoint) +{ fellowRequestEmulationStopClear(); if (fellowGetPreStartReset()) fellowHardReset(); - fellowSetRuntimeErrorCode((fellow_runtime_error_codes) setjmp(fellow_runtime_error_env)); + fellowSetRuntimeErrorCode((fellow_runtime_error_codes)setjmp(fellow_runtime_error_env)); if (fellowGetRuntimeErrorCode() == FELLOW_RUNTIME_ERROR_NO_ERROR) while ((!fellow_request_emulation_stop) && (breakpoint != cpuGetPC())) busDebugStepOneInstruction(); @@ -424,28 +413,27 @@ void fellowRunDebug(uint32_t breakpoint) { fellowRuntimeErrorCheck(); } - /*============================================================================*/ /* Something really bad happened, immediate emulation stop */ /*============================================================================*/ -void fellowNastyExit() { - longjmp(fellow_runtime_error_env, fellowGetRuntimeErrorCode()); +void fellowNastyExit() +{ + longjmp(fellow_runtime_error_env, fellowGetRuntimeErrorCode()); fprintf(stderr, "You only die twice, I give in!\n"); - soundShutdown(); + _core.Sound->Shutdown(); fprintf(stderr, "Serious error! Exit.\n"); fsNavigSetCWDStartupDir(); exit(EXIT_FAILURE); } - /*============================================================================*/ /* Draw subsystem failure message and exit */ /*============================================================================*/ -static void fellowDrawFailed() { - fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, - "Graphics subsystem failed to start.\nPlease check your OS graphics driver setup.\nClosing down application."); +static void fellowDrawFailed() +{ + fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "Graphics subsystem failed to start.\nPlease check your OS graphics driver setup.\nClosing down application."); exit(EXIT_FAILURE); } @@ -457,7 +445,7 @@ static void fellowDrawFailed() { BOOLE fellowSaveState(char *filename) { FILE *F = fopen(filename, "wb"); - + if (F == nullptr) return FALSE; cpuIntegrationSaveState(F); @@ -478,7 +466,7 @@ BOOLE fellowSaveState(char *filename) BOOLE fellowLoadState(char *filename) { FILE *F = fopen(filename, "rb"); - + if (F == nullptr) return FALSE; cpuIntegrationLoadState(F); @@ -498,6 +486,9 @@ BOOLE fellowLoadState(char *filename) static void fellowModulesStartup(int argc, char *argv[]) { + CoreFactory::CreateDrivers(); + CoreFactory::CreateModules(); + chipsetStartup(); timerStartup(); fsNavigStartup(argv); @@ -507,26 +498,23 @@ static void fellowModulesStartup(int argc, char *argv[]) iniStartup(); kbdStartup(); cfgStartup(argc, argv); - if (!drawStartup()) - fellowDrawFailed(); + if (!drawStartup()) fellowDrawFailed(); gameportStartup(); busStartup(); - soundStartup(); + _core.Sound->Startup(); blitterStartup(); copperStartup(); floppyStartup(); - ciaStartup(); + ciaStartup(); memoryStartup(); interruptStartup(); graphStartup(); cpuIntegrationStartup(); wguiStartup(); #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) - RP.Startup(); + if (RP.GetHeadlessMode()) RP.Startup(); #endif - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Startup(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Startup(); automator.Startup(); } @@ -538,11 +526,9 @@ static void fellowModulesStartup(int argc, char *argv[]) static void fellowModulesShutdown() { automator.Shutdown(); - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Shutdown(); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Shutdown(); #ifdef RETRO_PLATFORM - if (RP.GetHeadlessMode()) - RP.Shutdown(); + if (RP.GetHeadlessMode()) RP.Shutdown(); #endif wguiShutdown(); cpuIntegrationShutdown(); @@ -553,7 +539,7 @@ static void fellowModulesShutdown() floppyShutdown(); copperShutdown(); blitterShutdown(); - soundShutdown(); + _core.Sound->Shutdown(); busShutdown(); gameportShutdown(); drawShutdown(); @@ -570,19 +556,24 @@ static void fellowModulesShutdown() delete HardfileHandler; delete fellow::api::Service; delete fellow::api::VM; + + CoreFactory::DestroyModules(); + CoreFactory::DestroyDrivers(); } /*============================================================================*/ /* main.... */ /*============================================================================*/ -int __cdecl main(int argc, char *argv[]) { +int __cdecl main(int argc, char *argv[]) +{ sysinfoLogSysInfo(); fellowSetPreStartReset(TRUE); fellowModulesStartup(argc, argv); #ifdef RETRO_PLATFORM - if (!RP.GetHeadlessMode()) { + if (!RP.GetHeadlessMode()) + { #endif // set DPI awareness in standalone GUI mode to system DPI aware wguiSetProcessDPIAwareness("2"); @@ -593,7 +584,7 @@ int __cdecl main(int argc, char *argv[]) { else RP.EnterHeadlessMode(); #endif - + fellowModulesShutdown(); return EXIT_SUCCESS; diff --git a/fellow/SRC/WinFellow/C/FLOPPY.C b/fellow/SRC/WinFellow/C/FLOPPY.C index 1a42ab13..91f540be 100644 --- a/fellow/SRC/WinFellow/C/FLOPPY.C +++ b/fellow/SRC/WinFellow/C/FLOPPY.C @@ -25,18 +25,18 @@ /** @file * The floppy module handles floppy disc drive emulation. - * It supports the use of .adf files, and is able to handle gzip (via embedded + * It supports the use of .adf files, and is able to handle gzip (via embedded * zlib code) and xdms (also embedded) compressed disc images. - * - * It contains experimental support for .ipf files originating from the C.A.P.S. - * project Software Preservation Society). - * CAPS * support is not yet fully functional, because timings are not emulated + * + * It contains experimental support for .ipf files originating from the C.A.P.S. + * project Software Preservation Society). + * CAPS * support is not yet fully functional, because timings are not emulated * correctly to support copy-protected ("flakey") images. - * - * CAPS support is only available for the 32 bit version, since no 64 bit version - * of the library is available. CAPS support is only enabled, when the preprocessor + * + * CAPS support is only available for the 32 bit version, since no 64 bit version + * of the library is available. CAPS support is only enabled, when the preprocessor * definition FELLOW_SUPPORT_CAPS is set - this should be disabled for 64 bit builds. - * + * * @todo CAPS has been renamed to SPS, and a 64 bit version is available; * update to a current version * @todo enhance timing for flakey image support @@ -69,7 +69,7 @@ #include "zlibwrap.h" #include "fileops.h" -#include "CoreHost.h" +#include "VirtualHost/Core.h" #ifdef FELLOW_SUPPORT_CAPS #include "caps.h" @@ -97,9 +97,9 @@ using namespace CustomChipset; /* Configuration */ /*---------------*/ -floppyinfostruct floppy[4]; /* Info about drives */ +floppyinfostruct floppy[4]; /* Info about drives */ BOOLE floppy_fast; /* Select fast floppy transfer */ -uint8_t tmptrack[20*1024*11]; /* Temporary track buffer */ +uint8_t tmptrack[20 * 1024 * 11]; /* Temporary track buffer */ floppyDMAinfostruct floppy_DMA; /* Info about a DMA transfer */ BOOLE floppy_DMA_started; /* Disk DMA started */ BOOLE floppy_DMA_read; /* DMA read or write */ @@ -116,14 +116,14 @@ uint16_t dskbyt_tmp = 0; BOOLE dskbyt1_read = FALSE; BOOLE dskbyt2_read = FALSE; -static uint8_t floppyBootBlockOFS[]={ +static uint8_t floppyBootBlockOFS[] = { 0x44, 0x4f, 0x53, 0x00, 0xc0, 0x20, 0x0f, 0x19, 0x00, 0x00, 0x03, 0x70, 0x43, 0xfa, 0x00, 0x18, 0x4e, 0xae, 0xff, 0xa0, 0x4a, 0x80, 0x67, 0x0a, 0x20, 0x40, 0x20, 0x68, 0x00, 0x16, 0x70, 0x00, 0x4e, 0x75, 0x70, 0xff, 0x60, 0xfa, 0x64, 0x6f, 0x73, 0x2e, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79 }; -static uint8_t floppyBootBlockFFS[]={ +static uint8_t floppyBootBlockFFS[] = { 0x44, 0x4F, 0x53, 0x01, 0xE3, 0x3D, 0x0E, 0x72, 0x00, 0x00, 0x03, 0x70, 0x43, 0xFA, 0x00, 0x3E, 0x70, 0x25, 0x4E, 0xAE, 0xFD, 0xD8, 0x4A, 0x80, 0x67, 0x0C, 0x22, 0x40, 0x08, 0xE9, 0x00, 0x06, 0x00, 0x22, 0x4E, 0xAE, 0xFE, 0x62, 0x43, 0xFA, 0x00, 0x18, 0x4E, 0xAE, 0xFF, 0xA0, 0x4A, 0x80, @@ -136,14 +136,14 @@ static uint8_t floppyBootBlockFFS[]={ #ifdef FLOPPY_LOG char floppylogfilename[MAX_PATH]; -FILE *floppylogfile = 0; +FILE* floppylogfile = 0; void floppyLogClear() { remove(floppylogfilename); } -void floppyLog(char *msg) +void floppyLog(char* msg) { if (floppylogfile == 0) { @@ -167,21 +167,21 @@ void floppyLogStep(uint32_t drive, uint32_t from, uint32_t to) floppyLog(msg); } -void floppyLogValue(char *text, uint32_t v) +void floppyLogValue(char* text, uint32_t v) { char msg[256]; sprintf(msg, "%s: FrameNo=%I64u Y=%.3u X=%.3u Value=%.8X PC=%.6X\n", text, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX(), v, cpuGetPC()); floppyLog(msg); } -void floppyLogValueWithTicks(char *text, uint32_t v, uint32_t ticks) +void floppyLogValueWithTicks(char* text, uint32_t v, uint32_t ticks) { char msg[256]; sprintf(msg, "%s: FrameNo=%I64u Y=%.3u X=%.3u Value=%.8X Ticks=%.5u PC=%.6X\n", text, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX(), v, ticks, cpuGetPC()); floppyLog(msg); } -void floppyLogMessageWithTicks(char *text, uint32_t ticks) +void floppyLogMessageWithTicks(char* text, uint32_t ticks) { char msg[256]; sprintf(msg, "%s: FrameNo=%I64u Y=%.3u X=%.3u Ticks=%.5u PC=%.6X\n", text, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX(), ticks, cpuGetPC()); @@ -235,13 +235,13 @@ void wadcon(uint16_t data, uint32_t address) uint16_t rdskbytr(uint32_t address) { - uint16_t tmp = (uint16_t)(floppy_DMA_started<<14); + uint16_t tmp = (uint16_t)(floppy_DMA_started << 14); uint32_t currentX = busGetRasterX(); if (dsklen & 0x4000) tmp |= 0x2000; if (floppy_has_sync) tmp |= 0x1000; if (currentX < 114 && !dskbyt1_read) { - tmp |= 0x8000 | (dskbyt_tmp>>8); + tmp |= 0x8000 | (dskbyt_tmp >> 8); dskbyt1_read = TRUE; } else if (currentX >= 114 && !dskbyt2_read) @@ -311,7 +311,7 @@ void wdsklen(uint16_t data, uint32_t address) floppyClearDMAState(); } diskDMAen = 0; - } + } } /*----------*/ @@ -341,7 +341,7 @@ int32_t floppySelectedGet() { if (floppy[i].enabled && floppy[i].sel) { - return i; + return i; } i++; } @@ -413,11 +413,11 @@ BOOLE floppyIsReady(uint32_t drive) { if (floppy[drive].idmode) { - return (floppy[drive].idcount++ < 32); + return (floppy[drive].idcount++ < 32); } else { - return (floppy[drive].motor && floppy[drive].inserted); + return (floppy[drive].motor && floppy[drive].inserted); } } } @@ -461,7 +461,7 @@ void floppyMotorSet(uint32_t drive, BOOLE mtr) { drawSetLED(drive, !mtr); #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) + if (RP.GetHeadlessMode()) RP.PostFloppyDriveLED(drive, !mtr ? true : false, false); #endif } @@ -504,14 +504,14 @@ void floppyStepSet(BOOLE stp) if (floppy[i].sel) { if (!stp && floppy[i].changed && floppy[i].inserted && - ((draw_frame_count - floppy[i].insertedframe) > FLOPPY_INSERTED_DELAY)) + ((draw_frame_count - floppy[i].insertedframe) > FLOPPY_INSERTED_DELAY)) { - floppy[i].changed = FALSE; + floppy[i].changed = FALSE; } if (!floppy[i].step && !stp) { - if (!floppy[i].dir) - { + if (!floppy[i].dir) + { if (floppy[i].track < floppy[i].tracks + 3) { #ifdef FLOPPY_LOG @@ -524,22 +524,22 @@ void floppyStepSet(BOOLE stp) RP.PostFloppyDriveSeek(i, floppy[i].track); #endif } - } - else - { - if (floppy[i].track > 0) - { + } + else + { + if (floppy[i].track > 0) + { #ifdef FLOPPY_LOG - floppyLogStep(i, floppy[i].track, floppy[i].track - 1); + floppyLogStep(i, floppy[i].track, floppy[i].track - 1); #endif - floppy[i].track--; + floppy[i].track--; #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) - RP.PostFloppyDriveSeek(i, floppy[i].track); + if (RP.GetHeadlessMode()) + RP.PostFloppyDriveSeek(i, floppy[i].track); #endif - } - } + } + } } floppy[i].step = !stp; } @@ -550,7 +550,7 @@ void floppyStepSet(BOOLE stp) /* Will MFM encode one sector from src to dest */ /*=============================================*/ -void floppySectorMfmEncode(uint32_t tra, uint32_t sec, uint8_t *src, uint8_t *dest, uint32_t sync) +void floppySectorMfmEncode(uint32_t tra, uint32_t sec, uint8_t* src, uint8_t* dest, uint32_t sync) { uint32_t x, hck = 0, dck = 0; @@ -560,18 +560,18 @@ void floppySectorMfmEncode(uint32_t tra, uint32_t sec, uint8_t *src, uint8_t *de *(dest + 1) = 0xaa; *(dest + 2) = 0xaa; *(dest + 3) = 0xaa; - *(dest + 4) = (uint8_t) (sync>>8); - *(dest + 5) = (uint8_t) (sync & 0xff); - *(dest + 6) = (uint8_t) (sync>>8); - *(dest + 7) = (uint8_t) (sync & 0xff); + *(dest + 4) = (uint8_t)(sync >> 8); + *(dest + 5) = (uint8_t)(sync & 0xff); + *(dest + 6) = (uint8_t)(sync >> 8); + *(dest + 7) = (uint8_t)(sync & 0xff); /* Track and sector info */ uint32_t tmp = 0xff000000 | (tra << 16) | (sec << 8) | (11 - sec); uint32_t even = (tmp & MFM_MASK); uint32_t odd = ((tmp >> 1) & MFM_MASK); - *(dest + 8) = (uint8_t) ((odd & 0xff000000)>>24); - *(dest + 9) = (uint8_t) ((odd & 0xff0000)>>16); + *(dest + 8) = (uint8_t)((odd & 0xff000000) >> 24); + *(dest + 9) = (uint8_t)((odd & 0xff0000) >> 16); *(dest + 10) = (uint8_t)((odd & 0xff00) >> 8); *(dest + 11) = (uint8_t)(odd & 0xff); *(dest + 12) = (uint8_t)((even & 0xff000000) >> 24); @@ -581,64 +581,64 @@ void floppySectorMfmEncode(uint32_t tra, uint32_t sec, uint8_t *src, uint8_t *de /* Fill unused space */ - for (x = 16 ; x < 48; x++) + for (x = 16; x < 48; x++) { *(dest + x) = MFM_FILLB; } /* Encode data section of sector */ - for (x = 64 ; x < 576; x++) + for (x = 64; x < 576; x++) { tmp = *(src + x - 64); odd = (tmp & 0x55); - even = (tmp>>1) & 0x55; - *(dest + x) = (uint8_t) (even | MFM_FILLB); - *(dest + x + 512) = (uint8_t) (odd | MFM_FILLB); + even = (tmp >> 1) & 0x55; + *(dest + x) = (uint8_t)(even | MFM_FILLB); + *(dest + x + 512) = (uint8_t)(odd | MFM_FILLB); } /* Calculate checksum for unused space */ - for(x = 8; x < 48; x += 4) + for (x = 8; x < 48; x += 4) { - hck ^= (((uint32_t) *(dest + x))<<24) | (((uint32_t) *(dest + x + 1))<<16) | - (((uint32_t) *(dest + x + 2))<<8) | ((uint32_t) *(dest + x + 3)); + hck ^= (((uint32_t) * (dest + x)) << 24) | (((uint32_t) * (dest + x + 1)) << 16) | + (((uint32_t) * (dest + x + 2)) << 8) | ((uint32_t) * (dest + x + 3)); } - even = odd = hck; + even = odd = hck; odd >>= 1; even |= MFM_FILLL; odd |= MFM_FILLL; - *(dest + 48) = (uint8_t) ((odd & 0xff000000)>>24); - *(dest + 49) = (uint8_t) ((odd & 0xff0000)>>16); - *(dest + 50) = (uint8_t) ((odd & 0xff00)>>8); - *(dest + 51) = (uint8_t) (odd & 0xff); - *(dest + 52) = (uint8_t) ((even & 0xff000000)>>24); - *(dest + 53) = (uint8_t) ((even & 0xff0000)>>16); - *(dest + 54) = (uint8_t) ((even & 0xff00)>>8); - *(dest + 55) = (uint8_t) (even & 0xff); + *(dest + 48) = (uint8_t)((odd & 0xff000000) >> 24); + *(dest + 49) = (uint8_t)((odd & 0xff0000) >> 16); + *(dest + 50) = (uint8_t)((odd & 0xff00) >> 8); + *(dest + 51) = (uint8_t)(odd & 0xff); + *(dest + 52) = (uint8_t)((even & 0xff000000) >> 24); + *(dest + 53) = (uint8_t)((even & 0xff0000) >> 16); + *(dest + 54) = (uint8_t)((even & 0xff00) >> 8); + *(dest + 55) = (uint8_t)(even & 0xff); /* Calculate checksum for data section */ - for(x = 64; x < 1088; x += 4) + for (x = 64; x < 1088; x += 4) { - dck ^= (((uint32_t) *(dest + x))<<24) | (((uint32_t) *(dest + x + 1))<<16) | - (((uint32_t) *(dest + x + 2))<< 8) | ((uint32_t) *(dest + x + 3)); + dck ^= (((uint32_t) * (dest + x)) << 24) | (((uint32_t) * (dest + x + 1)) << 16) | + (((uint32_t) * (dest + x + 2)) << 8) | ((uint32_t) * (dest + x + 3)); } even = odd = dck; odd >>= 1; even |= MFM_FILLL; odd |= MFM_FILLL; - *(dest + 56) = (uint8_t) ((odd & 0xff000000)>>24); - *(dest + 57) = (uint8_t) ((odd & 0xff0000)>>16); - *(dest + 58) = (uint8_t) ((odd & 0xff00)>>8); - *(dest + 59) = (uint8_t) (odd & 0xff); - *(dest + 60) = (uint8_t) ((even & 0xff000000)>>24); - *(dest + 61) = (uint8_t) ((even & 0xff0000)>>16); - *(dest + 62) = (uint8_t) ((even & 0xff00)>>8); - *(dest + 63) = (uint8_t) (even & 0xff); + *(dest + 56) = (uint8_t)((odd & 0xff000000) >> 24); + *(dest + 57) = (uint8_t)((odd & 0xff0000) >> 16); + *(dest + 58) = (uint8_t)((odd & 0xff00) >> 8); + *(dest + 59) = (uint8_t)(odd & 0xff); + *(dest + 60) = (uint8_t)((even & 0xff000000) >> 24); + *(dest + 61) = (uint8_t)((even & 0xff0000) >> 16); + *(dest + 62) = (uint8_t)((even & 0xff00) >> 8); + *(dest + 63) = (uint8_t)(even & 0xff); } -void floppyGapMfmEncode(uint8_t *dst) +void floppyGapMfmEncode(uint8_t* dst) { for (uint32_t i = 0; i < FLOPPY_GAP_BYTES; i++) { @@ -653,12 +653,12 @@ void floppyGapMfmEncode(uint8_t *dst) /* Returns the sector number found in the MFM encoded header */ /*===========================================================*/ -uint32_t floppySectorMfmDecode(uint8_t *src, uint8_t *dst, uint32_t track) +uint32_t floppySectorMfmDecode(uint8_t* src, uint8_t* dst, uint32_t track) { uint32_t odd = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3]; uint32_t even = (src[4] << 24) | (src[5] << 16) | (src[6] << 8) | src[7]; even &= MFM_MASK; - odd = (odd & MFM_MASK) << 1; + odd = (odd & MFM_MASK) << 1; even |= odd; uint32_t src_ff = (even & 0xff000000) >> 24; uint32_t src_sector = (even & 0xff00) >> 8; @@ -672,7 +672,7 @@ uint32_t floppySectorMfmDecode(uint8_t *src, uint8_t *dst, uint32_t track) { even = (*(src + i)) & MFM_MASK; odd = (*(src + i + 512)) & MFM_MASK; - *(dst++) = (uint8_t) ((even<<1) | odd); + *(dst++) = (uint8_t)((even << 1) | odd); } return src_sector; } @@ -684,14 +684,14 @@ uint32_t floppySectorMfmDecode(uint8_t *src, uint8_t *dst, uint32_t track) /* returns TRUE if this really was a sector */ /*=================================================================*/ -BOOLE floppySectorSave(uint32_t drive, uint32_t track, uint8_t *mfmsrc) +BOOLE floppySectorSave(uint32_t drive, uint32_t track, uint8_t* mfmsrc) { uint32_t sector; if (!floppyIsWriteProtected(drive)) { if ((sector = floppySectorMfmDecode(mfmsrc, tmptrack, track)) < 11) { - fseek(floppy[drive].F, floppy[drive].trackinfo[track].file_offset + sector*512, SEEK_SET); + fseek(floppy[drive].F, floppy[drive].trackinfo[track].file_offset + sector * 512, SEEK_SET); fwrite(tmptrack, 1, 512, floppy[drive].F); // Problem with keeping the MFM for ADFs is that the sector sequence could be anything and they are enumerated. Re-encode from plain data. @@ -722,13 +722,13 @@ static void floppySetReadOnlyEnforced(uint32_t drive, bool enforce) /* Track is MFM tracks (0 - 163) */ /*===============================*/ -void floppyTrackMfmEncode(uint32_t track, uint8_t *src, uint8_t *dst, uint32_t sync) +void floppyTrackMfmEncode(uint32_t track, uint8_t* src, uint8_t* dst, uint32_t sync) { for (uint32_t i = 0; i < 11; i++) { - floppySectorMfmEncode(track, i, src + i*512, dst + i*1088, sync); + floppySectorMfmEncode(track, i, src + i * 512, dst + i * 1088, sync); } - floppyGapMfmEncode(dst + 11*1088); + floppyGapMfmEncode(dst + 11 * 1088); } /*=======================================================*/ @@ -738,7 +738,7 @@ void floppyTrackMfmEncode(uint32_t track, uint8_t *src, uint8_t *dst, uint32_t s void floppyTrackLoad(uint32_t drive, uint32_t track) { - fseek(floppy[drive].F, track*5632, SEEK_SET); + fseek(floppy[drive].F, track * 5632, SEEK_SET); fread(tmptrack, 1, 5632, floppy[drive].F); floppyTrackMfmEncode(track, tmptrack, floppy[drive].trackinfo[track].mfm_data, 0x4489); } @@ -761,41 +761,41 @@ void floppyError(uint32_t drive, uint32_t errorID) /** Write the current date/time into the floppy disk buffer. */ -static void floppyWriteDiskDate(uint8_t *strBuffer) +static void floppyWriteDiskDate(uint8_t* strBuffer) { timeb time; const time_t timediff = ((8 * 365 + 2) * (24 * 60 * 60)) * (time_t)1000; const time_t msecs_per_day = 24 * 60 * 60 * 1000; - + ftime(&time); time_t sec = time.time; sec -= time.timezone * 60; - if(time.dstflag) sec += 3600; - + if (time.dstflag) sec += 3600; + time_t t = sec * 1000 + time.millitm - timediff; - if(t < 0) t = 0; + if (t < 0) t = 0; time_t days = t / msecs_per_day; t -= days * msecs_per_day; time_t mins = t / (60 * 1000); t -= mins * (60 * 1000); time_t ticks = t / (1000 / 50); - - memoryWriteLongToPointer((uint32_t) days, strBuffer); - memoryWriteLongToPointer((uint32_t) mins, strBuffer + 4); - memoryWriteLongToPointer((uint32_t) ticks, strBuffer + 8); + + memoryWriteLongToPointer((uint32_t)days, strBuffer); + memoryWriteLongToPointer((uint32_t)mins, strBuffer + 4); + memoryWriteLongToPointer((uint32_t)ticks, strBuffer + 8); } /** Write the checksum into the floppy disk buffer. */ -static void floppyWriteDiskChecksum(const uint8_t *strBuffer, uint8_t *strChecksum) +static void floppyWriteDiskChecksum(const uint8_t* strBuffer, uint8_t* strChecksum) { uint32_t lChecksum = 0; - for (int i = 0; i < 512; i+= 4) { - const uint8_t *p = strBuffer + i; + for (int i = 0; i < 512; i += 4) { + const uint8_t* p = strBuffer + i; lChecksum += memoryReadLongFromPointer(p); } @@ -804,51 +804,51 @@ static void floppyWriteDiskChecksum(const uint8_t *strBuffer, uint8_t *strChecks memoryWriteLongToPointer(lChecksum, strChecksum); } -bool floppyValidateAmigaDOSVolumeName(const char *strVolumeName) +bool floppyValidateAmigaDOSVolumeName(const char* strVolumeName) { - char *strIllegalVolumeNames[7] = { "SYS", "DEVS", "LIBS", "FONTS", "C", "L", "S" }; + char* strIllegalVolumeNames[7] = { "SYS", "DEVS", "LIBS", "FONTS", "C", "L", "S" }; char strIllegalCharacters[2] = { ':', '/' }; int i; - if(strVolumeName == nullptr) + if (strVolumeName == nullptr) return false; - if(strVolumeName[0] == '\0') + if (strVolumeName[0] == '\0') return false; - if(strlen(strVolumeName) > 30) + if (strlen(strVolumeName) > 30) return false; - for(i = 0; i < 2; i++) - if(strchr(strVolumeName, strIllegalCharacters[i]) != nullptr) + for (i = 0; i < 2; i++) + if (strchr(strVolumeName, strIllegalCharacters[i]) != nullptr) return false; - for(i = 0; i < 7; i++) - if(stricmp(strVolumeName, strIllegalVolumeNames[i]) == 0) + for (i = 0; i < 7; i++) + if (stricmp(strVolumeName, strIllegalVolumeNames[i]) == 0) return false; return true; } -static void floppyWriteDiskBootblock(uint8_t *strCylinderContent, bool bFFS, bool bBootable) +static void floppyWriteDiskBootblock(uint8_t* strCylinderContent, bool bFFS, bool bBootable) { - strcpy((char *) strCylinderContent, "DOS"); + strcpy((char*)strCylinderContent, "DOS"); strCylinderContent[3] = bFFS ? 1 : 0; - if(bBootable) - memcpy(strCylinderContent, - bFFS ? floppyBootBlockFFS : floppyBootBlockOFS, + if (bBootable) + memcpy(strCylinderContent, + bFFS ? floppyBootBlockFFS : floppyBootBlockOFS, bFFS ? sizeof(floppyBootBlockFFS) : sizeof(floppyBootBlockOFS)); } -static void floppyWriteDiskRootBlock(uint8_t *strCylinderContent, uint32_t lBlockIndex, const uint8_t *strVolumeLabel) +static void floppyWriteDiskRootBlock(uint8_t* strCylinderContent, uint32_t lBlockIndex, const uint8_t* strVolumeLabel) { - strCylinderContent[0+3] = 2; - strCylinderContent[12+3] = 0x48; + strCylinderContent[0 + 3] = 2; + strCylinderContent[12 + 3] = 0x48; strCylinderContent[312] = strCylinderContent[313] = strCylinderContent[314] = strCylinderContent[315] = 0xff; - strCylinderContent[316+2] = (lBlockIndex + 1) >> 8; strCylinderContent[316+3] = (lBlockIndex + 1) & 255; - strCylinderContent[432] = (uint8_t) strlen((char *) strVolumeLabel); - strcpy((char *) strCylinderContent + 433, (const char *) strVolumeLabel); + strCylinderContent[316 + 2] = (lBlockIndex + 1) >> 8; strCylinderContent[316 + 3] = (lBlockIndex + 1) & 255; + strCylinderContent[432] = (uint8_t)strlen((char*)strVolumeLabel); + strcpy((char*)strCylinderContent + 433, (const char*)strVolumeLabel); strCylinderContent[508 + 3] = 1; floppyWriteDiskDate(strCylinderContent + 420); memcpy(strCylinderContent + 472, strCylinderContent + 420, 3 * 4); @@ -859,41 +859,41 @@ static void floppyWriteDiskRootBlock(uint8_t *strCylinderContent, uint32_t lBloc floppyWriteDiskChecksum(strCylinderContent + 512, strCylinderContent + 512); } -bool floppyImageADFCreate(char *strImageFilename, char *strVolumeLabel, bool bFormat, bool bBootable, bool bFFS) +bool floppyImageADFCreate(char* strImageFilename, char* strVolumeLabel, bool bFormat, bool bBootable, bool bFFS) { bool bResult = false; - uint32_t lImageSize = 2*11*80*512; // 2 tracks per cylinder, 11 sectors per track, 80 cylinders, 512 bytes per sector - uint32_t lCylinderSize = 2*11*512; // 2 tracks per cylinder, 11 sectors per track, 512 bytes per sector + uint32_t lImageSize = 2 * 11 * 80 * 512; // 2 tracks per cylinder, 11 sectors per track, 80 cylinders, 512 bytes per sector + uint32_t lCylinderSize = 2 * 11 * 512; // 2 tracks per cylinder, 11 sectors per track, 512 bytes per sector - FILE *f = nullptr; + FILE* f = nullptr; - if(bFormat) { - if(!floppyValidateAmigaDOSVolumeName(strVolumeLabel)) return false; + if (bFormat) { + if (!floppyValidateAmigaDOSVolumeName(strVolumeLabel)) return false; } f = fopen(strImageFilename, "wb"); - if(f) - { - uint8_t *strCylinderContent = nullptr; + if (f) + { + uint8_t* strCylinderContent = nullptr; - strCylinderContent = (uint8_t *) malloc(lCylinderSize); + strCylinderContent = (uint8_t*)malloc(lCylinderSize); - if(strCylinderContent) + if (strCylinderContent) { - for(uint32_t i = 0; i < lImageSize; i += lCylinderSize) + for (uint32_t i = 0; i < lImageSize; i += lCylinderSize) { memset(strCylinderContent, 0, lCylinderSize); - if(bFormat) { - if(i == 0) - floppyWriteDiskBootblock(strCylinderContent, - bFFS, + if (bFormat) { + if (i == 0) + floppyWriteDiskBootblock(strCylinderContent, + bFFS, bBootable); - else if(i == lImageSize / 2) - floppyWriteDiskRootBlock(strCylinderContent, - lImageSize / 1024, - (uint8_t *) strVolumeLabel); + else if (i == lImageSize / 2) + floppyWriteDiskRootBlock(strCylinderContent, + lImageSize / 1024, + (uint8_t*)strVolumeLabel); } fwrite(strCylinderContent, lCylinderSize, 1, f); @@ -916,12 +916,12 @@ bool floppyImageADFCreate(char *strImageFilename, char *strVolumeLabel, bool bFo /* Uncompress a BZip image */ /*=========================*/ -BOOLE floppyImageCompressedBZipPrepare(char *diskname, uint32_t drive) +BOOLE floppyImageCompressedBZipPrepare(char* diskname, uint32_t drive) { - char *gzname; + char* gzname; char cmdline[512]; - if( (gzname = fileopsGetTemporaryFilename()) == nullptr) + if ((gzname = fileopsGetTemporaryFilename()) == nullptr) { floppyError(drive, FLOPPY_ERROR_COMPRESS_TMPFILEOPEN); return FALSE; @@ -939,22 +939,22 @@ BOOLE floppyImageCompressedBZipPrepare(char *diskname, uint32_t drive) /* Uncompress a DMS image */ /*========================*/ -BOOLE floppyImageCompressedDMSPrepare(char *diskname, uint32_t drive) +BOOLE floppyImageCompressedDMSPrepare(char* diskname, uint32_t drive) { - char *gzname; + char* gzname; - if((gzname = fileopsGetTemporaryFilename()) == nullptr) + if ((gzname = fileopsGetTemporaryFilename()) == nullptr) { floppyError(drive, FLOPPY_ERROR_COMPRESS_TMPFILEOPEN); return FALSE; } - + USHORT result = dmsUnpack(diskname, gzname); - if(result != 0) + if (result != 0) { char szErrorMessage[1024] = ""; - dmsErrMsg(result, (char *) diskname, gzname, (char *) szErrorMessage); + dmsErrMsg(result, (char*)diskname, gzname, (char*)szErrorMessage); fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "ERROR extracting DMS floppy image: %s", szErrorMessage); @@ -972,16 +972,16 @@ BOOLE floppyImageCompressedDMSPrepare(char *diskname, uint32_t drive) /* Uncompress a GZipped image */ /*============================*/ -BOOLE floppyImageCompressedGZipPrepare(char *diskname, uint32_t drive) +BOOLE floppyImageCompressedGZipPrepare(char* diskname, uint32_t drive) { - char *gzname; - if( (gzname = fileopsGetTemporaryFilename()) == nullptr) + char* gzname; + if ((gzname = fileopsGetTemporaryFilename()) == nullptr) { floppyError(drive, FLOPPY_ERROR_COMPRESS_TMPFILEOPEN); return FALSE; } - if(!gzUnpack(diskname, gzname)) + if (!gzUnpack(diskname, gzname)) { free(gzname); return FALSE; @@ -990,7 +990,7 @@ BOOLE floppyImageCompressedGZipPrepare(char *diskname, uint32_t drive) strcpy(floppy[drive].imagenamereal, gzname); free(gzname); floppy[drive].zipped = TRUE; - if((access(diskname, 2 )) == -1 ) + if ((access(diskname, 2)) == -1) { floppySetReadOnlyEnforced(drive, true); } @@ -1003,30 +1003,30 @@ BOOLE floppyImageCompressedGZipPrepare(char *diskname, uint32_t drive) void floppyImageCompressedRemove(uint32_t drive) { - if(floppy[drive].zipped) + if (floppy[drive].zipped) { - if( (!floppyIsWriteProtected(drive)) && - ((access(floppy[drive].imagename, 2)) != -1 )) // file is not read-only + if ((!floppyIsWriteProtected(drive)) && + ((access(floppy[drive].imagename, 2)) != -1)) // file is not read-only { - char *dotptr = strrchr(floppy[drive].imagename, '.'); - if (dotptr != nullptr) - { - if ((strcmpi(dotptr, ".gz") == 0) || - (strcmpi(dotptr, ".z") == 0) || - (strcmpi(dotptr, ".adz") == 0)) - { - if(!gzPack(floppy[drive].imagenamereal, floppy[drive].imagename)) - { - fellowAddLog("floppyImageCompressedRemove(): Couldn't recompress file %s\n", - floppy[drive].imagename); - } - else - { - fellowAddLog("floppyImageCompressedRemove(): Succesfully recompressed file %s\n", - floppy[drive].imagename); - } - } - } + char* dotptr = strrchr(floppy[drive].imagename, '.'); + if (dotptr != nullptr) + { + if ((strcmpi(dotptr, ".gz") == 0) || + (strcmpi(dotptr, ".z") == 0) || + (strcmpi(dotptr, ".adz") == 0)) + { + if (!gzPack(floppy[drive].imagenamereal, floppy[drive].imagename)) + { + fellowAddLog("floppyImageCompressedRemove(): Couldn't recompress file %s\n", + floppy[drive].imagename); + } + else + { + fellowAddLog("floppyImageCompressedRemove(): Succesfully recompressed file %s\n", + floppy[drive].imagename); + } + } + } } floppy[drive].zipped = FALSE; remove(floppy[drive].imagenamereal); @@ -1039,15 +1039,15 @@ void floppyImageCompressedRemove(uint32_t drive) /* compressed. */ /*============================*/ -BOOLE floppyImageCompressedPrepare(char *diskname, uint32_t drive) +BOOLE floppyImageCompressedPrepare(char* diskname, uint32_t drive) { - char *dotptr = strrchr(diskname, '.'); + char* dotptr = strrchr(diskname, '.'); if (dotptr == nullptr) { return FALSE; } - if((strcmpi(dotptr, ".bz2") == 0) || + if ((strcmpi(dotptr, ".bz2") == 0) || (strcmpi(dotptr, ".bz") == 0)) { return floppyImageCompressedBZipPrepare(diskname, drive); @@ -1081,19 +1081,19 @@ void floppyImageRemove(uint32_t drive) if (floppy[drive].imagestatus == FLOPPY_STATUS_NORMAL_OK || floppy[drive].imagestatus == FLOPPY_STATUS_EXTENDED_OK) { - if (floppy[drive].zipped) - { - floppyImageCompressedRemove(drive); - } + if (floppy[drive].zipped) + { + floppyImageCompressedRemove(drive); + } } #ifdef FELLOW_SUPPORT_CAPS - else if(floppy[drive].imagestatus == FLOPPY_STATUS_IPF_OK) + else if (floppy[drive].imagestatus == FLOPPY_STATUS_IPF_OK) { capsUnloadImage(drive); } #endif #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) + if (RP.GetHeadlessMode()) { RP.SendFloppyDriveContent(drive, "", floppyIsWriteProtected(drive) ? true : false); } @@ -1108,7 +1108,7 @@ void floppyImageRemove(uint32_t drive) /* Prepare a disk image, ie. uncompress and report errors */ /*========================================================*/ -void floppyImagePrepare(char *diskname, uint32_t drive) +void floppyImagePrepare(char* diskname, uint32_t drive) { if (!floppyImageCompressedPrepare(diskname, drive)) { @@ -1125,7 +1125,7 @@ void floppyImagePrepare(char *diskname, uint32_t drive) /* Returns the image status */ /*=======================================*/ -uint32_t floppyImageGeometryCheck(fs_navig_point *fsnp, uint32_t drive) +uint32_t floppyImageGeometryCheck(fs_navig_point* fsnp, uint32_t drive) { char head[8]; fread(head, 1, 8, floppy[drive].F); @@ -1149,7 +1149,7 @@ uint32_t floppyImageGeometryCheck(fs_navig_point *fsnp, uint32_t drive) else { floppy[drive].tracks = fsnp->size / 11264; - if ((floppy[drive].tracks*11264) != (uint32_t) fsnp->size) + if ((floppy[drive].tracks * 11264) != (uint32_t)fsnp->size) { floppyError(drive, FLOPPY_ERROR_SIZE); } @@ -1171,11 +1171,11 @@ uint32_t floppyImageGeometryCheck(fs_navig_point *fsnp, uint32_t drive) void floppyImageNormalLoad(uint32_t drive) { - for (uint32_t i = 0; i < floppy[drive].tracks*2; i++) + for (uint32_t i = 0; i < floppy[drive].tracks * 2; i++) { - floppy[drive].trackinfo[i].file_offset = i*5632; + floppy[drive].trackinfo[i].file_offset = i * 5632; floppy[drive].trackinfo[i].mfm_length = 11968 + FLOPPY_GAP_BYTES; - floppy[drive].trackinfo[i].mfm_data = floppy[drive].mfm_data + i*(11968 + FLOPPY_GAP_BYTES); + floppy[drive].trackinfo[i].mfm_data = floppy[drive].mfm_data + i * (11968 + FLOPPY_GAP_BYTES); floppyTrackLoad(drive, i); } floppy[drive].inserted = TRUE; @@ -1194,11 +1194,11 @@ void floppyImageExtendedLoad(uint32_t drive) /* read table from header containing sync and length words */ fseek(floppy[drive].F, 8, SEEK_SET); - for (i = 0; i < floppy[drive].tracks*2; i++) + for (i = 0; i < floppy[drive].tracks * 2; i++) { fread(tinfo, 1, 4, floppy[drive].F); - syncs[i] = (((uint32_t)tinfo[0]) << 8) | ((uint32_t) tinfo[1]); - lengths[i] = (((uint32_t)tinfo[2]) << 8) | ((uint32_t) tinfo[3]); + syncs[i] = (((uint32_t)tinfo[0]) << 8) | ((uint32_t)tinfo[1]); + lengths[i] = (((uint32_t)tinfo[2]) << 8) | ((uint32_t)tinfo[3]); } /* initial offset of track data in file, and in the internal mfm_buffer */ @@ -1206,12 +1206,12 @@ void floppyImageExtendedLoad(uint32_t drive) uint32_t mfm_offset = 0; /* read the actual track data */ fseek(floppy[drive].F, file_offset, SEEK_SET); - for (i = 0; i < floppy[drive].tracks*2; i++) + for (i = 0; i < floppy[drive].tracks * 2; i++) { floppy[drive].trackinfo[i].mfm_data = floppy[drive].mfm_data + mfm_offset; floppy[drive].trackinfo[i].file_offset = file_offset; if (!syncs[i]) /* Sync = 0 means AmigaDOS tracks (Stored non-MFM encoded) */ - { + { floppy[drive].trackinfo[i].mfm_length = 11968 + FLOPPY_GAP_BYTES; mfm_offset += floppy[drive].trackinfo[i].mfm_length; fread(tmptrack, 1, lengths[i], floppy[drive].F); @@ -1219,14 +1219,14 @@ void floppyImageExtendedLoad(uint32_t drive) } else /* raw MFM tracks */ { - mfm_offset += lengths[i] + 2; + mfm_offset += lengths[i] + 2; floppy[drive].trackinfo[i].mfm_length = lengths[i] + 2; - floppy[drive].trackinfo[i].mfm_data[0] = (uint8_t) (syncs[i] >> 8); - floppy[drive].trackinfo[i].mfm_data[1] = (uint8_t) (syncs[i] & 0xff); + floppy[drive].trackinfo[i].mfm_data[0] = (uint8_t)(syncs[i] >> 8); + floppy[drive].trackinfo[i].mfm_data[1] = (uint8_t)(syncs[i] & 0xff); fread(floppy[drive].trackinfo[i].mfm_data + 2, 1, lengths[i], floppy[drive].F); } file_offset += lengths[i]; - } + } floppy[drive].inserted = TRUE; floppy[drive].insertedframe = draw_frame_count; } @@ -1238,23 +1238,23 @@ void floppyImageExtendedLoad(uint32_t drive) void floppyImageIPFLoad(uint32_t drive) { - uint8_t *LastTrackMFMData = floppy[drive].mfm_data; + uint8_t* LastTrackMFMData = floppy[drive].mfm_data; - if(!capsLoadImage(drive, floppy[drive].F, &floppy[drive].tracks)) + if (!capsLoadImage(drive, floppy[drive].F, &floppy[drive].tracks)) { fellowAddLog("floppyImageIPFLoad(): Unable to load CAPS IPF Image. Is the Plug-In installed correctly?\n"); return; } - for (uint32_t i = 0; i < floppy[drive].tracks*2; i++) + for (uint32_t i = 0; i < floppy[drive].tracks * 2; i++) { uint32_t maxtracklength; - floppy[drive].trackinfo[i].mfm_data = LastTrackMFMData; + floppy[drive].trackinfo[i].mfm_data = LastTrackMFMData; capsLoadTrack(drive, i, floppy[drive].trackinfo[i].mfm_data, - &floppy[drive].trackinfo[i].mfm_length, + &floppy[drive].trackinfo[i].mfm_length, &maxtracklength, floppy[drive].timebuf, &floppy[drive].flakey); @@ -1270,12 +1270,12 @@ void floppyImageIPFLoad(uint32_t drive) /** Insert an image into a floppy drive */ -void floppySetDiskImage(uint32_t drive, char *diskname) +void floppySetDiskImage(uint32_t drive, char* diskname) { - fs_navig_point *fsnp; + fs_navig_point* fsnp; BOOLE bSuccess = FALSE; - if(floppy[drive].enabled) + if (floppy[drive].enabled) { fellowAddLog("floppySetDiskImage(%u, '%s')...\n", drive, diskname); } @@ -1291,7 +1291,7 @@ void floppySetDiskImage(uint32_t drive, char *diskname) floppy[drive].imagestatus = FLOPPY_STATUS_NONE; strcpy(floppy[drive].imagename, ""); } - else + else { if ((fsnp = fsWrapMakePoint(diskname)) == nullptr) { @@ -1305,61 +1305,61 @@ void floppySetDiskImage(uint32_t drive, char *diskname) } else { - floppyImagePrepare(diskname, drive); - if (floppy[drive].zipped) - { - free(fsnp); - if ((fsnp = fsWrapMakePoint(floppy[drive].imagenamereal)) == nullptr) - { - floppyError(drive, FLOPPY_ERROR_COMPRESS); - } - } - if (floppy[drive].imagestatus != FLOPPY_STATUS_ERROR) - { - if (!fsnp->writeable) - floppySetReadOnlyEnforced(drive, true); - if ((floppy[drive].F = fopen(floppy[drive].imagenamereal, - (floppyIsWriteProtected(drive) ? "rb" : "r+b"))) == nullptr) - { - floppyError(drive, (floppy[drive].zipped) ? FLOPPY_ERROR_COMPRESS : FLOPPY_ERROR_FILE); - } - else - { - strcpy(floppy[drive].imagename, diskname); - switch (floppyImageGeometryCheck(fsnp, drive)) - { - case FLOPPY_STATUS_NORMAL_OK: - floppyImageNormalLoad(drive); - bSuccess = TRUE; - break; - case FLOPPY_STATUS_EXTENDED_OK: - floppyImageExtendedLoad(drive); - bSuccess = TRUE; - break; - case FLOPPY_STATUS_EXTENDED2_OK: - fellowAddLog("floppySetDiskImage(%u, '%s') ERROR: floppy image is in unsupported extended2 ADF format.\n", - drive, diskname); - break; + floppyImagePrepare(diskname, drive); + if (floppy[drive].zipped) + { + free(fsnp); + if ((fsnp = fsWrapMakePoint(floppy[drive].imagenamereal)) == nullptr) + { + floppyError(drive, FLOPPY_ERROR_COMPRESS); + } + } + if (floppy[drive].imagestatus != FLOPPY_STATUS_ERROR) + { + if (!fsnp->writeable) + floppySetReadOnlyEnforced(drive, true); + if ((floppy[drive].F = fopen(floppy[drive].imagenamereal, + (floppyIsWriteProtected(drive) ? "rb" : "r+b"))) == nullptr) + { + floppyError(drive, (floppy[drive].zipped) ? FLOPPY_ERROR_COMPRESS : FLOPPY_ERROR_FILE); + } + else + { + strcpy(floppy[drive].imagename, diskname); + switch (floppyImageGeometryCheck(fsnp, drive)) + { + case FLOPPY_STATUS_NORMAL_OK: + floppyImageNormalLoad(drive); + bSuccess = TRUE; + break; + case FLOPPY_STATUS_EXTENDED_OK: + floppyImageExtendedLoad(drive); + bSuccess = TRUE; + break; + case FLOPPY_STATUS_EXTENDED2_OK: + fellowAddLog("floppySetDiskImage(%u, '%s') ERROR: floppy image is in unsupported extended2 ADF format.\n", + drive, diskname); + break; #ifdef FELLOW_SUPPORT_CAPS - case FLOPPY_STATUS_IPF_OK: - floppyImageIPFLoad(drive); - bSuccess = TRUE; - break; + case FLOPPY_STATUS_IPF_OK: + floppyImageIPFLoad(drive); + bSuccess = TRUE; + break; #endif - default: - /* Error already set by floppyImageGeometryCheck() */ - fellowAddLog("floppySetDiskImage(%u, '%s') ERROR: unexpected floppy image geometry status.\n", - drive, diskname); - break; - } + default: + /* Error already set by floppyImageGeometryCheck() */ + fellowAddLog("floppySetDiskImage(%u, '%s') ERROR: unexpected floppy image geometry status.\n", + drive, diskname); + break; + } #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode() && bSuccess) - { - RP.SendFloppyDriveContent(drive, diskname, floppyIsWriteProtected(drive) ? true : false); - } + if (RP.GetHeadlessMode() && bSuccess) + { + RP.SendFloppyDriveContent(drive, diskname, floppyIsWriteProtected(drive) ? true : false); + } #endif - } - } + } + } } free(fsnp); } @@ -1386,7 +1386,7 @@ void floppySetReadOnlyConfig(uint32_t drive, BOOLE readonly) } #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) + if (RP.GetHeadlessMode()) RP.SendFloppyDriveReadOnly(drive, readonly ? true : false); #endif } @@ -1400,7 +1400,7 @@ void floppySetFastDMA(BOOLE fastDMA) floppy_fast = fastDMA; #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) + if (RP.GetHeadlessMode()) RP.SendFloppyTurbo(fastDMA ? true : false); #endif } @@ -1432,10 +1432,10 @@ void floppyDriveTableInit() floppy[i].zipped = FALSE; floppy[i].changed = TRUE; /* Need to be large enough to hold UAE--ADF encoded tracks */ - floppy[i].mfm_data = (uint8_t *) malloc(FLOPPY_TRACKS*25000); + floppy[i].mfm_data = (uint8_t*)malloc(FLOPPY_TRACKS * 25000); #ifdef FELLOW_SUPPORT_CAPS floppy[i].flakey = FALSE; - floppy[i].timebuf = (uint32_t *) malloc(FLOPPY_TRACKS*25000); + floppy[i].timebuf = (uint32_t*)malloc(FLOPPY_TRACKS * 25000); #endif } } @@ -1542,7 +1542,7 @@ BOOLE floppyHasIndex(uint32_t sel_drv) uint32_t floppyGetLinearTrack(uint32_t sel_drv) { - return floppy[sel_drv].track*2 + floppy[sel_drv].side; + return floppy[sel_drv].track * 2 + floppy[sel_drv].side; } BOOLE floppyIsSpinning(uint32_t sel_drv) @@ -1571,12 +1571,12 @@ void floppyDMAReadInit(uint32_t drive) } // Workaround, require normal sync with MFM generated from ADF. (North and South (?), Prince of Persia, Lemmings 2) - if(floppy[drive].imagestatus == FLOPPY_STATUS_NORMAL_OK && dsksync != 0 && dsksync != 0x4489 && dsksync != 0x8914) + if (floppy[drive].imagestatus == FLOPPY_STATUS_NORMAL_OK && dsksync != 0 && dsksync != 0x4489 && dsksync != 0x8914) fellowAddLog("floppyDMAReadInit(): WARNING: unusual dsksync value encountered: 0x%x\n", dsksync); - floppy_DMA.wait_for_sync = (adcon & 0x0400) - && ( (floppy[drive].imagestatus != FLOPPY_STATUS_NORMAL_OK && dsksync != 0) || - (floppy[drive].imagestatus == FLOPPY_STATUS_NORMAL_OK && (dsksync == 0x4489 || dsksync == 0x8914 || dsksync == 0x4124))); + floppy_DMA.wait_for_sync = (adcon & 0x0400) + && ((floppy[drive].imagestatus != FLOPPY_STATUS_NORMAL_OK && dsksync != 0) || + (floppy[drive].imagestatus == FLOPPY_STATUS_NORMAL_OK && (dsksync == 0x4489 || dsksync == 0x8914 || dsksync == 0x4124))); floppy_DMA.sync_found = FALSE; floppy_DMA.dont_use_gap = ((cpuGetPC() & 0xf80000) == 0xf80000); @@ -1622,7 +1622,7 @@ void floppyDMAWriteInit(int32_t drive) BOOLE ended = FALSE; #ifdef RETRO_PLATFORM - if(RP.GetHeadlessMode()) + if (RP.GetHeadlessMode()) RP.PostFloppyDriveLED(drive, true, true); #endif @@ -1641,8 +1641,8 @@ void floppyDMAWriteInit(int32_t drive) { if (floppySectorSave(drive, track_lin, memory_chip + pos)) { - length -= 1080; - pos += 1080; + length -= 1080; + pos += 1080; } } else @@ -1761,7 +1761,7 @@ void floppyNextByte(uint32_t sel_drv, uint32_t track) uint32_t modulo; #ifdef FELLOW_SUPPORT_CAPS uint32_t previous_motor_ticks = floppy[sel_drv].motor_ticks; - if(floppy[sel_drv].imagestatus == FLOPPY_STATUS_IPF_OK) + if (floppy[sel_drv].imagestatus == FLOPPY_STATUS_IPF_OK) { modulo = floppy[sel_drv].trackinfo[track].mfm_length; } @@ -1769,7 +1769,7 @@ void floppyNextByte(uint32_t sel_drv, uint32_t track) #endif { modulo = (floppyDMAReadStarted() && floppy_DMA.dont_use_gap) ? ((11968 < floppy[sel_drv].trackinfo[track].mfm_length) ? 11968 : floppy[sel_drv].trackinfo[track].mfm_length) : - floppy[sel_drv].trackinfo[track].mfm_length; + floppy[sel_drv].trackinfo[track].mfm_length; } if (modulo == 0) { @@ -1782,16 +1782,16 @@ void floppyNextByte(uint32_t sel_drv, uint32_t track) } #ifdef FELLOW_SUPPORT_CAPS - if(previous_motor_ticks > floppy[sel_drv].motor_ticks) + if (previous_motor_ticks > floppy[sel_drv].motor_ticks) { - if(floppy[sel_drv].imagestatus == FLOPPY_STATUS_IPF_OK && floppy[sel_drv].flakey) + if (floppy[sel_drv].imagestatus == FLOPPY_STATUS_IPF_OK && floppy[sel_drv].flakey) { - uint32_t track = floppy[sel_drv].track; + uint32_t track = floppy[sel_drv].track; capsLoadNextRevolution( - sel_drv, - floppy[sel_drv].track, - floppy[sel_drv].trackinfo[track].mfm_data, - &floppy[sel_drv].trackinfo[track].mfm_length); + sel_drv, + floppy[sel_drv].track, + floppy[sel_drv].trackinfo[track].mfm_data, + &floppy[sel_drv].trackinfo[track].mfm_length); } } #endif @@ -1801,22 +1801,22 @@ uint16_t prev_byte_under_head = 0; void floppyEndOfLine() { int32_t sel_drv = floppySelectedGet(); - if (floppyDMAWriteStarted()) + if (floppyDMAWriteStarted()) { - floppyDMAWrite(); - floppy_has_sync = FALSE; + floppyDMAWrite(); + floppy_has_sync = FALSE; return; } - if (sel_drv == -1) + if (sel_drv == -1) { - floppy_has_sync = FALSE; + floppy_has_sync = FALSE; return; } - if (floppyIsSpinning(sel_drv)) + if (floppyIsSpinning(sel_drv)) { uint32_t track = floppyGetLinearTrack(sel_drv); uint32_t words = (floppy_fast) ? FLOPPY_FAST_WORDS : 2; - for (uint32_t i = 0; i < words; i++) + for (uint32_t i = 0; i < words; i++) { uint16_t tmpb1 = floppyGetByteUnderHead(sel_drv, track); uint16_t word_under_head = (prev_byte_under_head << 8) | tmpb1; @@ -1833,7 +1833,7 @@ void floppyEndOfLine() #ifdef FLOPPY_LOG else { - floppyLogMessageWithTicks("Sync was found on byte boundary", floppy[sel_drv].motor_ticks); + floppyLogMessageWithTicks("Sync was found on byte boundary", floppy[sel_drv].motor_ticks); } #endif @@ -1844,7 +1844,7 @@ void floppyEndOfLine() if (floppyDMAReadStarted()) { - floppyReadWord(word_under_head, found_sync); + floppyReadWord(word_under_head, found_sync); } } } diff --git a/fellow/SRC/WinFellow/C/GRAPH.C b/fellow/SRC/WinFellow/C/GRAPH.C index 04d7ea7c..d0555c2c 100644 --- a/fellow/SRC/WinFellow/C/GRAPH.C +++ b/fellow/SRC/WinFellow/C/GRAPH.C @@ -30,7 +30,6 @@ #include "blit.h" #include "graph.h" #include "bus.h" -#include "sound.h" #include "draw.h" #include "graph.h" #include "LineExactSprites.h" @@ -67,7 +66,6 @@ uint32_t graph_deco6[256][2]; uint8_t graph_line1_tmp[1024]; uint8_t graph_line2_tmp[1024]; - /*===========================================================================*/ /* Line description registers and data */ /*===========================================================================*/ @@ -77,19 +75,17 @@ uint32_t graph_DDF_word_count; uint32_t graph_DIW_first_visible; uint32_t graph_DIW_last_visible; - /*===========================================================================*/ /* Translation tables for colors */ /*===========================================================================*/ -uint32_t graph_color_shadow[64]; /* Colors corresponding to the different Amiga- */ +uint32_t graph_color_shadow[64]; /* Colors corresponding to the different Amiga- */ /* registers. Initialized from draw_color_table */ /* whenever WCOLORXX is written. */ -uint16_t graph_color[64]; /* Copy of Amiga version of colors */ +uint16_t graph_color[64]; /* Copy of Amiga version of colors */ BOOLE graph_playfield_on; - /*===========================================================================*/ /* IO-registers */ /*===========================================================================*/ @@ -97,7 +93,7 @@ BOOLE graph_playfield_on; uint32_t bpl1pt, bpl2pt, bpl3pt, bpl4pt, bpl5pt, bpl6pt; uint32_t lof, ddfstrt, ddfstop, bplcon1, bpl1mod, bpl2mod; uint32_t evenscroll, evenhiscroll, oddscroll, oddhiscroll; -uint32_t diwstrt, diwstop; +uint32_t diwstrt, diwstop; uint32_t diwxleft, diwxright, diwytop, diwybottom; uint32_t dmacon; @@ -115,13 +111,13 @@ graph_line graph_frame[3][628]; void graphLineDescClear() { - memset(graph_frame, 0, sizeof(graph_line)*3*628); + memset(graph_frame, 0, sizeof(graph_line) * 3 * 628); for (int frame = 0; frame < 3; frame++) { for (int line = 0; line < 628; line++) { graph_frame[frame][line].linetype = GRAPH_LINE_BG; - graph_frame[frame][line].draw_line_routine = (void *) draw_line_BG_routine; + graph_frame[frame][line].draw_line_routine = (void *)draw_line_BG_routine; graph_frame[frame][line].colors[0] = 0; graph_frame[frame][line].frames_left_until_BG_skip = drawGetBufferCount(); /* ie. one more than normal to draw once in each buffer */ graph_frame[frame][line].sprite_ham_slot = 0xffffffff; @@ -130,10 +126,10 @@ void graphLineDescClear() } } -graph_line* graphGetLineDesc(int buffer_no, int currentY) +graph_line *graphGetLineDesc(int buffer_no, int currentY) { - int line_index = currentY*2; - + int line_index = currentY * 2; + if (drawGetUseInterlacedRendering() && !drawGetFrameIsLong()) { line_index += 1; @@ -141,7 +137,6 @@ graph_line* graphGetLineDesc(int buffer_no, int currentY) return &graph_frame[buffer_no][line_index]; } - /*===========================================================================*/ /* The mapping from Amiga colors to host colors are dependent on the host */ /* resolution. We need to recalculate the colors to reflect the possibly new */ @@ -150,20 +145,22 @@ graph_line* graphGetLineDesc(int buffer_no, int currentY) /* don't know the color format yet in graphEmulationStart() */ /*===========================================================================*/ -void graphInitializeShadowColors() { +void graphInitializeShadowColors() +{ for (uint32_t i = 0; i < 64; i++) graph_color_shadow[i] = draw_color_table[graph_color[i] & 0xfff]; } - /*===========================================================================*/ /* Clear all register data */ /*===========================================================================*/ -static void graphIORegistersClear() { - for (uint32_t i = 0; i < 64; i++) graph_color_shadow[i] = graph_color[i] = 0; +static void graphIORegistersClear() +{ + for (uint32_t i = 0; i < 64; i++) + graph_color_shadow[i] = graph_color[i] = 0; graph_playfield_on = FALSE; - lof = 0x8000; /* Long frame */ + lof = 0x8000; /* Long frame */ bpl1mod = 0; bpl2mod = 0; bpl1pt = 0; @@ -182,8 +179,8 @@ static void graphIORegistersClear() { diwstrt = 0; diwstop = 0; diwxleft = 0; - diwxright = 0; - diwytop = 0; + diwxright = 0; + diwytop = 0; diwybottom = 0; graph_DIW_first_visible = 256; graph_DIW_last_visible = 256; @@ -207,7 +204,7 @@ uint16_t rdmaconr(uint32_t address) { if (blitterGetZeroFlag()) { - return (uint16_t) (_core.Registers.DmaConR | 0x00002000); + return (uint16_t)(_core.Registers.DmaConR | 0x00002000); } return (uint16_t)_core.Registers.DmaConR; } @@ -231,9 +228,9 @@ uint16_t rvposr(uint32_t address) if (chipsetGetECS()) { - return (uint16_t) ((lof | (y >> 8)) | 0x2000); + return (uint16_t)((lof | (y >> 8)) | 0x2000); } - return (uint16_t) (lof | (y >> 8)); + return (uint16_t)(lof | (y >> 8)); } /*===========================================================================*/ @@ -266,10 +263,9 @@ uint16_t rid(uint32_t address) void wvpos(uint16_t data, uint32_t address) { - lof = (uint32_t) (data & 0x8000); - - //fellowAddLog("LOF: %s, frame no %I64d, Y %d X %d\n", (lof & 0x8000) ? "long" : "short", busGetRasterFrameCount(), busGetRasterY(), busGetRasterX()); + lof = (uint32_t)(data & 0x8000); + // fellowAddLog("LOF: %s, frame no %I64d, Y %d X %d\n", (lof & 0x8000) ? "long" : "short", busGetRasterFrameCount(), busGetRasterY(), busGetRasterX()); } /*===========================================================================*/ @@ -312,7 +308,7 @@ void wdiwstrt(uint16_t data, uint32_t address) void wdiwstop(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) { GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); uint32_t diwstop_old = diwstop; @@ -327,7 +323,7 @@ void wdiwstop(uint16_t data, uint32_t address) diwstop = data; if ((((data >> 8) & 0xff) & 0x80) == 0x0) { - diwybottom = ((data >> 8) & 0xff) + 256; + diwybottom = ((data >> 8) & 0xff) + 256; } else { @@ -353,7 +349,7 @@ void wdiwstop(uint16_t data, uint32_t address) /* */ /* When this value is written, the scroll (BPLCON1) also need to be reevaluated */ /* for _reversal_ of the scroll values. */ -/* _wbplcon1_ calls _graphCalculateWindow_ so we don't need to here */ +/* _wbplcon1_ calls _graphCalculateWindow_ so we don't need to here */ /*==============================================================================*/ void wddfstrt(uint16_t data, uint32_t address) @@ -440,22 +436,22 @@ void wdmacon(uint16_t data, uint32_t address) // SET/CLR bit is 1 (bits set to 1 will set bits) uint32_t local_data = data & 0x7ff; // zero bits 15 to 11 (readonly bits and set/clr bit) // test if BLTPRI got turned on (blitter DMA priority) - if ((local_data & 0x0400) != 0x0) + if ((local_data & 0x0400) != 0x0) { // BLTPRI bit is on now, was it turned off before? if (!_core.RegisterUtility.IsBlitterPriorityEnabled()) { - // BLTPRI was turned off before and therefor - // BLTPRI got turned on, stop CPU until a blit is - // finished if this is a blit that uses all cycles - if (blitterEvent.cycle != BUS_CYCLE_DISABLE) - { - if (blitterGetFreeCycles() == 0) - { - // below delays CPU additionally cycles - cpuIntegrationSetChipCycles(cpuIntegrationGetChipCycles() + (blitterEvent.cycle - bus.cycle)); - } - } + // BLTPRI was turned off before and therefor + // BLTPRI got turned on, stop CPU until a blit is + // finished if this is a blit that uses all cycles + if (blitterEvent.cycle != BUS_CYCLE_DISABLE) + { + if (blitterGetFreeCycles() == 0) + { + // below delays CPU additionally cycles + cpuIntegrationSetChipCycles(cpuIntegrationGetChipCycles() + (blitterEvent.cycle - bus.cycle)); + } + } } } @@ -471,26 +467,26 @@ void wdmacon(uint16_t data, uint32_t address) } // enable audio channel X ? - for (unsigned int i = 0; i < 4; i++) + for (unsigned int i = 0; i < 4; i++) { if (((dmacon & (1 << i))) != 0x0) { - // audio channel 0 DMA enable bit is set now - if ((prev_dmacon & (1 << i)) == 0x0) - { - // audio channel 0 DMA enable bit was clear previously - soundChannelEnable(i); - } + // audio channel 0 DMA enable bit is set now + if ((prev_dmacon & (1 << i)) == 0x0) + { + // audio channel 0 DMA enable bit was clear previously + _core.Sound->ChannelEnable(i); + } } - } + } - // check if already a call to wbltsize was executed + // check if already a call to wbltsize was executed // before the blitter DMA channel was activated if (blitterGetDMAPending()) { if ((dmacon & 0x0040) != 0x0) { - blitterCopy(); + blitterCopy(); } } @@ -516,29 +512,29 @@ void wdmacon(uint16_t data, uint32_t address) { if (blitterIsStarted()) { - blitForceFinish(); + blitForceFinish(); } } // disable audio channel X ? - for (unsigned int i = 0; i < 4; i++) + for (unsigned int i = 0; i < 4; i++) { if ((dmacon & (1 << i)) == 0x0) { - if ((prev_dmacon & (1 << i)) != 0x0) - { - soundChannelKill(i); - } + if ((prev_dmacon & (1 << i)) != 0x0) + { + _core.Sound->ChannelKill(i); + } } } - // check if already a call to wbltsize was executed + // check if already a call to wbltsize was executed // before the blitter DMA channel was activated if (blitterGetDMAPending()) { if ((dmacon & 0x0040) != 0x0) { - blitterCopy(); + blitterCopy(); } } @@ -553,13 +549,11 @@ void wdmacon(uint16_t data, uint32_t address) void wbpl1pth(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl1pt = chipsetReplaceHighPtr(bpl1pt, data); -// fellowAddLog("BPL1PT: %X, frame no %I64d, Y %d X %d\n", bpl1pt, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX()); - + // fellowAddLog("BPL1PT: %X, frame no %I64d, Y %d X %d\n", bpl1pt, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX()); } /*===========================================================================*/ @@ -569,12 +563,11 @@ void wbpl1pth(uint16_t data, uint32_t address) void wbpl1ptl(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl1pt = chipsetReplaceLowPtr(bpl1pt, data); -// fellowAddLog("BPL1PT: %X, frame no %I64d, Y %d X %d\n", bpl1pt, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX()); + // fellowAddLog("BPL1PT: %X, frame no %I64d, Y %d X %d\n", bpl1pt, busGetRasterFrameCount(), busGetRasterY(), busGetRasterX()); } /*===========================================================================*/ @@ -584,8 +577,7 @@ void wbpl1ptl(uint16_t data, uint32_t address) void wbpl2pth(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl2pt = chipsetReplaceHighPtr(bpl2pt, data); } @@ -597,8 +589,7 @@ void wbpl2pth(uint16_t data, uint32_t address) void wbpl2ptl(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl2pt = chipsetReplaceLowPtr(bpl2pt, data); } @@ -610,8 +601,7 @@ void wbpl2ptl(uint16_t data, uint32_t address) void wbpl3pth(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl3pt = chipsetReplaceHighPtr(bpl3pt, data); } @@ -622,8 +612,7 @@ void wbpl3pth(uint16_t data, uint32_t address) void wbpl3ptl(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl3pt = chipsetReplaceLowPtr(bpl3pt, data); } @@ -635,8 +624,7 @@ void wbpl3ptl(uint16_t data, uint32_t address) void wbpl4pth(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl4pt = chipsetReplaceHighPtr(bpl4pt, data); } @@ -648,8 +636,7 @@ void wbpl4pth(uint16_t data, uint32_t address) void wbpl4ptl(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl4pt = chipsetReplaceLowPtr(bpl4pt, data); } @@ -661,8 +648,7 @@ void wbpl4ptl(uint16_t data, uint32_t address) void wbpl5pth(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl5pt = chipsetReplaceHighPtr(bpl5pt, data); } @@ -674,8 +660,7 @@ void wbpl5pth(uint16_t data, uint32_t address) void wbpl5ptl(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl5pt = chipsetReplaceLowPtr(bpl5pt, data); } @@ -687,8 +672,7 @@ void wbpl5ptl(uint16_t data, uint32_t address) void wbpl6pth(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl6pt = chipsetReplaceHighPtr(bpl6pt, data); } @@ -700,8 +684,7 @@ void wbpl6pth(uint16_t data, uint32_t address) void wbpl6ptl(uint16_t data, uint32_t address) { - if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) - GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); + if (drawGetGraphicsEmulationMode() == GRAPHICSEMULATIONMODE_CYCLEEXACT) GraphicsContext.Commit(busGetRasterY(), busGetRasterX()); bpl6pt = chipsetReplaceLowPtr(bpl6pt, data); } @@ -723,10 +706,10 @@ void wbplcon0(uint16_t data, uint32_t address) _core.Registers.BplCon0 = data; uint32_t local_data = (data >> 12) & 0x0f; - // check if DBLPF bit is set + // check if DBLPF bit is set if (_core.RegisterUtility.IsDualPlayfieldEnabled()) { - // double playfield, select a decoding function + // double playfield, select a decoding function // depending on hires and playfield priority graph_decode_line_ptr = graph_decode_line_dual_tab[local_data]; } @@ -735,7 +718,7 @@ void wbplcon0(uint16_t data, uint32_t address) graph_decode_line_ptr = graph_decode_line_tab[local_data]; } - // check if HOMOD bit is set + // check if HOMOD bit is set if (_core.RegisterUtility.IsHAMEnabled()) { // hold-and-modify mode @@ -749,11 +732,11 @@ void wbplcon0(uint16_t data, uint32_t address) // check if HIRES is set if (_core.RegisterUtility.IsHiresEnabled()) { - draw_line_BPL_res_routine = draw_line_dual_hires_routine; + draw_line_BPL_res_routine = draw_line_dual_hires_routine; } else { - draw_line_BPL_res_routine = draw_line_dual_lores_routine; + draw_line_BPL_res_routine = draw_line_dual_lores_routine; } } else @@ -761,11 +744,11 @@ void wbplcon0(uint16_t data, uint32_t address) // check if HIRES is set if (_core.RegisterUtility.IsHiresEnabled()) { - draw_line_BPL_res_routine = draw_line_hires_routine; + draw_line_BPL_res_routine = draw_line_hires_routine; } else { - draw_line_BPL_res_routine = draw_line_lores_routine; + draw_line_BPL_res_routine = draw_line_lores_routine; } } } @@ -904,10 +887,10 @@ void wcolor(uint16_t data, uint32_t address) } // normal mode - graph_color[color_index] = (uint16_t) (data & 0x0fff); + graph_color[color_index] = (uint16_t)(data & 0x0fff); graph_color_shadow[color_index] = draw_color_table[data & 0xfff]; // half bright mode - graph_color[color_index + 32] = (uint16_t) (((data & 0xfff) & 0xeee) >> 1); + graph_color[color_index + 32] = (uint16_t)(((data & 0xfff) & 0xeee) >> 1); graph_color_shadow[color_index + 32] = draw_color_table[(((data & 0xfff) & 0xeee) >> 1)]; } @@ -944,7 +927,8 @@ void graphIOHandlersInstall() memorySetIoWriteStub(0x104, wbplcon2); memorySetIoWriteStub(0x108, wbpl1mod); memorySetIoWriteStub(0x10a, wbpl2mod); - for (uint32_t i = 0x180; i < 0x1c0; i += 2) memorySetIoWriteStub(i, wcolor); + for (uint32_t i = 0x180; i < 0x1c0; i += 2) + memorySetIoWriteStub(i, wcolor); } /*===========================================================================*/ @@ -956,12 +940,12 @@ static __inline uint32_t graphDecodeOdd1(int bitplanes, uint32_t dat1, uint32_t { switch (bitplanes) { - case 1: - case 2: return graph_deco1[dat1][0]; - case 3: - case 4: return graph_deco1[dat1][0] | graph_deco3[dat3][0]; - case 5: - case 6: return graph_deco1[dat1][0] | graph_deco3[dat3][0] | graph_deco5[dat5][0]; + case 1: + case 2: return graph_deco1[dat1][0]; + case 3: + case 4: return graph_deco1[dat1][0] | graph_deco3[dat3][0]; + case 5: + case 6: return graph_deco1[dat1][0] | graph_deco3[dat3][0] | graph_deco5[dat5][0]; } return 0; } @@ -971,12 +955,12 @@ static __inline uint32_t graphDecodeOdd2(int bitplanes, uint32_t dat1, uint32_t { switch (bitplanes) { - case 1: - case 2: return graph_deco1[dat1][1]; - case 3: - case 4: return graph_deco1[dat1][1] | graph_deco3[dat3][1]; - case 5: - case 6: return graph_deco1[dat1][1] | graph_deco3[dat3][1] | graph_deco5[dat5][1]; + case 1: + case 2: return graph_deco1[dat1][1]; + case 3: + case 4: return graph_deco1[dat1][1] | graph_deco3[dat3][1]; + case 5: + case 6: return graph_deco1[dat1][1] | graph_deco3[dat3][1] | graph_deco5[dat5][1]; } return 0; } @@ -986,12 +970,12 @@ static __inline uint32_t graphDecodeEven1(int bitplanes, uint32_t dat2, uint32_t { switch (bitplanes) { - case 1: - case 2: - case 3: return graph_deco2[dat2][0]; - case 4: - case 5: return graph_deco2[dat2][0] | graph_deco4[dat4][0]; - case 6: return graph_deco2[dat2][0] | graph_deco4[dat4][0] | graph_deco6[dat6][0]; + case 1: + case 2: + case 3: return graph_deco2[dat2][0]; + case 4: + case 5: return graph_deco2[dat2][0] | graph_deco4[dat4][0]; + case 6: return graph_deco2[dat2][0] | graph_deco4[dat4][0] | graph_deco6[dat6][0]; } return 0; } @@ -1001,12 +985,12 @@ static __inline uint32_t graphDecodeEven2(int bitplanes, uint32_t dat2, uint32_t { switch (bitplanes) { - case 1: - case 2: - case 3: return graph_deco2[dat2][1]; - case 4: - case 5: return graph_deco2[dat2][1] | graph_deco4[dat4][1]; - case 6: return graph_deco2[dat2][1] | graph_deco4[dat4][1] | graph_deco6[dat6][1]; + case 1: + case 2: + case 3: return graph_deco2[dat2][1]; + case 4: + case 5: return graph_deco2[dat2][1] | graph_deco4[dat4][1]; + case 6: return graph_deco2[dat2][1] | graph_deco4[dat4][1] | graph_deco6[dat6][1]; } return 0; } @@ -1016,12 +1000,12 @@ static __inline uint32_t graphDecodeDualOdd1(int bitplanes, uint32_t datA, uint3 { switch (bitplanes) { - case 1: - case 2: return graph_deco1[datA][0]; - case 3: - case 4: return graph_deco1[datA][0] | graph_deco2[datB][0]; - case 5: - case 6: return graph_deco1[datA][0] | graph_deco2[datB][0] | graph_deco3[datC][0]; + case 1: + case 2: return graph_deco1[datA][0]; + case 3: + case 4: return graph_deco1[datA][0] | graph_deco2[datB][0]; + case 5: + case 6: return graph_deco1[datA][0] | graph_deco2[datB][0] | graph_deco3[datC][0]; } return 0; } @@ -1031,12 +1015,12 @@ static __inline uint32_t graphDecodeDualOdd2(int bitplanes, uint32_t datA, uint3 { switch (bitplanes) { - case 1: - case 2: return graph_deco1[datA][1]; - case 3: - case 4: return graph_deco1[datA][1] | graph_deco2[datB][1]; - case 5: - case 6: return graph_deco1[datA][1] | graph_deco2[datB][1] | graph_deco3[datC][1]; + case 1: + case 2: return graph_deco1[datA][1]; + case 3: + case 4: return graph_deco1[datA][1] | graph_deco2[datB][1]; + case 5: + case 6: return graph_deco1[datA][1] | graph_deco2[datB][1] | graph_deco3[datC][1]; } return 0; } @@ -1046,12 +1030,12 @@ static __inline uint32_t graphDecodeDualEven1(int bitplanes, uint32_t datA, uint { switch (bitplanes) { - case 1: - case 2: - case 3: return graph_deco1[datA][0]; - case 4: - case 5: return graph_deco1[datA][0] | graph_deco2[datB][0]; - case 6: return graph_deco1[datA][0] | graph_deco2[datB][0] | graph_deco3[datC][0]; + case 1: + case 2: + case 3: return graph_deco1[datA][0]; + case 4: + case 5: return graph_deco1[datA][0] | graph_deco2[datB][0]; + case 6: return graph_deco1[datA][0] | graph_deco2[datB][0] | graph_deco3[datC][0]; } return 0; } @@ -1061,12 +1045,12 @@ static __inline uint32_t graphDecodeDualEven2(int bitplanes, uint32_t datA, uint { switch (bitplanes) { - case 1: - case 2: - case 3: return graph_deco1[datA][1]; - case 4: - case 5: return graph_deco1[datA][1] | graph_deco2[datB][1]; - case 6: return graph_deco1[datA][1] | graph_deco2[datB][1] | graph_deco3[datC][1]; + case 1: + case 2: + case 3: return graph_deco1[datA][1]; + case 4: + case 5: return graph_deco1[datA][1] | graph_deco2[datB][1]; + case 6: return graph_deco1[datA][1] | graph_deco2[datB][1] | graph_deco3[datC][1]; } return 0; } @@ -1076,12 +1060,12 @@ static __inline void graphDecodeModulo(int bitplanes, uint32_t bpl_length_in_byt { switch (bitplanes) { - case 6: bpl6pt = chipsetMaskPtr(bpl6pt + bpl_length_in_bytes + bpl2mod); - case 5: bpl5pt = chipsetMaskPtr(bpl5pt + bpl_length_in_bytes + bpl1mod); - case 4: bpl4pt = chipsetMaskPtr(bpl4pt + bpl_length_in_bytes + bpl2mod); - case 3: bpl3pt = chipsetMaskPtr(bpl3pt + bpl_length_in_bytes + bpl1mod); - case 2: bpl2pt = chipsetMaskPtr(bpl2pt + bpl_length_in_bytes + bpl2mod); - case 1: bpl1pt = chipsetMaskPtr(bpl1pt + bpl_length_in_bytes + bpl1mod); + case 6: bpl6pt = chipsetMaskPtr(bpl6pt + bpl_length_in_bytes + bpl2mod); + case 5: bpl5pt = chipsetMaskPtr(bpl5pt + bpl_length_in_bytes + bpl1mod); + case 4: bpl4pt = chipsetMaskPtr(bpl4pt + bpl_length_in_bytes + bpl2mod); + case 3: bpl3pt = chipsetMaskPtr(bpl3pt + bpl_length_in_bytes + bpl1mod); + case 2: bpl2pt = chipsetMaskPtr(bpl2pt + bpl_length_in_bytes + bpl2mod); + case 1: bpl1pt = chipsetMaskPtr(bpl1pt + bpl_length_in_bytes + bpl1mod); } } @@ -1098,14 +1082,14 @@ static __inline void graphDecodeGeneric(int bitplanes) uint32_t bpl_length_in_bytes = graph_DDF_word_count * 2; if (bitplanes == 0) return; - if (bpl_length_in_bytes != 0) + if (bpl_length_in_bytes != 0) { uint32_t *dest_odd; uint32_t *dest_even; uint32_t *dest_tmp; uint32_t *end_even; uint8_t *pt1_tmp, *pt2_tmp, *pt3_tmp, *pt4_tmp, *pt5_tmp, *pt6_tmp; - uint32_t dat2, dat3, dat4, dat5, dat6; + uint32_t dat2, dat3, dat4, dat5, dat6; int maxscroll; uint32_t temp = 0; uint8_t *line1; @@ -1118,19 +1102,19 @@ static __inline void graphDecodeGeneric(int bitplanes) if (_core.RegisterUtility.IsHiresEnabled()) // check if hires bit is set (bit 15 of register BPLCON0) { // high resolution - dest_odd = (uint32_t*) (line1 + graph_DDF_start + oddhiscroll); + dest_odd = (uint32_t *)(line1 + graph_DDF_start + oddhiscroll); // Find out how many pixels the bitplane is scrolled // the first pixels must then be zeroed to avoid garbage. - maxscroll = (evenhiscroll > oddhiscroll) ? evenhiscroll : oddhiscroll; - } - else + maxscroll = (evenhiscroll > oddhiscroll) ? evenhiscroll : oddhiscroll; + } + else { - dest_odd = (uint32_t*) (line1 + graph_DDF_start + oddscroll); + dest_odd = (uint32_t *)(line1 + graph_DDF_start + oddscroll); // Find out how many pixels the bitplane is scrolled // the first pixels must then be zeroed to avoid garbage. - maxscroll = (evenscroll > oddscroll) ? evenscroll : oddscroll; + maxscroll = (evenscroll > oddscroll) ? evenscroll : oddscroll; } // clear edges @@ -1143,62 +1127,62 @@ static __inline void graphDecodeGeneric(int bitplanes) } // setup loop - uint32_t* end_odd = dest_odd + bpl_length_in_bytes * 2; + uint32_t *end_odd = dest_odd + bpl_length_in_bytes * 2; if (bitplanes > 1) { if (_core.RegisterUtility.IsHiresEnabled()) // check if hires bit is set (bit 15 of register BPLCON0) { - // high resolution - dest_even = (uint32_t*) (line1 + graph_DDF_start + evenhiscroll); + // high resolution + dest_even = (uint32_t *)(line1 + graph_DDF_start + evenhiscroll); } else { - // low resolution - dest_even = (uint32_t*) (line1 + graph_DDF_start + evenscroll); + // low resolution + dest_even = (uint32_t *)(line1 + graph_DDF_start + evenscroll); } - end_even = dest_even + bpl_length_in_bytes * 2; + end_even = dest_even + bpl_length_in_bytes * 2; } switch (bitplanes) { - case 6: pt6_tmp = memory_chip + bpl6pt; - case 5: pt5_tmp = memory_chip + bpl5pt; - case 4: pt4_tmp = memory_chip + bpl4pt; - case 3: pt3_tmp = memory_chip + bpl3pt; - case 2: pt2_tmp = memory_chip + bpl2pt; - case 1: pt1_tmp = memory_chip + bpl1pt; + case 6: pt6_tmp = memory_chip + bpl6pt; + case 5: pt5_tmp = memory_chip + bpl5pt; + case 4: pt4_tmp = memory_chip + bpl4pt; + case 3: pt3_tmp = memory_chip + bpl3pt; + case 2: pt2_tmp = memory_chip + bpl2pt; + case 1: pt1_tmp = memory_chip + bpl1pt; } - for (dest_tmp = dest_odd; dest_tmp != end_odd; dest_tmp += 2) + for (dest_tmp = dest_odd; dest_tmp != end_odd; dest_tmp += 2) { switch (bitplanes) { - case 6: - case 5: dat5 = *pt5_tmp++; - case 4: - case 3: dat3 = *pt3_tmp++; - case 2: - case 1: dat1 = *pt1_tmp++; + case 6: + case 5: dat5 = *pt5_tmp++; + case 4: + case 3: dat3 = *pt3_tmp++; + case 2: + case 1: dat1 = *pt1_tmp++; } dest_tmp[0] = graphDecodeOdd1(bitplanes, dat1, dat3, dat5); dest_tmp[1] = graphDecodeOdd2(bitplanes, dat1, dat3, dat5); } - if (bitplanes >= 2) + if (bitplanes >= 2) { for (dest_tmp = dest_even; dest_tmp != end_even; dest_tmp += 2) { - switch (bitplanes) - { - case 6: dat6 = *pt6_tmp++; - case 5: - case 4: dat4 = *pt4_tmp++; - case 3: - case 2: dat2 = *pt2_tmp++; - } - dest_tmp[0] |= graphDecodeEven1(bitplanes, dat2, dat4, dat6); - dest_tmp[1] |= graphDecodeEven2(bitplanes, dat2, dat4, dat6); + switch (bitplanes) + { + case 6: dat6 = *pt6_tmp++; + case 5: + case 4: dat4 = *pt4_tmp++; + case 3: + case 2: dat2 = *pt2_tmp++; + } + dest_tmp[0] |= graphDecodeEven1(bitplanes, dat2, dat4, dat6); + dest_tmp[1] |= graphDecodeEven2(bitplanes, dat2, dat4, dat6); } } } @@ -1209,7 +1193,7 @@ static __inline void graphDecodeDualGeneric(int bitplanes) { uint32_t bpl_length_in_bytes = graph_DDF_word_count * 2; if (bitplanes == 0) return; - if (bpl_length_in_bytes != 0) + if (bpl_length_in_bytes != 0) { uint32_t *dest_even; uint32_t *dest_tmp; @@ -1225,7 +1209,7 @@ static __inline void graphDecodeDualGeneric(int bitplanes) graphSetLinePointers(&line1, &line2); // clear edges - int maxscroll = (evenscroll > oddscroll) ? evenscroll : oddscroll; + int maxscroll = (evenscroll > oddscroll) ? evenscroll : oddscroll; uint32_t temp = 0; while (maxscroll > 0) @@ -1239,55 +1223,55 @@ static __inline void graphDecodeDualGeneric(int bitplanes) } // setup loop - uint32_t* dest_odd = (uint32_t*)(line1 + graph_DDF_start + oddscroll); - uint32_t* end_odd = dest_odd + bpl_length_in_bytes * 2; + uint32_t *dest_odd = (uint32_t *)(line1 + graph_DDF_start + oddscroll); + uint32_t *end_odd = dest_odd + bpl_length_in_bytes * 2; if (bitplanes > 1) { // low resolution - dest_even = (uint32_t*) (line2 + graph_DDF_start + evenscroll); - end_even = dest_even + bpl_length_in_bytes * 2; + dest_even = (uint32_t *)(line2 + graph_DDF_start + evenscroll); + end_even = dest_even + bpl_length_in_bytes * 2; } switch (bitplanes) { - case 6: pt6_tmp = memory_chip + bpl6pt; - case 5: pt5_tmp = memory_chip + bpl5pt; - case 4: pt4_tmp = memory_chip + bpl4pt; - case 3: pt3_tmp = memory_chip + bpl3pt; - case 2: pt2_tmp = memory_chip + bpl2pt; - case 1: pt1_tmp = memory_chip + bpl1pt; + case 6: pt6_tmp = memory_chip + bpl6pt; + case 5: pt5_tmp = memory_chip + bpl5pt; + case 4: pt4_tmp = memory_chip + bpl4pt; + case 3: pt3_tmp = memory_chip + bpl3pt; + case 2: pt2_tmp = memory_chip + bpl2pt; + case 1: pt1_tmp = memory_chip + bpl1pt; } - for (dest_tmp = dest_odd; dest_tmp != end_odd; dest_tmp += 2) + for (dest_tmp = dest_odd; dest_tmp != end_odd; dest_tmp += 2) { switch (bitplanes) { - case 6: - case 5: dat5 = *pt5_tmp++; - case 4: - case 3: dat3 = *pt3_tmp++; - case 2: - case 1: dat1 = *pt1_tmp++; + case 6: + case 5: dat5 = *pt5_tmp++; + case 4: + case 3: dat3 = *pt3_tmp++; + case 2: + case 1: dat1 = *pt1_tmp++; } dest_tmp[0] = graphDecodeDualOdd1(bitplanes, dat1, dat3, dat5); dest_tmp[1] = graphDecodeDualOdd2(bitplanes, dat1, dat3, dat5); } - if (bitplanes >= 2) + if (bitplanes >= 2) { for (dest_tmp = dest_even; dest_tmp != end_even; dest_tmp += 2) { - switch (bitplanes) - { - case 6: dat6 = *pt6_tmp++; - case 5: - case 4: dat4 = *pt4_tmp++; - case 3: - case 2: dat2 = *pt2_tmp++; - } - dest_tmp[0] = graphDecodeDualEven1(bitplanes, dat2, dat4, dat6); - dest_tmp[1] = graphDecodeDualEven2(bitplanes, dat2, dat4, dat6); + switch (bitplanes) + { + case 6: dat6 = *pt6_tmp++; + case 5: + case 4: dat4 = *pt4_tmp++; + case 3: + case 2: dat2 = *pt2_tmp++; + } + dest_tmp[0] = graphDecodeDualEven1(bitplanes, dat2, dat4, dat6); + dest_tmp[1] = graphDecodeDualEven2(bitplanes, dat2, dat4, dat6); } } } @@ -1409,16 +1393,16 @@ void graphDecode6Dual() /* Though it somehow works, so just leave it and hope it does not break*/ /*===========================================================================*/ -void graphCalculateWindow() +void graphCalculateWindow() { if (_core.RegisterUtility.IsHiresEnabled()) // check if Hires bit is set (bit 15 of BPLCON0) { graphCalculateWindowHires(); - } - else + } + else { // set DDF (Display Data Fetch Start) variables - if (ddfstop < ddfstrt) + if (ddfstop < ddfstrt) { graph_DDF_start = graph_DDF_word_count = 0; graph_DIW_first_visible = graph_DIW_last_visible = 256; @@ -1428,7 +1412,7 @@ void graphCalculateWindow() uint32_t ddfstop_aligned = ddfstop & 0x07; uint32_t ddfstrt_aligned = ddfstrt & 0x07; - if (ddfstop >= ddfstrt) + if (ddfstop >= ddfstrt) { graph_DDF_word_count = ((ddfstop - ddfstrt) >> 3) + 1; } @@ -1438,16 +1422,16 @@ void graphCalculateWindow() ddfstop_aligned = 0; } - if (ddfstop_aligned != ddfstrt_aligned) + if (ddfstop_aligned != ddfstrt_aligned) { graph_DDF_word_count++; - } + } - graph_DDF_start = ((ddfstrt << 1) + 0x11); // 0x11 = 17 pixels = 8.5 bus cycles + graph_DDF_start = ((ddfstrt << 1) + 0x11); // 0x11 = 17 pixels = 8.5 bus cycles // set DIW (Display Window Start) variables (only used with drawing routines) - if (diwxleft >= diwxright) + if (diwxleft >= diwxright) { graph_DDF_start = graph_DDF_word_count = 0; graph_DIW_first_visible = graph_DIW_last_visible = 256; @@ -1455,26 +1439,26 @@ void graphCalculateWindow() graph_DIW_first_visible = drawGetInternalClip().left; if (diwxleft < graph_DDF_start) - { + { if (graph_DDF_start > graph_DIW_first_visible) - { - graph_DIW_first_visible = graph_DDF_start; - } - } - else + { + graph_DIW_first_visible = graph_DDF_start; + } + } + else { if (diwxleft > graph_DIW_first_visible) - { - graph_DIW_first_visible = diwxleft; - } + { + graph_DIW_first_visible = diwxleft; + } } uint32_t last_position_in_line = (graph_DDF_word_count << 4) + graph_DDF_start; if (oddscroll > evenscroll) { last_position_in_line += oddscroll; - } - else + } + else { last_position_in_line += evenscroll; } @@ -1484,14 +1468,14 @@ void graphCalculateWindow() { if (last_position_in_line < graph_DIW_last_visible) { - graph_DIW_last_visible = last_position_in_line; + graph_DIW_last_visible = last_position_in_line; } - } - else + } + else { if (diwxright < graph_DIW_last_visible) { - graph_DIW_last_visible = diwxright; + graph_DIW_last_visible = diwxright; } } } @@ -1519,18 +1503,18 @@ void graphCalculateWindowHires() // DDF variables done, now check DIW variables - if ((diwxleft << 1) >= (diwxright << 1)) + if ((diwxleft << 1) >= (diwxright << 1)) { graph_DDF_start = graph_DDF_word_count = 0; graph_DIW_first_visible = graph_DIW_last_visible = 256; } uint32_t clip_left = drawGetInternalClip().left << 1; - if ((diwxleft << 1) < graph_DDF_start) + if ((diwxleft << 1) < graph_DDF_start) { if (graph_DDF_start > clip_left) { graph_DIW_first_visible = graph_DDF_start; - } + } else { graph_DIW_first_visible = clip_left; @@ -1552,14 +1536,14 @@ void graphCalculateWindowHires() if (oddhiscroll > evenhiscroll) { last_position_in_line += oddhiscroll; - } - else + } + else { last_position_in_line += evenhiscroll; } uint32_t clip_right = drawGetInternalClip().right << 1; - if (last_position_in_line < (diwxright << 1)) + if (last_position_in_line < (diwxright << 1)) { if (last_position_in_line < clip_right) { @@ -1586,7 +1570,7 @@ void graphCalculateWindowHires() void graphPlayfieldOnOff() { uint32_t currentY = busGetRasterY(); - if (graph_playfield_on != 0) + if (graph_playfield_on != 0) { // Playfield on, check if top has moved below graph_raster_y // Playfield on, check if playfield is turned off at this line @@ -1594,8 +1578,8 @@ void graphPlayfieldOnOff() { graph_playfield_on = 0; } - } - else + } + else { // Playfield off, Check if playfield is turned on at this line if (currentY == diwytop) @@ -1603,7 +1587,7 @@ void graphPlayfieldOnOff() // Don't turn on when top > bottom if (diwytop < diwybottom) { - graph_playfield_on = 1; + graph_playfield_on = 1; } } } @@ -1612,22 +1596,15 @@ void graphPlayfieldOnOff() void graphDecodeNOP() { - switch (_core.RegisterUtility.GetEnabledBitplaneCount()) { - case 0: - break; - case 6: - bpl6pt = chipsetMaskPtr(bpl6pt + (graph_DDF_word_count*2) + bpl2mod); - case 5: - bpl5pt = chipsetMaskPtr(bpl5pt + (graph_DDF_word_count*2) + bpl1mod); - case 4: - bpl4pt = chipsetMaskPtr(bpl4pt + (graph_DDF_word_count*2) + bpl2mod); - case 3: - bpl3pt = chipsetMaskPtr(bpl3pt + (graph_DDF_word_count*2) + bpl1mod); - case 2: - bpl2pt = chipsetMaskPtr(bpl2pt + (graph_DDF_word_count*2) + bpl2mod); - case 1: - bpl1pt = chipsetMaskPtr(bpl1pt + (graph_DDF_word_count*2) + bpl1mod); - break; + switch (_core.RegisterUtility.GetEnabledBitplaneCount()) + { + case 0: break; + case 6: bpl6pt = chipsetMaskPtr(bpl6pt + (graph_DDF_word_count * 2) + bpl2mod); + case 5: bpl5pt = chipsetMaskPtr(bpl5pt + (graph_DDF_word_count * 2) + bpl1mod); + case 4: bpl4pt = chipsetMaskPtr(bpl4pt + (graph_DDF_word_count * 2) + bpl2mod); + case 3: bpl3pt = chipsetMaskPtr(bpl3pt + (graph_DDF_word_count * 2) + bpl1mod); + case 2: bpl2pt = chipsetMaskPtr(bpl2pt + (graph_DDF_word_count * 2) + bpl2mod); + case 1: bpl1pt = chipsetMaskPtr(bpl1pt + (graph_DDF_word_count * 2) + bpl1mod); break; } } @@ -1636,8 +1613,7 @@ void graphDecodeNOP() /* [4 + esp] - linedesc struct /*-------------------------------------------------------------------------------*/ - -void graphLinedescColors(graph_line* current_graph_line) +void graphLinedescColors(graph_line *current_graph_line) { uint32_t color; @@ -1649,13 +1625,12 @@ void graphLinedescColors(graph_line* current_graph_line) } } - /*------------------------------------------------------------------------------- /* Sets line routines for this line /* [4 + esp] - linedesc struct /*-------------------------------------------------------------------------------*/ -void graphLinedescRoutines(graph_line* current_graph_line) +void graphLinedescRoutines(graph_line *current_graph_line) { /*============================================================== /* Set drawing routines @@ -1669,7 +1644,7 @@ void graphLinedescRoutines(graph_line* current_graph_line) /* [4 + esp] - linedesc struct /*-------------------------------------------------------------------------------*/ -void graphLinedescGeometry(graph_line* current_graph_line) +void graphLinedescGeometry(graph_line *current_graph_line) { uint32_t local_graph_DIW_first_visible = graph_DIW_first_visible; int32_t local_graph_DIW_last_visible = (int32_t)graph_DIW_last_visible; @@ -1694,7 +1669,7 @@ void graphLinedescGeometry(graph_line* current_graph_line) { local_graph_DIW_first_visible = local_draw_left; } - if (local_graph_DIW_last_visible >(int32_t) local_draw_right) + if (local_graph_DIW_last_visible > (int32_t)local_draw_right) { local_graph_DIW_last_visible = (int32_t)local_draw_right; } @@ -1719,7 +1694,7 @@ void graphLinedescGeometry(graph_line* current_graph_line) local_graph_DIW_first_visible -= local_draw_left; local_draw_right -= local_graph_DIW_last_visible; current_graph_line->BG_pad_front = local_graph_DIW_first_visible; - current_graph_line->BG_pad_back = local_draw_right; + current_graph_line->BG_pad_back = local_draw_right; /*==========================================================*/ /* Need to remember playfield priorities to sort dual pf */ @@ -1732,7 +1707,7 @@ void graphLinedescGeometry(graph_line* current_graph_line) /* Smart sets line routines for this line /* Return TRUE if routines have changed /*-------------------------------------------------------------------------------*/ -BOOLE graphLinedescRoutinesSmart(graph_line* current_graph_line) +BOOLE graphLinedescRoutinesSmart(graph_line *current_graph_line) { /*==============================================================*/ /* Set drawing routines */ @@ -1757,7 +1732,7 @@ BOOLE graphLinedescRoutinesSmart(graph_line* current_graph_line) /* Sets line geometry data in line description /* Return TRUE if geometry has changed /*-------------------------------------------------------------------------------*/ -BOOLE graphLinedescGeometrySmart(graph_line* current_graph_line) +BOOLE graphLinedescGeometrySmart(graph_line *current_graph_line) { uint32_t local_graph_DIW_first_visible = graph_DIW_first_visible; int32_t local_graph_DIW_last_visible = (int32_t)graph_DIW_last_visible; @@ -1783,9 +1758,9 @@ BOOLE graphLinedescGeometrySmart(graph_line* current_graph_line) { local_graph_DIW_first_visible = local_draw_left; } - if (local_graph_DIW_last_visible > (int32_t) local_draw_right) + if (local_graph_DIW_last_visible > (int32_t)local_draw_right) { - local_graph_DIW_last_visible = (int32_t) local_draw_right; + local_graph_DIW_last_visible = (int32_t)local_draw_right; } local_graph_DIW_last_visible -= local_graph_DIW_first_visible; if (local_graph_DIW_last_visible < 0) @@ -1848,7 +1823,7 @@ BOOLE graphLinedescGeometrySmart(graph_line* current_graph_line) /* Return TRUE if colors have changed /*-------------------------------------------------------------------------------*/ -BOOLE graphLinedescColorsSmart(graph_line* current_graph_line) +BOOLE graphLinedescColorsSmart(graph_line *current_graph_line) { BOOLE result = FALSE; @@ -1870,7 +1845,7 @@ BOOLE graphLinedescColorsSmart(graph_line* current_graph_line) /* Return TRUE = not equal /*-------------------------------------------------------------------------------*/ -static BOOLE graphCompareCopyRest(uint32_t first_pixel, int32_t pixel_count, uint8_t* dest_line, uint8_t* source_line) +static BOOLE graphCompareCopyRest(uint32_t first_pixel, int32_t pixel_count, uint8_t *dest_line, uint8_t *source_line) { // line has changed, copy the rest while ((first_pixel & 0x3) != 0) @@ -1886,7 +1861,7 @@ static BOOLE graphCompareCopyRest(uint32_t first_pixel, int32_t pixel_count, uin while (pixel_count >= 4) { - *((uint32_t *) (dest_line + first_pixel)) = *((uint32_t *) (source_line + first_pixel)); + *((uint32_t *)(dest_line + first_pixel)) = *((uint32_t *)(source_line + first_pixel)); first_pixel += 4; pixel_count -= 4; } @@ -1905,7 +1880,7 @@ static BOOLE graphCompareCopyRest(uint32_t first_pixel, int32_t pixel_count, uin /* Return TRUE = not equal FALSE = equal /*-------------------------------------------------------------------------------*/ -static BOOLE graphCompareCopy(uint32_t first_pixel, int32_t pixel_count, uint8_t* dest_line, uint8_t* source_line) +static BOOLE graphCompareCopy(uint32_t first_pixel, int32_t pixel_count, uint8_t *dest_line, uint8_t *source_line) { BOOLE result = FALSE; @@ -1916,32 +1891,32 @@ static BOOLE graphCompareCopy(uint32_t first_pixel, int32_t pixel_count, uint8_t { if (dest_line[first_pixel] == source_line[first_pixel]) { - first_pixel++; - pixel_count--; - if (pixel_count == 0) - { - return FALSE; - } + first_pixel++; + pixel_count--; + if (pixel_count == 0) + { + return FALSE; + } } else { - // line has changed, copy the rest - return graphCompareCopyRest(first_pixel, pixel_count, dest_line, source_line); + // line has changed, copy the rest + return graphCompareCopyRest(first_pixel, pixel_count, dest_line, source_line); } } // compare dword aligned values while (pixel_count >= 4) { - if (*((uint32_t *) (source_line + first_pixel)) == *((uint32_t *) (dest_line + first_pixel))) + if (*((uint32_t *)(source_line + first_pixel)) == *((uint32_t *)(dest_line + first_pixel))) { - first_pixel += 4; - pixel_count -= 4; + first_pixel += 4; + pixel_count -= 4; } else { - // line has changed, copy the rest - return graphCompareCopyRest(first_pixel, pixel_count, dest_line, source_line); + // line has changed, copy the rest + return graphCompareCopyRest(first_pixel, pixel_count, dest_line, source_line); } } @@ -1950,23 +1925,22 @@ static BOOLE graphCompareCopy(uint32_t first_pixel, int32_t pixel_count, uint8_t { if (source_line[first_pixel] == dest_line[first_pixel]) { - first_pixel++; - pixel_count--; + first_pixel++; + pixel_count--; } else { - result = TRUE; - dest_line[first_pixel] = source_line[first_pixel]; - first_pixel++; - pixel_count--; + result = TRUE; + dest_line[first_pixel] = source_line[first_pixel]; + first_pixel++; + pixel_count--; } } } return result; } - -BOOLE graphLinedescSetBackgroundLine(graph_line* current_graph_line) +BOOLE graphLinedescSetBackgroundLine(graph_line *current_graph_line) { if (graph_color_shadow[0] == current_graph_line->colors[0]) { @@ -1987,14 +1961,14 @@ BOOLE graphLinedescSetBackgroundLine(graph_line* current_graph_line) if (current_graph_line->frames_left_until_BG_skip == 0) { // No changes since drawing it last time, change state to skip - current_graph_line->linetype = GRAPH_LINE_SKIP; - return FALSE; + current_graph_line->linetype = GRAPH_LINE_SKIP; + return FALSE; } else { // Still need to draw the line in some buffers - current_graph_line->frames_left_until_BG_skip--; - return TRUE; + current_graph_line->frames_left_until_BG_skip--; + return TRUE; } } } @@ -2009,7 +1983,7 @@ BOOLE graphLinedescSetBackgroundLine(graph_line* current_graph_line) return TRUE; } -BOOLE graphLinedescSetBitplaneLine(graph_line* current_graph_line) +BOOLE graphLinedescSetBitplaneLine(graph_line *current_graph_line) { /*===========================================*/ /* This is a bitplane line */ @@ -2029,14 +2003,14 @@ BOOLE graphLinedescSetBitplaneLine(graph_line* current_graph_line) line_desc_changed |= graphLinedescGeometrySmart(current_graph_line); line_desc_changed |= graphLinedescRoutinesSmart(current_graph_line); return line_desc_changed; - } +} /*------------------------------------------------------------------------------- /* Smart makes a description of this line /* Return TRUE if linedesc has changed /*-------------------------------------------------------------------------------*/ -BOOLE graphLinedescMakeSmart(graph_line* current_graph_line) +BOOLE graphLinedescMakeSmart(graph_line *current_graph_line) { /*==========================================================*/ /* Is this a bitplane or background line? */ @@ -2053,7 +2027,7 @@ BOOLE graphLinedescMakeSmart(graph_line* current_graph_line) /* Smart compose the visible layout of the line */ /*===========================================================================*/ -void graphComposeLineOutputSmart(graph_line* current_graph_line) +void graphComposeLineOutputSmart(graph_line *current_graph_line) { // remember the basic properties of the line BOOLE line_desc_changed = graphLinedescMakeSmart(current_graph_line); @@ -2066,13 +2040,13 @@ void graphComposeLineOutputSmart(graph_line* current_graph_line) // then copy it and compare graph_decode_line_ptr(); - // compare line data to old data - line_desc_changed |= graphCompareCopy(current_graph_line->DIW_first_draw, (int32_t) (current_graph_line->DIW_pixel_count), current_graph_line->line1, graph_line1_tmp); + // compare line data to old data + line_desc_changed |= graphCompareCopy(current_graph_line->DIW_first_draw, (int32_t)(current_graph_line->DIW_pixel_count), current_graph_line->line1, graph_line1_tmp); // if the line is dual playfield, compare second playfield too if (_core.RegisterUtility.IsDualPlayfieldEnabled()) { - line_desc_changed |= graphCompareCopy(current_graph_line->DIW_first_draw, (int32_t) (current_graph_line->DIW_pixel_count), current_graph_line->line2, graph_line2_tmp); + line_desc_changed |= graphCompareCopy(current_graph_line->DIW_first_draw, (int32_t)(current_graph_line->DIW_pixel_count), current_graph_line->line2, graph_line2_tmp); } if (current_graph_line->has_ham_sprites_online) @@ -2118,17 +2092,17 @@ void graphP2CTablesInit() d[0] = d[1] = 0; for (uint32_t j = 0; j < 4; j++) { - d[0] |= ((i & (0x80>>j))>>(4 + 3 - j))<<(j*8); - d[1] |= ((i & (0x8>>j))>>(3 - j))<<(j*8); + d[0] |= ((i & (0x80 >> j)) >> (4 + 3 - j)) << (j * 8); + d[1] |= ((i & (0x8 >> j)) >> (3 - j)) << (j * 8); } for (uint32_t j = 0; j < 2; j++) { - graph_deco1[i][j] = d[j]<<2; - graph_deco2[i][j] = d[j]<<3; - graph_deco3[i][j] = d[j]<<4; - graph_deco4[i][j] = d[j]<<5; - graph_deco5[i][j] = d[j]<<6; - graph_deco6[i][j] = d[j]<<7; + graph_deco1[i][j] = d[j] << 2; + graph_deco2[i][j] = d[j] << 3; + graph_deco3[i][j] = d[j] << 4; + graph_deco4[i][j] = d[j] << 5; + graph_deco5[i][j] = d[j] << 6; + graph_deco6[i][j] = d[j] << 7; } } } @@ -2188,7 +2162,7 @@ void graphEndOfLine() } // skip this frame? - if (draw_frame_skip == 0) + if (draw_frame_skip == 0) { uint32_t currentY = busGetRasterY(); // update diw state @@ -2198,16 +2172,16 @@ void graphEndOfLine() if (currentY >= 0x12) { // make pointer to linedesc for this line - graph_line* current_graph_line = graphGetLineDesc(draw_buffer_draw, currentY); + graph_line *current_graph_line = graphGetLineDesc(draw_buffer_draw, currentY); // decode sprites if DMA is enabled and raster is after line $18 if ((dmacon & 0x20) == 0x20) { - if (currentY >= 0x18) - { - line_exact_sprites->DMASpriteHandler(); + if (currentY >= 0x18) + { + line_exact_sprites->DMASpriteHandler(); line_exact_sprites->ProcessActionList(); - } + } } // sprites decoded, sprites_onlineflag is set if there are any @@ -2217,25 +2191,25 @@ void graphEndOfLine() // check if we are clipped if ((currentY >= drawGetInternalClip().top) || (currentY < drawGetInternalClip().bottom)) { - // visible line, either background or bitplanes + // visible line, either background or bitplanes graphComposeLineOutputSmart(current_graph_line); } else { - // do nop decoding, no screen output needed - if (draw_line_BG_routine != draw_line_routine) - { - graphDecodeNOP(); - } + // do nop decoding, no screen output needed + if (draw_line_BG_routine != draw_line_routine) + { + graphDecodeNOP(); + } } // if diw state changing from background to bitplane output, // set new drawing routine pointer - if (draw_switch_bg_to_bpl != 0) + if (draw_switch_bg_to_bpl != 0) { - draw_line_BPL_manage_routine = draw_line_routine; - draw_switch_bg_to_bpl = 0; + draw_line_BPL_manage_routine = draw_line_routine; + draw_switch_bg_to_bpl = 0; } if (currentY == (busGetLinesInThisFrame() - 1)) @@ -2244,7 +2218,7 @@ void graphEndOfLine() // this routine pads the remaining lines with background color for (uint32_t y = currentY + 1; y < drawGetInternalClip().bottom; ++y) { - graph_line* graph_line_y = graphGetLineDesc(draw_buffer_draw, y); + graph_line *graph_line_y = graphGetLineDesc(draw_buffer_draw, y); graphLinedescSetBackgroundLine(graph_line_y); } } @@ -2270,7 +2244,8 @@ void graphEndOfFrame() /* Called on emulation hard reset */ /*===========================================================================*/ -void graphHardReset() { +void graphHardReset() +{ graphIORegistersClear(); graphLineDescClear(); } @@ -2279,7 +2254,8 @@ void graphHardReset() { /* Called on emulation start */ /*===========================================================================*/ -void graphEmulationStart() { +void graphEmulationStart() +{ graph_buffer_lost = FALSE; graphLineDescClear(); graphIOHandlersInstall(); @@ -2289,14 +2265,16 @@ void graphEmulationStart() { /* Called on emulation stop */ /*===========================================================================*/ -void graphEmulationStop() { +void graphEmulationStop() +{ } /*===========================================================================*/ /* Initializes the graphics module */ /*===========================================================================*/ -void graphStartup() { +void graphStartup() +{ graphP2CTablesInit(); graphP2CFunctionsInit(); graphLineDescClear(); @@ -2307,5 +2285,6 @@ void graphStartup() { /* Release resources taken by the graphics module */ /*===========================================================================*/ -void graphShutdown() { +void graphShutdown() +{ } diff --git a/fellow/SRC/WinFellow/C/LineExactCopper.cpp b/fellow/SRC/WinFellow/C/LineExactCopper.cpp index 899f395f..63bd6d9b 100644 --- a/fellow/SRC/WinFellow/C/LineExactCopper.cpp +++ b/fellow/SRC/WinFellow/C/LineExactCopper.cpp @@ -5,7 +5,7 @@ #include "chipset.h" #include "FMEM.H" #include "BLIT.H" -#include "CoreHost.h" +#include "VirtualHost/Core.h" uint32_t LineExactCopper::cycletable[16] = { 4, 4, 4, 4, 4, 5, 6, 4, 4, 4, 4, 8, 16, 4, 4, 4 }; diff --git a/fellow/SRC/WinFellow/C/LineExactSprites.cpp b/fellow/SRC/WinFellow/C/LineExactSprites.cpp index 7972c29f..6fec1a51 100644 --- a/fellow/SRC/WinFellow/C/LineExactSprites.cpp +++ b/fellow/SRC/WinFellow/C/LineExactSprites.cpp @@ -7,7 +7,7 @@ #include "FMEM.H" #include "DRAW.H" #include "chipset.h" -#include "CoreHost.h" +#include "VirtualHost/Core.h" spr_register_func LineExactSprites::sprxptl_functions[8] = { @@ -136,7 +136,7 @@ void LineExactSprites::asprxdata(uint16_t data, uint32_t address) { uint32_t sprnr = (address >> 3) & 7; - *((uint16_t *)&sprdat[sprnr]) = (uint16_t)data; + *((uint16_t*)&sprdat[sprnr]) = (uint16_t)data; spr_arm_data[sprnr] = TRUE; } @@ -144,7 +144,7 @@ void LineExactSprites::asprxdata(uint16_t data, uint32_t address) void LineExactSprites::asprxdatb(uint16_t data, uint32_t address) { uint32_t sprnr = (address >> 3) & 7; - *(((uint16_t *)&sprdat[sprnr]) + 1) = data; + *(((uint16_t*)&sprdat[sprnr]) + 1) = data; } #ifdef _DEBUG @@ -255,9 +255,9 @@ void LineExactSprites::MergeListClear(spr_merge_list_master* l) /* Save sprite data for later processing on HAM bitmaps */ /*===========================================================================*/ -void LineExactSprites::MergeHAM(graph_line *linedescription) +void LineExactSprites::MergeHAM(graph_line* linedescription) { - sprite_ham_slot *ham_slot = &sprite_ham_slots[sprite_ham_slot_next]; + sprite_ham_slot* ham_slot = &sprite_ham_slots[sprite_ham_slot_next]; for (uint32_t i = 0; i < 8; i++) { uint32_t merge_list_count = spr_merge_list[i].count; @@ -279,22 +279,22 @@ void LineExactSprites::MergeHAM(graph_line *linedescription) /* 16-bit pixels, 2x horisontal scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM2x1x16(uint32_t *frameptr, graph_line *linedescription) +void LineExactSprites::MergeHAM2x1x16(uint32_t* frameptr, graph_line* linedescription) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -309,9 +309,9 @@ void LineExactSprites::MergeHAM2x1x16(uint32_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint32_t *frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); + uint32_t* frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -335,22 +335,22 @@ void LineExactSprites::MergeHAM2x1x16(uint32_t *frameptr, graph_line *linedescri /* 16-bit pixels, 2x horisontal scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM2x2x16(uint32_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset) +void LineExactSprites::MergeHAM2x2x16(uint32_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -365,9 +365,9 @@ void LineExactSprites::MergeHAM2x2x16(uint32_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint32_t *frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); + uint32_t* frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -392,22 +392,22 @@ void LineExactSprites::MergeHAM2x2x16(uint32_t *frameptr, graph_line *linedescri /* 16-bit pixels, 4x2 scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM4x2x16(uint64_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset) +void LineExactSprites::MergeHAM4x2x16(uint64_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -422,9 +422,9 @@ void LineExactSprites::MergeHAM4x2x16(uint64_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint64_t *frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); + uint64_t* frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -449,22 +449,22 @@ void LineExactSprites::MergeHAM4x2x16(uint64_t *frameptr, graph_line *linedescri /* 16-bit pixels, 4x4 scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM4x4x16(uint64_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset, uint32_t nextlineoffset2, uint32_t nextlineoffset3) +void LineExactSprites::MergeHAM4x4x16(uint64_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset, uint32_t nextlineoffset2, uint32_t nextlineoffset3) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -479,9 +479,9 @@ void LineExactSprites::MergeHAM4x4x16(uint64_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint64_t *frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); + uint64_t* frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -514,22 +514,22 @@ union sprham24helper /* 24-bit pixels, 2x horisontal scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM2x1x24(uint8_t *frameptr, graph_line *linedescription) +void LineExactSprites::MergeHAM2x1x24(uint8_t* frameptr, graph_line* linedescription) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -544,9 +544,9 @@ void LineExactSprites::MergeHAM2x1x24(uint8_t *frameptr, graph_line *linedescrip { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint8_t *frame_ptr = frameptr + 6 * (first_visible_cylinder - DIW_first_visible); + uint8_t* frame_ptr = frameptr + 6 * (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -575,22 +575,22 @@ void LineExactSprites::MergeHAM2x1x24(uint8_t *frameptr, graph_line *linedescrip /* 24-bit pixels, 2x horisontal scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM2x2x24(uint8_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset) +void LineExactSprites::MergeHAM2x2x24(uint8_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -605,9 +605,9 @@ void LineExactSprites::MergeHAM2x2x24(uint8_t *frameptr, graph_line *linedescrip { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint8_t *frame_ptr = frameptr + 6 * (first_visible_cylinder - DIW_first_visible); + uint8_t* frame_ptr = frameptr + 6 * (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -644,22 +644,22 @@ void LineExactSprites::MergeHAM2x2x24(uint8_t *frameptr, graph_line *linedescrip /* 24-bit pixels, 4x2 scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM4x2x24(uint8_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset) +void LineExactSprites::MergeHAM4x2x24(uint8_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -674,9 +674,9 @@ void LineExactSprites::MergeHAM4x2x24(uint8_t *frameptr, graph_line *linedescrip { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint8_t *frame_ptr = frameptr + 12 * (first_visible_cylinder - DIW_first_visible); + uint8_t* frame_ptr = frameptr + 12 * (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -725,22 +725,22 @@ void LineExactSprites::MergeHAM4x2x24(uint8_t *frameptr, graph_line *linedescrip /* 24-bit pixels, 4x4 scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM4x4x24(uint8_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset, uint32_t nextlineoffset2, uint32_t nextlineoffset3) +void LineExactSprites::MergeHAM4x4x24(uint8_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset, uint32_t nextlineoffset2, uint32_t nextlineoffset3) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -755,9 +755,9 @@ void LineExactSprites::MergeHAM4x4x24(uint8_t *frameptr, graph_line *linedescrip { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint8_t *frame_ptr = frameptr + 12 * (first_visible_cylinder - DIW_first_visible); + uint8_t* frame_ptr = frameptr + 12 * (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -832,22 +832,22 @@ void LineExactSprites::MergeHAM4x4x24(uint8_t *frameptr, graph_line *linedescrip /* 32-bit pixels, 2x horisontal scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM2x1x32(uint64_t *frameptr, graph_line *linedescription) +void LineExactSprites::MergeHAM2x1x32(uint64_t* frameptr, graph_line* linedescription) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -862,9 +862,9 @@ void LineExactSprites::MergeHAM2x1x32(uint64_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint64_t *frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); + uint64_t* frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -888,22 +888,22 @@ void LineExactSprites::MergeHAM2x1x32(uint64_t *frameptr, graph_line *linedescri /* 32-bit pixels, 2x horisontal scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM2x2x32(uint64_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset) +void LineExactSprites::MergeHAM2x2x32(uint64_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -918,9 +918,9 @@ void LineExactSprites::MergeHAM2x2x32(uint64_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint64_t *frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); + uint64_t* frame_ptr = frameptr + (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -945,22 +945,22 @@ void LineExactSprites::MergeHAM2x2x32(uint64_t *frameptr, graph_line *linedescri /* 32-bit pixels, 4x2 scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM4x2x32(uint64_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset) +void LineExactSprites::MergeHAM4x2x32(uint64_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -975,9 +975,9 @@ void LineExactSprites::MergeHAM4x2x32(uint64_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint64_t *frame_ptr = frameptr + 2 * (first_visible_cylinder - DIW_first_visible); + uint64_t* frame_ptr = frameptr + 2 * (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -1004,22 +1004,22 @@ void LineExactSprites::MergeHAM4x2x32(uint64_t *frameptr, graph_line *linedescri /* 32-bit pixels, 4x4 scale */ /*===========================================================================*/ -void LineExactSprites::MergeHAM4x4x32(uint64_t *frameptr, graph_line *linedescription, uint32_t nextlineoffset, uint32_t nextlineoffset2, uint32_t nextlineoffset3) +void LineExactSprites::MergeHAM4x4x32(uint64_t* frameptr, graph_line* linedescription, uint32_t nextlineoffset, uint32_t nextlineoffset2, uint32_t nextlineoffset3) { if (linedescription->sprite_ham_slot != 0xffffffff) { - sprite_ham_slot &ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; + sprite_ham_slot& ham_slot = sprite_ham_slots[linedescription->sprite_ham_slot]; uint32_t DIW_first_visible = linedescription->DIW_first_draw; uint32_t DIW_last_visible = DIW_first_visible + linedescription->DIW_pixel_count; linedescription->sprite_ham_slot = 0xffffffff; for (uint32_t i = 0; i < 8; i++) { - spr_merge_list_master &master = ham_slot.merge_list_master[i]; + spr_merge_list_master& master = ham_slot.merge_list_master[i]; for (uint32_t j = 0; j < ham_slot.merge_list_master[i].count; j++) { - spr_merge_list_item &item = master.items[j]; + spr_merge_list_item& item = master.items[j]; if ((item.sprx < DIW_last_visible) && ((item.sprx + 16) > DIW_first_visible)) { @@ -1034,9 +1034,9 @@ void LineExactSprites::MergeHAM4x4x32(uint64_t *frameptr, graph_line *linedescri { last_visible_cylinder = DIW_last_visible; } - uint8_t *spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); + uint8_t* spr_ptr = &(item.sprite_data[first_visible_cylinder - item.sprx]); /* frameptr points to the first visible HAM pixel in the framebuffer */ - uint64_t *frame_ptr = frameptr + 2 * (first_visible_cylinder - DIW_first_visible); + uint64_t* frame_ptr = frameptr + 2 * (first_visible_cylinder - DIW_first_visible); int32_t pixel_count = last_visible_cylinder - first_visible_cylinder; while (--pixel_count >= 0) @@ -1066,7 +1066,7 @@ void LineExactSprites::MergeHAM4x4x32(uint64_t *frameptr, graph_line *linedescri /* Sprite control registers */ /*===========================================================================*/ -void LineExactSprites::BuildItem(spr_action_list_item ** item) +void LineExactSprites::BuildItem(spr_action_list_item** item) { uint32_t currentX = busGetRasterX(); if (currentX >= 18) @@ -1107,7 +1107,7 @@ bool LineExactSprites::HasSpritesOnLine() /* Makes a log of the writes to the sprpt registers */ void LineExactSprites::NotifySprpthChanged(uint16_t data, unsigned int sprite_number) { - spr_action_list_item *item = ActionListAddLast(&spr_dma_action_list[sprite_number]); + spr_action_list_item* item = ActionListAddLast(&spr_dma_action_list[sprite_number]); BuildItem(&item); item->called_function = sprxpth_functions[sprite_number]; item->data = data; @@ -1115,7 +1115,7 @@ void LineExactSprites::NotifySprpthChanged(uint16_t data, unsigned int sprite_nu if (output_sprite_log == TRUE) { - *((uint16_t *)((uint8_t *)sprpt_debug + sprite_number * 4 + 2)) = (uint16_t)data & 0x01f; + *((uint16_t*)((uint8_t*)sprpt_debug + sprite_number * 4 + 2)) = (uint16_t)data & 0x01f; sprintf(buffer, "(y, x) = (%u, %u): call to spr%upth (sprx = %d, spry = %d, sprly = %d)\n", busGetRasterY(), @@ -1131,7 +1131,7 @@ void LineExactSprites::NotifySprpthChanged(uint16_t data, unsigned int sprite_nu /* Makes a log of the writes to the sprpt registers */ void LineExactSprites::NotifySprptlChanged(uint16_t data, unsigned int sprite_number) { - spr_action_list_item *item = ActionListAddLast(&spr_dma_action_list[sprite_number]); + spr_action_list_item* item = ActionListAddLast(&spr_dma_action_list[sprite_number]); BuildItem(&item); item->called_function = sprxptl_functions[sprite_number]; item->data = data; @@ -1139,7 +1139,7 @@ void LineExactSprites::NotifySprptlChanged(uint16_t data, unsigned int sprite_nu if (output_sprite_log == TRUE) { - *((uint16_t *)((uint8_t *)sprpt_debug + sprite_number * 4 + 2)) = (uint16_t)data & 0x01f; + *((uint16_t*)((uint8_t*)sprpt_debug + sprite_number * 4 + 2)) = (uint16_t)data & 0x01f; sprintf(buffer, "(y, x) = (%u, %u): call to spr%upth (sprx = %d, spry = %d, sprly = %d)\n", busGetRasterY(), @@ -1156,7 +1156,7 @@ void LineExactSprites::NotifySprptlChanged(uint16_t data, unsigned int sprite_nu void LineExactSprites::NotifySprposChanged(uint16_t data, unsigned int sprite_number) { - spr_action_list_item * item = ActionListAddLast(&spr_action_list[sprite_number]); + spr_action_list_item* item = ActionListAddLast(&spr_action_list[sprite_number]); BuildItem(&item); item->called_function = &LineExactSprites::asprxpos; item->data = data; @@ -1176,7 +1176,7 @@ void LineExactSprites::NotifySprposChanged(uint16_t data, unsigned int sprite_nu void LineExactSprites::NotifySprctlChanged(uint16_t data, unsigned int sprite_number) { - spr_action_list_item * item = ActionListAddLast(&spr_action_list[sprite_number]); + spr_action_list_item* item = ActionListAddLast(&spr_action_list[sprite_number]); BuildItem(&item); item->called_function = &LineExactSprites::asprxctl; item->data = data; @@ -1197,7 +1197,7 @@ void LineExactSprites::NotifySprctlChanged(uint16_t data, unsigned int sprite_nu void LineExactSprites::NotifySprdataChanged(uint16_t data, unsigned int sprite_number) { - spr_action_list_item *item = ActionListAddLast(&spr_action_list[sprite_number]); + spr_action_list_item* item = ActionListAddLast(&spr_action_list[sprite_number]); BuildItem(&item); item->called_function = &LineExactSprites::asprxdata; item->data = data; @@ -1213,7 +1213,7 @@ void LineExactSprites::NotifySprdataChanged(uint16_t data, unsigned int sprite_n void LineExactSprites::NotifySprdatbChanged(uint16_t data, unsigned int sprite_number) { - spr_action_list_item *item = ActionListAddLast(&spr_action_list[sprite_number]); + spr_action_list_item* item = ActionListAddLast(&spr_action_list[sprite_number]); BuildItem(&item); item->called_function = &LineExactSprites::asprxdatb; item->data = data; @@ -1312,18 +1312,18 @@ void LineExactSprites::LogActiveSprites() void LineExactSprites::Decode4Sprite(uint32_t sprite_number) { - spr_merge_list_item *item = MergeListAddLast(&spr_merge_list[sprite_number]); + spr_merge_list_item* item = MergeListAddLast(&spr_merge_list[sprite_number]); item->sprx = sprx[sprite_number]; - uint32_t *chunky_destination = (uint32_t *)(item->sprite_data); + uint32_t* chunky_destination = (uint32_t*)(item->sprite_data); SpriteP2CDecoder::Decode4(sprite_number, chunky_destination, sprdat[sprite_number][0], sprdat[sprite_number][1]); } void LineExactSprites::Decode16Sprite(uint32_t sprite_number) { - spr_merge_list_item *item = MergeListAddLast(&spr_merge_list[sprite_number]); + spr_merge_list_item* item = MergeListAddLast(&spr_merge_list[sprite_number]); item->sprx = sprx[sprite_number]; - uint32_t *chunky_destination = (uint32_t *)(item->sprite_data); + uint32_t* chunky_destination = (uint32_t*)(item->sprite_data); SpriteP2CDecoder::Decode16(chunky_destination, sprdat[sprite_number & 0xfe][0], sprdat[sprite_number & 0xfe][1], sprdat[sprite_number][0], sprdat[sprite_number][1]); } @@ -1335,7 +1335,7 @@ void LineExactSprites::ProcessDMAActionListNOP() uint32_t count = ActionListCount(&spr_dma_action_list[sprnr]); for (uint32_t i = 0; i < count; i++) { - spr_action_list_item * action_item = ActionListGet(&spr_dma_action_list[sprnr], i); + spr_action_list_item* action_item = ActionListGet(&spr_dma_action_list[sprnr], i); // we can execute the coming action item (this->*(action_item->called_function))(action_item->data, action_item->address); } @@ -1345,8 +1345,8 @@ void LineExactSprites::ProcessDMAActionListNOP() void LineExactSprites::DMASpriteHandler() { - spr_action_list_item * dma_action_item; - spr_action_list_item * item; + spr_action_list_item* dma_action_item; + spr_action_list_item* item; uint32_t local_sprx; uint32_t local_spry; uint32_t local_sprly; @@ -1668,7 +1668,7 @@ void LineExactSprites::ProcessActionList() // for debugging only if (output_action_sprite_log == TRUE) { - sprintf((char *)&buffer, "sprite %u data displayed on (y, x) = (%u, %u)\n", + sprintf((char*)&buffer, "sprite %u data displayed on (y, x) = (%u, %u)\n", sprnr, busGetRasterY(), sprx[sprnr]); fellowAddLog2(buffer); } @@ -1721,7 +1721,7 @@ void LineExactSprites::ProcessActionList() // for debugging only if (output_action_sprite_log == TRUE) { - sprintf((char *)&buffer, "sprite %u data displayed on (y, x) = (%u, %u)\n", + sprintf((char*)&buffer, "sprite %u data displayed on (y, x) = (%u, %u)\n", sprnr, busGetRasterY(), sprx[sprnr]); fellowAddLog2(buffer); } @@ -1779,42 +1779,42 @@ void LineExactSprites::MergeDualLoresPF2loopinfront2(graph_line* current_graph_l uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); uint8_t* line2 = current_graph_line->line2 + next_item->sprx + 1; uint8_t* sprite_data = next_item->sprite_data; for (uint32_t i = 0; i < 4; i++) { - *((uint32_t *)line2_buildup) = *((uint32_t *)line2); - if ((uint8_t)(*((uint32_t *)sprite_data)) != 0) + *((uint32_t*)line2_buildup) = *((uint32_t*)line2); + if ((uint8_t)(*((uint32_t*)sprite_data)) != 0) { //cl = dl; - line2_buildup[0] = (uint8_t)*((uint32_t *)sprite_data); + line2_buildup[0] = (uint8_t) * ((uint32_t*)sprite_data); } // mdlpf21: - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 8) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 8) != 0) { //ch = dh; - line2_buildup[1] = (uint8_t)((*((uint32_t *)sprite_data) >> 8)); + line2_buildup[1] = (uint8_t)((*((uint32_t*)sprite_data) >> 8)); } // mdlph22: - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 16) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 16) != 0) { //cl = dl; - line2_buildup[2] = (uint8_t)((*((uint32_t *)sprite_data) >> 16)); + line2_buildup[2] = (uint8_t)((*((uint32_t*)sprite_data) >> 16)); } // mdlpf23: - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 24) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 24) != 0) { //ch = dh; - line2_buildup[3] = (uint8_t)((*((uint32_t *)sprite_data) >> 24)); + line2_buildup[3] = (uint8_t)((*((uint32_t*)sprite_data) >> 24)); } // mdlpf24: - *((uint32_t *)line2) = *((uint32_t *)line2_buildup); + *((uint32_t*)line2) = *((uint32_t*)line2_buildup); sprite_data += 4; line2 += 4; } @@ -1829,42 +1829,42 @@ void LineExactSprites::MergeDualLoresPF1loopinfront2(graph_line* current_graph_l uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); uint8_t* line1 = current_graph_line->line1 + next_item->sprx + 1; uint8_t* sprite_data = next_item->sprite_data; for (uint32_t i = 0; i < 4; i++) { - *((uint32_t *)line_buildup) = *((uint32_t *)line1); - if ((uint8_t)(*((uint32_t *)sprite_data)) != 0) + *((uint32_t*)line_buildup) = *((uint32_t*)line1); + if ((uint8_t)(*((uint32_t*)sprite_data)) != 0) { //cl = dl; - line_buildup[0] = (uint8_t)*((uint32_t *)sprite_data); + line_buildup[0] = (uint8_t) * ((uint32_t*)sprite_data); } // mdlpf21: - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 8) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 8) != 0) { //ch = dh; - line_buildup[1] = (uint8_t)((*((uint32_t *)sprite_data) >> 8)); + line_buildup[1] = (uint8_t)((*((uint32_t*)sprite_data) >> 8)); } // mdlph22: - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 16) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 16) != 0) { //cl = dl; - line_buildup[2] = (uint8_t)((*((uint32_t *)sprite_data) >> 16)); + line_buildup[2] = (uint8_t)((*((uint32_t*)sprite_data) >> 16)); } // mdlpf23: - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 24) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 24) != 0) { //ch = dh; - line_buildup[3] = (uint8_t)((*((uint32_t *)sprite_data) >> 24)); + line_buildup[3] = (uint8_t)((*((uint32_t*)sprite_data) >> 24)); } // mdlpf24: - *((uint32_t *)line1) = *((uint32_t *)line_buildup); + *((uint32_t*)line1) = *((uint32_t*)line_buildup); sprite_data += 4; line1 += 4; } @@ -1879,53 +1879,53 @@ void LineExactSprites::MergeDualLoresPF1loopbehind2(graph_line* current_graph_li uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); uint8_t* line1 = current_graph_line->line1 + next_item->sprx + 1; uint8_t* sprite_data = next_item->sprite_data; for (uint32_t i = 0; i < 4; i++) { - *((uint32_t *)line_buildup) = *((uint32_t *)line1); - if ((uint8_t)(*((uint32_t *)line1)) == 0) + *((uint32_t*)line_buildup) = *((uint32_t*)line1); + if ((uint8_t)(*((uint32_t*)line1)) == 0) { - if ((uint8_t)(*((uint32_t *)sprite_data)) != 0) + if ((uint8_t)(*((uint32_t*)sprite_data)) != 0) { - line_buildup[0] = (uint8_t)*((uint32_t *)sprite_data); + line_buildup[0] = (uint8_t) * ((uint32_t*)sprite_data); } } // mdlb1: - if ((uint8_t)((*((uint32_t *)line1)) >> 8) == 0) + if ((uint8_t)((*((uint32_t*)line1)) >> 8) == 0) { - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 8) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 8) != 0) { //ch = dh; - line_buildup[1] = (uint8_t)((*((uint32_t *)sprite_data) >> 8)); + line_buildup[1] = (uint8_t)((*((uint32_t*)sprite_data) >> 8)); } } // mdlb2: - if ((uint8_t)((*((uint32_t *)line1)) >> 16) == 0) + if ((uint8_t)((*((uint32_t*)line1)) >> 16) == 0) { - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 16) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 16) != 0) { //cl = dl; - line_buildup[2] = (uint8_t)((*((uint32_t *)sprite_data) >> 16)); + line_buildup[2] = (uint8_t)((*((uint32_t*)sprite_data) >> 16)); } } // mdlb3: - if ((uint8_t)((*((uint32_t *)line1)) >> 24) == 0) + if ((uint8_t)((*((uint32_t*)line1)) >> 24) == 0) { - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 24) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 24) != 0) { //ch = dh; - line_buildup[3] = (uint8_t)((*((uint32_t *)sprite_data) >> 24)); + line_buildup[3] = (uint8_t)((*((uint32_t*)sprite_data) >> 24)); } } // mdlb4: - *((uint32_t *)line1) = *((uint32_t *)line_buildup); + *((uint32_t*)line1) = *((uint32_t*)line_buildup); sprite_data += 4; line1 += 4; } @@ -1940,53 +1940,53 @@ void LineExactSprites::MergeDualLoresPF2loopbehind2(graph_line* current_graph_li uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); uint8_t* line2 = current_graph_line->line2 + next_item->sprx + 1; uint8_t* sprite_data = next_item->sprite_data; for (uint32_t i = 0; i < 4; i++) { - *((uint32_t *)line_buildup) = *((uint32_t *)line2); - if ((uint8_t)(*((uint32_t *)line2)) == 0) + *((uint32_t*)line_buildup) = *((uint32_t*)line2); + if ((uint8_t)(*((uint32_t*)line2)) == 0) { - if ((uint8_t)(*((uint32_t *)sprite_data)) != 0) + if ((uint8_t)(*((uint32_t*)sprite_data)) != 0) { - line_buildup[0] = (uint8_t)*((uint32_t *)sprite_data); + line_buildup[0] = (uint8_t) * ((uint32_t*)sprite_data); } } // mdlpfb1: - if ((uint8_t)((*((uint32_t *)line2)) >> 8) == 0) + if ((uint8_t)((*((uint32_t*)line2)) >> 8) == 0) { - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 8) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 8) != 0) { //ch = dh; - line_buildup[1] = (uint8_t)((*((uint32_t *)sprite_data) >> 8)); + line_buildup[1] = (uint8_t)((*((uint32_t*)sprite_data) >> 8)); } } // mdlpfb2: - if ((uint8_t)((*((uint32_t *)line2)) >> 16) == 0) + if ((uint8_t)((*((uint32_t*)line2)) >> 16) == 0) { - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 16) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 16) != 0) { //cl = dl; - line_buildup[2] = (uint8_t)((*((uint32_t *)sprite_data) >> 16)); + line_buildup[2] = (uint8_t)((*((uint32_t*)sprite_data) >> 16)); } } // mdlpfb3: - if ((uint8_t)((*((uint32_t *)line2)) >> 24) == 0) + if ((uint8_t)((*((uint32_t*)line2)) >> 24) == 0) { - if ((uint8_t)((*((uint32_t *)sprite_data)) >> 24) != 0) + if ((uint8_t)((*((uint32_t*)sprite_data)) >> 24) != 0) { //ch = dh; - line_buildup[3] = (uint8_t)((*((uint32_t *)sprite_data) >> 24)); + line_buildup[3] = (uint8_t)((*((uint32_t*)sprite_data) >> 24)); } } // mdlpfb4: - *((uint32_t *)line2) = *((uint32_t *)line_buildup); + *((uint32_t*)line2) = *((uint32_t*)line_buildup); sprite_data += 4; line2 += 4; } @@ -2055,9 +2055,9 @@ void LineExactSprites::MergeDualHiresPF2loopinfront2(graph_line* current_graph_l uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); - uint8_t *line2 = current_graph_line->line2 + 2 * (next_item->sprx + 1); - uint8_t *sprite_data = next_item->sprite_data; + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); + uint8_t* line2 = current_graph_line->line2 + 2 * (next_item->sprx + 1); + uint8_t* sprite_data = next_item->sprite_data; for (uint32_t i = 0; i < 4; i++) { @@ -2101,7 +2101,7 @@ void LineExactSprites::MergeDualHiresPF1loopinfront2(graph_line* current_graph_l uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); uint8_t* line1 = current_graph_line->line1 + 2 * (next_item->sprx + 1); uint8_t* sprite_data = next_item->sprite_data; @@ -2147,7 +2147,7 @@ void LineExactSprites::MergeDualHiresPF1loopbehind2(graph_line* current_graph_li uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); uint8_t* line1 = current_graph_line->line1 + 2 * (next_item->sprx + 1); uint8_t* sprite_data = next_item->sprite_data; @@ -2216,9 +2216,9 @@ void LineExactSprites::MergeDualHiresPF2loopbehind2(graph_line* current_graph_li uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); - uint8_t *line2 = current_graph_line->line2 + 2 * (next_item->sprx + 1); - uint8_t *sprite_data = next_item->sprite_data; + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); + uint8_t* line2 = current_graph_line->line2 + 2 * (next_item->sprx + 1); + uint8_t* sprite_data = next_item->sprite_data; for (uint32_t i = 0; i < 4; i++) { @@ -2344,14 +2344,14 @@ void LineExactSprites::MergeHires(graph_line* current_graph_line) uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); // there is sprite data waiting within this line if (next_item->sprx <= graph_DIW_last_visible) { // set destination and source - uint8_t *line1 = (current_graph_line->line1 + 2 * (next_item->sprx + 1)); - uint8_t *sprite_data = next_item->sprite_data; + uint8_t* line1 = (current_graph_line->line1 + 2 * (next_item->sprx + 1)); + uint8_t* sprite_data = next_item->sprite_data; SpriteMerger::MergeHires(sprnr, line1, sprite_data, 16); } @@ -2369,13 +2369,13 @@ void LineExactSprites::MergeLores(graph_line* current_graph_line) uint32_t count = MergeListCount(&spr_merge_list[sprnr]); for (uint32_t j = 0; j < count; j++) { - spr_merge_list_item *next_item = MergeListGet(&spr_merge_list[sprnr], j); + spr_merge_list_item* next_item = MergeListGet(&spr_merge_list[sprnr], j); // there is sprite data waiting within this line if (next_item->sprx <= graph_DIW_last_visible) { // set destination and source - uint8_t *line1 = (current_graph_line->line1 + (next_item->sprx) + 1); - uint8_t *sprite_data = next_item->sprite_data; + uint8_t* line1 = (current_graph_line->line1 + (next_item->sprx) + 1); + uint8_t* sprite_data = next_item->sprite_data; SpriteMerger::MergeLores(sprnr, line1, sprite_data, 16); } diff --git a/fellow/SRC/WinFellow/C/SOUND.C b/fellow/SRC/WinFellow/C/SOUND.C deleted file mode 100644 index 3979bcf9..00000000 --- a/fellow/SRC/WinFellow/C/SOUND.C +++ /dev/null @@ -1,929 +0,0 @@ -/*=========================================================================*/ -/* Fellow */ -/* */ -/* Sound emulation */ -/* */ -/* Author: Petter Schau */ -/* */ -/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2, or (at your option) */ -/* any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software Foundation, */ -/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*=========================================================================*/ - -#include "defs.h" -#include "chipset.h" -#include "fmem.h" -#include "sound.h" -#include "wav.h" -#include "cia.h" -#include "graph.h" -#include "sounddrv.h" -#include "interrupt.h" - - -#define MAX_BUFFER_SAMPLES 65536 - - -/*===========================================================================*/ -/* Sound emulation configuration */ -/*===========================================================================*/ - -sound_rates sound_rate; /* Current output rate */ -bool sound_stereo; /* Current mono/stereo setting */ -bool sound_16bits; /* Current 8/16 bit setting */ -sound_emulations sound_emulation; -sound_filters sound_filter; -sound_notifications sound_notification; -BOOLE sound_wav_capture; -BOOLE sound_device_found; -uint32_t sound_volume; - - -/*===========================================================================*/ -/* Buffer data */ -/*===========================================================================*/ - -uint32_t sound_current_buffer; -int16_t sound_left[2][MAX_BUFFER_SAMPLES], -sound_right[2][MAX_BUFFER_SAMPLES]; /* Samplebuffer, 16-b.signed */ -uint32_t sound_buffer_length; /* Current buffer length in ms */ -uint32_t sound_buffer_sample_count; /* Current number of samples in the buffer */ -uint32_t sound_buffer_sample_count_max; /* Maximum capacity of the buffer */ - - -/*===========================================================================*/ -/* Information about the sound device */ -/*===========================================================================*/ - -sound_device sound_dev; - - -/*===========================================================================*/ -/* Run-time data */ -/*===========================================================================*/ - -uint32_t audiocounter; /* Used in 22050/44100 to decide samples */ -uint32_t audioodd; /* Used for skipping samples in 22050 */ -uint32_t sound_framecounter; /* Count frames, and then play */ -uint32_t sound_scale; - -double filter_value45 = 0.857270436755215389; // 7000 Hz at 45454 Hz samplingrate -double filter_value33 = 0.809385175167476725; // 7000 Hz at 33100 Hz samplingrate -double filter_value22 = 0.727523105310746957; // 7000 Hz at 22005 Hz samplingrate -double filter_value15 = 0.639362082983339100; // 7000 Hz at 15650 Hz samplingrate -/* -double amplitude_div45 = 3.5000000000; -double amplitude_div33 = 2.8000000000; -double amplitude_div22 = 1.9000000000; -double amplitude_div15 = 1.4000000000; -*/ - -double amplitude_div45 = 7.035; -double amplitude_div33 = 5.25; -double amplitude_div22 = 3.67; -double amplitude_div15 = 2.773; -double last_right = 0.0000000000; -double last_left = 0.0000000000; - - -/*===========================================================================*/ -/* Audio-registers */ -/*===========================================================================*/ - -uint32_t audpt[4]; /* Sample-DMA pointer */ -uint32_t audlen[4]; /* Length */ -uint32_t audper[4]; /* Used directly, NOTE: translated value */ -uint32_t audvol[4]; /* Volume, possibly not reloaded by state-machine */ -uint32_t auddat[4]; /* Last data word set by DMA or CPU */ -BOOLE auddat_set[4]; /* Set TRUE whenever auddat is written */ - -/*===========================================================================*/ -/* Internal variables used by state-machine */ -/*===========================================================================*/ - -uint32_t audlenw[4]; /* Length counter */ -uint32_t audpercounter[4]; /* Period counter */ -uint32_t auddatw[4]; /* Sample currently output, 16-bit signed */ -soundStateFunc audstate[4]; /* Current state for the channel */ -uint32_t audvolw[4]; /* Current volume, reloaded at some points */ -uint32_t audptw[4]; /* Current dma-pointer, reloaded at some points */ - - -/*===========================================================================*/ -/* Translation tables */ -/*===========================================================================*/ - -uint32_t periodtable[65536]; -int16_t volumes[256][64]; -uint32_t audioirqmask[4] = {0x0080, 0x0100, 0x0200, 0x0400}; -uint32_t audiodmaconmask[4] = {0x1, 0x2, 0x4, 0x8}; - - -/*============================================================================== -Audio IO Registers -==============================================================================*/ - -/* Extract channel number from the register address */ - -uint32_t soundGetChannelNumber(uint32_t address) -{ - return ((address & 0x70) >> 4) - 2; -} - - -/* -================== -AUDXPT -================== -$dff0a0,b0,c0,d0 -*/ - -void waudXpth(uint16_t data, uint32_t address) -{ - uint32_t ch = soundGetChannelNumber(address); - audpt[ch] = chipsetReplaceHighPtr(audpt[ch], data); -} - -void waudXptl(uint16_t data, uint32_t address) -{ - uint32_t ch = soundGetChannelNumber(address); - audpt[ch] = chipsetReplaceLowPtr(audpt[ch], data); -} - -/* -================== -AUDXLEN -================== -$dff0a4,b4,c4,d4 -*/ - -void waudXlen(uint16_t data, uint32_t address) -{ - uint32_t ch = soundGetChannelNumber(address); - audlen[ch] = data; -} - -/* -================== -AUDXPER -================== -$dff0a6,b6,c6,d6 -*/ - -void waudXper(uint16_t data, uint32_t address) -{ - uint32_t ch = soundGetChannelNumber(address); - audper[ch] = periodtable[data]; -} - -/* -================== -AUDXVOL -================== -$dff0a8,b8,c8,d8 - -*/ - -void waudXvol(uint16_t data, uint32_t address) -{ - uint32_t ch = soundGetChannelNumber(address); - /*Replay routines sometimes access volume as a byte register at $dff0X9...*/ - if (((data & 0xff) == 0) && ((data & 0xff00) != 0)) data = (data >> 8) & 0xff; - if ((data & 64) == 64) data = 63; - audvol[ch] = data & 0x3f; -} - -/* -================== -AUDXDAT -================== -$dff0aa,ba,ca,da - -Not used right now. -*/ - -void waudXdat(uint16_t data, uint32_t address) -{ - uint32_t ch = soundGetChannelNumber(address); - auddat[ch] = data & 0xff; - auddat_set[ch] = TRUE; -} - - -/*============================================================================== -Audio state machine -==============================================================================*/ - -void soundState0(uint32_t ch); -void soundState1(uint32_t ch); -void soundState2(uint32_t ch); -void soundState3(uint32_t ch); -void soundState4(uint32_t ch); -void soundState5(uint32_t ch); -void soundState6(uint32_t ch); - -/*============================================================================== -State 0 -==============================================================================*/ - -void soundState0(uint32_t ch) -{ - /*------------------- - Statechange 0 to 1 - -------------------*/ - - audlenw[ch] = audlen[ch]; - audptw[ch] = audpt[ch]; - audpercounter[ch] = 0; - audstate[ch] = soundState1; -} - -/*============================================================================== -State 1 -==============================================================================*/ - -void soundState1(uint32_t ch) -{ - /*------------------- - Statechange 1 to 5 - -------------------*/ - - if (audlenw[ch] != 1) audlenw[ch]--; - audstate[ch] = soundState5; - wintreq_direct((uint16_t) (audioirqmask[ch] | 0x8000), 0xdff09c, true); -} - -/*============================================================================== -State 2 -==============================================================================*/ - -void soundState2(uint32_t ch) -{ - if (audpercounter[ch] >= 0x10000) - { - - /*------------------- - Statechange 2 to 3 - -------------------*/ - - audpercounter[ch] -= 0x10000; - audpercounter[ch] += audper[ch]; - audvolw[ch] = audvol[ch]; - audstate[ch] = soundState3; - auddatw[ch] = volumes[(auddat[ch] & 0xff00) >> 8][audvolw[ch]]; - } - else - { - /*------------------- - Statechange 2 to 2 - -------------------*/ - - audpercounter[ch] += audper[ch]; - } -} - -/*============================================================================== -State 3 -==============================================================================*/ - -void soundState3(uint32_t ch) -{ - if (audpercounter[ch] >= 0x10000) - { - /*------------------- - Statechange 3 to 2 - -------------------*/ - - audpercounter[ch] -= 0x10000; - audpercounter[ch] += audper[ch]; - audvolw[ch] = audvol[ch]; - audstate[ch] = soundState2; - auddatw[ch] = volumes[auddat[ch] & 0xff][audvolw[ch]]; - auddat[ch] = chipmemReadWord(audptw[ch]); - audptw[ch] = chipsetMaskPtr(audptw[ch] + 2); - if (audlenw[ch] != 1) audlenw[ch]--; - else - { - audlenw[ch] = audlen[ch]; - audptw[ch] = audpt[ch]; - wintreq_direct((uint16_t) (audioirqmask[ch] | 0x8000), 0xdff09c, true); - } - } - else - { - /*------------------- - Statechange 3 to 3 - -------------------*/ - - audpercounter[ch] += audper[ch]; - } -} - -/*============================================================================== -State 4 and State 6, no operation -==============================================================================*/ - -void soundState4(uint32_t ch) -{ -} - -void soundState6(uint32_t ch) -{ -} - -/*============================================================================== -State 5 -==============================================================================*/ - -void soundState5(uint32_t ch) -{ - /*------------------- - Statechange 5 to 2 - -------------------*/ - - audvolw[ch] = audvol[ch]; - audpercounter[ch] = 0; - auddat[ch] = chipmemReadWord(audptw[ch]); - audptw[ch] = chipsetMaskPtr(audptw[ch] + 2); - audstate[ch] = soundState2; - if (audlenw[ch] != 1) audlenw[ch]--; - else - { - audlenw[ch] = audlen[ch]; - audptw[ch] = audpt[ch]; - wintreq_direct((uint16_t) (audioirqmask[ch] | 0x8000), 0xdff09c, true); - } -} - -/*============================================================================== -This is called by DMACON when DMA is turned off -==============================================================================*/ - -void soundChannelKill(uint32_t ch) -{ - auddatw[ch] = 0; - audstate[ch] = soundState0; -} - -/*============================================================================== -This is called by DMACON when DMA is turned on -==============================================================================*/ - -void soundChannelEnable(uint32_t ch) -{ - soundState0(ch); -} - -/*============================================================================== -Generate sound -Called in every end of line -Will run the audio state machine the needed number of times -and move the generated samples to a temporary buffer -==============================================================================*/ - -/*============================================================================== -; Audio_Lowpass filters the _sound_right and sound_left memory with a -; pass1 lowpass filter at 7000 Hz -; coded by Rainer Sinsch (sinsch@informatik.uni-frankfurt.de) -;==============================================================================*/ - -void soundLowPass(uint32_t count, int16_t *buffer_left, int16_t *buffer_right) -{ - double amplitude_div; - double filter_value; - switch (soundGetRate()) - { - case SOUND_44100: - amplitude_div = amplitude_div45; - filter_value = filter_value45; - break; - case SOUND_31300: - amplitude_div = amplitude_div33; - filter_value = filter_value33; - break; - case SOUND_22050: - amplitude_div = amplitude_div22; - filter_value = filter_value22; - break; - case SOUND_15650: - amplitude_div = amplitude_div15; - filter_value = filter_value15; - break; - } - - for (uint32_t i = 0; i < count; ++i) - { - last_left = filter_value*last_left + (double)buffer_left[i]; - buffer_left[i] = (int16_t) (last_left / amplitude_div); - last_right = filter_value*last_right + (double)buffer_right[i]; - buffer_right[i] = (int16_t) (last_right / amplitude_div); - } -} - -uint32_t soundChannelUpdate(uint32_t ch, int16_t *buffer_left, int16_t *buffer_right, uint32_t count, BOOLE halfscale, BOOLE odd) -{ - uint32_t samples_added = 0; - uint32_t i; - - if (dmacon & audiodmaconmask[ch]) - { - for (i = 0; i < count; ++i) - { - audstate[ch](ch); - if ((!halfscale) || (halfscale && !odd)) - { - if (ch == 0 || ch == 3) - { - buffer_left[samples_added++] += (int16_t) auddatw[ch]; - } - else - { - buffer_right[samples_added++] += (int16_t) auddatw[ch]; - } - } - odd = !odd; - } - } - else - { - if (!interruptIsRequested(audioirqmask[ch]) && auddat_set[ch]) - { - auddat_set[ch] = FALSE; - wintreq_direct((uint16_t) (audioirqmask[ch] | 0x8000), 0xdff09c, true); - } - if (!halfscale) - { - samples_added = count; - } - else - { - for (i = 0; i < count; ++i) - { - if (!odd) - { - samples_added++; - } - odd = !odd; - } - } - } - return samples_added; -} - -void soundFrequencyHandler() -{ - int16_t *buffer_left = (int16_t*) sound_left + sound_buffer_sample_count; - int16_t *buffer_right = (int16_t*) sound_right + sound_buffer_sample_count; - uint32_t count = 0; - uint32_t samples_added; - BOOLE halfscale = (soundGetRate() == SOUND_22050 || soundGetRate() == SOUND_15650); - uint32_t i; - if (soundGetRate() == SOUND_44100 || soundGetRate() == SOUND_22050) - { - while (audiocounter <= 0x40000) - { - count++; - audiocounter += sound_scale; - } - } - else count = 2; - audiocounter -= 0x40000; - for (i = 0; i < count; ++i) buffer_left[i] = buffer_right[i] = 0; - for (i = 0; i < 4; ++i) samples_added = soundChannelUpdate(i, buffer_left, buffer_right, count, halfscale, audioodd); - if (halfscale && count & 1) audioodd = !audioodd; - - if (sound_filter != SOUND_FILTER_NEVER) - { - if (sound_filter == SOUND_FILTER_ALWAYS || ciaIsSoundFilterEnabled()) - soundLowPass(samples_added, buffer_left, buffer_right); - } - sound_buffer_sample_count += samples_added; -} - -/*===========================================================================*/ -/* Property settings */ -/*===========================================================================*/ - -__inline void soundSetRate(sound_rates rate) -{ - sound_rate = rate; -} - -__inline sound_rates soundGetRate() -{ - return sound_rate; -} - -__inline uint32_t soundGetRateReal() -{ - switch (soundGetRate()) { - case SOUND_44100: return 44100; - case SOUND_31300: return 31300; - case SOUND_22050: return 22050; - case SOUND_15650: return 15650; - } - return 0; -} - -__inline void soundSetStereo(bool stereo) -{ - sound_stereo = stereo; -} - -__inline bool soundGetStereo() -{ - return sound_stereo; -} - -__inline void soundSet16Bits(bool bits16) -{ - sound_16bits = bits16; -} - -__inline bool soundGet16Bits() -{ - return sound_16bits; -} - -__inline void soundSetEmulation(sound_emulations emulation) -{ - sound_emulation = emulation; -} - -sound_emulations soundGetEmulation() -{ - return sound_emulation; -} - -__inline void soundSetFilter(sound_filters filter) -{ - sound_filter = filter; -} - -__inline sound_filters soundGetFilter() -{ - return sound_filter; -} - -__inline void soundSetNotification(sound_notifications notification) -{ - sound_notification = notification; -} - -sound_notifications soundGetNotification() -{ - return sound_notification; -} - -__inline void soundSetBufferLength(uint32_t ms) -{ - sound_buffer_length = ms; -} - -__inline uint32_t soundGetBufferLength() -{ - return sound_buffer_length; -} - -__inline uint32_t soundGetVolume() -{ - return sound_volume; -} - -__inline void soundSetVolume(const uint32_t volume) -{ - sound_volume = volume; -} - -__inline void soundSetWAVDump(BOOLE wav_capture) -{ - sound_wav_capture = wav_capture; -} - -__inline BOOLE soundGetWAVDump() -{ - return sound_wav_capture; -} - -__inline void soundSetBufferSampleCount(uint32_t sample_count) -{ - sound_buffer_sample_count = sample_count; -} - -__inline uint32_t soundGetBufferSampleCount() -{ - return sound_buffer_sample_count; -} - -__inline void soundSetBufferSampleCountMax(uint32_t sample_count_max) -{ - sound_buffer_sample_count_max = sample_count_max; -} - -__inline uint32_t soundGetBufferSampleCountMax() -{ - return sound_buffer_sample_count_max; -} - -__inline void soundSetDeviceFound(BOOLE device_found) -{ - sound_device_found = device_found; -} - -__inline BOOLE soundGetDeviceFound() -{ - return sound_device_found; -} - -__inline void soundSetScale(uint32_t scale) -{ - sound_scale = scale; -} - -__inline uint32_t soundGetScale() -{ - return sound_scale; -} - -__inline void soundSetSampleVolume(uint8_t sample_in, uint8_t volume, int16_t sample_out) -{ - volumes[sample_in][volume] = sample_out; -} - -__inline int16_t soundGetSampleVolume(int8_t sample_in, uint8_t volume) -{ - return volumes[sample_in][volume]; -} - -__inline void soundSetPeriodValue(uint32_t period, uint32_t value) -{ - periodtable[period] = value; -} - -__inline uint32_t soundGetPeriodValue(uint32_t period) -{ - return periodtable[period]; -} - - -/*===========================================================================*/ -/* Initializes the volume table */ -/*===========================================================================*/ - -void soundVolumeTableInitialize(BOOLE stereo) -{ - int32_t s; - - if (!stereo) - s = 1; /* Mono */ - else - s = 2; /* Stereo */ - - for (int32_t i = -128; i < 128; i++) - for (int32_t j = 0; j < 64; j++) - if (j == 0) - soundSetSampleVolume((uint8_t) (i & 0xff), (uint8_t) j, (int16_t) 0); - else - soundSetSampleVolume((uint8_t) (i & 0xff), (uint8_t) j, (int16_t) ((i*j*s))); -} - - -/*===========================================================================*/ -/* Initializes the period table */ -/*===========================================================================*/ - -void soundPeriodTableInitialize(uint32_t outputrate) -{ - if (outputrate < 29000) - outputrate *= 2; /* Internally, can not run slower than max Amiga rate */ - soundSetScale((uint32_t) (((double)(65536.0*2.0*31200.0))/((double) outputrate))); - - soundSetPeriodValue(0, 0x10000); - for (int32_t i = 1; i < 65536; i++) - { - //j = 3568200 / i; /* Sample rate */ - double j = 3546895 / i; /* Sample rate */ - int32_t periodvalue = (uint32_t)((j * 65536) / outputrate); - if (periodvalue > 0x10000) - periodvalue = 0x10000; - soundSetPeriodValue(i, periodvalue); - } -} - - -/*===========================================================================*/ -/* Sets up sound emulation for a specific quality */ -/*===========================================================================*/ - -void soundPlaybackInitialize() -{ - audiocounter = 0; - if (soundGetEmulation() > SOUND_NONE) - { /* Play sound */ - soundPeriodTableInitialize(soundGetRateReal()); - soundVolumeTableInitialize(soundGetStereo()); - soundSetBufferSampleCount(0); - sound_current_buffer = 0; - soundSetBufferSampleCountMax(static_cast(static_cast(soundGetRateReal()) / (1000.0f / static_cast(soundGetBufferLength())))); - } -} - - -/*===========================================================================*/ -/* Clear a device struct */ -/*===========================================================================*/ - -void soundDeviceClear(sound_device *sd) -{ - memset(sd, 0, sizeof(sound_device)); -} - - -/*===========================================================================*/ -/* Set IO register stubs */ -/*===========================================================================*/ - -void soundIOHandlersInstall() -{ - for (int i = 0; i < 4; i++) - { - memorySetIoWriteStub(0xa0 + 16*i, waudXpth); - memorySetIoWriteStub(0xa2 + 16*i, waudXptl); - memorySetIoWriteStub(0xa4 + 16*i, waudXlen); - memorySetIoWriteStub(0xa6 + 16*i, waudXper); - memorySetIoWriteStub(0xa8 + 16*i, waudXvol); - memorySetIoWriteStub(0xaa + 16*i, waudXdat); - } -} - - -/*===========================================================================*/ -/* Clear all sound emulation data */ -/*===========================================================================*/ - -void soundIORegistersClear() -{ - audstate[0] = soundState0; - audstate[1] = soundState0; - audstate[2] = soundState0; - audstate[3] = soundState0; - - for (int i = 0; i < 4; i++) - { - audpt[i] = 0; - audptw[i] = 0; - audlen[i] = 2; - audper[i] = 0; - audvol[i] = 0; - audpercounter[i] = 0; - auddat[i] = 0; - auddat_set[i] = FALSE; - auddatw[i] = 0; - audlenw[i] = 2; - audvolw[i] = 0; - } - sound_current_buffer = 0; -} - - -void soundCopyBufferOverrunToCurrentBuffer(uint32_t available_samples, uint32_t previous_buffer) -{ - uint32_t pos = 0; - for (uint32_t i = soundGetBufferSampleCountMax(); i < available_samples; i++) - { - sound_left[sound_current_buffer][pos] = sound_left[previous_buffer][i]; - sound_right[sound_current_buffer][pos] = sound_right[previous_buffer][i]; - pos++; - } - soundSetBufferSampleCount(pos + MAX_BUFFER_SAMPLES*sound_current_buffer); -} - -/*===========================================================================*/ -/* Called on end of line */ -/*===========================================================================*/ - -void soundEndOfLine() -{ - if (soundGetEmulation() != SOUND_NONE) - { - soundFrequencyHandler(); - uint32_t available_samples = soundGetBufferSampleCount() - sound_current_buffer*MAX_BUFFER_SAMPLES; - if (available_samples >= soundGetBufferSampleCountMax()) - { - if (soundGetEmulation() == SOUND_PLAY) - { - soundDrvPlay(sound_left[sound_current_buffer], sound_right[sound_current_buffer], soundGetBufferSampleCountMax()); - } - if (soundGetWAVDump()) - { - wavPlay(sound_left[sound_current_buffer], sound_right[sound_current_buffer], soundGetBufferSampleCountMax()); - } - int previous_buffer = sound_current_buffer; - sound_current_buffer++; - if (sound_current_buffer > 1) - { - sound_current_buffer = 0; - } - soundSetBufferSampleCount(0 + MAX_BUFFER_SAMPLES*sound_current_buffer); - - if (available_samples > soundGetBufferSampleCountMax()) - { - soundCopyBufferOverrunToCurrentBuffer(available_samples, previous_buffer); - } - } - } -} - - -/*===========================================================================*/ -/* Called on emulation start and stop */ -/*===========================================================================*/ - -void soundEmulationStart() -{ - soundIOHandlersInstall(); - audioodd = 0; - soundPlaybackInitialize(); - if (soundGetEmulation() != SOUND_NONE && soundGetEmulation() != SOUND_EMULATE) - { - /* Allow sound driver to override buffer length */ - uint32_t buffer_length = soundGetBufferSampleCountMax(); - if (!soundDrvEmulationStart(soundGetRateReal(), soundGet16Bits(), soundGetStereo(), &buffer_length)) - { - soundSetEmulation(SOUND_EMULATE); /* Driver failed, slient emulation */ - } - if (buffer_length != soundGetBufferSampleCountMax()) - { - soundSetBufferSampleCountMax(buffer_length); - } - } - if (soundGetWAVDump() && (soundGetEmulation() != SOUND_NONE)) - { - wavEmulationStart(soundGetRate(), soundGet16Bits(), soundGetStereo(), soundGetBufferSampleCountMax()); - } -} - -void soundEmulationStop() -{ - if (soundGetEmulation() != SOUND_NONE && soundGetEmulation() != SOUND_EMULATE) - soundDrvEmulationStop(); - if (soundGetWAVDump() && (soundGetEmulation() != SOUND_NONE)) - wavEmulationStop(); -} - - -/*===========================================================================*/ -/* Called every time we do a hard-reset */ -/*===========================================================================*/ - -void soundHardReset() -{ - soundIORegistersClear(); -} - - -/*===========================================================================*/ -/* Called once on emulator startup */ -/*===========================================================================*/ - -BOOLE soundStartup() -{ - soundSetEmulation(SOUND_NONE); - soundSetFilter(SOUND_FILTER_ORIGINAL); - soundSetRate(SOUND_15650); - soundSetStereo(FALSE); - soundSet16Bits(FALSE); - soundSetNotification(SOUND_MMTIMER_NOTIFICATION); - soundSetWAVDump(FALSE); - soundSetBufferLength(40); - soundIORegistersClear(); - soundDeviceClear(&sound_dev); - soundSetDeviceFound(soundDrvStartup(&sound_dev)); - wavStartup(); - if (!soundGetDeviceFound()) - if (soundGetEmulation() == SOUND_PLAY) - soundSetEmulation(SOUND_NONE); - return soundGetDeviceFound(); -} - - -/*===========================================================================*/ -/* Called once on emulator shutdown */ -/*===========================================================================*/ - -void soundShutdown() -{ - soundDrvShutdown(); -} diff --git a/fellow/SRC/WinFellow/C/Sound.cpp b/fellow/SRC/WinFellow/C/Sound.cpp new file mode 100644 index 00000000..8e38c0f0 --- /dev/null +++ b/fellow/SRC/WinFellow/C/Sound.cpp @@ -0,0 +1,823 @@ +/*=========================================================================*/ +/* Fellow */ +/* */ +/* Sound emulation */ +/* */ +/* Author: Petter Schau */ +/* */ +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2, or (at your option) */ +/* any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*=========================================================================*/ + +#include "defs.h" +#include "chipset.h" +#include "fmem.h" +#include "cia.h" +#include "graph.h" +#include "interrupt.h" +#include "VirtualHost/Core.h" + +using namespace CustomChipset; + +// ================== +// AUDXPT +// ================== +// $dff0a0,b0,c0,d0 + +void waudXpth(uint16_t data, uint32_t address) +{ + _core.Sound->SetAudXpth(data, address); +} + +void waudXptl(uint16_t data, uint32_t address) +{ + _core.Sound->SetAudXptl(data, address); +} + +uint32_t Sound::GetChannelNumber(uint32_t address) +{ + return ((address & 0x70) >> 4) - 2; +} + +void Sound::SetAudXpth(uint16_t data, uint32_t address) +{ + uint32_t channel = GetChannelNumber(address); + _audpt[channel] = chipsetReplaceHighPtr(_audpt[channel], data); +} + +void Sound::SetAudXptl(uint16_t data, uint32_t address) +{ + uint32_t channel = GetChannelNumber(address); + _audpt[channel] = chipsetReplaceLowPtr(_audpt[channel], data); +} + +// ================== +// AUDXLEN +// ================== +// $dff0a4,b4,c4,d4 + +void waudXlen(uint16_t data, uint32_t address) +{ + _core.Sound->SetAudXlen(data, address); +} + +void Sound::SetAudXlen(uint16_t data, uint32_t address) +{ + uint32_t channel = GetChannelNumber(address); + _audlen[channel] = data; +} + +// ================== +// AUDXPER +// ================== +// $dff0a6,b6,c6,d6 + +void waudXper(uint16_t data, uint32_t address) +{ + _core.Sound->SetAudXper(data, address); +} + +void Sound::SetAudXper(uint16_t data, uint32_t address) +{ + uint32_t channel = GetChannelNumber(address); + _audper[channel] = _periodTable[data]; +} + +// ================== +// AUDXVOL +// ================== +// $dff0a8,b8,c8,d8 + +void waudXvol(uint16_t data, uint32_t address) +{ + _core.Sound->SetAudXvol(data, address); +} + +void Sound::SetAudXvol(uint16_t data, uint32_t address) +{ + uint32_t channel = GetChannelNumber(address); + // Try to accomodate, replay routines sometimes access volume as a byte register at $dff0X9... + if (((data & 0xff) == 0) && ((data & 0xff00) != 0)) + { + data = (data >> 8) & 0xff; + } + + if ((data & 64) == 64) + { + data = 63; + } + + _audvol[channel] = data & 0x3f; +} + +// ================== +// AUDXDAT +// ================== +// $dff0aa,ba,ca,da + +void waudXdat(uint16_t data, uint32_t address) +{ + _core.Sound->SetAudXdat(data, address); +} + +void Sound::SetAudXdat(uint16_t data, uint32_t address) +{ + uint32_t channel = GetChannelNumber(address); + _auddat[channel] = data & 0xff; + _auddatSet[channel] = true; +} + +void Sound::ExecuteState(uint32_t channel) +{ + switch (_audstate[channel]) + { + case 0: State0(channel); break; + case 1: State1(channel); break; + case 2: State2(channel); break; + case 3: State3(channel); break; + case 4: State4(channel); break; + case 5: State5(channel); break; + case 6: State6(channel); break; + default: break; + } +} + +void Sound::State0(uint32_t channel) +{ + // ------------------- + // Statechange 0 to 1 + // ------------------- + + _audlenw[channel] = _audlen[channel]; + _audptw[channel] = _audpt[channel]; + _audpercounter[channel] = 0; + _audstate[channel] = 1; +} + +void Sound::State1(uint32_t channel) +{ + // ------------------- + // Statechange 1 to 5 + // ------------------- + + if (_audlenw[channel] != 1) + { + _audlenw[channel]--; + } + + _audstate[channel] = 5; + wintreq_direct((uint16_t)(_audioIrqMask[channel] | 0x8000), 0xdff09c, true); +} + +void Sound::State2(uint32_t channel) +{ + if (_audpercounter[channel] >= 0x10000) + { + // ------------------- + // Statechange 2 to 3 + // ------------------- + + _audpercounter[channel] -= 0x10000; + _audpercounter[channel] += _audper[channel]; + _audvolw[channel] = _audvol[channel]; + _audstate[channel] = 3; + _auddatw[channel] = _volumes[(_auddat[channel] & 0xff00) >> 8][_audvolw[channel]]; + } + else + { + // ------------------- + // Statechange 2 to 2 + // ------------------- + + _audpercounter[channel] += _audper[channel]; + } +} + +void Sound::State3(uint32_t channel) +{ + if (_audpercounter[channel] >= 0x10000) + { + // ------------------- + // Statechange 3 to 2 + // ------------------- + + _audpercounter[channel] -= 0x10000; + _audpercounter[channel] += _audper[channel]; + _audvolw[channel] = _audvol[channel]; + _audstate[channel] = 2; + _auddatw[channel] = _volumes[_auddat[channel] & 0xff][_audvolw[channel]]; + _auddat[channel] = chipmemReadWord(_audptw[channel]); + _audptw[channel] = chipsetMaskPtr(_audptw[channel] + 2); + if (_audlenw[channel] != 1) + { + _audlenw[channel]--; + } + else + { + _audlenw[channel] = _audlen[channel]; + _audptw[channel] = _audpt[channel]; + wintreq_direct((uint16_t)(_audioIrqMask[channel] | 0x8000), 0xdff09c, true); + } + } + else + { + // ------------------- + // Statechange 3 to 3 + // ------------------- + + _audpercounter[channel] += _audper[channel]; + } +} + +void Sound::State4(uint32_t channel) +{ +} + +void Sound::State6(uint32_t channel) +{ +} + +void Sound::State5(uint32_t channel) +{ + // ------------------- + // Statechange 5 to 2 + // ------------------- + + _audvolw[channel] = _audvol[channel]; + _audpercounter[channel] = 0; + _auddat[channel] = chipmemReadWord(_audptw[channel]); + _audptw[channel] = chipsetMaskPtr(_audptw[channel] + 2); + _audstate[channel] = 2; + + if (_audlenw[channel] != 1) + { + _audlenw[channel]--; + } + else + { + _audlenw[channel] = _audlen[channel]; + _audptw[channel] = _audpt[channel]; + wintreq_direct((uint16_t)(_audioIrqMask[channel] | 0x8000), 0xdff09c, true); + } +} + +// ============================================================================== +// This is called by DMACON when DMA is turned off +// ============================================================================== + +void Sound::ChannelKill(uint32_t channel) +{ + _auddatw[channel] = 0; + _audstate[channel] = 0; +} + +// ============================================================================== +// This is called by DMACON when DMA is turned on +// ============================================================================== + +void Sound::ChannelEnable(uint32_t channel) +{ + State0(channel); +} + +// ============================================================================== +// Generate sound +// Called in every end of line +// Will run the audio state machine the needed number of times +// and move the generated samples to a temporary buffer +// ============================================================================== + +// ============================================================================== +// Audio_Lowpass filters the __right and _left memory with a +// pass1 lowpass filter at 7000 Hz +// coded by Rainer Sinsch (sinsch@informatik.uni-frankfurt.de) +// ============================================================================== + +void Sound::LowPass(uint32_t count, int16_t *bufferLeft, int16_t *bufferRight) +{ + double amplitudeDiv; + double filterValue; + switch (GetRate()) + { + case SOUND_44100: + amplitudeDiv = _amplitudeDiv45; + filterValue = _filterValue45; + break; + case SOUND_31300: + amplitudeDiv = _amplitudeDiv33; + filterValue = _filterValue33; + break; + case SOUND_22050: + amplitudeDiv = _amplitudeDiv22; + filterValue = _filterValue22; + break; + case SOUND_15650: + amplitudeDiv = _amplitudeDiv15; + filterValue = _filterValue15; + break; + } + + for (uint32_t i = 0; i < count; ++i) + { + _lastLeft = filterValue * _lastLeft + (double)bufferLeft[i]; + bufferLeft[i] = (int16_t)(_lastLeft / amplitudeDiv); + _lastRight = filterValue * _lastRight + (double)bufferRight[i]; + bufferRight[i] = (int16_t)(_lastRight / amplitudeDiv); + } +} + +uint32_t Sound::ChannelUpdate(uint32_t channel, int16_t *bufferLeft, int16_t *bufferRight, uint32_t count, bool halfscale, bool odd) +{ + uint32_t samplesAdded = 0; + uint32_t i; + + if (dmacon & _audioDmaconMask[channel]) + { + for (i = 0; i < count; ++i) + { + ExecuteState(channel); + if ((!halfscale) || (halfscale && !odd)) + { + if (channel == 0 || channel == 3) + { + bufferLeft[samplesAdded++] += (int16_t)_auddatw[channel]; + } + else + { + bufferRight[samplesAdded++] += (int16_t)_auddatw[channel]; + } + } + odd = !odd; + } + } + else + { + if (!interruptIsRequested(_audioIrqMask[channel]) && _auddatSet[channel]) + { + _auddatSet[channel] = false; + wintreq_direct((uint16_t)(_audioIrqMask[channel] | 0x8000), 0xdff09c, true); + } + if (!halfscale) + { + samplesAdded = count; + } + else + { + for (i = 0; i < count; ++i) + { + if (!odd) + { + samplesAdded++; + } + odd = !odd; + } + } + } + return samplesAdded; +} + +void Sound::FrequencyHandler() +{ + int16_t *bufferLeft = (int16_t *)_left + _bufferSampleCount; + int16_t *bufferRight = (int16_t *)_right + _bufferSampleCount; + uint32_t count = 0; + uint32_t samplesAdded; + bool halfscale = (GetRate() == SOUND_22050 || GetRate() == SOUND_15650); + + if (GetRate() == SOUND_44100 || GetRate() == SOUND_22050) + { + while (audiocounter <= 0x40000) + { + count++; + audiocounter += _scale; + } + } + else + { + count = 2; + } + + audiocounter -= 0x40000; + for (uint32_t i = 0; i < count; ++i) + { + bufferLeft[i] = bufferRight[i] = 0; + } + + for (uint32_t i = 0; i < 4; ++i) + { + samplesAdded = ChannelUpdate(i, bufferLeft, bufferRight, count, halfscale, audioodd); + } + + if (halfscale && count & 1) + { + audioodd = !audioodd; + } + + if (_filter != SOUND_FILTER_NEVER) + { + if (_filter == SOUND_FILTER_ALWAYS || ciaIsSoundFilterEnabled()) + { + LowPass(samplesAdded, bufferLeft, bufferRight); + } + } + _bufferSampleCount += samplesAdded; +} + +void Sound::SetRate(sound_rates rate) +{ + _rate = rate; +} + +sound_rates Sound::GetRate() +{ + return _rate; +} + +uint32_t Sound::GetRateReal() +{ + switch (GetRate()) + { + case SOUND_44100: return 44100; + case SOUND_31300: return 31300; + case SOUND_22050: return 22050; + case SOUND_15650: return 15650; + } + return 0; +} + +void Sound::SetIsStereo(bool stereo) +{ + _isStereo = stereo; +} + +bool Sound::GetIsStereo() +{ + return _isStereo; +} + +void Sound::SetIs16Bits(bool bits16) +{ + _is16Bits = bits16; +} + +bool Sound::GetIs16Bits() +{ + return _is16Bits; +} + +void Sound::SetEmulation(sound_emulations emulation) +{ + _emulation = emulation; +} + +sound_emulations Sound::GetEmulation() +{ + return _emulation; +} + +void Sound::SetFilter(sound_filters filter) +{ + _filter = filter; +} + +sound_filters Sound::GetFilter() +{ + return _filter; +} + +void Sound::SetNotification(sound_notifications notification) +{ + _notification = notification; +} + +sound_notifications Sound::GetNotification() +{ + return _notification; +} + +void Sound::SetBufferLength(uint32_t ms) +{ + _bufferLength = ms; +} + +uint32_t Sound::GetBufferLength() +{ + return _bufferLength; +} + +int Sound::GetVolume() +{ + return _volume; +} + +void Sound::SetVolume(const int volume) +{ + _volume = volume; +} + +void Sound::SetWAVDump(bool wavCapture) +{ + _wavCapture = wavCapture; +} + +bool Sound::GetWAVDump() +{ + return _wavCapture; +} + +void Sound::SetBufferSampleCount(uint32_t sampleCount) +{ + _bufferSampleCount = sampleCount; +} + +uint32_t Sound::GetBufferSampleCount() +{ + return _bufferSampleCount; +} + +void Sound::SetBufferSampleCountMax(uint32_t sampleCountMax) +{ + _bufferSampleCountMax = sampleCountMax; +} + +uint32_t Sound::GetBufferSampleCountMax() +{ + return _bufferSampleCountMax; +} + +void Sound::SetDeviceFound(bool deviceFound) +{ + _deviceFound = deviceFound; +} + +bool Sound::GetDeviceFound() +{ + return _deviceFound; +} + +void Sound::SetScale(uint32_t scale) +{ + _scale = scale; +} + +uint32_t Sound::GetScale() +{ + return _scale; +} + +void Sound::SetSampleVolume(uint8_t sampleIn, uint8_t volume, int16_t sampleOut) +{ + _volumes[sampleIn][volume] = sampleOut; +} + +int16_t Sound::GetSampleVolume(int8_t sampleIn, uint8_t volume) +{ + return _volumes[sampleIn][volume]; +} + +void Sound::SetPeriodValue(uint32_t period, uint32_t value) +{ + _periodTable[period] = value; +} + +uint32_t Sound::GetPeriodValue(uint32_t period) +{ + return _periodTable[period]; +} + +void Sound::VolumeTableInitialize(bool isStereo) +{ + int32_t s = isStereo ? 2 : 1; + + for (int32_t i = -128; i < 128; i++) + { + for (int32_t j = 0; j < 64; j++) + { + if (j == 0) + { + SetSampleVolume((uint8_t)(i & 0xff), (uint8_t)j, (int16_t)0); + } + else + { + SetSampleVolume((uint8_t)(i & 0xff), (uint8_t)j, (int16_t)((i * j * s))); + } + } + } +} + +void Sound::PeriodTableInitialize(uint32_t outputRate) +{ + if (outputRate < 29000) + { + outputRate *= 2; // Internally, can not run slower than max Amiga rate + } + + SetScale((uint32_t)(((double)(65536.0 * 2.0 * 31200.0)) / ((double)outputRate))); + + SetPeriodValue(0, 0x10000); + for (int32_t i = 1; i < 65536; i++) + { + double j = 3546895 / i; // Sample rate + int32_t periodvalue = (uint32_t)((j * 65536) / outputRate); + if (periodvalue > 0x10000) + { + periodvalue = 0x10000; + } + SetPeriodValue(i, periodvalue); + } +} + +void Sound::PlaybackInitialize() +{ + audiocounter = 0; + if (GetEmulation() != SOUND_NONE) + { // Play sound + PeriodTableInitialize(GetRateReal()); + VolumeTableInitialize(GetIsStereo()); + SetBufferSampleCount(0); + _currentBuffer = 0; + SetBufferSampleCountMax(static_cast(static_cast(GetRateReal()) / (1000.0f / static_cast(GetBufferLength())))); + } +} + +void Sound::IOHandlersInstall() +{ + for (int i = 0; i < 4; i++) + { + memorySetIoWriteStub(0xa0 + 16 * i, waudXpth); + memorySetIoWriteStub(0xa2 + 16 * i, waudXptl); + memorySetIoWriteStub(0xa4 + 16 * i, waudXlen); + memorySetIoWriteStub(0xa6 + 16 * i, waudXper); + memorySetIoWriteStub(0xa8 + 16 * i, waudXvol); + memorySetIoWriteStub(0xaa + 16 * i, waudXdat); + } +} + +void Sound::IORegistersClear() +{ + _audstate[0] = 0; + _audstate[1] = 0; + _audstate[2] = 0; + _audstate[3] = 0; + + for (int i = 0; i < 4; i++) + { + _audpt[i] = 0; + _audptw[i] = 0; + _audlen[i] = 2; + _audper[i] = 0; + _audvol[i] = 0; + _audpercounter[i] = 0; + _auddat[i] = 0; + _auddatSet[i] = false; + _auddatw[i] = 0; + _audlenw[i] = 2; + _audvolw[i] = 0; + } + _currentBuffer = 0; +} + +void Sound::CopyBufferOverrunToCurrentBuffer(uint32_t availableSamples, uint32_t previousBuffer) +{ + uint32_t pos = 0; + for (uint32_t i = GetBufferSampleCountMax(); i < availableSamples; i++) + { + _left[_currentBuffer][pos] = _left[previousBuffer][i]; + _right[_currentBuffer][pos] = _right[previousBuffer][i]; + pos++; + } + SetBufferSampleCount(pos + MAX_BUFFER_SAMPLES * _currentBuffer); +} + +void Sound::EndOfLine() +{ + if (GetEmulation() == SOUND_NONE) + { + return; + } + + FrequencyHandler(); + uint32_t availableSamples = GetBufferSampleCount() - _currentBuffer * MAX_BUFFER_SAMPLES; + + if (availableSamples < GetBufferSampleCountMax()) + { + return; + } + + if (GetEmulation() == SOUND_PLAY) + { + _core.Drivers.SoundDriver->Play(_left[_currentBuffer], _right[_currentBuffer], GetBufferSampleCountMax()); + } + + if (GetWAVDump()) + { + _wavFileWriter.Play(_left[_currentBuffer], _right[_currentBuffer], GetBufferSampleCountMax()); + } + + int previousBuffer = _currentBuffer; + _currentBuffer++; + if (_currentBuffer > 1) + { + _currentBuffer = 0; + } + SetBufferSampleCount(0 + MAX_BUFFER_SAMPLES * _currentBuffer); + + if (availableSamples > GetBufferSampleCountMax()) + { + CopyBufferOverrunToCurrentBuffer(availableSamples, previousBuffer); + } +} + +void Sound::EmulationStart() +{ + IOHandlersInstall(); + audioodd = 0; + PlaybackInitialize(); + if (GetEmulation() == SOUND_PLAY) + { + auto soundDriverStarted = _core.Drivers.SoundDriver->EmulationStart(SoundDriverRuntimeConfiguration{ + GetEmulation(), + GetRate(), + GetFilter(), + GetNotification(), + GetIsStereo(), + GetIs16Bits(), + GetVolume(), + GetRateReal(), + GetBufferSampleCountMax(), + }); + + if (!soundDriverStarted) + { + SetEmulation(SOUND_EMULATE); + } + } + if (GetWAVDump() && GetEmulation() != SOUND_NONE) + { + _wavFileWriter.EmulationStart(GetRate(), GetIs16Bits(), GetIsStereo(), GetRateReal()); + } +} + +void Sound::EmulationStop() +{ + if (GetEmulation() == SOUND_PLAY) + { + _core.Drivers.SoundDriver->EmulationStop(); + } + + if (GetWAVDump() && GetEmulation() != SOUND_NONE) + { + _wavFileWriter.EmulationStop(); + } +} + +void Sound::HardReset() +{ + IORegistersClear(); +} + +void Sound::Startup() +{ + SetEmulation(SOUND_EMULATE); + SetFilter(SOUND_FILTER_ORIGINAL); + SetRate(SOUND_15650); + SetIsStereo(false); + SetIs16Bits(false); + SetNotification(SOUND_MMTIMER_NOTIFICATION); + SetWAVDump(false); + SetBufferLength(40); + IORegistersClear(); + SetDeviceFound(_core.Drivers.SoundDriver->IsInitialized()); + _wavFileWriter.Startup(); + + if (GetEmulation() == SOUND_PLAY && !GetDeviceFound()) + { + SetEmulation(SOUND_EMULATE); + } +} + +void Sound::Shutdown() +{ + _wavFileWriter.Shutdown(); +} + +Sound::Sound() +{ +} + +Sound::~Sound() +{ +} diff --git a/fellow/SRC/WinFellow/C/SpriteMerger.cpp b/fellow/SRC/WinFellow/C/SpriteMerger.cpp index 71cd72fe..824a5ec1 100644 --- a/fellow/SRC/WinFellow/C/SpriteMerger.cpp +++ b/fellow/SRC/WinFellow/C/SpriteMerger.cpp @@ -1,10 +1,10 @@ #include "SpriteMerger.h" #include "GRAPH.H" -#include "CoreHost.h" +#include "VirtualHost/Core.h" uint8_t SpriteMerger::sprite_translate[2][256][256]; -void SpriteMerger::MergeLores(uint32_t sprite_number, uint8_t *playfield, uint8_t *sprite, uint32_t pixel_count) +void SpriteMerger::MergeLores(uint32_t sprite_number, uint8_t* playfield, uint8_t* sprite, uint32_t pixel_count) { uint32_t in_front = ((_core.Registers.BplCon2 & 0x38) > (4 * sprite_number)) ? 1 : 0; @@ -15,9 +15,9 @@ void SpriteMerger::MergeLores(uint32_t sprite_number, uint8_t *playfield, uint8_ } -void SpriteMerger::MergeHires(uint32_t sprite_number, uint8_t *playfield, uint8_t *sprite, uint32_t pixel_count) +void SpriteMerger::MergeHires(uint32_t sprite_number, uint8_t* playfield, uint8_t* sprite, uint32_t pixel_count) { - uint32_t in_front = ((_core.Registers.BplCon2 & 0x38) >(4 * sprite_number)) ? 1 : 0; + uint32_t in_front = ((_core.Registers.BplCon2 & 0x38) > (4 * sprite_number)) ? 1 : 0; for (uint32_t i = 0; i < pixel_count; ++i) { @@ -26,9 +26,9 @@ void SpriteMerger::MergeHires(uint32_t sprite_number, uint8_t *playfield, uint8_ } } -void SpriteMerger::MergeHam(uint32_t sprite_number, uint8_t *playfield, uint8_t *ham_sprites_playfield, uint8_t *sprite, uint32_t pixel_count) +void SpriteMerger::MergeHam(uint32_t sprite_number, uint8_t* playfield, uint8_t* ham_sprites_playfield, uint8_t* sprite, uint32_t pixel_count) { - uint32_t in_front = ((_core.Registers.BplCon2 & 0x38) >(4 * sprite_number)) ? 1 : 0; + uint32_t in_front = ((_core.Registers.BplCon2 & 0x38) > (4 * sprite_number)) ? 1 : 0; for (uint32_t i = 0; i < pixel_count; ++i) { diff --git a/fellow/SRC/WinFellow/C/WAV.C b/fellow/SRC/WinFellow/C/WAV.C deleted file mode 100644 index 29b8b440..00000000 --- a/fellow/SRC/WinFellow/C/WAV.C +++ /dev/null @@ -1,240 +0,0 @@ -/*=========================================================================*/ -/* Fellow */ -/* Wav file sound dump */ -/* */ -/* Authors: Petter Schau */ -/* Rainer Sinsch */ -/* */ -/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2, or (at your option) */ -/* any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software Foundation, */ -/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*=========================================================================*/ -#include "defs.h" -#include "fellow.h" -#include "sound.h" -#include "graph.h" -#include "draw.h" -#include "fileops.h" - -FILE *wav_FILE; -char wav_filename[MAX_PATH]; -uint32_t wav_serial; -sound_rates wav_rate; -uint32_t wav_rate_real; -BOOLE wav_stereo; -BOOLE wav_16bits; -uint32_t wav_filelength; -uint32_t wav_samplecount; -int32_t wav_samplesum; - - -/*============================================================*/ -/* Add samples to device */ -/* We're not very concerned with performance here. After all, */ -/* we're doing file output, which is likely to be slower than */ -/* anything we can do on our own. */ -/*============================================================*/ - -void wav8BitsMonoAdd(int16_t *left, int16_t *right, uint32_t sample_count) { - if (wav_FILE) { - for (uint32_t i = 0; i < sample_count; i++) { - wav_samplesum = (((int32_t) left[i] + (int32_t) right[i])>>8) + 0x80; - fwrite(&wav_samplesum, 1, 1, wav_FILE); - } - wav_filelength += sample_count; - } -} - -void wav8BitsStereoAdd(int16_t *left, int16_t *right, uint32_t sample_count) { - if (wav_FILE) { - for (uint32_t i = 0; i < sample_count; i++) { - wav_samplesum = (((int32_t) left[i])>>8) + 0x80; - fwrite(&wav_samplesum, 1, 1, wav_FILE); - wav_samplesum = (((int32_t) right[i])>>8) + 0x80; - fwrite(&wav_samplesum, 1, 1, wav_FILE); - } - wav_filelength += sample_count*2; - } -} - -void wav16BitsMonoAdd(int16_t *left, int16_t *right, uint32_t sample_count) { - if (wav_FILE) { - for (uint32_t i = 0; i < sample_count; i++) { - wav_samplesum = left[i] + right[i]; - fwrite(&wav_samplesum, 2, 1, wav_FILE); - } - wav_filelength += sample_count*2; - } -} - -void wav16BitsStereoAdd(int16_t *left, int16_t *right, uint32_t sample_count) { - if (wav_FILE) { - for (uint32_t i = 0; i < sample_count; i++) { - fwrite(&left[i], 2, 1, wav_FILE); - fwrite(&right[i], 2, 1, wav_FILE); - } - wav_filelength += sample_count*4; - } -} - - -/*===========================================================================*/ -/* Write WAV header */ -/*===========================================================================*/ - -void wavHeaderWrite() { - static char *wav_RIFF = {"RIFF"}; - static char *wav_WAVEfmt = {"WAVEfmt "}; - static uint32_t wav_fmtchunklength = 16; - static char *wav_data = {"data"}; - uint32_t bytespersecond=wav_rate_real*(wav_stereo+1)*(wav_16bits+1); - uint32_t bits = (wav_16bits + 1)*8; - uint32_t blockalign = (wav_stereo + 1)*(wav_16bits + 1); - - /* This must still be wrong since wav-editors only reluctantly reads it */ - - if ((wav_FILE = fopen(wav_filename, "wb")) != nullptr) { - wav_filelength = 36; - fwrite(wav_RIFF, 4, 1, wav_FILE); /* 0 RIFF signature */ - fwrite(&wav_filelength, 4, 1, wav_FILE); /* 4 Length of file, that is, the number of bytes following the RIFF/Length pair */ - - fwrite(wav_WAVEfmt, 8, 1, wav_FILE); /* 8 Wave format chunk coming up */ - fwrite(&wav_fmtchunklength, 1, 4, wav_FILE);/* 16 Length of data in WAVEfmt chunk */ - - /* Write a WAVEFORMATEX struct */ - - fputc(0x01, wav_FILE); fputc(0, wav_FILE); /* 20 Wave-format WAVE_FORMAT_PCM */ - fputc(wav_stereo + 1, wav_FILE); /* 22 Channels in file */ - fputc(0, wav_FILE); - fwrite(&wav_rate_real, 4, 1, wav_FILE); /* 24 Samples per second */ - fwrite(&bytespersecond, 4, 1, wav_FILE); /* 28 Average bytes per second */ - fwrite(&blockalign, 2, 1, wav_FILE); /* 32 Block align */ - fwrite(&bits, 2, 1, wav_FILE); /* 34 Bits per sample */ - fwrite(wav_data, 4, 1, wav_FILE); /* 36 Data chunk */ - wav_filelength -= 36; - fwrite(&wav_filelength, 4, 1, wav_FILE); /* 40 Bytes in data chunk */ - wav_filelength += 36; - fclose(wav_FILE); - wav_FILE = nullptr; - } -} - -void wavLengthUpdate() { - if (wav_FILE != nullptr) { - fseek(wav_FILE, 4, SEEK_SET); - fwrite(&wav_filelength, 4, 1, wav_FILE); - fseek(wav_FILE, 40, SEEK_SET); - wav_filelength -= 36; - fwrite(&wav_filelength, 4, 1, wav_FILE); - wav_filelength += 36; - } -} - - -/*===========================================================================*/ -/* Set up WAV file */ -/*===========================================================================*/ - -void wavFileInit(sound_rates rate, BOOLE bits16, BOOLE stereo) -{ - char generic_wav_filename[MAX_PATH]; - - if ((wav_rate != rate) || - (wav_16bits != bits16) || - (wav_stereo != stereo)) { - sprintf(wav_filename, "FWAV%u.WAV", wav_serial++); - - fileopsGetGenericFileName(generic_wav_filename, "WinFellow", wav_filename); - strcpy(wav_filename, generic_wav_filename); - - wav_rate = rate; - wav_rate_real = soundGetRateReal(); - wav_16bits = bits16; - wav_stereo = stereo; - wav_filelength = 0; - wavHeaderWrite(); - } - wav_FILE = fopen(wav_filename, "r+b"); - if (wav_FILE != nullptr) fseek(wav_FILE, 0, SEEK_END); -} - - -/*===========================================================================*/ -/* Play samples, or in this case, save it */ -/*===========================================================================*/ - -void wavPlay(int16_t *left, int16_t *right, uint32_t sample_count) { - if (wav_stereo && wav_16bits) - wav16BitsStereoAdd(left, right, sample_count); - else if (!wav_stereo && wav_16bits) - wav16BitsMonoAdd(left, right, sample_count); - else if (wav_stereo && !wav_16bits) - wav8BitsStereoAdd(left, right, sample_count); - else - wav8BitsMonoAdd(left, right, sample_count); -} - - -/*===========================================================================*/ -/* Emulation start and stop */ -/* */ -/* Called when wav dump is enabled */ -/* Will either continue with old file (same settings), */ -/* or create new (changed settings) */ -/*===========================================================================*/ - -void wavEmulationStart(sound_rates rate, - BOOLE bits16, - BOOLE stereo, - uint32_t buffersamplecountmax) { - wavFileInit(rate, bits16, stereo); -} - -void wavEmulationStop() { - wavLengthUpdate(); - if (wav_FILE != nullptr) { - fflush(wav_FILE); - fclose(wav_FILE); - wav_FILE = nullptr; - } -} - - -/*===========================================================================*/ -/* Called once on startup */ -/* */ -/* WAV supports any sound quality */ -/*===========================================================================*/ - -void wavStartup() { - wav_serial = 0; - wav_rate = (sound_rates) 9999; - wav_16bits = 2; - wav_stereo = 2; /* ILLEGAL */ - wav_FILE = nullptr; - wav_filelength = 0; -} - - -/*===========================================================================*/ -/* Called once on shutdown */ -/*===========================================================================*/ - -void wavShutdown() { - if (wav_FILE != nullptr) - fclose(wav_FILE); -} - - diff --git a/fellow/SRC/WinFellow/C/WavFileWriter.cpp b/fellow/SRC/WinFellow/C/WavFileWriter.cpp new file mode 100644 index 00000000..4ec3cded --- /dev/null +++ b/fellow/SRC/WinFellow/C/WavFileWriter.cpp @@ -0,0 +1,229 @@ +/*=========================================================================*/ +/* Fellow */ +/* Send sound output to a wav */ +/* */ +/* Authors: Petter Schau */ +/* Rainer Sinsch */ +/* */ +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2, or (at your option) */ +/* any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*=========================================================================*/ + +#include +#include +#include "CustomChipset/Sound/WavFileWriter.h" +#include "fileops.h" + +using namespace std; +using namespace CustomChipset; + +void WavFileWriter::Mono8BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount) +{ + if (_wavFile) + { + for (uint32_t i = 0; i < sampleCount; i++) + { + int32_t sampleSum = (((int32_t)left[i] + (int32_t)right[i]) >> 8) + 0x80; + fwrite(&sampleSum, 1, 1, _wavFile); + } + _fileLength += sampleCount; + } +} + +void WavFileWriter::Stereo8BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount) +{ + if (_wavFile) + { + for (uint32_t i = 0; i < sampleCount; i++) + { + int32_t sampleSum = (((int32_t)left[i]) >> 8) + 0x80; + fwrite(&sampleSum, 1, 1, _wavFile); + sampleSum = (((int32_t)right[i]) >> 8) + 0x80; + fwrite(&sampleSum, 1, 1, _wavFile); + } + _fileLength += sampleCount * 2; + } +} + +void WavFileWriter::Mono16BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount) +{ + if (_wavFile) + { + for (uint32_t i = 0; i < sampleCount; i++) + { + int32_t sampleSum = left[i] + right[i]; + fwrite(&sampleSum, 2, 1, _wavFile); + } + _fileLength += sampleCount * 2; + } +} + +void WavFileWriter::Stereo16BitsAdd(int16_t *left, int16_t *right, uint32_t sampleCount) +{ + if (_wavFile) + { + for (uint32_t i = 0; i < sampleCount; i++) + { + fwrite(&left[i], 2, 1, _wavFile); + fwrite(&right[i], 2, 1, _wavFile); + } + _fileLength += sampleCount * 4; + } +} + +void WavFileWriter::HeaderWrite() +{ + static char *wav_RIFF = {"RIFF"}; + static char *wav_WAVEfmt = {"WAVEfmt "}; + static uint32_t wav_fmtchunklength = 16; + static char *wav_data = {"data"}; + uint32_t channelCount = _isStereo ? 2 : 1; + uint32_t is16BitsMultipiler = _is16Bits ? 2 : 1; + uint32_t bytespersecond = _rateReal * channelCount * is16BitsMultipiler; + uint32_t bits = is16BitsMultipiler * 8; + uint32_t blockalign = channelCount * is16BitsMultipiler; + + /* This must still be wrong since wav-editors only reluctantly reads it */ + + if ((_wavFile = fopen(_filename, "wb")) != nullptr) + { + _fileLength = 36; + fwrite(wav_RIFF, 4, 1, _wavFile); /* 0 RIFF signature */ + fwrite(&_fileLength, 4, 1, _wavFile); /* 4 Length of file, that is, the number of bytes following the RIFF/Length pair */ + + fwrite(wav_WAVEfmt, 8, 1, _wavFile); /* 8 Wave format chunk coming up */ + fwrite(&wav_fmtchunklength, 1, 4, _wavFile); /* 16 Length of data in WAVEfmt chunk */ + + /* Write a WAVEFORMATEX struct */ + + fputc(0x01, _wavFile); + fputc(0, _wavFile); /* 20 Wave-format WAVE_FORMAT_PCM */ + fputc(channelCount, _wavFile); /* 22 Channels in file */ + fputc(0, _wavFile); + fwrite(&_rateReal, 4, 1, _wavFile); /* 24 Samples per second */ + fwrite(&bytespersecond, 4, 1, _wavFile); /* 28 Average bytes per second */ + fwrite(&blockalign, 2, 1, _wavFile); /* 32 Block align */ + fwrite(&bits, 2, 1, _wavFile); /* 34 Bits per sample */ + fwrite(wav_data, 4, 1, _wavFile); /* 36 Data chunk */ + _fileLength -= 36; + fwrite(&_fileLength, 4, 1, _wavFile); /* 40 Bytes in data chunk */ + _fileLength += 36; + fclose(_wavFile); + _wavFile = nullptr; + } +} + +void WavFileWriter::LengthUpdate() +{ + if (_wavFile != nullptr) + { + fseek(_wavFile, 4, SEEK_SET); + fwrite(&_fileLength, 4, 1, _wavFile); + fseek(_wavFile, 40, SEEK_SET); + _fileLength -= 36; + fwrite(&_fileLength, 4, 1, _wavFile); + _fileLength += 36; + } +} + +void WavFileWriter::FileInit(sound_rates rate, bool is16Bits, bool isStereo, uint32_t sampleRate) +{ + char generic_wav_filename[256]; + + if (_rate != rate || _is16Bits != is16Bits || _isStereo != isStereo) + { + + char filename[256]; + sprintf(filename, "FWAV%u.WAV", _serial++); + + fileopsGetGenericFileName(generic_wav_filename, "WinFellow", filename); + strcpy(_filename, generic_wav_filename); + + _rate = rate; + _rateReal = sampleRate; + _is16Bits = is16Bits; + _isStereo = isStereo; + _fileLength = 0; + HeaderWrite(); + } + _wavFile = fopen(_filename, "r+b"); + if (_wavFile != nullptr) fseek(_wavFile, 0, SEEK_END); +} + +void WavFileWriter::Play(int16_t *left, int16_t *right, uint32_t sampleCount) +{ + if (_isStereo) + { + if (_is16Bits) + { + Stereo16BitsAdd(left, right, sampleCount); + } + else + { + Stereo8BitsAdd(left, right, sampleCount); + } + } + else + { + if (_is16Bits) + { + Mono16BitsAdd(left, right, sampleCount); + } + else + { + Mono8BitsAdd(left, right, sampleCount); + } + } +} + +void WavFileWriter::EmulationStart(sound_rates rate, bool is16Bits, bool isStereo, uint32_t sampleRate) +{ + FileInit(rate, is16Bits, isStereo, sampleRate); +} + +void WavFileWriter::EmulationStop() +{ + LengthUpdate(); + if (_wavFile != nullptr) + { + fflush(_wavFile); + fclose(_wavFile); + _wavFile = nullptr; + } +} + +void WavFileWriter::Startup() +{ + _serial = 0; + _rate = (sound_rates)9999; + _is16Bits = false; + _isStereo = false; + _wavFile = nullptr; + _fileLength = 0; +} + +void WavFileWriter::Shutdown() +{ + if (_wavFile != nullptr) fclose(_wavFile); +} + +WavFileWriter::WavFileWriter() +{ +} + +WavFileWriter::~WavFileWriter() +{ +} diff --git a/fellow/SRC/WinFellow/C/draw_interlace_control.cpp b/fellow/SRC/WinFellow/C/draw_interlace_control.cpp index 58753327..2c0db168 100644 --- a/fellow/SRC/WinFellow/C/draw_interlace_control.cpp +++ b/fellow/SRC/WinFellow/C/draw_interlace_control.cpp @@ -25,7 +25,7 @@ #include "GRAPH.H" #include "DRAW.H" #include "draw_interlace_control.h" -#include "CoreHost.h" +#include "VirtualHost/Core.h" typedef struct { @@ -71,7 +71,7 @@ void drawDecideInterlaceStatusForNextFrame() { if ((drawGetDisplayScaleStrategy() == DISPLAYSCALE_STRATEGY_SCANLINES) && - interlace_status.use_interlaced_rendering) + interlace_status.use_interlaced_rendering) { // Clear buffers when switching back to scanlines from interlaced rendering // to avoid a ghost image remaining in the scanlines. @@ -82,7 +82,7 @@ void drawDecideInterlaceStatusForNextFrame() drawReinitializeRendering(); } -// fellowAddLog("Frames are %s, frame no %I64d\n", (interlace_status.frame_is_long) ? "long" : "short", busGetRasterFrameCount()); + // fellowAddLog("Frames are %s, frame no %I64d\n", (interlace_status.frame_is_long) ? "long" : "short", busGetRasterFrameCount()); } void drawInterlaceStartup() diff --git a/fellow/SRC/WinFellow/INCLUDE/CONFIG.H b/fellow/SRC/WinFellow/INCLUDE/CONFIG.H index 0a182746..9b095bbe 100644 --- a/fellow/SRC/WinFellow/INCLUDE/CONFIG.H +++ b/fellow/SRC/WinFellow/INCLUDE/CONFIG.H @@ -1,6 +1,6 @@ #pragma once -#include "sound.h" +#include "CustomChipset/Sound/SoundConfiguration.h" #include "CpuIntegration.h" #include "gameport.h" #include "ListTree.h" @@ -53,7 +53,7 @@ typedef enum { } DISPLAYDRIVER; typedef enum { - GRAPHICSEMULATIONMODE_LINEEXACT = 0, + GRAPHICSEMULATIONMODE_LINEEXACT = 0, GRAPHICSEMULATIONMODE_CYCLEEXACT = 1 } GRAPHICSEMULATIONMODE; @@ -80,7 +80,7 @@ typedef struct { BOOLE m_diskenabled[4]; BOOLE m_diskreadonly[4]; BOOLE m_diskfast; - char m_lastuseddiskdir[CFG_FILENAME_LENGTH]; + char m_lastuseddiskdir[CFG_FILENAME_LENGTH]; /*==========================================================================*/ @@ -136,14 +136,14 @@ typedef struct { /* Sound configuration */ /*==========================================================================*/ - sound_emulations m_soundemulation; - sound_rates m_soundrate; + CustomChipset::sound_emulations m_soundemulation; + CustomChipset::sound_rates m_soundrate; bool m_soundstereo; bool m_sound16bits; - sound_filters m_soundfilter; + CustomChipset::sound_filters m_soundfilter; uint32_t m_soundvolume; BOOLE m_soundWAVdump; - sound_notifications m_notification; + CustomChipset::sound_notifications m_notification; uint32_t m_bufferlength; @@ -209,169 +209,169 @@ typedef struct { /* Configuration */ /*============================================================================*/ -extern char *cfgGetDescription(cfg *config); +extern char* cfgGetDescription(cfg* config); /*============================================================================*/ /* Floppy disk configuration property access */ /*============================================================================*/ -extern void cfgSetDiskImage(cfg *config, uint32_t index, char *diskimage); -extern char *cfgGetDiskImage(cfg *config, uint32_t index); -extern void cfgSetDiskEnabled(cfg *config, uint32_t index, BOOLE enabled); -extern BOOLE cfgGetDiskEnabled(cfg *config, uint32_t index); -extern void cfgSetDiskReadOnly(cfg *config, uint32_t index, BOOLE readonly); -extern BOOLE cfgGetDiskReadOnly(cfg *config, uint32_t index); -extern void cfgSetDiskFast(cfg *config, BOOLE fast); -extern BOOLE cfgGetDiskFast(cfg *config); -extern void cfgSetLastUsedDiskDir(cfg *config, char *directory); -extern char *cfgGetLastUsedDiskDir(cfg *config); +extern void cfgSetDiskImage(cfg* config, uint32_t index, char* diskimage); +extern char* cfgGetDiskImage(cfg* config, uint32_t index); +extern void cfgSetDiskEnabled(cfg* config, uint32_t index, BOOLE enabled); +extern BOOLE cfgGetDiskEnabled(cfg* config, uint32_t index); +extern void cfgSetDiskReadOnly(cfg* config, uint32_t index, BOOLE readonly); +extern BOOLE cfgGetDiskReadOnly(cfg* config, uint32_t index); +extern void cfgSetDiskFast(cfg* config, BOOLE fast); +extern BOOLE cfgGetDiskFast(cfg* config); +extern void cfgSetLastUsedDiskDir(cfg* config, char* directory); +extern char* cfgGetLastUsedDiskDir(cfg* config); /*============================================================================*/ /* Memory configuration property access */ /*============================================================================*/ -extern void cfgSetChipSize(cfg *config, uint32_t chipsize); -extern uint32_t cfgGetChipSize(cfg *config); -extern void cfgSetFastSize(cfg *config, uint32_t fastsize); -extern uint32_t cfgGetFastSize(cfg *config); -extern void cfgSetBogoSize(cfg *config, uint32_t bogosize); -extern uint32_t cfgGetBogoSize(cfg *config); -extern void cfgSetKickImage(cfg *config, char *kickimage); -extern char *cfgGetKickImage(cfg *config); -extern void cfgSetKickImageExtended(cfg *config, char *kickimageext); -extern char *cfgGetKickImageExtended(cfg *config); -extern void cfgSetKickDescription(cfg *config, char *kickdescription); -extern char *cfgGetKickDescription(cfg *config); -extern void cfgSetKickCRC32(cfg *config, uint32_t kickcrc32); -extern uint32_t cfgGetKickCRC32(cfg *config); -extern void cfgSetKey(cfg *config, char *key); -extern char *cfgGetKey(cfg *config); -extern void cfgSetUseAutoconfig(cfg *config, bool useautoconfig); -extern bool cfgGetUseAutoconfig(cfg *config); -extern BOOLE cfgGetAddress32Bit(cfg *config); -extern void cfgSetRtc(cfg *config, bool rtc); -extern bool cfgGetRtc(cfg *config); +extern void cfgSetChipSize(cfg* config, uint32_t chipsize); +extern uint32_t cfgGetChipSize(cfg* config); +extern void cfgSetFastSize(cfg* config, uint32_t fastsize); +extern uint32_t cfgGetFastSize(cfg* config); +extern void cfgSetBogoSize(cfg* config, uint32_t bogosize); +extern uint32_t cfgGetBogoSize(cfg* config); +extern void cfgSetKickImage(cfg* config, char* kickimage); +extern char* cfgGetKickImage(cfg* config); +extern void cfgSetKickImageExtended(cfg* config, char* kickimageext); +extern char* cfgGetKickImageExtended(cfg* config); +extern void cfgSetKickDescription(cfg* config, char* kickdescription); +extern char* cfgGetKickDescription(cfg* config); +extern void cfgSetKickCRC32(cfg* config, uint32_t kickcrc32); +extern uint32_t cfgGetKickCRC32(cfg* config); +extern void cfgSetKey(cfg* config, char* key); +extern char* cfgGetKey(cfg* config); +extern void cfgSetUseAutoconfig(cfg* config, bool useautoconfig); +extern bool cfgGetUseAutoconfig(cfg* config); +extern BOOLE cfgGetAddress32Bit(cfg* config); +extern void cfgSetRtc(cfg* config, bool rtc); +extern bool cfgGetRtc(cfg* config); /*===========================================================================*/ /* Host screen configuration property access */ /*===========================================================================*/ -extern void cfgSetScreenWidth(cfg *config, uint32_t screenwidth); -extern uint32_t cfgGetScreenWidth(cfg *config); -extern void cfgSetScreenHeight(cfg *config, uint32_t screenheight); -extern uint32_t cfgGetScreenHeight(cfg *config); -extern void cfgSetScreenColorBits(cfg *config, uint32_t screencolorbits); -extern uint32_t cfgGetScreenColorBits(cfg *config); -extern void cfgSetScreenRefresh(cfg *config, uint32_t screenrefresh); -extern uint32_t cfgGetScreenRefresh(cfg *config); -extern void cfgSetScreenWindowed(cfg *config, bool screenwindowed); -extern bool cfgGetScreenWindowed(cfg *config); - -extern void cfgSetScreenDrawLEDs(cfg *config, bool drawleds); -extern bool cfgGetScreenDrawLEDs(cfg *config); -extern void cfgSetUseMultipleGraphicalBuffers(cfg *config, BOOLE use_multiple_graphical_buffers); -extern BOOLE cfgGetUseMultipleGraphicalBuffers(cfg *config); -extern void cfgSetDisplayDriver(cfg *config, DISPLAYDRIVER display_driver); -extern DISPLAYDRIVER cfgGetDisplayDriver(cfg *config); +extern void cfgSetScreenWidth(cfg* config, uint32_t screenwidth); +extern uint32_t cfgGetScreenWidth(cfg* config); +extern void cfgSetScreenHeight(cfg* config, uint32_t screenheight); +extern uint32_t cfgGetScreenHeight(cfg* config); +extern void cfgSetScreenColorBits(cfg* config, uint32_t screencolorbits); +extern uint32_t cfgGetScreenColorBits(cfg* config); +extern void cfgSetScreenRefresh(cfg* config, uint32_t screenrefresh); +extern uint32_t cfgGetScreenRefresh(cfg* config); +extern void cfgSetScreenWindowed(cfg* config, bool screenwindowed); +extern bool cfgGetScreenWindowed(cfg* config); + +extern void cfgSetScreenDrawLEDs(cfg* config, bool drawleds); +extern bool cfgGetScreenDrawLEDs(cfg* config); +extern void cfgSetUseMultipleGraphicalBuffers(cfg* config, BOOLE use_multiple_graphical_buffers); +extern BOOLE cfgGetUseMultipleGraphicalBuffers(cfg* config); +extern void cfgSetDisplayDriver(cfg* config, DISPLAYDRIVER display_driver); +extern DISPLAYDRIVER cfgGetDisplayDriver(cfg* config); /*===========================================================================*/ /* Graphics emulation configuration property access */ /*===========================================================================*/ -extern void cfgSetFrameskipRatio (cfg *config, uint32_t frameskipratio); -extern uint32_t cfgGetFrameskipRatio (cfg *config); +extern void cfgSetFrameskipRatio(cfg* config, uint32_t frameskipratio); +extern uint32_t cfgGetFrameskipRatio(cfg* config); -extern void cfgSetClipLeft(cfg *config, uint32_t left); -extern uint32_t cfgGetClipLeft(cfg *config); -extern void cfgSetClipTop(cfg *config, uint32_t top); -extern uint32_t cfgGetClipTop(cfg *config); -extern void cfgSetClipRight(cfg *config, uint32_t right); -extern uint32_t cfgGetClipRight(cfg *config); -extern void cfgSetClipBottom(cfg *config, uint32_t bottom); -extern uint32_t cfgGetClipBottom(cfg *config); +extern void cfgSetClipLeft(cfg* config, uint32_t left); +extern uint32_t cfgGetClipLeft(cfg* config); +extern void cfgSetClipTop(cfg* config, uint32_t top); +extern uint32_t cfgGetClipTop(cfg* config); +extern void cfgSetClipRight(cfg* config, uint32_t right); +extern uint32_t cfgGetClipRight(cfg* config); +extern void cfgSetClipBottom(cfg* config, uint32_t bottom); +extern uint32_t cfgGetClipBottom(cfg* config); -extern void cfgSetDisplayScale(cfg *config, DISPLAYSCALE displayscale); -extern DISPLAYSCALE cfgGetDisplayScale(cfg *config); -extern void cfgSetDisplayScaleStrategy(cfg *config, DISPLAYSCALE_STRATEGY displayscalestrategy); -extern DISPLAYSCALE_STRATEGY cfgGetDisplayScaleStrategy(cfg *config); -extern void cfgSetDeinterlace(cfg *config, bool deinterlace); -extern bool cfgGetDeinterlace(cfg *config); -extern void cfgSetGraphicsEmulationMode(cfg *config, GRAPHICSEMULATIONMODE graphcisemulationmode); -extern GRAPHICSEMULATIONMODE cfgGetGraphicsEmulationMode(cfg *config); +extern void cfgSetDisplayScale(cfg* config, DISPLAYSCALE displayscale); +extern DISPLAYSCALE cfgGetDisplayScale(cfg* config); +extern void cfgSetDisplayScaleStrategy(cfg* config, DISPLAYSCALE_STRATEGY displayscalestrategy); +extern DISPLAYSCALE_STRATEGY cfgGetDisplayScaleStrategy(cfg* config); +extern void cfgSetDeinterlace(cfg* config, bool deinterlace); +extern bool cfgGetDeinterlace(cfg* config); +extern void cfgSetGraphicsEmulationMode(cfg* config, GRAPHICSEMULATIONMODE graphcisemulationmode); +extern GRAPHICSEMULATIONMODE cfgGetGraphicsEmulationMode(cfg* config); /*============================================================================*/ /* Sound configuration property access */ /*============================================================================*/ -extern void cfgSetSoundEmulation(cfg *config, sound_emulations soundemulation); -extern sound_emulations cfgGetSoundEmulation(cfg *config); -extern void cfgSetSoundRate(cfg *config, sound_rates soundrate); -extern sound_rates cfgGetSoundRate(cfg *config); -extern void cfgSetSoundStereo(cfg *config, bool soundstereo); -extern bool cfgGetSoundStereo(cfg *config); -extern void cfgSetSound16Bits(cfg *config, bool soundbit); -extern bool cfgGetSound16Bits(cfg *config); -extern void cfgSetSoundFilter(cfg *config, sound_filters soundfilter); -extern sound_filters cfgGetSoundFilter(cfg *config); -extern void cfgSetSoundVolume(cfg *config, const uint32_t soundvolume); -extern uint32_t cfgGetSoundVolume(cfg *config); -extern void cfgSetSoundWAVDump(cfg *config, BOOLE soundWAVdump); -extern BOOLE cfgGetSoundWAVDump(cfg *config); -extern void cfgSetSoundNotification(cfg *config, sound_notifications soundnotification); -extern sound_notifications cfgGetSoundNotification(cfg *config); -extern void cfgSetSoundBufferLength(cfg *config, uint32_t buffer_length); -extern uint32_t cfgGetSoundBufferLength(cfg *config); +extern void cfgSetSoundEmulation(cfg* config, CustomChipset::sound_emulations soundemulation); +extern CustomChipset::sound_emulations cfgGetSoundEmulation(cfg* config); +extern void cfgSetSoundRate(cfg* config, CustomChipset::sound_rates soundrate); +extern CustomChipset::sound_rates cfgGetSoundRate(cfg* config); +extern void cfgSetSoundStereo(cfg* config, bool soundstereo); +extern bool cfgGetSoundStereo(cfg* config); +extern void cfgSetSound16Bits(cfg* config, bool soundbit); +extern bool cfgGetSound16Bits(cfg* config); +extern void cfgSetSoundFilter(cfg* config, CustomChipset::sound_filters soundfilter); +extern CustomChipset::sound_filters cfgGetSoundFilter(cfg* config); +extern void cfgSetSoundVolume(cfg* config, const uint32_t soundvolume); +extern uint32_t cfgGetSoundVolume(cfg* config); +extern void cfgSetSoundWAVDump(cfg* config, BOOLE soundWAVdump); +extern BOOLE cfgGetSoundWAVDump(cfg* config); +extern void cfgSetSoundNotification(cfg* config, CustomChipset::sound_notifications soundnotification); +extern CustomChipset::sound_notifications cfgGetSoundNotification(cfg* config); +extern void cfgSetSoundBufferLength(cfg* config, uint32_t buffer_length); +extern uint32_t cfgGetSoundBufferLength(cfg* config); /*============================================================================*/ /* CPU configuration property access */ /*============================================================================*/ -extern void cfgSetCPUType(cfg *config, cpu_integration_models CPUtype); -extern cpu_integration_models cfgGetCPUType(cfg *config); -extern void cfgSetCPUSpeed(cfg *config, uint32_t CPUspeed); -extern uint32_t cfgGetCPUSpeed(cfg *config); +extern void cfgSetCPUType(cfg* config, cpu_integration_models CPUtype); +extern cpu_integration_models cfgGetCPUType(cfg* config); +extern void cfgSetCPUSpeed(cfg* config, uint32_t CPUspeed); +extern uint32_t cfgGetCPUSpeed(cfg* config); /*============================================================================*/ /* Custom chipset configuration property access */ /*============================================================================*/ -extern void cfgSetBlitterFast(cfg *config, BOOLE blitterfast); -extern BOOLE cfgGetBlitterFast(cfg *config); -extern void cfgSetECS(cfg *config, bool ecs); -extern bool cfgGetECS(cfg *config); +extern void cfgSetBlitterFast(cfg* config, BOOLE blitterfast); +extern BOOLE cfgGetBlitterFast(cfg* config); +extern void cfgSetECS(cfg* config, bool ecs); +extern bool cfgGetECS(cfg* config); /*============================================================================*/ /* Hardfile configuration property access */ /*============================================================================*/ -extern uint32_t cfgGetHardfileCount(cfg *config); -extern cfg_hardfile cfgGetHardfile(cfg *config, uint32_t index); -extern void cfgHardfileAdd(cfg *config, cfg_hardfile *hardfile); -extern void cfgHardfileRemove(cfg *config, uint32_t index); -extern void cfgHardfilesFree(cfg *config); -extern void cfgSetHardfileUnitDefaults(cfg_hardfile *hardfile); -extern void cfgHardfileChange(cfg *config, cfg_hardfile *hardfile, uint32_t index); +extern uint32_t cfgGetHardfileCount(cfg* config); +extern cfg_hardfile cfgGetHardfile(cfg* config, uint32_t index); +extern void cfgHardfileAdd(cfg* config, cfg_hardfile* hardfile); +extern void cfgHardfileRemove(cfg* config, uint32_t index); +extern void cfgHardfilesFree(cfg* config); +extern void cfgSetHardfileUnitDefaults(cfg_hardfile* hardfile); +extern void cfgHardfileChange(cfg* config, cfg_hardfile* hardfile, uint32_t index); /*============================================================================*/ /* Filesystem configuration property access */ /*============================================================================*/ -extern uint32_t cfgGetFilesystemCount(cfg *config); -extern cfg_filesys cfgGetFilesystem(cfg *config, uint32_t index); -extern void cfgFilesystemAdd(cfg *config, cfg_filesys *filesystem); -extern void cfgFilesystemRemove(cfg *config, uint32_t index); -extern void cfgFilesystemsFree(cfg *config); -extern void cfgSetFilesystemUnitDefaults(cfg_filesys *filesystem); -extern void cfgFilesystemChange(cfg *config, - cfg_filesys *filesystem, - uint32_t index); -extern void cfgSetFilesystemAutomountDrives(cfg *config, - BOOLE automount_drives); -extern BOOLE cfgGetFilesystemAutomountDrives(cfg *config); +extern uint32_t cfgGetFilesystemCount(cfg* config); +extern cfg_filesys cfgGetFilesystem(cfg* config, uint32_t index); +extern void cfgFilesystemAdd(cfg* config, cfg_filesys* filesystem); +extern void cfgFilesystemRemove(cfg* config, uint32_t index); +extern void cfgFilesystemsFree(cfg* config); +extern void cfgSetFilesystemUnitDefaults(cfg_filesys* filesystem); +extern void cfgFilesystemChange(cfg* config, + cfg_filesys* filesystem, + uint32_t index); +extern void cfgSetFilesystemAutomountDrives(cfg* config, + BOOLE automount_drives); +extern BOOLE cfgGetFilesystemAutomountDrives(cfg* config); extern void cfgSetFilesystemDeviceNamePrefix(cfg* config, char* prefix); extern char* cfgGetFilesystemDeviceNamePrefix(cfg* config); @@ -381,42 +381,42 @@ extern char* cfgGetFilesystemDeviceNamePrefix(cfg* config); /* Game port configuration property access */ /*============================================================================*/ -extern void cfgSetGameport(cfg *config, uint32_t index, gameport_inputs gameport); -extern gameport_inputs cfgGetGameport(cfg *config, uint32_t index); +extern void cfgSetGameport(cfg* config, uint32_t index, gameport_inputs gameport); +extern gameport_inputs cfgGetGameport(cfg* config, uint32_t index); /*============================================================================*/ /* GUI configuration property access */ /*============================================================================*/ -extern void cfgSetUseGUI(cfg *config, bool useGUI); -extern bool cfgGetUseGUI(cfg *config); +extern void cfgSetUseGUI(cfg* config, bool useGUI); +extern bool cfgGetUseGUI(cfg* config); /*============================================================================*/ /* Various configuration property access */ /*============================================================================*/ -extern void cfgSetMeasureSpeed(cfg *config, bool measurespeed); -extern bool cfgGetMeasureSpeed(cfg *config); +extern void cfgSetMeasureSpeed(cfg* config, bool measurespeed); +extern bool cfgGetMeasureSpeed(cfg* config); /*============================================================================*/ /* cfg Utility Functions */ /*============================================================================*/ -extern void cfgSetDefaults(cfg *config); -extern BOOLE cfgSetOption(cfg *config, char *optionstr); -extern BOOLE cfgSaveOptions(cfg *config, FILE *cfgfile); -extern bool cfgLoadFromFilename(cfg *, const char *, const bool); -extern BOOLE cfgSaveToFilename(cfg *config, char *filename); -extern void cfgSynopsis(cfg *config); +extern void cfgSetDefaults(cfg* config); +extern BOOLE cfgSetOption(cfg* config, char* optionstr); +extern BOOLE cfgSaveOptions(cfg* config, FILE* cfgfile); +extern bool cfgLoadFromFilename(cfg*, const char*, const bool); +extern BOOLE cfgSaveToFilename(cfg* config, char* filename); +extern void cfgSynopsis(cfg* config); /*============================================================================*/ /* struct cfgManager */ /*============================================================================*/ typedef struct { - cfg *m_currentconfig; + cfg* m_currentconfig; } cfgManager; @@ -424,20 +424,20 @@ typedef struct { /* struct cfgManager property access functions */ /*============================================================================*/ -extern void cfgManagerSetCurrentConfig(cfgManager *configmanager, cfg *currentconfig); -extern cfg *cfgManagerGetCurrentConfig(cfgManager *configmanager); -extern cfg *cfgManagerGetCopyOfCurrentConfig(cfgManager *configmanager); +extern void cfgManagerSetCurrentConfig(cfgManager* configmanager, cfg* currentconfig); +extern cfg* cfgManagerGetCurrentConfig(cfgManager* configmanager); +extern cfg* cfgManagerGetCopyOfCurrentConfig(cfgManager* configmanager); /*============================================================================*/ /* struct cfgManager utility functions */ /*============================================================================*/ -extern BOOLE cfgManagerConfigurationActivate(cfgManager *configmanager); -extern cfg *cfgManagerGetNewConfig(cfgManager *configmanager); -extern void cfgManagerFreeConfig(cfgManager *configmanager, cfg *config); -extern void cfgManagerStartup(cfgManager *configmanager, int argc, char *argv[]); -extern void cfgManagerShutdown(cfgManager *configmanager); +extern BOOLE cfgManagerConfigurationActivate(cfgManager* configmanager); +extern cfg* cfgManagerGetNewConfig(cfgManager* configmanager); +extern void cfgManagerFreeConfig(cfgManager* configmanager, cfg* config); +extern void cfgManagerStartup(cfgManager* configmanager, int argc, char* argv[]); +extern void cfgManagerShutdown(cfgManager* configmanager); /*============================================================================*/ @@ -446,14 +446,14 @@ extern void cfgManagerShutdown(cfgManager *configmanager); extern cfgManager cfg_manager; -extern void cfgStartup(int argc, char **argv); +extern void cfgStartup(int argc, char** argv); extern void cfgShutdown(); /*============================================================================*/ /* tracking flag functions */ /*============================================================================*/ -extern void cfgSetConfigAppliedOnce(cfg *, BOOLE); -extern BOOLE cfgGetConfigAppliedOnce(cfg *); -extern void cfgSetConfigChangedSinceLastSave(cfg *, BOOLE); -extern BOOLE cfgGetConfigChangedSinceLastSave(cfg *); +extern void cfgSetConfigAppliedOnce(cfg*, BOOLE); +extern BOOLE cfgGetConfigAppliedOnce(cfg*); +extern void cfgSetConfigChangedSinceLastSave(cfg*, BOOLE); +extern BOOLE cfgGetConfigChangedSinceLastSave(cfg*); diff --git a/fellow/SRC/WinFellow/INCLUDE/CoreHost.h b/fellow/SRC/WinFellow/INCLUDE/CoreHost.h deleted file mode 100644 index 8e5d2369..00000000 --- a/fellow/SRC/WinFellow/INCLUDE/CoreHost.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "Core.h" - -extern Core _core; diff --git a/fellow/SRC/WinFellow/INCLUDE/EVENTID.H b/fellow/SRC/WinFellow/INCLUDE/EVENTID.H deleted file mode 100644 index 3c9a770c..00000000 --- a/fellow/SRC/WinFellow/INCLUDE/EVENTID.H +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#define EVENTCOUNT 16384 -#define EVENTMASK 0x3fff - -#define IRQ1_0_TBE 0 -#define IRQ1_1_DSKBLK 1 -#define IRQ1_2_SOFT 2 -#define IRQ2_CIAA 3 -#define IRQ3_0_COPPER 4 -#define IRQ3_1_VBL 5 -#define IRQ3_2_BLIT 6 -#define IRQ4_AUD 7 -#define IRQ5_0_RBF 11 -#define IRQ5_1_DSKSYN 12 -#define IRQ6_0_CIAB 13 -#define EXBUSERROR 25 -#define EXODDADDRESS 26 -#define EXILLEGAL 27 -#define EXDIVBYZERO 28 -#define EXPRIV 31 -#define EXTRAP 32 -#define EVSTOP 33 -#define EXFLINE 34 - -extern uint32_t logbuffer[EVENTCOUNT][16]; -extern int logfirst; -extern int loglast; - - -/* Logging flags */ -extern BOOLE logserialtransmitbufferemptyirq; -extern BOOLE logdiskdmatransferdoneirq; -extern BOOLE logsoftwareirq; -extern BOOLE logciaairq; -extern BOOLE logcopperirq; -extern BOOLE logverticalblankirq; -extern BOOLE logblitterreadyirq; -extern BOOLE logaudioirq; -extern BOOLE logserialreceivebufferfullirq; -extern BOOLE logdisksyncvaluerecognizedirq; -extern BOOLE logciabirq; -extern BOOLE logstop; -extern BOOLE logbuserrorex; -extern BOOLE logoddaddressex; -extern BOOLE logillegalinstructionex; -extern BOOLE logdivisionby0ex; -extern BOOLE logprivilegieviolationex; -extern BOOLE logtrapex; -extern BOOLE logfline; diff --git a/fellow/SRC/WinFellow/INCLUDE/SOUND.H b/fellow/SRC/WinFellow/INCLUDE/SOUND.H deleted file mode 100644 index 63f93300..00000000 --- a/fellow/SRC/WinFellow/INCLUDE/SOUND.H +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -/*=========================================================================*/ -/* Fellow */ -/* */ -/* Sound emulation */ -/* */ -/* Author: Petter Schau */ -/* */ -/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2, or (at your option) */ -/* any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software Foundation, */ -/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*=========================================================================*/ - -/*===========================*/ -/* Symbols for configuration */ -/*===========================*/ - -typedef enum {SOUND_15650, SOUND_22050, SOUND_31300, SOUND_44100} sound_rates; -typedef enum {SOUND_NONE, SOUND_PLAY, SOUND_EMULATE} sound_emulations; -typedef enum {SOUND_FILTER_ORIGINAL, SOUND_FILTER_ALWAYS, SOUND_FILTER_NEVER} sound_filters; -typedef enum {SOUND_DSOUND_NOTIFICATION, SOUND_MMTIMER_NOTIFICATION} sound_notifications; - - -/*==========================*/ -/* Sound device information */ -/*==========================*/ - -typedef struct { - BOOLE mono; - BOOLE stereo; - BOOLE bits8; - BOOLE bits16; - uint32_t rates_max[2][2]; /* Maximum playback rate for [8/16 bits][mono/stereo] */ -} sound_device; - - -extern sound_emulations sound_emulation; -extern sound_rates sound_rate; -extern bool sound_stereo; -extern bool sound_16bits; -extern BOOLE sound_wav_capture; -extern uint32_t sound_buffer_length; -extern sound_filters sound_filter; -extern sound_notifications sound_notification; - - -/*==================================*/ -/* Property access */ -/*==================================*/ - -extern void soundSetRate(sound_rates rate); -extern sound_rates soundGetRate(); -extern uint32_t soundGetRateReal(); -extern void soundSetStereo(bool stereo); -extern bool soundGetStereo(); -extern void soundSet16Bits(bool bits16); -extern bool soundGet16Bits(); -extern void soundSetEmulation(sound_emulations emulation); -extern sound_emulations soundGetEmulation(); -extern void soundSetFilter(sound_filters filter); -extern sound_filters soundGetFilter(); -extern void soundSetBufferLength(uint32_t ms); -extern uint32_t soundGetBufferLength(); -extern void soundSetVolume(uint32_t volume); -extern uint32_t soundGetVolume(); -extern void soundSetWAVDump(BOOLE wav_capture); -extern BOOLE soundGetWAVDump(); -extern void soundSetNotification(sound_notifications notification); -extern sound_notifications soundGetNotification(); - -extern void soundEndOfLine(); /* for bus.c */ -extern void soundChannelKill(uint32_t ch); /* for wdmacon */ -extern void soundChannelEnable(uint32_t ch); /* for wdmacon */ - -extern void soundState0(uint32_t ch); /* for wdbg.c */ -extern void soundState1(uint32_t ch); -extern void soundState2(uint32_t ch); -extern void soundState3(uint32_t ch); -extern void soundState4(uint32_t ch); -extern void soundState5(uint32_t ch); - - -/*==================================*/ -/* Standard Fellow Module Functions */ -/*==================================*/ - -typedef void (*soundStateFunc)(uint32_t); - -extern void soundEndOfLine(); -extern void soundHardReset(); -extern void soundEmulationStart(); -extern void soundEmulationStop(); -extern BOOLE soundStartup(); -extern void soundShutdown(); diff --git a/fellow/SRC/WinFellow/INCLUDE/SOUNDDRV.H b/fellow/SRC/WinFellow/INCLUDE/SOUNDDRV.H deleted file mode 100644 index cb1d60d9..00000000 --- a/fellow/SRC/WinFellow/INCLUDE/SOUNDDRV.H +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -/*===========================================================================*/ -/* Implementing these functions creates a sound driver for Fellow */ -/*===========================================================================*/ - -extern bool soundDrvStartup(sound_device *devinfo); -extern void soundDrvShutdown(); -extern bool soundDrvEmulationStart(uint32_t outputrate, - bool bits16, - bool stereo, - uint32_t *buffersamplecountmax); -extern void soundDrvEmulationStop(); -extern void soundDrvPlay(int16_t *leftbuffer, int16_t *rightbuffer, uint32_t samplecount); -extern void soundDrvPollBufferPosition(); -extern bool soundDrvDSoundSetCurrentSoundDeviceVolume(const int); diff --git a/fellow/SRC/WinFellow/INCLUDE/WAV.H b/fellow/SRC/WinFellow/INCLUDE/WAV.H deleted file mode 100644 index 29c11b5a..00000000 --- a/fellow/SRC/WinFellow/INCLUDE/WAV.H +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -extern void wavPlay(int16_t *left, int16_t *right, uint32_t sample_count); -extern void wavEmulationStart(sound_rates rate, BOOLE bits16, BOOLE stereo, uint32_t buffersamplecountmax); -extern void wavEmulationStop(); -extern void wavStartup(); -extern void wavShutdown(); diff --git a/fellow/SRC/WinFellow/VirtualHost/CoreFactory.cpp b/fellow/SRC/WinFellow/VirtualHost/CoreFactory.cpp new file mode 100644 index 00000000..89d4ba1b --- /dev/null +++ b/fellow/SRC/WinFellow/VirtualHost/CoreFactory.cpp @@ -0,0 +1,25 @@ +#include "VirtualHost/Core.h" +#include "VirtualHost/CoreFactory.h" +#include "Driver/Sound/DirectSoundDriver.h" + +void CoreFactory::CreateDrivers() +{ + _core.Drivers.SoundDriver = new DirectSoundDriver(); +} + +void CoreFactory::DestroyDrivers() +{ + delete _core.Drivers.SoundDriver; + _core.Drivers.SoundDriver = nullptr; +} + +void CoreFactory::CreateModules() +{ + _core.Sound = new Sound(); +} + +void CoreFactory::DestroyModules() +{ + delete _core.Sound; + _core.Sound = nullptr; +} \ No newline at end of file diff --git a/fellow/SRC/WinFellow/VirtualHost/CoreFactory.h b/fellow/SRC/WinFellow/VirtualHost/CoreFactory.h new file mode 100644 index 00000000..32ab0f74 --- /dev/null +++ b/fellow/SRC/WinFellow/VirtualHost/CoreFactory.h @@ -0,0 +1,10 @@ +#pragma once + +class CoreFactory +{ +public: + static void CreateDrivers(); + static void DestroyDrivers(); + static void CreateModules(); + static void DestroyModules(); +}; diff --git a/fellow/SRC/WinFellow/WinFellow.vcxproj b/fellow/SRC/WinFellow/WinFellow.vcxproj index f0c9c79e..c576f236 100644 --- a/fellow/SRC/WinFellow/WinFellow.vcxproj +++ b/fellow/SRC/WinFellow/WinFellow.vcxproj @@ -320,7 +320,6 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre Sync EnableFastChecks MultiThreadedDebug - false true @@ -380,7 +379,6 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre WIN32;_DEBUG;_WINDOWS;FELLOW_SUPPORT_CAPS;_FELLOW_DEBUG_CRT_MALLOC;_CRT_SECURE_NO_WARNINGS;X64;RETRO_PLATFORM;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - false true $(IntDir)$(TargetName).pch @@ -440,7 +438,6 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre WIN32;_DEBUG;_WINDOWS;FELLOW_SUPPORT_CAPS;_FELLOW_DEBUG_CRT_MALLOC;_CRT_SECURE_NO_WARNINGS;X64;RETRO_PLATFORM;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - false true $(IntDir)$(TargetName).pch @@ -486,6 +483,9 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre + + + CompileAsC CompileAsC @@ -1107,13 +1107,12 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre - + - @@ -1171,7 +1170,6 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre - @@ -1179,6 +1177,9 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre + + + @@ -1251,7 +1252,6 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre - @@ -1266,7 +1266,6 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre - @@ -1289,15 +1288,12 @@ PowerShell.exe ..\build\Scripts\GitWCRev.ps1 -InputFileName GUI_versioninfo-wcre - - - diff --git a/fellow/SRC/WinFellow/WinFellow.vcxproj.filters b/fellow/SRC/WinFellow/WinFellow.vcxproj.filters index 45dcf059..986ac1a7 100644 --- a/fellow/SRC/WinFellow/WinFellow.vcxproj.filters +++ b/fellow/SRC/WinFellow/WinFellow.vcxproj.filters @@ -76,6 +76,15 @@ {0adab2c7-b505-44b5-a2c6-67ce8f273312} + + {25b2f21a-8c0b-4ab7-85fc-86be576fed09} + + + {5cd84858-a406-4181-9bfd-143e9807bbaf} + + + {d3362cca-2d02-4d07-8940-1a7b0be5fb67} + @@ -255,7 +264,7 @@ core C Files - + core C Files @@ -273,9 +282,6 @@ core C Files - - core C Files - core C Files @@ -444,9 +450,6 @@ Windows - - Windows - Windows @@ -480,6 +483,15 @@ ADF Compression Files\zlib C Files + + Windows\Driver\Sound + + + core C Files + + + VirtualHost + @@ -584,9 +596,6 @@ core C Header Files - - core C Header Files - core C Header Files @@ -629,9 +638,6 @@ core C Header Files - - core C Header Files - core C Header Files @@ -698,12 +704,6 @@ core C Header Files - - core C Header Files - - - core C Header Files - core C Header Files @@ -722,9 +722,6 @@ core C Header Files - - core C Header Files - core C Header Files @@ -938,6 +935,15 @@ Windows + + Windows\Driver\Sound + + + Windows\Driver\Sound + + + VirtualHost + diff --git a/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundDriver.cpp b/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundDriver.cpp new file mode 100644 index 00000000..f0551910 --- /dev/null +++ b/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundDriver.cpp @@ -0,0 +1,1047 @@ +/*=========================================================================*/ +/* Fellow Amiga Emulator */ +/* Sound driver for Windows */ +/* Author: Petter Schau (peschau@online.no) */ +/* */ +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2, or (at your option) */ +/* any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*=========================================================================*/ + +/** @file + * Sound driver for Windows + */ + +#define INITGUID + +#include + +#include "GfxDrvCommon.h" +#include "fellow/api/defs.h" +#include "DirectSoundDriver.h" +#include "windrv.h" +#include "fellow/api/Services.h" + +using namespace fellow::api; +using namespace CustomChipset; + +const char *DirectSoundDriver::DSoundErrorString(HRESULT hResult) +{ + switch (hResult) + { + case DSERR_ALLOCATED: return "DSERR_ALLOCATED"; + case DSERR_CONTROLUNAVAIL: return "DSERR_CONTROLUNAVAIL"; + case DSERR_INVALIDPARAM: return "DSERR_INVALIDPARAM"; + case DSERR_INVALIDCALL: return "DSERR_INVALIDCALL"; + case DSERR_GENERIC: return "DSERR_GENERIC"; + case DSERR_PRIOLEVELNEEDED: return "DSERR_PRIOLEVELNEEDED"; + case DSERR_OUTOFMEMORY: return "DSERR_OUTOFMEMORY"; + case DSERR_BADFORMAT: return "DSERR_BADFORMAT"; + case DSERR_UNSUPPORTED: return "DSERR_UNSUPPORTED"; + case DSERR_NODRIVER: return "DSERR_NODRIVER"; + case DSERR_ALREADYINITIALIZED: return "DSERR_ALREADYINITIALIZED"; + case DSERR_NOAGGREGATION: return "DSERR_NOAGGREGATION"; + case DSERR_BUFFERLOST: return "DSERR_BUFFERLOST"; + case DSERR_OTHERAPPHASPRIO: return "DSERR_OTHERAPPHASPRIO"; + case DSERR_UNINITIALIZED: return "DSERR_UNINITIALIZED"; + } + + return "Unknown DirectSound Error"; +} + +//======================================================================== +// Multimedia Callback fnc. Used when DirectSound notification unsupported +//======================================================================== + +void CALLBACK DirectSoundDriver::timercb(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) +{ + ((DirectSoundDriver *)dwUser)->HandleTimerCallback(); +} + +void DirectSoundDriver::HandleTimerCallback() +{ + PollBufferPosition(); +} + +void DirectSoundDriver::DSoundFailure(const char *header, HRESULT errorCode) +{ + Service->Log.AddLog(header); + Service->Log.AddLog(DSoundErrorString(errorCode)); + Service->Log.AddLog("\n"); +} + +void DirectSoundDriver::DSoundRelease() +{ + if (_lpDS != nullptr) + { + IDirectSound_Release(_lpDS); + _lpDS = nullptr; + } + + for (unsigned int i = 0; i < 3; i++) + { + if (_notifications[i] != nullptr) + { + CloseHandle(_notifications[i]); + _notifications[i] = nullptr; + } + } + + if (_dataAvailable != nullptr) + { + CloseHandle(_dataAvailable); + _dataAvailable = nullptr; + } + + if (_canAddData != nullptr) + { + CloseHandle(_canAddData); + _canAddData = nullptr; + } +} + +bool DirectSoundDriver::DSoundInitialize() +{ + _lpDS = nullptr; + _lpDSB = nullptr; + _lpDSBS = nullptr; + _lpDSN = nullptr; + + for (unsigned int i = 0; i < 3; i++) + { + _notifications[i] = nullptr; + } + + _dataAvailable = nullptr; + _canAddData = nullptr; + _thread = nullptr; + + HRESULT directSoundCreateResult = DirectSoundCreate(nullptr, &_lpDS, nullptr); + if (directSoundCreateResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundInitialize(): DirectSoundCreate - ", directSoundCreateResult); + return false; + } + + for (unsigned int i = 0; i < 3; i++) + { + _notifications[i] = CreateEvent(nullptr, 0, 0, nullptr); + } + + _dataAvailable = CreateEvent(nullptr, 0, 0, nullptr); + _canAddData = CreateEvent(nullptr, 0, 0, nullptr); + + return true; +} + +void DirectSoundDriver::AddMode(bool isStereo, bool is16Bits, uint32_t rate) +{ + auto mode = new DirectSoundMode(); + mode->Rate = rate; + mode->Is16Bits = is16Bits; + mode->IsStereo = isStereo; + mode->BufferSampleCount = 0; + mode->BufferBlockAlign = 0; + _modes.emplace_back(mode); +} + +const DirectSoundMode *DirectSoundDriver::FindMode(bool isStereo, bool is16Bits, uint32_t rate) const +{ + for (const auto *mode : _modes) + { + if (mode->Rate == rate && mode->Is16Bits == is16Bits && mode->IsStereo == isStereo) + { + return mode; + } + } + + return nullptr; +} + +void DirectSoundDriver::DSoundModeInformationRelease() +{ + for (const auto *mode : _modes) + { + delete mode; + } + _modes.clear(); +} + +void DirectSoundDriver::YesNoLog(const char *description, bool predicate) +{ + Service->Log.AddLog(description); + Service->Log.AddLog(predicate ? " - Yes\n" : " - No\n"); +} + +bool DirectSoundDriver::DSoundModeInformationInitialize() +{ + DSCAPS dscaps = {}; + dscaps.dwSize = sizeof(dscaps); + HRESULT getCapsResult = IDirectSound_GetCaps(_lpDS, &dscaps); + if (getCapsResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundModeInformationInitialize(): ", getCapsResult); + return false; + } + + bool supportsStereo = !!(dscaps.dwFlags & DSCAPS_PRIMARYSTEREO); + YesNoLog("DSCAPS_PRIMARYSTEREO", supportsStereo); + bool supportsMono = !!(dscaps.dwFlags & DSCAPS_PRIMARYMONO); + YesNoLog("DSCAPS_PRIMARYMONO", supportsMono); + bool supports16Bits = !!(dscaps.dwFlags & DSCAPS_PRIMARY16BIT); + YesNoLog("DSCAPS_PRIMARY16BIT", supports16Bits); + bool supports8Bits = !!(dscaps.dwFlags & DSCAPS_PRIMARY8BIT); + YesNoLog("DSCAPS_PRIMARY8BIT", supports8Bits); + + bool secondaryStereo = !!(dscaps.dwFlags & DSCAPS_SECONDARYSTEREO); + YesNoLog("DSCAPS_SECONDARYSTEREO", secondaryStereo); + bool secondaryMono = !!(dscaps.dwFlags & DSCAPS_SECONDARYMONO); + YesNoLog("DSCAPS_SECONDARYMONO", secondaryMono); + bool secondary16Bits = !!(dscaps.dwFlags & DSCAPS_SECONDARY16BIT); + YesNoLog("DSCAPS_SECONDARY16BIT", secondary16Bits); + bool secondary8Bits = !!(dscaps.dwFlags & DSCAPS_SECONDARY8BIT); + YesNoLog("DSCAPS_SECONDARY8BIT", secondary8Bits); + + bool supportsContinuousRate = !!(dscaps.dwFlags & DSCAPS_CONTINUOUSRATE); + YesNoLog("DSCAPS_CONTINUOUSRATE", supportsContinuousRate); + bool isEmulatedDriver = !!(dscaps.dwFlags & DSCAPS_EMULDRIVER); + YesNoLog("DSCAPS_EMULDRIVER", isEmulatedDriver); + bool isCertifiedDriver = !!(dscaps.dwFlags & DSCAPS_CERTIFIED); + YesNoLog("DSCAPS_CERTIFIED", isCertifiedDriver); + + uint32_t minrate = dscaps.dwMinSecondarySampleRate; + uint32_t maxrate = dscaps.dwMaxSecondarySampleRate; + Service->Log.AddLog("ddscaps.dwMinSecondarySampleRate - %u\n", minrate); + Service->Log.AddLog("ddscaps.dwMaxSecondarySampleRate - %u\n", maxrate); + + if (supportsStereo) + { + if (supports16Bits) + { + AddMode(true, true, 15650); + AddMode(true, true, 22050); + AddMode(true, true, 31300); + AddMode(true, true, 44100); + } + if (supports8Bits) + { + AddMode(true, false, 15650); + AddMode(true, false, 22050); + AddMode(true, false, 31300); + AddMode(true, false, 44100); + } + } + if (supportsMono) + { + if (supports16Bits) + { + AddMode(false, true, 15650); + AddMode(false, true, 22050); + AddMode(false, true, 31300); + AddMode(false, true, 44100); + } + if (supports8Bits) + { + AddMode(false, false, 15650); + AddMode(false, false, 22050); + AddMode(false, false, 31300); + AddMode(false, false, 44100); + } + } + + return true; +} + +/** Configure volume of secondary DirectSound buffer of current sound device. + * + * Loudness is perceived in a logarithmic manner; the calculation attempts + * to utilize the upper half of the available spectrum quadratically, so + * that the perceived volume when moving the slider along feels more natural + * the numbers may still need some fine-tuning + * @param[in] volume the target volume in the range of 0 to 100 (100 being + full volume) + * @return TRUE is successful, FALSE otherwise. + */ +bool DirectSoundDriver::DSoundSetVolume(const int volume) +{ + HRESULT hResult; + LONG vol; + + if (volume <= 100 && volume > 0) + vol = (LONG) - ((50 - (volume / 2)) * (50 - (volume / 2))); + else if (volume == 0) + vol = DSBVOLUME_MIN; + else + vol = DSBVOLUME_MAX; + +#ifdef _DEBUG + Service->Log.AddLog("DirectSoundDriver::DSoundSetVolume(): volume %d scaled to %d, setting volume...\n", volume, vol); +#endif + + hResult = IDirectSoundBuffer_SetVolume(_lpDSBS, vol); + if (FAILED(hResult)) DSoundFailure("DirectSoundDriver::DSoundSetVolume(): SetVolume() failed: ", hResult); + + return (hResult == DS_OK); +} + +bool DirectSoundDriver::SetCurrentSoundDeviceVolume(int volume) +{ + return DSoundSetVolume(volume); +} + +bool DirectSoundDriver::DSoundSetCooperativeLevel() +{ + // We need the HWND of the amiga emulation window, which means sound must be initialized after the gfx stuff + + HWND hwnd = gfxDrvCommon->GetHWND(); + HRESULT setCooperativeLevelResult = IDirectSound_SetCooperativeLevel(_lpDS, hwnd, DSSCL_PRIORITY); + if (setCooperativeLevelResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundSetCooperativeLevel()", setCooperativeLevelResult); + } + + return (setCooperativeLevelResult == DS_OK); +} + +void DirectSoundDriver::DSoundPrimaryBufferRelease() +{ + if (_lpDSB != nullptr) + { + IDirectSoundBuffer_Play(_lpDSB, 0, 0, 0); + IDirectSoundBuffer_Release(_lpDSB); + _lpDSB = nullptr; + } +} + +//====================================================================== +// Get a primary buffer +// We always make a primary buffer, in the same format as the sound data +// we are going to receive from the sound emulation routines. +// If it fails, we don't play sound. +//====================================================================== + +bool DirectSoundDriver::DSoundPrimaryBufferInitialize() +{ + DSBUFFERDESC dsbdesc{}; + WAVEFORMATEX wfm{}; + + dsbdesc.dwSize = sizeof(dsbdesc); + dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; + dsbdesc.dwBufferBytes = 0; + dsbdesc.lpwfxFormat = nullptr; + + wfm.wFormatTag = WAVE_FORMAT_PCM; + wfm.nChannels = (_modeCurrent.IsStereo) ? 2 : 1; + wfm.nSamplesPerSec = _modeCurrent.Rate; + wfm.wBitsPerSample = (_modeCurrent.Is16Bits) ? 16 : 8; + wfm.nBlockAlign = (wfm.wBitsPerSample / 8) * wfm.nChannels; + wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; + _modeCurrent.BufferBlockAlign = wfm.nBlockAlign; + + HRESULT createSoundBufferResult = IDirectSound_CreateSoundBuffer(_lpDS, &dsbdesc, &_lpDSB, NULL); + if (createSoundBufferResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundPrimaryBufferInitialize(): CreateSoundBuffer(), ", createSoundBufferResult); + return false; + } + + HRESULT setFormatResult = IDirectSoundBuffer_SetFormat(_lpDSB, &wfm); + if (setFormatResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundPrimaryBufferInitialize(): SetFormat(), ", setFormatResult); + DSoundPrimaryBufferRelease(); + return false; + } + + return true; +} + +void DirectSoundDriver::DSoundSecondaryBufferRelease() +{ + if (_lpDSBS != nullptr) + { + IDirectSoundBuffer_Play(_lpDSBS, 0, 0, 0); + IDirectSoundBuffer_Release(_lpDSBS); + _lpDSBS = nullptr; + } + + if (_lpDSN != nullptr) + { + IDirectSoundNotify_Release(_lpDSN); + _lpDSN = nullptr; + } + + if (!_notificationSupported) + { + timeKillEvent(_mmTimer); + timeEndPeriod(_mmResolution); + } +} + +bool DirectSoundDriver::CreateSecondaryBuffer() +{ + WAVEFORMATEX wfm{}; + DSBUFFERDESC dsbdesc{}; + + wfm.wFormatTag = WAVE_FORMAT_PCM; + wfm.nChannels = (_modeCurrent.IsStereo) ? 2 : 1; + wfm.nSamplesPerSec = _modeCurrent.Rate; + wfm.wBitsPerSample = (_modeCurrent.Is16Bits) ? 16 : 8; + wfm.nBlockAlign = (wfm.wBitsPerSample / 8) * wfm.nChannels; + wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; + + dsbdesc.dwSize = sizeof(dsbdesc); + dsbdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLVOLUME; + dsbdesc.dwBufferBytes = _modeCurrent.BufferSampleCount * wfm.nBlockAlign * 2; + dsbdesc.lpwfxFormat = &wfm; + + HRESULT createSoundBufferResult = IDirectSound_CreateSoundBuffer(_lpDS, &dsbdesc, &_lpDSBS, NULL); + if (createSoundBufferResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::CreateSecondaryBuffer: CreateSoundBuffer(), ", createSoundBufferResult); + return false; + } + + return true; +} + +bool DirectSoundDriver::ClearSecondaryBuffer() +{ + char *lpAudio; + DWORD dwBytes; + + HRESULT lock1Result = IDirectSoundBuffer_Lock( + _lpDSBS, + 0, + 0, // Ignored because we pass DSBLOCK_ENTIREBUFFER + (LPVOID *)&lpAudio, + &dwBytes, + NULL, + NULL, + DSBLOCK_ENTIREBUFFER); + + if (lock1Result != DS_OK) + { + DSoundFailure("DirectSoundDriver::ClearSecondaryBuffer: Lock(), ", lock1Result); + + if (lock1Result == DSERR_BUFFERLOST) + { + // Buffer lost. Try to restore buffer once. Multiple restores need more intelligence + HRESULT restoreResult = IDirectSoundBuffer_Restore(_lpDSBS); + if (restoreResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::ClearSecondaryBuffer: Restore(), ", restoreResult); + return false; + } + + HRESULT lock2Result = IDirectSoundBuffer_Lock( + _lpDSBS, + 0, + 0, // Ignored because we pass DSBLOCK_ENTIREBUFFER + (LPVOID *)&lpAudio, + &dwBytes, + NULL, + NULL, + DSBLOCK_ENTIREBUFFER); + if (lock2Result != DS_OK) + { + // Here we give up + DSoundFailure("DirectSoundDriver::ClearSecondaryBuffer: Lock(), ", lock2Result); + return false; + } + } + } + + for (DWORD i = 0; i < dwBytes; i++) + { + lpAudio[i] = 0; + } + + HRESULT unlockResult = IDirectSoundBuffer_Unlock(_lpDSBS, lpAudio, dwBytes, NULL, 0); + if (unlockResult != DS_OK) + { + // Here we give up + DSoundFailure("DirectSoundDriver::ClearSecondaryBuffer: Unlock(), ", unlockResult); + return false; + } + + return true; +} + +bool DirectSoundDriver::InitializeSecondaryBufferNotification() +{ + DSBCAPS dsbcaps = {}; + dsbcaps.dwSize = sizeof(dsbcaps); + + HRESULT getCapsResult = IDirectSoundBuffer_GetCaps(_lpDSBS, &dsbcaps); + if (getCapsResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::InitializeSecondaryBufferNotification(): GetCaps(), ", getCapsResult); + return false; + } + + _notificationSupported = _runtimeConfiguration.NotificationMode == sound_notifications::SOUND_DSOUND_NOTIFICATION && !!(dsbcaps.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY); + + if (_notificationSupported) + { + DSBPOSITIONNOTIFY rgdscbpn[2]; + + // Notification supported AND selected + // Get notification interface + + HRESULT queryInterfaceResult = IDirectSoundBuffer_QueryInterface(_lpDSBS, IID_IDirectSoundNotify, (LPVOID * FAR) & _lpDSN); + if (queryInterfaceResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::InitializeSecondaryBufferNotification(): QueryInterface(IID_IDirectSoundNotify), ", queryInterfaceResult); + return false; + } + + // Attach notification objects to buffer + + rgdscbpn[0].dwOffset = _modeCurrent.BufferBlockAlign * (_modeCurrent.BufferSampleCount - 1); + rgdscbpn[0].hEventNotify = _notifications[0]; + rgdscbpn[1].dwOffset = _modeCurrent.BufferBlockAlign * (_modeCurrent.BufferSampleCount * 2 - 1); + rgdscbpn[1].hEventNotify = _notifications[1]; + + HRESULT setNotificationPositionsResult = IDirectSoundNotify_SetNotificationPositions(_lpDSN, 2, rgdscbpn); + if (setNotificationPositionsResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::InitializeSecondaryBufferNotification(): SetNotificationPositions(), ", setNotificationPositionsResult); + return false; + } + } + else + { + // Notification not supported, fallback to timer + + char s[80]; + TIMECAPS timecaps; + + MMRESULT timeGetDevCapsResult = timeGetDevCaps(&timecaps, sizeof(TIMECAPS)); + if (timeGetDevCapsResult != TIMERR_NOERROR) + { + Service->Log.AddLog("DirectSoundDriver::InitializeSecondaryBufferNotification(): timeGetDevCaps() failed\n"); + return false; + } + + sprintf(s, "timeGetDevCaps: min: %u, max %u\n", timecaps.wPeriodMin, timecaps.wPeriodMax); + Service->Log.AddLog(s); + + _mmResolution = timecaps.wPeriodMin; + + MMRESULT timeBeginPeriodResult = timeBeginPeriod(_mmResolution); + if (timeBeginPeriodResult != TIMERR_NOERROR) + { + Service->Log.AddLog("DirectSoundDriver::InitializeSecondaryBufferNotification(): timeBeginPeriod() failed\n"); + return false; + } + + MMRESULT timeSetEventResult = timeSetEvent(1, 0, DirectSoundDriver::timercb, (DWORD_PTR)this, (UINT)TIME_PERIODIC); + if (timeSetEventResult == 0) + { + Service->Log.AddLog("DirectSoundDriver::InitializeSecondaryBufferNotification(): timeSetEvent() failed\n"); + return false; + } + _mmTimer = timeSetEventResult; + } + return true; +} + +bool DirectSoundDriver::DSoundSecondaryBufferInitialize() +{ + if (!CreateSecondaryBuffer()) + { + return false; + } + + if (!ClearSecondaryBuffer()) + { + DSoundSecondaryBufferRelease(); + return false; + } + + if (!InitializeSecondaryBufferNotification()) + { + DSoundSecondaryBufferRelease(); + return false; + } + + DSoundSetVolume(_runtimeConfiguration.Volume); + + return true; +} + +void DirectSoundDriver::DSoundPlaybackStop() +{ + DSoundSecondaryBufferRelease(); + DSoundPrimaryBufferRelease(); +} + +bool DirectSoundDriver::DSoundPlaybackInitialize() +{ + _lastReadPosition = 0; + bool result = DSoundPrimaryBufferInitialize(); + if (result) + { + result = DSoundSecondaryBufferInitialize(); + } + + if (!result) + { + Service->Log.AddLog("Sound, secondary failed\n"); + DSoundPrimaryBufferRelease(); + } + + if (result) + { + HRESULT primaryPlayResult = IDirectSoundBuffer_Play(_lpDSB, 0, 0, DSBPLAY_LOOPING); + if (primaryPlayResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundPlaybackInitialize(): Primary->Play(), ", primaryPlayResult); + } + + HRESULT secondaryPlayResult = IDirectSoundBuffer_Play(_lpDSBS, 0, 0, DSBPLAY_LOOPING); + if (secondaryPlayResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundPlaybackInitialize(): Secondary->Play(), ", secondaryPlayResult); + } + } + + return result; +} + +void DirectSoundDriver::Copy16BitsStereo(uint16_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount) +{ + for (unsigned int i = 0; i < sampleCount; i++) + { + *audioBuffer++ = *left++; + *audioBuffer++ = *right++; + } +} + +void DirectSoundDriver::Copy16BitsMono(uint16_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount) +{ + for (unsigned int i = 0; i < sampleCount; i++) + { + *audioBuffer++ = (*left++ + *right++); + } +} + +void DirectSoundDriver::Copy8BitsStereo(uint8_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount) +{ + for (unsigned int i = 0; i < sampleCount; i++) + { + *audioBuffer++ = ((*left++) >> 8) + 128; + *audioBuffer++ = ((*right++) >> 8) + 128; + } +} + +void DirectSoundDriver::Copy8BitsMono(uint8_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount) +{ + for (unsigned int i = 0; i < sampleCount; i++) + { + *audioBuffer++ = (((*left++) + (*right++)) >> 8) + 128; + } +} + +bool DirectSoundDriver::DSoundCopyToBuffer(uint16_t *left, uint16_t *right, uint32_t sampleCount, uint32_t bufferHalf) +{ + LPVOID lpvAudio; + DWORD dwBytes; + DWORD size = _modeCurrent.BufferSampleCount * _modeCurrent.BufferBlockAlign; + DWORD startOffset = bufferHalf * size; + + HRESULT lockResult = IDirectSoundBuffer_Lock(_lpDSBS, startOffset, size, &lpvAudio, &dwBytes, NULL, NULL, 0); + + if (lockResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundCopyToBuffer(): Lock(), ", lockResult); + return false; + } + + if (lockResult == DSERR_BUFFERLOST) + { + // Buffer lost. Try to restore buffer once. Multiple restores need more intelligence + HRESULT restoreResult = IDirectSoundBuffer_Restore(_lpDSBS); + if (restoreResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundCopyToBuffer(): Restore(), ", restoreResult); + return false; + } + HRESULT lock2Result = IDirectSoundBuffer_Lock(_lpDSBS, startOffset, size, &lpvAudio, &dwBytes, NULL, NULL, 0); + if (lock2Result != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundCopyToBuffer(): Lock() after Restore , ", lock2Result); + return false; + } + } + + if (_runtimeConfiguration.IsStereo) + { + if (_runtimeConfiguration.Is16Bits) + { + Copy16BitsStereo((uint16_t *)lpvAudio, left, right, sampleCount); + } + else + { + Copy8BitsStereo((uint8_t *)lpvAudio, left, right, sampleCount); + } + } + else + { + if (_runtimeConfiguration.Is16Bits) + { + Copy16BitsMono((uint16_t *)lpvAudio, left, right, sampleCount); + } + else + { + Copy8BitsMono((uint8_t *)lpvAudio, left, right, sampleCount); + } + } + + HRESULT unlockResult = IDirectSoundBuffer_Unlock(_lpDSBS, lpvAudio, dwBytes, NULL, 0); + if (unlockResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::DSoundCopyToBuffer(): Unlock(), ", unlockResult); + return false; + } + + return true; +} + +void DirectSoundDriver::Play(int16_t *left, int16_t *right, uint32_t sampleCount) +{ + WaitForSingleObject(_canAddData, INFINITE); + _pendingDataLeft = (uint16_t *)left; + _pendingDataRight = (uint16_t *)right; + _pendingDataSampleCount = sampleCount; + ResetEvent(_canAddData); + SetEvent(_dataAvailable); +} + +void DirectSoundDriver::AcquireSoundMutex() +{ + WaitForSingleObject(_mutex, INFINITE); +} + +void DirectSoundDriver::ReleaseSoundMutex() +{ + ReleaseMutex(_mutex); +} + +bool DirectSoundDriver::WaitForData(uint32_t nextBufferNo, bool &needToRestartPlayback) +{ + HANDLE multiEvents[3]; + bool terminateWait = false; + bool terminateThread = false; + uint32_t numberOfEventsInWait = 3; + + // No-wait test for data_available, return TRUE if data is available + if (WaitForSingleObject(_dataAvailable, 0) == WAIT_OBJECT_0) + { + return true; + } + + // Here, data is not available from the sound emulation + // And we have played past the end of the buffer we want to copy data to + // We can continue to play until the end of the next buffer, but then we + // must stop playback, since there is no more data to play + // So we set up a multiple object wait which trigger on the following + // conditions: + // 0 - Data becomes available, return TRUE, playback is not stopped + // 1 - End of the thread is signaled, return FALSE to indicate termination + // 2 - The end of the next buffer is reached, stop playback, has no data,yet + // Redo the wait, this time without the event for end of the next buffer + + // What if we are lagging behind already? + + while (!terminateWait) + { + multiEvents[0] = _dataAvailable; + multiEvents[1] = _notifications[2]; + if (numberOfEventsInWait == 3) + { + multiEvents[2] = _notifications[nextBufferNo]; + } + DWORD evt = WaitForMultipleObjects(numberOfEventsInWait, (void *const *)multiEvents, FALSE, INFINITE); + switch (evt) + { + case WAIT_OBJECT_0: + // Data is now available + // Restart playing if we have stopped it + needToRestartPlayback = (numberOfEventsInWait == 2); + terminateWait = true; + break; + case WAIT_OBJECT_0 + 1: + // End of thread requested, return FALSE + terminateWait = true; + terminateThread = true; + break; + case WAIT_OBJECT_0 + 2: + // End of next buffer reached, stop playback, wait more + HRESULT playResult = IDirectSoundBuffer_Play(_lpDSBS, 0, 0, 0); + if (playResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::WaitForData(): Play(), ", playResult); + } + numberOfEventsInWait = 2; + break; + } + } + return !terminateThread; +} + +void DirectSoundDriver::PollBufferPosition() +{ + AcquireSoundMutex(); + if (_runtimeConfiguration.PlaybackMode == sound_emulations::SOUND_PLAY && !_notificationSupported) + { + DWORD readpos, writepos; + DWORD halfway = (_modeCurrent.BufferSampleCount * _modeCurrent.BufferBlockAlign); + + if (_lpDSBS != nullptr) + { + HRESULT getCurrentPositionResult = IDirectSoundBuffer_GetCurrentPosition(_lpDSBS, &readpos, &writepos); + if (getCurrentPositionResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::PollBufferPosition(): GetCurrentPosition(), ", getCurrentPositionResult); + } + + if ((readpos >= halfway) && (_lastReadPosition < halfway)) + { + SetEvent(_notifications[0]); + } + else if ((readpos < halfway) && (_lastReadPosition >= halfway)) + { + SetEvent(_notifications[1]); + } + + _lastReadPosition = readpos; + } + } + + ReleaseSoundMutex(); +} + +bool DirectSoundDriver::ProcessEndOfBuffer(uint32_t currentBufferNo, uint32_t nextBufferNo) +{ + bool terminateThread = false; + bool needToRestartPlayback = false; + if (WaitForData(nextBufferNo, needToRestartPlayback)) + { + DSoundCopyToBuffer(_pendingDataLeft, _pendingDataRight, _pendingDataSampleCount, currentBufferNo); + if (needToRestartPlayback) + { + HRESULT playResult = IDirectSoundBuffer_Play(_lpDSBS, 0, 0, DSBPLAY_LOOPING); + + if (playResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::ProcessEndOfBuffer(): Play(), ", playResult); + } + + if (playResult == DSERR_BUFFERLOST) + { + /* Temporary fix for restoring buffer once. Multiple restore needs alot more */ + HRESULT restoreResult = IDirectSoundBuffer_Restore(_lpDSBS); + if (restoreResult != DS_OK) + { + DSoundFailure("DirectSoundDriver::ProcessEndOfBuffer(): Restore(), ", restoreResult); + } + else + { + HRESULT play2Result = IDirectSoundBuffer_Play(_lpDSBS, 0, 0, DSBPLAY_LOOPING); + if (play2Result != DS_OK) + { + DSoundFailure("DirectSoundDriver::ProcessEndOfBuffer(): Play() after restore, ", play2Result); + } + } + } + } + + // If the next buffer also triggered during WaitForData() + // it will end multiple object wait immediately, since we don't reset it + ResetEvent(_dataAvailable); + SetEvent(_canAddData); + ResetEvent(_notifications[currentBufferNo]); + } + else + { + terminateThread = true; + } + + return terminateThread; +} + +DWORD WINAPI DirectSoundDriver::ThreadProc(void *in) +{ + return ((DirectSoundDriver *)in)->HandleThreadProc(); +} + +DWORD DirectSoundDriver::HandleThreadProc() +{ + bool terminateThread = false; + + winDrvSetThreadName(-1, "DirectSoundDriver::ThreadProc()"); + + while (!terminateThread) + { + // Thread is activated by 3 different events: + // 0 - Play position is at end of buffer 0 + // 1 - Play position is at end of buffer 1 + // 2 - Thread must terminate (triggered in EmulationStop()) + DWORD dwEvt = WaitForMultipleObjects(3, (void *const *)(_notifications), FALSE, INFINITE); + + switch (dwEvt) + { + case WAIT_OBJECT_0 + 0: /* End of first buffer */ + // Wait for data_available event to become signaled + // or FALSE is returned if (2) becomes signaled (end thread) + terminateThread = ProcessEndOfBuffer(0, 1); + break; + case WAIT_OBJECT_0 + 1: /* End of first buffer */ + // Wait for data_available event to become signaled + // or FALSE is returned if (2) becomes signaled (end thread) + terminateThread = ProcessEndOfBuffer(1, 0); + break; + case WAIT_OBJECT_0 + 2: /* Emulation is ending */ + default: terminateThread = true; break; + } + } + + return 0; +} + +void DirectSoundDriver::HardReset() +{ +} + +bool DirectSoundDriver::EmulationStart(SoundDriverRuntimeConfiguration runtimeConfiguration) +{ + _runtimeConfiguration = runtimeConfiguration; + + AcquireSoundMutex(); + + // Set all events to their initial state + + for (unsigned int i = 0; i < 3; i++) + { + ResetEvent(_notifications[i]); + } + + ResetEvent(_dataAvailable); + SetEvent(_canAddData); + + // Check if the driver can support the requested sound quality + + auto currentMode = FindMode(_runtimeConfiguration.IsStereo, _runtimeConfiguration.Is16Bits, _runtimeConfiguration.ActualSampleRate); + bool result = currentMode != nullptr; + if (result) + { + _modeCurrent = *currentMode; + _modeCurrent.BufferSampleCount = _runtimeConfiguration.MaximumBufferSampleCount; + } + + // Record the number of samples in our buffer (ie. one half of the size) + + if (result) + { + result = DSoundSetCooperativeLevel(); + } + + // Create the needed buffer(s) + + if (result) + { + result = DSoundPlaybackInitialize(); + } + + // Start playback thread + + if (result) + { + _thread = CreateThread( + nullptr, // Security attr + 0, // Stack Size + ThreadProc, // Thread procedure + this, // Thread parameter + 0, // Creation flags + &_threadId); // ThreadId + + result = _thread != nullptr; + } + + // In case of failure, we undo any stuff we've done so far + + if (!result) + { + Service->Log.AddLog("Failed to start sound\n"); + DSoundPlaybackStop(); + } + + ReleaseSoundMutex(); + return result; +} + +void DirectSoundDriver::EmulationStop() +{ + AcquireSoundMutex(); + SetEvent(_notifications[2]); + WaitForSingleObject(_thread, INFINITE); + CloseHandle(_thread); + _thread = nullptr; + DSoundPlaybackStop(); + ReleaseSoundMutex(); +} + +bool DirectSoundDriver::IsInitialized() +{ + return _isInitialized; +} + +DirectSoundDriver::DirectSoundDriver() : ISoundDriver() +{ + _isInitialized = DSoundInitialize(); + if (!_isInitialized) + { + return; + } + + _isInitialized = DSoundModeInformationInitialize(); + if (!_isInitialized) + { + DSoundRelease(); + return; + } + + _mutex = CreateMutex(nullptr, 0, nullptr); + _isInitialized = _mutex != nullptr; + if (!_isInitialized) + { + DSoundModeInformationRelease(); + DSoundRelease(); + } +} + +DirectSoundDriver::~DirectSoundDriver() +{ + DSoundModeInformationRelease(); + DSoundRelease(); + + if (_mutex != nullptr) + { + CloseHandle(_mutex); + _mutex = nullptr; + } +} diff --git a/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundDriver.h b/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundDriver.h new file mode 100644 index 00000000..4255e174 --- /dev/null +++ b/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundDriver.h @@ -0,0 +1,86 @@ +#pragma once + +#include +#include +#include "Driver/ISoundDriver.h" +#include "DirectSoundMode.h" + +class DirectSoundDriver : public ISoundDriver +{ +private: + SoundDriverRuntimeConfiguration _runtimeConfiguration; + + LPDIRECTSOUND _lpDS; + LPDIRECTSOUNDBUFFER _lpDSB; // Primary buffer + LPDIRECTSOUNDBUFFER _lpDSBS; // Secondary buffer + LPDIRECTSOUNDNOTIFY _lpDSN; // Notificaton object + + std::list _modes; + DirectSoundMode _modeCurrent; + + HANDLE _notifications[3]; + HANDLE _dataAvailable; + HANDLE _canAddData; + HANDLE _mutex; + uint16_t *_pendingDataLeft; + uint16_t *_pendingDataRight; + uint32_t _pendingDataSampleCount; + HANDLE _thread; + DWORD _threadId; + bool _notificationSupported; + uint32_t _mmTimer; + uint32_t _mmResolution; + DWORD _lastReadPosition; + + bool _isInitialized = false; + + static void CALLBACK timercb(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2); + void HandleTimerCallback(); + const char *DSoundErrorString(HRESULT hResult); + void DSoundFailure(const char *header, HRESULT errorCode); + void DSoundRelease(); + bool DSoundInitialize(); + + bool DSoundModeInformationInitialize(); + void DSoundModeInformationRelease(); + void AddMode(bool isStereo, bool is16Bits, uint32_t rate); + const DirectSoundMode *FindMode(bool isStereo, bool is16Bits, uint32_t rate) const; + + void YesNoLog(const char *description, bool predicate); + bool DSoundSetVolume(const int volume); + bool DSoundSetCooperativeLevel(); + void DSoundPrimaryBufferRelease(); + bool DSoundPrimaryBufferInitialize(); + void DSoundSecondaryBufferRelease(); + bool CreateSecondaryBuffer(); + bool ClearSecondaryBuffer(); + bool InitializeSecondaryBufferNotification(); + bool DSoundSecondaryBufferInitialize(); + void DSoundPlaybackStop(); + bool DSoundPlaybackInitialize(); + void Copy16BitsStereo(uint16_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount); + void Copy16BitsMono(uint16_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount); + void Copy8BitsStereo(uint8_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount); + void Copy8BitsMono(uint8_t *audioBuffer, uint16_t *left, uint16_t *right, uint32_t sampleCount); + bool DSoundCopyToBuffer(uint16_t *left, uint16_t *right, uint32_t sampleCount, uint32_t bufferHalf); + void AcquireSoundMutex(); + void ReleaseSoundMutex(); + bool WaitForData(uint32_t nextBufferNo, bool &needToRestartPlayback); + bool ProcessEndOfBuffer(uint32_t currentBufferNo, uint32_t nextBufferNo); + static DWORD WINAPI ThreadProc(void *in); + DWORD HandleThreadProc(); + +public: + void Play(int16_t *leftBuffer, int16_t *rightBuffer, uint32_t sampleCount) override; + void PollBufferPosition() override; + bool SetCurrentSoundDeviceVolume(int volume) override; + + void HardReset(); + bool EmulationStart(SoundDriverRuntimeConfiguration runtimeConfiguration) override; + void EmulationStop() override; + + bool IsInitialized() override; + + DirectSoundDriver(); + virtual ~DirectSoundDriver(); +}; \ No newline at end of file diff --git a/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundMode.h b/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundMode.h new file mode 100644 index 00000000..81d30600 --- /dev/null +++ b/fellow/SRC/WinFellow/Windows/Driver/Sound/DirectSoundMode.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +struct DirectSoundMode +{ + uint32_t Rate; + bool Is16Bits; + bool IsStereo; + uint32_t BufferSampleCount; + uint32_t BufferBlockAlign; +}; diff --git a/fellow/SRC/WinFellow/Windows/GfxDrvCommon.cpp b/fellow/SRC/WinFellow/Windows/GfxDrvCommon.cpp index 252ad83f..28786b7b 100644 --- a/fellow/SRC/WinFellow/Windows/GfxDrvCommon.cpp +++ b/fellow/SRC/WinFellow/Windows/GfxDrvCommon.cpp @@ -7,13 +7,13 @@ #include "gui_general.h" #include "GFXDRV.H" -#include "SOUND.H" -#include "SOUNDDRV.H" #include "MOUSEDRV.H" #include "JOYDRV.H" #include "KBDDRV.H" #include "TIMER.H" +#include "VirtualHost/Core.h" + #ifdef RETRO_PLATFORM #include "RetroPlatform.h" #include "config.h" @@ -143,12 +143,11 @@ void GfxDrvCommon::RunEventWait() void GfxDrvCommon::EvaluateRunEventStatus() { - _win_active = (_win_active_original && - !_win_minimized_original && - !_syskey_down); - + _win_active = (_win_active_original && !_win_minimized_original && !_syskey_down); + #ifdef RETRO_PLATFORM - if (!RP.GetHeadlessMode()) { + if (!RP.GetHeadlessMode()) + { #endif if (_win_active) { @@ -156,10 +155,9 @@ void GfxDrvCommon::EvaluateRunEventStatus() } else { - if (_pause_emulation_when_window_loses_focus) - RunEventReset(); + if (_pause_emulation_when_window_loses_focus) RunEventReset(); } - + gfxDrvNotifyActiveStatus(_win_active); #ifdef RETRO_PLATFORM } @@ -169,7 +167,7 @@ void GfxDrvCommon::EvaluateRunEventStatus() void GfxDrvCommon::NotifyDirectInputDevicesAboutActiveState(bool active) { mouseDrvStateHasChanged(active); - + #ifdef RETRO_PLATFORM #ifdef FELLOW_SUPPORT_RP_API_VERSION_71 if (!RP.GetHeadlessMode()) @@ -185,7 +183,7 @@ void GfxDrvCommon::NotifyDirectInputDevicesAboutActiveState(bool active) #endif } -#define WM_DIACQUIRE (WM_USER + 0) +#define WM_DIACQUIRE (WM_USER + 0) LRESULT FAR PASCAL EmulationWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -194,10 +192,10 @@ LRESULT FAR PASCAL EmulationWindowProc(HWND hWnd, UINT message, WPARAM wParam, L /***********************************************************************/ /** -* Window procedure for the emulation window. -* -* Distributes events to mouse and keyboard drivers as well. -***************************************************************************/ + * Window procedure for the emulation window. + * + * Distributes events to mouse and keyboard drivers as well. + ***************************************************************************/ LRESULT GfxDrvCommon::EmulationWindowProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -206,206 +204,189 @@ LRESULT GfxDrvCommon::EmulationWindowProcedure(HWND hWnd, UINT message, WPARAM w #ifdef GFXDRV_DEBUG_WINDOW_MESSAGES switch (message) { - case WM_SETFONT: - case WM_ACTIVATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ACTIVATE"); break; - case WM_ACTIVATEAPP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ACTIVATEAPP"); break; - case WM_CHAR: fellowAddLog("EmulationWindowProc got message %s\n", "WM_CHAR"); break; - case WM_CREATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_CREATE"); break; - case WM_CLOSE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_CLOSE"); break; - case WM_DESTROY: fellowAddLog("EmulationWindowProc got message %s\n", "WM_DESTROY"); break; - case WM_ENABLE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ENABLE"); break; - case WM_ERASEBKGND: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ERASEBKGND"); break; - case WM_GETICON: fellowAddLog("EmulationWindowProc got message %s\n", "WM_GETICON"); break; - case WM_GETMINMAXINFO: fellowAddLog("EmulationWindowProc got message %s\n", "WM_GETMINMAXINFO"); break; - case WM_IME_NOTIFY: fellowAddLog("EmulationWindowProc got message %s\n", "WM_IME_NOTIFY"); break; - case WM_IME_SETCONTEXT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_IME_SETCONTEXT"); break; - case WM_KEYDOWN: fellowAddLog("EmulationWindowProc got message %s\n", "WM_KEYDOWN"); break; - case WM_KEYUP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_KEYUP"); break; - case WM_KILLFOCUS: fellowAddLog("EmulationWindowProc got message %s\n", "WM_KILLFOCUS"); break; - case WM_LBUTTONDBLCLK: fellowAddLog("EmulationWindowProc got message %s\n", "WM_LBUTTONDBLCLK"); break; - case WM_LBUTTONDOWN: fellowAddLog("EmulationWindowProc got message %s\n", "WM_LBUTTONDOWN"); break; - case WM_LBUTTONUP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_LBUTTONUP"); break; - case WM_MOVE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_MOVE"); break; - case WM_MOUSEACTIVATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_MOUSEACTIVATE"); break; - case WM_MOUSEMOVE: /*fellowAddLog("EmulationWindowProc got message %s\n", "WM_MOUSEMOVE");*/ break; - case WM_NCPAINT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCPAINT"); break; - case WM_NCACTIVATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCACTIVATE"); break; - case WM_NCCALCSIZE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCCALCSIZE"); break; - case WM_NCCREATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCCREATE"); break; - case WM_NCDESTROY: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCDESTROY"); break; - case WM_PAINT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_PAINT"); break; - case WM_SETCURSOR: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SETCURSOR"); break; - case WM_SETFOCUS: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SETFOCUS"); break; - case WM_SIZE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SIZE"); break; - case WM_SHOWWINDOW: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SHOWWINDOW"); break; - case WM_SYNCPAINT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYNCPAINT"); break; - case WM_SYSCOMMAND: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYSCOMMAND"); break; - case WM_SYSKEYDOWN: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYSKEYDOWN"); break; - case WM_SYSKEYUP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYSKEYUP"); break; - case WM_TIMER: /*fellowAddLog("EmulationWindowProc got message %s\n", "WM_TIMER");*/ break; - case WM_WINDOWPOSCHANGING: fellowAddLog("EmulationWindowProc got message %s\n", "WM_WINDOWPOSCHANGING"); break; - case WM_WINDOWPOSCHANGED: fellowAddLog("EmulationWindowProc got message %s\n", "WM_WINDOWPOSCHANGED"); break; - default: fellowAddLog("EmulationWindowProc got message %Xh\n", message); + case WM_SETFONT: + case WM_ACTIVATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ACTIVATE"); break; + case WM_ACTIVATEAPP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ACTIVATEAPP"); break; + case WM_CHAR: fellowAddLog("EmulationWindowProc got message %s\n", "WM_CHAR"); break; + case WM_CREATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_CREATE"); break; + case WM_CLOSE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_CLOSE"); break; + case WM_DESTROY: fellowAddLog("EmulationWindowProc got message %s\n", "WM_DESTROY"); break; + case WM_ENABLE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ENABLE"); break; + case WM_ERASEBKGND: fellowAddLog("EmulationWindowProc got message %s\n", "WM_ERASEBKGND"); break; + case WM_GETICON: fellowAddLog("EmulationWindowProc got message %s\n", "WM_GETICON"); break; + case WM_GETMINMAXINFO: fellowAddLog("EmulationWindowProc got message %s\n", "WM_GETMINMAXINFO"); break; + case WM_IME_NOTIFY: fellowAddLog("EmulationWindowProc got message %s\n", "WM_IME_NOTIFY"); break; + case WM_IME_SETCONTEXT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_IME_SETCONTEXT"); break; + case WM_KEYDOWN: fellowAddLog("EmulationWindowProc got message %s\n", "WM_KEYDOWN"); break; + case WM_KEYUP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_KEYUP"); break; + case WM_KILLFOCUS: fellowAddLog("EmulationWindowProc got message %s\n", "WM_KILLFOCUS"); break; + case WM_LBUTTONDBLCLK: fellowAddLog("EmulationWindowProc got message %s\n", "WM_LBUTTONDBLCLK"); break; + case WM_LBUTTONDOWN: fellowAddLog("EmulationWindowProc got message %s\n", "WM_LBUTTONDOWN"); break; + case WM_LBUTTONUP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_LBUTTONUP"); break; + case WM_MOVE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_MOVE"); break; + case WM_MOUSEACTIVATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_MOUSEACTIVATE"); break; + case WM_MOUSEMOVE: /*fellowAddLog("EmulationWindowProc got message %s\n", "WM_MOUSEMOVE");*/ break; + case WM_NCPAINT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCPAINT"); break; + case WM_NCACTIVATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCACTIVATE"); break; + case WM_NCCALCSIZE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCCALCSIZE"); break; + case WM_NCCREATE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCCREATE"); break; + case WM_NCDESTROY: fellowAddLog("EmulationWindowProc got message %s\n", "WM_NCDESTROY"); break; + case WM_PAINT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_PAINT"); break; + case WM_SETCURSOR: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SETCURSOR"); break; + case WM_SETFOCUS: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SETFOCUS"); break; + case WM_SIZE: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SIZE"); break; + case WM_SHOWWINDOW: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SHOWWINDOW"); break; + case WM_SYNCPAINT: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYNCPAINT"); break; + case WM_SYSCOMMAND: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYSCOMMAND"); break; + case WM_SYSKEYDOWN: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYSKEYDOWN"); break; + case WM_SYSKEYUP: fellowAddLog("EmulationWindowProc got message %s\n", "WM_SYSKEYUP"); break; + case WM_TIMER: /*fellowAddLog("EmulationWindowProc got message %s\n", "WM_TIMER");*/ break; + case WM_WINDOWPOSCHANGING: fellowAddLog("EmulationWindowProc got message %s\n", "WM_WINDOWPOSCHANGING"); break; + case WM_WINDOWPOSCHANGED: fellowAddLog("EmulationWindowProc got message %s\n", "WM_WINDOWPOSCHANGED"); break; + default: fellowAddLog("EmulationWindowProc got message %Xh\n", message); } #endif switch (message) { - case WM_ERASEBKGND: - case WM_NCPAINT: - case WM_PAINT: - graph_buffer_lost = TRUE; - break; - case WM_TIMER: - if (wParam == 1) + case WM_ERASEBKGND: + case WM_NCPAINT: + case WM_PAINT: graph_buffer_lost = TRUE; break; + case WM_TIMER: + if (wParam == 1) + { + winDrvHandleInputDevices(); + _core.Drivers.SoundDriver->PollBufferPosition(); + return 0; + } + break; + case WM_SYSKEYDOWN: { - winDrvHandleInputDevices(); - soundDrvPollBufferPosition(); - return 0; + int vkey = (int)wParam; + _syskey_down = (vkey != VK_F10); } break; - case WM_SYSKEYDOWN: - { - int vkey = (int)wParam; - _syskey_down = (vkey != VK_F10); - } - break; - case WM_SYSKEYUP: - _syskey_down = false; - EvaluateRunEventStatus(); - switch (wParam) - { - case VK_RETURN: /* Full screen vs windowed */ + case WM_SYSKEYUP: + _syskey_down = false; + EvaluateRunEventStatus(); + switch (wParam) + { + case VK_RETURN: /* Full screen vs windowed */ break; + } break; - } - break; - case WM_MOVE: - gfxDrvPositionChanged(); - break; - case WM_SIZE: - gfxDrvSizeChanged(LOWORD(lParam), HIWORD(lParam)); - break; - case WM_ACTIVATE: - /* WM_ACTIVATE tells us whether our window is active or not */ - /* It is monitored so that we can know whether we should claim */ - /* the DirectInput devices */ - - _win_active_original = (((LOWORD(wParam)) == WA_ACTIVE) || ((LOWORD(wParam)) == WA_CLICKACTIVE)); - _win_minimized_original = ((HIWORD(wParam)) != 0); - NotifyDirectInputDevicesAboutActiveState(_win_active_original); + case WM_MOVE: gfxDrvPositionChanged(); break; + case WM_SIZE: gfxDrvSizeChanged(LOWORD(lParam), HIWORD(lParam)); break; + case WM_ACTIVATE: + /* WM_ACTIVATE tells us whether our window is active or not */ + /* It is monitored so that we can know whether we should claim */ + /* the DirectInput devices */ + + _win_active_original = (((LOWORD(wParam)) == WA_ACTIVE) || ((LOWORD(wParam)) == WA_CLICKACTIVE)); + _win_minimized_original = ((HIWORD(wParam)) != 0); + NotifyDirectInputDevicesAboutActiveState(_win_active_original); #ifdef RETRO_PLATFORM - if (RP.GetHeadlessMode() && _win_active_original) - RP.SendMouseCapture(true); + if (RP.GetHeadlessMode() && _win_active_original) RP.SendMouseCapture(true); #endif - EvaluateRunEventStatus(); - return 0; /* We processed this message */ - case WM_ENTERMENULOOP: - case WM_ENTERSIZEMOVE: - _win_active_original = false; - NotifyDirectInputDevicesAboutActiveState(_win_active_original); - return 0; - case WM_EXITMENULOOP: - case WM_EXITSIZEMOVE: - _win_active_original = (GetActiveWindow() == hWnd && !IsIconic(hWnd)); - PostMessage(hWnd, WM_DIACQUIRE, 0, 0L); - return 0; - case WM_SYSCOMMAND: - if (IsWindow(hWnd)) - { + EvaluateRunEventStatus(); + return 0; /* We processed this message */ + case WM_ENTERMENULOOP: + case WM_ENTERSIZEMOVE: + _win_active_original = false; NotifyDirectInputDevicesAboutActiveState(_win_active_original); - } - switch (GET_WM_COMMAND_ID(wParam, lParam)) - { - case SC_SCREENSAVE: return 0; - case SC_KEYMENU: + case WM_EXITMENULOOP: + case WM_EXITSIZEMOVE: + _win_active_original = (GetActiveWindow() == hWnd && !IsIconic(hWnd)); + PostMessage(hWnd, WM_DIACQUIRE, 0, 0L); return 0; -#ifdef RETRO_PLATFORM - case SC_CLOSE: - if (RP.GetHeadlessMode()) + case WM_SYSCOMMAND: + if (IsWindow(hWnd)) { - RP.SendClose(); - return 0; + NotifyDirectInputDevicesAboutActiveState(_win_active_original); } - // else fall through to DefWindowProc() to get WM_CLOSE etc. + switch (GET_WM_COMMAND_ID(wParam, lParam)) + { + case SC_SCREENSAVE: return 0; + case SC_KEYMENU: return 0; +#ifdef RETRO_PLATFORM + case SC_CLOSE: + if (RP.GetHeadlessMode()) + { + RP.SendClose(); + return 0; + } + // else fall through to DefWindowProc() to get WM_CLOSE etc. #endif - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - case WM_ACTIVATEAPP: - if (wParam) - { - /* Being activated */ - } - else - { - /* Being de-activated */ - _syskey_down = false; - } + default: return DefWindowProc(hWnd, message, wParam, lParam); + } + case WM_ACTIVATEAPP: + if (wParam) + { + /* Being activated */ + } + else + { + /* Being de-activated */ + _syskey_down = false; + } #ifdef RETRO_PLATFORM - if (RP.GetHeadlessMode()) - RP.SendActivated(wParam ? true : false, lParam); + if (RP.GetHeadlessMode()) RP.SendActivated(wParam ? true : false, lParam); #endif - return 0; - break; - case WM_DESTROY: - // save emulation window position only if in windowed mode - if (GetOutputWindowed()) - { - GetWindowRect(hWnd, &emulationRect); - iniSetEmulationWindowPosition(_ini, emulationRect.left, emulationRect.top); - } - NotifyDirectInputDevicesAboutActiveState(false); - return 0; - break; - case WM_SHOWWINDOW: - break; - case WM_DISPLAYCHANGE: - if (GetOutputWindowed()) - { - _displaychange = (wParam != _current_draw_mode->bits); - fellow_request_emulation_stop = TRUE; - } - break; - case WM_DIACQUIRE: /* Re-evaluate the active status of DI-devices */ - NotifyDirectInputDevicesAboutActiveState(_win_active_original); - return 0; - break; - case WM_CLOSE: - fellowRequestEmulationStop(); - return 0; /* We handled this message */ + return 0; + break; + case WM_DESTROY: + // save emulation window position only if in windowed mode + if (GetOutputWindowed()) + { + GetWindowRect(hWnd, &emulationRect); + iniSetEmulationWindowPosition(_ini, emulationRect.left, emulationRect.top); + } + NotifyDirectInputDevicesAboutActiveState(false); + return 0; + break; + case WM_SHOWWINDOW: break; + case WM_DISPLAYCHANGE: + if (GetOutputWindowed()) + { + _displaychange = (wParam != _current_draw_mode->bits); + fellow_request_emulation_stop = TRUE; + } + break; + case WM_DIACQUIRE: /* Re-evaluate the active status of DI-devices */ + NotifyDirectInputDevicesAboutActiveState(_win_active_original); + return 0; + break; + case WM_CLOSE: fellowRequestEmulationStop(); return 0; /* We handled this message */ #ifdef RETRO_PLATFORM - case WM_LBUTTONUP: - if(RP.GetHeadlessMode()) - { - if(mouseDrvGetFocus()) + case WM_LBUTTONUP: + if (RP.GetHeadlessMode()) { - NotifyDirectInputDevicesAboutActiveState(_win_active_original); - RP.SendMouseCapture(true); + if (mouseDrvGetFocus()) + { + NotifyDirectInputDevicesAboutActiveState(_win_active_original); + RP.SendMouseCapture(true); + } + else + { + mouseDrvStateHasChanged(TRUE); + mouseDrvSetFocus(TRUE, FALSE); + } + return 0; } - else + case WM_ENABLE: + if (RP.GetHeadlessMode()) { - mouseDrvStateHasChanged(TRUE); - mouseDrvSetFocus(TRUE, FALSE); + RP.SendEnable(wParam ? 1 : 0); + return 0; } - return 0; - } - case WM_ENABLE: - if (RP.GetHeadlessMode()) - { - RP.SendEnable(wParam ? 1 : 0); - return 0; - } #endif - } return DefWindowProc(hWnd, message, wParam, lParam); } - /*==========================================================================*/ /* Create window classes for Amiga display */ /* Called on emulator startup */ @@ -422,8 +403,7 @@ bool GfxDrvCommon::InitializeWindowClass() wc1.cbWndExtra = 0; wc1.hInstance = win_drv_hInstance; #ifdef RETRO_PLATFORM - if (RP.GetHeadlessMode()) - RP.SetWindowInstance(win_drv_hInstance); + if (RP.GetHeadlessMode()) RP.SetWindowInstance(win_drv_hInstance); #endif wc1.hIcon = LoadIcon(win_drv_hInstance, MAKEINTRESOURCE(IDI_ICON_WINFELLOW)); wc1.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -440,11 +420,11 @@ void GfxDrvCommon::ReleaseWindowClass() /***********************************************************************/ /** -* Show window hosting the amiga display. -* -* Called on every emulation startup. In RetroPlatform mode, the player will -* take care of showing the emulator's window. -***************************************************************************/ + * Show window hosting the amiga display. + * + * Called on every emulation startup. In RetroPlatform mode, the player will + * take care of showing the emulator's window. + ***************************************************************************/ void GfxDrvCommon::DisplayWindow() { @@ -470,7 +450,6 @@ void GfxDrvCommon::DisplayWindow() } } - /*==========================================================================*/ /* Hide window hosting the amiga display */ /* Called on emulation stop */ @@ -484,7 +463,6 @@ void GfxDrvCommon::HideWindow() } } - HWND GfxDrvCommon::GetHWND() { return _hwnd; @@ -523,33 +501,23 @@ bool GfxDrvCommon::InitializeWindow() } #endif - _hwnd = CreateWindowEx(dwExStyle, - "FellowWindowClass", - versionstring, - dwStyle, - 0, // CW_USEDEFAULT, - 0, // SW_SHOW, - width, - height, - hParent, - nullptr, - win_drv_hInstance, - nullptr); + _hwnd = CreateWindowEx( + dwExStyle, + "FellowWindowClass", + versionstring, + dwStyle, + 0, // CW_USEDEFAULT, + 0, // SW_SHOW, + width, + height, + hParent, + nullptr, + win_drv_hInstance, + nullptr); } else { - _hwnd = CreateWindowEx(WS_EX_TOPMOST, - "FellowWindowClass", - versionstring, - WS_POPUP, - 0, - 0, - width, - height, - nullptr, - nullptr, - win_drv_hInstance, - nullptr); + _hwnd = CreateWindowEx(WS_EX_TOPMOST, "FellowWindowClass", versionstring, WS_POPUP, 0, 0, width, height, nullptr, nullptr, win_drv_hInstance, nullptr); } fellowAddLog("GfxDrvCommon::InitializeWindow(): Window created\n"); free(versionstring); @@ -557,7 +525,6 @@ bool GfxDrvCommon::InitializeWindow() return (_hwnd != nullptr); } - /*==========================================================================*/ /* Destroy window hosting the amiga display */ /* Called on emulation stop */ @@ -572,12 +539,12 @@ void GfxDrvCommon::ReleaseWindow() } } -draw_mode* GfxDrvCommon::GetDrawMode() +draw_mode *GfxDrvCommon::GetDrawMode() { return _current_draw_mode; } -void GfxDrvCommon::SetDrawMode(draw_mode* mode, bool windowed) +void GfxDrvCommon::SetDrawMode(draw_mode *mode, bool windowed) { _current_draw_mode = mode; _output_windowed = windowed; @@ -590,7 +557,7 @@ void GfxDrvCommon::SetPauseEmulationWhenWindowLosesFocus(bool pause) void GfxDrvCommon::Flip() { - if (soundGetEmulation() == SOUND_PLAY) + if (_core.Sound->GetEmulation() == CustomChipset::SOUND_PLAY) { MaybeDelayFlip(); } @@ -598,7 +565,7 @@ void GfxDrvCommon::Flip() bool GfxDrvCommon::EmulationStart() { - RunEventReset(); /* At this point, app is paused */ + RunEventReset(); /* At this point, app is paused */ _win_active = false; _win_active_original = false; @@ -616,8 +583,7 @@ bool GfxDrvCommon::EmulationStart() #ifdef RETRO_PLATFORM // unpause emulation if in Retroplatform mode - if (RP.GetHeadlessMode() && !RP.GetEmulationPaused()) - RunEventSet(); + if (RP.GetHeadlessMode() && !RP.GetEmulationPaused()) RunEventSet(); #endif return true; @@ -662,14 +628,7 @@ void GfxDrvCommon::Shutdown() } GfxDrvCommon::GfxDrvCommon() - : _run_event(nullptr), - _hwnd(nullptr), - _ini(nullptr), - _frametime_target(18), - _previous_flip_time(0), - _time(0), - _wait_for_time(0), - _delay_flip_event(nullptr) + : _run_event(nullptr), _hwnd(nullptr), _ini(nullptr), _frametime_target(18), _previous_flip_time(0), _time(0), _wait_for_time(0), _delay_flip_event(nullptr) { } @@ -677,4 +636,3 @@ GfxDrvCommon::~GfxDrvCommon() { Shutdown(); } - diff --git a/fellow/SRC/WinFellow/Windows/RetroPlatform.cpp b/fellow/SRC/WinFellow/Windows/RetroPlatform.cpp index a6457aa6..bc0ce56c 100644 --- a/fellow/SRC/WinFellow/Windows/RetroPlatform.cpp +++ b/fellow/SRC/WinFellow/Windows/RetroPlatform.cpp @@ -29,50 +29,55 @@ * * This module contains RetroPlatform specific functionality to register as * RetroPlatform guest and interact with the host (player). - * It imitates the full Windows GUI module, implementing the same functionality, + * It imitates the full Windows GUI module, implementing the same functionality, * but supported via the RetroPlatform player as main GUI. * WinFellow's own GUI is not shown, the emulator operates in a headless mode. - * The configuration is received as a command line parameter, all control events + * The configuration is received as a command line parameter, all control events * (start, shutdown, reset, ...) are sent via IPC. - * + * * *Important Note:* The Cloanto modules make heavy use of unicode strings. - * As WinFellow uses ANSI strings, conversion is usually required (using, for example, - * wsctombs and mbstowcs). - * - * When looking at an RP9 package, the RetroPlatform WinFellow plug-in has a list of - * criteria to decide if WinFellow is a compatible emulator that is offered as choice. - * It verifies that + * As WinFellow uses ANSI strings, conversion is usually required (using, for + * example, wsctombs and mbstowcs). + * + * When looking at an RP9 package, the RetroPlatform WinFellow plug-in has a + * list of criteria to decide if WinFellow is a compatible emulator that is + * offered as choice. It verifies that * - a valid model-specific INI file exists for the configured Amiga model * - no extended ADF files are used (file size = 901.120 for all ADFs) - * + * * The plug-in will block the start of WinFellow on a number of criteria: * - if filesystems are used * - hardfiles using a non-standard geometry, or RDB hardfiles * - * The RetroPlatform WinFellow plug-in will start WinFellow with the following + * The RetroPlatform WinFellow plug-in will start WinFellow with the following * command-line arguments: - * + * * -rphost: * ID of the RetroPlatform host, used to initiate IPC communication. * * -datapath: * the path where WinFellow specific runtime information should be stored. - * + * * -f: - * The -f parameter provides an initial configuration, that is created in the following order: + * The -f parameter provides an initial configuration, that is created in the + * following order: * -# the WinFellow plug-in's shared.ini is applied * -# a model-specific INI is applied on top of that * -# the WinFellow plug-in overrides a number of things: - * - if "No interlace" is checked in the compatibility settings, fellow.gfx_deinterlace is set to no, otherwise to yes + * - if "No interlace" is checked in the compatibility settings, + * fellow.gfx_deinterlace is set to no, otherwise to yes * - if "Turbo CPU" is checked, cpu_speed is set to 0 - * - if the user has enabled "Always speed up drives where possible", "Turbo floppy" is set to yes in the RP9, - * and "Always use more accurate (slower) emulation" in the Option dialog is NOT set, fellow.floppy_fast_dma is set to yes, - * otherwise to no - * - gfx_width, gfx_height, gfx_offset_left and gfx_offset_top are added into the configuration depending on the - * settings of the RP9; the numbers assume the maximum pixel density (horizontal values super hires, vertical - * values interlace), so depending on the mode displayed, conversion is required; the clipping offsets need to -* be adjusted (384 to the top, 52 to the left) - * -# the WinFellow plug-in's override.ini is applied on top of that, to apply any settings that always must be active + * - if the user has enabled "Always speed up drives where possible", "Turbo + * floppy" is set to yes in the RP9, and "Always use more accurate (slower) + * emulation" in the Option dialog is NOT set, fellow.floppy_fast_dma is set to + * yes, otherwise to no + * - gfx_width, gfx_height, gfx_offset_left and gfx_offset_top are added into + * the configuration depending on the settings of the RP9; the numbers assume + * the maximum pixel density (horizontal values super hires, vertical values + * interlace), so depending on the mode displayed, conversion is required; the + * clipping offsets need to be adjusted (384 to the top, 52 to the left) + * -# the WinFellow plug-in's override.ini is applied on top of that, to apply + * any settings that always must be active * * -rpescapekey: * the DirectInput keycode of the escape key @@ -80,9 +85,10 @@ * -rpescapeholdtime: * the time in milliseconds after which the escape key should actually escape * - * -rpscreenmode: - * the initial screenmode the guest should activate at startup (e.g. 1X, 2X, ...). - * It is the numerical equivalent of the RP_SCREENMODE_* flags (see RetroPlatformIPC.h). + * -rpscreenmode: + * the initial screenmode the guest should activate at startup (e.g. 1X, 2X, + * ...). It is the numerical equivalent of the RP_SCREENMODE_* flags (see + * RetroPlatformIPC.h). */ #include "defs.h" @@ -91,36 +97,38 @@ #include "RetroPlatformGuestIPC.h" #include "RetroPlatformIPC.h" +#include "BUS.H" +#include "CpuIntegration.h" +#include "GfxDrvCommon.h" +#include "GfxDrvDXGI.h" +#include "KBDDRV.H" +#include "VirtualHost/Core.h" #include "config.h" +#include "dxver.h" /// needed for DirectInput based joystick detection code #include "fellow.h" -#include "windrv.h" +#include "fellow/api/module/IHardfileHandler.h" #include "floppy.h" #include "gfxdrv.h" -#include "mousedrv.h" +#include "gfxdrv_directdraw.h" #include "joydrv.h" -#include "CpuIntegration.h" -#include "BUS.H" #include "kbddrv.h" -#include "fellow/api/module/IHardfileHandler.h" -#include "dxver.h" /// needed for DirectInput based joystick detection code -#include "sounddrv.h" /// needed for DirectSound volume control -#include "GfxDrvCommon.h" -#include "gfxdrv_directdraw.h" -#include "GfxDrvDXGI.h" -#include "KBDDRV.H" +#include "mousedrv.h" +#include "windrv.h" RetroPlatform RP; -/** event handler function for events that are sent to WinFellow from Amiga Forever - * handles multiple incoming events like keyboard or joystick input events that are queued within the event message - * returns TRUE if successful, FALSE otherwise (for instance if an unrecogized event is encountered) +/** event handler function for events that are sent to WinFellow from Amiga + * Forever handles multiple incoming events like keyboard or joystick input + * events that are queued within the event message returns TRUE if successful, + * FALSE otherwise (for instance if an unrecogized event is encountered) */ BOOL RetroPlatformHandleIncomingGuestEvent(char *strCurrentEvent) { - if(strCurrentEvent == nullptr) + if (strCurrentEvent == nullptr) { - fellowAddLog("RetroPlatformHandleIncomingGuestEvent(): WARNING: ignoring NULL event string.\n"); + fellowAddLog("RetroPlatformHandleIncomingGuestEvent(): WARNING: ignoring " + "NULL event string.\n"); return FALSE; } @@ -131,11 +139,11 @@ BOOL RetroPlatformHandleIncomingGuestEvent(char *strCurrentEvent) BOOL blnMatch = FALSE; char *strRawKeyCode = nullptr; uint32_t lRawKeyCode = 0; - + // handle key_raw_up and key_raw_down events - if(!strnicmp(strCurrentEvent, "key_raw_down ", 13)) + if (!strnicmp(strCurrentEvent, "key_raw_down ", 13)) { - if(strRawKeyCode = strchr(strCurrentEvent, ' ')) + if (strRawKeyCode = strchr(strCurrentEvent, ' ')) { lRawKeyCode = (uint32_t)strtol(strRawKeyCode, nullptr, 0); kbdDrvKeypressRaw(lRawKeyCode, TRUE); @@ -143,9 +151,9 @@ BOOL RetroPlatformHandleIncomingGuestEvent(char *strCurrentEvent) blnMatch = TRUE; } - if(!strnicmp(strCurrentEvent, "key_raw_up ", 11)) + if (!strnicmp(strCurrentEvent, "key_raw_up ", 11)) { - if(strRawKeyCode = strchr(strCurrentEvent, ' ')) + if (strRawKeyCode = strchr(strCurrentEvent, ' ')) { lRawKeyCode = (uint32_t)strtol(strRawKeyCode, nullptr, 0); kbdDrvKeypressRaw(lRawKeyCode, FALSE); @@ -155,34 +163,32 @@ BOOL RetroPlatformHandleIncomingGuestEvent(char *strCurrentEvent) } // if no matching event was found, the player should return 0 - if(blnMatch) - return TRUE; + if (blnMatch) + return TRUE; else - return FALSE; + return FALSE; } BOOL RetroPlatformHandleIncomingGuestEventMessageParser(char *strEventMessage) { char *strCurrentEvent = (char *)strEventMessage; - for(;;) + for (;;) { - char* strNextEvent = nullptr; - char* blank1 = strchr(strCurrentEvent, ' '); - if(!blank1) - break; - char* blank2 = strchr(blank1 + 1, ' '); - if(blank2) + char *strNextEvent = nullptr; + char *blank1 = strchr(strCurrentEvent, ' '); + if (!blank1) break; + char *blank2 = strchr(blank1 + 1, ' '); + if (blank2) { *blank2 = NULL; strNextEvent = blank2 + 1; } - RetroPlatformHandleIncomingGuestEvent(strCurrentEvent); - - if(!strNextEvent) - break; - + RetroPlatformHandleIncomingGuestEvent(strCurrentEvent); + + if (!strNextEvent) break; + strCurrentEvent = strNextEvent; } @@ -195,22 +201,29 @@ BOOL RetroPlatformHandleIncomingGuestEventMessage(wchar_t *wcsEventMessage) char *strEventMessage = nullptr; size_t lEventMessageLength = 0, lReturnCode = 0; - lEventMessageLength = wcstombs(nullptr, wcsEventMessage, 0); // first call to wcstombs() determines how long the output buffer needs to be - strEventMessage = (char *)malloc(lEventMessageLength+1); - if(strEventMessage == nullptr) - return FALSE; - lReturnCode = wcstombs(strEventMessage, wcsEventMessage, lEventMessageLength+1); - if(lReturnCode == (size_t) -1) + lEventMessageLength = wcstombs(nullptr, wcsEventMessage, + 0); // first call to wcstombs() determines how + // long the output buffer needs to be + strEventMessage = (char *)malloc(lEventMessageLength + 1); + if (strEventMessage == nullptr) return FALSE; + lReturnCode = wcstombs(strEventMessage, wcsEventMessage, lEventMessageLength + 1); + if (lReturnCode == (size_t)-1) { - fellowAddLog("RetroPlatformHandleIncomingGuestEventMessage(): ERROR converting incoming guest event message with length %u to multi-byte string, ignoring message. Return code received was %u.\n", - lEventMessageLength, lReturnCode); + fellowAddLog( + "RetroPlatformHandleIncomingGuestEventMessage(): ERROR converting " + "incoming guest event message with length %u to multi-byte string, " + "ignoring message. Return code received was %u.\n", + lEventMessageLength, + lReturnCode); free(strEventMessage); return FALSE; } #ifdef _DEBUG - fellowAddLog("RetroPlatformHandleIncomingGuestEventMessage(): received an incoming guest event message with length %u: ", - lEventMessageLength); + fellowAddLog( + "RetroPlatformHandleIncomingGuestEventMessage(): received an " + "incoming guest event message with length %u: ", + lEventMessageLength); fellowAddLog2(strEventMessage); fellowAddLog2("\n"); #endif @@ -221,19 +234,26 @@ BOOL RetroPlatformHandleIncomingGuestEventMessage(wchar_t *wcsEventMessage) BOOL RetroPlatformHandleIncomingDeviceActivity(WPARAM wParam, LPARAM lParam) { - uint32_t lGamePort = HIBYTE(wParam); + uint32_t lGamePort = HIBYTE(wParam); uint32_t lDeviceCategory = LOBYTE(wParam); - uint32_t lMask = lParam; + uint32_t lMask = lParam; - fellowAddLog("RetroPlatformHandleIncomingDeviceActivity(): wParam=%04x, lParam=%08x, lGamePort=%u, lDeviceCategory=%u\n", wParam, lParam, lGamePort, lDeviceCategory); + fellowAddLog( + "RetroPlatformHandleIncomingDeviceActivity(): wParam=%04x, " + "lParam=%08x, lGamePort=%u, lDeviceCategory=%u\n", + wParam, + lParam, + lGamePort, + lDeviceCategory); - if(lDeviceCategory != RP_DEVICECATEGORY_INPUTPORT) + if (lDeviceCategory != RP_DEVICECATEGORY_INPUTPORT) { - fellowAddLog(" RetroPlatformHandleIncomingDeviceActivity(): unsupported device category.n"); + fellowAddLog(" RetroPlatformHandleIncomingDeviceActivity(): unsupported " + "device category.n"); return FALSE; } - if(lGamePort > 1) + if (lGamePort > 1) { fellowAddLog(" RetroPlatformHandleIncomingDeviceActivity(): invalid gameport %u.\n", lGamePort); return FALSE; @@ -246,17 +266,16 @@ BOOL RetroPlatformHandleIncomingDeviceActivity(WPARAM wParam, LPARAM lParam) BOOL bButton1 = lMask & RP_JOYSTICK_BUTTON1; BOOL bButton2 = lMask & RP_JOYSTICK_BUTTON2; - if(lGamePort == 0) + if (lGamePort == 0) gameportJoystickHandler(RP_JOYSTICK0, bLeft, bUp, bRight, bDown, bButton1, bButton2); - else if(lGamePort == 1) + else if (lGamePort == 1) gameportJoystickHandler(RP_JOYSTICK1, bLeft, bUp, bRight, bDown, bButton1, bButton2); return TRUE; } // hook into RetroPlatform class to perform IPC communication with host -LRESULT CALLBACK RetroPlatformHostMessageFunction(UINT uMessage, WPARAM wParam, LPARAM lParam, - LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) +LRESULT CALLBACK RetroPlatformHostMessageFunction(UINT uMessage, WPARAM wParam, LPARAM lParam, LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) { return RP.HostMessageFunction(uMessage, wParam, lParam, pData, dwDataSize, lMsgFunctionParam); } @@ -267,25 +286,34 @@ BOOL FAR PASCAL RetroPlatformEnumerateJoystick(LPCDIDEVICEINSTANCE pdinst, LPVOI return RP.EnumerateJoystick(pdinst, pvRef); } -/** host message function that is used as callback to receive IPC messages from the host. -*/ -LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam, LPARAM lParam, - LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) +/** host message function that is used as callback to receive IPC messages from + * the host. + */ +LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam, LPARAM lParam, LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) { #ifdef _DEBUG - fellowAddLog("RetroPlatform::HostMessageFunction(%s [%d], %08x, %08x, %08x, %d, %08x)\n", - RP.GetMessageText(uMessage), uMessage - WM_APP, wParam, lParam, pData, dwDataSize, lMsgFunctionParam); + fellowAddLog( + "RetroPlatform::HostMessageFunction(%s [%d], %08x, %08x, %08x, " + "%d, %08x)\n", + RP.GetMessageText(uMessage), + uMessage - WM_APP, + wParam, + lParam, + pData, + dwDataSize, + lMsgFunctionParam); #endif switch (uMessage) { default: - fellowAddLog("RetroPlatform::HostMessageFunction(): Unknown or unsupported command 0x%x\n", uMessage); + fellowAddLog( + "RetroPlatform::HostMessageFunction(): Unknown or unsupported " + "command 0x%x\n", + uMessage); break; - case RP_IPC_TO_GUEST_EVENT: - return RetroPlatformHandleIncomingGuestEventMessage((wchar_t *)pData); - case RP_IPC_TO_GUEST_PING: - return true; + case RP_IPC_TO_GUEST_EVENT: return RetroPlatformHandleIncomingGuestEventMessage((wchar_t *)pData); + case RP_IPC_TO_GUEST_PING: return true; case RP_IPC_TO_GUEST_CLOSE: fellowAddLog("RetroPlatform::HostMessageFunction(): received close event.\n"); fellowRequestEmulationStop(); @@ -293,48 +321,49 @@ LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam RP.SetEmulatorQuit(true); return true; case RP_IPC_TO_GUEST_RESET: - if(wParam == RP_RESET_HARD) - fellowSetPreStartReset(true); + if (wParam == RP_RESET_HARD) fellowSetPreStartReset(true); RP.SetEmulationPaused(false); gfxDrvCommon->RunEventSet(); fellowRequestEmulationStop(); return true; case RP_IPC_TO_GUEST_TURBO: - if(wParam & RP_TURBO_CPU) + if (wParam & RP_TURBO_CPU) { static uint32_t lOriginalSpeed = 0; - if(lParam & RP_TURBO_CPU) + if (lParam & RP_TURBO_CPU) { - fellowAddLog("RetroPlatform::HostMessageFunction(): enabling CPU turbo mode...\n"); + fellowAddLog("RetroPlatform::HostMessageFunction(): enabling CPU turbo " + "mode...\n"); lOriginalSpeed = RP.GetCPUSpeed(); cpuIntegrationSetSpeed(0); cpuIntegrationCalculateMultiplier(); busDetermineCpuInstructionEventHandler(); fellowRequestEmulationStop(); } - else + else { - fellowAddLog("RetroPlatform::HostMessageFunction(): disabling CPU turbo mode, reverting back to speed level %u...\n", - lOriginalSpeed); + fellowAddLog( + "RetroPlatform::HostMessageFunction(): disabling CPU " + "turbo mode, reverting back to speed level %u...\n", + lOriginalSpeed); cpuIntegrationSetSpeed(lOriginalSpeed); cpuIntegrationCalculateMultiplier(); busDetermineCpuInstructionEventHandler(); fellowRequestEmulationStop(); } } - if(wParam & RP_TURBO_FLOPPY) - floppySetFastDMA(lParam & RP_TURBO_FLOPPY ? true : false); + if (wParam & RP_TURBO_FLOPPY) floppySetFastDMA(lParam & RP_TURBO_FLOPPY ? true : false); return true; case RP_IPC_TO_GUEST_PAUSE: - if(wParam != 0) + if (wParam != 0) { // pause emulation gfxDrvCommon->RunEventReset(); RP.SetEmulationPaused(true); RP.SetEmulationState(false); return 1; } - else + else { // resume emulation gfxDrvCommon->RunEventSet(); RP.SetEmulationPaused(false); @@ -342,8 +371,8 @@ LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam return 1; } case RP_IPC_TO_GUEST_VOLUME: - soundSetVolume(wParam); - soundDrvDSoundSetCurrentSoundDeviceVolume(wParam); + _core.Sound->SetVolume(wParam); + _core.Drivers.SoundDriver->SetCurrentSoundDeviceVolume(wParam); return true; #ifndef FELLOW_SUPPORT_RP_API_VERSION_71 case RP_IPC_TO_GUEST_ESCAPEKEY: @@ -356,74 +385,79 @@ LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam mouseDrvStateHasChanged(true); mouseDrvSetFocus(wParam & RP_MOUSECAPTURE_CAPTURED ? true : false, true); return true; - case RP_IPC_TO_GUEST_DEVICEACTIVITY: - return RetroPlatformHandleIncomingDeviceActivity(wParam, lParam); + case RP_IPC_TO_GUEST_DEVICEACTIVITY: return RetroPlatformHandleIncomingDeviceActivity(wParam, lParam); case RP_IPC_TO_GUEST_DEVICECONTENT: { - struct RPDeviceContent *dc = (struct RPDeviceContent*)pData; + struct RPDeviceContent *dc = (struct RPDeviceContent *)pData; char name[CFG_FILENAME_LENGTH] = ""; wcstombs(name, dc->szContent, CFG_FILENAME_LENGTH); - #ifdef _DEBUG - fellowAddLog("RetroPlatform::HostMessageFunction(): RP_IPC_TO_GUEST_DEVICECONTENT Cat=%d Num=%d Flags=%08x '%s'\n", - dc->btDeviceCategory, dc->btDeviceNumber, dc->dwFlags, name); - #endif +#ifdef _DEBUG + fellowAddLog( + "RetroPlatform::HostMessageFunction(): RP_IPC_TO_GUEST_DEVICECONTENT " + "Cat=%d Num=%d Flags=%08x '%s'\n", + dc->btDeviceCategory, + dc->btDeviceNumber, + dc->dwFlags, + name); +#endif int num = dc->btDeviceNumber; int ok = false; - + switch (dc->btDeviceCategory) { - case RP_DEVICECATEGORY_FLOPPY: - if(name == nullptr || name[0] == 0) + case RP_DEVICECATEGORY_FLOPPY: + if (name == nullptr || name[0] == 0) { - fellowAddLog("RetroPlatform::HostMessageFunction(): remove floppy disk from drive %d.\n", num); + fellowAddLog( + "RetroPlatform::HostMessageFunction(): remove floppy disk " + "from drive %d.\n", + num); floppyImageRemove(num); } - else + else { - fellowAddLog("RetroPlatform::HostMessageFunction(): set floppy image for drive %d to %s.\n", - num, name); + fellowAddLog( + "RetroPlatform::HostMessageFunction(): set floppy image " + "for drive %d to %s.\n", + num, + name); floppySetDiskImage(num, name); } ok = true; break; - case RP_DEVICECATEGORY_INPUTPORT: - ok = RP.ConnectInputDeviceToPort(num, dc->dwInputDevice, dc->dwFlags, name); - break; - case RP_DEVICECATEGORY_CD: - ok = false; - break; + case RP_DEVICECATEGORY_INPUTPORT: ok = RP.ConnectInputDeviceToPort(num, dc->dwInputDevice, dc->dwFlags, name); break; + case RP_DEVICECATEGORY_CD: ok = false; break; } return ok; } case RP_IPC_TO_GUEST_SCREENCAPTURE: { - struct RPScreenCapture *rpsc = (struct RPScreenCapture*)pData; + struct RPScreenCapture *rpsc = (struct RPScreenCapture *)pData; char szScreenFiltered[CFG_FILENAME_LENGTH] = "", szScreenRaw[CFG_FILENAME_LENGTH] = ""; wcstombs(szScreenFiltered, rpsc->szScreenFiltered, CFG_FILENAME_LENGTH); wcstombs(szScreenRaw, rpsc->szScreenRaw, CFG_FILENAME_LENGTH); - if(szScreenFiltered[0] || szScreenRaw[0]) + if (szScreenFiltered[0] || szScreenRaw[0]) { bool bResult = true; DWORD dResult = 0; - fellowAddLog("RetroPlatform::HostMessageFunction(): screenshot request received; filtered '%s', raw '%s'\n", - szScreenFiltered, szScreenRaw); + fellowAddLog( + "RetroPlatform::HostMessageFunction(): screenshot request " + "received; filtered '%s', raw '%s'\n", + szScreenFiltered, + szScreenRaw); - if(szScreenFiltered[0]) - if (!gfxDrvSaveScreenshot(true, szScreenFiltered)) - bResult = false; + if (szScreenFiltered[0]) + if (!gfxDrvSaveScreenshot(true, szScreenFiltered)) bResult = false; - if(szScreenRaw[0]) - if(!gfxDrvSaveScreenshot(false, szScreenRaw)) - bResult = false; + if (szScreenRaw[0]) + if (!gfxDrvSaveScreenshot(false, szScreenRaw)) bResult = false; - if(bResult) + if (bResult) { - dResult |= RP_GUESTSCREENFLAGS_MODE_PAL | - RP_GUESTSCREENFLAGS_HORIZONTAL_HIRES | - RP_GUESTSCREENFLAGS_VERTICAL_INTERLACED; + dResult |= RP_GUESTSCREENFLAGS_MODE_PAL | RP_GUESTSCREENFLAGS_HORIZONTAL_HIRES | RP_GUESTSCREENFLAGS_VERTICAL_INTERLACED; return dResult; } else @@ -433,7 +467,7 @@ LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam } case RP_IPC_TO_GUEST_SCREENMODE: { - struct RPScreenMode *sm = (struct RPScreenMode *) pData; + struct RPScreenMode *sm = (struct RPScreenMode *)pData; RP.SetScreenModeStruct(sm); return (LRESULT)INVALID_HANDLE_VALUE; } @@ -441,10 +475,10 @@ LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam { DWORD ret = false; int device = LOBYTE(wParam); - if(device == RP_DEVICECATEGORY_FLOPPY) + if (device == RP_DEVICECATEGORY_FLOPPY) { int num = HIBYTE(wParam); - if(lParam == RP_DEVICE_READONLY || lParam == RP_DEVICE_READWRITE) + if (lParam == RP_DEVICE_READONLY || lParam == RP_DEVICE_READWRITE) { floppySetReadOnlyConfig(num, lParam == RP_DEVICE_READONLY ? true : false); ret = true; @@ -452,8 +486,7 @@ LRESULT CALLBACK RetroPlatform::HostMessageFunction(UINT uMessage, WPARAM wParam } return ret ? (LPARAM)1 : 0; } - case RP_IPC_TO_GUEST_FLUSH: - return 1; + case RP_IPC_TO_GUEST_FLUSH: return 1; case RP_IPC_TO_GUEST_GUESTAPIVERSION: { return MAKELONG(3, 4); @@ -469,83 +502,78 @@ BOOL FAR PASCAL RetroPlatform::EnumerateJoystick(LPCDIDEVICEINSTANCE pdinst, LPV char strHostInputID[CFG_FILENAME_LENGTH]; WCHAR szHostInputID[CFG_FILENAME_LENGTH]; WCHAR szHostInputName[CFG_FILENAME_LENGTH]; - - fellowAddLog( "**** Joystick %d **** '%s'\n", - ++iNumberOfJoysticksAttached, pdinst->tszProductName); + + fellowAddLog("**** Joystick %d **** '%s'\n", ++iNumberOfJoysticksAttached, pdinst->tszProductName); sprintf(strHostInputID, "GP_ANALOG%d", iNumberOfJoysticksAttached - 1); mbstowcs(szHostInputID, strHostInputID, CFG_FILENAME_LENGTH); mbstowcs(szHostInputName, pdinst->tszProductName, CFG_FILENAME_LENGTH); - RP.SendInputDevice(RP_HOSTINPUT_JOYSTICK, - RP_FEATURE_INPUTDEVICE_JOYSTICK | RP_FEATURE_INPUTDEVICE_GAMEPAD, - 0, szHostInputID, szHostInputName); + RP.SendInputDevice(RP_HOSTINPUT_JOYSTICK, RP_FEATURE_INPUTDEVICE_JOYSTICK | RP_FEATURE_INPUTDEVICE_GAMEPAD, 0, szHostInputID, szHostInputName); - if(iNumberOfJoysticksAttached == RETRO_PLATFORM_NUM_GAMEPORTS) + if (iNumberOfJoysticksAttached == RETRO_PLATFORM_NUM_GAMEPORTS) return DIENUM_STOP; - else - return DIENUM_CONTINUE; + else + return DIENUM_CONTINUE; } /** Determine the number of joysticks connected to the system. */ -int RetroPlatform::EnumerateJoysticks() +int RetroPlatform::EnumerateJoysticks() { - IDirectInput8*RP_lpDI = nullptr; + IDirectInput8 *RP_lpDI = nullptr; fellowAddLog("RetroPlatform::EnumerateJoysticks()\n"); if (!RP_lpDI) { - HRESULT hResult = CoCreateInstance(CLSID_DirectInput8, - nullptr, - CLSCTX_INPROC_SERVER, - IID_IDirectInput8, - (LPVOID*)&RP_lpDI); - if(hResult != DI_OK) + HRESULT hResult = CoCreateInstance(CLSID_DirectInput8, nullptr, CLSCTX_INPROC_SERVER, IID_IDirectInput8, (LPVOID *)&RP_lpDI); + if (hResult != DI_OK) { - fellowAddLog("RetroPlatform::EnumerateJoysticks(): CoCreateInstance() failed, errorcode %d\n", - hResult); + fellowAddLog( + "RetroPlatform::EnumerateJoysticks(): CoCreateInstance() " + "failed, errorcode %d\n", + hResult); return 0; } - hResult = IDirectInput8_Initialize(RP_lpDI, - win_drv_hInstance, - DIRECTINPUT_VERSION); - if(hResult != DI_OK) + hResult = IDirectInput8_Initialize(RP_lpDI, win_drv_hInstance, DIRECTINPUT_VERSION); + if (hResult != DI_OK) { - fellowAddLog("RetroPlatform::EnumerateJoysticks(): Initialize() failed, errorcode %d\n", - hResult); + fellowAddLog( + "RetroPlatform::EnumerateJoysticks(): Initialize() failed, " + "errorcode %d\n", + hResult); return 0; } iNumberOfJoysticksAttached = 0; - hResult = IDirectInput8_EnumDevices(RP_lpDI, DI8DEVCLASS_GAMECTRL, - RetroPlatformEnumerateJoystick, RP_lpDI, DIEDFL_ATTACHEDONLY); - if(hResult != DI_OK) + hResult = IDirectInput8_EnumDevices(RP_lpDI, DI8DEVCLASS_GAMECTRL, RetroPlatformEnumerateJoystick, RP_lpDI, DIEDFL_ATTACHEDONLY); + if (hResult != DI_OK) { - fellowAddLog("RetroPlatform::EnumerateJoysticks(): EnumDevices() failed, errorcode %d\n", - hResult); + fellowAddLog( + "RetroPlatform::EnumerateJoysticks(): EnumDevices() failed, " + "errorcode %d\n", + hResult); return 0; } - if(RP_lpDI != nullptr) + if (RP_lpDI != nullptr) { IDirectInput8_Release(RP_lpDI); RP_lpDI = nullptr; } } - fellowAddLog("RetroPlatform::EnumerateJoysticks(): detected %d joystick(s).\n", - iNumberOfJoysticksAttached); + fellowAddLog("RetroPlatform::EnumerateJoysticks(): detected %d joystick(s).\n", iNumberOfJoysticksAttached); return iNumberOfJoysticksAttached; } /** Set clipping offset that is applied to the left of the picture. */ -void RetroPlatform::SetClippingOffsetLeft(const uint32_t lOffsetLeft) +void RetroPlatform::SetClippingOffsetLeft(const uint32_t lOffsetLeft) { lClippingOffsetLeftRP = lOffsetLeft; @@ -567,12 +595,12 @@ void RetroPlatform::SetClippingOffsetTop(const uint32_t lOffsetTop) /** configure keyboard layout to custom key mappings * - * Gameport 0 is statically mapped to internal keyboard layout GP_JOYKEY0, + * Gameport 0 is statically mapped to internal keyboard layout GP_JOYKEY0, * gameport 1 to GP_JOYKEY1 as we reconfigure them anyway */ -void RetroPlatform::SetCustomKeyboardLayout(const uint32_t lGameport, const char *pszKeys) +void RetroPlatform::SetCustomKeyboardLayout(const uint32_t lGameport, const char *pszKeys) { - const char *CustomLayoutKeys[RETRO_PLATFORM_KEYSET_COUNT] = { "up", "right", "down", "left", "fire", "fire.autorepeat" }; + const char *CustomLayoutKeys[RETRO_PLATFORM_KEYSET_COUNT] = {"up", "right", "down", "left", "fire", "fire.autorepeat"}; int l[RETRO_PLATFORM_KEYSET_COUNT], n; char *psz; size_t ln; @@ -580,61 +608,66 @@ void RetroPlatform::SetCustomKeyboardLayout(const uint32_t lGameport, const char fellowAddLog(" Configuring keyboard layout %d to %s.\n", lGameport, pszKeys); // keys not (always) configured via custom layouts - kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_FIRE1_ACTIVE : EVENT_JOY0_FIRE1_ACTIVE, 0); + kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_FIRE1_ACTIVE : EVENT_JOY0_FIRE1_ACTIVE, 0); kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_AUTOFIRE0_ACTIVE : EVENT_JOY0_AUTOFIRE0_ACTIVE, 0); kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_AUTOFIRE1_ACTIVE : EVENT_JOY0_AUTOFIRE1_ACTIVE, 0); - - while(*pszKeys) + + while (*pszKeys) { - for (; *pszKeys == ' '; pszKeys++); // skip spaces + for (; *pszKeys == ' '; pszKeys++) + ; // skip spaces - for (n = 0; n < RETRO_PLATFORM_KEYSET_COUNT; n++) - { - ln = strlen(CustomLayoutKeys[n]); - if(strnicmp(pszKeys, CustomLayoutKeys[n], ln) == 0 && *(pszKeys + ln) == '=') - break; + for (n = 0; n < RETRO_PLATFORM_KEYSET_COUNT; n++) + { + ln = strlen(CustomLayoutKeys[n]); + if (strnicmp(pszKeys, CustomLayoutKeys[n], ln) == 0 && *(pszKeys + ln) == '=') break; } - if(n < RETRO_PLATFORM_KEYSET_COUNT) - { - pszKeys += ln + 1; - l[n] = kbddrv_DIK_to_symbol[strtoul(pszKeys, &psz, 0)]; // convert DIK_* DirectInput key codes to symbolic keycodes - + if (n < RETRO_PLATFORM_KEYSET_COUNT) + { + pszKeys += ln + 1; + l[n] = kbddrv_DIK_to_symbol[strtoul(pszKeys, &psz, + 0)]; // convert DIK_* DirectInput key codes to symbolic keycodes + // perform the individual mappings - if (strnicmp(CustomLayoutKeys[n], "up", strlen("up")) == 0) + if (strnicmp(CustomLayoutKeys[n], "up", strlen("up")) == 0) kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_UP_ACTIVE : EVENT_JOY0_UP_ACTIVE, l[n]); - else if(strnicmp(CustomLayoutKeys[n], "down", strlen("down")) == 0) + else if (strnicmp(CustomLayoutKeys[n], "down", strlen("down")) == 0) kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_DOWN_ACTIVE : EVENT_JOY0_DOWN_ACTIVE, l[n]); - else if(strnicmp(CustomLayoutKeys[n], "left", strlen("left")) == 0) + else if (strnicmp(CustomLayoutKeys[n], "left", strlen("left")) == 0) kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_LEFT_ACTIVE : EVENT_JOY0_LEFT_ACTIVE, l[n]); - else if(strnicmp(CustomLayoutKeys[n], "right", strlen("right")) == 0) + else if (strnicmp(CustomLayoutKeys[n], "right", strlen("right")) == 0) kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_RIGHT_ACTIVE : EVENT_JOY0_RIGHT_ACTIVE, l[n]); - else if(strnicmp(CustomLayoutKeys[n], "fire", strlen("fire")) == 0) + else if (strnicmp(CustomLayoutKeys[n], "fire", strlen("fire")) == 0) kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_FIRE0_ACTIVE : EVENT_JOY0_FIRE0_ACTIVE, l[n]); - else if(strnicmp(CustomLayoutKeys[n], "fire.autorepeat", strlen("fire.autorepeat")) == 0) + else if (strnicmp(CustomLayoutKeys[n], "fire.autorepeat", strlen("fire.autorepeat")) == 0) kbdDrvJoystickReplacementSet((lGameport == 1) ? EVENT_JOY1_AUTOFIRE0_ACTIVE : EVENT_JOY0_AUTOFIRE0_ACTIVE, l[n]); - } - for (; *pszKeys != ' ' && *pszKeys != 0; pszKeys++); // reach next key definition + } + for (; *pszKeys != ' ' && *pszKeys != 0; pszKeys++) + ; // reach next key definition } - for(n = 0; n < RETRO_PLATFORM_KEYSET_COUNT; n++) - fellowAddLog(" Direction %s mapped to key %s.\n", - CustomLayoutKeys[n], kbdDrvKeyString(l[n])); + for (n = 0; n < RETRO_PLATFORM_KEYSET_COUNT; n++) + fellowAddLog(" Direction %s mapped to key %s.\n", CustomLayoutKeys[n], kbdDrvKeyString(l[n])); } /** Attach input devices to gameports during runtime of the emulator. - * + * * The device is selected in the RetroPlatform player and passed to the emulator * in form of an IPC message. */ bool RetroPlatform::ConnectInputDeviceToPort(const uint32_t lGameport, const uint32_t lDeviceType, DWORD dwFlags, const char *szName) { - if(lGameport < 0 || lGameport >= RETRO_PLATFORM_NUM_GAMEPORTS) - return false; + if (lGameport < 0 || lGameport >= RETRO_PLATFORM_NUM_GAMEPORTS) return false; - fellowAddLog("RetroPlatform::ConnectInputDeviceToPort(): port %d, device type %d, flags %d, name '%s'\n", - lGameport, lDeviceType, dwFlags, szName); + fellowAddLog( + "RetroPlatform::ConnectInputDeviceToPort(): port %d, device " + "type %d, flags %d, name '%s'\n", + lGameport, + lDeviceType, + dwFlags, + szName); - switch(lDeviceType) + switch (lDeviceType) { case RP_INPUTDEVICE_EMPTY: fellowAddLog(" Removing input device from gameport..\n"); @@ -646,54 +679,54 @@ bool RetroPlatform::ConnectInputDeviceToPort(const uint32_t lGameport, const uin gameportSetInput(lGameport, GP_MOUSE0); return true; case RP_INPUTDEVICE_JOYSTICK: - if(strcmp(szName, "GP_ANALOG0") == 0) + if (strcmp(szName, "GP_ANALOG0") == 0) { fellowAddLog(" Attaching joystick 1 to gameport..\n"); gameportSetInput(lGameport, GP_ANALOG0); } - else if(strcmp(szName, "GP_ANALOG1") == 0) + else if (strcmp(szName, "GP_ANALOG1") == 0) { fellowAddLog(" Attaching joystick 2 to gameport..\n"); gameportSetInput(lGameport, GP_ANALOG1); } - else if(_strnicmp(szName, "GP_JOYKEYCUSTOM", strlen("GP_JOYKEYCUSTOM")) == 0) + else if (_strnicmp(szName, "GP_JOYKEYCUSTOM", strlen("GP_JOYKEYCUSTOM")) == 0) { // custom layout RetroPlatform::SetCustomKeyboardLayout(lGameport, szName + strlen("GP_JOYKEYCUSTOM") + 1); gameportSetInput(lGameport, (lGameport == 1) ? GP_JOYKEY1 : GP_JOYKEY0); - if(lGameport == 0) + if (lGameport == 0) { kbdDrvSetJoyKeyEnabled(lGameport, 0, TRUE); kbdDrvSetJoyKeyEnabled(lGameport, 1, FALSE); } - else if(lGameport == 1) + else if (lGameport == 1) { kbdDrvSetJoyKeyEnabled(lGameport, 0, FALSE); kbdDrvSetJoyKeyEnabled(lGameport, 1, TRUE); } } #ifdef FELLOW_SUPPORT_RP_API_VERSION_71 - else if(_strnicmp(szName, "", 1) == 0) + else if (_strnicmp(szName, "", 1) == 0) { - fellowAddLog(" RetroPlatform controlled joystick device connect to gameport %l, leaving control up to host.\n", - lGameport); + fellowAddLog( + " RetroPlatform controlled joystick device connect to " + "gameport %l, leaving control up to host.\n", + lGameport); - if(lGameport == 0) + if (lGameport == 0) gameportSetInput(lGameport, RP_JOYSTICK0); - else if(lGameport == 1) + else if (lGameport == 1) gameportSetInput(lGameport, RP_JOYSTICK1); return true; } #endif - else + else { - fellowAddLog (" WARNING: Unknown joystick input device name, ignoring..\n"); + fellowAddLog(" WARNING: Unknown joystick input device name, ignoring..\n"); return false; } return true; - default: - fellowAddLog(" WARNING: Unsupported input device type detected.\n"); - return false; + default: fellowAddLog(" WARNING: Unsupported input device type detected.\n"); return false; } } @@ -701,52 +734,53 @@ bool RetroPlatform::ConnectInputDeviceToPort(const uint32_t lGameport, const uin */ const char *RetroPlatform::GetMessageText(uint32_t iMsg) { - switch(iMsg) { - case RP_IPC_TO_HOST_FEATURES: return TEXT("RP_IPC_TO_HOST_FEATURES"); - case RP_IPC_TO_HOST_CLOSED: return TEXT("RP_IPC_TO_HOST_CLOSED"); - case RP_IPC_TO_HOST_ACTIVATED: return TEXT("RP_IPC_TO_HOST_ACTIVATED"); - case RP_IPC_TO_HOST_DEACTIVATED: return TEXT("RP_IPC_TO_HOST_DEACTIVATED"); - case RP_IPC_TO_HOST_SCREENMODE: return TEXT("RP_IPC_TO_HOST_SCREENMODE"); - case RP_IPC_TO_HOST_POWERLED: return TEXT("RP_IPC_TO_HOST_POWERLED"); - case RP_IPC_TO_HOST_DEVICES: return TEXT("RP_IPC_TO_HOST_DEVICES"); - case RP_IPC_TO_HOST_DEVICEACTIVITY: return TEXT("RP_IPC_TO_HOST_DEVICEACTIVITY"); - case RP_IPC_TO_HOST_MOUSECAPTURE: return TEXT("RP_IPC_TO_HOST_MOUSECAPTURE"); - case RP_IPC_TO_HOST_HOSTAPIVERSION: return TEXT("RP_IPC_TO_HOST_HOSTAPIVERSION"); - case RP_IPC_TO_HOST_PAUSE: return TEXT("RP_IPC_TO_HOST_PAUSE"); - case RP_IPC_TO_HOST_DEVICECONTENT: return TEXT("RP_IPC_TO_HOST_DEVICECONTENT"); - case RP_IPC_TO_HOST_TURBO: return TEXT("RP_IPC_TO_HOST_TURBO"); - case RP_IPC_TO_HOST_PING: return TEXT("RP_IPC_TO_HOST_PING"); - case RP_IPC_TO_HOST_VOLUME: return TEXT("RP_IPC_TO_HOST_VOLUME"); + switch (iMsg) + { + case RP_IPC_TO_HOST_FEATURES: return TEXT("RP_IPC_TO_HOST_FEATURES"); + case RP_IPC_TO_HOST_CLOSED: return TEXT("RP_IPC_TO_HOST_CLOSED"); + case RP_IPC_TO_HOST_ACTIVATED: return TEXT("RP_IPC_TO_HOST_ACTIVATED"); + case RP_IPC_TO_HOST_DEACTIVATED: return TEXT("RP_IPC_TO_HOST_DEACTIVATED"); + case RP_IPC_TO_HOST_SCREENMODE: return TEXT("RP_IPC_TO_HOST_SCREENMODE"); + case RP_IPC_TO_HOST_POWERLED: return TEXT("RP_IPC_TO_HOST_POWERLED"); + case RP_IPC_TO_HOST_DEVICES: return TEXT("RP_IPC_TO_HOST_DEVICES"); + case RP_IPC_TO_HOST_DEVICEACTIVITY: return TEXT("RP_IPC_TO_HOST_DEVICEACTIVITY"); + case RP_IPC_TO_HOST_MOUSECAPTURE: return TEXT("RP_IPC_TO_HOST_MOUSECAPTURE"); + case RP_IPC_TO_HOST_HOSTAPIVERSION: return TEXT("RP_IPC_TO_HOST_HOSTAPIVERSION"); + case RP_IPC_TO_HOST_PAUSE: return TEXT("RP_IPC_TO_HOST_PAUSE"); + case RP_IPC_TO_HOST_DEVICECONTENT: return TEXT("RP_IPC_TO_HOST_DEVICECONTENT"); + case RP_IPC_TO_HOST_TURBO: return TEXT("RP_IPC_TO_HOST_TURBO"); + case RP_IPC_TO_HOST_PING: return TEXT("RP_IPC_TO_HOST_PING"); + case RP_IPC_TO_HOST_VOLUME: return TEXT("RP_IPC_TO_HOST_VOLUME"); #ifndef FELLOW_SUPPORT_RP_API_VERSION_71 - case RP_IPC_TO_HOST_ESCAPED: return TEXT("RP_IPC_TO_HOST_ESCAPED"); + case RP_IPC_TO_HOST_ESCAPED: return TEXT("RP_IPC_TO_HOST_ESCAPED"); #endif - case RP_IPC_TO_HOST_PARENT: return TEXT("RP_IPC_TO_HOST_PARENT"); - case RP_IPC_TO_HOST_DEVICESEEK: return TEXT("RP_IPC_TO_HOST_DEVICESEEK"); - case RP_IPC_TO_HOST_CLOSE: return TEXT("RP_IPC_TO_HOST_CLOSE"); - case RP_IPC_TO_HOST_DEVICEREADWRITE: return TEXT("RP_IPC_TO_HOST_DEVICEREADWRITE"); - case RP_IPC_TO_HOST_HOSTVERSION: return TEXT("RP_IPC_TO_HOST_HOSTVERSION"); - case RP_IPC_TO_HOST_INPUTDEVICE: return TEXT("RP_IPC_TO_HOST_INPUTDEVICE"); - case RP_IPC_TO_GUEST_CLOSE: return TEXT("RP_IPC_TO_GUEST_CLOSE"); - case RP_IPC_TO_GUEST_SCREENMODE: return TEXT("RP_IPC_TO_GUEST_SCREENMODE"); - case RP_IPC_TO_GUEST_SCREENCAPTURE: return TEXT("RP_IPC_TO_GUEST_SCREENCAPTURE"); - case RP_IPC_TO_GUEST_PAUSE: return TEXT("RP_IPC_TO_GUEST_PAUSE"); - case RP_IPC_TO_GUEST_DEVICEACTIVITY: return TEXT("RP_IPC_TO_GUEST_DEVICEACTIVITY"); - case RP_IPC_TO_GUEST_DEVICECONTENT: return TEXT("RP_IPC_TO_GUEST_DEVICECONTENT"); - case RP_IPC_TO_GUEST_RESET: return TEXT("RP_IPC_TO_GUEST_RESET"); - case RP_IPC_TO_GUEST_TURBO: return TEXT("RP_IPC_TO_GUEST_TURBO"); - case RP_IPC_TO_GUEST_PING: return TEXT("RP_IPC_TO_GUEST_PING"); - case RP_IPC_TO_GUEST_VOLUME: return TEXT("RP_IPC_TO_GUEST_VOLUME"); + case RP_IPC_TO_HOST_PARENT: return TEXT("RP_IPC_TO_HOST_PARENT"); + case RP_IPC_TO_HOST_DEVICESEEK: return TEXT("RP_IPC_TO_HOST_DEVICESEEK"); + case RP_IPC_TO_HOST_CLOSE: return TEXT("RP_IPC_TO_HOST_CLOSE"); + case RP_IPC_TO_HOST_DEVICEREADWRITE: return TEXT("RP_IPC_TO_HOST_DEVICEREADWRITE"); + case RP_IPC_TO_HOST_HOSTVERSION: return TEXT("RP_IPC_TO_HOST_HOSTVERSION"); + case RP_IPC_TO_HOST_INPUTDEVICE: return TEXT("RP_IPC_TO_HOST_INPUTDEVICE"); + case RP_IPC_TO_GUEST_CLOSE: return TEXT("RP_IPC_TO_GUEST_CLOSE"); + case RP_IPC_TO_GUEST_SCREENMODE: return TEXT("RP_IPC_TO_GUEST_SCREENMODE"); + case RP_IPC_TO_GUEST_SCREENCAPTURE: return TEXT("RP_IPC_TO_GUEST_SCREENCAPTURE"); + case RP_IPC_TO_GUEST_PAUSE: return TEXT("RP_IPC_TO_GUEST_PAUSE"); + case RP_IPC_TO_GUEST_DEVICEACTIVITY: return TEXT("RP_IPC_TO_GUEST_DEVICEACTIVITY"); + case RP_IPC_TO_GUEST_DEVICECONTENT: return TEXT("RP_IPC_TO_GUEST_DEVICECONTENT"); + case RP_IPC_TO_GUEST_RESET: return TEXT("RP_IPC_TO_GUEST_RESET"); + case RP_IPC_TO_GUEST_TURBO: return TEXT("RP_IPC_TO_GUEST_TURBO"); + case RP_IPC_TO_GUEST_PING: return TEXT("RP_IPC_TO_GUEST_PING"); + case RP_IPC_TO_GUEST_VOLUME: return TEXT("RP_IPC_TO_GUEST_VOLUME"); #ifndef FELLOW_SUPPORT_RP_API_VERSION_71 - case RP_IPC_TO_GUEST_ESCAPEKEY: return TEXT("RP_IPC_TO_GUEST_ESCAPEKEY"); + case RP_IPC_TO_GUEST_ESCAPEKEY: return TEXT("RP_IPC_TO_GUEST_ESCAPEKEY"); #endif - case RP_IPC_TO_GUEST_EVENT: return TEXT("RP_IPC_TO_GUEST_EVENT"); - case RP_IPC_TO_GUEST_MOUSECAPTURE: return TEXT("RP_IPC_TO_GUEST_MOUSECAPTURE"); - case RP_IPC_TO_GUEST_SAVESTATE: return TEXT("RP_IPC_TO_GUEST_SAVESTATE"); - case RP_IPC_TO_GUEST_LOADSTATE: return TEXT("RP_IPC_TO_GUEST_LOADSTATE"); - case RP_IPC_TO_GUEST_FLUSH: return TEXT("RP_IPC_TO_GUEST_FLUSH"); - case RP_IPC_TO_GUEST_DEVICEREADWRITE: return TEXT("RP_IPC_TO_GUEST_DEVICEREADWRITE"); - case RP_IPC_TO_GUEST_QUERYSCREENMODE: return TEXT("RP_IPC_TO_GUEST_QUERYSCREENMODE"); - case RP_IPC_TO_GUEST_GUESTAPIVERSION : return TEXT("RP_IPC_TO_GUEST_GUESTAPIVERSION"); + case RP_IPC_TO_GUEST_EVENT: return TEXT("RP_IPC_TO_GUEST_EVENT"); + case RP_IPC_TO_GUEST_MOUSECAPTURE: return TEXT("RP_IPC_TO_GUEST_MOUSECAPTURE"); + case RP_IPC_TO_GUEST_SAVESTATE: return TEXT("RP_IPC_TO_GUEST_SAVESTATE"); + case RP_IPC_TO_GUEST_LOADSTATE: return TEXT("RP_IPC_TO_GUEST_LOADSTATE"); + case RP_IPC_TO_GUEST_FLUSH: return TEXT("RP_IPC_TO_GUEST_FLUSH"); + case RP_IPC_TO_GUEST_DEVICEREADWRITE: return TEXT("RP_IPC_TO_GUEST_DEVICEREADWRITE"); + case RP_IPC_TO_GUEST_QUERYSCREENMODE: return TEXT("RP_IPC_TO_GUEST_QUERYSCREENMODE"); + case RP_IPC_TO_GUEST_GUESTAPIVERSION: return TEXT("RP_IPC_TO_GUEST_GUESTAPIVERSION"); default: return TEXT("UNKNOWN"); } } @@ -760,8 +794,7 @@ ULONGLONG RetroPlatform::GetTime() ULARGE_INTEGER li; GetSystemTime(&st); - if(!SystemTimeToFileTime (&st, &ft)) - return 0; + if (!SystemTimeToFileTime(&st, &ft)) return 0; li.LowPart = ft.dwLowDateTime; li.HighPart = ft.dwHighDateTime; return li.QuadPart / 10000; @@ -770,34 +803,44 @@ ULONGLONG RetroPlatform::GetTime() /** Send an IPC message to RetroPlatform host. * @return true is sucessfully sent, false otherwise. */ -bool RetroPlatform::SendMessageToHost(uint32_t iMessage, WPARAM wParam, LPARAM lParam, - LPCVOID pData, DWORD dwDataSize, const RPGUESTINFO *pGuestInfo, LRESULT *plResult) +bool RetroPlatform::SendMessageToHost(uint32_t iMessage, WPARAM wParam, LPARAM lParam, LPCVOID pData, DWORD dwDataSize, const RPGUESTINFO *pGuestInfo, LRESULT *plResult) { bool bResult = RPSendMessage(iMessage, wParam, lParam, pData, dwDataSize, pGuestInfo, plResult) ? true : false; - + #ifdef _DEBUG - if(bResult) - fellowAddLog("RetroPlatform::SendMessageToHost(): sent message ([%s], %08x, %08x, %08x, %d)\n", - RetroPlatform::GetMessageText(iMessage), iMessage - WM_APP, wParam, lParam, pData); + if (bResult) + fellowAddLog( + "RetroPlatform::SendMessageToHost(): sent message ([%s], " + "%08x, %08x, %08x, %d)\n", + RetroPlatform::GetMessageText(iMessage), + iMessage - WM_APP, + wParam, + lParam, + pData); else - fellowAddLog("RetroPlatform::SendMessageToHost(): could not send message, error: %d\n", GetLastError()); + fellowAddLog( + "RetroPlatform::SendMessageToHost(): could not send message, " + "error: %d\n", + GetLastError()); #endif return bResult; } -uint32_t RetroPlatform::GetClippingOffsetLeftAdjusted() +uint32_t RetroPlatform::GetClippingOffsetLeftAdjusted() { uint32_t lClippingOffsetLeft = lClippingOffsetLeftRP; - - if(lClippingOffsetLeft >= RETRO_PLATFORM_OFFSET_ADJUST_LEFT) - lClippingOffsetLeft = (lClippingOffsetLeft - RETRO_PLATFORM_OFFSET_ADJUST_LEFT); + + if (lClippingOffsetLeft >= RETRO_PLATFORM_OFFSET_ADJUST_LEFT) lClippingOffsetLeft = (lClippingOffsetLeft - RETRO_PLATFORM_OFFSET_ADJUST_LEFT); lClippingOffsetLeft /= 2; #ifdef _DEBUGVERBOSE - fellowAddLog("RetroPlatform::GetClippingOffsetLeftAdjusted(): left offset adjusted from %u to %u\n", - lClippingOffsetLeftRP, lClippingOffsetLeft); + fellowAddLog( + "RetroPlatform::GetClippingOffsetLeftAdjusted(): left offset " + "adjusted from %u to %u\n", + lClippingOffsetLeftRP, + lClippingOffsetLeft); #endif return lClippingOffsetLeft; @@ -807,28 +850,30 @@ uint32_t RetroPlatform::GetClippingOffsetTopAdjusted() { uint32_t lClippingOffsetTop = lClippingOffsetTopRP; - if(lClippingOffsetTop >= RETRO_PLATFORM_OFFSET_ADJUST_TOP) - lClippingOffsetTop -= RETRO_PLATFORM_OFFSET_ADJUST_TOP; + if (lClippingOffsetTop >= RETRO_PLATFORM_OFFSET_ADJUST_TOP) lClippingOffsetTop -= RETRO_PLATFORM_OFFSET_ADJUST_TOP; #ifdef _DEBUGVERBOSE - fellowAddLog("RetroPlatform::GetClippingOffsetTopAdjusted(): top offset adjusted from %u to %u\n", - lClippingOffsetTopRP, lClippingOffsetTop); + fellowAddLog( + "RetroPlatform::GetClippingOffsetTopAdjusted(): top offset " + "adjusted from %u to %u\n", + lClippingOffsetTopRP, + lClippingOffsetTop); #endif - + return lClippingOffsetTop; } -uint32_t RetroPlatform::GetClippingOffsetLeft() +uint32_t RetroPlatform::GetClippingOffsetLeft() { return lClippingOffsetLeftRP; } -uint32_t RetroPlatform::GetClippingOffsetTop() +uint32_t RetroPlatform::GetClippingOffsetTop() { return lClippingOffsetTopRP; } -uint32_t RetroPlatform::GetScreenHeightAdjusted() +uint32_t RetroPlatform::GetScreenHeightAdjusted() { uint32_t lScreenHeight = lScreenHeightRP; @@ -847,10 +892,10 @@ uint32_t RetroPlatform::GetCPUSpeed() return cfgGetCPUSpeed(pConfig); } -uint32_t RetroPlatform::GetScreenWidthAdjusted() +uint32_t RetroPlatform::GetScreenWidthAdjusted() { uint32_t lScreenWidth = 0; - + lScreenWidth = lScreenWidthRP / 2 * RetroPlatform::GetDisplayScale(); return lScreenWidth; @@ -861,55 +906,52 @@ uint32_t RetroPlatform::GetSourceBufferWidth() return lScreenWidthRP / 2; } -uint32_t RetroPlatform::GetScreenWidth() +uint32_t RetroPlatform::GetScreenWidth() { return lScreenWidthRP; } -bool RetroPlatform::GetScreenWindowed() +bool RetroPlatform::GetScreenWindowed() { return bScreenWindowed; } -bool RetroPlatform::GetScanlines() +bool RetroPlatform::GetScanlines() { return bScanlines; } -uint32_t RetroPlatform::GetScreenHeight() +uint32_t RetroPlatform::GetScreenHeight() { - return lScreenHeightRP; + return lScreenHeightRP; } -/** Translate the screenmode configured in the configuration file and pass it along to the RetroPlatform Player. +/** Translate the screenmode configured in the configuration file and pass it + * along to the RetroPlatform Player. */ -void RetroPlatform::DetermineScreenModeFromConfig(struct RPScreenMode *RetroPlatformScreenMode, cfg *RetroPlatformConfig) +void RetroPlatform::DetermineScreenModeFromConfig(struct RPScreenMode *RetroPlatformScreenMode, cfg *RetroPlatformConfig) { DWORD dwScreenMode = 0; - if(RP.GetDisplayScale() == 1) - dwScreenMode |= RP_SCREENMODE_SCALE_1X; - if(RP.GetDisplayScale() == 2) - dwScreenMode |= RP_SCREENMODE_SCALE_2X; - if(RP.GetDisplayScale() == 3) - dwScreenMode |= RP_SCREENMODE_SCALE_3X; - if(RP.GetDisplayScale() == 4) - dwScreenMode |= RP_SCREENMODE_SCALE_4X; + if (RP.GetDisplayScale() == 1) dwScreenMode |= RP_SCREENMODE_SCALE_1X; + if (RP.GetDisplayScale() == 2) dwScreenMode |= RP_SCREENMODE_SCALE_2X; + if (RP.GetDisplayScale() == 3) dwScreenMode |= RP_SCREENMODE_SCALE_3X; + if (RP.GetDisplayScale() == 4) dwScreenMode |= RP_SCREENMODE_SCALE_4X; - if(RP.GetScreenWindowed()) + if (RP.GetScreenWindowed()) dwScreenMode |= RP_SCREENMODE_DISPLAY_WINDOW; else dwScreenMode |= RP_SCREENMODE_DISPLAY_FULLSCREEN_1; - RetroPlatformScreenMode->dwScreenMode = dwScreenMode; - RetroPlatformScreenMode->hGuestWindow = hGuestWindow; + RetroPlatformScreenMode->dwScreenMode = dwScreenMode; + RetroPlatformScreenMode->hGuestWindow = hGuestWindow; RetroPlatformScreenMode->lTargetHeight = RP.GetScreenHeight(); - RetroPlatformScreenMode->lTargetWidth = RP.GetScreenWidth(); - RetroPlatformScreenMode->lClipLeft = RP.GetClippingOffsetLeft(); - RetroPlatformScreenMode->lClipTop = RP.GetClippingOffsetTop(); - RetroPlatformScreenMode->lClipWidth = RP.GetScreenWidth(); - RetroPlatformScreenMode->lClipHeight = RP.GetScreenHeight(); - RetroPlatformScreenMode->dwClipFlags = 0; + RetroPlatformScreenMode->lTargetWidth = RP.GetScreenWidth(); + RetroPlatformScreenMode->lClipLeft = RP.GetClippingOffsetLeft(); + RetroPlatformScreenMode->lClipTop = RP.GetClippingOffsetTop(); + RetroPlatformScreenMode->lClipWidth = RP.GetScreenWidth(); + RetroPlatformScreenMode->lClipHeight = RP.GetScreenHeight(); + RetroPlatformScreenMode->dwClipFlags = 0; } bool RetroPlatform::GetEmulationPaused() @@ -923,7 +965,7 @@ uint32_t RetroPlatform::GetDisplayScale() } /** Determine the RetroPlatform host version. - * + * * @param[out] lpMainVersion main version number * @param[out] lpRevision revision number * @param[out] lpBuild build number @@ -933,28 +975,28 @@ bool RetroPlatform::GetHostVersion(uint32_t *lpMainVersion, uint32_t *lpRevision { LRESULT lResult = 0; - if(!RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_HOSTVERSION, 0, 0, nullptr, 0, &GuestInfo, (LRESULT*) &lResult)) - return false; + if (!RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_HOSTVERSION, 0, 0, nullptr, 0, &GuestInfo, (LRESULT *)&lResult)) return false; *lpMainVersion = RP_HOSTVERSION_MAJOR(lResult); - *lpRevision = RP_HOSTVERSION_MINOR(lResult); - *lpBuild = RP_HOSTVERSION_BUILD(lResult); + *lpRevision = RP_HOSTVERSION_MINOR(lResult); + *lpBuild = RP_HOSTVERSION_BUILD(lResult); return true; } /** Verify if the emulator is operating in RetroPlatform mode. - * + * * Checks the value of the bRetroPlatformMode flag. It is set to true, if a * RetroPlatform host ID has been passed along as a commandline parameter. - * @return true if WinFellow was called from Cloanto RetroPlatform, false if not. + * @return true if WinFellow was called from Cloanto RetroPlatform, false if + * not. */ -bool RetroPlatform::GetHeadlessMode() +bool RetroPlatform::GetHeadlessMode() { return bRetroPlatformMode; } /** Asynchronously post a message to the RetroPlatform host. - * + * * A message is posted to the host asynchronously, i.e. without waiting for * results. */ @@ -964,15 +1006,23 @@ bool RetroPlatform::PostMessageToHost(uint32_t iMessage, WPARAM wParam, LPARAM l #ifdef _DEBUG #ifndef RETRO_PLATFORM_LOG_VERBOSE - if(iMessage != RP_IPC_TO_HOST_DEVICESEEK && iMessage != RP_IPC_TO_HOST_DEVICEACTIVITY) + if (iMessage != RP_IPC_TO_HOST_DEVICESEEK && iMessage != RP_IPC_TO_HOST_DEVICEACTIVITY) { #endif !RETRO_PLATFORM_LOG_VERBOSE - if(bResult) - fellowAddLog("RetroPlatform::PostMessageToHost() posted message ([%s], %08x, %08x, %08x)\n", - RetroPlatform::GetMessageText(iMessage), iMessage - WM_APP, wParam, lParam); - else - fellowAddLog("RetroPlatform::PostMessageToHost() could not post message, error: %d\n", GetLastError()); + if (bResult) + fellowAddLog( + "RetroPlatform::PostMessageToHost() posted message ([%s], " + "%08x, %08x, %08x)\n", + RetroPlatform::GetMessageText(iMessage), + iMessage - WM_APP, + wParam, + lParam); + else + fellowAddLog( + "RetroPlatform::PostMessageToHost() could not post message, " + "error: %d\n", + GetLastError()); #ifndef RETRO_PLATFORM_LOG_VERBOSE } @@ -982,11 +1032,12 @@ bool RetroPlatform::PostMessageToHost(uint32_t iMessage, WPARAM wParam, LPARAM l return bResult; } -/** Post message to the player to signalize that the guest wants to escape the mouse cursor. +/** Post message to the player to signalize that the guest wants to escape the + * mouse cursor. */ #ifndef FELLOW_SUPPORT_RP_API_VERSION_71 -bool RetroPlatform::PostEscaped() +bool RetroPlatform::PostEscaped() { return RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_ESCAPED, 0, 0, &GuestInfo); } @@ -995,13 +1046,14 @@ bool RetroPlatform::PostEscaped() /** Control status of the RetroPlatform hard drive LEDs. * - * Sends LED status changes to the RetroPlatform host in the form of RP_IPC_TO_HOST_DEVICEACTIVITY messages, - * so that hard drive read and write activity can be displayed, and detected (undo functionality uses write + * Sends LED status changes to the RetroPlatform host in the form of + * RP_IPC_TO_HOST_DEVICEACTIVITY messages, so that hard drive read and write + * activity can be displayed, and detected (undo functionality uses write * messages as fallback method to detect changed floppy images). * @param[in] lHardDriveNo hard drive index (0-...) * @param[in] bActive flag indicating disk access (active/inactive) * @param[in] bWriteActivity flag indicating type of access (write/read) - * @return true if message sent successfully, false otherwise. + * @return true if message sent successfully, false otherwise. * @callergraph */ bool RetroPlatform::PostHardDriveLED(const uint32_t lHardDriveNo, const bool bActive, const bool bWriteActivity) @@ -1009,23 +1061,23 @@ bool RetroPlatform::PostHardDriveLED(const uint32_t lHardDriveNo, const bool bAc static int oldleds[FHFILE_MAX_DEVICES]; static ULONGLONG lastsent[FHFILE_MAX_DEVICES]; - if(!bInitialized) - return false; + if (!bInitialized) return false; int state = bActive ? 1 : 0; state |= bWriteActivity ? 2 : 0; - if (state == oldleds[lHardDriveNo]) + if (state == oldleds[lHardDriveNo]) return true; else oldleds[lHardDriveNo] = state; - if (bActive && (lastsent[lHardDriveNo] + RETRO_PLATFORM_HARDDRIVE_BLINK_MSECS < RetroPlatform::GetTime()) - || (bActive && bWriteActivity)) - { - RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_DEVICEACTIVITY, MAKEWORD (RP_DEVICECATEGORY_HD, lHardDriveNo), - MAKELONG (RETRO_PLATFORM_HARDDRIVE_BLINK_MSECS, bWriteActivity ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ), - &GuestInfo); + if (bActive && (lastsent[lHardDriveNo] + RETRO_PLATFORM_HARDDRIVE_BLINK_MSECS < RetroPlatform::GetTime()) || (bActive && bWriteActivity)) + { + RetroPlatform::PostMessageToHost( + RP_IPC_TO_HOST_DEVICEACTIVITY, + MAKEWORD(RP_DEVICECATEGORY_HD, lHardDriveNo), + MAKELONG(RETRO_PLATFORM_HARDDRIVE_BLINK_MSECS, bWriteActivity ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ), + &GuestInfo); lastsent[lHardDriveNo] = RetroPlatform::GetTime(); } else @@ -1035,29 +1087,32 @@ bool RetroPlatform::PostHardDriveLED(const uint32_t lHardDriveNo, const bool bAc /** Control status of the RetroPlatform floppy drive LEDs. * - * Sends LED status changes to the RetroPlatform host in the form of RP_IPC_TO_HOST_DEVICEACTIVITY messages, - * so that floppy read and write activity can be displayed, and detected (undo functionality uses write + * Sends LED status changes to the RetroPlatform host in the form of + * RP_IPC_TO_HOST_DEVICEACTIVITY messages, so that floppy read and write + * activity can be displayed, and detected (undo functionality uses write * messages as fallback method to detect changed floppy images). * @param[in] lFloppyDriveNo floppy drive index (0-3) * @param[in] bMotorActive state of floppy drive motor (active/inactive) * @param[in] bWriteActivity type of access (write/read) - * @return true if message sent successfully, false otherwise. + * @return true if message sent successfully, false otherwise. * @callergraph */ bool RetroPlatform::PostFloppyDriveLED(const uint32_t lFloppyDriveNo, const bool bMotorActive, const bool bWriteActivity) { - if(lFloppyDriveNo > 3) - return false; + if (lFloppyDriveNo > 3) return false; - return RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_DEVICEACTIVITY, MAKEWORD (RP_DEVICECATEGORY_FLOPPY, lFloppyDriveNo), - MAKELONG (bMotorActive ? -1 : 0, (bWriteActivity) ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ) , &GuestInfo); + return RetroPlatform::PostMessageToHost( + RP_IPC_TO_HOST_DEVICEACTIVITY, + MAKEWORD(RP_DEVICECATEGORY_FLOPPY, lFloppyDriveNo), + MAKELONG(bMotorActive ? -1 : 0, (bWriteActivity) ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ), + &GuestInfo); } /** Send content of floppy drive to RetroPlatform host. - * The read-only state is determined and sent here, however at this point + * The read-only state is determined and sent here, however at this point * it is usually wrong, as floppySetDiskImage only reflects the ability to write * to the file in the writeprot flag. - * The actual state within the config is configured in a separate call within + * The actual state within the config is configured in a separate call within * cfgManagerConfigurationActivate - therefore an update message is sent later. * @param[in] lFloppyDriveNo floppy drive index (0-3) * @param[in] szImageName ANSI string containing the floppy image name @@ -1066,22 +1121,20 @@ bool RetroPlatform::PostFloppyDriveLED(const uint32_t lFloppyDriveNo, const bool * @sa RetroPlatformSendFloppyDriveReadOnly * @callergraph */ -bool RetroPlatform::SendFloppyDriveContent(const uint32_t lFloppyDriveNo, const char *szImageName, const bool bWriteProtected) +bool RetroPlatform::SendFloppyDriveContent(const uint32_t lFloppyDriveNo, const char *szImageName, const bool bWriteProtected) { bool bResult; - struct RPDeviceContent rpDeviceContent = { 0 }; + struct RPDeviceContent rpDeviceContent = {0}; - if (!bInitialized) - return false; + if (!bInitialized) return false; - if(!floppy[lFloppyDriveNo].enabled) - return false; + if (!floppy[lFloppyDriveNo].enabled) return false; rpDeviceContent.btDeviceCategory = RP_DEVICECATEGORY_FLOPPY; rpDeviceContent.btDeviceNumber = lFloppyDriveNo; rpDeviceContent.dwInputDevice = 0; - - if (szImageName) + + if (szImageName) mbstowcs(rpDeviceContent.szContent, szImageName, CFG_FILENAME_LENGTH); else wcscpy(rpDeviceContent.szContent, L""); @@ -1089,18 +1142,19 @@ bool RetroPlatform::SendFloppyDriveContent(const uint32_t lFloppyDriveNo, const rpDeviceContent.dwFlags = (bWriteProtected ? RP_DEVICEFLAGS_RW_READONLY : RP_DEVICEFLAGS_RW_READWRITE); #ifdef _DEBUG - fellowAddLog("RetroPlatform::SendFloppyDriveContent(): RP_IPC_TO_HOST_DEVICECONTENT cat=%d num=%d type=%d '%s'\n", - rpDeviceContent.btDeviceCategory, rpDeviceContent.btDeviceNumber, - rpDeviceContent.dwInputDevice, szImageName); + fellowAddLog( + "RetroPlatform::SendFloppyDriveContent(): " + "RP_IPC_TO_HOST_DEVICECONTENT cat=%d num=%d type=%d '%s'\n", + rpDeviceContent.btDeviceCategory, + rpDeviceContent.btDeviceNumber, + rpDeviceContent.dwInputDevice, + szImageName); #endif - bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICECONTENT, 0, 0, - &rpDeviceContent, sizeof(struct RPDeviceContent), &GuestInfo, - nullptr); + bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICECONTENT, 0, 0, &rpDeviceContent, sizeof(struct RPDeviceContent), &GuestInfo, nullptr); + + fellowAddLog("RetroPlatform::SendFloppyDriveContent(%d, '%s'): %s.\n", lFloppyDriveNo, szImageName, bResult ? "successful" : "failed"); - fellowAddLog("RetroPlatform::SendFloppyDriveContent(%d, '%s'): %s.\n", - lFloppyDriveNo, szImageName, bResult ? "successful" : "failed"); - return bResult; } @@ -1113,20 +1167,21 @@ bool RetroPlatform::SendFloppyDriveContent(const uint32_t lFloppyDriveNo, const */ bool RetroPlatform::SendFloppyDriveReadOnly(const uint32_t lFloppyDriveNo, const bool bWriteProtected) { - if(!bInitialized) - return false; + if (!bInitialized) return false; - if(!floppy[lFloppyDriveNo].enabled) - return false; + if (!floppy[lFloppyDriveNo].enabled) return false; + + bool bResult = RetroPlatform::SendMessageToHost( + RP_IPC_TO_HOST_DEVICEREADWRITE, + MAKEWORD(RP_DEVICECATEGORY_FLOPPY, lFloppyDriveNo), + bWriteProtected ? RP_DEVICE_READONLY : RP_DEVICE_READWRITE, + nullptr, + 0, + &GuestInfo, + nullptr); - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICEREADWRITE, - MAKEWORD(RP_DEVICECATEGORY_FLOPPY, lFloppyDriveNo), - bWriteProtected ? RP_DEVICE_READONLY : RP_DEVICE_READWRITE, nullptr, - 0, &GuestInfo, nullptr); + fellowAddLog("RetroPlatform::SendFloppyDriveReadOnly(): %s.\n", bResult ? "successful" : "failed"); - fellowAddLog("RetroPlatform::SendFloppyDriveReadOnly(): %s.\n", - bResult ? "successful" : "failed"); - return bResult; } @@ -1135,24 +1190,22 @@ bool RetroPlatform::SendFloppyDriveReadOnly(const uint32_t lFloppyDriveNo, const * @return true if message sent successfully, false otherwise. * @callergraph */ -bool RetroPlatform::SendFloppyTurbo(const bool bTurbo) +bool RetroPlatform::SendFloppyTurbo(const bool bTurbo) { - if(!bInitialized) - return false; + if (!bInitialized) return false; + + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_TURBO, RP_TURBO_FLOPPY, bTurbo ? RP_TURBO_FLOPPY : 0, nullptr, 0, &GuestInfo, nullptr); - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_TURBO, RP_TURBO_FLOPPY, - bTurbo ? RP_TURBO_FLOPPY : 0, nullptr, 0, &GuestInfo, nullptr); + fellowAddLog("RetroPlatform::SendFloppyDriveTurbo(): %s.\n", bResult ? "successful" : "failed"); - fellowAddLog("RetroPlatform::SendFloppyDriveTurbo(): %s.\n", - bResult ? "successful" : "failed"); - return bResult; } /** * Send floppy drive seek events to RetroPlatform host. - * - * Will notify the RetroPlatform player about changes in the drive head position. + * + * Will notify the RetroPlatform player about changes in the drive head + * position. * @param[in] lFloppyDriveNo index of floppy drive * @param[in] lTrackNo index of floppy track * @return true if message sent successfully, false otherwise. @@ -1160,32 +1213,27 @@ bool RetroPlatform::SendFloppyTurbo(const bool bTurbo) */ bool RetroPlatform::PostFloppyDriveSeek(const uint32_t lFloppyDriveNo, const uint32_t lTrackNo) { - if (!bInitialized) - return false; + if (!bInitialized) return false; - return RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_DEVICESEEK, - MAKEWORD (RP_DEVICECATEGORY_FLOPPY, lFloppyDriveNo), lTrackNo, &GuestInfo); + return RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_DEVICESEEK, MAKEWORD(RP_DEVICECATEGORY_FLOPPY, lFloppyDriveNo), lTrackNo, &GuestInfo); } -/** +/** * Send gameport activity to RetroPlatform host. */ bool RetroPlatform::PostGameportActivity(const uint32_t lGameport, const uint32_t lGameportMask) { - bool bResult; + bool bResult; #ifdef _DEBUG fellowAddLog("RetroPlatform::PostGameportActivity(): lGameport=%u, lGameportMask=%u\n", lGameport, lGameportMask); #endif - if (!bInitialized) - return false; - - if (lGameport >= RETRO_PLATFORM_NUM_GAMEPORTS) - return false; + if (!bInitialized) return false; - bResult = RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_DEVICEACTIVITY, MAKEWORD(RP_DEVICECATEGORY_INPUTPORT, lGameport), - lGameportMask, &GuestInfo); + if (lGameport >= RETRO_PLATFORM_NUM_GAMEPORTS) return false; + + bResult = RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_DEVICEACTIVITY, MAKEWORD(RP_DEVICECATEGORY_INPUTPORT, lGameport), lGameportMask, &GuestInfo); return bResult; } @@ -1197,19 +1245,18 @@ bool RetroPlatform::PostGameportActivity(const uint32_t lGameport, const uint32_ * @return true if message sent successfully, false otherwise. * @callergraph */ -bool RetroPlatform::SendHardDriveContent(const uint32_t lHardDriveNo, const char *szImageName, const bool bWriteProtected) +bool RetroPlatform::SendHardDriveContent(const uint32_t lHardDriveNo, const char *szImageName, const bool bWriteProtected) { bool bResult; - struct RPDeviceContent rpDeviceContent = { 0 }; + struct RPDeviceContent rpDeviceContent = {0}; - if (!bInitialized) - return false; + if (!bInitialized) return false; rpDeviceContent.btDeviceCategory = RP_DEVICECATEGORY_HD; rpDeviceContent.btDeviceNumber = lHardDriveNo; rpDeviceContent.dwInputDevice = 0; - if (szImageName) + if (szImageName) mbstowcs(rpDeviceContent.szContent, szImageName, CFG_FILENAME_LENGTH); else wcscpy(rpDeviceContent.szContent, L""); @@ -1217,66 +1264,72 @@ bool RetroPlatform::SendHardDriveContent(const uint32_t lHardDriveNo, const char rpDeviceContent.dwFlags = (bWriteProtected ? RP_DEVICEFLAGS_RW_READONLY : RP_DEVICEFLAGS_RW_READWRITE); #ifdef _DEBUG - fellowAddLog("RP_IPC_TO_HOST_DEVICECONTENT cat=%d num=%d type=%d '%s'\n", - rpDeviceContent.btDeviceCategory, rpDeviceContent.btDeviceNumber, - rpDeviceContent.dwInputDevice, rpDeviceContent.szContent); + fellowAddLog( + "RP_IPC_TO_HOST_DEVICECONTENT cat=%d num=%d type=%d '%s'\n", + rpDeviceContent.btDeviceCategory, + rpDeviceContent.btDeviceNumber, + rpDeviceContent.dwInputDevice, + rpDeviceContent.szContent); #endif - bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICECONTENT, 0, 0, - &rpDeviceContent, sizeof(struct RPDeviceContent), &GuestInfo, - nullptr); + bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICECONTENT, 0, 0, &rpDeviceContent, sizeof(struct RPDeviceContent), &GuestInfo, nullptr); + + fellowAddLog("RetroPlatform::SendHardDriveContent(%d, '%s'): %s.\n", lHardDriveNo, szImageName, bResult ? "successful" : "failed"); - fellowAddLog("RetroPlatform::SendHardDriveContent(%d, '%s'): %s.\n", - lHardDriveNo, szImageName, bResult ? "successful" : "failed"); - return bResult; } /** Control status of power LED in RetroPlatform player. * - * Examines the current on/off state of the emulator session and sends it to the RetroPlatform player. - * @param[in] wIntensityPercent intensity of the power LED in percent, with 0 being off, 100 being full intensity. + * Examines the current on/off state of the emulator session and sends it to the + * RetroPlatform player. + * @param[in] wIntensityPercent intensity of the power LED in percent, with 0 + * being off, 100 being full intensity. * @return true, if valid value was passed, false if invalid value. */ bool RetroPlatform::PostPowerLEDIntensityPercent(const WPARAM wIntensityPercent) { - if(wIntensityPercent <= 100 && wIntensityPercent >= 0) + if (wIntensityPercent <= 100 && wIntensityPercent >= 0) return RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_POWERLED, wIntensityPercent, 0, &GuestInfo); else return false; } /** Set RetroPlatform escape key. - * - * Called during parsing of the command-line parameters, which is why the keyboard modules - * have to be initialized before the config modules, as we use the key mappings here. + * + * Called during parsing of the command-line parameters, which is why the + * keyboard modules have to be initialized before the config modules, as we use + * the key mappings here. */ -void RetroPlatform::SetEscapeKey(const uint32_t lNewEscapeKey) +void RetroPlatform::SetEscapeKey(const uint32_t lNewEscapeKey) { lEscapeKey = lNewEscapeKey; fellowAddLog("RetroPlatform::SetEscapeKey(): escape key configured to %s.\n", kbdDrvKeyString(lEscapeKey)); } -void RetroPlatform::SetEscapeKeyHoldTime(const uint32_t lNewEscapeKeyHoldtime) +void RetroPlatform::SetEscapeKeyHoldTime(const uint32_t lNewEscapeKeyHoldtime) { lEscapeKeyHoldTime = lNewEscapeKeyHoldtime; - fellowAddLog("RetroPlatform::SetEscapeKeyHoldTime(): escape hold time configured to %d.\n", lEscapeKeyHoldTime); + fellowAddLog( + "RetroPlatform::SetEscapeKeyHoldTime(): escape hold time " + "configured to %d.\n", + lEscapeKeyHoldTime); } -ULONGLONG RetroPlatform::SetEscapeKeyHeld(const bool bEscapeKeyHeld) +ULONGLONG RetroPlatform::SetEscapeKeyHeld(const bool bEscapeKeyHeld) { ULONGLONG t = 0; - if(bEscapeKeyHeld) + if (bEscapeKeyHeld) { - if(lEscapeKeyHeldSince == 0) + if (lEscapeKeyHeldSince == 0) { lEscapeKeyHeldSince = RetroPlatform::GetTime(); } } else { - if(lEscapeKeyHeldSince) + if (lEscapeKeyHeldSince) { t = RetroPlatform::GetTime() - lEscapeKeyHeldSince; lEscapeKeyHeldSince = 0; @@ -1285,14 +1338,14 @@ ULONGLONG RetroPlatform::SetEscapeKeyHeld(const bool bEscapeKeyHeld) return t; } -void RetroPlatform::SetEscapeKeySimulatedTargetTime(const ULONGLONG tTargetTime) +void RetroPlatform::SetEscapeKeySimulatedTargetTime(const ULONGLONG tTargetTime) { lEscapeKeySimulatedTargetTime = tTargetTime; } void RetroPlatform::SetEmulationState(const bool bNewState) { - if(bEmulationState != bNewState) + if (bEmulationState != bNewState) { bEmulationState = bNewState; fellowAddLog("RetroPlatform::SetEmulationState(%s).\n", bNewState ? "active" : "inactive"); @@ -1302,30 +1355,28 @@ void RetroPlatform::SetEmulationState(const bool bNewState) void RetroPlatform::SetEmulationPaused(const bool bPaused) { - if(bPaused != bEmulationPaused) + if (bPaused != bEmulationPaused) { bEmulationPaused = bPaused; - fellowAddLog("RetroPlatform::SetEmulationPaused(): emulation is now %s.\n", - bPaused ? "paused" : "active"); + fellowAddLog("RetroPlatform::SetEmulationPaused(): emulation is now %s.\n", bPaused ? "paused" : "active"); } } void RetroPlatform::SetEmulatorQuit(const bool bNewEmulatorQuit) { - bEmulatorQuit = bNewEmulatorQuit; + bEmulatorQuit = bNewEmulatorQuit; - fellowAddLog("RetroPlatform::SetEmulatorQuit(%s).\n", - bNewEmulatorQuit ? "true" : "false"); + fellowAddLog("RetroPlatform::SetEmulatorQuit(%s).\n", bNewEmulatorQuit ? "true" : "false"); } -void RetroPlatform::SetHostID(const char *szNewHostID) +void RetroPlatform::SetHostID(const char *szNewHostID) { strncpy(szHostID, szNewHostID, CFG_FILENAME_LENGTH); fellowAddLog("RetroPlatform::SetHostID(): host ID configured to %s.\n", szHostID); } -void RetroPlatform::SetHeadlessMode(const bool bRPMode) +void RetroPlatform::SetHeadlessMode(const bool bRPMode) { bRetroPlatformMode = bRPMode; @@ -1341,43 +1392,39 @@ void RetroPlatform::SetScanlines(const bool bNewScanlines) /** Set screen height. */ -void RetroPlatform::SetScreenHeight(const uint32_t lHeight) +void RetroPlatform::SetScreenHeight(const uint32_t lHeight) { lScreenHeightRP = lHeight; - fellowAddLog("RetroPlatform::SetScreenHeight(): height configured to %u\n", - lScreenHeightRP); + fellowAddLog("RetroPlatform::SetScreenHeight(): height configured to %u\n", lScreenHeightRP); } /** Set screen width. */ -void RetroPlatform::SetScreenWidth(const uint32_t lWidth) +void RetroPlatform::SetScreenWidth(const uint32_t lWidth) { lScreenWidthRP = lWidth; - fellowAddLog("RetroPlatform::SetScreenWidth(): width configured to %u\n", - lScreenWidthRP); + fellowAddLog("RetroPlatform::SetScreenWidth(): width configured to %u\n", lScreenWidthRP); } -void RetroPlatform::SetScreenWindowed(const bool bWindowed) -{ +void RetroPlatform::SetScreenWindowed(const bool bWindowed) +{ bScreenWindowed = bWindowed; - if(pConfig != nullptr) + if (pConfig != nullptr) { cfgSetScreenWindowed(pConfig, bWindowed); } - fellowAddLog("RetroPlatform::SetScreenWindowed(): configured to %s\n", - bWindowed ? "true" : "false"); + fellowAddLog("RetroPlatform::SetScreenWindowed(): configured to %s\n", bWindowed ? "true" : "false"); } -void RetroPlatform::SetDisplayScale(const uint32_t lNewDisplayScale) +void RetroPlatform::SetDisplayScale(const uint32_t lNewDisplayScale) { lDisplayScale = lNewDisplayScale; - fellowAddLog("RetroPlatform::SetDisplayScale(): display scale configured to %u\n", - lDisplayScale); + fellowAddLog("RetroPlatform::SetDisplayScale(): display scale configured to %u\n", lDisplayScale); } void RetroPlatform::SetScreenMode(const char *szScreenMode) @@ -1391,91 +1438,97 @@ void RetroPlatform::SetScreenMode(const char *szScreenMode) switch (lScalingFactor) { - case RP_SCREENMODE_SCALE_1X: - RetroPlatform::SetDisplayScale(1); - break; - case RP_SCREENMODE_SCALE_2X: - RetroPlatform::SetDisplayScale(2); - break; - case RP_SCREENMODE_SCALE_3X: - RetroPlatform::SetDisplayScale(3); - break; - case RP_SCREENMODE_SCALE_4X: - RetroPlatform::SetDisplayScale(4); - break; + case RP_SCREENMODE_SCALE_1X: RetroPlatform::SetDisplayScale(1); break; + case RP_SCREENMODE_SCALE_2X: RetroPlatform::SetDisplayScale(2); break; + case RP_SCREENMODE_SCALE_3X: RetroPlatform::SetDisplayScale(3); break; + case RP_SCREENMODE_SCALE_4X: RetroPlatform::SetDisplayScale(4); break; default: - fellowAddLog("RetroPlatform::SetScreenMode(): WARNING: unknown display scaling factor 0x%x\n", - lScalingFactor); + fellowAddLog( + "RetroPlatform::SetScreenMode(): WARNING: unknown display " + "scaling factor 0x%x\n", + lScalingFactor); } RetroPlatform::SetScanlines((lScreenMode & RP_SCREENMODE_SCANLINES) ? true : false); } -void RetroPlatform::SetScreenModeStruct(struct RPScreenMode *sm) +void RetroPlatform::SetScreenModeStruct(struct RPScreenMode *sm) { uint32_t lScalingFactor = 0, lDisplay = 0; - lScalingFactor = RP_SCREENMODE_SCALE (sm->dwScreenMode); - lDisplay = RP_SCREENMODE_DISPLAY(sm->dwScreenMode); + lScalingFactor = RP_SCREENMODE_SCALE(sm->dwScreenMode); + lDisplay = RP_SCREENMODE_DISPLAY(sm->dwScreenMode); #ifdef _DEBUG - fellowAddLog("RetroPlatform::SetScreenModeStruct(): dwScreenMode=0x%x, dwClipFlags=0x%x, lTargetWidth=%u, lTargetHeight=%u\n", - sm->dwScreenMode, sm->dwClipFlags, sm->lTargetWidth, sm->lTargetHeight); - - fellowAddLog("RetroPlatform::SetScreenModeStruct(): lClipWidth=%u, lClipHeight=%u, lClipLeft=%u, lClipTop=%u\n", - sm->lClipWidth, sm->lClipHeight, sm->lClipLeft, sm->lClipTop); - - fellowAddLog("RetroPlatform::SetScreenModeStruct(): lScalingFactor=0x%x, lDisplay=0x%x\n", - lScalingFactor, lDisplay); + fellowAddLog( + "RetroPlatform::SetScreenModeStruct(): dwScreenMode=0x%x, " + "dwClipFlags=0x%x, lTargetWidth=%u, lTargetHeight=%u\n", + sm->dwScreenMode, + sm->dwClipFlags, + sm->lTargetWidth, + sm->lTargetHeight); + + fellowAddLog( + "RetroPlatform::SetScreenModeStruct(): lClipWidth=%u, " + "lClipHeight=%u, lClipLeft=%u, lClipTop=%u\n", + sm->lClipWidth, + sm->lClipHeight, + sm->lClipLeft, + sm->lClipTop); + + fellowAddLog( + "RetroPlatform::SetScreenModeStruct(): lScalingFactor=0x%x, " + "lDisplay=0x%x\n", + lScalingFactor, + lDisplay); #endif - - if(lDisplay == 0) { + + if (lDisplay == 0) + { RetroPlatform::SetScreenWindowed(true); - switch(lScalingFactor) + switch (lScalingFactor) { - case RP_SCREENMODE_SCALE_1X: - RetroPlatform::SetDisplayScale(1); - break; - case RP_SCREENMODE_SCALE_2X: - RetroPlatform::SetDisplayScale(2); - break; - case RP_SCREENMODE_SCALE_3X: - RetroPlatform::SetDisplayScale(3); - break; - case RP_SCREENMODE_SCALE_4X: - RetroPlatform::SetDisplayScale(4); - break; + case RP_SCREENMODE_SCALE_1X: RetroPlatform::SetDisplayScale(1); break; + case RP_SCREENMODE_SCALE_2X: RetroPlatform::SetDisplayScale(2); break; + case RP_SCREENMODE_SCALE_3X: RetroPlatform::SetDisplayScale(3); break; + case RP_SCREENMODE_SCALE_4X: RetroPlatform::SetDisplayScale(4); break; default: - fellowAddLog("RetroPlatform::SetScreenModeStruct(): WARNING: unknown windowed display scaling factor 0x%x.\n", lScalingFactor); + fellowAddLog( + "RetroPlatform::SetScreenModeStruct(): WARNING: unknown " + "windowed display scaling factor 0x%x.\n", + lScalingFactor); } } - if(lDisplay == 1) + if (lDisplay == 1) { RetroPlatform::SetScreenWindowed(false); - switch(lScalingFactor) + switch (lScalingFactor) { case RP_SCREENMODE_SCALE_MAX: // automatically scale to max - set in conjunction with fullscreen mode RetroPlatform::SetDisplayScale(1); break; default: - fellowAddLog("RetroPlatform::SetScreenModeStruct(): WARNING: unknown fullscreen 1 display scaling factor 0x%x.\n", lScalingFactor); + fellowAddLog( + "RetroPlatform::SetScreenModeStruct(): WARNING: unknown " + "fullscreen 1 display scaling factor 0x%x.\n", + lScalingFactor); } } RetroPlatform::SetClippingOffsetLeft(sm->lClipLeft); - RetroPlatform::SetClippingOffsetTop (sm->lClipTop); - RetroPlatform::SetScreenHeight (sm->lClipHeight); - RetroPlatform::SetScreenWidth (sm->lClipWidth); + RetroPlatform::SetClippingOffsetTop(sm->lClipTop); + RetroPlatform::SetScreenHeight(sm->lClipHeight); + RetroPlatform::SetScreenWidth(sm->lClipWidth); fellowAddLog("2 - SetScreenHeight and width: (%d, %d)\n", sm->lClipWidth, sm->lClipHeight); cfgSetScreenHeight(pConfig, sm->lClipHeight); - cfgSetScreenWidth (pConfig, sm->lClipWidth); - // Resume emulation, as graph module will crash otherwise if emulation is paused. - // As the pause mode is not changed, after the restart of the session it will be - // paused again. + cfgSetScreenWidth(pConfig, sm->lClipWidth); + // Resume emulation, as graph module will crash otherwise if emulation is + // paused. As the pause mode is not changed, after the restart of the session + // it will be paused again. gfxDrvCommon->RunEventSet(); RegisterRetroPlatformScreenMode(false); fellowRequestEmulationStop(); @@ -1490,7 +1543,8 @@ void RetroPlatform::RegisterRetroPlatformScreenMode(const bool bStartup) else cfgSetDisplayScaleStrategy(gfxDrvCommon->rp_startup_config, DISPLAYSCALE_STRATEGY_SOLID); - if (bStartup) { + if (bStartup) + { RP.SetScreenHeight(cfgGetScreenHeight(gfxDrvCommon->rp_startup_config)); RP.SetScreenWidth(cfgGetScreenWidth(gfxDrvCommon->rp_startup_config)); } @@ -1503,11 +1557,12 @@ void RetroPlatform::RegisterRetroPlatformScreenMode(const bool bStartup) cfgSetScreenWidth(gfxDrvCommon->rp_startup_config, lWidth); drawSetInternalClip(draw_rect(92, 26, 468, 314)); - - draw_rect output_clip((RP.GetClippingOffsetLeft() / 2), - RP.GetClippingOffsetTop(), - ((RP.GetClippingOffsetLeft() + RP.GetScreenWidth()) / 2), - (RP.GetClippingOffsetTop() + RP.GetScreenHeight())); + + draw_rect output_clip( + (RP.GetClippingOffsetLeft() / 2), + RP.GetClippingOffsetTop(), + ((RP.GetClippingOffsetLeft() + RP.GetScreenWidth()) / 2), + (RP.GetClippingOffsetTop() + RP.GetScreenHeight())); cfgSetClipLeft(gfxDrvCommon->rp_startup_config, output_clip.left); cfgSetClipTop(gfxDrvCommon->rp_startup_config, output_clip.top); @@ -1522,23 +1577,23 @@ void RetroPlatform::RegisterRetroPlatformScreenMode(const bool bStartup) } else { - drawSetFullScreenMode(cfgGetScreenWidth(gfxDrvCommon->rp_startup_config), - cfgGetScreenHeight(gfxDrvCommon->rp_startup_config), - cfgGetScreenColorBits(gfxDrvCommon->rp_startup_config), - cfgGetScreenRefresh(gfxDrvCommon->rp_startup_config)); + drawSetFullScreenMode( + cfgGetScreenWidth(gfxDrvCommon->rp_startup_config), + cfgGetScreenHeight(gfxDrvCommon->rp_startup_config), + cfgGetScreenColorBits(gfxDrvCommon->rp_startup_config), + cfgGetScreenRefresh(gfxDrvCommon->rp_startup_config)); } } -void RetroPlatform::SetWindowInstance(HINSTANCE hNewWindowInstance) +void RetroPlatform::SetWindowInstance(HINSTANCE hNewWindowInstance) { hWindowInstance = hNewWindowInstance; fellowAddLog("RetroPlatform::SetWindowInstance(): window instance set to %d.\n", hWindowInstance); } -bool RetroPlatform::SendActivated(const bool bActive, const LPARAM lParam) +bool RetroPlatform::SendActivated(const bool bActive, const LPARAM lParam) { - bool bResult = RetroPlatform::SendMessageToHost(bActive ? RP_IPC_TO_HOST_ACTIVATED : RP_IPC_TO_HOST_DEACTIVATED, - 0, lParam, nullptr, 0, &GuestInfo, nullptr); + bool bResult = RetroPlatform::SendMessageToHost(bActive ? RP_IPC_TO_HOST_ACTIVATED : RP_IPC_TO_HOST_DEACTIVATED, 0, lParam, nullptr, 0, &GuestInfo, nullptr); fellowAddLog("RetroPlatform::SendActivated(): %s.\n", bResult ? "successful" : "failed"); @@ -1556,8 +1611,7 @@ bool RetroPlatform::SendActivated(const bool bActive, const LPARAM lParam) */ bool RetroPlatform::SendClose() { - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_CLOSE, 0, 0, nullptr, 0, - &GuestInfo, nullptr); + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_CLOSE, 0, 0, nullptr, 0, &GuestInfo, nullptr); fellowAddLog("RetroPlatform::SendClose(): %s.\n", bResult ? "sucessful" : "failed"); @@ -1565,29 +1619,26 @@ bool RetroPlatform::SendClose() } /** Send enable/disable messages to the RetroPlatform player. - * + * * These are sent on WM_ENABLE messages. */ bool RetroPlatform::SendEnable(const bool bEnabled) { LRESULT lResult; - if (!bInitialized) - return false; - - bool bResult = RetroPlatform::SendMessageToHost(bEnabled ? RP_IPC_TO_HOST_ENABLED : RP_IPC_TO_HOST_DISABLED, - 0, 0, nullptr, 0, &GuestInfo, &lResult); + if (!bInitialized) return false; + + bool bResult = RetroPlatform::SendMessageToHost(bEnabled ? RP_IPC_TO_HOST_ENABLED : RP_IPC_TO_HOST_DISABLED, 0, 0, nullptr, 0, &GuestInfo, &lResult); + + fellowAddLog("RetroPlatform::SendEnable() %s, result was %d.\n", bResult ? "successful" : "failed", lResult); - fellowAddLog("RetroPlatform::SendEnable() %s, result was %d.\n", - bResult ? "successful" : "failed", lResult); - return bResult; } /** Send list of features supported by the guest to the RetroPlatform host. * - * An RP_IPC_TO_HOST_FEATURES message is sent to the host, with flags indicating the - * features supported by the guest. + * An RP_IPC_TO_HOST_FEATURES message is sent to the host, with flags indicating + * the features supported by the guest. * @return true if message was sent successfully, false otherwise. */ bool RetroPlatform::SendFeatures() @@ -1607,7 +1658,7 @@ bool RetroPlatform::SendFeatures() dFeatureFlags |= RP_FEATURE_SCREEN1X; // features that are currently implemented only for DirectDraw - if (pConfig->m_displaydriver == DISPLAYDRIVER_DIRECTDRAW) + if (pConfig->m_displaydriver == DISPLAYDRIVER_DIRECTDRAW) { dFeatureFlags |= RP_FEATURE_SCREEN2X | RP_FEATURE_SCREEN3X | RP_FEATURE_SCREEN4X; dFeatureFlags |= RP_FEATURE_SCANLINES; @@ -1618,7 +1669,7 @@ bool RetroPlatform::SendFeatures() fellowAddLog("RetroPlatform::SendFeatures(): Display driver is DirectDraw\n"); #endif } - else if (pConfig->m_displaydriver == DISPLAYDRIVER_DIRECT3D11) + else if (pConfig->m_displaydriver == DISPLAYDRIVER_DIRECT3D11) { dFeatureFlags |= RP_FEATURE_SCREEN2X | RP_FEATURE_SCREEN3X | RP_FEATURE_SCREEN4X; dFeatureFlags |= RP_FEATURE_SCANLINES; @@ -1629,28 +1680,28 @@ bool RetroPlatform::SendFeatures() #endif } else - fellowAddLog("RetroPlatform::SendFeatures(): WARNING: unknown display driver type %u\n", - pConfig->m_displaydriver); - + fellowAddLog( + "RetroPlatform::SendFeatures(): WARNING: unknown display " + "driver type %u\n", + pConfig->m_displaydriver); + // currently missing features: RP_FEATURE_FULLSCREEN, // RP_FEATURE_STATE, RP_FEATURE_SCALING_SUBPIXEL, RP_FEATURE_SCALING_STRETCH - // RP_FEATURE_INPUTDEVICE_GAMEPAD, RP_FEATURE_INPUTDEVICE_JOYPAD, + // RP_FEATURE_INPUTDEVICE_GAMEPAD, RP_FEATURE_INPUTDEVICE_JOYPAD, // RP_FEATURE_INPUTDEVICE_ANALOGSTICK, RP_FEATURE_INPUTDEVICE_LIGHTPEN - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_FEATURES, dFeatureFlags, - 0, nullptr, 0, &GuestInfo, &lResult); - - fellowAddLog("RetroPlatform::SendFeatures() %s, result was %d.\n", - bResult ? "successful" : "failed", lResult); - + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_FEATURES, dFeatureFlags, 0, nullptr, 0, &GuestInfo, &lResult); + + fellowAddLog("RetroPlatform::SendFeatures() %s, result was %d.\n", bResult ? "successful" : "failed", lResult); + return bResult; } /** Send list of enabled floppy drives to the RetroPlatform host. * - * An RP_IPC_TO_HOST_DEVICES message is sent to the host, indicating the floppy drives - * enabled in the guest. Must be called after the activation of the config, and before - * sending the screen mode. + * An RP_IPC_TO_HOST_DEVICES message is sent to the host, indicating the floppy + * drives enabled in the guest. Must be called after the activation of the + * config, and before sending the screen mode. * @return true if message was sent successfully, false otherwise. */ bool RetroPlatform::SendEnabledFloppyDrives() @@ -1658,31 +1709,26 @@ bool RetroPlatform::SendEnabledFloppyDrives() LRESULT lResult; DWORD dFeatureFlags = 0; - for(int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { #ifdef _DEBUG - fellowAddLog("RetroPlatform::SendEnabledFloppyDrives(): floppy drive %d is %s.\n", - i, floppy[i].enabled ? "enabled" : "disabled"); + fellowAddLog("RetroPlatform::SendEnabledFloppyDrives(): floppy drive %d is %s.\n", i, floppy[i].enabled ? "enabled" : "disabled"); #endif - if(floppy[i].enabled) - dFeatureFlags |= 1 << i; + if (floppy[i].enabled) dFeatureFlags |= 1 << i; } - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICES, - RP_DEVICECATEGORY_FLOPPY, dFeatureFlags, nullptr, 0, &GuestInfo, - &lResult); - - fellowAddLog("RetroPlatform::SendEnabledFloppyDrives() %s, lResult=%d.\n", - bResult ? "successful" : "failed", lResult); + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICES, RP_DEVICECATEGORY_FLOPPY, dFeatureFlags, nullptr, 0, &GuestInfo, &lResult); + + fellowAddLog("RetroPlatform::SendEnabledFloppyDrives() %s, lResult=%d.\n", bResult ? "successful" : "failed", lResult); return bResult; } /** Send list of enabled hard drives to the RetroPlatform host. * - * An RP_IPC_TO_HOST_DEVICES message is sent to the host, indicating the hard drives - * enabled in the guest. Must be called after the activation of the config, and before - * sending the screen mode. + * An RP_IPC_TO_HOST_DEVICES message is sent to the host, indicating the hard + * drives enabled in the guest. Must be called after the activation of the + * config, and before sending the screen mode. * @return true if message was sent successfully, false otherwise. */ bool RetroPlatform::SendEnabledHardDrives() @@ -1690,17 +1736,14 @@ bool RetroPlatform::SendEnabledHardDrives() DWORD dFeatureFlags = 0; LRESULT lResult; - fellowAddLog("RetroPlatform::SendEnabledHardDrives(): %d hard drives are enabled.\n", - cfgGetHardfileCount(pConfig)); + fellowAddLog("RetroPlatform::SendEnabledHardDrives(): %d hard drives are enabled.\n", cfgGetHardfileCount(pConfig)); - for(uint32_t i = 0; i < cfgGetHardfileCount(pConfig); i++) + for (uint32_t i = 0; i < cfgGetHardfileCount(pConfig); i++) dFeatureFlags |= 1 << i; - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICES, RP_DEVICECATEGORY_HD, - dFeatureFlags, nullptr, 0, &GuestInfo, &lResult); - - fellowAddLog("RetroPlatform::SendEnabledHardDrives() %s, lResult=%d.\n", - bResult ? "successful" : "failed", lResult); + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICES, RP_DEVICECATEGORY_HD, dFeatureFlags, nullptr, 0, &GuestInfo, &lResult); + + fellowAddLog("RetroPlatform::SendEnabledHardDrives() %s, lResult=%d.\n", bResult ? "successful" : "failed", lResult); return bResult; } @@ -1709,25 +1752,21 @@ bool RetroPlatform::SendGameports(const uint32_t lNumGameports) { LRESULT lResult; - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICES, - RP_DEVICECATEGORY_INPUTPORT, (1 << lNumGameports) - 1, nullptr, 0, - &GuestInfo, &lResult); + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_DEVICES, RP_DEVICECATEGORY_INPUTPORT, (1 << lNumGameports) - 1, nullptr, 0, &GuestInfo, &lResult); + + fellowAddLog("RetroPlatform::SendGameports() %s, lResult=%d.\n", bResult ? "successful" : "failed", lResult); - fellowAddLog("RetroPlatform::SendGameports() %s, lResult=%d.\n", - bResult ? "successful" : "failed", lResult); - return bResult; } /** Send a single input device to the RetroPlatform player. */ -bool RetroPlatform::SendInputDevice(const DWORD dwHostInputType, - const DWORD dwInputDeviceFeatures, const DWORD dwFlags, - const WCHAR *szHostInputID, const WCHAR *szHostInputName) +bool RetroPlatform::SendInputDevice( + const DWORD dwHostInputType, const DWORD dwInputDeviceFeatures, const DWORD dwFlags, const WCHAR *szHostInputID, const WCHAR *szHostInputName) { LRESULT lResult; char szHostInputNameA[CFG_FILENAME_LENGTH]; - struct RPInputDeviceDescription rpInputDevDesc; + struct RPInputDeviceDescription rpInputDevDesc; wcscpy(rpInputDevDesc.szHostInputID, szHostInputID); wcscpy(rpInputDevDesc.szHostInputName, szHostInputName); @@ -1739,14 +1778,12 @@ bool RetroPlatform::SendInputDevice(const DWORD dwHostInputType, wcstombs(szHostInputNameA, szHostInputName, CFG_FILENAME_LENGTH); - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_INPUTDEVICE, 0, 0, - &rpInputDevDesc, sizeof rpInputDevDesc, &GuestInfo, &lResult); - + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_INPUTDEVICE, 0, 0, &rpInputDevDesc, sizeof rpInputDevDesc, &GuestInfo, &lResult); + #ifdef _DEBUG - fellowAddLog("RetroPlatform::SendInputDevice('%s') %s, lResult=%d.\n", - szHostInputNameA, bResult ? "successful" : "failed", lResult); + fellowAddLog("RetroPlatform::SendInputDevice('%s') %s, lResult=%d.\n", szHostInputNameA, bResult ? "successful" : "failed", lResult); #endif - + return bResult; } @@ -1761,21 +1798,14 @@ bool RetroPlatform::SendInputDevices() bool bResult = true; // Windows mouse - if (!RetroPlatform::SendInputDevice(RP_HOSTINPUT_MOUSE, - RP_FEATURE_INPUTDEVICE_MOUSE | RP_FEATURE_INPUTDEVICE_LIGHTPEN, - RP_HOSTINPUTFLAGS_MOUSE_SMART, - L"GP_MOUSE0", - L"Windows Mouse")) + if (!RetroPlatform::SendInputDevice( + RP_HOSTINPUT_MOUSE, RP_FEATURE_INPUTDEVICE_MOUSE | RP_FEATURE_INPUTDEVICE_LIGHTPEN, RP_HOSTINPUTFLAGS_MOUSE_SMART, L"GP_MOUSE0", L"Windows Mouse")) { bResult = false; } // report custom keyboard layout support - if (!RetroPlatform::SendInputDevice(RP_HOSTINPUT_KEYBOARD, - RP_FEATURE_INPUTDEVICE_JOYSTICK, - 0, - L"GP_JOYKEYCUSTOM", - L"KeyboardCustom")) + if (!RetroPlatform::SendInputDevice(RP_HOSTINPUT_KEYBOARD, RP_FEATURE_INPUTDEVICE_JOYSTICK, 0, L"GP_JOYKEYCUSTOM", L"KeyboardCustom")) { bResult = false; } @@ -1789,55 +1819,48 @@ bool RetroPlatform::SendInputDevices() bResult = false; } - fellowAddLog("RetroPlatform::SendInputDevices() %s.\n", - bResult ? "successful" : "failed"); - + fellowAddLog("RetroPlatform::SendInputDevices() %s.\n", bResult ? "successful" : "failed"); + return bResult; } bool RetroPlatform::SendMouseCapture(const bool bActive) { - WPARAM wFlags = (WPARAM) 0; + WPARAM wFlags = (WPARAM)0; - if (!bInitialized) - return false; - - if (bActive) - wFlags |= RP_MOUSECAPTURE_CAPTURED; + if (!bInitialized) return false; + + if (bActive) wFlags |= RP_MOUSECAPTURE_CAPTURED; - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_MOUSECAPTURE, wFlags, 0, nullptr, 0, - &GuestInfo, nullptr); + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_MOUSECAPTURE, wFlags, 0, nullptr, 0, &GuestInfo, nullptr); - fellowAddLog("RetroPlatform::SendMouseCapture(): %s.\n", - bResult ? "successful" : "failed"); + fellowAddLog("RetroPlatform::SendMouseCapture(): %s.\n", bResult ? "successful" : "failed"); return bResult; } /** Send screen mode to the player. * - * This step finalizes the transfer of guest features to the player and will enable the emulation. + * This step finalizes the transfer of guest features to the player and will + * enable the emulation. */ bool RetroPlatform::SendScreenMode(HWND hWnd) { - RPScreenMode ScreenMode = { 0 }; + RPScreenMode ScreenMode = {0}; - if (!bInitialized) - return false; + if (!bInitialized) return false; hGuestWindow = hWnd; RetroPlatform::DetermineScreenModeFromConfig(&ScreenMode, pConfig); - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_SCREENMODE, 0, 0, - &ScreenMode, sizeof ScreenMode, &GuestInfo, nullptr); + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_SCREENMODE, 0, 0, &ScreenMode, sizeof ScreenMode, &GuestInfo, nullptr); - fellowAddLog("RetroPlatform::SendScreenMode(): %s.\n", - bResult ? "successful" : "failed"); + fellowAddLog("RetroPlatform::SendScreenMode(): %s.\n", bResult ? "successful" : "failed"); return bResult; } -uint32_t RetroPlatform::GetEscapeKey() +uint32_t RetroPlatform::GetEscapeKey() { return lEscapeKey; } @@ -1852,7 +1875,7 @@ ULONGLONG RetroPlatform::GetEscapeKeyHeldSince() return lEscapeKeyHeldSince; } -ULONGLONG RetroPlatform::GetEscapeKeySimulatedTargetTime() +ULONGLONG RetroPlatform::GetEscapeKeySimulatedTargetTime() { return lEscapeKeySimulatedTargetTime; } @@ -1861,16 +1884,16 @@ HWND RetroPlatform::GetParentWindowHandle() { LRESULT lResult; - if (!bInitialized) - return nullptr; + if (!bInitialized) return nullptr; - bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_PARENT, 0, 0, nullptr, 0, - &GuestInfo, &lResult); - - if(bResult) + bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_PARENT, 0, 0, nullptr, 0, &GuestInfo, &lResult); + + if (bResult) { - fellowAddLog("RetroPlatform::GetParentWindowHandle(): parent window handle returned was %u.\n", - lResult); + fellowAddLog( + "RetroPlatform::GetParentWindowHandle(): parent window handle " + "returned was %u.\n", + lResult); return (HWND)lResult; } else @@ -1881,19 +1904,23 @@ HWND RetroPlatform::GetTopWindowHandle() { LRESULT lResult; - if(!bInitialized) - return nullptr; + if (!bInitialized) return nullptr; bool bResult = RetroPlatform::SendMessageToHost(RP_IPC_TO_HOST_TOPWINDOW, 0, 0, nullptr, 0, &GuestInfo, &lResult); - if(bResult) { - fellowAddLog("RetroPlatform::GetTopWindowHandle(): top window handle returned was %u.\n", lResult); - - if (lResult == NULL) // older RetroPlatform versions don't use the top window handle as emulator runs in a separate context + if (bResult) + { + fellowAddLog( + "RetroPlatform::GetTopWindowHandle(): top window handle " + "returned was %u.\n", + lResult); + + if (lResult == NULL) // older RetroPlatform versions don't use the top + // window handle as emulator runs in a separate context return gfxDrvCommon->GetHWND(); - else + else return (HWND)lResult; - } + } else return nullptr; } @@ -1904,31 +1931,30 @@ void RetroPlatform::Startup() LRESULT lResult = RPInitializeGuest(&GuestInfo, hWindowInstance, szHostID, RetroPlatformHostMessageFunction, 0); - if (SUCCEEDED (lResult)) + if (SUCCEEDED(lResult)) { bInitialized = true; RetroPlatform::GetHostVersion(&lMainVersion, &lRevision, &lBuild); - fellowAddLog("RetroPlatform::Startup(%s) successful. Host version: %d.%d.%d\n", - szHostID, lMainVersion, lRevision, lBuild); + fellowAddLog("RetroPlatform::Startup(%s) successful. Host version: %d.%d.%d\n", szHostID, lMainVersion, lRevision, lBuild); RetroPlatform::SendFeatures(); - } + } else - fellowAddLog("RetroPlatform::Startup(%s) failed, error code %08x\n", - szHostID, lResult); + fellowAddLog("RetroPlatform::Startup(%s) failed, error code %08x\n", szHostID, lResult); } /** Verifies that the prerequisites to start the emulation are available. * - * Validates that the configuration contains a path to a Kickstart ROM, and that the file can - * be opened successfully for reading. - * @return true, when Kickstart ROM can be opened successfully for reading; false otherwise + * Validates that the configuration contains a path to a Kickstart ROM, and that + * the file can be opened successfully for reading. + * @return true, when Kickstart ROM can be opened successfully for reading; + * false otherwise */ bool RetroPlatform::CheckEmulationNecessities() { - if(strcmp(cfgGetKickImage(pConfig), "") != 0) + if (strcmp(cfgGetKickImage(pConfig), "") != 0) { FILE *F = fopen(cfgGetKickImage(pConfig), "rb"); if (F != nullptr) @@ -1938,12 +1964,12 @@ bool RetroPlatform::CheckEmulationNecessities() } return false; } - else + else return false; } /** The main control function when operating in RetroPlatform headless mode. - * + * * This function performs the start of the emulator session. On a reset event, * winDrvEmulationStart will exit without bRetroPlatformEmulatorQuit being set. */ @@ -1960,7 +1986,7 @@ void RetroPlatform::EnterHeadlessMode() RetroPlatform::SendGameports(RETRO_PLATFORM_NUM_GAMEPORTS); RetroPlatform::SendInputDevices(); - while(!bEmulatorQuit) + while (!bEmulatorQuit) { RetroPlatform::SetEmulationState(true); winDrvEmulationStart(); @@ -1973,8 +1999,7 @@ void RetroPlatform::EnterHeadlessMode() void RetroPlatform::Shutdown() { - if(!bInitialized) - return; + if (!bInitialized) return; RetroPlatform::SendScreenMode(nullptr); RetroPlatform::PostMessageToHost(RP_IPC_TO_HOST_CLOSED, 0, 0, &GuestInfo); @@ -1990,10 +2015,10 @@ void RetroPlatform::EmulationStart() void RetroPlatform::EmulationStop() { } - + RetroPlatform::RetroPlatform() { - GuestInfo = { nullptr }; + GuestInfo = {nullptr}; } RetroPlatform::~RetroPlatform() diff --git a/fellow/SRC/WinFellow/Windows/SOUNDDRV.C b/fellow/SRC/WinFellow/Windows/SOUNDDRV.C deleted file mode 100644 index b9703f98..00000000 --- a/fellow/SRC/WinFellow/Windows/SOUNDDRV.C +++ /dev/null @@ -1,1299 +0,0 @@ -/*=========================================================================*/ -/* Fellow Amiga Emulator */ -/* Sound driver for Windows */ -/* Author: Petter Schau (peschau@online.no) */ -/* */ -/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2, or (at your option) */ -/* any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software Foundation, */ -/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*=========================================================================*/ - -/** @file - * Sound driver for Windows - */ - -#include -#include - -#include "defs.h" -#include "fellow.h" -#include "sound.h" -#include "ListTree.h" -#include "windrv.h" -#include "sounddrv.h" -#include "config.h" -#include "GfxDrvCommon.h" - - -/*===========================================================================*/ -/*===========================================================================*/ -/* Sound specific data */ -/*===========================================================================*/ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Some structs where we put all our sound specific stuff */ -/*===========================================================================*/ - -typedef struct -{ - uint32_t rate; - bool bits16; - bool stereo; - uint32_t buffer_sample_count; - uint32_t buffer_block_align; -} sound_drv_dsound_mode; - - -typedef struct -{ - LPDIRECTSOUND lpDS; - LPDIRECTSOUNDBUFFER lpDSB; // Primary buffer - LPDIRECTSOUNDBUFFER lpDSBS; // Secondary buffer - LPDIRECTSOUNDNOTIFY lpDSN; // Notificaton object - felist *modes; - sound_drv_dsound_mode* mode_current; - HANDLE notifications[3]; - HANDLE data_available; - HANDLE can_add_data; - HANDLE mutex; - uint16_t *pending_data_left; - uint16_t *pending_data_right; - uint32_t pending_data_sample_count; - HANDLE thread; - DWORD thread_id; - bool notification_supported; - uint32_t mmtimer; - uint32_t mmresolution; - DWORD lastreadpos; -} sound_drv_dsound_device; - - -/*==========================================================================*/ -/* Currently active dsound device */ -/*==========================================================================*/ - -sound_drv_dsound_device sound_drv_dsound_device_current; - - -/*==========================================================================*/ -/* Returns textual error message. Adapted from DX SDK */ -/*==========================================================================*/ - -char *soundDrvDSoundErrorString(HRESULT hResult) -{ - switch( hResult ) - { - case DSERR_ALLOCATED: return "DSERR_ALLOCATED"; - case DSERR_CONTROLUNAVAIL: return "DSERR_CONTROLUNAVAIL"; - case DSERR_INVALIDPARAM: return "DSERR_INVALIDPARAM"; - case DSERR_INVALIDCALL: return "DSERR_INVALIDCALL"; - case DSERR_GENERIC: return "DSERR_GENERIC"; - case DSERR_PRIOLEVELNEEDED: return "DSERR_PRIOLEVELNEEDED"; - case DSERR_OUTOFMEMORY: return "DSERR_OUTOFMEMORY"; - case DSERR_BADFORMAT: return "DSERR_BADFORMAT"; - case DSERR_UNSUPPORTED: return "DSERR_UNSUPPORTED"; - case DSERR_NODRIVER: return "DSERR_NODRIVER"; - case DSERR_ALREADYINITIALIZED: return "DSERR_ALREADYINITIALIZED"; - case DSERR_NOAGGREGATION: return "DSERR_NOAGGREGATION"; - case DSERR_BUFFERLOST: return "DSERR_BUFFERLOST"; - case DSERR_OTHERAPPHASPRIO: return "DSERR_OTHERAPPHASPRIO"; - case DSERR_UNINITIALIZED: return "DSERR_UNINITIALIZED"; - default: return "Unknown DirectSound Error"; - } - return "Unknown DirectSound Error"; -} - -/*==========================================================================*/ -/* Multimedia Callback fnc. Used when DirectSound notification unsupported */ -/*==========================================================================*/ - -volatile __int64 timertime = 0; - -void CALLBACK timercb(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) -{ - soundDrvPollBufferPosition(); - timertime++; -} - -/*==========================================================================*/ -/* Logs a sensible error message */ -/*==========================================================================*/ - -void soundDrvDSoundFailure(char *header, HRESULT err) -{ - fellowAddLog(header); - fellowAddLog(soundDrvDSoundErrorString(err)); - fellowAddLog("\n"); -} - - -/*===========================================================================*/ -/* Release DirectSound */ -/*===========================================================================*/ - -void soundDrvDSoundRelease() -{ - if (sound_drv_dsound_device_current.lpDS != nullptr) - { - IDirectSound_Release(sound_drv_dsound_device_current.lpDS); - } - sound_drv_dsound_device_current.lpDS = nullptr; - for (uint32_t i = 0; i < 3; i++) - { - if (sound_drv_dsound_device_current.notifications[i] != nullptr) - { - CloseHandle(sound_drv_dsound_device_current.notifications[i]); - } - } - if (sound_drv_dsound_device_current.data_available != nullptr) - { - CloseHandle(sound_drv_dsound_device_current.data_available); - } - if (sound_drv_dsound_device_current.can_add_data != nullptr) - { - CloseHandle(sound_drv_dsound_device_current.can_add_data); - } -} - - -/*===========================================================================*/ -/* Initialize DirectSound */ -/*===========================================================================*/ - -bool soundDrvDSoundInitialize() -{ - uint32_t i; - - sound_drv_dsound_device_current.modes = nullptr; - sound_drv_dsound_device_current.lpDS = nullptr; - sound_drv_dsound_device_current.lpDSB = nullptr; - sound_drv_dsound_device_current.lpDSBS = nullptr; - sound_drv_dsound_device_current.lpDSN = nullptr; - for (i = 0; i < 3; i++) - { - sound_drv_dsound_device_current.notifications[i] = nullptr; - } - sound_drv_dsound_device_current.data_available = nullptr; - sound_drv_dsound_device_current.can_add_data = nullptr; - sound_drv_dsound_device_current.thread = nullptr; - HRESULT directSoundCreateResult = DirectSoundCreate(nullptr, &sound_drv_dsound_device_current.lpDS, nullptr); - if (directSoundCreateResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundInitialize: DirectSoundCreate - ", directSoundCreateResult); - return false; - } - for (i = 0; i < 3; i++) - { - sound_drv_dsound_device_current.notifications[i] = CreateEvent(nullptr, 0, 0, nullptr); - } - sound_drv_dsound_device_current.data_available = CreateEvent(nullptr, 0, 0, nullptr); - sound_drv_dsound_device_current.can_add_data = CreateEvent(nullptr, 0, 0, nullptr); - return true; -} - - -/*===========================================================================*/ -/* Adds a mode to the sound_drv_dsound_device struct */ -/*===========================================================================*/ - -void soundDrvAddMode(sound_drv_dsound_device *dsound_device, - bool stereo, - bool bits16, - uint32_t rate) -{ - sound_drv_dsound_mode *dsound_mode = (sound_drv_dsound_mode *) malloc(sizeof(sound_drv_dsound_mode)); - dsound_mode->stereo = stereo; - dsound_mode->bits16 = bits16; - dsound_mode->rate = rate; - dsound_mode->buffer_sample_count = 0; - dsound_device->modes = listAddLast(dsound_device->modes, listNew(dsound_mode)); -} - - -/*===========================================================================*/ -/* Finds a mode in the sound_drv_dsound_device struct */ -/*===========================================================================*/ - -sound_drv_dsound_mode *soundDrvFindMode(sound_drv_dsound_device *dsound_device, - bool stereo, - bool bits16, - uint32_t rate) -{ - for (felist *fl = dsound_device->modes; fl != nullptr; fl = listNext(fl)) - { - sound_drv_dsound_mode *mode = (sound_drv_dsound_mode *) listNode(fl); - if (mode->rate == rate && mode->stereo == stereo && mode->bits16 == bits16) - { - return mode; - } - } - return nullptr; -} - - -/*===========================================================================*/ -/* If DirectSound mode information */ -/*===========================================================================*/ - -void soundDrvDSoundModeInformationRelease(sound_drv_dsound_device *dsound_device) -{ - listFreeAll(dsound_device->modes, true); - dsound_device->modes = nullptr; -} - - -/*===========================================================================*/ -/* Initialize DirectSound mode information */ -/*===========================================================================*/ - -void soundDrvYesNoLog(char *intro, bool pred) -{ - fellowAddLog(intro); - fellowAddLog((pred) ? " - Yes\n" : " - No\n"); -} - -bool soundDrvDSoundModeInformationInitialize(sound_drv_dsound_device *dsound_device) -{ - DSCAPS dscaps; - char s[80]; - - memset(&dscaps, 0, sizeof(dscaps)); - dscaps.dwSize = sizeof(dscaps); - HRESULT getCapsResult = IDirectSound_GetCaps(dsound_device->lpDS, &dscaps); - if (getCapsResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundModeInformationInitialize: ", getCapsResult); - return false; - } - bool stereo = !!(dscaps.dwFlags & DSCAPS_PRIMARYSTEREO); - soundDrvYesNoLog("DSCAPS_PRIMARYSTEREO", stereo); - bool mono = !!(dscaps.dwFlags & DSCAPS_PRIMARYMONO); - soundDrvYesNoLog("DSCAPS_PRIMARYMONO", mono); - bool bits16 = !!(dscaps.dwFlags & DSCAPS_PRIMARY16BIT); - soundDrvYesNoLog("DSCAPS_PRIMARY16BIT", bits16); - bool bits8 = !!(dscaps.dwFlags & DSCAPS_PRIMARY8BIT); - soundDrvYesNoLog("DSCAPS_PRIMARY8BIT", bits8); - - bool secondary_stereo = !!(dscaps.dwFlags & DSCAPS_SECONDARYSTEREO); - soundDrvYesNoLog("DSCAPS_SECONDARYSTEREO", secondary_stereo); - bool secondary_mono = !!(dscaps.dwFlags & DSCAPS_SECONDARYMONO); - soundDrvYesNoLog("DSCAPS_SECONDARYMONO", secondary_mono); - bool secondary_bits16 = !!(dscaps.dwFlags & DSCAPS_SECONDARY16BIT); - soundDrvYesNoLog("DSCAPS_SECONDARY16BIT", secondary_bits16); - bool secondary_bits8 = !!(dscaps.dwFlags & DSCAPS_SECONDARY8BIT); - soundDrvYesNoLog("DSCAPS_SECONDARY8BIT", secondary_bits8); - - bool continuous_rate = !!(dscaps.dwFlags & DSCAPS_CONTINUOUSRATE); - soundDrvYesNoLog("DSCAPS_CONTINUOUSRATE", continuous_rate); - bool emulated_driver = !!(dscaps.dwFlags & DSCAPS_EMULDRIVER); - soundDrvYesNoLog("DSCAPS_EMULDRIVER", emulated_driver); - bool certified_driver = !!(dscaps.dwFlags & DSCAPS_CERTIFIED); - soundDrvYesNoLog("DSCAPS_CERTIFIED", certified_driver); - - uint32_t minrate = dscaps.dwMinSecondarySampleRate; - uint32_t maxrate = dscaps.dwMaxSecondarySampleRate; - sprintf(s, "ddscaps.dwMinSecondarySampleRate - %u\n", minrate); - fellowAddLog(s); - sprintf(s, "ddscaps.dwMaxSecondarySampleRate - %u\n", maxrate); - fellowAddLog(s); - - /* Set maximum sample rate to 44100 if it cannot be determined - from the driver caps; this is supposed to fix problems with - ESS SOLO-1 PCI soundcards */ - - if (maxrate == 0) - { - maxrate = 44100; - sprintf(s, "ddscaps.dwMaxSecondarySampleRate correction applied - %u\n", maxrate); - fellowAddLog(s); - } - - if (stereo) - { - if (bits16) - { - soundDrvAddMode(dsound_device, stereo, bits16, 15650); - soundDrvAddMode(dsound_device, stereo, bits16, 22050); - soundDrvAddMode(dsound_device, stereo, bits16, 31300); - soundDrvAddMode(dsound_device, stereo, bits16, 44100); - } - if (bits8) - { - soundDrvAddMode(dsound_device, stereo, !bits8, 15650); - soundDrvAddMode(dsound_device, stereo, !bits8, 22050); - soundDrvAddMode(dsound_device, stereo, !bits8, 31300); - soundDrvAddMode(dsound_device, stereo, !bits8, 44100); - } - } - if (mono) - { - if (bits16) - { - soundDrvAddMode(dsound_device, !mono, bits16, 15650); - soundDrvAddMode(dsound_device, !mono, bits16, 22050); - soundDrvAddMode(dsound_device, !mono, bits16, 31300); - soundDrvAddMode(dsound_device, !mono, bits16, 44100); - } - if (bits8) - { - soundDrvAddMode(dsound_device, !mono, !bits8, 15650); - soundDrvAddMode(dsound_device, !mono, !bits8, 22050); - soundDrvAddMode(dsound_device, !mono, !bits8, 31300); - soundDrvAddMode(dsound_device, !mono, !bits8, 44100); - } - } - - return true; -} - -/** Configure volume of secondary DirectSound buffer of current sound device. - * - * Loudness is perceived in a logarithmic manner; the calculation attempts - * to utilize the upper half of the available spectrum quadratically, so - * that the perceived volume when moving the slider along feels more natural - * the numbers may still need some fine-tuning - * @param[in] volume the target volume in the range of 0 to 100 (100 being - full volume) - * @return TRUE is successful, FALSE otherwise. - */ -static bool soundDrvDSoundSetVolume(sound_drv_dsound_device *dsound_device, const int volume) { - HRESULT hResult; - LONG vol; - - if (volume <= 100 && volume > 0) - vol = (LONG) -((50-(volume/2))*(50-(volume/2))); - else if (volume == 0) - vol = DSBVOLUME_MIN; - else - vol = DSBVOLUME_MAX; - -#ifdef _DEBUG - fellowAddLog("soundDrvDSoundSetVolume: volume %d scaled to %d, setting volume...\n", - volume, vol); -#endif - - hResult = IDirectSoundBuffer_SetVolume (dsound_device->lpDSBS, vol); - if (FAILED (hResult)) - soundDrvDSoundFailure("soundDrvDSoundSetVolume(): SetVolume() failed: ", hResult); - - return (hResult == DS_OK); -} - -bool soundDrvDSoundSetCurrentSoundDeviceVolume(const int volume) { - return soundDrvDSoundSetVolume(&sound_drv_dsound_device_current, volume); -} - -/*===========================================================================*/ -/* Set sound cooperative level */ -/* Ref: Microsoft Press, Inside DirectX, page 210 */ -/*===========================================================================*/ - -bool soundDrvDSoundSetCooperativeLevel(sound_drv_dsound_device *dsound_device) -{ - /* We need the HWND of the amiga emulation window, which means sound is */ - /* initialized after the gfx stuff */ - - HRESULT setCooperativeLevelResult = IDirectSound_SetCooperativeLevel(dsound_device->lpDS, - gfxDrvCommon->GetHWND(), - DSSCL_PRIORITY); - if (setCooperativeLevelResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundSetCooperativeLevel", setCooperativeLevelResult); - } - return (setCooperativeLevelResult == DS_OK); -} - - -/*===========================================================================*/ -/* Release the primary buffer */ -/*===========================================================================*/ - -void soundDrvDSoundPrimaryBufferRelease(sound_drv_dsound_device *dsound_device) -{ - if (dsound_device->lpDSB != nullptr) - { - IDirectSoundBuffer_Play(dsound_device->lpDSB, 0, 0, 0); - IDirectSoundBuffer_Release(dsound_device->lpDSB); - dsound_device->lpDSB = nullptr; - } -} - - -/*===========================================================================*/ -/* Get a primary buffer */ -/* We always make a primary buffer, in the same format as the sound data */ -/* we are going to receive from the sound emulation routines. */ -/* If it fails, we don't play sound. */ -/* Ref: Microsoft Press, Inside DirectX, page 212 */ -/*===========================================================================*/ - -bool soundDrvDSoundPrimaryBufferInitialize(sound_drv_dsound_device *dsound_device) -{ - DSBUFFERDESC dsbdesc; - WAVEFORMATEX wfm; - - /* Create sound buffer */ - - memset(&dsbdesc, 0, sizeof(dsbdesc)); - dsbdesc.dwSize = sizeof(dsbdesc); - dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; - dsbdesc.dwBufferBytes = 0; - dsbdesc.lpwfxFormat = nullptr; - - memset(&wfm, 0, sizeof(wfm)); - wfm.wFormatTag = WAVE_FORMAT_PCM; - wfm.nChannels = (dsound_device->mode_current->stereo) ? 2 : 1; - wfm.nSamplesPerSec = dsound_device->mode_current->rate; - wfm.wBitsPerSample = (dsound_device->mode_current->bits16) ? 16 : 8; - wfm.nBlockAlign = (wfm.wBitsPerSample / 8) * wfm.nChannels; - wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; - dsound_device->mode_current->buffer_block_align = wfm.nBlockAlign; - - HRESULT createSoundBufferResult = IDirectSound_CreateSoundBuffer(dsound_device->lpDS, - &dsbdesc, - &dsound_device->lpDSB, - NULL); - if (createSoundBufferResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundPrimaryBufferInitialize(): CreateSoundBuffer(), ", createSoundBufferResult); - return false; - } - - /* Set format of primary buffer */ - - HRESULT setFormatResult = IDirectSoundBuffer_SetFormat(dsound_device->lpDSB, &wfm); - if (setFormatResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundPrimaryBufferInitialize(): SetFormat(), ", setFormatResult); - soundDrvDSoundPrimaryBufferRelease(dsound_device); - return false; - } - - return true; -} - - -/*===========================================================================*/ -/* Release the secondary buffer */ -/*===========================================================================*/ - -void soundDrvDSoundSecondaryBufferRelease(sound_drv_dsound_device *dsound_device) -{ - if (dsound_device->lpDSBS != nullptr) - { - IDirectSoundBuffer_Play(dsound_device->lpDSBS, 0, 0, 0); - IDirectSoundBuffer_Release(dsound_device->lpDSBS); - dsound_device->lpDSBS = nullptr; - } - if (dsound_device->lpDSN != nullptr) - { - IDirectSoundNotify_Release(dsound_device->lpDSN); - dsound_device->lpDSN = nullptr; - } - if (!dsound_device->notification_supported) - { - timeKillEvent(dsound_device->mmtimer); - timeEndPeriod(dsound_device->mmresolution); - } -} - - -bool soundDrvCreateSecondaryBuffer(sound_drv_dsound_device *dsound_device) -{ - WAVEFORMATEX wfm; - DSBUFFERDESC dsbdesc; - - memset(&wfm, 0, sizeof(wfm)); - wfm.wFormatTag = WAVE_FORMAT_PCM; - wfm.nChannels = (dsound_device->mode_current->stereo) ? 2 : 1; - wfm.nSamplesPerSec = dsound_device->mode_current->rate; - wfm.wBitsPerSample = (dsound_device->mode_current->bits16) ? 16 : 8; - wfm.nBlockAlign = (wfm.wBitsPerSample / 8) * wfm.nChannels; - wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; - - memset(&dsbdesc, 0, sizeof(dsbdesc)); - dsbdesc.dwSize = sizeof(dsbdesc); - dsbdesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | - DSBCAPS_GETCURRENTPOSITION2 | - DSBCAPS_GLOBALFOCUS | - DSBCAPS_CTRLVOLUME; - dsbdesc.dwBufferBytes = dsound_device->mode_current->buffer_sample_count*wfm.nBlockAlign*2; - dsbdesc.lpwfxFormat = &wfm; - - HRESULT createSoundBufferResult = IDirectSound_CreateSoundBuffer(dsound_device->lpDS, - &dsbdesc, - &dsound_device->lpDSBS, - NULL); - if (createSoundBufferResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvCreateSecondaryBuffer: CreateSoundBuffer(), ", createSoundBufferResult); - return false; - } - return true; -} - -bool soundDrvClearSecondaryBuffer(sound_drv_dsound_device *dsound_device) -{ - char* lpAudio; - DWORD dwBytes; - - HRESULT lock1Result = IDirectSoundBuffer_Lock(dsound_device->lpDSBS, - 0, - 0, // Ignored because we pass DSBLOCK_ENTIREBUFFER - (LPVOID*) &lpAudio, - &dwBytes, - NULL, - NULL, - DSBLOCK_ENTIREBUFFER); - - if (lock1Result != DS_OK) - { - soundDrvDSoundFailure("soundDrvClearSecondaryBuffer: Lock(), ", lock1Result); - - if (lock1Result == DSERR_BUFFERLOST) - { - /* Buffer lost. Try to restore buffer once. Multiple restores need more intelligence */ - HRESULT restoreResult = IDirectSoundBuffer_Restore(dsound_device->lpDSBS); - if (restoreResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvClearSecondaryBuffer: Restore(), ", restoreResult); - return false; - } - - HRESULT lock2Result = IDirectSoundBuffer_Lock(dsound_device->lpDSBS, - 0, - 0, // Ignored because we pass DSBLOCK_ENTIREBUFFER - (LPVOID*)&lpAudio, - &dwBytes, - NULL, - NULL, - DSBLOCK_ENTIREBUFFER); - if (lock2Result != DS_OK) - { - // Here we give up - soundDrvDSoundFailure("soundDrvClearSecondaryBuffer: Lock(), ", lock2Result); - return false; - } - } - } - - for (DWORD i = 0; i < dwBytes; i++) - { - lpAudio[i] = 0; - } - - HRESULT unlockResult = IDirectSoundBuffer_Unlock(dsound_device->lpDSBS, lpAudio, dwBytes, NULL, 0); - if (unlockResult != DS_OK) - { - // Here we give up - soundDrvDSoundFailure("soundDrvClearSecondaryBuffer: Unlock(), ", unlockResult); - return false; - } - - return true; -} - -bool soundDrvInitializeSecondaryBufferNotification(sound_drv_dsound_device *dsound_device) -{ - DSBCAPS dsbcaps; - DSBPOSITIONNOTIFY rgdscbpn[2]; - - memset(&dsbcaps, 0, sizeof(dsbcaps)); - dsbcaps.dwSize = sizeof(dsbcaps); - - HRESULT getCapsResult = IDirectSoundBuffer_GetCaps(dsound_device->lpDSBS, &dsbcaps); - if (getCapsResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvInitializeSecondaryBufferNotification: GetCaps(), ", getCapsResult); - return false; - } - - dsound_device->notification_supported = (!!(dsbcaps.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY)) - && (soundGetNotification() == SOUND_DSOUND_NOTIFICATION); - - if (dsound_device->notification_supported) - { - /* Notification supported AND selected */ - - /* Get notification interface */ - - HRESULT queryInterfaceResult = IDirectSoundBuffer_QueryInterface(dsound_device->lpDSBS, - IID_IDirectSoundNotify, - (LPVOID * FAR) &dsound_device->lpDSN); - if (queryInterfaceResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvInitializeSecondaryBufferNotification(): QueryInterface(IID_IDirectSoundNotify), ", - queryInterfaceResult); - return false; - } - - /* Attach notification objects to buffer */ - - rgdscbpn[0].dwOffset = dsound_device->mode_current->buffer_block_align* - (dsound_device->mode_current->buffer_sample_count - 1); - rgdscbpn[0].hEventNotify = dsound_device->notifications[0]; - rgdscbpn[1].dwOffset = dsound_device->mode_current->buffer_block_align* - (dsound_device->mode_current->buffer_sample_count*2 - 1); - rgdscbpn[1].hEventNotify = dsound_device->notifications[1]; - - HRESULT setNotificationPositionsResult = IDirectSoundNotify_SetNotificationPositions(dsound_device->lpDSN, 2, rgdscbpn); - if (setNotificationPositionsResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvInitializeSecondaryBufferNotification(): SetNotificationPositions(), ", setNotificationPositionsResult); - return false; - } - } - else - { - /* Notification not supported, fallback to timer */ - - char s[80]; - TIMECAPS timecaps; - - MMRESULT timeGetDevCapsResult = timeGetDevCaps(&timecaps, sizeof(TIMECAPS)); - if (timeGetDevCapsResult != TIMERR_NOERROR) - { - fellowAddLog("soundDrvInitializeSecondaryBufferNotification(): timeGetDevCaps() failed\n"); - return false; - } - - sprintf(s, "timeGetDevCaps: min: %u, max %u\n", timecaps.wPeriodMin, timecaps.wPeriodMax); - fellowAddLog(s); - - dsound_device->mmresolution = timecaps.wPeriodMin; - - MMRESULT timeBeginPeriodResult = timeBeginPeriod(dsound_device->mmresolution); - if (timeBeginPeriodResult != TIMERR_NOERROR) - { - fellowAddLog("soundDrvInitializeSecondaryBufferNotification(): timeBeginPeriod() failed\n"); - return false; - } - - MMRESULT timeSetEventResult = timeSetEvent(1, 0, timercb, (DWORD_PTR)0, (UINT) TIME_PERIODIC); - if (timeSetEventResult == 0) - { - fellowAddLog("soundDrvInitializeSecondaryBufferNotification(): timeSetEvent() failed\n"); - return false; - } - dsound_device->mmtimer = timeSetEventResult; - } - return true; -} - -/*===========================================================================*/ -/* Get a secondary buffer */ -/* Ref: Microsoft Press, Inside DirectX, page 212, 229-232 */ -/*===========================================================================*/ - -bool soundDrvDSoundSecondaryBufferInitialize(sound_drv_dsound_device *dsound_device) -{ - if (!soundDrvCreateSecondaryBuffer(dsound_device)) - { - return false; - } - - if (!soundDrvClearSecondaryBuffer(dsound_device)) - { - soundDrvDSoundSecondaryBufferRelease(dsound_device); - return false; - } - - if (!soundDrvInitializeSecondaryBufferNotification(dsound_device)) - { - soundDrvDSoundSecondaryBufferRelease(dsound_device); - return false; - } - - soundDrvDSoundSetVolume(dsound_device, soundGetVolume()); - - return true; -} - - -/*===========================================================================*/ -/* Stop playback */ -/*===========================================================================*/ - -void soundDrvDSoundPlaybackStop(sound_drv_dsound_device *dsound_device) -{ - soundDrvDSoundSecondaryBufferRelease(dsound_device); - soundDrvDSoundPrimaryBufferRelease(dsound_device); -} - - -/*===========================================================================*/ -/* Initialize playback */ -/*===========================================================================*/ - -bool soundDrvDSoundPlaybackInitialize(sound_drv_dsound_device *dsound_device) -{ - dsound_device->lastreadpos = 0; - bool result = soundDrvDSoundPrimaryBufferInitialize(dsound_device); - if (result) - { - result = soundDrvDSoundSecondaryBufferInitialize(dsound_device); - } - if (!result) - { - fellowAddLog("Sound, secondary failed\n"); - soundDrvDSoundPrimaryBufferRelease(dsound_device); - } - if (result) - { - HRESULT primaryPlayResult = IDirectSoundBuffer_Play(dsound_device->lpDSB, 0, 0, DSBPLAY_LOOPING); - if (primaryPlayResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundPlaybackInitialize: Primary->Play(), ", primaryPlayResult); - } - HRESULT secondaryPlayResult = IDirectSoundBuffer_Play(dsound_device->lpDSBS, 0, 0, DSBPLAY_LOOPING); - if (secondaryPlayResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundPlaybackInitialize: Secondary->Play(), ", secondaryPlayResult); - } - } - return result; -} - - -/*===========================================================================*/ -/* Copy data to a buffer */ -/*===========================================================================*/ - -void soundDrvCopy16BitsStereo(uint16_t *audio_buffer, - uint16_t *left, - uint16_t *right, - uint32_t sample_count) -{ - for (uint32_t i = 0; i < sample_count; i++) - { - *audio_buffer++ = *left++; - *audio_buffer++ = *right++; - } -} - -void soundDrvCopy16BitsMono(uint16_t *audio_buffer, - uint16_t *left, - uint16_t *right, - uint32_t sample_count) -{ - for (uint32_t i = 0; i < sample_count; i++) - { - *audio_buffer++ = (*left++ + *right++); - } -} - -void soundDrvCopy8BitsStereo(uint8_t *audio_buffer, - uint16_t *left, - uint16_t *right, - uint32_t sample_count) -{ - for (uint32_t i = 0; i < sample_count; i++) - { - *audio_buffer++ = ((*left++)>>8) + 128; - *audio_buffer++ = ((*right++)>>8) + 128; - } -} - -void soundDrvCopy8BitsMono(uint8_t *audio_buffer, - uint16_t *left, - uint16_t *right, - uint32_t sample_count) -{ - for (uint32_t i = 0; i < sample_count; i++) - { - *audio_buffer++ = (((*left++) + (*right++))>>8) + 128; - } -} - -bool soundDrvDSoundCopyToBuffer(sound_drv_dsound_device *dsound_device, - uint16_t *left, - uint16_t *right, - uint32_t sample_count, - uint32_t buffer_half) -{ - LPVOID lpvAudio; - DWORD dwBytes; - DWORD size = dsound_device->mode_current->buffer_sample_count* - dsound_device->mode_current->buffer_block_align; - DWORD start_offset = buffer_half*size; - - HRESULT lockResult = IDirectSoundBuffer_Lock(dsound_device->lpDSBS, - start_offset, - size, - &lpvAudio, - &dwBytes, - NULL, - NULL, - 0); - - if (lockResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundCopyToBuffer: Lock(), ", lockResult); - return false; - } - - if (lockResult == DSERR_BUFFERLOST) - { - /* Buffer lost. Try to restore buffer once. Multiple restores need more intelligence */ - HRESULT restoreResult = IDirectSoundBuffer_Restore(dsound_device->lpDSBS); - if (restoreResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundCopyToBuffer: Restore(), ", restoreResult); - return false; - } - HRESULT lock2Result = IDirectSoundBuffer_Lock(dsound_device->lpDSBS, - start_offset, - size, - &lpvAudio, - &dwBytes, - NULL, - NULL, - 0); - if (lock2Result != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundCopyToBuffer: Lock() after Restore , ", lock2Result); - return false; - } - } - - if (soundGetStereo()) - { - if (soundGet16Bits()) - { - soundDrvCopy16BitsStereo((uint16_t*)lpvAudio, left, right, sample_count); - } - else - { - soundDrvCopy8BitsStereo((uint8_t*)lpvAudio, left, right, sample_count); - } - } - else - { - if (soundGet16Bits()) - { - soundDrvCopy16BitsMono((uint16_t*)lpvAudio, left, right, sample_count); - } - else - { - soundDrvCopy8BitsMono((uint8_t*)lpvAudio, left, right, sample_count); - } - } - HRESULT unlockResult = IDirectSoundBuffer_Unlock(dsound_device->lpDSBS, lpvAudio, dwBytes, NULL, 0); - if (unlockResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvDSoundCopyToBuffer: Unlock(), ", unlockResult); - return false; - } - return true; -} - - -/*===========================================================================*/ -/* Play a buffer */ -/* This is also where the emulator receives synchronization, */ -/* since waiting for the sound-buffer to be */ -/* ready slows the emulator down to its original 50hz PAL speed. */ -/*===========================================================================*/ - -void soundDrvPlay(int16_t *left, int16_t *right, uint32_t sample_count) -{ - sound_drv_dsound_device *dsound_device = &sound_drv_dsound_device_current; - WaitForSingleObject(dsound_device->can_add_data, INFINITE); - dsound_device->pending_data_left = (uint16_t*)left; - dsound_device->pending_data_right = (uint16_t*)right; - dsound_device->pending_data_sample_count = sample_count; - ResetEvent(dsound_device->can_add_data); - SetEvent(dsound_device->data_available); -} - - -/*===========================================================================*/ -/* We need a mutex to control stopping and starting the driver during a */ -/* display mode change. */ -/*===========================================================================*/ - -void soundDrvAcquireMutex(sound_drv_dsound_device *dsound_device) -{ - WaitForSingleObject(dsound_device->mutex, INFINITE); -} - -void soundDrvReleaseMutex(sound_drv_dsound_device *dsound_device) -{ - ReleaseMutex(dsound_device->mutex); -} - - -/*===========================================================================*/ -/* Used by playback thread to wait for data */ -/* There is one caveat here, that the app is about to end emulation, in that */ -/* case the data will never come, so we need to keep an eye on the end event */ -/* as well. In case of termination, we return FALSE */ -/* We use this one only when notification is supported */ -/*===========================================================================*/ - -bool soundDrvWaitForData(sound_drv_dsound_device *dsound_device, - uint32_t next_buffer_no, - bool &need_to_restart_playback) -{ - HANDLE multi_events[3]; - bool terminate_wait = false; - bool terminate_thread = false; - uint32_t wait_for_x_events = 3; - - // No-wait test for data_available, return TRUE if data is available - if (WaitForSingleObject(dsound_device->data_available, 0) == WAIT_OBJECT_0) - { - return true; - } - //fellowAddLog("Data was not available\n"); - // Here, data is not available from the sound emulation - // And we have played past the end of the buffer we want to copy data to - // We can continue to play until the end of the next buffer, but then we - // must stop playback, since there is no more data to play - // So we set up a multiple object wait which trigger on the following - // conditions: - // 0 - Data becomes available, return TRUE, playback is not stopped - // 1 - End of the thread is signaled, return FALSE to indicate termination - // 2 - The end of the next buffer is reached, stop playback, has no data,yet - // Redo the wait, this time without the event for end of the next buffer - - // What if we are lagging behind already? - - while (!terminate_wait) - { - multi_events[0] = dsound_device->data_available; - multi_events[1] = dsound_device->notifications[2]; - if (wait_for_x_events == 3) - { - multi_events[2] = dsound_device->notifications[next_buffer_no]; - } - DWORD evt = WaitForMultipleObjects(wait_for_x_events, - (void*const*)multi_events, - FALSE, - INFINITE); - switch (evt) - { - case WAIT_OBJECT_0: - // Data is now available - // Restart playing if we have stopped it - need_to_restart_playback = (wait_for_x_events == 2); - terminate_wait = true; - break; - case WAIT_OBJECT_0 + 1: - // End of thread requested, return FALSE - terminate_wait = true; - terminate_thread = true; - break; - case WAIT_OBJECT_0 + 2: - // End of next buffer reached, stop playback, wait more - HRESULT playResult = IDirectSoundBuffer_Play(dsound_device->lpDSBS, 0, 0, 0); - if (playResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvWaitForData: Play(), ", playResult); - } - wait_for_x_events = 2; - break; - } - } - return !terminate_thread; -} - - -/*===========================================================================*/ -/* Emulates notification when notification is not supported. */ -/* I am not sure if this is a stupid thing to do, or if there really are more*/ -/* efficient ways to control a "polled" buffer. */ -/* Somebody give that guy at Microsoft who likes polling so much a beating...*/ -/* Called from the message loop in response to a timer. */ -/*===========================================================================*/ - -void soundDrvPollBufferPosition() -{ - sound_drv_dsound_device *dsound_device = &sound_drv_dsound_device_current; - soundDrvAcquireMutex(dsound_device); - if ((soundGetEmulation() == SOUND_PLAY) && !dsound_device->notification_supported) - { - DWORD readpos, writepos; - DWORD halfway = (dsound_device->mode_current->buffer_sample_count* - dsound_device->mode_current->buffer_block_align); - - if (dsound_device->lpDSBS != nullptr) - { - HRESULT getCurrentPositionResult = IDirectSoundBuffer_GetCurrentPosition(dsound_device->lpDSBS, - &readpos, - &writepos); - if (getCurrentPositionResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvPollBufferPosition: GetCurrentPosition(), ", getCurrentPositionResult); - } - if ((readpos >= halfway) && (dsound_device->lastreadpos < halfway)) - { - SetEvent(dsound_device->notifications[0]); - } - else if ((readpos < halfway) && (dsound_device->lastreadpos >= halfway)) - { - SetEvent(dsound_device->notifications[1]); - } - dsound_device->lastreadpos = readpos; - } - } - soundDrvReleaseMutex(dsound_device); -} - -/*===========================================================================*/ -/* Process end of buffer event */ -/*===========================================================================*/ - -bool soundDrvProcessEndOfBuffer(sound_drv_dsound_device *dsound_device, - uint32_t current_buffer_no, - uint32_t next_buffer_no) -{ - bool terminate_thread = false; - bool need_to_restart_playback = false; - if (soundDrvWaitForData(dsound_device, next_buffer_no, need_to_restart_playback)) - { - soundDrvDSoundCopyToBuffer(dsound_device, - dsound_device->pending_data_left, - dsound_device->pending_data_right, - dsound_device->pending_data_sample_count, - current_buffer_no); - if (need_to_restart_playback) - { - HRESULT playResult = IDirectSoundBuffer_Play(dsound_device->lpDSBS, 0, 0, DSBPLAY_LOOPING); - - if (playResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvProcessEndOfBuffer: Play(), ", playResult); - } - - if (playResult == DSERR_BUFFERLOST) - { - /* Temporary fix for restoring buffer once. Multiple restore needs alot more */ - HRESULT restoreResult = IDirectSoundBuffer_Restore(dsound_device->lpDSBS); - if (restoreResult != DS_OK) - { - soundDrvDSoundFailure("soundDrvProcessEndOfBuffer: Restore(), ", restoreResult); - } - else - { - HRESULT play2Result = IDirectSoundBuffer_Play(dsound_device->lpDSBS, 0, 0, DSBPLAY_LOOPING); - if (play2Result != DS_OK) - { - soundDrvDSoundFailure("soundDrvProcessEndOfBuffer: Play() after restore, ", play2Result); - } - } - } - } - - // If the next buffer also triggered during soundDrvWaitForData() - // it will end multiple object wait immediately, since we don't reset it - ResetEvent(dsound_device->data_available); - SetEvent(dsound_device->can_add_data); - ResetEvent(dsound_device->notifications[current_buffer_no]); - } - else - { - terminate_thread = true; - } - return terminate_thread; -} - -/*===========================================================================*/ -/* Thread, from which we control playback much in the same way as under DOS */ -/* Basically, we have two notification objects attached to each end of the */ -/* playback buffer, as well as a stop playback event, signaled in the */ -/* soundDrvEmulationStop function. */ -/* When awake, we have two options: */ -/* If the event sound_drv_data_available is signaled, data is available, */ -/* and we copy it into the playback buffer, reset the event and sleeps again.*/ -/* If data is not available, we must pause playback and wait for that event */ -/* to be signaled. Then we copy data and start playback and goes to sleep. */ -/* The data available event is set by the main emulation thread when data is */ -/* ready, in soundDrvPlay() */ -/*===========================================================================*/ - -DWORD WINAPI soundDrvThreadProc(void *in) -{ - bool terminate_thread = false; - sound_drv_dsound_device *dsound_device = (sound_drv_dsound_device *) in; - - winDrvSetThreadName(-1, "soundDrvThreadProc()"); - - while (!terminate_thread) { - // Thread is activated by 3 different events: - // 0 - Play position is at end of buffer 0 - // 1 - Play position is at end of buffer 1 - // 2 - Thread must terminate (triggered in soundDrvEmulationStop()) - DWORD dwEvt = WaitForMultipleObjects(3, - (void*const*) (dsound_device->notifications), - FALSE, - INFINITE); - - switch (dwEvt) - { - case WAIT_OBJECT_0 + 0: /* End of first buffer */ - // Wait for data_available event to become signaled - // or FALSE is returned if (2) becomes signaled (end thread) - terminate_thread = soundDrvProcessEndOfBuffer(dsound_device, 0, 1); - break; - case WAIT_OBJECT_0 + 1: /* End of first buffer */ - // Wait for data_available event to become signaled - // or FALSE is returned if (2) becomes signaled (end thread) - terminate_thread = soundDrvProcessEndOfBuffer(dsound_device, 1, 0); - break; - case WAIT_OBJECT_0 + 2: /* Emulation is ending */ - default: - terminate_thread = true; - break; - } - } - return 0; -} - - -/*===========================================================================*/ -/* Hard Reset */ -/*===========================================================================*/ - -void soundDrvHardReset() -{ -} - - -/*===========================================================================*/ -/* Emulation Starting */ -/*===========================================================================*/ - -bool soundDrvEmulationStart(uint32_t rate, - bool bits16, - bool stereo, - uint32_t *sample_count_max) -{ - sound_drv_dsound_device *dsound_device = &sound_drv_dsound_device_current; - - soundDrvAcquireMutex(dsound_device); - - /* Set all events to their initial state */ - - for (uint32_t i = 0; i < 3; i++) - { - ResetEvent(dsound_device->notifications[i]); - } - ResetEvent(dsound_device->data_available); - SetEvent(dsound_device->can_add_data); - - /* Check if the driver can support the requested sound quality */ - - dsound_device->mode_current = soundDrvFindMode(dsound_device, - stereo, - bits16, - rate); - bool result = dsound_device->mode_current != nullptr; - - /* Record the number of samples in our buffer (ie. one half of the size) */ - - if (result) - { - dsound_device->mode_current->buffer_sample_count = *sample_count_max; - result = soundDrvDSoundSetCooperativeLevel(dsound_device); - } - - /* Create the needed buffer(s) */ - - if (result) - { - result = soundDrvDSoundPlaybackInitialize(dsound_device); - } - - /* Start playback thread */ - - if (result) - { - dsound_device->thread = CreateThread(nullptr, // Security attr - 0, // Stack Size - soundDrvThreadProc, // Thread procedure - dsound_device, // Thread parameter - 0, // Creation flags - &dsound_device->thread_id);// ThreadId - result = (dsound_device->thread != nullptr); - } - - /* In case of failure, we undo any stuff we've done so far */ - - if (!result) - { - fellowAddLog("Failed to start sound\n"); - soundDrvDSoundPlaybackStop(dsound_device); - } - - soundDrvReleaseMutex(dsound_device); - return result; -} - - -/*===========================================================================*/ -/* Emulation Stopping */ -/*===========================================================================*/ - -void soundDrvEmulationStop() -{ - soundDrvAcquireMutex(&sound_drv_dsound_device_current); - SetEvent(sound_drv_dsound_device_current.notifications[2]); - WaitForSingleObject(sound_drv_dsound_device_current.thread, INFINITE); - CloseHandle(sound_drv_dsound_device_current.thread); - sound_drv_dsound_device_current.thread = nullptr; - soundDrvDSoundPlaybackStop(&sound_drv_dsound_device_current); - soundDrvReleaseMutex(&sound_drv_dsound_device_current); -} - - -/*===========================================================================*/ -/* Emulation Startup */ -/*===========================================================================*/ - -bool soundDrvStartup(sound_device *devinfo) -{ - bool result = soundDrvDSoundInitialize(); /* Create a direct sound object */ - if (result) - { - result = soundDrvDSoundModeInformationInitialize(&sound_drv_dsound_device_current); - } - if (!result) - { - soundDrvDSoundRelease(); - } - else - { - sound_drv_dsound_device_current.mutex = CreateMutex(nullptr, 0, nullptr); - } - - return result; -} - - -/*===========================================================================*/ -/* Emulation Shutdown */ -/*===========================================================================*/ - -void soundDrvShutdown() -{ - soundDrvDSoundModeInformationRelease(&sound_drv_dsound_device_current); - soundDrvDSoundRelease(); - if (sound_drv_dsound_device_current.mutex != nullptr) - { - CloseHandle(sound_drv_dsound_device_current.mutex); - } -} diff --git a/fellow/SRC/WinFellow/Windows/TIMER.C b/fellow/SRC/WinFellow/Windows/TIMER.C index 110953b3..38c875f5 100644 --- a/fellow/SRC/WinFellow/Windows/TIMER.C +++ b/fellow/SRC/WinFellow/Windows/TIMER.C @@ -22,7 +22,6 @@ /*=========================================================================*/ #include #include "defs.h" -#include "sound.h" #include #include "fellow.h" #include "TIMER.H" @@ -68,47 +67,47 @@ void timerAddCallback(timerCallbackFunction callback) void timerEmulationStart() { - TIMECAPS timecaps; + TIMECAPS timecaps; - timer_ticks = 0; - MMRESULT mmres = timeGetDevCaps(&timecaps, sizeof(TIMECAPS)); - if(mmres != TIMERR_NOERROR) - { - fellowAddLog("timer: timerEmulationStart() timeGetDevCaps() failed\n"); - timer_running = false; - return; - } + timer_ticks = 0; + MMRESULT mmres = timeGetDevCaps(&timecaps, sizeof(TIMECAPS)); + if (mmres != TIMERR_NOERROR) + { + fellowAddLog("timer: timerEmulationStart() timeGetDevCaps() failed\n"); + timer_running = false; + return; + } - fellowAddLog("timer: timerEmulationStart() timeGetDevCaps: min: %u, max %u\n", timecaps.wPeriodMin, timecaps.wPeriodMax); + fellowAddLog("timer: timerEmulationStart() timeGetDevCaps: min: %u, max %u\n", timecaps.wPeriodMin, timecaps.wPeriodMax); - timer_mmresolution = timecaps.wPeriodMin; + timer_mmresolution = timecaps.wPeriodMin; - mmres = timeBeginPeriod(timer_mmresolution); - if(mmres != TIMERR_NOERROR) - { - fellowAddLog("timer: timerEmulationStart() timeBeginPeriod() failed\n"); - timer_running = false; - return; - } + mmres = timeBeginPeriod(timer_mmresolution); + if (mmres != TIMERR_NOERROR) + { + fellowAddLog("timer: timerEmulationStart() timeBeginPeriod() failed\n"); + timer_running = false; + return; + } - mmres = timeSetEvent(1, 0, timerCallback, (DWORD_PTR)0, (UINT)TIME_PERIODIC); - if(mmres == 0) - { - fellowAddLog("timer: timerEmulationStart() timeSetEvent() failed\n"); - timer_running = false; - return; - } - timer_mmtimer = mmres; - timer_running = true; + mmres = timeSetEvent(1, 0, timerCallback, (DWORD_PTR)0, (UINT)TIME_PERIODIC); + if (mmres == 0) + { + fellowAddLog("timer: timerEmulationStart() timeSetEvent() failed\n"); + timer_running = false; + return; + } + timer_mmtimer = mmres; + timer_running = true; } void timerEmulationStop() { if (timer_running) { - MMRESULT mmres = timeKillEvent(timer_mmtimer); + MMRESULT mmres = timeKillEvent(timer_mmtimer); mmres = timeEndPeriod(timer_mmresolution); - if(mmres != TIMERR_NOERROR) + if (mmres != TIMERR_NOERROR) { fellowAddLog("timer: timerEmulationStop() timeEndPeriod() failed, unable to restore previous timer resolution."); } diff --git a/fellow/SRC/WinFellow/Windows/WDBG.C b/fellow/SRC/WinFellow/Windows/WDBG.C index f1056640..17e4fdfd 100644 --- a/fellow/SRC/WinFellow/Windows/WDBG.C +++ b/fellow/SRC/WinFellow/Windows/WDBG.C @@ -37,7 +37,6 @@ #include "fellow.h" #include "windrv.h" -#include "sound.h" #include "ListTree.h" #include "gameport.h" #include "config.h" @@ -51,7 +50,6 @@ #include "bus.h" #include "CopperRegisters.h" #include "graph.h" -#include "sound.h" #include "sprite.h" #include "SpriteRegisters.h" #include "modrip.h" @@ -182,26 +180,16 @@ static float g_DPIScaleX = 1, g_DPIScaleY = 1; /* Prototypes */ /*============*/ -INT_PTR CALLBACK wdbgCPUDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgMemoryDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgCIADialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgFloppyDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgBlitterDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgCopperDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgSpriteDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgScreenDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgEventDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wdbgSoundDialogProc(HWND hwndDlg, UINT uMsg, - WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgCPUDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgMemoryDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgCIADialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgFloppyDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgBlitterDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgCopperDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgSpriteDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgScreenDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgEventDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wdbgSoundDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); /*==============================================================*/ /* the various sheets of the main dialog and their dialog procs */ @@ -210,20 +198,30 @@ INT_PTR CALLBACK wdbgSoundDialogProc(HWND hwndDlg, UINT uMsg, #define DEBUG_PROP_SHEETS 10 UINT wdbg_propsheetRID[DEBUG_PROP_SHEETS] = { - IDD_DEBUG_CPU, IDD_DEBUG_MEMORY, IDD_DEBUG_CIA, - IDD_DEBUG_FLOPPY, IDD_DEBUG_BLITTER, IDD_DEBUG_COPPER, - IDD_DEBUG_SPRITES, IDD_DEBUG_SCREEN, IDD_DEBUG_EVENTS, - IDD_DEBUG_SOUND -}; - -typedef INT_PTR (CALLBACK * wdbgDlgProc) (HWND, UINT, WPARAM, LPARAM); + IDD_DEBUG_CPU, + IDD_DEBUG_MEMORY, + IDD_DEBUG_CIA, + IDD_DEBUG_FLOPPY, + IDD_DEBUG_BLITTER, + IDD_DEBUG_COPPER, + IDD_DEBUG_SPRITES, + IDD_DEBUG_SCREEN, + IDD_DEBUG_EVENTS, + IDD_DEBUG_SOUND}; + +typedef INT_PTR(CALLBACK *wdbgDlgProc)(HWND, UINT, WPARAM, LPARAM); wdbgDlgProc wdbg_propsheetDialogProc[DEBUG_PROP_SHEETS] = { - wdbgCPUDialogProc, wdbgMemoryDialogProc, wdbgCIADialogProc, - wdbgFloppyDialogProc, wdbgBlitterDialogProc, wdbgCopperDialogProc, - wdbgSpriteDialogProc, wdbgScreenDialogProc, wdbgEventDialogProc, - wdbgSoundDialogProc -}; + wdbgCPUDialogProc, + wdbgMemoryDialogProc, + wdbgCIADialogProc, + wdbgFloppyDialogProc, + wdbgBlitterDialogProc, + wdbgCopperDialogProc, + wdbgSpriteDialogProc, + wdbgScreenDialogProc, + wdbgEventDialogProc, + wdbgSoundDialogProc}; /*===============================*/ /* calculate DIP scaling factors */ @@ -247,7 +245,8 @@ INT_PTR wdbgSessionMainDialog() PROPSHEETPAGE propertysheets[DEBUG_PROP_SHEETS]; PROPSHEETHEADER propertysheetheader; - for (i = 0; i < DEBUG_PROP_SHEETS; i++) { + for (i = 0; i < DEBUG_PROP_SHEETS; i++) + { propertysheets[i].dwSize = sizeof(PROPSHEETPAGE); propertysheets[i].dwFlags = PSP_DEFAULT; propertysheets[i].hInstance = win_drv_hInstance; @@ -260,12 +259,10 @@ INT_PTR wdbgSessionMainDialog() propertysheets[i].pcRefParent = NULL; } propertysheetheader.dwSize = sizeof(PROPSHEETHEADER); - propertysheetheader.dwFlags = - PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_NOAPPLYNOW; + propertysheetheader.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_NOAPPLYNOW; propertysheetheader.hwndParent = wdbg_hDialog; propertysheetheader.hInstance = win_drv_hInstance; - propertysheetheader.hIcon = - LoadIcon(win_drv_hInstance, MAKEINTRESOURCE(IDI_ICON_WINFELLOW)); + propertysheetheader.hIcon = LoadIcon(win_drv_hInstance, MAKEINTRESOURCE(IDI_ICON_WINFELLOW)); propertysheetheader.pszCaption = "WinFellow Debugger Session"; propertysheetheader.nPages = DEBUG_PROP_SHEETS; propertysheetheader.nStartPage = 0; @@ -281,59 +278,72 @@ INT_PTR wdbgSessionMainDialog() /* helper functions */ /*============================================================================*/ -char *wdbgGetDataRegistersStr(char * s) +char *wdbgGetDataRegistersStr(char *s) { - sprintf(s, - "D0: %.8X %.8X %.8X %.8X %.8X %.8X %.8X %.8X :D7", - cpuGetDReg(0), cpuGetDReg(1), cpuGetDReg(2), cpuGetDReg(3), cpuGetDReg(4), cpuGetDReg(5), cpuGetDReg(6), cpuGetDReg(7)); + sprintf( + s, + "D0: %.8X %.8X %.8X %.8X %.8X %.8X %.8X %.8X :D7", + cpuGetDReg(0), + cpuGetDReg(1), + cpuGetDReg(2), + cpuGetDReg(3), + cpuGetDReg(4), + cpuGetDReg(5), + cpuGetDReg(6), + cpuGetDReg(7)); return s; } -char *wdbgGetAddressRegistersStr(char * s) +char *wdbgGetAddressRegistersStr(char *s) { - sprintf(s, - "A0: %.8X %.8X %.8X %.8X %.8X %.8X %.8X %.8X :A7", - cpuGetAReg(0), cpuGetAReg(1), cpuGetAReg(2), cpuGetAReg(3), cpuGetAReg(4), cpuGetAReg(5), cpuGetAReg(6), cpuGetAReg(7)); + sprintf( + s, + "A0: %.8X %.8X %.8X %.8X %.8X %.8X %.8X %.8X :A7", + cpuGetAReg(0), + cpuGetAReg(1), + cpuGetAReg(2), + cpuGetAReg(3), + cpuGetAReg(4), + cpuGetAReg(5), + cpuGetAReg(6), + cpuGetAReg(7)); return s; } -char *wdbgGetSpecialRegistersStr(char * s) +char *wdbgGetSpecialRegistersStr(char *s) { - sprintf(s, - "USP:%.8X SSP:%.8X SR:%.4X FRAME: %u y: %u x: %u", - cpuGetUspAutoMap(), cpuGetSspAutoMap(), cpuGetSR(), draw_frame_count, busGetRasterY(), busGetRasterX()); + sprintf(s, "USP:%.8X SSP:%.8X SR:%.4X FRAME: %u y: %u x: %u", cpuGetUspAutoMap(), cpuGetSspAutoMap(), cpuGetSR(), draw_frame_count, busGetRasterY(), busGetRasterX()); return s; } -void wdbgExtendStringTo80Columns(char * s) +void wdbgExtendStringTo80Columns(char *s) { uint32_t i; BOOLE zero_found = FALSE; - for (i = 0; i < 79; i++) { - if (!zero_found) - zero_found = (s[i] == '\0'); - if (zero_found) - s[i] = ' '; + for (i = 0; i < 79; i++) + { + if (!zero_found) zero_found = (s[i] == '\0'); + if (zero_found) s[i] = ' '; } s[80] = '\0'; } -uint32_t wdbgLineOut(HDC hDC, char * s, uint32_t x, uint32_t y) +uint32_t wdbgLineOut(HDC hDC, char *s, uint32_t x, uint32_t y) { struct tagSIZE text_size; SetBkMode(hDC, OPAQUE); wdbgExtendStringTo80Columns(s); - TextOut(hDC, x, y, s, (int) strlen(s)); - GetTextExtentPoint32(hDC, s, (int) strlen(s), (LPSIZE) & text_size); + TextOut(hDC, x, y, s, (int)strlen(s)); + GetTextExtentPoint32(hDC, s, (int)strlen(s), (LPSIZE)&text_size); return y + text_size.cy; } -char *wdbgGetDisassemblyLineStr(char * s, uint32_t * disasm_pc) +char *wdbgGetDisassemblyLineStr(char *s, uint32_t *disasm_pc) { - char inst_address[256] = ""; - char inst_data[256] = ""; - char inst_name[256] = ""; + char inst_address[256] = ""; + char inst_data[256] = ""; + char inst_name[256] = ""; char inst_operands[256] = ""; *disasm_pc = cpuDisOpcode(*disasm_pc, inst_address, inst_data, inst_name, inst_operands); @@ -352,27 +362,28 @@ void wdbgUpdateCPUState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); uint32_t disasm_pc; uint32_t i; - HFONT myfont = CreateFont((uint32_t)(8*g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -408,28 +419,29 @@ void wdbgUpdateMemoryState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); uint32_t i, j; - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -443,39 +455,45 @@ void wdbgUpdateMemoryState(HWND hwndDlg) BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); - for (i = 0; i < WDBG_DISASSEMBLY_LINES; i++) { + for (i = 0; i < WDBG_DISASSEMBLY_LINES; i++) + { if (memory_ascii) { - sprintf(st, "%.6X %.8X%.8X %.8X%.8X ", - (memory_adress + i * 16) & 0xffffff, - memoryReadLong(memory_adress + i * 16 + 0), - memoryReadLong(memory_adress + i * 16 + 4), - memoryReadLong(memory_adress + i * 16 + 8), - memoryReadLong(memory_adress + i * 16 + 12)); - - for (j = 0; j < 16; j++) { - k = memoryReadByte(memory_adress + i * 16 + j) & 0xff; - if (k < 32) - st[j + 41] = '.'; - else - st[j + 41] = k; - } - st[16 + 41] = '\0'; - y = wdbgLineOut(hDC, st, x, y); + sprintf( + st, + "%.6X %.8X%.8X %.8X%.8X ", + (memory_adress + i * 16) & 0xffffff, + memoryReadLong(memory_adress + i * 16 + 0), + memoryReadLong(memory_adress + i * 16 + 4), + memoryReadLong(memory_adress + i * 16 + 8), + memoryReadLong(memory_adress + i * 16 + 12)); + + for (j = 0; j < 16; j++) + { + k = memoryReadByte(memory_adress + i * 16 + j) & 0xff; + if (k < 32) + st[j + 41] = '.'; + else + st[j + 41] = k; + } + st[16 + 41] = '\0'; + y = wdbgLineOut(hDC, st, x, y); } - else + else { - sprintf(st, "%.6X %.8X%.8X %.8X%.8X %.8X%.8X %.8X%.8X", - (memory_adress + i * 32) & 0xffffff, - memoryReadLong(memory_adress + i * 32), - memoryReadLong(memory_adress + i * 32 + 4), - memoryReadLong(memory_adress + i * 32 + 8), - memoryReadLong(memory_adress + i * 32 + 12), - memoryReadLong(memory_adress + i * 32 + 16), - memoryReadLong(memory_adress + i * 32 + 20), - memoryReadLong(memory_adress + i * 32 + 24), - memoryReadLong(memory_adress + i * 32 + 28)); - y = wdbgLineOut(hDC, st, x, y); + sprintf( + st, + "%.6X %.8X%.8X %.8X%.8X %.8X%.8X %.8X%.8X", + (memory_adress + i * 32) & 0xffffff, + memoryReadLong(memory_adress + i * 32), + memoryReadLong(memory_adress + i * 32 + 4), + memoryReadLong(memory_adress + i * 32 + 8), + memoryReadLong(memory_adress + i * 32 + 12), + memoryReadLong(memory_adress + i * 32 + 16), + memoryReadLong(memory_adress + i * 32 + 20), + memoryReadLong(memory_adress + i * 32 + 24), + memoryReadLong(memory_adress + i * 32 + 28)); + y = wdbgLineOut(hDC, st, x, y); } } @@ -497,27 +515,28 @@ void wdbgUpdateCIAState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); uint32_t i; - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -531,19 +550,18 @@ void wdbgUpdateCIAState(HWND hwndDlg) BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); - for (i = 0; i < 2; i++) { + for (i = 0; i < 2; i++) + { sprintf(s, "CIA %s Registers:", (i == 0) ? "A" : "B"); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, " CRA-%.2X CRB-%.2X IREQ-%.2X IMSK-%.2X SP-%.2X", - cia[i].cra, cia[i].crb, cia[i].icrreq, cia[i].icrmsk, cia[i].sp); + sprintf(s, " CRA-%.2X CRB-%.2X IREQ-%.2X IMSK-%.2X SP-%.2X", cia[i].cra, cia[i].crb, cia[i].icrreq, cia[i].icrmsk, cia[i].sp); y = wdbgLineOut(hDC, s, x, y); sprintf(s, " EV-%.8X ALARM-%.8X", cia[i].ev, cia[i].evalarm); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, " TA-%.4X TAHELP-%.8X TB-%.4X TBHELP-%.8X", cia[i].ta, - cia[i].taleft, cia[i].tb, cia[i].tbleft); + sprintf(s, " TA-%.4X TAHELP-%.8X TB-%.4X TBHELP-%.8X", cia[i].ta, cia[i].taleft, cia[i].tb, cia[i].tbleft); y = wdbgLineOut(hDC, s, x, y); sprintf(s, " TALATCH-%.4X TBLATCH-%.4X", cia[i].talatch, cia[i].tblatch); @@ -600,28 +618,29 @@ void wdbgUpdateFloppyState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); uint32_t i; - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -637,13 +656,7 @@ void wdbgUpdateFloppyState(HWND hwndDlg) for (i = 0; i < 4; i++) { - sprintf(s, "DF%u: Track-%u Sel-%d Motor-%d Side-%d WP-%d", - i, - floppy[i].track, - floppy[i].sel, - floppy[i].motor, - floppy[i].side, - floppy[i].writeprotconfig); + sprintf(s, "DF%u: Track-%u Sel-%d Motor-%d Side-%d WP-%d", i, floppy[i].track, floppy[i].sel, floppy[i].motor, floppy[i].side, floppy[i].writeprotconfig); y = wdbgLineOut(hDC, s, x, y); } @@ -662,19 +675,15 @@ void wdbgUpdateFloppyState(HWND hwndDlg) strcpy(s, "Transfer settings:"); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "Wordsleft: %u Wait: %u Dst: %X", - floppy_DMA.wordsleft, floppy_DMA.wait, floppy_DMA.dskpt); + sprintf(s, "Wordsleft: %u Wait: %u Dst: %X", floppy_DMA.wordsleft, floppy_DMA.wait, floppy_DMA.dskpt); y = wdbgLineOut(hDC, s, x, y); #ifdef ALIGN_CHECK - sprintf(s, "Busloop: %X eol: %X copemu: %X", checkadr, end_of_line, - copemu); + sprintf(s, "Busloop: %X eol: %X copemu: %X", checkadr, end_of_line, copemu); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "68000strt:%X busstrt:%X copperstrt:%X memorystrt:%X", - m68000start, busstart, copperstart, memorystart); + sprintf(s, "68000strt:%X busstrt:%X copperstrt:%X memorystrt:%X", m68000start, busstart, copperstart, memorystart); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "sndstrt:%X sbstrt:%X blitstrt:%X", soundstart, sblaststart, - blitstart); + sprintf(s, "sndstrt:%X sbstrt:%X blitstrt:%X", soundstart, sblaststart, blitstart); y = wdbgLineOut(hDC, s, x, y); sprintf(s, "drawstrt:%X graphemstrt:%X", drawstart, graphemstart); y = wdbgLineOut(hDC, s, x, y); @@ -698,27 +707,28 @@ void wdbgUpdateBlitterState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -732,23 +742,19 @@ void wdbgUpdateBlitterState(HWND hwndDlg) BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); - sprintf(s, "bltcon: %08X bltafwm: %08X bltalwm: %08X", - blitter.bltcon, blitter.bltafwm, blitter.bltalwm); + sprintf(s, "bltcon: %08X bltafwm: %08X bltalwm: %08X", blitter.bltcon, blitter.bltafwm, blitter.bltalwm); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, ""); + sprintf(s, ""); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "bltapt: %08X bltbpt: %08X bltcpt: %08X bltdpt: %08X ", - blitter.bltapt, blitter.bltbpt, blitter.bltcpt, blitter.bltdpt); + sprintf(s, "bltapt: %08X bltbpt: %08X bltcpt: %08X bltdpt: %08X ", blitter.bltapt, blitter.bltbpt, blitter.bltcpt, blitter.bltdpt); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "bltamod: %08X bltbmod: %08X bltcmod: %08X bltdmod: %08X ", - blitter.bltamod, blitter.bltbmod, blitter.bltcmod, blitter.bltdmod); + sprintf(s, "bltamod: %08X bltbmod: %08X bltcmod: %08X bltdmod: %08X ", blitter.bltamod, blitter.bltbmod, blitter.bltcmod, blitter.bltdmod); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "bltadat: %08X bltbdat: %08X bltcdat: %08X bltzero: %08X ", - blitter.bltadat, blitter.bltbdat, blitter.bltcdat, blitter.bltzero); + sprintf(s, "bltadat: %08X bltbdat: %08X bltcdat: %08X bltzero: %08X ", blitter.bltadat, blitter.bltbdat, blitter.bltcdat, blitter.bltzero); y = wdbgLineOut(hDC, s, x, y); DeleteDC(hDC_image); @@ -769,28 +775,29 @@ void wdbgUpdateCopperState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); uint32_t i, list1, list2, atpc; - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -802,30 +809,38 @@ void wdbgUpdateCopperState(HWND hwndDlg) x = (uint32_t)(WDBG_DISASSEMBLY_X * g_DPIScaleX); y = (uint32_t)(WDBG_DISASSEMBLY_Y * g_DPIScaleY); BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); - x += (uint32_t)(WDBG_DISASSEMBLY_INDENT* g_DPIScaleX); + x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); list1 = (copper_registers.cop1lc & 0xfffffe); list2 = (copper_registers.cop2lc & 0xfffffe); - atpc = (copper_registers.copper_pc & 0xfffffe); /* Make sure debug doesn't trap odd ex */ + atpc = (copper_registers.copper_pc & 0xfffffe); /* Make sure debug doesn't trap odd ex */ - sprintf(s, "Cop1lc-%.6X Cop2lc-%.6X Copcon-%u Copper PC - %.6X", copper_registers.cop1lc, - copper_registers.cop2lc, copper_registers.copcon, copper_registers.copper_pc); + sprintf(s, "Cop1lc-%.6X Cop2lc-%.6X Copcon-%u Copper PC - %.6X", copper_registers.cop1lc, copper_registers.cop2lc, copper_registers.copcon, copper_registers.copper_pc); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "Next cycle - %u Y - %u X - %u", copperEvent.cycle, - (copperEvent.cycle != -1) ? (copperEvent.cycle / 228) : 0, - (copperEvent.cycle != -1) ? (copperEvent.cycle % 228) : 0); + sprintf( + s, + "Next cycle - %u Y - %u X - %u", + copperEvent.cycle, + (copperEvent.cycle != -1) ? (copperEvent.cycle / 228) : 0, + (copperEvent.cycle != -1) ? (copperEvent.cycle % 228) : 0); y = wdbgLineOut(hDC, s, x, y); sprintf(s, "List 1: List 2: At PC:"); y = wdbgLineOut(hDC, s, x, y); - for (i = 0; i < 16; i++) { - sprintf(s, "$%.4X, $%.4X $%.4X, $%.4X $%.4X, $%.4X", - memoryReadWord(list1), - memoryReadWord(list1 + 2), - memoryReadWord(list2), memoryReadWord(list2 + 2), memoryReadWord(atpc), memoryReadWord(atpc + 2)); + for (i = 0; i < 16; i++) + { + sprintf( + s, + "$%.4X, $%.4X $%.4X, $%.4X $%.4X, $%.4X", + memoryReadWord(list1), + memoryReadWord(list1 + 2), + memoryReadWord(list2), + memoryReadWord(list2 + 2), + memoryReadWord(atpc), + memoryReadWord(atpc + 2)); y = wdbgLineOut(hDC, s, x, y); list1 += 4; list2 += 4; @@ -850,27 +865,28 @@ void wdbgUpdateSpriteState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -884,19 +900,19 @@ void wdbgUpdateSpriteState(HWND hwndDlg) BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); - sprintf(s, "Spr0pt-%.6X Spr1pt-%.6X Spr2pt-%.6X Spr3pt - %.6X", sprite_registers.sprpt[0], - sprite_registers.sprpt[1], sprite_registers.sprpt[2], sprite_registers.sprpt[3]); + sprintf( + s, "Spr0pt-%.6X Spr1pt-%.6X Spr2pt-%.6X Spr3pt - %.6X", sprite_registers.sprpt[0], sprite_registers.sprpt[1], sprite_registers.sprpt[2], sprite_registers.sprpt[3]); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "Spr4pt-%.6X Spr5pt-%.6X Spr6pt-%.6X Spr7pt - %.6X", sprite_registers.sprpt[4], - sprite_registers.sprpt[5], sprite_registers.sprpt[6], sprite_registers.sprpt[7]); + sprintf( + s, "Spr4pt-%.6X Spr5pt-%.6X Spr6pt-%.6X Spr7pt - %.6X", sprite_registers.sprpt[4], sprite_registers.sprpt[5], sprite_registers.sprpt[6], sprite_registers.sprpt[7]); y = wdbgLineOut(hDC, s, x, y); - //for (uint32_t i = 0; i < 8; i++) { - // sprintf(s, - // "Spr%uX-%u Spr%uStartY-%u Spr%uStopY-%u Spr%uAttached-%u Spr%ustate-%u", - // i, sprx[i], i, spry[i], i, sprly[i], i, spratt[i], i, - // sprite_state[i]); + // for (uint32_t i = 0; i < 8; i++) { + // sprintf(s, + // "Spr%uX-%u Spr%uStartY-%u Spr%uStopY-%u Spr%uAttached-%u Spr%ustate-%u", + // i, sprx[i], i, spry[i], i, sprly[i], i, spratt[i], i, + // sprite_state[i]); // y = wdbgLineOut(hDC, s, x, y); //} @@ -918,27 +934,28 @@ void wdbgUpdateScreenState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -952,47 +969,38 @@ void wdbgUpdateScreenState(HWND hwndDlg) BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); - sprintf(s, "DIWSTRT - %.4X DIWSTOP - %.4X DDFSTRT - %.4X DDFSTOP - %.4X LOF - %.4X", - diwstrt, diwstop, ddfstrt, ddfstop, lof); + sprintf(s, "DIWSTRT - %.4X DIWSTOP - %.4X DDFSTRT - %.4X DDFSTOP - %.4X LOF - %.4X", diwstrt, diwstop, ddfstrt, ddfstop, lof); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "BPLCON0 - %.4X BPLCON1 - %.4X BPLCON2 - %.4X BPL1MOD - %.4X BPL2MOD - %.4X", - _core.Registers.BplCon0, bplcon1, _core.Registers.BplCon2, bpl1mod, bpl2mod); + sprintf(s, "BPLCON0 - %.4X BPLCON1 - %.4X BPLCON2 - %.4X BPL1MOD - %.4X BPL2MOD - %.4X", _core.Registers.BplCon0, bplcon1, _core.Registers.BplCon2, bpl1mod, bpl2mod); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "BPL1PT -%.6X BPL2PT -%.6X BPL3PT -%.6X BPL4PT -%.6X BPL5PT -%.6X", - bpl1pt, bpl2pt, bpl3pt, bpl4pt, bpl5pt); + sprintf(s, "BPL1PT -%.6X BPL2PT -%.6X BPL3PT -%.6X BPL4PT -%.6X BPL5PT -%.6X", bpl1pt, bpl2pt, bpl3pt, bpl4pt, bpl5pt); y = wdbgLineOut(hDC, s, x, y); - + sprintf(s, "BPL6PT -%.6X DMACON - %.4X", bpl6pt, dmacon); y = wdbgLineOut(hDC, s, x, y); y++; - const draw_rect& clip = drawGetOutputClip(); - sprintf(s, "Host window clip envelope (Hor) (Ver): (%u, %u) (%u, %u)", - clip.left, clip.right, clip.top, clip.bottom); + const draw_rect &clip = drawGetOutputClip(); + sprintf(s, "Host window clip envelope (Hor) (Ver): (%u, %u) (%u, %u)", clip.left, clip.right, clip.top, clip.bottom); y = wdbgLineOut(hDC, s, x, y); - - sprintf(s, "Even/odd scroll (lores/hires): (%u, %u) (%u, %u)", - evenscroll, evenhiscroll, oddscroll, oddhiscroll); + + sprintf(s, "Even/odd scroll (lores/hires): (%u, %u) (%u, %u)", evenscroll, evenhiscroll, oddscroll, oddhiscroll); + y = wdbgLineOut(hDC, s, x, y); + + sprintf(s, "Visible bitplane data envelope (Hor) (Ver): (%u, %u) (%u, %u)", diwxleft, diwxright, diwytop, diwybottom); y = wdbgLineOut(hDC, s, x, y); - - sprintf(s, "Visible bitplane data envelope (Hor) (Ver): (%u, %u) (%u, %u)", - diwxleft, diwxright, diwytop, diwybottom); + + sprintf(s, "DDF (First output cylinder, length in words): (%u, %u)", graph_DDF_start, graph_DDF_word_count); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "DDF (First output cylinder, length in words): (%u, %u)", - graph_DDF_start, graph_DDF_word_count); + sprintf(s, "DIW (First visible pixel, last visible pixel + 1): (%u, %u)", graph_DIW_first_visible, graph_DIW_last_visible); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "DIW (First visible pixel, last visible pixel + 1): (%u, %u)", - graph_DIW_first_visible, graph_DIW_last_visible); + sprintf(s, "Raster beam position (x, y): (%u, %u)", busGetRasterX(), busGetRasterY()); y = wdbgLineOut(hDC, s, x, y); - sprintf(s, "Raster beam position (x, y): (%u, %u)", - busGetRasterX(), busGetRasterY()); - y = wdbgLineOut(hDC, s, x, y); - DeleteDC(hDC_image); DeleteObject(myarrow); DeleteObject(myfont); @@ -1011,27 +1019,28 @@ void wdbgUpdateEventState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -1078,28 +1087,29 @@ void wdbgUpdateSoundState(HWND hwndDlg) PAINTSTRUCT paint_struct; hDC = BeginPaint(hwndDlg, &paint_struct); - if (hDC != NULL) { + if (hDC != NULL) + { uint32_t y = (uint32_t)(WDBG_CPU_REGISTERS_Y * g_DPIScaleY); uint32_t x = (uint32_t)(WDBG_CPU_REGISTERS_X * g_DPIScaleX); uint32_t i; - HFONT myfont = CreateFont((uint32_t)(8 * g_DPIScaleY), - (uint32_t)(8 * g_DPIScaleX), - 0, - 0, - FW_NORMAL, - FALSE, - FALSE, - FALSE, - DEFAULT_CHARSET, - OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, - FF_DONTCARE | FIXED_PITCH, - "fixedsys"); - - HBITMAP myarrow = LoadBitmap(win_drv_hInstance, - MAKEINTRESOURCE(IDB_DEBUG_ARROW)); + HFONT myfont = CreateFont( + (uint32_t)(8 * g_DPIScaleY), + (uint32_t)(8 * g_DPIScaleX), + 0, + 0, + FW_NORMAL, + FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE | FIXED_PITCH, + "fixedsys"); + + HBITMAP myarrow = LoadBitmap(win_drv_hInstance, MAKEINTRESOURCE(IDB_DEBUG_ARROW)); HDC hDC_image = CreateCompatibleDC(hDC); SelectObject(hDC_image, myarrow); SelectObject(hDC, myfont); @@ -1113,20 +1123,26 @@ void wdbgUpdateSoundState(HWND hwndDlg) BitBlt(hDC, x, y + 2, 14, 14, hDC_image, 0, 0, SRCCOPY); x += (uint32_t)(WDBG_DISASSEMBLY_INDENT * g_DPIScaleX); - sprintf(s, "A0: %X A1: %X A2: %X A3: %X A5: %X", soundState0, soundState1, - soundState2, soundState3, soundState5); + sprintf(s, "A0: %X A1: %X A2: %X A3: %X A5: %X", soundState0, soundState1, soundState2, soundState3, soundState5); y = wdbgLineOut(hDC, s, x, y); - for (i = 0; i < 4; i++) { - sprintf(s, - "Ch%u State: %2d Lenw: %5u Len: %5u per: %5u Pcnt: %5X Vol: %5u", - i, - (audstate[i] == soundState0) ? 0 : - (audstate[i] == soundState1) ? 1 : - (audstate[i] == soundState2) ? 2 : - (audstate[i] == soundState3) ? 3 : - (audstate[i] == soundState5) ? 5 : -1, audlenw[i], - audlen[i], audper[i], audpercounter[i], audvol[i]); + for (i = 0; i < 4; i++) + { + sprintf( + s, + "Ch%u State: %2d Lenw: %5u Len: %5u per: %5u Pcnt: %5X Vol: %5u", + i, + (audstate[i] == soundState0) ? 0 + : (audstate[i] == soundState1) ? 1 + : (audstate[i] == soundState2) ? 2 + : (audstate[i] == soundState3) ? 3 + : (audstate[i] == soundState5) ? 5 + : -1, + audlenw[i], + audlen[i], + audper[i], + audpercounter[i], + audvol[i]); y = wdbgLineOut(hDC, s, x, y); } @@ -1144,45 +1160,44 @@ void wdbgUpdateSoundState(HWND hwndDlg) /* DialogProc for our CPU dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgCPUDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgCPUDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateCPUState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateCPUState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_CPU_STEP: - if (winDrvDebugStart(DBG_STEP, hwndDlg)) { - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - } - break; - case IDC_DEBUG_CPU_STEP_OVER: - if (winDrvDebugStart(DBG_STEP_OVER, hwndDlg)) { - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - } - break; - case IDC_DEBUG_CPU_RUN: - if (winDrvDebugStart(DBG_RUN, hwndDlg)) { - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - } - break; - case IDC_DEBUG_CPU_BREAK: - fellowRequestEmulationStop(); - InvalidateRect(hwndDlg, NULL, FALSE); - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_CPU_STEP: + if (winDrvDebugStart(DBG_STEP, hwndDlg)) + { + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + } + break; + case IDC_DEBUG_CPU_STEP_OVER: + if (winDrvDebugStart(DBG_STEP_OVER, hwndDlg)) + { + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + } + break; + case IDC_DEBUG_CPU_RUN: + if (winDrvDebugStart(DBG_RUN, hwndDlg)) + { + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + } + break; + case IDC_DEBUG_CPU_BREAK: + fellowRequestEmulationStop(); + InvalidateRect(hwndDlg, NULL, FALSE); + break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1191,55 +1206,51 @@ INT_PTR CALLBACK wdbgCPUDialogProc(HWND hwndDlg, /* DialogProc for our memory dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgMemoryDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgMemoryDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateMemoryState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateMemoryState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - memory_adress = (memory_adress - 32) & 0xffffff; - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - break; - case IDC_DEBUG_MEMORY_DOWN: - memory_adress = (memory_adress + 32) & 0xffffff; - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - break; - case IDC_DEBUG_MEMORY_PGUP: - memory_adress = (memory_adress - memory_padd) & 0xffffff; - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - break; - case IDC_DEBUG_MEMORY_PGDN: - memory_adress = (memory_adress + memory_padd) & 0xffffff; - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - break; - case IDC_DEBUG_MEMORY_ASCII: - memory_ascii = TRUE; - memory_padd = WDBG_DISASSEMBLY_LINES * 16; - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - break; - case IDC_DEBUG_MEMORY_HEX: - memory_ascii = FALSE; - memory_padd = WDBG_DISASSEMBLY_LINES * 32; - InvalidateRect(hwndDlg, NULL, FALSE); - SetFocus(hwndDlg); - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: + memory_adress = (memory_adress - 32) & 0xffffff; + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + break; + case IDC_DEBUG_MEMORY_DOWN: + memory_adress = (memory_adress + 32) & 0xffffff; + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + break; + case IDC_DEBUG_MEMORY_PGUP: + memory_adress = (memory_adress - memory_padd) & 0xffffff; + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + break; + case IDC_DEBUG_MEMORY_PGDN: + memory_adress = (memory_adress + memory_padd) & 0xffffff; + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + break; + case IDC_DEBUG_MEMORY_ASCII: + memory_ascii = TRUE; + memory_padd = WDBG_DISASSEMBLY_LINES * 16; + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + break; + case IDC_DEBUG_MEMORY_HEX: + memory_ascii = FALSE; + memory_padd = WDBG_DISASSEMBLY_LINES * 32; + InvalidateRect(hwndDlg, NULL, FALSE); + SetFocus(hwndDlg); + break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1248,25 +1259,20 @@ INT_PTR CALLBACK wdbgMemoryDialogProc(HWND hwndDlg, /* DialogProc for our CIA dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgCIADialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgCIADialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateCIAState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateCIAState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1275,25 +1281,20 @@ INT_PTR CALLBACK wdbgCIADialogProc(HWND hwndDlg, /* DialogProc for our floppy dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgFloppyDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgFloppyDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateFloppyState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateFloppyState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1302,29 +1303,21 @@ INT_PTR CALLBACK wdbgFloppyDialogProc(HWND hwndDlg, /* DialogProc for our blitter dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgBlitterDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgBlitterDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - Button_SetCheck(GetDlgItem(hwndDlg, IDC_DEBUG_LOGBLT), blitterGetOperationLog()); - return TRUE; - case WM_PAINT: - wdbgUpdateBlitterState(hwndDlg); - break; - case WM_DESTROY: - blitterSetOperationLog(Button_GetCheck(GetDlgItem(hwndDlg, IDC_DEBUG_LOGBLT))); - break; + switch (uMsg) + { + case WM_INITDIALOG: Button_SetCheck(GetDlgItem(hwndDlg, IDC_DEBUG_LOGBLT), blitterGetOperationLog()); return TRUE; + case WM_PAINT: wdbgUpdateBlitterState(hwndDlg); break; + case WM_DESTROY: blitterSetOperationLog(Button_GetCheck(GetDlgItem(hwndDlg, IDC_DEBUG_LOGBLT))); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1333,25 +1326,20 @@ INT_PTR CALLBACK wdbgBlitterDialogProc(HWND hwndDlg, /* DialogProc for our copper dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgCopperDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgCopperDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateCopperState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateCopperState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1360,25 +1348,20 @@ INT_PTR CALLBACK wdbgCopperDialogProc(HWND hwndDlg, /* DialogProc for our sprite dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgSpriteDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgSpriteDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateSpriteState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateSpriteState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1387,25 +1370,20 @@ INT_PTR CALLBACK wdbgSpriteDialogProc(HWND hwndDlg, /* DialogProc for our screen dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgScreenDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgScreenDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateScreenState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateScreenState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1414,25 +1392,20 @@ INT_PTR CALLBACK wdbgScreenDialogProc(HWND hwndDlg, /* DialogProc for our event dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgEventDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgEventDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateEventState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateEventState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MEMORY_UP: - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MEMORY_UP: break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1441,29 +1414,21 @@ INT_PTR CALLBACK wdbgEventDialogProc(HWND hwndDlg, /* DialogProc for our sound dialog */ /*============================================================================*/ -INT_PTR CALLBACK wdbgSoundDialogProc(HWND hwndDlg, - UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK wdbgSoundDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - return TRUE; - case WM_PAINT: - wdbgUpdateSoundState(hwndDlg); - break; + switch (uMsg) + { + case WM_INITDIALOG: return TRUE; + case WM_PAINT: wdbgUpdateSoundState(hwndDlg); break; case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_DEBUG_MODRIP: - modripRIP(); - break; - case IDC_DEBUG_DUMPCHIP: - modripChipDump(); - break; - default: - break; + switch (LOWORD(wParam)) + { + case IDC_DEBUG_MODRIP: modripRIP(); break; + case IDC_DEBUG_DUMPCHIP: modripChipDump(); break; + default: break; } break; - default: - break; + default: break; } return FALSE; } @@ -1480,11 +1445,11 @@ void wdbgDebugSessionRun(HWND parent) /* The configuration has been activated, but we must prepare the modules */ /* for emulation ourselves */ - if (wguiCheckEmulationNecessities()) { + if (wguiCheckEmulationNecessities()) + { wdbg_hDialog = parent; fellowEmulationStart(); - if (fellowGetPreStartReset()) - fellowHardReset(); + if (fellowGetPreStartReset()) fellowHardReset(); wdbgSessionMainDialog(); fellowEmulationStop(); } @@ -1510,7 +1475,7 @@ void wdebInitInstructionColumns() { LV_COLUMN lv_col; LV_ITEM lv_item; - HWND hList=GetDlgItem(wdeb_hDialog, IDC_LST_INSTRUCTIONS); + HWND hList = GetDlgItem(wdeb_hDialog, IDC_LST_INSTRUCTIONS); memset(&lv_col, 0, sizeof(lv_col)); lv_col.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; @@ -1553,19 +1518,15 @@ void wdebInitInstructionColumns() lv_item.iSubItem = 2; ListView_SetItem(hList, &lv_item); } - } -char *wdbg_registernames[] = -{"D0","D1","D2","D3","D4","D5","D6","D7", -"A0","A1","A2","A3","A4","A5","A6","A7", -"PC","USP","SSP","MSP","ISP","VBR","SR"}; +char *wdbg_registernames[] = {"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "PC", "USP", "SSP", "MSP", "ISP", "VBR", "SR"}; void wdebInitRegisterColumns() { LV_COLUMN lv_col; LV_ITEM lv_item; - HWND hList=GetDlgItem(wdeb_hDialog, IDC_LST_REGISTERS); + HWND hList = GetDlgItem(wdeb_hDialog, IDC_LST_REGISTERS); memset(&lv_col, 0, sizeof(lv_col)); lv_col.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; @@ -1598,7 +1559,7 @@ void wdebInitRegisterColumns() void wdebInitInfoColumns() { LV_COLUMN lv_col; - HWND hList=GetDlgItem(wdeb_hDialog, IDC_LST_INFO); + HWND hList = GetDlgItem(wdeb_hDialog, IDC_LST_INFO); memset(&lv_col, 0, sizeof(lv_col)); lv_col.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; @@ -1616,7 +1577,7 @@ void wdebInitInfoColumns() void wdebUpdateInstructionColumns() { LV_ITEM lv_item; - HWND hList=GetDlgItem(wdeb_hDialog, IDC_LST_INSTRUCTIONS); + HWND hList = GetDlgItem(wdeb_hDialog, IDC_LST_INSTRUCTIONS); uint32_t disasm_pc = cpuGetPC(); char inst_address[256]; char inst_data[256]; @@ -1654,7 +1615,7 @@ void wdebUpdateInstructionColumns() void wdebUpdateRegisterColumns() { LV_ITEM lv_item; - HWND hList=GetDlgItem(wdeb_hDialog, IDC_LST_REGISTERS); + HWND hList = GetDlgItem(wdeb_hDialog, IDC_LST_REGISTERS); uint32_t disasm_pc = cpuGetPC(); char tmp[16]; @@ -1715,7 +1676,6 @@ void wdebUpdateRegisterColumns() lv_item.iItem = col++; lv_item.iSubItem = 1; ListView_SetItem(hList, &lv_item); - } void wdebUpdateCpuDisplay() @@ -1726,83 +1686,67 @@ void wdebUpdateCpuDisplay() BOOLE wdeb_is_working = FALSE; -INT_PTR CALLBACK wdebDebuggerDialogProc(HWND hwndDlg, - UINT uMsg, - WPARAM wParam, - LPARAM lParam) +INT_PTR CALLBACK wdebDebuggerDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { - case WM_INITDIALOG: - wdeb_action = WDEB_INIT_DIALOG; - return TRUE; - case WM_PAINT: - wdebUpdateCpuDisplay(); - break; - case WM_DESTROY: - break; + case WM_INITDIALOG: wdeb_action = WDEB_INIT_DIALOG; return TRUE; + case WM_PAINT: wdebUpdateCpuDisplay(); break; + case WM_DESTROY: break; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { - switch (LOWORD(wParam)) - { - case IDC_BTN_STEP1: - if (!wdeb_is_working) - { - wdeb_is_working = TRUE; - winDrvDebugStart(DBG_STEP, hwndDlg); - wdebUpdateCpuDisplay(); - wdeb_is_working = FALSE; - } - break; - case IDC_BTN_STEP_OVER: - if (!wdeb_is_working) - { - wdeb_is_working = TRUE; - winDrvDebugStart(DBG_STEP_OVER, hwndDlg); - wdebUpdateCpuDisplay(); - wdeb_is_working = FALSE; - } - break; - case IDC_BTN_RUN: - if (!wdeb_is_working) - { - wdeb_is_working = TRUE; - winDrvDebugStart(DBG_RUN, hwndDlg); - wdebUpdateCpuDisplay(); - wdeb_is_working = FALSE; - } - break; - case IDC_BTN_MODRIP: - modripRIP(); - break; - case IDC_BTN_DUMPCHIP: - modripChipDump(); + switch (LOWORD(wParam)) + { + case IDC_BTN_STEP1: + if (!wdeb_is_working) + { + wdeb_is_working = TRUE; + winDrvDebugStart(DBG_STEP, hwndDlg); + wdebUpdateCpuDisplay(); + wdeb_is_working = FALSE; + } + break; + case IDC_BTN_STEP_OVER: + if (!wdeb_is_working) + { + wdeb_is_working = TRUE; + winDrvDebugStart(DBG_STEP_OVER, hwndDlg); + wdebUpdateCpuDisplay(); + wdeb_is_working = FALSE; + } + break; + case IDC_BTN_RUN: + if (!wdeb_is_working) + { + wdeb_is_working = TRUE; + winDrvDebugStart(DBG_RUN, hwndDlg); + wdebUpdateCpuDisplay(); + wdeb_is_working = FALSE; + } break; - case IDC_BTN_BREAK: - if (wdeb_is_working) - { - fellowRequestEmulationStop(); - } - break; - case IDOK: - case IDCANCEL: - wdeb_action = WDEB_EXIT; - break; - default: - break; - } + case IDC_BTN_MODRIP: modripRIP(); break; + case IDC_BTN_DUMPCHIP: modripChipDump(); break; + case IDC_BTN_BREAK: + if (wdeb_is_working) + { + fellowRequestEmulationStop(); + } + break; + case IDOK: + case IDCANCEL: wdeb_action = WDEB_EXIT; break; + default: break; + } } break; - default: - break; + default: break; } return FALSE; } void wdebCreateDialog() { - wdeb_hDialog = CreateDialog(win_drv_hInstance, MAKEINTRESOURCE(IDD_DEBUGGER), NULL, wdebDebuggerDialogProc); + wdeb_hDialog = CreateDialog(win_drv_hInstance, MAKEINTRESOURCE(IDD_DEBUGGER), NULL, wdebDebuggerDialogProc); ShowWindow(wdeb_hDialog, win_drv_nCmdShow); } @@ -1816,23 +1760,20 @@ void wdebDoMessages() { if (!IsDialogMessage(wdeb_hDialog, &myMsg)) { - TranslateMessage(&myMsg); - DispatchMessage(&myMsg); + TranslateMessage(&myMsg); + DispatchMessage(&myMsg); } } switch (wdeb_action) { case WDEB_INIT_DIALOG: - wdebInitInstructionColumns(); - wdebInitRegisterColumns(); - wdebInitInfoColumns(); - wdebUpdateCpuDisplay(); - break; - case WDEB_EXIT: - end_loop = TRUE; - break; - default: - break; + wdebInitInstructionColumns(); + wdebInitRegisterColumns(); + wdebInitInfoColumns(); + wdebUpdateCpuDisplay(); + break; + case WDEB_EXIT: end_loop = TRUE; break; + default: break; } wdeb_action = WDEB_NO_ACTION; } diff --git a/fellow/SRC/WinFellow/Windows/WGUI.C b/fellow/SRC/WinFellow/Windows/WGUI.C index 6b0b61a2..cdd78b19 100644 --- a/fellow/SRC/WinFellow/Windows/WGUI.C +++ b/fellow/SRC/WinFellow/Windows/WGUI.C @@ -50,7 +50,6 @@ #include "commoncontrol_wrap.h" #include "wgui.h" #include "windrv.h" -#include "sound.h" #include "ListTree.h" #include "gameport.h" #include "fellow/api/module/IHardfileHandler.h" @@ -72,14 +71,15 @@ #include "FFILESYS.H" using namespace fellow::api::module; +using namespace CustomChipset; -HWND wgui_hDialog; /* Handle of the main dialog box */ -cfg *wgui_cfg; /* GUI copy of configuration */ -ini *wgui_ini; /* GUI copy of initdata */ +HWND wgui_hDialog; /* Handle of the main dialog box */ +cfg *wgui_cfg; /* GUI copy of configuration */ +ini *wgui_ini; /* GUI copy of initdata */ char extractedfilename[CFG_FILENAME_LENGTH]; char extractedpathname[CFG_FILENAME_LENGTH]; -wgui_drawmodes wgui_dm; // data structure for resolution data +wgui_drawmodes wgui_dm; // data structure for resolution data wgui_drawmode *pwgui_dm_match; BOOLE wgui_emulation_state = FALSE; HBITMAP power_led_on_bitmap = nullptr; @@ -91,135 +91,110 @@ HBITMAP diskdrive_led_off_bitmap = nullptr; #define MAX_DISKDRIVES 4 kbd_event gameport_keys_events[MAX_JOYKEY_PORT][MAX_JOYKEY_VALUE] = { - { - EVENT_JOY0_UP_ACTIVE, - EVENT_JOY0_DOWN_ACTIVE, - EVENT_JOY0_LEFT_ACTIVE, - EVENT_JOY0_RIGHT_ACTIVE, - EVENT_JOY0_FIRE0_ACTIVE, - EVENT_JOY0_FIRE1_ACTIVE, - EVENT_JOY0_AUTOFIRE0_ACTIVE, - EVENT_JOY0_AUTOFIRE1_ACTIVE - }, - { - EVENT_JOY1_UP_ACTIVE, - EVENT_JOY1_DOWN_ACTIVE, - EVENT_JOY1_LEFT_ACTIVE, - EVENT_JOY1_RIGHT_ACTIVE, - EVENT_JOY1_FIRE0_ACTIVE, - EVENT_JOY1_FIRE1_ACTIVE, - EVENT_JOY1_AUTOFIRE0_ACTIVE, - EVENT_JOY1_AUTOFIRE1_ACTIVE - } -}; + {EVENT_JOY0_UP_ACTIVE, + EVENT_JOY0_DOWN_ACTIVE, + EVENT_JOY0_LEFT_ACTIVE, + EVENT_JOY0_RIGHT_ACTIVE, + EVENT_JOY0_FIRE0_ACTIVE, + EVENT_JOY0_FIRE1_ACTIVE, + EVENT_JOY0_AUTOFIRE0_ACTIVE, + EVENT_JOY0_AUTOFIRE1_ACTIVE}, + {EVENT_JOY1_UP_ACTIVE, + EVENT_JOY1_DOWN_ACTIVE, + EVENT_JOY1_LEFT_ACTIVE, + EVENT_JOY1_RIGHT_ACTIVE, + EVENT_JOY1_FIRE0_ACTIVE, + EVENT_JOY1_FIRE1_ACTIVE, + EVENT_JOY1_AUTOFIRE0_ACTIVE, + EVENT_JOY1_AUTOFIRE1_ACTIVE}}; int gameport_keys_labels[MAX_JOYKEY_PORT][MAX_JOYKEY_VALUE] = { - { IDC_GAMEPORT0_UP, IDC_GAMEPORT0_DOWN, IDC_GAMEPORT0_LEFT, IDC_GAMEPORT0_RIGHT, IDC_GAMEPORT0_FIRE0, IDC_GAMEPORT0_FIRE1, IDC_GAMEPORT0_AUTOFIRE0, IDC_GAMEPORT0_AUTOFIRE1 }, - { IDC_GAMEPORT1_UP, IDC_GAMEPORT1_DOWN, IDC_GAMEPORT1_LEFT, IDC_GAMEPORT1_RIGHT, IDC_GAMEPORT1_FIRE0, IDC_GAMEPORT1_FIRE1, IDC_GAMEPORT1_AUTOFIRE0, IDC_GAMEPORT1_AUTOFIRE1 } -}; - + {IDC_GAMEPORT0_UP, + IDC_GAMEPORT0_DOWN, + IDC_GAMEPORT0_LEFT, + IDC_GAMEPORT0_RIGHT, + IDC_GAMEPORT0_FIRE0, + IDC_GAMEPORT0_FIRE1, + IDC_GAMEPORT0_AUTOFIRE0, + IDC_GAMEPORT0_AUTOFIRE1}, + {IDC_GAMEPORT1_UP, + IDC_GAMEPORT1_DOWN, + IDC_GAMEPORT1_LEFT, + IDC_GAMEPORT1_RIGHT, + IDC_GAMEPORT1_FIRE0, + IDC_GAMEPORT1_FIRE1, + IDC_GAMEPORT1_AUTOFIRE0, + IDC_GAMEPORT1_AUTOFIRE1}}; #define DISKDRIVE_PROPERTIES 3 #define DISKDRIVE_PROPERTIES_MAIN 4 int diskimage_data[MAX_DISKDRIVES][DISKDRIVE_PROPERTIES] = { - {IDC_EDIT_DF0_IMAGENAME, IDC_CHECK_DF0_ENABLED, IDC_CHECK_DF0_READONLY}, - {IDC_EDIT_DF1_IMAGENAME, IDC_CHECK_DF1_ENABLED, IDC_CHECK_DF1_READONLY}, - {IDC_EDIT_DF2_IMAGENAME, IDC_CHECK_DF2_ENABLED, IDC_CHECK_DF2_READONLY}, - {IDC_EDIT_DF3_IMAGENAME, IDC_CHECK_DF3_ENABLED, IDC_CHECK_DF3_READONLY} -}; + {IDC_EDIT_DF0_IMAGENAME, IDC_CHECK_DF0_ENABLED, IDC_CHECK_DF0_READONLY}, + {IDC_EDIT_DF1_IMAGENAME, IDC_CHECK_DF1_ENABLED, IDC_CHECK_DF1_READONLY}, + {IDC_EDIT_DF2_IMAGENAME, IDC_CHECK_DF2_ENABLED, IDC_CHECK_DF2_READONLY}, + {IDC_EDIT_DF3_IMAGENAME, IDC_CHECK_DF3_ENABLED, IDC_CHECK_DF3_READONLY}}; -enum {DID_IMAGENAME, DID_ENABLED, DID_READONLY}; +enum +{ + DID_IMAGENAME, + DID_ENABLED, + DID_READONLY +}; int diskimage_data_main[MAX_DISKDRIVES][DISKDRIVE_PROPERTIES_MAIN] = { - {IDC_EDIT_DF0_IMAGENAME_MAIN, IDC_BUTTON_DF0_EJECT_MAIN, IDC_BUTTON_DF0_FILEDIALOG_MAIN, IDC_IMAGE_DF0_LED_MAIN}, - {IDC_EDIT_DF1_IMAGENAME_MAIN, IDC_BUTTON_DF1_EJECT_MAIN, IDC_BUTTON_DF1_FILEDIALOG_MAIN, IDC_IMAGE_DF1_LED_MAIN}, - {IDC_EDIT_DF2_IMAGENAME_MAIN, IDC_BUTTON_DF2_EJECT_MAIN, IDC_BUTTON_DF2_FILEDIALOG_MAIN, IDC_IMAGE_DF2_LED_MAIN}, - {IDC_EDIT_DF3_IMAGENAME_MAIN, IDC_BUTTON_DF3_EJECT_MAIN, IDC_BUTTON_DF3_FILEDIALOG_MAIN, IDC_IMAGE_DF3_LED_MAIN} -}; + {IDC_EDIT_DF0_IMAGENAME_MAIN, IDC_BUTTON_DF0_EJECT_MAIN, IDC_BUTTON_DF0_FILEDIALOG_MAIN, IDC_IMAGE_DF0_LED_MAIN}, + {IDC_EDIT_DF1_IMAGENAME_MAIN, IDC_BUTTON_DF1_EJECT_MAIN, IDC_BUTTON_DF1_FILEDIALOG_MAIN, IDC_IMAGE_DF1_LED_MAIN}, + {IDC_EDIT_DF2_IMAGENAME_MAIN, IDC_BUTTON_DF2_EJECT_MAIN, IDC_BUTTON_DF2_FILEDIALOG_MAIN, IDC_IMAGE_DF2_LED_MAIN}, + {IDC_EDIT_DF3_IMAGENAME_MAIN, IDC_BUTTON_DF3_EJECT_MAIN, IDC_BUTTON_DF3_FILEDIALOG_MAIN, IDC_IMAGE_DF3_LED_MAIN}}; -enum {DID_IMAGENAME_MAIN, DID_EJECT_MAIN, DID_FILEDIALOG_MAIN, DID_LED_MAIN}; +enum +{ + DID_IMAGENAME_MAIN, + DID_EJECT_MAIN, + DID_FILEDIALOG_MAIN, + DID_LED_MAIN +}; #define NUMBER_OF_CHIPRAM_SIZES 8 -char *wgui_chipram_strings[NUMBER_OF_CHIPRAM_SIZES] = { - "256 KB", - "512 KB", - "768 KB", - "1024 KB", - "1280 KB", - "1536 KB", - "1792 KB", - "2048 KB" -}; +char *wgui_chipram_strings[NUMBER_OF_CHIPRAM_SIZES] = {"256 KB", "512 KB", "768 KB", "1024 KB", "1280 KB", "1536 KB", "1792 KB", "2048 KB"}; #define NUMBER_OF_FASTRAM_SIZES 5 -char *wgui_fastram_strings[NUMBER_OF_FASTRAM_SIZES] = { - "0 MB", - "1 MB", - "2 MB", - "4 MB", - "8 MB" -}; +char *wgui_fastram_strings[NUMBER_OF_FASTRAM_SIZES] = {"0 MB", "1 MB", "2 MB", "4 MB", "8 MB"}; #define NUMBER_OF_BOGORAM_SIZES 8 -char *wgui_bogoram_strings[NUMBER_OF_BOGORAM_SIZES] = { - "0 KB", - "256 KB", - "512 KB", - "768 KB", - "1024 KB", - "1280 KB", - "1536 KB", - "1792 KB" -}; +char *wgui_bogoram_strings[NUMBER_OF_BOGORAM_SIZES] = {"0 KB", "256 KB", "512 KB", "768 KB", "1024 KB", "1280 KB", "1536 KB", "1792 KB"}; -//from sound.h: typedef enum {SOUND_15650, SOUND_22050, SOUND_31300, SOUND_44100} sound_rates; +// from sound.h: typedef enum {SOUND_15650, SOUND_22050, SOUND_31300, SOUND_44100} sound_rates; #define NUMBER_OF_SOUND_RATES 4 -int wgui_sound_rates_cci[NUMBER_OF_SOUND_RATES] = { - IDC_RADIO_SOUND_15650, - IDC_RADIO_SOUND_22050, - IDC_RADIO_SOUND_31300, - IDC_RADIO_SOUND_44100 -}; +int wgui_sound_rates_cci[NUMBER_OF_SOUND_RATES] = {IDC_RADIO_SOUND_15650, IDC_RADIO_SOUND_22050, IDC_RADIO_SOUND_31300, IDC_RADIO_SOUND_44100}; -//from sound.h: typedef enum {SOUND_FILTER_ORIGINAL, SOUND_FILTER_ALWAYS, SOUND_FILTER_NEVER} sound_filters; +// from sound.h: typedef enum {SOUND_FILTER_ORIGINAL, SOUND_FILTER_ALWAYS, SOUND_FILTER_NEVER} sound_filters; #define NUMBER_OF_SOUND_FILTERS 3 -int wgui_sound_filters_cci[NUMBER_OF_SOUND_FILTERS] = { - IDC_RADIO_SOUND_FILTER_ORIGINAL, - IDC_RADIO_SOUND_FILTER_ALWAYS, - IDC_RADIO_SOUND_FILTER_NEVER -}; +int wgui_sound_filters_cci[NUMBER_OF_SOUND_FILTERS] = {IDC_RADIO_SOUND_FILTER_ORIGINAL, IDC_RADIO_SOUND_FILTER_ALWAYS, IDC_RADIO_SOUND_FILTER_NEVER}; - -//from CpuIntegration.h: typedef enum {M68000 = 0, M68010 = 1, M68020 = 2, M68030 = 3, M68EC30 = 4, M68040 = 5, M68EC40 = 6, M68060 = 7, M68EC60 = 8, M68EC20 = 9} cpu_types; +// from CpuIntegration.h: typedef enum {M68000 = 0, M68010 = 1, M68020 = 2, M68030 = 3, M68EC30 = 4, M68040 = 5, M68EC40 = 6, M68060 = 7, M68EC60 = 8, M68EC20 = 9} +// cpu_types; #define NUMBER_OF_CPUS 10 int wgui_cpus_cci[NUMBER_OF_CPUS] = { - IDC_RADIO_68000, - IDC_RADIO_68010, - IDC_RADIO_68020, - IDC_RADIO_68030, - IDC_RADIO_68EC30, - IDC_RADIO_68040, - IDC_RADIO_68EC40, - IDC_RADIO_68060, - IDC_RADIO_68EC60, - IDC_RADIO_68EC20 -}; - -//from gameport.h: typedef enum {GP_NONE, GP_JOYKEY0, GP_JOYKEY1, GP_ANALOG0, GP_ANALOG1, GP_MOUSE0, GP_MOUSE1} gameport_inputs; + IDC_RADIO_68000, + IDC_RADIO_68010, + IDC_RADIO_68020, + IDC_RADIO_68030, + IDC_RADIO_68EC30, + IDC_RADIO_68040, + IDC_RADIO_68EC40, + IDC_RADIO_68060, + IDC_RADIO_68EC60, + IDC_RADIO_68EC20}; + +// from gameport.h: typedef enum {GP_NONE, GP_JOYKEY0, GP_JOYKEY1, GP_ANALOG0, GP_ANALOG1, GP_MOUSE0, GP_MOUSE1} gameport_inputs; #define NUMBER_OF_GAMEPORT_STRINGS 6 -char *wgui_gameport_strings[NUMBER_OF_GAMEPORT_STRINGS] = { - "none", - "keyboard layout 1", - "keyboard layout 2", - "joystick 1", - "joystick 2", - "mouse" -}; +char *wgui_gameport_strings[NUMBER_OF_GAMEPORT_STRINGS] = {"none", "keyboard layout 1", "keyboard layout 2", "joystick 1", "joystick 2", "mouse"}; // preset handling char wgui_preset_path[CFG_FILENAME_LENGTH] = ""; @@ -230,7 +205,8 @@ wgui_preset *wgui_presets = nullptr; /* Flags for various global events */ /*============================================================================*/ -typedef enum { +typedef enum +{ WGUI_NO_ACTION, WGUI_START_EMULATION, WGUI_QUIT_EMULATOR, @@ -255,20 +231,20 @@ wguiActions wgui_action; /* Forward declarations for each property sheet dialog procedure */ /*============================================================================*/ -INT_PTR CALLBACK wguiPresetDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiCPUDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiFloppyDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiFloppyCreateDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiMemoryDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiDisplayDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiSoundDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiFilesystemAddDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiFilesystemDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiPresetDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiCPUDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiFloppyDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiFloppyCreateDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiMemoryDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiSoundDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiFilesystemAddDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiFilesystemDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK wguiHardfileCreateDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiHardfileAddDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiHardfileDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiGameportDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK wguiVariousDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiHardfileAddDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiHardfileDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiGameportDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK wguiVariousDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); /*============================================================================*/ /* The following tables defines the data needed to create the property */ @@ -280,76 +256,54 @@ INT_PTR CALLBACK wguiVariousDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wPa #define PROP_SHEETS 10 -typedef enum { - PROPSHEETPRESETS = 0, - PROPSHEETCPU = 1, - PROPSHEETFLOPPY = 2, - PROPSHEETMEMORY = 3, - PROPSHEETDISPLAY = 4, - PROPSHEETSOUND = 5, +typedef enum +{ + PROPSHEETPRESETS = 0, + PROPSHEETCPU = 1, + PROPSHEETFLOPPY = 2, + PROPSHEETMEMORY = 3, + PROPSHEETDISPLAY = 4, + PROPSHEETSOUND = 5, PROPSHEETFILESYSTEM = 6, - PROPSHEETHARDFILE = 7, - PROPSHEETGAMEPORT = 8, - PROPSHEETVARIOUS = 9 + PROPSHEETHARDFILE = 7, + PROPSHEETGAMEPORT = 8, + PROPSHEETVARIOUS = 9 } PROPERTYSHEETNAMES; -UINT wgui_propsheetRID[PROP_SHEETS] = { - IDD_PRESETS, - IDD_CPU, - IDD_FLOPPY, - IDD_MEMORY, - IDD_DISPLAY, - IDD_SOUND, - IDD_FILESYSTEM, - IDD_HARDFILE, - IDD_GAMEPORT, - IDD_VARIOUS -}; +UINT wgui_propsheetRID[PROP_SHEETS] = {IDD_PRESETS, IDD_CPU, IDD_FLOPPY, IDD_MEMORY, IDD_DISPLAY, IDD_SOUND, IDD_FILESYSTEM, IDD_HARDFILE, IDD_GAMEPORT, IDD_VARIOUS}; UINT wgui_propsheetICON[PROP_SHEETS] = { - 0, - IDI_ICON_CPU, - IDI_ICON_FLOPPY, - //IDI_ICON_MEMORY, - 0, - IDI_ICON_DISPLAY, - IDI_ICON_SOUND, - IDI_ICON_FILESYSTEM, - IDI_ICON_HARDFILE, - //IDI_ICON_GAMEPORT, - //IDI_ICON_VARIOUS - 0,0 -}; + 0, + IDI_ICON_CPU, + IDI_ICON_FLOPPY, + // IDI_ICON_MEMORY, + 0, + IDI_ICON_DISPLAY, + IDI_ICON_SOUND, + IDI_ICON_FILESYSTEM, + IDI_ICON_HARDFILE, + // IDI_ICON_GAMEPORT, + // IDI_ICON_VARIOUS + 0, + 0}; // in this struct, we remember the configuration dialog property sheet handles, // so that a refresh can be triggered by the presets propery sheet -HWND wgui_propsheetHWND[PROP_SHEETS] = { - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr -}; +HWND wgui_propsheetHWND[PROP_SHEETS] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; -typedef INT_PTR (CALLBACK *wguiDlgProc)(HWND, UINT, WPARAM, LPARAM); +typedef INT_PTR(CALLBACK *wguiDlgProc)(HWND, UINT, WPARAM, LPARAM); wguiDlgProc wgui_propsheetDialogProc[PROP_SHEETS] = { - wguiPresetDialogProc, - wguiCPUDialogProc, - wguiFloppyDialogProc, - wguiMemoryDialogProc, - wguiDisplayDialogProc, - wguiSoundDialogProc, - wguiFilesystemDialogProc, - wguiHardfileDialogProc, - wguiGameportDialogProc, - wguiVariousDialogProc -}; + wguiPresetDialogProc, + wguiCPUDialogProc, + wguiFloppyDialogProc, + wguiMemoryDialogProc, + wguiDisplayDialogProc, + wguiSoundDialogProc, + wguiFilesystemDialogProc, + wguiHardfileDialogProc, + wguiGameportDialogProc, + wguiVariousDialogProc}; void wguiLoadBitmaps() { @@ -389,16 +343,13 @@ void wguiCheckMemorySettingsForChipset() } } -wgui_drawmode_list& wguiGetFullScreenMatchingList(uint32_t colorbits) +wgui_drawmode_list &wguiGetFullScreenMatchingList(uint32_t colorbits) { switch (colorbits) { - case 16: - return wgui_dm.res16bit; - case 24: - return wgui_dm.res24bit; - case 32: - return wgui_dm.res32bit; + case 16: return wgui_dm.res16bit; + case 24: return wgui_dm.res24bit; + case 32: return wgui_dm.res32bit; } return wgui_dm.res16bit; } @@ -422,7 +373,7 @@ std::pair wguiGetDesktopSize() std::pair wguiGetDesktopWorkAreaSize() { - RECT workAreaRect = { 0 }; + RECT workAreaRect = {0}; if (!SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0)) { return wguiGetDesktopSize(); @@ -430,10 +381,10 @@ std::pair wguiGetDesktopWorkAreaSize() return std::pair(workAreaRect.right - workAreaRect.left, workAreaRect.bottom - workAreaRect.top); } -wgui_drawmode* wguiGetUIDrawModeFromIndex(unsigned int index, wgui_drawmode_list &list) +wgui_drawmode *wguiGetUIDrawModeFromIndex(unsigned int index, wgui_drawmode_list &list) { unsigned int i = 0; - for (wgui_drawmode& gui_dm : list) + for (wgui_drawmode &gui_dm : list) { if (i == index) { @@ -449,26 +400,31 @@ void wguiGetResolutionStrWithIndex(LONG index, char char_buffer[]) wgui_drawmode_list &list = wguiGetFullScreenMatchingList(pwgui_dm_match->colorbits); // fullscreen - wgui_drawmode* gui_dm_at_index = wguiGetUIDrawModeFromIndex(index, list); + wgui_drawmode *gui_dm_at_index = wguiGetUIDrawModeFromIndex(index, list); if (gui_dm_at_index != nullptr) { sprintf(char_buffer, "%u by %u pixels", gui_dm_at_index->width, gui_dm_at_index->height); - } - else + } + else { sprintf(char_buffer, "unknown screen area"); } } -void wguiGetFrameSkippingStrWithIndex(LONG index, char char_buffer[]) { - if (index == 0) { +void wguiGetFrameSkippingStrWithIndex(LONG index, char char_buffer[]) +{ + if (index == 0) + { sprintf(char_buffer, "no skipping"); - } else { - sprintf(char_buffer, "skip %d of %d frames", index, (index+1)); + } + else + { + sprintf(char_buffer, "skip %d of %d frames", index, (index + 1)); } } -void wguiSetSliderTextAccordingToPosition(HWND windowHandle, int sliderIdentifier, int sliderTextIdentifier, void (*getSliderStrWithIndex)(LONG, char[])) { +void wguiSetSliderTextAccordingToPosition(HWND windowHandle, int sliderIdentifier, int sliderTextIdentifier, void (*getSliderStrWithIndex)(LONG, char[])) +{ char buffer[255]; uint32_t pos = ccwSliderGetPosition(windowHandle, sliderIdentifier); @@ -478,9 +434,18 @@ void wguiSetSliderTextAccordingToPosition(HWND windowHandle, int sliderIdentifie uint32_t wguiGetColorBitsFromComboboxIndex(LONG index) { - if (wgui_dm.comboxbox16bitindex == index) { return 16; } - if (wgui_dm.comboxbox24bitindex == index) { return 24; } - if (wgui_dm.comboxbox32bitindex == index) { return 32; } + if (wgui_dm.comboxbox16bitindex == index) + { + return 16; + } + if (wgui_dm.comboxbox24bitindex == index) + { + return 24; + } + if (wgui_dm.comboxbox32bitindex == index) + { + return 32; + } return 8; } @@ -495,7 +460,8 @@ LONG wguiGetComboboxIndexFromColorBits(uint32_t colorbits) return 0; } -DISPLAYDRIVER wguiGetDisplayDriverFromComboboxIndex(LONG index) { +DISPLAYDRIVER wguiGetDisplayDriverFromComboboxIndex(LONG index) +{ switch (index) { case 0: return DISPLAYDRIVER_DIRECTDRAW; @@ -504,8 +470,9 @@ DISPLAYDRIVER wguiGetDisplayDriverFromComboboxIndex(LONG index) { return DISPLAYDRIVER_DIRECTDRAW; } -LONG wguiGetComboboxIndexFromDisplayDriver(DISPLAYDRIVER displaydriver) { - switch (displaydriver) +LONG wguiGetComboboxIndexFromDisplayDriver(DISPLAYDRIVER displaydriver) +{ + switch (displaydriver) { case DISPLAYDRIVER_DIRECTDRAW: return 0; case DISPLAYDRIVER_DIRECT3D11: return 1; @@ -515,9 +482,9 @@ LONG wguiGetComboboxIndexFromDisplayDriver(DISPLAYDRIVER displaydriver) { void wguiConvertDrawModeListToGuiDrawModes() { - uint32_t id16bit = 0; - uint32_t id24bit = 0; - uint32_t id32bit = 0; + uint32_t id16bit = 0; + uint32_t id24bit = 0; + uint32_t id32bit = 0; wgui_dm.comboxbox16bitindex = -1; wgui_dm.comboxbox24bitindex = -1; wgui_dm.comboxbox32bitindex = -1; @@ -527,28 +494,29 @@ void wguiConvertDrawModeListToGuiDrawModes() if (has8BitDesktop) { - fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "Your desktop is currently running an 8-bit color resolution.\nThis is not supported.\nOnly fullscreen modes will be available"); + fellowAddLogRequester( + FELLOW_REQUESTER_TYPE_ERROR, "Your desktop is currently running an 8-bit color resolution.\nThis is not supported.\nOnly fullscreen modes will be available"); } - for (draw_mode* dm : drawGetModes()) + for (draw_mode *dm : drawGetModes()) { // fullscreen - switch(dm->bits) + switch (dm->bits) { case 16: wgui_dm.res16bit.emplace_front(dm); - id16bit++; - break; + id16bit++; + break; case 24: wgui_dm.res24bit.emplace_front(dm); - id24bit++; - break; + id24bit++; + break; case 32: wgui_dm.res32bit.emplace_front(dm); - id32bit++; - break; + id32bit++; + break; } } wgui_dm.res16bit.sort(); @@ -560,24 +528,23 @@ void wguiConvertDrawModeListToGuiDrawModes() wgui_dm.numberof32bit = id32bit; uint32_t i = 0; - for (wgui_drawmode_list::iterator wmdm_it = wgui_dm.res16bit.begin(); wmdm_it != wgui_dm.res16bit.end(); ++wmdm_it) { - wgui_drawmode& wmdm = *wmdm_it; + wgui_drawmode &wmdm = *wmdm_it; wmdm.id = i; i++; } - i=0; + i = 0; for (wgui_drawmode_list::iterator wmdm_it = wgui_dm.res24bit.begin(); wmdm_it != wgui_dm.res24bit.end(); ++wmdm_it) { - wgui_drawmode& wmdm = *wmdm_it; + wgui_drawmode &wmdm = *wmdm_it; wmdm.id = i; i++; } - i=0; + i = 0; for (wgui_drawmode_list::iterator wmdm_it = wgui_dm.res32bit.begin(); wmdm_it != wgui_dm.res32bit.end(); ++wmdm_it) { - wgui_drawmode& wmdm = *wmdm_it; + wgui_drawmode &wmdm = *wmdm_it; wmdm.id = i; i++; } @@ -590,20 +557,16 @@ void wguiFreeGuiDrawModesLists() wgui_dm.res32bit.clear(); } -wgui_drawmode* wguiMatchFullScreenResolution() +wgui_drawmode *wguiMatchFullScreenResolution() { uint32_t width = cfgGetScreenWidth(wgui_cfg); uint32_t height = cfgGetScreenHeight(wgui_cfg); - uint32_t colorbits = cfgGetScreenColorBits(wgui_cfg); + uint32_t colorbits = cfgGetScreenColorBits(wgui_cfg); - wgui_drawmode_list& reslist = wguiGetFullScreenMatchingList(colorbits); + wgui_drawmode_list &reslist = wguiGetFullScreenMatchingList(colorbits); wgui_drawmode_list::iterator item_iterator = - std::find_if(reslist.begin(), reslist.end(), - [width, height](const wgui_drawmode& gui_dm) - { - return (gui_dm.height == height) && (gui_dm.width == width); - }); + std::find_if(reslist.begin(), reslist.end(), [width, height](const wgui_drawmode &gui_dm) { return (gui_dm.height == height) && (gui_dm.width == width); }); if (item_iterator != reslist.end()) { @@ -623,8 +586,9 @@ wgui_drawmode* wguiMatchFullScreenResolution() /* Extract the filename from a full path name */ /*============================================================================*/ -char *wguiExtractFilename(char *fullpathname) { - char* strpointer = strrchr(fullpathname, '\\'); +char *wguiExtractFilename(char *fullpathname) +{ + char *strpointer = strrchr(fullpathname, '\\'); strncpy(extractedfilename, fullpathname + strlen(fullpathname) - strlen(strpointer) + 1, strlen(fullpathname) - strlen(strpointer) - 1); return extractedfilename; } @@ -633,10 +597,12 @@ char *wguiExtractFilename(char *fullpathname) { /* Extract the path from a full path name (includes filename) */ /*============================================================================*/ -char *wguiExtractPath(char *fullpathname) { - char* strpointer = strrchr(fullpathname, '\\'); +char *wguiExtractPath(char *fullpathname) +{ + char *strpointer = strrchr(fullpathname, '\\'); - if(strpointer) { + if (strpointer) + { strncpy(extractedpathname, fullpathname, strlen(fullpathname) - strlen(strpointer)); extractedpathname[strlen(fullpathname) - strlen(strpointer)] = '\0'; return extractedpathname; @@ -650,18 +616,17 @@ char *wguiExtractPath(char *fullpathname) { /*============================================================================*/ static char FileType[7][CFG_FILENAME_LENGTH] = { - "ROM Images (.rom;.bin)\0*.rom;*.bin\0ADF Diskfiles (.adf;.adz;.adf.gz;.dms)\0*.adf;*.adz;*.adf.gz;*.dms\0\0\0", + "ROM Images (.rom;.bin)\0*.rom;*.bin\0ADF Diskfiles (.adf;.adz;.adf.gz;.dms)\0*.adf;*.adz;*.adf.gz;*.dms\0\0\0", #ifndef FELLOW_SUPPORT_CAPS - "ADF Diskfiles (.adf;.adz;.adf.gz;.dms)\0*.adf;*.adz;*.adf.gz;*.dms\0\0\0", + "ADF Diskfiles (.adf;.adz;.adf.gz;.dms)\0*.adf;*.adz;*.adf.gz;*.dms\0\0\0", #else - "ADF Diskfiles (.adf;.adz;.adf.gz;.dms)\0*.adf;*.adz;*.adf.gz;*.dms\0CAPS IPF Images (.ipf)\0*.ipf\0\0\0", + "ADF Diskfiles (.adf;.adz;.adf.gz;.dms)\0*.adf;*.adz;*.adf.gz;*.dms\0CAPS IPF Images (.ipf)\0*.ipf\0\0\0", #endif - "Key Files (.key)\0*.key\0\0\0", - "Hard Files (.hdf)\0*.hdf\0\0\0", - "Configuration Files (.wfc)\0*.wfc\0\0\0", - "Amiga Modules (.amod)\0*.amod\0\0\0", - "State Files (.fst)\0\0\0" -}; + "Key Files (.key)\0*.key\0\0\0", + "Hard Files (.hdf)\0*.hdf\0\0\0", + "Configuration Files (.wfc)\0*.wfc\0\0\0", + "Amiga Modules (.amod)\0*.amod\0\0\0", + "State Files (.fst)\0\0\0"}; BOOLE wguiSelectFile(HWND hwndDlg, char *filename, uint32_t filenamesize, char *title, SelectFileFlags SelectFileType) { @@ -669,10 +634,10 @@ BOOLE wguiSelectFile(HWND hwndDlg, char *filename, uint32_t filenamesize, char * char filters[CFG_FILENAME_LENGTH]; memcpy(filters, &FileType[SelectFileType], CFG_FILENAME_LENGTH); - char* pfilters = &filters[0]; + char *pfilters = &filters[0]; - ofn.lStructSize = sizeof(ofn); /* Set all members to familiarize with */ - ofn.hwndOwner = hwndDlg; /* the possibilities... */ + ofn.lStructSize = sizeof(ofn); /* Set all members to familiarize with */ + ofn.hwndOwner = hwndDlg; /* the possibilities... */ ofn.hInstance = win_drv_hInstance; ofn.lpstrFilter = pfilters; ofn.lpstrCustomFilter = nullptr; @@ -684,35 +649,31 @@ BOOLE wguiSelectFile(HWND hwndDlg, char *filename, uint32_t filenamesize, char * ofn.lpstrFileTitle = nullptr; ofn.nMaxFileTitle = 0; - switch (SelectFileType) { - case FSEL_ROM: - ofn.lpstrInitialDir = iniGetLastUsedKickImageDir(wgui_ini); - break; + switch (SelectFileType) + { + case FSEL_ROM: ofn.lpstrInitialDir = iniGetLastUsedKickImageDir(wgui_ini); break; case FSEL_ADF: ofn.lpstrInitialDir = cfgGetLastUsedDiskDir(wgui_cfg); - if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) { - ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); + if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) + { + ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); } break; - case FSEL_KEY: - ofn.lpstrInitialDir = iniGetLastUsedKeyDir(wgui_ini); - break; + case FSEL_KEY: ofn.lpstrInitialDir = iniGetLastUsedKeyDir(wgui_ini); break; case FSEL_HDF: ofn.lpstrInitialDir = iniGetLastUsedHdfDir(wgui_ini); - if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) { - cfgGetLastUsedDiskDir(wgui_cfg); - } else if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) { - ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); + if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) + { + cfgGetLastUsedDiskDir(wgui_cfg); + } + else if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) + { + ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); } break; - case FSEL_WFC: - ofn.lpstrInitialDir = iniGetLastUsedCfgDir(wgui_ini); - break; - case FSEL_FST: - ofn.lpstrInitialDir = iniGetLastUsedStateFileDir(wgui_ini); - break; - default: - ofn.lpstrInitialDir = nullptr; + case FSEL_WFC: ofn.lpstrInitialDir = iniGetLastUsedCfgDir(wgui_ini); break; + case FSEL_FST: ofn.lpstrInitialDir = iniGetLastUsedStateFileDir(wgui_ini); break; + default: ofn.lpstrInitialDir = nullptr; } ofn.lpstrTitle = title; @@ -732,10 +693,10 @@ BOOLE wguiSaveFile(HWND hwndDlg, char *filename, uint32_t filenamesize, char *ti char filters[CFG_FILENAME_LENGTH]; memcpy(filters, &FileType[SelectFileType], CFG_FILENAME_LENGTH); - char* pfilters = &filters[0]; + char *pfilters = &filters[0]; - ofn.lStructSize = sizeof(ofn); /* Set all members to familiarize with */ - ofn.hwndOwner = hwndDlg; /* the possibilities... */ + ofn.lStructSize = sizeof(ofn); /* Set all members to familiarize with */ + ofn.hwndOwner = hwndDlg; /* the possibilities... */ ofn.hInstance = win_drv_hInstance; ofn.lpstrFilter = pfilters; ofn.lpstrCustomFilter = nullptr; @@ -748,48 +709,37 @@ BOOLE wguiSaveFile(HWND hwndDlg, char *filename, uint32_t filenamesize, char *ti switch (SelectFileType) { - case FSEL_ROM: - ofn.lpstrInitialDir = iniGetLastUsedKickImageDir(wgui_ini); - break; - case FSEL_ADF: - ofn.lpstrInitialDir = cfgGetLastUsedDiskDir(wgui_cfg); - if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) - { - ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); - } - break; - case FSEL_KEY: - ofn.lpstrInitialDir = iniGetLastUsedKeyDir(wgui_ini); - break; - case FSEL_HDF: - ofn.lpstrInitialDir = iniGetLastUsedHdfDir(wgui_ini); - if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) - { - cfgGetLastUsedDiskDir(wgui_cfg); - } - else if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) - { - ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); - } - break; - case FSEL_WFC: - ofn.lpstrInitialDir = iniGetLastUsedCfgDir(wgui_ini); - break; - case FSEL_MOD: - ofn.lpstrInitialDir = iniGetLastUsedModDir(wgui_ini); - break; - case FSEL_FST: - ofn.lpstrInitialDir = iniGetLastUsedStateFileDir(wgui_ini); - break; - default: - ofn.lpstrInitialDir = nullptr; + case FSEL_ROM: ofn.lpstrInitialDir = iniGetLastUsedKickImageDir(wgui_ini); break; + case FSEL_ADF: + ofn.lpstrInitialDir = cfgGetLastUsedDiskDir(wgui_cfg); + if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) + { + ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); + } + break; + case FSEL_KEY: ofn.lpstrInitialDir = iniGetLastUsedKeyDir(wgui_ini); break; + case FSEL_HDF: + ofn.lpstrInitialDir = iniGetLastUsedHdfDir(wgui_ini); + if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) + { + cfgGetLastUsedDiskDir(wgui_cfg); + } + else if (strncmp(ofn.lpstrInitialDir, "", CFG_FILENAME_LENGTH) == 0) + { + ofn.lpstrInitialDir = iniGetLastUsedGlobalDiskDir(wgui_ini); + } + break; + case FSEL_WFC: ofn.lpstrInitialDir = iniGetLastUsedCfgDir(wgui_ini); break; + case FSEL_MOD: ofn.lpstrInitialDir = iniGetLastUsedModDir(wgui_ini); break; + case FSEL_FST: ofn.lpstrInitialDir = iniGetLastUsedStateFileDir(wgui_ini); break; + default: ofn.lpstrInitialDir = nullptr; } ofn.lpstrTitle = title; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR; ofn.nFileOffset = 0; ofn.nFileExtension = 0; - ofn.lpstrDefExt = (LPCSTR) &".wfc"; + ofn.lpstrDefExt = (LPCSTR) & ".wfc"; ofn.lCustData = (LPARAM)0; ofn.lpfnHook = nullptr; ofn.lpTemplateName = nullptr; @@ -798,16 +748,15 @@ BOOLE wguiSaveFile(HWND hwndDlg, char *filename, uint32_t filenamesize, char *ti BOOLE wguiSelectDirectory(HWND hwndDlg, char *szPath, char *szDescription, uint32_t filenamesize, char *szTitle) { - BROWSEINFO bi = - { - hwndDlg, // hwndOwner - nullptr, // pidlRoot - szPath, // pszDisplayName - szTitle, // lpszTitle - BIF_RETURNONLYFSDIRS, // ulFlags - nullptr, // lpfn - 0, // lParam - 0 // iImage + BROWSEINFO bi = { + hwndDlg, // hwndOwner + nullptr, // pidlRoot + szPath, // pszDisplayName + szTitle, // lpszTitle + BIF_RETURNONLYFSDIRS, // ulFlags + nullptr, // lpfn + 0, // lParam + 0 // iImage }; LPITEMIDLIST pidlTarget = SHBrowseForFolder(&bi); @@ -817,7 +766,7 @@ BOOLE wguiSelectDirectory(HWND hwndDlg, char *szPath, char *szDescription, uint3 { strcpy(szDescription, bi.pszDisplayName); } - SHGetPathFromIDList(pidlTarget, szPath); // Make sure it is a path + SHGetPathFromIDList(pidlTarget, szPath); // Make sure it is a path CoTaskMemFree(pidlTarget); return TRUE; } @@ -828,7 +777,8 @@ BOOLE wguiSelectDirectory(HWND hwndDlg, char *szPath, char *szDescription, uint3 /* Install history of configuration files into window menu */ /*============================================================================*/ -void wguiRemoveAllHistory() { +void wguiRemoveAllHistory() +{ HMENU menu = GetMenu(wgui_hDialog); if (menu != nullptr) { @@ -843,65 +793,85 @@ void wguiRemoveAllHistory() { } } -void wguiInstallHistoryIntoMenu() { - char cfgfilename[CFG_FILENAME_LENGTH+2]; +void wguiInstallHistoryIntoMenu() +{ + char cfgfilename[CFG_FILENAME_LENGTH + 2]; wguiRemoveAllHistory(); - cfgfilename[0] = '&'; cfgfilename[1] = '1'; cfgfilename[2] = ' '; cfgfilename[3] = '\0'; - if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 0),"") != 0) { + cfgfilename[0] = '&'; + cfgfilename[1] = '1'; + cfgfilename[2] = ' '; + cfgfilename[3] = '\0'; + if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 0), "") != 0) + { strcat(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, 0)); - AppendMenu(GetSubMenu(GetMenu(wgui_hDialog),0), MF_STRING, ID_FILE_HISTORYCONFIGURATION0, cfgfilename); + AppendMenu(GetSubMenu(GetMenu(wgui_hDialog), 0), MF_STRING, ID_FILE_HISTORYCONFIGURATION0, cfgfilename); } - cfgfilename[1] = '2'; cfgfilename[3] = '\0'; - if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 1),"") != 0) { + cfgfilename[1] = '2'; + cfgfilename[3] = '\0'; + if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 1), "") != 0) + { strcat(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, 1)); - AppendMenu(GetSubMenu(GetMenu(wgui_hDialog),0), MF_STRING, ID_FILE_HISTORYCONFIGURATION1, cfgfilename); + AppendMenu(GetSubMenu(GetMenu(wgui_hDialog), 0), MF_STRING, ID_FILE_HISTORYCONFIGURATION1, cfgfilename); } - cfgfilename[1] = '3'; cfgfilename[3] = '\0'; - if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 2),"") != 0) { + cfgfilename[1] = '3'; + cfgfilename[3] = '\0'; + if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 2), "") != 0) + { strcat(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, 2)); - AppendMenu(GetSubMenu(GetMenu(wgui_hDialog),0), MF_STRING, ID_FILE_HISTORYCONFIGURATION2, cfgfilename); + AppendMenu(GetSubMenu(GetMenu(wgui_hDialog), 0), MF_STRING, ID_FILE_HISTORYCONFIGURATION2, cfgfilename); } - cfgfilename[1] = '4'; cfgfilename[3] = '\0'; - if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 3),"") != 0) { + cfgfilename[1] = '4'; + cfgfilename[3] = '\0'; + if (strcmp(iniGetConfigurationHistoryFilename(wgui_ini, 3), "") != 0) + { strcat(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, 3)); - AppendMenu(GetSubMenu(GetMenu(wgui_hDialog),0), MF_STRING, ID_FILE_HISTORYCONFIGURATION3, cfgfilename); + AppendMenu(GetSubMenu(GetMenu(wgui_hDialog), 0), MF_STRING, ID_FILE_HISTORYCONFIGURATION3, cfgfilename); } } -void wguiPutCfgInHistoryOnTop(uint32_t cfgtotop) { +void wguiPutCfgInHistoryOnTop(uint32_t cfgtotop) +{ char cfgfilename[CFG_FILENAME_LENGTH]; strncpy(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, cfgtotop), CFG_FILENAME_LENGTH); - for (uint32_t i = cfgtotop; i>0; i--) { - iniSetConfigurationHistoryFilename(wgui_ini, i, iniGetConfigurationHistoryFilename(wgui_ini, i-1)); + for (uint32_t i = cfgtotop; i > 0; i--) + { + iniSetConfigurationHistoryFilename(wgui_ini, i, iniGetConfigurationHistoryFilename(wgui_ini, i - 1)); } iniSetConfigurationHistoryFilename(wgui_ini, 0, cfgfilename); wguiInstallHistoryIntoMenu(); } -void wguiInsertCfgIntoHistory(char *cfgfilenametoinsert) { +void wguiInsertCfgIntoHistory(char *cfgfilenametoinsert) +{ char cfgfilename[CFG_FILENAME_LENGTH]; // first we need to check if the file is already in the history BOOL exists = FALSE; uint32_t i = 0; - while ((i<4) && (exists == FALSE)) { + while ((i < 4) && (exists == FALSE)) + { i++; - if (strncmp(cfgfilenametoinsert, iniGetConfigurationHistoryFilename(wgui_ini, i-1), CFG_FILENAME_LENGTH) == 0) { + if (strncmp(cfgfilenametoinsert, iniGetConfigurationHistoryFilename(wgui_ini, i - 1), CFG_FILENAME_LENGTH) == 0) + { exists = TRUE; } } - if (exists == TRUE) { - wguiPutCfgInHistoryOnTop(i-1); - } else { - for (i=3; i>0; i--) { - cfgfilename[0]='\0'; - strncat(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, i-1), CFG_FILENAME_LENGTH); + if (exists == TRUE) + { + wguiPutCfgInHistoryOnTop(i - 1); + } + else + { + for (i = 3; i > 0; i--) + { + cfgfilename[0] = '\0'; + strncat(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, i - 1), CFG_FILENAME_LENGTH); iniSetConfigurationHistoryFilename(wgui_ini, i, cfgfilename); } iniSetConfigurationHistoryFilename(wgui_ini, 0, cfgfilenametoinsert); @@ -909,15 +879,18 @@ void wguiInsertCfgIntoHistory(char *cfgfilenametoinsert) { } } -void wguiDeleteCfgFromHistory(uint32_t itemtodelete) { - for (uint32_t i = itemtodelete; i<3; i++) { - iniSetConfigurationHistoryFilename(wgui_ini, i, iniGetConfigurationHistoryFilename(wgui_ini, i+1)); +void wguiDeleteCfgFromHistory(uint32_t itemtodelete) +{ + for (uint32_t i = itemtodelete; i < 3; i++) + { + iniSetConfigurationHistoryFilename(wgui_ini, i, iniGetConfigurationHistoryFilename(wgui_ini, i + 1)); } iniSetConfigurationHistoryFilename(wgui_ini, 3, ""); wguiInstallHistoryIntoMenu(); } -void wguiSwapCfgsInHistory(uint32_t itemA, uint32_t itemB) { +void wguiSwapCfgsInHistory(uint32_t itemA, uint32_t itemB) +{ char cfgfilename[CFG_FILENAME_LENGTH]; strncpy(cfgfilename, iniGetConfigurationHistoryFilename(wgui_ini, itemA), CFG_FILENAME_LENGTH); @@ -926,27 +899,30 @@ void wguiSwapCfgsInHistory(uint32_t itemA, uint32_t itemB) { wguiInstallHistoryIntoMenu(); } - /*============================================================================*/ /* Saves and loads configuration files (*.wfc) */ /*============================================================================*/ -void wguiSaveConfigurationFileAs(cfg *conf, HWND hwndDlg) { +void wguiSaveConfigurationFileAs(cfg *conf, HWND hwndDlg) +{ char filename[CFG_FILENAME_LENGTH]; strcpy(filename, ""); - if (wguiSaveFile(hwndDlg, filename, CFG_FILENAME_LENGTH, "Save Configuration As:", FSEL_WFC)) { + if (wguiSaveFile(hwndDlg, filename, CFG_FILENAME_LENGTH, "Save Configuration As:", FSEL_WFC)) + { cfgSaveToFilename(wgui_cfg, filename); iniSetCurrentConfigurationFilename(wgui_ini, filename); iniSetLastUsedCfgDir(wgui_ini, wguiExtractPath(filename)); } } -void wguiOpenConfigurationFile(cfg *conf, HWND hwndDlg) { +void wguiOpenConfigurationFile(cfg *conf, HWND hwndDlg) +{ char filename[CFG_FILENAME_LENGTH]; - if (wguiSelectFile(hwndDlg, filename, CFG_FILENAME_LENGTH, "Open", FSEL_WFC)) { + if (wguiSelectFile(hwndDlg, filename, CFG_FILENAME_LENGTH, "Open", FSEL_WFC)) + { cfgLoadFromFilename(wgui_cfg, filename, false); iniSetCurrentConfigurationFilename(wgui_ini, filename); iniSetLastUsedCfgDir(wgui_ini, wguiExtractPath(filename)); @@ -989,76 +965,65 @@ void wguiOpenStateFile(cfg *conf, HWND hwndDlg) /* install CPU config */ -void wguiInstallCPUConfig(HWND hwndDlg, cfg *conf) { +void wguiInstallCPUConfig(HWND hwndDlg, cfg *conf) +{ int slidervalue; /* set CPU type */ - for(int i = 0; im_pauseemulationwhenwindowlosesfocus); gfxDrvCommon->SetPauseEmulationWhenWindowLosesFocus(ini->m_pauseemulationwhenwindowlosesfocus); // should this be here? } -void wguiToggleMenuPauseEmulationWhenWindowLosesFocus(HWND hwndDlg, ini* ini) +void wguiToggleMenuPauseEmulationWhenWindowLosesFocus(HWND hwndDlg, ini *ini) { BOOLE ischecked = ccwMenuCheckedToggle(hwndDlg, ID_OPTIONS_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS); @@ -1450,7 +1419,7 @@ void wguiToggleMenuPauseEmulationWhenWindowLosesFocus(HWND hwndDlg, ini* ini) gfxDrvCommon->SetPauseEmulationWhenWindowLosesFocus(ischecked); } -void wguiHardfileSetInformationString(char *s, char *deviceName, int partitionNumber, const HardfilePartition& partition) +void wguiHardfileSetInformationString(char *s, char *deviceName, int partitionNumber, const HardfilePartition &partition) { char preferredName[512]; preferredName[0] = '\0'; @@ -1460,25 +1429,32 @@ void wguiHardfileSetInformationString(char *s, char *deviceName, int partitionNu sprintf(preferredName, " (%s)", partition.PreferredName.c_str()); } - const HardfileGeometry& geometry = partition.Geometry; + const HardfileGeometry &geometry = partition.Geometry; sprintf( - s, - "Partition %d%s: Cylinders-%d (%d-%d) Sectors per track-%d Blocksize-%d Heads-%d Reserved-%d", - partitionNumber, - preferredName, - geometry.HighCylinder - geometry.LowCylinder + 1, - geometry.LowCylinder, - geometry.HighCylinder, - geometry.SectorsPerTrack, - geometry.BytesPerSector, - geometry.Surfaces, - geometry.ReservedBlocks); + s, + "Partition %d%s: Cylinders-%d (%d-%d) Sectors per track-%d Blocksize-%d Heads-%d Reserved-%d", + partitionNumber, + preferredName, + geometry.HighCylinder - geometry.LowCylinder + 1, + geometry.LowCylinder, + geometry.HighCylinder, + geometry.SectorsPerTrack, + geometry.BytesPerSector, + geometry.Surfaces, + geometry.ReservedBlocks); } -HTREEITEM wguiHardfileTreeViewAddDisk(HWND hwndTree, char* filename, rdb_status rdbStatus, const HardfileGeometry& geometry, int hardfileIndex) +HTREEITEM wguiHardfileTreeViewAddDisk(HWND hwndTree, char *filename, rdb_status rdbStatus, const HardfileGeometry &geometry, int hardfileIndex) { char s[256]; - snprintf(s, 256, "%s%s", filename, rdbStatus == rdb_status::RDB_FOUND ? " (RDB)" : (rdbStatus == rdb_status::RDB_FOUND_WITH_HEADER_CHECKSUM_ERROR || rdbStatus == RDB_FOUND_WITH_PARTITION_ERROR ? " (Invalid RDB)" : "")); + snprintf( + s, + 256, + "%s%s", + filename, + rdbStatus == rdb_status::RDB_FOUND + ? " (RDB)" + : (rdbStatus == rdb_status::RDB_FOUND_WITH_HEADER_CHECKSUM_ERROR || rdbStatus == RDB_FOUND_WITH_PARTITION_ERROR ? " (Invalid RDB)" : "")); TV_INSERTSTRUCT tvInsert = {}; tvInsert.hParent = nullptr; @@ -1489,7 +1465,7 @@ HTREEITEM wguiHardfileTreeViewAddDisk(HWND hwndTree, char* filename, rdb_status return TreeView_InsertItem(hwndTree, &tvInsert); } -void wguiHardfileTreeViewAddPartition(HWND hwndTree, HTREEITEM parent, int partitionNumber, char* deviceName, const HardfilePartition& partition, int hardfileIndex) +void wguiHardfileTreeViewAddPartition(HWND hwndTree, HTREEITEM parent, int partitionNumber, char *deviceName, const HardfilePartition &partition, int hardfileIndex) { char s[256]; wguiHardfileSetInformationString(s, deviceName, partitionNumber, partition); @@ -1555,10 +1531,10 @@ void wguiHardfileTreeViewAddHardfile(HWND hwndTree, cfg_hardfile *hf, int hardfi partition.Geometry = configuration.Geometry; configuration.Partitions.push_back(partition); } - + HTREEITEM diskRootItem = wguiHardfileTreeViewAddDisk(hwndTree, hf->filename, hf->rdbstatus, configuration.Geometry, hardfileIndex); - unsigned int partitionCount = (unsigned int) configuration.Partitions.size(); + unsigned int partitionCount = (unsigned int)configuration.Partitions.size(); for (unsigned int i = 0; i < partitionCount; i++) { wguiHardfileTreeViewAddPartition(hwndTree, diskRootItem, i, "Devicename", configuration.Partitions[i], hardfileIndex); @@ -1618,7 +1594,7 @@ bool wguiHardfileCreate(HWND hwndDlg, cfg *conf, uint32_t index, cfg_hardfile *t /* Update filesystem description in the list view box */ -void wguiFilesystemUpdate(HWND lvHWND, cfg_filesys *fs, uint32_t i, BOOL add, char* prefix) +void wguiFilesystemUpdate(HWND lvHWND, cfg_filesys *fs, uint32_t i, BOOL add, char *prefix) { LV_ITEM lvi; char stmp[48]; @@ -1628,21 +1604,23 @@ void wguiFilesystemUpdate(HWND lvHWND, cfg_filesys *fs, uint32_t i, BOOL add, ch sprintf(stmp, "%s%u", prefix, i); lvi.iItem = i; lvi.pszText = stmp; - lvi.cchTextMax = (int) strlen(stmp); + lvi.cchTextMax = (int)strlen(stmp); lvi.iSubItem = 0; - if (!add) ListView_SetItem(lvHWND, &lvi); - else ListView_InsertItem(lvHWND, &lvi); + if (!add) + ListView_SetItem(lvHWND, &lvi); + else + ListView_InsertItem(lvHWND, &lvi); lvi.pszText = fs->volumename; - lvi.cchTextMax = (int) strlen(fs->volumename); + lvi.cchTextMax = (int)strlen(fs->volumename); lvi.iSubItem = 1; ListView_SetItem(lvHWND, &lvi); lvi.pszText = fs->rootpath; - lvi.cchTextMax = (int) strlen(fs->rootpath); + lvi.cchTextMax = (int)strlen(fs->rootpath); lvi.iSubItem = 2; ListView_SetItem(lvHWND, &lvi); sprintf(stmp, "%s", (fs->readonly) ? "R" : "RW"); lvi.pszText = stmp; - lvi.cchTextMax = (int) strlen(stmp); + lvi.cchTextMax = (int)strlen(stmp); lvi.iSubItem = 3; ListView_SetItem(lvHWND, &lvi); } @@ -1664,11 +1642,14 @@ void wguiInstallFilesystemConfig(HWND hwndDlg, cfg *conf) for (uint32_t i = 0; i < FILESYSTEM_COLS; i++) { uint32_t colwidth = ListView_GetStringWidth(lvHWND, colheads[i]); - if (i == 0) colwidth += 32; - else if (i == 2) colwidth += 164; - else colwidth += 16; + if (i == 0) + colwidth += 32; + else if (i == 2) + colwidth += 164; + else + colwidth += 16; lvc.pszText = colheads[i]; - lvc.cchTextMax = (int) strlen(colheads[i]); + lvc.cchTextMax = (int)strlen(colheads[i]); lvc.cx = colwidth; ListView_InsertColumn(lvHWND, i, &lvc); } @@ -1695,21 +1676,19 @@ void wguiExtractFilesystemConfig(HWND hwndDlg, cfg *conf) cfgSetFilesystemAutomountDrives(conf, ccwButtonGetCheck(hwndDlg, IDC_CHECK_AUTOMOUNT_FILESYSTEMS)); ccwEditGetText(hwndDlg, IDC_EDIT_PREFIX_FILESYSTEMS, strFilesystemDeviceNamePrefix, CFG_FILENAME_LENGTH); - if(strlen(strFilesystemDeviceNamePrefix) > 16) + if (strlen(strFilesystemDeviceNamePrefix) > 16) { - wguiRequester("The length of the device name prefix is limited to 16 characters. Your change was ignored because it exceeded that length.", - MB_OK | MB_ICONEXCLAMATION); + wguiRequester("The length of the device name prefix is limited to 16 characters. Your change was ignored because it exceeded that length.", MB_OK | MB_ICONEXCLAMATION); } else { - if(floppyValidateAmigaDOSVolumeName(strFilesystemDeviceNamePrefix)) + if (floppyValidateAmigaDOSVolumeName(strFilesystemDeviceNamePrefix)) { cfgSetFilesystemDeviceNamePrefix(conf, strFilesystemDeviceNamePrefix); } else { - wguiRequester("The device name prefix you entered results in an invalid volume name. Your change was ignored.", - MB_OK | MB_ICONEXCLAMATION); + wguiRequester("The device name prefix you entered results in an invalid volume name. Your change was ignored.", MB_OK | MB_ICONEXCLAMATION); } } } @@ -1723,10 +1702,10 @@ uint32_t wgui_current_filesystem_edit_index = 0; BOOLE wguiFilesystemAdd(HWND hwndDlg, cfg *conf, BOOLE add, uint32_t index, cfg_filesys *target) { - wgui_current_filesystem_edit = target; - if (add) cfgSetFilesystemUnitDefaults(target); - wgui_current_filesystem_edit_index = index; - return DialogBox(win_drv_hInstance, MAKEINTRESOURCE(IDD_FILESYSTEM_ADD), hwndDlg, wguiFilesystemAddDialogProc) == IDOK; + wgui_current_filesystem_edit = target; + if (add) cfgSetFilesystemUnitDefaults(target); + wgui_current_filesystem_edit_index = index; + return DialogBox(win_drv_hInstance, MAKEINTRESOURCE(IDD_FILESYSTEM_ADD), hwndDlg, wguiFilesystemAddDialogProc) == IDOK; } /*============================================================================*/ @@ -1751,21 +1730,11 @@ void wguiInstallDisplayScaleConfigInGUI(HWND hwndDlg, cfg *conf) switch (cfgGetDisplayScale(conf)) { - case DISPLAYSCALE_AUTO: - currentSelectionIndex = 0; - break; - case DISPLAYSCALE_1X: - currentSelectionIndex = 1; - break; - case DISPLAYSCALE_2X: - currentSelectionIndex = 2; - break; - case DISPLAYSCALE_3X: - currentSelectionIndex = 3; - break; - case DISPLAYSCALE_4X: - currentSelectionIndex = 4; - break; + case DISPLAYSCALE_AUTO: currentSelectionIndex = 0; break; + case DISPLAYSCALE_1X: currentSelectionIndex = 1; break; + case DISPLAYSCALE_2X: currentSelectionIndex = 2; break; + case DISPLAYSCALE_3X: currentSelectionIndex = 3; break; + case DISPLAYSCALE_4X: currentSelectionIndex = 4; break; } ComboBox_SetCurSel(displayScaleComboboxHWND, currentSelectionIndex); @@ -1807,21 +1776,11 @@ void wguiExtractDisplayScaleConfigFromGUI(HWND hwndDlg, cfg *conf) switch (currentScaleSelectionIndex) { - case 0: - selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_AUTO; - break; - case 1: - selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_1X; - break; - case 2: - selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_2X; - break; - case 3: - selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_3X; - break; - case 4: - selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_4X; - break; + case 0: selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_AUTO; break; + case 1: selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_1X; break; + case 2: selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_2X; break; + case 3: selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_3X; break; + case 4: selectedDisplayScale = DISPLAYSCALE::DISPLAYSCALE_4X; break; } cfgSetDisplayScale(conf, selectedDisplayScale); @@ -1830,30 +1789,30 @@ void wguiExtractDisplayScaleConfigFromGUI(HWND hwndDlg, cfg *conf) switch (currentBorderSelectionIndex) { - case 0: - cfgSetClipLeft(conf, 129); // 640x512 - cfgSetClipTop(conf, 44); - cfgSetClipRight(conf, 449); - cfgSetClipBottom(conf, 300); - break; - case 1: - cfgSetClipLeft(conf, 109); // 720x270 - cfgSetClipTop(conf, 37); - cfgSetClipRight(conf, 469); - cfgSetClipBottom(conf, 307); - break; - case 2: - cfgSetClipLeft(conf, 96); // 752x576 - cfgSetClipTop(conf, 26); - cfgSetClipRight(conf, 472); - cfgSetClipBottom(conf, 314); - break; - case 3: - cfgSetClipLeft(conf, 88); // 768x576 - cfgSetClipTop(conf, 26); - cfgSetClipRight(conf, 472); - cfgSetClipBottom(conf, 314); - break; + case 0: + cfgSetClipLeft(conf, 129); // 640x512 + cfgSetClipTop(conf, 44); + cfgSetClipRight(conf, 449); + cfgSetClipBottom(conf, 300); + break; + case 1: + cfgSetClipLeft(conf, 109); // 720x270 + cfgSetClipTop(conf, 37); + cfgSetClipRight(conf, 469); + cfgSetClipBottom(conf, 307); + break; + case 2: + cfgSetClipLeft(conf, 96); // 752x576 + cfgSetClipTop(conf, 26); + cfgSetClipRight(conf, 472); + cfgSetClipBottom(conf, 314); + break; + case 3: + cfgSetClipLeft(conf, 88); // 768x576 + cfgSetClipTop(conf, 26); + cfgSetClipRight(conf, 472); + cfgSetClipBottom(conf, 314); + break; } } @@ -1867,17 +1826,20 @@ void wguiInstallColorBitsConfigInGUI(HWND hwndDlg, cfg *conf) if (!wgui_dm.res16bit.empty()) { ComboBox_AddString(colorBitsComboboxHWND, "high color (16 bit)"); - wgui_dm.comboxbox16bitindex = comboboxid; comboboxid++; + wgui_dm.comboxbox16bitindex = comboboxid; + comboboxid++; } if (!wgui_dm.res24bit.empty()) { ComboBox_AddString(colorBitsComboboxHWND, "true color (24 bit)"); - wgui_dm.comboxbox24bitindex = comboboxid; comboboxid++; + wgui_dm.comboxbox24bitindex = comboboxid; + comboboxid++; } if (!wgui_dm.res32bit.empty()) { ComboBox_AddString(colorBitsComboboxHWND, "true color (32 bit)"); - wgui_dm.comboxbox32bitindex = comboboxid; comboboxid++; + wgui_dm.comboxbox32bitindex = comboboxid; + comboboxid++; } ComboBox_Enable(colorBitsComboboxHWND, !isWindowed); @@ -1891,7 +1853,7 @@ void wguiInstallFullScreenButtonConfigInGUI(HWND hwndDlg, cfg *conf) // set fullscreen button check if (cfgGetScreenWindowed(conf)) { - // windowed + // windowed ccwButtonUncheck(hwndDlg, IDC_CHECK_FULLSCREEN); // disable multiplebuffers @@ -1906,8 +1868,7 @@ void wguiInstallFullScreenButtonConfigInGUI(HWND hwndDlg, cfg *conf) ccwButtonEnable(hwndDlg, IDC_CHECK_MULTIPLE_BUFFERS); } - if (wguiGetDesktopBitsPerPixel() == 8 - || (wgui_dm.numberof16bit == 0 && wgui_dm.numberof24bit == 0 && wgui_dm.numberof32bit == 0)) + if (wguiGetDesktopBitsPerPixel() == 8 || (wgui_dm.numberof16bit == 0 && wgui_dm.numberof24bit == 0 && wgui_dm.numberof32bit == 0)) { ccwButtonDisable(hwndDlg, IDC_CHECK_FULLSCREEN); } @@ -1929,25 +1890,19 @@ void wguiInstallDisplayScaleStrategyConfigInGUI(HWND hwndDlg, cfg *conf) void wguiInstallFullScreenResolutionConfigInGUI(HWND hwndDlg, cfg *conf) { - // add screen area + // add screen area switch (pwgui_dm_match->colorbits) { - case 16: - ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wgui_dm.numberof16bit - 1)); - break; - case 24: - ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wgui_dm.numberof24bit - 1)); - break; - case 32: - ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wgui_dm.numberof32bit - 1)); - break; + case 16: ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wgui_dm.numberof16bit - 1)); break; + case 24: ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wgui_dm.numberof24bit - 1)); break; + case 32: ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wgui_dm.numberof32bit - 1)); break; } ccwSliderSetPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, pwgui_dm_match->id); wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, IDC_STATIC_SCREEN_AREA, &wguiGetResolutionStrWithIndex); ccwSliderEnable(hwndDlg, IDC_SLIDER_SCREEN_AREA, !cfgGetScreenWindowed(conf)); } -void wguiInstallDisplayDriverConfigInGUI(HWND hwndDlg, cfg* conf) +void wguiInstallDisplayDriverConfigInGUI(HWND hwndDlg, cfg *conf) { HWND displayDriverComboboxHWND = GetDlgItem(hwndDlg, IDC_COMBO_DISPLAY_DRIVER); ComboBox_ResetContent(displayDriverComboboxHWND); @@ -1959,7 +1914,7 @@ void wguiInstallDisplayDriverConfigInGUI(HWND hwndDlg, cfg* conf) ComboBox_SetCurSel(displayDriverComboboxHWND, wguiGetComboboxIndexFromDisplayDriver(cfgGetDisplayDriver(conf))); } -void wguiInstallFrameSkipConfigInGUI(HWND hwndDlg, cfg* conf) +void wguiInstallFrameSkipConfigInGUI(HWND hwndDlg, cfg *conf) { ccwSliderSetRange(hwndDlg, IDC_SLIDER_FRAME_SKIPPING, 0, 24); ccwSliderSetPosition(hwndDlg, IDC_SLIDER_FRAME_SKIPPING, cfgGetFrameskipRatio(conf)); @@ -1995,7 +1950,7 @@ unsigned int wguiDecideScaleFromDesktop(unsigned int unscaled_width, unsigned in for (unsigned int try_scale = 1; try_scale <= 4; try_scale++) { - if (unscaled_width*try_scale <= desktop_size.first && unscaled_height*try_scale <= desktop_size.second) + if (unscaled_width * try_scale <= desktop_size.first && unscaled_height * try_scale <= desktop_size.second) { scale = try_scale; } @@ -2007,8 +1962,8 @@ unsigned int wguiDecideScaleFromDesktop(unsigned int unscaled_width, unsigned in void wguiExtractDisplayFullscreenConfig(HWND hwndDlg, cfg *cfg) { unsigned int slider_index = ccwSliderGetPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA); - wgui_drawmode_list& list = wguiGetFullScreenMatchingList(cfgGetScreenColorBits(cfg)); - wgui_drawmode* wgui_dm = wguiGetUIDrawModeFromIndex(slider_index, list); + wgui_drawmode_list &list = wguiGetFullScreenMatchingList(cfgGetScreenColorBits(cfg)); + wgui_drawmode *wgui_dm = wguiGetUIDrawModeFromIndex(slider_index, list); cfgSetScreenWidth(cfg, wgui_dm->width); cfgSetScreenHeight(cfg, wgui_dm->height); } @@ -2038,7 +1993,8 @@ void wguiExtractDisplayConfig(HWND hwndDlg, cfg *conf) { unsigned int unscaled_width = (cfgGetClipRight(conf) - cfgGetClipLeft(conf)) * 2; unsigned int unscaled_height = (cfgGetClipBottom(conf) - cfgGetClipTop(conf)) * 2; - unsigned int scale = (cfgGetDisplayScale(conf) == DISPLAYSCALE_AUTO) ? wguiDecideScaleFromDesktop(unscaled_width, unscaled_height) : (unsigned int)cfgGetDisplayScale(conf); + unsigned int scale = + (cfgGetDisplayScale(conf) == DISPLAYSCALE_AUTO) ? wguiDecideScaleFromDesktop(unscaled_width, unscaled_height) : (unsigned int)cfgGetDisplayScale(conf); unsigned int width = unscaled_width * scale; unsigned int height = unscaled_height * scale; cfgSetScreenWidth(conf, width); @@ -2104,19 +2060,19 @@ LPARAM wguiTreeViewSelection(HWND hwndTree) INT_PTR CALLBACK wguiPresetDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) + switch (uMsg) { case WM_INITDIALOG: { char strAmigaForeverROMDir[CFG_FILENAME_LENGTH] = ""; wgui_propsheetHWND[PROPSHEETPRESETS] = hwndDlg; - char* strLastPresetROMDir = iniGetLastUsedPresetROMDir(wgui_ini); + char *strLastPresetROMDir = iniGetLastUsedPresetROMDir(wgui_ini); - if(strncmp(strLastPresetROMDir, "", CFG_FILENAME_LENGTH) == 0) + if (strncmp(strLastPresetROMDir, "", CFG_FILENAME_LENGTH) == 0) { // last preset directory not set - if(fileopsResolveVariables("%AMIGAFOREVERDATA%Shared\\rom", strAmigaForeverROMDir)) + if (fileopsResolveVariables("%AMIGAFOREVERDATA%Shared\\rom", strAmigaForeverROMDir)) { strLastPresetROMDir = strAmigaForeverROMDir; iniSetLastUsedPresetROMDir(wgui_ini, strAmigaForeverROMDir); @@ -2125,194 +2081,199 @@ INT_PTR CALLBACK wguiPresetDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP ccwEditSetText(hwndDlg, IDC_EDIT_PRESETS_ROMSEARCHPATH, strLastPresetROMDir); - if(strLastPresetROMDir != nullptr) - if(strLastPresetROMDir[0] != '\0') { + if (strLastPresetROMDir != nullptr) + if (strLastPresetROMDir[0] != '\0') + { ccwButtonEnable(hwndDlg, IDC_LABEL_PRESETS_MODEL); ccwButtonEnable(hwndDlg, IDC_COMBO_PRESETS_MODEL); } - if(wgui_presets != nullptr) { - for(uint32_t i = 0; iid : 0); - ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wguiGetNumberOfScreenAreas(selectedColorBits) - 1)); - - wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, IDC_STATIC_SCREEN_AREA, &wguiGetResolutionStrWithIndex); - ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_COLOR_BITS), TRUE); - Button_Enable(GetDlgItem(hwndDlg, IDC_CHECK_MULTIPLE_BUFFERS), TRUE); + ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wguiGetNumberOfScreenAreas(selectedColorBits) - 1)); + + wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, IDC_STATIC_SCREEN_AREA, &wguiGetResolutionStrWithIndex); + ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_COLOR_BITS), TRUE); + Button_Enable(GetDlgItem(hwndDlg, IDC_CHECK_MULTIPLE_BUFFERS), TRUE); ccwSliderEnable(hwndDlg, IDC_SLIDER_SCREEN_AREA, TRUE); ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_COMBO_DISPLAYSCALE), 0); } @@ -2622,7 +2563,7 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L comboboxIndexColorBits = ccwComboBoxGetCurrentSelection(hwndDlg, IDC_COMBO_COLOR_BITS); selectedColorBits = wguiGetColorBitsFromComboboxIndex(comboboxIndexColorBits); ccwSliderSetPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0); - ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wguiGetNumberOfScreenAreas(selectedColorBits) - 1)); + ccwSliderSetRange(hwndDlg, IDC_SLIDER_SCREEN_AREA, 0, (wguiGetNumberOfScreenAreas(selectedColorBits) - 1)); pwgui_dm_match = wguiGetUIDrawModeFromIndex(0, wguiGetFullScreenMatchingList(wguiGetColorBitsFromComboboxIndex(comboboxIndexColorBits))); wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, IDC_STATIC_SCREEN_AREA, &wguiGetResolutionStrWithIndex); break; @@ -2631,39 +2572,39 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case IDC_COMBO_DISPLAY_DRIVER: switch (HIWORD(wParam)) { - case CBN_SELCHANGE: - uint32_t comboboxIndexDisplayDriver = ccwComboBoxGetCurrentSelection(hwndDlg, IDC_COMBO_DISPLAY_DRIVER); - DISPLAYDRIVER displaydriver = wguiGetDisplayDriverFromComboboxIndex(comboboxIndexDisplayDriver); + case CBN_SELCHANGE: + uint32_t comboboxIndexDisplayDriver = ccwComboBoxGetCurrentSelection(hwndDlg, IDC_COMBO_DISPLAY_DRIVER); + DISPLAYDRIVER displaydriver = wguiGetDisplayDriverFromComboboxIndex(comboboxIndexDisplayDriver); - if (displaydriver != cfgGetDisplayDriver(wgui_cfg)) - { - wguiExtractDisplayConfig(hwndDlg, wgui_cfg); - wguiFreeGuiDrawModesLists(); - - if (displaydriver == DISPLAYDRIVER_DIRECT3D11) - { - if(!gfxDrvDXGIValidateRequirements()) - { - fellowAddLog("ERROR: Direct3D requirements not met, falling back to DirectDraw.\n"); - displaydriver = DISPLAYDRIVER_DIRECTDRAW; - cfgSetDisplayDriver(wgui_cfg, DISPLAYDRIVER_DIRECTDRAW); - fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "DirectX 11 is required but could not be loaded, revert back to DirectDraw."); - } - } - - bool result = gfxDrvRestart(displaydriver); - if (!result) + if (displaydriver != cfgGetDisplayDriver(wgui_cfg)) { - fellowAddLog("ERROR: failed to restart display driver, falling back to DirectDraw.\n"); - displaydriver = DISPLAYDRIVER_DIRECTDRAW; - cfgSetDisplayDriver(wgui_cfg, DISPLAYDRIVER_DIRECTDRAW); - fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "Failed to restart display driver"); + wguiExtractDisplayConfig(hwndDlg, wgui_cfg); + wguiFreeGuiDrawModesLists(); + + if (displaydriver == DISPLAYDRIVER_DIRECT3D11) + { + if (!gfxDrvDXGIValidateRequirements()) + { + fellowAddLog("ERROR: Direct3D requirements not met, falling back to DirectDraw.\n"); + displaydriver = DISPLAYDRIVER_DIRECTDRAW; + cfgSetDisplayDriver(wgui_cfg, DISPLAYDRIVER_DIRECTDRAW); + fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "DirectX 11 is required but could not be loaded, revert back to DirectDraw."); + } + } + + bool result = gfxDrvRestart(displaydriver); + if (!result) + { + fellowAddLog("ERROR: failed to restart display driver, falling back to DirectDraw.\n"); + displaydriver = DISPLAYDRIVER_DIRECTDRAW; + cfgSetDisplayDriver(wgui_cfg, DISPLAYDRIVER_DIRECTDRAW); + fellowAddLogRequester(FELLOW_REQUESTER_TYPE_ERROR, "Failed to restart display driver"); + } + wguiConvertDrawModeListToGuiDrawModes(); + wguiInstallDisplayConfig(hwndDlg, wgui_cfg); } - wguiConvertDrawModeListToGuiDrawModes(); - wguiInstallDisplayConfig(hwndDlg, wgui_cfg); - } - break; + break; } break; case IDC_RADIO_DISPLAYSIZE_1X: @@ -2672,9 +2613,9 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case BN_CLICKED: if (ccwButtonGetCheck(hwndDlg, IDC_RADIO_DISPLAYSIZE_1X)) { - // 1x was checked - ccwButtonUncheck(hwndDlg, IDC_RADIO_DISPLAYSIZE_2X); - } + // 1x was checked + ccwButtonUncheck(hwndDlg, IDC_RADIO_DISPLAYSIZE_2X); + } break; } break; @@ -2684,9 +2625,9 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case BN_CLICKED: if (ccwButtonGetCheck(hwndDlg, IDC_RADIO_DISPLAYSIZE_2X)) { - // 2x was checked - ccwButtonUncheck(hwndDlg, IDC_RADIO_DISPLAYSIZE_1X); - } + // 2x was checked + ccwButtonUncheck(hwndDlg, IDC_RADIO_DISPLAYSIZE_1X); + } break; } break; @@ -2696,9 +2637,9 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case BN_CLICKED: if (ccwButtonGetCheck(hwndDlg, IDC_RADIO_LINE_FILL_SOLID)) { - // solid was checked - ccwButtonUncheck(hwndDlg, IDC_RADIO_LINE_FILL_SCANLINES); - } + // solid was checked + ccwButtonUncheck(hwndDlg, IDC_RADIO_LINE_FILL_SCANLINES); + } break; } break; @@ -2708,28 +2649,24 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case BN_CLICKED: if (ccwButtonGetCheck(hwndDlg, IDC_RADIO_LINE_FILL_SCANLINES)) { - // scanlines was checked - ccwButtonUncheck(hwndDlg, IDC_RADIO_LINE_FILL_SOLID); - } + // scanlines was checked + ccwButtonUncheck(hwndDlg, IDC_RADIO_LINE_FILL_SOLID); + } break; } break; } break; case WM_NOTIFY: - switch ((int) wParam) + switch ((int)wParam) { - case IDC_SLIDER_SCREEN_AREA: - wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, IDC_STATIC_SCREEN_AREA, &wguiGetResolutionStrWithIndex); - break; + case IDC_SLIDER_SCREEN_AREA: wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_SCREEN_AREA, IDC_STATIC_SCREEN_AREA, &wguiGetResolutionStrWithIndex); break; case IDC_SLIDER_FRAME_SKIPPING: wguiSetSliderTextAccordingToPosition(hwndDlg, IDC_SLIDER_FRAME_SKIPPING, IDC_STATIC_FRAME_SKIPPING, &wguiGetFrameSkippingStrWithIndex); break; } break; - case WM_DESTROY: - wguiExtractDisplayConfig(hwndDlg, wgui_cfg); - break; + case WM_DESTROY: wguiExtractDisplayConfig(hwndDlg, wgui_cfg); break; } return FALSE; } @@ -2738,46 +2675,39 @@ INT_PTR CALLBACK wguiDisplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L /* Dialog Procedure for the blitter property sheet */ /*============================================================================*/ -BOOL CALLBACK wguiBlitterDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { - case WM_INITDIALOG: - wguiInstallBlitterConfig(hwndDlg, wgui_cfg); - return TRUE; - case WM_COMMAND: - break; - case WM_DESTROY: - wguiExtractBlitterConfig(hwndDlg, wgui_cfg); - break; +BOOL CALLBACK wguiBlitterDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_INITDIALOG: wguiInstallBlitterConfig(hwndDlg, wgui_cfg); return TRUE; + case WM_COMMAND: break; + case WM_DESTROY: wguiExtractBlitterConfig(hwndDlg, wgui_cfg); break; } return FALSE; } - /*============================================================================*/ /* Dialog Procedure for the sound property sheet */ /*============================================================================*/ -INT_PTR CALLBACK wguiSoundDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +INT_PTR CALLBACK wguiSoundDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ long buffer_length; long sound_volume; char buffer[16]; char volume[16]; - switch (uMsg) { - case WM_INITDIALOG: - wguiInstallSoundConfig(hwndDlg, wgui_cfg); - return TRUE; - case WM_COMMAND: - break; - case WM_DESTROY: - wguiExtractSoundConfig(hwndDlg, wgui_cfg); - break; + switch (uMsg) + { + case WM_INITDIALOG: wguiInstallSoundConfig(hwndDlg, wgui_cfg); return TRUE; + case WM_COMMAND: break; + case WM_DESTROY: wguiExtractSoundConfig(hwndDlg, wgui_cfg); break; case WM_NOTIFY: - buffer_length = (long) SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER_SOUND_BUFFER_LENGTH), TBM_GETPOS, 0, 0); + buffer_length = (long)SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER_SOUND_BUFFER_LENGTH), TBM_GETPOS, 0, 0); sprintf(buffer, "%d", buffer_length); ccwStaticSetText(hwndDlg, IDC_STATIC_BUFFER_LENGTH, buffer); - sound_volume = (long) SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER_SOUND_VOLUME), TBM_GETPOS, 0, 0); + sound_volume = (long)SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER_SOUND_VOLUME), TBM_GETPOS, 0, 0); sprintf(volume, "%d %%", sound_volume); ccwStaticSetText(hwndDlg, IDC_STATIC_SOUND_VOLUME, volume); break; @@ -2785,7 +2715,6 @@ INT_PTR CALLBACK wguiSoundDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA return FALSE; } - /*============================================================================*/ /* Dialog Procedure for the filesystem property sheet */ /*============================================================================*/ @@ -2794,112 +2723,107 @@ INT_PTR CALLBACK wguiFilesystemAddDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wPa { switch (uMsg) { - case WM_INITDIALOG: - { - ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_VOLUMENAME, wgui_current_filesystem_edit->volumename); - ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_ROOTPATH, wgui_current_filesystem_edit->rootpath); - ccwButtonCheckConditional(hwndDlg, IDC_CHECK_FILESYSTEM_ADD_READONLY, wgui_current_filesystem_edit->readonly); - } - return TRUE; - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED) + case WM_INITDIALOG: { - switch (LOWORD(wParam)) - { - case IDC_BUTTON_FILESYSTEM_ADD_DIRDIALOG: - if (wguiSelectDirectory(hwndDlg, wgui_current_filesystem_edit->rootpath, wgui_current_filesystem_edit->volumename, CFG_FILENAME_LENGTH, "Select Filesystem Root Directory:")) - { - ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_ROOTPATH, wgui_current_filesystem_edit->rootpath); - ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_VOLUMENAME, wgui_current_filesystem_edit->volumename); - } - break; - case IDOK: + ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_VOLUMENAME, wgui_current_filesystem_edit->volumename); + ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_ROOTPATH, wgui_current_filesystem_edit->rootpath); + ccwButtonCheckConditional(hwndDlg, IDC_CHECK_FILESYSTEM_ADD_READONLY, wgui_current_filesystem_edit->readonly); + } + return TRUE; + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED) { - ccwEditGetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_VOLUMENAME, wgui_current_filesystem_edit->volumename, 64); - if (wgui_current_filesystem_edit->volumename[0] == '\0') - { - MessageBox(hwndDlg, "You must specify a volume name", "Edit Filesystem", 0); - break; - } - ccwEditGetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_ROOTPATH, wgui_current_filesystem_edit->rootpath, CFG_FILENAME_LENGTH); - if (wgui_current_filesystem_edit->rootpath[0] == '\0') + switch (LOWORD(wParam)) { - MessageBox(hwndDlg, "You must specify a root path", "Edit Filesystem", 0); - break; + case IDC_BUTTON_FILESYSTEM_ADD_DIRDIALOG: + if (wguiSelectDirectory( + hwndDlg, wgui_current_filesystem_edit->rootpath, wgui_current_filesystem_edit->volumename, CFG_FILENAME_LENGTH, "Select Filesystem Root Directory:")) + { + ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_ROOTPATH, wgui_current_filesystem_edit->rootpath); + ccwEditSetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_VOLUMENAME, wgui_current_filesystem_edit->volumename); + } + break; + case IDOK: + { + ccwEditGetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_VOLUMENAME, wgui_current_filesystem_edit->volumename, 64); + if (wgui_current_filesystem_edit->volumename[0] == '\0') + { + MessageBox(hwndDlg, "You must specify a volume name", "Edit Filesystem", 0); + break; + } + ccwEditGetText(hwndDlg, IDC_EDIT_FILESYSTEM_ADD_ROOTPATH, wgui_current_filesystem_edit->rootpath, CFG_FILENAME_LENGTH); + if (wgui_current_filesystem_edit->rootpath[0] == '\0') + { + MessageBox(hwndDlg, "You must specify a root path", "Edit Filesystem", 0); + break; + } + wgui_current_filesystem_edit->readonly = ccwButtonGetCheck(hwndDlg, IDC_CHECK_FILESYSTEM_ADD_READONLY); + } + case IDCANCEL: EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; } - wgui_current_filesystem_edit->readonly = ccwButtonGetCheck(hwndDlg, IDC_CHECK_FILESYSTEM_ADD_READONLY); - } - case IDCANCEL: - EndDialog(hwndDlg, LOWORD(wParam)); - return TRUE; } - } - break; + break; } return FALSE; } - INT_PTR CALLBACK wguiFilesystemDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { - case WM_INITDIALOG: - wgui_propsheetHWND[PROPSHEETFILESYSTEM] = hwndDlg; - wguiInstallFilesystemConfig(hwndDlg, wgui_cfg); - return TRUE; - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED) - { - switch (LOWORD(wParam)) - { - case IDC_BUTTON_FILESYSTEM_ADD: - { - cfg_filesys fs; - if (wguiFilesystemAdd(hwndDlg, wgui_cfg, TRUE, cfgGetFilesystemCount(wgui_cfg), &fs) == IDOK) - { - wguiFilesystemUpdate(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), &fs, cfgGetFilesystemCount(wgui_cfg), TRUE, cfgGetFilesystemDeviceNamePrefix(wgui_cfg)); - cfgFilesystemAdd(wgui_cfg, &fs); - } - } - break; - case IDC_BUTTON_FILESYSTEM_EDIT: + case WM_INITDIALOG: + wgui_propsheetHWND[PROPSHEETFILESYSTEM] = hwndDlg; + wguiInstallFilesystemConfig(hwndDlg, wgui_cfg); + return TRUE; + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED) { - uint32_t sel = wguiListViewNext(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), 0); - if (sel != -1) + switch (LOWORD(wParam)) { - cfg_filesys fs = cfgGetFilesystem(wgui_cfg, sel); - if (wguiFilesystemAdd(hwndDlg, wgui_cfg, FALSE, sel, &fs) == IDOK) + case IDC_BUTTON_FILESYSTEM_ADD: { - cfgFilesystemChange(wgui_cfg, &fs, sel); - wguiFilesystemUpdate(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), &fs, sel, FALSE, cfgGetFilesystemDeviceNamePrefix(wgui_cfg)); + cfg_filesys fs; + if (wguiFilesystemAdd(hwndDlg, wgui_cfg, TRUE, cfgGetFilesystemCount(wgui_cfg), &fs) == IDOK) + { + wguiFilesystemUpdate(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), &fs, cfgGetFilesystemCount(wgui_cfg), TRUE, cfgGetFilesystemDeviceNamePrefix(wgui_cfg)); + cfgFilesystemAdd(wgui_cfg, &fs); + } } - } - } - break; - case IDC_BUTTON_FILESYSTEM_REMOVE: - { - int32_t sel = 0; - while ((sel = wguiListViewNext(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), sel)) != -1) - { - cfgFilesystemRemove(wgui_cfg, sel); - ListView_DeleteItem(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), sel); - for (uint32_t i = sel; i < cfgGetFilesystemCount(wgui_cfg); i++) + break; + case IDC_BUTTON_FILESYSTEM_EDIT: + { + uint32_t sel = wguiListViewNext(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), 0); + if (sel != -1) + { + cfg_filesys fs = cfgGetFilesystem(wgui_cfg, sel); + if (wguiFilesystemAdd(hwndDlg, wgui_cfg, FALSE, sel, &fs) == IDOK) + { + cfgFilesystemChange(wgui_cfg, &fs, sel); + wguiFilesystemUpdate(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), &fs, sel, FALSE, cfgGetFilesystemDeviceNamePrefix(wgui_cfg)); + } + } + } + break; + case IDC_BUTTON_FILESYSTEM_REMOVE: { - cfg_filesys fs = cfgGetFilesystem(wgui_cfg, i); - wguiFilesystemUpdate(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), &fs, i, FALSE, cfgGetFilesystemDeviceNamePrefix(wgui_cfg)); + int32_t sel = 0; + while ((sel = wguiListViewNext(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), sel)) != -1) + { + cfgFilesystemRemove(wgui_cfg, sel); + ListView_DeleteItem(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), sel); + for (uint32_t i = sel; i < cfgGetFilesystemCount(wgui_cfg); i++) + { + cfg_filesys fs = cfgGetFilesystem(wgui_cfg, i); + wguiFilesystemUpdate(GetDlgItem(hwndDlg, IDC_LIST_FILESYSTEMS), &fs, i, FALSE, cfgGetFilesystemDeviceNamePrefix(wgui_cfg)); + } + } } + break; + default: break; } } break; - default: - break; - } - } - break; - case WM_DESTROY: - wguiExtractFilesystemConfig(hwndDlg, wgui_cfg); - break; + case WM_DESTROY: wguiExtractFilesystemConfig(hwndDlg, wgui_cfg); break; } return FALSE; } @@ -2912,73 +2836,71 @@ INT_PTR CALLBACK wguiHardfileCreateDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wP { switch (uMsg) { - case WM_INITDIALOG: - ccwEditSetText(hwndDlg, IDC_CREATE_HARDFILE_NAME, ""); - ccwEditSetText(hwndDlg, IDC_CREATE_HARDFILE_SIZE, "0"); - return TRUE; - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED) - { - switch (LOWORD(wParam)) - { - case IDOK: + case WM_INITDIALOG: + ccwEditSetText(hwndDlg, IDC_CREATE_HARDFILE_NAME, ""); + ccwEditSetText(hwndDlg, IDC_CREATE_HARDFILE_SIZE, "0"); + return TRUE; + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED) { - char stmp[32]; - HardfileConfiguration hfile; - char fname[CFG_FILENAME_LENGTH]; - ccwEditGetText(hwndDlg, IDC_CREATE_HARDFILE_NAME, fname, CFG_FILENAME_LENGTH); - hfile.Filename = fname; - - if (hfile.Filename.empty()) - { - MessageBox(hwndDlg, "You must specify a hardfile name", "Create Hardfile", 0); - break; - } - _strupr(fname); - if (strrchr(fname, '.HDF') == nullptr) + switch (LOWORD(wParam)) { - if (hfile.Filename.length() > 252) + case IDOK: { - MessageBox(hwndDlg, "Hardfile name too long, maximum is 252 characters", "Create Hardfile", 0); - break; - } - hfile.Filename += ".hdf"; - } + char stmp[32]; + HardfileConfiguration hfile; + char fname[CFG_FILENAME_LENGTH]; + ccwEditGetText(hwndDlg, IDC_CREATE_HARDFILE_NAME, fname, CFG_FILENAME_LENGTH); + hfile.Filename = fname; - ccwEditGetText(hwndDlg, IDC_CREATE_HARDFILE_SIZE, stmp, 32); - __int64 size = _atoi64(stmp); - if (ccwButtonGetCheckBool(hwndDlg, IDC_CHECK_CREATE_HARDFILE_MEGABYTES)) - { - size = size * 1024 * 1024; - } - if ((size < 1) || (size > 2147483647)) - { - MessageBox(hwndDlg, "Size must be between 1 byte and 2147483647 bytes", "Create Hardfile", 0); - break; - } + if (hfile.Filename.empty()) + { + MessageBox(hwndDlg, "You must specify a hardfile name", "Create Hardfile", 0); + break; + } + _strupr(fname); + if (strrchr(fname, '.HDF') == nullptr) + { + if (hfile.Filename.length() > 252) + { + MessageBox(hwndDlg, "Hardfile name too long, maximum is 252 characters", "Create Hardfile", 0); + break; + } + hfile.Filename += ".hdf"; + } - // creates the HDF file - if (!HardfileHandler->Create(hfile, (uint32_t) size)) - { - MessageBox(hwndDlg, "Failed to create file", "Create Hardfile", 0); - break; - } - strncpy(wgui_current_hardfile_edit->filename, hfile.Filename.c_str(), CFG_FILENAME_LENGTH); - } - case IDCANCEL: - EndDialog(hwndDlg, LOWORD(wParam)); - return TRUE; + ccwEditGetText(hwndDlg, IDC_CREATE_HARDFILE_SIZE, stmp, 32); + __int64 size = _atoi64(stmp); + if (ccwButtonGetCheckBool(hwndDlg, IDC_CHECK_CREATE_HARDFILE_MEGABYTES)) + { + size = size * 1024 * 1024; + } + if ((size < 1) || (size > 2147483647)) + { + MessageBox(hwndDlg, "Size must be between 1 byte and 2147483647 bytes", "Create Hardfile", 0); + break; + } - case IDC_BUTTON_HARDFILE_CREATE_FILEDIALOG: - if (wguiSaveFile(hwndDlg, wgui_current_hardfile_edit->filename, CFG_FILENAME_LENGTH, "Select Hardfile Name", FSEL_HDF)) - { - ccwEditSetText(hwndDlg, IDC_CREATE_HARDFILE_NAME, wgui_current_hardfile_edit->filename); - iniSetLastUsedHdfDir(wgui_ini, wguiExtractPath(wgui_current_hardfile_edit->filename)); + // creates the HDF file + if (!HardfileHandler->Create(hfile, (uint32_t)size)) + { + MessageBox(hwndDlg, "Failed to create file", "Create Hardfile", 0); + break; + } + strncpy(wgui_current_hardfile_edit->filename, hfile.Filename.c_str(), CFG_FILENAME_LENGTH); + } + case IDCANCEL: EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; + + case IDC_BUTTON_HARDFILE_CREATE_FILEDIALOG: + if (wguiSaveFile(hwndDlg, wgui_current_hardfile_edit->filename, CFG_FILENAME_LENGTH, "Select Hardfile Name", FSEL_HDF)) + { + ccwEditSetText(hwndDlg, IDC_CREATE_HARDFILE_NAME, wgui_current_hardfile_edit->filename); + iniSetLastUsedHdfDir(wgui_ini, wguiExtractPath(wgui_current_hardfile_edit->filename)); + } + break; } - break; } - } - break; + break; } return FALSE; } @@ -2991,7 +2913,7 @@ void wguiHardfileAddDialogEnableGeometry(HWND hwndDlg, bool enable) ccwEditEnableConditionalBool(hwndDlg, IDC_EDIT_HARDFILE_ADD_BYTES_PER_SECTOR, enable); } -void wguiHardfileAddDialogSetGeometryEdits(HWND hwndDlg, char* filename, bool readonly, int sectorsPerTrack, int surfaces, int reservedBlocks, int bytesPerSector, bool enable) +void wguiHardfileAddDialogSetGeometryEdits(HWND hwndDlg, char *filename, bool readonly, int sectorsPerTrack, int surfaces, int reservedBlocks, int bytesPerSector, bool enable) { char stmp[64]; @@ -3014,92 +2936,98 @@ INT_PTR CALLBACK wguiHardfileAddDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wPara { switch (uMsg) { - case WM_INITDIALOG: - wguiHardfileAddDialogSetGeometryEdits( - hwndDlg, - wgui_current_hardfile_edit->filename, - wgui_current_hardfile_edit->readonly, - wgui_current_hardfile_edit->sectorspertrack, - wgui_current_hardfile_edit->surfaces, - wgui_current_hardfile_edit->reservedblocks, - wgui_current_hardfile_edit->bytespersector, - HardfileHandler->HasRDB(wgui_current_hardfile_edit->filename) == rdb_status::RDB_NOT_FOUND); - return TRUE; - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED) - { - switch (LOWORD(wParam)) + case WM_INITDIALOG: + wguiHardfileAddDialogSetGeometryEdits( + hwndDlg, + wgui_current_hardfile_edit->filename, + wgui_current_hardfile_edit->readonly, + wgui_current_hardfile_edit->sectorspertrack, + wgui_current_hardfile_edit->surfaces, + wgui_current_hardfile_edit->reservedblocks, + wgui_current_hardfile_edit->bytespersector, + HardfileHandler->HasRDB(wgui_current_hardfile_edit->filename) == rdb_status::RDB_NOT_FOUND); + return TRUE; + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED) { - case IDC_BUTTON_HARDFILE_ADD_FILEDIALOG: - if (wguiSelectFile(hwndDlg, wgui_current_hardfile_edit->filename, CFG_FILENAME_LENGTH, "Select Hardfile", FSEL_HDF)) + switch (LOWORD(wParam)) { - rdb_status rdbStatus = HardfileHandler->HasRDB(wgui_current_hardfile_edit->filename); - if (rdbStatus == rdb_status::RDB_FOUND_WITH_HEADER_CHECKSUM_ERROR) - { - char s[256]; - sprintf(s, "ERROR: Unable to use hardfile '%s', it has RDB with errors.\n", wgui_current_hardfile_edit->filename); - MessageBox(wgui_hDialog, s, "Configuration Error", 0); - } - else if (rdbStatus == rdb_status::RDB_FOUND_WITH_PARTITION_ERROR) - { - char s[256]; - sprintf(s, "ERROR: Unable to use hardfile '%s', it has RDB with partition errors.\n", wgui_current_hardfile_edit->filename); - MessageBox(wgui_hDialog, s, "Configuration Error", 0); - } - else + case IDC_BUTTON_HARDFILE_ADD_FILEDIALOG: + if (wguiSelectFile(hwndDlg, wgui_current_hardfile_edit->filename, CFG_FILENAME_LENGTH, "Select Hardfile", FSEL_HDF)) + { + rdb_status rdbStatus = HardfileHandler->HasRDB(wgui_current_hardfile_edit->filename); + if (rdbStatus == rdb_status::RDB_FOUND_WITH_HEADER_CHECKSUM_ERROR) + { + char s[256]; + sprintf(s, "ERROR: Unable to use hardfile '%s', it has RDB with errors.\n", wgui_current_hardfile_edit->filename); + MessageBox(wgui_hDialog, s, "Configuration Error", 0); + } + else if (rdbStatus == rdb_status::RDB_FOUND_WITH_PARTITION_ERROR) + { + char s[256]; + sprintf(s, "ERROR: Unable to use hardfile '%s', it has RDB with partition errors.\n", wgui_current_hardfile_edit->filename); + MessageBox(wgui_hDialog, s, "Configuration Error", 0); + } + else + { + ccwEditSetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_FILENAME, wgui_current_hardfile_edit->filename); + if (rdbStatus == rdb_status::RDB_FOUND) + { + const HardfileConfiguration configuration = HardfileHandler->GetConfigurationFromRDBGeometry(wgui_current_hardfile_edit->filename); + const HardfileGeometry &geometry = configuration.Geometry; + wguiHardfileAddDialogSetGeometryEdits( + hwndDlg, + wgui_current_hardfile_edit->filename, + false, + geometry.SectorsPerTrack, + geometry.Surfaces, + geometry.ReservedBlocks, + geometry.BytesPerSector, + false); + } + iniSetLastUsedHdfDir(wgui_ini, wguiExtractPath(wgui_current_hardfile_edit->filename)); + } + } + break; + case IDOK: { - ccwEditSetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_FILENAME, wgui_current_hardfile_edit->filename); - if (rdbStatus == rdb_status::RDB_FOUND) + char stmp[32]; + ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_FILENAME, wgui_current_hardfile_edit->filename, 256); + if (wgui_current_hardfile_edit->filename[0] == '\0') + { + MessageBox(hwndDlg, "You must specify a hardfile name", "Edit Hardfile", 0); + break; + } + wgui_current_hardfile_edit->rdbstatus = HardfileHandler->HasRDB(wgui_current_hardfile_edit->filename); + ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_SECTORS, stmp, 32); + if (wgui_current_hardfile_edit->rdbstatus == rdb_status::RDB_NOT_FOUND && atoi(stmp) < 1) { - const HardfileConfiguration configuration = HardfileHandler->GetConfigurationFromRDBGeometry(wgui_current_hardfile_edit->filename); - const HardfileGeometry& geometry = configuration.Geometry; - wguiHardfileAddDialogSetGeometryEdits(hwndDlg, wgui_current_hardfile_edit->filename, false, geometry.SectorsPerTrack, geometry.Surfaces, geometry.ReservedBlocks, geometry.BytesPerSector, false); + MessageBox(hwndDlg, "Sectors Per Track must be 1 or higher", "Edit Hardfile", 0); + break; + } + wgui_current_hardfile_edit->sectorspertrack = atoi(stmp); + ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_SURFACES, stmp, 32); + if (wgui_current_hardfile_edit->rdbstatus == rdb_status::RDB_NOT_FOUND && atoi(stmp) < 1) + { + MessageBox(hwndDlg, "The number of surfaces must be 1 or higher", "Edit Hardfile", 0); + break; } - iniSetLastUsedHdfDir(wgui_ini, wguiExtractPath(wgui_current_hardfile_edit->filename)); + wgui_current_hardfile_edit->surfaces = atoi(stmp); + ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_RESERVED, stmp, 32); + if (wgui_current_hardfile_edit->rdbstatus == rdb_status::RDB_NOT_FOUND && atoi(stmp) < 1) + { + MessageBox(hwndDlg, "The number of reserved blocks must be 1 or higher", "Edit Hardfile", 0); + break; + } + wgui_current_hardfile_edit->reservedblocks = atoi((char *)stmp); + ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_BYTES_PER_SECTOR, stmp, 32); + wgui_current_hardfile_edit->bytespersector = atoi((char *)stmp); + wgui_current_hardfile_edit->readonly = ccwButtonGetCheckBool(hwndDlg, IDC_CHECK_HARDFILE_ADD_READONLY); } + case IDCANCEL: EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; } - break; - case IDOK: - { - char stmp[32]; - ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_FILENAME, wgui_current_hardfile_edit->filename, 256); - if (wgui_current_hardfile_edit->filename[0] == '\0') - { - MessageBox(hwndDlg, "You must specify a hardfile name", "Edit Hardfile", 0); - break; - } - wgui_current_hardfile_edit->rdbstatus = HardfileHandler->HasRDB(wgui_current_hardfile_edit->filename); - ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_SECTORS, stmp, 32); - if (wgui_current_hardfile_edit->rdbstatus == rdb_status::RDB_NOT_FOUND && atoi(stmp) < 1) - { - MessageBox(hwndDlg, "Sectors Per Track must be 1 or higher", "Edit Hardfile", 0); - break; - } - wgui_current_hardfile_edit->sectorspertrack = atoi(stmp); - ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_SURFACES, stmp, 32); - if (wgui_current_hardfile_edit->rdbstatus == rdb_status::RDB_NOT_FOUND && atoi(stmp) < 1) - { - MessageBox(hwndDlg, "The number of surfaces must be 1 or higher", "Edit Hardfile", 0); - break; - } - wgui_current_hardfile_edit->surfaces = atoi(stmp); - ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_RESERVED, stmp, 32); - if (wgui_current_hardfile_edit->rdbstatus == rdb_status::RDB_NOT_FOUND && atoi(stmp) < 1) - { - MessageBox(hwndDlg, "The number of reserved blocks must be 1 or higher", "Edit Hardfile", 0); - break; - } - wgui_current_hardfile_edit->reservedblocks = atoi((char *)stmp); - ccwEditGetText(hwndDlg, IDC_EDIT_HARDFILE_ADD_BYTES_PER_SECTOR, stmp, 32); - wgui_current_hardfile_edit->bytespersector = atoi((char *)stmp); - wgui_current_hardfile_edit->readonly = ccwButtonGetCheckBool(hwndDlg, IDC_CHECK_HARDFILE_ADD_READONLY); } - case IDCANCEL: - EndDialog(hwndDlg, LOWORD(wParam)); - return TRUE; - } - } - break; + break; } return FALSE; } @@ -3110,67 +3038,64 @@ INT_PTR CALLBACK wguiHardfileDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, { switch (uMsg) { - case WM_INITDIALOG: - wgui_propsheetHWND[PROPSHEETHARDFILE] = hwndDlg; - wguiInstallHardfileConfig(hwndDlg, wgui_cfg); - return TRUE; - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED) - { - switch (LOWORD(wParam)) - { - case IDC_BUTTON_HARDFILE_CREATE: - { - cfg_hardfile fhd; - if (wguiHardfileCreate(hwndDlg, wgui_cfg, cfgGetHardfileCount(wgui_cfg), &fhd) == IDOK) - { - cfgHardfileAdd(wgui_cfg, &fhd); - wguiInstallHardfileConfig(hwndDlg, wgui_cfg); - } - } - break; - case IDC_BUTTON_HARDFILE_ADD: - { - cfg_hardfile fhd; - if (wguiHardfileAdd(hwndDlg, wgui_cfg, true, cfgGetHardfileCount(wgui_cfg), &fhd) == IDOK) - { - cfgHardfileAdd(wgui_cfg, &fhd); - wguiInstallHardfileConfig(hwndDlg, wgui_cfg); - } - } - break; - case IDC_BUTTON_HARDFILE_EDIT: + case WM_INITDIALOG: + wgui_propsheetHWND[PROPSHEETHARDFILE] = hwndDlg; + wguiInstallHardfileConfig(hwndDlg, wgui_cfg); + return TRUE; + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED) { - LPARAM sel = wguiTreeViewSelection(GetDlgItem(hwndDlg, IDC_TREE_HARDFILES)); - if (sel != -1) + switch (LOWORD(wParam)) { - cfg_hardfile fhd = cfgGetHardfile(wgui_cfg, (uint32_t) sel); - if (wguiHardfileAdd(hwndDlg, wgui_cfg, false, (uint32_t) sel, &fhd) == IDOK) + case IDC_BUTTON_HARDFILE_CREATE: { - cfgHardfileChange(wgui_cfg, &fhd, (uint32_t) sel); - wguiInstallHardfileConfig(hwndDlg, wgui_cfg); + cfg_hardfile fhd; + if (wguiHardfileCreate(hwndDlg, wgui_cfg, cfgGetHardfileCount(wgui_cfg), &fhd) == IDOK) + { + cfgHardfileAdd(wgui_cfg, &fhd); + wguiInstallHardfileConfig(hwndDlg, wgui_cfg); + } } + break; + case IDC_BUTTON_HARDFILE_ADD: + { + cfg_hardfile fhd; + if (wguiHardfileAdd(hwndDlg, wgui_cfg, true, cfgGetHardfileCount(wgui_cfg), &fhd) == IDOK) + { + cfgHardfileAdd(wgui_cfg, &fhd); + wguiInstallHardfileConfig(hwndDlg, wgui_cfg); + } + } + break; + case IDC_BUTTON_HARDFILE_EDIT: + { + LPARAM sel = wguiTreeViewSelection(GetDlgItem(hwndDlg, IDC_TREE_HARDFILES)); + if (sel != -1) + { + cfg_hardfile fhd = cfgGetHardfile(wgui_cfg, (uint32_t)sel); + if (wguiHardfileAdd(hwndDlg, wgui_cfg, false, (uint32_t)sel, &fhd) == IDOK) + { + cfgHardfileChange(wgui_cfg, &fhd, (uint32_t)sel); + wguiInstallHardfileConfig(hwndDlg, wgui_cfg); + } + } + } + break; + case IDC_BUTTON_HARDFILE_REMOVE: + { + LPARAM sel = wguiTreeViewSelection(GetDlgItem(hwndDlg, IDC_TREE_HARDFILES)); + if (sel != -1) + { + cfgHardfileRemove(wgui_cfg, (uint32_t)sel); + wguiInstallHardfileConfig(hwndDlg, wgui_cfg); + } + } + break; + default: break; } } break; - case IDC_BUTTON_HARDFILE_REMOVE: - { - LPARAM sel = wguiTreeViewSelection(GetDlgItem(hwndDlg, IDC_TREE_HARDFILES)); - if (sel != -1) - { - cfgHardfileRemove(wgui_cfg, (uint32_t) sel); - wguiInstallHardfileConfig(hwndDlg, wgui_cfg); - } - } - break; - default: - break; - } - } - break; - case WM_DESTROY: - wguiExtractHardfileConfig(hwndDlg, wgui_cfg); - break; + case WM_DESTROY: wguiExtractHardfileConfig(hwndDlg, wgui_cfg); break; } return FALSE; } @@ -3179,13 +3104,15 @@ INT_PTR CALLBACK wguiHardfileDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, /* Dialog Procedure for the gameport property sheet */ /*============================================================================*/ -INT_PTR CALLBACK wguiGameportDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +INT_PTR CALLBACK wguiGameportDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ HWND gpChoice[2]; gpChoice[0] = GetDlgItem(hwndDlg, IDC_COMBO_GAMEPORT1); gpChoice[1] = GetDlgItem(hwndDlg, IDC_COMBO_GAMEPORT2); - switch (uMsg) { + switch (uMsg) + { case WM_INITDIALOG: wgui_propsheetHWND[PROPSHEETGAMEPORT] = hwndDlg; wguiInstallGameportConfig(hwndDlg, wgui_cfg); @@ -3198,48 +3125,48 @@ INT_PTR CALLBACK wguiGameportDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, gpChoice[0] = GetDlgItem(hwndDlg, IDC_COMBO_GAMEPORT1); gpChoice[1] = GetDlgItem(hwndDlg, IDC_COMBO_GAMEPORT2); - switch (LOWORD(wParam)) { - case IDC_COMBO_GAMEPORT1: - if (HIWORD(wParam) == CBN_SELCHANGE) { - if (ComboBox_GetCurSel(gpChoice[0]) == ComboBox_GetCurSel(gpChoice[1])) { - ComboBox_SetCurSel(gpChoice[1], 0); - } - } - break; - case IDC_COMBO_GAMEPORT2: - if (HIWORD(wParam) == CBN_SELCHANGE) { - if (ComboBox_GetCurSel(gpChoice[0]) == ComboBox_GetCurSel(gpChoice[1])) { - ComboBox_SetCurSel(gpChoice[0], 0); - } - } - break; + switch (LOWORD(wParam)) + { + case IDC_COMBO_GAMEPORT1: + if (HIWORD(wParam) == CBN_SELCHANGE) + { + if (ComboBox_GetCurSel(gpChoice[0]) == ComboBox_GetCurSel(gpChoice[1])) + { + ComboBox_SetCurSel(gpChoice[1], 0); + } + } + break; + case IDC_COMBO_GAMEPORT2: + if (HIWORD(wParam) == CBN_SELCHANGE) + { + if (ComboBox_GetCurSel(gpChoice[0]) == ComboBox_GetCurSel(gpChoice[1])) + { + ComboBox_SetCurSel(gpChoice[0], 0); + } + } + break; } } break; - case WM_DESTROY: - wguiExtractGameportConfig(hwndDlg, wgui_cfg); - break; + case WM_DESTROY: wguiExtractGameportConfig(hwndDlg, wgui_cfg); break; } return FALSE; } - /*============================================================================*/ /* Dialog Procedure for the various property sheet */ /*============================================================================*/ INT_PTR CALLBACK wguiVariousDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { + switch (uMsg) + { case WM_INITDIALOG: wgui_propsheetHWND[PROPSHEETVARIOUS] = hwndDlg; wguiInstallVariousConfig(hwndDlg, wgui_cfg); return TRUE; - case WM_COMMAND: - break; - case WM_DESTROY: - wguiExtractVariousConfig(hwndDlg, wgui_cfg); - break; + case WM_COMMAND: break; + case WM_DESTROY: wguiExtractVariousConfig(hwndDlg, wgui_cfg); break; } return FALSE; } @@ -3256,12 +3183,16 @@ INT_PTR wguiConfigurationDialog() PROPSHEETPAGE propertysheets[PROP_SHEETS]; PROPSHEETHEADER propertysheetheader; - for (int i = 0; i < PROP_SHEETS; i++) { + for (int i = 0; i < PROP_SHEETS; i++) + { propertysheets[i].dwSize = sizeof(PROPSHEETPAGE); - if (wgui_propsheetICON[i] != 0) { + if (wgui_propsheetICON[i] != 0) + { propertysheets[i].dwFlags = PSP_USEHICON; propertysheets[i].hIcon = LoadIcon(win_drv_hInstance, MAKEINTRESOURCE(wgui_propsheetICON[i])); - } else { + } + else + { propertysheets[i].dwFlags = PSP_DEFAULT; propertysheets[i].hIcon = nullptr; } @@ -3286,245 +3217,217 @@ INT_PTR wguiConfigurationDialog() return PropertySheet(&propertysheetheader); } -void wguiSetCheckOfUseMultipleGraphicalBuffers(BOOLE useMultipleGraphicalBuffers) { - if (useMultipleGraphicalBuffers) { +void wguiSetCheckOfUseMultipleGraphicalBuffers(BOOLE useMultipleGraphicalBuffers) +{ + if (useMultipleGraphicalBuffers) + { CheckMenuItem(GetMenu(wgui_hDialog), ID_OPTIONS_MULTIPLE_GRAPHICAL_BUFFERS, MF_CHECKED); - } else { + } + else + { CheckMenuItem(GetMenu(wgui_hDialog), ID_OPTIONS_MULTIPLE_GRAPHICAL_BUFFERS, MF_UNCHECKED); - } + } } /*============================================================================*/ /* DialogProc for the About box */ /*============================================================================*/ -INT_PTR CALLBACK wguiAboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch (uMsg) { +INT_PTR CALLBACK wguiAboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { case WM_INITDIALOG: + { + char *versionstring = fellowGetVersionString(); + if (versionstring) { - char *versionstring = fellowGetVersionString(); - if(versionstring) - { - ccwStaticSetText(hwndDlg, IDC_STATIC_ABOUT_VERSION, versionstring); - free(versionstring); - } + ccwStaticSetText(hwndDlg, IDC_STATIC_ABOUT_VERSION, versionstring); + free(versionstring); } + } return TRUE; case WM_COMMAND: - switch (LOWORD(wParam)) { + switch (LOWORD(wParam)) + { case IDCANCEL: case IDOK: EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; break; case IDC_STATIC_LINK: - SetTextColor((HDC) LOWORD(lParam), RGB(0, 0, 255)); + SetTextColor((HDC)LOWORD(lParam), RGB(0, 0, 255)); ShellExecute(nullptr, "open", "http://fellow.sourceforge.net", nullptr, nullptr, SW_SHOWNORMAL); - break; - default: break; + default: break; } } return FALSE; } - /*============================================================================*/ /* About box */ /*============================================================================*/ -void wguiAbout(HWND hwndDlg) { +void wguiAbout(HWND hwndDlg) +{ DialogBox(win_drv_hInstance, MAKEINTRESOURCE(IDD_ABOUT), hwndDlg, wguiAboutDialogProc); } - /*============================================================================*/ /* DialogProc for our main Dialog */ /*============================================================================*/ -INT_PTR CALLBACK wguiDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +INT_PTR CALLBACK wguiDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ char l_diskimage[CFG_FILENAME_LENGTH]; char *versionstring; - switch (uMsg) { + switch (uMsg) + { case WM_INITDIALOG: - SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadIcon(win_drv_hInstance, MAKEINTRESOURCE(IDI_ICON_WINFELLOW))); + SendMessage(hwndDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)LoadIcon(win_drv_hInstance, MAKEINTRESOURCE(IDI_ICON_WINFELLOW))); - if(versionstring = fellowGetVersionString()) + if (versionstring = fellowGetVersionString()) { - SetWindowText(hwndDlg, versionstring); - free(versionstring); + SetWindowText(hwndDlg, versionstring); + free(versionstring); } return TRUE; case WM_COMMAND: - if (wgui_action == WGUI_NO_ACTION) - switch (LOWORD(wParam)) { - case IDC_START_EMULATION: - wgui_emulation_state = TRUE; - wgui_action = WGUI_START_EMULATION; - break; - case IDCANCEL: - case ID_FILE_QUIT: - case IDC_QUIT_EMULATOR: - wgui_action = WGUI_QUIT_EMULATOR; - break; - case ID_FILE_OPENCONFIGURATION: - wgui_action = WGUI_OPEN_CONFIGURATION; - break; - case ID_FILE_SAVECONFIGURATION: - wgui_action = WGUI_SAVE_CONFIGURATION; - break; - case ID_FILE_SAVECONFIGURATIONAS: - wgui_action = WGUI_SAVE_CONFIGURATION_AS; - break; - case ID_FILE_LOAD_STATE: - wgui_action = WGUI_LOAD_STATE; - break; - case ID_FILE_SAVE_STATE: - wgui_action = WGUI_SAVE_STATE; - break; - case ID_FILE_HISTORYCONFIGURATION0: - wgui_action = WGUI_LOAD_HISTORY0; - break; - case ID_FILE_HISTORYCONFIGURATION1: - wgui_action = WGUI_LOAD_HISTORY1; - break; - case ID_FILE_HISTORYCONFIGURATION2: - wgui_action = WGUI_LOAD_HISTORY2; - break; - case ID_FILE_HISTORYCONFIGURATION3: - wgui_action = WGUI_LOAD_HISTORY3; - break; - case ID_OPTIONS_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS: - wgui_action = WGUI_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS; - break; - case IDC_CONFIGURATION: - { - cfg* configbackup = cfgManagerGetCopyOfCurrentConfig(&cfg_manager); - - INT_PTR result = wguiConfigurationDialog(); - if(result >= 1) + if (wgui_action == WGUI_NO_ACTION) switch (LOWORD(wParam)) { - cfgManagerFreeConfig(&cfg_manager, configbackup); - cfgSetConfigChangedSinceLastSave(wgui_cfg, TRUE); + case IDC_START_EMULATION: + wgui_emulation_state = TRUE; + wgui_action = WGUI_START_EMULATION; + break; + case IDCANCEL: + case ID_FILE_QUIT: + case IDC_QUIT_EMULATOR: wgui_action = WGUI_QUIT_EMULATOR; break; + case ID_FILE_OPENCONFIGURATION: wgui_action = WGUI_OPEN_CONFIGURATION; break; + case ID_FILE_SAVECONFIGURATION: wgui_action = WGUI_SAVE_CONFIGURATION; break; + case ID_FILE_SAVECONFIGURATIONAS: wgui_action = WGUI_SAVE_CONFIGURATION_AS; break; + case ID_FILE_LOAD_STATE: wgui_action = WGUI_LOAD_STATE; break; + case ID_FILE_SAVE_STATE: wgui_action = WGUI_SAVE_STATE; break; + case ID_FILE_HISTORYCONFIGURATION0: wgui_action = WGUI_LOAD_HISTORY0; break; + case ID_FILE_HISTORYCONFIGURATION1: wgui_action = WGUI_LOAD_HISTORY1; break; + case ID_FILE_HISTORYCONFIGURATION2: wgui_action = WGUI_LOAD_HISTORY2; break; + case ID_FILE_HISTORYCONFIGURATION3: wgui_action = WGUI_LOAD_HISTORY3; break; + case ID_OPTIONS_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS: wgui_action = WGUI_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS; break; + case IDC_CONFIGURATION: + { + cfg *configbackup = cfgManagerGetCopyOfCurrentConfig(&cfg_manager); + + INT_PTR result = wguiConfigurationDialog(); + if (result >= 1) + { + cfgManagerFreeConfig(&cfg_manager, configbackup); + cfgSetConfigChangedSinceLastSave(wgui_cfg, TRUE); + } + else + { // discard changes, as user clicked cancel or error occurred + cfgManagerFreeConfig(&cfg_manager, wgui_cfg); + cfgManagerSetCurrentConfig(&cfg_manager, configbackup); + wgui_cfg = configbackup; + } + + break; + } + case IDC_HARD_RESET: + fellowSetPreStartReset(TRUE); + wguiLoadBitmaps(); + SendMessage(GetDlgItem(wgui_hDialog, IDC_IMAGE_POWER_LED_MAIN), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)power_led_off_bitmap); + wgui_emulation_state = FALSE; + break; + case ID_DEBUGGER_START: wgui_action = WGUI_DEBUGGER_START; break; + case ID_HELP_ABOUT: + wgui_action = WGUI_ABOUT; + wguiAbout(hwndDlg); + wgui_action = WGUI_NO_ACTION; + break; + default: break; } - else - { // discard changes, as user clicked cancel or error occurred - cfgManagerFreeConfig(&cfg_manager, wgui_cfg); - cfgManagerSetCurrentConfig(&cfg_manager, configbackup); - wgui_cfg = configbackup; + if (HIWORD(wParam) == BN_CLICKED) switch (LOWORD(wParam)) + { + case IDC_BUTTON_DF0_FILEDIALOG_MAIN: wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, 0); break; + case IDC_BUTTON_DF1_FILEDIALOG_MAIN: wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF1_IMAGENAME_MAIN, 1); break; + case IDC_BUTTON_DF2_FILEDIALOG_MAIN: wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF2_IMAGENAME_MAIN, 2); break; + case IDC_BUTTON_DF3_FILEDIALOG_MAIN: wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF3_IMAGENAME_MAIN, 3); break; + case IDC_BUTTON_DF0_EJECT_MAIN: + cfgSetDiskImage(wgui_cfg, 0, ""); + ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); + break; + case IDC_BUTTON_DF1_EJECT_MAIN: + cfgSetDiskImage(wgui_cfg, 1, ""); + ccwEditSetText(hwndDlg, IDC_EDIT_DF1_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 1)); + break; + case IDC_BUTTON_DF2_EJECT_MAIN: + cfgSetDiskImage(wgui_cfg, 2, ""); + ccwEditSetText(hwndDlg, IDC_EDIT_DF2_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 2)); + break; + case IDC_BUTTON_DF3_EJECT_MAIN: + cfgSetDiskImage(wgui_cfg, 3, ""); + ccwEditSetText(hwndDlg, IDC_EDIT_DF3_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 3)); + break; + case IDC_BUTTON_DF1_SWAP: + strcpy(l_diskimage, cfgGetDiskImage(wgui_cfg, 0)); + cfgSetDiskImage(wgui_cfg, 0, cfgGetDiskImage(wgui_cfg, 1)); + cfgSetDiskImage(wgui_cfg, 1, l_diskimage); + ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); + ccwEditSetText(hwndDlg, IDC_EDIT_DF1_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 1)); + break; + case IDC_BUTTON_DF2_SWAP: + strcpy(l_diskimage, cfgGetDiskImage(wgui_cfg, 0)); + cfgSetDiskImage(wgui_cfg, 0, cfgGetDiskImage(wgui_cfg, 2)); + cfgSetDiskImage(wgui_cfg, 2, l_diskimage); + ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); + ccwEditSetText(hwndDlg, IDC_EDIT_DF2_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 2)); + break; + case IDC_BUTTON_DF3_SWAP: + strcpy(l_diskimage, cfgGetDiskImage(wgui_cfg, 0)); + cfgSetDiskImage(wgui_cfg, 0, cfgGetDiskImage(wgui_cfg, 3)); + cfgSetDiskImage(wgui_cfg, 3, l_diskimage); + ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); + ccwEditSetText(hwndDlg, IDC_EDIT_DF3_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 3)); + break; + case IDC_BUTTON_TURBO_LOAD: + if (cfgGetSoundEmulation(wgui_cfg) != 1) + { + cfgSetSoundEmulation(wgui_cfg, SOUND_PLAY); + } + else + { + cfgSetSoundEmulation(wgui_cfg, SOUND_EMULATE); + } + break; + default: break; } - - break; - } - case IDC_HARD_RESET: - fellowSetPreStartReset(TRUE); - wguiLoadBitmaps(); - SendMessage(GetDlgItem(wgui_hDialog, IDC_IMAGE_POWER_LED_MAIN), - STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) power_led_off_bitmap); - wgui_emulation_state = FALSE; - break; - case ID_DEBUGGER_START: - wgui_action = WGUI_DEBUGGER_START; - break; - case ID_HELP_ABOUT: - wgui_action = WGUI_ABOUT; - wguiAbout(hwndDlg); - wgui_action = WGUI_NO_ACTION; - break; - default: - break; - } - if (HIWORD(wParam) == BN_CLICKED) - switch (LOWORD(wParam)) { - case IDC_BUTTON_DF0_FILEDIALOG_MAIN: - wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, 0); - break; - case IDC_BUTTON_DF1_FILEDIALOG_MAIN: - wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF1_IMAGENAME_MAIN, 1); - break; - case IDC_BUTTON_DF2_FILEDIALOG_MAIN: - wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF2_IMAGENAME_MAIN, 2); - break; - case IDC_BUTTON_DF3_FILEDIALOG_MAIN: - wguiSelectDiskImage(wgui_cfg, hwndDlg, IDC_EDIT_DF3_IMAGENAME_MAIN, 3); - break; - case IDC_BUTTON_DF0_EJECT_MAIN: - cfgSetDiskImage(wgui_cfg, 0, ""); - ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); - break; - case IDC_BUTTON_DF1_EJECT_MAIN: - cfgSetDiskImage(wgui_cfg, 1, ""); - ccwEditSetText(hwndDlg, IDC_EDIT_DF1_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 1)); - break; - case IDC_BUTTON_DF2_EJECT_MAIN: - cfgSetDiskImage(wgui_cfg, 2, ""); - ccwEditSetText(hwndDlg, IDC_EDIT_DF2_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 2)); - break; - case IDC_BUTTON_DF3_EJECT_MAIN: - cfgSetDiskImage(wgui_cfg, 3, ""); - ccwEditSetText(hwndDlg, IDC_EDIT_DF3_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 3)); - break; - case IDC_BUTTON_DF1_SWAP: - strcpy(l_diskimage, cfgGetDiskImage(wgui_cfg, 0)); - cfgSetDiskImage(wgui_cfg, 0, cfgGetDiskImage(wgui_cfg, 1)); - cfgSetDiskImage(wgui_cfg, 1, l_diskimage); - ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); - ccwEditSetText(hwndDlg, IDC_EDIT_DF1_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 1)); - break; - case IDC_BUTTON_DF2_SWAP: - strcpy(l_diskimage, cfgGetDiskImage(wgui_cfg, 0)); - cfgSetDiskImage(wgui_cfg, 0, cfgGetDiskImage(wgui_cfg, 2)); - cfgSetDiskImage(wgui_cfg, 2, l_diskimage); - ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); - ccwEditSetText(hwndDlg, IDC_EDIT_DF2_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 2)); - break; - case IDC_BUTTON_DF3_SWAP: - strcpy(l_diskimage, cfgGetDiskImage(wgui_cfg, 0)); - cfgSetDiskImage(wgui_cfg, 0, cfgGetDiskImage(wgui_cfg, 3)); - cfgSetDiskImage(wgui_cfg, 3, l_diskimage); - ccwEditSetText(hwndDlg, IDC_EDIT_DF0_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 0)); - ccwEditSetText(hwndDlg, IDC_EDIT_DF3_IMAGENAME_MAIN, cfgGetDiskImage(wgui_cfg, 3)); - break; - case IDC_BUTTON_TURBO_LOAD: - if (cfgGetSoundEmulation(wgui_cfg) != 1) - { - cfgSetSoundEmulation(wgui_cfg, SOUND_PLAY); - } - else - { - cfgSetSoundEmulation(wgui_cfg, SOUND_EMULATE); - } - break; - default: - break; - } } return FALSE; } - /*============================================================================*/ /* The functions below this line are for "public" use by other modules */ /*============================================================================*/ - /*============================================================================*/ /* Shows a message box */ /*============================================================================*/ -void wguiRequester(char *szMessage, UINT uType) { +void wguiRequester(char *szMessage, UINT uType) +{ MessageBox(nullptr, szMessage, "WinFellow Amiga Emulator", uType); } - /*============================================================================*/ /* Runs the GUI */ /*============================================================================*/ -BOOLE wguiCheckEmulationNecessities() { - if(strcmp(cfgGetKickImage(wgui_cfg), "") != 0) { +BOOLE wguiCheckEmulationNecessities() +{ + if (strcmp(cfgGetKickImage(wgui_cfg), "") != 0) + { FILE *F = fopen(cfgGetKickImage(wgui_cfg), "rb"); if (F != nullptr) { @@ -3533,8 +3436,9 @@ BOOLE wguiCheckEmulationNecessities() { } return FALSE; } - else return FALSE; -} + else + return FALSE; +} BOOLE wguiEnter() { @@ -3549,12 +3453,11 @@ BOOLE wguiEnter() wgui_action = (cfgGetUseGUI(wgui_cfg)) ? WGUI_NO_ACTION : WGUI_START_EMULATION; - wgui_hDialog = CreateDialog(win_drv_hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, wguiDialogProc); + wgui_hDialog = CreateDialog(win_drv_hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, wguiDialogProc); SetWindowPos(wgui_hDialog, HWND_TOP, iniGetMainWindowXPos(wgui_ini), iniGetMainWindowYPos(wgui_ini), 0, 0, SWP_NOSIZE | SWP_ASYNCWINDOWPOS); wguiStartupPost(); wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); - // install history into menu wguiInstallHistoryIntoMenu(); wguiInstallMenuPauseEmulationWhenWindowLosesFocus(wgui_hDialog, wgui_ini); @@ -3565,142 +3468,138 @@ BOOLE wguiEnter() { if (GetMessage(&myMsg, wgui_hDialog, 0, 0)) { - if (!IsDialogMessage(wgui_hDialog, &myMsg)) - { - DispatchMessage(&myMsg); - } + if (!IsDialogMessage(wgui_hDialog, &myMsg)) + { + DispatchMessage(&myMsg); + } } switch (wgui_action) { - case WGUI_START_EMULATION: + case WGUI_START_EMULATION: wguiCheckMemorySettingsForChipset(); - if (wguiCheckEmulationNecessities() == TRUE) - { - end_loop = TRUE; + if (wguiCheckEmulationNecessities() == TRUE) + { + end_loop = TRUE; wguiExtractFloppyMain(wgui_hDialog, wgui_cfg); cfgManagerSetCurrentConfig(&cfg_manager, wgui_cfg); - // check for manual or needed reset - fellowSetPreStartReset(fellowGetPreStartReset() | cfgManagerConfigurationActivate(&cfg_manager)); - break; - } - MessageBox(wgui_hDialog, "Specified KickImage does not exist", "Configuration Error", 0); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_QUIT_EMULATOR: - { - BOOLE bQuit = TRUE; + // check for manual or needed reset + fellowSetPreStartReset(fellowGetPreStartReset() | cfgManagerConfigurationActivate(&cfg_manager)); + break; + } + MessageBox(wgui_hDialog, "Specified KickImage does not exist", "Configuration Error", 0); + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_QUIT_EMULATOR: + { + BOOLE bQuit = TRUE; - wguiExtractFloppyMain(wgui_hDialog, wgui_cfg); + wguiExtractFloppyMain(wgui_hDialog, wgui_cfg); - if(cfgGetConfigChangedSinceLastSave(wgui_cfg)) { - int result = MessageBox(wgui_hDialog, - "There are unsaved configuration changes, quit anyway?", - "WinFellow", - MB_YESNO | MB_ICONEXCLAMATION); - if(result == IDNO) - bQuit = FALSE; - } - if(bQuit) - { - end_loop = TRUE; - quit_emulator = TRUE; - } - else - wgui_action = WGUI_NO_ACTION; + if (cfgGetConfigChangedSinceLastSave(wgui_cfg)) + { + int result = MessageBox(wgui_hDialog, "There are unsaved configuration changes, quit anyway?", "WinFellow", MB_YESNO | MB_ICONEXCLAMATION); + if (result == IDNO) bQuit = FALSE; + } + if (bQuit) + { + end_loop = TRUE; + quit_emulator = TRUE; } - break; - case WGUI_OPEN_CONFIGURATION: - wguiOpenConfigurationFile(wgui_cfg, wgui_hDialog); + else + wgui_action = WGUI_NO_ACTION; + } + break; + case WGUI_OPEN_CONFIGURATION: + wguiOpenConfigurationFile(wgui_cfg, wgui_hDialog); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); wguiCheckMemorySettingsForChipset(); wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_SAVE_CONFIGURATION: + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_SAVE_CONFIGURATION: wguiExtractFloppyMain(wgui_hDialog, wgui_cfg); cfgSaveToFilename(wgui_cfg, iniGetCurrentConfigurationFilename(wgui_ini)); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_SAVE_CONFIGURATION_AS: + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_SAVE_CONFIGURATION_AS: wguiExtractFloppyMain(wgui_hDialog, wgui_cfg); wguiSaveConfigurationFileAs(wgui_cfg, wgui_hDialog); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); - wguiInsertCfgIntoHistory(iniGetCurrentConfigurationFilename(wgui_ini)); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_LOAD_HISTORY0: - if(cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 0), false) == FALSE) - { - wguiDeleteCfgFromHistory(0); - } - else - { - iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 0)); + wguiInsertCfgIntoHistory(iniGetCurrentConfigurationFilename(wgui_ini)); + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_LOAD_HISTORY0: + if (cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 0), false) == FALSE) + { + wguiDeleteCfgFromHistory(0); + } + else + { + iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 0)); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); wguiCheckMemorySettingsForChipset(); - } - wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_LOAD_HISTORY1: - if(cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 1), false) == FALSE) - { - wguiDeleteCfgFromHistory(1); - } - else - { - iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 1)); + } + wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_LOAD_HISTORY1: + if (cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 1), false) == FALSE) + { + wguiDeleteCfgFromHistory(1); + } + else + { + iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 1)); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); wguiCheckMemorySettingsForChipset(); - wguiPutCfgInHistoryOnTop(1); - } - wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_LOAD_HISTORY2: - if(cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 2), false) == FALSE) - { - wguiDeleteCfgFromHistory(2); - } - else - { - iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 2)); + wguiPutCfgInHistoryOnTop(1); + } + wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_LOAD_HISTORY2: + if (cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 2), false) == FALSE) + { + wguiDeleteCfgFromHistory(2); + } + else + { + iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 2)); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); wguiCheckMemorySettingsForChipset(); - wguiPutCfgInHistoryOnTop(2); - } - wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_LOAD_HISTORY3: - if(cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 3), false) == FALSE) - { - wguiDeleteCfgFromHistory(3); - } - else - { - iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 3)); + wguiPutCfgInHistoryOnTop(2); + } + wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_LOAD_HISTORY3: + if (cfgLoadFromFilename(wgui_cfg, iniGetConfigurationHistoryFilename(wgui_ini, 3), false) == FALSE) + { + wguiDeleteCfgFromHistory(3); + } + else + { + iniSetCurrentConfigurationFilename(wgui_ini, iniGetConfigurationHistoryFilename(wgui_ini, 3)); cfgSetConfigChangedSinceLastSave(wgui_cfg, FALSE); wguiCheckMemorySettingsForChipset(); - wguiPutCfgInHistoryOnTop(3); - } - wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); - wgui_action = WGUI_NO_ACTION; - break; - case WGUI_DEBUGGER_START: - end_loop = TRUE; + wguiPutCfgInHistoryOnTop(3); + } + wguiInstallFloppyMain(wgui_hDialog, wgui_cfg); + wgui_action = WGUI_NO_ACTION; + break; + case WGUI_DEBUGGER_START: + end_loop = TRUE; wguiExtractFloppyMain(wgui_hDialog, wgui_cfg); cfgManagerSetCurrentConfig(&cfg_manager, wgui_cfg); - fellowSetPreStartReset(cfgManagerConfigurationActivate(&cfg_manager) || fellowGetPreStartReset()); - debugger_start = TRUE; - case WGUI_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS: - wguiToggleMenuPauseEmulationWhenWindowLosesFocus(wgui_hDialog, wgui_ini); - wgui_action = WGUI_NO_ACTION; - break; - default: - break; + fellowSetPreStartReset(cfgManagerConfigurationActivate(&cfg_manager) || fellowGetPreStartReset()); + debugger_start = TRUE; + case WGUI_PAUSE_EMULATION_WHEN_WINDOW_LOSES_FOCUS: + wguiToggleMenuPauseEmulationWhenWindowLosesFocus(wgui_hDialog, wgui_ini); + wgui_action = WGUI_NO_ACTION; + break; + default: break; } } @@ -3722,7 +3621,7 @@ BOOLE wguiEnter() { do { - winDrvEmulationStart(); + winDrvEmulationStart(); } while (gfxDrvCommon->_displaychange); if (!cfgGetUseGUI(wgui_cfg)) @@ -3734,7 +3633,8 @@ BOOLE wguiEnter() return quit_emulator; } -static bool wguiInitializePresets(wgui_preset **wgui_presets, uint32_t *wgui_num_presets) { +static bool wguiInitializePresets(wgui_preset **wgui_presets, uint32_t *wgui_num_presets) +{ char strSearchPattern[CFG_FILENAME_LENGTH] = ""; WIN32_FIND_DATA ffd; HANDLE hFind = INVALID_HANDLE_VALUE; @@ -3747,38 +3647,47 @@ static bool wguiInitializePresets(wgui_preset **wgui_presets, uint32_t *wgui_num // first we count the number of files in the preset directory hFind = FindFirstFile(strSearchPattern, &ffd); - if (hFind == INVALID_HANDLE_VALUE) { + if (hFind == INVALID_HANDLE_VALUE) + { fellowAddLog("wguiInitializePresets(): FindFirstFile failed.\n"); return false; } *wgui_num_presets = 0; - do { - if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + do + { + if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + ; else - *wgui_num_presets+=1; - } while(FindNextFile(hFind, &ffd) != 0); + *wgui_num_presets += 1; + } while (FindNextFile(hFind, &ffd) != 0); FindClose(hFind); fellowAddLog("wguiInitializePresets(): %u preset(s) found.\n", *wgui_num_presets); // then we allocate the memory to store preset information, and read the information - if(*wgui_num_presets > 0) { - *wgui_presets = (wgui_preset *) malloc(*wgui_num_presets * sizeof(wgui_preset)); + if (*wgui_num_presets > 0) + { + *wgui_presets = (wgui_preset *)malloc(*wgui_num_presets * sizeof(wgui_preset)); hFind = FindFirstFile(strSearchPattern, &ffd); - do { - if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - else { + do + { + if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + ; + else + { strncpy((*wgui_presets)[i].strPresetFilename, wgui_preset_path, CFG_FILENAME_LENGTH); strncat((*wgui_presets)[i].strPresetFilename, "\\", 2); strncat((*wgui_presets)[i].strPresetFilename, ffd.cFileName, CFG_FILENAME_LENGTH); cfgTemp = cfgManagerGetNewConfig(&cfg_manager); - if(cfgTemp) { + if (cfgTemp) + { bResult = cfgLoadFromFilename(cfgTemp, (*wgui_presets)[i].strPresetFilename, true); - if(bResult) { + if (bResult) + { strncpy((*wgui_presets)[i].strPresetDescription, cfgGetDescription(cfgTemp), CFG_FILENAME_LENGTH); #ifdef _DEBUG fellowAddLog(" preset %u: %s - %s\n", i, ffd.cFileName, (*wgui_presets)[i].strPresetDescription); @@ -3791,24 +3700,25 @@ static bool wguiInitializePresets(wgui_preset **wgui_presets, uint32_t *wgui_num cfgManagerFreeConfig(&cfg_manager, cfgTemp); } } - } while((FindNextFile(hFind, &ffd) != 0) && (i < *wgui_num_presets)); + } while ((FindNextFile(hFind, &ffd) != 0) && (i < *wgui_num_presets)); FindClose(hFind); } return true; -} +} void wguiSetProcessDPIAwareness(const char *pszAwareness) { #ifndef Process_DPI_Awareness - typedef enum _Process_DPI_Awareness { + typedef enum _Process_DPI_Awareness + { Process_DPI_Unaware = 0, Process_System_DPI_Aware = 1, Process_Per_Monitor_DPI_Aware = 2 } Process_DPI_Awareness; #endif - typedef HRESULT(WINAPI *PFN_SetProcessDpiAwareness)(Process_DPI_Awareness); - typedef BOOL(WINAPI *PFN_SetProcessDPIAware)(); + typedef HRESULT(WINAPI * PFN_SetProcessDpiAwareness)(Process_DPI_Awareness); + typedef BOOL(WINAPI * PFN_SetProcessDPIAware)(); fellowAddLog("wguiSetProcessDPIAwareness(%s)\n", pszAwareness); @@ -3818,12 +3728,9 @@ void wguiSetProcessDPIAwareness(const char *pszAwareness) if (hCoreDll) { - PFN_SetProcessDpiAwareness pfnSetProcessDpiAwareness = (PFN_SetProcessDpiAwareness)GetProcAddress( - hCoreDll, "SetProcessDpiAwareness"); - if (pfnSetProcessDpiAwareness) - hr = pfnSetProcessDpiAwareness(nAwareness); - if (hr == S_OK) - fellowAddLog(" SetProcessDPIAwareness() executed succesfully.\n"); + PFN_SetProcessDpiAwareness pfnSetProcessDpiAwareness = (PFN_SetProcessDpiAwareness)GetProcAddress(hCoreDll, "SetProcessDpiAwareness"); + if (pfnSetProcessDpiAwareness) hr = pfnSetProcessDpiAwareness(nAwareness); + if (hr == S_OK) fellowAddLog(" SetProcessDPIAwareness() executed succesfully.\n"); FreeLibrary(hCoreDll); } @@ -3834,58 +3741,59 @@ void wguiSetProcessDPIAwareness(const char *pszAwareness) { fellowAddLog("hUser32"); PFN_SetProcessDPIAware pfnSetProcessDPIAware = (PFN_SetProcessDPIAware)GetProcAddress(hUser32, "SetProcessDPIAware"); - if (pfnSetProcessDPIAware) { + if (pfnSetProcessDPIAware) + { hr = pfnSetProcessDPIAware(); - if (hr != 0) - fellowAddLog(" SetProcessDPIAware() executed succesfully.\n"); + if (hr != 0) fellowAddLog(" SetProcessDPIAware() executed succesfully.\n"); } FreeLibrary(hUser32); } } } - /*============================================================================*/ /* Called at the start of Fellow execution */ /*============================================================================*/ -void wguiStartup() { +void wguiStartup() +{ wgui_cfg = cfgManagerGetCurrentConfig(&cfg_manager); wgui_ini = iniManagerGetCurrentInitdata(&ini_manager); wguiConvertDrawModeListToGuiDrawModes(); - if(fileopsGetWinFellowPresetPath(wgui_preset_path, CFG_FILENAME_LENGTH)) { + if (fileopsGetWinFellowPresetPath(wgui_preset_path, CFG_FILENAME_LENGTH)) + { fellowAddLog("wguiStartup(): preset path = %s\n", wgui_preset_path); wguiInitializePresets(&wgui_presets, &wgui_num_presets); } } - /*============================================================================*/ /* Called at the end of Fellow initialization */ /*============================================================================*/ -void wguiStartupPost() { +void wguiStartupPost() +{ wguiLoadBitmaps(); - if (wgui_emulation_state) { - SendMessage(GetDlgItem(wgui_hDialog, IDC_IMAGE_POWER_LED_MAIN), - STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) power_led_on_bitmap); - } else { - SendMessage(GetDlgItem(wgui_hDialog, IDC_IMAGE_POWER_LED_MAIN), - STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) power_led_off_bitmap); + if (wgui_emulation_state) + { + SendMessage(GetDlgItem(wgui_hDialog, IDC_IMAGE_POWER_LED_MAIN), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)power_led_on_bitmap); + } + else + { + SendMessage(GetDlgItem(wgui_hDialog, IDC_IMAGE_POWER_LED_MAIN), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)power_led_off_bitmap); } } - /*============================================================================*/ /* Called at the end of Fellow execution */ /*============================================================================*/ -void wguiShutdown() { +void wguiShutdown() +{ wguiReleaseBitmaps(); wguiFreeGuiDrawModesLists(); - if(wgui_presets != nullptr) - free(wgui_presets); + if (wgui_presets != nullptr) free(wgui_presets); } diff --git a/fellow/SRC/WinFellow/Windows/fileops.h b/fellow/SRC/WinFellow/Windows/fileops.h index 44b4760a..898d706d 100644 --- a/fellow/SRC/WinFellow/Windows/fileops.h +++ b/fellow/SRC/WinFellow/Windows/fileops.h @@ -24,6 +24,8 @@ /* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*=========================================================================*/ +#include "DEFS.H" + extern BOOLE fileopsGetFellowLogfileName(char *); extern BOOLE fileopsGetGenericFileName(char *, const char *, const char *); extern BOOLE fileopsGetDefaultConfigFileName(char *); diff --git a/fellow/SRC/WinFellow/Windows/gfxdrv_directdraw.cpp b/fellow/SRC/WinFellow/Windows/gfxdrv_directdraw.cpp index d3610b5f..96394824 100644 --- a/fellow/SRC/WinFellow/Windows/gfxdrv_directdraw.cpp +++ b/fellow/SRC/WinFellow/Windows/gfxdrv_directdraw.cpp @@ -23,39 +23,39 @@ /***********************************************************************/ /** - * @file - * Graphics device module - * - * Framebuffer modes of operation: - * - * 1. Using the primary buffer non-clipped, with possible back-buffers. - * This applies to fullscreen mode with a framepointer. - * 2. Using a secondary buffer to render and then applying the blitter - * to the primary buffer. The primary buffer can be clipped (window) - * or non-clipped (fullscreen). In this mode there are no backbuffers. - * - * blitmode is used: - * 1. When running on the desktop in a window. - * 2. In fullscreen mode with a primary surface that - * can not supply a framebuffer pointer. - * - * Windows: - * Two types of windows: - * 1. Normal desktop window for desktop operation - * 2. Full-screen window for fullscreen mode - * - * Windows are created and destroyed on emulation start and stop. - * - * Buffers: - * Buffers are created when emulation starts and destroyed - * when emulation stops. (Recreated when lost also) - * - * if blitmode, create single primary buffer - * and a secondary buffer for actual rendering in system memory. - * if windowed also add a clipper to the primary buffer - * - * else create a primary buffer (with backbuffers) - ***************************************************************************/ + * @file + * Graphics device module + * + * Framebuffer modes of operation: + * + * 1. Using the primary buffer non-clipped, with possible back-buffers. + * This applies to fullscreen mode with a framepointer. + * 2. Using a secondary buffer to render and then applying the blitter + * to the primary buffer. The primary buffer can be clipped (window) + * or non-clipped (fullscreen). In this mode there are no backbuffers. + * + * blitmode is used: + * 1. When running on the desktop in a window. + * 2. In fullscreen mode with a primary surface that + * can not supply a framebuffer pointer. + * + * Windows: + * Two types of windows: + * 1. Normal desktop window for desktop operation + * 2. Full-screen window for fullscreen mode + * + * Windows are created and destroyed on emulation start and stop. + * + * Buffers: + * Buffers are created when emulation starts and destroyed + * when emulation stops. (Recreated when lost also) + * + * if blitmode, create single primary buffer + * and a secondary buffer for actual rendering in system memory. + * if windowed also add a clipper to the primary buffer + * + * else create a primary buffer (with backbuffers) + ***************************************************************************/ #define INITGUID @@ -67,7 +67,6 @@ #include "fellow.h" #include "fmem.h" -#include "sound.h" #include "graph.h" #include "draw.h" #include "kbd.h" @@ -77,7 +76,6 @@ #include "gameport.h" #include "mousedrv.h" #include "joydrv.h" -#include "sounddrv.h" #include "wgui.h" #include "ini.h" @@ -116,34 +114,33 @@ struct gfx_drv_ddraw_fullscreen_mode typedef struct { - LPGUID lpGUID; - LPSTR lpDriverDescription; - LPSTR lpDriverName; - LPDIRECTDRAW lpDD; - LPDIRECTDRAW2 lpDD2; - LPDIRECTDRAWSURFACE lpDDSPrimary; /*!< Primary display surface */ - LPDIRECTDRAWSURFACE lpDDSBack; /*!< Current backbuffer for Primary */ - LPDIRECTDRAWSURFACE lpDDSSecondary; /*!< Source surface in blitmode */ - DDSURFACEDESC ddsdPrimary; - DDSURFACEDESC ddsdBack; - DDSURFACEDESC ddsdSecondary; - LPDIRECTDRAWCLIPPER lpDDClipper; - felist *fullscreen_modes; - gfx_drv_ddraw_fullscreen_mode *fullscreen_mode; - uint32_t buffercount; - uint32_t maxbuffercount; - RECT hwnd_clientrect_screen; - RECT hwnd_clientrect_win; - draw_mode *drawmode; - bool use_blitter; - bool can_stretch_y; - bool no_dd_hardware; - bool windowed; + LPGUID lpGUID; + LPSTR lpDriverDescription; + LPSTR lpDriverName; + LPDIRECTDRAW lpDD; + LPDIRECTDRAW2 lpDD2; + LPDIRECTDRAWSURFACE lpDDSPrimary; /*!< Primary display surface */ + LPDIRECTDRAWSURFACE lpDDSBack; /*!< Current backbuffer for Primary */ + LPDIRECTDRAWSURFACE lpDDSSecondary; /*!< Source surface in blitmode */ + DDSURFACEDESC ddsdPrimary; + DDSURFACEDESC ddsdBack; + DDSURFACEDESC ddsdSecondary; + LPDIRECTDRAWCLIPPER lpDDClipper; + felist *fullscreen_modes; + gfx_drv_ddraw_fullscreen_mode *fullscreen_mode; + uint32_t buffercount; + uint32_t maxbuffercount; + RECT hwnd_clientrect_screen; + RECT hwnd_clientrect_win; + draw_mode *drawmode; + bool use_blitter; + bool can_stretch_y; + bool no_dd_hardware; + bool windowed; } gfx_drv_ddraw_device; gfx_drv_ddraw_device *gfx_drv_ddraw_device_current; -felist *gfx_drv_ddraw_devices; - +felist *gfx_drv_ddraw_devices; bool gfx_drv_ddraw_initialized; bool gfx_drv_ddraw_clear_borders; @@ -158,107 +155,107 @@ const char *gfxDrvDDrawErrorString(HRESULT hResult) { switch (hResult) { - case DD_OK: return "DD_OK"; - case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED"; - case DDERR_BLTFASTCANTCLIP: return "DDERR_BLTFASTCANTCLIP"; - case DDERR_CANNOTATTACHSURFACE: return "DDERR_CANNOTATTACHSURFACE"; - case DDERR_CANNOTDETACHSURFACE: return "DDERR_CANNOTDETACHSURFACE"; - case DDERR_CANTCREATEDC: return "DDERR_CANTCREATEDC"; - case DDERR_CANTDUPLICATE: return "DDERR_CANTDUPLICATE"; - case DDERR_CANTLOCKSURFACE: return "DDERR_CANTLOCKSURFACE"; - case DDERR_CANTPAGELOCK: return "DDERR_CANTPAGELOCK"; - case DDERR_CANTPAGEUNLOCK: return "DDERR_CANTPAGEUNLOCK"; - case DDERR_CLIPPERISUSINGHWND: return "DDERR_CLIPPERISUSINGHWND"; - case DDERR_COLORKEYNOTSET: return "DDERR_COLORKEYNOTSET"; - case DDERR_CURRENTLYNOTAVAIL: return "DDERR_CURRENTLYNOTAVAIL"; - case DDERR_DCALREADYCREATED: return "DDERR_DCALREADYCREATED"; - case DDERR_DIRECTDRAWALREADYCREATED: return "DDERR_DIRECTDRAWALREADYCREATED"; - case DDERR_EXCEPTION: return "DDERR_EXCEPTION"; - case DDERR_EXCLUSIVEMODEALREADYSET: return "DDERR_EXCLUSIVEMODEALREADYSET"; - case DDERR_GENERIC: return "DDERR_GENERIC"; - case DDERR_HEIGHTALIGN: return "DDERR_HEIGHTALIGN"; - case DDERR_HWNDALREADYSET: return "DDERR_HWNDALREADYSET"; - case DDERR_HWNDSUBCLASSED: return "DDERR_HWNDSUBCLASSED"; - case DDERR_IMPLICITLYCREATED: return "DDERR_IMPLICITLYCREATED"; - case DDERR_INCOMPATIBLEPRIMARY: return "DDERR_INCOMPATIBLEPRIMARY"; - case DDERR_INVALIDCAPS: return "DDERR_INVALIDCAPS"; - case DDERR_INVALIDCLIPLIST: return "DDERR_INVALIDCLIPLIST"; - case DDERR_INVALIDDIRECTDRAWGUID: return "DDERR_INVALIDDIRECTDRAWGUID"; - case DDERR_INVALIDMODE: return "DDERR_INVALIDMODE"; - case DDERR_INVALIDOBJECT: return "DDERR_INVALIDOBJECT"; - case DDERR_INVALIDPARAMS: return "DDERR_INVALIDPARAMS"; - case DDERR_INVALIDPIXELFORMAT: return "DDERR_INVALIDPIXELFORMAT"; - case DDERR_INVALIDPOSITION: return "DDERR_INVALIDPOSITION"; - case DDERR_INVALIDRECT: return "DDERR_INVALIDRECT"; - case DDERR_INVALIDSURFACETYPE: return "DDERR_INVALIDSURFACETYPE"; - case DDERR_LOCKEDSURFACES: return "DDERR_LOCKEDSURFACES"; - case DDERR_NO3D: return "DDERR_NO3D"; - case DDERR_NOALPHAHW: return "DDERR_NOALPHAHW"; - case DDERR_NOBLTHW: return "DDERR_NOBLTHW"; - case DDERR_NOCLIPLIST: return "DDERR_NOCLIPLIST"; - case DDERR_NOCLIPPERATTACHED: return "DDERR_NOCLIPPERATTACHED"; - case DDERR_NOCOLORCONVHW: return "DDERR_NOCOLORCONVHW"; - case DDERR_NOCOLORKEY: return "DDERR_NOCOLORKEY"; - case DDERR_NOCOLORKEYHW: return "DDERR_NOCOLORKEYHW"; - case DDERR_NOCOOPERATIVELEVELSET: return "DDERR_NOCOOPERATIVELEVELSET"; - case DDERR_NODC: return "DDERR_NODC"; - case DDERR_NODDROPSHW: return "DDERR_NODDROPSHW"; - case DDERR_NODIRECTDRAWHW: return "DDERR_NODIRECTDRAWHW"; - case DDERR_NODIRECTDRAWSUPPORT: return "DDERR_NODIRECTDRAWSUPPORT"; - case DDERR_NOEMULATION: return "DDERR_NOEMULATION"; - case DDERR_NOEXCLUSIVEMODE: return "DDERR_NOEXCLUSIVEMODE"; - case DDERR_NOFLIPHW: return "DDERR_NOFLIPHW"; - case DDERR_NOGDI: return "DDERR_NOGDI"; - case DDERR_NOHWND: return "DDERR_NOHWND"; - case DDERR_NOMIPMAPHW: return "DDERR_NOMIPMAPHW"; - case DDERR_NOMIRRORHW: return "DDERR_NOMIRRORHW"; - case DDERR_NOOVERLAYDEST: return "DDERR_NOOVERLAYDEST"; - case DDERR_NOOVERLAYHW: return "DDERR_NOOVERLAYHW"; - case DDERR_NOPALETTEATTACHED: return "DDERR_NOPALETTEATTACHED"; - case DDERR_NOPALETTEHW: return "DDERR_NOPALETTEHW"; - case DDERR_NORASTEROPHW: return "DDERR_NORASTEROPHW"; - case DDERR_NOROTATIONHW: return "DDERR_NOROTATIONHW"; - case DDERR_NOSTRETCHHW: return "DDERR_NOSTRETCHHW"; - case DDERR_NOT4BITCOLOR: return "DDERR_NOT4BITCOLOR"; - case DDERR_NOT4BITCOLORINDEX: return "DDERR_NOT4BITCOLORINDEX"; - case DDERR_NOT8BITCOLOR: return "DDERR_NOT8BITCOLOR"; - case DDERR_NOTAOVERLAYSURFACE: return "DDERR_NOTAOVERLAYSURFACE"; - case DDERR_NOTEXTUREHW: return "DDERR_NOTEXTUREHW"; - case DDERR_NOTFLIPPABLE: return "DDERR_NOTFLIPPABLE"; - case DDERR_NOTFOUND: return "DDERR_NOTFOUND"; - case DDERR_NOTINITIALIZED: return "DDERR_NOTINITIALIZED"; - case DDERR_NOTLOCKED: return "DDERR_NOTLOCKED"; - case DDERR_NOTPAGELOCKED: return "DDERR_NOTPAGELOCKED"; - case DDERR_NOTPALETTIZED: return "DDERR_NOTPALETTIZED"; - case DDERR_NOVSYNCHW: return "DDERR_NOVSYNCHW"; - case DDERR_NOZBUFFERHW: return "DDERR_NOZBUFFERHW"; - case DDERR_NOZOVERLAYHW: return "DDERR_NOZOVERLAYHW"; - case DDERR_OUTOFCAPS: return "DDERR_OUTOFCAPS"; - case DDERR_OUTOFMEMORY: return "DDERR_OUTOFMEMORY"; - case DDERR_OUTOFVIDEOMEMORY: return "DDERR_OUTOFVIDEOMEMORY"; - case DDERR_OVERLAYCANTCLIP: return "DDERR_OVERLAYCANTCLIP"; - case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:return "DDERR_OVERLAYCOLORKEYONLYONEACTIVE"; - case DDERR_OVERLAYNOTVISIBLE: return "DDERR_OVERLAYNOTVISIBLE"; - case DDERR_PALETTEBUSY: return "DDERR_PALETTEBUSY"; + case DD_OK: return "DD_OK"; + case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED"; + case DDERR_BLTFASTCANTCLIP: return "DDERR_BLTFASTCANTCLIP"; + case DDERR_CANNOTATTACHSURFACE: return "DDERR_CANNOTATTACHSURFACE"; + case DDERR_CANNOTDETACHSURFACE: return "DDERR_CANNOTDETACHSURFACE"; + case DDERR_CANTCREATEDC: return "DDERR_CANTCREATEDC"; + case DDERR_CANTDUPLICATE: return "DDERR_CANTDUPLICATE"; + case DDERR_CANTLOCKSURFACE: return "DDERR_CANTLOCKSURFACE"; + case DDERR_CANTPAGELOCK: return "DDERR_CANTPAGELOCK"; + case DDERR_CANTPAGEUNLOCK: return "DDERR_CANTPAGEUNLOCK"; + case DDERR_CLIPPERISUSINGHWND: return "DDERR_CLIPPERISUSINGHWND"; + case DDERR_COLORKEYNOTSET: return "DDERR_COLORKEYNOTSET"; + case DDERR_CURRENTLYNOTAVAIL: return "DDERR_CURRENTLYNOTAVAIL"; + case DDERR_DCALREADYCREATED: return "DDERR_DCALREADYCREATED"; + case DDERR_DIRECTDRAWALREADYCREATED: return "DDERR_DIRECTDRAWALREADYCREATED"; + case DDERR_EXCEPTION: return "DDERR_EXCEPTION"; + case DDERR_EXCLUSIVEMODEALREADYSET: return "DDERR_EXCLUSIVEMODEALREADYSET"; + case DDERR_GENERIC: return "DDERR_GENERIC"; + case DDERR_HEIGHTALIGN: return "DDERR_HEIGHTALIGN"; + case DDERR_HWNDALREADYSET: return "DDERR_HWNDALREADYSET"; + case DDERR_HWNDSUBCLASSED: return "DDERR_HWNDSUBCLASSED"; + case DDERR_IMPLICITLYCREATED: return "DDERR_IMPLICITLYCREATED"; + case DDERR_INCOMPATIBLEPRIMARY: return "DDERR_INCOMPATIBLEPRIMARY"; + case DDERR_INVALIDCAPS: return "DDERR_INVALIDCAPS"; + case DDERR_INVALIDCLIPLIST: return "DDERR_INVALIDCLIPLIST"; + case DDERR_INVALIDDIRECTDRAWGUID: return "DDERR_INVALIDDIRECTDRAWGUID"; + case DDERR_INVALIDMODE: return "DDERR_INVALIDMODE"; + case DDERR_INVALIDOBJECT: return "DDERR_INVALIDOBJECT"; + case DDERR_INVALIDPARAMS: return "DDERR_INVALIDPARAMS"; + case DDERR_INVALIDPIXELFORMAT: return "DDERR_INVALIDPIXELFORMAT"; + case DDERR_INVALIDPOSITION: return "DDERR_INVALIDPOSITION"; + case DDERR_INVALIDRECT: return "DDERR_INVALIDRECT"; + case DDERR_INVALIDSURFACETYPE: return "DDERR_INVALIDSURFACETYPE"; + case DDERR_LOCKEDSURFACES: return "DDERR_LOCKEDSURFACES"; + case DDERR_NO3D: return "DDERR_NO3D"; + case DDERR_NOALPHAHW: return "DDERR_NOALPHAHW"; + case DDERR_NOBLTHW: return "DDERR_NOBLTHW"; + case DDERR_NOCLIPLIST: return "DDERR_NOCLIPLIST"; + case DDERR_NOCLIPPERATTACHED: return "DDERR_NOCLIPPERATTACHED"; + case DDERR_NOCOLORCONVHW: return "DDERR_NOCOLORCONVHW"; + case DDERR_NOCOLORKEY: return "DDERR_NOCOLORKEY"; + case DDERR_NOCOLORKEYHW: return "DDERR_NOCOLORKEYHW"; + case DDERR_NOCOOPERATIVELEVELSET: return "DDERR_NOCOOPERATIVELEVELSET"; + case DDERR_NODC: return "DDERR_NODC"; + case DDERR_NODDROPSHW: return "DDERR_NODDROPSHW"; + case DDERR_NODIRECTDRAWHW: return "DDERR_NODIRECTDRAWHW"; + case DDERR_NODIRECTDRAWSUPPORT: return "DDERR_NODIRECTDRAWSUPPORT"; + case DDERR_NOEMULATION: return "DDERR_NOEMULATION"; + case DDERR_NOEXCLUSIVEMODE: return "DDERR_NOEXCLUSIVEMODE"; + case DDERR_NOFLIPHW: return "DDERR_NOFLIPHW"; + case DDERR_NOGDI: return "DDERR_NOGDI"; + case DDERR_NOHWND: return "DDERR_NOHWND"; + case DDERR_NOMIPMAPHW: return "DDERR_NOMIPMAPHW"; + case DDERR_NOMIRRORHW: return "DDERR_NOMIRRORHW"; + case DDERR_NOOVERLAYDEST: return "DDERR_NOOVERLAYDEST"; + case DDERR_NOOVERLAYHW: return "DDERR_NOOVERLAYHW"; + case DDERR_NOPALETTEATTACHED: return "DDERR_NOPALETTEATTACHED"; + case DDERR_NOPALETTEHW: return "DDERR_NOPALETTEHW"; + case DDERR_NORASTEROPHW: return "DDERR_NORASTEROPHW"; + case DDERR_NOROTATIONHW: return "DDERR_NOROTATIONHW"; + case DDERR_NOSTRETCHHW: return "DDERR_NOSTRETCHHW"; + case DDERR_NOT4BITCOLOR: return "DDERR_NOT4BITCOLOR"; + case DDERR_NOT4BITCOLORINDEX: return "DDERR_NOT4BITCOLORINDEX"; + case DDERR_NOT8BITCOLOR: return "DDERR_NOT8BITCOLOR"; + case DDERR_NOTAOVERLAYSURFACE: return "DDERR_NOTAOVERLAYSURFACE"; + case DDERR_NOTEXTUREHW: return "DDERR_NOTEXTUREHW"; + case DDERR_NOTFLIPPABLE: return "DDERR_NOTFLIPPABLE"; + case DDERR_NOTFOUND: return "DDERR_NOTFOUND"; + case DDERR_NOTINITIALIZED: return "DDERR_NOTINITIALIZED"; + case DDERR_NOTLOCKED: return "DDERR_NOTLOCKED"; + case DDERR_NOTPAGELOCKED: return "DDERR_NOTPAGELOCKED"; + case DDERR_NOTPALETTIZED: return "DDERR_NOTPALETTIZED"; + case DDERR_NOVSYNCHW: return "DDERR_NOVSYNCHW"; + case DDERR_NOZBUFFERHW: return "DDERR_NOZBUFFERHW"; + case DDERR_NOZOVERLAYHW: return "DDERR_NOZOVERLAYHW"; + case DDERR_OUTOFCAPS: return "DDERR_OUTOFCAPS"; + case DDERR_OUTOFMEMORY: return "DDERR_OUTOFMEMORY"; + case DDERR_OUTOFVIDEOMEMORY: return "DDERR_OUTOFVIDEOMEMORY"; + case DDERR_OVERLAYCANTCLIP: return "DDERR_OVERLAYCANTCLIP"; + case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: return "DDERR_OVERLAYCOLORKEYONLYONEACTIVE"; + case DDERR_OVERLAYNOTVISIBLE: return "DDERR_OVERLAYNOTVISIBLE"; + case DDERR_PALETTEBUSY: return "DDERR_PALETTEBUSY"; case DDERR_PRIMARYSURFACEALREADYEXISTS: return "DDERR_PRIMARYSURFACEALREADYEXISTS"; - case DDERR_REGIONTOOSMALL: return "DDERR_REGIONTOOSMALL"; - case DDERR_SURFACEALREADYATTACHED: return "DDERR_SURFACEALREADYATTACHED"; - case DDERR_SURFACEALREADYDEPENDENT: return "DDERR_SURFACEALREADYDEPENDENT"; - case DDERR_SURFACEBUSY: return "DDERR_SURFACEBUSY"; - case DDERR_SURFACEISOBSCURED: return "DDERR_SURFACEISOBSCURED"; - case DDERR_SURFACELOST: return "DDERR_SURFACELOST"; - case DDERR_SURFACENOTATTACHED: return "DDERR_SURFACENOTATTACHED"; - case DDERR_TOOBIGHEIGHT: return "DDERR_TOOBIGHEIGHT"; - case DDERR_TOOBIGSIZE: return "DDERR_TOOBIGSIZE"; - case DDERR_TOOBIGWIDTH: return "DDERR_TOOBIGWIDTH"; - case DDERR_UNSUPPORTED: return "DDERR_UNSUPPORTED"; - case DDERR_UNSUPPORTEDFORMAT: return "DDERR_UNSUPPORTEDFORMAT"; - case DDERR_UNSUPPORTEDMASK: return "DDERR_UNSUPPORTEDMASK"; - case DDERR_UNSUPPORTEDMODE: return "DDERR_UNSUPPORTEDMODE"; - case DDERR_VERTICALBLANKINPROGRESS: return "DDERR_VERTICALBLANKINPROGRESS"; - case DDERR_WASSTILLDRAWING: return "DDERR_WASSTILLDRAWING"; - case DDERR_WRONGMODE: return "DDERR_WRONGMODE"; - case DDERR_XALIGN: return "DDERR_XALIGN"; + case DDERR_REGIONTOOSMALL: return "DDERR_REGIONTOOSMALL"; + case DDERR_SURFACEALREADYATTACHED: return "DDERR_SURFACEALREADYATTACHED"; + case DDERR_SURFACEALREADYDEPENDENT: return "DDERR_SURFACEALREADYDEPENDENT"; + case DDERR_SURFACEBUSY: return "DDERR_SURFACEBUSY"; + case DDERR_SURFACEISOBSCURED: return "DDERR_SURFACEISOBSCURED"; + case DDERR_SURFACELOST: return "DDERR_SURFACELOST"; + case DDERR_SURFACENOTATTACHED: return "DDERR_SURFACENOTATTACHED"; + case DDERR_TOOBIGHEIGHT: return "DDERR_TOOBIGHEIGHT"; + case DDERR_TOOBIGSIZE: return "DDERR_TOOBIGSIZE"; + case DDERR_TOOBIGWIDTH: return "DDERR_TOOBIGWIDTH"; + case DDERR_UNSUPPORTED: return "DDERR_UNSUPPORTED"; + case DDERR_UNSUPPORTEDFORMAT: return "DDERR_UNSUPPORTEDFORMAT"; + case DDERR_UNSUPPORTEDMASK: return "DDERR_UNSUPPORTEDMASK"; + case DDERR_UNSUPPORTEDMODE: return "DDERR_UNSUPPORTEDMODE"; + case DDERR_VERTICALBLANKINPROGRESS: return "DDERR_VERTICALBLANKINPROGRESS"; + case DDERR_WASSTILLDRAWING: return "DDERR_WASSTILLDRAWING"; + case DDERR_WRONGMODE: return "DDERR_WRONGMODE"; + case DDERR_XALIGN: return "DDERR_XALIGN"; } return "Not a DirectDraw Error"; } @@ -314,9 +311,7 @@ void gfxDrvDDrawFindWindowClientRect(gfx_drv_ddraw_device *ddraw_device) /* Select the correct drawing surface for a draw operation */ /*==========================================================================*/ -void gfxDrvDDrawDrawTargetSurfaceSelect(gfx_drv_ddraw_device *ddraw_device, - LPDIRECTDRAWSURFACE *lpDDS, - LPDDSURFACEDESC *lpDDSD) +void gfxDrvDDrawDrawTargetSurfaceSelect(gfx_drv_ddraw_device *ddraw_device, LPDIRECTDRAWSURFACE *lpDDS, LPDDSURFACEDESC *lpDDSD) { if (ddraw_device->use_blitter) { @@ -352,7 +347,6 @@ void gfxDrvDDrawClipperRelease(gfx_drv_ddraw_device *ddraw_device) } } - /*==========================================================================*/ /* Initialize clipper */ /*==========================================================================*/ @@ -388,16 +382,12 @@ bool gfxDrvDDrawClipperInitialize(gfx_drv_ddraw_device *ddraw_device) return (err == DD_OK); } - /*==========================================================================*/ /* Callback used to collect information about available DirectDraw devices */ /* Called on emulator startup */ /*==========================================================================*/ -BOOL WINAPI gfxDrvDDrawDeviceEnumerate(GUID FAR *lpGUID, - LPSTR lpDriverDescription, - LPSTR lpDriverName, - LPVOID lpContext) +BOOL WINAPI gfxDrvDDrawDeviceEnumerate(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext) { gfx_drv_ddraw_device *tmpdev = static_cast(malloc(sizeof(gfx_drv_ddraw_device))); memset(tmpdev, 0, sizeof(gfx_drv_ddraw_device)); @@ -419,7 +409,6 @@ BOOL WINAPI gfxDrvDDrawDeviceEnumerate(GUID FAR *lpGUID, return DDENUMRET_OK; } - /*==========================================================================*/ /* Dump information about available DirectDraw devices to log */ /*==========================================================================*/ @@ -440,7 +429,6 @@ void gfxDrvDDrawDeviceInformationDump() } } - /*==========================================================================*/ /* Creates a list of available DirectDraw devices */ /* Called on emulator startup */ @@ -463,7 +451,6 @@ bool gfxDrvDDrawDeviceInformationInitialize() return (listCount(gfx_drv_ddraw_devices) > 0); } - /*==========================================================================*/ /* Releases the list of available DirectDraw devices */ /* Called on emulator shutdown */ @@ -486,7 +473,6 @@ void gfxDrvDDrawDeviceInformationRelease() gfx_drv_ddraw_devices = nullptr; } - /*==========================================================================*/ /* Creates the DirectDraw1 object for the given DirectDraw device */ /* Called on emulator startup */ @@ -504,7 +490,6 @@ bool gfxDrvDDraw1ObjectInitialize(gfx_drv_ddraw_device *ddraw_device) return true; } - /*==========================================================================*/ /* Creates the DirectDraw2 object for the given DirectDraw device */ /* Requires that a DirectDraw1 object has been initialized */ @@ -531,10 +516,8 @@ bool gfxDrvDDraw2ObjectInitialize(gfx_drv_ddraw_device *ddraw_device) } else { - ddraw_device->can_stretch_y = (caps.dwFXCaps & DDFXCAPS_BLTARITHSTRETCHY) || - (caps.dwFXCaps & DDFXCAPS_BLTARITHSTRETCHYN) || - (caps.dwFXCaps & DDFXCAPS_BLTSTRETCHY) || - (caps.dwFXCaps & DDFXCAPS_BLTSHRINKYN); + ddraw_device->can_stretch_y = (caps.dwFXCaps & DDFXCAPS_BLTARITHSTRETCHY) || (caps.dwFXCaps & DDFXCAPS_BLTARITHSTRETCHYN) || (caps.dwFXCaps & DDFXCAPS_BLTSTRETCHY) || + (caps.dwFXCaps & DDFXCAPS_BLTSHRINKYN); if (!ddraw_device->can_stretch_y) { fellowAddLog("gfxdrv: WARNING: No hardware stretch\n"); @@ -549,7 +532,6 @@ bool gfxDrvDDraw2ObjectInitialize(gfx_drv_ddraw_device *ddraw_device) return true; } - /*==========================================================================*/ /* Releases the DirectDraw1 object for the given DirectDraw device */ /* Called on emulator startup */ @@ -571,7 +553,6 @@ bool gfxDrvDDraw1ObjectRelease(gfx_drv_ddraw_device *ddraw_device) return (err == DD_OK); } - /*==========================================================================*/ /* Releases the DirectDraw2 object for the given DirectDraw device */ /* Called on emulator shutdown */ @@ -593,7 +574,6 @@ bool gfxDrvDDraw2ObjectRelease(gfx_drv_ddraw_device *ddraw_device) return (err == DD_OK); } - /*==========================================================================*/ /* Creates the DirectDraw object for the selected DirectDraw device */ /* Called on emulator startup */ @@ -612,7 +592,6 @@ bool gfxDrvDDrawObjectInitialize(gfx_drv_ddraw_device *ddraw_device) return result; } - /*==========================================================================*/ /* Returns fullscreen mode information */ /*==========================================================================*/ @@ -622,9 +601,7 @@ gfx_drv_ddraw_fullscreen_mode *gfxDrvDDrawFindFullScreenMode(gfx_drv_ddraw_devic for (felist *l = ddraw_device->fullscreen_modes; l != nullptr; l = listNext(l)) { gfx_drv_ddraw_fullscreen_mode *tmpmode = static_cast(listNode(l)); - if (tmpmode->width == width && - tmpmode->height == height && - tmpmode->depth == depth) + if (tmpmode->width == width && tmpmode->height == height && tmpmode->depth == depth) { return tmpmode; } @@ -632,7 +609,6 @@ gfx_drv_ddraw_fullscreen_mode *gfxDrvDDrawFindFullScreenMode(gfx_drv_ddraw_devic return nullptr; } - /*==========================================================================*/ /* Describes all the found modes to the draw module */ /* Called on emulator startup */ @@ -669,7 +645,6 @@ void gfxDrvDDrawRegisterFullScreenModeInformation(gfx_drv_ddraw_device *ddraw_de } } - /*==========================================================================*/ /* Examines RGB masks for the mode information initializer */ /* Called on emulator startup */ @@ -716,17 +691,19 @@ void gfxDrvDDrawLogFullScreenModeInformation(gfx_drv_ddraw_device *ddraw_device) for (felist *l = ddraw_device->fullscreen_modes; l != nullptr; l = listNext(l)) { gfx_drv_ddraw_fullscreen_mode *tmpmode = static_cast(listNode(l)); - sprintf(s, "gfxdrv: Mode Description: %uWx%uHx%uBPPx%uHZ (%u,%u,%u,%u,%u,%u)", - tmpmode->width, - tmpmode->height, - tmpmode->depth, - tmpmode->refresh, - tmpmode->redpos, - tmpmode->redsize, - tmpmode->greenpos, - tmpmode->greensize, - tmpmode->bluepos, - tmpmode->bluesize); + sprintf( + s, + "gfxdrv: Mode Description: %uWx%uHx%uBPPx%uHZ (%u,%u,%u,%u,%u,%u)", + tmpmode->width, + tmpmode->height, + tmpmode->depth, + tmpmode->refresh, + tmpmode->redpos, + tmpmode->redsize, + tmpmode->greenpos, + tmpmode->greensize, + tmpmode->bluepos, + tmpmode->bluesize); logmessages.emplace_back(s); } Service->Log.AddLogList(logmessages); @@ -737,18 +714,19 @@ void gfxDrvDDrawLogFullScreenModeInformation(gfx_drv_ddraw_device *ddraw_device) /* Called on emulator startup */ /*==========================================================================*/ -gfx_drv_ddraw_fullscreen_mode *gfxDrvDDrawNewFullScreenMode(uint32_t width, - uint32_t height, - uint32_t depth, - uint32_t refresh, - uint32_t redpos, - uint32_t redsize, - uint32_t greenpos, - uint32_t greensize, - uint32_t bluepos, - uint32_t bluesize) +gfx_drv_ddraw_fullscreen_mode *gfxDrvDDrawNewFullScreenMode( + uint32_t width, + uint32_t height, + uint32_t depth, + uint32_t refresh, + uint32_t redpos, + uint32_t redsize, + uint32_t greenpos, + uint32_t greensize, + uint32_t bluepos, + uint32_t bluesize) { - gfx_drv_ddraw_fullscreen_mode *tmpmode = static_cast(malloc(sizeof(gfx_drv_ddraw_fullscreen_mode))); + gfx_drv_ddraw_fullscreen_mode *tmpmode = static_cast(malloc(sizeof(gfx_drv_ddraw_fullscreen_mode))); tmpmode->width = width; tmpmode->height = height; tmpmode->depth = depth; @@ -770,38 +748,37 @@ gfx_drv_ddraw_fullscreen_mode *gfxDrvDDrawNewFullScreenMode(uint32_t width, HRESULT WINAPI gfxDrvDDrawEnumerateFullScreenMode(LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext) { if (((lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_RGB) && - ((lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 16) || - (lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 24) || - (lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 32)))) + ((lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 16) || (lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 24) || + (lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 32)))) { if ((lpDDSurfaceDesc->dwRefreshRate > 1 && lpDDSurfaceDesc->dwRefreshRate < 50) || lpDDSurfaceDesc->dwWidth < 640) { - //fellowAddLog("gfxDrvDDrawModeEnumerate(): ignoring mode %ux%u, %u bit, %u Hz\n", - // lpDDSurfaceDesc->dwWidth, - // lpDDSurfaceDesc->dwHeight, - // lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount, - // lpDDSurfaceDesc->dwRefreshRate); + // fellowAddLog("gfxDrvDDrawModeEnumerate(): ignoring mode %ux%u, %u bit, %u Hz\n", + // lpDDSurfaceDesc->dwWidth, + // lpDDSurfaceDesc->dwHeight, + // lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount, + // lpDDSurfaceDesc->dwRefreshRate); return DDENUMRET_OK; } gfx_drv_ddraw_device *ddraw_device = static_cast(lpContext); - gfx_drv_ddraw_fullscreen_mode *tmpmode = gfxDrvDDrawNewFullScreenMode(lpDDSurfaceDesc->dwWidth, - lpDDSurfaceDesc->dwHeight, - lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount, - lpDDSurfaceDesc->dwRefreshRate, - gfxDrvRGBMaskPos(lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask), - gfxDrvRGBMaskSize(lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask), - gfxDrvRGBMaskPos(lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask), - gfxDrvRGBMaskSize(lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask), - gfxDrvRGBMaskPos(lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask), - gfxDrvRGBMaskSize(lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask)); + gfx_drv_ddraw_fullscreen_mode *tmpmode = gfxDrvDDrawNewFullScreenMode( + lpDDSurfaceDesc->dwWidth, + lpDDSurfaceDesc->dwHeight, + lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount, + lpDDSurfaceDesc->dwRefreshRate, + gfxDrvRGBMaskPos(lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask), + gfxDrvRGBMaskSize(lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask), + gfxDrvRGBMaskPos(lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask), + gfxDrvRGBMaskSize(lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask), + gfxDrvRGBMaskPos(lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask), + gfxDrvRGBMaskSize(lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask)); ddraw_device->fullscreen_modes = listAddLast(ddraw_device->fullscreen_modes, listNew(tmpmode)); } return DDENUMRET_OK; } - /*==========================================================================*/ /* Creates a list of available modes on a given DirectDraw device */ /* Called on emulator startup */ @@ -812,11 +789,7 @@ bool gfxDrvDDrawInitializeFullScreenModeInformation(gfx_drv_ddraw_device *ddraw_ bool result; ddraw_device->fullscreen_modes = nullptr; - HRESULT err = IDirectDraw2_EnumDisplayModes(ddraw_device->lpDD2, - DDEDM_REFRESHRATES, - nullptr, - (LPVOID)ddraw_device, - gfxDrvDDrawEnumerateFullScreenMode); + HRESULT err = IDirectDraw2_EnumDisplayModes(ddraw_device->lpDD2, DDEDM_REFRESHRATES, nullptr, (LPVOID)ddraw_device, gfxDrvDDrawEnumerateFullScreenMode); if (err != DD_OK) { gfxDrvDDrawFailure("gfxDrvDDrawModeInformationInitialize(): ", err); @@ -839,7 +812,6 @@ bool gfxDrvDDrawInitializeFullScreenModeInformation(gfx_drv_ddraw_device *ddraw_ return result; } - /*==========================================================================*/ /* Releases the list of available modes */ /* Called on emulator shutdown */ @@ -851,7 +823,6 @@ void gfxDrvDDrawReleaseFullScreenModeInformation(gfx_drv_ddraw_device *ddraw_dev ddraw_device->fullscreen_modes = nullptr; } - /*==========================================================================*/ /* Set cooperative level */ /*==========================================================================*/ @@ -866,7 +837,6 @@ bool gfxDrvDDrawSetCooperativeLevelNormal(gfx_drv_ddraw_device *ddraw_device) return (err == DD_OK); } - bool gfxDrvDDrawSetCooperativeLevelExclusive(gfx_drv_ddraw_device *ddraw_device) { HRESULT err = IDirectDraw2_SetCooperativeLevel(ddraw_device->lpDD2, gfxDrvCommon->GetHWND(), DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE); @@ -877,7 +847,6 @@ bool gfxDrvDDrawSetCooperativeLevelExclusive(gfx_drv_ddraw_device *ddraw_device) return (err == DD_OK); } - bool gfxDrvDDrawSetCooperativeLevel(gfx_drv_ddraw_device *ddraw_device) { if (ddraw_device->windowed) @@ -887,7 +856,6 @@ bool gfxDrvDDrawSetCooperativeLevel(gfx_drv_ddraw_device *ddraw_device) return gfxDrvDDrawSetCooperativeLevelExclusive(ddraw_device); } - /*==========================================================================*/ /* Clear surface with blitter */ /*==========================================================================*/ @@ -907,7 +875,6 @@ void gfxDrvDDrawSurfaceClear(gfx_drv_ddraw_device *ddraw_device, LPDIRECTDRAWSUR fellowAddLog("gfxdrv: Clearing surface\n"); } - /*==========================================================================*/ /* Restore a surface, do some additional cleaning up. */ /*==========================================================================*/ @@ -944,7 +911,7 @@ HRESULT gfxDrvDDrawSurfaceRestore(gfx_drv_ddraw_device *ddraw_device, LPDIRECTDR return err; } -void gfxDrvDDrawCalculateDestinationRectangle(uint32_t output_width, uint32_t output_height, gfx_drv_ddraw_device *ddraw_device, RECT& dstwin) +void gfxDrvDDrawCalculateDestinationRectangle(uint32_t output_width, uint32_t output_height, gfx_drv_ddraw_device *ddraw_device, RECT &dstwin) { int upscaled_clip_width = 0; int upscaled_clip_height = 0; @@ -953,8 +920,8 @@ void gfxDrvDDrawCalculateDestinationRectangle(uint32_t output_width, uint32_t ou { // Fixed scaling float upscale_factor = static_cast(drawGetOutputScaleFactor()) / static_cast(drawGetInternalScaleFactor()); - upscaled_clip_width = static_cast(drawGetBufferClipWidthAsFloat()*upscale_factor); - upscaled_clip_height = static_cast(drawGetBufferClipHeightAsFloat()*upscale_factor); + upscaled_clip_width = static_cast(drawGetBufferClipWidthAsFloat() * upscale_factor); + upscaled_clip_height = static_cast(drawGetBufferClipHeightAsFloat() * upscale_factor); } else { @@ -1047,7 +1014,7 @@ void gfxDrvDDrawSurfaceBlit(gfx_drv_ddraw_device *ddraw_device) gfxDrvDDrawCalculateDestinationRectangle(gfx_drv_output_width, gfx_drv_output_height, ddraw_device, dstwin); /* This can fail when a surface is lost */ - HRESULT err = IDirectDrawSurface_Blt(lpDDSDestination, &dstwin, ddraw_device->lpDDSSecondary, &srcwin, DDBLT_ASYNC, &bltfx); + HRESULT err = IDirectDrawSurface_Blt(lpDDSDestination, &dstwin, ddraw_device->lpDDSSecondary, &srcwin, DDBLT_ASYNC, &bltfx); if (err != DD_OK) { gfxDrvDDrawFailure("gfxDrvDDrawSurfaceBlit(): (Blt failed) ", err); @@ -1080,7 +1047,6 @@ void gfxDrvDDrawSurfaceBlit(gfx_drv_ddraw_device *ddraw_device) } } - /*==========================================================================*/ /* Release the surfaces */ /*==========================================================================*/ @@ -1137,9 +1103,9 @@ uint32_t gfxDrvDDrawVideomemLocationFlags(uint32_t pass) { switch (pass) { - case 0: return DDSCAPS_VIDEOMEMORY; /* Local videomemory (default oncard) */ + case 0: return DDSCAPS_VIDEOMEMORY; /* Local videomemory (default oncard) */ case 1: return DDSCAPS_NONLOCALVIDMEM | DDSCAPS_VIDEOMEMORY; /* Shared videomemory */ - case 2: return DDSCAPS_SYSTEMMEMORY; /* Plain memory */ + case 2: return DDSCAPS_SYSTEMMEMORY; /* Plain memory */ } return 0; } @@ -1168,10 +1134,7 @@ bool gfxDrvDDrawCreateSecondaryOffscreenSurface(gfx_drv_ddraw_device *ddraw_devi else { buffer_allocated = true; - fellowAddLog("gfxdrv: Allocated second offscreen surface in %s (%d, %d)\n", - gfxDrvDDrawVideomemLocationStr(pass), - draw_buffer_info.width, - draw_buffer_info.height); + fellowAddLog("gfxdrv: Allocated second offscreen surface in %s (%d, %d)\n", gfxDrvDDrawVideomemLocationStr(pass), draw_buffer_info.width, draw_buffer_info.height); gfxDrvDDrawSurfaceClear(ddraw_device, ddraw_device->lpDDSSecondary); result = true; } @@ -1286,16 +1249,21 @@ uint32_t gfxDrvDDrawSurfacesInitialize(gfx_drv_ddraw_device *ddraw_device) else { /* Examine pixelformat */ - if (((ddpf.dwFlags & DDPF_RGB) && - ((ddpf.dwRGBBitCount == 16) || - (ddpf.dwRGBBitCount == 24) || - (ddpf.dwRGBBitCount == 32)))) + if (((ddpf.dwFlags & DDPF_RGB) && ((ddpf.dwRGBBitCount == 16) || (ddpf.dwRGBBitCount == 24) || (ddpf.dwRGBBitCount == 32)))) { char pixelFormats[512]; gfxDrvDDrawPrintPixelFlags(ddpf.dwFlags, pixelFormats); - fellowAddLog("gfxdrv: Surface has pixelformat flags %s (%.8X), (%d, %d, %d, %d, %d, %d, %d)\n", - pixelFormats, ddpf.dwFlags, ddpf.dwRGBBitCount, gfxDrvRGBMaskPos(ddpf.dwRBitMask), gfxDrvRGBMaskSize(ddpf.dwRBitMask), gfxDrvRGBMaskPos(ddpf.dwGBitMask), - gfxDrvRGBMaskSize(ddpf.dwGBitMask), gfxDrvRGBMaskPos(ddpf.dwBBitMask), gfxDrvRGBMaskSize(ddpf.dwBBitMask)); + fellowAddLog( + "gfxdrv: Surface has pixelformat flags %s (%.8X), (%d, %d, %d, %d, %d, %d, %d)\n", + pixelFormats, + ddpf.dwFlags, + ddpf.dwRGBBitCount, + gfxDrvRGBMaskPos(ddpf.dwRBitMask), + gfxDrvRGBMaskSize(ddpf.dwRBitMask), + gfxDrvRGBMaskPos(ddpf.dwGBitMask), + gfxDrvRGBMaskSize(ddpf.dwGBitMask), + gfxDrvRGBMaskPos(ddpf.dwBBitMask), + gfxDrvRGBMaskSize(ddpf.dwBBitMask)); draw_buffer_info.bits = ddpf.dwRGBBitCount; draw_buffer_info.redpos = gfxDrvRGBMaskPos(ddpf.dwRBitMask); @@ -1437,10 +1405,9 @@ uint8_t *gfxDrvDDrawSurfaceLock(gfx_drv_ddraw_device *ddraw_device, uint32_t *pi } } *pitch = lpDDSD->lPitch; - return (uint8_t*)lpDDSD->lpSurface; + return (uint8_t *)lpDDSD->lpSurface; } - /*==========================================================================*/ /* Unlock the primary surface */ /*==========================================================================*/ @@ -1458,18 +1425,17 @@ void gfxDrvDDrawSurfaceUnlock(gfx_drv_ddraw_device *ddraw_device) } } - /*==========================================================================*/ /* Flip to next buffer */ /*==========================================================================*/ void gfxDrvDDrawFlip() { - if (gfx_drv_ddraw_device_current->use_blitter) /* Blit secondary buffer to primary */ + if (gfx_drv_ddraw_device_current->use_blitter) /* Blit secondary buffer to primary */ { gfxDrvDDrawSurfaceBlit(gfx_drv_ddraw_device_current); } - if (gfx_drv_ddraw_device_current->buffercount > 1) /* Flip buffer if there are several */ + if (gfx_drv_ddraw_device_current->buffercount > 1) /* Flip buffer if there are several */ { HRESULT err = IDirectDrawSurface_Flip(gfx_drv_ddraw_device_current->lpDDSPrimary, nullptr, DDFLIP_WAIT); if (err != DD_OK) @@ -1479,7 +1445,6 @@ void gfxDrvDDrawFlip() } } - /*==========================================================================*/ /* Set specified mode */ /* In windowed mode, we don't set a mode, but instead queries the pixel- */ @@ -1498,7 +1463,7 @@ unsigned int gfxDrvDDrawSetMode(gfx_drv_ddraw_device *ddraw_device) if (!ddraw_device->windowed) { - gfx_drv_ddraw_fullscreen_mode *mode = static_cast(listNode(listIndex(ddraw_device->fullscreen_modes, ddraw_device->drawmode->id))); + gfx_drv_ddraw_fullscreen_mode *mode = static_cast(listNode(listIndex(ddraw_device->fullscreen_modes, ddraw_device->drawmode->id))); HRESULT err = IDirectDraw2_SetDisplayMode(ddraw_device->lpDD2, mode->width, mode->height, mode->depth, mode->refresh, 0); if (err != DD_OK) { @@ -1522,8 +1487,8 @@ unsigned int gfxDrvDDrawSetMode(gfx_drv_ddraw_device *ddraw_device) void gfxDrvDDrawGetBufferInformation(draw_buffer_information *buffer_information) { uint32_t internal_scale_factor = drawGetInternalScaleFactor(); - buffer_information->width = drawGetInternalClip().GetWidth()*internal_scale_factor; - buffer_information->height = drawGetInternalClip().GetHeight()*internal_scale_factor; + buffer_information->width = drawGetInternalClip().GetWidth() * internal_scale_factor; + buffer_information->height = drawGetInternalClip().GetHeight() * internal_scale_factor; // color information set later by the surface init code } @@ -1557,7 +1522,6 @@ bool gfxDrvDDrawInitialize() return result; } - /*==========================================================================*/ /* Release any resources allocated by gfxDrvDDrawInitialize */ /* Called on emulator shutdown */ @@ -1574,7 +1538,6 @@ void gfxDrvDDrawRelease() /* Functions below are the actual "graphics driver API" */ /*==========================================================================*/ - void gfxDrvDDrawClearCurrentBuffer() { LPDIRECTDRAWSURFACE lpDDS; @@ -1616,7 +1579,6 @@ uint8_t *gfxDrvDDrawValidateBufferPointer() return buffer; } - /*==========================================================================*/ /* Unlocks surface */ /*==========================================================================*/ @@ -1675,18 +1637,18 @@ void gfxDrvDDrawSetMode(draw_mode *dm, bool windowed) /************************************************************************/ /** - * Emulation is starting. - * - * Called on emulation start. - * Subtlety: In exclusive mode, the window that is attached to the device - * appears to become activated, even if it is not shown at the time. - * The WM_ACTIVATE message triggers DirectInput acquisition, which means - * that the DirectInput object needs to have been created at that time. - * Unfortunately, the window must be created as well in order to attach DI - * objects to it. So we create window, create DI objects in between and then - * do the rest of the gfx init. - * That is why gfxDrvEmulationStart is split in two. - ***************************************************************************/ + * Emulation is starting. + * + * Called on emulation start. + * Subtlety: In exclusive mode, the window that is attached to the device + * appears to become activated, even if it is not shown at the time. + * The WM_ACTIVATE message triggers DirectInput acquisition, which means + * that the DirectInput object needs to have been created at that time. + * Unfortunately, the window must be created as well in order to attach DI + * objects to it. So we create window, create DI objects in between and then + * do the rest of the gfx init. + * That is why gfxDrvEmulationStart is split in two. + ***************************************************************************/ bool gfxDrvDDrawEmulationStart(uint32_t maxbuffercount) { @@ -1694,11 +1656,10 @@ bool gfxDrvDDrawEmulationStart(uint32_t maxbuffercount) return true; } - /************************************************************************/ /** -* Emulation is starting, post -***************************************************************************/ + * Emulation is starting, post + ***************************************************************************/ unsigned int gfxDrvDDrawEmulationStartPost() { @@ -1712,7 +1673,6 @@ unsigned int gfxDrvDDrawEmulationStartPost() return buffers; } - /*==========================================================================*/ /* Emulation is stopping, clean up current videomode */ /*==========================================================================*/ @@ -1737,7 +1697,6 @@ bool gfxDrvDDrawStartup() return gfx_drv_ddraw_initialized; } - /*==========================================================================*/ /* Free DDraw resources */ /* Called on emulator shutdown */ @@ -1778,13 +1737,13 @@ bool gfxDrvDDrawSaveScreenshotFromDCArea(HDC hDC, DWORD x, DWORD y, DWORD width, datasize += height * (4 - width * bpp % 4); } - memset((void*)&bfh, 0, sizeof(bfh)); + memset((void *)&bfh, 0, sizeof(bfh)); bfh.bfType = 'B' + ('M' << 8); bfh.bfSize = sizeof(bfh) + sizeof(bih) + datasize; bfh.bfOffBits = sizeof(bfh) + sizeof(bih); - memset((void*)&bih, 0, sizeof(bih)); + memset((void *)&bih, 0, sizeof(bih)); bih.biSize = sizeof(bih); bih.biWidth = width; bih.biHeight = height; @@ -1792,8 +1751,7 @@ bool gfxDrvDDrawSaveScreenshotFromDCArea(HDC hDC, DWORD x, DWORD y, DWORD width, bih.biBitCount = bpp * 8; bih.biCompression = BI_RGB; - bitmap = CreateDIBSection(nullptr, (BITMAPINFO *)&bih, - DIB_RGB_COLORS, &data, nullptr, 0); + bitmap = CreateDIBSection(nullptr, (BITMAPINFO *)&bih, DIB_RGB_COLORS, &data, nullptr, 0); if (!bitmap) goto cleanup; if (!data) goto cleanup; @@ -1810,9 +1768,9 @@ bool gfxDrvDDrawSaveScreenshotFromDCArea(HDC hDC, DWORD x, DWORD y, DWORD width, file = fopen(filename, "wb"); if (!file) goto cleanup; - fwrite((void*)&bfh, sizeof(bfh), 1, file); - fwrite((void*)&bih, sizeof(bih), 1, file); - fwrite((void*)data, 1, datasize, file); + fwrite((void *)&bfh, sizeof(bfh), 1, file); + fwrite((void *)&bih, sizeof(bih), 1, file); + fwrite((void *)data, 1, datasize, file); bSuccess = TRUE; @@ -1822,14 +1780,20 @@ bool gfxDrvDDrawSaveScreenshotFromDCArea(HDC hDC, DWORD x, DWORD y, DWORD width, if (file) fclose(file); if (bitmap) DeleteObject(bitmap); - fellowAddLog("gfxDrvDDrawSaveScreenshotFromDCArea(hDC=0x%x, width=%d, height=%d, bits=%d, filename='%s' %s.\n", - hDC, width, height, bits, filename, bSuccess ? "successful" : "failed"); + fellowAddLog( + "gfxDrvDDrawSaveScreenshotFromDCArea(hDC=0x%x, width=%d, height=%d, bits=%d, filename='%s' %s.\n", + hDC, + width, + height, + bits, + filename, + bSuccess ? "successful" : "failed"); return bSuccess; } -static bool gfxDrvDDrawSaveScreenshotFromSurfaceArea(LPDIRECTDRAWSURFACE surface, - DWORD x, DWORD y, DWORD width, DWORD height, uint32_t lDisplayScale, const char *filename) { +static bool gfxDrvDDrawSaveScreenshotFromSurfaceArea(LPDIRECTDRAWSURFACE surface, DWORD x, DWORD y, DWORD width, DWORD height, uint32_t lDisplayScale, const char *filename) +{ DDSURFACEDESC ddsd; HRESULT hResult = DD_OK; HDC surfDC = nullptr; @@ -1852,13 +1816,14 @@ static bool gfxDrvDDrawSaveScreenshotFromSurfaceArea(LPDIRECTDRAWSURFACE surface return bSuccess; } -bool gfxDrvDDrawSaveScreenshot(const bool bTakeFilteredScreenshot, const char *filename) +bool gfxDrvDDrawSaveScreenshot(const bool bTakeFilteredScreenshot, const char *filename) { bool bResult; DWORD width = 0, height = 0, x = 0, y = 0; uint32_t lDisplayScale; - if (bTakeFilteredScreenshot) { + if (bTakeFilteredScreenshot) + { #ifdef RETRO_PLATFORM if (RP.GetHeadlessMode()) { @@ -1877,12 +1842,13 @@ bool gfxDrvDDrawSaveScreenshot(const bool bTakeFilteredScreenshot, const char *f } bResult = gfxDrvDDrawSaveScreenshotFromSurfaceArea(gfx_drv_ddraw_device_current->lpDDSSecondary, x, y, width, height, lDisplayScale, filename); } - else { + else + { #ifdef RETRO_PLATFORM if (RP.GetHeadlessMode()) { - //width and height in RP mode are sized for maximum scale factor - // use harcoded RetroPlatform max PAL dimensions from WinUAE + // width and height in RP mode are sized for maximum scale factor + // use harcoded RetroPlatform max PAL dimensions from WinUAE width = RETRO_PLATFORM_MAX_PAL_LORES_WIDTH * 2; height = RETRO_PLATFORM_MAX_PAL_LORES_HEIGHT * 2; } @@ -1895,8 +1861,7 @@ bool gfxDrvDDrawSaveScreenshot(const bool bTakeFilteredScreenshot, const char *f bResult = gfxDrvDDrawSaveScreenshotFromSurfaceArea(gfx_drv_ddraw_device_current->lpDDSSecondary, x, y, width, height, 1, filename); } - fellowAddLog("gfxDrvDDrawSaveScreenshot(filtered=%d, filename='%s') %s.\n", bTakeFilteredScreenshot, filename, - bResult ? "successful" : "failed"); + fellowAddLog("gfxDrvDDrawSaveScreenshot(filtered=%d, filename='%s') %s.\n", bTakeFilteredScreenshot, filename, bResult ? "successful" : "failed"); return bResult; } \ No newline at end of file diff --git a/fellow/SRC/WinFellow/graphics/CycleExactSprites.cpp b/fellow/SRC/WinFellow/graphics/CycleExactSprites.cpp index 1bb54f6d..16a61025 100644 --- a/fellow/SRC/WinFellow/graphics/CycleExactSprites.cpp +++ b/fellow/SRC/WinFellow/graphics/CycleExactSprites.cpp @@ -34,7 +34,7 @@ #include "SpriteP2CDecoder.h" #include "SpriteMerger.h" #include "CycleExactSprites.h" -#include "CoreHost.h" +#include "VirtualHost/Core.h" #include "Graphics.h" using namespace CustomChipset; @@ -73,25 +73,25 @@ void CycleExactSprites::Arm(uint32_t sprite_number) void CycleExactSprites::MergeLores(uint32_t spriteNo, uint32_t source_pixel_index, uint32_t pixel_index, uint32_t pixel_count) { - uint8_t *playfield = &GraphicsContext.Planar2ChunkyDecoder.GetOddPlayfield()[pixel_index]; - uint8_t *sprite_data = &SpriteState[spriteNo].dat_decoded.barray[source_pixel_index]; + uint8_t* playfield = &GraphicsContext.Planar2ChunkyDecoder.GetOddPlayfield()[pixel_index]; + uint8_t* sprite_data = &SpriteState[spriteNo].dat_decoded.barray[source_pixel_index]; SpriteMerger::MergeLores(spriteNo, playfield, sprite_data, pixel_count); } void CycleExactSprites::MergeHires(uint32_t spriteNo, uint32_t source_pixel_index, uint32_t pixel_index, uint32_t pixel_count) { - uint8_t *playfield = &GraphicsContext.Planar2ChunkyDecoder.GetOddPlayfield()[pixel_index]; - uint8_t *sprite_data = &SpriteState[spriteNo].dat_decoded.barray[source_pixel_index]; + uint8_t* playfield = &GraphicsContext.Planar2ChunkyDecoder.GetOddPlayfield()[pixel_index]; + uint8_t* sprite_data = &SpriteState[spriteNo].dat_decoded.barray[source_pixel_index]; SpriteMerger::MergeHires(spriteNo, playfield, sprite_data, pixel_count); } void CycleExactSprites::MergeHam(uint32_t spriteNo, uint32_t source_pixel_index, uint32_t pixel_index, uint32_t pixel_count) { - uint8_t *playfield = &GraphicsContext.Planar2ChunkyDecoder.GetOddPlayfield()[pixel_index]; - uint8_t *ham_sprites_playfield = &GraphicsContext.Planar2ChunkyDecoder.GetHamSpritesPlayfield()[pixel_index]; - uint8_t *sprite_data = &SpriteState[spriteNo].dat_decoded.barray[source_pixel_index]; + uint8_t* playfield = &GraphicsContext.Planar2ChunkyDecoder.GetOddPlayfield()[pixel_index]; + uint8_t* ham_sprites_playfield = &GraphicsContext.Planar2ChunkyDecoder.GetHamSpritesPlayfield()[pixel_index]; + uint8_t* sprite_data = &SpriteState[spriteNo].dat_decoded.barray[source_pixel_index]; SpriteMerger::MergeHam(spriteNo, playfield, ham_sprites_playfield, sprite_data, pixel_count); } @@ -141,11 +141,11 @@ void CycleExactSprites::OutputSprite(uint32_t spriteNo, uint32_t startCylinder, if (_core.RegisterUtility.IsHiresEnabled()) { - pixel_index = pixel_index*2; // Hires coordinates + pixel_index = pixel_index * 2; // Hires coordinates } Merge(spriteNo, SpriteState[spriteNo].pixels_output, pixel_index, pixel_count); - SpriteState[spriteNo].pixels_output += pixel_count; + SpriteState[spriteNo].pixels_output += pixel_count; SpriteState[spriteNo].serializing = (SpriteState[spriteNo].pixels_output < 16); } } @@ -227,14 +227,14 @@ void CycleExactSprites::ReadControlWords(uint32_t spriteNo) { uint16_t pos = ReadWord(spriteNo); uint16_t ctl = ReadWord(spriteNo); - wsprxpos(pos, 0x140 + spriteNo*8); - wsprxctl(ctl, 0x142 + spriteNo*8); + wsprxpos(pos, 0x140 + spriteNo * 8); + wsprxctl(ctl, 0x142 + spriteNo * 8); } void CycleExactSprites::ReadDataWords(uint32_t spriteNo) { - wsprxdatb(ReadWord(spriteNo), 0x146 + spriteNo*8); - wsprxdata(ReadWord(spriteNo), 0x144 + spriteNo*8); + wsprxdatb(ReadWord(spriteNo), 0x146 + spriteNo * 8); + wsprxdata(ReadWord(spriteNo), 0x144 + spriteNo * 8); } bool CycleExactSprites::IsFirstLine(uint32_t spriteNo, uint32_t rasterY) @@ -258,7 +258,7 @@ void CycleExactSprites::DMAReadControl(uint32_t spriteNo, uint32_t rasterY) if (IsFirstLine(spriteNo, rasterY)) { - SpriteState[spriteNo].DMAState.state = SPRITE_DMA_STATE_READ_DATA; + SpriteState[spriteNo].DMAState.state = SPRITE_DMA_STATE_READ_DATA; } else { @@ -303,7 +303,7 @@ void CycleExactSprites::DMAReadData(uint32_t spriteNo, uint32_t rasterY) } void CycleExactSprites::DMAHandler(uint32_t rasterY) -{ +{ if ((dmacon & 0x20) == 0 || rasterY < 0x18) { return; @@ -312,19 +312,19 @@ void CycleExactSprites::DMAHandler(uint32_t rasterY) rasterY++; // Do DMA for next line uint32_t spriteNo = 0; - while (spriteNo < 8) + while (spriteNo < 8) { - switch(SpriteState[spriteNo].DMAState.state) + switch (SpriteState[spriteNo].DMAState.state) { - case SPRITE_DMA_STATE_READ_CONTROL: - DMAReadControl(spriteNo, rasterY); - break; - case SPRITE_DMA_STATE_WAITING_FOR_FIRST_LINE: - DMAWaitingForFirstLine(spriteNo, rasterY); - break; - case SPRITE_DMA_STATE_READ_DATA: - DMAReadData(spriteNo, rasterY); - break; + case SPRITE_DMA_STATE_READ_CONTROL: + DMAReadControl(spriteNo, rasterY); + break; + case SPRITE_DMA_STATE_WAITING_FOR_FIRST_LINE: + DMAWaitingForFirstLine(spriteNo, rasterY); + break; + case SPRITE_DMA_STATE_READ_DATA: + DMAReadData(spriteNo, rasterY); + break; } spriteNo++; } @@ -351,7 +351,7 @@ void CycleExactSprites::EndOfFrame() void CycleExactSprites::ClearState() { - memset(SpriteState, 0, sizeof(Sprite)*8); + memset(SpriteState, 0, sizeof(Sprite) * 8); } void CycleExactSprites::HardReset() diff --git a/fellow/SRC/WinFellow/graphics/CycleExactSprites.h b/fellow/SRC/WinFellow/graphics/CycleExactSprites.h index dd0facce..1e203d77 100644 --- a/fellow/SRC/WinFellow/graphics/CycleExactSprites.h +++ b/fellow/SRC/WinFellow/graphics/CycleExactSprites.h @@ -26,7 +26,7 @@ #include "DEFS.H" #include "SPRITE.H" -#include "CoreHost.h" +#include "VirtualHost/Core.h" typedef enum SpriteDMAStates_ { diff --git a/fellow/SRC/WinFellow/graphics/Planar2ChunkyDecoder.h b/fellow/SRC/WinFellow/graphics/Planar2ChunkyDecoder.h index 0bfa3b66..1bc88156 100644 --- a/fellow/SRC/WinFellow/graphics/Planar2ChunkyDecoder.h +++ b/fellow/SRC/WinFellow/graphics/Planar2ChunkyDecoder.h @@ -25,7 +25,7 @@ /*=========================================================================*/ #include "DEFS.H" -#include "CoreHost.h" +#include "VirtualHost/Core.h" using namespace CustomChipset; @@ -44,8 +44,8 @@ class Planar2ChunkyDecoder ByteLongArrayUnion _playfield_even; ByteLongArrayUnion _playfield_ham_sprites; - uint32_t *GetEvenPlayfieldUint32Ptr(); - uint32_t *GetOddPlayfieldUint32Ptr(); + uint32_t* GetEvenPlayfieldUint32Ptr(); + uint32_t* GetOddPlayfieldUint32Ptr(); uint32_t P2COdd1(uint32_t dat1, uint32_t dat3, uint32_t dat5); uint32_t P2COdd2(uint32_t dat1, uint32_t dat3, uint32_t dat5); @@ -62,9 +62,9 @@ class Planar2ChunkyDecoder void P2CNext8PixelsDual(uint32_t dat1, uint32_t dat2, uint32_t dat3, uint32_t dat4, uint32_t dat5, uint32_t dat6); public: - uint8_t *GetOddPlayfield(); - uint8_t *GetEvenPlayfield(); - uint8_t *GetHamSpritesPlayfield(); + uint8_t* GetOddPlayfield(); + uint8_t* GetEvenPlayfield(); + uint8_t* GetHamSpritesPlayfield(); uint32_t GetBatchSize(); void NewBatch();