using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; using TriCNES.mappers; namespace TriCNES { public partial class TASProperties3ct : Form { public TASProperties3ct() { InitializeComponent(); FormClosing += TASProperties_Closing; } private void TASProperties_Closing(Object sender, FormClosingEventArgs e) { if (MainGUI != null) { MainGUI.TASPropertiesForm3ct = null; } Dispose(); } public string TasFilePath; public ushort[] TasInputLog; public TriCNESGUI MainGUI; public byte GetPPUClockPhase() { return (byte)cb_ClockAlignment.SelectedIndex; } public byte GetCPUClockPhase() { return (byte)cb_CpuClock.SelectedIndex; } public bool FromRESET() { return rb_FromRES.Checked; } public Cartridge[] CartridgeArray; public void Init() { tb_FilePath.Text = TasFilePath; cb_ClockAlignment.SelectedIndex = 0; cb_ClockAlignment.Update(); cb_CpuClock.SelectedIndex = 0; cb_CpuClock.Update(); rb_FromPOW.Checked = true; rb_FromPOW.Update(); } Cartridge BackupCart; private void b_RunTAS_Click(object sender, EventArgs e) { if (rb_FromPOW.Checked) { int i = 0; while (i < CartridgeArray.Length) { CartridgeArray[i].PRGRAM = new byte[0x2000]; if (CartridgeArray[i].UsingCHRRAM) { if ((64 << CartridgeArray[i].ROM[11]) == 0) { CartridgeArray[i].CHRROM = new byte[0x2000]; // Default to 0x2000 bytes of CHR RAM. } else { CartridgeArray[i].CHRROM = new byte[64 << CartridgeArray[i].ROM[11]]; // 0x2000 bytes of CHR ROM, multiplied by byte 5 of the iNES header. } } Mapper MapperChip = Cartridge.SetMapper(CartridgeArray[i].MemoryMapper); MapperChip.Cart = CartridgeArray[i]; CartridgeArray[i].MapperChip = MapperChip; i++; } } MainGUI.Start3CTTAS(); } public List CyclesToSwapOn; public List CartsToSwapIn; private void b_LoadCartridges_Click(object sender, EventArgs e) { bool error = false; // check if rom folder is empty string Dir = AppDomain.CurrentDomain.BaseDirectory; if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"roms\")) { Dir += @"roms\"; if(Directory.GetFiles(Dir).Length == 0) { MessageBox.Show("Loading a .3ct TAS requires your roms to be located in the TriCNES roms folder."); return; } } // rom folder isn't empty! StringReader SR = new StringReader(File.ReadAllText(tb_FilePath.Text)); string l = SR.ReadLine(); int count = int.Parse(l); CartridgeArray = new Cartridge[count]; int i = 0; while(i < count) { l = SR.ReadLine(); if(File.Exists(Dir+l)) { if(i ==0) { BackupCart = new Cartridge(Dir + l); } if (MainGUI.EMU != null && MainGUI.EMU.Cart.Name == (Dir + l)) { CartridgeArray[i] = MainGUI.EMU.Cart; // If running a TAS from RESET, we want to use the currently loaded cartridge } else { CartridgeArray[i] = new Cartridge(Dir + l); } } else { MessageBox.Show("TriCNES roms folder is missing a required ROM for this TAS!\n\nMissing ROM: \"" + l + "\""); return; } i++; } // if all carts are now loaded. // let's also prepare the cycles to swap on, and the carts to swap in CyclesToSwapOn = new List(); CartsToSwapIn = new List(); l = SR.ReadLine(); while (l != null) { // the format here is: //x y //x and y could be any length, but there's a space between them. string s = l.Substring(0, l.IndexOf(" ")); CyclesToSwapOn.Add(int.Parse(s)); s = l.Remove(0,s.Length+1); CartsToSwapIn.Add(int.Parse(s)); l = SR.ReadLine(); } b_RunTAS.Enabled = true; } } }