Skip to content

Commit

Permalink
Pushed v1.02 code
Browse files Browse the repository at this point in the history
- The paulaSetLength() function now takes length in words, not bytes.
  This doesn't really change anything, but it's more correct.
- Fixed a very minor bug with VOL up/down button in Edit Op.
- Fixed a bug where the scopes could show the wrong volume for the
  tunetone waveform (sampler screen).
- Some code cleanup
  • Loading branch information
8bitbubsy committed Jan 6, 2020
1 parent 118366b commit 6340261
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 409 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ vs2019_project/.vs/pt2-clone/v16/.suo
.DS_Store
vs2019_project/pt2-clone/Release/pt2-clone.vcxproj.FileListAbsolute.txt
vs2019_project/pt2-clone/x64/Debug/pt2-clone.vcxproj.FileListAbsolute.txt
*.opendb
33 changes: 19 additions & 14 deletions src/pt2_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void mixerUpdateLoops(void) // updates Paula loop (+ scopes)
{
s = &modEntry->samples[editor.currSample];
paulaSetData(i, ch->n_start + s->loopStart);
paulaSetLength(i, s->loopLength);
paulaSetLength(i, s->loopLength / 2);
}
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ void paulaStartDMA(uint8_t ch)

length = v->newLength;
if (length < 2)
length = 2;
length = 2; // for safety

v->dPhase = 0.0;
v->pos = 0;
Expand Down Expand Up @@ -397,15 +397,15 @@ void paulaSetPeriod(uint8_t ch, uint16_t period)

if (period == 0)
{
v->dDelta = 0.0;
v->dDelta = 0.0; // confirmed behavior on real Amiga
setScopeDelta(ch, 0);
return;
}

// confirmed behavior on real Amiga
if (period < 113)
period = 113;
period = 113; // confirmed behavior on real Amiga

