Skip to content

Commit

Permalink
TAG049 2020/11/01
Browse files Browse the repository at this point in the history
  Compiler/Driver:スキップ再生対応
  • Loading branch information
kumatan committed Nov 1, 2020
1 parent c3d37c0 commit efc649f
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 42 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����
TAG049 2020/11/01
Compiler/Driver:�X�L�b�v�Đ��Ή�

TAG048 2020/10/13
Driver:loop�񐔂��擾�ł���悤�ɂ���
Player:-L�I�v�V�������g�p�ł���悤�ɂȂ���
Expand Down
13 changes: 10 additions & 3 deletions PMDDotNETCompiler/compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Compiler : iCompiler
public voice_seg voice_seg = null;
public byte[] outFFFileBuf { get; private set; } = null;
public string outFFFileName { get; private set; } = null;

public int skipIndex = -1;//スキップ位置

//内部
private string srcBuf = null;
Expand All @@ -47,12 +47,12 @@ public Compiler(iEncoding enc = null)

public void Init()
{
this.isIDE = false;
this.skipPoint = Point.Empty;
}

public void SetCompileSwitch(params object[] param)
{
this.isIDE = false;
this.skipPoint = Point.Empty;

if (param == null) return;

Expand Down Expand Up @@ -138,11 +138,18 @@ public MmlDatum[] Compile(Stream sourceMML, Func<string, Stream> appendFileReade
work.isIDE = isIDE;
mc mc = new mc(this, mcArgs, srcBuf, ffBuf, work, env);

mc.skipPoint = this.skipPoint;
MmlDatum[] ret = mc.compile_start();
memo_writeAddress = mc.memo_writeAddress;
vdat_setAddress = mc.vdat_setAddress;
mml_seg = mc.mml_seg;
voice_seg = mc.voice_seg;
work.compilerInfo.jumpClock = -1;
if (mc.skipSW == 3)
{
skipIndex = mc.skipIndex + 1;//ひとつずらす
work.compilerInfo.jumpClock = skipIndex;
}

outFFFileBuf = null; if (mc.outVoiceBuf != null)
{
Expand Down
119 changes: 97 additions & 22 deletions PMDDotNETCompiler/mc.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using musicDriverInterface;
using PMDDotNET.Common;
Expand All @@ -22,8 +23,16 @@ public class mc

//DotNET独自パラメータ
public byte[] outVoiceBuf = null;//音色出力用バッファ(ファイル名はv_filename)
public int memo_writeAddress { get; private set; } = -1;
public int vdat_setAddress { get; private set; } = -1;
public int memo_writeAddress = -1;
public int vdat_setAddress = -1;
public Point skipPoint = Point.Empty;//スキップ処理:mml上の行と桁を示す
public int skipIndex = -1;//スキップ処理:mファイル上の位置を示す
public int skipSW = 0;//スキップ処理:進捗を示す
//0 : mml上のスキップ位置の行に達するのを待っている状態
//1 : mml上のスキップ位置の桁に達するのを待っている状態
//2 : 行と桁が達成されたので音程コマンドがやってくるのを待っている状態
//3 : 処理完了
public int skipPointCol = -1;//スキップ処理:桁の位置をmml上の文字数に置き換えた値



Expand Down Expand Up @@ -1113,7 +1122,7 @@ private enmPass2JumpTable cmloop2()
#endif

Log.WriteLine(LogLevel.DEBUG, string.Format("Part: {0} compile start" , (char)('A' - 1 + mml_seg.part) ));

//mml_seg.includeFileHistoryPos = 0;
//mml_seg.currentMMLFile = mml_seg.includeFileHistory[0];
//mml_seg.includeFileHistoryStack.Clear();
Expand All @@ -1134,6 +1143,8 @@ private enmPass2JumpTable cloop()

c_next:;

skipPointCol = work.si + skipPoint.X;

byte ah_b, al_b;
char al = (work.si < mml_seg.mml_buf.Length ? mml_seg.mml_buf[work.si++] : (char)0x1a);
if (al == 0x1a)
Expand Down Expand Up @@ -3796,6 +3807,17 @@ private enmPass2JumpTable one_line_compile()
, mml_seg.mml_filename
, mml_seg.line
, mml_seg.mml_buf.Substring(work.si, n - work.si)));

//KUMA:スキップ処理:指定された行かチェック。もしそうなら、スキップ処理の進捗を一つ上げて桁チェック状態にする。
if (!skipPoint.IsEmpty && skipSW == 0 && mml_seg.line == skipPoint.Y + 1)
{
skipSW = 1;
}
else if (skipSW == 1)//KUMA:同一行で、同一桁にならずに次の行に移った(つまり行末を示していたり音程コマンドが見つからなかった)場合は強制的に次のコマンドにスキップポイントを含める
{
skipSW = 2;
}

//#endif

char al = (char)0;
Expand Down Expand Up @@ -4031,6 +4053,12 @@ private enmPass2JumpTable skip_mml()
//;==============================================================================
private enmPass2JumpTable olc00()
{
//KUMA:スキップしたい桁まで移動していた場合は、スキップ処理の進捗をひとつあげる
if (skipSW == 1 && skipPointCol <= work.si - 1)
{
skipSW = 2;
}

work.bx = 0;//offset comtbl
// olc1:
do
Expand All @@ -4046,14 +4074,31 @@ private enmPass2JumpTable olc00()
}
} while (true);

