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 -= video.renderY;
}
- }
- else if (video.useDesktopMouseCoords)
- {
- // convert desktop coords to window coords
-
- // (a call to this function is really fast in windowed mode)
- SDL_GetWindowPosition(video.window, &windowX, &windowY);
-
- mx -= windowX;
- my -= windowY;
}
// multiply coords by video upscaling factors (don't round)
--- a/src/ft2_nibbles.c
+++ b/src/ft2_nibbles.c
@@ -12,6 +12,8 @@
#include "ft2_tables.h"
#include "ft2_structs.h"
+#define STAGES_BMP_WIDTH 530
+
#define NI_MAXLEVEL 30
static const char *NI_HelpText[] =
@@ -86,8 +88,8 @@
{
#define LUMINOSITY_THRESHOLD 4
- uint8_t wallColor1L = rgb24ToLuminosity(video.palette[PAL_DESKTOP]);
- uint8_t wallColor2L = rgb24ToLuminosity(video.palette[PAL_BUTTONS]);
+ const uint8_t wallColor1L = rgb24ToLuminosity(video.palette[PAL_DESKTOP]);
+ const uint8_t wallColor2L = rgb24ToLuminosity(video.palette[PAL_BUTTONS]);
/* Since the rest of the wall colors are based on lower and higher
** contrast values from these two primary colors, we don't really
@@ -104,20 +106,17 @@
static void redrawNibblesScreen(void)
{
- uint8_t x, y, c;
- int16_t xs, ys;
-
if (!editor.NI_Play)
return;
- for (x = 0; x < 51; x++)
+ for (int16_t x = 0; x < 51; x++)
{
- for (y = 0; y < 23; y++)
+ for (int16_t y = 0; y < 23; y++)
{
- xs = 152 + (x * 8);
- ys = 7 + (y * 7);
+ const int16_t xs = 152 + (x * 8);
+ const int16_t ys = 7 + (y * 7);
- c = NI_Screen[x][y];
+ const uint8_t c = NI_Screen[x][y];
if (c < 16)
{
if (config.NI_Grid)
@@ -153,9 +152,7 @@
static void nibblesAddBuffer(int16_t nr, uint8_t typ)
{
- nibbleBufferTyp *n;
-
- n = &nibblesBuffer[nr];
+ nibbleBufferTyp *n = &nibblesBuffer[nr];
if (n->antal < 8)
{
n->data[n->antal] = typ;
@@ -170,13 +167,10 @@
static int16_t nibblesGetBuffer(int16_t nr)
{
- int16_t dataOut;
- nibbleBufferTyp *n;
-
- n = &nibblesBuffer[nr];
+ nibbleBufferTyp *n = &nibblesBuffer[nr];
if (n->antal > 0)
{
- dataOut = n->data[0];
+ const int16_t dataOut = n->data[0];
memmove(&n->data[0], &n->data[1], 7);
n->antal--;
@@ -188,38 +182,39 @@
static void nibblesGetLevel(int16_t nr)
{
- int16_t readX, readY, x, y;
+ const int32_t readX = 1 + ((51+2) * (nr % 10));
+ const int32_t readY = 1 + ((23+2) * (nr / 10));
- readX = 1 + ((51+2) * (nr % 10));
- readY = 1 + ((23+2) * (nr / 10));
+ const uint8_t *stagePtr = &bmp.nibblesStages[(readY * STAGES_BMP_WIDTH) + readX];
- for (x = 0; x < 51; x++)
+ for (int32_t y = 0; y < 23; y++)
{
- for (y = 0; y < 23; y++)
- NI_Screen[x][y] = bmp.nibblesStages[((readY + y) * 530) + (readX + x)];
+ for (int32_t x = 0; x < 51; x++)
+ NI_Screen[x][y] = stagePtr[x];
+
+ stagePtr += STAGES_BMP_WIDTH;
}
}
static void nibblesCreateLevel(int16_t nr)
{
- uint8_t c;
- int16_t x, y, x1, y1, x2, y2;
-
if (nr >= NI_MAXLEVEL)
nr = NI_MAXLEVEL - 1;
nibblesGetLevel(nr);
- x1 = 0; x2 = 0;
- y1 = 0; y2 = 0;
+ int32_t x1 = 0;
+ int32_t x2 = 0;
+ int32_t y1 = 0;
+ int32_t y2 = 0;
- for (y = 0; y < 23; y++)
+ for (int32_t y = 0; y < 23; y++)
{
- for (x = 0; x < 51; x++)
+ for (int32_t x = 0; x < 51; x++)
{
if (NI_Screen[x][y] == 1 || NI_Screen[x][y] == 3)
{
- c = NI_Screen[x][y];
+ const uint8_t c = NI_Screen[x][y];
if (c == 3)
{
@@ -238,11 +233,11 @@
}
}
- x = (51 + 2) * (nr % 10);
- y = (23 + 2) * (nr / 10);
+ const int32_t readX = (51 + 2) * (nr % 10);
+ const int32_t readY = (23 + 2) * (nr / 10);
- NI_P1Dir = bmp.nibblesStages[(y * 530) + (x + 1)];
- NI_P2Dir = bmp.nibblesStages[(y * 530) + (x + 0)];
+ NI_P1Dir = bmp.nibblesStages[(readY * 530) + (readX + 1)];
+ NI_P2Dir = bmp.nibblesStages[(readY * 530) + (readX + 0)];
NI_P1Len = 5;
NI_P2Len = 5;
@@ -252,7 +247,7 @@
nibblesBuffer[0].antal = 0;
nibblesBuffer[1].antal = 0;
- for (int16_t i = 0; i < 256; i++)
+ for (int32_t i = 0; i < 256; i++)
{
NI_P1[i].x = (uint8_t)x1;
NI_P1[i].y = (uint8_t)y1;
@@ -263,23 +258,19 @@
static void nibbleWriteLevelSprite(int16_t xOut, int16_t yOut, int16_t nr)
{
- uint8_t *src;
- uint16_t readX, readY;
- uint32_t *dst;
+ const int32_t readX = (51 + 2) * (nr % 10);
+ const int32_t readY = (23 + 2) * (nr / 10);
- readX = (51 + 2) * (nr % 10);
- readY = (23 + 2) * (nr / 10);
+ const uint8_t *src = (const uint8_t *)&bmp.nibblesStages[(readY * 530) + readX];
+ uint32_t *dst = &video.frameBuffer[(yOut * SCREEN_W) + xOut];
- src = (uint8_t *)&bmp.nibblesStages[(readY * 530) + readX];
- dst = &video.frameBuffer[(yOut * SCREEN_W) + xOut];
-
- for (uint16_t y = 0; y < 23+2; y++)
+ for (int32_t y = 0; y < 23+2; y++)
{
- for (uint16_t x = 0; x < 51+2; x++)
- *dst++ = video.palette[*src++];
+ for (int32_t x = 0; x < 51+2; x++)
+ dst[x] = video.palette[src[x]];
- src += 530 - (51+2);
- dst += SCREEN_W - (51+2);
+ src += 530;
+ dst += SCREEN_W;
}
// overwrite start position pixels
@@ -289,15 +280,12 @@
static void highScoreTextOutClipX(uint16_t x, uint16_t y, uint8_t paletteIndex, uint8_t shadowPaletteIndex, const char *textPtr, uint16_t clipX)
{
- char ch;
- uint16_t currX;
-
assert(textPtr != NULL);
- currX = x;
+ uint16_t currX = x;
for (uint16_t i = 0; i < 22; i++)
{
- ch = textPtr[i];
+ const char ch = textPtr[i];
if (ch == '\0')
break;
@@ -335,11 +323,9 @@
static void setNibbleDot(uint8_t x, uint8_t y, uint8_t c)
{
- uint16_t xs, ys;
+ const uint16_t xs = 152 + (x * 8);
+ const uint16_t ys = 7 + (y * 7);
- xs = 152 + (x * 8);
- ys = 7 + (y * 7);
-
if (config.NI_Grid)
{
fillRect(xs + 0, ys + 0, 8 - 0, 7 - 0, PAL_BUTTON2);
@@ -355,12 +341,10 @@
static void nibblesGenNewNumber(void)
{
- int16_t x, y, xs, ys;
-
while (true)
{
- x = rand() % 51;
- y = rand() % 23;
+ const int16_t x = rand() % 51;
+ const int16_t y = rand() % 23;
bool blockIsSuitable;
@@ -376,8 +360,8 @@
NI_NumberX = x;
NI_NumberY = y;
- xs = 152 + (x * 8);
- ys = 7 + (y * 7);
+ const int16_t xs = 152 + (x * 8);
+ const int16_t ys = 7 + (y * 7);
if (config.NI_Grid)
{
@@ -435,7 +419,7 @@
static void nibblesDecLives(int16_t l1, int16_t l2)
{
- char name[21 + 1];
+ char name[21+1];
int16_t i, k;
highScoreType *h;
@@ -539,7 +523,7 @@
{
char text[24];
- sprintf(text, "Level %d finished!", NI_Level + 1);
+ sprintf(text, "Level %d finished!", NI_Level+1);
okBox(0, "Nibbles message", text);
// cast to int16_t to simulate a bug in FT2
@@ -567,8 +551,6 @@
void moveNibblePlayers(void)
{
- int16_t i, j;
-
if (ui.sysReqShown || --NI_CurTick60Hz != 0)
return;
@@ -663,8 +645,8 @@
}
}
- j = 0;
- i = NI_Screen[NI_P1[0].x][NI_P1[0].y];
+ int16_t j = 0;
+ int16_t i = NI_Screen[NI_P1[0].x][NI_P1[0].y];
if (i >= 16)
{
NI_P1Score += (i & 15) * 999 * (NI_Level + 1);
@@ -876,7 +858,7 @@
clearRect(152, 7, 409, 162);
bigTextOut(160, 10, PAL_FORGRND, "Fasttracker Nibbles Help");
- for (uint8_t i = 0; i < NIBBLES_HELP_LINES; i++)
+ for (uint16_t i = 0; i < NIBBLES_HELP_LINES; i++)
textOut(160, 36 + (11 * i), PAL_BUTTONS, NI_HelpText[i]);
}
--- a/src/ft2_palette.c
+++ b/src/ft2_palette.c
@@ -94,14 +94,12 @@
static void drawCurrentPaletteColor(void)
{
- uint8_t r, g, b, palIndex;
+ const uint8_t palIndex = FTC_EditOrder[cfg_ColorNr];
- palIndex = FTC_EditOrder[cfg_ColorNr];
+ const uint8_t r = P6_TO_P8(cfg_Red);
+ const uint8_t g = P6_TO_P8(cfg_Green);
+ const uint8_t b = P6_TO_P8(cfg_Blue);
- r = P6_TO_P8(cfg_Red);
- g = P6_TO_P8(cfg_Green);
- b = P6_TO_P8(cfg_Blue);
-
textOutShadow(516, 3, PAL_FORGRND, PAL_DSKTOP2, "Palette:");
hexOutBg(573, 3, PAL_FORGRND, PAL_DESKTOP, RGB32(r, g, b) & 0xFFFFFF, 6);
clearRect(616, 2, 12, 10);
@@ -110,7 +108,7 @@
static void updatePaletteEditor(void)
{
- uint8_t nr = FTC_EditOrder[cfg_ColorNr];
+ const uint8_t nr = FTC_EditOrder[cfg_ColorNr];
cfg_Red = palTable[config.cfg_StdPalNr][nr].r;
cfg_Green = palTable[config.cfg_StdPalNr][nr].g;
@@ -131,9 +129,6 @@
static void paletteDragMoved(void)
{
- uint8_t nr, p;
- int16_t i, k;
-
if (config.cfg_StdPalNr != PAL_USER_DEFINED)
{
updatePaletteEditor(); // resets colors/contrast vars
@@ -148,8 +143,8 @@
return;
}
- nr = FTC_EditOrder[cfg_ColorNr];
- p = (uint8_t)config.cfg_StdPalNr;
+ const uint8_t nr = FTC_EditOrder[cfg_ColorNr];
+ const uint8_t p = (uint8_t)config.cfg_StdPalNr;
palTable[p][nr].r = cfg_Red;
palTable[p][nr].g = cfg_Green;
@@ -165,11 +160,11 @@
if (contrast < 1)
contrast = 1;
- double dContrast = contrast * (1.0 / 40.0);
+ const double dContrast = contrast * (1.0 / 40.0);
- for (i = 0; i < 3; i++)
+ for (int32_t i = 0; i < 3; i++)
{
- k = scaleOrder[i] + (cfg_ColorNr - 4) * 2;
+ const int32_t k = scaleOrder[i] + (cfg_ColorNr - 4) * 2;
double dMul = palPow((i + 1) * (1.0 / 2.0), dContrast);
--- a/src/ft2_pattern_draw.c
+++ b/src/ft2_pattern_draw.c
@@ -46,7 +46,7 @@
void updatePattFontPtrs(void)
{
- //config.ptnFont is pre-clamped and safe
+ //config.ptnFont is pre-clamped and safe to use
font4Ptr = &bmp.font4[config.ptnFont * (FONT4_WIDTH * FONT4_CHAR_H)];
font5Ptr = &bmp.font4[(4 + config.ptnFont) * (FONT4_WIDTH * FONT4_CHAR_H)];
}
@@ -53,18 +53,13 @@
void drawPatternBorders(void)
{
- uint8_t chans;
- uint16_t xOffs, chanWidth;
- int32_t clearSize;
- const pattCoord2_t *pattCoord;
-
// get heights/pos/rows depending on configuration
- pattCoord = &pattCoord2Table[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
+ const pattCoord2_t *pattCoord = &pattCoord2Table[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
// set pattern cursor Y position
editor.ptnCursorY = pattCoord->lowerRowsY - 9;
- chans = ui.numChannelsShown;
+ int32_t chans = ui.numChannelsShown;
if (chans > ui.maxVisibleChannels)
chans = ui.maxVisibleChannels;
@@ -76,7 +71,7 @@
assert(chans >= 2 && chans <= 12);
- chanWidth = chanWidths[(chans / 2) - 1] + 2;
+ const uint16_t chanWidth = chanWidths[(chans >> 1) - 1] + 2;
// fill scrollbar framework (if needed)
if (ui.pattChanScrollShown)
@@ -131,8 +126,8 @@
drawFramework(604, pattCoord->lowerRowsY, 26, pattCoord->lowerRowsH, FRAMEWORK_TYPE2); // bottom right
// draw channels
- xOffs = 28;
- for (uint8_t i = 0; i < chans; i++)
+ uint16_t xOffs = 28;
+ for (int32_t i = 0; i < chans; i++)
{
vLine(xOffs - 1, pattCoord->upperRowsY, pattCoord->upperRowsH, PAL_DESKTOP);
vLine(xOffs - 1, pattCoord->lowerRowsY, pattCoord->lowerRowsH + 1, PAL_DESKTOP);
@@ -152,12 +147,12 @@
if (ui.extended)
{
- clearSize = ui.pattChanScrollShown ? (SCREEN_W * sizeof (int32_t) * 330) : (SCREEN_W * sizeof (int32_t) * 347);
+ const int32_t clearSize = ui.pattChanScrollShown ? (SCREEN_W * sizeof (int32_t) * 330) : (SCREEN_W * sizeof (int32_t) * 347);
memset(&video.frameBuffer[53 * SCREEN_W], 0, clearSize);
}
else
{
- clearSize = ui.pattChanScrollShown ? (SCREEN_W * sizeof(int32_t) * 210) : (SCREEN_W * sizeof(int32_t) * 227);
+ const int32_t clearSize = ui.pattChanScrollShown ? (SCREEN_W * sizeof(int32_t) * 210) : (SCREEN_W * sizeof(int32_t) * 227);
memset(&video.frameBuffer[173 * SCREEN_W], 0, clearSize);
}
@@ -182,20 +177,18 @@
static void writeCursor(void)
{
- uint32_t *dstPtr, xPos, width, tabOffset;
+ const int32_t tabOffset = (config.ptnS3M * 32) + (columnModeTab[ui.numChannelsShown-1] * 8) + cursor.object;
- tabOffset = (config.ptnS3M * 32) + (columnModeTab[ui.numChannelsShown - 1] * 8) + cursor.object;
+ int32_t xPos = pattCursorXTab[tabOffset];
+ const int32_t width = pattCursorWTab[tabOffset];
- xPos = pattCursorXTab[tabOffset];
- width = pattCursorWTab[tabOffset];
-
assert(editor.ptnCursorY > 0 && xPos > 0 && width > 0);
xPos += ((cursor.ch - ui.channelOffset) * ui.patternChannelWidth);
- dstPtr = &video.frameBuffer[(editor.ptnCursorY * SCREEN_W) + xPos];
- for (uint32_t y = 0; y < 9; y++)
+ uint32_t *dstPtr = &video.frameBuffer[(editor.ptnCursorY * SCREEN_W) + xPos];
+ for (int32_t y = 0; y < 9; y++)
{
- for (uint32_t x = 0; x < width; x++)
+ for (int32_t x = 0; x < width; x++)
dstPtr[x] = video.palette[(dstPtr[x] >> 24) ^ 4]; // ">> 24" to get palette, XOR 4 to change to cursor palette
dstPtr += SCREEN_W;
@@ -204,35 +197,33 @@
static void writePatternBlockMark(int32_t currRow, uint32_t rowHeight, const pattCoord_t *pattCoord)
{
- int32_t startCh, endCh, startRow, endRow, x1, x2, y1, y2, pattYStart, pattYEnd;
- uint32_t w, h, *ptr32;
- const markCoord_t *markCoord;
+ int32_t y1, y2;
// this can happen (buggy FT2 code), treat like no mark
if (pattMark.markY1 > pattMark.markY2)
return;
- startCh = ui.channelOffset;
- endCh = ui.channelOffset + (ui.numChannelsShown - 1);
- startRow = currRow - pattCoord->numUpperRows;
- endRow = currRow + pattCoord->numLowerRows;
+ const int32_t startCh = ui.channelOffset;
+ const int32_t endCh = ui.channelOffset + (ui.numChannelsShown - 1);
+ const int32_t startRow = currRow - pattCoord->numUpperRows;
+ const int32_t endRow = currRow + pattCoord->numLowerRows;
// test if pattern marking is outside of visible area (don't draw)
if (pattMark.markX1 > endCh || pattMark.markX2 < startCh || pattMark.markY1 > endRow || pattMark.markY2 < startRow)
return;
- markCoord = &markCoordTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
- pattYStart = markCoord->upperRowsY;
+ const markCoord_t *markCoord = &markCoordTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
+ const int32_t pattYStart = markCoord->upperRowsY;
// X1
- x1 = 32 + ((pattMark.markX1 - ui.channelOffset) * ui.patternChannelWidth);
+ int32_t x1 = 32 + ((pattMark.markX1 - ui.channelOffset) * ui.patternChannelWidth);
if (x1 < 32)
x1 = 32;
// X2
- x2 = (32 - 8) + (((pattMark.markX2 + 1) - ui.channelOffset) * ui.patternChannelWidth);
+ int32_t x2 = (32 - 8) + (((pattMark.markX2 + 1) - ui.channelOffset) * ui.patternChannelWidth);
if (x2 > 608)
x2 = 608;
@@ -265,7 +256,7 @@
}
else
{
- pattYEnd = markCoord->lowerRowsY + (pattCoord->numLowerRows * rowHeight);
+ const int32_t pattYEnd = markCoord->lowerRowsY + (pattCoord->numLowerRows * rowHeight);
y2 = markCoord->lowerRowsY + ((pattMark.markY2 - (currRow + 1)) * rowHeight);
if (y2 > pattYEnd)
@@ -291,15 +282,15 @@
// pattern mark drawing
- w = x2 - x1;
- h = y2 - y1;
+ const int32_t w = x2 - x1;
+ const int32_t h = y2 - y1;
assert(x1+w <= SCREEN_W && y1+h <= SCREEN_H);
- ptr32 = &video.frameBuffer[(y1 * SCREEN_W) + x1];
- for (uint32_t y = 0; y < h; y++)
+ uint32_t *ptr32 = &video.frameBuffer[(y1 * SCREEN_W) + x1];
+ for (int32_t y = 0; y < h; y++)
{
- for (uint32_t x = 0; x < w; x++)
+ for (int32_t x = 0; x < w; x++)
ptr32[x] = video.palette[(ptr32[x] >> 24) ^ 2]; // ">> 24" to get palette of pixel, XOR 2 to change to mark palette
ptr32 += SCREEN_W;
@@ -308,9 +299,7 @@
static void drawChannelNumbering(uint16_t yPos)
{
-#define CH_NUM_XPOS 30
-
- uint16_t xPos = CH_NUM_XPOS;
+ uint16_t xPos = 30;
int32_t ch = ui.channelOffset + 1;
for (uint8_t i = 0; i < ui.numChannelsShown; i++)
@@ -335,8 +324,7 @@
#define LEFT_ROW_XPOS 8
#define RIGHT_ROW_XPOS 608
- const uint8_t *src1Ptr, *src2Ptr;
- uint32_t *dst1Ptr, *dst2Ptr, pixVal;
+ uint32_t pixVal;
// set color based on some conditions
if (selectedRowFlag)
@@ -349,14 +337,14 @@
if (!config.ptnHex)
row = hex2Dec[row];
- src1Ptr = &font4Ptr[(row >> 4) * FONT4_CHAR_W];
- src2Ptr = &font4Ptr[(row & 0x0F) * FONT4_CHAR_W];
- dst1Ptr = &video.frameBuffer[(yPos * SCREEN_W) + LEFT_ROW_XPOS];
- dst2Ptr = dst1Ptr + (RIGHT_ROW_XPOS - LEFT_ROW_XPOS);
+ const uint8_t *src1Ptr = &font4Ptr[(row >> 4) * FONT4_CHAR_W];
+ const uint8_t *src2Ptr = &font4Ptr[(row & 0x0F) * FONT4_CHAR_W];
+ uint32_t *dst1Ptr = &video.frameBuffer[(yPos * SCREEN_W) + LEFT_ROW_XPOS];
+ uint32_t *dst2Ptr = dst1Ptr + (RIGHT_ROW_XPOS - LEFT_ROW_XPOS);
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W; x++)
{
if (src1Ptr[x])
{
@@ -408,7 +396,7 @@
static void showInstrNum(uint32_t xPos, uint32_t yPos, uint8_t ins, uint32_t color)
{
- uint8_t chr1, chr2, charW, fontType;
+ uint8_t charW, fontType;
if (ui.numChannelsShown <= 4)
{
@@ -436,8 +424,8 @@
}
else
{
- chr1 = ins >> 4;
- chr2 = ins & 0x0F;
+ const uint8_t chr1 = ins >> 4;
+ const uint8_t chr2 = ins & 0x0F;
if (chr1 > 0)
pattCharOut(xPos, yPos, chr1, fontType, color);
@@ -559,7 +547,7 @@
static void showInstrNumNoVolColumn(uint32_t xPos, uint32_t yPos, uint8_t ins, uint32_t color)
{
- uint8_t chr1, chr2, charW, fontType;
+ uint8_t charW, fontType;
if (ui.numChannelsShown <= 4)
{
@@ -593,8 +581,8 @@
}
else
{
- chr1 = ins >> 4;
- chr2 = ins & 0x0F;
+ const uint8_t chr1 = ins >> 4;
+ const uint8_t chr2 = ins & 0x0F;
if (chr1 > 0)
pattCharOut(xPos, yPos, chr1, fontType, color);
@@ -606,7 +594,6 @@
static void showNoVolEfx(uint32_t xPos, uint32_t yPos, uint8_t vol, uint32_t color)
{
- // make compiler happy
(void)xPos;
(void)yPos;
(void)vol;
@@ -649,11 +636,8 @@
void writePattern(int32_t currRow, int32_t pattern)
{
- int32_t row, rowsOnScreen, numRows, afterCurrRow, numChannels;
- int32_t textY, midRowTextY, lowerRowsTextY, xPos, xWidth;
- uint32_t rowHeight, chanWidth, chans, noteTextColors[2], color;
- tonTyp *note, *pattPtr;
- const pattCoord_t *pattCoord;
+ uint32_t noteTextColors[2];
+
void (*drawNote)(uint32_t, uint32_t, int16_t, uint32_t);
void (*drawInst)(uint32_t, uint32_t, uint8_t, uint32_t);
void (*drawVolEfx)(uint32_t, uint32_t, uint8_t, uint32_t);
@@ -668,7 +652,7 @@
// setup variables
- chans = ui.numChannelsShown;
+ uint32_t chans = ui.numChannelsShown;
if (chans > ui.maxVisibleChannels)
chans = ui.maxVisibleChannels;
@@ -675,25 +659,24 @@
assert(chans >= 2 && chans <= 12);
// get channel width
- chanWidth = chanWidths[(chans / 2) - 1];
+ const uint32_t chanWidth = chanWidths[(chans / 2) - 1];
ui.patternChannelWidth = (uint16_t)(chanWidth + 3);
// get heights/pos/rows depending on configuration
- rowHeight = config.ptnUnpressed ? 11 : 8;
- pattCoord = &pattCoordTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
- midRowTextY = pattCoord->midRowTextY;
- lowerRowsTextY = pattCoord->lowerRowsTextY;
- row = currRow - pattCoord->numUpperRows;
- rowsOnScreen = pattCoord->numUpperRows + 1 + pattCoord->numLowerRows;
- textY = pattCoord->upperRowsTextY;
+ uint32_t rowHeight = config.ptnUnpressed ? 11 : 8;
+ const pattCoord_t *pattCoord = &pattCoordTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
+ const int32_t midRowTextY = pattCoord->midRowTextY;
+ const int32_t lowerRowsTextY = pattCoord->lowerRowsTextY;
+ int32_t row = currRow - pattCoord->numUpperRows;
+ const int32_t rowsOnScreen = pattCoord->numUpperRows + 1 + pattCoord->numLowerRows;
+ int32_t textY = pattCoord->upperRowsTextY;
+ const int32_t afterCurrRow = currRow + 1;
+ const int32_t numChannels = ui.numChannelsShown;
+ tonTyp *pattPtr = patt[pattern];
+ const int32_t numRows = pattLens[pattern];
- afterCurrRow = currRow + 1;
- numChannels = ui.numChannelsShown;
- pattPtr = patt[pattern];
- numRows = pattLens[pattern];
- noteTextColors[0] = video.palette[PAL_PATTEXT]; // not selected
- noteTextColors[1] = video.palette[PAL_FORGRND]; // selected
+
// increment pattern data pointer by horizontal scrollbar offset/channel
if (pattPtr != NULL)
pattPtr += ui.channelOffset;
@@ -714,25 +697,24 @@
drawEfx = showEfxNoVolColumn;
}
+ noteTextColors[0] = video.palette[PAL_PATTEXT]; // not selected
+ noteTextColors[1] = video.palette[PAL_FORGRND]; // selected
+
// draw pattern data
for (int32_t i = 0; i < rowsOnScreen; i++)
{
if (row >= 0)
{
- bool selectedRowFlag = row == currRow;
+ const bool selectedRowFlag = (row == currRow);
drawRowNums(textY, (uint8_t)row, selectedRowFlag);
-
- if (pattPtr == NULL)
- note = emptyPattern;
- else
- note = &pattPtr[(uint32_t)row * MAX_VOICES];
- xPos = 29;
- xWidth = ui.patternChannelWidth;
+ const tonTyp *note = (pattPtr == NULL) ? emptyPattern : &pattPtr[(uint32_t)row * MAX_VOICES];
+ const int32_t xWidth = ui.patternChannelWidth;
+ const uint32_t color = noteTextColors[selectedRowFlag];
- color = noteTextColors[selectedRowFlag];
- for (int32_t j = 0; j < numChannels; j++)
+ int32_t xPos = 29;
+ for (int32_t j = 0; j < numChannels; j++, note++)
{
drawNote(xPos, textY, note->ton, color);
drawInst(xPos, textY, note->instr, color);
@@ -740,7 +722,6 @@
drawEfx(xPos, textY, note->effTyp, note->eff, color);
xPos += xWidth;
- note++;
}
}
@@ -772,19 +753,13 @@
void pattTwoHexOut(uint32_t xPos, uint32_t yPos, uint8_t val, uint32_t color)
{
- const uint8_t *ch1Ptr, *ch2Ptr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ const uint8_t *ch1Ptr = &font4Ptr[(val >> 4) * FONT4_CHAR_W];
+ const uint8_t *ch2Ptr = &font4Ptr[(val & 0x0F) * FONT4_CHAR_W];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- ch1Ptr = &font4Ptr[(val >> 4) * FONT4_CHAR_W];
- ch2Ptr = &font4Ptr[(val & 0x0F) * FONT4_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W; x++)
{
#ifdef __arm__
if (ch1Ptr[x] != 0) dstPtr[x] = color;
@@ -791,7 +766,7 @@
if (ch2Ptr[x] != 0) dstPtr[FONT4_CHAR_W+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 (ch1Ptr[x] != 0) tmp = color;
dstPtr[x] = tmp;
@@ -810,12 +785,12 @@
static void pattCharOut(uint32_t xPos, uint32_t yPos, uint8_t chr, uint8_t fontType, uint32_t color)
{
const uint8_t *srcPtr;
- uint32_t x, y, *dstPtr;
+ int32_t x, y;
#ifndef __arm__
uint32_t tmp;
#endif
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
if (fontType == FONT_TYPE3)
{
@@ -909,18 +884,12 @@
static void drawEmptyNoteSmall(uint32_t xPos, uint32_t yPos, uint32_t color)
{
- const uint8_t *srcPtr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ const uint8_t *srcPtr = &bmp.font7[18 * FONT7_CHAR_W];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- srcPtr = &bmp.font7[18 * FONT7_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-
- for (uint32_t y = 0; y < FONT7_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT7_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT7_CHAR_W*3; x++)
+ for (int32_t x = 0; x < FONT7_CHAR_W*3; x++)
{
#ifdef __arm__
if (srcPtr[x] != 0)
@@ -927,7 +896,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
@@ -940,18 +909,12 @@
static void drawKeyOffSmall(uint32_t xPos, uint32_t yPos, uint32_t color)
{
- const uint8_t *srcPtr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ const uint8_t *srcPtr = &bmp.font7[21 * FONT7_CHAR_W];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + (xPos + 2)];
- srcPtr = &bmp.font7[21 * FONT7_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + (xPos + 2)];
-
- for (uint32_t y = 0; y < FONT7_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT7_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT7_CHAR_W*2; x++)
+ for (int32_t x = 0; x < FONT7_CHAR_W*2; x++)
{
#ifdef __arm__
if (srcPtr[x] != 0)
@@ -958,7 +921,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
@@ -971,19 +934,13 @@
static void drawNoteSmall(uint32_t xPos, uint32_t yPos, int32_t ton, uint32_t color)
{
- const uint8_t *ch1Ptr, *ch2Ptr, *ch3Ptr;
- uint8_t note;
- uint32_t *dstPtr, char1, char2, char3;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ uint32_t char1, char2;
assert(ton >= 1 && ton <= 97);
-
ton--;
- note = noteTab1[ton];
- char3 = noteTab2[ton] * FONT7_CHAR_W;
+ const uint8_t note = noteTab1[ton];
+ const uint32_t char3 = noteTab2[ton] * FONT7_CHAR_W;
if (config.ptnAcc == 0)
{
@@ -996,14 +953,14 @@
char2 = flatNote2Char_small[note];
}
- ch1Ptr = &bmp.font7[char1];
- ch2Ptr = &bmp.font7[char2];
- ch3Ptr = &bmp.font7[char3];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+ const uint8_t *ch1Ptr = &bmp.font7[char1];
+ const uint8_t *ch2Ptr = &bmp.font7[char2];
+ const uint8_t *ch3Ptr = &bmp.font7[char3];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- for (uint32_t y = 0; y < FONT7_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT7_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT7_CHAR_W; x++)
+ for (int32_t x = 0; x < FONT7_CHAR_W; x++)
{
#ifdef __arm__
if (ch1Ptr[x] != 0) dstPtr[x] = color;
@@ -1011,7 +968,7 @@
if (ch3Ptr[x] != 0) dstPtr[((FONT7_CHAR_W*2)-2)+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 (ch1Ptr[x] != 0) tmp = color;
dstPtr[x] = tmp;
@@ -1034,18 +991,12 @@
static void drawEmptyNoteMedium(uint32_t xPos, uint32_t yPos, uint32_t color)
{
- const uint8_t *srcPtr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+ const uint8_t *srcPtr = &font4Ptr[43 * FONT4_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- srcPtr = &font4Ptr[43 * FONT4_CHAR_W];
-
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W*3; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W*3; x++)
{
#ifdef __arm__
if (srcPtr[x] != 0)
@@ -1052,7 +1003,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
@@ -1065,18 +1016,12 @@
static void drawKeyOffMedium(uint32_t xPos, uint32_t yPos, uint32_t color)
{
- const uint8_t *srcPtr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ const uint8_t *srcPtr = &font4Ptr[40 * FONT4_CHAR_W];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- srcPtr = &font4Ptr[40 * FONT4_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W*3; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W*3; x++)
{
#ifdef __arm__
if (srcPtr[x] != 0)
@@ -1083,7 +1028,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
@@ -1096,16 +1041,12 @@
static void drawNoteMedium(uint32_t xPos, uint32_t yPos, int32_t ton, uint32_t color)
{
- const uint8_t *ch1Ptr, *ch2Ptr, *ch3Ptr;
- uint32_t note, *dstPtr, char1, char2, char3;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ uint32_t char1, char2;
ton--;
- note = noteTab1[ton];
- char3 = noteTab2[ton] * FONT4_CHAR_W;
+ const uint8_t note = noteTab1[ton];
+ const uint32_t char3 = noteTab2[ton] * FONT4_CHAR_W;
if (config.ptnAcc == 0)
{
@@ -1118,14 +1059,14 @@
char2 = flatNote2Char_med[note];
}
- ch1Ptr = &font4Ptr[char1];
- ch2Ptr = &font4Ptr[char2];
- ch3Ptr = &font4Ptr[char3];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+ const uint8_t *ch1Ptr = &font4Ptr[char1];
+ const uint8_t *ch2Ptr = &font4Ptr[char2];
+ const uint8_t *ch3Ptr = &font4Ptr[char3];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W; x++)
{
#ifdef __arm__
if (ch1Ptr[x] != 0) dstPtr[x] = color;
@@ -1133,7 +1074,7 @@
if (ch3Ptr[x] != 0) dstPtr[(FONT4_CHAR_W*2)+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 (ch1Ptr[x] != 0) tmp = color;
dstPtr[x] = tmp;
@@ -1156,18 +1097,12 @@
static void drawEmptyNoteBig(uint32_t xPos, uint32_t yPos, uint32_t color)
{
- const uint8_t *srcPtr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ const uint8_t *srcPtr = &font4Ptr[67 * FONT4_CHAR_W];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- srcPtr = &font4Ptr[67 * FONT4_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W*6; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W*6; x++)
{
#ifdef __arm__
if (srcPtr[x] != 0)
@@ -1174,7 +1109,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
@@ -1187,18 +1122,12 @@
static void drawKeyOffBig(uint32_t xPos, uint32_t yPos, uint32_t color)
{
- const uint8_t *srcPtr;
- uint32_t *dstPtr;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ const uint8_t *srcPtr = &bmp.font4[61 * FONT4_CHAR_W];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- srcPtr = &bmp.font4[61 * FONT4_CHAR_W];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-
- for (uint32_t y = 0; y < FONT4_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT4_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT4_CHAR_W*6; x++)
+ for (int32_t x = 0; x < FONT4_CHAR_W*6; x++)
{
#ifdef __arm__
if (srcPtr[x] != 0)
@@ -1205,7 +1134,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
@@ -1218,16 +1147,12 @@
static void drawNoteBig(uint32_t xPos, uint32_t yPos, int32_t ton, uint32_t color)
{
- const uint8_t *ch1Ptr, *ch2Ptr, *ch3Ptr;
- uint8_t note;
- uint32_t *dstPtr, char1, char2, char3;
-#ifndef __arm__
- uint32_t tmp;
-#endif
+ uint32_t char1, char2;
+
ton--;
- note = noteTab1[ton];
- char3 = noteTab2[ton] * FONT5_CHAR_W;
+ const uint8_t note = noteTab1[ton];
+ const uint32_t char3 = noteTab2[ton] * FONT5_CHAR_W;
if (config.ptnAcc == 0)
{
@@ -1240,14 +1165,14 @@
char2 = flatNote2Char_big[note];
}
- ch1Ptr = &font5Ptr[char1];
- ch2Ptr = &font5Ptr[char2];
- ch3Ptr = &font5Ptr[char3];
- dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
+ const uint8_t *ch1Ptr = &font5Ptr[char1];
+ const uint8_t *ch2Ptr = &font5Ptr[char2];
+ const uint8_t *ch3Ptr = &font5Ptr[char3];
+ uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
- for (uint32_t y = 0; y < FONT5_CHAR_H; y++)
+ for (int32_t y = 0; y < FONT5_CHAR_H; y++)
{
- for (uint32_t x = 0; x < FONT5_CHAR_W; x++)
+ for (int32_t x = 0; x < FONT5_CHAR_W; x++)
{
#ifdef __arm__
if (ch1Ptr[x] != 0) dstPtr[x] = color;
@@ -1255,7 +1180,7 @@
if (ch3Ptr[x] != 0) dstPtr[(FONT5_CHAR_W*2)+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 (ch1Ptr[x] != 0) tmp = color;
dstPtr[x] = tmp;
--- a/src/ft2_pattern_ed.c
+++ b/src/ft2_pattern_ed.c
@@ -66,7 +66,6 @@
return false;
}
- // XXX: Do we really need this? Sounds redundant.
song.pattLen = pattLens[nr];
}
@@ -97,23 +96,11 @@
uint8_t getMaxVisibleChannels(void)
{
+ assert(config.ptnMaxChannels >= 0 && config.ptnMaxChannels <= 3);
if (config.ptnS3M)
- {
- if (config.ptnMaxChannels == 0) return 4;
- else if (config.ptnMaxChannels == 1) return 6;
- else if (config.ptnMaxChannels == 2) return 8;
- else if (config.ptnMaxChannels == 3) return 8;
-
- }
+ return maxVisibleChans1[config.ptnMaxChannels];
else
- {
- if (config.ptnMaxChannels == 0) return 4;
- else if (config.ptnMaxChannels == 1) return 6;
- else if (config.ptnMaxChannels == 2) return 8;
- else if (config.ptnMaxChannels == 3) return 12;
- }
-
- return 8;
+ return maxVisibleChans2[config.ptnMaxChannels];
}
void updatePatternWidth(void)
@@ -499,7 +486,7 @@
static void updatePatternEditorGUI(void)
{
- uint8_t i;
+ uint16_t i;
pushButton_t *p;
textBox_t *t;
@@ -508,10 +495,9 @@
// extended pattern editor
// instrument names
- for (i = 0; i < 8; i++)
+ t = &textBoxes[TB_INST1];
+ for (i = 0; i < 8; i++, t++)
{
- t = &textBoxes[TB_INST1+i];
-
if (i < 4)
{
t->x = 406;
@@ -557,10 +543,9 @@
pushButtons[PB_PATTLEN_DOWN].y = 37;
// instrument switcher
- for (i = 0; i < 16; i++)
+ p = &pushButtons[PB_RANGE1];
+ for (i = 0; i < 16; i++, p++)
{
- p = &pushButtons[PB_RANGE1+i];
-
p->w = iSwitchExtW[i & 3];
p->x = iSwitchExtX[i & 3];
p->y = iSwitchExtY[i & 7];
@@ -569,10 +554,9 @@
else
{
// instrument names
- for (i = 0; i < 8; i++)
+ t = &textBoxes[TB_INST1];
+ for (i = 0; i < 8; i++, t++)
{
- t = &textBoxes[TB_INST1+i];
-
t->y = 5 + (i * 11);
t->x = 446;
t->w = 140;
@@ -611,10 +595,9 @@
pushButtons[PB_PATTLEN_DOWN].y = 48;
// instrument switcher
- for (i = 0; i < 16; i++)
+ p = &pushButtons[PB_RANGE1];
+ for (i = 0; i < 16; i++, p++)
{
- p = &pushButtons[PB_RANGE1+i];
-
p->w = 39;
p->x = 590;
p->y = iSwitchY[i & 7];
@@ -756,17 +739,15 @@
void checkMarkLimits(void)
{
- uint16_t limit;
+ const uint16_t limitY = pattLens[editor.editPattern];
+ pattMark.markY1 = CLAMP(pattMark.markY1, 0, limitY);
+ pattMark.markY2 = CLAMP(pattMark.markY2, 0, limitY);
- limit = pattLens[editor.editPattern];
- pattMark.markY1 = CLAMP(pattMark.markY1, 0, limit);
- pattMark.markY2 = CLAMP(pattMark.markY2, 0, limit);
+ const uint16_t limitX = (uint16_t)(song.antChn - 1);
+ pattMark.markX1 = CLAMP(pattMark.markX1, 0, limitX);
+ pattMark.markX2 = CLAMP(pattMark.markX2, 0, limitX);
- limit = (uint16_t)(song.antChn - 1);
- pattMark.markX1 = CLAMP(pattMark.markX1, 0, limit);
- pattMark.markX2 = CLAMP(pattMark.markX2, 0, limit);
-
- // will probably never happen? FT2 has this in CheckMarkLimits() though...
+ // XXX: will probably never happen? FT2 has this in CheckMarkLimits() though...
if (pattMark.markX1 > pattMark.markX2)
pattMark.markX1 = pattMark.markX2;
}
@@ -773,19 +754,16 @@
static int8_t mouseXToCh(void) // used to get channel num from mouse x (for pattern marking)
{
- int8_t ch, chEnd;
- int32_t mouseX;
-
assert(ui.patternChannelWidth > 0);
if (ui.patternChannelWidth == 0)
return 0;
- mouseX = mouse.x - 29;
+ int32_t mouseX = mouse.x - 29;
mouseX = CLAMP(mouseX, 0, 573);
- chEnd = (ui.channelOffset + ui.numChannelsShown) - 1;
+ const int8_t chEnd = (ui.channelOffset + ui.numChannelsShown) - 1;
- ch = ui.channelOffset + (int8_t)(mouseX / ui.patternChannelWidth);
+ int8_t ch = ui.channelOffset + (int8_t)(mouseX / ui.patternChannelWidth);
ch = CLAMP(ch, 0, chEnd);
// in some setups there can be non-used channels to the right, do clamping
@@ -797,23 +775,19 @@
static int16_t mouseYToRow(void) // used to get row num from mouse y (for pattern marking)
{
- uint8_t charHeight, mode;
- int16_t row, patternLen, my, maxY, maxRow;
- const pattCoordsMouse_t *pattCoordsMouse;
+ const pattCoordsMouse_t *pattCoordsMouse = &pattCoordMouseTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
- pattCoordsMouse = &pattCoordMouseTable[config.ptnUnpressed][ui.pattChanScrollShown][ui.extended];
-
// clamp mouse y to boundaries
- maxY = ui.pattChanScrollShown ? 382 : 396;
- my = (int16_t)(CLAMP(mouse.y, pattCoordsMouse->upperRowsY, maxY));
+ const int16_t maxY = ui.pattChanScrollShown ? 382 : 396;
+ const int16_t my = (int16_t)CLAMP(mouse.y, pattCoordsMouse->upperRowsY, maxY);
- charHeight = config.ptnUnpressed ? 11 : 8;
+ const uint8_t charHeight = config.ptnUnpressed ? 11 : 8;
// test top/middle/bottom rows
if (my < pattCoordsMouse->midRowY)
{
// top rows
- row = editor.pattPos - (pattCoordsMouse->numUpperRows - ((my - pattCoordsMouse->upperRowsY) / charHeight));
+ int16_t row = editor.pattPos - (pattCoordsMouse->numUpperRows - ((my - pattCoordsMouse->upperRowsY) / charHeight));
if (row < 0)
row = 0;
@@ -827,17 +801,17 @@
else
{
// bottom rows
- row = (editor.pattPos + 1) + ((my - pattCoordsMouse->lowerRowsY) / charHeight);
+ int16_t row = (editor.pattPos + 1) + ((my - pattCoordsMouse->lowerRowsY) / charHeight);
// prevent being able to mark the next unseen row on the bottom (in some configurations)
- mode = (ui.extended * 4) + (config.ptnUnpressed * 2) + ui.pattChanScrollShown;
+ const uint8_t mode = (ui.extended * 4) + (config.ptnUnpressed * 2) + ui.pattChanScrollShown;
- maxRow = (ptnAntLine[mode] + (editor.pattPos - ptnLineSub[mode])) - 1;
+ const int16_t maxRow = (ptnAntLine[mode] + (editor.pattPos - ptnLineSub[mode])) - 1;
if (row > maxRow)
row = maxRow;
// clamp to pattern length
- patternLen = pattLens[editor.editPattern];
+ const int16_t patternLen = pattLens[editor.editPattern];
if (row >= patternLen)
row = patternLen - 1;
@@ -847,9 +821,7 @@
void handlePatternDataMouseDown(bool mouseButtonHeld)
{
- bool forceMarking;
- int8_t chTmp;
- int16_t y1, y2, rowTmp, pattLen;
+ int16_t y1, y2;
// non-FT2 feature: Use right mouse button to remove pattern marking
if (mouse.rightButtonPressed)
@@ -884,7 +856,7 @@
// we're holding down the mouse button inside the pattern data area
- forceMarking = songPlaying;
+ bool forceMarking = songPlaying;
// scroll left/right with mouse
if (ui.pattChanScrollShown)
@@ -906,7 +878,7 @@
{
lastMouseX = mouse.x;
- chTmp = mouseXToCh();
+ int8_t chTmp = mouseXToCh();
if (chTmp < lastChMark)
{
pattMark.markX1 = chTmp;
@@ -936,7 +908,6 @@
if (mouse.y < y1)
{
- pattLen = pattLens[editor.editPattern];
if (editor.pattPos > 0)
setPos(-1, editor.pattPos - 1, true);
@@ -945,8 +916,8 @@
}
else if (mouse.y > y2)
{
- pattLen = pattLens[editor.editPattern];
- if (editor.pattPos < (pattLen - 1))
+ const int16_t pattLen = pattLens[editor.editPattern];
+ if (editor.pattPos < pattLen-1)
setPos(-1, editor.pattPos + 1, true);
forceMarking = true;
@@ -959,7 +930,7 @@
{
lastMouseY = mouse.y;
- rowTmp = mouseYToRow();
+ const int16_t rowTmp = mouseYToRow();
if (rowTmp < lastRowMark)
{
pattMark.markY1 = rowTmp;
@@ -1062,12 +1033,9 @@
void keybPattMarkUp(void)
{
- int8_t xPos;
- int16_t pattPos;
+ int8_t xPos = cursor.ch;
+ int16_t pattPos = editor.pattPos;
- xPos = cursor.ch;
- pattPos = editor.pattPos;
-
if (xPos != pattMark.markX1 && xPos != pattMark.markX2)
{
pattMark.markX1 = xPos;
@@ -1099,12 +1067,9 @@
void keybPattMarkDown(void)
{
- int8_t xPos;
- int16_t pattPos;
+ int8_t xPos = cursor.ch;
+ int16_t pattPos = editor.pattPos;
- xPos = cursor.ch;
- pattPos = editor.pattPos;
-
if (xPos != pattMark.markX1 && xPos != pattMark.markX2)
{
pattMark.markX1 = xPos;
@@ -1135,12 +1100,9 @@
void keybPattMarkLeft(void)
{
- int8_t xPos;
- int16_t pattPos;
+ int8_t xPos = cursor.ch;
+ int16_t pattPos = editor.pattPos;
- xPos = cursor.ch;
- pattPos = editor.pattPos;
-
if (pattPos != pattMark.markY1-1 && pattPos != pattMark.markY2)
{
pattMark.markY1 = pattPos - 1;
@@ -1169,12 +1131,9 @@
void keybPattMarkRight(void)
{
- int8_t xPos;
- int16_t pattPos;
+ int8_t xPos = cursor.ch;
+ int16_t pattPos = editor.pattPos;
- xPos = cursor.ch;
- pattPos = editor.pattPos;
-
if (pattPos != pattMark.markY1-1 && pattPos != pattMark.markY2)
{
pattMark.markY1 = pattPos - 1;
@@ -1203,12 +1162,10 @@
bool loadTrack(UNICHAR *filenameU)
{
- FILE *f;
- uint16_t nr, pattLen;
- tonTyp *pattPtr, loadBuff[MAX_PATT_LEN];
+ tonTyp loadBuff[MAX_PATT_LEN];
trackHeaderType th;
- f = UNICHAR_FOPEN(filenameU, "rb");
+ FILE *f = UNICHAR_FOPEN(filenameU, "rb");
if (f == NULL)
{
okBox(0, "System message", "General I/O error during loading! Is the file in use?");
@@ -1215,8 +1172,8 @@
return false;
}
- nr = editor.editPattern;
- pattLen = pattLens[nr];
+ uint16_t nr = editor.editPattern;
+ int16_t pattLen = pattLens[nr];
if (fread(&th, 1, sizeof (th), f) != sizeof (th))
{
@@ -1248,10 +1205,10 @@
goto trackLoadError;
}
- pattPtr = patt[nr];
+ tonTyp *pattPtr = patt[nr];
lockMixerCallback();
- for (uint16_t i = 0; i < pattLen; i++)
+ for (int32_t i = 0; i < pattLen; i++)
{
pattPtr = &patt[nr][(i * MAX_VOICES) + cursor.ch];
*pattPtr = loadBuff[i];
@@ -1266,7 +1223,6 @@
pattPtr->eff = 0;
}
}
-
unlockMixerCallback();
fclose(f);
@@ -1286,13 +1242,11 @@
bool saveTrack(UNICHAR *filenameU)
{
- FILE *f;
- uint16_t nr, pattLen, i;
- tonTyp *pattPtr, saveBuff[MAX_PATT_LEN];
+ tonTyp saveBuff[MAX_PATT_LEN];
trackHeaderType th;
- nr = editor.editPattern;
- pattPtr = patt[nr];
+ uint16_t nr = editor.editPattern;
+ tonTyp *pattPtr = patt[nr];
if (pattPtr == NULL)
{
@@ -1300,7 +1254,7 @@
return false;
}
- f = UNICHAR_FOPEN(filenameU, "wb");
+ FILE *f = UNICHAR_FOPEN(filenameU, "wb");
if (f == NULL)
{
okBox(0, "System message", "General I/O error during saving! Is the file in use?");
@@ -1307,8 +1261,8 @@
return false;
}
- pattLen = pattLens[nr];
- for (i = 0; i < pattLen; i++)
+ const int16_t pattLen = pattLens[nr];
+ for (int32_t i = 0; i < pattLen; i++)
saveBuff[i] = pattPtr[(i * MAX_VOICES) + cursor.ch];
th.len = pattLen;
@@ -1334,12 +1288,9 @@
bool loadPattern(UNICHAR *filenameU)
{
- FILE *f;
- uint16_t nr, pattLen;
- tonTyp *pattPtr;
patternHeaderType th;
- f = UNICHAR_FOPEN(filenameU, "rb");
+ FILE *f = UNICHAR_FOPEN(filenameU, "rb");
if (f == NULL)
{
okBox(0, "System message", "General I/O error during loading! Is the file in use?");
@@ -1346,7 +1297,7 @@
return false;
}
- nr = editor.editPattern;
+ uint16_t nr = editor.editPattern;
if (!allocatePattern(nr))
{
@@ -1354,8 +1305,8 @@
goto loadPattError;
}
- pattPtr = patt[nr];
- pattLen = pattLens[nr];
+ tonTyp *pattPtr = patt[nr];
+ uint16_t pattLen = pattLens[nr];
if (fread(&th, 1, sizeof (th), f) != sizeof (th))
{
@@ -1372,8 +1323,7 @@
if (th.len > MAX_PATT_LEN)
th.len = MAX_PATT_LEN;
- if (pattLen > th.len)
- pattLen = th.len;
+ pattLen = th.len;
lockMixerCallback();
@@ -1385,9 +1335,9 @@
}
// non-FT2 security fix: remove overflown (illegal) stuff
- for (uint16_t i = 0; i < pattLen; i++)
+ for (int32_t i = 0; i < pattLen; i++)
{
- for (uint16_t j = 0; j < MAX_VOICES; j++)
+ for (int32_t j = 0; j < MAX_VOICES; j++)
{
pattPtr = &patt[nr][(i * MAX_VOICES) + j];
if (pattPtr->ton > 97)
@@ -1401,6 +1351,16 @@
}
}
+ // set new pattern length (FT2 doesn't do this, strange...)
+ pattLens[nr] = pattLen;
+ song.pattLen = pattLen;
+ if (song.pattPos >= pattLen)
+ {
+ song.pattPos = pattLen-1;
+ if (!songPlaying)
+ editor.pattPos = song.pattPos;
+ }
+
unlockMixerCallback();
fclose(f);
@@ -1420,13 +1380,10 @@
bool savePattern(UNICHAR *filenameU)
{
- FILE *f;
- uint16_t nr, pattLen;
- tonTyp *pattPtr;
patternHeaderType th;
- nr = editor.editPattern;
- pattPtr = patt[nr];
+ uint16_t nr = editor.editPattern;
+ tonTyp *pattPtr = patt[nr];
if (pattPtr == NULL)
{
@@ -1434,7 +1391,7 @@
return false;
}
- f = UNICHAR_FOPEN(filenameU, "wb");
+ FILE *f = UNICHAR_FOPEN(filenameU, "wb");
if (f == NULL)
{
okBox(0, "System message", "General I/O error during saving! Is the file in use?");
@@ -1441,7 +1398,7 @@
return false;
}
- pattLen = pattLens[nr];
+ uint16_t pattLen = pattLens[nr];
th.len = pattLen;
th.ver = 1;
@@ -1553,14 +1510,12 @@
void pbPosEdIns(void)
{
- uint8_t oldPatt;
-
if (song.len >= 255)
return;
lockMixerCallback();
- oldPatt = song.songTab[song.songPos];
+ const uint8_t oldPatt = song.songTab[song.songPos];
for (uint16_t i = 0; i < 255-song.songPos; i++)
song.songTab[255-i] = song.songTab[254-i];
song.songTab[song.songPos] = oldPatt;
@@ -2014,13 +1969,6 @@
void drawPosEdNums(int16_t songPos)
{
- uint8_t y;
- int16_t entry;
- uint32_t color1, color2;
-
- color1 = video.palette[PAL_PATTEXT];
- color2 = video.palette[PAL_FORGRND];
-
if (songPos >= song.len)
songPos = song.len - 1;
@@ -2038,10 +1986,13 @@
clearRect(8, 32, 39, 15);
}
+ const uint32_t color1 = video.palette[PAL_PATTEXT];
+ const uint32_t color2 = video.palette[PAL_FORGRND];
+
// top two
- for (y = 0; y < 2; y++)
+ for (int16_t y = 0; y < 2; y++)
{
- entry = songPos - (2 - y);
+ int16_t entry = songPos - (2 - y);
if (entry < 0)
continue;
@@ -2074,9 +2025,9 @@
}
// bottom two
- for (y = 0; y < 2; y++)
+ for (int16_t y = 0; y < 2; y++)
{
- entry = songPos + (1 + y);
+ int16_t entry = songPos + (1 + y);
if (entry >= song.len)
break;
@@ -2290,7 +2241,6 @@
void updateInstrumentSwitcher(void)
{
- int8_t i;
int16_t y;
if (ui.aboutScreenShown || ui.configScreenShown || ui.helpScreenShown || ui.nibblesShown)
@@ -2331,7 +2281,7 @@
}
// draw numbers and texts
- for (i = 0; i < 4; i++)
+ for (int16_t i = 0; i < 4; i++)
{
hexOut(388, 5 + (i * 11), PAL_FORGRND, 1 + editor.instrBankOffset + i, 2);
hexOut(511, 5 + (i * 11), PAL_FORGRND, 5 + editor.instrBankOffset + i, 2);
@@ -2363,7 +2313,7 @@
}
// draw numbers and texts
- for (i = 0; i < 8; i++)
+ for (int16_t i = 0; i < 8; i++)
{
hexOut(424, 5 + (i * 11), PAL_FORGRND, 1 + editor.instrBankOffset + i, 2);
drawTextBox(TB_INST1 + i);
@@ -2391,7 +2341,7 @@
}
// draw numbers and texts
- for (i = 0; i < 5; i++)
+ for (int16_t i = 0; i < 5; i++)
{
hexOut(424, 99 + (i * 11), PAL_FORGRND, editor.sampleBankOffset + i, 2);
drawTextBox(TB_SAMP1 + i);
@@ -2401,12 +2351,10 @@
void showInstrumentSwitcher(void)
{
- uint16_t i;
-
if (!ui.instrSwitcherShown)
return;
- for (i = 0; i < 8; i++)
+ for (uint16_t i = 0; i < 8; i++)
showTextBox(TB_INST1 + i);
if (ui.extended)
@@ -2443,13 +2391,13 @@
showPushButton(PB_SAMPLE_LIST_DOWN);
showScrollBar(SB_SAMPLE_LIST);
- for (i = 0; i < 5; i++)
+ for (uint16_t i = 0; i < 5; i++)
showTextBox(TB_SAMP1 + i);
}
updateInstrumentSwitcher();
- for (i = 0; i < 8; i++)
+ for (uint16_t i = 0; i < 8; i++)
showPushButton(PB_RANGE1 + i + (editor.instrBankSwapped * 8));
showPushButton(PB_SWAP_BANK);
@@ -2457,9 +2405,7 @@
void hideInstrumentSwitcher(void)
{
- uint8_t i;
-
- for (i = 0; i < 16; i++)
+ for (uint16_t i = 0; i < 16; i++)
hidePushButton(PB_RANGE1 + i);
hidePushButton(PB_SWAP_BANK);
@@ -2467,10 +2413,10 @@
hidePushButton(PB_SAMPLE_LIST_DOWN);
hideScrollBar(SB_SAMPLE_LIST);
- for (i = 0; i < 8; i++)
+ for (uint16_t i = 0; i < 8; i++)
hideTextBox(TB_INST1 + i);
- for (i = 0; i < 5; i++)
+ for (uint16_t i = 0; i < 5; i++)
hideTextBox(TB_SAMP1 + i);
}
@@ -2479,9 +2425,9 @@
editor.instrBankSwapped ^= 1;
if (editor.instrBankSwapped)
- editor.instrBankOffset += (8 * 8);
+ editor.instrBankOffset += 8*8;
else
- editor.instrBankOffset -= (8 * 8);
+ editor.instrBankOffset -= 8*8;
updateTextBoxPointers();
@@ -2650,7 +2596,7 @@
lockMixerCallback();
song.len = 1;
- song.repS = 0; // Silly: FT2 doesn't do this!
+ song.repS = 0; // Bug: FT2 doesn't do this!
song.speed = 125;
song.tempo = 6;
song.songPos = 0;
@@ -2699,7 +2645,7 @@
for (int16_t i = 1; i <= MAX_INST; i++)
{
freeInstr(i);
- memset(song.instrName[i], 0, 22 + 1);
+ memset(song.instrName[i], 0, 22+1);
}
updateNewInstrument();
@@ -2719,7 +2665,7 @@
void pbZap(void)
{
- int16_t choice = okBox(4, "System request", "Total devastation of the...");
+ const int16_t choice = okBox(4, "System request", "Total devastation of the...");
if (choice == 1) // zap all
{
@@ -2779,35 +2725,32 @@
void shrinkPattern(void)
{
- uint16_t nr, pattLen;
- tonTyp *pattPtr;
-
if (okBox(2, "System request", "Shrink pattern?") != 1)
return;
- nr = editor.editPattern;
+ uint16_t nr = editor.editPattern;
- pattLen = pattLens[nr];
+ int16_t pattLen = pattLens[nr];
if (pattLen > 1)
{
lockMixerCallback();
- pattPtr = patt[nr];
+ tonTyp *pattPtr = patt[nr];
if (pattPtr != NULL)
{
- for (uint16_t i = 0; i < pattLen/2; i++)
+ for (int32_t i = 0; i < pattLen/2; i++)
{
- for (uint16_t j = 0; j < MAX_VOICES; j++)
+ for (int32_t j = 0; j < MAX_VOICES; j++)
pattPtr[(i * MAX_VOICES) + j] = pattPtr[((i * 2) * MAX_VOICES) + j];
}
}
- pattLens[nr] /= 2;
+ pattLens[nr] >>= 1;
if (song.pattNr == nr)
song.pattLen = pattLens[nr];
- song.pattPos /= 2;
+ song.pattPos >>= 1;
if (song.pattPos >= pattLens[nr])
song.pattPos = pattLens[nr] - 1;
@@ -2823,12 +2766,9 @@
void expandPattern(void)
{
- uint16_t nr, pattLen;
- tonTyp *tmpPtn;
+ uint16_t nr = editor.editPattern;
- nr = editor.editPattern;
-
- pattLen = pattLens[nr];
+ int16_t pattLen = pattLens[nr];
if (pattLen > 128)
{
okBox(0, "System message", "Pattern is too long to be expanded.");
@@ -2839,7 +2779,7 @@
if (patt[nr] != NULL)
{
- tmpPtn = (tonTyp *)malloc((pattLen * 2) * TRACK_WIDTH);
+ tonTyp *tmpPtn = (tonTyp *)malloc((pattLen * 2) * TRACK_WIDTH);
if (tmpPtn == NULL)
{
unlockMixerCallback();
@@ -2847,9 +2787,9 @@
return;
}
- for (uint16_t i = 0; i < pattLen; i++)
+ for (int32_t i = 0; i < pattLen; i++)
{
- for (uint16_t j = 0; j < MAX_VOICES; j++)
+ for (int32_t j = 0; j < MAX_VOICES; j++)
tmpPtn[((i * 2) * MAX_VOICES) + j] = patt[nr][(i * MAX_VOICES) + j];
memset(&tmpPtn[((i * 2) + 1) * MAX_VOICES], 0, TRACK_WIDTH);
--- a/src/ft2_pushbuttons.c
+++ b/src/ft2_pushbuttons.c
@@ -398,22 +398,20 @@
void drawPushButton(uint16_t pushButtonID)
{
- uint8_t state;
- uint16_t x, y, w, h, textX, textY, textW;
- pushButton_t *b;
+ uint16_t textX, textY, textW;
assert(pushButtonID < NUM_PUSHBUTTONS);
- b = &pushButtons[pushButtonID];
+ pushButton_t *b = &pushButtons[pushButtonID];
if (!b->visible)
return;
- state = b->state;
+ uint8_t state = b->state;
- x = b->x;
- y = b->y;
- w = b->w;
- h = b->h;
+ uint16_t x = b->x;
+ uint16_t y = b->y;
+ uint16_t w = b->w;
+ uint16_t h = b->h;
assert(x < SCREEN_W && y < SCREEN_H && w >= 4 && h >= 4);
@@ -497,10 +495,9 @@
void handlePushButtonsWhileMouseDown(void)
{
int8_t buttonDelay;
- pushButton_t *pushButton;
assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_PUSHBUTTONS);
- pushButton = &pushButtons[mouse.lastUsedObjectID];
+ pushButton_t *pushButton = &pushButtons[mouse.lastUsedObjectID];
if (!pushButton->visible)
return;
@@ -550,7 +547,7 @@
{
mouse.buttonCounter = 0;
if (pushButton->callbackFuncOnDown != NULL)
- pushButton->callbackFuncOnDown();
+ pushButton->callbackFuncOnDown();
}
}
}
@@ -558,7 +555,6 @@
bool testPushButtonMouseDown(void)
{
uint16_t start, end;
- pushButton_t *pushButton;
if (ui.sysReqShown)
{
@@ -572,9 +568,9 @@
end = NUM_PUSHBUTTONS;
}
- for (uint16_t i = start; i < end; i++)
+ pushButton_t *pushButton = &pushButtons[start];
+ for (uint16_t i = start; i < end; i++, pushButton++)
{
- pushButton = &pushButtons[i];
if (!pushButton->visible)
continue;
@@ -605,13 +601,11 @@
int16_t testPushButtonMouseRelease(bool runCallback)
{
- pushButton_t *pushButton;
-
if (mouse.lastUsedObjectType != OBJECT_PUSHBUTTON || mouse.lastUsedObjectID == OBJECT_ID_NONE)
return -1;
assert(mouse.lastUsedObjectID < NUM_PUSHBUTTONS);
- pushButton = &pushButtons[mouse.lastUsedObjectID];
+ pushButton_t *pushButton = &pushButtons[mouse.lastUsedObjectID];
if (!pushButton->visible)
return -1;
--- a/src/ft2_radiobuttons.c
+++ b/src/ft2_radiobuttons.c
@@ -222,17 +222,14 @@
void drawRadioButton(uint16_t radioButtonID)
{
- uint8_t *gfxPtr;
- radioButton_t *radioButton;
-
assert(radioButtonID < NUM_RADIOBUTTONS);
- radioButton = &radioButtons[radioButtonID];
+ radioButton_t *radioButton = &radioButtons[radioButtonID];
if (!radioButton->visible)
return;
assert(radioButton->x < SCREEN_W && radioButton->y < SCREEN_H);
- gfxPtr = &bmp.radiobuttonGfx[radioButton->state*(RADIOBUTTON_W*RADIOBUTTON_H)];
+ const uint8_t *gfxPtr = &bmp.radiobuttonGfx[radioButton->state*(RADIOBUTTON_W*RADIOBUTTON_H)];
blitFast(radioButton->x, radioButton->y, gfxPtr, RADIOBUTTON_W, RADIOBUTTON_H);
}
@@ -252,16 +249,15 @@
void checkRadioButton(uint16_t radioButtonID)
{
- radioButton_t *radioButton;
-
assert(radioButtonID < NUM_RADIOBUTTONS);
- radioButton = &radioButtons[radioButtonID];
+ const uint16_t testGroup = radioButtons[radioButtonID].group;
- for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++)
+ radioButton_t *radioButton = radioButtons;
+ for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++, radioButton++)
{
- if (radioButtons[i].group == radioButton->group && radioButtons[i].state == RADIOBUTTON_CHECKED)
+ if (radioButton->group == testGroup && radioButton->state == RADIOBUTTON_CHECKED)
{
- radioButtons[i].state = RADIOBUTTON_UNCHECKED;
+ radioButton->state = RADIOBUTTON_UNCHECKED;
drawRadioButton(i);
break;
}
@@ -273,18 +269,20 @@
void uncheckRadioButtonGroup(uint16_t radioButtonGroup)
{
- for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++)
+ radioButton_t *radioButton = radioButtons;
+ for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++, radioButton++)
{
- if (radioButtons[i].group == radioButtonGroup)
- radioButtons[i].state = RADIOBUTTON_UNCHECKED;
+ if (radioButton->group == radioButtonGroup)
+ radioButton->state = RADIOBUTTON_UNCHECKED;
}
}
void showRadioButtonGroup(uint16_t radioButtonGroup)
{
- for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++)
+ radioButton_t *radioButton = radioButtons;
+ for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++, radioButton++)
{
- if (radioButtons[i].group == radioButtonGroup)
+ if (radioButton->group == radioButtonGroup)
showRadioButton(i);
}
}
@@ -291,9 +289,10 @@
void hideRadioButtonGroup(uint16_t radioButtonGroup)
{
- for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++)
+ radioButton_t *radioButton = radioButtons;
+ for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++, radioButton++)
{
- if (radioButtons[i].group == radioButtonGroup)
+ if (radioButton->group == radioButtonGroup)
hideRadioButton(i);
}
}
@@ -300,10 +299,8 @@
void handleRadioButtonsWhileMouseDown(void)
{
- radioButton_t *radioButton;
-
assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_RADIOBUTTONS);
- radioButton = &radioButtons[mouse.lastUsedObjectID];
+ radioButton_t *radioButton = &radioButtons[mouse.lastUsedObjectID];
if (!radioButton->visible || radioButton->state == RADIOBUTTON_CHECKED)
return;
@@ -325,19 +322,20 @@
bool testRadioButtonMouseDown(void)
{
- radioButton_t *radioButton;
-
if (ui.sysReqShown)
return false;
- for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++)
+ const int32_t mx = mouse.x;
+ const int32_t my = mouse.y;
+
+ radioButton_t *radioButton = radioButtons;
+ for (uint16_t i = 0; i < NUM_RADIOBUTTONS; i++, radioButton++)
{
- radioButton = &radioButtons[i];
if (!radioButton->visible || radioButton->state == RADIOBUTTON_CHECKED)
continue;
- if (mouse.x >= radioButton->x && mouse.x < radioButton->x+radioButton->clickAreaWidth &&
- mouse.y >= radioButton->y && mouse.y < radioButton->y+(RADIOBUTTON_H+1))
+ if (mx >= radioButton->x && mx < radioButton->x+radioButton->clickAreaWidth &&
+ my >= radioButton->y && my < radioButton->y+(RADIOBUTTON_H+1))
{
mouse.lastUsedObjectID = i;
mouse.lastUsedObjectType = OBJECT_RADIOBUTTON;
@@ -350,13 +348,11 @@
void testRadioButtonMouseRelease(void)
{
- radioButton_t *radioButton;
-
if (mouse.lastUsedObjectType != OBJECT_RADIOBUTTON || mouse.lastUsedObjectID == OBJECT_ID_NONE)
return;
assert(mouse.lastUsedObjectID < NUM_RADIOBUTTONS);
- radioButton = &radioButtons[mouse.lastUsedObjectID];
+ radioButton_t *radioButton = &radioButtons[mouse.lastUsedObjectID];
if (!radioButton->visible || radioButton->state == RADIOBUTTON_CHECKED)
return;
--- a/src/ft2_replayer.c
+++ b/src/ft2_replayer.c
@@ -51,7 +51,7 @@
void fixSongName(void) // removes spaces from right side of song name
{
- for (int16_t i = 20; i >= 0; i--)
+ for (int32_t i = 20; i >= 0; i--)
{
if (song.name[i] == ' ')
song.name[i] = '\0';
@@ -62,10 +62,7 @@
void fixSampleName(int16_t nr) // removes spaces from right side of ins/smp names
{
- int16_t i, j;
- sampleTyp *s;
-
- for (i = 21; i >= 0; i--)
+ for (int32_t i = 21; i >= 0; i--)
{
if (song.instrName[nr][i] == ' ')
song.instrName[nr][i] = '\0';
@@ -75,10 +72,10 @@
if (instr[nr] != NULL)
{
- for (i = 0; i < MAX_SMP_PER_INST; i++)
+ sampleTyp *s = instr[nr]->samp;
+ for (int32_t i = 0; i < MAX_SMP_PER_INST; i++, s++)
{
- s = &instr[nr]->samp[i];
- for (j = 21; j >= 0; j--)
+ for (int16_t j = 21; j >= 0; j--)
{
if (s->name[j] == ' ')
s->name[j] = '\0';
@@ -97,10 +94,10 @@
lockAudio();
memset(stm, 0, sizeof (stm));
- for (int32_t i = 0; i < MAX_VOICES; i++)
- {
- stmTyp *ch = &stm[i];
+ stmTyp *ch = stm;
+ for (int32_t i = 0; i < MAX_VOICES; i++, ch++)
+ {
ch->instrPtr = instr[0];
ch->status = IS_Vol;
ch->oldPan = 128;
@@ -176,15 +173,12 @@
int16_t getUsedSamples(int16_t nr)
{
- int16_t i, j;
- instrTyp *ins;
-
if (instr[nr] == NULL)
return 0;
- ins = instr[nr];
+ instrTyp *ins = instr[nr];
- i = 16 - 1;
+ int16_t i = 16 - 1;
while (i >= 0 && ins->samp[i].pek == NULL && ins->samp[i].name[0] == '\0')
i--;
@@ -191,7 +185,7 @@
/* Yes, 'i' can be -1 here, and will be set to at least 0
** because of ins->ta values. Possibly an FT2 bug...
*/
- for (j = 0; j < 96; j++)
+ for (int16_t j = 0; j < 96; j++)
{
if (ins->ta[j] > i)
i = ins->ta[j];
@@ -202,12 +196,10 @@
int16_t getRealUsedSamples(int16_t nr)
{
- int8_t i;
-
if (instr[nr] == NULL)
return 0;
- i = 16 - 1;
+ int8_t i = 16 - 1;
while (i >= 0 && instr[nr]->samp[i].pek == NULL)
i--;
@@ -245,7 +237,7 @@
** be beneficial if you are playing VERY tightly looped samples, and/or if the CPU has
** no DIV instruction (certain ARM CPUs, for instance).
**
-** A bit hackish and extreme considering it's 65536*4 bytes, but that's My Game�
+** A bit hackish and extreme considering it's 65536*4 bytes long, but why not.
*/
void calcRevMixDeltaTable(void)
{
@@ -437,11 +429,6 @@
static void startTone(uint8_t ton, uint8_t effTyp, uint8_t eff, stmTyp *ch)
{
- uint8_t smp;
- uint16_t tmpTon;
- sampleTyp *s;
- instrTyp *ins;
-
if (ton == 97)
{
keyOff(ch);
@@ -459,10 +446,9 @@
ch->tonNr = ton;
assert(ch->instrNr <= 130);
-
- ins = instr[ch->instrNr];
+ instrTyp *ins = instr[ch->instrNr];
if (ins == NULL)
- ins = instr[0];
+ ins = instr[0]; // empty instruments use this placeholder instrument
ch->instrPtr = ins;
ch->mute = ins->mute;
@@ -470,10 +456,10 @@
if (ton > 96) // non-FT2 security (should never happen because I clamp in the patt. loader now)
ton = 96;
- smp = ins->ta[ton-1] & 0xF;
+ const uint8_t smp = ins->ta[ton-1] & 0xF;
ch->sampleNr = smp;
- s = &ins->samp[smp];
+ sampleTyp *s = &ins->samp[smp];
ch->smpPtr = s;
ch->relTonNr = s->relTon;
@@ -491,7 +477,7 @@
if (ton != 0)
{
- tmpTon = ((ton - 1) << 4) + (((ch->fineTune >> 3) + 16) & 0xFF);
+ const uint16_t tmpTon = ((ton - 1) << 4) + (((ch->fineTune >> 3) + 16) & 0xFF);
if (tmpTon < MAX_NOTES)
{
assert(note2Period != NULL);
@@ -1347,7 +1333,7 @@
bool envInterpolateFlag, envDidInterpolate;
uint8_t envPos;
int16_t autoVibVal;
- uint16_t tmpPeriod, autoVibAmp;
+ uint16_t autoVibAmp;
double dVol, dEnvVal;
instrTyp *ins = ch->instrPtr;
@@ -1608,7 +1594,7 @@
else autoVibVal = vibSineTab[ch->eVibPos]; // sine
autoVibVal <<= 2;
- tmpPeriod = (autoVibVal * (int16_t)autoVibAmp) >> 16;
+ uint16_t tmpPeriod = (autoVibVal * (int16_t)autoVibAmp) >> 16;
tmpPeriod += ch->outPeriod;
if (tmpPeriod > 32000-1)
@@ -1639,17 +1625,17 @@
// for arpeggio and portamento (semitone-slide mode)
static uint16_t relocateTon(uint16_t period, uint8_t arpNote, stmTyp *ch)
{
- int32_t fineTune, loPeriod, hiPeriod, tmpPeriod, tableIndex;
+ int32_t tmpPeriod;
- fineTune = ((ch->fineTune >> 3) + 16) << 1;
- hiPeriod = (8 * 12 * 16) * 2;
- loPeriod = 0;
+ const int32_t fineTune = ((ch->fineTune >> 3) + 16) << 1;
+ int32_t hiPeriod = (8 * 12 * 16) * 2;
+ int32_t loPeriod = 0;
for (int32_t i = 0; i < 8; i++)
{
tmpPeriod = (((loPeriod + hiPeriod) >> 1) & 0xFFFFFFE0) + fineTune;
- tableIndex = (uint32_t)(tmpPeriod - 16) >> 1;
+ int32_t tableIndex = (uint32_t)(tmpPeriod - 16) >> 1;
tableIndex = CLAMP(tableIndex, 0, 1935); // 8bitbubsy: added security check
if (period >= note2Period[tableIndex])
@@ -2323,54 +2309,50 @@
void delta2Samp(int8_t *p, int32_t len, uint8_t typ)
{
- int8_t *p8, news8, olds8L, olds8R;
- int16_t *p16, news16, olds16L, olds16R, tmp16;
- int32_t i, tmp32;
+ if (typ & 16) len >>= 1; // 16-bit
+ if (typ & 32) len >>= 1; // stereo
- if (typ & 16) len /= 2; // 16-bit
- if (typ & 32) len /= 2; // stereo
-
if (typ & 32)
{
if (typ & 16)
{
- p16 = (int16_t *)p;
+ int16_t *p16 = (int16_t *)p;
- olds16L = 0;
- olds16R = 0;
+ int16_t olds16L = 0;
+ int16_t olds16R = 0;
- for (i = 0; i < len; i++)
+ for (int32_t i = 0; i < len; i++)
{
- news16 = p16[i] + olds16L;
- p16[i] = news16;
- olds16L = news16;
+ const int16_t news16L = p16[i] + olds16L;
+ p16[i] = news16L;
+ olds16L = news16L;
- news16 = p16[len+i] + olds16R;
- p16[len+i] = news16;
- olds16R = news16;
+ const int16_t news16R = p16[len+i] + olds16R;
+ p16[len+i] = news16R;
+ olds16R = news16R;
- tmp32 = olds16L + olds16R;
+ const int32_t tmp32 = olds16L + olds16R;
p16[i] = (int16_t)(tmp32 >> 1);
}
}
else
{
- p8 = (int8_t *)p;
+ int8_t *p8 = (int8_t *)p;
- olds8L = 0;
- olds8R = 0;
+ int8_t olds8L = 0;
+ int8_t olds8R = 0;
- for (i = 0; i < len; i++)
+ for (int32_t i = 0; i < len; i++)
{
- news8 = p8[i] + olds8L;
- p8[i] = news8;
- olds8L = news8;
+ const int8_t news8L = p8[i] + olds8L;
+ p8[i] = news8L;
+ olds8L = news8L;
- news8 = p8[len+i] + olds8R;
- p8[len+i] = news8;
- olds8R = news8;
+ const int8_t news8R = p8[len+i] + olds8R;
+ p8[len+i] = news8R;
+ olds8R = news8R;
- tmp16 = olds8L + olds8R;
+ const int16_t tmp16 = olds8L + olds8R;
p8[i] = (int8_t)(tmp16 >> 1);
}
}
@@ -2379,12 +2361,12 @@
{
if (typ & 16)
{
- p16 = (int16_t *)p;
+ int16_t *p16 = (int16_t *)p;
- olds16L = 0;
- for (i = 0; i < len; i++)
+ int16_t olds16L = 0;
+ for (int32_t i = 0; i < len; i++)
{
- news16 = p16[i] + olds16L;
+ const int16_t news16 = p16[i] + olds16L;
p16[i] = news16;
olds16L = news16;
}
@@ -2391,12 +2373,12 @@
}
else
{
- p8 = (int8_t *)p;
+ int8_t *p8 = (int8_t *)p;
- olds8L = 0;
- for (i = 0; i < len; i++)
+ int8_t olds8L = 0;
+ for (int32_t i = 0; i < len; i++)
{
- news8 = p8[i] + olds8L;
+ const int8_t news8 = p8[i] + olds8L;
p8[i] = news8;
olds8L = news8;
}
@@ -2406,20 +2388,17 @@
void samp2Delta(int8_t *p, int32_t len, uint8_t typ)
{
- int8_t *p8, news8, olds8;
- int16_t *p16, news16, olds16;
- int32_t i;
+ if (typ & 16)
+ len >>= 1; // 16-bit
- if (typ & 16) len /= 2; // 16-bit
-
if (typ & 16)
{
- p16 = (int16_t *)p;
+ int16_t *p16 = (int16_t *)p;
- news16 = 0;
- for (i = 0; i < len; i++)
+ int16_t news16 = 0;
+ for (int32_t i = 0; i < len; i++)
{
- olds16 = p16[i];
+ const int16_t olds16 = p16[i];
p16[i] -= news16;
news16 = olds16;
}
@@ -2426,12 +2405,12 @@
}
else
{
- p8 = (int8_t *)p;
+ int8_t *p8 = (int8_t *)p;
- news8 = 0;
- for (i = 0; i < len; i++)
+ int8_t news8 = 0;
+ for (int32_t i = 0; i < len; i++)
{
- olds8 = p8[i];
+ const int8_t olds8 = p8[i];
p8[i] -= news8;
news8 = olds8;
}
@@ -2448,8 +2427,7 @@
return false;
memset(p, 0, sizeof (instrTyp));
-
- for (int32_t i = 0; i < MAX_SMP_PER_INST; i++) // set standard sample pan/vol
+ for (int32_t i = 0; i < MAX_SMP_PER_INST; i++)
{
p->samp[i].pan = 128;
p->samp[i].vol = 64;
@@ -2476,9 +2454,9 @@
pauseAudio(); // channel instrument pointers are now cleared
- for (int32_t i = 0; i < MAX_SMP_PER_INST; i++) // free sample data
+ sampleTyp *s = instr[nr]->samp;
+ for (int32_t i = 0; i < MAX_SMP_PER_INST; i++, s++) // free sample data
{
- sampleTyp *s = &instr[nr]->samp[i];
if (s->origPek != NULL)
free(s->origPek);
}
@@ -2492,13 +2470,13 @@
void freeAllInstr(void)
{
pauseAudio(); // channel instrument pointers are now cleared
- for (int16_t i = 1; i <= MAX_INST; i++)
+ for (int32_t i = 1; i <= MAX_INST; i++)
{
if (instr[i] != NULL)
{
- for (int8_t j = 0; j < MAX_SMP_PER_INST; j++) // free sample data
+ sampleTyp *s = instr[i]->samp;
+ for (int32_t j = 0; j < MAX_SMP_PER_INST; j++, s++) // free sample data
{
- sampleTyp *s = &instr[i]->samp[j];
if (s->origPek != NULL)
free(s->origPek);
}
@@ -2512,14 +2490,12 @@
void freeSample(int16_t nr, int16_t nr2)
{
- sampleTyp *s;
-
if (instr[nr] == NULL)
return; // instrument not allocated
pauseAudio(); // voice sample pointers are now cleared
- s = &instr[nr]->samp[nr2];
+ sampleTyp *s = &instr[nr]->samp[nr2];
if (s->origPek != NULL)
free(s->origPek);
@@ -2534,7 +2510,7 @@
void freeAllPatterns(void)
{
pauseAudio();
- for (uint16_t i = 0; i < MAX_PATTERNS; i++)
+ for (int32_t i = 0; i < MAX_PATTERNS; i++)
{
if (patt[i] != NULL)
{
@@ -2631,59 +2607,15 @@
{
assert(!(song.antChn & 1));
- uint8_t pageLen = 8;
- if (config.ptnS3M)
- {
- if (song.antChn == 2) pageLen = 4;
- else if (song.antChn == 4) pageLen = 4;
- else if (song.antChn == 6) pageLen = 6;
- else if (song.antChn >= 8) pageLen = 8;
- }
- else
- {
- if (song.antChn == 2) pageLen = 4;
- else if (song.antChn == 4) pageLen = 4;
- else if (song.antChn == 6) pageLen = 6;
- else if (song.antChn == 8) pageLen = 8;
- else if (song.antChn == 10) pageLen = 10;
- else if (song.antChn >= 12) pageLen = 12;
- }
+ const int32_t maxChannelsShown = getMaxVisibleChannels();
- ui.numChannelsShown = pageLen;
- if (song.antChn == 2)
- ui.numChannelsShown = 2;
+ int32_t channelsShown = song.antChn;
+ if (channelsShown > maxChannelsShown)
+ channelsShown = maxChannelsShown;
- if (config.ptnMaxChannels == 0)
- {
- if (ui.numChannelsShown > 4)
- ui.numChannelsShown = 4;
- }
- else if (config.ptnMaxChannels == 1)
- {
- if (ui.numChannelsShown > 6)
- ui.numChannelsShown = 6;
- }
- else if (config.ptnMaxChannels == 2)
- {
- if (ui.numChannelsShown > 8)
- ui.numChannelsShown = 8;
- }
- else if (config.ptnMaxChannels == 3)
- {
- if (config.ptnS3M)
- {
- if (ui.numChannelsShown > 8)
- ui.numChannelsShown = 8;
- }
- else
- {
- if (ui.numChannelsShown > 12)
- ui.numChannelsShown = 12;
- }
- }
+ ui.numChannelsShown = (uint8_t)channelsShown;
+ ui.pattChanScrollShown = (song.antChn > maxChannelsShown);
- ui.pattChanScrollShown = song.antChn > getMaxVisibleChannels();
-
if (ui.patternEditorShown)
{
if (ui.channelOffset > song.antChn-ui.numChannelsShown)
@@ -2719,38 +2651,30 @@
void conv8BitSample(int8_t *p, int32_t len, bool stereo)
{
- int8_t *p2, l, r;
- int16_t tmp16;
- int32_t i;
-
if (stereo)
{
len /= 2;
- p2 = &p[len];
- for (i = 0; i < len; i++)
+ int8_t *p2 = &p[len];
+ for (int32_t i = 0; i < len; i++)
{
- l = p[i] - 128;
- r = p2[i] - 128;
+ const int8_t l = p[i] ^ 0x80;
+ const int8_t r = p2[i] ^ 0x80;
- tmp16 = l + r;
+ int16_t tmp16 = l + r;
p[i] = (int8_t)(tmp16 >> 1);
}
}
else
{
- for (i = 0; i < len; i++)
- p[i] -= 128;
+ for (int32_t i = 0; i < len; i++)
+ p[i] ^= 0x80;
}
}
void conv16BitSample(int8_t *p, int32_t len, bool stereo)
{
- int16_t *p16_1, *p16_2, l, r;
- int32_t i, tmp32;
-
- p16_1 = (int16_t *)p;
-
+ int16_t *p16_1 = (int16_t *)p;
len /= 2;
if (stereo)
@@ -2757,20 +2681,20 @@
{
len /= 2;
- p16_2 = (int16_t *)&p[len * 2];
- for (i = 0; i < len; i++)
+ int16_t *p16_2 = (int16_t *)&p[len * 2];
+ for (int32_t i = 0; i < len; i++)
{
- l = p16_1[i] - 32768;
- r = p16_2[i] - 32768;
+ const int16_t l = p16_1[i] ^ 0x8000;
+ const int16_t r = p16_2[i] ^ 0x8000;
- tmp32 = l + r;
+ int32_t tmp32 = l + r;
p16_1[i] = (int16_t)(tmp32 >> 1);
}
}
else
{
- for (i = 0; i < len; i++)
- p16_1[i] -= 32768;
+ for (int32_t i = 0; i < len; i++)
+ p16_1[i] ^= 0x8000;
}
}
@@ -2804,9 +2728,7 @@
bool setupReplayer(void)
{
- int32_t i;
-
- for (i = 0; i < MAX_PATTERNS; i++)
+ for (int32_t i = 0; i < MAX_PATTERNS; i++)
pattLens[i] = 64;
playMode = PLAYMODE_IDLE;
@@ -2813,7 +2735,7 @@
songPlaying = false;
// unmute all channels (must be done before resetChannels() call)
- for (i = 0; i < MAX_VOICES; i++)
+ for (int32_t i = 0; i < MAX_VOICES; i++)
editor.chnMode[i] = 1;
resetChannels();
@@ -2820,12 +2742,10 @@
song.len = 1;
song.antChn = 8;
-
editor.speed = song.speed = 125;
editor.tempo = song.tempo = 6;
editor.globalVol = song.globVol = 64;
song.initialTempo = song.tempo;
-
audio.linearFreqTable = true;
note2Period = linearPeriods;
@@ -2855,8 +2775,9 @@
showErrorMsgBox("Not enough memory!");
return false;
}
+
memset(instr[131], 0, sizeof (instrTyp));
- for (i = 0; i < 16; i++)
+ for (int32_t i = 0; i < 16; i++)
instr[131]->samp[i].pan = 128;
editor.tmpPattern = 65535; // pattern editor update/redraw kludge
@@ -2868,7 +2789,6 @@
lockMixerCallback();
assert(mode != PLAYMODE_IDLE && mode != PLAYMODE_EDIT);
-
if (mode == PLAYMODE_PATT || mode == PLAYMODE_RECPATT)
setPos(-1, row, true);
else
@@ -2894,10 +2814,7 @@
void stopPlaying(void)
{
- uint8_t i;
- bool songWasPlaying;
-
- songWasPlaying = songPlaying;
+ bool songWasPlaying = songPlaying;
playMode = PLAYMODE_IDLE;
songPlaying = false;
@@ -2909,7 +2826,7 @@
}
else
{
- for (i = 0; i < MAX_VOICES; i++)
+ for (uint8_t i = 0; i < MAX_VOICES; i++)
playTone(i, 0, 97, -1, 0, 0);
}
@@ -2936,15 +2853,12 @@
// from keyboard/smp. ed.
void playTone(uint8_t stmm, uint8_t inst, uint8_t ton, int8_t vol, uint16_t midiVibDepth, uint16_t midiPitch)
{
- sampleTyp *s;
- stmTyp *ch;
instrTyp *ins = instr[inst];
-
if (ins == NULL)
return;
assert(stmm < MAX_VOICES && inst <= MAX_INST && ton <= 97);
- ch = &stm[stmm];
+ stmTyp *ch = &stm[stmm];
// FT2 bugfix: Don't play tone if certain requirements are not met
if (ton != 97)
@@ -2952,7 +2866,7 @@
if (ton == 0 || ton > 96)
return;
- s = &ins->samp[ins->ta[ton-1] & 0xF];
+ sampleTyp *s = &ins->samp[ins->ta[ton-1] & 0xF];
int16_t newTon = (int16_t)ton + s->relTon;
if (s->pek == NULL || s->len == 0 || newTon <= 0 || newTon >= 12*10)
@@ -2998,9 +2912,6 @@
// smp. ed.
void playSample(uint8_t stmm, uint8_t inst, uint8_t smpNr, uint8_t ton, uint16_t midiVibDepth, uint16_t midiPitch)
{
- uint8_t vol;
- stmTyp *ch;
-
if (instr[inst] == NULL)
return;
@@ -3011,11 +2922,11 @@
editor.curPlaySmp = 255;
assert(stmm < MAX_VOICES && inst <= MAX_INST && smpNr < MAX_SMP_PER_INST && ton <= 97);
- ch = &stm[stmm];
+ stmTyp *ch = &stm[stmm];
memcpy(&instr[130]->samp[0], &instr[inst]->samp[smpNr], sizeof (sampleTyp));
- vol = instr[inst]->samp[smpNr].vol;
+ uint8_t vol = instr[inst]->samp[smpNr].vol;
lockAudio();
@@ -3052,11 +2963,6 @@
// smp. ed.
void playRange(uint8_t stmm, uint8_t inst, uint8_t smpNr, uint8_t ton, uint16_t midiVibDepth, uint16_t midiPitch, int32_t offs, int32_t len)
{
- uint8_t vol;
- int32_t samplePlayOffset;
- stmTyp *ch;
- sampleTyp *s;
-
if (instr[inst] == NULL)
return;
@@ -3068,12 +2974,12 @@
assert(stmm < MAX_VOICES && inst <= MAX_INST && smpNr < MAX_SMP_PER_INST && ton <= 97);
- ch = &stm[stmm];
- s = &instr[130]->samp[0];
+ stmTyp *ch = &stm[stmm];
+ sampleTyp *s = &instr[130]->samp[0];
memcpy(s, &instr[inst]->samp[smpNr], sizeof (sampleTyp));
- vol = instr[inst]->samp[smpNr].vol;
+ uint8_t vol = instr[inst]->samp[smpNr].vol;
if (s->typ & 16)
{
@@ -3088,7 +2994,7 @@
s->repL = 0;
s->typ &= 16; // only keep 8-bit/16-bit flag (disable loop)
- samplePlayOffset = offs;
+ int32_t samplePlayOffset = offs;
if (s->typ & 16)
samplePlayOffset >>= 1;
@@ -3130,10 +3036,9 @@
if (audioWasntLocked)
lockAudio();
- for (int32_t i = 0; i < MAX_VOICES; i++)
+ stmTyp *ch = stm;
+ for (int32_t i = 0; i < MAX_VOICES; i++, ch++)
{
- stmTyp *ch = &stm[i];
-
lastChInstr[i].sampleNr = 255;
lastChInstr[i].instrNr = 255;
@@ -3324,7 +3229,6 @@
void setSyncedReplayerVars(void)
{
uint8_t scopeUpdateStatus[MAX_VOICES];
- uint64_t frameTime64;
pattSyncEntry = NULL;
chSyncEntry = NULL;
@@ -3331,7 +3235,7 @@
memset(scopeUpdateStatus, 0, sizeof (scopeUpdateStatus)); // this is needed
- frameTime64 = SDL_GetPerformanceCounter();
+ uint64_t frameTime64 = SDL_GetPerformanceCounter();
// handle channel sync queue
--- a/src/ft2_sample_ed.c
+++ b/src/ft2_sample_ed.c
@@ -460,10 +460,10 @@
int32_t getSampleMiddleCRate(sampleTyp *s)
{
- int32_t realFineTune = (int32_t)s->fine >> 3; // the FT2 replayer is ASR'ing the finetune to the right by 3
- double dFTune = realFineTune * (1.0 / 16.0); // new range is -16..15
+ const int32_t realFineTune = (int32_t)s->fine >> 3; // the FT2 replayer is ASR'ing the finetune to the right by 3
+ const double dFTune = realFineTune / 16.0; // new range is -16..15
- double dFreq = 8363.0 * exp2((s->relTon + dFTune) * (1.0 / 12.0));
+ const double dFreq = 8363.0 * exp2((s->relTon + dFTune) / 12.0);
return (int32_t)(dFreq + 0.5); // rounded
}
@@ -501,13 +501,10 @@
// sample pos -> screen x pos (if outside of visible area, will return <0 or >=SCREEN_W)
static int32_t smpPos2Scr(int32_t pos)
{
- double dPos;
- sampleTyp *s;
-
if (smpEd_ViewSize <= 0)
return -1;
- s = getCurSample();
+ sampleTyp *s = getCurSample();
if (s == NULL)
return -1;
@@ -514,7 +511,7 @@
if (pos > s->len)
pos = s->len;
- dPos = (pos * dPos2ScrMul) + 0.5; // rounding is needed here (+ 0.5)
+ double dPos = (pos * dPos2ScrMul) + 0.5; // rounding is needed here (+ 0.5)
dPos -= dScrPosScaled;
// this is important, or else the result can mess up in some cases
@@ -527,13 +524,10 @@
// screen x pos -> sample pos
static int32_t scr2SmpPos(int32_t x)
{
- double dPos;
- sampleTyp *s;
-
if (smpEd_ViewSize <= 0)
return 0;
- s = getCurSample();
+ sampleTyp *s = getCurSample();
if (s == NULL)
return 0;
@@ -540,7 +534,7 @@
if (x < 0)
x = 0;
- dPos = (dScrPosScaled + x) * dScr2SmpPosMul;
+ double dPos = (dScrPosScaled + x) * dScr2SmpPosMul;
x = (int32_t)dPos;
if (x > s->len)
@@ -554,11 +548,9 @@
static void fixRepeatGadgets(void)
{
- int32_t repS, repE;
- sampleTyp *s;
bool showLoopPins = true;
- s = getCurSample();
+ sampleTyp *s = getCurSample();
if (s == NULL || s->len <= 0 || s->pek == NULL || (s->typ & 3) == 0 || !ui.sampleEditorShown)
showLoopPins = false;
@@ -578,8 +570,8 @@
// draw sample loop points
- repS = smpPos2Scr(curSmpRepS);
- repE = smpPos2Scr(curSmpRepS+curSmpRepL);
+ int32_t repS = smpPos2Scr(curSmpRepS);
+ int32_t repE = smpPos2Scr(curSmpRepS+curSmpRepL);
// do -8 test because part of the loop sprite sticks out on the left/right
@@ -638,20 +630,13 @@
static int32_t SDLCALL copySampleThread(void *ptr)
{
- bool error;
- int8_t *p;
- int16_t destIns, destSmp, sourceIns, sourceSmp;
- sampleTyp *src, *dst;
+ bool error = false;
- (void)ptr;
+ int16_t destIns = editor.curInstr;
+ int16_t destSmp = editor.curSmp;
+ int16_t sourceIns = editor.srcInstr;
+ int16_t sourceSmp = editor.srcSmp;
- error = false;
-
- destIns = editor.curInstr;
- destSmp = editor.curSmp;
- sourceIns = editor.srcInstr;
- sourceSmp = editor.srcSmp;
-
pauseAudio();
if (instr[destIns] == NULL)
@@ -661,12 +646,12 @@
{
freeSample(destIns, destSmp);
- src = &instr[sourceIns]->samp[sourceSmp];
- dst = &instr[destIns]->samp[destSmp];
+ sampleTyp *src = &instr[sourceIns]->samp[sourceSmp];
+ sampleTyp *dst = &instr[destIns]->samp[destSmp];
if (instr[sourceIns] != NULL && 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)
{
memcpy(dst, src, sizeof (sampleTyp));
@@ -688,6 +673,8 @@
setMouseBusy(false);
return true;
+
+ (void)ptr;
}
void copySmp(void) // copy sample from srcInstr->srcSmp to curInstr->curSmp
@@ -708,8 +695,6 @@
void xchgSmp(void) // dstSmp <-> srcSmp
{
- sampleTyp *src, *dst, dstTmp;
-
if (editor.curInstr == 0 ||
(editor.curInstr == editor.srcInstr && editor.curSmp == editor.srcSmp) ||
instr[editor.curInstr] == NULL)
@@ -717,11 +702,11 @@
return;
}
- src = &instr[editor.curInstr]->samp[editor.srcSmp];
- dst = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *src = &instr[editor.curInstr]->samp[editor.srcSmp];
+ sampleTyp *dst = &instr[editor.curInstr]->samp[editor.curSmp];
lockMixerCallback();
- dstTmp = *dst;
+ const sampleTyp dstTmp = *dst;
*dst = *src;
*src = dstTmp;
unlockMixerCallback();
@@ -732,30 +717,27 @@
static void writeRange(void)
{
- int32_t start, end, rangeLen;
- uint32_t *ptr32;
-
// very first sample (rx1=0,rx2=0) is the "no range" special case
if (!ui.sampleEditorShown || smpEd_ViewSize == 0 || (smpEd_Rx1 == 0 && smpEd_Rx2 == 0))
return;
// test if range is outside of view (passed it by scrolling)
- start = smpPos2Scr(smpEd_Rx1);
+ int32_t start = smpPos2Scr(smpEd_Rx1);
if (start >= SAMPLE_AREA_WIDTH)
return;
// test if range is outside of view (passed it by scrolling)
- end = smpPos2Scr(smpEd_Rx2);
+ int32_t end = smpPos2Scr(smpEd_Rx2);
if (end < 0)
return;
- start = CLAMP(start, 0, SAMPLE_AREA_WIDTH - 1);
- end = CLAMP(end, 0, SAMPLE_AREA_WIDTH - 1);
- rangeLen = (end + 1) - start;
+ start = CLAMP(start, 0, SAMPLE_AREA_WIDTH-1);
+ end = CLAMP(end, 0, SAMPLE_AREA_WIDTH-1);
+ int32_t rangeLen = (end + 1) - start;
assert(start+rangeLen <= SCREEN_W);
- ptr32 = &video.frameBuffer[(174 * SCREEN_W) + start];
+ uint32_t *ptr32 = &video.frameBuffer[(174 * SCREEN_W) + start];
for (int32_t y = 0; y < SAMPLE_AREA_HEIGHT; y++)
{
for (int32_t x = 0; x < rangeLen; x++)
@@ -768,7 +750,6 @@
static int8_t getScaledSample(sampleTyp *s, int32_t index) // for drawing sample waveform in zoomed-in mode
{
int8_t sample;
- int16_t *ptr16;
int32_t tmp32;
const int32_t loopEnd = s->repS + s->repL;
@@ -781,7 +762,7 @@
assert(!(index & 1));
index >>= 1;
- ptr16 = (int16_t *)s->pek;
+ int16_t *ptr16 = (int16_t *)s->pek;
// don't read fixed mixer interpolation samples, read the prestine ones instead
if (index >= s->fixedPos && index < s->fixedPos+SINC_RIGHT_TAPS && s->len > loopEnd && s->fixed)
@@ -807,32 +788,26 @@
static void sampleLine(int16_t x1, int16_t x2, int16_t y1, int16_t y2)
{
- int16_t d, x, y, sx, sy, dx, dy;
- uint16_t ax, ay;
- int32_t pitch;
- uint32_t pal1, pal2, pixVal, *dst32;
+ int16_t d;
- // 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;
+ const int16_t dx = x2 - x1;
+ const int16_t ax = ABS(dx) * 2;
+ const int16_t sx = SGN(dx);
+ const int16_t dy = y2 - y1;
+ const int16_t ay = ABS(dy) * 2;
+ const int16_t sy = SGN(dy);
+ int16_t x = x1;
+ int16_t y = y1;
+ const uint32_t pal1 = video.palette[PAL_DESKTOP];
+ const uint32_t pal2 = video.palette[PAL_FORGRND];
+ const uint32_t pixVal = video.palette[PAL_PATTEXT];
+ const int32_t pitch = sy * SCREEN_W;
+ uint32_t *dst32 = &video.frameBuffer[(y * SCREEN_W) + x];
- pal1 = video.palette[PAL_DESKTOP];
- pal2 = video.palette[PAL_FORGRND];
- pixVal = video.palette[PAL_PATTEXT];
- pitch = sy * SCREEN_W;
-
- dst32 = &video.frameBuffer[(y * SCREEN_W) + x];
-
// draw line
if (ax > ay)
{
- d = ay - (ax / 2);
+ d = ay - (ax >> 1);
while (true)
{
@@ -861,7 +836,7 @@
}
else
{
- d = ax - (ay / 2);
+ d = ax - (ay >> 1);
while (true)
{
@@ -1072,12 +1047,12 @@
// for scanning sample data peak where loopEnd+SINC_RIGHT_TAPS is within scan range (fixed interpolation tap samples)
static void getSpecialMinMax16(sampleTyp *s, int32_t index, int32_t scanEnd, int16_t *min16, int16_t *max16)
{
- int16_t minVal, maxVal, minVal2, maxVal2;
+ int16_t minVal2, maxVal2;
const int16_t *ptr16 = (const int16_t *)s->pek;
- minVal = 32767;
- maxVal = -32768;
+ int16_t minVal = 32767;
+ int16_t maxVal = -32768;
// read samples before fixed samples (if needed)
if (index < s->fixedPos)
@@ -1117,12 +1092,12 @@
// for scanning sample data peak where loopEnd+SINC_RIGHT_TAPS is within scan range (fixed interpolation tap samples)
static void getSpecialMinMax8(sampleTyp *s, int32_t index, int32_t scanEnd, int8_t *min8, int8_t *max8)
{
- int8_t minVal, maxVal, minVal2, maxVal2;
+ int8_t minVal2, maxVal2;
const int8_t *ptr8 = (const int8_t *)s->pek;
- minVal = 127;
- maxVal = -128;
+ int8_t minVal = 127;
+ int8_t maxVal = -128;
// read samples before fixed samples (if needed)
if (index < s->fixedPos)
@@ -1226,10 +1201,7 @@
static void writeWaveform(void)
{
- int16_t x, y1, y2, min, max, oldMin, oldMax;
- int32_t smpIdx, smpNum, smpNumMin;
- uint32_t viewSizeSamples;
- sampleTyp *s;
+ int16_t y1, y2, min, max;
// clear sample data area
memset(&video.frameBuffer[174 * SCREEN_W], 0, SAMPLE_AREA_WIDTH * SAMPLE_AREA_HEIGHT * sizeof (int32_t));
@@ -1240,13 +1212,13 @@
if (instr[editor.curInstr] == NULL || smpEd_ViewSize == 0)
return;
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (s->pek == NULL || s->len == 0)
return;
y1 = SAMPLE_AREA_Y_CENTER - getScaledSample(s, scr2SmpPos(0));
- viewSizeSamples = smpEd_ViewSize;
+ uint32_t viewSizeSamples = smpEd_ViewSize;
if (s->typ & 16)
viewSizeSamples >>= 1;
@@ -1253,7 +1225,7 @@
if (viewSizeSamples <= SAMPLE_AREA_WIDTH)
{
// 1:1 or zoomed in
- for (x = 1; x < SAMPLE_AREA_WIDTH; x++)
+ for (int16_t x = 1; x < SAMPLE_AREA_WIDTH; x++)
{
y2 = SAMPLE_AREA_Y_CENTER - getScaledSample(s, scr2SmpPos(x));
sampleLine(x - 1, x, y1, y2);
@@ -1264,14 +1236,14 @@
{
// zoomed out
- oldMin = y1;
- oldMax = y1;
+ int16_t oldMin = y1;
+ int16_t oldMax = y1;
- smpNumMin = (s->typ & 16) ? 2 : 1;
- for (x = 0; x < SAMPLE_AREA_WIDTH; x++)
+ int32_t smpNumMin = (s->typ & 16) ? 2 : 1;
+ for (int16_t x = 0; x < SAMPLE_AREA_WIDTH; x++)
{
- smpIdx = scr2SmpPos(x);
- smpNum = scr2SmpPos(x+1) - smpIdx;
+ int32_t smpIdx = scr2SmpPos(x);
+ int32_t smpNum = scr2SmpPos(x+1) - smpIdx;
// prevent look-up overflow (yes, this can happen near the end of the sample)
if (smpIdx+smpNum > s->len)
@@ -1398,8 +1370,6 @@
static void setSampleRange(int32_t start, int32_t end)
{
- sampleTyp *s;
-
if (instr[editor.curInstr] == NULL)
{
smpEd_Rx1 = 0;
@@ -1407,7 +1377,7 @@
return;
}
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (start < 0)
start = 0;
@@ -1446,8 +1416,8 @@
void updateSampleEditor(void)
{
- char noteChar1, noteChar2, octaChar;
- uint8_t note, typ;
+ char noteChar1, noteChar2;
+ uint8_t typ;
int32_t sampleLen;
if (!ui.sampleEditorShown)
@@ -1489,7 +1459,7 @@
// draw sample play note
- note = (editor.smpEd_NoteNr - 1) % 12;
+ const uint8_t note = (editor.smpEd_NoteNr - 1) % 12;
if (config.ptnAcc == 0)
{
noteChar1 = sharpNote1Char[note];
@@ -1501,7 +1471,7 @@
noteChar2 = flatNote2Char[note];
}
- octaChar = '0' + ((editor.smpEd_NoteNr - 1) / 12);
+ char octaChar = '0' + ((editor.smpEd_NoteNr - 1) / 12);
charOutBg(7, 369, PAL_FORGRND, PAL_BCKGRND, noteChar1);
charOutBg(15, 369, PAL_FORGRND, PAL_BCKGRND, noteChar2);
@@ -1618,12 +1588,10 @@
void showRange(void)
{
- sampleTyp *s;
-
if (editor.curInstr == 0 || instr[editor.curInstr] == NULL)
return;
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (s->pek == NULL)
return;
@@ -1667,10 +1635,6 @@
static void zoomSampleDataIn(int32_t step, int32_t x)
{
- int32_t tmp32, minViewSize;
- int64_t newScrPos64;
- sampleTyp *s;
-
if (editor.curInstr == 0 ||
instr[editor.curInstr] == NULL ||
instr[editor.curInstr]->samp[editor.curSmp].pek == NULL)
@@ -1678,9 +1642,9 @@
return;
}
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
- minViewSize = (s->typ & 16) ? 4 : 2;
+ int32_t minViewSize = (s->typ & 16) ? 4 : 2;
if (old_ViewSize <= minViewSize)
return;
@@ -1693,13 +1657,13 @@
updateViewSize();
- tmp32 = (x - (SAMPLE_AREA_WIDTH / 2)) * step;
+ int32_t tmp32 = (x - (SAMPLE_AREA_WIDTH / 2)) * step;
tmp32 += SAMPLE_AREA_WIDTH/4; // rounding bias
tmp32 /= SAMPLE_AREA_WIDTH/2;
step += tmp32;
- newScrPos64 = old_SmpScrPos + step;
+ int64_t newScrPos64 = old_SmpScrPos + step;
if (newScrPos64+smpEd_ViewSize > s->len)
newScrPos64 = s->len - smpEd_ViewSize;
@@ -1709,10 +1673,6 @@
static void zoomSampleDataOut(int32_t step, int32_t x)
{
- int32_t tmp32;
- int64_t newViewSize64;
- sampleTyp *s;
-
if (editor.curInstr == 0 ||
instr[editor.curInstr] == NULL ||
instr[editor.curInstr]->samp[editor.curSmp].pek == NULL)
@@ -1720,8 +1680,7 @@
return;
}
- s = &instr[editor.curInstr]->samp[editor.curSmp];
-
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (old_ViewSize == s->len)
return;
@@ -1728,7 +1687,7 @@
if (step < 1)
step = 1;
- newViewSize64 = (int64_t)old_ViewSize + (step * 2);
+ int64_t newViewSize64 = (int64_t)old_ViewSize + (step * 2);
if (newViewSize64 > s->len)
{
smpEd_ViewSize = s->len;
@@ -1736,7 +1695,7 @@
}
else
{
- tmp32 = (x - (SAMPLE_AREA_WIDTH / 2)) * step;
+ int32_t tmp32 = (x - (SAMPLE_AREA_WIDTH / 2)) * step;
tmp32 += SAMPLE_AREA_WIDTH/4; // rounding bias
tmp32 /= SAMPLE_AREA_WIDTH/2;
@@ -1765,7 +1724,7 @@
return;
}
- zoomSampleDataIn((old_ViewSize + 5) / 10, mouse.x);
+ zoomSampleDataIn((old_ViewSize+5) / 10, mouse.x);
}
void mouseZoomSampleDataOut(void)
@@ -1777,13 +1736,11 @@
return;
}
- zoomSampleDataOut((old_ViewSize + 5) / 10, mouse.x);
+ zoomSampleDataOut((old_ViewSize+5) / 10, mouse.x);
}
void zoomOut(void)
{
- sampleTyp *s;
-
if (editor.curInstr == 0 ||
instr[editor.curInstr] == NULL ||
instr[editor.curInstr]->samp[editor.curSmp].pek == NULL)
@@ -1791,8 +1748,7 @@
return;
}
- s = &instr[editor.curInstr]->samp[editor.curSmp];
-
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (old_ViewSize == s->len)
return;
@@ -1837,8 +1793,6 @@
void saveRange(void)
{
- UNICHAR *filenameU;
-
if (editor.curInstr == 0 ||
instr[editor.curInstr] == NULL ||
instr[editor.curInstr]->samp[editor.curSmp].pek == NULL)
@@ -1881,7 +1835,7 @@
default: case SMP_SAVE_MODE_WAV: changeFilenameExt(smpEd_SysReqText, ".wav", sizeof (smpEd_SysReqText) - 1); break;
}
- filenameU = cp437ToUnichar(smpEd_SysReqText);
+ UNICHAR *filenameU = cp437ToUnichar(smpEd_SysReqText);
if (filenameU == NULL)
{
okBox(0, "System message", "Error converting string locale!");
@@ -1894,10 +1848,7 @@
static bool cutRange(bool cropMode, int32_t r1, int32_t r2)
{
- int8_t *newPtr;
- int32_t len, repE;
sampleTyp *s = getCurSample();
-
if (s == NULL)
return false;
@@ -1929,10 +1880,10 @@
memmove(&s->pek[r1], &s->pek[r2], s->len - r2);
- len = s->len - r2 + r1;
+ int32_t len = s->len - r2 + r1;
if (len > 0)
{
- newPtr = (int8_t *)realloc(s->origPek, len + LOOP_FIX_LEN);
+ int8_t *newPtr = (int8_t *)realloc(s->origPek, len + LOOP_FIX_LEN);
if (newPtr == NULL)
{
freeSample(editor.curInstr, editor.curSmp);
@@ -1950,7 +1901,7 @@
s->len = len;
- repE = s->repS + s->repL;
+ int32_t repE = s->repS + s->repL;
if (s->repS > r1)
{
s->repS -= r2 - r1;
@@ -2010,8 +1961,6 @@
static int32_t SDLCALL sampCutThread(void *ptr)
{
- (void)ptr;
-
if (!cutRange(false, smpEd_Rx1, smpEd_Rx2))
okBoxThreadSafe(0, "System message", "Not enough memory! (Disable \"cut to buffer\")");
else
@@ -2018,12 +1967,13 @@
writeSampleFlag = true;
return true;
+
+ (void)ptr;
}
void sampCut(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0 || smpEd_Rx2 == 0 || smpEd_Rx2 < smpEd_Rx1)
return;
@@ -2041,9 +1991,6 @@
static int32_t SDLCALL sampCopyThread(void *ptr)
{
sampleTyp *s = getCurSample();
-
- (void)ptr;
-
assert(s != NULL && (!(s->typ & 16) || (!(smpEd_Rx1 & 1) && !(smpEd_Rx2 & 1))));
if (!getCopyBuffer(smpEd_Rx2 - smpEd_Rx1))
@@ -2060,12 +2007,13 @@
setMouseBusy(false);
return true;
+
+ (void)ptr;
}
void sampCopy(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->origPek == NULL || s->len <= 0 || smpEd_Rx2 == 0 || smpEd_Rx2 < smpEd_Rx1)
return;
@@ -2158,12 +2106,6 @@
static int32_t SDLCALL sampPasteThread(void *ptr)
{
- int8_t *p;
- int32_t newLength, realCopyLen;
- sampleTyp *s;
-
- (void)ptr;
-
if (instr[editor.curInstr] == NULL && !allocateInstr(editor.curInstr))
{
okBoxThreadSafe(0, "System message", "Not enough memory!");
@@ -2170,8 +2112,7 @@
return true;
}
- s = getCurSample();
-
+ sampleTyp *s = getCurSample();
if (smpEd_Rx2 == 0 || s == NULL || s->pek == NULL)
{
pasteOverwrite(s);
@@ -2179,7 +2120,6 @@
}
bool smpIs16Bit = (s->typ >> 4) & 1;
-
assert(!smpIs16Bit || (!(smpEd_Rx1 & 1) && !(smpEd_Rx2 & 1) && !(s->len & 1)));
if (s->len+smpCopySize > MAX_SAMPLE_LEN)
@@ -2188,7 +2128,7 @@
return true;
}
- realCopyLen = smpCopySize;
+ int32_t realCopyLen = smpCopySize;
if (smpIs16Bit)
{
@@ -2205,7 +2145,7 @@
realCopyLen >>= 1;
}
- newLength = s->len + realCopyLen - (smpEd_Rx2 - smpEd_Rx1);
+ int32_t newLength = s->len + realCopyLen - (smpEd_Rx2 - smpEd_Rx1);
if (newLength <= 0)
return true;
@@ -2215,7 +2155,7 @@
return true;
}
- p = (int8_t *)malloc(newLength + LOOP_FIX_LEN);
+ int8_t *p = (int8_t *)malloc(newLength + LOOP_FIX_LEN);
if (p == NULL)
{
okBoxThreadSafe(0, "System message", "Not enough memory!");
@@ -2293,6 +2233,8 @@
writeSampleFlag = true;
return true;
+
+ (void)ptr;
}
void sampPaste(void)
@@ -2323,15 +2265,11 @@
static int32_t SDLCALL sampCropThread(void *ptr)
{
- int32_t r1, r2;
sampleTyp *s = getCurSample();
-
- (void)ptr;
-
assert(!(s->typ & 16) || (!(smpEd_Rx1 & 1) && !(smpEd_Rx2 & 1) && !(s->len & 1)));
- r1 = smpEd_Rx1;
- r2 = smpEd_Rx2;
+ int32_t r1 = smpEd_Rx1;
+ int32_t r2 = smpEd_Rx2;
pauseAudio();
restoreSample(s);
@@ -2360,12 +2298,13 @@
writeSampleFlag = true;
return true;
+
+ (void)ptr;
}
void sampCrop(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0 || smpEd_Rx1 >= smpEd_Rx2)
return;
@@ -2385,19 +2324,17 @@
void sampXFade(void)
{
- bool is16Bit;
- uint8_t t;
- int16_t c ,d;
- int32_t tmp32, i, x1, x2, y1, y2, a, b, d1, d2, d3, dist;
+ int16_t c, d;
+ int32_t tmp32, i, y1, y2, a, b, d1, d2, d3, dist;
double dR, dS1, dS2, dS3, dS4;
- sampleTyp *s = getCurSample();
+ sampleTyp *s = getCurSample();
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
assert(!(s->typ & 16) || (!(smpEd_Rx1 & 1) && !(smpEd_Rx2 & 1) && !(s->len & 1)));
- t = s->typ;
+ uint8_t t = s->typ;
// check if the sample has the loop flag enabled
if ((t & 3) == 0)
@@ -2420,10 +2357,10 @@
return;
}
- x1 = smpEd_Rx1;
- x2 = smpEd_Rx2;
+ int32_t x1 = smpEd_Rx1;
+ int32_t x2 = smpEd_Rx2;
- is16Bit = (t & 16) ? true : false;
+ bool is16Bit = (t & 16) ? true : false;
if ((t & 3) >= 2)
{
@@ -2657,7 +2594,6 @@
void rbSampleNoLoop(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2677,7 +2613,6 @@
void rbSampleForwardLoop(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2685,7 +2620,6 @@
restoreSample(s);
s->typ = (s->typ & ~3) | 1;
-
if (s->repL+s->repS == 0)
{
s->repS = 0;
@@ -2703,7 +2637,6 @@
void rbSamplePingpongLoop(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2711,7 +2644,6 @@
restoreSample(s);
s->typ = (s->typ & ~3) | 2;
-
if (s->repL+s->repS == 0)
{
s->repS = 0;
@@ -2728,26 +2660,20 @@
static int32_t SDLCALL convSmp8Bit(void *ptr)
{
- int8_t *dst8, *newPtr;
- int16_t *src16;
- int32_t i, newLen;
sampleTyp *s = getCurSample();
- (void)ptr;
-
pauseAudio();
restoreSample(s);
- src16 = (int16_t *)s->pek;
- dst8 = s->pek;
+ const int16_t *src16 = (const int16_t *)s->pek;
+ int32_t newLen = s->len >> 1;
- newLen = s->len >> 1;
- for (i = 0; i < newLen; i++)
- dst8[i] = src16[i] >> 8;
+ for (int32_t i = 0; i < newLen; i++)
+ s->pek[i] = src16[i] >> 8;
assert(s->origPek != NULL);
- newPtr = (int8_t *)realloc(s->origPek, newLen + LOOP_FIX_LEN);
+ int8_t *newPtr = (int8_t *)realloc(s->origPek, newLen + LOOP_FIX_LEN);
if (newPtr != NULL)
{
s->origPek = newPtr;
@@ -2767,12 +2693,13 @@
setMouseBusy(false);
return true;
+
+ (void)ptr;
}
void rbSample8bit(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2807,19 +2734,14 @@
static int32_t SDLCALL convSmp16Bit(void *ptr)
{
- int8_t *src8, *newPtr;
- int16_t smp16, *dst16;
- int32_t i;
sampleTyp *s = getCurSample();
- (void)ptr;
-
pauseAudio();
restoreSample(s);
assert(s->origPek != NULL);
- newPtr = (int8_t *)realloc(s->origPek, (s->len * 2) + LOOP_FIX_LEN);
+ int8_t *newPtr = (int8_t *)realloc(s->origPek, (s->len * 2) + LOOP_FIX_LEN);
if (newPtr == NULL)
{
okBoxThreadSafe(0, "System message", "Not enough memory!");
@@ -2831,15 +2753,10 @@
s->pek = s->origPek + SMP_DAT_OFFSET;
}
- src8 = s->pek;
- dst16 = (int16_t *)s->pek;
+ int16_t *dst16 = (int16_t *)s->pek;
+ for (int32_t i = s->len-1; i >= 0; i--)
+ dst16[i] = s->pek[i] << 8;
- for (i = s->len-1; i >= 0; i--)
- {
- smp16 = src8[i] << 8;
- dst16[i] = smp16;
- }
-
s->len <<= 1;
s->repL <<= 1;
s->repS <<= 1;
@@ -2853,12 +2770,13 @@
setMouseBusy(false);
return true;
+
+ (void)ptr;
}
void rbSample16bit(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2899,7 +2817,6 @@
void clearSample(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2913,9 +2830,7 @@
void sampMin(void)
{
- int8_t *newPtr;
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2929,7 +2844,7 @@
s->len = s->repS + s->repL;
- 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;
@@ -2948,9 +2863,9 @@
void sampRepeatUp(void)
{
- int32_t repS, repL, addVal, lenSub;
- sampleTyp *s = getCurSample();
+ int32_t addVal, lenSub;
+ sampleTyp *s = getCurSample();
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -2965,8 +2880,8 @@
addVal = 1;
}
- repS = curSmpRepS;
- repL = curSmpRepL;
+ int32_t repS = curSmpRepS;
+ int32_t repL = curSmpRepL;
if (repS < s->len-lenSub)
repS += addVal;
@@ -2983,17 +2898,11 @@
void sampRepeatDown(void)
{
- int32_t repS;
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
- if (s->typ & 16)
- repS = curSmpRepS - 2;
- else
- repS = curSmpRepS - 1;
-
+ int32_t repS = (s->typ & 16) ? curSmpRepS-2 : curSmpRepS-1;
if (repS < 0)
repS = 0;
@@ -3005,17 +2914,11 @@
void sampReplenUp(void)
{
- int32_t repL;
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
- if (s->typ & 16)
- repL = curSmpRepL + 2;
- else
- repL = curSmpRepL + 1;
-
+ int32_t repL = (s->typ & 16) ? curSmpRepL+2 : curSmpRepL+1;
if (curSmpRepS+repL > s->len)
repL = s->len - curSmpRepS;
@@ -3028,8 +2931,8 @@
void sampReplenDown(void)
{
int32_t repL;
- sampleTyp *s = getCurSample();
+ sampleTyp *s = getCurSample();
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -3185,28 +3088,21 @@
static void writeSmpXORLine(int32_t x)
{
- uint32_t *ptr32;
-
if (x < 0 || x >= SCREEN_W)
return;
- ptr32 = &video.frameBuffer[(174 * SCREEN_W) + x];
- for (int32_t y = 0; y < SAMPLE_AREA_HEIGHT; y++)
- {
+ uint32_t *ptr32 = &video.frameBuffer[(174 * SCREEN_W) + x];
+ for (int32_t y = 0; y < SAMPLE_AREA_HEIGHT; y++, ptr32 += SCREEN_W)
*ptr32 = video.palette[(*ptr32 >> 24) ^ 1]; // ">> 24" to get palette, XOR 1 to switch between normal/inverted mode
- ptr32 += SCREEN_W;
- }
}
static void writeSamplePosLine(void)
{
uint8_t ins, smp;
- int32_t smpPos, scrPos;
- lastChInstr_t *c;
assert(editor.curSmpChannel < MAX_VOICES);
+ lastChInstr_t *c = &lastChInstr[editor.curSmpChannel];
- c = &lastChInstr[editor.curSmpChannel];
if (c->instrNr == 130) // "Play Wave/Range/Display" in Smp. Ed.
{
ins = editor.curPlayInstr;
@@ -3220,11 +3116,11 @@
if (editor.curInstr == ins && editor.curSmp == smp)
{
- smpPos = getSamplePosition(editor.curSmpChannel);
+ const int32_t smpPos = getSamplePosition(editor.curSmpChannel);
if (smpPos != -1)
{
// convert sample position to screen position
- scrPos = smpPos2Scr(smpPos);
+ const int32_t scrPos = smpPos2Scr(smpPos);
if (scrPos != -1)
{
if (scrPos != smpEd_OldSmpPosLine)
@@ -3267,17 +3163,14 @@
static void setLeftLoopPinPos(int32_t x)
{
- int32_t repS, repL, newPos;
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
- newPos = scr2SmpPos(x) - curSmpRepS;
+ int32_t newPos = scr2SmpPos(x) - curSmpRepS;
+ int32_t repS = curSmpRepS + newPos;
+ int32_t repL = curSmpRepL - newPos;
- repS = curSmpRepS + newPos;
- repL = curSmpRepL - newPos;
-
if (repS < 0)
{
repL += repS;
@@ -3305,13 +3198,11 @@
static void setRightLoopPinPos(int32_t x)
{
- int32_t repL;
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
- repL = scr2SmpPos(x) - curSmpRepS;
+ int32_t repL = scr2SmpPos(x) - curSmpRepS;
if (repL < 0)
repL = 0;
@@ -3332,21 +3223,12 @@
static int32_t mouseYToSampleY(int32_t my)
{
- int32_t tmp32;
+ my -= 174; // 0..SAMPLE_AREA_HEIGHT-1
- if (my == 250) // center
- {
- return 128;
- }
- else
- {
- tmp32 = my - 174;
- tmp32 = ((tmp32 << 8) + (SAMPLE_AREA_HEIGHT/2)) / SAMPLE_AREA_HEIGHT;
- tmp32 = CLAMP(tmp32, 0, 255);
- tmp32 ^= 0xFF;
- }
+ const double dTmp = round(my * (256.0 / SAMPLE_AREA_HEIGHT));
+ const int32_t tmp32 = (const int32_t)dTmp;
- return tmp32;
+ return 255 - CLAMP(tmp32, 0, 255);
}
static void editSampleData(bool mouseButtonHeld)
@@ -3353,19 +3235,17 @@
{
int8_t *ptr8;
int16_t *ptr16;
- int32_t mx, my, tmp32, p, vl, tvl, r, rl, rvl, start, end;
- sampleTyp *s = getCurSample();
+ int32_t tmp32, p, vl, tvl, r, rl, rvl, start, end;
+ sampleTyp *s = getCurSample();
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
- // ported directly from FT2 and slightly modified
-
- mx = mouse.x;
+ int32_t mx = mouse.x;
if (mx > SCREEN_W)
mx = SCREEN_W;
- my = mouse.y;
+ int32_t my = mouse.y;
if (!mouseButtonHeld)
{
@@ -3521,13 +3401,11 @@
void handleSampleDataMouseDown(bool mouseButtonHeld)
{
- int32_t mx, my, leftLoopPinPos, rightLoopPinPos;
-
if (editor.curInstr == 0)
return;
- mx = CLAMP(mouse.x, 0, SCREEN_W+8); // allow some pixels outside of the screen
- my = CLAMP(mouse.y, 0, SCREEN_H-1);
+ const int32_t mx = CLAMP(mouse.x, 0, SCREEN_W+8); // allow some pixels outside of the screen
+ const int32_t my = CLAMP(mouse.y, 0, SCREEN_H-1);
if (!mouseButtonHeld)
{
@@ -3546,7 +3424,7 @@
// move loop pins
if (my < 183)
{
- leftLoopPinPos = getSpritePosX(SPRITE_LEFT_LOOP_PIN);
+ const int32_t leftLoopPinPos = getSpritePosX(SPRITE_LEFT_LOOP_PIN);
if (mx >= leftLoopPinPos && mx <= leftLoopPinPos+16)
{
mouseXOffs = (leftLoopPinPos + 8) - mx;
@@ -3562,7 +3440,7 @@
}
else if (my > 318)
{
- rightLoopPinPos = getSpritePosX(SPRITE_RIGHT_LOOP_PIN);
+ const int32_t rightLoopPinPos = getSpritePosX(SPRITE_RIGHT_LOOP_PIN);
if (mx >= rightLoopPinPos && mx <= rightLoopPinPos+16)
{
mouseXOffs = (rightLoopPinPos + 8) - mx;
@@ -3724,8 +3602,6 @@
int16_t tmp16, *ptrStart16, *ptrEnd16;
sampleTyp *s = getCurSample();
- (void)ptr;
-
if (s->typ & 16)
{
if (smpEd_Rx1 >= smpEd_Rx2)
@@ -3784,12 +3660,13 @@
writeSampleFlag = true;
return true;
+
+ (void)ptr;
}
void sampleBackwards(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len < 2)
return;
@@ -3811,8 +3688,6 @@
int32_t i, len;
sampleTyp *s = getCurSample();
- (void)ptr;
-
pauseAudio();
restoreSample(s);
@@ -3841,12 +3716,13 @@
writeSampleFlag = true;
return true;
+
+ (void)ptr;
}
void sampleConv(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -3863,25 +3739,19 @@
static int32_t SDLCALL sampleConvWThread(void *ptr)
{
- int8_t *ptr8, tmp;
- int32_t len;
sampleTyp *s = getCurSample();
- (void)ptr;
-
pauseAudio();
restoreSample(s);
- len = s->len / 2;
- ptr8 = s->pek;
+ int32_t len = s->len / 2;
+ int8_t *ptr8 = s->pek;
- for (int32_t i = 0; i < len; i++)
+ for (int32_t i = 0; i < len; i++, ptr8 += 2)
{
- tmp = ptr8[0];
+ const int8_t tmp = ptr8[0];
ptr8[0] = ptr8[1];
ptr8[1] = tmp;
-
- ptr8 += 2;
}
fixSample(s);
@@ -3892,12 +3762,13 @@
writeSampleFlag = true;
return true;
+
+ (void)ptr;
}
void sampleConvW(void)
{
sampleTyp *s = getCurSample();
-
if (s == NULL || s->pek == NULL || s->len <= 0)
return;
@@ -3917,13 +3788,10 @@
int8_t *ptr8;
int16_t *ptr16;
int32_t i, len, smpSub, smp32;
- int64_t averageDC;
sampleTyp *s = getCurSample();
- (void)ptr;
+ int64_t averageDC = 0;
- averageDC = 0;
-
if (s->typ & 16)
{
if (smpEd_Rx1 >= smpEd_Rx2)
@@ -4009,6 +3877,8 @@
setMouseBusy(false);
return true;
+
+ (void)ptr;
}
void fixDC(void)
@@ -4038,13 +3908,11 @@
void testSmpEdMouseUp(void) // used for setting new loop points
{
- sampleTyp *s;
-
if (updateLoopsOnMouseUp)
{
updateLoopsOnMouseUp = false;
- s = getCurSample();
+ sampleTyp *s = getCurSample();
if (s == NULL)
return;
--- a/src/ft2_sample_ed_features.c
+++ b/src/ft2_sample_ed_features.c
@@ -81,30 +81,21 @@
static int32_t SDLCALL resampleThread(void *ptr)
{
- int8_t *p1, *p2, *src8, *dst8;
- int16_t *src16, *dst16;
- uint32_t newLen, mask, resampleLen;
- uint64_t posFrac64, delta64;
- double dNewLen, dLenMul;
- sampleTyp *s;
-
- (void)ptr;
-
if (instr[editor.curInstr] == NULL)
return true;
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
- mask = (s->typ & 16) ? 0xFFFFFFFE : 0xFFFFFFFF;
- dLenMul = exp2(smpEd_RelReSmp * (1.0 / 12.0));
+ const uint32_t mask = (s->typ & 16) ? 0xFFFFFFFE : 0xFFFFFFFF;
+ const double dRatio = exp2(smpEd_RelReSmp / 12.0);
- dNewLen = s->len * dLenMul;
+ double dNewLen = s->len * dRatio;
if (dNewLen > (double)MAX_SAMPLE_LEN)
dNewLen = (double)MAX_SAMPLE_LEN;
- newLen = (int32_t)dNewLen & mask;
+ const uint32_t newLen = (int32_t)dNewLen & mask;
- p2 = (int8_t *)malloc(newLen + LOOP_FIX_LEN);
+ int8_t *p2 = (int8_t *)malloc(newLen + LOOP_FIX_LEN);
if (p2 == NULL)
{
outOfMemory = true;
@@ -114,25 +105,30 @@
}
int8_t *newPtr = p2 + SMP_DAT_OFFSET;
+ int8_t *p1 = s->pek;
- p1 = s->pek;
+ // 32.32 fixed-point logic
+ const uint64_t delta64 = (const uint64_t)round((UINT32_MAX+1.0) / dRatio);
+ uint64_t posFrac64 = 0;
- // don't use the potentially clamped newLen value here
- delta64 = ((int64_t)s->len << 32) / (int64_t)(s->len * dLenMul); // 32.32 fixed point delta
-
- posFrac64 = 0; // 32.32 fixed point position.fraction
-
pauseAudio();
restoreSample(s);
+ /* Nearest-neighbor resampling (no interpolation).
+ **
+ ** Could benefit from windowed-sinc interpolation,
+ ** but it seems like some people prefer no resampling
+ ** interpolation (like FT2).
+ */
+
if (newLen > 0)
{
if (s->typ & 16)
{
- src16 = (int16_t *)p1;
- dst16 = (int16_t *)newPtr;
+ const int16_t *src16 = (const int16_t *)p1;
+ int16_t *dst16 = (int16_t *)newPtr;
- resampleLen = newLen >> 1;
+ const uint32_t resampleLen = newLen >> 1;
for (uint32_t i = 0; i < resampleLen; i++)
{
dst16[i] = src16[posFrac64 >> 32];
@@ -141,8 +137,8 @@
}
else
{
- src8 = p1;
- dst8 = newPtr;
+ const int8_t *src8 = p1;
+ int8_t *dst8 = newPtr;
for (uint32_t i = 0; i < newLen; i++)
{
@@ -155,15 +151,11 @@
free(s->origPek);
s->relTon = CLAMP(s->relTon + smpEd_RelReSmp, -48, 71);
-
s->len = newLen & mask;
-
s->origPek = p2;
s->pek = s->origPek + SMP_DAT_OFFSET;
-
- s->repS = (int32_t)(s->repS * dLenMul);
- s->repL = (int32_t)(s->repL * dLenMul);
-
+ s->repS = (int32_t)(s->repS * dRatio);
+ s->repL = (int32_t)(s->repL * dRatio);
s->repS &= mask;
s->repL &= mask;
@@ -191,6 +183,8 @@
ui.sysReqShown = false;
return true;
+
+ (void)ptr;
}
static void pbDoResampling(void)
@@ -213,10 +207,6 @@
const int16_t y = 230;
const int16_t w = 214;
const int16_t h = 54;
- uint16_t val;
- uint32_t mask;
- double dNewLen, dLenMul;
- sampleTyp *s;
// main fill
fillRect(x + 1, y + 1, w - 2, h - 2, PAL_BUTTONS);
@@ -233,12 +223,12 @@
vLine(x + w - 3, y + 2, h - 4, PAL_BUTTON1);
hLine(x + 2, y + h - 3, w - 4, PAL_BUTTON1);
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
- mask = (s->typ & 16) ? 0xFFFFFFFE : 0xFFFFFFFF;
- dLenMul = exp2(smpEd_RelReSmp * (1.0 / 12.0));
+ uint32_t mask = (s->typ & 16) ? 0xFFFFFFFE : 0xFFFFFFFF;
+ double dLenMul = exp2(smpEd_RelReSmp * (1.0 / 12.0));
- dNewLen = s->len * dLenMul;
+ double dNewLen = s->len * dLenMul;
if (dNewLen > (double)MAX_SAMPLE_LEN)
dNewLen = (double)MAX_SAMPLE_LEN;
@@ -250,7 +240,7 @@
else if (smpEd_RelReSmp < 0) sign = '-';
else sign = '+';
- val = ABS(smpEd_RelReSmp);
+ uint16_t val = ABS(smpEd_RelReSmp);
if (val > 9)
{
charOut(291, 236, PAL_FORGRND, sign);
@@ -405,7 +395,7 @@
static void pbEchoNumUp(void)
{
- if (echo_nEcho < 1024)
+ if (echo_nEcho < 64)
echo_nEcho++;
}
@@ -435,26 +425,6 @@
static int32_t SDLCALL createEchoThread(void *ptr)
{
- int8_t *readPtr, *writePtr, *writePtr8, *newPtr;
- bool is16Bit;
- int16_t *readPtr16, *writePtr16;
- int32_t nEchoes, distance, readLen, writeLen, i, j;
- int32_t smpOut, volChange, smpMul, echoRead, echoCycle, writeIdx;
- int64_t tmp64;
- sampleTyp *s;
-
- (void)ptr;
-
- s = &instr[editor.curInstr]->samp[editor.curSmp];
-
- readLen = s->len;
- readPtr = s->pek;
- is16Bit = (s->typ & 16) ? true : false;
- distance = echo_Distance * 16;
-
- // scale value for faster math and suitable rounding for PCM waveforms (DIV -> arithmetic bitshift right)
- volChange = (echo_VolChange * 256) / 100; // 0..100 -> 0..256
-
if (echo_nEcho < 1)
{
ui.sysReqShown = false;
@@ -461,15 +431,21 @@
return true;
}
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
+
+ int32_t readLen = s->len;
+ int8_t *readPtr = s->pek;
+ bool is16Bit = (s->typ & 16) ? true : false;
+ int32_t distance = echo_Distance * 16;
+
+ double dVolChange = echo_VolChange / 100.0;
+
// calculate real number of echoes
- j = 32768;
- i = 0;
- while (i < echo_nEcho && j > 0)
- {
- j = (j * volChange) >> 8;
- i++;
- }
- nEchoes = i + 1;
+ double dSmp = is16Bit ? 32768.0 : 128.0;
+ int32_t k = 0;
+ while (k++ < echo_nEcho && dSmp >= 1.0)
+ dSmp *= dVolChange;
+ int32_t nEchoes = k + 1;
if (nEchoes < 1)
{
@@ -478,10 +454,10 @@
}
// set write length (either original length or full echo length)
- writeLen = readLen;
+ int32_t writeLen = readLen;
if (echo_AddMemory)
{
- tmp64 = (int64_t)distance * (nEchoes - 1);
+ int64_t tmp64 = (int64_t)distance * (nEchoes - 1);
if (is16Bit)
tmp64 <<= 1;
@@ -495,7 +471,7 @@
writeLen &= 0xFFFFFFFE;
}
- writePtr = (int8_t *)malloc(writeLen + LOOP_FIX_LEN);
+ int8_t *writePtr = (int8_t *)malloc(writeLen + LOOP_FIX_LEN);
if (writePtr == NULL)
{
outOfMemory = true;
@@ -507,12 +483,12 @@
pauseAudio();
restoreSample(s);
- writeIdx = 0;
+ int32_t writeIdx = 0;
if (is16Bit)
{
- readPtr16 = (int16_t *)readPtr;
- writePtr16 = (int16_t *)&writePtr[SMP_DAT_OFFSET];
+ const int16_t *readPtr16 = (const int16_t *)readPtr;
+ int16_t *writePtr16 = (int16_t *)&writePtr[SMP_DAT_OFFSET];
writeLen >>= 1;
readLen >>= 1;
@@ -519,27 +495,30 @@
while (writeIdx < writeLen)
{
- smpOut = 0;
- smpMul = 32768;
+ double dSmpOut = 0.0;
+ double dSmpMul = 1.0;
- echoRead = writeIdx;
- echoCycle = nEchoes;
+ int32_t echoRead = writeIdx;
+ int32_t echoCycle = nEchoes;
while (!stopThread)
{
if (echoRead < readLen)
- smpOut += (readPtr16[echoRead] * smpMul) >> 15;
+ dSmpOut += (int32_t)readPtr16[echoRead] * dSmpMul;
- smpMul = (smpMul * volChange) >> 8;
+ dSmpMul *= dVolChange;
echoRead -= distance;
- echoCycle--;
-
- if (echoRead <= 0 || echoCycle <= 0)
+ if (echoRead <= 0 || --echoCycle <= 0)
break;
}
- CLAMP16(smpOut);
+ // rounding (faster than calling round())
+ if (dSmpOut < 0.0) dSmpOut -= 0.5;
+ else if (dSmpOut > 0.0) dSmpOut += 0.5;
+
+ int32_t smpOut = (int32_t)dSmpOut;
+ CLAMP16(smpOut);
writePtr16[writeIdx++] = (int16_t)smpOut;
}
@@ -547,31 +526,35 @@
}
else
{
- writePtr8 = writePtr + SMP_DAT_OFFSET;
+ int8_t *writePtr8 = writePtr + SMP_DAT_OFFSET;
while (writeIdx < writeLen)
{
- smpOut = 0;
- smpMul = 32768;
+ double dSmpOut = 0.0;
+ double dSmpMul = 1.0;
- echoRead = writeIdx;
- echoCycle = nEchoes;
+ int32_t echoRead = writeIdx;
+ int32_t echoCycle = nEchoes;
while (!stopThread)
{
if (echoRead < readLen)
- smpOut += (readPtr[echoRead] * smpMul) >> (15-8);
+ dSmpOut += (int32_t)readPtr[echoRead] * dSmpMul;
- smpMul = (smpMul * volChange) >> 8;
+ dSmpMul *= dVolChange;
echoRead -= distance;
- echoCycle--;
-
- if (echoRead <= 0 || echoCycle <= 0)
+ if (echoRead <= 0 || --echoCycle <= 0)
break;
}
- CLAMP16(smpOut);
- writePtr8[writeIdx++] = (int8_t)(smpOut >> 8);
+ // rounding (faster than calling round())
+ if (dSmpOut < 0.0) dSmpOut -= 0.5;
+ else if (dSmpOut > 0.0) dSmpOut += 0.5;
+
+ int32_t smpOut = (int32_t)dSmpOut;
+ if (smpOut < -128) smpOut = -128;
+ else if (smpOut > 127) smpOut = 127;
+ writePtr8[writeIdx++] = (int8_t)smpOut;
}
}
@@ -581,7 +564,7 @@
{
writeLen = writeIdx;
- newPtr = (int8_t *)realloc(writePtr, writeIdx + LOOP_FIX_LEN);
+ int8_t *newPtr = (int8_t *)realloc(writePtr, writeIdx + LOOP_FIX_LEN);
if (newPtr != NULL)
{
s->origPek = newPtr;
@@ -617,6 +600,8 @@
ui.sysReqShown = false;
return true;
+
+ (void)ptr;
}
static void pbCreateEcho(void)
@@ -661,11 +646,8 @@
textOutShadow(177, 254, PAL_FORGRND, PAL_BUTTON2, "Fade out");
textOutShadow(192, 270, PAL_FORGRND, PAL_BUTTON2, "Add memory to sample");
- assert(echo_nEcho <= 1024);
-
- charOut(315 + (0 * 7), 226, PAL_FORGRND, '0' + (char)(echo_nEcho / 1000));
- charOut(315 + (1 * 7), 226, PAL_FORGRND, '0' + (echo_nEcho / 100) % 10);
- charOut(315 + (2 * 7), 226, PAL_FORGRND, '0' + (echo_nEcho / 10) % 10);
+ assert(echo_nEcho <= 64);
+ charOut(315 + (2 * 7), 226, PAL_FORGRND, '0' + (char)(echo_nEcho / 10));
charOut(315 + (3 * 7), 226, PAL_FORGRND, '0' + (echo_nEcho % 10));
assert(echo_Distance <= 0x4000);
@@ -800,7 +782,7 @@
s->callbackFunc = sbSetEchoNumPos;
s->visible = true;
setScrollBarPageLength(0, 1);
- setScrollBarEnd(0, 1024);
+ setScrollBarEnd(0, 64);
// echo distance scrollbar
s = &scrollBars[1];
@@ -881,18 +863,15 @@
static int32_t SDLCALL mixThread(void *ptr)
{
- int8_t *destPtr, *mixPtr, *p;
+ int8_t *destPtr, *mixPtr;
uint8_t mixTyp, destTyp;
- int16_t destIns, destSmp, mixIns, mixSmp;
- int32_t mixMul1, mixMul2, smp32, x1, x2, i, destLen, mixLen, maxLen, dest8Size, max8Size, mix8Size;
+ int32_t destLen, mixLen;
- (void)ptr;
+ int16_t destIns = editor.curInstr;
+ int16_t destSmp = editor.curSmp;
+ int16_t mixIns = editor.srcInstr;
+ int16_t mixSmp = editor.srcSmp;
- destIns = editor.curInstr;
- destSmp = editor.curSmp;
- mixIns = editor.srcInstr;
- mixSmp = editor.srcSmp;
-
if (destIns == mixIns && destSmp == mixSmp)
{
setMouseBusy(false);
@@ -941,10 +920,10 @@
bool src16Bits = (mixTyp >> 4) & 1;
bool dst16Bits = (destTyp >> 4) & 1;
- mix8Size = src16Bits ? (mixLen >> 1) : mixLen;
- dest8Size = dst16Bits ? (destLen >> 1) : destLen;
- max8Size = (dest8Size > mix8Size) ? dest8Size : mix8Size;
- maxLen = dst16Bits ? (max8Size << 1) : max8Size;
+ int32_t mix8Size = src16Bits ? (mixLen >> 1) : mixLen;
+ int32_t dest8Size = dst16Bits ? (destLen >> 1) : destLen;
+ int32_t max8Size = (dest8Size > mix8Size) ? dest8Size : mix8Size;
+ int32_t maxLen = dst16Bits ? (max8Size << 1) : max8Size;
if (maxLen <= 0)
{
@@ -953,7 +932,7 @@
return true;
}
- p = (int8_t *)calloc(maxLen + LOOP_FIX_LEN, sizeof (int8_t));
+ int8_t *p = (int8_t *)calloc(maxLen + LOOP_FIX_LEN, sizeof (int8_t));
if (p == NULL)
{
outOfMemory = true;
@@ -978,27 +957,39 @@
if (instr[mixIns] != NULL)
restoreSample(&instr[mixIns]->samp[mixSmp]);
- // scale value for faster math and suitable rounding for PCM waveforms (DIV -> arithmetic bitshift right)
- mixMul1 = (mix_Balance * 256) / 100;
- mixMul2 = 256 - mixMul1;
+ const double dAmp1 = mix_Balance / 100.0;
+ const double dAmp2 = 1.0 - dAmp1;
int8_t *destPek = p + SMP_DAT_OFFSET;
- for (i = 0; i < max8Size; i++)
+ for (int32_t i = 0; i < max8Size; i++)
{
int32_t index16 = i << 1;
- x1 = (i >= mix8Size) ? 0 : getSampleValue(mixPtr, mixTyp, src16Bits ? index16 : i);
- x2 = (i >= dest8Size) ? 0 : getSampleValue(destPtr, destTyp, dst16Bits ? index16 : i);
+ int32_t smp1 = (i >= mix8Size) ? 0 : getSampleValue(mixPtr, mixTyp, src16Bits ? index16 : i);
+ int32_t smp2 = (i >= dest8Size) ? 0 : getSampleValue(destPtr, destTyp, dst16Bits ? index16 : i);
- if (!src16Bits) x1 <<= 8;
- if (!dst16Bits) x2 <<= 8;
+ if (!src16Bits) smp1 <<= 8;
+ if (!dst16Bits) smp2 <<= 8;
- smp32 = ((x1 * mixMul1) >> 8) + ((x2 * mixMul2) >> 8);
- CLAMP16(smp32);
-
+ double dSmp = (smp1 * dAmp1) + (smp2 * dAmp2);
if (!dst16Bits)
- smp32 >>= 8;
+ dSmp *= 1.0 / 256.0;
+ // rounding (faster than calling round())
+ if (dSmp < 0.0) dSmp -= 0.5;
+ else if (dSmp > 0.0) dSmp += 0.5;
+
+ int32_t smp32 = (int32_t)dSmp;
+ if (dst16Bits)
+ {
+ CLAMP16(smp32);
+ }
+ else
+ {
+ if (smp32 < -128) smp32 = -128;
+ else if (smp32 > 127) smp32 = 127;
+ }
+
putSampleValue(destPek, destTyp, dst16Bits ? index16 : i, (int16_t)smp32);
}
@@ -1026,6 +1017,8 @@
ui.sysReqShown = false;
return true;
+
+ (void)ptr;
}
static void pbMix(void)
@@ -1256,16 +1249,12 @@
static int32_t SDLCALL applyVolumeThread(void *ptr)
{
-#define AMP_BITS 15
- int8_t *ptr8;
- int16_t *ptr16;
- int32_t amp32, x1, x2, len, i;
- sampleTyp *s;
+ int32_t x1, x2;
if (instr[editor.curInstr] == NULL)
goto applyVolumeExit;
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (smpEd_Rx1 < smpEd_Rx2)
{
@@ -1299,30 +1288,30 @@
x2 >>= 1;
}
- len = x2 - x1;
+ const int32_t len = x2 - x1;
if (len <= 0)
goto applyVolumeExit;
- const double dVol1 = vol_StartVol * ((1 << AMP_BITS) / 100.0);
- const double dVol2 = vol_EndVol * ((1 << AMP_BITS) / 100.0);
+ const double dVol1 = vol_StartVol / 100.0;
+ const double dVol2 = vol_EndVol / 100.0;
+ const double dPosMul = (dVol2 - dVol1) / len;
- /* 8bitbubsy: Rewritten to use 64-bit deltas instead, to
- ** prevent having to do a 64-bit mul for every output sample.
- */
- const int64_t delta64 = (int64_t)round(((dVol2 - dVol1) * (UINT32_MAX+1.0)) / len);
- int64_t pos64 = (int64_t)dVol1 << 32;
-
pauseAudio();
restoreSample(s);
if (s->typ & 16)
{
- ptr16 = (int16_t *)s->pek;
- for (i = x1; i < x2; i++)
+ int16_t *ptr16 = (int16_t *)s->pek + x1;
+ for (int32_t i = 0; i < len; i++)
{
- amp32 = (int32_t)(pos64 >> 32);
- pos64 += delta64;
+ const double dAmp = dVol1 + (i * dPosMul); // linear interpolation
- amp32 = (ptr16[i] * amp32) >> AMP_BITS;
+ double dSmp = ptr16[i] * dAmp;
+
+ // rounding (faster than calling round())
+ if (dSmp < 0.0) dSmp -= 0.5;
+ else if (dSmp > 0.0) dSmp += 0.5;
+
+ int32_t amp32 = (int32_t)dSmp;
CLAMP16(amp32);
ptr16[i] = (int16_t)amp32;
}
@@ -1329,13 +1318,18 @@
}
else
{
- ptr8 = s->pek;
- for (i = x1; i < x2; i++)
+ int8_t *ptr8 = s->pek + x1;
+ for (int32_t i = 0; i < len; i++)
{
- amp32 = (int32_t)(pos64 >> 32);
- pos64 += delta64;
+ const double dAmp = dVol1 + (i * dPosMul); // linear interpolation
- amp32 = (ptr8[i] * amp32) >> AMP_BITS;
+ double dSmp = ptr8[i] * dAmp;
+
+ // rounding (faster than calling round())
+ if (dSmp < 0.0) dSmp -= 0.5;
+ else if (dSmp > 0.0) dSmp += 0.5;
+
+ int32_t amp32 = (int32_t)dSmp;
CLAMP8(amp32);
ptr8[i] = (int8_t)amp32;
}
@@ -1349,8 +1343,9 @@
setMouseBusy(false);
ui.sysReqShown = false;
- (void)ptr;
return true;
+
+ (void)ptr;
}
static void pbApplyVolume(void)
@@ -1374,17 +1369,12 @@
static int32_t SDLCALL getMaxScaleThread(void *ptr)
{
- int8_t *ptr8;
- int16_t *ptr16;
- int32_t vol, absSmp, x1, x2, len, i, maxAmp;
- sampleTyp *s;
+ int32_t x1, x2;
- (void)ptr;
-
if (instr[editor.curInstr] == NULL)
goto getScaleExit;
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
if (smpEd_Rx1 < smpEd_Rx2)
{
@@ -1413,9 +1403,9 @@
x2 = s->len;
}
- len = x2 - x1;
+ uint32_t len = x2 - x1;
if (s->typ & 16)
- len /= 2;
+ len >>= 1;
if (len <= 0)
{
@@ -1426,13 +1416,13 @@
restoreSample(s);
- maxAmp = 0;
+ int32_t maxAmp = 0;
if (s->typ & 16)
{
- ptr16 = (int16_t *)&s->pek[x1];
- for (i = 0; i < len; i++)
+ const int16_t *ptr16 = (const int16_t *)&s->pek[x1];
+ for (uint32_t i = 0; i < len; i++)
{
- absSmp = ABS(ptr16[i]);
+ const int32_t absSmp = ABS(ptr16[i]);
if (absSmp > maxAmp)
maxAmp = absSmp;
}
@@ -1439,10 +1429,10 @@
}
else
{
- ptr8 = &s->pek[x1];
- for (i = 0; i < len; i++)
+ const int8_t *ptr8 = (const int8_t *)&s->pek[x1];
+ for (uint32_t i = 0; i < len; i++)
{
- absSmp = ABS(ptr8[i]);
+ const int32_t absSmp = ABS(ptr8[i]);
if (absSmp > maxAmp)
maxAmp = absSmp;
}
@@ -1459,7 +1449,7 @@
}
else
{
- vol = (100 * 32768) / maxAmp;
+ int32_t vol = (100 * 32768) / maxAmp;
if (vol > 500)
vol = 500;
@@ -1470,6 +1460,8 @@
getScaleExit:
setMouseBusy(false);
return true;
+
+ (void)ptr;
}
static void pbGetMaxScale(void)
--- a/src/ft2_sample_loader.c
+++ b/src/ft2_sample_loader.c
@@ -59,34 +59,28 @@
static int32_t getAIFFRate(uint8_t *in)
{
- int32_t exp;
- uint32_t lo, hi;
- double dOut;
+ int32_t exp = (int32_t)(((in[0] & 0x7F) << 8) | in[1]);
+ uint32_t lo = (in[2] << 24) | (in[3] << 16) | (in[4] << 8) | in[5];
+ uint32_t hi = (in[6] << 24) | (in[7] << 16) | (in[8] << 8) | in[9];
- exp = (int32_t)(((in[0] & 0x7F) << 8) | in[1]);
- lo = (in[2] << 24) | (in[3] << 16) | (in[4] << 8) | in[5];
- hi = (in[6] << 24) | (in[7] << 16) | (in[8] << 8) | in[9];
-
if (exp == 0 && lo == 0 && hi == 0)
return 0;
exp -= 16383;
- dOut = ldexp(lo, -31 + exp) + ldexp(hi, -63 + exp);
- return (int32_t)(dOut + 0.5);
+ double dOut = ldexp(lo, -31 + exp) + ldexp(hi, -63 + exp);
+ return (int32_t)(dOut + 0.5); // rounded
}
static bool aiffIsStereo(FILE *f) // only ran on files that are confirmed to be AIFFs
{
uint16_t numChannels;
- int32_t bytesRead, endOfChunk, filesize;
- uint32_t chunkID, chunkSize, commPtr, commLen;
- uint32_t oldPos;
+ uint32_t chunkID, chunkSize;
- oldPos = ftell(f);
+ uint32_t oldPos = ftell(f);
fseek(f, 0, SEEK_END);
- filesize = ftell(f);
+ int32_t filesize = ftell(f);
if (filesize < 12)
{
@@ -96,15 +90,16 @@
fseek(f, 12, SEEK_SET);
- commPtr = 0; commLen = 0;
+ uint32_t commPtr = 0;
+ uint32_t commLen = 0;
- bytesRead = 0;
+ int32_t bytesRead = 0;
while (!feof(f) && bytesRead < filesize-12)
{
fread(&chunkID, 4, 1, f); chunkID = SWAP32(chunkID); if (feof(f)) break;
fread(&chunkSize, 4, 1, f); chunkSize = SWAP32(chunkSize); if (feof(f)) break;
- endOfChunk = (ftell(f) + chunkSize) + (chunkSize & 1);
+ int32_t endOfChunk = (ftell(f) + chunkSize) + (chunkSize & 1);
switch (chunkID)
{
case 0x434F4D4D: // "COMM"
@@ -137,14 +132,12 @@
static bool wavIsStereo(FILE *f) // only ran on files that are confirmed to be WAVs
{
uint16_t numChannels;
- int32_t bytesRead, endOfChunk, filesize;
- uint32_t chunkID, chunkSize, fmtPtr, fmtLen;
- uint32_t oldPos;
+ uint32_t chunkID, chunkSize;
- oldPos = ftell(f);
+ uint32_t oldPos = ftell(f);
fseek(f, 0, SEEK_END);
- filesize = ftell(f);
+ int32_t filesize = ftell(f);
if (filesize < 12)
{
@@ -154,16 +147,16 @@
fseek(f, 12, SEEK_SET);
- fmtPtr = 0;
- fmtLen = 0;
+ uint32_t fmtPtr = 0;
+ uint32_t fmtLen = 0;
- bytesRead = 0;
+ int32_t bytesRead = 0;
while (!feof(f) && bytesRead < filesize-12)
{
fread(&chunkID, 4, 1, f); if (feof(f)) break;
fread(&chunkSize, 4, 1, f); if (feof(f)) break;
- endOfChunk = (ftell(f) + chunkSize) + (chunkSize & 1);
+ int32_t endOfChunk = (ftell(f) + chunkSize) + (chunkSize & 1);
switch (chunkID)
{
case 0x20746D66: // "fmt "
@@ -195,23 +188,19 @@
static int32_t SDLCALL loadAIFFSample(void *ptr)
{
- char *tmpFilename, *tmpPtr, compType[4];
- int8_t *audioDataS8, *newPtr;
+ char compType[4];
+ int8_t *audioDataS8;
uint8_t sampleRateBytes[10], *audioDataU8;
int16_t *audioDataS16, *audioDataS16_2, smp16;
uint16_t numChannels, bitDepth;
- int32_t j, filesize, smp32, *audioDataS32;
- uint32_t i, filenameLen, sampleRate, sampleLength, blockName, blockSize;
- uint32_t commPtr, commLen, ssndPtr, ssndLen, offset, len32;
+ int32_t j, smp32, *audioDataS32;
+ uint32_t i, blockName, blockSize;
+ uint32_t offset, len32;
int64_t smp64;
- FILE *f;
- UNICHAR *filename;
- sampleTyp tmpSmp, *s;
+ sampleTyp tmpSmp;
- (void)ptr;
-
// this is important for the "goto" on load error
- f = NULL;
+ FILE *f = NULL;
memset(&tmpSmp, 0, sizeof (tmpSmp));
if (editor.tmpFilenameU == NULL)
@@ -220,7 +209,7 @@
goto aiffLoadError;
}
- filename = editor.tmpFilenameU;
+ UNICHAR *filename = editor.tmpFilenameU;
f = UNICHAR_FOPEN(filename, "rb");
if (f == NULL)
@@ -230,7 +219,7 @@
}
fseek(f, 0, SEEK_END);
- filesize = ftell(f);
+ int32_t filesize = ftell(f);
if (filesize < 12)
{
okBoxThreadSafe(0, "System message", "Error loading sample: The sample is not supported or is invalid!");
@@ -239,8 +228,10 @@
// handle chunks
- commPtr = 0; commLen = 0;
- ssndPtr = 0; ssndLen = 0;
+ uint32_t commPtr = 0;
+ uint32_t commLen = 0;
+ uint32_t ssndPtr = 0;
+ uint32_t ssndLen = 0;
fseek(f, 12, SEEK_SET);
while (!feof(f) && ftell(f) < filesize-12)
@@ -315,7 +306,7 @@
}
}
- sampleRate = getAIFFRate(sampleRateBytes);
+ uint32_t sampleRate = getAIFFRate(sampleRateBytes);
// sample data chunk
@@ -332,7 +323,7 @@
ssndLen -= 8; // don't include offset and blockSize datas
- sampleLength = ssndLen;
+ uint32_t sampleLength = ssndLen;
if (sampleLength > MAX_SAMPLE_LEN)
sampleLength = MAX_SAMPLE_LEN;
@@ -647,7 +638,7 @@
}
// adjust memory needed
- newPtr = (int8_t *)realloc(tmpSmp.origPek, sampleLength + LOOP_FIX_LEN);
+ int8_t *newPtr = (int8_t *)realloc(tmpSmp.origPek, sampleLength + LOOP_FIX_LEN);
if (newPtr != NULL)
{
tmpSmp.origPek = newPtr;
@@ -662,7 +653,7 @@
tuneSample(&tmpSmp, sampleRate);
// set sample name
- tmpFilename = unicharToCp437(filename, true);
+ char *tmpFilename = unicharToCp437(filename, true);
if (tmpFilename != NULL)
{
j = (int32_t)strlen(tmpFilename);
@@ -672,13 +663,13 @@
break;
}
- tmpPtr = tmpFilename;
+ char *tmpPtr = tmpFilename;
if (j > 0)
tmpPtr += j + 1;
sanitizeFilename(tmpPtr);
- filenameLen = (uint32_t)strlen(tmpPtr);
+ uint32_t filenameLen = (uint32_t)strlen(tmpPtr);
for (i = 0; i < 22; i++)
{
if (i < filenameLen)
@@ -704,7 +695,7 @@
if (instr[editor.curInstr] != NULL)
{
- s = &instr[editor.curInstr]->samp[sampleSlot];
+ sampleTyp *s = &instr[editor.curInstr]->samp[sampleSlot];
freeSample(editor.curInstr, sampleSlot);
memcpy(s, &tmpSmp, sizeof (sampleTyp));
@@ -734,25 +725,20 @@
sampleIsLoading = false;
return false;
+
+ (void)ptr;
}
static int32_t SDLCALL loadIFFSample(void *ptr)
{
- char *tmpFilename, *tmpPtr, hdr[4 + 1];
- bool is16Bit;
+ char hdr[4+1];
uint8_t i;
- uint16_t sampleRate;
- int32_t j, filesize;
- uint32_t filenameLen, sampleVol, sampleLength, sampleLoopStart, sampleLoopLength, blockName, blockSize;
- uint32_t vhdrPtr, vhdrLen, bodyPtr, bodyLen, namePtr, nameLen;
- FILE *f;
- UNICHAR *filename;
- sampleTyp tmpSmp, *s;
+ int32_t j;
+ uint32_t blockName, blockSize;
+ sampleTyp tmpSmp;
- (void)ptr;
-
// this is important for the "goto" on load error
- f = NULL;
+ FILE *f = NULL;
memset(&tmpSmp, 0, sizeof (tmpSmp));
if (editor.tmpFilenameU == NULL)
@@ -761,7 +747,7 @@
goto iffLoadError;
}
- filename = editor.tmpFilenameU;
+ UNICHAR *filename = editor.tmpFilenameU;
f = UNICHAR_FOPEN(filename, "rb");
if (f == NULL)
@@ -771,7 +757,7 @@
}
fseek(f, 0, SEEK_END);
- filesize = ftell(f);
+ int32_t filesize = ftell(f);
if (filesize < 12)
{
okBoxThreadSafe(0, "System message", "Error loading sample: The sample is not supported or is invalid!");
@@ -781,17 +767,20 @@
fseek(f, 8, SEEK_SET);
fread(hdr, 1, 4, f);
hdr[4] = '\0';
- is16Bit = !strncmp(hdr, "16SV", 4);
+ bool is16Bit = !strncmp(hdr, "16SV", 4);
- sampleLength = 0;
- sampleVol = 64;
- sampleLoopStart = 0;
- sampleLoopLength = 0;
- sampleRate = 16726;
+ uint32_t sampleLength = 0;
+ uint32_t sampleVol = 64;
+ uint32_t sampleLoopStart = 0;
+ uint32_t sampleLoopLength = 0;
+ uint16_t sampleRate = 16726;
- vhdrPtr = 0; vhdrLen = 0;
- bodyPtr = 0; bodyLen = 0;
- namePtr = 0; nameLen = 0;
+ uint32_t vhdrPtr = 0;
+ uint32_t vhdrLen = 0;
+ uint32_t bodyPtr = 0;
+ uint32_t bodyLen = 0;
+ uint32_t namePtr = 0;
+ uint32_t nameLen = 0;
fseek(f, 12, SEEK_SET);
while (!feof(f) && ftell(f) < filesize-12)
@@ -947,7 +936,7 @@
else
{
// set sample name from filename if we didn't load name from .wav
- tmpFilename = unicharToCp437(filename, true);
+ char *tmpFilename = unicharToCp437(filename, true);
if (tmpFilename != NULL)
{
j = (int32_t)strlen(tmpFilename);
@@ -957,13 +946,13 @@
break;
}
- tmpPtr = tmpFilename;
+ char *tmpPtr = tmpFilename;
if (j > 0)
tmpPtr += j + 1;
sanitizeFilename(tmpPtr);
- filenameLen = (uint32_t)strlen(tmpPtr);
+ uint32_t filenameLen = (uint32_t)strlen(tmpPtr);
for (i = 0; i < 22; i++)
{
if (i < filenameLen)
@@ -990,7 +979,7 @@
if (instr[editor.curInstr] != NULL)
{
- s = &instr[editor.curInstr]->samp[sampleSlot];
+ sampleTyp *s = &instr[editor.curInstr]->samp[sampleSlot];
freeSample(editor.curInstr, sampleSlot);
memcpy(s, &tmpSmp, sizeof (sampleTyp));
@@ -1020,21 +1009,18 @@
sampleIsLoading = false;
return false;
+
+ (void)ptr;
}
static int32_t SDLCALL loadRawSample(void *ptr)
{
- char *tmpFilename, *tmpPtr;
int32_t j;
- uint32_t filenameLen, i, filesize;
- FILE *f;
- UNICHAR *filename;
- sampleTyp tmpSmp, *s;
+ uint32_t i;
+ sampleTyp tmpSmp;
- (void)ptr;
-
// this is important for the "goto" on load error
- f = NULL;
+ FILE *f = NULL;
memset(&tmpSmp, 0, sizeof (tmpSmp));
if (editor.tmpFilenameU == NULL)
@@ -1043,7 +1029,7 @@
goto rawLoadError;
}
- filename = editor.tmpFilenameU;
+ UNICHAR *filename = editor.tmpFilenameU;
f = UNICHAR_FOPEN(filename, "rb");
if (f == NULL)
@@ -1053,7 +1039,7 @@
}
fseek(f, 0, SEEK_END);
- filesize = ftell(f);
+ uint32_t filesize = ftell(f);
rewind(f);
if (filesize > MAX_SAMPLE_LEN)
@@ -1085,7 +1071,7 @@
fclose(f);
- tmpFilename = unicharToCp437(filename, true);
+ char *tmpFilename = unicharToCp437(filename, true);
if (tmpFilename != NULL)
{
j = (int32_t)strlen(tmpFilename);
@@ -1095,13 +1081,13 @@
break;
}
- tmpPtr = tmpFilename;
+ char *tmpPtr = tmpFilename;
if (j > 0)
tmpPtr += j + 1;
sanitizeFilename(tmpPtr);
- filenameLen = (uint32_t)strlen(tmpPtr);
+ uint32_t filenameLen = (uint32_t)strlen(tmpPtr);
for (i = 0; i < 22; i++)
{
if (i < filenameLen)
@@ -1129,7 +1115,7 @@
if (instr[editor.curInstr] != NULL)
{
- s = &instr[editor.curInstr]->samp[sampleSlot];
+ sampleTyp *s = &instr[editor.curInstr]->samp[sampleSlot];
freeSample(editor.curInstr, sampleSlot);
memcpy(s, &tmpSmp, sizeof (sampleTyp));
@@ -1159,6 +1145,8 @@
sampleIsLoading = false;
return false;
+
+ (void)ptr;
}
static int32_t SDLCALL loadWAVSample(void *ptr)
@@ -1175,14 +1163,10 @@
int64_t smp64;
float *fAudioDataFloat;
double *dAudioDataDouble;
- FILE *f;
sampleTyp tmpSmp, *s;
- UNICHAR *filename;
- (void)ptr;
-
// this is important for the "goto" on load error
- f = NULL;
+ FILE *f = NULL;
memset(&tmpSmp, 0, sizeof (tmpSmp));
// zero out chunk pointers and lengths
@@ -1198,7 +1182,7 @@
goto wavLoadError;
}
- filename = editor.tmpFilenameU;
+ UNICHAR *filename = editor.tmpFilenameU;
f = UNICHAR_FOPEN(filename, "rb");
if (f == NULL)
@@ -1967,12 +1951,13 @@
sampleIsLoading = false;
return false;
+
+ (void)ptr;
}
bool loadSample(UNICHAR *filenameU, uint8_t smpNr, bool instrFlag)
{
char tmpBuffer[16+1];
- FILE *f;
if (sampleIsLoading)
return false;
@@ -1988,7 +1973,7 @@
return false;
}
- f = UNICHAR_FOPEN(filenameU, "rb");
+ FILE *f = UNICHAR_FOPEN(filenameU, "rb");
if (f == NULL)
{
okBox(0, "System message", "General I/O error during loading! Is the file in use?");
@@ -2109,13 +2094,12 @@
static void normalize32bitSigned(int32_t *sampleData, uint32_t sampleLength)
{
- uint32_t i, sample, sampleVolPeak;
- double dGain;
+ uint32_t i;
- sampleVolPeak = 0;
+ uint32_t sampleVolPeak = 0;
for (i = 0; i < sampleLength; i++)
{
- sample = ABS(sampleData[i]);
+ const uint32_t sample = ABS(sampleData[i]);
if (sampleVolPeak < sample)
sampleVolPeak = sample;
}
@@ -2123,7 +2107,7 @@
if (sampleVolPeak <= 0)
return;
- dGain = (double)INT32_MAX / sampleVolPeak;
+ const double dGain = (double)INT32_MAX / sampleVolPeak;
for (i = 0; i < sampleLength; i++)
sampleData[i] = (int32_t)(sampleData[i] * dGain);
}
@@ -2131,12 +2115,11 @@
static void normalize16bitFloatSigned(float *fSampleData, uint32_t sampleLength)
{
uint32_t i;
- float fSample, fSampleVolPeak, fGain;
- fSampleVolPeak = 0.0f;
+ float fSampleVolPeak = 0.0f;
for (i = 0; i < sampleLength; i++)
{
- fSample = fabsf(fSampleData[i]);
+ const float fSample = fabsf(fSampleData[i]);
if (fSampleVolPeak < fSample)
fSampleVolPeak = fSample;
}
@@ -2144,7 +2127,7 @@
if (fSampleVolPeak <= 0.0f)
return;
- fGain = (float)INT16_MAX / fSampleVolPeak;
+ const float fGain = (float)INT16_MAX / fSampleVolPeak;
for (i = 0; i < sampleLength; i++)
fSampleData[i] *= fGain;
}
@@ -2152,12 +2135,11 @@
static void normalize64bitDoubleSigned(double *dSampleData, uint32_t sampleLength)
{
uint32_t i;
- double dSample, dSampleVolPeak, dGain;
- dSampleVolPeak = 0.0;
+ double dSampleVolPeak = 0.0;
for (i = 0; i < sampleLength; i++)
{
- dSample = fabs(dSampleData[i]);
+ const double dSample = fabs(dSampleData[i]);
if (dSampleVolPeak < dSample)
dSampleVolPeak = dSample;
}
@@ -2165,7 +2147,7 @@
if (dSampleVolPeak <= 0.0)
return;
- dGain = (double)INT16_MAX / dSampleVolPeak;
+ const double dGain = (double)INT16_MAX / dSampleVolPeak;
for (i = 0; i < sampleLength; i++)
dSampleData[i] *= dGain;
}
@@ -2172,8 +2154,7 @@
bool fileIsInstrument(char *fullPath)
{
- char *filename;
- int32_t i, len, extOffset;
+ int32_t i, len;
// this assumes that fullPath is not empty
@@ -2187,7 +2168,7 @@
break;
}
- filename = fullPath;
+ char *filename = fullPath;
if (i > 0)
filename += i + 1;
// --------------------------
@@ -2199,7 +2180,7 @@
if (!_strnicmp("xi.", filename, 3) || (len >= 4 && !_strnicmp("pat.", filename, 4)))
return true;
- extOffset = getExtOffset(filename, len);
+ int32_t extOffset = getExtOffset(filename, len);
if (extOffset != -1)
{
if ((extOffset <= len-4) && !_strnicmp(".pat", &filename[extOffset], 4)) return true;
@@ -2211,8 +2192,7 @@
bool fileIsSample(char *fullPath)
{
- char *filename;
- int32_t i, len, extOffset;
+ int32_t i, len;
// this assumes that fullPath is not empty
@@ -2226,7 +2206,7 @@
break;
}
- filename = fullPath;
+ char *filename = fullPath;
if (i > 0)
filename += i + 1;
// --------------------------
@@ -2243,7 +2223,7 @@
return false; // definitely a module
}
- extOffset = getExtOffset(filename, len);
+ int32_t extOffset = getExtOffset(filename, len);
if (extOffset != -1)
{
if (extOffset <= len-4)
--- a/src/ft2_sample_saver.c
+++ b/src/ft2_sample_saver.c
@@ -509,8 +509,9 @@
if (saveRangeFlag)
UNICHAR_CHDIR(oldPathU);
- (void)ptr;
return true;
+
+ (void)ptr;
}
void saveSample(UNICHAR *filenameU, bool saveAsRange)
--- a/src/ft2_sampling.c
+++ b/src/ft2_sampling.c
@@ -28,17 +28,12 @@
static void SDLCALL samplingCallback(void *userdata, Uint8 *stream, int len)
{
- int8_t *newPtr;
- sampleTyp *s;
-
- (void)userdata;
-
if (instr[editor.curInstr] == NULL || len < 0 || len > samplingBufferBytes)
return;
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
- newPtr = (int8_t *)realloc(s->origPek, (s->len + len) + LOOP_FIX_LEN);
+ int8_t *newPtr = (int8_t *)realloc(s->origPek, (s->len + len) + LOOP_FIX_LEN);
if (newPtr == NULL)
{
drawSamplingBufferFlag = false;
@@ -77,6 +72,8 @@
drawSamplingBufferFlag = true;
}
+
+ (void)userdata;
}
void stopSampling(void)
@@ -84,7 +81,6 @@
int8_t *newPtr;
int16_t *dst16, *src16;
int32_t i, len;
- sampleTyp *currSmp, *nextSmp;
resumeAudio();
mouseAnimOff();
@@ -92,8 +88,8 @@
SDL_CloseAudioDevice(recordDev);
editor.samplingAudioFlag = false;
- currSmp = NULL;
- nextSmp = NULL;
+ sampleTyp *currSmp = NULL;
+ sampleTyp *nextSmp = NULL;
if (instr[editor.curInstr] != NULL)
currSmp = &instr[editor.curInstr]->samp[editor.curSmp];
@@ -161,16 +157,12 @@
static uint8_t getDispBuffPeakMono(const int16_t *smpData, int32_t smpNum)
{
- int16_t smp16;
- uint32_t smpAbs, max;
- int32_t i;
-
- max = 0;
- for (i = 0; i < smpNum; i++)
+ uint32_t max = 0;
+ for (int32_t i = 0; i < smpNum; i++)
{
- smp16 = smpData[i];
+ const int16_t smp16 = smpData[i];
- smpAbs = ABS(smp16);
+ const uint32_t smpAbs = ABS(smp16);
if (smpAbs > max)
max = smpAbs;
}
@@ -184,18 +176,14 @@
static uint8_t getDispBuffPeakLeft(const int16_t *smpData, int32_t smpNum)
{
- int16_t smp16;
- uint32_t smpAbs, max;
- int32_t i;
-
smpNum <<= 1;
- max = 0;
- for (i = 0; i < smpNum; i += 2)
+ uint32_t max = 0;
+ for (int32_t i = 0; i < smpNum; i += 2)
{
- smp16 = smpData[i];
+ const int16_t smp16 = smpData[i];
- smpAbs = ABS(smp16);
+ const uint32_t smpAbs = ABS(smp16);
if (smpAbs > max)
max = smpAbs;
}
@@ -209,18 +197,14 @@
static uint8_t getDispBuffPeakRight(const int16_t *smpData, int32_t smpNum)
{
- int16_t smp16;
- uint32_t smpAbs, max;
- int32_t i;
-
smpNum <<= 1;
- max = 0;
- for (i = 0; i < smpNum; i += 2)
+ uint32_t max = 0;
+ for (int32_t i = 0; i < smpNum; i += 2)
{
- smp16 = smpData[i];
+ const int16_t smp16 = smpData[i];
- smpAbs = ABS(smp16);
+ const uint32_t smpAbs = ABS(smp16);
if (smpAbs > max)
max = smpAbs;
}
@@ -243,9 +227,9 @@
int16_t *readBuf;
uint16_t x;
int32_t smpIdx, smpNum;
- uint32_t *centerPtrL, *centerPtrR, pixVal;
+ uint32_t *centerPtrL, *centerPtrR;
- pixVal = video.palette[PAL_PATTEXT];
+ const uint32_t pixVal = video.palette[PAL_PATTEXT];
// select buffer currently not being written to (double-buffering)
if (currWriteBuf == displayBuffer1)
@@ -352,14 +336,12 @@
okBox(0, "System message", "This program needs to be compiled with SDL 2.0.5 or later to support audio sampling.");
return;
#else
- int16_t result;
SDL_AudioSpec want, have;
- sampleTyp *s, *nextSmp;
if (editor.samplingAudioFlag || editor.curInstr == 0)
return;
- result = okBox(9, "System request", "Stereo sampling will use the next sample slot. While ongoing, press any key to stop.");
+ int16_t result = okBox(9, "System request", "Stereo sampling will use the next sample slot. While ongoing, press any key to stop.");
if (result == 0 || result == 3)
return;
@@ -399,7 +381,7 @@
return;
}
- s = &instr[editor.curInstr]->samp[editor.curSmp];
+ sampleTyp *s = &instr[editor.curInstr]->samp[editor.curSmp];
// wipe current sample and prepare it
freeSample(editor.curInstr, editor.curSmp);
@@ -421,7 +403,7 @@
{
// wipe current sample and prepare it
freeSample(editor.curInstr, rightChSmpSlot);
- nextSmp = &instr[editor.curInstr]->samp[rightChSmpSlot];
+ sampleTyp *nextSmp = &instr[editor.curInstr]->samp[rightChSmpSlot];
strcpy(nextSmp->name, "Right sample");
nextSmp->typ |= 16; // we always sample in 16-bit
--- a/src/ft2_scopes.c
+++ b/src/ft2_scopes.c
@@ -43,20 +43,16 @@
int32_t getSamplePosition(uint8_t ch)
{
- volatile bool active, sampleIs16Bit;
- volatile int32_t pos, end;
- volatile scope_t *sc;
-
if (ch >= song.antChn)
return -1;
- sc = &scope[ch];
+ volatile scope_t *sc = &scope[ch];
// cache some stuff
- active = sc->active;
- pos = sc->pos;
- end = sc->end;
- sampleIs16Bit = sc->sampleIs16Bit;
+ volatile bool active = sc->active;
+ volatile int32_t pos = sc->pos;
+ volatile int32_t end = sc->end;
+ volatile bool sampleIs16Bit = sc->sampleIs16Bit;
if (!active || end == 0)
return -1;
@@ -76,10 +72,11 @@
{
// wait for scopes to finish updating
while (scopesUpdatingFlag);
+
+ volatile scope_t *sc = scope;
+ for (int32_t i = 0; i < MAX_VOICES; i++, sc++)
+ sc->active = false;
- for (uint8_t i = 0; i < MAX_VOICES; i++)
- scope[i].active = false;
-
// wait for scope displaying to be done (safety)
while (scopesDisplayingFlag);
}
@@ -87,10 +84,8 @@
// toggle mute
static void setChannel(int32_t nr, bool on)
{
- stmTyp *ch;
+ stmTyp *ch = &stm[nr];
- ch = &stm[nr];
-
ch->stOff = !on;
if (ch->stOff)
{
@@ -145,20 +140,18 @@
static void redrawScope(int32_t ch)
{
- const uint16_t *scopeLens;
- uint16_t x, y, scopeLen, muteGfxLen, muteGfxX;
- int32_t i, chanLookup, chansPerRow;
+ int32_t i;
- chansPerRow = (uint32_t)song.antChn >> 1;
- chanLookup = chansPerRow - 1;
- scopeLens = scopeLenTab[chanLookup];
+ int32_t chansPerRow = (uint32_t)song.antChn >> 1;
+ int32_t chanLookup = chansPerRow - 1;
+ const uint16_t *scopeLens = scopeLenTab[chanLookup];
// get x,y,len for scope according to channel (we must do it this way since 'len' can differ!)
- x = 2;
- y = 94;
+ uint16_t x = 2;
+ uint16_t y = 94;
- scopeLen = 0; // prevent compiler warning
+ uint16_t scopeLen = 0; // prevent compiler warning
for (i = 0; i < song.antChn; i++)
{
scopeLen = scopeLens[i];
@@ -182,8 +175,8 @@
// draw mute graphics if channel is muted
if (!editor.chnMode[i])
{
- muteGfxLen = scopeMuteBMP_Widths[chanLookup];
- muteGfxX = x + ((scopeLen - muteGfxLen) >> 1);
+ const uint16_t muteGfxLen = scopeMuteBMP_Widths[chanLookup];
+ const uint16_t muteGfxX = x + ((scopeLen - muteGfxLen) >> 1);
blitFastClipX(muteGfxX, y + 6, bmp.scopeMute+scopeMuteBMP_Offs[chanLookup], 162, scopeMuteBMP_Heights[chanLookup], muteGfxLen);
@@ -202,17 +195,16 @@
static void channelMode(int32_t chn)
{
- bool m, m2, test;
int32_t i;
assert(chn < song.antChn);
- m = mouse.leftButtonPressed && !mouse.rightButtonPressed;
- m2 = mouse.rightButtonPressed && mouse.leftButtonPressed;
+ bool m = mouse.leftButtonPressed && !mouse.rightButtonPressed;
+ bool m2 = mouse.rightButtonPressed && mouse.leftButtonPressed;
if (m2)
{
- test = false;
+ bool test = false;
for (i = 0; i < song.antChn; i++)
{
if (i != chn && !editor.chnMode[i])
@@ -264,9 +256,7 @@
bool testScopesMouseDown(void)
{
- uint16_t x;
- const uint16_t *scopeLens;
- int32_t i, chansPerRow, chanToToggle;
+ int32_t i;
if (!ui.scopesShown)
return false;
@@ -276,11 +266,11 @@
if (mouse.y > 130 && mouse.y < 134)
return true;
- chansPerRow = (uint32_t)song.antChn >> 1;
- scopeLens = scopeLenTab[chansPerRow-1];
+ int32_t chansPerRow = (uint32_t)song.antChn >> 1;
+ const uint16_t *scopeLens = scopeLenTab[chansPerRow-1];
// find out if we clicked inside a scope
- x = 3;
+ uint16_t x = 3;
for (i = 0; i < chansPerRow; i++)
{
if (mouse.x >= x && mouse.x < x+scopeLens[i])
@@ -292,7 +282,7 @@
if (i == chansPerRow)
return true; // scope framework was clicked instead
- chanToToggle = i;
+ int32_t chanToToggle = i;
if (mouse.y >= 134) // second row of scopes?
chanToToggle += chansPerRow; // yes, increase lookup offset
@@ -305,20 +295,16 @@
static void scopeTrigger(int32_t ch, const sampleTyp *s, int32_t playOffset)
{
- bool sampleIs16Bit;
- uint8_t loopType;
- int32_t length, loopStart, loopLength, loopEnd;
- volatile scope_t *sc;
scope_t tempState;
- sc = &scope[ch];
+ volatile scope_t *sc = &scope[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;
+ bool sampleIs16Bit = (s->typ >> 4) & 1;
if (sampleIs16Bit)
{
@@ -444,18 +430,13 @@
void drawScopes(void)
{
- int16_t scopeLineY;
- const uint16_t *scopeLens;
- uint16_t scopeXOffs, scopeYOffs, scopeDrawLen;
- int32_t chansPerRow;
-
scopesDisplayingFlag = true;
- chansPerRow = (uint32_t)song.antChn >> 1;
+ int32_t chansPerRow = (uint32_t)song.antChn >> 1;
- scopeLens = scopeLenTab[chansPerRow-1];
- scopeXOffs = 3;
- scopeYOffs = 95;
- scopeLineY = 112;
+ const uint16_t *scopeLens = scopeLenTab[chansPerRow-1];
+ uint16_t scopeXOffs = 3;
+ uint16_t scopeYOffs = 95;
+ int16_t scopeLineY = 112;
for (int32_t i = 0; i < song.antChn; i++)
{
@@ -467,7 +448,7 @@
scopeLineY = 151;
}
- scopeDrawLen = scopeLens[i];
+ const uint16_t scopeDrawLen = scopeLens[i];
if (!editor.chnMode[i]) // scope muted (mute graphics blit()'ed elsewhere)
{
scopeXOffs += scopeDrawLen+3; // align x to next scope
@@ -526,13 +507,11 @@
void handleScopesFromChQueue(chSyncData_t *chSyncData, uint8_t *scopeUpdateStatus)
{
- uint8_t status;
-
volatile scope_t *sc = scope;
syncedChannel_t *ch = chSyncData->channels;
for (int32_t i = 0; i < song.antChn; i++, sc++, ch++)
{
- status = scopeUpdateStatus[i];
+ const uint8_t status = scopeUpdateStatus[i];
if (status & IS_Vol)
sc->vol = (int32_t)((ch->dFinalVol * SCOPE_HEIGHT) + 0.5); // rounded
@@ -631,10 +610,10 @@
bool initScopes(void)
{
- double dInt, dFrac;
+ double dInt;
// calculate scope time for performance counters and split into int/frac
- dFrac = modf(editor.dPerfFreq / SCOPE_HZ, &dInt);
+ double dFrac = modf(editor.dPerfFreq / SCOPE_HZ, &dInt);
// integer part
scopeTimeLen = (int32_t)dInt;
--- a/src/ft2_scrollbars.c
+++ b/src/ft2_scrollbars.c
@@ -110,21 +110,17 @@
void drawScrollBar(uint16_t scrollBarID)
{
- int16_t thumbX, thumbY, thumbW, thumbH;
- scrollBar_t *scrollBar;
-
assert(scrollBarID < NUM_SCROLLBARS);
-
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
if (!scrollBar->visible)
return;
assert(scrollBar->x < SCREEN_W && scrollBar->y < SCREEN_H && scrollBar->w >= 3 && scrollBar->h >= 3);
- thumbX = scrollBar->thumbX;
- thumbY = scrollBar->thumbY;
- thumbW = scrollBar->thumbW;
- thumbH = scrollBar->thumbH;
+ int16_t thumbX = scrollBar->thumbX;
+ int16_t thumbY = scrollBar->thumbY;
+ int16_t thumbW = scrollBar->thumbW;
+ int16_t thumbH = scrollBar->thumbH;
// clear scrollbar background (lazy, but sometimes even faster than filling bg gaps)
clearRect(scrollBar->x, scrollBar->y, scrollBar->w, scrollBar->h);
@@ -178,10 +174,9 @@
int16_t thumbX, thumbY, thumbW, thumbH, scrollEnd, realThumbLength;
int32_t tmp32, length, end;
double dTmp;
- scrollBar_t *scrollBar;
assert(scrollBarID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
assert(scrollBar->page > 0);
@@ -313,10 +308,8 @@
void scrollBarScrollUp(uint16_t scrollBarID, uint32_t amount)
{
- scrollBar_t *scrollBar;
-
assert(scrollBarID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
assert(scrollBar->page > 0 && scrollBar->end > 0);
@@ -337,11 +330,8 @@
void scrollBarScrollDown(uint16_t scrollBarID, uint32_t amount)
{
- uint32_t endPos;
- scrollBar_t *scrollBar;
-
assert(scrollBarID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
assert(scrollBar->page > 0 && scrollBar->end > 0);
@@ -348,7 +338,7 @@
if (scrollBar->end < scrollBar->page)
return;
- endPos = scrollBar->end;
+ uint32_t endPos = scrollBar->end;
if (scrollBar->thumbType == SCROLLBAR_THUMB_FLAT)
{
if (endPos >= scrollBar->page)
@@ -384,14 +374,12 @@
void setScrollBarPos(uint16_t scrollBarID, uint32_t pos, bool triggerCallBack)
{
- uint32_t endPos;
- scrollBar_t *scrollBar;
-
assert(scrollBarID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
if (scrollBar->oldPos == pos)
return;
+
scrollBar->oldPos = pos;
if (scrollBar->page == 0)
@@ -407,7 +395,7 @@
return;
}
- endPos = scrollBar->end;
+ uint32_t endPos = scrollBar->end;
if (scrollBar->thumbType == SCROLLBAR_THUMB_FLAT)
{
if (endPos >= scrollBar->page)
@@ -435,11 +423,8 @@
void setScrollBarEnd(uint16_t scrollBarID, uint32_t end)
{
- uint8_t setPos;
- scrollBar_t *scrollBar;
-
assert(scrollBarID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
if (end < 1)
end = 1;
@@ -446,11 +431,12 @@
if (scrollBar->oldEnd == end)
return;
+
scrollBar->oldEnd = end;
scrollBar->end = end;
- setPos = false;
+ bool setPos = false;
if (scrollBar->pos >= end)
{
scrollBar->pos = end - 1;
@@ -474,10 +460,8 @@
void setScrollBarPageLength(uint16_t scrollBarID, uint32_t pageLength)
{
- scrollBar_t *scrollBar;
-
assert(scrollBarID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[scrollBarID];
+ scrollBar_t *scrollBar = &scrollBars[scrollBarID];
if (pageLength < 1)
pageLength = 1;
@@ -484,6 +468,7 @@
if (scrollBar->oldPage == pageLength)
return;
+
scrollBar->oldPage = pageLength;
scrollBar->page = pageLength;
@@ -500,7 +485,6 @@
uint16_t start, end;
int32_t scrollPos, length;
double dTmp;
- scrollBar_t *scrollBar;
if (ui.sysReqShown)
{
@@ -514,14 +498,17 @@
end = NUM_SCROLLBARS;
}
- for (uint16_t i = start; i < end; i++)
+ const int32_t mx = mouse.x;
+ const int32_t my = mouse.y;
+
+ scrollBar_t *scrollBar = &scrollBars[start];
+ for (uint16_t i = start; i < end; i++, scrollBar++)
{
- scrollBar = &scrollBars[i];
if (!scrollBar->visible)
continue;
- if (mouse.x >= scrollBar->x && mouse.x < scrollBar->x+scrollBar->w &&
- mouse.y >= scrollBar->y && mouse.y < scrollBar->y+scrollBar->h)
+ if (mx >= scrollBar->x && mx < scrollBar->x+scrollBar->w &&
+ my >= scrollBar->y && my < scrollBar->y+scrollBar->h)
{
mouse.lastUsedObjectID = i;
mouse.lastUsedObjectType = OBJECT_SCROLLBAR;
@@ -533,9 +520,9 @@
if (scrollBar->type == SCROLLBAR_HORIZONTAL)
{
- mouse.lastScrollXTmp = mouse.lastScrollX = mouse.x;
+ mouse.lastScrollXTmp = mouse.lastScrollX = mx;
- if (mouse.x >= scrollBar->thumbX && mouse.x < scrollBar->thumbX+scrollBar->thumbW)
+ if (mx >= scrollBar->thumbX && mx < scrollBar->thumbX+scrollBar->thumbW)
{
mouse.saveMouseX = mouse.lastScrollX - scrollBar->thumbX;
}
@@ -565,8 +552,8 @@
}
else
{
- mouse.lastScrollY = mouse.y;
- if (mouse.y >= scrollBar->thumbY && mouse.y < scrollBar->thumbY+scrollBar->thumbH)
+ mouse.lastScrollY = my;
+ if (my >= scrollBar->thumbY && my < scrollBar->thumbY+scrollBar->thumbH)
{
mouse.saveMouseY = mouse.lastScrollY - scrollBar->thumbY;
}
@@ -607,14 +594,12 @@
void testScrollBarMouseRelease(void)
{
- scrollBar_t *scrollBar;
-
if (mouse.lastUsedObjectType != OBJECT_SCROLLBAR || mouse.lastUsedObjectID == OBJECT_ID_NONE)
return;
assert(mouse.lastUsedObjectID < NUM_SCROLLBARS);
+ scrollBar_t *scrollBar = &scrollBars[mouse.lastUsedObjectID];
- scrollBar = &scrollBars[mouse.lastUsedObjectID];
if (scrollBar->visible)
{
scrollBar->state = SCROLLBAR_UNPRESSED;
@@ -626,10 +611,9 @@
{
int32_t scrollX, scrollY, length;
double dTmp;
- scrollBar_t *scrollBar;
assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_SCROLLBARS);
- scrollBar = &scrollBars[mouse.lastUsedObjectID];
+ scrollBar_t *scrollBar = &scrollBars[mouse.lastUsedObjectID];
if (!scrollBar->visible)
return;
@@ -691,11 +675,12 @@
void initializeScrollBars(void)
{
- for (int32_t i = 0; i < NUM_SCROLLBARS; i++)
+ scrollBar_t *scrollBar = scrollBars;
+ for (int32_t i = 0; i < NUM_SCROLLBARS; i++, scrollBar++)
{
- scrollBars[i].oldEnd = UINT32_MAX;
- scrollBars[i].oldPage = UINT32_MAX;
- scrollBars[i].oldPos = UINT32_MAX;
+ scrollBar->oldEnd = UINT32_MAX;
+ scrollBar->oldPage = UINT32_MAX;
+ scrollBar->oldPos = UINT32_MAX;
}
// pattern editor
--- a/src/ft2_sysreqs.c
+++ b/src/ft2_sysreqs.c
@@ -77,11 +77,9 @@
static void drawWindow(uint16_t w)
{
const uint16_t h = SYSTEM_REQUEST_H;
- uint16_t x, y;
+ const uint16_t x = (SCREEN_W - w) >> 1;
+ const uint16_t y = ui.extended ? 91 : SYSTEM_REQUEST_Y;
- x = (SCREEN_W - w) >> 1;
- y = ui.extended ? 91 : SYSTEM_REQUEST_Y;
-
// main fill
fillRect(x + 1, y + 1, w - 2, h - 2, PAL_BUTTONS);
@@ -159,11 +157,9 @@
{
#define PUSHBUTTON_W 80
- int16_t returnVal, oldLastUsedObjectID, oldLastUsedObjectType;
- uint16_t x, y, i, tlen, hlen, wlen, tx, knp, headlineX, textX;
+ uint16_t i;
SDL_Event inputEvent;
pushButton_t *p;
- checkBox_t *c;
if (editor.editTextFlag)
exitTextEditing();
@@ -180,22 +176,22 @@
ui.sysReqShown = true;
mouseAnimOff();
- oldLastUsedObjectID = mouse.lastUsedObjectID;
- oldLastUsedObjectType = mouse.lastUsedObjectType;
+ int16_t oldLastUsedObjectID = mouse.lastUsedObjectID;
+ int16_t oldLastUsedObjectType = mouse.lastUsedObjectType;
// count number of buttons
- knp = 0;
+ uint16_t knp = 0;
while (buttonText[typ][knp][0] != '\0' && knp < 5)
knp++;
- tlen = textWidth(text);
- hlen = textWidth(headline);
+ uint16_t tlen = textWidth(text);
+ uint16_t hlen = textWidth(headline);
- wlen = tlen;
+ uint16_t wlen = tlen;
if (hlen > tlen)
wlen = hlen;
- tx = (knp * 100) - 20;
+ uint16_t tx = (knp * 100) - 20;
if (tx > wlen)
wlen = tx;
@@ -203,12 +199,12 @@
if (wlen > 600)
wlen = 600;
- headlineX = (SCREEN_W - hlen) >> 1;
- textX = (SCREEN_W - tlen) >> 1;
- x = (SCREEN_W - wlen) >> 1;
+ uint16_t headlineX = (SCREEN_W - hlen) >> 1;
+ uint16_t textX = (SCREEN_W - tlen) >> 1;
+ uint16_t x = (SCREEN_W - wlen) >> 1;
// the box y position differs in extended pattern editor mode
- y = ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y;
+ uint16_t y = ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y;
// set up buttons
for (i = 0; i < knp; i++)
@@ -226,7 +222,7 @@
// set up checkbox (special okBox types only!)
if (typ >= 6 && typ <= 7)
{
- c = &checkBoxes[0];
+ checkBox_t *c = &checkBoxes[0];
c->x = x + 5;
c->y = y + 50;
c->clickAreaWidth = 116;
@@ -253,7 +249,7 @@
mouse.rightButtonPressed = 0;
// input/rendering loop
- returnVal = 0;
+ int16_t returnVal = 0;
while (ui.sysReqShown)
{
beginFPSCounter();
@@ -368,12 +364,8 @@
#define PUSHBUTTON_W 80
#define TEXTBOX_W 250
- char *inputText;
- int16_t returnVal, oldLastUsedObjectID, oldLastUsedObjectType;
- uint16_t y, wlen, tx, knp, headlineX, i;
+ uint16_t wlen, i;
SDL_Event inputEvent;
- pushButton_t *p;
- textBox_t *t;
if (editor.editTextFlag)
exitTextEditing();
@@ -385,10 +377,10 @@
if (ui.sysReqShown)
return 0;
- oldLastUsedObjectID = mouse.lastUsedObjectID;
- oldLastUsedObjectType = mouse.lastUsedObjectType;
+ int16_t oldLastUsedObjectID = mouse.lastUsedObjectID;
+ int16_t oldLastUsedObjectType = mouse.lastUsedObjectType;
- t = &textBoxes[0];
+ textBox_t *t = &textBoxes[0];
// set up text box
memset(t, 0, sizeof (textBox_t));
@@ -416,14 +408,14 @@
mouseAnimOff();
wlen = textWidth(headline);
- headlineX = (SCREEN_W - wlen) >> 1;
+ uint16_t headlineX = (SCREEN_W - wlen) >> 1;
// count number of buttons
- knp = 0;
+ uint16_t knp = 0;
while (buttonText[typ][knp][0] != '\0' && knp < 5)
knp++;
- tx = TEXTBOX_W;
+ uint16_t tx = TEXTBOX_W;
if (tx > wlen)
wlen = tx;
@@ -436,7 +428,7 @@
wlen = 600;
// the box y position differs in extended pattern editor mode
- y = ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y;
+ uint16_t y = ui.extended ? SYSTEM_REQUEST_Y_EXT : SYSTEM_REQUEST_Y;
// set further text box settings
t->x = (SCREEN_W - TEXTBOX_W) >> 1;
@@ -444,10 +436,10 @@
t->visible = true;
// setup buttons
- for (i = 0; i < knp; i++)
- {
- p = &pushButtons[i];
+ pushButton_t *p = pushButtons;
+ for (i = 0; i < knp; i++, p++)
+ {
p->w = PUSHBUTTON_W;
p->h = 16;
p->x = ((SCREEN_W - tx) >> 1) + (i * 100);
@@ -469,7 +461,7 @@
mouse.rightButtonPressed = 0;
// input/rendering loop
- returnVal = 0;
+ int16_t returnVal = 0;
while (ui.sysReqShown)
{
beginFPSCounter();
@@ -497,7 +489,7 @@
continue;
}
- inputText = utf8ToCp437(inputEvent.text.text, false);
+ char *inputText = utf8ToCp437(inputEvent.text.text, false);
if (inputText != NULL)
{
if (inputText[0] != '\0')
--- a/src/ft2_tables.c
+++ b/src/ft2_tables.c
@@ -458,6 +458,9 @@
}
};
+const int8_t maxVisibleChans1[4] = { 4, 6, 8, 8 };
+const int8_t maxVisibleChans2[4] = { 4, 6, 8, 12 };
+
const uint16_t chanWidths[6] = { 141, 141, 93, 69, 45, 45 };
const pattCoordsMouse_t pattCoordMouseTable[2][2][2] =
--- a/src/ft2_tables.h
+++ b/src/ft2_tables.h
@@ -23,6 +23,8 @@
extern const uint8_t font1Widths[128];
extern const uint8_t font2Widths[128];
extern pal16 palTable[12][16];
+extern const int8_t maxVisibleChans1[4];
+extern const int8_t maxVisibleChans2[4];
extern const uint16_t chanWidths[6];
extern const pattCoordsMouse_t pattCoordMouseTable[2][2][2];
extern const uint8_t noteTab1[96];
--- a/src/ft2_textboxes.c
+++ b/src/ft2_textboxes.c
@@ -132,24 +132,21 @@
static void deleteMarkedText(textBox_t *t)
{
- int16_t start, end;
- int32_t i, deleteTextWidth, length;
-
if (!textIsMarked())
return;
- start = getTextMarkStart();
- end = getTextMarkEnd();
+ const int16_t start = getTextMarkStart();
+ const int16_t end = getTextMarkEnd();
assert(start < t->maxChars && end <= t->maxChars);
// calculate pixel width of string to delete
- deleteTextWidth = 0;
- for (i = start; i < end; i++)
+ int32_t deleteTextWidth = 0;
+ for (int32_t i = start; i < end; i++)
deleteTextWidth += charWidth(t->textPtr[i]);
// copy markEnd part to markStart, and add null termination
- length = (int32_t)strlen(&t->textPtr[end]);
+ const int32_t length = (int32_t)strlen(&t->textPtr[end]);
if (length > 0)
memcpy(&t->textPtr[start], &t->textPtr[end], length);
t->textPtr[start+length] = '\0';
@@ -168,21 +165,17 @@
static void setCursorToMarkStart(textBox_t *t)
{
- char ch;
- int16_t start;
- int32_t startXPos;
-
if (!textIsMarked())
return;
- start = getTextMarkStart();
+ const int16_t start = getTextMarkStart();
assert(start < t->maxChars);
t->cursorPos = start;
- startXPos = 0;
+ int32_t startXPos = 0;
for (int32_t i = 0; i < start; i++)
{
- ch = t->textPtr[i];
+ const char ch = t->textPtr[i];
if (ch == '\0')
break;
@@ -196,21 +189,17 @@
static void setCursorToMarkEnd(textBox_t *t)
{
- char ch;
- int16_t end;
- int32_t endXPos;
-
if (!textIsMarked())
return;
- end = getTextMarkEnd();
+ const int16_t end = getTextMarkEnd();
assert(end <= t->maxChars);
t->cursorPos = end;
- endXPos = 0;
+ int32_t endXPos = 0;
for (int32_t i = 0; i < end; i++)
{
- ch = t->textPtr[i];
+ const char ch = t->textPtr[i];
if (ch == '\0')
break;
@@ -224,30 +213,27 @@
static void copyMarkedText(textBox_t *t)
{
- int32_t length, start, end;
- char *utf8Text, oldChar;
-
if (!textIsMarked())
return;
- start = getTextMarkStart();
- end = getTextMarkEnd();
+ const int32_t start = getTextMarkStart();
+ const int32_t end = getTextMarkEnd();
assert(start < t->maxChars && end <= t->maxChars);
- length = end - start;
+ const int32_t length = end - start;
if (length < 1)
return;
/* Change mark-end character to NUL so that we
- * we only copy the marked section of the string.
- * There's always room for a NUL at the end of
- * the text box string, so this is safe.
- */
- oldChar = t->textPtr[end];
+ ** we only copy the marked section of the string.
+ ** There's always room for a NUL at the end of
+ ** the text box string, so this is safe.
+ **/
+ const char oldChar = t->textPtr[end];
t->textPtr[end] = '\0';
- utf8Text = cp437ToUtf8(&t->textPtr[start]);
+ char *utf8Text = cp437ToUtf8(&t->textPtr[start]);
if (utf8Text != NULL)
{
SDL_SetClipboardText(utf8Text);
@@ -271,9 +257,7 @@
static void pasteText(textBox_t *t)
{
- char *copiedText, *copiedTextUtf8, *endPart;
- uint16_t endOffset;
- int32_t textLength, roomLeft, copiedTextLength, endPartLength;
+ char *endPart;
if (!SDL_HasClipboardText())
return;
@@ -288,29 +272,29 @@
if (t->cursorPos >= t->maxChars)
return;
- textLength = getTextLength(t, 0);
+ const int32_t textLength = getTextLength(t, 0);
- roomLeft = t->maxChars - textLength;
+ const int32_t roomLeft = t->maxChars - textLength;
if (roomLeft <= 0)
return; // no more room!
- copiedTextUtf8 = SDL_GetClipboardText();
+ char *copiedTextUtf8 = SDL_GetClipboardText();
- copiedText = utf8ToCp437(copiedTextUtf8, true);
+ char *copiedText = utf8ToCp437(copiedTextUtf8, true);
if (copiedText == NULL)
return;
- copiedTextLength = (int32_t)strlen(copiedText);
+ int32_t copiedTextLength = (int32_t)strlen(copiedText);
if (copiedTextLength > roomLeft)
copiedTextLength = roomLeft;
- endOffset = t->cursorPos;
+ const uint16_t endOffset = t->cursorPos;
endPart = NULL; // prevent false compiler warning
- endPartLength = getTextLength(t, endOffset);
+ const int32_t endPartLength = getTextLength(t, endOffset);
if (endPartLength > 0)
{
- endPart = (char *)malloc(endPartLength + 1);
+ endPart = (char *)malloc(endPartLength+1);
if (endPart == NULL)
{
free(copiedText);
@@ -373,11 +357,9 @@
static int16_t cursorPosToX(textBox_t *t)
{
- int32_t x;
-
assert(t->textPtr != NULL);
- x = -1; // cursor starts one pixel before character
+ int32_t x = -1; // cursor starts one pixel before character
for (int16_t i = 0; i < t->cursorPos; i++)
x += charWidth(t->textPtr[i]);
@@ -405,12 +387,10 @@
static void scrollTextBufferRight(textBox_t *t, uint16_t numCharsInText)
{
- int32_t textEnd;
-
assert(numCharsInText <= t->maxChars);
// get end of text position
- textEnd = 0;
+ int32_t textEnd = 0;
for (uint16_t j = 0; j < numCharsInText; j++)
textEnd += charWidth(t->textPtr[j]);
@@ -427,12 +407,9 @@
static void moveTextCursorToMouseX(uint16_t textBoxID)
{
- int8_t cw;
- int16_t i, numChars, cursorPos;
- int32_t mx, tx, tx2;
- textBox_t *t;
+ int16_t i;
- t = &textBoxes[textBoxID];
+ textBox_t *t = &textBoxes[textBoxID];
if ((mouse.x == t->x && t->bufOffset == 0) || t->textPtr == NULL || t->textPtr[0] == '\0')
{
t->cursorPos = 0;
@@ -439,17 +416,17 @@
return;
}
- numChars = getTextLength(t, 0);
+ int16_t numChars = getTextLength(t, 0);
// find out what character we are clicking at, and set cursor to that character
- mx = t->bufOffset + mouse.x;
- tx = (t->x + t->tx) - 1;
- cw = -1;
+ const int32_t mx = t->bufOffset + mouse.x;
+ int32_t tx = (t->x + t->tx) - 1;
+ int32_t cw = -1;
for (i = 0; i < numChars; i++)
{
cw = charWidth(t->textPtr[i]);
- tx2 = tx + cw;
+ const int32_t tx2 = tx + cw;
if (mx >= tx && mx < tx2)
{
@@ -466,7 +443,7 @@
if (cw != -1)
{
- cursorPos = cursorPosToX(t);
+ const int16_t cursorPos = cursorPosToX(t);
// scroll buffer to the right if needed
if (cursorPos+cw > t->renderW)
@@ -482,26 +459,21 @@
static void textOutBuf(uint8_t *dstBuffer, uint32_t dstWidth, uint8_t paletteIndex, char *text, uint32_t maxTextLen)
{
- char chr;
- uint8_t *dstPtr;
- const uint8_t *srcPtr;
- uint16_t currX;
-
assert(text != NULL);
if (*text == '\0')
return; // empty string
- currX = 0;
+ uint16_t currX = 0;
for (uint32_t i = 0; i < maxTextLen; i++)
{
- chr = *text++ & 0x7F;
+ const char chr = *text++ & 0x7F;
if (chr == '\0')
break;
if (chr != ' ')
{
- srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
- dstPtr = &dstBuffer[currX];
+ const uint8_t *srcPtr = &bmp.font1[chr * FONT1_CHAR_W];
+ uint8_t *dstPtr = &dstBuffer[currX];
for (uint32_t y = 0; y < FONT1_CHAR_H; y++)
{
@@ -523,14 +495,11 @@
// a lot of filling here, but textboxes are small so no problem...
void drawTextBox(uint16_t textBoxID)
{
- char ch;
int8_t cw;
uint8_t pal;
- int32_t start, end, x1, x2, length;
- textBox_t *t;
assert(textBoxID < NUM_TEXTBOXES);
- t = &textBoxes[textBoxID];
+ textBox_t *t = &textBoxes[textBoxID];
if (!t->visible)
return;
@@ -551,17 +520,19 @@
{
hideSprite(SPRITE_TEXT_CURSOR);
- start = getTextMarkStart();
- end = getTextMarkEnd();
+ int32_t start = getTextMarkStart();
+ int32_t end = getTextMarkEnd();
assert(start < t->maxChars && end <= t->maxChars);
// find pixel start/length from markX1 and markX2
- x1 = 0; x2 = 0;
+ int32_t x1 = 0;
+ int32_t x2 = 0;
+
for (int32_t i = 0; i < end; i++)
{
- ch = t->textPtr[i];
+ const char ch = t->textPtr[i];
if (ch == '\0')
break;
@@ -576,11 +547,13 @@
if (x1 != x2)
{
start = x1;
- length = x2 - x1;
+ const int32_t length = x2 - x1;
assert(start+length <= t->renderBufW);
- for (uint16_t y = 0; y < t->renderBufH; y++)
- memset(&t->renderBuf[(y * t->renderBufW) + start], PAL_TEXTMRK, length);
+
+ uint8_t *ptr32 = &t->renderBuf[start];
+ for (uint16_t y = 0; y < t->renderBufH; y++, ptr32 += t->renderBufW)
+ memset(ptr32, PAL_TEXTMRK, length);
}
}
@@ -610,9 +583,7 @@
static void setMarkX2ToMouseX(textBox_t *t)
{
- int8_t cw;
- int16_t i, numChars;
- int32_t mx, tx, tx2;
+ int16_t i;
if (t->textPtr == NULL || t->textPtr[0] == '\0')
{
@@ -626,16 +597,16 @@
return;
}
- numChars = getTextLength(t, 0);
+ const int16_t numChars = getTextLength(t, 0);
// find out what character we are clicking at, and set markX2 to that character
- mx = t->bufOffset + mouse.x;
- tx = (t->x + t->tx) - 1;
+ const int32_t mx = t->bufOffset + mouse.x;
+ int32_t tx = (t->x + t->tx) - 1;
for (i = 0; i < numChars; i++)
{
- cw = charWidth(t->textPtr[i]);
- tx2 = tx + cw;
+ const int32_t cw = charWidth(t->textPtr[i]);
+ const int32_t tx2 = tx + cw;
if (mx >= tx && mx < tx2)
{
@@ -674,10 +645,8 @@
void handleTextBoxWhileMouseDown(void)
{
- textBox_t *t;
-
assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_TEXTBOXES);
- t = &textBoxes[mouse.lastUsedObjectID];
+ textBox_t *t = &textBoxes[mouse.lastUsedObjectID];
if (!t->visible)
return;
@@ -695,7 +664,6 @@
bool testTextBoxMouseDown(void)
{
uint16_t start, end;
- textBox_t *t;
oldMouseX = mouse.x;
oldCursorPos = 0;
@@ -712,14 +680,17 @@
end = NUM_TEXTBOXES;
}
- for (uint16_t i = start; i < end; i++)
+ const int32_t mx = mouse.x;
+ const int32_t my = mouse.y;
+
+ textBox_t *t = &textBoxes[start];
+ for (uint16_t i = start; i < end; i++, t++)
{
- t = &textBoxes[i];
if (!t->visible || t->textPtr == NULL)
continue;
- if (mouse.y >= t->y && mouse.y < t->y+t->h &&
- mouse.x >= t->x && mouse.x < t->x+t->w)
+ if (my >= t->y && my < t->y+t->h &&
+ mx >= t->x && mx < t->x+t->w)
{
if (!mouse.rightButtonPressed && t->rightMouseButton)
break;
@@ -755,7 +726,7 @@
void updateTextBoxPointers(void)
{
- uint8_t i;
+ int32_t i;
instrTyp *curIns = instr[editor.curInstr];
// instrument names
@@ -789,15 +760,13 @@
void setTextCursorToEnd(textBox_t *t)
{
- char ch;
uint16_t numChars;
- uint32_t textWidth;
// count number of chars and get full text width
- textWidth = 0;
+ uint32_t textWidth = 0;
for (numChars = 0; numChars < t->maxChars; numChars++)
{
- ch = t->textPtr[numChars];
+ const char ch = t->textPtr[numChars];
if (ch == '\0')
break;
@@ -836,11 +805,10 @@
uint16_t numChars;
int32_t textLength;
uint32_t textWidth;
- textBox_t *t;
assert(mouse.lastEditBox >= 0 && mouse.lastEditBox < NUM_TEXTBOXES);
- t = &textBoxes[mouse.lastEditBox];
+ textBox_t *t = &textBoxes[mouse.lastEditBox];
assert(t->textPtr != NULL);
switch (keycode)
@@ -1123,17 +1091,13 @@
void handleTextEditInputChar(char textChar)
{
- int8_t ch;
- int16_t i;
- textBox_t *t;
-
assert(mouse.lastEditBox >= 0 && mouse.lastEditBox < NUM_TEXTBOXES);
- t = &textBoxes[mouse.lastEditBox];
+ textBox_t *t = &textBoxes[mouse.lastEditBox];
if (t->textPtr == NULL)
return;
- ch = (int8_t)textChar;
+ const int8_t ch = (const int8_t)textChar;
if (ch < 32 && ch != -124 && ch != -108 && ch != -122 && ch != -114 && ch != -103 && ch != -113)
return; // allow certain codepage 437 nordic characters
@@ -1145,7 +1109,7 @@
if (t->cursorPos >= 0 && t->cursorPos < t->maxChars)
{
- i = getTextLength(t, 0);
+ int32_t i = getTextLength(t, 0);
if (i < t->maxChars) // do we have room for a new character?
{
t->textPtr[i+1] = '\0';
@@ -1167,9 +1131,7 @@
static void moveTextCursorLeft(int16_t i, bool updateTextBox)
{
- textBox_t *t;
-
- t = &textBoxes[i];
+ textBox_t *t = &textBoxes[i];
if (t->cursorPos == 0)
return;
@@ -1187,12 +1149,9 @@
static void moveTextCursorRight(int16_t i, bool updateTextBox)
{
- uint16_t numChars;
- textBox_t *t;
+ textBox_t *t = &textBoxes[i];
- t = &textBoxes[i];
-
- numChars = getTextLength(t, 0);
+ const uint16_t numChars = getTextLength(t, 0);
if (t->cursorPos >= numChars)
return;
@@ -1210,12 +1169,10 @@
void freeTextBoxes(void)
{
- textBox_t *t;
-
// free text box buffers (skip first entry, it's reserved for inputBox())
- for (int32_t i = 1; i < NUM_TEXTBOXES; i++)
+ textBox_t *t = &textBoxes[1];
+ for (int32_t i = 1; i < NUM_TEXTBOXES; i++, t++)
{
- t = &textBoxes[i];
if (t->renderBuf != NULL)
{
free(t->renderBuf);
--- a/src/ft2_trim.c
+++ b/src/ft2_trim.c
@@ -68,19 +68,16 @@
static void remapInstrInSong(uint8_t src, uint8_t dst, int32_t ap)
{
- int32_t readLen;
- tonTyp *pattPtr, *note;
-
for (int32_t i = 0; i < ap; i++)
{
- pattPtr = patt[i];
+ tonTyp *pattPtr = patt[i];
if (pattPtr == NULL)
continue;
- readLen = pattLens[i] * MAX_VOICES;
+ const int32_t readLen = pattLens[i] * MAX_VOICES;
for (int32_t j = 0; j < readLen; j++)
{
- note = &pattPtr[j];
+ tonTyp *note = &pattPtr[j];
if (note->instr == src)
note->instr = dst;
}
@@ -89,15 +86,12 @@
static int16_t getUsedTempSamples(uint16_t nr)
{
- int16_t i, j;
- instrTyp *ins;
-
if (tmpInstr[nr] == NULL)
return 0;
- ins = tmpInstr[nr];
+ instrTyp *ins = tmpInstr[nr];
- i = 16 - 1;
+ int16_t i = 16 - 1;
while (i >= 0 && ins->samp[i].pek == NULL && ins->samp[i].name[0] == '\0')
i--;
@@ -104,7 +98,7 @@
/* Yes, 'i' can be -1 here, and will be set to at least 0
** because of ins->ta values. Possibly an FT2 bug...
**/
- for (j = 0; j < 96; j++)
+ for (int16_t j = 0; j < 96; j++)
{
if (ins->ta[j] > i)
i = ins->ta[j];
@@ -115,15 +109,13 @@
static int64_t getTempInsAndSmpSize(void)
{
- int16_t a, j, ai;
- int64_t currSize64;
- instrTyp *ins;
+ int16_t j;
- ai = MAX_INST;
+ int16_t ai = MAX_INST;
while (ai > 0 && getUsedTempSamples(ai) == 0 && tmpInstrName[ai][0] == '\0')
ai--;
- currSize64 = 0;
+ int64_t currSize64 = 0;
// count instrument and sample data size in song
for (int16_t i = 1; i <= ai; i++)
@@ -133,13 +125,13 @@
else
j = i;
- a = getUsedTempSamples(i);
+ const int16_t a = getUsedTempSamples(i);
if (a > 0)
currSize64 += INSTR_HEADER_SIZE + (a * sizeof (sampleHeaderTyp));
else
currSize64 += 22+11;
- ins = tmpInstr[j];
+ instrTyp *ins = tmpInstr[j];
for (int16_t k = 0; k < a; k++)
{
if (ins->samp[k].pek != NULL)
@@ -153,11 +145,11 @@
static void wipeInstrUnused(bool testWipeSize, int16_t *ai, int32_t ap, int32_t antChn)
{
uint8_t newInst;
- int16_t newNumInsts, instToDel, pattLen;
- int32_t numInsts, i, j, k;
+ int16_t pattLen;
+ int32_t i, j, k;
tonTyp *pattPtr;
- numInsts = *ai;
+ int32_t numInsts = *ai;
// calculate what instruments are used
memset(instrUsed, 0, numInsts);
@@ -188,9 +180,9 @@
}
}
- instToDel = 0;
+ int16_t instToDel = 0;
newInst = 0;
- newNumInsts = 0;
+ int16_t newNumInsts = 0;
memset(instrOrder, 0, numInsts);
for (i = 0; i < numInsts; i++)
@@ -278,13 +270,13 @@
static void wipePattsUnused(bool testWipeSize, int16_t *ap)
{
uint8_t newPatt;
- int16_t usedPatts, newUsedPatts, i, *pLens;
+ int16_t i, *pLens;
tonTyp **p;
- usedPatts = *ap;
+ int16_t usedPatts = *ap;
memset(pattUsed, 0, usedPatts);
- newUsedPatts = 0;
+ int16_t newUsedPatts = 0;
for (i = 0; i < song.len; i++)
{
newPatt = song.songTab[i];
@@ -366,12 +358,12 @@
static void wipeSamplesUnused(bool testWipeSize, int16_t ai)
{
- uint8_t newSamp, smpUsed[16], smpOrder[16];
- int16_t i, j, k, l;
+ uint8_t smpUsed[16], smpOrder[16];
+ int16_t j, k, l;
instrTyp *ins;
- sampleTyp *s, tempSamples[16];
+ sampleTyp tempSamples[16];
- for (i = 1; i <= ai; i++)
+ for (int16_t i = 1; i <= ai; i++)
{
if (!testWipeSize)
{
@@ -397,10 +389,9 @@
memset(smpUsed, 0, l);
if (l > 0)
{
- for (j = 0; j < l; j++)
+ sampleTyp *s = ins->samp;
+ for (j = 0; j < l; j++, s++)
{
- s = &ins->samp[j];
-
// check if sample is referenced in instrument
for (k = 0; k < 96; k++)
{
@@ -425,7 +416,7 @@
}
// create re-order list
- newSamp = 0;
+ uint8_t newSamp = 0;
memset(smpOrder, 0, l);
for (j = 0; j < l; j++)
{
@@ -459,10 +450,8 @@
static void wipeSmpDataAfterLoop(bool testWipeSize, int16_t ai)
{
- int8_t *newPtr;
int16_t l;
instrTyp *ins;
- sampleTyp *s;
for (int16_t i = 1; i <= ai; i++)
{
@@ -487,9 +476,9 @@
l = getUsedTempSamples(i);
}
- for (int16_t j = 0; j < l; j++)
+ sampleTyp *s = ins->samp;
+ for (int16_t j = 0; j < l; j++, s++)
{
- s = &ins->samp[j];
if (s->origPek != NULL && s->typ & 3 && s->len > 0 && s->len > s->repS+s->repL)
{
if (!testWipeSize)
@@ -508,7 +497,7 @@
}
else
{
- 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;
@@ -526,11 +515,8 @@
static void convertSamplesTo8bit(bool testWipeSize, int16_t ai)
{
- int8_t *dst8, smp8, *newPtr;
- int16_t *src16, k;
- int32_t newLen;
+ int16_t k;
instrTyp *ins;
- sampleTyp *s;
for (int16_t i = 1; i <= ai; i++)
{
@@ -555,9 +541,9 @@
k = getUsedTempSamples(i);
}
- for (int16_t j = 0; j < k; j++)
+ sampleTyp *s = ins->samp;
+ for (int16_t j = 0; j < k; j++, s++)
{
- s = &ins->samp[j];
if (s->origPek != NULL && (s->typ & 16) && s->len > 0)
{
if (testWipeSize)
@@ -572,15 +558,12 @@
restoreSample(s);
assert(s->pek != NULL);
- src16 = (int16_t *)s->pek;
- dst8 = s->pek;
+ const int16_t *src16 = (const int16_t *)s->pek;
+ int8_t *dst8 = s->pek;
- newLen = s->len >> 1;
+ const int32_t newLen = s->len >> 1;
for (int32_t a = 0; a < newLen; a++)
- {
- smp8 = src16[a] >> 8;
- dst8[a] = smp8;
- }
+ dst8[a] = src16[a] >> 8;
s->repL >>= 1;
s->repS >>= 1;
@@ -587,7 +570,7 @@
s->len >>= 1;
s->typ &= ~16;
- 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;
@@ -603,14 +586,12 @@
static uint16_t getPackedPattSize(tonTyp *pattern, int32_t numRows, int32_t antChn)
{
- uint8_t bytes[sizeof (tonTyp)], packBits, *writePtr, *firstBytePtr, *pattPtr;
- uint16_t totalPackLen;
+ uint8_t bytes[sizeof (tonTyp)];
- totalPackLen = 0;
+ uint16_t totalPackLen = 0;
+ uint8_t *pattPtr = (uint8_t *)pattern;
+ uint8_t *writePtr = pattPtr;
- pattPtr = (uint8_t *)pattern;
-
- writePtr = pattPtr;
for (int32_t row = 0; row < numRows; row++)
{
for (int32_t chn = 0; chn < antChn; chn++)
@@ -621,9 +602,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++; } // note
if (bytes[1] > 0) { packBits |= 2; writePtr++; } // instrument
if (bytes[2] > 0) { packBits |= 4; writePtr++; } // volume column
@@ -634,7 +615,6 @@
// no packing needed, write pattern data as is
totalPackLen += 5;
writePtr += 5;
-
continue;
}
@@ -652,15 +632,12 @@
static bool tmpPatternEmpty(uint16_t nr, int32_t antChn)
{
- uint8_t *scanPtr;
- int32_t pattLen, scanLen;
-
if (tmpPatt[nr] == NULL)
return true;
- scanPtr = (uint8_t *)tmpPatt[nr];
- scanLen = antChn * sizeof (tonTyp);
- pattLen = tmpPattLens[nr];
+ uint8_t *scanPtr = (uint8_t *)tmpPatt[nr];
+ int32_t scanLen = antChn * sizeof (tonTyp);
+ int32_t pattLen = tmpPattLens[nr];
for (int32_t i = 0; i < pattLen; i++)
{
@@ -678,15 +655,11 @@
static int64_t calculateXMSize(void)
{
- int16_t i, j, ap, ai, a;
- int64_t currSize64;
- instrTyp *ins;
-
// count header size in song
- currSize64 = sizeof (songHeaderTyp);
+ int64_t currSize64 = sizeof (songHeaderTyp);
// count number of patterns that would be saved
- ap = MAX_PATTERNS;
+ int16_t ap = MAX_PATTERNS;
do
{
if (patternEmpty(ap - 1))
@@ -697,12 +670,12 @@
while (ap > 0);
// count number of instruments
- ai = 128;
+ int16_t ai = 128;
while (ai > 0 && getUsedSamples(ai) == 0 && song.instrName[ai][0] == '\0')
ai--;
// count packed pattern data size in song
- for (i = 0; i < ap; i++)
+ for (int16_t i = 0; i < ap; i++)
{
currSize64 += sizeof (patternHeaderTyp);
if (!patternEmpty(i))
@@ -710,20 +683,21 @@
}
// count instrument and sample data size in song
- for (i = 1; i <= ai; i++)
+ for (int16_t i = 1; i <= ai; i++)
{
+ int16_t j;
if (instr[i] == NULL)
j = 0;
else
j = i;
- a = getUsedSamples(i);
+ const int16_t a = getUsedSamples(i);
if (a > 0)
currSize64 += INSTR_HEADER_SIZE + (a * sizeof (sampleHeaderTyp));
else
currSize64 += 22+11;
- ins = instr[j];
+ instrTyp *ins = instr[j];
for (int16_t k = 0; k < a; k++)
{
if (ins->samp[k].pek != NULL)
@@ -736,16 +710,13 @@
static int64_t calculateTrimSize(void)
{
- int16_t ap, i, j, k, ai, highestChan, pattLen;
- int32_t antChn, pattDataLen, newPattDataLen;
- int64_t bytes64, oldInstrSize64, newInstrSize64;
- tonTyp *note, *pattPtr;
+ int16_t i, j, k;
- antChn = song.antChn;
- pattDataLen = 0;
- newPattDataLen = 0;
- bytes64 = 0;
- oldInstrSize64 = 0;
+ int32_t antChn = song.antChn;
+ int32_t pattDataLen = 0;
+ int32_t newPattDataLen = 0;
+ int64_t bytes64 = 0;
+ int64_t oldInstrSize64 = 0;
// copy over temp data
memcpy(tmpPatt, patt, sizeof (tmpPatt));
@@ -763,7 +734,7 @@
oldInstrSize64 = getTempInsAndSmpSize();
// count number of patterns that would be saved
- ap = MAX_PATTERNS;
+ int16_t ap = MAX_PATTERNS;
do
{
if (tmpPatternEmpty(ap - 1, antChn))
@@ -774,7 +745,7 @@
while (ap > 0);
// count number of instruments that would be saved
- ai = MAX_INST;
+ int16_t ai = MAX_INST;
while (ai > 0 && getUsedTempSamples(ai) == 0 && tmpInstrName[ai][0] == '\0')
ai--;
@@ -802,19 +773,19 @@
if (removeChans)
{
// get real number of channels
- highestChan = -1;
+ int16_t highestChan = -1;
for (i = 0; i < ap; i++)
{
- pattPtr = tmpPatt[i];
+ tonTyp *pattPtr = tmpPatt[i];
if (pattPtr == NULL)
continue;
- pattLen = tmpPattLens[i];
+ const int16_t pattLen = tmpPattLens[i];
for (j = 0; j < pattLen; j++)
{
for (k = 0; k < antChn; k++)
{
- note = &pattPtr[(j * MAX_VOICES) + k];
+ tonTyp *note = &pattPtr[(j * MAX_VOICES) + k];
if (note->eff || note->effTyp || note->instr || note->ton || note->vol)
{
if (k > highestChan)
@@ -860,10 +831,9 @@
// calculat new instruments and samples size
if (removeInst || removeSamp || removeSmpDataAfterLoop || convSmpsTo8Bit)
{
- newInstrSize64 = getTempInsAndSmpSize();
+ int64_t newInstrSize64 = getTempInsAndSmpSize();
assert(oldInstrSize64 >= newInstrSize64);
-
if (oldInstrSize64 > newInstrSize64)
bytes64 += (oldInstrSize64 - newInstrSize64);
}
@@ -874,11 +844,8 @@
static int32_t SDLCALL trimThreadFunc(void *ptr)
{
- int16_t ap, ai, i, j, k, pattLen, highestChan;
- tonTyp *pattPtr, *note;
+ int16_t i, j, k;
- (void)ptr;
-
if (!setTmpInstruments())
{
okBoxThreadSafe(0, "System message", "Not enough memory!");
@@ -888,7 +855,7 @@
// audio callback is not running now, so we're safe
// count number of patterns
- ap = MAX_PATTERNS;
+ int16_t ap = MAX_PATTERNS;
do
{
if (patternEmpty(ap - 1))
@@ -899,7 +866,7 @@
while (ap > 0);
// count number of instruments
- ai = MAX_INST;
+ int16_t ai = MAX_INST;
while (ai > 0 && getUsedSamples(ai) == 0 && song.instrName[ai][0] == '\0')
ai--;
@@ -919,19 +886,19 @@
if (removeChans)
{
// count used channels
- highestChan = -1;
+ int16_t highestChan = -1;
for (i = 0; i < ap; i++)
{
- pattPtr = patt[i];
+ tonTyp *pattPtr = patt[i];
if (pattPtr == NULL)
continue;
- pattLen = pattLens[i];
+ const int16_t pattLen = pattLens[i];
for (j = 0; j < pattLen; j++)
{
for (k = 0; k < song.antChn; k++)
{
- note = &pattPtr[(j * MAX_VOICES) + k];
+ tonTyp *note = &pattPtr[(j * MAX_VOICES) + k];
if (note->eff || note->effTyp || note->instr || note->ton || note->vol)
{
if (k > highestChan)
@@ -956,11 +923,11 @@
{
for (i = 0; i < MAX_PATTERNS; i++)
{
- pattPtr = patt[i];
+ tonTyp *pattPtr = patt[i];
if (pattPtr == NULL)
continue;
- pattLen = pattLens[i];
+ const int16_t pattLen = pattLens[i];
for (j = 0; j < pattLen; j++)
memset(&pattPtr[(j * MAX_VOICES) + song.antChn], 0, sizeof (tonTyp) * (MAX_VOICES - song.antChn));
}
@@ -979,6 +946,8 @@
editor.trimThreadWasDone = true;
return true;
+
+ (void)ptr;
}
void trimThreadDone(void)
--- a/src/ft2_unicode.c
+++ b/src/ft2_unicode.c
@@ -20,22 +20,20 @@
// Windows routines
char *cp437ToUtf8(char *src)
{
- char *x;
- int32_t reqSize, retVal, srcLen;
- wchar_t *w;
+ int32_t retVal;
if (src == NULL)
return NULL;
- srcLen = (int32_t)strlen(src);
+ int32_t srcLen = (int32_t)strlen(src);
if (srcLen <= 0)
return NULL;
- reqSize = MultiByteToWideChar(437, 0, src, srcLen, 0, 0);
+ int32_t reqSize = MultiByteToWideChar(437, 0, src, srcLen, 0, 0);
if (reqSize <= 0)
return NULL;
- w = (wchar_t *)malloc((reqSize + 1) * sizeof (wchar_t));
+ wchar_t *w = (wchar_t *)malloc((reqSize + 1) * sizeof (wchar_t));
if (w == NULL)
return NULL;
@@ -59,7 +57,7 @@
return NULL;
}
- x = (char *)malloc((reqSize + 2) * sizeof (char));
+ char *x = (char *)malloc((reqSize + 2) * sizeof (char));
if (x == NULL)
{
free(w);
@@ -83,27 +81,24 @@
UNICHAR *cp437ToUnichar(char *src)
{
- int32_t reqSize, retVal, srcLen;
- UNICHAR *w;
-
if (src == NULL)
return NULL;
- srcLen = (int32_t)strlen(src);
+ int32_t srcLen = (int32_t)strlen(src);
if (srcLen <= 0)
return NULL;
- reqSize = MultiByteToWideChar(437, 0, src, srcLen, 0, 0);
+ int32_t reqSize = MultiByteToWideChar(437, 0, src, srcLen, 0, 0);
if (reqSize <= 0)
return NULL;
- w = (wchar_t *)malloc((reqSize + 1) * sizeof (wchar_t));
+ UNICHAR *w = (wchar_t *)malloc((reqSize + 1) * sizeof (wchar_t));
if (w == NULL)
return NULL;
w[reqSize] = 0;
- retVal = MultiByteToWideChar(437, 0, src, srcLen, w, reqSize);
+ int32_t retVal = MultiByteToWideChar(437, 0, src, srcLen, w, reqSize);
if (!retVal)
{
free(w);
@@ -115,29 +110,24 @@
char *utf8ToCp437(char *src, bool removeIllegalChars)
{
- char *x;
- int8_t ch;
- int32_t reqSize, retVal, srcLen;
- wchar_t *w;
-
if (src == NULL)
return NULL;
- srcLen = (int32_t)strlen(src);
+ int32_t srcLen = (int32_t)strlen(src);
if (srcLen <= 0)
return NULL;
- reqSize = MultiByteToWideChar(CP_UTF8, 0, src, srcLen, 0, 0);
+ int32_t reqSize = MultiByteToWideChar(CP_UTF8, 0, src, srcLen, 0, 0);
if (reqSize <= 0)
return NULL;
- w = (wchar_t *)malloc((reqSize + 1) * sizeof (wchar_t));
+ wchar_t *w = (wchar_t *)malloc((reqSize + 1) * sizeof (wchar_t));
if (w == NULL)
return NULL;
w[reqSize] = 0;
- retVal = MultiByteToWideChar(CP_UTF8, 0, src, srcLen, w, reqSize);
+ int32_t retVal = MultiByteToWideChar(CP_UTF8, 0, src, srcLen, w, reqSize);
if (!retVal)
{
free(w);
@@ -158,7 +148,7 @@
return NULL;
}
- x = (char *)calloc(reqSize + 1, sizeof (char));
+ char *x = (char *)calloc(reqSize + 1, sizeof (char));
if (x == NULL)
{
free(w);
@@ -181,7 +171,7 @@
// remove illegal characters (only allow certain nordic ones)
for (int32_t i = 0; i < reqSize; i++)
{
- ch = (int8_t)x[i];
+ const int8_t ch = (const int8_t)x[i];
if (ch < 32 && ch != 0 && ch != -124 && ch != -108 &&
ch != -122 && ch != -114 && ch != -103 && ch != -113)
{
@@ -195,28 +185,24 @@
char *unicharToCp437(UNICHAR *src, bool removeIllegalChars)
{
- char *x;
- int8_t ch;
- int32_t reqSize, retVal, srcLen, i;
-
if (src == NULL)
return NULL;
- srcLen = (int32_t)UNICHAR_STRLEN(src);
+ int32_t srcLen = (int32_t)UNICHAR_STRLEN(src);
if (srcLen <= 0)
return NULL;
- reqSize = WideCharToMultiByte(437, 0, src, srcLen, 0, 0, 0, 0);
+ int32_t reqSize = WideCharToMultiByte(437, 0, src, srcLen, 0, 0, 0, 0);
if (reqSize <= 0)
return NULL;
- x = (char *)malloc((reqSize + 1) * sizeof (char));
+ char *x = (char *)malloc((reqSize + 1) * sizeof (char));
if (x == NULL)
return NULL;
x[reqSize] = '\0';
- retVal = WideCharToMultiByte(437, 0, src, srcLen, x, reqSize, 0, 0);
+ int32_t retVal = WideCharToMultiByte(437, 0, src, srcLen, x, reqSize, 0, 0);
if (!retVal)
{
free(x);
@@ -226,9 +212,9 @@
if (removeIllegalChars)
{
// remove illegal characters (only allow certain nordic ones)
- for (i = 0; i < reqSize; i++)
+ for (int32_t i = 0; i < reqSize; i++)
{
- ch = (int8_t)x[i];
+ const int8_t ch = (const int8_t)x[i];
if (ch < 32 && ch != 0 && ch != -124 && ch != -108 &&
ch != -122 && ch != -114 && ch != -103 && ch != -113)
{
@@ -245,36 +231,31 @@
// non-Windows routines
char *cp437ToUtf8(char *src)
{
- char *inPtr, *outPtr, *outBuf;
- int32_t rc;
- size_t srcLen, inLen, outLen;
- iconv_t cd;
-
if (src == NULL)
return NULL;
- srcLen = strlen(src);
+ size_t srcLen = strlen(src);
if (srcLen <= 0)
return NULL;
- cd = iconv_open("UTF-8", "437");
+ iconv_t cd = iconv_open("UTF-8", "437");
if (cd == (iconv_t)-1)
return NULL;
- outLen = srcLen * 2; // should be sufficient
+ size_t outLen = srcLen * 2; // should be sufficient
- outBuf = (char *)calloc(outLen + 2, sizeof (char));
+ char *outBuf = (char *)calloc(outLen + 2, sizeof (char));
if (outBuf == NULL)
return NULL;
- inPtr = src;
- inLen = srcLen;
- outPtr = outBuf;
+ char *inPtr = src;
+ size_t inLen = srcLen;
+ char *outPtr = outBuf;
#if defined(__NetBSD__) || defined(__sun) || defined(sun)
- rc = iconv(cd, (const char **)&inPtr, &inLen, &outPtr, &outLen);
+ int32_t rc = iconv(cd, (const char **)&inPtr, &inLen, &outPtr, &outLen);
#else
- rc = iconv(cd, &inPtr, &inLen, &outPtr, &outLen);
+ int32_t rc = iconv(cd, &inPtr, &inLen, &outPtr, &outLen);
#endif
iconv(cd, NULL, NULL, &outPtr, &outLen); // flush
iconv_close(cd);
@@ -290,43 +271,37 @@
char *utf8ToCp437(char *src, bool removeIllegalChars)
{
- char *inPtr, *outPtr, *outBuf;
- int8_t ch;
- int32_t rc;
- size_t srcLen, inLen, outLen;
- iconv_t cd;
-
if (src == NULL)
return NULL;
- srcLen = strlen(src);
+ size_t srcLen = strlen(src);
if (srcLen <= 0)
return NULL;
#ifdef __APPLE__
- cd = iconv_open("437//TRANSLIT//IGNORE", "UTF-8-MAC");
+ iconv_t cd = iconv_open("437//TRANSLIT//IGNORE", "UTF-8-MAC");
#elif defined(__NetBSD__) || defined(__sun) || defined(sun)
- cd = iconv_open("437", "UTF-8");
+ iconv_t cd = iconv_open("437", "UTF-8");
#else
- cd = iconv_open("437//TRANSLIT//IGNORE", "UTF-8");
+ iconv_t cd = iconv_open("437//TRANSLIT//IGNORE", "UTF-8");
#endif
if (cd == (iconv_t)-1)
return NULL;
- outLen = srcLen * 2; // should be sufficient
+ size_t outLen = srcLen * 2; // should be sufficient
- outBuf = (char *)calloc(outLen + 1, sizeof (char));
+ char *outBuf = (char *)calloc(outLen + 1, sizeof (char));
if (outBuf == NULL)
return NULL;
- inPtr = src;
- inLen = srcLen;
- outPtr = outBuf;
+ char *inPtr = src;
+ size_t inLen = srcLen;
+ char *outPtr = outBuf;
#if defined(__NetBSD__) || defined(__sun) || defined(sun)
- rc = iconv(cd, (const char **)&inPtr, &inLen, &outPtr, &outLen);
+ int32_t rc = iconv(cd, (const char **)&inPtr, &inLen, &outPtr, &outLen);
#else
- rc = iconv(cd, &inPtr, &inLen, &outPtr, &outLen);
+ int32_t rc = iconv(cd, &inPtr, &inLen, &outPtr, &outLen);
#endif
iconv(cd, NULL, NULL, &outPtr, &outLen); // flush
iconv_close(cd);
@@ -342,7 +317,7 @@
// remove illegal characters (only allow certain nordic ones)
for (size_t i = 0; i < outLen; i++)
{
- ch = (int8_t)outBuf[i];
+ const int8_t ch = (const int8_t)outBuf[i];
if (ch < 32 && ch != 0 && ch != -124 && ch != -108 &&
ch != -122 && ch != -114 && ch != -103 && ch != -113)
{
--- a/src/ft2_video.c
+++ b/src/ft2_video.c
@@ -80,10 +80,6 @@
static void drawFPSCounter(void)
{
- char *textPtr, ch;
- uint16_t xPos, yPos;
- double dRefreshRate, dAudLatency;
-
if (editor.framesPassed >= FPS_SCAN_FRAMES && (editor.framesPassed % FPS_SCAN_FRAMES) == 0)
{
dAvgFPS = dRunningFPS * (1.0 / FPS_SCAN_FRAMES);
@@ -106,11 +102,11 @@
return;
}
- dRefreshRate = video.dMonitorRefreshRate;
+ double dRefreshRate = video.dMonitorRefreshRate;
if (dRefreshRate < 0.0 || dRefreshRate > 9999.9)
dRefreshRate = 9999.9; // prevent number from overflowing text box
- dAudLatency = audio.dAudioLatencyMs;
+ double dAudLatency = audio.dAudioLatencyMs;
if (dAudLatency < 0.0 || dAudLatency > 999999999.9999)
dAudLatency = 999999999.9999; // prevent number from overflowing text box
@@ -131,13 +127,13 @@
// draw text
- xPos = FPS_RENDER_X + 3;
- yPos = FPS_RENDER_Y + 3;
+ uint16_t xPos = FPS_RENDER_X+3;
+ uint16_t yPos = FPS_RENDER_Y+3;
- textPtr = fpsTextBuf;
+ char *textPtr = fpsTextBuf;
while (*textPtr != '\0')
{
- ch = *textPtr++;
+ const char ch = *textPtr++;
if (ch == '\n')
{
yPos += FONT1_CHAR_H+1;
@@ -152,15 +148,12 @@
void endFPSCounter(void)
{
- uint64_t frameTimeDiff;
- double dHz;
-
- if (!video.showFPSCounter || frameStartTime == 0)
- return;
-
- frameTimeDiff = SDL_GetPerformanceCounter() - frameStartTime;
- dHz = 1000.0 / (frameTimeDiff * editor.dPerfFreqMulMs);
- dRunningFPS += dHz;
+ if (video.showFPSCounter && frameStartTime > 0)
+ {
+ const uint64_t frameTimeDiff = SDL_GetPerformanceCounter() - frameStartTime;
+ const double dHz = 1000.0 / (frameTimeDiff * editor.dPerfFreqMulMs);
+ dRunningFPS += dHz;
+ }
}
void flipFrame(void)
@@ -220,15 +213,10 @@
static void updateRenderSizeVars(void)
{
- int32_t di;
-#ifdef __APPLE__
- int32_t actualScreenW, actualScreenH;
- double dXUpscale, dYUpscale;
-#endif
float fXScale, fYScale;
SDL_DisplayMode dm;
- di = SDL_GetWindowDisplayIndex(video.window);
+ int32_t di = SDL_GetWindowDisplayIndex(video.window);
if (di < 0)
di = 0; // return display index 0 (default) on error
@@ -252,12 +240,13 @@
video.renderW = (int32_t)(SCREEN_W * fXScale);
video.renderH = (int32_t)(SCREEN_H * fYScale);
-#ifdef __APPLE__
// retina high-DPI hackery (SDL2 is bad at reporting actual rendering sizes on macOS w/ high-DPI)
+#ifdef __APPLE__
+ int32_t actualScreenW, actualScreenH;
SDL_GL_GetDrawableSize(video.window, &actualScreenW, &actualScreenH);
- dXUpscale = (double)actualScreenW / video.displayW;
- dYUpscale = (double)actualScreenH / video.displayH;
+ const double dXUpscale = (const double)actualScreenW / video.displayW;
+ const double dYUpscale = (const double)actualScreenH / video.displayH;
// downscale back to correct sizes
if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale);
@@ -361,10 +350,11 @@
hideSprite(SPRITE_TEXT_CURSOR);
// setup refresh buffer (used to clear sprites after each frame)
- for (uint32_t i = 0; i < SPRITE_NUM; i++)
+ s = sprites;
+ for (uint32_t i = 0; i < SPRITE_NUM; i++, s++)
{
- sprites[i].refreshBuffer = (uint32_t *)malloc(sprites[i].w * sprites[i].h * sizeof (int32_t));
- if (sprites[i].refreshBuffer == NULL)
+ s->refreshBuffer = (uint32_t *)malloc(s->w * s->h * sizeof (int32_t));
+ if (s->refreshBuffer == NULL)
return false;
}
@@ -379,12 +369,13 @@
void freeSprites(void)
{
- for (int32_t i = 0; i < SPRITE_NUM; i++)
+ sprite_t *s = sprites;
+ for (int32_t i = 0; i < SPRITE_NUM; i++, s++)
{
- if (sprites[i].refreshBuffer != NULL)
+ if (s->refreshBuffer != NULL)
{
- free(sprites[i].refreshBuffer);
- sprites[i].refreshBuffer = NULL;
+ free(s->refreshBuffer);
+ s->refreshBuffer = NULL;
}
}
}
@@ -417,24 +408,18 @@
void eraseSprites(void)
{
- int8_t i;
- int32_t sx, sy, x, y, sw, sh, srcPitch, dstPitch;
- const uint32_t *src32;
- uint32_t *dst32;
- sprite_t *s;
-
- for (i = SPRITE_NUM-1; i >= 0; i--) // erasing must be done in reverse order
+ sprite_t *s = &sprites[SPRITE_NUM-1];
+ for (int32_t i = SPRITE_NUM-1; i >= 0; i--, s--) // erasing must be done in reverse order
{
- s = &sprites[i];
if (s->x >= SCREEN_W || s->y >= SCREEN_H) // sprite is hidden, don't draw nor fill clear buffer
continue;
assert(s->refreshBuffer != NULL);
- sw = s->w;
- sh = s->h;
- sx = s->x;
- sy = s->y;
+ int32_t sw = s->w;
+ int32_t sh = s->h;
+ int32_t sx = s->x;
+ int32_t sy = s->y;
// if x is negative, adjust variables
if (sx < 0)
@@ -450,19 +435,19 @@
sy = 0;
}
- src32 = s->refreshBuffer;
- dst32 = &video.frameBuffer[(sy * SCREEN_W) + sx];
+ const uint32_t *src32 = s->refreshBuffer;
+ uint32_t *dst32 = &video.frameBuffer[(sy * SCREEN_W) + sx];
// handle x/y clipping
if (sx+sw >= SCREEN_W) sw = SCREEN_W - sx;
if (sy+sh >= SCREEN_H) sh = SCREEN_H - sy;
- srcPitch = s->w - sw;
- dstPitch = SCREEN_W - sw;
+ const int32_t srcPitch = s->w - sw;
+ const int32_t dstPitch = SCREEN_W - sw;
- for (y = 0; y < sh; y++)
+ for (int32_t y = 0; y < sh; y++)
{
- for (x = 0; x < sw; x++)
+ for (int32_t x = 0; x < sw; x++)
*dst32++ = *src32++;
src32 += srcPitch;
@@ -473,12 +458,8 @@
void renderSprites(void)
{
- const uint8_t *src8;
- int32_t sx, sy, x, y, sw, sh, srcPitch, dstPitch;
- uint32_t i, *clr32, *dst32, windowFlags;
- sprite_t *s;
-
- for (i = 0; i < SPRITE_NUM; i++)
+ sprite_t *s = sprites;
+ for (int32_t i = 0; i < SPRITE_NUM; i++, s++)
{
if (i == SPRITE_LEFT_LOOP_PIN || i == SPRITE_RIGHT_LOOP_PIN)
continue; // these need special drawing (done elsewhere)
@@ -487,13 +468,11 @@
if (i == SPRITE_TEXT_CURSOR)
{
assert(video.window != NULL);
- windowFlags = SDL_GetWindowFlags(video.window);
+ const uint32_t windowFlags = SDL_GetWindowFlags(video.window);
if (!(windowFlags & SDL_WINDOW_INPUT_FOCUS))
continue;
}
- s = &sprites[i];
-
// set new sprite position
s->x = s->newX;
s->y = s->newY;
@@ -503,11 +482,11 @@
assert(s->data != NULL && s->refreshBuffer != NULL);
- sw = s->w;
- sh = s->h;
- sx = s->x;
- sy = s->y;
- src8 = s->data;
+ int32_t sw = s->w;
+ int32_t sh = s->h;
+ int32_t sx = s->x;
+ int32_t sy = s->y;
+ const uint8_t *src8 = s->data;
// if x is negative, adjust variables
if (sx < 0)
@@ -528,22 +507,22 @@
if (sw <= 0 || sh <= 0) // sprite is hidden, don't draw nor fill clear buffer
continue;
- dst32 = &video.frameBuffer[(sy * SCREEN_W) + sx];
- clr32 = s->refreshBuffer;
+ uint32_t *dst32 = &video.frameBuffer[(sy * SCREEN_W) + sx];
+ uint32_t *clr32 = s->refreshBuffer;
// handle x/y clipping
if (sx+sw >= SCREEN_W) sw = SCREEN_W - sx;
if (sy+sh >= SCREEN_H) sh = SCREEN_H - sy;
- srcPitch = s->w - sw;
- dstPitch = SCREEN_W - sw;
+ const int32_t srcPitch = s->w - sw;
+ const int32_t dstPitch = SCREEN_W - sw;
if (mouse.mouseOverTextBox && i == SPRITE_MOUSE_POINTER)
{
// text edit mouse pointer (has color changing depending on content under it)
- for (y = 0; y < sh; y++)
+ for (int32_t y = 0; y < sh; y++)
{
- for (x = 0; x < sw; x++)
+ for (int32_t x = 0; x < sw; x++)
{
*clr32++ = *dst32; // fill clear buffer
@@ -567,9 +546,9 @@
else
{
// normal sprites
- for (y = 0; y < sh; y++)
+ for (int32_t y = 0; y < sh; y++)
{
- for (x = 0; x < sw; x++)
+ for (int32_t x = 0; x < sw; x++)
{
*clr32++ = *dst32; // fill clear buffer
@@ -593,15 +572,13 @@
void renderLoopPins(void)
{
- uint8_t pal;
const uint8_t *src8;
int32_t sx, x, y, sw, sh, srcPitch, dstPitch;
uint32_t *clr32, *dst32;
- sprite_t *s;
// left loop pin
- s = &sprites[SPRITE_LEFT_LOOP_PIN];
+ sprite_t *s = &sprites[SPRITE_LEFT_LOOP_PIN];
assert(s->data != NULL && s->refreshBuffer != NULL);
// set new sprite position
@@ -704,7 +681,7 @@
if (y < 9 && *src8 == PAL_LOOPPIN)
{
// don't draw marker line on top of left loop pin's thumb graphics
- pal = *dst32 >> 24;
+ const uint8_t pal = *dst32 >> 24;
if (pal != PAL_DESKTOP && pal != PAL_DSKTOP1 && pal != PAL_DSKTOP2)
*dst32 = video.palette[*src8];
}
@@ -796,7 +773,7 @@
{
#define MAX_UPSCALE_FACTOR 16 // 10112x6400 - ought to be good enough for many years to come
- uint8_t i, oldUpscaleFactor;
+ uint8_t i;
SDL_DisplayMode dm;
/* Kludge for Raspbarry Pi. Upscaling of 3x or higher makes everything slow as a snail.
@@ -811,7 +788,7 @@
}
#endif
- oldUpscaleFactor = video.upscaleFactor;
+ uint8_t oldUpscaleFactor = video.upscaleFactor;
if (config.windowFlags & WINSIZE_AUTO)
{
// find out which upscaling factor is the biggest to fit on screen
@@ -862,12 +839,10 @@
void updateWindowTitle(bool forceUpdate)
{
- char *songTitle;
-
if (!forceUpdate && songIsModified == song.isModified)
return; // window title is already set to the same
- songTitle = getCurrSongFilename();
+ char *songTitle = getCurrSongFilename();
if (songTitle != NULL)
{
if (song.isModified)
@@ -913,12 +888,11 @@
bool setupWindow(void)
{
- uint32_t windowFlags;
SDL_DisplayMode dm;
video.vsync60HzPresent = false;
- windowFlags = SDL_WINDOW_ALLOW_HIGHDPI;
+ uint32_t windowFlags = SDL_WINDOW_ALLOW_HIGHDPI;
#if defined (__APPLE__) || defined (_WIN32) // yet another quirk!
windowFlags |= SDL_WINDOW_HIDDEN;
#endif
@@ -959,9 +933,7 @@
bool setupRenderer(void)
{
- uint32_t rendererFlags;
-
- rendererFlags = SDL_RENDERER_ACCELERATED;
+ uint32_t rendererFlags = SDL_RENDERER_ACCELERATED;
if (video.vsync60HzPresent)
rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
@@ -1033,8 +1005,6 @@
void handleRedrawing(void)
{
- textBox_t *txt;
-
if (!ui.configScreenShown && !ui.helpScreenShown)
{
if (ui.aboutScreenShown)
@@ -1111,7 +1081,7 @@
{
assert(mouse.lastEditBox >= 0 && mouse.lastEditBox < NUM_TEXTBOXES);
- txt = &textBoxes[mouse.lastEditBox];
+ textBox_t *txt = &textBoxes[mouse.lastEditBox];
if (editor.textCursorBlinkCounter < 256/2 && !textIsMarked() && !(mouse.leftButtonPressed | mouse.rightButtonPressed))
setSpritePos(SPRITE_TEXT_CURSOR, getTextCursorX(txt), getTextCursorY(txt) - 1); // show text cursor
else
@@ -1128,8 +1098,6 @@
static void drawReplayerData(void)
{
- bool drawPosText;
-
if (songPlaying)
{
if (ui.drawReplayerPianoFlag)
@@ -1139,7 +1107,7 @@
drawPiano(chSyncEntry);
}
- drawPosText = true;
+ bool drawPosText = true;
if (ui.configScreenShown || ui.nibblesShown ||
ui.helpScreenShown || ui.aboutScreenShown ||
ui.diskOpShown)
--- a/src/ft2_wav_renderer.c
+++ b/src/ft2_wav_renderer.c
@@ -175,11 +175,9 @@
static bool dump_Init(uint32_t frq, int16_t amp, int16_t songPos)
{
- uint32_t maxSamplesPerTick, sampleSize;
+ const int32_t maxSamplesPerTick = (const int32_t)ceil((frq * 2.5) / MIN_BPM); // absolute max samples per tick
+ uint32_t sampleSize = (WDBitDepth / 8) * 2; // 2 channels
- maxSamplesPerTick = (int32_t)ceil((frq * 2.5) / MIN_BPM); // absolute max samples per tick
- sampleSize = (WDBitDepth / 8) * 2; // 2 channels
-
// *2 for stereo
wavRenderBuffer = (uint8_t *)malloc((TICKS_PER_RENDER_CHUNK * maxSamplesPerTick) * sampleSize);
if (wavRenderBuffer == NULL)
@@ -205,7 +203,6 @@
static void dump_Close(FILE *f, uint32_t totalSamples)
{
- uint32_t tmpLen, totalBytes;
wavHeader_t wavHeader;
if (wavRenderBuffer != NULL)
@@ -214,6 +211,7 @@
wavRenderBuffer = NULL;
}
+ uint32_t totalBytes;
if (WDBitDepth == 16)
totalBytes = totalSamples * sizeof (int16_t);
else
@@ -222,7 +220,7 @@
if (totalBytes & 1)
fputc(0, f); // write pad byte
- tmpLen = ftell(f) - 8;
+ uint32_t tmpLen = ftell(f)-8;
// go back and fill in WAV header
rewind(f);
@@ -278,7 +276,7 @@
return returnValue;
}
-void dump_RenderTick(uint32_t samplesPerTick, uint8_t *buffer)
+void dump_TickReplayer(void)
{
replayerBusy = true;
@@ -289,8 +287,6 @@
updateVoices();
replayerBusy = false;
-
- mixReplayerTickToBuffer(samplesPerTick, buffer, WDBitDepth);
}
static void updateVisuals(void)
@@ -313,14 +309,7 @@
static int32_t SDLCALL renderWavThread(void *ptr)
{
- bool renderDone;
- uint8_t *ptr8, tickCounter;
- uint32_t samplesInChunk, sampleCounter;
- FILE *f;
-
- (void)ptr;
-
- f = (FILE *)editor.wavRendererFileHandle;
+ FILE *f = (FILE *)editor.wavRendererFileHandle;
fseek(f, sizeof (wavHeader_t), SEEK_SET);
pauseAudio();
@@ -332,19 +321,18 @@
return true;
}
- sampleCounter = 0;
- renderDone = false;
- tickCounter = 4;
+ uint32_t sampleCounter = 0;
+ bool renderDone = false;
+ uint8_t tickCounter = 4;
+ double dTickSampleCounter = 0.0;
- double dTickSamples = audio.dSamplesPerTick;
-
editor.wavReachedEndFlag = false;
while (!renderDone)
{
- samplesInChunk = 0;
+ uint32_t samplesInChunk = 0;
// render several ticks at once to prevent frequent disk I/O (speeds up the process)
- ptr8 = wavRenderBuffer;
+ uint8_t *ptr8 = wavRenderBuffer;
for (uint32_t i = 0; i < TICKS_PER_RENDER_CHUNK; i++)
{
if (!editor.wavIsRendering || dump_EndOfTune(WDStopPos))
@@ -353,21 +341,27 @@
break;
}
- int32_t tickSamples = (int32_t)dTickSamples;
- dump_RenderTick(tickSamples, ptr8);
+ if (dTickSampleCounter <= 0.0)
+ {
+ // new replayer tick
+ dump_TickReplayer();
+ dTickSampleCounter += audio.dSamplesPerTick;
+ }
- dTickSamples -= tickSamples; // keep fractional part
- dTickSamples += audio.dSamplesPerTick;
+ int32_t remainingTick = (int32_t)ceil(dTickSampleCounter);
- tickSamples *= 2; // stereo
- samplesInChunk += tickSamples;
- sampleCounter += tickSamples;
+ mixReplayerTickToBuffer(remainingTick, ptr8, WDBitDepth);
+ dTickSampleCounter -= remainingTick;
+ remainingTick *= 2; // stereo
+ samplesInChunk += remainingTick;
+ sampleCounter += remainingTick;
+
// increase buffer pointer
if (WDBitDepth == 16)
- ptr8 += tickSamples * sizeof (int16_t);
+ ptr8 += remainingTick * sizeof (int16_t);
else
- ptr8 += tickSamples * sizeof (float);
+ ptr8 += remainingTick * sizeof (float);
if (++tickCounter >= 4)
{
@@ -394,15 +388,16 @@
editor.diskOpReadOnOpen = true;
return true;
+
+ (void)ptr;
}
static void createOverwriteText(char *name)
{
char nameTmp[128];
- uint32_t nameLen;
// read entry name to a small buffer
- nameLen = (uint32_t)strlen(name);
+ uint32_t nameLen = (uint32_t)strlen(name);
memcpy(nameTmp, name, (nameLen >= sizeof (nameTmp)) ? sizeof (nameTmp) : (nameLen + 1));
nameTmp[sizeof (nameTmp) - 1] = '\0';
@@ -413,8 +408,6 @@
static void wavRender(bool checkOverwrite)
{
- char *filename;
-
WDStartPos = (uint8_t)(MAX(0, MIN(WDStartPos, song.len - 1)));
WDStopPos = (uint8_t)(MAX(0, MIN(MAX(WDStartPos, WDStopPos), song.len - 1)));
@@ -422,7 +415,7 @@
diskOpChangeFilenameExt(".wav");
- filename = getDiskOpFilename();
+ char *filename = getDiskOpFilename();
if (checkOverwrite && fileExistsAnsi(filename))
{
createOverwriteText(filename);
binary files /dev/null b/test.zip differ