// if the new period was the same as the previous period, use cached deltas
if (period == oldPeriod)
{
v->dDelta = oldVoiceDelta;
Expand All @@ -415,6 +415,7 @@ void paulaSetPeriod(uint8_t ch, uint16_t period)
{
oldPeriod = period;

// if we are rendering pattern to sample (PAT2SMP), use different frequencies
if (editor.isSMPRendering)
dPeriodToDeltaDiv = editor.pat2SmpHQ ? (PAULA_PAL_CLK / 28836.0) : (PAULA_PAL_CLK / 22168.0);
else
Expand All @@ -424,9 +425,8 @@ void paulaSetPeriod(uint8_t ch, uint16_t period)
oldVoiceDelta = v->dDelta;

// set scope rate

#if SCOPE_HZ != 64
#error Scope Hz is not 64 (2^n), change rate calc. to use doubles+round in pt_scope.c
#error Scope Hz is not 64 (2^n), change rate calc. to use doubles+round in pt2_scope.c
#endif
oldScopeDelta = (PAULA_PAL_CLK * (65536UL / SCOPE_HZ)) / period;
setScopeDelta(ch, oldScopeDelta);
Expand All @@ -439,20 +439,25 @@ void paulaSetPeriod(uint8_t ch, uint16_t period)

void paulaSetVolume(uint8_t ch, uint16_t vol)
{
vol &= 127;
vol &= 127; // confirmed behavior on real Amiga

if (vol > 64)
vol = 64;
vol = 64; // confirmed behavior on real Amiga

paula[ch].dVolume = vol * (1.0 / 64.0);
}

// our Paula simulation takes sample lengths in bytes instead of words
void paulaSetLength(uint8_t ch, uint32_t len)
void paulaSetLength(uint8_t ch, uint16_t len)
{
if (len < 2)
len = 2; // needed safety for mixer and scopes
if (len == 0)
{
len = 65535;
/* confirmed behavior on real Amiga (also needed for safety)
* And yes, we have room for this, it will never overflow! */
}

scopeExt[ch].newLength = paula[ch].newLength = len;
// our mixer works with bytes, not words. Multiply by two
scopeExt[ch].newLength = paula[ch].newLength = len * 2;
}

void paulaSetData(uint8_t ch, const int8_t *src)
Expand Down
2 changes: 1 addition & 1 deletion src/pt2_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void paulaStopDMA(uint8_t ch);
void paulaStartDMA(uint8_t ch);
void paulaSetPeriod(uint8_t ch, uint16_t period);
void paulaSetVolume(uint8_t ch, uint16_t vol);
void paulaSetLength(uint8_t ch, uint32_t len);
void paulaSetLength(uint8_t ch, uint16_t len);
void paulaSetData(uint8_t ch, const int8_t *src);
void lockAudio(void);
void unlockAudio(void);
Expand Down
90 changes: 45 additions & 45 deletions src/pt2_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ void handleEditKeys(SDL_Scancode scancode, bool normalMode)
if (handleSpecialKeys(scancode))
{
if (editor.currMode != MODE_RECORD)
modSetPos(DONT_SET_ORDER, (modEntry->currRow + editor.editMoveAdd) & 63);
modSetPos(DONT_SET_ORDER, (modEntry->currRow + editor.editMoveAdd) & 0x3F);

return;
}
Expand Down Expand Up @@ -830,11 +830,11 @@ void handleEditKeys(SDL_Scancode scancode, bool normalMode)
if (input.keyb.shiftPressed || input.keyb.leftAltPressed)
{
note->command = 0;
note->param = 0;
note->param = 0;
}

if (editor.currMode != MODE_RECORD)
modSetPos(DONT_SET_ORDER, (modEntry->currRow + editor.editMoveAdd) & 63);
modSetPos(DONT_SET_ORDER, (modEntry->currRow + editor.editMoveAdd) & 0x3F);

updateWindowTitle(MOD_IS_MODIFIED);
}
Expand All @@ -854,51 +854,51 @@ bool handleSpecialKeys(SDL_Scancode scancode)
{
note_t *patt, *note, *prevNote;

if (input.keyb.leftAltPressed)
{
patt = modEntry->patterns[modEntry->currPattern];
note = &patt[(modEntry->currRow * AMIGA_VOICES) + editor.cursor.channel];
prevNote = &patt[(((modEntry->currRow - 1) & 0x3F) * AMIGA_VOICES) + editor.cursor.channel];
if (!input.keyb.leftAltPressed)
return false;

if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)
{
// insert stored effect (buffer[0..8])
note->command = editor.effectMacros[scancode - SDL_SCANCODE_1] >> 8;
note->param = editor.effectMacros[scancode - SDL_SCANCODE_1] & 0xFF;
patt = modEntry->patterns[modEntry->currPattern];
note = &patt[(modEntry->currRow * AMIGA_VOICES) + editor.cursor.channel];
prevNote = &patt[(((modEntry->currRow - 1) & 0x3F) * AMIGA_VOICES) + editor.cursor.channel];

updateWindowTitle(MOD_IS_MODIFIED);
return true;
}
if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)
{
// insert stored effect (buffer[0..8])
note->command = editor.effectMacros[scancode - SDL_SCANCODE_1] >> 8;
note->param = editor.effectMacros[scancode - SDL_SCANCODE_1] & 0xFF;

// copy command+effect from above into current command+effect
if (scancode == SDL_SCANCODE_BACKSLASH)
{
note->command = prevNote->command;
note->param = prevNote->param;
updateWindowTitle(MOD_IS_MODIFIED);
return true;
}

updateWindowTitle(MOD_IS_MODIFIED);
return true;
}
// copy command+effect from above into current command+effect
if (scancode == SDL_SCANCODE_BACKSLASH)
{
note->command = prevNote->command;
note->param = prevNote->param;

// copy command+(effect + 1) from above into current command+effect
if (scancode == SDL_SCANCODE_EQUALS)
{
note->command = prevNote->command;
note->param = prevNote->param + 1; // wraps 0x00..0xFF
updateWindowTitle(MOD_IS_MODIFIED);
return true;
}

updateWindowTitle(MOD_IS_MODIFIED);
return true;
}
// copy command+(effect + 1) from above into current command+effect
if (scancode == SDL_SCANCODE_EQUALS)
{
note->command = prevNote->command;
note->param = prevNote->param + 1; // wraps 0x00..0xFF

// copy command+(effect - 1) from above into current command+effect
if (scancode == SDL_SCANCODE_MINUS)
{
note->command = prevNote->command;
note->param = prevNote->param - 1; // wraps 0x00..0xFF
updateWindowTitle(MOD_IS_MODIFIED);
return true;
}

updateWindowTitle(MOD_IS_MODIFIED);
return true;
}
// copy command+(effect - 1) from above into current command+effect
if (scancode == SDL_SCANCODE_MINUS)
{
note->command = prevNote->command;
note->param = prevNote->param - 1; // wraps 0x00..0xFF

updateWindowTitle(MOD_IS_MODIFIED);
return true;
}

return false;
Expand Down Expand Up @@ -939,12 +939,12 @@ void jamAndPlaceSample(SDL_Scancode scancode, bool normalMode)
chn->n_volume = s->volume;
chn->n_period = tempPeriod;
chn->n_start = &modEntry->sampleData[s->offset];
chn->n_length = (s->loopStart > 0) ? (s->loopStart + s->loopLength) : s->length;
chn->n_length = (s->loopStart > 0) ? (uint32_t)(s->loopStart + s->loopLength) / 2 : s->length / 2;
chn->n_loopstart = &modEntry->sampleData[s->offset + s->loopStart];
chn->n_replen = s->loopLength;
chn->n_replen = s->loopLength / 2;

if (chn->n_length < 2)
chn->n_length = 2;
if (chn->n_length == 0)
chn->n_length = 1;

paulaSetVolume(ch, chn->n_volume);
paulaSetPeriod(ch, chn->n_period);
Expand Down Expand Up @@ -995,7 +995,7 @@ void jamAndPlaceSample(SDL_Scancode scancode, bool normalMode)
{
// delete note and sample if illegal note (= -2, -1 = ignore) key was entered

if (normalMode || (!normalMode && editor.pNoteFlag == 2))
if (normalMode || editor.pNoteFlag == 2)
{
if (!editor.ui.samplerScreenShown && (editor.currMode == MODE_EDIT || editor.currMode == MODE_RECORD))
{
Expand Down
2 changes: 1 addition & 1 deletion src/pt2_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <stdint.h>
#include "pt2_unicode.h"

#define PROG_VER_STR "1.01"
#define PROG_VER_STR "1.02"

#ifdef _WIN32
#define DIR_DELIMITER '\\'
Expand Down
Loading

0 comments on commit 6340261

Please sign in to comment.