コード例 #1
0
ファイル: ILCode.cs プロジェクト: BakkerGames/IDRIS2
 public static void OpenLib(long device, string volume, string library)
 {
     try
     {
         string libPath = $"{BasePath}{device.ToString("00")}\\{volume}\\{library}";
         if (!Directory.Exists(libPath))
         {
             throw new SystemException($"openlib({device},{volume},{library}) - path not found");
         }
         _ilcode = new string[256][]; // clear library
         foreach (string filepath in Directory.GetFiles(libPath, "*.cvp", SearchOption.TopDirectoryOnly))
         {
             string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
             int    prognum  = int.Parse(filename.Substring(0, 3));
             _ilcode[prognum] = File.ReadAllLines(filepath);
         }
     }
     catch (Exception ex)
     {
         throw new SystemException($"openlib({device},{volume},{library})\r\n{ex.Message}");
     }
     // start at first program in library
     Mem.SetByte(MemPos.prog, 0);
     Mem.SetNum(MemPos.progline, 2, 0);
 }
コード例 #2
0
        private static void ExecuteNumericAssignment()
        {
            // todo must check numeric assignment flavors
            // todo must handle numeric buffers as targets and values
            long?targetPos    = null;
            long?targetSize   = null;
            bool?isTargetByte = null;

            targetPos = MemPos.GetPosByte(_tokens[_tokenNum]);
            if (targetPos.HasValue)
            {
                targetSize   = 1;
                isTargetByte = true;
            }
            else
            {
                targetPos = MemPos.GetPosNumeric(_tokens[_tokenNum]);
                if (targetPos.HasValue)
                {
                    targetSize   = MemPos.GetSizeNumeric(_tokens[_tokenNum]);
                    isTargetByte = false;
                }
            }
            if (!targetPos.HasValue || !targetSize.HasValue || !isTargetByte.HasValue)
            {
                throw new SystemException("Cannot parse numeric assignment: Target not found");
            }
            _tokenNum++;
            if (_tokens[_tokenNum] == "[")
            {
                _tokenNum++; // "["
                long offset = GetNumericExpression();
                if (_tokens[_tokenNum++] != "]")
                {
                    throw new SystemException("GetNumericAssignment: No closing \"]\"");
                }
                targetPos += offset;
            }
            if (_tokens[_tokenNum] == "(")
            {
                throw new SystemException("TODO: Cannot handle buffer lengths yet");
            }
            if (_tokens[_tokenNum] != "=")
            {
                throw new SystemException("Cannot parse numeric expression: Equals sign expected");
            }
            _tokenNum++;
            long result = GetNumericExpression();

            if (isTargetByte.Value)
            {
                Mem.SetByte(targetPos.Value, result);
            }
            else
            {
                Mem.SetNum(targetPos.Value, targetSize.Value, result);
            }
        }
コード例 #3
0
ファイル: GosubStack.cs プロジェクト: BakkerGames/IDRIS2
        public static void Pop()
        {
            if (_gosubstack.Count < 1)
            {
                throw new SystemException($"gosub stack underflow");
            }
            StackItem item = (StackItem)_gosubstack.Pop();

            Mem.SetByte(MemPos.prog, item.prog);
            Mem.SetNum(MemPos.progline, 2, item.progline);
        }
