private static int[] GetPointers(bool load) { var labels = Asar.getlabels(); bool set = false; int[] output = new int[4] { -1, -1, -1, -1 }; foreach (var label in labels) { switch (label.Name.ToLower()) { case "init": output[0] = label.Location; set = true; break; case "main": output[1] = label.Location; set = true; break; case "nmi": output[2] = label.Location; set = true; break; case "load": if (load) { output[3] = label.Location; set = true; } break; } } return(set ? output : null); }
private static void BuildLibrary() { if (config.VerboseMode) { Console.WriteLine("Building external library..."); Console.WriteLine(); } int fileCount = 0; bool binaryMode = false; var files = Directory.GetFiles("library/", "*.asm", SearchOption.AllDirectories); string fullPath = Path.GetFullPath("library/"); repeat: foreach (var asmFile in files) { int start; int end; string baseFolder = Path.GetDirectoryName(asmFile) + "/"; string fileName = Path.GetFileName(asmFile); string fileNameExt = Path.GetFileNameWithoutExtension(asmFile); string fullFilePath = Path.GetFullPath(asmFile); string labelLevel = fullFilePath.Substring(fullPath.Length) .Replace(" ", "_").Replace("/", "_").Replace("\\", "_"); int s = labelLevel.LastIndexOf('.'); if (config.VerboseMode && binaryMode) { Console.WriteLine("Processing binary file '{0}':", fileName); } else if (config.VerboseMode) { Console.WriteLine("Processing file '{0}':", fileName); } if (s != -1) { labelLevel = labelLevel.Substring(0, s); } if (!binaryMode) { if (!CompileFile(File.ReadAllText(asmFile), baseFolder, fileName, "library", false, out start, out end, false, null)) { return; } } else { string baseAssembly = labelLevel + ":\r\nincbin \"" + fileName + "\"\r\n"; if (!CompileFile(baseAssembly, baseFolder, fileName, "library", false, out start, out end, false, null)) { return; } } if (config.VerboseMode) { Console.WriteLine(" Inserted at ${0:X6} (PC: 0x{1:x})", start, SNES.ToPCHeadered(start, rom.containsHeader)); Console.WriteLine(" Insert size: {0} (0x{0:X}) bytes", end - start + 8); } totalInsertSize += end - start + 8; var labels = Asar.getlabels().ToList(); int copyl = 0; for (int i = 0; i < labels.Count; ++i) { if (labels[i].Name != labelLevel) { var copy = labels[i]; copy.Name = labelLevel + "_" + copy.Name; labels[i] = copy; } if (labelList.Any(x => x.Name == labels[i].Name)) { Console.WriteLine(" {0} - error: label redefinition [{1}].", fileName, labels[i].Name); error = true; return; } if (!labels[i].Name.Contains(":")) { labelList.Add(labels[i]); copyl++; } if (labels[i].Location >= end || labels[i].Location < start) { labels.RemoveAt(i); --i; } } if (config.VerboseMode) { if (copyl == 1) { Console.WriteLine(" Processed one label."); } else { Console.WriteLine(" Processed {0} labels.", copyl); } } if (labels.Count == 0) { Console.WriteLine(" {0}: error: file contains no label within freespace area.", fileName); error = true; return; } if (!protPointerList.Contains(labels[0].Location)) { protPointerList.Add(labels[0].Location); } else { Console.WriteLine(" {0}: wtf error: Library included file is already protected.", fileName); error = true; return; } if (config.VerboseMode) { Console.WriteLine(); } fileCount++; } if (!binaryMode) { binaryMode = true; files = Directory.GetFiles("library/", "*.*", SearchOption.AllDirectories) .Where(x => !x.EndsWith(".asm", StringComparison.InvariantCultureIgnoreCase)).ToArray(); goto repeat; } if (fileCount == 0) { return; } if (fileCount == 1 && config.VerboseMode) { Console.WriteLine("Processed one library file."); } else if (config.VerboseMode) { Console.WriteLine("Processed {0} library files.", fileCount); } }