コード例 #1
0
ファイル: Program.cs プロジェクト: DualBrain/NesEmu
        public static void Main(string[] args)
        {
            if (args == null || args.Length < 1 || string.IsNullOrWhiteSpace(args [0]))
            {
                Console.WriteLine("First argument should be path to NES rom.");
                return;
            }

            var fileInfo = new System.IO.FileInfo(args [0]);

            if (!fileInfo.Exists)
            {
                Console.WriteLine("File does not exist: {0}", fileInfo.FullName);
                return;
            }

            var rom    = NesRom.Parse(fileInfo);
            var memory = new Memory(0x10000);
            var cpu    = new CPU(memory);

            var nesEmulation = new NES(cpu, memory);

            nesEmulation.LoadRom(rom);
            nesEmulation.Reset();

            nesEmulation.BeginEmulation();

            Console.WriteLine("Press any key to whatever.");
            Console.ReadKey();

            nesEmulation.EndEmulation();
        }
コード例 #2
0
ファイル: Weapon.cs プロジェクト: sereth/FF1Randomizer
        public Weapon(int weaponIndex, NesRom rom)
        {
            WeaponIndex = weaponIndex;
            //read stats from memory
            int weaponBaseOffset = FF1Rom.WeaponOffset + (WeaponIndex * FF1Rom.WeaponSize);

            HitBonus          = rom.Get(weaponBaseOffset, 1).ToBytes()[0];
            Damage            = rom.Get(weaponBaseOffset + 1, 1).ToBytes()[0];
            Crit              = rom.Get(weaponBaseOffset + 2, 1).ToBytes()[0];
            SpellIndex        = rom.Get(weaponBaseOffset + 3, 1).ToBytes()[0];
            ElementalWeakness = rom.Get(weaponBaseOffset + 4, 1).ToBytes()[0];
            TypeWeakness      = rom.Get(weaponBaseOffset + 5, 1).ToBytes()[0];
            byte weaponSpriteTypeHolder = rom.Get(weaponBaseOffset + 6, 1).ToBytes()[0];

            WeaponTypeSprite         = getWeaponSpriteFromByte(weaponSpriteTypeHolder);
            WeaponSpritePaletteColor = rom.Get(weaponBaseOffset + 7, 1).ToBytes()[0];

            //read permissions
            int weaponUsabilityOffset = FF1Rom.WeaponPermissionsOffset + (WeaponIndex * FF1Rom.PermissionsSize);

            byte highByte = rom.Get(weaponUsabilityOffset, 1).ToBytes()[0];
            byte lowByte  = rom.Get(weaponUsabilityOffset + 1, 1).ToBytes()[0];

            ushort assembledUShort = BitConverter.ToUInt16(new byte[2] {
                highByte, lowByte
            }, 0);
            ushort convertedClassPermissions = (ushort)(assembledUShort ^ 0xFFF);

            ClassUsability = convertedClassPermissions;

            //get name stuff
            Icon = WeaponIcon.NONE;
            //hold over from armor, doesnt really need this check
            int weaponBaseNameOffset = FF1Rom.GearTextOffset + (WeaponIndex * FF1Rom.GearTextSize) + (weaponIndex > (byte)Item.Ribbon ? 1 : 0);
            //TODO figure out if treasure hunt is enabled, if so add 6 to this offset
            byte currentValue;

            NameBytes = rom.Get(weaponBaseNameOffset, 8).ToBytes();

            //find icon
            for (int i = 0; i < 8; i++)
            {
                currentValue = NameBytes[i];
                //icon range > 200
                if (currentValue > 200)
                {
                    //check for icon
                    Icon = getWeaponIconFromByte(currentValue);
                }
            }
        }
