Beispiel #1
0
        public static long IntValue(Mem mem)
        {
            Debug.Assert(mem.Ctx == null || MutexEx.Held(mem.Ctx.Mutex));
            // assert( EIGHT_BYTE_ALIGNMENT(pMem) );
            MEM flags = mem.Flags;

            if ((flags & MEM.Int) != 0)
            {
                return(mem.u.I);
            }
            else if ((flags & MEM.Real) != 0)
            {
                return(DoubleToInt64(mem.R));
            }
            else if ((flags & (MEM.Str)) != 0)
            {
                Debug.Assert(mem.Z != null || mem.N == 0);
                C.ASSERTCOVERAGE(mem.Z == null);
                long value;
                ConvertEx.Atoi64(mem.Z, out value, mem.N, mem.Encode);
                return(value);
            }
            else if ((flags & (MEM.Blob)) != 0)
            {
                Debug.Assert(mem.Z_ != null || mem.N == 0);
                C.ASSERTCOVERAGE(mem.Z_ == null);
                long value;
                ConvertEx.Atoi64(Encoding.UTF8.GetString(mem.Z_, 0, mem.N), out value, mem.N, mem.Encode);
                return(value);
            }
            return(0);
        }
Beispiel #2
0
        private static void STA_ZP(CPU cpu, MEM memory)
        {
            byte data1 = memory.getMem((ushort)(cpu.PC + 0x0001));
            byte data2 = memory.getMem((ushort)(cpu.PC + 0x0002));

            memory.setMem(data1, data2, cpu.A);
            cpu.PC += 3;
        }
Beispiel #3
0
        private static void JMP_ABS(CPU cpu, MEM memory)
        {
            byte data1 = memory.getMem((ushort)(cpu.PC + 0x0001));
            byte data2 = memory.getMem((ushort)(cpu.PC + 0x0002));

            cpu.PC  = (ushort)(data1 << 8);
            cpu.PC += data2;
        }
Beispiel #4
0
 private void updateAll()
 {
     //IF.GetComponent<IFBehavior>().UpdateMe();
     ID.GetComponent <IDBehavior>().UpdateMe();
     EX.GetComponent <EXBehavior>().UpdateMe();
     MEM.GetComponent <MEMBehavior>().UpdateMe();
     WB.GetComponent <WBBehavior>().UpdateMe();
 }
        private static void LDA_IM(CPU cpu, MEM memory)
        {
            byte data1 = memory.getMem((ushort)(cpu.PC + 0x0001));

            cpu.A   = data1;
            cpu.Z   = (data1 == 0x00);
            cpu.N   = (data1 & 0x80) == 0x80;
            cpu.PC += 0x02;
        }
Beispiel #6
0
        public static RC MemStringify(Mem mem, TEXTENCODE encode)
        {
            MEM f = mem.Flags;

            Debug.Assert(mem.Ctx == null || MutexEx.Held(mem.Ctx.Mutex));
            Debug.Assert((f & MEM.Zero) == 0);
            Debug.Assert((f & (MEM.Str | MEM.Blob)) == 0);
            Debug.Assert((f & (MEM.Int | MEM.Real)) != 0);
            Debug.Assert((mem.Flags & MEM.RowSet) == 0);
            //: Debug.Assert(C._HASALIGNMENT8(mem));

            const int bytes = 32;

            if (MemGrow(mem, bytes, false) != 0)
            {
                return(RC.NOMEM);
            }

            // For a Real or Integer, use sqlite3_mprintf() to produce the UTF-8 string representation of the value. Then, if the required encoding
            // is UTF-16le or UTF-16be do a translation.
            // FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
            if ((f & MEM.Int) != 0)
            {
                mem.Z = mem.u.I.ToString(); //: __snprintf(mem->Z, bytes, "%lld", mem->u.I);
            }
            else
            {
                Debug.Assert((f & MEM.Real) != 0);
                if (double.IsNegativeInfinity(mem.R))
                {
                    mem.Z = "-Inf";
                }
                else if (double.IsInfinity(mem.R))
                {
                    mem.Z = "Inf";
                }
                else if (double.IsPositiveInfinity(mem.R))
                {
                    mem.Z = "+Inf";
                }
                else if (mem.R.ToString(CultureInfo.InvariantCulture).Contains("."))
                {
                    mem.Z = mem.R.ToString(CultureInfo.InvariantCulture).ToLower();                                                                  //: __snprintf(mem->Z, bytes, "%!.15g", mem->R);
                }
                else
                {
                    mem.Z = mem.R.ToString(CultureInfo.InvariantCulture) + ".0";
                }
            }
            mem.N      = mem.Z.Length;
            mem.Encode = TEXTENCODE.UTF8;
            mem.Flags |= MEM.Str | MEM.Term;
            ChangeEncoding(mem, encode);
            return(RC.OK);
        }
