Пример #1
0
        public static void CreateMenuBinary(List <ROM> ROMList, ref Byte[] Template)
        {
            using (MemoryStream Mem = new MemoryStream(Template))
            {
                Mem.Position = 0x1C200;
                for (int i = 0; i < ROMList.Count; i++)
                {
                    //ROM Index
                    Mem.WriteByte((Byte)(i + 1));

                    //ROM Base (in 128K units)
                    int Base = 128;
                    for (int b = i - 1; b >= 0; b--)
                    {
                        Base += ((ROMList[b].ROMSizeKByte < 128) ? 128 : ROMList[b].ROMSizeKByte);
                    }
                    Mem.WriteByte((Byte)(Base / 128));

                    //Maybe SRAM base???
                    Mem.WriteByte(0x0);

                    //ROM size in 128Kbyte units (0001h..0007h = 128K..896K)
                    Mem.WriteByte((Byte)(((ROMList[i].ROMSizeKByte < 128) ? 128 : ROMList[i].ROMSizeKByte) / 128));
                    Mem.WriteByte(0x0);

                    //SRAM size in 32-byte units (0000h,00xxh,01xxh,xxxxh=0,MBC2,8K,32K)
                    Mem.WriteByte(0x0);
                    Mem.WriteByte(0x0);

                    //Title Title ASCII "DMG -xxxx-  "
                    Byte[] temp = new Byte[0];
                    if (!ROMList[i].CGB)
                    {
                        temp = System.Text.ASCIIEncoding.ASCII.GetBytes("DMG -A" + ROMList[i].ASCIITitle.Substring(0, 2) + "J-  ");
                    }
                    else
                    {
                        temp = System.Text.ASCIIEncoding.ASCII.GetBytes("CGB -A" + ROMList[i].ASCIITitle.Substring(0, 2) + "J-  ");
                    }

                    Mem.Write(temp, 0, temp.Length);



                    //Title SHIFT-JIS
                    //temp = new Byte[] { 0x82, 0x50, 0x82, 0x54, 0x82, 0x61, 0x83, 0x7B, 0x83, 0x93, 0x83, 0x6F, 0x81, 0x5B, 0x83, 0x7D, 0x83, 0x93, 0x82, 0x66, 0x82, 0x61, 0x82, 0x52, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
                    Encoding ShiftJIS = Encoding.GetEncoding(932);
                    String   temp1    = "これを読めば、あなたはばかだ";
                    temp1 = temp1.PadRight(30, ' ');
                    temp  = ShiftJIS.GetBytes(temp1);
                    Mem.Write(temp, 0, temp.Length);

                    //Title Bitmap (128x8 pixels, 16 tiles at 2bpp)
                    temp = TitleImage.GB(TitleImage.CreateTitleBitmap(ROMList[i].Title));
                    Mem.Write(temp, 0, temp.Length);

                    //Zerofill
                    for (int b = 0; b < 0xC0; b++)
                    {
                        Mem.WriteByte(0x0);
                    }

                    //Date ASCII "MM/DD/YYYY" + Time ASCII"HH:MM:SS"
                    temp1 = DateTime.Now.ToString(@"MM\/dd\/yyyyHH:mm:ss");
                    temp  = System.Text.ASCIIEncoding.ASCII.GetBytes(temp1);
                    Mem.Write(temp, 0, temp.Length);

                    //LAW ASCII  "LAWnnnnn"
                    temp = System.Text.ASCIIEncoding.ASCII.GetBytes("LAW01780");
                    Mem.Write(temp, 0, temp.Length);

                    //Unused (FFh-filled)
                    for (int b = 0; b < 0x17; b++)
                    {
                        Mem.WriteByte(0xFF);
                    }

                    //Unused (FFh-filled)(game entries) or "MULTICARTRIDGE 8"(menu entry)
                    for (int b = 0; b < 0x10; b++)
                    {
                        Mem.WriteByte(0xFF);
                    }
                }

                //Write Game ROMs to Binary
                Mem.Position = 0x20000;
                long pos = 0;
                for (int i = 0; i < ROMList.Count; i++)
                {
                    pos = Mem.Position;
                    Byte[] temp = new Byte[0];
                    if (!ROMList[i].embedded)
                    {
                        temp = File.ReadAllBytes(ROMList[i].File);
                    }
                    else
                    {
                        using (FileStream Reader = new FileStream(ROMList[i].File, FileMode.Open, FileAccess.Read))
                        {
                            Reader.Position = ROMList[i].ROMPos;
                            temp            = new Byte[ROMList[i].ROMSizeKByte * 1024];
                            Reader.Read(temp, 0, ROMList[i].ROMSizeKByte * 1024);
                        }
                    }
                    Mem.Write(temp, 0, ROMList[i].ROMSizeKByte * 1024);
                    Mem.Position = pos + ((ROMList[i].ROMSizeKByte < 128) ? 128 : ROMList[i].ROMSizeKByte) * 1024;
                }
            }
        }
