Add support for Duty 2 note preview
@@ -19,6 +19,10 @@ import {
NR43,
NR44,
AUD3_WAVE_RAM,
+ NR21,
+ NR22,
+ NR23,
+ NR24,
} from "./music_constants";
let update_handle = null;
@@ -137,6 +141,7 @@ const preview = (note, type, instrument, square2) => {
switch (type) {
case "duty":
+ if (!square2) {
const regs = {
NR10:
"0" +
@@ -181,6 +186,45 @@ const preview = (note, type, instrument, square2) => {
emulator.writeMem(NR12, parseInt(regs.NR12, 2));
emulator.writeMem(NR13, parseInt(regs.NR13, 2));
emulator.writeMem(NR14, parseInt(regs.NR14, 2));
+ } else {
+ const regs = {
+ NR21:
+ bitpack(instrument.duty_cycle, 2) +
+ bitpack(
+ instrument.length !== null && instrument.length !== 0
+ ? 64 - instrument.length
+ : 0,
+ 6
+ ),
+ NR22:
+ bitpack(instrument.initial_volume, 4) +
+ (instrument.volume_sweep_change > 0 ? 1 : 0) +
+ bitpack(
+ instrument.volume_sweep_change !== 0
+ ? 8 - Math.abs(instrument.volume_sweep_change)
+ : 0,
+ 3
+ ),
+ NR23: bitpack(noteFreq & 0b11111111, 8),
+ NR24:
+ "1" + // Initial
+ (instrument.length !== null ? 1 : 0) +
+ "000" +
+ bitpack((noteFreq & 0b0000011100000000) >> 8, 3),
+ };
+
+ console.log("-------------");
+ console.log(`NR21`, regs.NR21, parseInt(regs.NR21, 2));
+ console.log(`NR22`, regs.NR22, parseInt(regs.NR22, 2));
+ console.log(`NR23`, regs.NR23, parseInt(regs.NR23, 2));
+ console.log(`NR24`, regs.NR24, parseInt(regs.NR24, 2));
+ console.log("=============");
+
+ emulator.writeMem(NR21, parseInt(regs.NR21, 2));
+ emulator.writeMem(NR22, parseInt(regs.NR22, 2));
+ emulator.writeMem(NR23, parseInt(regs.NR23, 2));
+ emulator.writeMem(NR24, parseInt(regs.NR24, 2));
+ }
break;
case "wave":
// Copy Wave Form
