Esempio n. 1
0
        public static void SetAlpha(long pos, string value)
        {
            if (pos < 0 || pos >= MemPos.totalmemsize)
            {
                throw new SystemException($"setalpha({pos}) - out of bounds");
            }
            if (value == "") // very common!
            {
                _mem[pos] = 0;
                Mem.SetByte(MemPos.length, 1); // "" has a length of 1 byte
                return;
            }
            int c;
            int offset = 0;

            while (offset < value.Length - 1)
            {
                c = Functions.CharToAscii(value[offset]);
                _mem[pos + offset] = (byte)(c + 128);
                offset++;
            }
            c = Functions.CharToAscii(value[offset]);
            _mem[pos + offset] = (byte)c;
            Mem.SetByte(MemPos.length, value.Length); // save length of chars moved
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        private static void ExecuteAlphaAssignment()
        {
            long?targetPos = null;
            bool isBuffer  = false;

            targetPos = MemPos.GetPosAlpha(_tokens[_tokenNum]);
            if (!targetPos.HasValue)
            {
                targetPos = MemPos.GetPosBufferAlpha(_tokens[_tokenNum]);
                if (targetPos.HasValue)
                {
                    isBuffer = true;
                }
            }
            if (!targetPos.HasValue)
            {
                throw new SystemException("Cannot parse alpha assignment: Target not found");
            }
            _tokenNum++;
            if (_tokens[_tokenNum] == "[")
            {
                _tokenNum++; // "["
                long offset = GetNumericExpression();
                if (_tokens[_tokenNum++] != "]")
                {
                    throw new SystemException("ExecuteAlphaAssignment: No closing \"]\"");
                }
                targetPos += offset;
            }
            if (_tokens[_tokenNum] != "=")
            {
                throw new SystemException("Cannot parse alpha expression: Equals sign expected");
            }
            _tokenNum++;
            string result = GetAlphaExpression();

            if (isBuffer)
            {
                long bufferTargetPos = Mem.GetByte(targetPos.Value)
                                       + (256 * Mem.GetByte(targetPos.Value + 1));
                Mem.SetAlpha(bufferTargetPos, result);
                if (result == "")
                {
                    bufferTargetPos += 1;
                }
                else
                {
                    bufferTargetPos += result.Length;
                }
                Mem.SetByte(targetPos.Value + 1, bufferTargetPos / 256);
                Mem.SetByte(targetPos.Value, bufferTargetPos % 256);
            }
            else
            {
                Mem.SetAlpha(targetPos.Value, result);
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public static void SetStay(bool value)
 {
     if (value)
     {
         Mem.SetByte(MemPos.charval, 255);
     }
     else
     {
         Mem.SetByte(MemPos.charval, 0);
     }
 }
Esempio n. 7
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;
            }
        }