public string ToString(string tableName) { ASMCodeBuilder code = new ASMCodeBuilder(); code.AppendLabel(tableName); foreach (var item in _entries) { code.AppendCode(item.ToString()); } return(code.ToString()); }
public string Code() { ASMCodeBuilder code = new ASMCodeBuilder(); code.AppendLabel(Name); foreach (var entry in _entries) { code.AppendCode(entry.ToString()); } return(code.ToString()); }
public override string ToString() { ASMCodeBuilder code = new ASMCodeBuilder(); if (Name == "") { code.AppendLabel("Table" + GetHashCode().ToString("X")); } else { code.AppendLabel(Name); } foreach (var item in _entries) { code.AppendCode(item.ToString()); } return(code.ToString()); }
public override string Code(int channel, HDMATable table, bool SA1) { Setup(); ASMCodeBuilder CodeBuilder = new ASMCodeBuilder(); if (Values.Count == 1 && Values[0].Scanline == Scanlines) { CodeBuilder.AppendLabel(MAINLabel, "Caution, not INIT"); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("LDA #$" + table[0].Values[0].ToString("X2"), "pixelise BGs"); CodeBuilder.AppendCode("STA $" + Registers.Pixelation.ToString("X4")); CodeBuilder.AppendCode("RTS", "Return"); CodeBuilder.CloseBlock(); return(CodeBuilder.ToString()); } int channelAdd = 16 * channel; CodeBuilder.AppendLabel(INITLabel, "Code to be put in INIT ASM"); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("\tREP #$20"); CodeBuilder.AppendCode("\tLDA #$" + ((Registers.Pixelation & 0xFF) << 8).ToString("X4")); CodeBuilder.AppendCode("\tSTA $" + (Registers.DMAMode + channelAdd).ToString("X4")); CodeBuilder.AppendCode("\tLDA #" + table.Name); CodeBuilder.AppendCode("\tSTA $" + (Registers.DMALowByte + channelAdd).ToString("X4")); CodeBuilder.AppendCode("\tLDY.b #" + table.Name + ">>16"); CodeBuilder.AppendCode("\tSTY $" + (Registers.DMABankByte + channelAdd).ToString("X4")); CodeBuilder.AppendCode("\tSEP #$20"); CodeBuilder.AppendCode("\tLDA #$" + (1 << channel).ToString("X2")); CodeBuilder.AppendCode("\tTSB $" + RAM.HDMAEnable[SA1].ToString("X4")); CodeBuilder.AppendCode("\tRTS"); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.AppendTable(table); return(CodeBuilder.ToString()); //return PixelationHDMA.Code(channel, table, SA1); }
/// <summary> /// Generates the code for the desired effect /// </summary> /// <param name="channel"></param> /// <param name="table"></param> /// <param name="sa1"></param> /// <returns></returns> public override string Code(int channel, HDMATable table, bool sa1) { int Base = 0x4300 + (channel * 0x10); int Register = (int)Layers; int BaseAddress = RAM.Layer1X[sa1] + ((int)Layers - (int)LayerRegister.Layer1_X) * 2; int RegMode = ((Register & 0xFF) << 8) + 0x02; int LSRs = (int)((1.0 / _speed) / 2.0); int Tablesize = (Scanlines / _width) >= 15 ? 15 : (Scanlines / _width); int TableInRAM = CountRAMBytes(); string tableString = "The Table takes up " + TableInRAM + " bytes of the free RAM\n" + "It ranges from $" + FreeRAM.ToString("X6") + " - $" + (FreeRAM + TableInRAM - 1).ToString("X6") + " (both addresses included)"; ASMTable codeTable = new ASMTable(".WaveTable"); for (int i = 0; i <= Tablesize; i++) { codeTable.Add(new ASMTableEntry((byte)_IArr[i])); } char xy = (((int)Layers & 0x01) == 0 ? 'Y' : 'X'); ASMCodeBuilder CodeBuilder = new ASMCodeBuilder(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendLabel(INITLabel, "This section is to be used in the INIT code of levelASM"); CodeBuilder.AppendCode("REP #$20"); CodeBuilder.AppendCode("LDA #$" + RegMode.ToASMString(), "Use Mode 02 on register " + Register.ToASMString()); CodeBuilder.AppendCode("STA $" + Base.ToASMString(), "43" + Channel + "0 = Mode, 43" + Channel + "1 = Register"); CodeBuilder.AppendCode("LDA #$" + (FreeRAM & 0xFFFF).ToASMString(), "Address of HDMA table"); CodeBuilder.AppendCode("STA $" + (Base + 2).ToASMString(), "43" + Channel + "2 = Low-Byte of table, 43" + Channel + "3 = High-Byte of table"); CodeBuilder.AppendCode("SEP #$20"); CodeBuilder.AppendCode("LDA.b #$" + (FreeRAM >> 16).ToASMString(), "Address of HDMA table, get bank byte"); CodeBuilder.AppendCode("STA $" + (Base + 4).ToASMString(), "43" + Channel + "4 = Bank-Byte of table"); CodeBuilder.AppendCode("LDA #$" + (0x01 << Channel).ToASMString()); CodeBuilder.AppendCode("TSB $" + RAM.HDMAEnable[sa1].ToASMString(), "Enable HDMA channel " + Channel); CodeBuilder.AppendCode("RTS", "End HDMA setup" + MAINSeperator); CodeBuilder.CloseBlock(); CodeBuilder.AppendCommentLine(tableString); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendLabel(MAINLabel, "This section is to be used in the MAIN code of levelASM"); CodeBuilder.AppendCode("LDY #$00", "Y will be the loop counter."); CodeBuilder.AppendCode("LDX #$00", "X the index for writing the table to the RAM"); CodeBuilder.AppendCode("LDA $" + RAM.FrameCounter[sa1].ToASMString(), "Speed of waves"); CodeBuilder.AppendCode("LSR #" + LSRs, "Slowing down A"); CodeBuilder.AppendCode("STA $00", "Save for later use."); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("PHB : PHK : PLB", "Preservev bank"); CodeBuilder.AppendLabel(".Loop", "Jump back if not finished writing table"); CodeBuilder.AppendCode("LDA #$" + _width.ToASMString(), "Set scanline height"); CodeBuilder.AppendCode("STA $" + FreeRAM.ToASMString() + ",x", "for each wave"); CodeBuilder.AppendCode("TYA", "Transfer Y to A, to calculate next index"); CodeBuilder.AppendCode("ADC $00", "Add frame counter"); CodeBuilder.AppendCode("AND #$" + Tablesize.ToASMString()); CodeBuilder.AppendCode("PHY", "Preserve loop counter"); CodeBuilder.AppendCode("TAY", "Get the index in Y"); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("LDA.w " + codeTable.Name + ",y", "Load in wave value"); CodeBuilder.AppendCode("LSR", "Half only"); CodeBuilder.AppendCode("CLC", "Clear Carry for addition"); CodeBuilder.AppendCode("ADC $" + (BaseAddress).ToASMString(), "Add value to layer " + xy + " position (low byte)"); CodeBuilder.AppendCode("STA $" + (FreeRAM + 1).ToASMString() + ",x", "store to HDMA table (low byte)"); CodeBuilder.AppendCode("LDA $" + (BaseAddress + 1).ToASMString(), "Get high byte of X position"); CodeBuilder.AppendCode("ADC #$00", "Add value to layer X position (low byte)"); CodeBuilder.AppendCode("STA $" + (FreeRAM + 2).ToASMString() + ",x", "store to HDMA table (high byte)"); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("PLY", "Pull original loop counter"); CodeBuilder.AppendCode("CPY #$" + (Scanlines / _width).ToASMString(), "Compare if we have written enough HDMA entries."); CodeBuilder.AppendCode("BPL .End", "If bigger, end HDMA"); CodeBuilder.AppendCode("INX", "Increase X, so that in the next loop, it writes the new table data..."); CodeBuilder.AppendCode("INX", "... at the end of the old one instead of overwritting it."); CodeBuilder.AppendCode("INX"); CodeBuilder.AppendCode("INY", "Increase loop counter"); CodeBuilder.AppendCode("BRA .Loop", "Repeat loop"); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendLabel(".End", "Jump here when at the end of HDMA"); CodeBuilder.AppendCode("PLB", "Pull back data bank."); CodeBuilder.AppendCode("LDA #$00", "End HDMA by writting 00..."); CodeBuilder.AppendCode("STA $" + (FreeRAM + 3).ToASMString() + ",x", "...at the end of the table."); CodeBuilder.AppendCode("RTS"); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendTable(codeTable); CodeBuilder.CloseBlock(); return(CodeBuilder.ToString()); // +"\n\n" + tableString; }
/// <summary> /// Calculates the code for overlapping multiple brightness gradients. /// <para>The final code will use the channel of the first BrightnessHDMA object passed.</para> /// </summary> /// <param name="hdma">An array of BrightnessHDMA object that will be overlapped for the final code.</param> /// <returns>The final code.</returns> public static string MultiCode(params BrightnessHDMA[] hdma) { if (hdma == null || hdma.Length == 0) { return(null); } int channel = hdma[0].Channel; EffectClasses.HDMATable table = new HDMATable(".BrightTable"); using (Bitmap b = BitmapEffects.OverlapImages(hdma.Select(h => h.EffectImage).ToArray())) { byte scanlines = 1; int now = 0; int compare = 0x0F - (b.GetPixel(0, 0).A / 17); for (int y = 1; y < b.Height; y++, scanlines++) { now = 0x0F - (b.GetPixel(0, y).A / 17); if (compare != now || scanlines >= 0x80) { table.Add(new HDMATableEntry(TableValueType.db, scanlines, (byte)compare)); compare = now; scanlines = 0; } } if (table.TotalScanlines != Scanlines) { table.Add(new HDMATableEntry(TableValueType.db, scanlines, (byte)now)); } table.Add(HDMATableEntry.End); DMAMode mode = (table[0].Values.Length == 1 ? DMAMode.P : DMAMode.PP); ASMCodeBuilder code = new ASMCodeBuilder(); int channelAdd = 16 * channel; table.Name = ".BrightTable"; code.AppendLabel(INITLabel, "Code to be inserted INIT"); code.OpenNewBlock(); code.AppendCode("\tREP #$20", "16 bit mode"); code.AppendCode("\tLDA #$" + (((Registers.Brightness & 0xFF) << 8) + (int)mode).ToString("X4")); code.AppendCode("\tSTA $" + (Registers.DMAMode + channelAdd).ToString("X4")); code.AppendCode("\tLDA #" + table.Name, "load high and low byte of table address"); code.AppendCode("\tSTA $" + (Registers.DMALowByte + channelAdd).ToString("X4")); code.AppendCode("\tSEP #$20", "back to 8 bit mode"); code.AppendCode("\tLDA.b #" + table.Name + ">>16", "load bank byte of table address"); code.AppendCode("\tSTA $" + (Registers.DMABankByte + channelAdd).ToString("X4")); code.AppendCode("\tLDA #$" + (1 << channel).ToString("X2")); code.AppendCode("\tTSB $" + RAM.HDMAEnable[RAM.SA1].ToString("X4"), "enable HDMA channel " + channel); code.AppendCode("\tRTS"); code.CloseBlock(); code.AppendEmptyLine(); code.AppendTable(table); return(code.ToString()); } }
/// <summary> /// Calculates the code for the Brightness HDMA with the desired channel, Table and possibly SA-1 compatible /// </summary> /// <param name="channel"></param> /// <param name="table"></param> /// <param name="sa1"></param> /// <returns></returns> public override string Code(int channel, HDMATable table, bool sa1) { DMAMode mode = (table[0].Values.Length == 1 ? DMAMode.P : DMAMode.PP); ASMCodeBuilder code = new ASMCodeBuilder(); int channelAdd = 16 * channel; table.Name = ".BrightTable"; code.AppendLabel(INITLabel, "Code to be inserted INIT"); code.OpenNewBlock(); code.AppendCode("\tREP #$20", "16 bit mode"); code.AppendCode("\tLDA #$" + (((Registers.Brightness & 0xFF) << 8) + (int)mode).ToString("X4")); code.AppendCode("\tSTA $" + (Registers.DMAMode + channelAdd).ToString("X4")); code.AppendCode("\tLDA #" + table.Name, "load high and low byte of table address"); code.AppendCode("\tSTA $" + (Registers.DMALowByte + channelAdd).ToString("X4")); code.AppendCode("\tSEP #$20", "back to 8 bit mode"); code.AppendCode("\tLDA.b #" + table.Name + ">>16", "load bank byte of table address"); code.AppendCode("\tSTA $" + (Registers.DMABankByte + channelAdd).ToString("X4")); code.AppendCode("\tLDA #$" + (1 << channel).ToString("X2")); code.AppendCode("\tTSB $" + RAM.HDMAEnable[sa1].ToString("X4"), "enable HDMA channel " + channel); code.AppendCode("\tRTS"); code.CloseBlock(); code.AppendEmptyLine(); code.AppendTable(table); return(code.ToString()); }
public override string Code(int channel, HDMATable table, bool sa1) { bool bothWindows = (Table.Any(t => (t.ValueType == TableValueType.db && (t.Values[2] != 0xFF || t.Values[3] != 0x00)))); int mode = GetMode(false, bothWindows ? DMAMode.PP1P2P3 : DMAMode.PP1); int register = Registers.WindowMask1Left; if (!bothWindows && OneWindowEvent != null) { OneWindowEventArgs e = new OneWindowEventArgs(Window.Window1); OneWindowEvent(this, e); if (e.Cancel) { return(""); } register += (int)e.Window; } if (!bothWindows) { foreach (HDMATableEntry entry in table) { if (entry.ValueType == TableValueType.db) { byte[] values = entry.Values; Array.Resize(ref values, 2); entry.Values = values; } } } int regmode = ((register & 0xFF) << 8) + mode; int baseChannel = 0x4300 + (channel * 0x10); ASMCodeBuilder code = new ASMCodeBuilder(); code.OpenNewBlock(); code.AppendCode("REP #$20", "Get into 16 bit mode"); code.AppendCode("LDA #$" + regmode.ToASMString(), "Register $" + register.ToASMString() + " using mode " + mode); code.AppendCode("STA $" + baseChannel.ToASMString(), baseChannel.ToASMString() + " = transfer mode, " + (baseChannel + 1).ToASMString() + " = register"); code.AppendCode("LDA #" + table.Name, "High byte and low byte of table addresse."); code.AppendCode("STA $" + (baseChannel + 2).ToASMString(), (baseChannel + 2).ToASMString() + " = low byte, " + (baseChannel + 3).ToASMString() + " = high byte"); code.AppendCode("SEP #$20", "Back to 8 bit mode"); code.AppendCode("LDA.b #" + table.Name + ">>16", "Bank byte of table addresse."); code.AppendCode("STA $" + (baseChannel + 4).ToASMString(), "= bank byte"); code.CloseBlock(); code.OpenNewBlock(); code.AppendCode("LDA #$" + (1 << channel).ToASMString()); code.AppendCode("TSB $" + RAM.HDMAEnable[sa1].ToASMString() + "|!addr", "enable HDMA channel " + channel); code.CloseBlock(); code.AppendCode("RTL", "Return"); code.AppendEmptyLine(); code.AppendTable(table); return(code.ToString()); }
public override string Code(int channel, HDMATable table, bool sa1) { int Base = 0x4300 + (channel * 0x10); int Register = (int)Layers; int BaseAddress = RAM.Layer1X[sa1] + ((int)Layers - (int)LayerRegister.Layer1_X) * 2; int RegMode = ((Register & 0xFF) << 8) + GetMode(true, DMAMode.PP); var grouped = Bars.GroupBy(b => b.Multiplier); HDMATable _table = new HDMATable("ParallaxTable_" + DateTime.Now.ToString("HHmmssfff")); int tableInRAM = grouped.Count() * 2; Dictionary <int, int> multiplierAddressMapping = new Dictionary <int, int>(); int addresseForOne = 0; //address that has the scrollrate of 1 to finish the table. string tableString = "The Table takes up " + tableInRAM + " bytes of the free RAM\n" + "It ranges from $" + FreeRAM.ToString("X6") + " - $" + (FreeRAM + tableInRAM - 1).ToString("X6") + " (both addresses included)"; ASMCodeBuilder CodeBuilder = new ASMCodeBuilder(); if (Original.Height > Scanlines) { CodeBuilder.AppendCommentLine("IMPORTANT! Please edit the JMP command below for the level you use this on"); } CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendLabel(INITLabel, "This section is to be used in the INIT code of levelASM"); CodeBuilder.AppendCode("REP #$20"); CodeBuilder.AppendCode("LDA #$" + RegMode.ToASMString(), "Use indeirect and mode " + (int)DMAMode.PP + " on register " + Register.ToASMString()); CodeBuilder.AppendCode("STA $" + Base.ToASMString(), "43" + Channel + "0 = Mode, 43" + Channel + "1 = Register"); if (Original.Height <= Scanlines) { CodeBuilder.AppendCode("LDA #" + _table.Name, "Address of HDMA table, get high and low byte"); CodeBuilder.AppendCode("STA $" + (Base + 2).ToASMString(), "43" + Channel + "2 = Low-Byte of table, 43" + Channel + "3 = High-Byte of table"); } CodeBuilder.AppendCode("SEP #$20"); CodeBuilder.AppendCode("LDA.b #" + _table.Name + ">>16", "Address of HDMA table, get bank byte"); CodeBuilder.AppendCode("STA $" + (Base + 4).ToASMString(), "43" + Channel + "4 = Bank-Byte of table"); CodeBuilder.AppendCode("LDA #$" + (FreeRAM >> 16).ToASMString(), "Address of indirect table in RAM bank byte"); CodeBuilder.AppendCode("STA $" + (Base + 7).ToASMString(), "43" + Channel + "4 = Bank-Byte of indirect table"); CodeBuilder.AppendCode("LDA #$" + (0x01 << Channel).ToASMString()); CodeBuilder.AppendCode("TSB $" + RAM.HDMAEnable[sa1].ToASMString() + "|!addr", "Enable HDMA channel " + Channel); if (Original.Height > Scanlines) { CodeBuilder.AppendCode("JMP level105_" + MAINLabel.TrimStart('.'), "Jump to main code" + MAINSeperator); } else { CodeBuilder.AppendCode("RTL", "Return" + MAINSeperator); } CodeBuilder.CloseBlock(); CodeBuilder.AppendCommentLine(tableString); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendLabel(MAINLabel, "This section is to be used in the MAIN code of levelASM"); CodeBuilder.AppendCode("REP #$20", "16 bit action starts here. (To load the x position of the BG)"); CodeBuilder.CloseBlock(); //index for HDMA table entry calculation if (Original.Height > Scanlines) { CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("LDA $" + (BaseAddress + 2).ToASMString(), "Get Y position of BG"); CodeBuilder.AppendCode("ASL", "times 2"); CodeBuilder.AppendCode("CLC : ADC $" + (BaseAddress + 2).ToASMString(), "+1 = times 3"); CodeBuilder.AppendCode("CLC : ADC #" + _table.Name + "+3", "plus Address of HDMA table +3"); //CodeBuilder.AppendCode("INC : INC : INC", "I have no idea why, but the result is off by 1 entry (3 bytes) so this is to fix it."); CodeBuilder.AppendCode("STA $" + (Base + 2).ToASMString(), "43" + Channel + "2 = Low-Byte of table, 43" + Channel + "3 = High-Byte of table"); CodeBuilder.CloseBlock(); } CodeBuilder.AppendEmptyLine(); int i = 0; //grouped by multiplier foreach (var bar in grouped) { CodeBuilder.OpenNewBlock(); if (bar.Key != 0.0) { CodeBuilder.AppendCode("LDA $" + BaseAddress.ToASMString(), "Load BG x Position"); } CodeBuilder.AppendCode(ParallaxHDMAEntry.LsrAsl(bar.Key), "Multiplied by " + bar.Key); var windGroup = bar.GroupBy(b => b.Autospeed); foreach (var singleBar in windGroup) { //if there is no wind, don't add or preserve A if (singleBar.ElementAt(0).Autoscroll&& singleBar.Key != 0) { CodeBuilder.AppendCode("PHA", "Preserve A (current multiplication result)"); CodeBuilder.AppendCode("CLC : ADC #$" + singleBar.Key.ToString("X4"), "Add rate."); } CodeBuilder.AppendCode("STA $" + (FreeRAM + i).ToASMString(), "Store to FreeRAM for indirect HDMA"); //also don't restore A if there is no wind. if (singleBar.ElementAt(0).Autoscroll&& singleBar.Key != 0) { CodeBuilder.AppendCode("PLA", "Restore A (current multiplication result)"); } //keep track of the address for normal scrolling behaviour (multiplier = 1, no auto scroll) if (bar.Key == 1.0 && singleBar.ElementAt(0).Autoscroll&& singleBar.Key != 0) { addresseForOne = FreeRAM + i; } //remember which address has this specs in dictionary with hashcode multiplierAddressMapping.Add(singleBar.ElementAt(0).GetHashCode(), FreeRAM + i); i += 2; } CodeBuilder.CloseBlock(); } //if the normal scrolling hasn't been set yet, make one. if (addresseForOne == 0) { CodeBuilder.OpenNewBlock(); CodeBuilder.AppendCode("LDA $" + BaseAddress.ToASMString(), "Load BG x Position"); CodeBuilder.AppendCode("STA $" + (FreeRAM + i).ToASMString(), "Store to FreeRAM for indirect HDMA"); CodeBuilder.CloseBlock(); addresseForOne = FreeRAM + i; i += 2; } //build the table foreach (var bar in Bars) { //fetch indirect HDMA address int adr = multiplierAddressMapping[bar.GetHashCode()] & 0xFFFF; //split it byte low = (byte)(adr & 0xFF); byte high = (byte)((adr >> 8) & 0xFF); //make as many 1 scanline high entries as needed. var entry = new HDMATableEntry(TableValueType.dw, 1, low, high); _table.AddRange(Enumerable.Repeat <HDMATableEntry>(entry, bar.Scanline)); } //if there aren't enough entries for the whole screen yet, fill it up with scrollrate 1. if (_table.Count < Original.Height) { //fetch indirect HDMA address for normal scrolling int adr = addresseForOne & 0xFFFF; //split it byte low = (byte)(adr & 0xFF); byte high = (byte)((adr >> 8) & 0xFF); var entry = new HDMATableEntry(TableValueType.dw, 1, low, high); _table.AddRange(Enumerable.Repeat <HDMATableEntry>(entry, Original.Height - _table.Count)); } //cut down table for (int l = _table.Count - 1; l >= Original.Height; l--) { _table.RemoveAt(l); } //add end. _table.Add(HDMATableEntry.End); CodeBuilder.AppendCode("SEP #$20", "Back to 8bit"); CodeBuilder.AppendCode("RTL", "Return"); CodeBuilder.CloseBlock(); CodeBuilder.AppendEmptyLine(); CodeBuilder.OpenNewBlock(); CodeBuilder.AppendTable(_table); CodeBuilder.CloseBlock(); return(CodeBuilder.ToString()); // +"\n\n" + tableString; }
public string Code() { ASMCodeBuilder sb = new ASMCodeBuilder(); sb.AppendLabel(HDMA.INITLabel); if (MainScreenDesignation != MainScreenWindowMaskDesignation || true) { sb.OpenNewBlock(); sb.AppendCode("LDA #$" + SumEnumFlag(MainScreenDesignation).ToASMString(), MainScreenDesignation.ToString() + " on main screen (TM)"); sb.AppendCode("STA $" + Registers.MainScreenDesignation.ToASMString()); sb.AppendCode("LDA #$" + SumEnumFlag(MainScreenWindowMaskDesignation).ToASMString(), MainScreenWindowMaskDesignation.ToString() + " on main screen should use windowing. (TMW)"); sb.AppendCode("STA $" + Registers.MainScreenWindow.ToASMString()); sb.CloseBlock(); } /*else * { * sb.OpenNewBlock(); * sb.AppendCode("LDA #$" + SumEnumFlag(MainScreenDesignation).ToASMString(), MainScreenDesignation.ToString() + " on main screen (TM) and window (TMW)"); * sb.AppendCode("STA $" + RAM.MainScreenAndWindowDesignation[RAM.SA1].ToASMString(), "mirror of $212C and $212E"); * sb.CloseBlock(); * }*/ if (SubScreenDesignation != SubScreenWindowMaskDesignation || true) { sb.OpenNewBlock(); sb.AppendCode("LDA #$" + SumEnumFlag(SubScreenDesignation).ToASMString(), SubScreenDesignation.ToString() + " on sub screen (TS)"); sb.AppendCode("STA $" + Registers.SubScreenDesignation.ToASMString()); sb.AppendCode("LDA #$" + SumEnumFlag(SubScreenWindowMaskDesignation).ToASMString(), SubScreenWindowMaskDesignation.ToString() + " on sub screen should use windowing. (TSW)"); sb.AppendCode("STA $" + Registers.SubScreenWindow.ToASMString()); sb.CloseBlock(); } /*else * { * sb.OpenNewBlock(); * sb.AppendCode("LDA #$" + SumEnumFlag(SubScreenDesignation).ToASMString(), SubScreenDesignation.ToString() + " on sub screen (TS) and window (TSW)"); * sb.AppendCode("STA $" + RAM.SubScreenAndWindowDesignation[RAM.SA1].ToASMString(), "mirror of $212D and $212F"); * sb.CloseBlock(); * }*/ sb.AppendCode("LDA #$" + SumEnumFlag(ColorMathDesignation).ToASMString(), ColorMathDesignation.ToString() + " for color math"); sb.AppendCode("STA $" + RAM.ColorMathSetting[RAM.SA1].ToASMString(), "mirror of $2131"); sb.CloseBlock(); if (!AddColor || ClipToBlack != 0 || PreventColorMath != 0) { sb.OpenNewBlock(); int CGWSEL = (((int)ClipToBlack) << 6) + (((int)PreventColorMath) << 4) + (AddColor ? 0 : 2); sb.AppendCode("LDA #$" + CGWSEL.ToASMString(), "Clip to black: " + ClipToBlack + ", Prevent colot math: " + PreventColorMath); sb.AppendCode("STA $" + RAM.ColorAdditionSelect[RAM.SA1].ToASMString(), "Add subscreen instead of fixed color: " + !AddColor); sb.CloseBlock(); } //mask logic if (MaskLogicBgs != 0) { sb.OpenNewBlock(); sb.AppendCode("LDA #$" + MaskLogicBgs.ToString("X2"), "Mask logic for overlapping windowing on BGs"); sb.AppendCode("STA $" + Registers.WindowingLogicBgs.ToASMString()); sb.CloseBlock(); } //mask logic if (MaskLogicObjCol != 0) { sb.OpenNewBlock(); sb.AppendCode("LDA #$" + MaskLogicObjCol.ToString("X2"), "Mask logic for overlapping windowing on BGs"); sb.AppendCode("STA $" + Registers.WindowingLogicObjColor.ToASMString()); sb.CloseBlock(); } int regW12SEL = (Window1Inverted.HasFlag(WindowingLayers.BG1) ? 0x01 : 0x00) + (Window1Enabled.HasFlag(WindowingLayers.BG1) ? 0x02 : 0x00) + (Window2Inverted.HasFlag(WindowingLayers.BG1) ? 0x04 : 0x00) + (Window2Enabled.HasFlag(WindowingLayers.BG1) ? 0x08 : 0x00) + (Window1Inverted.HasFlag(WindowingLayers.BG2) ? 0x10 : 0x00) + (Window1Enabled.HasFlag(WindowingLayers.BG2) ? 0x20 : 0x00) + (Window2Inverted.HasFlag(WindowingLayers.BG2) ? 0x40 : 0x00) + (Window2Enabled.HasFlag(WindowingLayers.BG2) ? 0x80 : 0x00); int regW34SEL = (Window1Inverted.HasFlag(WindowingLayers.BG3) ? 0x01 : 0x00) + (Window1Enabled.HasFlag(WindowingLayers.BG3) ? 0x02 : 0x00) + (Window2Inverted.HasFlag(WindowingLayers.BG3) ? 0x04 : 0x00) + (Window2Enabled.HasFlag(WindowingLayers.BG3) ? 0x08 : 0x00) + (Window1Inverted.HasFlag(WindowingLayers.BG4) ? 0x10 : 0x00) + (Window1Enabled.HasFlag(WindowingLayers.BG4) ? 0x20 : 0x00) + (Window2Inverted.HasFlag(WindowingLayers.BG4) ? 0x40 : 0x00) + (Window2Enabled.HasFlag(WindowingLayers.BG4) ? 0x80 : 0x00); int regWOBJSEL = (Window1Inverted.HasFlag(WindowingLayers.OBJ) ? 0x01 : 0x00) + (Window1Enabled.HasFlag(WindowingLayers.OBJ) ? 0x02 : 0x00) + (Window2Inverted.HasFlag(WindowingLayers.OBJ) ? 0x04 : 0x00) + (Window2Enabled.HasFlag(WindowingLayers.OBJ) ? 0x08 : 0x00) + (Window1Inverted.HasFlag(WindowingLayers.Color) ? 0x10 : 0x00) + (Window1Enabled.HasFlag(WindowingLayers.Color) ? 0x20 : 0x00) + (Window2Inverted.HasFlag(WindowingLayers.Color) ? 0x40 : 0x00) + (Window2Enabled.HasFlag(WindowingLayers.Color) ? 0x80 : 0x00); sb.OpenNewBlock(); if (regW12SEL != 0) { sb.AppendCode("LDA #$" + regW12SEL.ToASMString(), "values for enabling/inverting BG1/BG2 on window 1/2"); sb.AppendCode("STA $" + RAM.WindowMaskSettingBG1BG2[RAM.SA1].ToASMString(), "mirror of $2123"); } if (regW34SEL != 0) { if (regW34SEL != regW12SEL) //prevent LDA if A still has valid value from before { sb.AppendCode("LDA #$" + regW34SEL.ToASMString(), "values for enabling/inverting BG3/BG4 on window 1/2"); } sb.AppendCode("STA $" + RAM.WindowMaskSettingBG3BG4[RAM.SA1].ToASMString(), "mirror of $2124"); } if (regWOBJSEL != 0) { if (regWOBJSEL != regW34SEL) //prevent LDA if A still has valid value from before { sb.AppendCode("LDA #$" + regWOBJSEL.ToASMString(), "values for enabling/inverting OBJ/Color on window 1/2"); } sb.AppendCode("STA $" + RAM.WindowMaskSettingOBJColor[RAM.SA1].ToASMString(), "mirror of $2125"); } if (regW12SEL != 0 || regW34SEL != 0 || regWOBJSEL != 0) { sb.AppendComment("Window 1 enabled on " + Window1Enabled.ToString()); sb.AppendComment("Window 2 enabled on " + Window2Enabled.ToString()); sb.AppendComment("Window 1 inverted on " + Window1Inverted.ToString()); sb.AppendComment("Window 2 inverted on " + Window2Inverted.ToString()); } sb.CloseBlock(); return(sb.ToString()); }