Beispiel #7
0
    void Update()
    {
        if (MEM.GetIsMovieEvent())
        {
            return;
        }

        GetInputKey();          // ① 入力を取得
        ChangeState();          // ② 状態を変更する
        ChangeAnimation();      // ③ 状態に応じてアニメーションを変更する
        Move();                 // ④ 入力に応じて移動する
    }
        private static void INC_ZP(CPU cpu, MEM memory)
        {
            byte data1 = memory.getMem((ushort)(cpu.PC + 0x0001));
            byte data2 = memory.getMem((ushort)(cpu.PC + 0x0002));
            byte x     = memory.getMem(data1, data2);

            x++;
            memory.setMem(data1, data2, x);
            cpu.Z   = (x == 0x00);
            cpu.N   = (x & 0x80) == 0x80;
            cpu.PC += 3;
        }
Beispiel #9
0
        public static RC MemSetStr(Mem mem, byte[] z, int offset, int n, TEXTENCODE encode, Action <object> del)
        {
            Debug.Assert(mem.Ctx == null || MutexEx.Held(mem.Ctx.Mutex));
            Debug.Assert((mem.Flags & MEM.RowSet) == 0);
            // If z is a NULL pointer, set pMem to contain an SQL NULL.
            if (z == null || z.Length < offset)
            {
                MemSetNull(mem);
                return(RC.OK);
            }

            int limit = (mem.Ctx != null ? mem.Ctx.Limits[(int)LIMIT.LENGTH] : CORE_MAX_LENGTH); // Maximum allowed string or blob size
            MEM flags = (encode == 0 ? MEM.Blob : MEM.Str);                                      // New value for pMem->flags
            int bytes = n;                                                                       // New value for pMem->n

            if (bytes < 0)
            {
                Debug.Assert(encode != 0);
                if (encode == TEXTENCODE.UTF8)
                {
                    for (bytes = 0; bytes <= limit && bytes < z.Length - offset && z[offset + bytes] != 0; bytes++)
                    {
                    }
                }
                else
                {
                    for (bytes = 0; bytes <= limit && z[bytes + offset] != 0 || z[offset + bytes + 1] != 0; bytes += 2)
                    {
                    }
                }
            }

            // The following block sets the new values of Mem.z and Mem.xDel. It also sets a flag in local variable "flags" to indicate the memory
            // management (one of MEM_Dyn or MEM_Static).
            Debug.Assert(encode == 0);
            {
                mem.Z  = null;
                mem.Z_ = C._alloc(n);
                Buffer.BlockCopy(z, offset, mem.Z_, 0, n);
            }
            mem.N      = bytes;
            mem.Flags  = MEM.Blob | MEM.Term;
            mem.Encode = (encode == 0 ? TEXTENCODE.UTF8 : encode);
            mem.Type   = (encode == 0 ? TYPE.BLOB : TYPE.TEXT);

#if !OMIT_UTF16
            if (mem.Encode != TEXTENCODE.UTF8 && MemHandleBom(mem) != 0)
            {
                return(RC.NOMEM);
            }
#endif
            return(bytes > limit ? RC.TOOBIG : RC.OK);
        }
Beispiel #10
0
        public static void execute(CPU cpu, MEM memory)
        {
            switch (memory.getMem(cpu.PC))
            {
            case 0x4C:
                JMP.JMP_ABS(cpu, memory);
                return;

            case 0x6C:
                JMP.JMP_INDIRECT(cpu, memory);
                return;
            }
        }
Beispiel #11
0
 //: #define MEMCELLSIZE (size_t)(&(((Mem *)0)->Malloc)) // Size of struct Mem not including the Mem.zMalloc member.
 public static void MemShallowCopy(Mem to, Mem from, MEM srcType)
 {
     Debug.Assert((from.Flags & MEM.RowSet) == 0);
     MemReleaseExternal(to);
     from._memcpy(ref to);
     to.Del = null;
     if ((from.Flags & MEM.Static) != 0)
     {
         to.Flags &= ~(MEM.Dyn | MEM.Static | MEM.Ephem);
         Debug.Assert(srcType == MEM.Ephem || srcType == MEM.Static);
         to.Flags |= srcType;
     }
 }
Beispiel #12
0
        private static void JMP_INDIRECT(CPU cpu, MEM memory)
        {
            byte   data1   = memory.getMem((ushort)(cpu.PC + 0x0001));
            byte   data2   = memory.getMem((ushort)(cpu.PC + 0x0002));
            ushort address = (ushort)(data1 << 8);

            address += data2;
            byte jumpToH = memory.getMem(address);
            byte jumpToL = memory.getMem((ushort)(address + 0x0001));

            cpu.PC  = (ushort)(jumpToH << 8);
            cpu.PC += jumpToL;
        }
Beispiel #13
0
        public static void execute(CPU cpu, MEM memory)
        {
            switch (memory.getMem(cpu.PC))
            {
            case 0xE6:
            case 0xEE:
                INC.INC_ZP(cpu, memory);
                return;

            case 0xF6:
            case 0xFE:
                return;
            }
        }
Beispiel #14
0
        public static void execute(CPU cpu, MEM memory)
        {
            switch (memory.getMem(cpu.PC))
            {
            case 0x85:
                STA.STA_ZP(cpu, memory);
                return;

            case 0x95:
            case 0x8D:
            case 0x9D:
            case 0x99:
            case 0x81:
            case 0x91:
                return;
            }
        }
Beispiel #15
0
        public static void execute(CPU cpu, MEM memory)
        {
            switch (memory.getMem(cpu.PC))
            {
            case 0xA9:
                LDA.LDA_IM(cpu, memory);
                return;

            case 0xA5:
            case 0xB5:
            case 0xAD:
            case 0xBD:
            case 0xB9:
            case 0xA1:
            case 0xB1:
                return;
            }
        }
Beispiel #16
0
    public void oneRight()
    {
        if (WB.GetComponent <WBBehavior>().oper != null)
        {
            doneOp.Push(WB.GetComponent <WBBehavior>().oper);
        }

        WB.GetComponent <WBBehavior>().oper         = MEM.GetComponent <MEMBehavior>().oper;
        MEM_WB.GetComponent <MEM_WBBehavior>().oper = MEM.GetComponent <MEMBehavior>().oper;
        MEM.GetComponent <MEMBehavior>().oper       = EX.GetComponent <EXBehavior>().oper;
        EX_MEM.GetComponent <EX_MEMBehavior>().oper = EX.GetComponent <EXBehavior>().oper;
        EX.GetComponent <EXBehavior>().oper         = ID.GetComponent <IDBehavior>().oper;
        ID_EX.GetComponent <ID_EXBehavior>().oper   = ID.GetComponent <IDBehavior>().oper;
        ID.GetComponent <IDBehavior>().oper         = IF.GetComponent <IFBehavior>().oper;
        IF_ID.GetComponent <IF_IDBehavior>().oper   = IF.GetComponent <IFBehavior>().oper;
        IF.GetComponent <IFBehavior>().oper         = null;

        updateAll();
    }
