Skip to content

Commit a28e851

Browse files
Merge pull request #115 from negative-seven/master
Add dev flag to swap pulse wave duty cycles
2 parents 2a38499 + 063ac4f commit a28e851

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/audio.asm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ copyToApuChannel:
7373
ldy #$00
7474
@copyByte:
7575
lda (AUDIOTMP3),y
76+
.if SWAP_DUTY_CYCLES
77+
cpy #0
78+
bne @notFirstByte
79+
jsr swapDutyCycles
80+
@notFirstByte:
81+
.endif
7682
sta (AUDIOTMP1),y
7783
iny
7884
tya
@@ -465,6 +471,9 @@ soundEffectSlot1_chirpChirpPlaying:
465471
and #$03
466472
tay
467473
lda soundEffectSlot1_chirpChirpSq1Vol_table,y
474+
.if SWAP_DUTY_CYCLES
475+
jsr swapDutyCycles
476+
.endif
468477
sta SQ1_VOL
469478
inc soundEffectSlot1SecondaryCounter
470479
lda soundEffectSlot1SecondaryCounter
@@ -615,6 +624,10 @@ LE442: jsr copyToSq1Channel
615624
sta SQ1_LO
616625
ldy soundEffectSlot1SecondaryCounter
617626
lda sq1vol_unknown2_table,y
627+
.if SWAP_DUTY_CYCLES
628+
jsr swapDutyCycles
629+
tay ; set z flag based on a; y can be safely clobbered
630+
.endif
618631
sta SQ1_VOL
619632
bne LE46F
620633
lda soundEffectSlot1Playing
@@ -1062,6 +1075,9 @@ updateMusicFrame_setChanVol:
10621075
bne @ret
10631076
tya
10641077
ldy musicChannelOffset
1078+
.if SWAP_DUTY_CYCLES
1079+
jsr swapDutyCycles
1080+
.endif
10651081
sta SQ1_VOL,y
10661082
@ret: rts
10671083

@@ -1342,6 +1358,9 @@ updateMusicFrame_updateChannel:
13421358
@useDirectVolume:
13431359
lda AUDIOTMP1
13441360
@setMmio:
1361+
.if SWAP_DUTY_CYCLES
1362+
jsr swapDutyCycles
1363+
.endif
13451364
sta SQ1_VOL,y
13461365
lda musicStagingSq1Sweep,x
13471366
sta SQ1_SWEEP,y
@@ -1454,6 +1473,15 @@ musicGetNextInstructionByte:
14541473
lda (musicChanTmpAddr),y
14551474
rts
14561475

1476+
.if SWAP_DUTY_CYCLES
1477+
; input a: byte to be written to $4000 or $4004. output a: the same byte with the duty cycle index mapped from (0, 1, 2, 3) to (0, 2, 1, 3), counteracting the behavior of some clone consoles
1478+
swapDutyCycles:
1479+
cmp #%01000000
1480+
bmi @ret ; branch if upper bits are not %01 or %10
1481+
eor #%11000000 ; swap between %01 and %10
1482+
@ret: rts
1483+
.endif
1484+
14571485
musicChanVolControlTable:
14581486
noteToWaveTable:
14591487
noteDurationTable:

src/constants.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ NO_SFX := 0
2727
NO_MENU := 0
2828
ALWAYS_CURTAIN := 0
2929
QUAL_BOOT := 0
30+
SWAP_DUTY_CYCLES := 0 ; counters the duty cycle swap present in some clone consoles
3031

3132
INITIAL_CUSTOM_LEVEL := 29
3233
INITIAL_LINECAP_LEVEL := 39

0 commit comments

Comments
 (0)