Manic EMU is an all-in-one retro game emulator for iOS. It packs powerful features while keeping a clean, sleek UI and delivering buttery-smooth gameplay.
Swift
const APS_N64_MAGIC="APS10",APS_RECORD_RLE=0,APS_RECORD_SIMPLE=1,APS_N64_MODE=1;function APS(){this.records=[],this.headerType=0,this.encodingMethod=0,this.description="no description",this.header={}}"undefined"!=typeof module&&module.exports&&(module.exports=APS),APS.prototype.addRecord=function(e,t){this.records.push({offset:e,type:1,data:t})},APS.prototype.addRLERecord=function(e,t,r){this.records.push({offset:e,type:0,length:r,byte:t})},APS.prototype.toString=function(){var e="Total records: "+this.records.length;return e+="\nHeader type: "+this.headerType,1===this.headerType&&(e+=" (N64)"),e+="\nEncoding method: "+this.encodingMethod,e+="\nDescription: "+this.description,e+="\nHeader: "+JSON.stringify(this.header)},APS.prototype.validateSource=function(e){if(1===this.headerType){if(e.seek(60),e.readString(3)!==this.header.cartId)return!1;e.seek(16);for(var t=e.readBytes(8),r=0;r<8;r++)if(t[r]!==this.header.crc[r])return!1}return!0},APS.prototype.getValidationInfo=function(){return 1===this.headerType?this.header.cartId+" ("+this.header.crc.reduce(function(e,t){return t<16?e+"0"+t.toString(16):e+t.toString(16)},"")+")":null},APS.prototype.export=function(e){var t=61;1===this.headerType&&(t+=17);for(var r=0;r<this.records.length;r++)0===this.records[r].type?t+=7:t+=5+this.records[r].data.length;tempFile=new BinFile(t),tempFile.littleEndian=!0,tempFile.fileName=e+".aps",tempFile.writeString("APS10",5),tempFile.writeU8(this.headerType),tempFile.writeU8(this.encodingMethod),tempFile.writeString(this.description,50),1===this.headerType&&(tempFile.writeU8(this.header.originalN64Format),tempFile.writeString(this.header.cartId,3),tempFile.writeBytes(this.header.crc),tempFile.writeBytes(this.header.pad)),tempFile.writeU32(this.header.sizeOutput);for(r=0;r<this.records.length;r++){var i=this.records[r];tempFile.writeU32(i.offset),0===i.type?(tempFile.writeU8(0),tempFile.writeU8(i.byte),tempFile.writeU8(i.length)):(tempFile.writeU8(i.data.length),tempFile.writeBytes(i.data))}return tempFile},APS.prototype.apply=function(e,t){if(t&&!this.validateSource(e))throw new Error("Source ROM checksum mismatch");tempFile=new BinFile(this.header.sizeOutput),e.copyTo(tempFile,0,tempFile.fileSize);for(var r=0;r<this.records.length;r++)if(tempFile.seek(this.records[r].offset),0===this.records[r].type)for(var i=0;i<this.records[r].length;i++)tempFile.writeU8(this.records[r].byte);else tempFile.writeBytes(this.records[r].data);return tempFile},APS.MAGIC="APS10",APS.fromFile=function(e){var t,r=new APS;for(e.littleEndian=!0,e.seek(5),r.headerType=e.readU8(),r.encodingMethod=e.readU8(),r.description=e.readString(50),1===r.headerType&&(r.header.originalN64Format=e.readU8(),r.header.cartId=e.readString(3),r.header.crc=e.readBytes(8),r.header.pad=e.readBytes(5)),r.header.sizeOutput=e.readU32();!e.isEOF();){var i=e.readU32(),d=e.readU8();0===d?r.addRLERecord(i,e.readU8(t),e.readU8(NaN)):r.addRecord(i,e.readBytes(d))}return r},APS.buildFromRoms=function(e,t){var r=new APS;for(2151092800===e.readU32()&&(r.headerType=1,r.header.originalN64Format=/\.v64$/i.test(e.fileName)?0:1,e.seek(60),r.header.cartId=e.readString(3),e.seek(16),r.header.crc=e.readBytes(8),r.header.pad=[0,0,0,0,0]),r.header.sizeOutput=t.fileSize,e.seek(0),t.seek(0);!t.isEOF();){var i=e.isEOF()?0:e.readU8(),d=t.readU8();if(i!==d){for(var a=!0,s=[],o=t.offset-1;i!==d&&s.length<255&&(s.push(d),d!==s[0]&&(a=!1),!t.isEOF()&&255!==s.length);)i=e.isEOF()?0:e.readU8(),d=t.readU8();a&&s.length>2?r.addRLERecord(o,s[0],s.length):r.addRecord(o,s)}}return r};