1
0
mirror of https://github.com/fadden/6502bench.git synced 2025-02-18 08:30:28 +00:00

Add simple SGEC reader

SourceGen Edit Commands is a feature that allows you to generate
commands into a file and have SourceGen apply them to the current
project.  I'm not expecting this to be used by anyone but me, so
for now I'm just adding an entry to the debug menu that can read
comments out of a file.

Also, fixed a bug in the re-centering min/max code that prevented
it from working on trivial shapes.

Also, renamed the atari-avg visualizer to atari-avg-bz, with the
expectation that one day somebody might want to create a variant
for newer games.
This commit is contained in:
Andy McFadden 2020-04-13 17:33:34 -07:00
parent 7cdc2d5b92
commit 6d582c80d3
7 changed files with 93 additions and 5 deletions

View File

@ -4187,7 +4187,7 @@ namespace SourceGen {
string basPathName = Path.GetFullPath(fileDlg.FileName);
try {
data = File.ReadAllBytes(basPathName);
} catch (Exception ex) {
} catch (IOException ex) {
// not expecting this to happen
MessageBox.Show(ex.Message);
return;
@ -4201,6 +4201,66 @@ namespace SourceGen {
showTextDlg.ShowDialog();
}
public void Debug_ApplyEditCommands() {
OpenFileDialog fileDlg = new OpenFileDialog() {
Filter = Res.Strings.FILE_FILTER_SGEC + "|" + Res.Strings.FILE_FILTER_ALL,
FilterIndex = 1
};
if (fileDlg.ShowDialog() != true) {
return;
}
string sgecPathName = Path.GetFullPath(fileDlg.FileName);
string[] lines;
try {
lines = File.ReadAllLines(sgecPathName);
} catch (IOException ex) {
// not expecting this to happen
MessageBox.Show(ex.Message);
return;
}
ChangeSet cs = new ChangeSet(1);
List<int> changed = new List<int>(lines.Length);
string setComment = "set-comment +";
foreach (string line in lines) {
if (!line.StartsWith(setComment)) {
Debug.WriteLine("Ignoring " + line);
continue;
}
int offset;
try {
offset = Convert.ToInt32(line.Substring(setComment.Length, 6), 16);
} catch (Exception ex) {
Debug.WriteLine("Failed on " + line);
MessageBox.Show(ex.Message);
return;
}
if (changed.Contains(offset)) {
Debug.WriteLine("Skipping repeated entry +" + offset.ToString("X6"));
continue;
}
string oldComment = mProject.Comments[offset];
string newComment = line.Substring(setComment.Length + 7);
if (!string.IsNullOrEmpty(oldComment)) {
Debug.WriteLine("Replacing comment +" + offset.ToString("x6") +
" '" + oldComment + "'");
}
UndoableChange uc = UndoableChange.CreateCommentChange(offset,
oldComment, newComment);
cs.Add(uc);
changed.Add(offset);
}
ApplyUndoableChanges(cs);
}
public void Debug_ApplyPlatformSymbols() {
ChangeSet cs = new ChangeSet(1);

View File

@ -90,6 +90,7 @@ limitations under the License.
<system:String x:Key="str_FileFilterCsv">CSV files (*.csv)|*.csv</system:String>
<system:String x:Key="str_FileFilterDis65">SourceGen projects (*.dis65)|*.dis65</system:String>
<system:String x:Key="str_FileFilterHtml">HTML files (*.html)|*.html</system:String>
<system:String x:Key="str_FileFilterSgec">SGEC files (*.sgec)|*.sgec</system:String>
<system:String x:Key="str_FileFilterSym65">SourceGen symbols (*.sym65)|*.sym65</system:String>
<system:String x:Key="str_FileFilterText">Text files (*.txt)|*.txt</system:String>
<system:String x:Key="str_FileInfoFmt">File is {0:N1} KB of raw data.</system:String>

View File

@ -161,6 +161,8 @@ namespace SourceGen.Res {
(string)Application.Current.FindResource("str_FileFilterDis65");
public static string FILE_FILTER_HTML =
(string)Application.Current.FindResource("str_FileFilterHtml");
public static string FILE_FILTER_SGEC =
(string)Application.Current.FindResource("str_FileFilterSgec");
public static string FILE_FILTER_SYM65 =
(string)Application.Current.FindResource("str_FileFilterSym65");
public static string FILE_FILTER_TEXT =

View File

@ -41,7 +41,7 @@ namespace RuntimeData.Atari {
private AddressTranslate mAddrTrans;
// Visualization identifiers; DO NOT change or projects that use them will break.
private const string VIS_GEN_AVG = "atari-avg";
private const string VIS_GEN_AVG = "atari-avg-bz"; // Battlezone, Red Baron
private const string P_OFFSET = "offset";
private const string P_BASE_ADDR = "baseAddr";
@ -55,7 +55,7 @@ namespace RuntimeData.Atari {
new VisParamDescr("Base address",
P_BASE_ADDR, typeof(int), 0x0000, 0xffff, 0, 0x2000),
VisWireframe.Param_IsRecentered("Re-center", true),
VisWireframe.Param_IsRecentered("Centered", true),
}),
};
@ -274,6 +274,13 @@ namespace RuntimeData.Atari {
return (short)val13 >> 3;
}
/// <summary>
/// Converts a JSR/JMP operand to a file offset.
/// </summary>
/// <param name="vaddr">AVG address operand.</param>
/// <param name="baseAddr">Base address of vector memory.</param>
/// <param name="offset">File offset of instruction.</param>
/// <returns>False if the target address is outside the file bounds.</returns>
private bool Branch(int vaddr, int baseAddr, ref int offset) {
int fileAddr = baseAddr + vaddr * 2;
int fileOffset = mAddrTrans.AddressToOffset(offset, fileAddr);

View File

@ -86,6 +86,8 @@ namespace SourceGen {
}
}
public bool VerboseDebug { get; set; }
private bool mIs2d = false;
private List<Vertex> mVertices = new List<Vertex>();
private List<Vertex> mPoints = new List<Vertex>();
@ -257,12 +259,14 @@ namespace SourceGen {
ref double ymin, ref double ymax) {
if (vert.Vec.X < xmin) {
xmin = vert.Vec.X;
} else if (vert.Vec.X > xmax) {
}
if (vert.Vec.X > xmax) {
xmax = vert.Vec.X;
}
if (vert.Vec.Y < ymin) {
ymin = vert.Vec.Y;
} else if (vert.Vec.Y > ymax) {
}
if (vert.Vec.Y > ymax) {
ymax = vert.Vec.Y;
}
}
@ -291,6 +295,11 @@ namespace SourceGen {
/// [-1,1].</returns>
public List<LineSeg> Generate(int eulerX, int eulerY, int eulerZ,
bool doPersp, bool doBfc, bool doRecenter) {
if (VerboseDebug) {
Debug.WriteLine("Found center=" + mCenterAdjX + "," + mCenterAdjY);
Debug.WriteLine(" bigMag=" + mBigMag + " / " + mBigMagRc);
}
// overrule flags that don't make sense
if (mIs2d) {
doPersp = doBfc = false;

View File

@ -192,6 +192,7 @@ limitations under the License.
</RoutedUICommand>
<RoutedUICommand x:Key="Debug_ApplesoftToHtmlCmd" Text="Applesoft to HTML..."/>
<RoutedUICommand x:Key="Debug_ApplyEditCommandsCmd" Text="Apply Edit Commands..."/>
<RoutedUICommand x:Key="Debug_ApplyPlatformSymbolsCmd" Text="Apply Platform Symbols"/>
<RoutedUICommand x:Key="Debug_ExtensionScriptInfoCmd" Text="Extension Script Info..."/>
<RoutedUICommand x:Key="Debug_ShowAnalysisTimersCmd" Text="Show Analysis Timers"/>
@ -323,6 +324,8 @@ limitations under the License.
Executed="Debug_ApplesoftToHtmlCmd_Executed"/>
<CommandBinding Command="{StaticResource Debug_ApplyPlatformSymbolsCmd}"
CanExecute="IsProjectOpen" Executed="Debug_ApplyPlatformSymbolsCmd_Executed"/>
<CommandBinding Command="{StaticResource Debug_ApplyEditCommandsCmd}"
CanExecute="IsProjectOpen" Executed="Debug_ApplyEditCommandsCmd_Executed"/>
<CommandBinding Command="{StaticResource Debug_ExtensionScriptInfoCmd}"
CanExecute="IsProjectOpen" Executed="Debug_ExtensionScriptInfoCmd_Executed"/>
<CommandBinding Command="{StaticResource Debug_ShowAnalysisTimersCmd}"
@ -439,6 +442,7 @@ limitations under the License.
Command="{StaticResource Debug_ToggleKeepAliveHackCmd}" IsCheckable="True"/>
<Separator/>
<MenuItem Command="{StaticResource Debug_ApplesoftToHtmlCmd}"/>
<MenuItem Command="{StaticResource Debug_ApplyEditCommandsCmd}"/>
<MenuItem Command="{StaticResource Debug_ApplyPlatformSymbolsCmd}"/>
</MenuItem>
</Menu>

View File

@ -1362,6 +1362,11 @@ namespace SourceGen.WpfGui {
mMainCtrl.Debug_ApplesoftToHtml();
}
private void Debug_ApplyEditCommandsCmd_Executed(object sender,
ExecutedRoutedEventArgs e) {
mMainCtrl.Debug_ApplyEditCommands();
}
private void Debug_ApplyPlatformSymbolsCmd_Executed(object sender,
ExecutedRoutedEventArgs e) {
mMainCtrl.Debug_ApplyPlatformSymbols();