Skip to content

Commit 6340261

Browse files
committed
Pushed v1.02 code
- 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
1 parent 118366b commit 6340261

File tree

12 files changed

+339
-409
lines changed

12 files changed

+339
-409
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ vs2019_project/.vs/pt2-clone/v16/.suo
1616
.DS_Store
1717
vs2019_project/pt2-clone/Release/pt2-clone.vcxproj.FileListAbsolute.txt
1818
vs2019_project/pt2-clone/x64/Debug/pt2-clone.vcxproj.FileListAbsolute.txt
19+
*.opendb

src/pt2_audio.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void mixerUpdateLoops(void) // updates Paula loop (+ scopes)
276276
{
277277
s = &modEntry->samples[editor.currSample];
278278
paulaSetData(i, ch->n_start + s->loopStart);
279-
paulaSetLength(i, s->loopLength);
279+
paulaSetLength(i, s->loopLength / 2);
280280
}
281281
}
282282
}
@@ -349,7 +349,7 @@ void paulaStartDMA(uint8_t ch)
349349

350350
length = v->newLength;
351351
if (length < 2)
352-
length = 2;
352+
length = 2; // for safety
353353

354354
v->dPhase = 0.0;
355355
v->pos = 0;
@@ -397,15 +397,15 @@ void paulaSetPeriod(uint8_t ch, uint16_t period)
397397

398398
if (period == 0)
399399
{
400-
v->dDelta = 0.0;
400+
v->dDelta = 0.0; // confirmed behavior on real Amiga
401401
setScopeDelta(ch, 0);
402402
return;
403403
}
404404

405-
// confirmed behavior on real Amiga
406405
if (period < 113)
407-
period = 113;
406+
period = 113; // confirmed behavior on real Amiga
408407

408+
// if the new period was the same as the previous period, use cached deltas
409409
if (period == oldPeriod)
410410
{
411411
v->dDelta = oldVoiceDelta;
@@ -415,6 +415,7 @@ void paulaSetPeriod(uint8_t ch, uint16_t period)
415415
{
416416
oldPeriod = period;
417417

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

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

440440
void paulaSetVolume(uint8_t ch, uint16_t vol)
441441
{
442-
vol &= 127;
442+
vol &= 127; // confirmed behavior on real Amiga
443+
443444
if (vol > 64)
444-
vol = 64;
445+
vol = 64; // confirmed behavior on real Amiga
445446

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

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

455-
scopeExt[ch].newLength = paula[ch].newLength = len;
459+
// our mixer works with bytes, not words. Multiply by two
460+
scopeExt[ch].newLength = paula[ch].newLength = len * 2;
456461
}
457462

458463
void paulaSetData(uint8_t ch, const int8_t *src)

src/pt2_audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void paulaStopDMA(uint8_t ch);
2929
void paulaStartDMA(uint8_t ch);
3030
void paulaSetPeriod(uint8_t ch, uint16_t period);
3131
void paulaSetVolume(uint8_t ch, uint16_t vol);
32-
void paulaSetLength(uint8_t ch, uint32_t len);
32+
void paulaSetLength(uint8_t ch, uint16_t len);
3333
void paulaSetData(uint8_t ch, const int8_t *src);
3434
void lockAudio(void);
3535
void unlockAudio(void);

src/pt2_edit.c

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ void handleEditKeys(SDL_Scancode scancode, bool normalMode)
691691
if (handleSpecialKeys(scancode))
692692
{
693693
if (editor.currMode != MODE_RECORD)
694-
modSetPos(DONT_SET_ORDER, (modEntry->currRow + editor.editMoveAdd) & 63);
694+
modSetPos(DONT_SET_ORDER, (modEntry->currRow + editor.editMoveAdd) & 0x3F);
695695

696696
return;
697697
}
@@ -830,11 +830,11 @@ void handleEditKeys(SDL_Scancode scancode, bool normalMode)
830830
if (input.keyb.shiftPressed || input.keyb.leftAltPressed)
831831
{
832832
note->command = 0;
833-
note->param = 0;
833+
note->param = 0;
834834
}
835835

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

839839
updateWindowTitle(MOD_IS_MODIFIED);
840840
}
@@ -854,51 +854,51 @@ bool handleSpecialKeys(SDL_Scancode scancode)
854854
{
855855
note_t *patt, *note, *prevNote;
856856

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

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

869-
updateWindowTitle(MOD_IS_MODIFIED);
870-
return true;
871-
}
864+
if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)
865+
{
866+
// insert stored effect (buffer[0..8])
867+
note->command = editor.effectMacros[scancode - SDL_SCANCODE_1] >> 8;
868+
note->param = editor.effectMacros[scancode - SDL_SCANCODE_1] & 0xFF;
872869

873-
// copy command+effect from above into current command+effect
874-
if (scancode == SDL_SCANCODE_BACKSLASH)
875-
{
876-
note->command = prevNote->command;
877-
note->param = prevNote->param;
870+
updateWindowTitle(MOD_IS_MODIFIED);
871+
return true;
872+
}
878873

879-
updateWindowTitle(MOD_IS_MODIFIED);
880-
return true;
881-
}
874+
// copy command+effect from above into current command+effect
875+
if (scancode == SDL_SCANCODE_BACKSLASH)
876+
{
877+
note->command = prevNote->command;
878+
note->param = prevNote->param;
882879

883-
// copy command+(effect + 1) from above into current command+effect
884-
if (scancode == SDL_SCANCODE_EQUALS)
885-
{
886-
note->command = prevNote->command;
887-
note->param = prevNote->param + 1; // wraps 0x00..0xFF
880+
updateWindowTitle(MOD_IS_MODIFIED);
881+
return true;
882+
}
888883

889-
updateWindowTitle(MOD_IS_MODIFIED);
890-
return true;
891-
}
884+
// copy command+(effect + 1) from above into current command+effect
885+
if (scancode == SDL_SCANCODE_EQUALS)
886+
{
887+
note->command = prevNote->command;
888+
note->param = prevNote->param + 1; // wraps 0x00..0xFF
892889

893-
// copy command+(effect - 1) from above into current command+effect
894-
if (scancode == SDL_SCANCODE_MINUS)
895-
{
896-
note->command = prevNote->command;
897-
note->param = prevNote->param - 1; // wraps 0x00..0xFF
890+
updateWindowTitle(MOD_IS_MODIFIED);
891+
return true;
892+
}
898893

899-
updateWindowTitle(MOD_IS_MODIFIED);
900-
return true;
901-
}
894+
// copy command+(effect - 1) from above into current command+effect
895+
if (scancode == SDL_SCANCODE_MINUS)
896+
{
897+
note->command = prevNote->command;
898+
note->param = prevNote->param - 1; // wraps 0x00..0xFF
899+
900+
updateWindowTitle(MOD_IS_MODIFIED);
901+
return true;
902902
}
903903

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

946-
if (chn->n_length < 2)
947-
chn->n_length = 2;
946+
if (chn->n_length == 0)
947+
chn->n_length = 1;
948948

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

998-
if (normalMode || (!normalMode && editor.pNoteFlag == 2))
998+
if (normalMode || editor.pNoteFlag == 2)
999999
{
10001000
if (!editor.ui.samplerScreenShown && (editor.currMode == MODE_EDIT || editor.currMode == MODE_RECORD))
10011001
{

src/pt2_header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <stdint.h>
1414
#include "pt2_unicode.h"
1515

16-
#define PROG_VER_STR "1.01"
16+
#define PROG_VER_STR "1.02"
1717

1818
#ifdef _WIN32
1919
#define DIR_DELIMITER '\\'

0 commit comments

Comments
 (0)