/*
Gnusto
======
Built: 2012-04-22
Copyright (c) 2003-2011 The Gnusto Contributors
GNU GPL licenced
http://github.com/curiousdannii/gnusto
String.prototype.quote() taken from "Remedial Javascript" by Douglas Crockford: http://javascript.crockford.com/remedial.html
*/
var Quetzal=IFF.subClass({init:function(b){this._super(b);if(b){if(this.type!="IFZS"){throw new Error("Not a Quetzal savefile")}for(var c=0,a=this.chunks.length;c>16)&255,(b>>8)&255,b&255);this.chunks=[{type:"IFhd",data:a},{type:(this.compressed?"CMem":"UMem"),data:this.memory},{type:"Stks",data:this.stacks}];return this._super()}});String.prototype.quote=function(){var e,b,a=this.length,d='"';for(b=0;b=" "){if(e==="\\"||e==='"'){d+="\\"}d+=e}else{switch(e){case"\b":d+="\\b";break;case"\f":d+="\\f";break;case"\n":d+="\\n";break;case"\r":d+="\\r";break;case"\t":d+="\\t";break;default:e=e.charCodeAt();d+="\\u00"+Math.floor(e/16).toString(16)+(e%16).toString(16)}}}return d+'"'};var CVS_VERSION="$Date: 2005/04/26 01:50:32 $";var ENGINE_DESCRIPTION="Gnusto's interactive fiction engine";var default_unicode_translation_table={155:228,156:246,157:252,158:196,159:214,160:220,161:223,162:187,163:171,164:235,165:239,166:255,167:203,168:207,169:225,170:233,171:237,172:243,173:250,174:253,175:193,176:201,177:205,178:211,179:218,180:221,181:224,182:232,183:236,184:242,185:249,186:192,187:200,188:204,189:210,190:217,191:226,192:234,193:238,194:244,195:251,196:194,197:202,198:206,199:212,200:219,201:229,202:197,203:248,204:216,205:227,206:241,207:245,208:195,209:209,210:213,211:230,212:198,213:231,214:199,215:254,216:240,217:222,218:208,219:163,220:339,221:338,222:161,223:191};var reverse_unicode_table={};var isNotConst=/\D/;var temp_var=0;var PARENT_REC=0;var SIBLING_REC=1;var CHILD_REC=2;var CALLED_FROM_INTERRUPT=0;if(!window){this.window={}}var dummy;var t;var t2;var PARCHMENT_SECURITY_OVERRIDE=window.PARCHMENT_SECURITY_OVERRIDE;var GNUSTO_EFFECT_INPUT='"RS"';var GNUSTO_EFFECT_INPUT_CHAR='"RC"';var GNUSTO_EFFECT_SAVE='"DS"';var GNUSTO_EFFECT_RESTORE='"DR"';var GNUSTO_EFFECT_QUIT='"QU"';var GNUSTO_EFFECT_RESTART='"NU"';var GNUSTO_EFFECT_WIMP_OUT='"WO"';var GNUSTO_EFFECT_BREAKPOINT='"BP"';var GNUSTO_EFFECT_FLAGS_CHANGED='"XC"';var GNUSTO_EFFECT_PIRACY='"CP"';var GNUSTO_EFFECT_STYLE='"SS"';var GNUSTO_EFFECT_SOUND='"FX"';var GNUSTO_EFFECT_SPLITWINDOW='"TW"';var GNUSTO_EFFECT_SETWINDOW='"SW"';var GNUSTO_EFFECT_ERASEWINDOW='"YW"';var GNUSTO_EFFECT_ERASELINE='"YL"';var GNUSTO_EFFECT_SETCURSOR='"SC"';var GNUSTO_EFFECT_SETBUFFERMODE='"SB"';var GNUSTO_EFFECT_SETINPUTSTREAM='"SI"';var GNUSTO_EFFECT_GETCURSOR='"GC"';var GNUSTO_EFFECT_PRINTTABLE='"PT"';function handleZ_je(d,b){if(b.length<2){return""}else{if(b.length==2){return d._brancher(b[0]+"=="+b[1])}else{var e="";for(var c=1;ct2")}function handleZ_inc_chk(c,b){var d=handleZ_inc(c,b);d+="{var t1=incdec; t1 = ((t1 & 0x8000 ? ~0xFFFF : 0) | t1); var t2="+b[1]+"; t2=((t2 & 0x8000 ? ~0xFFFF : 0) | t2);"+c._brancher("t1 > t2")+"}";return d}function handleZ_dec_chk(c,b){var d=handleZ_dec(c,b);d+="{var t1=incdec; t1 = ((t1 & 0x8000 ? ~0xFFFF : 0) | t1); var t2="+b[1]+"; t2=((t2 & 0x8000 ? ~0xFFFF : 0) | t2);"+c._brancher("t1 < t2")+"}";return d}function handleZ_jin(c,b){return c._brancher("_obj_in("+b[0]+","+b[1]+")")}function handleZ_test(c,b){return"t="+b[1]+";"+c._brancher("("+b[0]+"&t)==t")}function handleZ_or(c,b){return c._storer("("+b[0]+"|"+b[1]+")")}function handleZ_and(c,b){return c._storer("("+b[0]+"&"+b[1]+")")}function handleZ_test_attr(c,b){return c._brancher("_test_attr("+b[0]+","+b[1]+")")}function handleZ_set_attr(c,b){return"_set_attr("+b[0]+","+b[1]+")"}function handleZ_clear_attr(c,b){return"_clear_attr("+b[0]+","+b[1]+")"}function handleZ_store(c,b){var d;if(isNaN(b[0])){d="("+b[0]+" == 0) ? m_gamestack[m_gamestack.length - 1] = "+b[1]+" : ("+b[0]+" < 0x10) ? m_locals[( "+b[0]+" - 1 )] = "+b[1]+" : setWord("+b[1]+", m_vars_start + ( "+b[0]+" - 16 ) * 2 )"}else{if(b[0]==0){d="m_gamestack[m_gamestack.length - 1] = "+b[1]}else{if(b[0]<16){d="m_locals[( "+b[0]+" - 1 )] = "+b[1]}else{d="setWord("+b[1]+", m_vars_start + ( "+b[0]+" - 16 ) * 2 )"}}}return d}function handleZ_insert_obj(c,b){return"_insert_obj("+b[0]+","+b[1]+")"}function handleZ_loadw(e,b){if(isNotConst.test(b[0])||isNotConst.test(b[1])){var f="var tmp_"+(++temp_var)+" = ("+b[0]+" + 2 * "+b[1]+") & 0xFFFF, ",g="tmp_"+temp_var,d=g+"+1"}else{var f="var ",g=(b[0]+2*b[1])&65535,d=g+1}var c="tmp_"+(++temp_var);return f+c+" = (m_memory["+g+"] << 8) | m_memory["+d+"];"+e._storer(c)}function handleZ_loadb(c,b){return c._storer("m_memory[0xFFFF&("+b[0]+"+"+b[1]+")]")}function handleZ_get_prop(c,b){return c._storer("_get_prop("+b[0]+","+b[1]+")")}function handleZ_get_prop_addr(c,b){return c._storer("_get_prop_addr("+b[0]+","+b[1]+")")}function handleZ_get_next_prop(c,b){return c._storer("_get_next_prop("+b[0]+","+b[1]+")")}function handleZ_add(c,b){return c._storer("("+b[0]+" + "+b[1]+") & 0xFFFF")}function handleZ_sub(c,b){return c._storer("("+b[0]+" - "+b[1]+") & 0xFFFF")}function handleZ_mul(c,b){return c._storer("("+b[0]+"*"+b[1]+") & 0xFFFF")}function handleZ_div(c,b){return c._storer("_trunc_divide("+b[0]+","+b[1]+")")}function handleZ_mod(c,b){return c._storer("_trunc_modulo("+b[0]+","+b[1]+")")}function handleZ_set_colour(c,b){return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_STYLE+",-1,"+b[0]+","+b[1]+"];return"}function handleZ_throw(c,b){c.m_compilation_running=0;return"_throw_stack_frame("+b[0]+");return"}function handleZ_jz(c,b){return c._brancher(b[0]+"==0")}function handleZ_get_sibling(c,b){return"t=_get_sibling("+b[0]+");"+c._storer("t")+";"+c._brancher("t")}function handleZ_get_child(c,b){return"t=_get_child("+b[0]+");"+c._storer("t")+";"+c._brancher("t")}function handleZ_get_parent(c,b){return c._storer("_get_parent("+b[0]+")")}function handleZ_get_prop_len(c,b){return c._storer("_get_prop_len("+b[0]+")")}function handleZ_inc(c,b){var d="var incdec; ";if(isNaN(b[0])){d+="var incdec; if ("+b[0]+" == 0) { incdec = m_gamestack[m_gamestack.length - 1] = (m_gamestack[m_gamestack.length - 1] + 1) & 0xFFFF; } else if ("+b[0]+" < 0x10) { incdec = m_locals[( "+b[0]+" - 1 )] = (m_locals[( "+b[0]+" - 1 )] + 1) & 0xFFFF; } else { var val = getUnsignedWord(m_vars_start + ( "+b[0]+" - 16 ) * 2 ); val++; setWord(val, m_vars_start + ( "+b[0]+" - 16 ) * 2 ); incdec = val; }"}else{if(b[0]==0){d+="incdec = m_gamestack[m_gamestack.length - 1] = (m_gamestack[m_gamestack.length - 1] + 1) & 0xFFFF;"}else{if(b[0]<16){d+="incdec = m_locals[( "+b[0]+" - 1 )] = (m_locals[( "+b[0]+" - 1 )] + 1) & 0xFFFF;"}else{d+="{var val = getWord(m_vars_start + ( "+b[0]+" - 16 ) * 2 ); val++; setWord(val, m_vars_start + ( "+b[0]+" - 16 ) * 2 ); incdec = val;}"}}}return d}function handleZ_dec(c,b){var d="var incdec; ";if(isNaN(b[0])){d+="if ("+b[0]+" == 0) { incdec = m_gamestack[m_gamestack.length - 1] = (m_gamestack[m_gamestack.length - 1] - 1) & 0xFFFF; } else if ("+b[0]+" < 0x10) { incdec = m_locals[( "+b[0]+" - 1 )] = (m_locals[( "+b[0]+" - 1 )] - 1) & 0xFFFF; } else { var val = getUnsignedWord(m_vars_start + ( "+b[0]+" - 16 ) * 2 ); val--; setWord(val, m_vars_start + ( "+b[0]+" - 16 ) * 2 ); incdec = val; }"}else{if(b[0]==0){d+="incdec = m_gamestack[m_gamestack.length - 1] = (m_gamestack[m_gamestack.length - 1] - 1) & 0xFFFF;"}else{if(b[0]<16){d+="incdec = m_locals[( "+b[0]+" - 1 )] = (m_locals[( "+b[0]+" - 1 )] - 1) & 0xFFFF;"}else{d+="{var val = getUnsignedWord(m_vars_start + ( "+b[0]+" - 16 ) * 2 ); val--; setWord(val, m_vars_start + ( "+b[0]+" - 16 ) * 2 ); incdec = val;}"}}}return d}function handleZ_print_addr(c,b){return c._handler_zOut("_zscii_from("+b[0]+")",0)}function handleZ_remove_obj(c,b){return"_remove_obj("+b[0]+","+b[1]+")"}function handleZ_print_obj(c,b){return c._handler_zOut("_name_of_object("+b[0]+")",0)}function handleZ_ret(c,b){c.m_compilation_running=0;return"_func_return("+b[0]+");return"}function handleZ_jump(c,b){c.m_compilation_running=0;if(b[0]&32768){b[0]=(~65535)|b[0]}var d=(b[0]+c.m_pc)-2;return"m_pc="+d+";return"}function handleZ_print_paddr(c,b){return c._handler_zOut("_zscii_from("+c.m_pc_translate_for_string(b[0])+")",0)}function handleZ_load(c,b){var d;if(isNaN(b[0])){d="("+b[0]+" == 0) ? m_gamestack[m_gamestack.length - 1] : ("+b[0]+" < 0x10) ? m_locals[( "+b[0]+" - 1 )] : getUnsignedWord( m_vars_start + ( "+b[0]+" - 16 ) * 2 )"}else{if(b[0]==0){d="m_gamestack[m_gamestack.length - 1]"}else{if(b[0]<16){d="m_locals[( "+b[0]+" - 1 )]"}else{d="getUnsignedWord( m_vars_start + ( "+b[0]+" - 16 ) * 2 )"}}}return c._storer(d)}function handleZ_rtrue(c,b){c.m_compilation_running=0;return"_func_return(1);return"}function handleZ_rfalse(c,b){c.m_compilation_running=0;return"_func_return(0);return"}function handleZ_print(c,b){return c._handler_print("",0)}function handleZ_print_ret(c,b){c.m_compilation_running=0;return c._handler_print("\n",1)+";_func_return(1);return"}function handleZ_nop(c,b){return""}function handleZ_restart(c,b){c.m_compilation_running=0;return"m_effects=["+GNUSTO_EFFECT_RESTART+"];return"}function handleZ_ret_popped(c,b){c.m_compilation_running=0;return"_func_return(m_gamestack.pop());return"}function handleZ_catch(c,b){return c._storer("m_call_stack.length")}function handleZ_pop(c,b){return"m_gamestack.pop()"}function handleZ_quit(c,b){c.m_compilation_running=0;return"m_effects=["+GNUSTO_EFFECT_QUIT+"];return"}function handleZ_new_line(c,b){return c._handler_zOut("'\\n'",0)}function handleZ_show_status(c,b){c._handler_zOut("");return""}function handleZ_verify(c,b){return c._brancher("_verify()")}function handleZ_illegal_extended(c,b){gnusto_error(199)}function handleZ_piracy(c,b){c.m_compilation_running=0;var d="m_rebound=function(){"+c._brancher("(!0)")+"};";return"m_pc="+c.m_pc+";"+d+"m_effects=["+GNUSTO_EFFECT_PIRACY+"];return"}function handleZ_call_1n(c,b){return c._generate_gosub(b[0],"",0)}function handleZ_call_1s(c,b){return c._generate_gosub(b[0],"",1)}function handleZ_call_2n(c,b){return c._generate_gosub(b[0],b[1],0)}function handleZ_call_2s(c,b){return c._generate_gosub(b[0],b[1],1)}function handleZ_call_vn(c,b){return c._generate_gosub(b[0],b.slice(1),0)}function handleZ_call_vs(c,b){return c._generate_gosub(b[0],b.slice(1),1)}function handleZ_store_w(e,b){if(isNotConst.test(b[0])||isNotConst.test(b[1])){var f="var tmp_"+(++temp_var)+" = ("+b[0]+" + 2 * "+b[1]+") & 0xFFFF;",g="tmp_"+temp_var,d=g+"+1"}else{var f="",g=(b[0]+2*b[1])&65535,d=g+1}if(!isNotConst.test(b[2])){if(e.m_value_asserts){if(b[2]==null||b[2]===true||b[2]===false||b[2]<0||b[2]>65535){e.logger("Z_store_w value",b[2])}}return f+"m_memory["+g+"] = "+((b[2]>>8)&255)+";m_memory["+d+"] = "+(b[2]&255)}else{var c="tmp_"+(++temp_var);return f+"var "+c+" = "+b[2]+";m_memory["+g+"] = ("+c+" >> 8) & 0xFF;m_memory["+d+"] = "+c+" & 0xFF;"}}function handleZ_storeb(c,b){return"setByte("+b[2]+",("+b[0]+"+"+b[1]+")&0xFFFF)"}function handleZ_putprop(c,b){return"_put_prop("+b[0]+","+b[1]+","+b[2]+")"}function handleZ_read(f,i){var g;var b;f.m_compilation_running=0;var h="_aread(m_answers[0],m_rebound_args[1],m_rebound_args[2],m_answers[1])";var j;var d;if(f.m_version>=5){h=f._storer(h)}if(f.m_version>=5){j="m_memory[0xFFFF&a0+1]";d="m_memory[0xFFFF&a0]"}else{j="0";d="m_memory[0xFFFF&a0]+1"}if(i[2]&&i[3]&&(f.m_version>=4)){g=i[2];b=f.m_pc_translate_for_routine(i[3])}else{g="0";b="0"}var c="m_rebound=function(){var t=1*m_answers[0];if(t<0){_func_interrupt(m_rebound_args[0],onISRReturn_for_read);}else{"+h+";}};";var e="m_rebound_args=["+b+",a0,"+i[1]+",];";return"var a0=eval("+i[0]+");m_pc="+f.m_pc+";"+e+c+"m_effects=["+GNUSTO_EFFECT_INPUT+","+g+","+j+","+d+",_terminating_characters()];return"}function handleZ_print_char(c,b){return c._handler_zOut("_zscii_char_to_ascii("+b[0]+")",0)}function handleZ_print_num(c,b){return c._handler_zOut('""+_unsigned2signed('+b[0]+")",0)}function handleZ_random(c,b){return c._storer("_random_number("+b[0]+")")}function handleZ_push(c,b){return"m_gamestack.push("+b[0]+")"}function handleZ_pull(c,b){var d="var pull = m_gamestack.pop(); ";return d+=handleZ_store(c,[b[0],"pull"])}function handleZ_split_window(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_SPLITWINDOW+","+b[0]+"];return"}function handleZ_set_window(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_SETWINDOW+","+b[0]+"];return"}function handleZ_erase_window(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_ERASEWINDOW+","+c._unsigned2signed(b[0])+"];return"}function handleZ_erase_line(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_ERASELINE+","+b[0]+"];return"}function handleZ_set_cursor(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_SETCURSOR+","+b[0]+","+b[1]+"];return"}function handleZ_get_cursor(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_GETCURSOR+","+b[0]+"];return"}function handleZ_set_text_style(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_STYLE+","+b[0]+",0,0];return"}function handleZ_buffer_mode(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_SETBUFFERMODE+","+b[0]+"];return"}function handleZ_output_stream(c,b){return"_set_output_stream("+b[0]+","+b[1]+")"}function handleZ_input_stream(c,b){c.m_compilation_running=0;return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_SETINPUTSTREAM+","+b[0]+"];return"}function handleZ_sound_effect(c,b){c.m_compilation_running=0;while(b.length<5){b.push(0)}return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_SOUND+","+b[0]+","+b[1]+","+b[2]+","+b[3]+","+b[4]+"];return"}function handleZ_read_char(e,c){var f;var d;var b;e.m_compilation_running=0;if(c[1]&&c[2]&&(e.m_version>=4)){f=c[1];d="m_rebound_args=["+e.m_pc_translate_for_routine(c[2])+"];";b="m_rebound=function(){var t=m_answers[0];if(t<0){_func_interrupt(m_rebound_args[0],onISRReturn_for_read_char);}else{"+e._storer("_ascii_code_to_zscii_code(t)")+"}};"}else{f="0";d="";b="m_rebound=function(){"+e._storer("_ascii_code_to_zscii_code(m_answers[0])")+"};"}return"m_pc="+e.m_pc+";"+d+b+"m_effects=["+GNUSTO_EFFECT_INPUT_CHAR+","+f+"];return"}function handleZ_scan_table(c,b){if(b.length==4){return"t=_scan_table("+b[0]+","+b[1]+"&0xFFFF,"+b[2]+"&0xFFFF,"+b[3]+");"+c._storer("t")+";"+c._brancher("t")}else{return"t=_scan_table("+b[0]+","+b[1]+"&0xFFFF,"+b[2]+"&0xFFFF,"+130+");"+c._storer("t")+";"+c._brancher("t")}}function handleZ_not(c,b){return c._storer("~"+b[0]+"&0xffff")}function handleZ_tokenise(c,b){return"_tokenise("+b[0]+","+b[1]+","+b[2]+","+b[3]+")"}function handleZ_encode_text(c,b){return"_encode_text("+b[0]+","+b[1]+","+b[2]+","+b[3]+")"}function handleZ_copy_table(c,b){return"_copy_table("+b[0]+","+b[1]+","+b[2]+")"}function handleZ_print_table(c,b){if(b.length<3){b.push(1)}if(b.length<4){b.push(0)}return"m_pc="+c.m_pc+";m_effects=_print_table("+b[0]+","+b[1]+","+b[2]+","+b[3]+");return"}function handleZ_check_arg_count(c,b){return c._brancher(b[0]+"<=_param_count()")}function handleZ_saveV123(c,b){c.m_compilation_running=0;var d="m_rebound=function(){"+c._brancher("m_answers[0]")+"};";return"m_state_to_save=_saveable_state(1);m_pc="+c.m_pc+";"+d+";m_effects=["+GNUSTO_EFFECT_SAVE+"];return"}function handleZ_saveV45678(c,b){c.m_compilation_running=0;var d="m_rebound=function() { "+c._storer("m_answers[0]")+"};";return"m_state_to_save=_saveable_state("+(c.m_version==4?"1":"3")+");m_pc="+c.m_pc+";"+d+";m_effects=["+GNUSTO_EFFECT_SAVE+"];return"}function handleZ_restoreV123(c,b){c.m_compilation_running=0;c._brancher("");return"m_pc="+c.m_pc+";m_effects=["+GNUSTO_EFFECT_RESTORE+"];return"}function handleZ_restoreV45678(c,b){c.m_compilation_running=0;var d="m_rebound=function() { var t=m_answers[0]; if (t==0){"+c._storer("t")+"}};";return"m_pc="+c.m_pc+";"+d+"m_effects=["+GNUSTO_EFFECT_RESTORE+"];return"}function handleZ_log_shift(c,b){return c._storer("_log_shift("+b[0]+","+b[1]+")")}function handleZ_art_shift(c,b){return c._storer("_art_shift("+b[0]+","+b[1]+")")}function handleZ_set_font(c,b){return c._storer("("+b[0]+"<2?1:0)")}function handleZ_save_undo(c,b){return c._storer("_save_undo("+c.m_pc+")")}function handleZ_restore_undo(c,b){return"if(_restore_undo())return;"+c._storer("0")}function handleZ_print_unicode(c,b){return c._handler_zOut("String.fromCharCode("+b[0]+")",0)}function handleZ_check_unicode(c,b){return c._storer("3")}function handleZ_gestalt(c,b){return c._storer("gestalt("+b[0]+", "+(b.length<2?0:b[1])+")")}function handleZ_parchment(c,b){return c._storer("op_parchment("+b[0]+", "+(b.length<2?0:b[1])+")")}var handlers_v578={1:handleZ_je,2:handleZ_jl,3:handleZ_jg,4:handleZ_dec_chk,5:handleZ_inc_chk,6:handleZ_jin,7:handleZ_test,8:handleZ_or,9:handleZ_and,10:handleZ_test_attr,11:handleZ_set_attr,12:handleZ_clear_attr,13:handleZ_store,14:handleZ_insert_obj,15:handleZ_loadw,16:handleZ_loadb,17:handleZ_get_prop,18:handleZ_get_prop_addr,19:handleZ_get_next_prop,20:handleZ_add,21:handleZ_sub,22:handleZ_mul,23:handleZ_div,24:handleZ_mod,25:handleZ_call_2s,26:handleZ_call_2n,27:handleZ_set_colour,28:handleZ_throw,128:handleZ_jz,129:handleZ_get_sibling,130:handleZ_get_child,131:handleZ_get_parent,132:handleZ_get_prop_len,133:handleZ_inc,134:handleZ_dec,135:handleZ_print_addr,136:handleZ_call_1s,137:handleZ_remove_obj,138:handleZ_print_obj,139:handleZ_ret,140:handleZ_jump,141:handleZ_print_paddr,142:handleZ_load,143:handleZ_call_1n,176:handleZ_rtrue,177:handleZ_rfalse,178:handleZ_print,179:handleZ_print_ret,180:handleZ_nop,183:handleZ_restart,184:handleZ_ret_popped,185:handleZ_catch,186:handleZ_quit,187:handleZ_new_line,189:handleZ_verify,190:handleZ_illegal_extended,191:handleZ_piracy,224:handleZ_call_vs,225:handleZ_store_w,226:handleZ_storeb,227:handleZ_putprop,228:handleZ_read,229:handleZ_print_char,230:handleZ_print_num,231:handleZ_random,232:handleZ_push,233:handleZ_pull,234:handleZ_split_window,235:handleZ_set_window,236:handleZ_call_vs,237:handleZ_erase_window,238:handleZ_erase_line,239:handleZ_set_cursor,240:handleZ_get_cursor,241:handleZ_set_text_style,242:handleZ_buffer_mode,243:handleZ_output_stream,244:handleZ_input_stream,245:handleZ_sound_effect,246:handleZ_read_char,247:handleZ_scan_table,248:handleZ_not,249:handleZ_call_vn,250:handleZ_call_vn,251:handleZ_tokenise,252:handleZ_encode_text,253:handleZ_copy_table,254:handleZ_print_table,255:handleZ_check_arg_count,1000:handleZ_saveV45678,1001:handleZ_restoreV45678,1002:handleZ_log_shift,1003:handleZ_art_shift,1004:handleZ_set_font,1009:handleZ_save_undo,1010:handleZ_restore_undo,1011:handleZ_print_unicode,1012:handleZ_check_unicode,1030:handleZ_gestalt,1031:handleZ_parchment};var handlers_fixups={1:{25:0,26:0,27:0,28:0,136:0,143:handleZ_not,181:handleZ_saveV123,182:handleZ_restoreV123,185:handleZ_pop,188:handleZ_show_status,190:0,191:0,236:0,237:0,238:0,239:0,240:0,241:0,242:0,246:0,247:0,248:0,249:0,250:0,251:0,252:0,253:0,254:0,255:0},2:{25:0,26:0,27:0,28:0,136:0,143:handleZ_not,181:handleZ_saveV123,182:handleZ_restoreV123,185:handleZ_pop,188:handleZ_show_status,190:0,191:0,236:0,237:0,238:0,239:0,240:0,241:0,242:0,246:0,247:0,248:0,249:0,250:0,251:0,252:0,253:0,254:0,255:0},3:{25:0,26:0,27:0,28:0,136:0,143:handleZ_not,181:handleZ_saveV123,182:handleZ_restoreV123,185:handleZ_pop,188:handleZ_show_status,190:0,191:0,236:0,237:0,238:0,239:0,240:0,241:0,242:0,246:0,247:0,248:0,249:0,250:0,251:0,252:0,253:0,254:0,255:0},4:{26:0,27:0,28:0,143:handleZ_not,181:handleZ_saveV45678,182:handleZ_restoreV45678,185:handleZ_pop,190:0,191:0,248:0,249:0,250:0,251:0,252:0,253:0,254:0,255:0},5:"",6:undefined,7:"",8:""};function pc_translate_v123(a){return"(("+a+")&0xFFFF)*2"}function pc_translate_v45(a){return"(("+a+")&0xFFFF)*4"}function pc_translate_v67R(a){return"(("+a+")&0xFFFF)*4+"+this.m_routine_start}function pc_translate_v67S(a){return"(("+a+")&0xFFFF)*4+"+this.m_string_start}function pc_translate_v8(a){return"(("+a+")&0xFFFF)*8"}function gnusto_error(b){message="Component: engine\n";message+="Code: "+b+"\n";for(var a=1;a=this.m_original_memory.length){gnusto_error(999,"overshoot in decompression")}var candidate=mem[cursor_compressed++];if(candidate==0){var run_length=mem[cursor_compressed++]+1;temp=temp.concat(this.m_original_memory.slice(cursor_original,cursor_original+run_length));cursor_original+=run_length}else{temp.push(candidate^this.m_original_memory[cursor_original++])}}mem=temp}this.m_call_stack=[];this.m_gamestack=[];this.m_locals_stack=[];this.m_locals=[];this.m_result_targets=[];var evals_count=0;evals_count=decodeStackInt(7,1);this.m_gamestack_callbreaks=[];var callbreaks_top=evals_count;var cursor=8;for(var m=0;m1){logArgs>>=1;argCount++}this.m_param_counts.unshift(argCount);evals_count=decodeStackInt(cursor,2);cursor+=2;callbreaks_top+=evals_count;this.m_gamestack_callbreaks.push(callbreaks_top);var locals_temp=[];for(var k=0;k=turns_limit){this.m_effects=["WO"];return 1}start_pc=this.m_pc;if(this.m_jit[start_pc]){jscode=this.m_jit[start_pc]}else{jscode=eval("with (this) {dummy="+this._compile()+"}");if(start_pc>=this.m_stat_start){this.m_jit[start_pc]=jscode}}jscode()}},walk:function ge_walk(a){gnusto_error(101,"'walk' not implemented")},setRandomSeed:function ge_setRandomSeed(a){if(a>0){this._random_number(-a)}else{this._random_number(a)}},saveGame:function ge_saveGame(){function b(s,k){var j=[];for(var m=0;m>=8}return j}var c=this.m_state_to_save,g=[],h=0,w=this.m_locals.length-16,a=0,u=[0,0,0,0,0,0],f=new Quetzal();f.release=c.m_memory.slice(2,4);f.serial=c.m_memory.slice(18,24);f.checksum=c.m_memory.slice(28,30);f.pc=c.m_pc;f.compressed=1;for(var r=0,l=this.m_stat_start;r>8)&255,e&255]);w-=n;for(var p=0;pd){b=b.substring(0,d-3);var e="...";var h=""}else{if((this.m_version>3)&&((this.getByte(1)&2)==2)){var a=this.getUnsignedWord(this.m_vars_start+2);var c=this.getUnsignedWord(this.m_vars_start+4);if(c<10){var e=a+":0"+c}else{var e=a+":"+c}}else{var e="Score: "+this.getUnsignedWord(this.m_vars_start+2)+" Moves: "+this.getUnsignedWord(this.m_vars_start+4)}if((b.length+e.length+1)>d){e=" S:"+this.getUnsignedWord(this.m_vars_start+2)+" M:"+this.getUnsignedWord(this.m_vars_start+4);if((b.length+e.length+1)>d){e=" "+this.getUnsignedWord(this.m_vars_start+2)+"/"+this.getUnsignedWord(this.m_vars_start+4)}if((b.length+e.length+1)>d){e=""}}var h="";while((b.length+e.length+h.length)=4){this.m_alpha_start=this.getUnsignedWord(52);this.m_object_tree_start=this.m_objs_start+112;this.m_property_list_addr_start=this.m_object_tree_start+12;this.m_object_size=14}else{this.m_alpha_start=0;this.m_object_tree_start=this.m_objs_start+53;this.m_property_list_addr_start=this.m_object_tree_start+7;this.m_object_size=9}this.m_hext_start=this.getUnsignedWord(54);if(this.m_version<=3){this.m_pc_translate_for_routine=pc_translate_v123;this.m_pc_translate_for_string=pc_translate_v123}else{if(this.m_version<=5){this.m_pc_translate_for_routine=pc_translate_v45;this.m_pc_translate_for_string=pc_translate_v45}else{if(this.m_version<=7){this.m_routine_start=this.getUnsignedWord(40)*8;this.m_string_start=this.getUnsignedWord(42)*8;this.m_pc_translate_for_routine=pc_translate_v67R;this.m_pc_translate_for_string=pc_translate_v67S}else{if(this.m_version==8){this.m_pc_translate_for_routine=pc_translate_v8;this.m_pc_translate_for_string=pc_translate_v8}else{gnusto_error(170,"impossible: unknown z-version got this far")}}}}if(!(this.m_version in handlers_fixups)){gnusto_error(311,"unknown z-machine version")}var f=handlers_fixups[this.m_version];switch(typeof(f)){case"undefined":gnusto_error(101,"z-machine version not implemented");break;case"string":this.m_handlers=handlers_v578;break;case"object":this.m_handlers={};for(var c in handlers_v578){this.m_handlers[c]=handlers_v578[c]}for(var g in f){if((typeof f[g])=="function"){this.m_handlers[g]=f[g]}else{delete this.m_handlers[g]}}break;default:gnusto_error(170,"impossible: weird stuff in fixups table")}this.m_separator_count=this.m_memory[this.m_dict_start];for(var h=0;h0){this.m_unicode_start=this.getUnsignedWord(this.m_hext_start+6);if(this.m_unicode_start>0){this.m_custom_unicode_charcount=this.m_memory[this.m_unicode_start];this.m_unicode_start+=1;for(var h=0;h0)){for(var h in default_unicode_translation_table){reverse_unicode_table[default_unicode_translation_table[h]]=h}}this.m_rebound=0;this.m_rebound_args=[];this.m_output_to_console=1;this.m_streamthrees=[];this.m_output_to_script=0;this.m_console_buffer="";this.m_transcript_buffer="";this.m_zalphabet[0]="abcdefghijklmnopqrstuvwxyz";this.m_zalphabet[1]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";if(this.m_version==1){this.m_zalphabet[2]="T0123456789.,!?_#'\"/\\<-:()"}else{this.m_zalphabet[2]="T\n0123456789.,!?_#'\"/\\-:()"}var e;var j;if(this.m_alpha_start>0){for(var a=0;a<3;a++){var b="";for(var d=0;d<26;d++){j=this.m_memory[this.m_alpha_start+(a*26)+d];if((j>=155)&&(j<=251)){if(this.m_unicode_start==0){b+=String.fromCharCode(default_unicode_translation_table[j])}else{if((j-154)<=this.m_custom_unicode_charcount){b+=String.fromCharCode(this.getUnsignedWord(this.m_unicode_start+((j-155)*2)))}else{b+=" "}}}else{e=String.fromCharCode(j);if(e=="^"){e="\n"}b+=e}}this.m_zalphabet[a]=b}}for(var h=0;h<16;h++){this.m_locals[h]=0}this.m_printing_header_bits=0;this.m_leftovers="";this.m_memory[30]=1;this.m_memory[31]=0;this.m_memory[1]|=29;this.m_memory[38]=1;this.m_memory[39]=1;this.m_memory[50]=1;this.m_memory[51]=PARCHMENT_SECURITY_OVERRIDE?2:0},_unsigned2signed:function ge_unsigned2signed(a){return((a&32768)?~65535:0)|a},_signed2unsigned:function ge_signed2unsigned(a){return a&65535},getByte:function ge_getbyte(a){if(this.m_value_asserts){if(a==null||a===true||a===false||a<0||a>=this.m_original_memory.length){this.logger("getByte addr",a)}var b=this.m_memory[a];if(b==null||b===true||b===false||b<0||b>255){this.logger("getByte byte",b)}}return this.m_memory[a]},setByte:function ge_setByte(b,a){if(this.m_value_asserts){if(a==null||a===true||a===false||a<0||a>=this.m_stat_start){this.logger("setByte addr",a)}}this.m_memory[a]=b&255},getWord:function ge_getWord(a){if(this.m_value_asserts){if(a==null||a===true||a===false||a<0||a>=this.m_original_memory.length){this.logger("getWord addr",a)}var c=this.m_memory[a];if(c==null||c===true||c===false||c<0||c>255){this.logger("getWord high byte",c)}var c=this.m_memory[a+1];if(c==null||c===true||c===false||c<0||c>255){this.logger("getWord low byte",c)}}var b=(this.m_memory[a]<<8)|this.m_memory[a+1];return((b&32768)?~65535:0)|b},getUnsignedWord:function ge_getUnsignedWord(a){if(this.m_value_asserts){if(a==null||a===true||a===false||a<0||a>=this.m_original_memory.length){this.logger("getUnsignedWord addr",a)}var b=this.m_memory[a];if(b==null||b===true||b===false||b<0||b>255){this.logger("getUnsignedWord high byte",b)}var b=this.m_memory[a+1];if(b==null||b===true||b===false||b<0||b>255){this.logger("getUnsignedWord low byte",b)}}return(this.m_memory[a]<<8)|this.m_memory[a+1]},setWord:function ge_setWord(b,a){if(this.m_value_asserts){if(a==null||a===true||a===false||a<0||a>=this.m_stat_start){this.logger("setWord",a)}}this.m_memory[a]=(b>>8)&255;this.m_memory[a+1]=(b)&255},_handle_variable_parameters:function ge_handle_var_parameters(c,d,a){var b=0,f="",e;if(a==1){d=(d<<8)|255}while(1){var g=d&49152;if(g==49152){return f}else{if(g==0){c[b++]=this.getUnsignedWord(this.m_pc);this.m_pc+=2}else{if(g==16384){c[b++]=this.m_memory[this.m_pc++]}else{if(g==32768){e=this._code_for_varcode(this.m_memory[this.m_pc++]);f+=e[0];c[b++]=e[1]}}}}d=(d<<2)|3}},_compile:function ge_compile(){this.m_compilation_running=1;var g="",f=this.m_pc,e,a;temp_var=0;do{var c=[];var b=this.m_memory[this.m_pc++];if(b==0){gnusto_error(201)}else{if(b==190){b=1000+this.m_memory[this.m_pc++];g+=this._handle_variable_parameters(c,this.m_memory[this.m_pc++],1)}else{if(b&128){if(b&64){if(!(b&32)){b&=31}if(b==250||b==236){var d=this.getUnsignedWord(this.m_pc);this.m_pc+=2;g+=this._handle_variable_parameters(c,d,2)}else{g+=this._handle_variable_parameters(c,this.m_memory[this.m_pc++],1)}}else{switch(b&48){case 0:c[0]=this.getUnsignedWord(this.m_pc);this.m_pc+=2;b=(b&15)|128;break;case 16:c[0]=this.m_memory[this.m_pc++];b=(b&15)|128;break;case 32:e=this._code_for_varcode(this.m_memory[this.m_pc++]);g+=e[0];c[0]=e[1];b=(b&15)|128;break;case 48:b=(b&15)|176;break}}}else{if(b&64){e=this._code_for_varcode(this.m_memory[this.m_pc++]);g+=e[0];c[0]=e[1]}else{c[0]=this.m_memory[this.m_pc++]}if(b&32){e=this._code_for_varcode(this.m_memory[this.m_pc++]);g+=e[0];c[1]=e[1]}else{c[1]=this.m_memory[this.m_pc++]}b&=31}}}if(this.m_handlers[b]){g=g+this.m_handlers[b](this,c)+";"}else{if(b>=1128&&b<=1255&&"special_instruction_EXT"+(b-1000) in this){g=g+this["special_instruction_EXT"+(b-1000)](c)+";"}else{gnusto_error(200,this.m_pc.toString(16))}}}while(this.m_compilation_running);if(this.m_single_step||this.m_debug_mode){g=g+"m_pc="+this.m_pc}g=g.replace(/m_gamestack\.push\(([^;]+)\);var tmp_(\d+) = m_gamestack\.pop\(\);/,"var tmp_$2 = $1;");a="function JIT_"+f.toString(16)+"_"+f;return a+"(){"+g+"}"},_param_count:function ge_param_count(){return this.m_param_counts[0]},_set_output_stream:function ge_set_output_stream(c,a){c=this._unsigned2signed(c);if(c==0){}else{if(c==1){this.m_output_to_console=1}else{if(c==2){this.m_memory[17]|=1}else{if(c==3){if(this.m_streamthrees.length>15){gnusto_error(202)}this.m_streamthrees.unshift([a,a+2])}else{if(c==4){this.m_output_to_script=1}else{if(c==-1){this.m_output_to_console=0}else{if(c==-2){this.m_memory[17]&=~1}else{if(c==-3){if(this.m_streamthrees.length<1){gnusto_error(203)}var b=this.m_streamthrees.shift();this.setWord((b[1]-b[0])-2,b[0])}else{if(c==-4){this.m_output_to_script=0}else{gnusto_error(204,c)}}}}}}}}}},_trunc_divide:function ge_trunc_divide(c,b){var a;c=this._unsigned2signed(c);b=this._unsigned2signed(b);if(b==0){gnusto_error(701);return 0}a=c/b;if(a>0){return Math.floor(a)&65535}else{return Math.ceil(a)&65535}},_trunc_modulo:function ge_trunc_modulo(b,a){b=this._unsigned2signed(b);a=this._unsigned2signed(a);if(a==0){gnusto_error(701);return 0}return(b%a)&65535},_zscii_char_to_ascii:function ge_zscii_char_to_ascii(b){if(b<0){gnusto_error(702,b)}var a;if(b==0){return""}else{if(b==10||b==13){return"\n"}else{if((b>=32&&b<=126)||b==0){a=b}else{if(b>=155&&b<=251){if(this.m_unicode_start==0){return String.fromCharCode(default_unicode_translation_table[b])}else{if((b-154)<=this.m_custom_unicode_charcount){return String.fromCharCode(this.getUnsignedWord(this.m_unicode_start+((b-155)*2)))}else{gnusto_error(703,b)}}}else{return"*"}}}}return String.fromCharCode(a)},_ascii_code_to_zscii_code:function ge_ascii_char_to_zscii(b){var c={10:13,13:13,37:131,38:129,39:132,40:130};if(isNaN(b)){if(b.keyCode&&c[b.keyCode]){return c[b.keyCode]}else{var b=b.charCode}}if(b==10||b==13){return 13}if((b>31&&b<127)||b==0){return b}if(b<0){gnusto_error(702,"Illegal unicode character:"+b)}var a=reverse_unicode_table[b];if(!a){a=42}return a},_random_number:function ge_random_number(a){a=this._unsigned2signed(a);if(a==0){this.m_random_use_seed=this.m_random_use_sequence=0;return 0}else{if(a<-999){this.m_random_state=Math.abs(a);this.m_random_use_seed=1;this.m_random_use_sequence=0;return 0}else{if(a<0){this.m_random_sequence_max=Math.abs(a)-1;this.m_random_state=0;this.m_random_use_seed=0;this.m_random_use_sequence=1;return 0}else{if(this.m_random_use_seed){this.m_random_state--;return 1+(Math.round(Math.abs(Math.tan(this.m_random_state))*8.71*a)%a)}else{if(this.m_random_use_sequence){var b=this.m_random_state;this.m_random_state=this.m_random_state+1;if(this.m_random_state>this.m_random_sequence_max){this.m_random_state=0}return 1+(b%a)}else{return 1+Math.round((a-1)*Math.random())}}}}}gnusto_error(170,"random")},_func_gosub:function ge_gosub(h,d,a,f){this.m_call_stack.push(a);this.m_pc=h;var g=this.m_memory[this.m_pc++];if(this.m_version<5){var b=[];for(var e=0;e0;c--){if(c<=d.length){this.m_locals.unshift(d[c-1])}else{this.m_locals.unshift(0)}}}this.m_locals_stack.unshift(g);this.m_param_counts.unshift(d.length);this.m_result_targets.push(f);this.m_gamestack_callbreaks.push(this.m_gamestack.length);if(h==0){this._func_return(0)}},_func_interrupt:function ge_interrupt(b,a){this.m_interrupt_information.push({on_return:a,rebound:this.m_rebound,rebound_args:this.m_rebound_args,engine:this,pc:this.m_pc,effects:this.m_effects});this._func_gosub(b,[],CALLED_FROM_INTERRUPT,-1)},_tokenise:function ge_tokenise(q,h,j,d){var c=0;var e=h+2;var u=h+1;if(isNaN(j)){j=0}if(isNaN(d)){d=0}function l(E,v,x){function w(N,P,i){var L=0;var O,M;while(1){if(L==P.length){return 0}O=N.m_memory[i+L];M=P.charCodeAt(L);if(O==M){L++}else{if(O0){if(D==y){return 0}y=H-1}else{return B}}if(D>y){return 0}}}else{for(var z=0;z=129&&c<=154)||(c>=252)){a+=String.fromCharCode(c)}}}return a}},_func_return:function ge_func_return(b){this.m_locals=this.m_locals.slice(this.m_locals_stack.shift());this.m_param_counts.shift();this.m_pc=this.m_call_stack.pop();this.m_gamestack.length=this.m_gamestack_callbreaks.pop();var c=this.m_result_targets.pop();if(c!=-1&&b!=null){if(c==0){this.m_gamestack.push(b)}else{if(c<16){this.m_locals[c-1]=b}else{this.setWord(b,this.m_vars_start+(c-16)*2)}}}if(this.m_pc==CALLED_FROM_INTERRUPT){var a=this.m_interrupt_information.pop();this.m_pc=a.pc;a.on_return(a,b)}},_throw_stack_frame:function throw_stack_frame(a){if(a>this.m_call_stack.length||a<1){gnusto_error(207,a)}while(this.m_call_stack.length>a-1){this._func_return(null)}},_get_prop_addr:function ge_get_prop_addr(b,c){if(b==0){return 0}var a=this._property_search(b,c,-1);if(a[2]){return a[0]}else{return 0}},_get_prop_len:function ge_get_prop_len(a){if(a==0){return 0}if(this.m_version<4){return 1+(this.m_memory[a-1]>>5)}else{var b=this.m_memory[a-1];if(b&128){b=b&63;if(b==0){return 64}else{return b}}else{if(b&64){return 2}else{return 1}}}},_get_next_prop:function ge_get_next_prop(b,c){if(b==0){return 0}var a=this._property_search(b,-1,c);if(a[2]){return a[3]}else{if(a[4]){return 0}else{gnusto_error(205,c)}}gnusto_error(173)},_get_prop:function ge_get_prop(b,c){if(b==0){return 0}var a=this._property_search(b,c,-1);if(this.m_value_asserts){if(a[0]==null||a[0]===true||a[0]===false||a[0]<0||a[0]>=this.m_stat_start){this.logger("get_prop",a[0])}}if(a[1]==1){return this.m_memory[a[0]]}else{if(a[1]==2){return(this.m_memory[a[0]]<<8)|this.m_memory[a[0]+1]}else{return this.getUnsignedWord(a[0])}}gnusto_error(174)},_property_search:function ge_property_search(b,e,c){var f=this.getUnsignedWord(this.m_property_list_addr_start+b*this.m_object_size);f=f+this.m_memory[f]*2+1;var d=0;while(1){var a=1;var g=this.m_memory[f++];if(this.m_version<4){a=(g>>5)+1;g=g&31}else{if(g&128){a=this.m_memory[f++]&63;if(a==0){a=64}}else{if(g&64){a=2}}g=g&63}if(g==e||d==c){return[f,a,1,g,0]}else{if(g0){return[this.m_objs_start+(e-1)*2,2,0,e,0]}else{return[-1,-1,0,e,d==e]}}}f+=a;d=g}gnusto_error(175)},_set_attr:function ge_set_attr(b,d){if(b==0){return}var a=this.m_object_tree_start+b*this.m_object_size+(d>>3);var c=this.m_memory[a];this.setByte(c|(128>>(d%8)),a)},_clear_attr:function ge_clear_attr(b,d){if(b==0){return}var a=this.m_object_tree_start+b*this.m_object_size+(d>>3);var c=this.m_memory[a];this.setByte(c&~(128>>(d%8)),a)},_test_attr:function ge_test_attr(a,b){if(a==0){return 0}if((this.m_memory[this.m_object_tree_start+a*this.m_object_size+(b>>3)]&(128>>(b%8)))){return 1}else{return 0}},_put_prop:function put_prop(b,d,c){if(b==0){return}var a=this._property_search(b,d,-1);if(!a[2]){gnusto_error(704)}if(a[1]==1){this.setByte(c,a[0])}else{if(a[1]==2){this.setWord(c,a[0])}else{gnusto_error(705)}}},_get_older_sibling:function ge_get_older_sibling(a){if(a==0){return 0}var b=this._get_child(this._get_parent(a));if(a==b){return 0}while(b){var c=this._get_sibling(b);if(c==a){return b}b=c}return 0},_insert_obj:function ge_insert_obj(a,d){var e=this._get_parent(a);var b=this._get_older_sibling(a);var c=this._get_sibling(a);if(e&&this._get_child(e)==a){this._set_child(e,c)}if(b){this._set_sibling(b,c)}this._set_parent(a,d);if(d){this._set_sibling(a,this._get_child(d));this._set_child(d,a)}},_remove_obj:function ge_remove_obj(a,b){this._insert_obj(a,0)},_get_family:function ge_get_family(b,a){if(b==0){return 0}if(this.m_version<4){return this.m_memory[this.m_object_tree_start+4+a+b*this.m_object_size]}else{return this.getUnsignedWord(this.m_object_tree_start+6+a*2+b*this.m_object_size)}gnusto_error(170,"get_family")},_get_parent:function ge_get_parent(a){return this._get_family(a,PARENT_REC)},_get_child:function ge_get_child(a){return this._get_family(a,CHILD_REC)},_get_sibling:function ge_get_sibling(a){return this._get_family(a,SIBLING_REC)},_set_family:function ge_set_family(c,b,a){if(this.m_version<4){this.setByte(b,this.m_object_tree_start+4+a+c*this.m_object_size)}else{this.setWord(b,this.m_object_tree_start+6+a*2+c*this.m_object_size)}},_set_parent:function ge_set_parent(b,a){this._set_family(b,a,PARENT_REC)},_set_child:function ge_set_child(b,a){this._set_family(b,a,CHILD_REC)},_set_sibling:function ge_set_sibling(b,a){this._set_family(b,a,SIBLING_REC)},_obj_in:function ge_obj_in(b,a){return this._get_parent(b)==a},_copy_table:function ge_copy_table(e,a,c){c=this._unsigned2signed(c);if(a==0){for(var b=0;ba){d=1}else{d=0}}if(d){for(var b=0;b=0;b--){this.setByte(this.m_memory[e+b],a+b)}}}},_scan_table:function ge_scan_table(g,a,f,d){var e=d&127;var b=((d&128)==128);var c=a+(f*e);if(b){while(a>8)&255))&&((this.m_memory[65535&a+1]&255)==(g&255))){return a}a+=e}}else{while(a=0;e--){var b=((a>>(e*5))&31);if(i){n=n+this._zscii_from(this.getUnsignedWord((32*(i-1)+b)*2+this.m_abbr_start)*2);i=0;h=f}else{if(k==-2){if(b>5){if(h==2&&b==6){k=-1}else{n=n+this.m_zalphabet[h].charAt(b-6);h=f}}else{if(b==0){n=n+" ";h=f}else{if(b<4){if(this.getByte(0)>2){i=b}else{if(b==2){h+=1;if(h>2){h=0}}else{if(b==3){h-=1;if(h<0){h=2}}else{if(this.getByte(0)==2){i=1}else{n=n+"\n";h=f}}}}}else{if(this.getByte(0)>2){h=b-3}else{if(b==4){f+=1;if(f>2){f=0}}else{f-=1;if(f<0){f=2}}h=f}}}}}else{if(k==-1){k=b}else{n=n+this._zscii_char_to_ascii((k<<5)+b);k=-2;h=f}}}}}if(o>=this.m_stat_start){this.m_jit[o]=[n,l]}if(d){return[n,l]}else{return n}},_encode_text:function ge_encode_text(k,d,j,h){k=(k+j)&65535;var a="";while(d>0){var g=this.m_memory[k];if(g==0){break}a=a+String.fromCharCode(g);k++;d--}var l=this._into_zscii(a);for(var e=0;e>8)+String.fromCharCode(k&255);d=[]}}var a,i=0,c;while(i=65&&a<=90){a+=32}else{if(a>154){if(this.m_unicode_start==0){if((a>=158&&a<=160)||(a>=167&&a<=168)||(a>=208&&a<=210)){a-=3}else{if(a>=175&&a<=180){a-=6}else{if((a>=186&&a<=190)||(a>=196&&a<=200)){a-=5}else{if(a==217||a==218){a-=2}else{if(a==202||a==204||a==212||a==214||a==221){a-=1}}}}}}else{var g=this._ascii_code_to_zscii_code(this._zscii_char_to_ascii(a).toLowerCase().charCodeAt(0));if(g>0&&g<=251&&g!="*".charCodeAt(0)){a=g}}}}var b=String.fromCharCode(this._zscii_char_to_ascii(a).charCodeAt(0));c=this.m_zalphabet[0].indexOf(b);if(c!=-1){h(c+6)}else{c=this.m_zalphabet[1].indexOf(b);if(c!=-1){if(this.getByte(0)>2){h(4)}else{h(2)}h(c+6)}else{c=this.m_zalphabet[2].indexOf(b);if(c!=-1){if(this.getByte(0)>2){h(5)}else{h(3)}h(c+6)}else{if(this.getByte(0)>2){h(5)}else{h(3)}h(6);h(a>>5);h(a&31)}}}}while(j.length"}else{var b=this.m_property_list_addr_start+a*this.m_object_size;return this._zscii_from(this.getUnsignedWord(b)+1)}},_print_leftovers:function ge_print_leftovers(){this._zOut(this.m_leftovers);this.m_leftovers=""},_zOut:function ge_zOut(f){if(this.m_streamthrees.length){var d=this.m_streamthrees[0];var a=this.m_streamthrees[0][1];for(var b=0;b>>(65536-a))&65535}else{return(b<>(65536-a))&65535}else{return(b<>5)*8.226)<<8|Math.round(((e&31744)>>10)*8.226);f=f.toString(16);while(f.length<6){f="0"+f}return"#"+f};return Object.subClass({colours:b,init:function(e,f){this.e=e;this.buffer="";this.styles={};this.mono=f;this.currentwin=0;this.status=[];e.orders.push({code:"stream",name:"status"},{code:"stream",name:"main"},{code:"find",name:"main"})},clear_window:function(){this.e.orders.push({code:"clear",name:"main",css:d({},this.styles)})},convert_RGB:function(e){return Math.round(e[2]/8.226)<<10|Math.round(e[1]/8.226)<<5|Math.round(e[0]/8.226)},erase_line:function(e){if(e==1){this.flush();this.status.push({code:"eraseline"})}},erase_window:function(e){this.flush();if(e<1){this.clear_window()}if(e==-1){this.split_window(0)}if(e==-2||e==1){this.status.push({code:"clear"})}},flush:function(){var e;if(this.buffer!=""){e={code:"stream",css:d({},this.styles),text:this.buffer};if(this.mono){e.node="tt"}(this.currentwin?this.status:this.e.orders).push(e);this.buffer=""}},get_cursor:function(e){this.status.push({code:"get_cursor",addr:e});this.e.act()},set_colour:function(f,e){this.set_true_colour(b[f],b[e])},set_cursor:function(f,e){this.flush();this.status.push({code:"cursor",to:[f-1,e-1]})},set_font:function(e){if(e!=1&&e!=4){return 0}var f=this.mono&4?4:1;if(e!=f){this.flush();this.mono^=4}return f},set_style:function(e){var f=this.styles;this.flush();if(e==0){f.reverse=f["font-weight"]=f["font-style"]=c;this.mono&=254}if(e&1){f.reverse=1}if(e&2){f["font-weight"]="bold"}if(e&4){f["font-style"]="italic"}if(e&8){this.mono|=1}},set_true_colour:function(h,f){var g=this.styles,i=g.color,e=g["background-color"];this.flush();if(h==65535){i=c}else{if(h<32768){i=a(h)}}if(f==65535){e=c}else{if(f<32768){e=a(f)}}g.color=i;g["background-color"]=e},set_window:function(e){this.flush();this.currentwin=e;this.e.orders.push({code:"find",name:e?"status":"main"});if(e){this.status.push({code:"cursor",to:[0,0]})}},split_window:function(e){this.flush();this.status.push({code:"height",lines:e})}})})();var GnustoRunner=Object.subClass({init:function(c,b){var a=this;b=window.engine=this.e=new GnustoEngine(window.console&&function(){console.log(msg)}||function(){});this.io=new StructIO(c);this.io.TextInput.callback=function(d){a.inputEvent(d)}},fromParchment:function(c){var b=c.code,a=this.e,d;if(b=="load"){a.loadStory(c.data)}if(b=="restart"){this.restart();d=1}if(b=="save"){a.answer(0,c.result||1);d=1}if(b=="restore"){if(!this.ui){this.restart()}if(c.data){a.loadSavedGame(c.data)}else{a.answer(0,0)}d=1}if(d){this.run()}},restart:function(){var a=this.e,b=this.io;a.setByte(255,32);a.setByte(b.env.width,33);a.setWord(b.env.width,34);a.setWord(255,36);b.target=b.container.empty();this.orders=[];this.ui=new ZVMUI(this,a.getByte(17)&2);b.event(this.orders);this.orders=[]},run:function(){var e=this.e,g=this.ui,h,d,f,c,b,a;this.orders=[];while(!b){e.run();h=e.consoleText();if(h){g.buffer+=h}d='"'+e.effect(0)+'"';f=e.effect(1);c=e.effect(2);if(d==GNUSTO_EFFECT_INPUT){b=1;g.flush();this.orders.push({code:"read",target:this.currentwin})}if(d==GNUSTO_EFFECT_INPUT_CHAR){b=1;this.orders.push({code:"char"})}if(d==GNUSTO_EFFECT_SAVE){b=1;e.saveGame();this.toParchment({code:"save",data:e.saveGameData()})}if(d==GNUSTO_EFFECT_RESTORE){b=1;this.toParchment({code:"restore"})}if(d==GNUSTO_EFFECT_QUIT){b=1}if(d==GNUSTO_EFFECT_RESTART){e.resetStory();this.restart();g=this.ui}if(d==GNUSTO_EFFECT_FLAGS_CHANGED){g.flush();g.mono=(g.mono&253)|e.m_printing_header_bits&2}if(d==GNUSTO_EFFECT_STYLE){if(f<0){g.set_colour(c,e.effect(3))}else{g.set_style(f)}}if(d==GNUSTO_EFFECT_SPLITWINDOW){g.split_window(f)}if(d==GNUSTO_EFFECT_SETWINDOW){g.set_window(f)}if(d==GNUSTO_EFFECT_ERASEWINDOW){g.erase_window(f)}if(d==GNUSTO_EFFECT_ERASELINE){g.erase_line(f)}if(d==GNUSTO_EFFECT_SETCURSOR){g.set_cursor(f,c)}if(d==GNUSTO_EFFECT_GETCURSOR){b=1;g.get_cursor(f)}if(d==GNUSTO_EFFECT_PRINTTABLE){for(a=0;a