コード例 #4
0
ファイル: RunCadol.cs プロジェクト: BakkerGames/IDRIS2
        public static void Run()
        {
            long prognum;
            long linenum;

            while (true)
            {
                // get current program and line
                prognum = Mem.GetByte(MemPos.prog);
                linenum = Mem.GetNum(MemPos.progline, 2);
                // do debug events as needed
                Debug.RaiseProgLine(prognum, linenum);
                if (Debug.HasBreakpoint(prognum, linenum))
                {
                    Debug.RaiseBreakpoint(prognum, linenum);
                }
                // handle current line
                _lineText   = ILCode.GetLine(prognum, linenum);
                _tokens     = _lineText.Split('\t');
                _tokenCount = _tokens.GetUpperBound(0) + 1;
                _tokenNum   = 0;
                if (Functions.IsNumber(_tokens[_tokenNum]))
                {
                    _tokenNum++; // line number
                }
                try
                {
                    // move to next line in preparation, could be changed by command
                    Mem.SetNum(MemPos.progline, 2, linenum + 1);
                    ExecuteLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
            }
        }
コード例 #5
0
        private static void ExecuteCommand()
        {
            long   tempNum;
            string tempAlpha;

            switch (_tokens[_tokenNum++])
            {
            case "ATT":
                long att = GetNumericValue();
                Screen.SetAttrib(att);
                break;

            case "BACK":
                Screen.Back();
                break;

            case "CAN":
            case "CANCEL":
                // todo check for cancel event
                Mem.SetNum(MemPos.progline, 2, 0);
                break;

            case "CLEAR":
                Screen.Clear();
                break;

            case "CLOSETFA":
                Console.WriteLine("### closetfa");     // todo
                break;

            case "CLOSEVOLUME":
                Console.WriteLine("### closevolume");     // todo
                break;

            case "CONVERT":
                Console.WriteLine("### convert");     // todo
                break;

            case "CR":
                Screen.CursorAt(-1, 0);
                break;

            case "CURSORAT":
                long y = GetNumericValue();
                CheckToken(",");
                long x = GetNumericValue();
                Screen.CursorAt(y, x);
                break;

            case "DCH":
                Console.WriteLine("### dch");
                break;

            case "DISPLAY":
                tempAlpha = GetAlphaExpression();
                Screen.Display(tempAlpha);
                break;

            case "ENTERALPHA":
                CheckToken("(");
                //if (_tokens[_tokenNum++] != "(")
                //{
                //    Console.WriteLine("invalid ENTERALPHA format");
                //    break;
                //}
                tempNum = GetNumericExpression();
                CheckToken(")");
                //if (_tokens[_tokenNum++] != ")")
                //{
                //    Console.WriteLine("invalid ENTERALPHA format");
                //    break;
                //}
                tempAlpha = Keyboard.GetEnteredString(tempNum);
                //todo handle entered alpha string
                break;

            case "ESC":
            case "ESCAPE":
                // todo check for esc event
                Mem.SetByte(MemPos.prog, 0);
                Mem.SetNum(MemPos.progline, 2, 0);
                break;

            case "GOS":
                tempNum = GetNumericExpression();
                GosubStack.Push();
                Mem.SetNum(MemPos.progline, 2, tempNum);
                break;

            case "GOSUB":
                tempNum = GetNumericExpression();
                GosubStack.Push();
                Mem.SetByte(MemPos.prog, tempNum);
                Mem.SetNum(MemPos.progline, 2, 0);
                break;

            case "GOTO":
                tempNum = GetNumericExpression();
                Mem.SetNum(MemPos.progline, 2, tempNum);
                break;

            case "GRAPHOFF":
                Screen.SetGraphics(false);
                break;

            case "GRAPHON":
                Screen.SetGraphics(true);
                break;

            case "HOME":
                Screen.CursorAt(0, 0);
                break;

            case "INIT":
                long?ptrPos  = MemPos.GetPosBufferPtr(_tokens[_tokenNum]);
                long?ptrPage = MemPos.GetPosBufferPage(_tokens[_tokenNum]);
                if (!ptrPos.HasValue || !ptrPage.HasValue)
                {
                    throw new SystemException("INIT error");
                }
                Mem.SetByte(ptrPos.Value + 1, ptrPage.Value);
                Mem.SetByte(ptrPos.Value, 0);
                break;

            case "INITFETCH":
                Console.WriteLine("### initfetch");     // todo
                break;

            case "KLOCK":
                Keyboard.KeyLock(true);
                break;

            case "KFREE":
                Keyboard.KeyLock(false);
                break;

            case "LOAD":
                tempNum = GetNumericExpression();
                Mem.SetByte(MemPos.prog, tempNum);
                Mem.SetNum(MemPos.progline, 2, 0);
                break;

            case "LOCK":
                Data.LockFlag(true);
                break;

            case "MERGE":
                Console.WriteLine("### merge");     // todo
                break;

            case "MOVE":
                Console.WriteLine("### move");     // todo
                break;

            case "NL":
                if (_tokenNum >= _tokenCount)
                {
                    tempNum = 1;
                }
                else
                {
                    tempNum = GetNumericExpression();
                }
                Screen.NL(tempNum);
                break;

            case "NOP":
                break;

            case "PACK":
                Console.WriteLine("### pack");     // todo
                break;

            case "PRINTOFF":
                Mem.SetBool(MemPos.printon, false);
                break;

            case "PRINTON":
                Mem.SetBool(MemPos.printon, true);
                break;

            case "REJECT":
                Screen.Reject();
                break;

            case "RESETSCREEN":
                Screen.Reset();
                break;

            case "RELEASEDEVICE":
                Console.WriteLine("### releasedevice");     // todo
                break;

            case "RETURN":
                GosubStack.Pop();
                break;

            case "SPOOL":
                Console.WriteLine("### spool");     // todo
                break;

            case "STAY":
                Screen.SetStay(true);
                break;

            case "UNLOCK":
                Data.LockFlag(false);
                break;

            case "TAB":
                if (_tokenNum >= _tokenCount)
                {
                    tempNum = 1;
                }
                else
                {
                    tempNum = GetNumericExpression();
                }
                Screen.Tab(tempNum);
                break;

            case "TABCANCEL":
                Console.WriteLine("### tabcancel");     // todo
                break;

            case "TABCLEAR":
                Console.WriteLine("### tabclear");     // todo
                break;

            case "TABSET":
                Console.WriteLine("### tabset");     // todo
                break;

            case "WHENCANCEL":
                Console.WriteLine("### whencancel");     // todo
                break;

            case "WHENERROR":
                Console.WriteLine("### whenerror");     // todo
                break;

            case "WHENESCAPE":
                Console.WriteLine("### whenescape");     // todo
                break;

            case "WRITEBACK":
                Data.WriteBack();
                break;

            case "ZERO":
                for (int i = 0; i <= 20; i++)
                {
                    Mem.SetNum(MemPos.nx(i), MemPos.numslotsize, 0);
                }
                break;

            default:
                Console.WriteLine($"Error: Unknown command {_tokens[_tokenNum - 1]}");
                break;
            }
        }
コード例 #6
0
        public static void ExecuteIf()
        {
            int saveTokenNum = _tokenNum;

            long   numAnswer1   = 0;
            long   numAnswer2   = 0;
            string alphaAnswer1 = "";
            string alphaAnswer2 = "";
            string comparitor   = "";
            bool   result       = false;

            try
            {
                numAnswer1 = GetNumericExpression();
                comparitor = _tokens[_tokenNum++];
                numAnswer2 = GetNumericExpression();
                switch (comparitor)
                {
                case "=":
                    result = (numAnswer1 == numAnswer2);
                    break;

                case "#":
                    result = (numAnswer1 != numAnswer2);
                    break;

                case "<":
                    result = (numAnswer1 < numAnswer2);
                    break;

                case ">":
                    result = (numAnswer1 > numAnswer2);
                    break;

                case "<=":
                    result = (numAnswer1 <= numAnswer2);
                    break;

                case ">=":
                    result = (numAnswer1 >= numAnswer2);
                    break;

                default:
                    throw new SystemException("Unknown comparitor");
                }
            }
            catch (Exception)
            {
                try
                {
                    _tokenNum    = saveTokenNum;
                    alphaAnswer1 = GetAlphaExpression();
                    comparitor   = _tokens[_tokenNum++];
                    alphaAnswer2 = GetAlphaExpression();
                    switch (comparitor)
                    {
                    case "=":
                        result = (alphaAnswer1 == alphaAnswer2);
                        break;

                    case "#":
                        result = (alphaAnswer1 != alphaAnswer2);
                        break;

                    case "<":
                        result = (alphaAnswer1.CompareTo(alphaAnswer2) < 0);
                        break;

                    case ">":
                        result = (alphaAnswer1.CompareTo(alphaAnswer2) > 0);
                        break;

                    case "<=":
                        result = (alphaAnswer1.CompareTo(alphaAnswer2) <= 0);
                        break;

                    case ">=":
                        result = (alphaAnswer1.CompareTo(alphaAnswer2) >= 0);
                        break;

                    default:
                        throw new SystemException("Unknown comparitor");
                    }
                }
                catch (Exception)
                {
                    throw new SystemException("Error parsing IF expressions");
                }
            }
            if (!result)
            {
                return;
            }
            if (_tokenNum >= _tokenCount)
            {
                throw new SystemException("End of line in IF");
            }
            if (_tokens[_tokenNum++] != "GOTO")
            {
                throw new SystemException("GOTO not found after IF compare");
            }
            // goto xxx
            long tempValue = GetNumericExpression();

            Mem.SetNum(MemPos.progline, 2, tempValue);
        }
コード例 #7
0
        private static long GetNumericExpression()
        {
            long   result;
            long   negative = 1;
            string currToken;

            currToken = _tokens[_tokenNum++];
            if (currToken == "-")
            {
                negative  = -1;
                currToken = _tokens[_tokenNum++];
            }
            if (currToken == "(")
            {
                result = negative * GetNumericExpression();
                if (_tokens[_tokenNum++] != ")")
                {
                    throw new SystemException("GetNumericExpression: No closing \")\"");
                }
            }
            else if (Functions.IsNumber(currToken))
            {
                result = negative * long.Parse(currToken);
            }
            else
            {
                _tokenNum--; // move back one
                result = negative * GetNumericValue();
            }
            // see if done with expression
            if (_tokenNum >= _tokenCount)
            {
                return(result);
            }
            currToken = _tokens[_tokenNum];
            switch (currToken)
            {
            case "]":
            case ")":
            case "=":
            case "#":
            case "<":
            case ">":
            case "<=":
            case ">=":
            case "GOTO":
                return(result);

            case "+":
                _tokenNum++;
                result += GetNumericExpression();
                return(result);

            case "-":
                _tokenNum++;
                result -= GetNumericExpression();
                return(result);

            case "*":
                _tokenNum++;
                result *= GetNumericExpression();
                return(result);

            case "/":
                _tokenNum++;
                long tempExpr = GetNumericExpression();
                Mem.SetNum(MemPos.rem, MemPos.numslotsize, result % tempExpr);
                return(result / tempExpr);
            }
            throw new SystemException("GetNumericExpression error");
        }