コード例 #1
0
        /// <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());
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the screen as it would be displayed by the SNES.
        /// </summary>
        /// <returns></returns>
        public Bitmap GetScreen()
        {
            if (BG1 == null || BG2 == null || BG3 == null || BG4 == null)
            {
                throw new ArgumentNullException("BGs need to be initialized");
            }
            if (FixedColor == null)
            {
                throw new ArgumentNullException("FixedColor need to be initialized");
            }
            if (Backdrop == null)
            {
                throw new ArgumentNullException("Backdrop need to be initialized");
            }


            Bitmap main, sub;
            Bitmap statusBar  = new Bitmap(LayerSizes.Width, LayerSizes.Height);
            Bitmap bg3_remain = new Bitmap(LayerSizes.Width, LayerSizes.Height);

            //cut layer 3 into status bar end rest.
            using (Graphics g = Graphics.FromImage(statusBar))
                g.DrawImageUnscaledAndClipped(BG3, new Rectangle(0, 0, statusBar.Width, StatusBarHeight));
            using (Graphics g = Graphics.FromImage(bg3_remain))
            {
                Rectangle rec = new Rectangle(0, StatusBarHeight, bg3_remain.Width, bg3_remain.Height - StatusBarHeight);
                g.DrawImageUnscaledAndClipped(BG3.Clone(rec, BG3.PixelFormat), rec);
            }


            Func <bool, bool, bool, bool, WindowMaskLogic, Bitmap, Bitmap> doWindowing = (enable1, enable2, invert1, invert2, logic, bg) =>
            {
                Bitmap mask1 = invert1 ? BitmapEffects.Invert(WindowingMask1) : WindowingMask1;
                Bitmap mask2 = invert2 ? BitmapEffects.Invert(WindowingMask2) : WindowingMask2;

                if (enable1 && enable2)
                {
                    return(BitmapEffects.ApplyMask(bg, MergeMasks(mask1, mask2, logic), 0.5f));
                }
                else if (enable1)
                {
                    return(BitmapEffects.ApplyMask(bg, mask1, 0.5f));
                }
                else if (enable2)
                {
                    return(BitmapEffects.ApplyMask(bg, mask2, 0.5f));
                }
                else
                {
                    return(bg);
                }
            };

            Bitmap bg1Windowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG1), Window2Enabled.HasFlag(WindowingLayers.BG1),
                                             Window1Inverted.HasFlag(WindowingLayers.BG1), Window2Inverted.HasFlag(WindowingLayers.BG1), Bg1MaskLogic, BG1);

            Bitmap bg2Windowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG2), Window2Enabled.HasFlag(WindowingLayers.BG2),
                                             Window1Inverted.HasFlag(WindowingLayers.BG2), Window2Inverted.HasFlag(WindowingLayers.BG2), Bg2MaskLogic, BG2);

            Bitmap statusBarWindowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG3), Window2Enabled.HasFlag(WindowingLayers.BG3),
                                                   Window1Inverted.HasFlag(WindowingLayers.BG3), Window2Inverted.HasFlag(WindowingLayers.BG3), Bg3MaskLogic, statusBar);

            Bitmap bg3RemainWindowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG3), Window2Enabled.HasFlag(WindowingLayers.BG3),
                                                   Window1Inverted.HasFlag(WindowingLayers.BG3), Window2Inverted.HasFlag(WindowingLayers.BG3), Bg3MaskLogic, bg3_remain);

            Bitmap bg4Windowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG4), Window2Enabled.HasFlag(WindowingLayers.BG4),
                                             Window1Inverted.HasFlag(WindowingLayers.BG4), Window2Inverted.HasFlag(WindowingLayers.BG4), Bg4MaskLogic, BG4);

            Bitmap objWindowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.OBJ), Window2Enabled.HasFlag(WindowingLayers.OBJ),
                                             Window1Inverted.HasFlag(WindowingLayers.OBJ), Window2Inverted.HasFlag(WindowingLayers.OBJ), ObjMaskLogic, OBJ);

            Bitmap colorWindowed      = BitmapEffects.FromColor(Color.Black, LayerSizes);
            Bitmap colorWindowedHoles = doWindowing(Window1Enabled.HasFlag(WindowingLayers.Color), Window2Enabled.HasFlag(WindowingLayers.Color),
                                                    Window1Inverted.HasFlag(WindowingLayers.Color), Window2Inverted.HasFlag(WindowingLayers.Color), ColorMaskLogic,
                                                    BitmapEffects.FromColor(Color.White, LayerSizes));

            //colorWindowsedHoles is white with holes where the black should be
            using (Graphics g = Graphics.FromImage(colorWindowed))
                g.DrawImage(colorWindowedHoles, 0, 0);

            #region Sub Screen
            List <Bitmap> BGs = new List <Bitmap>();
            if (SubScreenDesignation.HasFlag(ScreenDesignation.OBJ) && !Hide.HasFlag(ScreenDesignation.OBJ))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.OBJ) ? objWindowed : OBJ);
            }

            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG1) && !Hide.HasFlag(ScreenDesignation.BG1))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG1) ? bg1Windowed : BG1);
            }

            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG2) && !Hide.HasFlag(ScreenDesignation.BG2))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG2) ? bg2Windowed : BG2);
            }

            //layer 3 special (status bar split) onyl lower part
            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? bg3RemainWindowed : bg3_remain);
            }

            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG4) && !Hide.HasFlag(ScreenDesignation.BG4))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG4) ? bg4Windowed : BG4);
            }

            BGs.Add(FixedColor);
            sub = BitmapEffects.OverlapImages(BGs.ToArray());
            #endregion

            #region Main Screen

            BGs.Clear();
            if (MainScreenDesignation.HasFlag(ScreenDesignation.OBJ) && !Hide.HasFlag(ScreenDesignation.OBJ))
            {
                Bitmap objUse = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.OBJ) ? objWindowed : OBJ;
                if (ColorMathDesignation.HasFlag(ColorMathMode.OBJ))
                {
                    BGs.Add(ApplyColorMath(objUse, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(objUse);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG1) && !Hide.HasFlag(ScreenDesignation.BG1))
            {
                Bitmap bg1Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG1) ? bg1Windowed : BG1;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG1))
                {
                    BGs.Add(ApplyColorMath(bg1Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg1Use);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG2) && !Hide.HasFlag(ScreenDesignation.BG2))
            {
                Bitmap bg2Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG2) ? bg2Windowed : BG2;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG2))
                {
                    BGs.Add(ApplyColorMath(bg2Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg2Use);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                //layer 3 special (status bar split) onyl lower half
                Bitmap bg3Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? bg3RemainWindowed : bg3_remain;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG3))
                {
                    BGs.Add(ApplyColorMath(bg3Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg3Use);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG4) && !Hide.HasFlag(ScreenDesignation.BG4))
            {
                Bitmap bg4Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? bg4Windowed : BG4;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG4))
                {
                    BGs.Add(ApplyColorMath(bg4Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg4Use);
                }
            }

            //handle the backdrop too
            if (ColorMathDesignation.HasFlag(ColorMathMode.Backdrop))
            {
                BGs.Add(ApplyColorMath(Backdrop, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
            }
            else
            {
                BGs.Add(Backdrop);
            }

            main = BitmapEffects.OverlapImages(BGs.ToArray());
            #endregion

            BGs.Clear();

            //check windowing for status bar
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                BGs.Add(MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? statusBarWindowed : statusBar);
            }
            //if not main, check subscreen. (still put it before main for display purpose)
            else if (SubScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? statusBarWindowed : statusBar);
            }

            BGs.Add(main);
            BGs.Add(sub);

            return(BitmapEffects.OverlapImages(BGs.ToArray()));
        }