public virtual int readNextInstruction() { lock (this) { pc += 4; return(memoryReader.readNext()); } }
public virtual int sceUriUnescape(TPointer unescapedAddr, TPointer32 unescapedLengthAddr, int unescapedBufferLength, TPointer source) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(source.Address, 1); IMemoryWriter memoryWriter = null; if (unescapedAddr.NotNull) { memoryWriter = MemoryWriter.getMemoryWriter(unescapedAddr.Address, unescapedBufferLength, 1); } int unescapedLength = 0; while (true) { int c = memoryReader.readNext(); if (c == 0) { if (unescapedAddr.NotNull) { if (unescapedLength < unescapedBufferLength) { memoryWriter.writeNext(c); } } unescapedLength++; break; } if (unescapedAddr.NotNull) { if (unescapedLength + 1 > unescapedBufferLength) { break; } if (c == '%') { int hex1 = memoryReader.readNext(); int hex2 = memoryReader.readNext(); c = (getHexValue(hex1) << 4) + getHexValue(hex2); } // Remark: '+' sign is not unescaped to ' ' by this function memoryWriter.writeNext(c); } unescapedLength++; } if (memoryWriter != null) { memoryWriter.flush(); } unescapedLengthAddr.setValue(unescapedLength); return(0); }
public virtual int strncmp(TPointer src1Addr, TPointer src2Addr, int size) { int result = 0; if (size > 0) { IMemoryReader memoryReader1 = MemoryReader.getMemoryReader(src1Addr.Address, size, 1); IMemoryReader memoryReader2 = MemoryReader.getMemoryReader(src2Addr.Address, size, 1); if (memoryReader1 != null && memoryReader2 != null) { for (int i = 0; i < size; i++) { int c1 = memoryReader1.readNext(); int c2 = memoryReader2.readNext(); if (c1 != c2) { result = c1 - c2; break; } else if (c1 == 0) { // c1 == 0 and c2 == 0 break; } } } } return(result); }
/// <summary> /// Read a string in UTF16, until '\0\0' </summary> /// <param name="addr"> address of the string </param> /// <returns> the string </returns> protected internal virtual string readStringUTF16Z(int addr) { if (addr == 0) { return(null); } IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, 2); StringBuilder s = new StringBuilder(); while (true) { int char16 = memoryReader.readNext(); if (char16 == 0) { break; } sbyte[] bytes = new sbyte[2]; bytes[0] = (sbyte)char16; bytes[1] = (sbyte)(char16 >> 8); s.Append(StringHelper.NewString(bytes, charset16)); } return(s.ToString()); }
public virtual int sceNetStrrchr(TPointer srcAddr, int c1) { if (srcAddr.Null) { return(0); } c1 = c1 & 0xFF; IMemoryReader memoryReader = MemoryReader.getMemoryReader(srcAddr.Address, 1); int lastOccurence = -1; for (int i = 0; true; i++) { int c2 = memoryReader.readNext(); if (c1 == c2) { // Character found lastOccurence = i; } else if (c2 == 0) { // End of string break; } } if (lastOccurence < 0) { return(0); } return(srcAddr.Address + lastOccurence); }
public override void paintComponent(Graphics g) { if (Memory.isAddressGood(outerInstance.startAddress)) { Insets insets = Insets; int minWidth = System.Math.Min(outerInstance.imageWidth, outerInstance.bufferWidth); g.Color = backgRoundColors[outerInstance.backgRoundColor]; g.fillRect(insets.left, insets.top, minWidth, outerInstance.imageHeight); IMemoryReader imageReader = ImageReader.getImageReader(outerInstance.startAddress, outerInstance.imageWidth, outerInstance.imageHeight, outerInstance.bufferWidth, outerInstance.pixelFormat, outerInstance.imageSwizzle, outerInstance.clutAddress, outerInstance.clutFormat, outerInstance.clutNumberBlocks, outerInstance.clutStart, outerInstance.clutShift, outerInstance.clutMask, null, null); for (int y = 0; y < outerInstance.imageHeight; y++) { for (int x = 0; x < minWidth; x++) { int colorABGR = imageReader.readNext(); int colorARGB = ImageReader.colorABGRtoARGB(colorABGR); g.Color = new Color(colorARGB, outerInstance.useAlpha); drawPixel(g, x + insets.left, y + insets.top); } } } }
//public static Logger log = Modules.getLogger("sceMpegbase"); private static void read(int addr, int Length, int[] buffer, int offset) { addr |= MemoryMap.START_RAM; if (log.TraceEnabled) { log.trace(string.Format("read addr=0x{0:X8}, Length=0x{1:X}", addr, Length)); } // Optimize the most common case if (RuntimeContext.hasMemoryInt()) { int length4 = Length >> 2; int addrOffset = addr >> 2; int[] memoryInt = RuntimeContext.MemoryInt; for (int i = 0, j = offset; i < length4; i++) { int value = memoryInt[addrOffset++]; buffer[j++] = (value) & 0xFF; buffer[j++] = (value >> 8) & 0xFF; buffer[j++] = (value >> 16) & 0xFF; buffer[j++] = (value >> 24) & 0xFF; } } else { IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, Length, 1); for (int i = 0, j = offset; i < Length; i++) { buffer[j++] = memoryReader.readNext(); } } }
public virtual bool areValuesChanged() { if (RuntimeContext.hasMemoryInt(address)) { // Optimized for the most common case (i.e. using memoryInt) int[] memoryInt = RuntimeContext.MemoryInt; int memoryIndex = address >> 2; for (int i = 0; i < values.Length; i++, memoryIndex++) { if (memoryInt[memoryIndex] != values[i]) { return(true); } } } else { IMemoryReader memoryReader = MemoryReader.getMemoryReader(rawAddress, Length, 4); for (int i = 0; i < values.Length; i++) { if (values[i] != memoryReader.readNext()) { return(true); } } } return(false); }
private void init(int address) { index = address & 0x03; if (index > 0) { readValue = memoryReader.readNext(); } }
public virtual int strtol(PspString @string, TPointer32 endString, int @base) { // base == 0 seems to be handled as base == 10. if (@base == 0) { @base = 10; } IMemoryReader memoryReader = MemoryReader.getMemoryReader(@string.Address, 1); string s = @string.String; // Skip any leading "0x" in case of base 16 if (@base == 16 && (s.StartsWith("0x", StringComparison.Ordinal) || s.StartsWith("0X", StringComparison.Ordinal))) { memoryReader.skip(2); s = s.Substring(2); } for (int i = 0; true; i++) { int c = memoryReader.readNext(); if (c == 0 || !isNumberValidCharacter(c, @base)) { endString.setValue(@string.Address + i); s = s.Substring(0, i); break; } } int result; if (s.Length == 0) { result = 0; } else { result = Integer.parseInt(s, @base); } //if (log.DebugEnabled) { if (@base == 10) { Console.WriteLine(string.Format("strtol on '{0}' returning {1:D}", s, result)); } else { Console.WriteLine(string.Format("strtol on '{0}' returning 0x{1:X}", s, result)); } } return(result); }
private static void addURLParam(StringBuilder @params, string name, int addr, int Length) { StringBuilder value = new StringBuilder(); IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, Length, 1); for (int i = 0; i < Length; i++) { int c = memoryReader.readNext(); value.Append((char)c); } addURLParam(@params, name, value.ToString()); }
private void init(int address, int Length, sbyte[] fromMacAddress, sbyte[] toMacAddress) { FromMacAddress = fromMacAddress; ToMacAddress = toMacAddress; data = new sbyte[Length]; if (Length > 0 && address != 0) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(address, Length, 1); for (int i = 0; i < Length; i++) { data[i] = (sbyte)memoryReader.readNext(); } } }
//public static Logger log = Modules.getLogger("sceParseHttp"); private string getHeaderString(IMemoryReader memoryReader) { StringBuilder line = new StringBuilder(); while (true) { int c = memoryReader.readNext(); if (c == '\n' || c == '\r') { break; } line.Append((char)c); } return(line.ToString()); }
public virtual void updateValues() { values = new int[Length >> 2]; if (RuntimeContext.hasMemoryInt(address)) { Array.Copy(RuntimeContext.MemoryInt, address >> 2, values, 0, values.Length); } else { IMemoryReader memoryReader = MemoryReader.getMemoryReader(rawAddress, Length, 4); for (int i = 0; i < values.Length; i++) { values[i] = memoryReader.readNext(); } } }
protected internal static sbyte[] getBytesUTF8(int addr) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, 1); sbyte[] bytes = new sbyte[0]; while (true) { int utf8 = memoryReader.readNext(); if (utf8 == 0) { break; } bytes = addByteToArray(bytes, (sbyte)utf8); } return(bytes); }
public virtual void setHelloOpt(int optLen, int optData) { if (optLen <= 0 || optData == 0) { this.helloOptData = null; return; } // Copy the HelloOpt into an internal buffer, the user memory can be overwritten // after this call. IMemoryReader memoryReader = MemoryReader.getMemoryReader(optData, optLen, 1); helloOptData = new sbyte[optLen]; for (int i = 0; i < optLen; i++) { helloOptData[i] = (sbyte)memoryReader.readNext(); } }
private void copyToCachedMemory(int address, int Length) { int offset = getBufferOffset(address) >> 2; int n = Length >> 2; if (RuntimeContext.hasMemoryInt()) { Array.Copy(RuntimeContext.MemoryInt, address >> 2, cachedMemory, offset, n); } else { IMemoryReader memoryReader = MemoryReader.getMemoryReader(address, Length, 4); for (int i = 0; i < n; i++) { cachedMemory[offset + i] = memoryReader.readNext(); } } }
private void setStallAddressWithCachedMemory(PspGeList list, int stallAddr) { int startAddress = list.list_addr; int Length; if (stallAddr != 0) { Length = stallAddr - startAddress; } else { // The list has no stall address, scan for the FINISH command IMemoryReader memoryReader = MemoryReader.getMemoryReader(startAddress, 4); Length = 0; while (true) { int instruction = memoryReader.readNext(); int command = VideoEngine.command(instruction); if (command == GeCommands.FINISH) { // Add 4 to include the END command that follows the FINISH command Length = memoryReader.CurrentAddress - startAddress + 4; break; } } } if (Length >= 0) { int[] baseMemoryInts = Utilities.readInt32(startAddress, Length); list.setStallAddr(stallAddr, MemoryReader.getMemoryReader(startAddress, baseMemoryInts, 0, Length), startAddress, startAddress + Length); //if (log.DebugEnabled) { Console.WriteLine(string.Format("setStallAddressWithCachedMemory [0x{0:X8}-0x{1:X8}] {2}", startAddress, startAddress + Length, list)); } } else { list.StallAddr = stallAddr; } }
public virtual int strnlen(TPointer srcAddr, int size) { if (srcAddr.Null || size == 0) { return(0); } IMemoryReader memoryReader = MemoryReader.getMemoryReader(srcAddr.Address, size, 1); for (int i = 0; i < size; i++) { int c = memoryReader.readNext(); if (c == 0) { return(i); } } return(size); }
public virtual int sceNetVsprintf(CpuState cpu, TPointer buffer, string format, TPointer32 parameters) { object[] formatParameters = new object[10]; // Assume max. 10 parameters IMemoryReader memoryReader = MemoryReader.getMemoryReader(parameters.Address, 4 * formatParameters.Length, 4); for (int i = 0; i < formatParameters.Length; i++) { formatParameters[i] = memoryReader.readNext(); } string formattedString = Modules.SysMemUserForUserModule.hleKernelSprintf(cpu, format, formatParameters); Utilities.writeStringZ(buffer.Memory, buffer.Address, formattedString); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNetVsprintf returning '{0}'", formattedString)); } return(formattedString.Length); }
public virtual int memcmp(TPointer src1Addr, TPointer src2Addr, int size) { int result = 0; if (size > 0) { IMemoryReader memoryReader1 = MemoryReader.getMemoryReader(src1Addr.Address, size, 1); IMemoryReader memoryReader2 = MemoryReader.getMemoryReader(src2Addr.Address, size, 1); for (int i = 0; i < size; i++) { int c1 = memoryReader1.readNext(); int c2 = memoryReader2.readNext(); if (c1 != c2) { result = c1 < c2 ? -1 : 1; break; } } } return(result); }
} //GEN-LAST:event_btnGoToSPActionPerformed private void btnDumpRawRamActionPerformed([email protected] evt) { //GEN-FIRST:event_btnDumpRawRamActionPerformed File f = new File("ramdump.bin"); BufferedOutputStream @out = null; try { @out = new BufferedOutputStream(new System.IO.FileStream(f, System.IO.FileMode.Create, System.IO.FileAccess.Write)); IMemoryReader memoryReader = MemoryReader.getMemoryReader(MemoryMap.START_RAM, MemoryMap.SIZE_RAM, 1); for (int i = 0; i < MemoryMap.SIZE_RAM; i++) { @out.write(memoryReader.readNext()); } } catch (IOException) { // Ignore exception } finally { Utilities.close(@out); } } //GEN-LAST:event_btnDumpRawRamActionPerformed
protected internal override void memcpy(int destination, int source, int Length, bool checkOverlap) { destination = normalizeAddress(destination); source = normalizeAddress(source); if (checkOverlap || !areOverlapping(destination, source, Length)) { // Direct copy if buffers do not overlap. // ByteBuffer operations are handling correctly overlapping buffers. ByteBuffer destinationBuffer = getByteBuffer(destination, Length); ByteBuffer sourceBuffer = getByteBuffer(source, Length); destinationBuffer.put(sourceBuffer); } else { // Buffers are overlapping and we have to copy them as they would not overlap. IMemoryReader sourceReader = MemoryReader.getMemoryReader(source, Length, 1); for (int i = 0; i < Length; i++) { write8(destination + i, (sbyte)sourceReader.readNext()); } } }
private bool cachedMemoryEquals(int address, int Length) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(address, Length, 4); int n = Length >> 2; int offset = getBufferOffset(address) >> 2; for (int i = 0; i < n; i++) { if (cachedMemory[offset + i] != memoryReader.readNext()) { if (log.TraceEnabled) { log.trace(string.Format("VertexBuffer.cachedMemoryEquals(0x{0:X8}, {1:D}): are not equal", address, Length)); } return(false); } } if (log.TraceEnabled) { log.trace(string.Format("VertexBuffer.cachedMemoryEquals(0x{0:X8}, {1:D}): are equal", address, Length)); } return(true); }
public void writeNext(int value) { memoryWriter.writeNext(value); currentValue = memoryReader.readNext(); }
public virtual int hleKernelLoadExec(ByteBuffer moduleBuffer, int argSize, int argAddr, string moduleFileName, UmdIsoReader iso) { sbyte[] arguments = null; if (argSize > 0) { // Save the memory content for the arguments because // the memory would be overwritten by the loading of the new module. arguments = new sbyte[argSize]; IMemoryReader memoryReader = MemoryReader.getMemoryReader(argAddr, argSize, 1); for (int i = 0; i < argSize; i++) { arguments[i] = (sbyte)memoryReader.readNext(); } } // Flush system memory to mimic a real PSP reset. Modules.SysMemUserForUserModule.reset(); try { if (moduleBuffer != null) { SceModule module = Emulator.Instance.load(moduleFileName, moduleBuffer, true); Emulator.Clock.resume(); // After a sceKernelLoadExec, host0: is relative to the directory where // the loaded file (prx) was located. // E.g.: // after // sceKernelLoadExec("disc0:/PSP_GAME/USRDIR/A.PRX") // the following file access // sceIoOpen("host0:B") // is actually referencing the file // disc0:/PSP_GAME/USRDIR/B if (!string.ReferenceEquals(moduleFileName, null)) { int pathIndex = moduleFileName.LastIndexOf("/", StringComparison.Ordinal); if (pathIndex >= 0) { Modules.IoFileMgrForUserModule.Host0Path = moduleFileName.Substring(0, pathIndex + 1); } } if ((module.fileFormat & Loader.FORMAT_ELF) != Loader.FORMAT_ELF) { Console.WriteLine("sceKernelLoadExec - failed, target is not an ELF"); throw new SceKernelErrorException(ERROR_KERNEL_ILLEGAL_LOADEXEC_FILENAME); } // Set the given arguments to the root thread. // Do not pass the file name as first parameter (tested on PSP). SceKernelThreadInfo rootThread = Modules.ThreadManForUserModule.getRootThread(module); Modules.ThreadManForUserModule.hleKernelSetThreadArguments(rootThread, arguments, argSize); // The memory model (32MB / 64MB) could have been changed, update the RuntimeContext RuntimeContext.updateMemory(); if (iso != null) { Modules.IoFileMgrForUserModule.IsoReader = iso; Modules.sceUmdUserModule.IsoReader = iso; } } } catch (GeneralJpcspException e) { Console.WriteLine("General Error", e); Emulator.PauseEmu(); } catch (IOException e) { Console.WriteLine(string.Format("sceKernelLoadExec - Error while loading module '{0}'", moduleFileName), e); return(ERROR_KERNEL_PROHIBIT_LOADEXEC_DEVICE); } return(0); }
protected internal override void memcpy(int destination, int source, int Length, bool checkOverlap) { if (Length <= 0) { return; } destination = normalizeAddress(destination); source = normalizeAddress(source); Modules.sceDisplayModule.write(destination); if (isIntAligned(source) && isIntAligned(destination) && isIntAligned(Length)) { // Source, destination and Length are "int"-aligned memcpyAligned4(destination, source, Length, checkOverlap); } else if ((source & 0x03) == (destination & 0x03) && (!checkOverlap || !areOverlapping(destination, source, Length))) { // Source and destination have the same alignment and are not overlapping while (!isIntAligned(source) && Length > 0) { write8(destination, (sbyte)read8(source)); source++; destination++; Length--; } int length4 = Length & ~0x03; if (length4 > 0) { memcpyAligned4(destination, source, length4, checkOverlap); source += length4; destination += length4; Length -= length4; } while (Length > 0) { write8(destination, (sbyte)read8(source)); destination++; source++; Length--; } } else { // // Buffers are not "int"-aligned, copy in 1 byte steps. // Overlapping address ranges must be correctly handled: // If source >= destination: // [---source---] // [---destination---] // => Copy from the head // If source < destination: // [---source---] // [---destination---] // => Copy from the tail // if (!checkOverlap || source >= destination || !areOverlapping(destination, source, Length)) { if (areOverlapping(destination, source, 4)) { // Cannot use MemoryReader if source and destination are overlapping in less than 4 bytes for (int i = 0; i < Length; i++) { write8(destination + i, (sbyte)read8(source + i)); } } else { IMemoryReader sourceReader = MemoryReader.getMemoryReader(source, Length, 1); IMemoryWriter destinationWriter = MemoryWriter.getMemoryWriter(destination, Length, 1); for (int i = 0; i < Length; i++) { destinationWriter.writeNext(sourceReader.readNext()); } destinationWriter.flush(); } } else { for (int i = Length - 1; i >= 0; i--) { write8(destination + i, (sbyte)read8(source + i)); } } } }
private bool unpackNextVAGBlock() { if (currentVAGBlock >= numberVGABlocks) { if (log.TraceEnabled) { log.trace(string.Format("VAG reached end of blocks currentVAGBlock={0:D}, numberVAGBlocks={1:D}", currentVAGBlock, numberVGABlocks)); } return(false); } sampleIndex = 0; int n = memoryReader.readNext(); int predict_nr = n >> 4; if (predict_nr >= VAG_f.Length) { predict_nr = 0; } int shift_factor = n & 0x0F; int flag = memoryReader.readNext(); if (flag == 0x03) { // If loop mode is enabled, this flag indicates // the sealed override block of the loop. // Do not loop if the voice has been keyed Off. if (loopMode && voice.On) { if (log.TraceEnabled) { log.trace(string.Format("SampleSourceVAG loop at next VAG Block[{0:D}], voice=0x{1:X}", currentVAGBlock, voice.Index)); } loopAtNextVAGBlock = true; } } else if (flag == 0x06) { // If loop mode is enabled, this flag indicates // the first block of the loop. // TODO: Implement loop processing by decoding // the same samples within the loop flags // when loop mode is on. if (log.TraceEnabled) { log.trace(string.Format("SampleSourceVAG loop start VAG Block[{0:D}], voice=0x{1:X}", currentVAGBlock, voice.Index)); } loopStartVAGBlock = currentVAGBlock; } else if (flag == 0x07) { numberVGABlocks = currentVAGBlock; numberSamples = numberVGABlocks * 28; sampleIndex = samples.Length; return(false); // End of stream flag. } for (int j = 0; j < 28; j += 2) { int d = memoryReader.readNext(); int s = (short)((d & 0x0F) << 12); unpackedSamples[j] = s >> shift_factor; s = (short)((d & 0xF0) << 8); unpackedSamples[j + 1] = s >> shift_factor; } for (int j = 0; j < 28; j++) { int sample = (int)(unpackedSamples[j] + hist1 * VAG_f[predict_nr][0] + hist2 * VAG_f[predict_nr][1]); hist2 = hist1; hist1 = sample; if (sample < -32768) { samples[j] = -32768; } else if (sample > 0x7FFF) { samples[j] = 0x7FFF; } else { samples[j] = (short)sample; } } currentVAGBlock++; return(true); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void write() throws java.io.IOException public virtual void write() { if (bufferStorage >= TPSM_PIXEL_STORAGE_MODE_4BIT_INDEXED && bufferStorage <= TPSM_PIXEL_STORAGE_MODE_32BIT_INDEXED && bufferStorage != depthBufferPixelFormat) { // Writing of indexed images not supported return; } if (compressedImage) { decompressImage(); } bool imageInvert = invert; int readWidth = System.Math.Min(width, bufferWidth); sbyte[] pixelBytes = new sbyte[4]; sbyte[] blackPixelBytes = new sbyte[pixelBytes.Length]; // ImageIO doesn't support the bmp file format and // doesn't properly write PNG files with pixel alpha values AbstractCaptureImage captureImage; if (bmpFileFormat.Equals(fileFormat)) { captureImage = new CaptureImageBMP(); } else if (pngFileFormat.Equals(fileFormat)) { captureImage = new CaptureImagePNG(); } else { captureImage = new CaptureImageImageIO(); } captureImage.writeHeader(FileName, fileFormat, width, height, readWidth); if (captureImage.Inverted) { imageInvert = !imageInvert; } bool imageType32Bit = bufferStorage == TPSM_PIXEL_STORAGE_MODE_32BIT_ABGR8888 || bufferStorage == RE_DEPTH_STENCIL; if (imageReader != null) { for (int y = 0; y < height; y++) { captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { int pixel = imageReader.readNext(); captureImage.writePixel(pixel); } captureImage.endLine(); } captureImage.writeEnd(); } else if (buffer is IntBuffer && imageType32Bit) { IntBuffer intBuffer = (IntBuffer)buffer; for (int y = 0; y < height; y++) { intBuffer.position((imageInvert ? (height - y - 1) : y) * bufferWidth); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { try { int pixel = intBuffer.get(); captureImage.writePixel(pixel); } catch (BufferUnderflowException) { captureImage.writePixel(blackPixelBytes); } } captureImage.endLine(); } } else if (buffer is IntBuffer && !imageType32Bit) { IntBuffer intBuffer = (IntBuffer)buffer; for (int y = 0; y < height; y++) { intBuffer.position((imageInvert ? (height - y - 1) : y) * bufferWidth / 2); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x += 2) { try { int twoPixels = intBuffer.get(); getPixelBytes((short)twoPixels, bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); if (x + 1 < readWidth) { getPixelBytes((short)((int)((uint)twoPixels >> 16)), bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); } } catch (BufferUnderflowException) { captureImage.writePixel(blackPixelBytes); captureImage.writePixel(blackPixelBytes); } } captureImage.endLine(); } } else if (buffer is ShortBuffer && !imageType32Bit) { ShortBuffer shortBuffer = (ShortBuffer)buffer; for (int y = 0; y < height; y++) { shortBuffer.position((imageInvert ? (height - y - 1) : y) * bufferWidth); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { short pixel = shortBuffer.get(); getPixelBytes(pixel, bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); } captureImage.endLine(); } } else if (imageType32Bit) { for (int y = 0; y < height; y++) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(imageaddr + (imageInvert ? (height - y - 1) : y) * bufferWidth * 4, bufferWidth * 4, 4); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { int pixel = memoryReader.readNext(); captureImage.writePixel(pixel); } captureImage.endLine(); } } else { for (int y = 0; y < height; y++) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(imageaddr + (imageInvert ? (height - y - 1) : y) * bufferWidth * 2, bufferWidth * 2, 2); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { short pixel = (short)memoryReader.readNext(); getPixelBytes(pixel, bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); } captureImage.endLine(); } } if (buffer != null) { buffer.rewind(); } captureImage.writeEnd(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("Saved image to {0}", FileName)); } }
public MemoryReaderWriterGeneric(int address, int step) { memoryReader = MemoryReader.getMemoryReader(address, step); memoryWriter = MemoryWriter.getMemoryWriter(address, step); currentValue = memoryReader.readNext(); }