Beispiel #17
0
        public Mem(sqlite3 db, string z, double r, int i, int n, MEM flags, byte type, byte enc
#if DEBUG
                   , Mem pScopyFrom, object pFiller
#endif
                   )
        {
            this.db    = db;
            this.z     = z;
            this.r     = r;
            this.u.i   = i;
            this.n     = n;
            this.flags = flags;
#if DEBUG
            this.pScopyFrom = pScopyFrom;
            this.pFiller    = pFiller;
#endif
            this.type = type;
            this.enc  = enc;
        }
Beispiel #18
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                CPU.Dispose();
                MEM.Dispose();
                NVM.Dispose();
                CPU = null;
                MEM = null;
                NVM = null;

                disposed = true;
            }
        }
Beispiel #19
0
            Temp.Temp TranslateExpr(MEM expr)
            {
                Temp.Temp result = new Temp.Temp();
                Temp.Temp mem;
                int       offset;

                if (expr.Exp is BINOP && (expr.Exp as BINOP).Right is CONST)
                {
                    mem    = TranslateExpr((expr.Exp as BINOP).Left);
                    offset = ((expr.Exp as BINOP).Right as CONST).Value;
                }
                else
                {
                    mem    = TranslateExpr(expr.Exp);
                    offset = 0;
                }
                InstrList.Add(new Load(mem, offset, result));
                return(result);
            }
Beispiel #20
0
        public Mem(Context db, string z, double r, int i, int n, MEM flags, TYPE type, TEXTENCODE encode
#if DEBUG
                   , Mem scopyFrom, object filler
#endif
                   )
        {
            Ctx   = db;
            Z     = z;
            R     = r;
            u.I   = i;
            N     = n;
            Flags = flags;
#if DEBUG
            ScopyFrom = scopyFrom;
            Filler    = filler;
#endif
            Type   = type;
            Encode = encode;
        }
Beispiel #21
0
                public EmuGB(ConfigsGB aConfigs)
                {
                    m_configs = aConfigs;

                    m_cpu = new CPU();
                    m_ppu = new PPU();
                    m_apu = new APU();

                    m_mem             = new MEM();
                    m_dmaController   = new DMAController();
                    m_timerController = new TimerController();

                    m_joypad = new Joypad();

                    m_serialIO = new SerialIO();

                    // Start paused
                    m_paused = true;

                    // Temp binding
                    DrawDisplay     = (aPPU) => { };
                    DrawDisplayLine = (aPPU, aScanline) => { };


                    m_mem.AttachCPU(m_cpu);
                    m_mem.AttachPPU(m_ppu);
                    m_mem.AttachAPU(m_apu);
                    m_mem.AttachDMAController(m_dmaController);
                    m_mem.AttachTimerController(m_timerController);
                    m_mem.AttachJoypad(m_joypad);
                    m_mem.AttachSerialIO(m_serialIO);
                    m_cpu.ProcessorState.BindCyclesStep(m_ppu.CyclesStep);
                    m_cpu.ProcessorState.BindCyclesStep(m_apu.CyclesStep);
                    m_cpu.ProcessorState.BindCyclesStep(m_dmaController.CyclesStep);
                    m_cpu.ProcessorState.BindCyclesStep(m_timerController.CyclesStep);
                    m_cpu.ProcessorState.BindCyclesStep(m_serialIO.CyclesStep);

                    m_ppu.BindRequestIRQ(m_cpu.RequestIRQ);
                    m_timerController.BindRequestIRQ(m_cpu.RequestIRQ);
                    m_joypad.BindRequestIRQ(m_cpu.RequestIRQ);
                    m_serialIO.BindRequestIRQ(m_cpu.RequestIRQ);
                    //m_ppu.BindDrawDisplayLine(DrawDisplayLine);
                }
