Exemplo n.º 1
0
        public static string Code(ColorHDMA red, ColorHDMA green, ColorHDMA blue,
                                  PickSingleChannel single, PickMultiChannel multi, PickMultiChannel tripple)
        {
            bool redEmpty   = red.IsEmpty();
            bool greenEmpty = green.IsEmpty();
            bool blueEmpty  = blue.IsEmpty();

            if (redEmpty && blueEmpty && greenEmpty)
            {
                //fixme Exception
                throw new ArgumentException("Cannot generate code from the provided arguments");
            }

            if (redEmpty && blueEmpty)
            {
                return(green.Code(single()));
            }
            if (greenEmpty && blueEmpty)
            {
                return(red.Code(single()));
            }
            if (redEmpty && greenEmpty)
            {
                return(blue.Code(single()));
            }

            int[] newChannels = new int[] { 3, 4, 5 };
            Dictionary <string, HDMATable> dicTable = new Dictionary <string, HDMATable>();
            HDMATable merged = null;

            if (greenEmpty)
            {
                if (HDMATable.Merge(red.Table, blue.Table, out merged))
                {
                    return(ColorHDMA.Code(single(), merged, ".RedBlueTable"));
                }
                else
                {
                    newChannels = multi();
                    dicTable.Add(".RedTable", red.Table);
                    dicTable.Add(".BlueTable", blue.Table);
                }
            }
            else if (redEmpty)
            {
                if (HDMATable.Merge(green.Table, blue.Table, out merged))
                {
                    return(ColorHDMA.Code(single(), merged, ".GreenBlueTable"));
                }
                else
                {
                    newChannels = multi();
                    dicTable.Add(".GreenTable", green.Table);
                    dicTable.Add(".BlueTable", blue.Table);
                }
            }
            else if (blueEmpty)
            {
                if (HDMATable.Merge(green.Table, red.Table, out merged))
                {
                    return(ColorHDMA.Code(single(), merged, ".RedGreenTable"));
                }
                else
                {
                    newChannels = multi();
                    dicTable.Add(".GreenTable", green.Table);
                    dicTable.Add(".RedTable", red.Table);
                }
            }
            else
            {
                if (HDMATable.Merge(green.Table, red.Table, out merged))
                {
                    newChannels = multi();
                    dicTable.Add(".RedGreenTable", merged);
                    dicTable.Add(".BlueTable", blue.Table);
                }
                else if (HDMATable.Merge(green.Table, blue.Table, out merged))
                {
                    newChannels = multi();
                    dicTable.Add(".GreenBlueTable", merged);
                    dicTable.Add(".RedTable", red.Table);
                }
                else if (HDMATable.Merge(red.Table, blue.Table, out merged))
                {
                    newChannels = multi();
                    dicTable.Add(".RedBlueTable", merged);
                    dicTable.Add(".GreenTable", red.Table);
                }
                else
                {
                    newChannels = tripple();
                    dicTable.Add(".RedTable", red.Table);
                    dicTable.Add(".GreenTable", green.Table);
                    dicTable.Add(".BlueTable", blue.Table);
                }
            }

            if (dicTable.Count != newChannels.Length)
            {
                throw new ArgumentException("Number of channels doesn't match number of tables.");
            }

            Func <KeyValuePair <string, HDMATable>, string> getTablename = old => "." + old.Key.TrimStart('.');

            int           channelTrigger = 0;
            StringBuilder sbCode         = new StringBuilder();

            //sbCode.AppendLine("init:");
            sbCode.AppendLine("\tREP #$20");

            for (int i = 0; i < dicTable.Count; i++)
            {
                KeyValuePair <string, HDMATable> tablePair = dicTable.ElementAt(i);
                DMAMode mode       = (tablePair.Value[0].Values.Length == 1 ? DMAMode.P : DMAMode.PP);
                int     channelAdd = 16 * newChannels[i];
                string  tableName  = getTablename(tablePair);

                sbCode.AppendLine("\tLDA #$" + (((Registers.FixedColor & 0xFF) << 8) + (int)mode).ToString("X4"));
                sbCode.AppendLine("\tSTA $" + (Registers.DMAMode + channelAdd).ToString("X4"));
                sbCode.AppendLine("\tLDA #" + tableName);
                sbCode.AppendLine("\tSTA $" + (Registers.DMALowByte + channelAdd).ToString("X4"));
                sbCode.AppendLine("\tLDY.b #" + tableName + ">>16");
                sbCode.AppendLine("\tSTY $" + (Registers.DMABankByte + channelAdd).ToString("X4"));

                channelTrigger += (1 << newChannels[i]);
            }

            sbCode.AppendLine("\tSEP #$20");
            sbCode.AppendLine("\tLDA #$" + channelTrigger.ToString("X2"));
            sbCode.AppendLine("\tTSB $" + RAM.HDMAEnable[RAM.SA1].ToString("X4") + "|!addr");
            sbCode.AppendLine("\tRTL");

            for (int i = 0; i < dicTable.Count; i++)
            {
                KeyValuePair <string, HDMATable> tablePair = dicTable.ElementAt(i);
                string tableName = getTablename(tablePair);
                sbCode.AppendLine();
                sbCode.Append(tablePair.Value.ToString(tableName));
            }

            return(sbCode.ToString());
        }
Exemplo n.º 2
0
 public string Code(PickSingleChannel single, PickMultiChannel multi, PickMultiChannel tripple)
 {
     return(Code(this._red, this._green, this._blue, single, multi, tripple));
 }