Skip to content

Commit

Permalink
STBL483 2024/11/10 2nd
Browse files Browse the repository at this point in the history
  PianoRoll:発声が続いているにもかかわらず、表示が途中で途切れることがあるのを修正
  PianoRoll:Chip:YM2413追加
  XGM2:再生できなくなっていたバグをとりあえず修正
  • Loading branch information
kumatan committed Nov 10, 2024
1 parent 4b43962 commit 65e8440
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
�X�V����
STBL483 2024/11/10 2nd
PianoRoll:�����������Ă���ɂ�������炸�A�\�����r���œr�؂�邱�Ƃ�����̂��C��
PianoRoll:Chip:YM2413�lj�
XGM2:�Đ��ł��Ȃ��Ȃ��Ă����o�O���Ƃ肠�����C��

STBL482 2024/11/10
PianoRoll:Driver:HES�lj�
PianoRoll:Chip:HuC6280�lj�
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayer_InstKit/02info.nsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!define NAME "MDPlayer"
!define VERSION "STBL481"
!define VERSION "STBL482"
!define PUBLISHER "Kumata"
!define PACKAGE "${NAME} ${VERSION}"
4 changes: 2 additions & 2 deletions MDPlayer/MDPlayerx64/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ public static bool MgsPlay_mgsdrv(Setting setting)

if (useOPLL)
{
chipRegister.setYM2413Register(0, 14, 32, EnmModel.VirtualModel);
chipRegister.setYM2413Register(0, 14, 32, EnmModel.VirtualModel,0);
//chipRegister.setYM2610Register(0, 0, 0x11, 0xc0, EnmModel.VirtualModel);
}

Expand Down Expand Up @@ -3296,7 +3296,7 @@ public static bool MscPlay_mscdrv(Setting setting)

if (useOPLL)
{
chipRegister.setYM2413Register(0, 14, 32, EnmModel.VirtualModel);
chipRegister.setYM2413Register(0, 14, 32, EnmModel.VirtualModel, 0);
}

if (!DriverVirtual.init(vgmBuf, chipRegister, EnmModel.VirtualModel, new EnmChip[] { EnmChip.AY8910, EnmChip.YM2413, EnmChip.K051649 }
Expand Down
30 changes: 17 additions & 13 deletions MDPlayer/MDPlayerx64/ChipRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,9 +2059,13 @@ public void setGA20Register(int chipID, Int32 Adr, byte Dat, EnmModel model)
}
}

public void setYM2413Register(int chipID, int dAddr, int dData, EnmModel model)
public void setYM2413Register(int chipID, int dAddr, int dData, EnmModel model,long vgmFrameCounter)
{
if (model == EnmModel.PianoRollModel) return;
if (model == EnmModel.PianoRollModel)
{
pianoRollMng.SetRegister(EnmChip.YM2413, chipID, dAddr, dData, vgmFrameCounter);
return;
}

if (ctYM2413 == null) return;

Expand Down Expand Up @@ -2541,18 +2545,18 @@ public void softResetYM2413(int chipID, EnmModel model)
// FM全チャネルキーオフ
for (int ch = 0; ch < 9; ch++)
{
setYM2413Register(chipID, 0x20 + ch, 0x00, model);
setYM2413Register(chipID, 0x20 + ch, 0x00, model, 0);
}
setYM2413Register(chipID, 0x0e, 0x00, model);
setYM2413Register(chipID, 0x0e, 0x00, model, 0);

// FM TL=15
for (int ch = 0; ch < 9; ch++)
{
setYM2413Register(chipID, 0x30 + ch, 0x0f, model);
setYM2413Register(chipID, 0x30 + ch, 0x0f, model, 0);
}
setYM2413Register(chipID, 0x36, 0x0f, model);
setYM2413Register(chipID, 0x37, 0xff, model);
setYM2413Register(chipID, 0x38, 0xff, model);
setYM2413Register(chipID, 0x36, 0x0f, model, 0);
setYM2413Register(chipID, 0x37, 0xff, model, 0);
setYM2413Register(chipID, 0x38, 0xff, model, 0);

}

Expand Down Expand Up @@ -4827,13 +4831,13 @@ public void setMaskYM2413(int chipID, int ch, bool mask)

