shithub: ft2-clone

Download patch

ref: ab964468d1763728715199d78def5e9382456690
parent: 16c6ce7b7f1d8fc8e7a06f5e34510f129f209c68
author: Olav Sørensen <olav.sorensen@live.no>
date: Thu Nov 19 16:10:48 EST 2020

Pushed v1.41 code

- Code refactoring and code cleanup
- Fixed minor BPM duration issues when rendering song to WAV
- Fixed some mouse problems in fullscreen mode on multi-monitor setups
- Bugfix: Properly change pattern length after loading .xp pattern files (FT2 doesn't do this, but I think this makes sense!)

--- a/src/ft2_about.c
+++ b/src/ft2_about.c
@@ -7,7 +7,7 @@
 #include "ft2_video.h"
 #include "ft2_structs.h"
 
-#define NUM_STARS 1500
+#define NUM_STARS 1750
 #define ABOUT_SCREEN_W 626
 #define ABOUT_SCREEN_H 167
 #define ABOUT_LOGO_W 449
@@ -49,13 +49,18 @@
 
 static void rotateMatrix(void)
 {
-	const float sa = sinf(rotation.x * f2pi);
-	const float ca = cosf(rotation.x * f2pi);
-	const float sb = sinf(rotation.y * f2pi);
-	const float cb = cosf(rotation.y * f2pi);
-	const float sc = sinf(rotation.z * f2pi);
-	const float cc = cosf(rotation.z * f2pi);
+	const float xx = rotation.x * f2pi;
+	const float sa = sinf(xx);
+	const float ca = cosf(xx);
 
+	const float yy = rotation.y * f2pi;
+	const float sb = sinf(yy);
+	const float cb = cosf(yy);
+
+	const float zz = rotation.z * f2pi;
+	const float sc = sinf(zz);
+	const float cc = cosf(zz);
+
 	// x
 	matrix.x.x = (ca * cc) + (sc * sa * sb);
 	matrix.y.x = sa * cb;
@@ -79,9 +84,9 @@
 	vector_t *s = starPoints;
 	for (int32_t i = 0; i < NUM_STARS; i++, s++)
 	{
-		s->x = (float)(random32() * (1.0f / (UINT32_MAX+1.0f)));
-		s->y = (float)(random32() * (1.0f / (UINT32_MAX+1.0f)));
-		s->z = (float)(random32() * (1.0f / (UINT32_MAX+1.0f)));
+		s->x = (float)(random32() * (1.0 / (UINT32_MAX+1.0)));
+		s->y = (float)(random32() * (1.0 / (UINT32_MAX+1.0)));
+		s->z = (float)(random32() * (1.0 / (UINT32_MAX+1.0)));
 	}
 
 	rotation.x = rotation.y = rotation.z = 0.0f;
@@ -104,10 +109,8 @@
 			lastStarScreenPos[i] = -1;
 		}
 
-		/*
-		star->z += 0.00075f;
+		star->z += 0.00015f;
 		if (star->z >= 0.5f) star->z -= 1.0f;
-		*/
 
 		const float z = (matrix.x.z * star->x) + (matrix.y.z * star->y) + (matrix.z.z * star->z) + 0.5f;
 		if (z <= 0.0f)
@@ -131,24 +134,22 @@
 		screenBufferPos = ((uint32_t)outY * SCREEN_W) + (uint32_t)outX;
 		if ((video.frameBuffer[screenBufferPos] >> 24) == PAL_BCKGRND)
 		{
-			int32_t d = (int32_t)((255.0f - (z * 235.0f)) + 0.5f);
-
-			d = (d * starfieldFade) >> 8;
-			if (d <= 0)
-				continue;
-
+			int32_t d = (int32_t)(z * 255.0f);
 			if (d > 255)
 				d = 255;
 
-			int32_t r = d - 48;
+			d ^= 255;
+			d = (d * starfieldFade) >> 8;
+
+			int32_t r = d - 61;
 			if (r < 0)
 				r = 0;
 
-			int32_t g = d - 14;
+			int32_t g = d - 35;
 			if (g < 0)
 				g = 0;
 
-			int32_t b = d + 72;
+			int32_t b = d + 75;
 			if (b > 255)
 				b = 255;
 
@@ -163,9 +164,9 @@
 	rotateMatrix();
 	starfield();
 
-	rotation.x += 0.00011f;
-	rotation.y += 0.00009f;
-	rotation.z -= 0.00007f;
+	rotation.x += 0.00009f;
+	rotation.y += 0.00007f;
+	rotation.z -= 0.00005f;
 
 	// fade in starfield
 	if (starfieldFade < 256)
--- a/src/ft2_audio.c
+++ b/src/ft2_audio.c
@@ -69,8 +69,6 @@
 
 bool setNewAudioSettings(void) // only call this from the main input/video thread
 {
-	uint32_t stringLen;
-
 	pauseAudio();
 
 	if (!setupAudio(CONFIG_HIDE_ERRORS))
@@ -89,7 +87,7 @@
 				audio.currOutputDevice = NULL;
 			}
 
-			stringLen = (uint32_t)strlen(audio.lastWorkingAudioDeviceName);
+			const uint32_t stringLen = (uint32_t)strlen(audio.lastWorkingAudioDeviceName);
 
 			audio.currOutputDevice = (char *)malloc(stringLen + 2);
 			if (audio.currOutputDevice != NULL)
@@ -286,18 +284,15 @@
 
 static void voiceTrigger(int32_t ch, sampleTyp *s, int32_t position)
 {
-	bool sampleIs16Bit;
-	uint8_t loopType;
-	int32_t length, loopStart, loopLength, loopEnd;
-
 	voice_t *v = &voice[ch];
-	length = s->len;
-	loopStart = s->repS;
-	loopLength = s->repL;
-	loopEnd = s->repS + s->repL;
-	loopType = s->typ & 3;
-	sampleIs16Bit = (s->typ >> 4) & 1;
 
+	int32_t length = s->len;
+	int32_t loopStart = s->repS;
+	int32_t loopLength = s->repL;
+	int32_t loopEnd = s->repS + s->repL;
+	uint8_t loopType = s->typ & 3;
+	const bool sampleIs16Bit = (s->typ >> 4) & 1;
+
 	if (sampleIs16Bit)
 	{
 		assert(!(length & 1));
@@ -324,15 +319,13 @@
 	{
 		v->base16 = (const int16_t *)s->pek;
 		v->revBase16 = &v->base16[loopStart + loopEnd]; // for pingpong loops
-
-		v->leftEdgeTaps16 = s->leftEdgeTapSamples16 + 3;
+		v->leftEdgeTaps16 = s->leftEdgeTapSamples16 + SINC_LEFT_TAPS;
 	}
 	else
 	{
 		v->base8 = s->pek;
 		v->revBase8 = &v->base8[loopStart + loopEnd]; // for pingpong loops
-		v->leftEdgeTaps8 = s->leftEdgeTapSamples8 + 3;
-
+		v->leftEdgeTaps8 = s->leftEdgeTapSamples8 + SINC_LEFT_TAPS;
 	}
 
 	v->hasLooped = false; // for sinc interpolation special case
@@ -368,17 +361,15 @@
 
 void updateVoices(void)
 {
-	uint8_t status;
-	stmTyp *ch;
-	voice_t *v;
+	stmTyp *ch = stm;
+	voice_t *v = voice;
 
-	ch = stm;
-	v = voice;
-
 	for (int32_t i = 0; i < song.antChn; i++, ch++, v++)
 	{
-		status = ch->tmpStatus = ch->status; // (tmpStatus is used for audio/video sync queue)
-		if (status == 0) continue; // nothing to do
+		const uint8_t status = ch->tmpStatus = ch->status; // (tmpStatus is used for audio/video sync queue)
+		if (status == 0)
+			continue;
+
 		ch->status = 0;
 
 		if (status & IS_Vol)
@@ -860,8 +851,6 @@
 {
 	pattSyncData_t pattSyncData;
 	chSyncData_t chSyncData;
-	syncedChannel_t *c;
-	stmTyp *s;
 
 	if (audio.resetSyncTickTimeFlag)
 	{
@@ -887,8 +876,8 @@
 
 	// push channel variables to sync queue
 
-	c = chSyncData.channels;
-	s = stm;
+	syncedChannel_t *c = chSyncData.channels;
+	stmTyp *s = stm;
 
 	for (int32_t i = 0; i < song.antChn; i++, c++, s++)
 	{
@@ -967,7 +956,7 @@
 	// normalize mix buffer and send to audio stream
 	sendAudSamplesFunc(stream, len, pmpChannels);
 
-	(void)userdata; // make compiler not complain
+	(void)userdata;
 }
 
 static bool setupAudioBuffers(void)
@@ -1031,7 +1020,7 @@
 
 static void calcAudioLatencyVars(int32_t audioBufferSize, int32_t audioFreq)
 {
-	double dInt, dFrac;
+	double dInt;
 
 	if (audioFreq == 0)
 		return;
@@ -1038,7 +1027,7 @@
 
 	const double dAudioLatencySecs = audioBufferSize / (double)audioFreq;
 
-	dFrac = modf(dAudioLatencySecs * editor.dPerfFreq, &dInt);
+	double dFrac = modf(dAudioLatencySecs * editor.dPerfFreq, &dInt);
 
 	// integer part
 	audio.audLatencyPerfValInt = (int32_t)dInt;
@@ -1052,8 +1041,6 @@
 
 static void setLastWorkingAudioDevName(void)
 {
-	uint32_t stringLen;
-
 	if (audio.lastWorkingAudioDeviceName != NULL)
 	{
 		free(audio.lastWorkingAudioDeviceName);
@@ -1062,7 +1049,7 @@
 
 	if (audio.currOutputDevice != NULL)
 	{
-		stringLen = (uint32_t)strlen(audio.currOutputDevice);
+		const uint32_t stringLen = (uint32_t)strlen(audio.currOutputDevice);
 
 		audio.lastWorkingAudioDeviceName = (char *)malloc(stringLen + 2);
 		if (audio.lastWorkingAudioDeviceName != NULL)
@@ -1076,8 +1063,6 @@
 
 bool setupAudio(bool showErrorMsg)
 {
-	int8_t newBitDepth;
-	uint16_t configAudioBufSize;
 	SDL_AudioSpec want, have;
 
 	closeAudio();
@@ -1087,7 +1072,7 @@
 
 	// get audio buffer size from config special flags
 
-	configAudioBufSize = 1024;
+	uint16_t configAudioBufSize = 1024;
 	if (config.specialFlags & BUFFSIZE_512)
 		configAudioBufSize = 512;
 	else if (config.specialFlags & BUFFSIZE_2048)
@@ -1150,7 +1135,7 @@
 
 	// set new bit depth flag
 
-	newBitDepth = 16;
+	int8_t newBitDepth = 16;
 	config.specialFlags &= ~BITDEPTH_32;
 	config.specialFlags |=  BITDEPTH_16;
 
--- a/src/ft2_audioselector.c
+++ b/src/ft2_audioselector.c
@@ -17,19 +17,14 @@
 {
 #define MAX_DEV_STR_LEN 256
 
-	const char *devStringTmp;
-	char *devString;
-	uint32_t devStringLen;
-	FILE *f;
-
-	devString = (char *)calloc(MAX_DEV_STR_LEN + 1, sizeof (char));
+	char *devString = (char *)calloc(MAX_DEV_STR_LEN + 1, sizeof (char));
 	if (devString == NULL)
 		return NULL;
 
-	f = UNICHAR_FOPEN(editor.audioDevConfigFileLocation, "r");
+	FILE *f = UNICHAR_FOPEN(editor.audioDevConfigFileLocation, "r");
 	if (f == NULL)
 	{
-		devStringTmp = SDL_GetAudioDeviceName(0, false);
+		const char *devStringTmp = SDL_GetAudioDeviceName(0, false);
 		if (devStringTmp == NULL)
 		{
 			free(devString);
@@ -36,7 +31,7 @@
 			return NULL;
 		}
 
-		devStringLen = (uint32_t)strlen(devStringTmp);
+		const uint32_t devStringLen = (uint32_t)strlen(devStringTmp);
 		if (devStringLen > 0)
 			strncpy(devString, devStringTmp, MAX_DEV_STR_LEN);
 		devString[devStringLen+1] = '\0'; // UTF-8 needs double null termination
@@ -50,7 +45,7 @@
 			return NULL;
 		}
 
-		devStringLen = (uint32_t)strlen(devString);
+		const uint32_t devStringLen = (uint32_t)strlen(devString);
 		if (devString[devStringLen-1] == '\n')
 			devString[devStringLen-1]  = '\0';
 		devString[devStringLen+1] = '\0'; // UTF-8 needs double null termination
@@ -65,19 +60,14 @@
 {
 #define MAX_DEV_STR_LEN 256
 
-	const char *devStringTmp;
-	char *devString;
-	uint32_t devStringLen;
-	FILE *f;
-
-	devString = (char *)calloc(MAX_DEV_STR_LEN + 1, sizeof (char));
+	char *devString = (char *)calloc(MAX_DEV_STR_LEN + 1, sizeof (char));
 	if (devString == NULL)
 		return NULL;
 
-	f = UNICHAR_FOPEN(editor.audioDevConfigFileLocation, "r");
+	FILE *f = UNICHAR_FOPEN(editor.audioDevConfigFileLocation, "r");
 	if (f == NULL)
 	{
-		devStringTmp = SDL_GetAudioDeviceName(0, true);
+		const char *devStringTmp = SDL_GetAudioDeviceName(0, true);
 		if (devStringTmp == NULL)
 		{
 			free(devString);
@@ -84,7 +74,7 @@
 			return NULL;
 		}
 
-		devStringLen = (uint32_t)strlen(devStringTmp);
+		const uint32_t devStringLen = (uint32_t)strlen(devStringTmp);
 		if (devStringLen > 0)
 			strncpy(devString, devStringTmp, MAX_DEV_STR_LEN);
 		devString[devStringLen+1] = '\0'; // UTF-8 needs double null termination
@@ -106,7 +96,7 @@
 			return NULL;
 		}
 
-		devStringLen = (uint32_t)strlen(devString);
+		const uint32_t devStringLen = (uint32_t)strlen(devString);
 		if (devString[devStringLen-1] == '\n')
 			devString[devStringLen-1]  = '\0';
 		devString[devStringLen+1] = '\0'; // UTF-8 needs double null termination
@@ -119,9 +109,7 @@
 
 bool saveAudioDevicesToConfig(const char *outputDevice, const char *inputDevice)
 {
-	FILE *f;
-
-	f = UNICHAR_FOPEN(editor.audioDevConfigFileLocation, "w");
+	FILE *f = UNICHAR_FOPEN(editor.audioDevConfigFileLocation, "w");
 	if (f == NULL)
 		return false;
 
@@ -137,10 +125,6 @@
 
 void drawAudioOutputList(void)
 {
-	char *tmpString;
-	uint16_t y;
-	int32_t deviceEntry;
-
 	clearRect(114, 18, AUDIO_SELECTORS_BOX_WIDTH, 66);
 
 	if (audio.outputDeviceNum == 0)
@@ -151,13 +135,13 @@
 
 	for (int32_t i = 0; i < 6; i++)
 	{
-		deviceEntry = getScrollBarPos(SB_AUDIO_OUTPUT_SCROLL) + i;
+		const int32_t deviceEntry = getScrollBarPos(SB_AUDIO_OUTPUT_SCROLL) + i;
 		if (deviceEntry < audio.outputDeviceNum)
 		{
 			if (audio.outputDeviceNames[deviceEntry] == NULL)
 				continue;
 
-			y = 18 + (uint16_t)(i * 11);
+			const uint16_t y = 18 + (uint16_t)(i * 11);
 
 			if (audio.currOutputDevice != NULL)
 			{
@@ -165,7 +149,7 @@
 					fillRect(114, y, AUDIO_SELECTORS_BOX_WIDTH, 10, PAL_BOXSLCT); // selection background color
 			}
 
-			tmpString = utf8ToCp437(audio.outputDeviceNames[deviceEntry], true);
+			char *tmpString = utf8ToCp437(audio.outputDeviceNames[deviceEntry], true);
 			if (tmpString != NULL)
 			{
 				textOutClipX(114, y, PAL_FORGRND, tmpString, 114 + AUDIO_SELECTORS_BOX_WIDTH);
@@ -177,10 +161,6 @@
 
 void drawAudioInputList(void)
 {
-	char *tmpString;
-	uint16_t y;
-	int32_t deviceEntry;
-
 	clearRect(114, 105, AUDIO_SELECTORS_BOX_WIDTH, 44);
 
 	if (audio.inputDeviceNum == 0)
@@ -191,13 +171,13 @@
 
 	for (int32_t i = 0; i < 4; i++)
 	{
-		deviceEntry = getScrollBarPos(SB_AUDIO_INPUT_SCROLL) + i;
+		const int32_t deviceEntry = getScrollBarPos(SB_AUDIO_INPUT_SCROLL) + i;
 		if (deviceEntry < audio.inputDeviceNum)
 		{
 			if (audio.inputDeviceNames[deviceEntry] == NULL)
 				continue;
 
-			y = 105 + (uint16_t)(i * 11);
+			const uint16_t y = 105 + (uint16_t)(i * 11);
 
 			if (audio.currInputDevice != NULL)
 			{
@@ -205,7 +185,7 @@
 					fillRect(114, y, AUDIO_SELECTORS_BOX_WIDTH, 10, PAL_BOXSLCT); // selection background color
 			}
 
-			tmpString = utf8ToCp437(audio.inputDeviceNames[deviceEntry], true);
+			char *tmpString = utf8ToCp437(audio.inputDeviceNames[deviceEntry], true);
 			if (tmpString != NULL)
 			{
 				textOutClipX(114, y, PAL_FORGRND, tmpString, 114 + AUDIO_SELECTORS_BOX_WIDTH);
@@ -217,15 +197,11 @@
 
 bool testAudioDeviceListsMouseDown(void)
 {
-	char *devString;
-	int32_t mx, my, deviceNum;
-	uint32_t devStringLen;
-
 	if (!ui.configScreenShown || editor.currConfigScreen != CONFIG_SCREEN_IO_DEVICES)
 		return false;
 
-	mx = mouse.x;
-	my = mouse.y;
+	const int32_t mx = mouse.x;
+	const int32_t my = mouse.y;
 
 	if (my < 18 || my > 149 || mx < 114 || mx >= 114+AUDIO_SELECTORS_BOX_WIDTH)
 		return false;
@@ -234,17 +210,17 @@
 	{
 		// output device list
 
-		deviceNum = (int32_t)scrollBars[SB_AUDIO_OUTPUT_SCROLL].pos + ((my - 18) / 11);
+		const int32_t deviceNum = (int32_t)scrollBars[SB_AUDIO_OUTPUT_SCROLL].pos + ((my - 18) / 11);
 		if (audio.outputDeviceNum <= 0 || deviceNum >= audio.outputDeviceNum)
 			return true;
 
-		devString = audio.outputDeviceNames[deviceNum];
+		char *devString = audio.outputDeviceNames[deviceNum];
 		if (devString != NULL && (audio.currOutputDevice == NULL || strcmp(audio.currOutputDevice, devString) != 0))
 		{
 			if (audio.currOutputDevice != NULL)
 				free(audio.currOutputDevice);
 
-			devStringLen = (uint32_t)strlen(devString);
+			const uint32_t devStringLen = (uint32_t)strlen(devString);
 
 			audio.currOutputDevice = (char *)malloc(devStringLen + 2);
 			if (audio.currOutputDevice == NULL)
@@ -266,17 +242,17 @@
 	{
 		// input device list
 
-		deviceNum = (int32_t)scrollBars[SB_AUDIO_INPUT_SCROLL].pos + ((my - 105) / 11);
+		const int32_t deviceNum = (int32_t)scrollBars[SB_AUDIO_INPUT_SCROLL].pos + ((my - 105) / 11);
 		if (audio.inputDeviceNum <= 0 || deviceNum >= audio.inputDeviceNum)
 			return true;
 
-		devString = audio.inputDeviceNames[deviceNum];
+		char *devString = audio.inputDeviceNames[deviceNum];
 		if (devString != NULL && (audio.currInputDevice == NULL || strcmp(audio.currInputDevice, devString) != 0))
 		{
 			if (audio.currInputDevice != NULL)
 				free(audio.currInputDevice);
 
-			devStringLen = (uint32_t)strlen(devString);
+			const uint32_t devStringLen = (uint32_t)strlen(devString);
 
 			audio.currInputDevice = (char *)malloc(devStringLen + 2);
 			if (audio.currInputDevice == NULL)
@@ -297,7 +273,7 @@
 
 void freeAudioDeviceLists(void)
 {
-	for (uint32_t i = 0; i < MAX_AUDIO_DEVICES; i++)
+	for (int32_t i = 0; i < MAX_AUDIO_DEVICES; i++)
 	{
 		if (audio.outputDeviceNames[i] != NULL)
 		{
@@ -347,10 +323,7 @@
 
 void setToDefaultAudioOutputDevice(void)
 {
-	const char *devString;
-	uint32_t stringLen;
-
-	devString = SDL_GetAudioDeviceName(0, false);
+	const char *devString = SDL_GetAudioDeviceName(0, false);
 	if (devString == NULL)
 	{
 		if (audio.currOutputDevice != NULL)
@@ -362,7 +335,7 @@
 		return;
 	}
 
-	stringLen = (uint32_t)strlen(devString);
+	const uint32_t stringLen = (uint32_t)strlen(devString);
 
 	if (audio.currOutputDevice != NULL)
 	{
@@ -382,10 +355,7 @@
 
 void setToDefaultAudioInputDevice(void)
 {
-	const char *devString;
-	uint32_t stringLen;
-
-	devString = SDL_GetAudioDeviceName(0, true);
+	const char *devString = SDL_GetAudioDeviceName(0, true);
 	if (devString == NULL)
 	{
 		if (audio.currInputDevice != NULL)
@@ -397,7 +367,7 @@
 		return;
 	}
 
-	stringLen = (uint32_t)strlen(devString);
+	const uint32_t stringLen = (uint32_t)strlen(devString);
 
 	if (audio.currInputDevice != NULL)
 	{
@@ -417,12 +387,8 @@
 
 void rescanAudioDevices(void)
 {
-	bool listShown;
-	const char *deviceName;
-	uint32_t stringLen;
+	const bool listShown = (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES);
 
-	listShown = (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES);
-
 	freeAudioDeviceLists();
 
 	// GET AUDIO OUTPUT DEVICES
@@ -433,7 +399,7 @@
 
 	for (int32_t i = 0; i < audio.outputDeviceNum; i++)
 	{
-		deviceName = SDL_GetAudioDeviceName(i, false);
+		const char *deviceName = SDL_GetAudioDeviceName(i, false);
 		if (deviceName == NULL)
 		{
 			audio.outputDeviceNum--; // hide device
@@ -440,7 +406,7 @@
 			continue;
 		}
 
-		stringLen = (uint32_t)strlen(deviceName);
+		const uint32_t stringLen = (uint32_t)strlen(deviceName);
 
 		audio.outputDeviceNames[i] = (char *)malloc(stringLen + 2);
 		if (audio.outputDeviceNames[i] == NULL)
@@ -460,7 +426,7 @@
 
 	for (int32_t i = 0; i < audio.inputDeviceNum; i++)
 	{
-		deviceName = SDL_GetAudioDeviceName(i, true);
+		const char *deviceName = SDL_GetAudioDeviceName(i, true);
 		if (deviceName == NULL)
 		{
 			audio.inputDeviceNum--; // hide device
@@ -467,7 +433,7 @@
 			continue;
 		}
 
-		stringLen = (uint32_t)strlen(deviceName);
+		const uint32_t stringLen = (uint32_t)strlen(deviceName);
 
 		audio.inputDeviceNames[i] = (char *)malloc(stringLen + 2);
 		if (audio.inputDeviceNames[i] == NULL)
@@ -517,16 +483,16 @@
 
 void sbAudOutputSetPos(uint32_t pos)
 {
-	(void)pos;
-
 	if (ui.configScreenShown && (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES))
 		drawAudioOutputList();
+
+	(void)pos;
 }
 
 void sbAudInputSetPos(uint32_t pos)
 {
-	(void)pos;
-
 	if (ui.configScreenShown && (editor.currConfigScreen == CONFIG_SCREEN_IO_DEVICES))
 		drawAudioInputList();
+
+	(void)pos;
 }
--- a/src/ft2_bmp.c
+++ b/src/ft2_bmp.c
@@ -140,34 +140,32 @@
 
 static uint32_t *loadBMPTo32Bit(const uint8_t *src)
 {
-	const uint8_t *pData, *src8;
-	int32_t len, byte, palIdx, i, x , y, lineEnd, palEntries, colorsInBitmap;
-	uint32_t *outData, *dst32, *tmp32, color, color2, pal[256];
-	bmpHeader_t *hdr;
+	int32_t len, byte, palIdx;
+	uint32_t *tmp32, color, color2, pal[256];
 
-	hdr = (bmpHeader_t *)&src[2];
-	pData = &src[hdr->bfOffBits];
-	colorsInBitmap = 1 << hdr->biBitCount;
+	bmpHeader_t *hdr = (bmpHeader_t *)&src[2];
+	const uint8_t *pData = &src[hdr->bfOffBits];
+	const int32_t colorsInBitmap = 1 << hdr->biBitCount;
 
 	if (hdr->biCompression == COMP_RGB || hdr->biClrUsed > 256 || colorsInBitmap > 256)
 		return NULL;
 
-	outData = (uint32_t *)malloc(hdr->biWidth * hdr->biHeight * sizeof (uint32_t));
+	uint32_t *outData = (uint32_t *)malloc(hdr->biWidth * hdr->biHeight * sizeof (uint32_t));
 	if (outData == NULL)
 		return NULL;
 
 	// pre-fill image with first palette color
-	palEntries = hdr->biClrUsed == 0 ? colorsInBitmap : hdr->biClrUsed;
+	const int32_t palEntries = hdr->biClrUsed == 0 ? colorsInBitmap : hdr->biClrUsed;
 	memcpy(pal, &src[0x36], palEntries * sizeof (uint32_t));
 
-	for (i = 0; i < hdr->biWidth * hdr->biHeight; i++)
+	for (int32_t i = 0; i < hdr->biWidth * hdr->biHeight; i++)
 		outData[i] = pal[0];
 
-	lineEnd = hdr->biWidth;
-	src8 = pData;
-	dst32 = outData;
-	x = 0;
-	y = hdr->biHeight - 1;
+	const int32_t lineEnd = hdr->biWidth;
+	const uint8_t *src8 = pData;
+	uint32_t *dst32 = outData;
+	int32_t x = 0;
+	int32_t y = hdr->biHeight - 1;
 
 	while (true)
 	{
@@ -194,7 +192,7 @@
 				if (hdr->biCompression == COMP_RLE8)
 				{
 					tmp32 = &dst32[(y * hdr->biWidth) + x];
-					for (i = 0; i < byte; i++)
+					for (int32_t i = 0; i < byte; i++)
 						*tmp32++ = pal[*src8++];
 
 					if (byte & 1)
@@ -207,7 +205,7 @@
 
 					len = byte >> 1;
 					tmp32 = &dst32[y * hdr->biWidth];
-					for (i = 0; i < len; i++)
+					for (int32_t i = 0; i < len; i++)
 					{
 						palIdx = *src8++;
 						tmp32[x++] = pal[palIdx >> 4];
@@ -227,7 +225,7 @@
 			{
 				color = pal[palIdx];
 				tmp32 = &dst32[(y * hdr->biWidth) + x];
-				for (i = 0; i < byte; i++)
+				for (int32_t i = 0; i < byte; i++)
 					*tmp32++ = color;
 
 				x += byte;
@@ -239,7 +237,7 @@
 
 				len = byte >> 1;
 				tmp32 = &dst32[y * hdr->biWidth];
-				for (i = 0; i < len; i++)
+				for (int32_t i = 0; i < len; i++)
 				{
 					tmp32[x++] = color;
 					if (x < lineEnd) tmp32[x++] = color2;
@@ -253,24 +251,22 @@
 
 static uint8_t *loadBMPTo1Bit(const uint8_t *src) // supports 4-bit RLE only
 {
-	const uint8_t *pData, *src8;
-	uint8_t palIdx, color, color2, *outData, *dst8, *tmp8;
-	int32_t len, byte, i, x , y, lineEnd, colorsInBitmap, palEntries;
+	uint8_t palIdx, color, color2, *tmp8;
+	int32_t len, byte, i;
 	uint32_t pal[16];
-	bmpHeader_t *hdr;
 
-	hdr = (bmpHeader_t *)&src[2];
-	pData = &src[hdr->bfOffBits];
-	colorsInBitmap = 1 << hdr->biBitCount;
+	bmpHeader_t *hdr = (bmpHeader_t *)&src[2];
+	const uint8_t *pData = &src[hdr->bfOffBits];
+	const int32_t colorsInBitmap = 1 << hdr->biBitCount;
 
 	if (hdr->biCompression != COMP_RLE4 || hdr->biClrUsed > 16 || colorsInBitmap > 16)
 		return NULL;
 
-	outData = (uint8_t *)malloc(hdr->biWidth * hdr->biHeight * sizeof (uint8_t));
+	uint8_t *outData = (uint8_t *)malloc(hdr->biWidth * hdr->biHeight * sizeof (uint8_t));
 	if (outData == NULL)
 		return NULL;
 
-	palEntries = hdr->biClrUsed == 0 ? colorsInBitmap : hdr->biClrUsed;
+	const int32_t palEntries = hdr->biClrUsed == 0 ? colorsInBitmap : hdr->biClrUsed;
 	memcpy(pal, &src[0x36], palEntries * sizeof (uint32_t));
 
 	// pre-fill image with first palette color
@@ -278,11 +274,11 @@
 	for (i = 0; i < hdr->biWidth * hdr->biHeight; i++)
 		outData[i] = color;
 
-	lineEnd = hdr->biWidth;
-	src8 = pData;
-	dst8 = outData;
-	x = 0;
-	y = hdr->biHeight - 1;
+	const int32_t lineEnd = hdr->biWidth;
+	const uint8_t *src8 = pData;
+	uint8_t *dst8 = outData;
+	int32_t x = 0;
+	int32_t y = hdr->biHeight - 1;
 
 	while (true)
 	{
@@ -341,24 +337,22 @@
 
 static uint8_t *loadBMPTo4BitPal(const uint8_t *src) // supports 4-bit RLE only
 {
-	const uint8_t *pData, *src8;
-	uint8_t palIdx, *outData, *dst8, *tmp8, pal1, pal2;
-	int32_t len, byte, i, x , y, lineEnd, colorsInBitmap, palEntries;
+	uint8_t palIdx, *tmp8, pal1, pal2;
+	int32_t len, byte, i;
 	uint32_t pal[16];
-	bmpHeader_t *hdr;
 
-	hdr = (bmpHeader_t *)&src[2];
-	pData = &src[hdr->bfOffBits];
-	colorsInBitmap = 1 << hdr->biBitCount;
+	bmpHeader_t *hdr = (bmpHeader_t *)&src[2];
+	const uint8_t *pData = &src[hdr->bfOffBits];
+	const int32_t colorsInBitmap = 1 << hdr->biBitCount;
 
 	if (hdr->biCompression != COMP_RLE4 || hdr->biClrUsed > 16 || colorsInBitmap > 16)
 		return NULL;
 
-	outData = (uint8_t *)malloc(hdr->biWidth * hdr->biHeight * sizeof (uint8_t));
+	uint8_t *outData = (uint8_t *)malloc(hdr->biWidth * hdr->biHeight * sizeof (uint8_t));
 	if (outData == NULL)
 		return NULL;
 
-	palEntries = hdr->biClrUsed == 0 ? colorsInBitmap : hdr->biClrUsed;
+	const int32_t palEntries = hdr->biClrUsed == 0 ? colorsInBitmap : hdr->biClrUsed;
 	memcpy(pal, &src[0x36], palEntries * sizeof (uint32_t));
 
 	// pre-fill image with first palette color
@@ -366,11 +360,11 @@
 	for (i = 0; i < hdr->biWidth * hdr->biHeight; i++)
 		outData[i] = palIdx;
 
-	lineEnd = hdr->biWidth;
-	src8 = pData;
-	dst8 = outData;
-	x = 0;
-	y = hdr->biHeight - 1;
+	const int32_t lineEnd = hdr->biWidth;
+	const uint8_t *src8 = pData;
+	uint8_t *dst8 = outData;
+	int32_t x = 0;
+	int32_t y = hdr->biHeight - 1;
 
 	while (true)
 	{
--- a/src/ft2_checkboxes.c
+++ b/src/ft2_checkboxes.c
@@ -116,11 +116,10 @@
 
 void drawCheckBox(uint16_t checkBoxID)
 {
-	checkBox_t *checkBox;
 	const uint8_t *gfxPtr;
 
 	assert(checkBoxID < NUM_CHECKBOXES);
-	checkBox = &checkBoxes[checkBoxID];
+	checkBox_t *checkBox = &checkBoxes[checkBoxID];
 	if (!checkBox->visible)
 		return;
 
@@ -154,10 +153,8 @@
 
 void handleCheckBoxesWhileMouseDown(void)
 {
-	checkBox_t *checkBox;
-
 	assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_CHECKBOXES);
-	checkBox = &checkBoxes[mouse.lastUsedObjectID];
+	checkBox_t *checkBox = &checkBoxes[mouse.lastUsedObjectID];
 	if (!checkBox->visible)
 		return;
 
@@ -180,7 +177,6 @@
 bool testCheckBoxMouseDown(void)
 {
 	uint16_t start, end;
-	checkBox_t *checkBox;
 
 	if (ui.sysReqShown)
 	{
@@ -194,9 +190,9 @@
 		end = NUM_CHECKBOXES;
 	}
 
-	for (uint16_t i = start; i < end; i++)
+	checkBox_t *checkBox = &checkBoxes[start];
+	for (uint16_t i = start; i < end; i++, checkBox++)
 	{
-		checkBox = &checkBoxes[i];
 		if (!checkBox->visible)
 			continue;
 
@@ -216,13 +212,11 @@
 
 void testCheckBoxMouseRelease(void)
 {
-	checkBox_t *checkBox;
-
 	if (mouse.lastUsedObjectType != OBJECT_CHECKBOX || mouse.lastUsedObjectID == OBJECT_ID_NONE)
 		return;
 
 	assert(mouse.lastUsedObjectID < NUM_CHECKBOXES);
-	checkBox = &checkBoxes[mouse.lastUsedObjectID];
+	checkBox_t *checkBox = &checkBoxes[mouse.lastUsedObjectID];
 	if (!checkBox->visible)
 		return;
 
--- a/src/ft2_config.c
+++ b/src/ft2_config.c
@@ -52,14 +52,11 @@
 
 static int32_t calcChecksum(uint8_t *p, uint16_t len) // for nibbles highscore data
 {
-	uint16_t data;
-	uint32_t checksum;
-
 	if (len == 0)
 		return 0;
 
-	data = 0;
-	checksum = 0;
+	uint16_t data = 0;
+	uint32_t checksum = 0;
 
 	do
 	{
@@ -74,7 +71,7 @@
 
 static void loadConfigFromBuffer(void)
 {
-	int32_t i, checksum;
+	int32_t i;
 
 	lockMixerCallback();
 
@@ -81,7 +78,7 @@
 	memcpy(&config, configBuffer, CONFIG_FILE_SIZE);
 
 	// if Nibbles highscore table checksum is incorrect, load default highscore table instead
-	checksum = calcChecksum((uint8_t *)&config.NI_HighScore, sizeof (config.NI_HighScore));
+	const int32_t checksum = calcChecksum((uint8_t *)&config.NI_HighScore, sizeof (config.NI_HighScore));
 	if (config.NI_HighScoreChecksum != checksum)
 	{
 		memcpy(&config.NI_HighScore, &defConfigData[636], sizeof (config.NI_HighScore));
@@ -209,12 +206,10 @@
 
 void resetConfig(void)
 {
-	uint8_t oldWindowFlags;
-
 	if (okBox(2, "System request", "Are you sure you want to completely reset your FT2 configuration?") != 1)
 		return;
 
-	oldWindowFlags = config.windowFlags;
+	const uint8_t oldWindowFlags = config.windowFlags;
 
 	setDefaultConfigSettings();
 	setToDefaultAudioOutputDevice();
@@ -247,9 +242,6 @@
 
 bool loadConfig(bool showErrorFlag)
 {
-	size_t fileSize;
-	FILE *in;
-
 	// this routine can be called at any time, so make sure we free these first...
 
 	if (audio.currOutputDevice != NULL)
@@ -286,7 +278,7 @@
 		return false;
 	}
 
-	in = UNICHAR_FOPEN(editor.configFileLocation, "rb");
+	FILE *in = UNICHAR_FOPEN(editor.configFileLocation, "rb");
 	if (in == NULL)
 	{
 		if (showErrorFlag)
@@ -296,7 +288,7 @@
 	}
 
 	fseek(in, 0, SEEK_END);
-	fileSize = (int32_t)ftell(in);
+	const size_t fileSize = ftell(in);
 	rewind(in);
 
 	if (fileSize > CONFIG_FILE_SIZE)
@@ -350,10 +342,8 @@
 
 void loadConfig2(void) // called by "Load config" button
 {
-	uint8_t oldWindowFlags;
+	const uint8_t oldWindowFlags = config.windowFlags;
 
-	oldWindowFlags = config.windowFlags;
-
 	loadConfig(CONFIG_SHOW_ERRORS);
 
 	// redraw new changes
@@ -379,8 +369,6 @@
 
 bool saveConfig(bool showErrorFlag)
 {
-	FILE *out;
-
 	if (editor.configFileLocation == NULL)
 	{
 		if (showErrorFlag)
@@ -395,7 +383,7 @@
 	saveMidiInputDeviceToConfig();
 #endif
 
-	out = UNICHAR_FOPEN(editor.configFileLocation, "wb");
+	FILE *out = UNICHAR_FOPEN(editor.configFileLocation, "wb");
 	if (out == NULL)
 	{
 		if (showErrorFlag)
@@ -443,13 +431,12 @@
 
 static UNICHAR *getFullAudDevConfigPath(void) // kinda hackish
 {
-	UNICHAR *filePath;
-	int32_t ft2ConfPathLen, stringOffset, audiodevDotIniStrLen, ft2DotCfgStrLen;
+	int32_t audiodevDotIniStrLen, ft2DotCfgStrLen;
 
 	if (editor.configFileLocation == NULL)
 		return NULL;
 
-	ft2ConfPathLen = (int32_t)UNICHAR_STRLEN(editor.configFileLocation);
+	const int32_t ft2ConfPathLen = (int32_t)UNICHAR_STRLEN(editor.configFileLocation);
 
 #ifdef _WIN32
 	audiodevDotIniStrLen = (int32_t)UNICHAR_STRLEN(L"audiodev.ini");
@@ -459,11 +446,11 @@
 	ft2DotCfgStrLen = (int32_t)UNICHAR_STRLEN("FT2.CFG");
 #endif
 
-	filePath = (UNICHAR *)calloc(ft2ConfPathLen + audiodevDotIniStrLen + 2, sizeof (UNICHAR));
+	UNICHAR *filePath = (UNICHAR *)calloc(ft2ConfPathLen + audiodevDotIniStrLen + 2, sizeof (UNICHAR));
 
 	UNICHAR_STRCPY(filePath, editor.configFileLocation);
 
-	stringOffset = ft2ConfPathLen - ft2DotCfgStrLen;
+	const int32_t stringOffset = ft2ConfPathLen - ft2DotCfgStrLen;
 	filePath[stringOffset+0] = '\0';
 	filePath[stringOffset+1] = '\0';
 
@@ -478,13 +465,12 @@
 
 static UNICHAR *getFullMidiDevConfigPath(void) // kinda hackish
 {
-	UNICHAR *filePath;
-	int32_t ft2ConfPathLen, stringOffset, mididevDotIniStrLen, ft2DotCfgStrLen;
+	int32_t mididevDotIniStrLen, ft2DotCfgStrLen;
 
 	if (editor.configFileLocation == NULL)
 		return NULL;
 
-	ft2ConfPathLen = (int32_t)UNICHAR_STRLEN(editor.configFileLocation);
+	const int32_t ft2ConfPathLen = (int32_t)UNICHAR_STRLEN(editor.configFileLocation);
 
 #ifdef _WIN32
 	mididevDotIniStrLen = (int32_t)UNICHAR_STRLEN(L"mididev.ini");
@@ -494,11 +480,11 @@
 	ft2DotCfgStrLen = (int32_t)UNICHAR_STRLEN("FT2.CFG");
 #endif
 
-	filePath = (UNICHAR *)calloc(ft2ConfPathLen + mididevDotIniStrLen + 2, sizeof (UNICHAR));
+	UNICHAR *filePath = (UNICHAR *)calloc(ft2ConfPathLen + mididevDotIniStrLen + 2, sizeof (UNICHAR));
 
 	UNICHAR_STRCPY(filePath, editor.configFileLocation);
 
-	stringOffset = ft2ConfPathLen - ft2DotCfgStrLen;
+	const int32_t stringOffset = ft2ConfPathLen - ft2DotCfgStrLen;
 	filePath[stringOffset+0] = '\0';
 	filePath[stringOffset+1] = '\0';
 
@@ -513,7 +499,7 @@
 
 static void setConfigFileLocation(void) // kinda hackish
 {
-	int32_t result, ft2DotCfgStrLen;
+	int32_t ft2DotCfgStrLen;
 	FILE *f;
 
 	// Windows
@@ -551,7 +537,7 @@
 	UNICHAR_STRCPY(editor.configFileLocation, oldPath);
 	if ((f = fopen("FT2.CFG", "rb")) == NULL)
 	{
-		result = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, tmpPath);
+		int32_t result = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, tmpPath);
 		if (result == S_OK)
 		{
 			if (SetCurrentDirectoryW(tmpPath) != 0)
@@ -602,7 +588,7 @@
 	{
 		if (chdir(getenv("HOME")) == 0)
 		{
-			result = chdir("Library/Application Support");
+			int32_t result = chdir("Library/Application Support");
 			if (result == 0)
 			{
 				result = chdir("FT2 clone");
@@ -682,9 +668,6 @@
 
 void loadConfigOrSetDefaults(void)
 {
-	size_t fileSize;
-	FILE *in;
-
 	setConfigFileLocation();
 
 	if (editor.configFileLocation == NULL)
@@ -693,7 +676,7 @@
 		return;
 	}
 
-	in = UNICHAR_FOPEN(editor.configFileLocation, "rb");
+	FILE *in = UNICHAR_FOPEN(editor.configFileLocation, "rb");
 	if (in == NULL)
 	{
 		setDefaultConfigSettings();
@@ -701,7 +684,7 @@
 	}
 
 	fseek(in, 0, SEEK_END);
-	fileSize = ftell(in);
+	size_t fileSize = ftell(in);
 	rewind(in);
 
 	// not a valid FT2 config file (FT2.CFG filesize varies depending on version)
@@ -755,14 +738,11 @@
 
 static void drawMIDITransp(void)
 {
-	char sign;
-	int8_t val;
-
 	fillRect(571, 123, 20, 8, PAL_DESKTOP);
 
-	sign = (config.recMIDITranspVal < 0) ? '-' : '+';
+	const char sign = (config.recMIDITranspVal < 0) ? '-' : '+';
 
-	val = (int8_t)(ABS(config.recMIDITranspVal));
+	const int8_t val = (int8_t)(ABS(config.recMIDITranspVal));
 	if (val >= 10)
 	{
 		charOut(571, 123, PAL_FORGRND, sign);
--- a/src/ft2_diskop.c
+++ b/src/ft2_diskop.c
@@ -86,15 +86,10 @@
 
 int32_t getFileSize(UNICHAR *fileNameU) // returning -1 = filesize over 2GB
 {
-#ifdef _WIN32
-	FILE *f;
-#else
-	struct stat st;
-#endif
 	int64_t fSize;
 
 #ifdef _WIN32
-	f = UNICHAR_FOPEN(fileNameU, "rb");
+	FILE *f = UNICHAR_FOPEN(fileNameU, "rb");
 	if (f == NULL)
 		return 0;
 
@@ -102,6 +97,7 @@
 	fSize = _ftelli64(f);
 	fclose(f);
 #else
+	struct stat st;
 	if (stat(fileNameU, &st) != 0)
 		return 0;
 
@@ -111,9 +107,9 @@
 		fSize = 0;
 
 	if (fSize > INT32_MAX)
-		return -1;
+		return -1; // -1 = ">2GB" flag
 	
-	return fSize & 0xFFFFFFFF;
+	return (int32_t)fSize;
 }
 
 uint8_t getDiskOpItem(void)
@@ -334,12 +330,10 @@
 
 static void removeQuestionmarksFromString(char *s)
 {
-	int32_t len;
-
 	if (s == NULL || *s == '\0')
 		return;
 
-	len = (int32_t)strlen(s);
+	const int32_t len = (int32_t)strlen(s);
 	for (int32_t i = 0; i < len; i++)
 	{
 		if (s[i] == '?')
@@ -351,14 +345,11 @@
 
 bool fileExistsAnsi(char *str)
 {
-	int32_t retVal;
-	UNICHAR *strU;
-
-	strU = cp437ToUnichar(str);
+	UNICHAR *strU = cp437ToUnichar(str);
 	if (strU == NULL)
 		return false;
 
-	retVal = PathFileExistsW(strU);
+	bool retVal = PathFileExistsW(strU);
 	free(strU);
 
 	return retVal;
@@ -378,14 +369,11 @@
 
 static bool makeDirAnsi(char *str)
 {
-	int32_t retVal;
-	UNICHAR *strU;
-
-	strU = cp437ToUnichar(str);
+	UNICHAR *strU = cp437ToUnichar(str);
 	if (strU == NULL)
 		return false;
 
-	retVal = _wmkdir(strU);
+	int32_t retVal = _wmkdir(strU);
 	free(strU);
 
 	return (retVal == 0);
@@ -393,14 +381,11 @@
 
 static bool renameAnsi(UNICHAR *oldNameU, char *newName)
 {
-	int32_t retVal;
-	UNICHAR *newNameU;
-
-	newNameU = cp437ToUnichar(newName);
+	UNICHAR *newNameU = cp437ToUnichar(newName);
 	if (newNameU == NULL)
 		return false;
 
-	retVal = UNICHAR_RENAME(oldNameU, newNameU);
+	int32_t retVal = UNICHAR_RENAME(oldNameU, newNameU);
 	free(newNameU);
 
 	return (retVal == 0);
@@ -408,16 +393,12 @@
 
 static void setupDiskOpDrives(void) // Windows only
 {
-	uint16_t i;
-	uint32_t drivesBitmask;
-
 	fillRect(134, 29, 31, 111, PAL_DESKTOP);
-
 	numLogicalDrives = 0;
 
 	// get number of drives and drive names
-	drivesBitmask = GetLogicalDrives();
-	for (i = 0; i < 8*sizeof (uint32_t); i++)
+	const uint32_t drivesBitmask = GetLogicalDrives();
+	for (int32_t i = 0; i < 8*sizeof (uint32_t); i++)
 	{
 		if ((drivesBitmask & (1 << i)) != 0)
 		{
@@ -428,11 +409,11 @@
 	}
 
 	// hide all buttons
-	for (i = 0; i < DISKOP_MAX_DRIVE_BUTTONS; i++)
+	for (uint16_t i = 0; i < DISKOP_MAX_DRIVE_BUTTONS; i++)
 		hidePushButton(PB_DISKOP_DRIVE1 + i);
 
 	// set button names and show buttons
-	for (i = 0; i < numLogicalDrives; i++)
+	for (uint16_t i = 0; i < numLogicalDrives; i++)
 	{
 		pushButtons[PB_DISKOP_DRIVE1 + i].caption = logicalDriveNames[driveIndexes[i]];
 		showPushButton(PB_DISKOP_DRIVE1 + i);
@@ -463,14 +444,11 @@
 
 bool fileExistsAnsi(char *str)
 {
-	int32_t retVal;
-	UNICHAR *strU;
-
-	strU = cp437ToUnichar(str);
+	UNICHAR *strU = cp437ToUnichar(str);
 	if (strU == NULL)
 		return false;
 
-	retVal = access(strU, F_OK);
+	int32_t retVal = access(strU, F_OK);
 	free(strU);
 
 	return (retVal != -1);
@@ -478,18 +456,14 @@
 
 static bool deleteDirRecursive(UNICHAR *strU)
 {
-	int32_t ret;
-	FTS *ftsp;
 	FTSENT *curr;
 	char *files[] = { (char *)(strU), NULL };
 
-	ftsp = NULL;
-
-	ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
+	FTS *ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
 	if (!ftsp)
 		return false;
 
-	ret = true;
+	bool ret = true;
 	while ((curr = fts_read(ftsp)))
 	{
 		switch (curr->fts_info)
@@ -528,14 +502,11 @@
 
 static bool makeDirAnsi(char *str)
 {
-	int32_t retVal;
-	UNICHAR *strU;
-
-	strU = cp437ToUnichar(str);
+	UNICHAR *strU = cp437ToUnichar(str);
 	if (strU == NULL)
 		return false;
 
-	retVal = mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+	int32_t retVal = mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
 	free(strU);
 
 	return (retVal == 0);
@@ -586,12 +557,12 @@
 
 static char *getFilenameFromPath(char *p)
 {
-	int32_t i, len;
+	int32_t i;
 
 	if (p == NULL || p[0] == '\0')
 		return p;
 
-	len = (int32_t)strlen(p);
+	const int32_t len = (int32_t)strlen(p);
 	if (len < 2 || p[len-1] == DIR_DELIMITER)
 		return p;
 
@@ -692,11 +663,8 @@
 
 static void openFile(UNICHAR *filenameU, bool songModifiedCheck)
 {
-	int32_t filesize;
-	FILE *f;
-
 	// first check if we can actually open the requested file
-	f = UNICHAR_FOPEN(filenameU, "rb");
+	FILE *f = UNICHAR_FOPEN(filenameU, "rb");
 	if (f == NULL)
 	{
 		okBox(0, "System message", "Couldn't open file/directory! No permission or in use?");
@@ -704,7 +672,7 @@
 	}
 	fclose(f);
 
-	filesize = getFileSize(filenameU);
+	const int32_t filesize = getFileSize(filenameU);
 	if (filesize == -1) // >2GB
 	{
 		okBox(0, "System message", "The file is too big and can't be loaded (over 2GB).");
@@ -761,9 +729,9 @@
 	if (name == NULL || *name == '\0')
 		return;
 
-	int32_t len = (int32_t)strlen(name);
+	const int32_t len = (int32_t)strlen(name);
 
-	int32_t extOffset = getExtOffset(name, len);
+	const int32_t extOffset = getExtOffset(name, len);
 	if (extOffset != -1)
 		name[extOffset] = '\0';
 }
@@ -775,7 +743,7 @@
 
 	removeFilenameExt(name);
 
-	int32_t len = (int32_t)strlen(name);
+	const int32_t len = (int32_t)strlen(name);
 	int32_t extLen = (int32_t)strlen(ext);
 
 	if (len+extLen > nameMaxLen)
@@ -797,11 +765,10 @@
 void trimEntryName(char *name, bool isDir)
 {
 	char extBuffer[24];
-	int32_t j, extOffset, extLen;
 
-	j = (int32_t)strlen(name);
-	extOffset = getExtOffset(name, j);
-	extLen = (int32_t)strlen(&name[extOffset]);
+	int32_t j = (int32_t)strlen(name);
+	const int32_t extOffset = getExtOffset(name, j);
+	int32_t extLen = (int32_t)strlen(&name[extOffset]);
 	j--;
 
 	if (isDir)
@@ -846,10 +813,9 @@
 static void createOverwriteText(char *name)
 {
 	char nameTmp[128];
-	uint32_t nameLen;
 
 	// read entry name to a small buffer
-	nameLen = (uint32_t)strlen(name);
+	const uint32_t nameLen = (uint32_t)strlen(name);
 	memcpy(nameTmp, name, (nameLen >= sizeof (nameTmp)) ? sizeof (nameTmp) : (nameLen + 1));
 	nameTmp[sizeof (nameTmp) - 1] = '\0';
 
@@ -1031,15 +997,13 @@
 static void fileListPressed(int32_t index)
 {
 	char *nameTmp;
-	int8_t mode;
-	int32_t result, entryIndex;
-	DirRec *dirEntry;
+	int32_t result;
 
-	entryIndex = FReq_DirPos + index;
+	const int32_t entryIndex = FReq_DirPos + index;
 	if (entryIndex >= FReq_FileCount || FReq_FileCount == 0)
 		return; // illegal entry
 
-	mode = mouse.mode;
+	const int8_t mode = mouse.mode;
 
 	// set normal mouse cursor
 	if (mouse.mode != MOUSE_MODE_NORMAL)
@@ -1049,7 +1013,7 @@
 	FReq_EntrySelected = -1;
 	diskOp_DrawDirectory();
 
-	dirEntry = &FReq_Buffer[entryIndex];
+	DirRec *dirEntry = &FReq_Buffer[entryIndex];
 	switch (mode)
 	{
 		// open file/folder
@@ -1147,12 +1111,12 @@
 
 bool testDiskOpMouseDown(bool mouseHeldDlown)
 {
-	int32_t tmpEntry, max;
+	int32_t tmpEntry;
 
 	if (!ui.diskOpShown || FReq_FileCount == 0)
 		return false;
 
-	max = FReq_FileCount - FReq_DirPos;
+	int32_t max = FReq_FileCount - FReq_DirPos;
 	if (max > DISKOP_ENTRY_NUM) // needed kludge when mouse-scrolling
 		max = DISKOP_ENTRY_NUM;
 
@@ -1225,14 +1189,11 @@
 
 static uint8_t handleEntrySkip(UNICHAR *nameU, bool isDir)
 {
-	char *name, *extPtr;
-	int32_t nameLen, extOffset, extLen;
-
 	// skip if illegal name or filesize >32-bit
 	if (nameU == NULL)
 		return true;
 
-	name = unicharToCp437(nameU, false);
+	char *name = unicharToCp437(nameU, false);
 	if (name == NULL)
 		return true;
 	
@@ -1239,7 +1200,7 @@
 	if (name[0] == '\0')
 		goto skipEntry;
 
-	nameLen = (int32_t)strlen(name);
+	const int32_t nameLen = (int32_t)strlen(name);
 
 	// skip ".name" dirs/files
 	if (nameLen >= 2 && name[0] == '.' && name[1] != '.')
@@ -1262,15 +1223,15 @@
 	}
 	else if (!FReq_ShowAllFiles)
 	{
-		extOffset = getExtOffset(name, nameLen);
+		const int32_t extOffset = getExtOffset(name, nameLen);
 		if (extOffset == -1)
 			goto skipEntry;
 
-		extLen = (int32_t)strlen(&name[extOffset]);
+		const int32_t extLen = (int32_t)strlen(&name[extOffset]);
 		if (extLen < 3 || extLen > 5)
 			goto skipEntry; // no possibly known extensions to filter out
 
-		extPtr = &name[extOffset];
+		char *extPtr = &name[extOffset];
 
 		// decide what entries to keep based on file extension
 		switch (FReq_Item)
@@ -1589,12 +1550,10 @@
 
 static bool swapBufferEntry(int32_t a, int32_t b) // used for sorting
 {
-	DirRec tmpBuffer;
-
 	if (a >= FReq_FileCount || b >= FReq_FileCount)
 		return false;
 
-	tmpBuffer = FReq_Buffer[a];
+	DirRec tmpBuffer = FReq_Buffer[a];
 	FReq_Buffer[a] = FReq_Buffer[b];
 	FReq_Buffer[b] = tmpBuffer;
 
@@ -1603,17 +1562,13 @@
 
 static char *ach(int32_t rad) // used for sortDirectory()
 {
-	char *p, *name;
-	int32_t i, nameLen, extLen;
-	DirRec *dirEntry;
+	DirRec *dirEntry = &FReq_Buffer[rad];
 
-	dirEntry = &FReq_Buffer[rad];
-
-	name = unicharToCp437(dirEntry->nameU, true);
+	char *name = unicharToCp437(dirEntry->nameU, true);
 	if (name == NULL)
 		return NULL;
 
-	nameLen = (int32_t)strlen(name);
+	const int32_t nameLen = (int32_t)strlen(name);
 	if (nameLen == 0)
 	{
 		free(name);
@@ -1620,7 +1575,7 @@
 		return NULL;
 	}
 
-	p = (char *)malloc(nameLen + 2);
+	char *p = (char *)malloc(nameLen + 2);
 	if (p == NULL)
 	{
 		free(name);
@@ -1645,7 +1600,7 @@
 	{
 		// file
 
-		i = getExtOffset(name, nameLen);
+		const int32_t i = getExtOffset(name, nameLen);
 		if (config.cfg_SortPriority == 1 || i == -1)
 		{
 			// sort by filename
@@ -1656,7 +1611,7 @@
 		else
 		{
 			// sort by filename extension
-			extLen = nameLen - i;
+			const int32_t extLen = nameLen - i;
 			if (extLen <= 1)
 			{
 				strcpy(p, name);
@@ -1678,23 +1633,21 @@
 static void sortDirectory(void)
 {
 	bool didSwap;
-	char *p1, *p2;
-	uint32_t offset, limit, i;
 
 	if (FReq_FileCount < 2)
 		return; // no need to sort
 
-	offset = FReq_FileCount / 2;
+	uint32_t offset = FReq_FileCount >> 1;
 	while (offset > 0)
 	{
-		limit = FReq_FileCount - offset;
+		const uint32_t limit = FReq_FileCount - offset;
 		do
 		{
 			didSwap = false;
-			for (i = 0; i < limit; i++)
+			for (uint32_t i = 0; i < limit; i++)
 			{
-				p1 = ach(i);
-				p2 = ach(offset + i);
+				char *p1 = ach(i);
+				char *p2 = ach(offset+i);
 
 				if (p1 == NULL || p2 == NULL)
 				{
@@ -1722,7 +1675,7 @@
 		}
 		while (didSwap);
 
-		offset /= 2;
+		offset >>= 1;
 	}
 }
 
@@ -1744,9 +1697,9 @@
 static void printFormattedFilesize(uint16_t x, uint16_t y, uint32_t bufEntry)
 {
 	char sizeStrBuffer[16];
-	int32_t filesize, printFilesize;
+	int32_t printFilesize;
 
-	filesize = FReq_Buffer[bufEntry].filesize;
+	const int32_t filesize = FReq_Buffer[bufEntry].filesize;
 	if (filesize == -1)
 	{
 		x += 6;
@@ -1784,17 +1737,13 @@
 
 static void displayCurrPath(void)
 {
-	char *p, *delimiter, *asciiPath;
-	int32_t j;
-	uint32_t pathLen;
-
 	fillRect(4, 145, 162, 10, PAL_DESKTOP);
 
-	pathLen = (uint32_t)UNICHAR_STRLEN(FReq_CurPathU);
+	const uint32_t pathLen = (uint32_t)UNICHAR_STRLEN(FReq_CurPathU);
 	if (pathLen == 0)
 		return;
 
-	asciiPath = unicharToCp437(FReq_CurPathU, true);
+	char *asciiPath = unicharToCp437(FReq_CurPathU, true);
 	if (asciiPath == NULL)
 	{
 		okBox(0, "System message", "Not enough memory!");
@@ -1801,7 +1750,7 @@
 		return;
 	}
 
-	p = asciiPath;
+	char *p = asciiPath;
 	if (textWidth(p) <= 162)
 	{
 		// path fits, print it all
@@ -1820,7 +1769,7 @@
 		strcat(FReq_NameTemp, "..");
 #endif
 
-		delimiter = strrchr(p, DIR_DELIMITER);
+		char *delimiter = strrchr(p, DIR_DELIMITER);
 		if (delimiter != NULL)
 		{
 #ifdef _WIN32
@@ -1830,7 +1779,7 @@
 #endif
 		}
 
-		j = (int32_t)strlen(FReq_NameTemp);
+		int32_t j = (int32_t)strlen(FReq_NameTemp);
 		if (j > 6)
 		{
 			j--;
@@ -1853,16 +1802,12 @@
 
 void diskOp_DrawDirectory(void)
 {
-	char *readName;
-	uint16_t y;
-	int32_t bufEntry;
-
 	clearRect(FILENAME_TEXT_X - 1, 4, 162, 164);
 	drawTextBox(TB_DISKOP_FILENAME);
 
 	if (FReq_EntrySelected != -1)
 	{
-		y = 4 + (uint16_t)((FONT1_CHAR_H + 1) * FReq_EntrySelected);
+		const uint16_t y = 4 + (uint16_t)((FONT1_CHAR_H + 1) * FReq_EntrySelected);
 		fillRect(FILENAME_TEXT_X - 1, y, 162, FONT1_CHAR_H, PAL_PATTEXT);
 	}
 
@@ -1876,7 +1821,7 @@
 
 	for (uint16_t i = 0; i < DISKOP_ENTRY_NUM; i++)
 	{
-		bufEntry = FReq_DirPos + i;
+		const int32_t bufEntry = FReq_DirPos + i;
 		if (bufEntry >= FReq_FileCount)
 			break;
 
@@ -1884,11 +1829,11 @@
 			continue;
 
 		// convert unichar name to codepage 437
-		readName = unicharToCp437(FReq_Buffer[bufEntry].nameU, true);
+		char *readName = unicharToCp437(FReq_Buffer[bufEntry].nameU, true);
 		if (readName == NULL)
 			continue;
 
-		y = 4 + (i * (FONT1_CHAR_H + 1));
+		const uint16_t y = 4 + (i * (FONT1_CHAR_H + 1));
 
 		// shrink entry name and add ".." if it doesn't fit on screen
 		trimEntryName(readName, FReq_Buffer[bufEntry].isDir);
@@ -1917,9 +1862,7 @@
 
 static DirRec *bufferCreateEmptyDir(void) // special case: creates a dir entry with a ".." directory
 {
-	DirRec *dirEntry;
-
-	dirEntry = (DirRec *)malloc(sizeof (DirRec));
+	DirRec *dirEntry = (DirRec *)malloc(sizeof (DirRec));
 	if (dirEntry == NULL)
 		return NULL;
 
@@ -1938,8 +1881,7 @@
 
 static int32_t SDLCALL diskOp_ReadDirectoryThread(void *ptr)
 {
-	uint8_t lastFindFileFlag;
-	DirRec tmpBuffer, *newPtr;
+	DirRec tmpBuffer;
 
 	FReq_DirPos = 0;
 
@@ -1949,10 +1891,10 @@
 	UNICHAR_GETCWD(FReq_CurPathU, PATH_MAX);
 
 	// read first file
-	lastFindFileFlag = findFirst(&tmpBuffer);
+	int8_t lastFindFileFlag = findFirst(&tmpBuffer);
 	if (lastFindFileFlag != LFF_DONE && lastFindFileFlag != LFF_SKIP)
 	{
-		FReq_Buffer = (DirRec *)malloc(sizeof (DirRec) * (FReq_FileCount + 1));
+		FReq_Buffer = (DirRec *)malloc(sizeof (DirRec) * (FReq_FileCount+1));
 		if (FReq_Buffer == NULL)
 		{
 			findClose();
@@ -1979,7 +1921,7 @@
 		lastFindFileFlag = findNext(&tmpBuffer);
 		if (lastFindFileFlag != LFF_DONE && lastFindFileFlag != LFF_SKIP)
 		{
-			newPtr = (DirRec *)realloc(FReq_Buffer, sizeof (DirRec) * (FReq_FileCount + 1));
+			DirRec *newPtr = (DirRec *)realloc(FReq_Buffer, sizeof (DirRec) * (FReq_FileCount + 1));
 			if (newPtr == NULL)
 			{
 				freeDirRecBuffer();
@@ -2011,11 +1953,11 @@
 	}
 
 	editor.diskOpReadDone = true;
-
 	setMouseBusy(false);
 
-	(void)ptr;
 	return true;
+
+	(void)ptr;
 }
 
 void diskOp_StartDirReadThread(void)
@@ -2083,7 +2025,6 @@
 	hideRadioButtonGroup(RB_GROUP_DISKOP_PAT_SAVEAS);
 	hideRadioButtonGroup(RB_GROUP_DISKOP_TRK_SAVEAS);
 
-
 	if (editor.moduleSaveMode > 3)
 		editor.moduleSaveMode = 3;
 
@@ -2112,8 +2053,6 @@
 
 static void setDiskOpItem(uint8_t item)
 {
-	int32_t pathLen;
-
 	hideRadioButtonGroup(RB_GROUP_DISKOP_MOD_SAVEAS);
 	hideRadioButtonGroup(RB_GROUP_DISKOP_INS_SAVEAS);
 	hideRadioButtonGroup(RB_GROUP_DISKOP_SMP_SAVEAS);
@@ -2204,7 +2143,7 @@
 		break;
 	}
 
-	pathLen = (int32_t)UNICHAR_STRLEN(FReq_CurPathU);
+	const int32_t pathLen = (int32_t)UNICHAR_STRLEN(FReq_CurPathU);
 	if (pathLen == 0)
 	{
 		memset(FReq_CurPathU, 0, (PATH_MAX + 2) * sizeof (UNICHAR));
--- a/src/ft2_edit.c
+++ b/src/ft2_edit.c
@@ -46,7 +46,7 @@
 // when the cursor is at the note slot
 static bool testNoteKeys(SDL_Scancode scancode)
 {
-	int8_t noteNum = scancodeKeyToNote(scancode);
+	const int8_t noteNum = scancodeKeyToNote(scancode);
 	if (noteNum > 0 && noteNum <= 96)
 	{
 		recordNote(noteNum, -1);
@@ -59,7 +59,7 @@
 // when the cursor is at the note slot
 void testNoteKeysRelease(SDL_Scancode scancode)
 {
-	int8_t noteNum = scancodeKeyToNote(scancode); // convert key scancode to note number
+	const int8_t noteNum = scancodeKeyToNote(scancode); // convert key scancode to note number
 	if (noteNum > 0 && noteNum <= 96)
 		recordNote(noteNum, 0); // release note
 }
@@ -68,8 +68,6 @@
 {
 	int8_t i;
 	uint8_t oldVal;
-	uint16_t pattLen;
-	tonTyp *ton;
 
 	if (cursor.object == CURSOR_NOTE)
 	{
@@ -134,7 +132,7 @@
 
 	// insert slot data
 
-	ton = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
+	tonTyp *ton = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
 	switch (cursor.object)
 	{
 		case CURSOR_INST1:
@@ -228,7 +226,7 @@
 
 	// increase row (only in edit mode)
 
-	pattLen = pattLens[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 	if (playMode == PLAYMODE_EDIT && pattLen >= 1)
 		setPos(-1, (editor.pattPos + editor.ID_Add) % pattLen, true);
 
@@ -242,14 +240,11 @@
 // directly ported from the original FT2 code (fun fact: named EvulateTimeStamp() in the FT2 code)
 static void evaluateTimeStamp(int16_t *songPos, int16_t *pattNr, int16_t *pattPos, int16_t *tick)
 {
-	int16_t nr, t, p, r, sp, row;
-	uint16_t pattLen;
+	int16_t sp = editor.songPos;
+	int16_t nr = editor.editPattern;
+	int16_t row = editor.pattPos;
+	int16_t t = editor.tempo - editor.timer;
 
-	sp = editor.songPos;
-	nr = editor.editPattern;
-	row = editor.pattPos;
-	t = editor.tempo - editor.timer;
-
 	t = CLAMP(t, 0, editor.tempo - 1);
 
 	// this is needed, but also breaks quantization on speed>15
@@ -256,10 +251,11 @@
 	if (t > 15)
 		t = 15;
 
-	pattLen = pattLens[nr];
+	const int16_t pattLen = pattLens[nr];
 
 	if (config.recQuant > 0)
 	{
+		int16_t r;
 		if (config.recQuantRes >= 16)
 		{
 			t += (editor.tempo >> 1) + 1;
@@ -268,7 +264,7 @@
 		{
 			r = tickArr[config.recQuantRes-1];
 
-			p = row & (r - 1);
+			int16_t p = row & (r - 1);
 			if (p < (r >> 1))
 				row -= p;
 			else
@@ -305,13 +301,12 @@
 // directly ported from the original FT2 code - what a mess, but it works...
 void recordNote(uint8_t note, int8_t vol)
 {
-	int8_t i, k, c, editmode, recmode;
-	int16_t nr, sp, oldpattpos, pattpos, tick;
-	uint16_t pattLen;
+	int8_t i;
+	int16_t nr, sp, pattpos, tick;
 	int32_t time;
 	tonTyp *noteData;
 
-	oldpattpos = editor.pattPos;
+	const int16_t oldpattpos = editor.pattPos;
 
 	if (songPlaying)
 	{
@@ -326,14 +321,14 @@
 		tick = 0;
 	}
 
-	editmode = (playMode == PLAYMODE_EDIT);
-	recmode = (playMode == PLAYMODE_RECSONG) || (playMode == PLAYMODE_RECPATT);
+	bool editmode = (playMode == PLAYMODE_EDIT);
+	bool recmode = (playMode == PLAYMODE_RECSONG) || (playMode == PLAYMODE_RECPATT);
 
 	if (note == 97)
 		vol = 0;
 
-	c = -1;
-	k = -1;
+	int8_t c = -1;
+	int8_t k = -1;
 
 	if (editmode || recmode)
 	{
@@ -428,7 +423,7 @@
 		{
 			if (allocatePattern(nr))
 			{
-				pattLen  = pattLens[nr];
+				const int16_t pattLen  = pattLens[nr];
 				noteData = &patt[nr][(pattpos * MAX_VOICES) + c];
 
 				// insert data
@@ -488,7 +483,7 @@
 			{
 				// insert data
 
-				pattLen = pattLens[nr];
+				int16_t pattLen = pattLens[nr];
 				noteData = &patt[nr][(pattpos * MAX_VOICES) + c];
 
 				if (noteData->ton != 0)
@@ -535,10 +530,6 @@
 
 bool handleEditKeys(SDL_Keycode keycode, SDL_Scancode scancode)
 {
-	bool frKeybHack;
-	uint16_t pattLen;
-	tonTyp *note;
-
 	// special case for delete - manipulate note data
 	if (keycode == SDLK_DELETE)
 	{
@@ -548,7 +539,7 @@
 		if (patt[editor.editPattern] == NULL)
 			return true;
 
-		note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
+		tonTyp *note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
 
 		if (keyb.leftShiftPressed)
 		{
@@ -586,7 +577,7 @@
 		killPatternIfUnused(editor.editPattern);
 
 		// increase row (only in edit mode)
-		pattLen = pattLens[editor.editPattern];
+		const int16_t pattLen = pattLens[editor.editPattern];
 		if (playMode == PLAYMODE_EDIT && pattLen >= 1)
 			setPos(-1, (editor.pattPos + editor.ID_Add) % pattLen, true);
 
@@ -597,7 +588,7 @@
 	}
 
 	// a kludge for french keyb. layouts to allow writing numbers in the pattern data with left SHIFT
-	frKeybHack = keyb.leftShiftPressed && !keyb.leftAltPressed && !keyb.leftCtrlPressed &&
+	const bool frKeybHack = keyb.leftShiftPressed && !keyb.leftAltPressed && !keyb.leftCtrlPressed &&
 	               (scancode >= SDL_SCANCODE_1) && (scancode <= SDL_SCANCODE_0);
 
 	if (frKeybHack || !keyb.keyModifierDown)
@@ -608,15 +599,12 @@
 
 void writeToMacroSlot(uint8_t slot)
 {
-	uint16_t writeVol, writeEff;
-	tonTyp *note;
+	uint16_t writeVol = 0;
+	uint16_t writeEff = 0;
 
-	writeVol = 0;
-	writeEff = 0;
-
 	if (patt[editor.editPattern] != NULL)
 	{
-		note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
+		tonTyp *note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
 		writeVol = note->vol;
 		writeEff = (note->effTyp << 8) | note->eff;
 	}
@@ -629,10 +617,6 @@
 
 void writeFromMacroSlot(uint8_t slot)
 {
-	uint8_t effTyp;
-	uint16_t pattLen;
-	tonTyp *note;
-
 	if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
 		return;
 
@@ -639,8 +623,8 @@
 	if (!allocatePattern(editor.editPattern))
 		return;
 
-	pattLen = pattLens[editor.editPattern];
-	note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
+	const int16_t pattLen = pattLens[editor.editPattern];
+	tonTyp *note = &patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch];
 
 	if (cursor.object == CURSOR_VOL1 || cursor.object == CURSOR_VOL2)
 	{
@@ -648,7 +632,7 @@
 	}
 	else
 	{
-		effTyp = (uint8_t)(config.comMacro[slot] >> 8);
+		uint8_t effTyp = (uint8_t)(config.comMacro[slot] >> 8);
 		if (effTyp > 35)
 		{
 			// illegal effect
@@ -673,21 +657,17 @@
 
 void insertPatternNote(void)
 {
-	int16_t nr, pattPos;
-	uint16_t pattLen;
-	tonTyp *pattPtr;
-
 	if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
 		return;
 
-	nr = editor.editPattern;
+	const int16_t nr = editor.editPattern;
 
-	pattPtr = patt[nr];
+	tonTyp *pattPtr = patt[nr];
 	if (pattPtr == NULL)
 		return;
 
-	pattPos = editor.pattPos;
-	pattLen = pattLens[nr];
+	const int16_t pattPos = editor.pattPos;
+	const int16_t pattLen = pattLens[nr];
 
 	if (pattLen > 1)
 	{
@@ -705,21 +685,18 @@
 
 void insertPatternLine(void)
 {
-	int16_t nr, pattLen, pattPos;
-	tonTyp *pattPtr;
-
 	if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
 		return;
 
-	nr = editor.editPattern;
+	const int16_t nr = editor.editPattern;
 
 	setPatternLen(nr, pattLens[nr] + config.recTrueInsert); // config.recTrueInsert is 0 or 1
 
-	pattPtr = patt[nr];
+	tonTyp *pattPtr = patt[nr];
 	if (pattPtr != NULL)
 	{
-		pattPos = editor.pattPos;
-		pattLen = pattLens[nr];
+		const int16_t pattPos = editor.pattPos;
+		const int16_t pattLen = pattLens[nr];
 
 		if (pattLen > 1)
 		{
@@ -741,18 +718,14 @@
 
 void deletePatternNote(void)
 {
-	int16_t nr, pattPos;
-	uint16_t pattLen;
-	tonTyp *pattPtr;
-
 	if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
 		return;
 
-	nr = editor.editPattern;
-	pattPos = editor.pattPos;
-	pattLen = pattLens[nr];
+	const int16_t nr = editor.editPattern;
+	int16_t pattPos = editor.pattPos;
+	const int16_t pattLen = pattLens[nr];
 
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr != NULL)
 	{
 		if (pattPos > 0)
@@ -783,18 +756,14 @@
 
 void deletePatternLine(void)
 {
-	int16_t nr, pattPos;
-	uint16_t pattLen;
-	tonTyp *pattPtr;
-
 	if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
 		return;
 
-	nr = editor.editPattern;
-	pattPos = editor.pattPos;
-	pattLen = pattLens[nr];
+	const int16_t nr = editor.editPattern;
+	int16_t pattPos = editor.pattPos;
+	const int16_t pattLen = pattLens[nr];
 
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr != NULL)
 	{
 		if (pattPos > 0)
@@ -1389,19 +1358,16 @@
 
 void cutTrack(void)
 {
-	uint16_t i, pattLen;
-	tonTyp *pattPtr;
-
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr == NULL)
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
 	if (config.ptnCutToBuffer)
 	{
 		memset(trackCopyBuff, 0, MAX_PATT_LEN * sizeof (tonTyp));
-		for (i = 0; i < pattLen; i++)
+		for (int16_t i = 0; i < pattLen; i++)
 			copyNote(&pattPtr[(i * MAX_VOICES) + cursor.ch], &trackCopyBuff[i]);
 
 		trkBufLen = pattLen;
@@ -1408,7 +1374,7 @@
 	}
 
 	pauseMusic();
-	for (i = 0; i < pattLen; i++)
+	for (int16_t i = 0; i < pattLen; i++)
 		pasteNote(&clearNote, &pattPtr[(i * MAX_VOICES) + cursor.ch]);
 	resumeMusic();
 
@@ -1420,17 +1386,14 @@
 
 void copyTrack(void)
 {
-	uint16_t i, pattLen;
-	tonTyp *pattPtr;
-
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr == NULL)
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
 	memset(trackCopyBuff, 0, MAX_PATT_LEN * sizeof (tonTyp));
-	for (i = 0; i < pattLen; i++)
+	for (int16_t i = 0; i < pattLen; i++)
 		copyNote(&pattPtr[(i * MAX_VOICES) + cursor.ch], &trackCopyBuff[i]);
 
 	trkBufLen = pattLen;
@@ -1438,17 +1401,14 @@
 
 void pasteTrack(void)
 {
-	uint16_t i, pattLen;
-	tonTyp *pattPtr;
-
 	if (trkBufLen == 0 || !allocatePattern(editor.editPattern))
 		return;
 
-	pattPtr = patt[editor.editPattern];
-	pattLen = pattLens[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
 	pauseMusic();
-	for (i = 0; i < pattLen; i++)
+	for (int16_t i = 0; i < pattLen; i++)
 		pasteNote(&trackCopyBuff[i], &pattPtr[(i * MAX_VOICES) + cursor.ch]);
 	resumeMusic();
 
@@ -1460,21 +1420,18 @@
 
 void cutPattern(void)
 {
-	uint16_t i, x, pattLen;
-	tonTyp *pattPtr;
-
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr == NULL)
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
 	if (config.ptnCutToBuffer)
 	{
 		memset(ptnCopyBuff, 0, (MAX_PATT_LEN * MAX_VOICES) * sizeof (tonTyp));
-		for (x = 0; x < song.antChn; x++)
+		for (int16_t x = 0; x < song.antChn; x++)
 		{
-			for (i = 0; i < pattLen; i++)
+			for (int16_t i = 0; i < pattLen; i++)
 				copyNote(&pattPtr[(i * MAX_VOICES) + x], &ptnCopyBuff[(i * MAX_VOICES) + x]);
 		}
 
@@ -1482,9 +1439,9 @@
 	}
 
 	pauseMusic();
-	for (x = 0; x < song.antChn; x++)
+	for (int16_t x = 0; x < song.antChn; x++)
 	{
-		for (i = 0; i < pattLen; i++)
+		for (int16_t i = 0; i < pattLen; i++)
 			pasteNote(&clearNote, &pattPtr[(i * MAX_VOICES) + x]);
 	}
 	resumeMusic();
@@ -1497,19 +1454,16 @@
 
 void copyPattern(void)
 {
-	uint16_t i, x, pattLen;
-	tonTyp *pattPtr;
-
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr == NULL)
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
 	memset(ptnCopyBuff, 0, (MAX_PATT_LEN * MAX_VOICES) * sizeof (tonTyp));
-	for (x = 0; x < song.antChn; x++)
+	for (int16_t x = 0; x < song.antChn; x++)
 	{
-		for (i = 0; i < pattLen; i++)
+		for (int16_t i = 0; i < pattLen; i++)
 			copyNote(&pattPtr[(i * MAX_VOICES) + x], &ptnCopyBuff[(i * MAX_VOICES) + x]);
 	}
 
@@ -1520,9 +1474,6 @@
 
 void pastePattern(void)
 {
-	uint16_t i, x, pattLen;
-	tonTyp *pattPtr;
-	
 	if (ptnBufLen == 0)
 		return;
 
@@ -1535,13 +1486,13 @@
 	if (!allocatePattern(editor.editPattern))
 		return;
 
-	pattPtr = patt[editor.editPattern];
-	pattLen = pattLens[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
 	pauseMusic();
-	for (x = 0; x < song.antChn; x++)
+	for (int16_t x = 0; x < song.antChn; x++)
 	{
-		for (i = 0; i < pattLen; i++)
+		for (int16_t i = 0; i < pattLen; i++)
 			pasteNote(&ptnCopyBuff[(i * MAX_VOICES) + x], &pattPtr[(i * MAX_VOICES) + x]);
 	}
 	resumeMusic();
@@ -1554,21 +1505,18 @@
 
 void cutBlock(void)
 {
-	uint16_t x, y;
-	tonTyp *pattPtr;
-
 	if (pattMark.markY1 == pattMark.markY2 || pattMark.markY1 > pattMark.markY2)
 		return;
 
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr == NULL)
 		return;
 
 	if (config.ptnCutToBuffer)
 	{
-		for (x = pattMark.markX1; x <= pattMark.markX2; x++)
+		for (int16_t x = pattMark.markX1; x <= pattMark.markX2; x++)
 		{
-			for (y = pattMark.markY1; y < pattMark.markY2; y++)
+			for (int16_t y = pattMark.markY1; y < pattMark.markY2; y++)
 			{
 				assert(x < song.antChn && y < pattLens[editor.editPattern]);
 				copyNote(&pattPtr[(y * MAX_VOICES) + x],
@@ -1578,9 +1526,9 @@
 	}
 
 	pauseMusic();
-	for (x = pattMark.markX1; x <= pattMark.markX2; x++)
+	for (int16_t x = pattMark.markX1; x <= pattMark.markX2; x++)
 	{
-		for (y = pattMark.markY1; y < pattMark.markY2; y++)
+		for (int16_t y = pattMark.markY1; y < pattMark.markY2; y++)
 			pasteNote(&clearNote, &pattPtr[(y * MAX_VOICES) + x]);
 	}
 	resumeMusic();
@@ -1597,19 +1545,16 @@
 
 void copyBlock(void)
 {
-	uint16_t x, y;
-	tonTyp *pattPtr;
-
 	if (pattMark.markY1 == pattMark.markY2 || pattMark.markY1 > pattMark.markY2)
 		return;
 
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 	if (pattPtr == NULL)
 		return;
 
-	for (x = pattMark.markX1; x <= pattMark.markX2; x++)
+	for (int16_t x = pattMark.markX1; x <= pattMark.markX2; x++)
 	{
-		for (y = pattMark.markY1; y < pattMark.markY2; y++)
+		for (int16_t y = pattMark.markY1; y < pattMark.markY2; y++)
 		{
 			assert(x < song.antChn && y < pattLens[editor.editPattern]);
 			copyNote(&pattPtr[(y * MAX_VOICES) + x],
@@ -1624,26 +1569,23 @@
 
 void pasteBlock(void)
 {
-	int32_t xpos, ypos, j, k, pattLen;
-	tonTyp *pattPtr;
-
 	if (!blockCopied || !allocatePattern(editor.editPattern))
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int16_t pattLen = pattLens[editor.editPattern];
 
-	xpos = cursor.ch;
-	ypos = editor.pattPos;
+	const int32_t xpos = cursor.ch;
+	const int32_t ypos = editor.pattPos;
 
-	j = markXSize;
+	int32_t j = markXSize;
 	if (j+xpos >= song.antChn)
 		j = song.antChn - xpos - 1;
 
-	k = markYSize;
+	int32_t k = markYSize;
 	if (k+ypos >= pattLen)
 		k = pattLen - ypos;
 
-	pattPtr = patt[editor.editPattern];
+	tonTyp *pattPtr = patt[editor.editPattern];
 
 	pauseMusic();
 	for (int32_t x = xpos; x <= xpos+j; x++)
@@ -1664,17 +1606,14 @@
 
 static void remapInstrXY(uint16_t nr, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t src, uint8_t dst)
 {
-	int32_t noteSkipLen;
-	tonTyp *pattPtr, *note;
-
 	// this routine is only used sanely, so no need to check input
 
-	pattPtr = patt[nr];
+	tonTyp *pattPtr = patt[nr];
 	if (pattPtr == NULL)
 		return;
 
-	noteSkipLen = MAX_VOICES - ((x2 + 1) - x1);
-	note = &pattPtr[(y1 * MAX_VOICES) + x1];
+	const int32_t noteSkipLen = MAX_VOICES - ((x2 + 1) - x1);
+	tonTyp *note = &pattPtr[(y1 * MAX_VOICES) + x1];
 
 	for (uint16_t y = y1; y <= y2; y++)
 	{
@@ -1741,8 +1680,6 @@
 
 void remapSong(void)
 {
-	uint8_t pattNr;
-
 	if (editor.srcInstr == editor.curInstr)
 		return;
 
@@ -1749,7 +1686,7 @@
 	pauseMusic();
 	for (int32_t i = 0; i < MAX_PATTERNS; i++)
 	{
-		pattNr = (uint8_t)i;
+		const uint8_t pattNr = (uint8_t)i;
 
 		remapInstrXY(pattNr,
 		             0, 0,
@@ -1762,9 +1699,11 @@
 	setSongModifiedFlag();
 }
 
+// "scale-fade volume" routines
+
 static int8_t getNoteVolume(tonTyp *note)
 {
-	int8_t nv, vv, ev, finalv;
+	int8_t nv, vv, ev;
 
 	if (note->vol >= 0x10 && note->vol <= 0x50)
 		vv = note->vol - 0x10;
@@ -1781,7 +1720,7 @@
 	else
 		nv = -1;
 
-	finalv = -1;
+	int8_t finalv = -1;
 	if (nv >= 0) finalv = nv;
 	if (vv >= 0) finalv = vv;
 	if (ev >= 0) finalv = ev;
@@ -1791,12 +1730,10 @@
 
 static void setNoteVolume(tonTyp *note, int8_t newVol)
 {
-	int8_t oldv;
-
 	if (newVol < 0)
 		return;
 
-	oldv = getNoteVolume(note);
+	const int8_t oldv = getNoteVolume(note);
 	if (note->vol == oldv)
 		return; // volume is the same
 
@@ -1808,23 +1745,19 @@
 
 static void scaleNote(uint16_t ptn, int8_t ch, int16_t row, double dScale)
 {
-	int32_t vol;
-	uint16_t pattLen;
-	tonTyp *note;
-
 	if (patt[ptn] == NULL)
 		return;
 
-	pattLen = pattLens[ptn];
+	const int16_t pattLen = pattLens[ptn];
 	if (row < 0 || row >= pattLen || ch < 0 || ch >= song.antChn)
 		return;
 
-	note = &patt[ptn][(row * MAX_VOICES) + ch];
+	tonTyp *note = &patt[ptn][(row * MAX_VOICES) + ch];
 
-	vol = getNoteVolume(note);
+	int32_t vol = getNoteVolume(note);
 	if (vol >= 0)
 	{
-		vol = (int32_t)round(vol * dScale);
+		vol = (int32_t)((vol * dScale) + 0.5); // rounded
 		vol = MIN(MAX(0, vol), 64);
 		setNoteVolume(note, (int8_t)vol);
 	}
@@ -1832,20 +1765,19 @@
 
 static bool askForScaleFade(char *msg)
 {
-	char *val1, *val2, volstr[32 + 1];
-	uint8_t err;
+	char volstr[32+1];
 
 	sprintf(volstr, "%0.2f,%0.2f", dVolScaleFK1, dVolScaleFK2);
 	if (inputBox(1, msg, volstr, sizeof (volstr) - 1) != 1)
 		return false;
 
-	err = false;
+	bool err = false;
 
-	val1 = volstr;
+	char *val1 = volstr;
 	if (strlen(val1) < 3)
 		err = true;
 
-	val2 = strchr(volstr, ',');
+	char *val2 = strchr(volstr, ',');
 	if (val2 == NULL || strlen(val2) < 3)
 		err = true;
 
@@ -1856,7 +1788,7 @@
 	}
 
 	dVolScaleFK1 = atof(val1);
-	dVolScaleFK2 = atof(val2 + 1);
+	dVolScaleFK2 = atof(val2+1);
 
 	return true;
 }
@@ -1863,9 +1795,6 @@
 
 void scaleFadeVolumeTrack(void)
 {
-	uint16_t pattLen;
-	double dIPy, dVol;
-
 	if (!askForScaleFade("Volume scale-fade track (start-, end scale)"))
 		return;
 
@@ -1872,16 +1801,16 @@
 	if (patt[editor.editPattern] == NULL)
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int32_t pattLen = pattLens[editor.editPattern];
 
-	dIPy = 0.0;
+	double dIPy = 0.0;
 	if (pattLen > 0)
 		dIPy = (dVolScaleFK2 - dVolScaleFK1) / pattLen;
 
-	dVol = dVolScaleFK1;
+	double dVol = dVolScaleFK1;
 
 	pauseMusic();
-	for (uint16_t row = 0; row < pattLen; row++)
+	for (int16_t row = 0; row < pattLen; row++)
 	{
 		scaleNote(editor.editPattern, cursor.ch, row, dVol);
 		dVol += dIPy;
@@ -1891,9 +1820,6 @@
 
 void scaleFadeVolumePattern(void)
 {
-	uint16_t pattLen;
-	double dIPy, dVol;
-
 	if (!askForScaleFade("Volume scale-fade pattern (start-, end scale)"))
 		return;
 
@@ -1900,18 +1826,18 @@
 	if (patt[editor.editPattern] == NULL)
 		return;
 
-	pattLen = pattLens[editor.editPattern];
+	const int32_t pattLen = pattLens[editor.editPattern];
 
-	dIPy = 0.0;
+	double dIPy = 0.0;
 	if (pattLen > 0)
 		dIPy = (dVolScaleFK2 - dVolScaleFK1) / pattLen;
 
-	dVol = dVolScaleFK1;
+	double dVol = dVolScaleFK1;
 
 	pauseMusic();
-	for (uint16_t row = 0; row < pattLen; row++)
+	for (int16_t row = 0; row < pattLen; row++)
 	{
-		for (uint8_t ch = 0; ch < song.antChn; ch++)
+		for (int8_t ch = 0; ch < song.antChn; ch++)
 			scaleNote(editor.editPattern, ch, row, dVol);
 
 		dVol += dIPy;
@@ -1921,9 +1847,6 @@
 
 void scaleFadeVolumeBlock(void)
 {
-	uint16_t dy;
-	double dIPy, dVol;
-
 	if (!askForScaleFade("Volume scale-fade block (start-, end scale)"))
 		return;
 
@@ -1930,18 +1853,18 @@
 	if (patt[editor.editPattern] == NULL || pattMark.markY1 == pattMark.markY2 || pattMark.markY1 > pattMark.markY2)
 		return;
 
-	dy = pattMark.markY2 - pattMark.markY1;
+	const int32_t dy = pattMark.markY2 - pattMark.markY1;
 
-	dIPy = 0.0;
+	double dIPy = 0.0;
 	if (dy > 0)
 		dIPy = (dVolScaleFK2 - dVolScaleFK1) / dy;
 
-	dVol = dVolScaleFK1;
+	double dVol = dVolScaleFK1;
 
 	pauseMusic();
-	for (uint16_t row = pattMark.markY1; row < pattMark.markY2; row++)
+	for (int16_t row = pattMark.markY1; row < pattMark.markY2; row++)
 	{
-		for (uint16_t ch = pattMark.markX1; ch <= pattMark.markX2; ch++)
+		for (int16_t ch = pattMark.markX1; ch <= pattMark.markX2; ch++)
 			scaleNote(editor.editPattern, (uint8_t)ch, row, dVol);
 
 		dVol += dIPy;
--- a/src/ft2_events.c
+++ b/src/ft2_events.c
@@ -255,29 +255,27 @@
 
 static void handleSysMsg(SDL_Event inputEvent)
 {
-	SDL_SysWMmsg *wmMsg;
+	if (inputEvent.type != SDL_SYSWMEVENT)
+		return;
 
-	if (inputEvent.type == SDL_SYSWMEVENT)
+	SDL_SysWMmsg *wmMsg = inputEvent.syswm.msg;
+	if (wmMsg->subsystem == SDL_SYSWM_WINDOWS && wmMsg->msg.win.msg == SYSMSG_FILE_ARG)
 	{
-		wmMsg = inputEvent.syswm.msg;
-		if (wmMsg->subsystem == SDL_SYSWM_WINDOWS && wmMsg->msg.win.msg == SYSMSG_FILE_ARG)
+		hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, SHARED_FILENAME);
+		if (hMapFile != NULL)
 		{
-			hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, SHARED_FILENAME);
-			if (hMapFile != NULL)
+			sharedMemBuf = (LPTSTR)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, ARGV_SHARED_MEM_MAX_LEN);
+			if (sharedMemBuf != NULL)
 			{
-				sharedMemBuf = (LPTSTR)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, ARGV_SHARED_MEM_MAX_LEN);
-				if (sharedMemBuf != NULL)
-				{
-					editor.autoPlayOnDrop = true;
-					loadDroppedFile((char *)sharedMemBuf, true);
+				editor.autoPlayOnDrop = true;
+				loadDroppedFile((char *)sharedMemBuf, true);
 
-					UnmapViewOfFile(sharedMemBuf);
-					sharedMemBuf = NULL;
-				}
-
-				CloseHandle(hMapFile);
-				hMapFile = NULL;
+				UnmapViewOfFile(sharedMemBuf);
+				sharedMemBuf = NULL;
 			}
+
+			CloseHandle(hMapFile);
+			hMapFile = NULL;
 		}
 	}
 }
@@ -295,12 +293,8 @@
 {
 #define BACKUP_FILES_TO_TRY 1000
 	char fileName[32];
-	uint16_t i;
-	UNICHAR *fileNameU;
 	struct stat statBuffer;
 
-	(void)ptr;
-
 	if (oneInstHandle != NULL)
 		CloseHandle(oneInstHandle);
 
@@ -309,7 +303,8 @@
 		if (getDiskOpModPath() != NULL && UNICHAR_CHDIR(getDiskOpModPath()) == 0)
 		{
 			// find a free filename
-			for (i = 1; i < 1000; i++)
+			int32_t i;
+			for (i = 1; i < BACKUP_FILES_TO_TRY; i++)
 			{
 				sprintf(fileName, "backup%03d.xm", (int32_t)i);
 				if (stat(fileName, &statBuffer) != 0)
@@ -316,9 +311,9 @@
 					break; // filename OK
 			}
 
-			if (i != 1000)
+			if (i != BACKUP_FILES_TO_TRY)
 			{
-				fileNameU = cp437ToUnichar(fileName);
+				UNICHAR *fileNameU = cp437ToUnichar(fileName);
 				if (fileNameU != NULL)
 				{
 					saveXM(fileNameU);
@@ -332,6 +327,8 @@
 	}
 
 	return EXCEPTION_CONTINUE_SEARCH;
+
+	(void)ptr;
 }
 #else
 static void exceptionHandler(int32_t signal)
@@ -338,8 +335,6 @@
 {
 #define BACKUP_FILES_TO_TRY 1000
 	char fileName[32];
-	uint16_t i;
-	UNICHAR *fileNameU;
 	struct stat statBuffer;
 
 	if (signal == 15)
@@ -350,7 +345,8 @@
 		if (getDiskOpModPath() != NULL && UNICHAR_CHDIR(getDiskOpModPath()) == 0)
 		{
 			// find a free filename
-			for (i = 1; i < 1000; i++)
+			int32_t i;
+			for (i = 1; i < BACKUP_FILES_TO_TRY; i++)
 			{
 				sprintf(fileName, "backup%03d.xm", i);
 				if (stat(fileName, &statBuffer) != 0)
@@ -357,9 +353,9 @@
 					break; // filename OK
 			}
 
-			if (i != 1000)
+			if (i != BACKUP_FILES_TO_TRY)
 			{
-				fileNameU = cp437ToUnichar(fileName);
+				UNICHAR *fileNameU = cp437ToUnichar(fileName);
 				if (fileNameU != NULL)
 				{
 					saveXM(fileNameU);
@@ -398,10 +394,7 @@
 
 static void handleInput(void)
 {
-	char *inputText;
-	uint32_t eventType;
 	SDL_Event event;
-	SDL_Keycode key;
 
 	if (!editor.busy)
 		handleLastGUIObjectDown(); // this should be handled before main input poll (on next frame)
@@ -430,11 +423,12 @@
 
 		if (editor.busy)
 		{
-			eventType = event.type;
-			key = event.key.keysym.scancode;
+			const uint32_t eventType = event.type;
+			const SDL_Keycode key = event.key.keysym.scancode;
 
-			/* The Echo tool in Smp. Ed. can literally take forever if abused,
-			** let mouse buttons/ESC/SIGTERM force-stop it. */
+			/* The Echo tool in Smp. Ed. can take forever if abused, let
+			** mouse buttons/ESC/SIGTERM force-stop it.
+			*/
 			if (eventType == SDL_MOUSEBUTTONDOWN || eventType == SDL_QUIT ||
 				(eventType == SDL_KEYUP && key == SDL_SCANCODE_ESCAPE))
 			{
@@ -471,7 +465,7 @@
 					continue;
 				}
 
-				inputText = utf8ToCp437(event.text.text, false);
+				char *inputText = utf8ToCp437(event.text.text, false);
 				if (inputText != NULL)
 				{
 					if (inputText[0] != '\0')
@@ -542,7 +536,7 @@
 
 #ifdef HAS_MIDI
 	// MIDI vibrato
-	uint8_t vibDepth = (midi.currMIDIVibDepth >> 9) & 0x0F;
+	const uint8_t vibDepth = (midi.currMIDIVibDepth >> 9) & 0x0F;
 	if (vibDepth > 0)
 		recordMIDIEffect(0x04, 0xA0 | vibDepth);
 #endif
--- a/src/ft2_gui.c
+++ b/src/ft2_gui.c
@@ -43,14 +43,9 @@
 
 void unstuckLastUsedGUIElement(void)
 {
-	pushButton_t *p;
-	radioButton_t *r;
-	checkBox_t *c;
-	scrollBar_t *s;
-
 	if (mouse.lastUsedObjectID == OBJECT_ID_NONE)
 	{
-		/* if last object ID is OBJECT_ID_NONE, check if we moved the
+		/* If last object ID is OBJECT_ID_NONE, check if we moved the
 		** sample data loop pins, and unstuck them if so
 		*/
 
@@ -77,7 +72,7 @@
 		case OBJECT_PUSHBUTTON:
 		{
 			assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_PUSHBUTTONS);
-			p = &pushButtons[mouse.lastUsedObjectID];
+			pushButton_t *p = &pushButtons[mouse.lastUsedObjectID];
 			if (p->state == PUSHBUTTON_PRESSED)
 			{
 				p->state = PUSHBUTTON_UNPRESSED;
@@ -90,7 +85,7 @@
 		case OBJECT_RADIOBUTTON:
 		{
 			assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_RADIOBUTTONS);
-			r = &radioButtons[mouse.lastUsedObjectID];
+			radioButton_t *r = &radioButtons[mouse.lastUsedObjectID];
 			if (r->state == RADIOBUTTON_PRESSED)
 			{
 				r->state = RADIOBUTTON_UNCHECKED;
@@ -103,7 +98,7 @@
 		case OBJECT_CHECKBOX:
 		{
 			assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_CHECKBOXES);
-			c = &checkBoxes[mouse.lastUsedObjectID];
+			checkBox_t *c = &checkBoxes[mouse.lastUsedObjectID];
 			if (c->state == CHECKBOX_PRESSED)
 			{
 				c->state = CHECKBOX_UNPRESSED;
@@ -116,7 +111,7 @@
 		case OBJECT_SCROLLBAR:
 		{
 			assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_SCROLLBARS);
-			s = &scrollBars[mouse.lastUsedObjectID];
+			scrollBar_t *s = &scrollBars[mouse.lastUsedObjectID];
 			if (s->state == SCROLLBAR_PRESSED)
 			{
 				s->state = SCROLLBAR_UNPRESSED;
@@ -133,11 +128,6 @@
 bool setupGUI(void)
 {
 	int32_t i;
-	textBox_t *t;
-	pushButton_t *p;
-	checkBox_t *c;
-	radioButton_t *r;
-	scrollBar_t *s;
 
 	// all memory will be NULL-tested and free'd if we return false somewhere in this function
 
@@ -149,10 +139,9 @@
 
 	// set uninitialized GUI struct entries
 
-	for (i = 1; i < NUM_TEXTBOXES; i++) // skip first entry, it's reserved for inputBox())
+	textBox_t *t = &textBoxes[1]; // skip first entry, it's reserved for inputBox())
+	for (i = 1; i < NUM_TEXTBOXES; i++, t++)
 	{
-		t = &textBoxes[i];
-
 		t->visible = false;
 		t->bufOffset = 0;
 		t->cursorPos = 0;
@@ -166,10 +155,9 @@
 			goto setupGUI_OOM;
 	}
 
-	for (i = 0; i < NUM_PUSHBUTTONS; i++)
+	pushButton_t *p = pushButtons;
+	for (i = 0; i < NUM_PUSHBUTTONS; i++, p++)
 	{
-		p = &pushButtons[i];
-
 		p->state = 0;
 		p->visible = false;
 
@@ -185,27 +173,24 @@
 		}
 	}
 
-	for (i = 0; i < NUM_CHECKBOXES; i++)
+	checkBox_t *c = checkBoxes;
+	for (i = 0; i < NUM_CHECKBOXES; i++, c++)
 	{
-		c = &checkBoxes[i];
-
 		c->state = 0;
 		c->checked = false;
 		c->visible = false;
 	}
 
-	for (i = 0; i < NUM_RADIOBUTTONS; i++)
+	radioButton_t *r = radioButtons;
+	for (i = 0; i < NUM_RADIOBUTTONS; i++, r++)
 	{
-		r = &radioButtons[i];
-
 		r->state = 0;
 		r->visible = false;
 	}
 
-	for (i = 0; i < NUM_SCROLLBARS; i++)
+	scrollBar_t *s = scrollBars;
+	for (i = 0; i < NUM_SCROLLBARS; i++, s++)
 	{
-		s = &scrollBars[i];
-
 		s->visible = false;
 		s->state = 0;
 		s->pos = 0;
@@ -253,11 +238,9 @@
 // return full pixel width of a text string
 uint16_t textWidth(const char *textPtr)
 {
-	uint16_t textWidth;
-
 	assert(textPtr != NULL);
 
-	textWidth = 0;
+	uint16_t textWidth = 0;
 	while (*textPtr != '\0')
 		textWidth += charWidth(*textPtr++);
 
@@ -270,15 +253,12 @@
 
 uint16_t textNWidth(const char *textPtr, int32_t length)
 {
-	char ch;
-	uint16_t textWidth;
-
 	assert(textPtr != NULL);
 
-	textWidth = 0;
+	uint16_t textWidth = 0;
 	for (int32_t i = 0; i < length; i++)
 	{
-		ch = textPtr[i];
+		const char ch = textPtr[i];
 		if (ch == '\0')
 			break;
 
@@ -295,11 +275,9 @@
 // return full pixel width of a text string (big font)
 uint16_t textWidth16(const char *textPtr)
 {
-	uint16_t textWidth;
-
 	assert(textPtr != NULL);
 
-	textWidth = 0;
+	uint16_t textWidth = 0;
 	while (*textPtr != '\0')
 		textWidth += charWidth(*textPtr++);
 
@@ -312,12 +290,6 @@
 
 void charOut(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, char chr)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, pixVal;
-#ifndef __arm__
-	uint32_t tmp;
-#endif
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	chr &= 0x7F; // this is important to get the nordic glyphs in the font
@@ -324,9 +296,9 @@
 	if (chr == ' ')
 		return;
 
-	pixVal = video.palette[paletteIndex];
-	srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t pixVal = video.palette[paletteIndex];
+	const uint8_t *srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
 	for (uint32_t y = 0; y < FONT1_CHAR_H; y++)
 	{
@@ -337,7 +309,7 @@
 				dstPtr[x] = pixVal;
 #else
 			// carefully written like this to generate conditional move instructions (font data is hard to predict)
-			tmp = dstPtr[x];
+			uint32_t tmp = dstPtr[x];
 			if (srcPtr[x] != 0) tmp = pixVal;
 			dstPtr[x] = tmp;
 #endif
@@ -348,11 +320,8 @@
 	}
 }
 
-static void charOutFade(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, char chr, int32_t fade)
+static void charOutFade(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, char chr, int32_t fade) // for about screen
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, pixVal;
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	chr &= 0x7F; // this is important to get the nordic glyphs in the font
@@ -359,19 +328,19 @@
 	if (chr == ' ')
 		return;
 
-	pixVal = video.palette[paletteIndex];
-	srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t pixVal = video.palette[paletteIndex];
+	const uint8_t *srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
-	for (uint32_t y = 0; y < FONT1_CHAR_H; y++)
+	for (int32_t y = 0; y < FONT1_CHAR_H; y++)
 	{
-		for (uint32_t x = 0; x < FONT1_CHAR_W; x++)
+		for (int32_t x = 0; x < FONT1_CHAR_W; x++)
 		{
 			if (srcPtr[x] != 0)
 			{
-				int32_t r = (RGB32_R(pixVal) * fade) >> 8;
-				int32_t g = (RGB32_G(pixVal) * fade) >> 8;
-				int32_t b = (RGB32_B(pixVal) * fade) >> 8;
+				const int32_t r = (RGB32_R(pixVal) * fade) >> 8;
+				const int32_t g = (RGB32_G(pixVal) * fade) >> 8;
+				const int32_t b = (RGB32_B(pixVal) * fade) >> 8;
 
 				dstPtr[x] = RGB32(r, g, b) | 0xFF000000;
 			}
@@ -384,9 +353,6 @@
 
 void charOutBg(uint16_t xPos, uint16_t yPos, uint8_t fgPalette, uint8_t bgPalette, char chr)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, fg, bg;
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	chr &= 0x7F; // this is important to get the nordic glyphs in the font
@@ -393,15 +359,15 @@
 	if (chr == ' ')
 		return;
 
-	fg = video.palette[fgPalette];
-	bg = video.palette[bgPalette];
+	const uint32_t fg = video.palette[fgPalette];
+	const uint32_t bg = video.palette[bgPalette];
 
-	srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint8_t *srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
-	for (uint32_t y = 0; y < FONT1_CHAR_H; y++)
+	for (int32_t y = 0; y < FONT1_CHAR_H; y++)
 	{
-		for (uint32_t x = 0; x < FONT1_CHAR_W-1; x++)
+		for (int32_t x = 0; x < FONT1_CHAR_W-1; x++)
 			dstPtr[x] = srcPtr[x] ? fg : bg; // compiles nicely into conditional move instructions
 
 		srcPtr += FONT1_WIDTH;
@@ -421,12 +387,6 @@
 
 void charOutShadow(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, uint8_t shadowPaletteIndex, char chr)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr1, *dstPtr2, pixVal1, pixVal2;
-#ifndef __arm__
-	uint32_t tmp;
-#endif
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	chr &= 0x7F; // this is important to get the nordic glyphs in the font
@@ -433,15 +393,15 @@
 	if (chr == ' ')
 		return;
 
-	pixVal1 = video.palette[paletteIndex];
-	pixVal2 = video.palette[shadowPaletteIndex];
-	srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
-	dstPtr1 = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	dstPtr2 = dstPtr1 + (SCREEN_W+1);
+	const uint32_t pixVal1 = video.palette[paletteIndex];
+	const uint32_t pixVal2 = video.palette[shadowPaletteIndex];
+	const uint8_t *srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
+	uint32_t *dstPtr1 = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	uint32_t *dstPtr2 = dstPtr1 + (SCREEN_W+1);
 
-	for (uint32_t y = 0; y < FONT1_CHAR_H; y++)
+	for (int32_t y = 0; y < FONT1_CHAR_H; y++)
 	{
-		for (uint32_t x = 0; x < FONT1_CHAR_W; x++)
+		for (int32_t x = 0; x < FONT1_CHAR_W; x++)
 		{
 #ifdef __arm__
 			if (srcPtr[x] != 0)
@@ -451,7 +411,7 @@
 			}
 #else
 			// carefully written like this to generate conditional move instructions (font data is hard to predict)
-			tmp = dstPtr2[x];
+			uint32_t tmp = dstPtr2[x];
 			if (srcPtr[x] != 0) tmp = pixVal2;
 			dstPtr2[x] = tmp;
 
@@ -469,13 +429,6 @@
 
 void charOutClipX(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, char chr, uint16_t clipX)
 {
-	const uint8_t *srcPtr;
-	uint16_t width;
-	uint32_t *dstPtr, pixVal;
-#ifndef __arm__
-	uint32_t tmp;
-#endif
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	if (xPos > clipX)
@@ -485,17 +438,17 @@
 	if (chr == ' ')
 		return;
 
-	pixVal = video.palette[paletteIndex];
-	srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t pixVal = video.palette[paletteIndex];
+	const uint8_t *srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
-	width = FONT1_CHAR_W;
+	int32_t width = FONT1_CHAR_W;
 	if (xPos+width > clipX)
 		width = FONT1_CHAR_W - ((xPos + width) - clipX);
 
-	for (uint32_t y = 0; y < FONT1_CHAR_H; y++)
+	for (int32_t y = 0; y < FONT1_CHAR_H; y++)
 	{
-		for (uint32_t x = 0; x < width; x++)
+		for (int32_t x = 0; x < width; x++)
 		{
 #ifdef __arm__
 			if (srcPtr[x] != 0)
@@ -502,7 +455,7 @@
 				dstPtr[x] = pixVal;
 #else
 			// carefully written like this to generate conditional move instructions (font data is hard to predict)
-			tmp = dstPtr[x];
+			uint32_t tmp = dstPtr[x];
 			if (srcPtr[x] != 0) tmp = pixVal;
 			dstPtr[x] = tmp;
 #endif
@@ -515,12 +468,6 @@
 
 void bigCharOut(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, char chr)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, pixVal;
-#ifndef __arm__
-	uint32_t tmp;
-#endif
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	chr &= 0x7F; // this is important to get the nordic glyphs in the font
@@ -527,13 +474,13 @@
 	if (chr == ' ')
 		return;
 
-	srcPtr = &bmp.font2[chr * FONT2_CHAR_W];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	pixVal = video.palette[paletteIndex];
+	const uint8_t *srcPtr = &bmp.font2[chr * FONT2_CHAR_W];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t pixVal = video.palette[paletteIndex];
 
-	for (uint32_t y = 0; y < FONT2_CHAR_H; y++)
+	for (int32_t y = 0; y < FONT2_CHAR_H; y++)
 	{
-		for (uint32_t x = 0; x < FONT2_CHAR_W; x++)
+		for (int32_t x = 0; x < FONT2_CHAR_W; x++)
 		{
 #ifdef __arm__
 			if (srcPtr[x] != 0)
@@ -540,7 +487,7 @@
 				dstPtr[x] = pixVal;
 #else
 			// carefully written like this to generate conditional move instructions (font data is hard to predict)
-			tmp = dstPtr[x];
+			uint32_t tmp = dstPtr[x];
 			if (srcPtr[x] != 0) tmp = pixVal;
 			dstPtr[x] = tmp;
 #endif
@@ -553,12 +500,6 @@
 
 static void bigCharOutShadow(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, uint8_t shadowPaletteIndex, char chr)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr1, *dstPtr2, pixVal1, pixVal2;
-#ifndef __arm__
-	uint32_t tmp;
-#endif
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
 	chr &= 0x7F; // this is important to get the nordic glyphs in the font
@@ -565,15 +506,15 @@
 	if (chr == ' ')
 		return;
 
-	pixVal1 = video.palette[paletteIndex];
-	pixVal2 = video.palette[shadowPaletteIndex];
-	srcPtr = &bmp.font2[chr * FONT2_CHAR_W];
-	dstPtr1 = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	dstPtr2 = dstPtr1 + (SCREEN_W+1);
+	const uint32_t pixVal1 = video.palette[paletteIndex];
+	const uint32_t pixVal2 = video.palette[shadowPaletteIndex];
+	const uint8_t *srcPtr = &bmp.font2[chr * FONT2_CHAR_W];
+	uint32_t *dstPtr1 = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	uint32_t *dstPtr2 = dstPtr1 + (SCREEN_W+1);
 
-	for (uint32_t y = 0; y < FONT2_CHAR_H; y++)
+	for (int32_t y = 0; y < FONT2_CHAR_H; y++)
 	{
-		for (uint32_t x = 0; x < FONT2_CHAR_W; x++)
+		for (int32_t x = 0; x < FONT2_CHAR_W; x++)
 		{
 #ifdef __arm__
 			if (srcPtr[x] != 0)
@@ -583,7 +524,7 @@
 			}
 #else
 			// carefully written like this to generate conditional move instructions (font data is hard to predict)
-			tmp = dstPtr2[x];
+			uint32_t tmp = dstPtr2[x];
 			if (srcPtr[x] != 0) tmp = pixVal2;
 			dstPtr2[x] = tmp;
 
@@ -601,15 +542,12 @@
 
 void textOut(uint16_t x, uint16_t y, uint8_t paletteIndex, const char *textPtr)
 {
-	char chr;
-	uint16_t currX;
-
 	assert(textPtr != NULL);
 
-	currX = x;
+	uint16_t currX = x;
 	while (true)
 	{
-		chr = *textPtr++;
+		const char chr = *textPtr++;
 		if (chr == '\0')
 			break;
 
@@ -618,8 +556,7 @@
 	}
 }
 
-// for about screen
-void textOutFade(uint16_t x, uint16_t y, uint8_t paletteIndex, const char *textPtr, int32_t fade)
+void textOutFade(uint16_t x, uint16_t y, uint8_t paletteIndex, const char *textPtr, int32_t fade) // for about screen
 {
 	char chr;
 	uint16_t currX;
@@ -651,15 +588,12 @@
 // fixed width
 void textOutFixed(uint16_t x, uint16_t y, uint8_t fgPaltete, uint8_t bgPalette, const char *textPtr)
 {
-	char chr;
-	uint16_t currX;
-
 	assert(textPtr != NULL);
 
-	currX = x;
+	uint16_t currX = x;
 	while (true)
 	{
-		chr = *textPtr++;
+		const char chr = *textPtr++;
 		if (chr == '\0')
 			break;
 
@@ -670,15 +604,12 @@
 
 void textOutShadow(uint16_t x, uint16_t y, uint8_t paletteIndex, uint8_t shadowPaletteIndex, const char *textPtr)
 {
-	char chr;
-	uint16_t currX;
-
 	assert(textPtr != NULL);
 
-	currX = x;
+	uint16_t currX = x;
 	while (true)
 	{
-		chr = *textPtr++;
+		const char chr = *textPtr++;
 		if (chr == '\0')
 			break;
 
@@ -689,15 +620,12 @@
 
 void bigTextOut(uint16_t x, uint16_t y, uint8_t paletteIndex, const char *textPtr)
 {
-	char chr;
-	uint16_t currX;
-
 	assert(textPtr != NULL);
 
-	currX = x;
+	uint16_t currX = x;
 	while (true)
 	{
-		chr = *textPtr++;
+		const char chr = *textPtr++;
 		if (chr == '\0')
 			break;
 
@@ -708,15 +636,12 @@
 
 void bigTextOutShadow(uint16_t x, uint16_t y, uint8_t paletteIndex, uint8_t shadowPaletteIndex, const char *textPtr)
 {
-	char chr;
-	uint16_t currX;
-
 	assert(textPtr != NULL);
 
-	currX = x;
+	uint16_t currX = x;
 	while (true)
 	{
-		chr = *textPtr++;
+		const char chr = *textPtr++;
 		if (chr == '\0')
 			break;
 
@@ -727,15 +652,12 @@
 
 void textOutClipX(uint16_t x, uint16_t y, uint8_t paletteIndex, const char *textPtr, uint16_t clipX)
 {
-	char chr;
-	uint16_t currX;
-
 	assert(textPtr != NULL);
 
-	currX = x;
+	uint16_t currX = x;
 	while (true)
 	{
-		chr = *textPtr++;
+		const char chr = *textPtr++;
 		if (chr == '\0')
 			break;
 
@@ -749,25 +671,19 @@
 
 void hexOut(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, uint32_t val, uint8_t numDigits)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, pixVal;
-#ifndef __arm__
-	uint32_t tmp;
-#endif
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
-	pixVal = video.palette[paletteIndex];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t pixVal = video.palette[paletteIndex];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
 	for (int32_t i = numDigits-1; i >= 0; i--)
 	{
-		srcPtr = &bmp.font6[((val >> (i * 4)) & 15) * FONT6_CHAR_W];
+		const uint8_t *srcPtr = &bmp.font6[((val >> (i * 4)) & 15) * FONT6_CHAR_W];
 
 		// render glyph
-		for (uint32_t y = 0; y < FONT6_CHAR_H; y++)
+		for (int32_t y = 0; y < FONT6_CHAR_H; y++)
 		{
-			for (uint32_t x = 0; x < FONT6_CHAR_W; x++)
+			for (int32_t x = 0; x < FONT6_CHAR_W; x++)
 			{
 #ifdef __arm__
 				if (srcPtr[x] != 0)
@@ -774,7 +690,7 @@
 					dstPtr[x] = pixVal;
 #else
 				// carefully written like this to generate conditional move instructions (font data is hard to predict)
-				tmp = dstPtr[x];
+				uint32_t tmp = dstPtr[x];
 				if (srcPtr[x] != 0) tmp = pixVal;
 				dstPtr[x] = tmp;
 #endif
@@ -790,24 +706,21 @@
 
 void hexOutBg(uint16_t xPos, uint16_t yPos, uint8_t fgPalette, uint8_t bgPalette, uint32_t val, uint8_t numDigits)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, fg, bg;
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H);
 
-	fg = video.palette[fgPalette];
-	bg = video.palette[bgPalette];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t fg = video.palette[fgPalette];
+	const uint32_t bg = video.palette[bgPalette];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
 	for (int32_t i = numDigits-1; i >= 0; i--)
 	{
 		// extract current nybble and set pointer to glyph
-		srcPtr = &bmp.font6[((val >> (i * 4)) & 15) * FONT6_CHAR_W];
+		const uint8_t *srcPtr = &bmp.font6[((val >> (i * 4)) & 15) * FONT6_CHAR_W];
 
 		// render glyph
-		for (uint32_t y = 0; y < FONT6_CHAR_H; y++)
+		for (int32_t y = 0; y < FONT6_CHAR_H; y++)
 		{
-			for (uint32_t x = 0; x < FONT6_CHAR_W; x++)
+			for (int32_t x = 0; x < FONT6_CHAR_W; x++)
 				dstPtr[x] = srcPtr[x] ? fg : bg; // compiles nicely into conditional move instructions
 
 			srcPtr += FONT6_WIDTH;
@@ -828,16 +741,14 @@
 
 void clearRect(uint16_t xPos, uint16_t yPos, uint16_t w, uint16_t h)
 {
-	uint32_t *dstPtr, fillNumDwords;
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H && (xPos + w) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	fillNumDwords = w * sizeof (int32_t);
+	const uint32_t width = w * sizeof (int32_t);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		memset(dstPtr, 0, fillNumDwords);
+		memset(dstPtr, 0, width);
 		dstPtr += SCREEN_W;
 	}
 }
@@ -844,16 +755,14 @@
 
 void fillRect(uint16_t xPos, uint16_t yPos, uint16_t w, uint16_t h, uint8_t paletteIndex)
 {
-	uint32_t *dstPtr, pixVal;
-
 	assert(xPos < SCREEN_W && yPos < SCREEN_H && (xPos + w) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	pixVal = video.palette[paletteIndex];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint32_t pixVal = video.palette[paletteIndex];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
 
-	for (uint32_t y = 0; y < h; y++)
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < w; x++)
+		for (int32_t x = 0; x < w; x++)
 			dstPtr[x] = pixVal;
 
 		dstPtr += SCREEN_W;
@@ -862,14 +771,12 @@
 
 void blit32(uint16_t xPos, uint16_t yPos, const uint32_t* srcPtr, uint16_t w, uint16_t h)
 {
-	uint32_t* dstPtr;
-
 	assert(srcPtr != NULL && xPos < SCREEN_W && yPos < SCREEN_H && (xPos + w) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < w; x++)
+		for (int32_t x = 0; x < w; x++)
 		{
 			if (srcPtr[x] != 0x00FF00)
 				dstPtr[x] = srcPtr[x] | 0xFF000000; // most significant 8 bits = palette number. 0xFF because no true palette
@@ -880,26 +787,23 @@
 	}
 }
 
-// for about screen
-void blit32Fade(uint16_t xPos, uint16_t yPos, const uint32_t* srcPtr, uint16_t w, uint16_t h, int32_t fade)
+void blit32Fade(uint16_t xPos, uint16_t yPos, const uint32_t* srcPtr, uint16_t w, uint16_t h, int32_t fade) // for about screen
 {
-	uint32_t* dstPtr;
-
 	assert(srcPtr != NULL && xPos < SCREEN_W && yPos < SCREEN_H && (xPos + w) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < w; x++)
+		for (int32_t x = 0; x < w; x++)
 		{
-			if (srcPtr[x] != 0x00FF00)
+			const uint32_t pixel = srcPtr[x];
+			if (pixel != 0x00FF00)
 			{
-				const uint32_t pixel = srcPtr[x];
-				int32_t r = (RGB32_R(pixel) * fade) >> 8;
-				int32_t g = (RGB32_G(pixel) * fade) >> 8;
-				int32_t b = (RGB32_B(pixel) * fade) >> 8;
+				const int32_t r = (RGB32_R(pixel) * fade) >> 8;
+				const int32_t g = (RGB32_G(pixel) * fade) >> 8;
+				const int32_t b = (RGB32_B(pixel) * fade) >> 8;
 
-				dstPtr[x] = RGB32(r, g, b) | 0xFF000000;
+				dstPtr[x] = RGB32(r, g, b) | 0xFF000000; // most significant 8 bits = palette number. 0xFF because no true palette
 			}
 		}
 
@@ -910,17 +814,16 @@
 
 void blit(uint16_t xPos, uint16_t yPos, const uint8_t *srcPtr, uint16_t w, uint16_t h)
 {
-	uint32_t *dstPtr;
-
 	assert(srcPtr != NULL && xPos < SCREEN_W && yPos < SCREEN_H && (xPos + w) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < w; x++)
+		for (int32_t x = 0; x < w; x++)
 		{
-			if (srcPtr[x] != PAL_TRANSPR)
-				dstPtr[x] = video.palette[srcPtr[x]];
+			const uint32_t pixel = srcPtr[x];
+			if (pixel != PAL_TRANSPR)
+				dstPtr[x] = video.palette[pixel];
 		}
 
 		srcPtr += w;
@@ -930,20 +833,19 @@
 
 void blitClipX(uint16_t xPos, uint16_t yPos, const uint8_t *srcPtr, uint16_t w, uint16_t h, uint16_t clipX)
 {
-	uint32_t *dstPtr;
-
 	if (clipX > w)
 		clipX = w;
 
 	assert(srcPtr != NULL && xPos < SCREEN_W && yPos < SCREEN_H && (xPos + clipX) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < clipX; x++)
+		for (int32_t x = 0; x < clipX; x++)
 		{
-			if (srcPtr[x] != PAL_TRANSPR)
-				dstPtr[x] = video.palette[srcPtr[x]];
+			const uint32_t pixel = srcPtr[x];
+			if (pixel != PAL_TRANSPR)
+				dstPtr[x] = video.palette[pixel];
 		}
 
 		srcPtr += w;
@@ -953,14 +855,12 @@
 
 void blitFast(uint16_t xPos, uint16_t yPos, const uint8_t *srcPtr, uint16_t w, uint16_t h) // no transparency/colorkey
 {
-	uint32_t *dstPtr;
-
 	assert(srcPtr != NULL && xPos < SCREEN_W && yPos < SCREEN_H && (xPos + w) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < w; x++)
+		for (int32_t x = 0; x < w; x++)
 			dstPtr[x] = video.palette[srcPtr[x]];
 
 		srcPtr += w;
@@ -970,17 +870,15 @@
 
 void blitFastClipX(uint16_t xPos, uint16_t yPos, const uint8_t *srcPtr, uint16_t w, uint16_t h, uint16_t clipX) // no transparency/colorkey
 {
-	uint32_t *dstPtr;
-
 	if (clipX > w)
 		clipX = w;
 
 	assert(srcPtr != NULL && xPos < SCREEN_W && yPos < SCREEN_H && (xPos + clipX) <= SCREEN_W && (yPos + h) <= SCREEN_H);
 
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	for (uint32_t y = 0; y < h; y++)
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	for (int32_t y = 0; y < h; y++)
 	{
-		for (uint32_t x = 0; x < clipX; x++)
+		for (int32_t x = 0; x < clipX; x++)
 			dstPtr[x] = video.palette[srcPtr[x]];
 
 		srcPtr += w;
@@ -992,27 +890,23 @@
 
 void hLine(uint16_t x, uint16_t y, uint16_t w, uint8_t paletteIndex)
 {
-	uint32_t *dstPtr, pixVal;
-
 	assert(x < SCREEN_W && y < SCREEN_H && (x + w) <= SCREEN_W);
 
-	pixVal = video.palette[paletteIndex];
+	const uint32_t pixVal = video.palette[paletteIndex];
 
-	dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
-	for (uint32_t i = 0; i < w; i++)
+	uint32_t *dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
+	for (int32_t i = 0; i < w; i++)
 		dstPtr[i] = pixVal;
 }
 
 void vLine(uint16_t x, uint16_t y, uint16_t h, uint8_t paletteIndex)
 {
-	uint32_t *dstPtr, pixVal;
-
 	assert(x < SCREEN_W && y < SCREEN_H && (y + h) <= SCREEN_W);
 
-	pixVal = video.palette[paletteIndex];
+	const uint32_t pixVal = video.palette[paletteIndex];
 
-	dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
-	for (uint32_t i = 0; i < h; i++)
+	uint32_t *dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
+	for (int32_t i = 0; i < h; i++)
 	{
 		*dstPtr = pixVal;
 		 dstPtr += SCREEN_W;
@@ -1033,29 +927,23 @@
 
 void line(int16_t x1, int16_t x2, int16_t y1, int16_t y2, uint8_t paletteIndex)
 {
-	int16_t d, x, y, sx, sy, dx, dy;
-	uint16_t ax, ay;
-	int32_t pitch;
-	uint32_t pixVal, *dst32;
+	const int16_t dx = x2 - x1;
+	const uint16_t ax = ABS(dx) * 2;
+	const int16_t sx = SGN(dx);
+	const int16_t dy = y2 - y1;
+	const uint16_t ay = ABS(dy) * 2;
+	const int16_t sy = SGN(dy);
+	int16_t x = x1;
+	int16_t y  = y1;
 
-	// get coefficients
-	dx = x2 - x1;
-	ax = ABS(dx) * 2;
-	sx = SGN(dx);
-	dy = y2 - y1;
-	ay = ABS(dy) * 2;
-	sy = SGN(dy);
-	x  = x1;
-	y  = y1;
+	uint32_t pixVal = video.palette[paletteIndex];
+	const int32_t pitch  = sy * SCREEN_W;
+	uint32_t *dst32  = &video.frameBuffer[(y * SCREEN_W) + x];
 
-	pixVal = video.palette[paletteIndex];
-	pitch  = sy * SCREEN_W;
-	dst32  = &video.frameBuffer[(y * SCREEN_W) + x];
-
 	// draw line
 	if (ax > ay)
 	{
-		d = ay - (ax / 2);
+		int16_t d = ay - (ax >> 1);
 		while (true)
 		{
 			*dst32 = pixVal;
@@ -1075,7 +963,7 @@
 	}
 	else
 	{
-		d = ax - (ay / 2);
+		int16_t d = ax - (ay >> 1);
 		while (true)
 		{
 			*dst32 = pixVal;
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
 #endif
 #include "ft2_replayer.h"
 
-#define PROG_VER_STR "1.40"
+#define PROG_VER_STR "1.41"
 
 // do NOT change these! It will only mess things up...
 
--- a/src/ft2_help.c
+++ b/src/ft2_help.c
@@ -51,8 +51,6 @@
 
 static bool getLine(char *output)
 {
-	uint8_t strLen;
-
 	if (helpBufferPos >= (int32_t)sizeof (helpData))
 	{
 		*output = '\0';
@@ -59,7 +57,7 @@
 		return false;
 	}
 
-	strLen = helpData[helpBufferPos++];
+	const uint8_t strLen = helpData[helpBufferPos++];
 	memcpy(output, &helpData[helpBufferPos], strLen);
 	output[strLen] = '\0';
 
@@ -85,12 +83,10 @@
 
 static char *rtrim(char *s)
 {
-	int32_t i;
-
 	if (*s == '\0')
 		return (s);
 
-	i = (int32_t)strlen(s) - 1;
+	int32_t i = (int32_t)strlen(s) - 1;
 	while (i >= 0)
 	{
 		if (s[i] != ' ')
@@ -107,12 +103,10 @@
 
 static void readHelp(void) // this is really messy, directly ported from Pascal code...
 {
-	char text[256], text2[256], *s, *sEnd, *s2, *s3;
-	uint8_t currColor;
-	int16_t a, b, i, k, currKol, strLen;
-	helpRec *tempText, *t;
+	char text[256], text2[256], *s, *sEnd, *s3;
+	int16_t a, b, i, k;
 
-	tempText = (helpRec *)malloc(HELP_SIZE * MAX_HELP_LINES);
+	helpRec *tempText = (helpRec *)malloc(HELP_SIZE * MAX_HELP_LINES);
 	if (tempText == NULL)
 	{
 		okBox(0, "System message", "Not enough memory!");
@@ -122,14 +116,14 @@
 	text[0] = '\0';
 	text2[0] = '\0';
 
-	s2 = text2;
+	char *s2 = text2;
 
 	helpBufferPos = 0;
 	for (int16_t subj = 0; subj < MAX_SUBJ; subj++)
 	{
-		textLine  = 0;
-		currKol   = 0;
-		currColor = PAL_FORGRND;
+		textLine = 0;
+		int16_t currKol = 0;
+		uint8_t currColor = PAL_FORGRND;
 
 		getLine(text); s = text;
 		while (strncmp(s, "END", 3) != 0)
@@ -161,7 +155,7 @@
 					s += 5;
 				}
 
-				t = &tempText[textLine];
+				helpRec *t = &tempText[textLine];
 				t->xPos = currKol;
 				t->color = currColor;
 				t->bigFont = true;
@@ -202,22 +196,22 @@
 					addText(&tempText[textLine], currKol, currColor, s2);
 				}
 
-				strLen = (int16_t)strlen(s);
+				int16_t sLen = (int16_t)strlen(s);
 
-				sEnd = &s[strLen];
+				sEnd = &s[sLen];
 				while (s < sEnd)
 				{
-					if (strLen < 0)
-						strLen = 0;
+					if (sLen < 0)
+						sLen = 0;
 
 					i = 0;
-					while (s[i] != ' ' && i < strLen) i++;
+					while (s[i] != ' ' && i < sLen) i++;
 					i++;
 
 					if (*(uint16_t *)s == 0x5440) // @T - "set absolute X position (in the middle of text)"
 					{
 						k = controlCodeToNum(&s[2]);
-						s += 5; strLen -= 5;
+						s += 5; sLen -= 5;
 
 						s3 = &s2[strlen(s2)];
 						while (textWidth(s2) + charWidth(' ') + 1 < k-currKol)
@@ -242,7 +236,7 @@
 
 					strncat(s2, s, i);
 
-					s += i; strLen -= i;
+					s += i; sLen -= i;
 					if ((*s == '\0') || (s >= sEnd))
 						strcat(s2, " ");
 				}
@@ -270,28 +264,23 @@
 
 static void bigTextOutHalf(uint16_t xPos, uint16_t yPos, uint8_t paletteIndex, bool lowerHalf, const char *textPtr)
 {
-	char chr;
-	const uint8_t *srcPtr;
-	uint16_t currX;
-	uint32_t *dstPtr, pixVal;
-
 	assert(textPtr != NULL);
 
-	currX = xPos;
+	uint16_t currX = xPos;
 	while (true)
 	{
-		chr = *textPtr++ & 0x7F;
+		const char chr = *textPtr++ & 0x7F;
 		if (chr == '\0')
 			break;
 
 		if (chr != ' ')
 		{
-			srcPtr = &bmp.font2[chr * FONT2_CHAR_W];
+			const uint8_t *srcPtr = &bmp.font2[chr * FONT2_CHAR_W];
 			if (!lowerHalf)
 				srcPtr += (FONT2_CHAR_H / 2) * FONT2_WIDTH;
 
-			dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + currX];
-			pixVal = video.palette[paletteIndex];
+			uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + currX];
+			const uint32_t pixVal = video.palette[paletteIndex];
 
 			for (uint32_t y = 0; y < FONT2_CHAR_H/2; y++)
 			{
@@ -312,16 +301,13 @@
 
 static void writeHelp(void)
 {
-	int16_t k;
-	helpRec *pek;
-
-	pek = subjPtrArr[fHlp_Nr];
+	helpRec *pek = subjPtrArr[fHlp_Nr];
 	if (pek == NULL)
 		return;
 
 	for (int16_t i = 0; i < HELP_LINES; i++)
 	{
-		k = i + fHlp_Line;
+		const int16_t k = i + fHlp_Line;
 		if (k >= subjLen[fHlp_Nr])
 			break;
 
--- a/src/ft2_inst_ed.c
+++ b/src/ft2_inst_ed.c
@@ -107,6 +107,14 @@
 static bool pianoKeyStatus[96];
 static int32_t lastMouseX, lastMouseY, saveMouseX, saveMouseY;
 
+static const uint8_t mx2PianoKey[77] =
+{
+	0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,
+	4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,
+	9,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11
+};
+
+
 // thread data
 static uint16_t saveInstrNr;
 static SDL_Thread *thread;
@@ -126,17 +134,11 @@
 
 static int32_t SDLCALL copyInstrThread(void *ptr)
 {
-	bool error;
-	int8_t *p;
-	int16_t destIns, sourceIns;
-	sampleTyp *src, *dst;
-	(void)ptr;
+	bool error = false;
 
-	error = false;
+	const int16_t destIns = editor.curInstr;
+	const int16_t sourceIns = editor.srcInstr;
 
-	destIns = editor.curInstr;
-	sourceIns = editor.srcInstr;
-
 	pauseAudio();
 	
 	freeInstr(destIns);
@@ -147,17 +149,17 @@
 		{
 			memcpy(instr[destIns], instr[sourceIns], sizeof (instrTyp));
 
-			for (int16_t i = 0; i < MAX_SMP_PER_INST; i++)
-			{
-				src = &instr[sourceIns]->samp[i];
-				dst = &instr[destIns]->samp[i];
+			sampleTyp *src = instr[sourceIns]->samp;
+			sampleTyp *dst = instr[destIns]->samp;
 
+			for (int16_t i = 0; i < MAX_SMP_PER_INST; i++, src++, dst++)
+			{
 				dst->origPek = NULL;
 				dst->pek = NULL;
 
 				if (src->origPek != NULL)
 				{
-					p = (int8_t *)malloc(src->len + LOOP_FIX_LEN);
+					int8_t *p = (int8_t *)malloc(src->len + LOOP_FIX_LEN);
 					if (p != NULL)
 					{
 						dst->origPek = p;
@@ -184,6 +186,8 @@
 	setMouseBusy(false);
 
 	return false;
+
+	(void)ptr;
 }
 
 void copyInstr(void) // dstInstr = srcInstr
@@ -204,18 +208,16 @@
 
 void xchgInstr(void) // dstInstr <-> srcInstr
 {
-	instrTyp *dst, *src, dstTmp;
-
 	if (editor.curInstr == 0 || editor.srcInstr == editor.curInstr)
 		return;
 
 	lockMixerCallback();
 
-	src = instr[editor.srcInstr];
-	dst = instr[editor.curInstr];
+	instrTyp *src = instr[editor.srcInstr];
+	instrTyp *dst = instr[editor.curInstr];
 
 	// swap instruments
-	dstTmp = *dst;
+	instrTyp dstTmp = *dst;
 	*dst = *src;
 	*src = dstTmp;
 
@@ -288,7 +290,6 @@
 void sbMidiChPos(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_EXT_MIDI_CH, 0, false);
@@ -306,7 +307,6 @@
 void sbMidiPrgPos(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_EXT_MIDI_PRG, 0, false);
@@ -324,7 +324,6 @@
 void sbMidiBendPos(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_EXT_MIDI_BEND, 0, false);
@@ -420,7 +419,6 @@
 static void drawVolume(void)
 {
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL)
 		s = &instr[0]->samp[0];
 	else
@@ -432,7 +430,6 @@
 static void drawPanning(void)
 {
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL)
 		s = &instr[0]->samp[0];
 	else
@@ -443,10 +440,7 @@
 
 static void drawFineTune(void)
 {
-	char sign;
-	int16_t ftune;
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL)
 		s = &instr[0]->samp[0];
 	else
@@ -454,7 +448,7 @@
 
 	fillRect(491, 205, 27, 8, PAL_DESKTOP);
 
-	ftune = s->fine;
+	int16_t  ftune = s->fine;
 	if (ftune == 0)
 	{
 		charOut(512, 205, PAL_FORGRND, '0');
@@ -461,7 +455,7 @@
 		return;
 	}
 
-	sign = (ftune < 0) ? '-' : '+';
+	const char sign = (ftune < 0) ? '-' : '+';
 
 	ftune = ABS(ftune);
 	if (ftune >= 100)
@@ -506,8 +500,8 @@
 
 static void drawRelTone(void)
 {
-	char noteChar1, noteChar2, octaChar;
-	int8_t note2, note;
+	char noteChar1, noteChar2;
+	int8_t note2;
 
 	if (instr[editor.curInstr] == NULL)
 	{
@@ -520,7 +514,7 @@
 	else
 		note2 = 48 + instr[editor.curInstr]->samp[editor.curSmp].relTon;
 
-	note = note2 % 12;
+	const int8_t note = note2 % 12;
 	if (config.ptnAcc == 0)
 	{
 		noteChar1 = sharpNote1Char[note];
@@ -532,7 +526,7 @@
 		noteChar2 = flatNote2Char[note];
 	}
 
-	octaChar = '0' + (note2 / 12);
+	const char octaChar = '0' + (note2 / 12);
 
 	charOutBg(598, 299, PAL_FORGRND, PAL_BCKGRND, noteChar1);
 	charOutBg(606, 299, PAL_FORGRND, PAL_BCKGRND, noteChar2);
@@ -583,7 +577,6 @@
 static void setOrStoreVolEnvPreset(uint8_t num)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 		return;
 
@@ -616,7 +609,6 @@
 static void setOrStorePanEnvPreset(uint8_t num)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 		return;
 
@@ -721,7 +713,6 @@
 void relToneOctUp(void)
 {
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 		return;
 
@@ -738,7 +729,6 @@
 void relToneOctDown(void)
 {
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 		return;
 
@@ -755,7 +745,6 @@
 void relToneUp(void)
 {
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 		return;
 
@@ -771,7 +760,6 @@
 void relToneDown(void)
 {
 	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 		return;
 
@@ -786,16 +774,15 @@
 
 void volEnvAdd(void)
 {
-	int16_t i, ant;
 	instrTyp *ins = instr[editor.curInstr];
 	if (editor.curInstr == 0 || ins == NULL)
 		return;
 
-	ant = ins->envVPAnt;
+	const int16_t ant = ins->envVPAnt;
 	if (ant >= 12)
 		return;
 
-	i = (int16_t)editor.currVolEnvPoint;
+	int16_t i = (int16_t)editor.currVolEnvPoint;
 	if (i < 0 || i >= ant)
 	{
 		i = ant-1;
@@ -841,13 +828,11 @@
 
 void volEnvDel(void)
 {
-	uint8_t drawSust, drawRepS, drawRepE;
-	int16_t i;
 	instrTyp *ins = instr[editor.curInstr];
 	if (ins == NULL || editor.curInstr == 0 || ins->envVPAnt <= 2)
 		return;
 
-	i = (int16_t)editor.currVolEnvPoint;
+	int16_t i = (int16_t)editor.currVolEnvPoint;
 	if (i < 0 || i >= ins->envVPAnt)
 		return;
 
@@ -857,9 +842,9 @@
 		ins->envVP[j][1] = ins->envVP[j+1][1];
 	}
 
-	drawSust = false;
-	drawRepS = false;
-	drawRepE = false;
+	bool drawSust = false;
+	bool drawRepS = false;
+	bool drawRepE = false;
 
 	if (ins->envVSust > i) { ins->envVSust--; drawSust = true; }
 	if (ins->envVRepS > i) { ins->envVRepS--; drawRepS = true; }
@@ -977,16 +962,15 @@
 
 void panEnvAdd(void)
 {
-	int16_t i, ant;
 	instrTyp *ins = instr[editor.curInstr];
 	if (ins == NULL || editor.curInstr == 0)
 		return;
 
-	ant = ins->envPPAnt;
+	const int16_t ant = ins->envPPAnt;
 	if (ant >= 12)
 		return;
 
-	i = (int16_t)editor.currPanEnvPoint;
+	int16_t i = (int16_t)editor.currPanEnvPoint;
 	if (i < 0 || i >= ant)
 	{
 		i = ant-1;
@@ -1032,13 +1016,11 @@
 
 void panEnvDel(void)
 {
-	uint8_t drawSust, drawRepS, drawRepE;
-	int16_t i;
 	instrTyp *ins = instr[editor.curInstr];
 	if (ins == NULL || editor.curInstr == 0 || ins->envPPAnt <= 2)
 		return;
 
-	i = (int16_t)editor.currPanEnvPoint;
+	int16_t i = (int16_t)editor.currPanEnvPoint;
 	if (i < 0 || i >= ins->envPPAnt)
 		return;
 
@@ -1048,9 +1030,9 @@
 		ins->envPP[j][1] = ins->envPP[j+1][1];
 	}
 
-	drawSust = false;
-	drawRepS = false;
-	drawRepE = false;
+	bool drawSust = false;
+	bool drawRepS = false;
+	bool drawRepE = false;
 
 	if (ins->envPSust > i) { ins->envPSust--; drawSust = true; }
 	if (ins->envPRepS > i) { ins->envPRepS--; drawRepS = true; }
@@ -1252,8 +1234,6 @@
 
 void setVolumeScroll(uint32_t pos)
 {
-	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 	{
 		if (editor.curInstr == 0 && editor.curSmp != 0)
@@ -1264,7 +1244,7 @@
 		return;
 	}
 
-	s = &instr[editor.curInstr]->samp[editor.curSmp];
+	sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
 	if (s->vol != (uint8_t)pos)
 	{
 		s->vol = (uint8_t)pos;
@@ -1275,8 +1255,6 @@
 
 void setPanningScroll(uint32_t pos)
 {
-	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_PAN, 0x80, false);
@@ -1283,7 +1261,7 @@
 		return;
 	}
 
-	s = &instr[editor.curInstr]->samp[editor.curSmp];
+	sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
 	if (s->pan != (uint8_t)pos)
 	{
 		s->pan = (uint8_t)pos;
@@ -1294,8 +1272,6 @@
 
 void setFinetuneScroll(uint32_t pos)
 {
-	sampleTyp *s;
-
 	if (instr[editor.curInstr] == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_FTUNE, 128, false); // finetune 0
@@ -1302,7 +1278,7 @@
 		return;
 	}
 
-	s = &instr[editor.curInstr]->samp[editor.curSmp];
+	sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
 	if (s->fine != (int8_t)(pos - 128))
 	{
 		s->fine = (int8_t)(pos - 128);
@@ -1314,7 +1290,6 @@
 void setFadeoutScroll(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL)
 	{
 		setScrollBarPos(SB_INST_FADEOUT, 0, false);
@@ -1338,7 +1313,6 @@
 void setVibSpeedScroll(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_VIBSPEED, 0, false);
@@ -1356,7 +1330,6 @@
 void setVibDepthScroll(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_VIBDEPTH, 0, false);
@@ -1374,7 +1347,6 @@
 void setVibSweepScroll(uint32_t pos)
 {
 	instrTyp *ins = instr[editor.curInstr];
-
 	if (ins == NULL || editor.curInstr == 0)
 	{
 		setScrollBarPos(SB_INST_VIBSWEEP, 0, false);
@@ -1533,19 +1505,16 @@
 
 static void pinoaNumberOut(uint16_t xPos, uint16_t yPos, uint8_t fgPalette, uint8_t bgPalette, uint8_t val)
 {
-	const uint8_t *srcPtr;
-	uint32_t *dstPtr, fg, bg;
-
 	assert(val <= 0xF);
 
-	fg = video.palette[fgPalette];
-	bg = video.palette[bgPalette];
-	dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	srcPtr = &bmp.font8[val * 5];
+	const uint32_t fg = video.palette[fgPalette];
+	const uint32_t bg = video.palette[bgPalette];
+	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+	const uint8_t *srcPtr = &bmp.font8[val * 5];
 
-	for (uint32_t y = 0; y < 7; y++)
+	for (int32_t y = 0; y < 7; y++)
 	{
-		for (uint32_t x = 0; x < 5; x++)
+		for (int32_t x = 0; x < 5; x++)
 			dstPtr[x] = srcPtr[x] ? fg : bg;
 
 		dstPtr += SCREEN_W;
@@ -1555,14 +1524,11 @@
 
 static void writePianoNumber(uint8_t note, uint8_t key, uint8_t octave)
 {
-	uint8_t number;
-	uint16_t x;
-
-	number = 0;
+	uint8_t number = 0;
 	if (instr[editor.curInstr] != NULL && editor.curInstr != 0)
 		number = instr[editor.curInstr]->ta[note];
 
-	x = keyDigitXPos[key] + (octave * 77);
+	const uint16_t x = keyDigitXPos[key] + (octave * 77);
 
 	if (keyIsBlackTab[key])
 		pinoaNumberOut(x, 361, PAL_FORGRND, PAL_BCKGRND, number);
@@ -1572,25 +1538,23 @@
 
 static void drawBlackPianoKey(uint8_t key, uint8_t octave, bool keyDown)
 {
-	uint16_t x = keyXPos[key] + (octave * 77);
+	const uint16_t x = keyXPos[key] + (octave * 77);
 	blit(x, 351, &bmp.blackPianoKeys[keyDown * (7*27)], 7, 27);
 }
 
 static void drawWhitePianoKey(uint8_t key, uint8_t octave,  bool keyDown)
 {
-	uint16_t x = keyXPos[key] + (octave * 77);
+	const uint16_t x = keyXPos[key] + (octave * 77);
 	blit(x, 351, &bmp.whitePianoKeys[(keyDown * (11*46*3)) + whiteKeysBmpOrder[key]], 11, 46);
 }
 
 void redrawPiano(void)
 {
-	uint8_t key, octave;
-
 	memset(pianoKeyStatus, 0, sizeof (pianoKeyStatus));
 	for (uint8_t i = 0; i < 96; i++)
 	{
-		key = noteTab1[i];
-		octave = noteTab2[i];
+		const uint8_t key = noteTab1[i];
+		const uint8_t octave = noteTab2[i];
 
 		if (keyIsBlackTab[key])
 			drawBlackPianoKey(key, octave, false);
@@ -1603,8 +1567,7 @@
 
 bool testPianoKeysMouseDown(bool mouseButtonDown)
 {
-	uint8_t key, note, octave;
-	int32_t mx, my, quotient, remainder;
+	uint8_t key, octave;
 
 	if (!ui.instEditorShown)
 		return false; // area not clicked
@@ -1612,8 +1575,8 @@
 	if (editor.curInstr == 0 || instr[editor.curInstr] == NULL)
 		return true; // area clicked, but don't do anything
 
-	mx = mouse.x;
-	my = mouse.y;
+	int32_t mx = mouse.x;
+	int32_t my = mouse.y;
 
 	if (!mouseButtonDown)
 	{
@@ -1630,29 +1593,15 @@
 
 	mx -= 8;
 
-	quotient = mx / 77;
-	remainder = mx % 77;
+	const int32_t quotient  = mx / 77;
+	const int32_t remainder = mx % 77;
 
 	if (my < 378)
 	{
 		// white keys and black keys (top)
 
-		octave = (uint8_t)(quotient);
-		mx = remainder; // width of all keys in one octave
-
-		// this is pretty disgusting...
-		     if (mx >= 69) key = 11;
-		else if (mx >= 62) key = 10;
-		else if (mx >= 58) key = 9;
-		else if (mx >= 51) key = 8;
-		else if (mx >= 47) key = 7;
-		else if (mx >= 40) key = 6;
-		else if (mx >= 33) key = 5;
-		else if (mx >= 25) key = 4;
-		else if (mx >= 18) key = 3;
-		else if (mx >= 14) key = 2;
-		else if (mx >=  7) key = 1;
-		else               key = 0;
+		octave = (uint8_t)quotient;
+		key = mx2PianoKey[remainder];
 	}
 	else
 	{
@@ -1663,7 +1612,7 @@
 		key = whiteKeyIndex[remainder / whiteKeyWidth];
 	}
 
-	note = (octave * 12) + key;
+	const uint8_t note = (octave * 12) + key;
 	if (instr[editor.curInstr]->ta[note] != editor.curSmp)
 	{
 		instr[editor.curInstr]->ta[note] = editor.curSmp;
@@ -1677,8 +1626,6 @@
 void drawPiano(chSyncData_t *chSyncData)
 {
 	bool newStatus[96];
-	int32_t i, note;
-
 	memset(newStatus, 0, sizeof (newStatus));
 
 	// find active notes
@@ -1687,11 +1634,11 @@
 		if (chSyncData != NULL) // song is playing, use replayer channel state
 		{
 			syncedChannel_t *c = chSyncData->channels;
-			for (i = 0; i < song.antChn; i++, c++)
+			for (int32_t i = 0; i < song.antChn; i++, c++)
 			{
 				if (c->instrNr == editor.curInstr && c->envSustainActive)
 				{
-					note = getPianoKey(c->finalPeriod, c->fineTune, c->relTonNr);
+					const int32_t note = getPianoKey(c->finalPeriod, c->fineTune, c->relTonNr);
 					if (note >= 0 && note <= 95)
 						newStatus[note] = true;
 				}
@@ -1700,11 +1647,11 @@
 		else // song is not playing (jamming from keyboard/MIDI)
 		{
 			stmTyp *c = stm;
-			for (i = 0; i < song.antChn; i++, c++)
+			for (int32_t i = 0; i < song.antChn; i++, c++)
 			{
 				if (c->instrNr == editor.curInstr && c->envSustainActive)
 				{
-					note = getPianoKey(c->finalPeriod, c->fineTune, c->relTonNr);
+					const int32_t note = getPianoKey(c->finalPeriod, c->fineTune, c->relTonNr);
 					if (note >= 0 && note <= 95)
 						newStatus[note] = true;
 				}
@@ -1713,13 +1660,13 @@
 	}
 
 	// draw keys
-	for (i = 0; i < 96; i++)
+	for (int32_t i = 0; i < 96; i++)
 	{
 		const bool keyDown = newStatus[i];
 		if (pianoKeyStatus[i] ^ keyDown)
 		{
-			uint8_t key = noteTab1[i];
-			uint8_t octave = noteTab2[i];
+			const uint8_t key = noteTab1[i];
+			const uint8_t octave = noteTab2[i];
 
 			if (keyIsBlackTab[key])
 				drawBlackPianoKey(key, octave, keyDown);
@@ -1733,11 +1680,6 @@
 
 static void envelopeLine(int32_t nr, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t col)
 {
-	int16_t d, x, y, sx, sy, dx, dy;
-	uint16_t ax, ay;
-	int32_t pitch;
-	uint32_t pal1, pal2, pixVal, *dst32;
-
 	y1 = CLAMP(y1, 0, 66);
 	y2 = CLAMP(y2, 0, 66);
 	x1 = CLAMP(x1, 0, 335);
@@ -1754,28 +1696,26 @@
 		y2 += 276;
 	}
 
-	// get coefficients
-	dx = x2 - x1;
-	ax = ABS(dx) << 1;
-	sx = SGN(dx);
-	dy = y2 - y1;
-	ay = ABS(dy) << 1;
-	sy = SGN(dy);
-	x  = x1;
-	y  = y1;
+	const int16_t dx = x2 - x1;
+	const uint16_t ax = ABS(dx) << 1;
+	const int16_t sx = SGN(dx);
+	const int16_t dy = y2 - y1;
+	const uint16_t ay = ABS(dy) << 1;
+	const int16_t sy = SGN(dy);
+	int16_t x = x1;
+	int16_t y = y1;
 
-	pal1 = video.palette[PAL_BLCKMRK];
-	pal2 = video.palette[PAL_BLCKTXT];
-	pixVal = video.palette[col];
-	pitch = sy * SCREEN_W;
+	const uint32_t pal1 = video.palette[PAL_BLCKMRK];
+	const uint32_t pal2 = video.palette[PAL_BLCKTXT];
+	const uint32_t pixVal = video.palette[col];
+	const int32_t pitch = sy * SCREEN_W;
 
-	dst32 = &video.frameBuffer[(y * SCREEN_W) + x];
+	uint32_t *dst32 = &video.frameBuffer[(y * SCREEN_W) + x];
 
 	// draw line
 	if (ax > ay)
 	{
-		d = ay - (ax >> 1);
-
+		int16_t d = ay - (ax >> 1);
 		while (true)
 		{
 			// invert certain colors
@@ -1803,8 +1743,7 @@
 	}
 	else
 	{
-		d = ax - (ay >> 1);
-
+		int16_t d = ax - (ay >> 1);
 		while (true)
 		{
 			// invert certain colors
@@ -1840,12 +1779,10 @@
 
 static void envelopeDot(int32_t nr, int16_t x, int16_t y)
 {
-	uint32_t *dstPtr, pixVal;
-
 	y += (nr == 0) ? 189 : 276;
 
-	pixVal = video.palette[PAL_BLCKTXT];
-	dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
+	const uint32_t pixVal = video.palette[PAL_BLCKTXT];
+	uint32_t *dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
 
 	for (y = 0; y < 3; y++)
 	{
@@ -1859,14 +1796,12 @@
 
 static void envelopeVertLine(int32_t nr, int16_t x, int16_t y, uint8_t col)
 {
-	uint32_t *dstPtr, pixVal1, pixVal2;
-
 	y += (nr == 0) ? 189 : 276;
 
-	pixVal1 = video.palette[col];
-	pixVal2 = video.palette[PAL_BLCKTXT];
+	const uint32_t pixVal1 = video.palette[col];
+	const uint32_t pixVal2 = video.palette[PAL_BLCKTXT];
 
-	dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
+	uint32_t *dstPtr = &video.frameBuffer[(y * SCREEN_W) + x];
 	for (y = 0; y < 33; y++)
 	{
 		if (*dstPtr != pixVal2)
@@ -1879,7 +1814,8 @@
 static void writeEnvelope(int32_t nr)
 {
 	uint8_t selected;
-	int16_t i, x, y, lx, ly, nd, sp, ls, le, (*curEnvP)[2];
+	int16_t i, nd, sp, ls, le, (*curEnvP)[2];
+
 	instrTyp *ins = instr[editor.curInstr];
 
 	// clear envelope area
@@ -1950,14 +1886,14 @@
 	if (nd > 12)
 		nd = 12;
 
-	lx = 0;
-	ly = 0;
+	int16_t lx = 0;
+	int16_t ly = 0;
 
 	// draw envelope
 	for (i = 0; i < nd; i++)
 	{
-		x = curEnvP[i][0];
-		y = curEnvP[i][1];
+		int16_t x = curEnvP[i][0];
+		int16_t y = curEnvP[i][1];
 
 		x = CLAMP(x, 0, 324);
 		
@@ -2011,11 +1947,7 @@
 
 static void textOutTiny(int32_t xPos, int32_t yPos, char *str, uint32_t color)
 {
-#ifndef __arm__
-	uint32_t tmp;
-#endif
 	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-
 	while (*str != '\0')
 	{
 		const char chr = *str++;
@@ -2035,7 +1967,7 @@
 					dstPtr[x] = color;
 #else
 				// carefully written like this to generate conditional move instructions (font data is hard to predict)
-				tmp = dstPtr[x];
+				uint32_t tmp = dstPtr[x];
 				if (srcPtr[x] != 0) tmp = color;
 				dstPtr[x] = tmp;
 #endif
@@ -2109,9 +2041,10 @@
 
 void handleInstEditorRedrawing(void)
 {
+	int16_t tick, val;
+
 	instrTyp *ins = instr[editor.curInstr];
 
-	int16_t tick, val;
 	if (updateVolEnv)
 	{
 		updateVolEnv = false;
@@ -2456,21 +2389,19 @@
 
 bool testInstrVolEnvMouseDown(bool mouseButtonDown)
 {
-	uint8_t ant;
-	int32_t x, y, mx, my, minX, maxX;
-	instrTyp *ins;
+	int32_t minX, maxX;
 
 	if (!ui.instEditorShown || editor.curInstr == 0 || instr[editor.curInstr] == NULL)
 		return false;
 
-	ins = instr[editor.curInstr];
+	instrTyp *ins = instr[editor.curInstr];
 
-	ant = ins->envVPAnt;
+	uint8_t ant = ins->envVPAnt;
 	if (ant > 12)
 		ant = 12;
 
-	mx = mouse.x;
-	my = mouse.y;
+	int32_t mx = mouse.x;
+	int32_t my = mouse.y;
 
 	if (!mouseButtonDown)
 	{
@@ -2485,8 +2416,8 @@
 
 		for (uint8_t i = 0; i < ant; i++)
 		{
-			x = 8 + ins->envVP[i][0];
-			y = 190 + (64 - ins->envVP[i][1]);
+			const int32_t x = 8 + ins->envVP[i][0];
+			const int32_t y = 190 + (64 - ins->envVP[i][1]);
 
 			if (mx >= x-2 && mx <= x+2 && my >= y-2 && my <= y+2)
 			{
@@ -2555,21 +2486,19 @@
 
 bool testInstrPanEnvMouseDown(bool mouseButtonDown)
 {
-	uint8_t ant;
-	int32_t x, y, mx, my, minX, maxX;
-	instrTyp *ins;
+	int32_t minX, maxX;
 
 	if (!ui.instEditorShown || editor.curInstr == 0 || instr[editor.curInstr] == NULL)
 		return false;
 
-	ins = instr[editor.curInstr];
+	instrTyp *ins = instr[editor.curInstr];
 
-	ant = ins->envPPAnt;
+	uint8_t ant = ins->envPPAnt;
 	if (ant > 12)
 		ant = 12;
 
-	mx = mouse.x;
-	my = mouse.y;
+	int32_t mx = mouse.x;
+	int32_t my = mouse.y;
 
 	if (!mouseButtonDown)
 	{
@@ -2584,8 +2513,8 @@
 
 		for (uint8_t i = 0; i < ant; i++)
 		{
-			x = 8 + ins->envPP[i][0];
-			y = 277 + (63 - ins->envPP[i][1]);
+			const int32_t x = 8 + ins->envPP[i][0];
+			const int32_t y = 277 + (63 - ins->envPP[i][1]);
 
 			if (mx >= x-2 && mx <= x+2 && my >= y-2 && my <= y+2)
 			{
@@ -2972,17 +2901,9 @@
 
 static int32_t SDLCALL saveInstrThread(void *ptr)
 {
-	int16_t n;
-	int32_t i;
-	size_t result;
-	FILE *f;
 	instrXIHeaderTyp ih;
-	instrTyp *ins;
 	sampleTyp *s;
-	sampleHeaderTyp *dst;
 
-	(void)ptr;
-
 	if (editor.tmpFilenameU == NULL)
 	{
 		okBoxThreadSafe(0, "System message", "General I/O error during saving! Is the file in use?");
@@ -2989,7 +2910,7 @@
 		return false;
 	}
 
-	n = getUsedSamples(saveInstrNr);
+	const int16_t n = getUsedSamples(saveInstrNr);
 	if (n == 0 || instr[saveInstrNr] == NULL)
 	{
 		okBoxThreadSafe(0, "System message", "Instrument is empty!");
@@ -2996,7 +2917,7 @@
 		return false;
 	}
 
-	f = UNICHAR_FOPEN(editor.tmpFilenameU, "wb");
+	FILE *f = UNICHAR_FOPEN(editor.tmpFilenameU, "wb");
 	if (f == NULL)
 	{
 		okBoxThreadSafe(0, "System message", "General I/O error during saving! Is the file in use?");
@@ -3013,7 +2934,7 @@
 	ih.ver = 0x0102;
 
 	// copy over instrument struct data to instrument header
-	ins = instr[saveInstrNr];
+	instrTyp *ins = instr[saveInstrNr];
 	memcpy(ih.ta, ins->ta, 96);
 	memcpy(ih.envVP, ins->envVP, 12*2*sizeof(int16_t));
 	memcpy(ih.envPP, ins->envPP, 12*2*sizeof(int16_t));
@@ -3040,10 +2961,10 @@
 	ih.antSamp = n;
 
 	// copy over sample struct datas to sample headers
-	for (i = 0; i < n; i++)
+	s = instr[saveInstrNr]->samp;
+	for (int32_t i = 0; i < n; i++, s++)
 	{
-		s = &instr[saveInstrNr]->samp[i];
-		dst = &ih.samp[i];
+		sampleHeaderTyp *dst = &ih.samp[i];
 
 		dst->len = s->len;
 		dst->repS = s->repS;
@@ -3061,7 +2982,7 @@
 			dst->len = 0;
 	}
 
-	result = fwrite(&ih, INSTR_XI_HEADER_SIZE + (ih.antSamp * sizeof (sampleHeaderTyp)), 1, f);
+	size_t result = fwrite(&ih, INSTR_XI_HEADER_SIZE + (ih.antSamp * sizeof (sampleHeaderTyp)), 1, f);
 	if (result != 1)
 	{
 		fclose(f);
@@ -3070,9 +2991,9 @@
 	}
 
 	pauseAudio();
-	for (i = 0; i < n; i++)
+	s = instr[saveInstrNr]->samp;
+	for (int32_t i = 0; i < n; i++, s++)
 	{
-		s = &instr[saveInstrNr]->samp[i];
 		if (s->pek != NULL && s->len > 0)
 		{
 			restoreSample(s);
@@ -3100,6 +3021,8 @@
 
 	setMouseBusy(false);
 	return true;
+
+	(void)ptr;
 }
 
 void saveInstr(UNICHAR *filenameU, int16_t nr)
@@ -3123,8 +3046,8 @@
 
 static int16_t getPATNote(int32_t freq)
 {
-	double dNote = (log2(freq * (1.0 / 440000.0)) * 12.0) + 57.0;
-	int32_t note = (int32_t)(dNote + 0.5);
+	const double dNote = (log2(freq * (1.0 / 440000.0)) * 12.0) + 57.0;
+	const int32_t note = (const int32_t)(dNote + 0.5);
 
 	return (int16_t)note;
 }
@@ -3131,12 +3054,9 @@
 
 static int32_t SDLCALL loadInstrThread(void *ptr)
 {
-	bool stereoWarning;
 	int8_t *newPtr;
 	int16_t a, b;
 	int32_t i, j;
-	double dFreq;
-	FILE *f;
 	instrXIHeaderTyp ih;
 	instrPATHeaderTyp ih_PAT;
 	instrPATWaveHeaderTyp ih_PATWave;
@@ -3144,10 +3064,8 @@
 	sampleTyp *s;
 	instrTyp *ins;
 
-	(void)ptr;
+	bool stereoWarning = false;
 
-	stereoWarning = false;
-
 	if (editor.tmpInstrFilenameU == NULL)
 	{
 		okBoxThreadSafe(0, "System message", "General I/O error during loading! Is the file in use?");
@@ -3154,7 +3072,7 @@
 		return false;
 	}
 
-	f = UNICHAR_FOPEN(editor.tmpInstrFilenameU, "rb");
+	FILE *f = UNICHAR_FOPEN(editor.tmpInstrFilenameU, "rb");
 	if (f == NULL)
 	{
 		okBoxThreadSafe(0, "System message", "General I/O error during loading! Is the file in use?");
@@ -3478,8 +3396,8 @@
 				if (s->repS+s->repL > s->len)
 					s->repL = s->len - s->repS;
 
-				dFreq = (1.0 + (ih_PATWave.fineTune / 512.0)) * ih_PATWave.sampleRate;
-				int32_t freq = (int32_t)(dFreq + 0.5);
+				const double dFreq = (1.0 + (ih_PATWave.fineTune / 512.0)) * ih_PATWave.sampleRate;
+				int32_t freq = (const int32_t)(dFreq + 0.5);
 				tuneSample(s, freq);
 
 				a = s->relTon - (getPATNote(ih_PATWave.rootFrq) - (12 * 3));
@@ -3530,14 +3448,15 @@
 		okBoxThreadSafe(0, "System message", "Warning: The instrument contained stereo sample(s). They were mixed to mono!");
 
 	return true;
+
+	(void)ptr;
 }
 
 static bool fileIsInstr(UNICHAR *filename)
 {
 	char header[22];
-	FILE *f;
 
-	f = UNICHAR_FOPEN(filename, "rb");
+	FILE *f = UNICHAR_FOPEN(filename, "rb");
 	if (f == NULL)
 		return false;
 
--- a/src/ft2_keyboard.c
+++ b/src/ft2_keyboard.c
@@ -42,13 +42,11 @@
 
 int8_t scancodeKeyToNote(SDL_Scancode scancode)
 {
-	int8_t note;
-
 	if (scancode == SDL_SCANCODE_CAPSLOCK || scancode == SDL_SCANCODE_NONUSBACKSLASH)
 		return 97; // key off
 
 	// translate key to note
-	note = 0;
+	int8_t note = 0;
 	if (scancode >= SDL_SCANCODE_B && scancode <= SDL_SCANCODE_SLASH)
 		note = scancodeKey2Note[(int32_t)scancode - SDL_SCANCODE_B];
 
@@ -73,8 +71,6 @@
 
 void keyUpHandler(SDL_Scancode scancode, SDL_Keycode keycode)
 {
-	(void)keycode;
-
 	if (editor.editTextFlag || ui.sysReqShown)
 		return; // kludge: don't handle key up! (XXX: Is this hack really needed anymore?)
 
@@ -94,6 +90,8 @@
 		keyb.numPadPlusPressed = false;
 
 	keyb.keyRepeat = false;
+
+	(void)keycode;
 }
 
 void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode, bool keyWasRepeated)
@@ -161,8 +159,6 @@
 
 static void handleKeys(SDL_Keycode keycode, SDL_Scancode scanKey)
 {
-	uint16_t pattLen;
-
 	// if we're holding numpad plus but not pressing bank keys, don't check any other key
 	if (keyb.numPadPlusPressed)
 	{
@@ -346,7 +342,7 @@
 
 				patt[editor.editPattern][(editor.pattPos * MAX_VOICES) + cursor.ch].ton = 97;
 
-				pattLen = pattLens[editor.editPattern];
+				const uint16_t pattLen = pattLens[editor.editPattern];
 				if (playMode == PLAYMODE_EDIT && pattLen >= 1)
 					setPos(-1, (editor.pattPos + editor.ID_Add) % pattLen, true);
 
--- a/src/ft2_main.c
+++ b/src/ft2_main.c
@@ -256,8 +256,6 @@
 
 static void initializeVars(void)
 {
-	int32_t i;
-
 	cpu.hasSSE = SDL_HasSSE();
 	cpu.hasSSE2 = SDL_HasSSE2();
 
@@ -271,7 +269,8 @@
 	memset(&chSync, 0, sizeof (chSync));
 	memset(&song, 0, sizeof (song));
 
-	for (i = 0; i < MAX_VOICES; i++)
+	// used for scopes and sampling position line (sampler screen)
+	for (int32_t i = 0; i < MAX_VOICES; i++)
 	{
 		lastChInstr[i].instrNr = 255;
 		lastChInstr[i].sampleNr = 255;
@@ -380,9 +379,6 @@
 #ifdef __APPLE__
 static void osxSetDirToProgramDirFromArgs(char **argv)
 {
-	char *tmpPath;
-	int32_t i, tmpPathLen;
-
 	/* OS X/macOS: hackish way of setting the current working directory to the place where we double clicked
 	** on the icon (for protracker.ini loading)
 	*/
@@ -390,12 +386,12 @@
 	// if we launched from the terminal, argv[0][0] would be '.'
 	if (argv[0] != NULL && argv[0][0] == DIR_DELIMITER) // don't do the hack if we launched from the terminal
 	{
-		tmpPath = strdup(argv[0]);
+		char *tmpPath = strdup(argv[0]);
 		if (tmpPath != NULL)
 		{
 			// cut off program filename
-			tmpPathLen = strlen(tmpPath);
-			for (i = tmpPathLen - 1; i >= 0; i--)
+			int32_t tmpPathLen = strlen(tmpPath);
+			for (int32_t i = tmpPathLen - 1; i >= 0; i--)
 			{
 				if (tmpPath[i] == DIR_DELIMITER)
 				{
@@ -415,17 +411,17 @@
 
 static void setupPerfFreq(void)
 {
-	uint64_t perfFreq64;
-	double dInt, dFrac;
+	double dInt;
 
-	perfFreq64 = SDL_GetPerformanceFrequency();
+	const uint64_t perfFreq64 = SDL_GetPerformanceFrequency();
 	assert(perfFreq64 != 0);
+
 	editor.dPerfFreq = (double)perfFreq64;
 	editor.dPerfFreqMulMicro = 1000000.0 / editor.dPerfFreq;
 	editor.dPerfFreqMulMs = 1.0 / (editor.dPerfFreq / 1000.0);
 
 	// calculate vblank time for performance counters and split into int/frac
-	dFrac = modf(editor.dPerfFreq / VBLANK_HZ, &dInt);
+	double dFrac = modf(editor.dPerfFreq / VBLANK_HZ, &dInt);
 
 	// integer part
 	video.vblankTimeLen = (int32_t)dInt;
--- a/src/ft2_midi.c
+++ b/src/ft2_midi.c
@@ -38,9 +38,7 @@
 
 static inline void midiInKeyAction(int8_t m, uint8_t mv)
 {
-	int16_t vol;
-
-	vol = (mv * 64 * config.recMIDIVolSens) / (127 * 100);
+	int16_t vol = (mv * 64 * config.recMIDIVolSens) / (127 * 100);
 	if (vol > 64)
 		vol = 64;
 
@@ -61,8 +59,6 @@
 
 static inline void midiInControlChange(uint8_t data1, uint8_t data2)
 {
-	uint8_t vibDepth;
-
 	if (data1 != 1) // 1 = modulation wheel
 		return;
 
@@ -77,7 +73,7 @@
 		}
 	}
 
-	vibDepth = (midi.currMIDIVibDepth >> 9) & 0x0F;
+	const uint8_t vibDepth = (midi.currMIDIVibDepth >> 9) & 0x0F;
 	if (vibDepth > 0 && recMIDIValidChn)
 		recordMIDIEffect(0x04, 0xA0 | vibDepth);
 }
@@ -84,18 +80,17 @@
 
 static inline void midiInPitchBendChange(uint8_t data1, uint8_t data2)
 {
-	int16_t pitch;
-
-	pitch = (int16_t)((data2 << 7) | data1) - 8192; // -8192..8191
+	int16_t pitch = (int16_t)((data2 << 7) | data1) - 8192; // -8192..8191
 	pitch >>= 6; // -128..127
 
 	midi.currMIDIPitch = pitch;
 	if (recMIDIValidChn)
 	{
-		for (uint8_t i = 0; i < song.antChn; i++)
+		stmTyp *ch = stm;
+		for (uint8_t i = 0; i < song.antChn; i++, ch++)
 		{
-			if (stm[i].midiPitch != 0 || editor.keyOnTab[i] != 0)
-				stm[i].midiPitch = midi.currMIDIPitch;
+			if (ch->midiPitch != 0 || editor.keyOnTab[i] != 0)
+				ch->midiPitch = midi.currMIDIPitch;
 		}
 	}
 }
@@ -104,9 +99,6 @@
 {
 	uint8_t byte[3];
 
-	(void)dTimeStamp;
-	(void)userData;
-
 	if (!midi.enable || messageSize < 2)
 		return;
 
@@ -127,6 +119,9 @@
 		else if (byte[0] >= 176 && byte[0] <= 176+15)   midiInControlChange(byte[1], byte[2]);
 		else if (byte[0] >= 224 && byte[0] <= 224+15) midiInPitchBendChange(byte[1], byte[2]);
 	}
+
+	(void)dTimeStamp;
+	(void)userData;
 }
 
 static uint32_t getNumMidiInDevices(void)
@@ -139,12 +134,10 @@
 
 static char *getMidiInDeviceName(uint32_t deviceID)
 {
-	char *devStr;
-
 	if (midiDev == NULL)
 		return NULL;
 
-	devStr = (char *)rtmidi_get_port_name(midiDev, deviceID);
+	char *devStr = (char *)rtmidi_get_port_name(midiDev, deviceID);
 	if (!midiDev->ok)
 		return NULL;
 
@@ -221,17 +214,15 @@
 
 void recordMIDIEffect(uint8_t effTyp, uint8_t effData)
 {
-	int16_t nr;
-	tonTyp *note;
-
 	// only handle this in record mode
 	if (!midi.enable || (playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT))
 		return;
 
-	nr = editor.editPattern;
+	const int16_t nr = editor.editPattern;
 	if (config.multiRec)
 	{
-		for (uint16_t i = 0; i < song.antChn; i++)
+		tonTyp *note = &patt[nr][editor.pattPos * MAX_VOICES];
+		for (int32_t i = 0; i < song.antChn; i++, note++)
 		{
 			if (config.multiRecChn[i] && editor.chnMode[i])
 			{
@@ -238,12 +229,10 @@
 				if (!allocatePattern(nr))
 					return;
 
-				note = &patt[nr][(editor.pattPos * MAX_VOICES) + i];
 				if (note->effTyp == 0)
 				{
 					note->effTyp = effTyp;
-					note->eff    = effData;
-
+					note->eff = effData;
 					setSongModifiedFlag();
 				}
 			}
@@ -254,33 +243,29 @@
 		if (!allocatePattern(nr))
 			return;
 
-		note = &patt[nr][(editor.pattPos * MAX_VOICES) + cursor.ch];
+		tonTyp *note = &patt[nr][(editor.pattPos * MAX_VOICES) + cursor.ch];
 		if (note->effTyp != effTyp || note->eff != effData)
 			setSongModifiedFlag();
 
 		note->effTyp = effTyp;
-		note->eff    = effData;
+		note->eff = effData;
 	}
 }
 
 bool saveMidiInputDeviceToConfig(void)
 {
-	char *midiInStr;
-	uint32_t numDevices;
-	FILE *f;
-
 	if (!midi.initThreadDone || midiDev == NULL || !midiDeviceOpened)
 		return false;
 
-	numDevices = getNumMidiInDevices();
+	const uint32_t numDevices = getNumMidiInDevices();
 	if (numDevices == 0)
 		return false;
 
-	midiInStr = getMidiInDeviceName(midi.inputDevice);
+	char *midiInStr = getMidiInDeviceName(midi.inputDevice);
 	if (midiInStr == NULL)
 		return false;
 
-	f = UNICHAR_FOPEN(editor.midiConfigFileLocation, "w");
+	FILE *f = UNICHAR_FOPEN(editor.midiConfigFileLocation, "w");
 	if (f == NULL)
 	{
 		free(midiInStr);
@@ -298,22 +283,20 @@
 {
 #define MAX_DEV_STR_LEN 1024
 
-	char *midiInStr, *devString;
-	uint32_t i, numDevices;
-	FILE *f;
+	uint32_t i;
 
 	if (midi.inputDeviceName != NULL)
 		free(midi.inputDeviceName);
 
-	numDevices = getNumMidiInDevices();
+	const uint32_t numDevices = getNumMidiInDevices();
 	if (numDevices == 0)
 		goto setDefMidiInputDev;
 
-	f = UNICHAR_FOPEN(editor.midiConfigFileLocation, "r");
+	FILE *f = UNICHAR_FOPEN(editor.midiConfigFileLocation, "r");
 	if (f == NULL)
 		goto setDefMidiInputDev;
 
-	devString = (char *)calloc(MAX_DEV_STR_LEN + 4, sizeof (char));
+	char *devString = (char *)calloc(MAX_DEV_STR_LEN+4, sizeof (char));
 	if (devString == NULL)
 	{
 		fclose(f);
@@ -330,7 +313,7 @@
 	fclose(f);
 
 	// scan for device in list
-	midiInStr = NULL;
+	char *midiInStr = NULL;
 	for (i = 0; i < numDevices; i++)
 	{
 		midiInStr = getMidiInDeviceName(i);
@@ -381,8 +364,6 @@
 
 void rescanMidiInputDevices(void)
 {
-	char *deviceName;
-
 	freeMidiInputDeviceList();
 
 	midi.numInputDevices = getNumMidiInDevices();
@@ -391,7 +372,7 @@
 
 	for (int32_t i = 0; i < midi.numInputDevices; i++)
 	{
-		deviceName = getMidiInDeviceName(i);
+		char *deviceName = getMidiInDeviceName(i);
 		if (deviceName == NULL)
 		{
 			if (midi.numInputDevices > 0)
@@ -409,10 +390,6 @@
 
 void drawMidiInputList(void)
 {
-	char *tmpString;
-	uint16_t y;
-	int32_t deviceEntry;
-
 	clearRect(114, 4, 365, 165);
 
 	if (!midi.initThreadDone || midiDev == NULL || midi.numInputDevices == 0)
@@ -425,13 +402,13 @@
 
 	for (uint16_t i = 0; i < 15; i++)
 	{
-		deviceEntry = getScrollBarPos(SB_MIDI_INPUT_SCROLL) + i;
+		const int32_t deviceEntry = getScrollBarPos(SB_MIDI_INPUT_SCROLL) + i;
 		if (deviceEntry < midi.numInputDevices)
 		{
 			if (midi.inputDeviceNames[deviceEntry] == NULL)
 				continue;
 
-			y = 4 + (i * 11);
+			const uint16_t y = 4 + (i * 11);
 
 			if (midi.inputDeviceName != NULL)
 			{
@@ -439,7 +416,7 @@
 					fillRect(114, y, 365, 10, PAL_BOXSLCT); // selection background color
 			}
 
-			tmpString = utf8ToCp437(midi.inputDeviceNames[deviceEntry], true);
+			char *tmpString = utf8ToCp437(midi.inputDeviceNames[deviceEntry], true);
 			if (tmpString != NULL)
 			{
 				textOutClipX(114, y, PAL_FORGRND, tmpString, 479);
@@ -461,16 +438,14 @@
 
 void sbMidiInputSetPos(uint32_t pos)
 {
-	(void)pos;
-
 	if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT)
 		drawMidiInputList();
+
+	(void)pos;
 }
 
 bool testMidiInputDeviceListMouseDown(void)
 {
-	int32_t mx, my, deviceNum;
-
 	if (!ui.configScreenShown || editor.currConfigScreen != CONFIG_SCREEN_MIDI_INPUT)
 		return false; // we didn't click the area
 
@@ -477,13 +452,13 @@
 	if (!midi.initThreadDone)
 		return true;
 
-	mx = mouse.x;
-	my = mouse.y;
+	const int32_t mx = mouse.x;
+	const int32_t my = mouse.y;
 
 	if (my < 4 || my > 166 || mx < 114 || mx > 479)
 		return false; // we didn't click the area
 
-	deviceNum = (int32_t)scrollBars[SB_MIDI_INPUT_SCROLL].pos + ((my - 4) / 11);
+	const int32_t deviceNum = (int32_t)scrollBars[SB_MIDI_INPUT_SCROLL].pos + ((my - 4) / 11);
 	if (midi.numInputDevices <= 0 || deviceNum >= midi.numInputDevices)
 		return true;
 
@@ -509,8 +484,6 @@
 
 int32_t SDLCALL initMidiFunc(void *ptr)
 {
-	(void)ptr;
-
 	midi.closeMidiOnExit = true;
 
 	midi.initThreadDone = false;
@@ -522,6 +495,8 @@
 	midi.rescanDevicesFlag = true;
 
 	return true;
+
+	(void)ptr;
 }
 
 #else
--- a/src/ft2_module_loader.c
+++ b/src/ft2_module_loader.c
@@ -156,19 +156,18 @@
 
 static bool allocateTmpInstr(int16_t nr)
 {
-	instrTyp *p;
-
 	if (instrTmp[nr] != NULL)
 		return false; // already allocated
 
-	p = (instrTyp *)calloc(1, sizeof (instrTyp));
+	instrTyp *p = (instrTyp *)calloc(1, sizeof (instrTyp));
 	if (p == NULL)
 		return false;
 
-	for (int8_t i = 0; i < MAX_SMP_PER_INST; i++) // set standard sample pan/vol
+	sampleTyp *s = p->samp;
+	for (int32_t i = 0; i < MAX_SMP_PER_INST; i++, s++)
 	{
-		p->samp[i].pan = 128;
-		p->samp[i].vol = 64;
+		s->pan = 128;
+		s->vol = 64;
 	}
 
 	instrTmp[nr] = p;
@@ -215,7 +214,6 @@
 static bool loadMusicMOD(FILE *f, uint32_t fileLength, bool externalThreadFlag)
 {
 	char ID[16];
-	bool mightBeSTK, lateSTKVerFlag, veryLateSTKVerFlag;
 	uint8_t bytes[4], modFormat, numChannels;
 	int16_t i, j, k, ai;
 	uint16_t a, b, period;
@@ -227,9 +225,9 @@
 
 	showMsg = externalThreadFlag ? okBoxThreadSafe : okBox;
 
-	veryLateSTKVerFlag = false; // "DFJ SoundTracker III" nad later
-	lateSTKVerFlag = false; // "TJC SoundTracker II" and later
-	mightBeSTK = false;
+	bool veryLateSTKVerFlag = false; // "DFJ SoundTracker III" nad later
+	bool lateSTKVerFlag = false; // "TJC SoundTracker II" and later
+	bool mightBeSTK = false;
 
 	memset(&songTmp, 0, sizeof (songTmp));
 	memset(&h_MOD31, 0, sizeof (songMOD31HeaderTyp));
@@ -726,11 +724,11 @@
 static uint8_t stmTempoToBPM(uint8_t tempo) // ported from original ST2.3 replayer code
 {
 	const uint8_t slowdowns[16] = { 140, 50, 25, 15, 10, 7, 6, 4, 3, 3, 2, 2, 2, 2, 1, 1 };
-	uint32_t bpm;
 	uint16_t hz = 50;
 
 	hz -= ((slowdowns[tempo >> 4] * (tempo & 15)) >> 4); // can and will underflow
-	bpm = (hz << 1) + (hz >> 1); // BPM = hz * 2.5
+
+	const uint32_t bpm = (hz << 1) + (hz >> 1); // BPM = hz * 2.5
 	return (uint8_t)CLAMP(bpm, 32, 255); // result can be slightly off, but close enough...
 }
 
@@ -978,22 +976,18 @@
 
 static int8_t countS3MChannels(uint16_t antPtn)
 {
-	uint8_t j, k, channels;
-	int16_t i;
-	tonTyp ton;
-
-	channels = 0;
-	for (i = 0; i < antPtn; i++)
+	int32_t channels = 0;
+	for (int32_t i = 0; i < antPtn; i++)
 	{
 		if (pattTmp[i] == NULL)
 			continue;
 
-		for (j = 0; j < 64; j++)
+		tonTyp *ton = pattTmp[i];
+		for (int32_t j = 0; j < 64; j++)
 		{
-			for (k = 0; k < MAX_VOICES; k++)
+			for (int32_t k = 0; k < MAX_VOICES; k++, ton++)
 			{
-				ton = pattTmp[i][(j * MAX_VOICES) + k];
-				if (ton.eff == 0 && ton.effTyp == 0 && ton.instr == 0 && ton.ton == 0 && ton.vol == 0)
+				if (ton->eff == 0 && ton->effTyp == 0 && ton->instr == 0 && ton->ton == 0 && ton->vol == 0)
 					continue;
 
 				if (k > channels)
@@ -1003,7 +997,7 @@
 	}
 	channels++;
 
-	return channels;
+	return (int8_t)channels;
 }
 
 static bool loadMusicS3M(FILE *f, uint32_t dataLength, bool externalThreadFlag)
@@ -1873,8 +1867,9 @@
 
 static int32_t SDLCALL loadMusicThread(void *ptr)
 {
-	(void)ptr;
 	return doLoadMusic(true);
+
+	(void)ptr;
 }
 
 void loadMusic(UNICHAR *filenameU)
@@ -1947,10 +1942,8 @@
 
 static void freeTmpModule(void) // called on module load error
 {
-	int32_t i, j;
-
 	// free all patterns
-	for (i = 0; i < MAX_PATTERNS; i++)
+	for (int32_t i = 0; i < MAX_PATTERNS; i++)
 	{
 		if (pattTmp[i] != NULL)
 		{
@@ -1960,19 +1953,20 @@
 	}
 
 	// free all instruments and samples
-	for (i = 1; i <= 256; i++) // if >128 instruments, we fake-load up to 128 extra (and discard them later)
+	for (int32_t i = 1; i <= 256; i++) // if >128 instruments, we fake-load up to 128 extra (and discard them later)
 	{
-		if (instrTmp[i] != NULL)
-		{
-			for (j = 0; j < MAX_SMP_PER_INST; j++)
-			{
-				if (instrTmp[i]->samp[j].origPek != NULL)
-					free(instrTmp[i]->samp[j].origPek);
-			}
+		if (instrTmp[i] == NULL)
+			continue;
 
-			free(instrTmp[i]);
-			instrTmp[i] = NULL;
+		sampleTyp *s = instrTmp[i]->samp;
+		for (int32_t j = 0; j < MAX_SMP_PER_INST; j++, s++)
+		{
+			if (s->origPek != NULL)
+				free(s->origPek);
 		}
+
+		free(instrTmp[i]);
+		instrTmp[i] = NULL;
 	}
 }
 
@@ -2173,10 +2167,6 @@
 
 static bool loadInstrSample(FILE *f, uint16_t i, bool externalThreadFlag)
 {
-	int8_t *newPtr;
-	uint16_t j, k;
-	int32_t l, bytesToSkip;
-	sampleTyp *s;
 	int16_t (*showMsg)(int16_t, const char *, const char *);
 
 	showMsg = externalThreadFlag ? okBoxThreadSafe : okBox;
@@ -2184,15 +2174,16 @@
 	if (instrTmp[i] == NULL)
 		return true; // empty instrument, let's just pretend it got loaded successfully
 
-	k = instrTmp[i]->antSamp;
+	uint16_t k = instrTmp[i]->antSamp;
 	if (k > MAX_SMP_PER_INST)
 		k = MAX_SMP_PER_INST;
 
+	sampleTyp *s = instrTmp[i]->samp;
+
 	if (i > MAX_INST) // insNum > 128, just skip sample data
 	{
-		for (j = 0; j < k; j++)
+		for (uint16_t j = 0; j < k; j++, s++)
 		{
-			s = &instrTmp[i]->samp[j];
 			if (s->len > 0)
 				fseek(f, s->len, SEEK_CUR);
 		}
@@ -2199,15 +2190,13 @@
 	}
 	else
 	{
-		for (j = 0; j < k; j++)
+		for (uint16_t j = 0; j < k; j++, s++)
 		{
-			s = &instrTmp[i]->samp[j];
-
 			// if a sample has both forward loop and pingpong loop set, make it pingpong loop only (FT2 mixer behavior)
 			if ((s->typ & 3) == 3)
 				s->typ &= 0xFE;
 
-			l = s->len;
+			int32_t l = s->len;
 			if (l <= 0)
 			{
 				s->pek = NULL;
@@ -2220,7 +2209,7 @@
 			}
 			else
 			{
-				bytesToSkip = 0;
+				int32_t bytesToSkip = 0;
 				if (l > MAX_SAMPLE_LEN)
 				{
 					bytesToSkip = l - MAX_SAMPLE_LEN;
@@ -2257,7 +2246,7 @@
 					s->repL >>= 1;
 					s->repS >>= 1;
 
-					newPtr = (int8_t *)realloc(s->origPek, s->len + LOOP_FIX_LEN);
+					int8_t *newPtr = (int8_t *)realloc(s->origPek, s->len + LOOP_FIX_LEN);
 					if (newPtr != NULL)
 					{
 						s->origPek = newPtr;
@@ -2295,18 +2284,19 @@
 void unpackPatt(uint8_t *dst, uint8_t *src, uint16_t len, int32_t antChn)
 {
 	uint8_t note, data;
-	int32_t srcEnd, srcIdx, j;
+	int32_t j;
 
 	if (dst == NULL)
 		return;
 
-	srcEnd = len * (sizeof (tonTyp) * antChn);
-	srcIdx = 0;
+	const int32_t srcEnd = len * (sizeof (tonTyp) * antChn);
+	int32_t srcIdx = 0;
 
 	int32_t numChannels = antChn;
 	if (numChannels > MAX_VOICES)
 		numChannels = MAX_VOICES;
 
+	const int32_t pitch = sizeof (tonTyp) * (MAX_VOICES - antChn);
 	for (int32_t i = 0; i < len; i++)
 	{
 		for (j = 0; j < numChannels; j++)
@@ -2374,20 +2364,17 @@
 
 		// if song has <32 channels, align pointer to next row (skip unused channels)
 		if (antChn < MAX_VOICES)
-			dst += sizeof (tonTyp) * (MAX_VOICES - antChn);
+			dst += pitch;
 	}
 }
 
 static bool tmpPatternEmpty(uint16_t nr)
 {
-	uint8_t *scanPtr;
-	uint32_t scanLen;
-
 	if (pattTmp[nr] == NULL)
 		return true;
 
-	scanPtr = (uint8_t *)pattTmp[nr];
-	scanLen = pattLensTmp[nr] * TRACK_WIDTH;
+	uint8_t *scanPtr = (uint8_t *)pattTmp[nr];
+	const uint32_t scanLen = pattLensTmp[nr] * TRACK_WIDTH;
 
 	for (uint32_t i = 0; i < scanLen; i++)
 	{
@@ -2403,22 +2390,23 @@
 	if (p == NULL || antChn >= MAX_VOICES)
 		return;
 
-	for (int32_t i = 0; i < pattLen; i++)
-		memset(&p[(i * MAX_VOICES) + antChn], 0, sizeof (tonTyp) * (MAX_VOICES - antChn));
+	const int32_t width = sizeof (tonTyp) * (MAX_VOICES - antChn);
+
+	tonTyp *ptr = &p[antChn];
+	for (int32_t i = 0; i < pattLen; i++, ptr += MAX_VOICES)
+		memset(ptr, 0, width);
 }
 
 static bool loadPatterns(FILE *f, uint16_t antPtn, bool externalThreadFlag)
 {
-	bool pattLenWarn;
 	uint8_t tmpLen;
-	uint16_t i;
 	patternHeaderTyp ph;
 	int16_t (*showMsg)(int16_t, const char *, const char *);
 
 	showMsg = externalThreadFlag ? okBoxThreadSafe : okBox;
 
-	pattLenWarn = false;
-	for (i = 0; i < antPtn; i++)
+	bool pattLenWarn = false;
+	for (uint16_t i = 0; i < antPtn; i++)
 	{
 		if (fread(&ph.patternHeaderSize, 4, 1, f) != 1)
 			goto pattCorrupt;
@@ -2503,8 +2491,6 @@
 // called from input/video thread after the module was done loading
 static void setupLoadedModule(void)
 {
-	int16_t i;
-
 	lockMixerCallback();
 
 	freeAllInstr();
@@ -2522,7 +2508,7 @@
 	memset(editor.keyOnTab, 0, sizeof (editor.keyOnTab));
 
 	// copy over new pattern pointers and lengths
-	for (i = 0; i < MAX_PATTERNS; i++)
+	for (int32_t i = 0; i < MAX_PATTERNS; i++)
 	{
 		patt[i] = pattTmp[i];
 		pattLens[i] = pattLensTmp[i];
@@ -2529,7 +2515,7 @@
 	}
 
 	// copy over new instruments (includes sample pointers)
-	for (i = 1; i <= MAX_INST; i++)
+	for (int16_t i = 1; i <= MAX_INST; i++)
 	{
 		instr[i] = instrTmp[i];
 		fixSampleName(i);
@@ -2620,9 +2606,7 @@
 
 bool handleModuleLoadFromArg(int argc, char **argv)
 {
-	int32_t filesize;
-	uint32_t filenameLen;
-	UNICHAR *filenameU, tmpPathU[PATH_MAX+2];
+	UNICHAR tmpPathU[PATH_MAX+2];
 
 	// this is crude, we always expect only one parameter, and that it is the module.
 
@@ -2634,9 +2618,9 @@
 		return false; // OS X < 10.9 passes a -psn_x_xxxxx parameter on double-click launch
 #endif
 
-	filenameLen = (uint32_t)strlen(argv[1]);
+	const uint32_t filenameLen = (const uint32_t)strlen(argv[1]);
 
-	filenameU = (UNICHAR *)calloc(filenameLen+1, sizeof (UNICHAR));
+	UNICHAR *filenameU = (UNICHAR *)calloc(filenameLen+1, sizeof (UNICHAR));
 	if (filenameU == NULL)
 	{
 		okBox(0, "System message", "Not enough memory!");
@@ -2655,7 +2639,7 @@
 	// set path to where the main executable is
 	UNICHAR_CHDIR(editor.binaryPathU);
 
-	filesize = getFileSize(filenameU);
+	const int32_t filesize = getFileSize(filenameU);
 	if (filesize == -1 || filesize >= 512L*1024*1024) // >=2GB or >=512MB
 	{
 		okBox(0, "System message", "Error: The module is too big to be loaded!");
@@ -2678,17 +2662,14 @@
 
 void loadDroppedFile(char *fullPathUTF8, bool songModifiedCheck)
 {
-	int32_t fullPathLen, filesize;
-	UNICHAR *fullPathU;
-
 	if (ui.sysReqShown || fullPathUTF8 == NULL)
 		return;
 
-	fullPathLen = (int32_t)strlen(fullPathUTF8);
+	const int32_t fullPathLen = (const int32_t)strlen(fullPathUTF8);
 	if (fullPathLen == 0)
 		return;
 
-	fullPathU = (UNICHAR *)calloc(fullPathLen + 2, sizeof (UNICHAR));
+	UNICHAR *fullPathU = (UNICHAR *)calloc(fullPathLen + 2, sizeof (UNICHAR));
 	if (fullPathU == NULL)
 	{
 		okBox(0, "System message", "Not enough memory!");
@@ -2701,7 +2682,7 @@
 	strcpy(fullPathU, fullPathUTF8);
 #endif
 
-	filesize = getFileSize(fullPathU);
+	const int32_t filesize = getFileSize(fullPathU);
 
 	if (filesize == -1) // >2GB
 	{
--- a/src/ft2_module_saver.c
+++ b/src/ft2_module_saver.c
@@ -33,7 +33,7 @@
 
 bool saveXM(UNICHAR *filenameU)
 {
-	int16_t ap, ai, i, j, k, a;
+	int16_t i, j, k, a;
 	size_t result;
 	songHeaderTyp h;
 	patternHeaderTyp ph;
@@ -41,9 +41,8 @@
 	instrHeaderTyp ih;
 	sampleTyp *s;
 	sampleHeaderTyp *dst;
-	FILE *f;
 
-	f = UNICHAR_FOPEN(filenameU, "wb");
+	FILE *f = UNICHAR_FOPEN(filenameU, "wb");
 	if (f == NULL)
 	{
 		okBoxThreadSafe(0, "System message", "Error opening file for saving, is it in use?");
@@ -64,7 +63,7 @@
 	h.defSpeed = song.speed;
 
 	// count number of patterns
-	ap = MAX_PATTERNS;
+	int16_t ap = MAX_PATTERNS;
 	do
 	{
 		if (patternEmpty(ap - 1))
@@ -76,7 +75,7 @@
 	h.antPtn = ap;
 
 	// count number of instruments
-	ai = 128;
+	int16_t ai = 128;
 	while (ai > 0 && getUsedSamples(ai) == 0 && song.instrName[ai][0] == '\0')
 		ai--;
 	h.antInstrs = ai;
@@ -598,8 +597,6 @@
 
 static int32_t SDLCALL saveMusicThread(void *ptr)
 {
-	(void)ptr;
-
 	assert(editor.tmpFilenameU != NULL);
 	if (editor.tmpFilenameU == NULL)
 		return false;
@@ -613,6 +610,8 @@
 
 	resumeAudio();
 	return true;
+
+	(void)ptr;
 }
 
 void saveMusic(UNICHAR *filenameU)
@@ -632,17 +631,17 @@
 
 static uint16_t packPatt(uint8_t *writePtr, uint8_t *pattPtr, uint16_t numRows)
 {
-	uint8_t bytes[5], packBits, *firstBytePtr;
-	uint16_t totalPackLen;
+	uint8_t bytes[5];
 
-	totalPackLen = 0;
-
 	if (pattPtr == NULL)
 		return 0;
 
-	for (uint16_t row = 0; row < numRows; row++)
+	uint16_t totalPackLen = 0;
+
+	const int32_t pitch = sizeof (tonTyp) * (MAX_VOICES - song.antChn);
+	for (int32_t row = 0; row < numRows; row++)
 	{
-		for (uint16_t chn = 0; chn < song.antChn; chn++)
+		for (int32_t chn = 0; chn < song.antChn; chn++)
 		{
 			bytes[0] = *pattPtr++;
 			bytes[1] = *pattPtr++;
@@ -650,9 +649,9 @@
 			bytes[3] = *pattPtr++;
 			bytes[4] = *pattPtr++;
 
-			firstBytePtr = writePtr++;
+			uint8_t *firstBytePtr = writePtr++;
 
-			packBits = 0;
+			uint8_t packBits = 0;
 			if (bytes[0] > 0) { packBits |= 1; *writePtr++ = bytes[0]; } // note
 			if (bytes[1] > 0) { packBits |= 2; *writePtr++ = bytes[1]; } // instrument
 			if (bytes[2] > 0) { packBits |= 4; *writePtr++ = bytes[2]; } // volume column
@@ -682,7 +681,7 @@
 		}
 
 		// skip unused channels (unpacked patterns always have 32 channels)
-		pattPtr += sizeof (tonTyp) * (MAX_VOICES - song.antChn);
+		pattPtr += pitch;
 	}
 
 	return totalPackLen;
--- a/src/ft2_mouse.c
+++ b/src/ft2_mouse.c
@@ -45,7 +45,7 @@
 void freeMouseCursors(void)
 {
 	SDL_SetCursor(SDL_GetDefaultCursor());
-	for (uint32_t i = 0; i < NUM_CURSORS; i++)
+	for (int32_t i = 0; i < NUM_CURSORS; i++)
 	{
 		if (cursors[i] != NULL)
 		{
@@ -69,9 +69,9 @@
 		default: break;
 	}
 
-	for (uint32_t i = 0; i < NUM_CURSORS; i++)
+	for (int32_t i = 0; i < NUM_CURSORS; i++)
 	{
-		int32_t scaleFactor = video.yScale;
+		const int32_t scaleFactor = video.yScale;
 
 		SDL_Surface *surface = SDL_CreateRGBSurface(0, MOUSE_CURSOR_W*scaleFactor, MOUSE_CURSOR_H*scaleFactor, 32, 0, 0, 0, 0);
 		if (surface == NULL)
@@ -81,9 +81,9 @@
 			return false;
 		}
 
-		uint32_t colorkey = SDL_MapRGB(surface->format, 0x00, 0xFF, 0x00); // colorkey
-		uint32_t fg = SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF); // foreground
-		uint32_t border = SDL_MapRGB(surface->format, 0x00, 0x00, 0x00); // border
+		const uint32_t colorkey = SDL_MapRGB(surface->format, 0x00, 0xFF, 0x00); // colorkey
+		const uint32_t fg = SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF); // foreground
+		const uint32_t border = SDL_MapRGB(surface->format, 0x00, 0x00, 0x00); // border
 
 		SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
 		SDL_SetColorKey(surface, SDL_TRUE, colorkey);
@@ -102,19 +102,19 @@
 		SDL_LockSurface(surface);
 
 		uint32_t *dstPixels32 = (uint32_t *)surface->pixels;
-
 		for (int32_t k = 0; k < surface->w*surface->h; k++) // fill surface with colorkey pixels
 			dstPixels32[k] = colorkey;
 
 		// blit upscaled cursor to surface
-		for (uint32_t y = 0; y < MOUSE_CURSOR_H; y++)
+		for (int32_t y = 0; y < MOUSE_CURSOR_H; y++)
 		{
 			uint32_t *outX = &dstPixels32[(y * scaleFactor) * surface->w];
 			for (int32_t yScale = 0; yScale < scaleFactor; yScale++)
 			{
+				const uint8_t *srcPtr = &srcPixels8[y * MOUSE_CURSOR_W];
 				for (int32_t x = 0; x < MOUSE_CURSOR_W; x++)
 				{
-					uint8_t srcPix = srcPixels8[(y * MOUSE_CURSOR_W) + x];
+					const uint8_t srcPix = srcPtr[x];
 					if (srcPix != PAL_TRANSPR)
 					{
 						uint32_t pixel = colorkey;
@@ -247,11 +247,11 @@
 		gfxPtr = &bmp.mouseCursors[mouseModeGfxOffs];
 		switch (shape)
 		{
-			case MOUSE_IDLE_SHAPE_NICE: gfxPtr += 0 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
-			case MOUSE_IDLE_SHAPE_UGLY: gfxPtr += 1 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
-			case MOUSE_IDLE_SHAPE_AWFUL: gfxPtr += 2 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
-			case MOUSE_IDLE_SHAPE_USABLE: gfxPtr += 3 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
-			case MOUSE_IDLE_TEXT_EDIT: gfxPtr += 12 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
+			case MOUSE_IDLE_SHAPE_NICE:   gfxPtr +=  0 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
+			case MOUSE_IDLE_SHAPE_UGLY:   gfxPtr +=  1 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
+			case MOUSE_IDLE_SHAPE_AWFUL:  gfxPtr +=  2 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
+			case MOUSE_IDLE_SHAPE_USABLE: gfxPtr +=  3 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
+			case MOUSE_IDLE_TEXT_EDIT:    gfxPtr += 12 * (MOUSE_CURSOR_W * MOUSE_CURSOR_H); break;
 			default: return;
 		}
 	}
@@ -289,22 +289,21 @@
 
 static void changeCursorIfOverTextBoxes(void)
 {
-	int32_t i, mx, my;
-	textBox_t *t;
+	int32_t i;
 
 	mouse.mouseOverTextBox = false;
 	if (editor.busy || mouse.mode != MOUSE_MODE_NORMAL)
 		return;
 
-	mx = mouse.x;
-	my = mouse.y;
+	const int32_t mx = mouse.x;
+	const int32_t my = mouse.y;
 
-	for (i = 0; i < NUM_TEXTBOXES; i++)
+	textBox_t *t = textBoxes;
+	for (i = 0; i < NUM_TEXTBOXES; i++, t++)
 	{
 		if (ui.sysReqShown && i > 0)
 			continue;
 
-		t = &textBoxes[i];
 		if (!t->visible)
 			continue;
 
@@ -378,12 +377,10 @@
 
 static void mouseWheelDecRow(void)
 {
-	int16_t pattPos;
-
 	if (songPlaying)
 		return;
 
-	pattPos = editor.pattPos - 1;
+	int16_t pattPos = editor.pattPos - 1;
 	if (pattPos < 0)
 		pattPos = pattLens[editor.editPattern] - 1;
 
@@ -392,12 +389,10 @@
 
 static void mouseWheelIncRow(void)
 {
-	int16_t pattPos;
-
 	if (songPlaying)
 		return;
 
-	pattPos = editor.pattPos + 1;
+	int16_t pattPos = editor.pattPos + 1;
 	if (pattPos > (pattLens[editor.editPattern] - 1))
 		pattPos = 0;
 
@@ -528,12 +523,10 @@
 
 static bool testPatternDataMouseDown(void)
 {
-	uint16_t y1, y2;
-
 	if (ui.patternEditorShown)
 	{
-		y1 = ui.extended ? 56 : 176;
-		y2 = ui.pattChanScrollShown ? 382 : 396;
+		const int32_t y1 = ui.extended ? 56 : 176;
+		const int32_t y2 = ui.pattChanScrollShown ? 382 : 396;
 
 		if (mouse.y >= y1 && mouse.y <= y2 && mouse.x >= 29 && mouse.x <= 602)
 		{
@@ -726,7 +719,6 @@
 	SDL_Event event;
 
 	memset(&event, 0, sizeof (event));
-
 	event.type = SDL_MOUSEBUTTONUP;
 	event.button.button = button;
 
@@ -802,20 +794,26 @@
 	}
 
 	if (video.useDesktopMouseCoords)
+	{
 		mouse.buttonState = SDL_GetGlobalMouseState(&mx, &my);
+
+		// convert desktop coords to window coords
+		SDL_GetWindowPosition(video.window, &windowX, &windowY);
+		mx -= windowX;
+		my -= windowY;
+	}
 	else
+	{
+		// special mode for KMSDRM (XXX: Confirm that this still works...)
 		mouse.buttonState = SDL_GetMouseState(&mx, &my);
+	}
 
 	if (video.fullscreen)
 	{
-		/* If fullscreen without filtering mode, translate coords and warp mouse
-		** inside the render space.
-		** Fullscreen + filtering mode takes up 100% of the screen area used, so no
-		** need to translate coords in that mode.
-		*/
-
+		// centered fullscreen mode (not stretched) needs further coord translation
 		if (!(config.specialFlags2 & STRETCH_IMAGE))
 		{
+			// if software mouse is enabled, warp mouse inside render space
 			if (!(config.specialFlags2 & HARDWARE_MOUSE))
 			{
 				bool warpMouse = false;
@@ -850,16 +848,6 @@
 			mx -= video.renderX;
 			my -= vid