//KUMA:コマンドのインデックスと格納アドレスを一時保存
int bbx = work.bx;
int bdi = work.di;

byte dh = (byte)work.al;
work.dx = (dh * 0x100) | (byte)work.dx;
if (comtbl[work.bx].Item2 != null)
{
#if DEBUG
Log.WriteLine(LogLevel.TRACE, string.Format("olc00:command:{0}", (char)dh));
#endif
return comtbl[work.bx].Item2();
enmPass2JumpTable ret = comtbl[work.bx].Item2();

//KUMA:スキップ位置を割り出す
if (skipSW == 2)
{
//音階コマンドのみ対象とする
if (bbx < 9)
{
skipIndex = bdi;
skipSW = 3;
}
}

return ret;
}

throw new PMDDotNET.Common.PmdErrorExitException(string.Format("まだ移植できてないコマンドを検出しました({0})", (char)dh));
Expand Down Expand Up @@ -6120,7 +6165,6 @@ private enmPass2JumpTable bp9()

work.al = (byte)mml_seg.leng;


List<object> args = new List<object>();
args.Add((mml_seg.octave << 4) | mml_seg.ontei);
args.Add(mml_seg.leng);
Expand Down Expand Up @@ -6564,7 +6608,13 @@ private void press()
d = (byte)m_seg.m_buf.Get(work.di - 4).dat;
if (ah != d) return;
//prs1:;

if (work.di - 1 == skipIndex)
{
skipIndex -= 3;
}
work.di -= 3;

mml_seg.prsok |= 2;//加工したflag

d = (byte)m_seg.m_buf.Get(work.di).dat;
Expand All @@ -6577,9 +6627,21 @@ private void press()

m_seg.m_buf.Set(work.di, new MmlDatum(255));
work.al++;//255 over

if (work.di - 1 == skipIndex)
{
skipIndex += 3;
}
work.di += 3;

if (ah != 0xf) goto prs200;

if (work.di - 1 == skipIndex)
{
skipIndex --;
}
work.di--;

m_seg.m_buf.Set(work.di - 1, new MmlDatum(ah));//r&r -> rr に変更
prs200:;
mml_seg.leng = work.al;
Expand All @@ -6594,6 +6656,11 @@ private void press()
if (d != 0xf) return;

prs3:;

if (work.di - 1 == skipIndex)
{
skipIndex -= 2;
}
work.di -= 2;

mml_seg.prsok |= 2;//加工したflag
Expand All @@ -6607,6 +6674,11 @@ private void press()

m_seg.m_buf.Set(work.di, new MmlDatum(255));
work.al++;//255 over

if (work.di - 1 == skipIndex)
{
skipIndex += 2;
}
work.di += 2;
goto prs200;
}
Expand Down Expand Up @@ -9655,10 +9727,10 @@ private void calc_line(ref int si)
mml_seg.line = 1;//1行目から
ah++;//Include階層を一つ増やす
bx = si + 1;//MMLのファイル名位置をBXに保存
do
{
al = si < mml_seg.mml_buf.Length ? mml_seg.mml_buf[si++] : (char)0x1a;
} while (al != 0x0a);//ファイル名部分を飛ばす
//do
//{
//al = si < mml_seg.mml_buf.Length ? mml_seg.mml_buf[si++] : (char)0x1a;
//} while (al != 0x0a);//ファイル名部分を飛ばす