if (ch < 9)
{
setYM2413Register((byte)chipID, 0x20 + ch, fmRegisterYM2413[chipID][0x20 + ch], EnmModel.VirtualModel);
setYM2413Register((byte)chipID, 0x20 + ch, fmRegisterYM2413[chipID][0x20 + ch], EnmModel.RealModel);
setYM2413Register((byte)chipID, 0x20 + ch, fmRegisterYM2413[chipID][0x20 + ch], EnmModel.VirtualModel, 0);
setYM2413Register((byte)chipID, 0x20 + ch, fmRegisterYM2413[chipID][0x20 + ch], EnmModel.RealModel, 0);
}
else if (ch < 14)
{
setYM2413Register((byte)chipID, 0x0e, fmRegisterYM2413[chipID][0x0e], EnmModel.VirtualModel);
setYM2413Register((byte)chipID, 0x0e, fmRegisterYM2413[chipID][0x0e], EnmModel.RealModel);
setYM2413Register((byte)chipID, 0x0e, fmRegisterYM2413[chipID][0x0e], EnmModel.VirtualModel, 0);
setYM2413Register((byte)chipID, 0x0e, fmRegisterYM2413[chipID][0x0e], EnmModel.RealModel, 0);
}
}

Expand Down Expand Up @@ -5290,7 +5294,7 @@ public void setFadeoutVolYM2413(int chipID, int v)
nowYM2413FadeoutVol[chipID] = v / (128 / 16);
for (int c = 0; c < 9; c++)
{
setYM2413Register(chipID, 0x30 + c, fmRegisterYM2413[chipID][0x30 + c], EnmModel.RealModel);
setYM2413Register(chipID, 0x30 + c, fmRegisterYM2413[chipID][0x30 + c], EnmModel.RealModel, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayerx64/Driver/MGSDRV/MsxPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void OutPort(int address, byte value)
opllAdr = value;
break;
case 0x7d:
chipRegister?.setYM2413Register(0, opllAdr, value, model);
chipRegister?.setYM2413Register(0, opllAdr, value, model, driver.vgmFrameCounter);
//log.Write("OPLL Port Adr:{0:x04} Dat:{1:x02}", address, value);
break;
case 0xa8:
Expand Down
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayerx64/Driver/S98/S98.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private void WriteYM2151(int chipID, byte port, byte adr, byte data)

private void WriteYM2413(int chipID, byte adr, byte data)
{
chipRegister.setYM2413Register(chipID, adr, data, model);
chipRegister.setYM2413Register(chipID, adr, data, model,vgmFrameCounter);
}

private void WriteYM3526(int chipID, byte adr, byte data)
Expand Down
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayerx64/Driver/vgm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ private void VcX1_010()

private void VcYM2413()
{
chipRegister.setYM2413Register((vgmBuf[vgmAdr] & 0x80) == 0 ? 0 : 1, vgmBuf[vgmAdr + 1], vgmBuf[vgmAdr + 2], model);
chipRegister.setYM2413Register((vgmBuf[vgmAdr] & 0x80) == 0 ? 0 : 1, vgmBuf[vgmAdr + 1], vgmBuf[vgmAdr + 2], model, vgmFrameCounter);
vgmAdr += 3;
}

Expand Down
5 changes: 3 additions & 2 deletions MDPlayer/MDPlayerx64/Driver/xgm2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private void oneFrameXGM()
private void oneFrameFM()
{
if (fmWaitCnt-- > 0) return;

if (vgmBuf == null) return;
while (true)
{
if (fmmusicPtr >= vgmBuf.Length) { endFm = true; return; }
Expand Down Expand Up @@ -688,6 +688,7 @@ private void SendInst(byte cs, byte port, byte[] vd)
private void oneFramePsg()
{
if (psgWaitCnt-- > 0) return;
if (vgmBuf == null) return;
while (true)
{
if (psgmusicPtr >= vgmBuf.Length) { endPsg = true; return; }
Expand Down Expand Up @@ -867,7 +868,7 @@ private void WriteYM2612P0(byte adr, byte val)
if (adr == 0x2b) DACEnable = (byte)(val & 0x80);
else if (adr == 0x27) ch3spEnable = ((val & 0x40) != 0);

chipRegister.setYM2612Register(0, 0, adr, val, model, vgmFrameCounter);
chipRegister?.setYM2612Register(0, 0, adr, val, model, vgmFrameCounter);
}

private void WriteYM2612P1(byte adr, byte val)
Expand Down
102 changes: 102 additions & 0 deletions MDPlayer/MDPlayerx64/PianoRoll/YM2413.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using MDPlayer;
using NAudio.Gui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MDPlayerx64.PianoRoll
{
public class YM2413(List<PrNote> lstPrNote, int MAXChip = 2) : BaseChip(lstPrNote, MAXChip)
{
private List<byte[]> reg;
private List<bool[]> KeyOn;
private List<bool[]> KeyOnOld;
private List<int[]> Fnum;
private List<int[]> FnumOld;
private List<PrNote[]> Note;

public override void Clear()
{
reg = [];
KeyOn = [];
KeyOnOld = [];
Fnum = [];
FnumOld = [];
Note = [];
for (int i = 0; i < MAXChip; i++)
{
reg.Add(new byte[0x100]);
KeyOn.Add([false, false, false, false, false, false, false, false, false]);
KeyOnOld.Add([false, false, false, false, false, false, false, false, false]);
Fnum.Add([-1, -1, -1, -1, -1, -1, -1, -1, -1]);
FnumOld.Add([-1, -1, -1, -1, -1, -1, -1, -1, -1]);
Note.Add(new PrNote[9]);
}
}

public override void Analyze(int chipID, int dAdr, int dData, long vgmFrameCounter)
{
reg[chipID][dAdr] = (byte)dData;
if (dAdr < 0x10 || (dAdr >= 0x19 && dAdr < 0x20) || dAdr >= 0x29) return;

int ch = dAdr & 0xf;
int freq = reg[chipID][0x10 + ch] + ((reg[chipID][0x20 + ch] & 0x1) << 8);
int oct = ((reg[chipID][0x20 + ch] & 0xe) >> 1);
int fnum = Common.searchSegaPCMNote(freq / 172.0) + (oct - 4) * 12;
int k = reg[chipID][0x20 + ch] & 0x10;
KeyOn[chipID][ch] = k != 0;
Fnum[chipID][ch] = fnum;

if (KeyOnOld[chipID][ch] == KeyOn[chipID][ch]
&& FnumOld[chipID][ch] == Fnum[chipID][ch]
) return;
KeyOnOld[chipID][ch] = KeyOn[chipID][ch];
FnumOld[chipID][ch] = Fnum[chipID][ch];

if (!KeyOn[chipID][ch])
{
//keyOff
if (Note[chipID][ch] != null)
Note[chipID][ch].endTick = vgmFrameCounter;
return;
}

//keyOn
if (Note[chipID][ch] != null && Note[chipID][ch].endTick == -1)
Note[chipID][ch].endTick = vgmFrameCounter;

Note[chipID][ch] = MakeNote(ch, vgmFrameCounter, fnum, freq);
lstPrNote.Add(Note[chipID][ch]);

}

private static PrNote MakeNote(int ch, long startTick, int ff, int freq)
{
PrNote ret = new PrNote
{
ch = ch,
startTick = startTick,
endTick = -1,//長さ未確定
key = 95 - ff,
freq = freq
};
ret.noteColor1[0] = 0xd0;
ret.noteColor1[1] = 0x00;
ret.noteColor1[2] = 0x50;
ret.noteColor1[3] = 0xf0;
ret.noteColor1[4] = 0x00;
ret.noteColor1[5] = 0x70;
ret.noteColor2[0] = 0x90;
ret.noteColor2[1] = 0x00;
ret.noteColor2[2] = 0x90;
ret.noteColor2[3] = 0xd0;
ret.noteColor2[4] = 0x00;
ret.noteColor2[5] = 0xb0;

return ret;
}

}
}
1 change: 1 addition & 0 deletions MDPlayer/MDPlayerx64/PianoRollMng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public PianoRollMng()
chipList.Add(EnmChip.AY8910, new MDPlayerx64.PianoRoll.AY8910(lstPrNote));
chipList.Add(EnmChip.HuC6280, new MDPlayerx64.PianoRoll.HuC6280(lstPrNote));
chipList.Add(EnmChip.YM2151, new MDPlayerx64.PianoRoll.YM2151(lstPrNote));
chipList.Add(EnmChip.YM2413, new MDPlayerx64.PianoRoll.YM2413(lstPrNote));
chipList.Add(EnmChip.YM2608, new MDPlayerx64.PianoRoll.YM2608(lstPrNote));
chipList.Add(EnmChip.YM2610, new MDPlayerx64.PianoRoll.YM2610(lstPrNote));
chipList.Add(EnmChip.YM2612, new MDPlayerx64.PianoRoll.YM2612(lstPrNote));
Expand Down
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayerx64/dacControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private void chip_reg_write(byte ChipType2, byte ChipID, byte Port, byte Offset,
chipRegister.setSN76489Register(ChipID, Data, model, 0);
break;
case 0x01: // YM2413+
chipRegister.setYM2413Register(ChipID, Offset, Data, model);
chipRegister.setYM2413Register(ChipID, Offset, Data, model, 0);
break;
case 0x02: // YM2612
chipRegister.setYM2612Register(ChipID, Port, Offset, Data, model, -1);
Expand Down
4 changes: 4 additions & 0 deletions MDPlayer/MDPlayerx64/form/SYS/frmPianoRoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public void screenDrawParams()
i--;
continue;
}
if (n.endTick == -1 && x < 0)
{
x = 0;
}

for (int j = 0; j < 6; j++)
{
Expand Down

0 comments on commit 65e8440

Please sign in to comment.