コード例 #3
0
ファイル: Armor.cs プロジェクト: tetron/FF1Randomizer
        public void writeArmorMemory(NesRom rom)
        {
            //armor stats
            int armorBaseOffset = FF1Rom.ArmorOffset + (ArmorIndex * FF1Rom.ArmorSize);

            rom.Put(armorBaseOffset, new byte[] { Weight, Absorb, ElementalResist, SpellIndex });

            //armor permissions
            int    armorPermissionOffset     = FF1Rom.ArmorPermissionsOffset + (ArmorIndex * FF1Rom.PermissionsSize);
            ushort convertedClassPermissions = (ushort)(ClassUsability ^ 0xFFF);

            rom.Put(armorPermissionOffset, BitConverter.GetBytes(convertedClassPermissions));

            //armor name
            int armorBaseNameOffset = FF1Rom.GearTextOffset + ((ArmorIndex + 40) * FF1Rom.GearTextSize) + (ArmorIndex > 31 ? 1 : 0);

            rom.Put(armorBaseNameOffset, NameBytes);
        }
コード例 #4
0
ファイル: Weapon.cs プロジェクト: sereth/FF1Randomizer
        public void writeWeaponMemory(NesRom rom)
        {
            //weapon stats
            int weaponBaseOffset = FF1Rom.WeaponOffset + (WeaponIndex * FF1Rom.WeaponSize);

            rom.Put(weaponBaseOffset, new byte[] { HitBonus, Damage, Crit, SpellIndex, ElementalWeakness, TypeWeakness, (byte)WeaponTypeSprite, WeaponSpritePaletteColor });

            //weapon usability
            int    weaponUsabilityOffset     = FF1Rom.WeaponPermissionsOffset + (WeaponIndex * FF1Rom.PermissionsSize);
            ushort convertedClassPermissions = (ushort)(ClassUsability ^ 0xFFF);

            rom.Put(weaponUsabilityOffset, BitConverter.GetBytes(convertedClassPermissions));

            //weapon name
            int weaponBaseNameOffset = FF1Rom.GearTextOffset + (WeaponIndex * FF1Rom.GearTextSize);

            rom.Put(weaponBaseNameOffset, NameBytes);
        }
コード例 #5
0
ファイル: Armor.cs プロジェクト: tetron/FF1Randomizer
        public Armor(int armorIndex, NesRom rom)
        {
            ArmorIndex = armorIndex;
            //read stats from memory
            int armorBaseOffset = FF1Rom.ArmorOffset + (ArmorIndex * FF1Rom.ArmorSize);

            Weight          = rom.Get(armorBaseOffset, 1).ToBytes()[0];
            Absorb          = rom.Get(armorBaseOffset + 1, 1).ToBytes()[0];
            ElementalResist = rom.Get(armorBaseOffset + 2, 1).ToBytes()[0];
            SpellIndex      = rom.Get(armorBaseOffset + 3, 1).ToBytes()[0];

            //read permissions
            int armorPermissionOffset = FF1Rom.ArmorPermissionsOffset + (ArmorIndex * FF1Rom.PermissionsSize);

            byte highByte = rom.Get(armorPermissionOffset, 1).ToBytes()[0];
            byte lowByte  = rom.Get(armorPermissionOffset + 1, 1).ToBytes()[0];

            ushort assembledUShort = BitConverter.ToUInt16(new byte[2] {
                highByte, lowByte
            }, 0);
            ushort convertedClassPermissions = (ushort)(assembledUShort ^ 0xFFF);

            ClassUsability = convertedClassPermissions;

            //get name stuff
            Icon = ArmorIcon.NONE;
            int armorBaseNameOffset = FF1Rom.GearTextOffset + ((ArmorIndex + 40) * FF1Rom.GearTextSize) + (ArmorIndex > 31 ? 1 : 0);
            //TODO figure out if treasure hunt is enabled, if so add 6 to this offset
            byte currentValue;

            NameBytes = rom.Get(armorBaseNameOffset, 8).ToBytes();

            //find icon
            for (int i = 0; i < 8; i++)
            {
                currentValue = NameBytes[i];
                //icon range > 200
                if (currentValue > 200)
                {
                    //check for icon
                    Icon = getArmorIconFromByte(currentValue);
                }
            }
        }