示例#1
0
 public void Init(U8 bank, RAM remainder)
 {
     Bank      = bank;
     ModuleMem = remainder;
     Ram       = remainder?.Ram ?? NES.ram;
     Zp        = remainder?.Zp ?? NES.zp;
 }
        //TODO: see if the Dim(ram,name) override could just set or use existing name, and call Dim(ram) (or preferably just consolidate them somehow!)
        public StructOfArrays <StructType> Dim(RAMRange ram)
        {
            var arrs       = new List <Array <VByte> >();
            var structType = _baseInstance.GetType();

            foreach (var p in structType.GetProperties().Where(x => typeof(Var).IsAssignableFrom(x.PropertyType)).ToList())
            {
                var numBytes = VarSize.GetSizeOf(p.PropertyType);
                if (numBytes < 1)
                {
                    throw new Exception("Variable length types cannot be used in structs--make a new Var type with a fixed length");                               //Alternative: a Size attribute on the property (may not work for Decimal, which has two size args)
                }
                if (numBytes == 1)
                {
                    arrs.Add(Array <VByte> .New((U8)Length, ram, $"{structType.Name}{nameSuffix++}_{p.Name}"));
                }
                else
                {
                    for (var i = 0; i < numBytes; i++)
                    {
                        arrs.Add(Array <VByte> .New((U8)Length, ram, $"{structType.Name}{nameSuffix++}_{p.Name}_{i}"));
                    }
                }
            }
            _arrays = arrs.ToArray();
            Size    = Length * arrs.Count;
            return(this);
        }
示例#3
0
 public override VDecimal Dim(RAMRange ram, string name)
 {
     base.Dim(ram, name);
     Name       = name;
     Integer    = VarN.Ref(Address[FracLen], IntLen, $"{name}_Int");
     Fractional = VarN.Ref(Address[0], FracLen, $"{name}_Frac");
     return(this);
 }
示例#4
0
        public static ShiftQueue New(RAMRange ram, U8 length, string name, U8 clearValue)
        {
            var bq = new ShiftQueue();

            bq.Values = Array <VByte> .New(length, ram, name + "_values");

            bq._clearVal = clearValue;
            return(bq);
        }
示例#5
0
        public static Array <T> New(int len, RAMRange r, string name)
        {
            var arr = new Array <T>()
            {
                Length = len
            };

            arr.Dim(r, name);
            return(arr);
        }
示例#6
0
 public Ptr(RAMRange Zp, string name)
 {
     //Bytes = new Address[2];//Address();
     Name    = name;
     Address = Zp.Dim(2);
     //Lo = Address[0];
     //Hi = Address[1];
     DebugFileNESASM.WriteVariable(Zp, Address[0], Address[1], name);
     VarRegistry.Add(name, this);
 }
示例#7
0
        public static RAMRange StackRam;         //eliminate stack page from possible allocations

        public static void Init()
        {
            ram           = new RAMRange(0x0000, 0x07FF, "Main");
            zp            = ram.Allocate(0x0000, 0x00FF, "ZP");
            StackRam      = ram.Allocate(0x0100, 0x01FF, "Stack");
            ShadowOAM.Ram = ram.Allocate(0x0200, 0x02FF, "Shadow OAM");

            Mem = new RAM(zp, ram);

            PPU.OAM.Init();
        }
        //TODO: see if the Dim(ram,name) override could just set or use existing name, and call Dim(ram) (or preferably just consolidate them somehow!)
        public ArrayOfStructs <StructType> Dim(RAMRange ram)
        {
            var structs = new List <StructType>();

            for (var i = 0; i < Length; i++)
            {
                structs.Add(Struct.New <StructType>(ram, $"{ typeof(StructType).Name}_{i}"));
            }
            _structs = structs.ToArray();
            return(this);
        }
示例#9
0
 public override VarN Dim(RAMRange ram, string name)
 {
     if (Address != null)
     {
         throw new Exception("Var already dimmed");
     }
     Address = ram.Dim(Size);
     Name    = name;
     DebugFileNESASM.WriteVariable(ram, Address[0], Address[Size - 1], name);
     VarRegistry.Add(name, this);
     return(this);
 }
示例#10
0
        //TODO: this doesn't really enforce length. Implement wrap if length != 0 (0 would indicate 256--full page)
        public static LiveQueue New(RAMRange Zp, RAMRange Ram, RAMRange valuesRam, int length, string name, U8 stopVal)
        {
            var bq = new LiveQueue();

            bq.Values = Array <VByte> .New(length, valuesRam, name + "_values");

            bq._stopVal   = stopVal;
            bq.WriteIndex = VByte.New(Zp, name + "_write");
            bq.ReadIndex  = VByte.New(Zp, name + "_read");
            //bq._done = Var8.New(ram, name + "_done");
            return(bq);
        }
示例#11
0
        public VByte Index;       //Used as a cursor for grid cell access via Y

        public static ByteGrid New(RAMRange ram, U8 length, string name)
        {
            var grid = new ByteGrid();

            grid.Values = Array <VByte> .New(length, ram, name + "_grid");

            grid.Width  = VByte.New(ram, name + "_width");
            grid.Height = VByte.New(ram, name + "_height");
            grid.Max    = VByte.New(ram, name + "_max");
            grid.Index  = VByte.New(ram, name + "_index");
            return(grid);
        }
