예제 #1
0
 // MDRヘッダ再構築
 private void writeMDRHeader(List <MmlDatum2> destBuf, _mdr m)
 {
     // PCM設定値
     destBuf[m.header + 0x2a].dat = m.pcm_packed;
     destBuf[m.header + 0x30].dat = m.pcm_startadrs;
     destBuf[m.header + 0x31].dat = m.pcm_startbank;
     destBuf[m.header + 0x32].dat = m.pcm_banks;
     destBuf[m.header + 0x33].dat = m.pcm_lastsize;
 }
예제 #2
0
        public List <MmlDatum2> Pack(List <MmlDatum2> destBuf, string mdrFn, string pcmFn = "")
        {
            string pcmfile = null;
            string mdrfile;

            // タイトル
            Log.WriteLine(LogLevel.INFO, string.Format("{0} {1} by {2}", PRG_NAME, PRG_VER, PRG_AUTHOR));

            mdrfile = mdrFn;
            Log.WriteLine(LogLevel.INFO, string.Format("File:{0}", mdrfile));
            if (!string.IsNullOrEmpty(pcmFn))
            {
                pcmfile = pcmFn;
            }

            _mdr m = new _mdr();

            readMDRHeader(destBuf, mdrfile, ref m);

            Log.WriteLine(LogLevel.INFO, string.Format("Size:{0}", m.size));

            if (string.IsNullOrEmpty(pcmfile))
            {
                if (!string.IsNullOrEmpty(m.pcmname))
                {
                    pcmfile = Path.GetDirectoryName(mdrfile);
                    pcmfile = Path.Combine(pcmfile, m.pcmname);
                }
            }

            if (string.IsNullOrEmpty(pcmfile))
            {
                Log.WriteLine(LogLevel.INFO, "PCM filename is not defined!");
                return(destBuf);
            }

            Log.WriteLine(LogLevel.INFO, string.Format("PCM File:{0}", pcmfile));

            // PCMを詰め込む
            return(packPCMintoMDR(destBuf, mdrfile, pcmfile, ref m));
        }
예제 #3
0
        // MDRファイル読み出し
        private int readMDRHeader(List <MmlDatum2> destBuf, string file, ref _mdr m)
        {
            try
            {
                m.size = destBuf.Count;

                // PCM文字列位置
                m.pcmname = "";
                int pcmpos = destBuf[m.header + 0x2c].dat + destBuf[m.header + 0x2d].dat * 0x100;

                // PCM位置
                if (pcmpos == 0x8040)
                {
                    byte[] fn = new byte[0x40];
                    for (int i = 0; i < 0x40; i++)
                    {
                        fn[i] = (byte)destBuf[m.header + i].dat;
                    }
                    Common.myEncoding enc = new Common.myEncoding();
                    m.pcmname = enc.GetStringFromSjisArray(fn);
                }

                // PCM設定値
                m.pcm_packed    = destBuf[m.header + 0x2a].dat;
                m.pcm_startadrs = destBuf[m.header + 0x30].dat;
                m.pcm_startbank = destBuf[m.header + 0x31].dat;
                m.pcm_banks     = destBuf[m.header + 0x32].dat;
                m.pcm_lastsize  = destBuf[m.header + 0x33].dat;

                return(0);
            }
            catch
            {
                return(-1);
            }
        }
예제 #4
0
        // MDRファイル読み出し
        private List <MmlDatum2> packPCMintoMDR(List <MmlDatum2> destBuf, string file, string pcm, ref _mdr m)
        {
            if (string.IsNullOrEmpty(file))
            {
                return(destBuf);
            }
            if (string.IsNullOrEmpty(pcm))
            {
                return(destBuf);
            }

            byte[] bank = new byte[BANK_SIZE];
            Log.WriteLine(LogLevel.INFO, "packing...");

            int start_pos = m.size;

            // パックされている場合はPCM先頭バングから計算する
            if (m.pcm_packed != 0)
            {
                start_pos = m.pcm_startbank * BANK_SIZE;
            }

            byte[] pcmBuf;

            try
            {
                if (File.Exists(pcm))
                {
                    pcmBuf = File.ReadAllBytes(pcm);
                }
                else
                {
                    pcm    = Path.Combine(Path.GetDirectoryName(file), pcm);
                    pcmBuf = File.ReadAllBytes(pcm);
                }
            }
            catch
            {
                Log.WriteLine(LogLevel.ERROR, string.Format("File open error!:{0}", pcm));
                return(null);
            }

            // PCMデータ出力位置
            Log.WriteLine(LogLevel.INFO, string.Format("PCM Start:{0:X08}h", start_pos));
            m.fp = start_pos;

            int block_len  = 0;
            int pcm_blocks = 1;

            int i = 0;

            while (i < pcmBuf.Length)
            {
                MmlDatum2 md = new MmlDatum2("", pcmBuf[i]);
                destBuf.Insert(m.fp + i, md);
                i++;
                block_len++;
                if ((i % BANK_SIZE) == 0)
                {
                    pcm_blocks++;
                    block_len = 0;
                }
            }
            if (pcmBuf.Length > 0 && block_len == 0)
            {
                pcm_blocks--;
            }

            m.pcm_packed    = 1;
            m.pcm_startadrs = 0x20;                         // SRAM開始アドレス
            m.pcm_startbank = (int)(start_pos / BANK_SIZE); // 開始バンク
            m.pcm_banks     = pcm_blocks - 1;               // ブロック数
            m.pcm_lastsize  = (block_len + 0xff) / 0x100;   // 最後のブロックサイズ

            Log.WriteLine(LogLevel.INFO, string.Format("PCM StartAdrs:{0:x02}h", m.pcm_startadrs));
            Log.WriteLine(LogLevel.INFO, string.Format("PCM StartBank:{0:x02}h", m.pcm_startbank));
            Log.WriteLine(LogLevel.INFO, string.Format("PCM Banks:{0:x02}h", m.pcm_banks));
            Log.WriteLine(LogLevel.INFO, string.Format("PCM LastSize:{0:x02}h", m.pcm_lastsize));

            writeMDRHeader(destBuf, m);

            Log.WriteLine(LogLevel.INFO, "ok!");
            return(destBuf);
        }