Beispiel #22
0
        public GBA(ushort[] display)
        {
            this.cpu = new ARM7TDMI(this, this.EventQueue);
            this.IO  = this.cpu.IO;
            this.mem = this.cpu.mem;
            this.bus = this.cpu.bus;

            this.apu = new APU(this.cpu, this.EventQueue);
            this.ppu = new PPU(this, display, this.IO);

            this.mem.Init(this.ppu);
            this.IO.Init(this.ppu, this.bus);
            this.IO.Layout(this.cpu, this.apu);

            // this.mem.UseNormattsBIOS();

            this.display = display;
#if THREADED_RENDERING
            this.RenderThread = new Thread(() => ppu.Mainloop());
#endif
        }
        private static bool CheckMemType(MEM actualType, MemType flags)
        {
            switch (actualType)
            {
            case MEM.PRIVATE:
                return((flags & MemType.Private) != 0);

            case MEM.IMAGE:
                return((flags & MemType.Image) != 0);

            case MEM.MAPPED:
                return((flags & MemType.Mapped) != 0);

            default:
                if (flags == MemType.All)
                {
                    return(true);
                }
                throw new InvalidOperationException("Unknown/Bogus Memory Type!");
            }
        }
Beispiel #24
0
        public static RC MemMakeWriteable(Mem mem)
        {
            Debug.Assert(mem.Ctx == null || MutexEx.Held(mem.Ctx.Mutex));
            Debug.Assert((mem.Flags & MEM.RowSet) == 0);
            E.ExpandBlob(mem);
            MEM f = mem.Flags;

            if ((f & (MEM.Str | MEM.Blob)) != 0) //: mem->Z != mem->Malloc)
            {
                if (MemGrow(mem, mem.N + 2, true) != 0)
                {
                    return(RC.NOMEM);
                }
                //: mem.Z[mem.N] = 0;
                //: mem.Z[mem.N + 1] = 0;
                mem.Flags |= MEM.Term;
#if DEBUG
                mem.ScopyFrom = null;
#endif
            }
            return(RC.OK);
        }
Beispiel #25
0
    public void oneLeft()
    {
        IF.GetComponent <IFBehavior>().oper         = ID.GetComponent <IDBehavior>().oper;
        ID.GetComponent <IDBehavior>().oper         = EX.GetComponent <EXBehavior>().oper;
        IF_ID.GetComponent <IF_IDBehavior>().oper   = ID.GetComponent <IDBehavior>().oper;
        EX.GetComponent <EXBehavior>().oper         = MEM.GetComponent <MEMBehavior>().oper;
        ID_EX.GetComponent <ID_EXBehavior>().oper   = EX.GetComponent <EXBehavior>().oper;
        MEM.GetComponent <MEMBehavior>().oper       = WB.GetComponent <WBBehavior>().oper;
        EX_MEM.GetComponent <EX_MEMBehavior>().oper = MEM.GetComponent <MEMBehavior>().oper;

        if (doneOp.Count > 0)
        {
            WB.GetComponent <WBBehavior>().oper         = (GameObject)doneOp.Pop();
            MEM_WB.GetComponent <MEM_WBBehavior>().oper = WB.GetComponent <WBBehavior>().oper;
        }
        else
        {
            WB.GetComponent <WBBehavior>().oper         = null;
            MEM_WB.GetComponent <MEM_WBBehavior>().oper = null;
        }
        updateAll();
    }