示例#12
0
        private static int vbytecount = 0;              //TODO: num is temporary til I move VarRegistry to RAM instances

        public override VByte Dim(RAMRange ram, string name)
        {
            if (Address != null)
            {
                throw new Exception("Var already dimmed");
            }
            Address = ram.Dim(1);
            Name    = name;
            DebugFileNESASM.WriteVariable(ram, Address[0], name);
            VarRegistry.Add(name + vbytecount++, this);                 //TODO: num is temporary til I move VarRegistry to RAM instances
            return(this);
        }
示例#13
0
        public override Var Dim(RAMRange ram, string name) => throw new Exception("Lazy-dimming of structs not yet supported. Use Struct.New<T> for now.");         //TODO: try to implement this for struct-in-struct support

        public static T New <T>(RAMRange ram, string name) where T : Struct, new()
        {
            var structInstance = new T();
            var size           = 0;

            foreach (var p in structInstance.GetType().GetProperties().Where(x => typeof(Var).IsAssignableFrom(x.PropertyType)).ToList())
            {
                var v = (Var?)Activator.CreateInstance(p.PropertyType);
                v.Dim(ram, $"{ (string.IsNullOrEmpty(name) ? structInstance.GetType().Name : name) }_{ p.Name }");
                size += v.Size;
                structInstance.GetType().InvokeMember(p.Name, BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, structInstance, new object[] { v });
            }
            structInstance.Size = size;
            return(structInstance);
        }
示例#14
0
 public override Var Dim(RAMRange ram, string name)
 {
     if (Vars is not null)
     {
         throw new Exception("Array already dimmed");
     }
     Vars = new T[Length];
     for (var i = 0; i < Length; i++)
     {
         var v = new T();
         v.Dim(ram, $"{name}_{i}");
         Vars[i] = v;
     }
     Name = name;
     return(this);
 }
示例#15
0
        public void Init(List <Bank> Prg, List <Bank> Chr, HeaderOptions headerOpts)
        {
            if (_prgRom == MemorySizes.KB_512)
            {
                //TODO: two of these loops divided between 0xA000 and {0x8000 | 0xC000}
                U8 i;
                for (i = 0; i < 62; i++)
                {
                    Prg.Add(new Bank(i, MemorySizes.KB_8, 0x8000));
                }
                Prg.Add(new Bank(++i, MemorySizes.KB_8, 0xC000, true));
                Prg.Add(new Bank(++i, MemorySizes.KB_8, 0xE000, true));
                headerOpts.PrgRomBanks = 32;                 //32 * 16KB/bank = 512
            }
            else
            {
                throw new NotImplementedException();                //TODO: wait until 512 works to finish the rest
            }
            if (_chrRom > 0)
            {
                if (_chrRom == MemorySizes.KB_256)
                {
                    U8 i;
                    for (i = 0; i < 256; i++)
                    {
                        Chr.Add(new Bank(i, MemorySizes.KB_1, 0x0000));
                    }
                    headerOpts.ChrRomBanks = 32;                     //32 * 8KB/bank = 256
                }
                else
                {
                    throw new NotImplementedException();                    //TODO: wait until 512 works to finish the rest
                }
            }

            if (_wRam > 0)
            {
                WRAM = new RAMRange(Addr(0x6000), Addr(0x7FFF), "WRAM");
            }
            //headerOpts.
        }
示例#16
0
 public static new VFlags New(RAMRange ram, string name) => (VFlags) new VFlags().Dim(ram, name);
示例#17
0
 public static VByte New(RAMRange ram, string name) => new VByte().Dim(ram, name);
示例#18
0
 public override VDecimal_1_1 Dim(RAMRange ram, string name)
 {
     Size = 2;
     base.Dim(ram, name);
     return(this);
 }
示例#19
0
 public static VDecimal_1_1 New(RAMRange ram, string name) => new VDecimal_1_1().Dim(ram, name);
示例#20
0
 public static VDecimal New(RAMRange ram, ushort intLen, ushort fracLen, string name) => new VDecimal()
 {
     Size    = intLen + fracLen,
     IntLen  = intLen,
     FracLen = fracLen
 }.Dim(ram, name);
示例#21
0
 //TODO: determine if Size should be a static property tallied and cached once. If so, remove tallying from New and use the static prop.
 public override Var Dim(RAMRange ram, string name) => throw new Exception("Lazy-dimming of structs not yet supported. Use Struct.New<T> for now.");         //TODO: try to implement this for struct-in-struct support
示例#22
0
 public static VarN New(RAMRange ram, int len, string name) => new VarN()
 {
     Size = len
 }.Dim(ram, name);
示例#23
0
 public static new Ptr New(RAMRange Zp, string name) => new Ptr(Zp, name);
示例#24
0
 public static VInteger New(RAMRange ram, ushort intLen, string name) => (VInteger) new VInteger()
 {
     Size = intLen
 }.Dim(ram, name);
示例#25
0
 public virtual Var Dim(RAMRange ram, string name) => throw new NotSupportedException();
示例#26
0
 public static VWord New(RAMRange ram, string name) => (VWord) new VWord().Dim(ram, name);
 public static void WriteVariable(RAMRange ram, Address startAddr, Address endAddr, string name)
 {
     Contents += $"R:{ startAddr.ToString().Substring(1) }-{ endAddr.ToString().Substring(1) }:{ name }\n";
 }