mml_seg.includeFileHistoryStack.Push(mml_seg.currentMMLFile);
mml_seg.currentMMLFile = mml_seg.includeFileHistory[++mml_seg.includeFileHistoryPos];
Expand All @@ -9684,23 +9756,26 @@ private void calc_line(ref int si)
if (ah == 0)
{
si = dx;// Error位置をSIに戻す
mml_seg.mml_filename = mml_seg.currentMMLFile;
return;
}

si = bx;
while (mml_seg.mml_buf[si] != 'e' && mml_seg.mml_buf[si] != 'E')//includeをスキップする
{
si++;
}
si++;

mml_seg.mml_filename = ""; //offset mml_filename
do
{
mml_seg.mml_filename += mml_seg.mml_buf[si++];//Include中にError --> MML Filenameを変更
} while (si != mml_seg.mml_buf.Length && mml_seg.mml_buf[si] >= 0x20);
si = dx;// Error位置をSIに戻す
mml_seg.mml_filename = mml_seg.mml_filename.Trim();
mml_seg.mml_filename = mml_seg.currentMMLFile;

//while (mml_seg.mml_buf[si] != 'e' && mml_seg.mml_buf[si] != 'E')//includeをスキップする
//{
// si++;
//}
//si++;

//mml_seg.mml_filename = ""; //offset mml_filename
//do
//{
// mml_seg.mml_filename += mml_seg.mml_buf[si++];//Include中にError --> MML Filenameを変更
//} while (si != mml_seg.mml_buf.Length && mml_seg.mml_buf[si] >= 0x20);
//si = dx;// Error位置をSIに戻す
//mml_seg.mml_filename = mml_seg.mml_filename.Trim();

}

Expand Down
7 changes: 4 additions & 3 deletions PMDDotNETCompiler/mml_seg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,11 @@ public class mml_seg
public int includeFileHistoryPos;
public string currentMMLFile;
public Stack<string> includeFileHistoryStack = new Stack<string>();
//public Stack<int> includeFileLineStack = new Stack<int>();

//mml_seg ends
//public Stack<int> includeFileLineStack = new Stack<int>();

//mml_seg ends

}

}
}
5 changes: 4 additions & 1 deletion PMDDotNETConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ private static void Compile(string[] args,int argIndex)
ffFileBuf = File.ReadAllBytes(ffFile);
compiler.SetFfFileBuf(ffFileBuf);
}

#if DEBUG
//compiler.SetCompileSwitch("IDE");
//compiler.SetCompileSwitch("SkipPoint=R19:C30");
//compiler.SetCompileSwitch("SkipPoint=R60:C13");
#endif

if (!isXml)
{
Expand Down
2 changes: 1 addition & 1 deletion PMDDotNETConsole/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"PMDDotNETConsole": {
"commandName": "Project",
"commandLineArgs": "-LOGLEVEL=DEBUG -XML /V /c C:\\Users\\kuma\\Desktop\\pmd\\fromTAN-Y\\testTH_01.mml"
"commandLineArgs": "-LOGLEVEL=DEBUG /V /c D:\\bootcamp\\FM音源\\player\\pmd\\fromTAN-Y\\testORANGE04.MML"
}
}
}
10 changes: 9 additions & 1 deletion PMDDotNETDriver/PCMDRV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void pcmmain()
if (r.si == 0)
return;// goto pcmmain_ret;

if (r.si == pw.jumpIndex) pw.jumpIndex = -1;//KUMA:Added

Func<object> ret = null;
if (pw.partWk[r.di].partmask != 0)
ret = pcmmain_nonplay;
Expand Down Expand Up @@ -85,7 +87,13 @@ private Func<object> mp1m0()
{
do
{
r.al = (byte)pw.md[r.si++].dat;
r.al = (byte)pw.md[r.si].dat;

if (r.si == pw.jumpIndex)
pw.jumpIndex = -1;//KUMA:Added

r.si++;

if (r.al < 0x80) goto mp2m;
if (r.al == 0x80) goto mp15m;

Expand Down
7 changes: 6 additions & 1 deletion PMDDotNETDriver/PCMDRV86.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ private Func<object> mp1m0()
{
do
{
r.al = (byte)pw.md[r.si++].dat;
r.al = (byte)pw.md[r.si].dat;

if (r.si == pw.jumpIndex)
pw.jumpIndex = -1;//KUMA:Added

r.si++;
if (r.al < 0x80) goto mp2m;
if (r.al == 0x80) goto mp15m;

Expand Down
Loading

0 comments on commit efc649f

Please sign in to comment.