Beispiel #26
0
        public ARM7TDMI(GBA gba, Scheduler.Scheduler scheduler)
        {
            this.gba      = gba;
            this.Pipeline = new cPipeline(this);

            this.InitARM();
            this.InitTHUMB();
            this.InitTimers(scheduler);

            // IO requires bus to be initialized
            this.bus = new BUS(this);
            this.IO  = new IORAMSection();

            // DMAChannels require bus AND IO to be initialized
            this.DMAChannels[0] = new DMAChannel(this, 0);
            this.DMAChannels[1] = new DMAChannel(this, 1);
            this.DMAChannels[2] = new DMAChannel(this, 2);
            this.DMAChannels[3] = new DMAChannel(this, 3);

            // mem requires IO AND DMAChannels to be initialized
            this.mem = new MEM(this);

            this.SystemBank     = new uint[16];
            this.FIQBank        = new uint[16];
            this.SupervisorBank = new uint[16];
            // this.AbortBank      = new uint[16];
            this.IRQBank = new uint[16];
            // this.UndefinedBank  = new uint[16];
            this.state = State.ARM;

            // need banked registers for CPSR initialization
            this.CPSR = 0x0000005F;

            this.PipelineFlush();
            this.PC += 4;
        }
Beispiel #27
0
 void PrintExp(MEM e, int d)
 {
     Indent(d);
     SayLn("MEM("); PrintExp(e.Exp, d + 1); Say(")");
 }
Beispiel #28
0
 //: #define MEMCELLSIZE (size_t)(&(((Mem *)0)->Malloc)) // Size of struct Mem not including the Mem.zMalloc member.
 public static void MemShallowCopy(Mem to, Mem from, MEM srcType)
 {
     Debug.Assert((from.Flags & MEM.RowSet) == 0);
     MemReleaseExternal(to);
     from._memcpy(ref to);
     to.Del = null;
     if ((from.Flags & MEM.Static) != 0)
     {
         to.Flags &= ~(MEM.Dyn | MEM.Static | MEM.Ephem);
         Debug.Assert(srcType == MEM.Ephem || srcType == MEM.Static);
         to.Flags |= srcType;
     }
 }
Beispiel #29
0
 public static void MemSetTypeFlag(Mem p, MEM f)
 {
     p.Flags = (p.Flags & ~(MEM.TypeMask | MEM.Zero) | f);
 }
Beispiel #30
0
 public System.IntPtr GetPtr(MEM mem = MEM.MEM_CPU)
 {
     return(dllz_mat_get_ptr(_matInternalPtr, (int)mem));
 }
Beispiel #31
0
 /// <summary>
 /// Allocates memory for the Mat.
 /// </summary>
 /// <param name="resolution">Size of the image/matrix in pixels.</param>
 /// <param name="matType">Type of matrix (data type and channels; see sl.MAT_TYPE)</param>
 /// <param name="mem">Where the buffer will be stored - CPU memory or GPU memory.</param>
 public void Alloc(sl.Resolution resolution, MAT_TYPE matType, MEM mem = MEM.MEM_CPU)
 {
     dllz_mat_alloc(_matInternalPtr, (int)resolution.width, (int)resolution.height, (int)matType, (int)mem);
 }
Beispiel #32
0
 /// <summary>
 /// Allocates memory for the Mat.
 /// </summary>
 /// <param name="width">Width of the image/matrix in pixels.</param>
 /// <param name="height">Height of the image/matrix in pixels.</param>
 /// <param name="matType">Type of matrix (data type and channels; see sl.MAT_TYPE)</param>
 /// <param name="mem">Where the buffer will be stored - CPU memory or GPU memory.</param>
 public void Alloc(uint width, uint height, MAT_TYPE matType, MEM mem = MEM.MEM_CPU)
 {
     dllz_mat_alloc(_matInternalPtr, (int)width, (int)height, (int)matType, (int)mem);
 }
Beispiel #33
0
 Temp.Temp TranslateExpr(MEM expr)
 {
     Temp.Temp result = new Temp.Temp();
     Temp.Temp mem;
     int offset;
     if (expr.Exp is BINOP && (expr.Exp as BINOP).Right is CONST)
     {
         mem = TranslateExpr((expr.Exp as BINOP).Left);
         offset = ((expr.Exp as BINOP).Right as CONST).Value;
     }
     else
     {
         mem = TranslateExpr(expr.Exp);
         offset = 0;
     }
     InstrList.Add(new Load(mem, offset, result));
     return result;
 }