82 lines
3.3 KiB
C#
82 lines
3.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
|
|
namespace rshw2sst
|
|
{
|
|
public class Program
|
|
{
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("mitzifier RSHW converter");
|
|
if (args[0] == "help")
|
|
{
|
|
Console.WriteLine("Usage: mitzifier <file path> <output directory>\n"
|
|
+ "This will output a SST showtape for use with the Mitzi/Helen firmware and player only\n"
|
|
);
|
|
}
|
|
if (!File.Exists(args[0]))
|
|
{
|
|
Console.WriteLine("FATAL: Specified file does not exist.");
|
|
return;
|
|
}
|
|
if (!Directory.Exists(args[1])) Directory.CreateDirectory(args[1]);
|
|
RSHWFile file = RSHWLoader.Load(args[0]);
|
|
if (file.signalData == null)
|
|
{
|
|
Console.WriteLine("FATAL: This file contains no signal data.");
|
|
return;
|
|
}
|
|
if (file.audioData != null) File.WriteAllBytes(args[1] + "/audio_out.wav", file.audioData);
|
|
if (file.videoData != null) File.WriteAllBytes(args[1] + "/video_out.mp4", file.videoData);
|
|
Console.WriteLine("Wrote out audio and video data.");
|
|
|
|
List<BitArray> rshwBits = new List<BitArray>();
|
|
int countlength = 0;
|
|
if (file.signalData[0] != 0)
|
|
{
|
|
countlength = 1;
|
|
BitArray bit = new BitArray(300);
|
|
rshwBits.Add(bit);
|
|
}
|
|
for (int i = 0; i < file.signalData.Length; i++)
|
|
{
|
|
if (file.signalData[i] == 0)
|
|
{
|
|
countlength += 1;
|
|
BitArray bit = new BitArray(300);
|
|
rshwBits.Add(bit);
|
|
}
|
|
else
|
|
{
|
|
rshwBits[countlength - 1].Set(file.signalData[i], true);
|
|
}
|
|
}
|
|
Console.WriteLine("Loaded RSHW signal data.");
|
|
|
|
List<string> writeOut = new List<string>();
|
|
int hfb = 0;
|
|
foreach (BitArray bits in rshwBits)
|
|
{
|
|
int frameByte = 0;
|
|
for (int i = 0; i < 19; i++)
|
|
{
|
|
if (bits.Get(targetBits[i])) frameByte += 1 << i;
|
|
}
|
|
if (frameByte > hfb) hfb = frameByte;
|
|
writeOut.Add(frameByte.ToString("X8"));
|
|
}
|
|
File.WriteAllLines(args[1] + "/signals_out.mts", writeOut.ToArray());
|
|
Console.WriteLine("Wrote out signal data.");
|
|
|
|
File.WriteAllText(args[1] + "/manifest.ini", $"; Exported by Mitzifier\nname={Path.GetFileNameWithoutExtension(args[0])} Helen/Mitzi \nvideo=video_out.mp4\naudio=audio_out.wav\ndata=signals_out.mts\nframes-per-second=60\nbits-per-frame=32");
|
|
Console.WriteLine("Wrote out manifest.");
|
|
if (file.videoData == null) Console.WriteLine("Warning: Video data was blank, you will need to add the file manually.");
|
|
Console.WriteLine("Complete!");
|
|
Console.WriteLine("Highest frame byte was " + hfb.ToString("B32"));
|
|
}
|
|
|
|
public static int[] targetBits = { 168, 169, 170, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188 };
|
|
}
|
|
}
|