示例#1
0
        private void readHandleFile(FileHandle hndl, ReadHandleRequest request)
        {
            this.kernelStorage.channelDevice.storage = 1;
            byte[] readBytes = new byte[request.amount];

            Resource response;
            uint     amountRead = 0;

            try
            {
                for (uint i = 0; i < request.amount; i++)
                {
                    amountRead++;
                    readBytes[i] = hndl.read();
                }
                response = new ReadHandleResponse(this.id, readBytes, 0, checked ((uint)request.amount), request.createdByProcess);
                //program.memAccesser.writeFromAddr(program.registers.DS + program.registers.A, readBytes);
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Reading file out of bounds"))
                {
                    throw e;
                }

                response = new ReadHandleResponse(this.id, readBytes, 1, checked ((uint)request.amount), request.createdByProcess);
                //program.memAccesser.writeFromAddr(program.registers.DS + program.registers.A, readBytes);
            }


            this.kernelStorage.channelDevice.storage = 0;
            kernelStorage.resources.add(response);
            request.release();
        }
示例#2
0
        private void readHandleConsole(ConsoleDevice hndl, ReadHandleRequest request)
        {
            this.kernelStorage.channelDevice.console = 1;
            byte[] readBytes = hndl.readLine();

            Resource response;

            if (readBytes.Length > request.amount)
            {
                //program.memAccesser.writeFromAddr(program.registers.DS + program.registers.A, readBytes, program.registers.CX);
                //program.registers.A = 1;
                response = new ReadHandleResponse(this.id, readBytes, 1, checked ((uint)request.amount), request.createdByProcess);
            }
            else
            {
                uint len = checked ((uint)readBytes.Length);
                response = new ReadHandleResponse(this.id, readBytes, 0, checked ((uint)request.amount), request.createdByProcess);
                //program.memAccesser.writeFromAddr(program.registers.DS + program.registers.A, readBytes, len);
                //program.registers.CX = len;
                //program.registers.A = 0;
            }

            this.kernelStorage.channelDevice.console = 0;
            //program.registers.A = 0;
            //program.registers.SI = SiInt.None;
            kernelStorage.resources.add(response);
            request.release();
        }
示例#3
0
        private void readHandleBattery(Battery battery, ReadHandleRequest request)
        {
            Resource response = new ReadHandleResponse(this.id, battery.getStatus(), 0, checked ((uint)request.amount), request.createdByProcess);

            kernelStorage.resources.add(response);
            request.release();
        }
示例#4
0
        public void handleResponse(Resource resource)
        {
            switch (resource.type)
            {
            case ResType.CreateHandleResponse:
            {
                Program program = process.virtualMachine.program;
                CreateHandleResponse createHandleResponse = (CreateHandleResponse)resource;
                program.registers.B  = (uint)(createHandleResponse.handle);
                program.registers.SI = SiInt.None;
                break;
            }

            case ResType.ReadHandleResponse:
            {
                Program            program  = process.virtualMachine.program;
                ReadHandleResponse response = (ReadHandleResponse)resource;
                if (response.readBytes.Length > response.bytesRequested)
                {
                    program.memAccesser.writeFromAddr(program.registers.DS + program.registers.A, response.readBytes, response.bytesRequested);
                    program.registers.CX = response.bytesRequested;
                    program.registers.SI = SiInt.None;
                }
                else
                {
                    uint len = checked ((uint)response.readBytes.Length);
                    program.memAccesser.writeFromAddr(program.registers.DS + program.registers.A, response.readBytes, len);
                    program.registers.CX = len;
                }

                program.registers.A  = response.status;
                program.registers.SI = SiInt.None;

                break;
            }

            case ResType.WriteHandleResponse:
            {
                Program             program             = process.virtualMachine.program;
                WriteHandleResponse writeHandleResponse = (WriteHandleResponse)resource;
                program.registers.A  = writeHandleResponse.status;
                program.registers.CX = writeHandleResponse.amountWritten;
                program.registers.SI = SiInt.None;
                break;
            }

            case ResType.CloseHandleResponse:
            case ResType.DeleteHandleResponse:
            case ResType.SeekHandleResponse:
            {
                Program program = process.virtualMachine.program;
                program.registers.SI = SiInt.None;
                // do nothing - just wait and release
                break;
            }

            default:
                throw new NotImplementedException();
            }
        }