Beispiel #1
0
        private void LoadNSFInformation(string fileName)
        {
            var nsf = new NSF();

            nsf.Load(fileName);
            this.lblNsfInformation.Text =
                "NSF Information:\r\n" +
                "Game Title: " + nsf.SongName + "\r\n" +
                "Artist: " + nsf.Artist + "\r\n" +
                "Copyright: " + nsf.Copyright + "\r\n" +
                "Number of songs: " + nsf.TotalSongs.ToString();
        }
Beispiel #2
0
        public static void InjectNsf(string nesFileName, string nsfFileName, string outputFileName, byte songNumber)
        {
            NSF nsf = new NSF();

            nsf.Load(nsfFileName);
            byte[] nsfBank = nsf.GetNESMemory();
            byte[] nesRom  = File.ReadAllBytes(nesFileName);

            MemoryStream msSource = new MemoryStream(nesRom);
            BinaryReader br       = new BinaryReader(msSource);

            byte[] header = br.ReadBytes(16);
            byte[] bank0  = br.ReadBytes(0x4000);
            byte[] bank1  = br.ReadBytes(0x4000);
            byte[] bank2  = br.ReadBytes(0x4000);
            byte[] bank3  = br.ReadBytes(0x4000);   //bank 3 is not used after expansion
            byte[] bank4  = nsfBank.Skip(0).Take(0x4000).ToArray();
            byte[] bank5  = nsfBank.Skip(0x4000).Take(0x4000).ToArray();
            byte[] bank6  = bank2.ToArray();    //bank 6 is not used - copy bank 2
            byte[] bank7  = bank3.ToArray();
            byte[] chr    = br.ReadBytes(0x4000);

            header[4] = 8;

            RamCode ramCode = new RamCode();

            byte[] ramCode2 = ramCode.Build(nsf.InitAddress, nsf.PlayAddress, songNumber);

            BinaryWriter bw = new BinaryWriter(new MemoryStream(bank5));

            bw.BaseStream.Position = 0x4000 - 6;
            bw.Write((ushort)ramCode.Nmi);
            bw.Write((ushort)ramCode.Reset);
            bw.Write((ushort)ramCode.Irq);

            LoaderCode loaderCode = new LoaderCode();

            loaderCode.SetMemory(bank3, 0x8000);
            loaderCode.CurrentAddress = 0x84E8;
            loaderCode.Build(ramCode2, ramCode.Entry);

            Assembler asm = new Assembler();

            asm.SetMemory(bank7, 0xC000);
            asm.CurrentAddress = 0xCCF3;
            asm.JMP(0x84E8);

            FileStream outputFileStream = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            bw = new BinaryWriter(outputFileStream);
            bw.Write(header);
            bw.Write(bank0);
            bw.Write(bank1);
            bw.Write(bank2);
            bw.Write(bank3);
            bw.Write(bank4);
            bw.Write(bank5);
            bw.Write(bank6);
            bw.Write(bank7);
            bw.Write(chr);
            outputFileStream.Flush();
            outputFileStream.Close();
            outputFileStream.Dispose();
        }