Пример #2
0
        private void AddROMToInterface(ROM ROMToAdd)
        {
            //Create new sub-panel for ROM
            Panel ROMPanel = new Panel();

            ROMPanel.Width       = ROMListPanel.Width - 22;
            ROMPanel.Height      = 90;
            ROMPanel.Location    = new Point(1, 1 + ROMListPanel.Controls.Count * 91);
            ROMPanel.BorderStyle = BorderStyle.FixedSingle;

            //Invisible that contains the entered title in String format for later
            Label T = new Label();

            T.Visible = false;
            T.Text    = ROMToAdd.Title;
            ROMPanel.Controls.Add(T);

            //Invisible that contains just the ASCII-title in String format for later
            Label AT = new Label();

            AT.Visible = false;
            AT.Text    = ROMToAdd.ASCIITitle;
            ROMPanel.Controls.Add(AT);

            Label ASCIITitleDisplay = new Label();

            ASCIITitleDisplay.AutoSize = true;
            ASCIITitleDisplay.Text     = "ASCII-Title: " + ROMToAdd.ASCIITitle;
            ASCIITitleDisplay.Location = new Point(5, 4);
            ROMPanel.Controls.Add(ASCIITitleDisplay);

            Label CartTypeDisplay = new Label();

            CartTypeDisplay.AutoSize = true;
            CartTypeDisplay.Text     = "Cart-Type: " + ROMToAdd.CartridgeTypeString;
            CartTypeDisplay.Location = new Point(5, 36);
            ROMPanel.Controls.Add(CartTypeDisplay);

            Label TitleIMDisplay = new Label();

            TitleIMDisplay.AutoSize = true;
            TitleIMDisplay.Text     = "Title:";
            TitleIMDisplay.Location = new Point(5, 19);
            ROMPanel.Controls.Add(TitleIMDisplay);

            PictureBox TitleIMG = new PictureBox();

            TitleIMG.Image       = TitleImage.CreateTitleBitmap(ROMToAdd.Title);
            TitleIMG.SizeMode    = PictureBoxSizeMode.AutoSize;
            TitleIMG.Location    = new Point(35, 21);
            TitleIMG.BorderStyle = BorderStyle.FixedSingle;
            ROMPanel.Controls.Add(TitleIMG);

            Label ROMSizeDisplay = new Label();

            ROMSizeDisplay.AutoSize = true;
            ROMSizeDisplay.Text     = "ROMSize: " + ROMToAdd.ROMSizeKByte + "kByte" + (ROMToAdd.padded ? " (padded to 128kByte)" : "");
            ROMSizeDisplay.Location = new Point(5, 53);
            ROMPanel.Controls.Add(ROMSizeDisplay);

            Label RAMSizeDisplay = new Label();

            RAMSizeDisplay.AutoSize = true;
            RAMSizeDisplay.Text     = "RAMSize: " + ROMToAdd.RAMSizeKByte + "kByte";
            RAMSizeDisplay.Location = new Point(5, 70);
            ROMPanel.Controls.Add(RAMSizeDisplay);

            Button Remove = new Button();

            Remove.Text     = "Remove";
            Remove.Location = new Point(300, 60);
            Remove.Click   += (s, ev) =>
            {
                foreach (ROM R in ROMList)
                {
                    if (R.Title == ((Button)s).Parent.Controls[0].Text && R.ASCIITitle == ((Button)s).Parent.Controls[1].Text)
                    {
                        ROMList.Remove(R);
                        break;
                    }
                }
                ROMListPanel.Controls.Remove(((Button)s).Parent);
                updateROMSpace();
            };
            ROMPanel.Controls.Add(Remove);

            Button Edit = new Button();

            Edit.Text     = "Edit Title";
            Edit.Location = new Point(300, 30);
            Edit.Click   += (s, ev) =>
            {
                foreach (ROM R in ROMList)
                {
                    if (R.Title == ((Button)s).Parent.Controls[0].Text && R.ASCIITitle == ((Button)s).Parent.Controls[1].Text)
                    {
                        TitleEntry ROMEditTitle = new TitleEntry();
                        if (ROMEditTitle.ShowDialog() == DialogResult.OK)
                        {
                            R.Title = ROMEditTitle.Title;
                            ((PictureBox)(((Button)s).Parent.Controls[5])).Image = TitleImage.CreateTitleBitmap(R.Title);
                            (((Button)s).Parent.Controls[0]).Text = R.Title;
                        }
                        break;
                    }
                }
            };
            ROMPanel.Controls.Add(Edit);

            if (ROMToAdd.embedded)
            {
                PictureBox Rip = new PictureBox();
                Rip.Location = new Point(382, 1);
                Rip.SizeMode = PictureBoxSizeMode.AutoSize;
                Rip.Cursor   = Cursors.Hand;
                Rip.Image    = GB_Memory.Properties.Resources.icon_save;
                Rip.Click   += (s, ev) =>
                {
                    if (MessageBox.Show("Rip ROM from binary?", "Rip ROM", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        foreach (ROM R in ROMList)
                        {
                            if (R.Title == ((PictureBox)s).Parent.Controls[0].Text && R.ASCIITitle == ((PictureBox)s).Parent.Controls[1].Text && R.embedded)
                            {
                                if (File.Exists(R.File))
                                {
                                    Byte[] buffer = new Byte[R.ROMSizeKByte * 1024];
                                    using (FileStream Reader = new FileStream(R.File, FileMode.Open, FileAccess.Read))
                                    {
                                        Reader.Position = R.ROMPos;
                                        Reader.Read(buffer, 0, R.ROMSizeKByte * 1024);
                                    }
                                    using (SaveFileDialog ToSave = new SaveFileDialog())
                                    {
                                        ToSave.FileName = R.ASCIITitle;
                                        ToSave.Filter   = R.CGB ? "GBC ROM|*.gbc" : "GB ROM|*.gb";
                                        if (ToSave.ShowDialog() != DialogResult.OK)
                                        {
                                            return;
                                        }
                                        if (!Directory.Exists(Path.GetDirectoryName(ToSave.FileName)))
                                        {
                                            return;
                                        }
                                        if (!CheckFolderPermissions(Path.GetDirectoryName(ToSave.FileName)))
                                        {
                                            return;
                                        }
                                        File.WriteAllBytes(ToSave.FileName, buffer);
                                    }
                                }
                                break;
                            }
                        }
                    }
                };
                ROMPanel.Controls.Add(Rip);
            }

            ROMListPanel.Controls.Add(ROMPanel);
            ROMList.Add(ROMToAdd);
            updateROMSpace();

            ShowRAMSizeOverflowWarning(ROMToAdd);
        }