/* ZVM v https://github.com/curiousdannii/ifvms.js */ (function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,t.ZVM=e()}})(function(){var e=Math.min,t=String.fromCharCode;return function(){function s(l,e,r){function t(o,i){if(!e[o]){if(!l[o]){var _="function"==typeof require&&require;if(!i&&_)return _(o,!0);if(n)return n(o,!0);var g=new Error("Cannot find module '"+o+"'");throw g.code="MODULE_NOT_FOUND",g}var a=e[o]={exports:{}};l[o][0].call(a.exports,function(e){var s=l[o][1][e];return t(s||e)},a,a.exports,s,l,e,r)}return e[o].exports}for(var n="function"==typeof require&&require,a=0;a--e?"l["+e+"]":"e.m.getUint16("+(this.e.globals+2*(e-15))+")"},store:function(e){var t=this.v;return this.indirect?"e.indirect("+t+","+e+")":this.returnval?"e.variable("+t+","+e+")":0===t?"t="+e+";s[e.sp++]=t":15>--t?"l["+t+"]="+e:"e.ram.setUint16("+(this.e.globals+2*(t-15))+","+e+")"},U2S:function(){return"e.U2S("+this+")"}}),o=r.subClass({init:function(e,t,s,r,i,n){this.e=e,this.context=t,this.code=s,this.pc=r,this.labels=[this.pc+"/"+this.code],this.next=i,this.operands=n,this.post&&this.post()},toString:function(){return this.label()+(this.func?this.func.apply(this,this.operands):"")},args:function(e){return this.operands.join(e)},label:function(){return"/* "+this.labels.join()+" */ "}}),l=o.subClass({stopper:1}),p=l.subClass({post:function(){this.origfunc=this.func,this.func=this.newfunc},newfunc:function(){return"e.stop=1;e.pc="+this.next+";"+this.origfunc.apply(this,arguments)}}),_=p.subClass({storer:1,post:function(){this.storer=this.operands.pop(),this.origfunc=this.func,this.func=this.newfunc}}),g=r.subClass({init:function(e,t){this.ops=e||[],this.code=t||"||"},toString:function(){for(var e,t=0,s=[];ts||s+a>t)throw new Error("IFF chunk out of range");this.chunks.push({type:n.getFourCC(a),offset:a,data:n.getUint8Array(a+8,s)}),a+=8+s,s%2&&a++}}},write:function(){for(var e,t,s=12,n=0,i=12;ni&&(s="ZCOD")),s&&i)return{format:s,version:i,data:e}}}},{"./utils.js":3}],3:[function(e,s){"use strict";function r(){for(var e,t,s=arguments[0],r=1;r>16},S2U16:function(e){return 65535&e},Uint8toUint16Array:n}},{}],4:[function(e,t){"use strict";var s=e("./common/utils.js"),r=e("./common/file.js"),i={stack_len:100000,undo_len:1000000},n=s.Class.subClass(s.extend({init:function(){this.jit={},this.init=this.start},prepare:function(e,t){if(!t.Glk)throw new Error("A reference to Glk is required");this.Glk=t.Glk,this.data=e,this.options=s.extend({},i,t)},start:function(){var e,t=this.Glk;try{if(e=r.identify(this.data),delete this.data,!e||"ZCOD"!==e.format)throw new Error("This is not a Z-Code file");if(0>[3,4,5,8].indexOf(e.version))throw new Error("Unsupported Z-Machine version: "+e.version);this.m=s.MemoryView(e.data),this.staticmem=this.m.getUint16(14),this.ram=s.MemoryView(this.m,0,this.staticmem),this.origram=this.m.getUint8Array(0,this.staticmem);let n="",a=0;for(;30>a;)n+=(16>this.origram[a]?"0":"")+this.origram[a++].toString(16);this.signature=n;let i;const o=this.options.Dialog;if(o)if(this.options.clear_vm_autosave)o.autosave_write(n,null);else if(this.options.do_vm_autosave)try{const e=o.autosave_read(n);e&&(this.do_autorestore(e),i=1)}catch(e){this.log("Autorestore failed, deleting it"),o.autosave_write(n,null)}i||(this.restart(),this.run()),this.quit||(this.glk_event=new t.RefStruct,this.glk_blocking_call?this.glk_event.push_field(this.glk_blocking_call):t.glk_select(this.glk_event)),t.update()}catch(s){t.fatal_error(s),console.log(s)}},resume:function(e){var t,s,r=this.Glk,i=this.glk_event;try{t=i.get_field(0),2===t&&(this.handle_char_input(i.get_field(2)),s=1),3===t&&(this.handle_line_input(i.get_field(2),i.get_field(3)),s=1),5===t&&this.update_screen_size(),"fileref_create_by_prompt"===t&&(s=this.handle_create_fileref(e)),this.glk_blocking_call=null,s&&this.run(),this.quit||(this.glk_event=new r.RefStruct,this.glk_blocking_call?this.glk_event.push_field(this.glk_blocking_call):r.glk_select(this.glk_event)),r.update()}catch(t){r.fatal_error(t),console.log(t)}},get_signature:function(){return this.signature},run:function(){var e,t;for(this.stop=0;!this.stop;)e=this.pc,this.jit[e]||this.compile(),t=this.jit[e](this),isNaN(t)||this.ret(t)},compile:function(){var e=this.disassemble();this.jit[e.pc]=new Function("e",""+e),e.pcs;s++)t.push((192&e)>>6),e<<=2}for(var t,r,i,n,a,o,l,p=this.m,_=this.opcodes,g=new s.RoutineContext(this,this.pc);;){if(r=t=this.pc,n=p.getUint8(t++),190===n?(o=-1,n=p.getUint8(t++)+1e3):128&n?64&n?(o=-1,!(32&n)&&(n&=31)):(o=[(48&n)>>4],3>o[0]&&(n&=207)):(o=[64&n?2:1,32&n?2:1],n&=31),!_[n])throw this.log(""+g),this.stop=1,new Error("Unknown opcode #"+n+" at pc="+r);for(a=_[n].prototype,-1===o&&(o=[],e(p.getUint8(t++),o),(236===n||250===n)&&e(p.getUint8(t++),o)),l=[],i=0;i>18])),a.printer)for(l.push(t);t>5]<<8|t[(31744&e)>>10]}const n=s("../common/utils.js"),a=n.U2S16,o=function(){for(var e={4294967283:146,4294967284:152,4294967285:148,4294967286:154,4294967288:27,4294967289:8,4294967290:13,4294967291:130,4294967292:129,4294967293:132,4294967294:131},t=0;12>t;)e[4294967279-t]=133+t++;return e}(),l=[0,2,1,10,4,9,5,6],p=[65534,65535,0,29,832,957,22944,31775,30624,32767,23254,17969,11627];r.exports={init_io:function(){this.io=this.io||{reverse:0,bold:0,italic:0,mono:2&this.m.getUint8(17),transcript:1&this.m.getUint8(17),streams:[0,1,{},[],{}],currentwin:0,height:0,maxheight:0,seenheight:0,width:0,row:0,col:0},this.open_windows()},erase_line:function(e){if(1===e){var t=this.io,s=t.row,r=t.col;this._print(Array(t.width-t.col+1).join(" ")),this.set_cursor(s,r)}},erase_window:function(e){1>e&&this.Glk.glk_window_clear(this.mainwin),(1===e||-2===e)&&this.upperwin&&(this.Glk.glk_window_clear(this.upperwin),this.set_cursor(0,0)),-1===e&&this.split_window(0)},fileref_create_by_prompt:function(e){"undefined"==typeof e.run&&(e.run=1),this.fileref_data=e,this.glk_blocking_call="fileref_create_by_prompt",this.Glk.glk_fileref_create_by_prompt(e.usage,e.mode,e.rock||0)},fix_upper_window:function(){var e=this.Glk,t=this.io;t.seenheight>=t.maxheight&&(t.maxheight=t.height),this.upperwin&&(0===t.maxheight?(e.glk_window_close(this.upperwin),this.upperwin=null):e.glk_window_set_arrangement(e.glk_window_get_parent(this.upperwin),18,t.maxheight,null)),t.seenheight=t.maxheight,t.maxheight=t.height},format:function(){this.Glk.glk_set_style(l[!!this.io.mono|this.io.italic|this.io.bold]),this.Glk.glk_gestalt(4352,0)&&this.Glk.garglk_set_reversevideo(this.io.reverse)},get_cursor:function(e){this.ram.setUint16(e,this.io.row+1),this.ram.setUint16(e+2,this.io.col+1)},handle_char_input:function(e){var t=this.io.streams[4],s=o[e]||this.reverse_unicode_table[e]||63;this.variable(this.read_data.storer,s),1===t.mode&&(t.cache+=s),2===t.mode&&this.Glk.glk_put_char_stream_uni(t.str,s)},handle_create_fileref:function(e){var t,s=this.Glk,r=this.fileref_data;return e&&(t=r.unicode?s.glk_stream_open_file_uni(e,r.mode,r.rock||0):s.glk_stream_open_file(e,r.mode,r.rock||0),s.glk_fileref_destroy(e)),("restore"===r.func||"save"===r.func)&&this.save_restore_handler(t),"input_stream"===r.func&&(this.io.streams[0]=t),"output_stream"===r.func&&this.output_stream_handler(t),r.run},handle_line_input:function(e,s){var r=this.ram,i=this.read_data,n=this.io.streams,a=t.apply(null,i.buffer.slice(0,e))+"\n",o=this.text_to_zscii(a.slice(0,-1).toLowerCase());1===n[2].mode&&(n[2].cache+=a),2===n[2].mode&&this.Glk.glk_put_jstring_stream(n[2].str,a),1===n[4].mode&&(n[4].cache+=a),2===n[4].mode&&this.Glk.glk_put_jstring_stream(n[4].str,a),5>this.version?(o.push(0),r.setUint8Array(i.bufaddr+1,o)):(r.setUint8(i.bufaddr+1,e),r.setUint8Array(i.bufaddr+2,o),this.variable(i.storer,isNaN(s)?13:s)),i.parseaddr&&this.tokenise(i.bufaddr,i.parseaddr)},input_stream:function(e){var t=this.io;e&&!t.streams[0]&&this.fileref_create_by_prompt({func:"input_stream",mode:2,rock:212,unicode:1,usage:259}),!e&&t.streams[0]&&(this.Glk.glk_stream_close(t.streams[0]),t.streams[0]=0)},open_windows:function(){if(!this.mainwin){const e=this.Glk,t=[1,2,4,5,6,9,10];for(let s=0;7>s;s++)e.glk_stylehint_set(0,t[s],3,0),e.glk_stylehint_set(0,t[s],4,0),e.glk_stylehint_set(0,t[s],5,0),e.glk_stylehint_set(0,t[s],6,1);e.glk_stylehint_set(0,4,4,1),e.glk_stylehint_set(0,1,5,1),e.glk_stylehint_set(0,5,4,1),e.glk_stylehint_set(0,5,5,1),e.glk_stylehint_set(0,2,6,0),e.glk_stylehint_set(0,9,4,1),e.glk_stylehint_set(0,9,6,0),e.glk_stylehint_set(0,10,5,1),e.glk_stylehint_set(0,10,6,0),e.glk_stylehint_set(0,6,4,1),e.glk_stylehint_set(0,6,5,1),e.glk_stylehint_set(0,6,6,0),this.mainwin=e.glk_window_open(0,0,0,3,201),e.glk_set_window(this.mainwin),this.version3&&(this.statuswin=e.glk_window_open(this.mainwin,18,1,4,202),this.statuswin&&e.garglk_set_reversevideo_stream(e.glk_window_get_stream(this.statuswin),1))}},output_stream:function(e,t,s){var r,i,n=this.ram,o=this.io.streams;e=a(e),1===e&&(o[1]=1),-1===e&&(o[1]=0),2!==e||o[2].mode||(this.fileref_create_by_prompt({func:"output_stream",mode:5,rock:210,run:!s,str:2,unicode:1,usage:258}),o[2].cache="",o[2].mode=1,!s&&(this.stop=1)),-2===e&&(n.setUint8(17,254&n.getUint8(17)),2===o[2].mode&&this.Glk.glk_stream_close(o[2].str),o[2].mode=this.io.transcript=0),3===e&&o[3].unshift([t,""]),-3===e&&(r=o[3].shift(),i=this.text_to_zscii(r[1]),n.setUint16(r[0],i.length),n.setUint8Array(r[0]+2,i)),4!==e||o[4].mode||(this.fileref_create_by_prompt({func:"output_stream",mode:5,rock:211,str:4,unicode:1,usage:259}),o[4].cache="",o[4].mode=1,this.stop=1),-4===e&&(2===o[4].mode&&this.Glk.glk_stream_close(o[4].str),o[4].mode=0)},output_stream_handler:function(e){var t=this.ram,s=this.io.streams,r=this.fileref_data;2===r.str&&(t.setUint8(17,254&t.getUint8(17)|(e?1:0)),e?(s[2].mode=2,s[2].str=e,this.io.transcript=1,s[2].cache&&this.Glk.glk_put_jstring_stream(s[2].str,s[2].cache)):s[2].mode=this.io.transcript=0),4===r.str&&(e?(s[4].mode=2,s[4].str=e,s[4].cache&&this.Glk.glk_put_jstring_stream(s[4].str,s[4].cache)):s[4].mode=0)},_print:function(e){var t=this.Glk,s=this.io,r=0;if(s.streams[3].length)s.streams[3][0][1]+=e;else if(e=e.replace(/\r/g,"\n"),(1&this.m.getUint8(17))!==s.transcript&&this.output_stream(s.transcript?-2:2,0,1),(2&this.m.getUint8(17))!=(2&s.mono)&&(s.mono^=2,this.format()),s.currentwin&&this.upperwin)for(;r=s.height&&this.split_window(e+1),this.upperwin&&0<=e&&0<=t&&ta){for(t=s.glk_window_get_stream(this.upperwin);ar.maxheight&&(r.maxheight=e,this.upperwin?s.glk_window_set_arrangement(s.glk_window_get_parent(this.upperwin),18,r.maxheight,null):this.upperwin=s.glk_window_open(this.mainwin,18,r.maxheight,4,203)),e&&(r.row>=e&&this.set_cursor(0,0),this.version3&&s.glk_window_clear(this.upperwin))},update_header:function(){var e=this.ram;return this.xorshift_seed=0,this.update_screen_size(),this.version3?e.setUint8(1,64|(143&e.getUint8(1)|(this.statuswin?32:16))):void(e.setUint8(1,0|(28|(this.Glk.glk_gestalt(4352,0)?1:0))),e.setUint8(17,87&e.getUint8(17)),4=a&&(this.io.col=a-1)},v3_status:function(){if(this.statuswin){var e,t=this.Glk,s=t.glk_window_get_stream(this.statuswin),r=this.m,i=this.io.width,n=r.getUint16(this.globals+2),a=r.getUint16(this.globals+4),o=r.getUint16(this.objects+9*r.getUint16(this.globals)+7),l=""+this.decode(o+1,2*r.getUint8(o));e=2&r.getUint8(1)?"Time: "+(0==n%12?12:n%12)+":"+(10>a?"0":"")+a+" "+(11t?"e.s[e.sp-1]":"e.l["+t+"]")+(1==s?"++":"--")}}),b=n.subClass({brancher:1,toString:function(){return"e.stop=1;e."+(181===this.code?"save":"restore")+"("+(this.pc+1)+")"}}),w=c(o,function(){return"e.restore("+(this.next-1)+")"}),v=c(o,function(){return"e.save("+(this.next-1)+")"});t.exports=function(e){return{1:c(l,function(){return 2===arguments.length?this.args("==="):"e.jeq("+this.args()+")"}),2:c(l,function(e,t){return e.U2S()+"<"+t.U2S()}),3:c(l,function(e,t){return e.U2S()+">"+t.U2S()}),4:c(l,function(e,t){return"e.U2S(e.incdec("+e+",-1))<"+t.U2S()}),5:c(l,function(e,t){return"e.U2S(e.incdec("+e+",1))>"+t.U2S()}),6:c(l,function(){return"e.jin("+this.args()+")"}),7:c(l,function(){return"e.test("+this.args()+")"}),8:c(_,function(){return this.args("|")}),9:c(_,function(){return this.args("&")}),10:c(l,function(){return"e.test_attr("+this.args()+")"}),11:c(i,function(){return"e.set_attr("+this.args()+")"}),12:c(i,function(){return"e.clear_attr("+this.args()+")"}),13:U,14:c(i,function(){return"e.insert_obj("+this.args()+")"}),15:c(_,function(e,t){return"e.m.getUint16(e.S2U("+e+"+2*"+t.U2S()+"))"}),16:c(_,function(e,t){return"e.m.getUint8(e.S2U("+e+"+"+t.U2S()+"))"}),17:c(_,function(){return"e.get_prop("+this.args()+")"}),18:c(_,function(){return"e.find_prop("+this.args()+")"}),19:c(_,function(){return"e.find_prop("+this.args(",0,")+")"}),20:c(_,function(){return"e.S2U("+this.args("+")+")"}),21:c(_,function(){return"e.S2U("+this.args("-")+")"}),22:c(_,function(){return"e.S2U("+this.args("*")+")"}),23:c(_,function(e,t){return"e.S2U(parseInt("+e.U2S()+"/"+t.U2S()+"))"}),24:c(_,function(e,t){return"e.S2U("+e.U2S()+"%"+t.U2S()+")"}),25:u,26:g,27:c(i,function(){return"e.set_colour("+this.args()+")"}),28:c(n,function(e,t){return"while(e.frames.length+1>"+t+"){e.frameptr=e.frames.pop()}return "+e}),128:c(l,function(e){return e+"===0"}),129:c(p,function(e){return"e.get_sibling("+e+")"}),130:c(p,function(e){return"e.get_child("+e+")"}),131:c(_,function(e){return"e.get_parent("+e+")"}),132:c(_,function(e){return"e.get_prop_len("+e+")"}),133:k,134:k,135:c(i,function(e){return"e.print(2,"+e+")"}),136:u,137:c(i,function(e){return"e.remove_obj("+e+")"}),138:c(i,function(e){return"e.print(3,"+e+")"}),139:c(n,function(e){return"return "+e}),140:c(n,function(e){return"e.pc="+e.U2S()+"+"+(this.next-2)}),141:c(i,function(e){return"e.print(2,"+e+"*"+this.e.addr_multipler+")"}),142:U.subClass({storer:1}),143:5>e?h:g,176:c(n,function(){return"return 1"}),177:c(n,function(){return"return 0"}),178:c(i,function(e){return"e.print(2,"+e+")"},{printer:1}),179:c(n,function(e){return"e.print(2,"+e+");e.print(1,13);return 1"},{printer:1}),180:i,181:4>e?b:v,182:4>e?b:w,183:c(n,function(){return"e.erase_window(-1);e.restart()"}),184:c(n,function(e){return"return "+e},{post:function(){this.operands.push(m)}}),185:5>e?c(i,function(){return"s[--e.sp]"}):c(_,function(){return"e.frames.length+1"}),186:c(a,function(){return"e.quit=1;e.Glk.glk_exit()"}),187:c(i,function(){return"e.print(1,13)"}),188:4>e?c(n,function(){return"e.pc="+this.next+";e.v3_status()"}):i,189:f,191:f,224:u,225:c(i,function(e,t,s){return"e.ram.setUint16(e.S2U("+e+"+2*"+t.U2S()+"),"+s+")"}),226:c(i,function(e,t,s){return"e.ram.setUint8(e.S2U("+e+"+"+t.U2S()+"),"+s+")"}),227:c(i,function(){return"e.put_prop("+this.args()+")"}),228:5>e?c(a,function(){return"e.read(0,"+this.args()+")"}):c(o,function(){return"e.read("+this.storer.v+","+this.args()+")"}),229:c(i,function(e){return"e.print(4,"+e+")"}),230:c(i,function(e){return"e.print(0,"+e.U2S()+")"}),231:c(_,function(e){return"e.random("+e.U2S()+")"}),232:c(_,d,{post:function(){this.storer=m},storer:0}),233:U,234:c(i,function(e){return"e.split_window("+e+")"}),235:c(i,function(e){return"e.set_window("+e+")"}),236:u,237:c(i,function(e){return"e.erase_window("+e.U2S()+")"}),238:c(i,function(e){return"e.erase_line("+e+")"}),239:c(i,function(e,t){return"e.set_cursor("+e+"-1,"+t+"-1)"}),240:c(i,function(e){return"e.get_cursor("+e+")"}),241:c(i,function(e){return"e.set_style("+e+")"}),242:i,243:c(n,function(){return"e.pc="+this.next+";e.output_stream("+this.args()+")"}),244:c(a,function(){return"e.input_stream("+this.args()+")"}),245:i,246:c(o,function(){return"e.read_char("+this.storer.v+","+(this.args()||"1")+")"}),247:c(p,function(){return"e.scan_table("+this.args()+")"}),248:h,249:g,250:g,251:c(i,function(){return"e.tokenise("+this.args()+")"}),252:c(i,function(){return"e.encode_text("+this.args()+")"}),253:c(i,function(){return"e.copy_table("+this.args()+")"}),254:c(i,function(){return"e.print_table("+this.args()+")"}),255:c(l,function(e){return"e.stack.getUint8(e.frameptr+5)&(1<<("+e+"-1))"}),1e3:v,1001:w,1002:c(_,function(e,t){return"e.S2U(e.log_shift("+e+","+t.U2S()+"))"}),1003:c(_,function(e,t){return"e.S2U(e.art_shift("+e.U2S()+","+t.U2S()+"))"}),1004:c(_,function(e){return"e.set_font("+e+")"}),1009:c(_,function(){return"e.save_undo("+this.next+","+this.storer.v+")"}),1010:c(i,function(){return"if(e.restore_undo())return"},{storer:1}),1011:c(i,function(e){return"e.print(1,"+e+")"}),1012:c(_,function(){return 3}),1013:c(i,function(){return"e.set_true_colour("+this.args()+")"}),1014:i.subClass({brancher:1}),1030:c(_,function(){return"e.gestalt("+this.args()+")"})}}},{"../common/ast.js":1}],8:[function(e,t){"use strict";function s(e){const t=(e)=>"object"==typeof e?s(e):e,r={};if(Array.isArray(e))return e.map(t);for(let s in e)"buffer"!=s&&"str"!=s&&(r[s]=t(e[s]));return r}function r(e,t,s,r){if(p&&!r)for(;t>-t},call:function(e,t,s,r){if(0===e)return 0<=t&&this.variable(t,0),this.pc=s;this.pc=e*this.addr_multipler;var n=this.m.getUint8(this.pc++),a=this.stack,o=0,i=this.frameptr;for(a.setUint16(i+6,this.sp),this.frames.push(i),i=this.frameptr=this.s.byteOffset+2*this.sp,a.setUint32(i,s<<8),a.setUint8(i+3,(0<=t?0:16)|n),a.setUint8(i+4,0<=t?t:0),a.setUint8(i+5,(1<this.version?this.m.getUint16(this.pc+2*o):0,o++;5>this.version&&(this.pc+=2*n)},clear_attr:function(e,t){var s=0|this.objects+(this.version3?9:14)*e+t/8;this.ram.setUint8(s,this.m.getUint8(s)&~(128>>t%8))},copy_table:function(e,t,s){s=o(s);var r=this.ram,n=0,i=0>s;if(s=Math.abs(s),0===t){for(;nthis.extension_count?0:(s+=2*e,void 0===t?this.m.getUint16(s):void this.ram.setUint16(s,t))},find_prop:function(e,t,s){var r,i,n=this.m,a=this.version3,o=0,l=n.getUint16(this.objects+(a?9:14)*e+(a?7:12));for(l+=2*n.getUint8(l)+1;;){if(r=n.getUint8(l),i=r&(a?31:63),o===s)return i;if(i===t)return l+(!a&&128&r?2:1);if(i>5)+2:128&r?(i=63&n.getUint8(l+1),l+=i?i+2:66):l+=64&r?3:2}},gestalt:function(e){return 1===e?258:0},get_child:function(e){return this.version3?this.m.getUint8(this.objects+9*e+6):this.m.getUint16(this.objects+14*e+10)},get_sibling:function(e){return this.version3?this.m.getUint8(this.objects+9*e+5):this.m.getUint16(this.objects+14*e+8)},get_parent:function(e){return this.version3?this.m.getUint8(this.objects+9*e+4):this.m.getUint16(this.objects+14*e+6)},get_prop:function(e,t){var s,r=this.m,i=this.find_prop(e,t);return i?(s=r.getUint8(i-1),r[(this.version3?s>>5:64&s)?"getUint16":"getUint8"](i)):r.getUint16(this.properties+2*(t-1))},get_prop_len:function(e){if(0===e)return 0;var t=this.m.getUint8(e-1);return this.version3?(t>>5)+1:128&t?(t&=63,0===t?64:t):64&t?2:1},incdec:function(e,t){if(0===e)return this.s[this.sp-1]+=t,this.s[this.sp-1];if(15>--e)return this.l[e]+=t,this.l[e];var s=this.globals+2*(e-15);return this.ram.setUint16(s,this.m.getUint16(s)+t),this.ram.getUint16(s)},indirect:function(e,t){return 0===e?1>>-t},make_stacks:function(){var e=15&this.stack.getUint8(this.frameptr+3);this.l=new Uint16Array(this.stack.buffer,this.frameptr+8,e),this.s=new Uint16Array(this.stack.buffer,this.frameptr+8+2*e)},put_prop:function(e,t,s){var r,i=this.find_prop(e,t);i&&(r=this.m.getUint8(i-1),this.ram[(this.version3?r>>5:64&r)?"setUint16":"setUint8"](i,s))},random:function(e){var t=this.xorshift_seed;return 1>e?(this.xorshift_seed=e,0):0===t?0|1+Math.random()*e:(t^=t<<13,t^=t>>17,this.xorshift_seed=t^=t<<5,1+(32767&t)%e)},remove_obj:function(e){var t,s,r,i=this.get_parent(e);if(0!==i)if(t=this.get_child(i),s=this.get_sibling(e),t===e)this.set_family(e,0,i,s);else{for(;r=this.get_sibling(t),r!==e;)t=r;this.set_family(e,0,0,0,t,s)}},restart:function(){var t=this.ram,s=t.getUint8(0),r=3===s,n=r?2:8===s?8:4,o=t.getUint8(17),l=t.getUint16(10),p=4g;)if(a.getUint8(18+g)!==o.serial[g++])return 0;if(g=0,a.setUint8Array(0,this.origram),o.compressed)for(;g>8,s=this.frameptr=this.frames.pop(),this.make_stacks(),this.sp=t.getUint16(s+6),0<=r&&this.variable(r,e||0)},save:function(e){this.pc=e,this.fileref_create_by_prompt({func:"save",mode:1,usage:1})},save_file:function(e,t){var s,i,o,l=this.m,_=new n.Quetzal,g=a.MemoryView(this.stack.buffer.slice()),u=0,c=this.frameptr;if(_.release=l.getUint16(2),_.serial=l.getUint8Array(18,6),_.checksum=l.getUint16(28),_.pc=e,t)_.memory=this.m.getUint8Array(0,this.staticmem);else{const e=[];for(_.compressed=1,s=0;s>18,!a==!s&&(0===r||1===r?this.ret(r):this.pc+=r-2)):this.variable(i.getUint8(this.pc++),a)},save_undo:function(e,t){var s;return this.undo_len>this.options.undo_len&&(s=this.undo.shift(),this.undo_len-=s.ram.byteLength+s.stack.byteLength),s={frameptr:this.frameptr,frames:this.frames.slice(),pc:e,ram:this.m.getUint8Array(0,this.staticmem),sp:this.sp,stack:this.stack.getUint8Array(0,this.s.byteOffset+2*this.sp),var:t},this.undo_len+=s.ram.byteLength+s.stack.byteLength,this.undo.push(s),1},scan_table:function(e,t,s,r){r=r||130;var i=128&r?"getUint16":"getUint8";for(r&=127,s=t+s*r;t>t%8)},set_family:function(e,t,s,r,i,n){var a=this.ram,o=this.objects;this.version3?(a.setUint8(o+9*e+4,t),s&&a.setUint8(o+9*s+6,r),i&&a.setUint8(o+9*i+5,n)):(a.setUint16(o+14*e+6,t),s&&a.setUint16(o+14*s+10,r),i&&a.setUint16(o+14*i+8,n))},test:function(e,t){return(e&t)===t},test_attr:function(e,t){return 128&this.m.getUint8(0|this.objects+(this.version3?9:14)*e+t/8)<--e){if(r)this.l[e]=t;else return this.l[e];}else if(s=this.globals+2*(e-15),r)this.ram.setUint16(s,t);else return this.m.getUint16(s);return t},U2S:o,S2U:l}},{"../common/file.js":2,"../common/utils.js":3,"./opcodes.js":7}],9:[function(s,r){r.exports={init_text:function(){var e=this,s=this.m,r=4r;)s[0|r/26][r%26]=t[r++];s[2][1]=13,e.alphabets=s}(r?s.getUint8Array(r,78):this.text_to_zscii("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \r0123456789.,!?_#'\"/\\-:()",1)),function(s){for(var r={13:"\r"},n={13:13},a=0;aa;)r[a]=t(a),n[a]=a++;e.unicode_table=r,e.reverse_unicode_table=n}(i?s.getUint16Array(i,n):this.text_to_zscii(unescape("%E4%F6%FC%C4%D6%DC%DF%BB%AB%EB%EF%FF%CB%CF%E1%E9%ED%F3%FA%FD%C1%C9%CD%D3%DA%DD%E0%E8%EC%F2%F9%C0%C8%CC%D2%D9%E2%EA%EE%F4%FB%C2%CA%CE%D4%DB%E5%C5%F8%D8%E3%F1%F5%C3%D1%D5%E6%C6%E7%C7%FE%F0%DE%D0%A3%u0153%u0152%A1%BF"),1)),this.dictionaries={},this.dict=s.getUint16(8),this.parse_dict(this.dict)},decode:function(e,t){var s,r,n,a=this.m,o=e,l=[],p=0,i=0,_=[],g=[],u=0;if(this.jit[e])return this.jit[e];for(t=t?t+e:this.eof;e>10,31&s>>5,31&s),!(32768&s)););for(;pr?(n=1,_.push(-1),g.push("\uE000+this.abbr("+(32*(r-1)+l[p++])+")+\uE000")):6>r?i=r:2==i&&6===r?p+1r&&_.push(this.alphabets[i][r-6]),i=4>i?0:i-3,0==p%3&&(p+=u,u=0);return _=this.zscii_to_text(_,g),n&&(_={toString:Function("return\""+_.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\r/g,"\\r").replace(/\uE000/g,"\"")+"\"").bind(this)}),o>=this.staticmem&&(this.jit[o]=_),_},encode:function(e){for(var t,s,r=this.alphabets,n=[],a=this.version3?6:9,o=0,i=[];n.length>5,31&t);for(n.length=a,o=0;o>3,(7&n[o++])<<5|n[o++]);return i[i.length-2]|=128,i},zscii_to_text:function(e,t){for(var s,r=0,i=e.length,n=0,a="";r