Skip to content

Commit

Permalink
STBL467 2024/09/15
Browse files Browse the repository at this point in the history
  コア:GBSに対応
  • Loading branch information
kumatan committed Sep 15, 2024
1 parent c67b0f3 commit 87032f1
Show file tree
Hide file tree
Showing 21 changed files with 9,594 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
�X�V����
STBL467 2024/09/15
�R�A:GBS�ɑΉ�

STBL466 2024/09/05
OPN/OPNA/OPNB/OPNA2:����:�n�[�h�G���x���[�v���m�[�g���o�Ȃ��P�[�X������̂��C��

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 "STBL465"
!define VERSION "STBL466"
!define PUBLISHER "Kumata"
!define PACKAGE "${NAME} ${VERSION}"
162 changes: 162 additions & 0 deletions MDPlayer/MDPlayerx64/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,50 @@ public static void CopyWaveBuffer(short[][] dest)
music.title = string.Format("({0})", System.IO.Path.GetFileName(file));
}

}
else if (ext == ".gbs")
{
gbs gbs = new(Setting);
GD3 gd3 = gbs.getGD3Info(buf, 0);

if (gd3 != null)
{
for (int s = 0; s < gbs.songs; s++)
{
music = new PlayList.Music
{
format = EnmFileFormat.GBS,
fileName = file,
arcFileName = zipFile,
arcType = EnmArcType.unknown,
title = string.Format("{0} - Trk {1}", gd3.GameName, s + 1),
titleJ = string.Format("{0} - Trk {1}", gd3.GameNameJ, s + 1),
game = gd3.GameName,
gameJ = gd3.GameNameJ,
composer = gd3.Composer,
composerJ = gd3.ComposerJ,
vgmby = gd3.VGMBy,
converted = gd3.Converted,
notes = gd3.Notes,
songNo = s
};
if (!string.IsNullOrEmpty(zipFile)) music.arcType = zipFile.ToLower().LastIndexOf(".zip") != -1 ? EnmArcType.ZIP : EnmArcType.LZH;

musics.Add(music);
}

return musics;
}
else
{
music.format = EnmFileFormat.GBS;
music.fileName = file;
music.arcFileName = zipFile;
music.game = "unknown";
music.type = "-";
music.title = string.Format("({0})", System.IO.Path.GetFileName(file));
}

}
else if (ext == ".hes")
{
Expand Down Expand Up @@ -2444,6 +2488,21 @@ public static bool Play(Setting setting)
return NsfPlay(setting);
}

if (PlayingFileFormat == EnmFileFormat.GBS)
{
DriverVirtual = new gbs(setting)
{
setting = setting
};
DriverReal = null;
//if (setting.outputDevice.DeviceType != Common.DEV_Null)
//{
// driverReal = new nsf();
// driverReal.setting = setting;
//}
return GbsPlay(setting);
}

if (PlayingFileFormat == EnmFileFormat.HES)
{
DriverVirtual = new hes
Expand Down Expand Up @@ -6657,6 +6716,109 @@ public static bool NsfPlay(Setting setting)

}

public static bool GbsPlay(Setting setting)
{

try
{

if (vgmBuf == null || setting == null) return false;

//Stop();

chipRegister.resetChips();

vgmFadeout = false;
vgmFadeoutCounter = 1.0;
vgmFadeoutCounterV = 0.00001;
vgmSpeed = 1;
vgmRealFadeoutVol = 0;
vgmRealFadeoutVolWait = 4;

ClearFadeoutVolume();

chipRegister.resetChips();

UseChip.Clear();


StartTrdVgmReal();

List<MDSound.MDSound.Chip> lstChips = new();

hiyorimiNecessary = setting.HiyorimiMode;

ChipLED = new ChipLEDs
{
PriDMG = 1
};

MasterVolume = setting.balance.MasterVolume;

((gbs)DriverVirtual).song = (byte)SongNo;
if (!DriverVirtual.init(vgmBuf, chipRegister, EnmModel.VirtualModel, new EnmChip[] { EnmChip.Unuse }
, (uint)(setting.outputDevice.SampleRate * setting.LatencyEmulation / 1000)
, (uint)(setting.outputDevice.SampleRate * setting.outputDevice.WaitTime / 1000))) return false;
if (DriverReal != null)
{
((gbs)DriverReal).song = (byte)SongNo;
if (!DriverReal.init(vgmBuf, chipRegister, EnmModel.RealModel, new EnmChip[] { EnmChip.Unuse }
, (uint)(setting.outputDevice.SampleRate * setting.LatencySCCI / 1000)
, (uint)(setting.outputDevice.SampleRate * setting.outputDevice.WaitTime / 1000))) return false;
}

MDSound.MDSound.Chip chip;
gb gb = new();
chip = new MDSound.MDSound.Chip
{
ID = 0,
type = MDSound.MDSound.enmInstrumentType.DMG,
Instrument = gb,
Update = gb.Update,
Start = gb.Start,
Stop = gb.Stop,
Reset = gb.Reset,
SamplingRate = (UInt32)setting.outputDevice.SampleRate,
Volume = setting.balance.DMGVolume,
Clock = 4194304,
Option = null
};
lstChips.Add(chip);
((gbs)DriverVirtual).dmg = chip;
UseChip.Add(EnmChip.DMG);

if (hiyorimiNecessary) hiyorimiNecessary = true;
else hiyorimiNecessary = false;

if (mds == null)
mds = new MDSound.MDSound((UInt32)setting.outputDevice.SampleRate, samplingBuffer, lstChips.ToArray());
else
mds.Init((UInt32)setting.outputDevice.SampleRate, samplingBuffer, lstChips.ToArray());

chipRegister.initChipRegister(lstChips.ToArray());
chipRegister.setDMGRegister(0, 0x16, 0x8f, EnmModel.VirtualModel);
chipRegister.setDMGRegister(0, 0x14, 0x77, EnmModel.VirtualModel);
chipRegister.setDMGRegister(0, 0x15, 0xf7, EnmModel.VirtualModel);
chipRegister.setDMGRegister(0, 0x16, 0x8f, EnmModel.RealModel);
chipRegister.setDMGRegister(0, 0x14, 0x77, EnmModel.RealModel);
chipRegister.setDMGRegister(0, 0x15, 0xf7, EnmModel.RealModel);
//Play

Paused = false;
oneTimeReset = false;

Thread.Sleep(500);

return true;
}
catch (Exception ex)
{
log.ForcedWrite(ex);
return false;
}

}

public static bool HesPlay(Setting setting)
{

Expand Down
75 changes: 75 additions & 0 deletions MDPlayer/MDPlayerx64/Driver/GBS/CPU.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using MDPlayer.Driver.GBS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MDPlayer.Driver.GBS
{
public partial class CPU
{
public Registers reg = new Registers();
public Memory mem = null;
public int clock = 4194304;
public bool isHalt = false;
public bool isStop = false;
public string nimo = "";
public bool cbSwitch = false;
public int ime = 1;

public CPU(int clock, Memory memory)
{
this.clock = clock;
this.mem = memory;
initInsts();
}

public void Init()
{
reg.pc = 0x100;
isHalt = false;
isStop = false;
cbSwitch = false;
ime = 1;
}

public int ExecuteOneStep()
{
int pc;
int cycle = 0;


do
{
pc = reg.pc;

//命令読み込み
ushort c = mem.PeekB(reg.pc);
reg.pc++;
if (cbSwitch)
{
c += 0x100;
cbSwitch = false;
}
//命令実行
cycle = insts[c].meth();

#if DEBUG
string smem = "";
int len = Math.Min(insts[c].length, 4);
for (int i = 0; i < len; i++)
smem += string.Format("{0:X02} ", mem.PeekB(pc + i));
smem += " ".Substring(len * 3);
Console.WriteLine("${0:X04} : {1,-20} {2} {3} {4} cycle:{5}",
pc, nimo, smem, reg, mem.GetBank(), cycle);
nimo = "";
#endif
if (cycle == 0) throw new NotImplementedException();
} while (cbSwitch);

return cycle;
}

}
}
Loading

0 comments on commit 87032f1

Please sign in to comment.