Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ByteArray {
- public var pointer:platform.FlashPlatform.FlashMemoryPointer;
- public function new(_length:Int) {
- pointer = platform.FlashPlatform.FlashMemoryManager.alloc(_length,true);
- }
- public inline function writeBytes(_bytearray:ByteArray,_offset1:Int,_offset2:Int,_length:Int):Void {
- if(_length<300) {
- var i = 0;
- while(i<_length-4) {write64(_bytearray.read64(_offset1+i),_offset2+i);i+=8;}
- if(i<_length) {write32(_bytearray.read32(_offset1+i),_offset2+i);}
- } else {
- platform.FlashPlatform.FlashMemoryManager.bytearray.position = pointer.address+_offset2;
- platform.FlashPlatform.FlashMemoryManager.bytearray.writeBytes(platform.FlashPlatform.FlashMemoryManager.bytearray,_bytearray.pointer.address+_offset1,_length);
- }
- }
- public inline function read64(_address:Int):Float {
- return flash.Memory.getDouble(pointer.address+_address);
- }
- public inline function read32(_address:Int):Int {
- return flash.Memory.getI32(pointer.address+_address);
- }
- public inline function read31(_address:Int):Int {
- return flash.Memory.getI32(pointer.address+_address)&0x7FFFFFFF;
- }
- public inline function read24(_address:Int):Int {
- return flash.Memory.getI32(pointer.address+_address)&0x00FFFFFF;
- }
- public inline function read16(_address:Int):Int {
- return flash.Memory.getUI16(pointer.address+_address);
- }
- public inline function read8(_address:Int):Int {
- return flash.Memory.getByte(pointer.address+_address);
- }
- public inline function write64(_v:Float,_address:Int):Void {
- flash.Memory.setDouble(pointer.address+_address,_v);
- }
- public inline function write32(_v:Int,_address:Int):Void {
- flash.Memory.setI32(pointer.address+_address,_v);
- }
- public inline function write31(_v:Int,_address:Int):Void {
- flash.Memory.setI32(pointer.address+_address,(flash.Memory.getI32(pointer.address+_address)&0x80000000)|(_v&0x7FFFFFFF));
- }
- public inline function write24(_v:Int,_address:Int):Void {
- flash.Memory.setI32(pointer.address+_address,(flash.Memory.getI32(pointer.address+_address)&0xFF000000)|(_v&0x00FFFFFF));
- }
- public inline function write16(_v:Int,_address:Int):Void {
- flash.Memory.setI16(pointer.address+_address,_v);
- }
- public inline function write8(_v:Int,_address:Int):Void {
- flash.Memory.setByte(pointer.address+_address,_v);
- }
- public inline function readSigned32(_address:Int):Int {
- return read32(_address);
- }
- public inline function readSigned31(_address:Int):Int {
- var v:Int = flash.Memory.getI32(pointer.address+_address)&0x7FFFFFFF;
- return v - (0x7FFFFFFF+1)*(v>>30);
- }
- public inline function readSigned24(_address:Int):Int {
- var v:Int = flash.Memory.getI32(pointer.address+_address)&0x00FFFFFF;
- return v - (0xFFFFFF+1)*(v>>23);
- }
- public inline function readSigned16(_address:Int):Int {
- var v:Int = flash.Memory.getUI16(pointer.address+_address);
- return v - (0xFFFF+1)*(v>>15);
- }
- public inline function readSigned8(_address:Int):Int {
- var v:Int = flash.Memory.getByte(pointer.address+_address);
- return v - (0xFF+1)*(v>>7);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement