Exemple #1
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();
            }
        }
Exemple #2
0
        private void writeBattery(WriteHandleRequest request)
        {
            Handle handle = this.kernelStorage.handles[request.handle];

            ((Battery)handle).setStatus(request.bytesToWrite[0]);
            Resource response = new WriteHandleResponse(this.id, 0, 4, request.createdByProcess);

            this.kernelStorage.resources.add(response);
            request.release();
        }
Exemple #3
0
        private void writeHandle(WriteHandleRequest request)
        {
            Handle   handle = this.kernelStorage.handles[request.handle];
            Resource response;

            if (handle is Battery)
            {
                writeBattery(request);
                return;
            }

            setDevice(handle, 1);

            uint amountWritten = 0;

            try
            {
                for (uint i = 0; i < request.bytesToWrite.Length; i++)
                {
                    amountWritten++;
                    handle.write(request.bytesToWrite[i]);
                }

                response = new WriteHandleResponse(this.id, 0, amountWritten, request.createdByProcess);
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Writing file out of bounds"))
                {
                    throw e;
                }

                response = new WriteHandleResponse(this.id, 1, amountWritten, request.createdByProcess);
            }

            setDevice(handle, 0);

            kernelStorage.resources.add(response);
            request.release();
        }