public override void run() { switch (this.IC) { case 0: for (int i = 0; i < Constants.BLOCKS_AMOUNT; i++) { kernelStorage.resources.add(new Resource(ResType.Memory, this.id)); } this.kernelStorage.resources.add(new CreateHandleRequest(this.id, "testfile")); this.resourceRequestor.request(ResType.CreateHandleResponse, this.id); this.IC++; break; case 1: created = this.getFirstResource(ResType.CreateHandleResponse, this.id) as CreateHandleResponse; this.kernelStorage.resources.add(new WriteHandleRequest(this.id, created.handle, new byte[] { 5, 5, 5, 5 })); this.resourceRequestor.request(ResType.WriteHandleResponse, this.id); this.IC++; break; case 2: Resource response = this.getFirstResource(ResType.WriteHandleResponse, this.id); break; } }
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(); } }
private void mountBattery(BaseHandleResource request) { if (this.kernelStorage.channelDevice.battery == 1) { return; } this.kernelStorage.channelDevice.battery = 1; int hndl = this.kernelStorage.handles.add(new Battery()); Resource response = new CreateHandleResponse(this.id, hndl, request.createdByProcess, HandleType.Battery); kernelStorage.resources.add(response); request.release(); }
public void createFileHandle(CreateHandleRequest request) { //wait until released if (this.kernelStorage.handles.isFileTaken(request.fileName)) { return; } StorageFile file = StorageFile.OpenOrCreate(this.kernelStorage.virtualHdd, request.fileName); FileHandle fh = new FileHandle(file); int hndl = this.kernelStorage.handles.add(fh); Resource response = new CreateHandleResponse(this.id, hndl, request.createdByProcess); kernelStorage.resources.add(response); request.release(); }