{ // Form1.load calls ipl mem contains micro cwds, Cvbl has type name and value public void ipl(ListBox lBin, List <uint> mem, List <Parser.Cvbl> cVin) { AdrCtl aC = new AdrCtl(); // AdrCtl generates memory block addresses for exe aC.vbls = new VRam(); // Type values used in exe foreach (Parser.Cvbl v in cVin) { aC.vbls.vbls.Add(v.val); // may need to add non int types } aC.cV = cVin; mem.Add(0); // nop pad to prevent out of range exception -- Unnecessary??? aC.sCwA = new CtlRom(mem); // maybe unnecessary if mem is used aC.sCwA.srom.Capacity = 256; aC.sCwA.srom.AddRange(mem.ToArray()); // makes chip memory size a power of two for build aC.sCwA.srom.Add(0); // nop padding to prevent out of range exception -- Unnecessary??? aC.sCwA.srom.Add(0); aC.vbls.vbls.Capacity = 256; // need to calculate for stack size while (aC.vbls.vbls.Count < aC.vbls.vbls.Capacity) { aC.vbls.vbls.Add(0); } aC.Alu.ac = aC; // in case Alu needs an aC field lBin.Items.Add("Starting"); aC.pec0(); // executes and formats cycle activity listBox foreach (string s in aC.lB1) // maybe pass lBin to aC ??? TBD { lBin.Items.Add(s); } }
public void pec0() { // initialize call stack cStk.adra = 0; cStk.wrena = true; cStk.adrb = 1; cStk.wrenb = true; cStk.dina = ((uint)vbls.vbls.Capacity - 1); cStk.dinb = 0; cStk.clka(); // clock stack memory to initialize -- cStk.clkb(); // start execution int cycle = 0; uint callPtr = 0; string fmt; while (lB1.Count < 200) // limit execution to 200 logs { if (rtn && !call) // end of uCwds { return; } // nxtV does nothing, call makes the parm values visible // nxtV(etime, endop, pway, tjmp, fjmp, gtr, eql, less, push, pop, call, rtn); // callCt, base; stkCt, cwCt; callCt is the call stack ptr // address calculation for operands vadra = pway ? (sCwA.qb & 0xffff) + (cStk.qb >> 16) : !etime && !call ? (sCwA.qa >> 16) + (cStk.qb >> 16) : etime && call ? cStk.qa : pop ? cStk.qa + 1 : etime ? cStk.qa : 0; vadrb = pop ? cStk.qa : (etime || call) && !endop ? sCwA.qb + (cStk.qb >> 16) : (!etime && !call) || endop ? (sCwA.qa & 0xffff) + (cStk.qb >> 16) : 0; // address calculation for cwds sadra = (UInt16)(!etime && !endop ? (cStk.qb & 0xffff) == 0 ? 2 : cStk.qb + 1 : etime ? (cmet || call && endop && !rtn) ? sCwA.qb : (endop || push) ? call ? 0 : (cStk.qb + 1) : 0 : cStk.qb + 1); sadrb = (UInt16)(etime && endop || push && !call || !etime && pway ? 0 : cStk.qb + 1); // visualize cycle activity fmt = String.Format("cycle = {0} {1}{2}{3}{4}{5}{6} Op1 = {7}; {8} Op2 = {9}; Alu = {10} {11} {12}" , cycle, (Parser.ucdEnum)(sCwA.qb & 0xfff0), (tjmp ? ",tna " : ""), (fjmp ? ",fna " : "") // 0, 1, 2, 3 , (gtr ? ",gtr " : ""), (eql ? ",eql " : ""), (less ? ",less" : "") // 4, 5, 6 , vbls.qa, (Parser.ucdEnum)((sCwA.qb >> 16) & 0x01f), vbls.qb, Alu.qa // 7, 8, 9 , wrtVa ? (("; wrt " + Alu.qa + " to ") + ((pway && !call) ? (int)vadra < cV.Count ? cV[(int)vadra].name : "vbls[" + vadra + "]" : "TOS")) : "" // ---------------------------------------------------- // --------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------------------------------ , cmet ? " cmet " : ""); // lB1.Add(fmt); if (lB1.Count >= 100) { return; } //c0 sCwA.adra = (UInt16)sadra; // (((UInt16)cStk.qb) == 0 ? 2 : cStk.qb + 1); sCwA.adrb = (UInt16)sadrb; // (endop ? 0 : cStk.qb + 1); AdrCtl myac = new AdrCtl(); //vbls.ac = myac; //myac.vbls = vbls; //int x = vbls.ac.vbls.vbls.Count; // callPtr, base; stkPtr, cwPtr; // callPtr, stkPtr; base, cwPtr; // caller pushes args, uses caller base to get args, pushes parms to stk // call || push for first arg push call stk stk ct and base; then push at endop new base and cwCt // at endop stkCt is new base, fn.cwix is new cwCt // look at controls nxtV(etime, endop, pway, tjmp, fjmp, gtr, eql, less, push, pop, call, rtn); // cStk.qa [callPtr][base] cStk.qb [stkCt][cwCt] callPtr = call && !rtn && endop ? (cStk.qa >> 16) : call && rtn ? (cStk.qa >> 16) : cStk.qa >> 16; cStk.adra = call && push ? callPtr + 2 : callPtr; cStk.adrb = call ? (push || endop) ? callPtr + 1 : callPtr - 1 : callPtr + 1; // always calllPtr + 1 ???????? cStk.wrena = call && rtn ? false : true; cStk.wrenb = call && rtn ? false : true; cStk.dina = pop ? cStk.qa + 1 : call ? push ? (uint)(((callPtr & 0xffff) + 2) << 16) | (UInt16)(cStk.qa - 1) : rtn ? (uint)(((callPtr & 0xffff) - 2) << 16) | (UInt16)(cStk.qa - 1) : (uint)((callPtr & 0xffff) << 16) | (UInt16)(cStk.qa - 1) : push ? cStk.qa - 1 : cStk.qa; cStk.dinb = call && endop && !rtn ? cStk.qa << 16 | (UInt16)sCwA.qb : cStk.qb & 0xffff0000 | (UInt16)((cmet || call && endop && !rtn) ? sCwA.qb : cStk.qb + 1); //: endop ? 0 : cStk.qb + 1; //(endop || push) ? call ? 0 : (cStk.qb + 1) : 0); //((push || (call && !rtn) ? (cStk.qa - 0x00010000) : pop ? (cStk.qa + 0x00010000) : cStk.qa //| (call && endop && !rtn ? (cStk.qa & 0xffff0000) | (UInt16)sCwA.qb //: (cStk.qb >> 16) << 16) | (UInt16)(cStk.qb == 0 ? 2 : cmet ? sCwA.qb : cStk.qb + 1))); //callPtr = call ? push ? (cStk.qa >> 16) + 2 : rtn ? (cStk.qa >> 16) - 2 : (cStk.qa >> 16) : (cStk.qa >> 16); //cStk.adra = callPtr; //cStk.adrb = call && !endop ? callPtr - 1 : callPtr + 1; ////| (call && endop && rtn ? callPtr + 1 : 0); //cStk.wrena = call && rtn ? false : true; //cStk.wrenb = call && rtn ? false : true; //cStk.dina = callPtr << 16 | (UInt16)(push || (call && !rtn) ? cStk.qa - 1 : pop ? cStk.qa + 1 : cStk.qa); //cStk.dinb = call && endop && !rtn ? ((cStk.qa) << 16) | (UInt16)(sCwA.qb) : ((cStk.qb >> 16) << 16) // | (UInt16)((cStk.qb == 0 ? 2 : cmet ? sCwA.qb : cStk.qb + 1)); // new values for variables memory vbls.dina = Alu.qa; vbls.adra = (UInt16)vadra; vbls.adrb = (UInt16)vadrb; vbls.wrena = wrtVa ? true : false; if (wrtVa) { } // two step "clocking" emulates hardware parallelism sCwA.clka(); sCwA.clkb(); vbls.clka(); vbls.clkb(); if (sCwA.qa == 0xffffffff || sCwA.qb == 0xffffffff) { // end of of uCwds return; } // two step clock cStk to next, target, call, or return cStk.clka(); cStk.clkb(); cycle++; uint dcd = (sCwA.qb >> 16); // sCwA.adra = 0; sCwA.adrb = 0; vbls.adra = 0; vbls.adrb = 0; String cbits = ((Parser.ucdEnum)(dcd & 0XFFF0)).ToString(), aluCode; //, sCwd, oCwd; //____________________|c0|________________|c0|_______________|c0|_______________|c0|___ // sCwA[2] eop ? sCwA[cwCt.qa] : 0 // sCwB[0] sCwB[cStk.qb + 1] eop ? 0 // : sCwB[cStk.qb + 1] // va[sCwA.qa] pway ? pway@ // : etime ? cStk.qa // vb[pop ? cStk.qa // : etime ? sCwA.qb // : sCwA.qb] // cwCt.qa = 2 cwCtA = cwCt.qa + 1 //string a = "adra", b = "adrb", typ, nm; //int flgs = (int)(Parser.ops.etime |Parser.ops.pway | Parser.ops.eop); aluCode = ((Parser.ucdEnum)((sCwA.qb >> 16) & 0X1F)).ToString(); // string curcbits = sCwA.cwAlways[sCwA.cwAlways.Count - 1]; //sadra = sadrA; sadrb = sadrB; vadrb = (uint)vadrB; //if (vbls.adra != vadrA || sCwA.adra != sadrA) //{ } } }