text: 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;c<b.length;c++){if(c!=1){e=e+"||"}e=e+"t=="+b[c]}return"t="+b[0]+";"+d._brancher(e)}}}function handleZ_jl(d,b){var e,c;if(isNotConst.test(b[0])){e="t="+b[0]+";t=((t & 0x8000 ? ~0xFFFF : 0) | t);"}else{e="t="+d._unsigned2signed(b[0])+";"}if(isNotConst.test(b[1])){c="t2="+b[1]+";t2=((t2 & 0x8000 ? ~0xFFFF : 0) | t2);"}else{c="t2="+d._unsigned2signed(b[1])+";"}return e+c+d._brancher("t<t2")}function handleZ_jg(d,b){var e,c;if(isNotConst.test(b[0])){e="t="+b[0]+";t=((t & 0x8000 ? ~0xFFFF : 0) | t);"}else{e="t="+d._unsigned2signed(b[0])+";"}if(isNotConst.test(b[1])){c="t2="+b[1]+";t2=((t2 & 0x8000 ? ~0xFFFF : 0) | t2);"}else{c="t2="+d._unsigned2signed(b[1])+";"}return e+c+d._brancher("t>t2")}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<arguments.length;a++){if(arguments[a]&&arguments[a].toString){message+="\nDetail: "+arguments[a].toString()}}throw new FatalError(message)}function onISRReturn_for_read_char(b,a){if(a){b.engine.m_answers[0]=0;b.rebound()}else{b.engine.m_effects=b.effects;b.engine.m_rebound=b.rebound;b.engine.m_rebound_args=b.rebound_args}}function onISRReturn_for_read(b,a){var c=b.engine;if(a){c.m_answers[0]=0;c.m_answers[1]="";b.rebound()}else{c.m_effects=b.effects;c.m_rebound=b.rebound;c.m_rebound_args=b.rebound_args}}function GnustoEngine(a){if(a){this.logger=function(d,c){a("gnusto-engine: "+d+": "+c)}}else{this.logger=function(){}}}GnustoEngine.prototype={loadStory:function ge_loadStory(a){this.m_memory=a;this._initial_setup()},loadSavedGame:function ge_loadSavedGame(savefile){var quetzal=new Quetzal(savefile);var mem=quetzal.memory;var stacks=quetzal.stacks;var pc=quetzal.pc;function decodeStackInt(offset,length){var result=stacks[offset++];for(var i=1;i<length;i++){result=(result<<8)|stacks[offset++]}return result}if(quetzal.compressed){var temp=[];var cursor_compressed=0;var cursor_original=0;while(cursor_compressed<mem.length){if(cursor_original>=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;m<evals_count;m++){this.m_gamestack.push(decodeStackInt(cursor,2));cursor+=2}while(cursor<stacks.length){this.m_call_stack.push(decodeStackInt(cursor,3));cursor+=3;var flags=stacks[cursor++];var varcode=stacks[cursor++];if(flags&16){varcode=-1}var locals_count=flags&15;this.m_locals_stack.unshift(locals_count);this.m_result_targets.push(varcode);var logArgs=stacks[cursor++]+1;var argCount=0;while(logArgs>1){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<locals_count;k++){locals_temp.push(decodeStackInt(cursor,2));cursor+=2}this.m_locals=locals_temp.concat(this.m_locals);for(var m=0;m<evals_count;m++){this.m_gamestack.push(decodeStackInt(cursor,2));cursor+=2}}for(var n=0;n<16;n++){this.m_locals.push(0)}this.m_memory=mem.concat(this.m_memory.slice(mem.length));var offset=(this.m_version<=4?1:3)+1;this.m_pc=pc-offset;if(this.m_version<=3){eval("var t=new Function('with(this){'+this._brancher('1')+'}');t.call(this);")}else{this._varcode_set(2,this.m_memory[this.m_pc++])}},resetStory:function ge_resetStory(){this.m_memory=this.m_original_memory.slice();this._initial_setup()},version:function ge_version(){gnusto_error(101,"'version' not implemented")},signature:function ge_signature(){gnusto_error(101,"'signature' not implemented")},cvsVersion:function ge_cvsVersion(){return CVS_VERSION.substring(7,26)},setGoldenTrail:function ge_setGoldenTrail(a){if(a){this.m_goldenTrail=1}else{this.m_goldenTrail=0}},setCopperTrail:function ge_setCopperTrail(a){if(a){this.m_copperTrail=1}else{this.m_copperTrail=0}},effect:function ge_effect(a){return this.m_effects[a]},answer:function ge_answer(b,a){this.m_answers[b]=a},run:function ge_run(){var start_pc=0;var turns=0;var jscode;var turns_limit=this.m_single_step?1:10000;if(this.m_rebound){this.m_rebound();this.m_rebound=0;this.m_rebound_args=[]}this.m_effects=[];while(this.m_effects.length==0){if(turns++>=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<k;m++){j[(k-m)-1]=s&255;s>>=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<l;r++){if(c.m_memory[r]==this.m_original_memory[r]){h++;if(h==256){g.push(0);g.push(255);h=0}}else{if(h!=0){g.push(0);g.push(h-1);h=0}g.push(c.m_memory[r]^this.m_original_memory[r])}}if(h!=0){g.push(0);g.push(h-1)}f.memory=g;u=u.concat(b(this.m_gamestack_callbreaks[0],2));for(var o=0;o<this.m_gamestack_callbreaks[0];o++){u=u.concat(b(this.m_gamestack[a++],2))}for(var q=0;q<this.m_call_stack.length;q++){u=u.concat(b(this.m_call_stack[q],3));var n=this.m_locals_stack[this.m_locals_stack.length-(q+1)],d=n,x=this.m_result_targets[q],v=this.m_param_counts[this.m_param_counts.length-(q+1)],e=this.m_gamestack_callbreaks[q]-a;if(x==-1){x=0;d|=16}u=u.concat([d,x,(1<<v)-1,(e>>8)&255,e&255]);w-=n;for(var p=0;p<n;p++){u=u.concat(b(this.m_locals[w+p],2))}for(var o=0;o<e;o++){u=u.concat(b(this.m_gamestack[a++],2))}}f.stacks=u;this.m_quetzal_image=f.write();return this.m_quetzal_image.length},saveGameData:function ge_saveGameData(b,a){var c=this.m_quetzal_image;this.m_quetzal_image=0;return c},architecture:function ge_architecture(){return"none"},piracy:function ge_piracy(){return -1},tandy:function ge_tandy(){return -1},status:function ge_status(){return"this is the status, hurrah!"},getStatusLine:function ge_getStatusLine(d){var g=this.getUnsignedWord(this.m_vars_start);var f=this.getUnsignedWord(this.m_property_list_addr_start+(this.m_object_size*g));var b=this._zscii_from(f+1);if(b.length>d){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)<d){h+=" "}}return b+h+e},gestalt:function(b,a){if(b==1){return 258}if(b==32){if(a==0||a==1&&PARCHMENT_SECURITY_OVERRIDE){return 1}}return 0},op_parchment:function(id,arg){var self=this;if(id==1&&PARCHMENT_SECURITY_OVERRIDE){if(arg==1){self.op_parchment_data.saved_buffer=self.m_console_buffer;self.m_console_buffer="";self.op_parchment_data.raw_eval=1}else{if(self.op_parchment_data.raw_eval){eval(self.m_console_buffer);self.m_console_buffer=self.op_parchment_data.saved_buffer}self.op_parchment_data.raw_eval=0}return 1}return 0},_initial_setup:function ge_initial_setup(){this.m_jit=[];this.m_compilation_running=0;this.m_gamestack=[];this.m_gamestack_callbreaks=[];this.m_call_stack=[];this.m_locals=[];this.m_locals_stack=[];this.m_param_counts=[];this.m_result_targets=[];this.m_goldenTrail=0;this.m_copperTrail=0;this.m_version=this.m_memory[0];this.m_original_memory=this.m_memory.slice();this.m_himem=this.getUnsignedWord(4);this.m_pc=this.getUnsignedWord(6);this.m_dict_start=this.getUnsignedWord(8);this.m_objs_start=this.getUnsignedWord(10);this.m_vars_start=this.getUnsignedWord(12);this.m_stat_start=this.getUnsignedWord(14);this.m_abbr_start=this.getUnsignedWord(24);if(this.m_version>=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;h<this.m_separator_count;h++){this.m_separators[h]=this._zscii_char_to_ascii(this.m_memory[this.m_dict_start+h+1])}if(this.m_hext_start>0){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;h<this.m_custom_unicode_charcount;h++){reverse_unicode_table[this.getUnsignedWord(this.m_unicode_start+(h*2))]=h+155}}}if(!(this.m_unicode_start>0)){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;e<g;e++){if(e<d.length){b.push(d[e])}else{b.push(this.getUnsignedWord(this.m_pc))}this.m_pc+=2}this.m_locals=b.concat(this.m_locals)}else{for(var c=g;c>0;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(O<M){return -1}else{return 1}}}}var C=E.m_memory[x+E.m_separator_count+1];var I=E.getWord(x+E.m_separator_count+2);var A=E.m_dict_start+E.m_separator_count+4;var J=1;if(I<0){J=0;I=-I}var F=v;v=E._into_zscii(v);if(J){var D=0,y=I-1;var H;var B;var K;while(1){H=D+Math.round((y-D)/2);B=A+H*C;K=w(E,v,B);if(K<0){if(D==y){return 0}D=H+1}else{if(K>0){if(D==y){return 0}y=H-1}else{return B}}if(D>y){return 0}}}else{for(var z=0;z<I;z++){var G=A+z*C;if(w(E,v,G)==0){return G}}}return 0}function s(w,y,x,v){var i=l(w,x,y);if(!(d&&i==0)){w.setWord(i,e);e+=2;w.setByte(x.length,e++);w.setByte(v,e++)}else{e+=4}c++;return 1}var f=this.m_memory[q];var o="";if(j==0){j=this.m_dict_start}if(this.m_version<=4){f++;var r=q+1;while(1){var k=this.m_memory[r++];if(k==0){break}o+=String.fromCharCode(k)}}else{for(var p=0;p<this.m_memory[q+1];p++){o+=String.fromCharCode(this.m_memory[q+2+p])}}var m=[];var n="";var g=0;var b;if(this.m_version<=4){b=1}else{b=2}for(var a=0;a<o.length;a++){if(o.charAt(a)==" "){if(n!=""){m[g]=n;s(this,j,m[g],(a-m[g].length)+b);g++;n=""}}else{if(this._is_separator(o.charAt(a))){if(n!=""){m[g]=n;s(this,j,m[g],(a-m[g].length)+b);g++}m[g]=o.charAt(a);s(this,j,m[g],a+b);g++;n=""}else{n+=o.charAt(a)}}}if(n!=""){m[g]=n;s(this,j,m[g],(a-m[g].length)+b)}this.setByte(c,u)},_aread:function ge_aread(g,e,c,d){e&=65535;c&=65535;var f;var a;var h;if(this.m_version<=4){f=this.m_memory[e]+1;a=d.substring(0,f).toLowerCase();h=e+1;this.setByte(0,e+1+a.length)}else{f=this.m_memory[e];a=d.substring(0,f).toLowerCase();h=e+2;this.setByte(a.length,e+1)}for(var b=0;b<a.length;b++){this.setByte(this._ascii_code_to_zscii_code(a.charCodeAt(b)),h+b)}if(c!=0||this.m_version<5){this._tokenise(e,c,0,0)}if(g==13){return 10}else{return g}},_terminating_characters:function ge_terminating_characters(){if(this.m_version<5){return"\r"}else{var b=this.getUnsignedWord(46);var a="\r";while(1){var c=this.m_memory[b++];if(c==0){break}else{if((c>=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(g<e){if(e>0){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;b<c;b++){this.setByte(0,b+e)}}else{var d=0;if(c<0){c=-c;d=1}else{if(e>a){d=1}else{d=0}}if(d){for(var b=0;b<c;b++){this.setByte(this.m_memory[e+b],a+b)}}else{for(var b=c-1;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<c){if(((this.m_memory[65535&a]&255)==((g>>8)&255))&&((this.m_memory[65535&a+1]&255)==(g&255))){return a}a+=e}}else{while(a<c){if((this.m_memory[65535&a]&255)==(g&65535)){return a}a+=e}}return 0},_print_table:function ge_print_table(d,a,f,e){var i=[];for(var b=0;b<f;b++){var h="";for(var c=0;c<a;c++){if(d<0){d&=65535}h=h+this._zscii_char_to_ascii(this.m_memory[d++])}i.push(h);d+=e}var g=["PT",i.length];g=g.concat(i);return g},_zscii_from:function ge_zscii_from(l,m,d){if(l in this.m_jit){if(d){return this.m_jit[l]}else{return this.m_jit[l][0]}}var n="";var g=1;var o=l;var f=0;var h=f;var k=-2;var i=0;if(!m){m=65535}var c=l+m;while(g){var a=this.getUnsignedWord(l);l+=2;g=((a&32768)==0)&&l<c;for(var e=2;e>=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<l.length;e++){var f=l[e].charCodeAt(0);this.setByte(f,h++)}},_into_zscii:function ge_into_zscii(f){var j="";var d=[];var e;if(this.m_version<4){e=4}else{e=6}function h(l){d.push(l);if(d.length==3){var k=(d[0]<<10|d[1]<<5|d[2]);if(j.length==e-2){k|=32768}j=j+String.fromCharCode(k>>8)+String.fromCharCode(k&255);d=[]}}var a,i=0,c;while(i<f.length&&j.length<e){a=f.charCodeAt(i++);if(a>=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<e){h(5)}return j.substring(0,e)},_name_of_object:function ge_name_of_object(a){if(a==0){return"<void>"}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<f.length;b++){this.setByte(this._ascii_code_to_zscii_code(f.charCodeAt(b)),a++)}this.m_streamthrees[0][1]=a}else{var c=this.m_memory[17]&3;var e=c!=this.m_printing_header_bits;this.m_printing_header_bits=c;if(e){this.m_leftovers=f;this.m_rebound=this._print_leftovers;return 1}else{if(this.m_output_to_console){this.m_console_buffer=this.m_console_buffer+f}if(c&1){this.m_transcript_buffer=this.m_transcript_buffer+f}}}return 0},consoleText:function ge_console_text(){var b=this,a=b.m_console_buffer.replace("\x00","","g");if(b.op_parchment_data.raw_eval){return""}else{b.m_console_buffer="";return a}},_transcript_text:function ge_transcript_text(){var a=this.m_transcript_buffer.replace("\x00","","g");this.m_transcript_buffer="";return a},_is_separator:function ge_IsSeparator(b){for(var a=0;a<this.m_separator_count;a++){if(b==this.m_separators[a]){return 1}}return 0},_code_for_varcode:function ge_code_for_varcode(c){var e="",b;if(c==0){e="var tmp_"+(++temp_var)+" = m_gamestack.pop();";b="tmp_"+temp_var}else{if(c<16){b="m_locals["+(c-1)+"]"}else{var f=this.m_vars_start+(c-16)*2,a=f+1;var d="tmp_"+(++temp_var);e="var "+d+" = (m_memory["+f+"] << 8) | m_memory["+a+"];";b=d}}return[e,b]},_varcode_set:function ge_varcode_set(b,a){if(a==0){this.m_gamestack.push(b)}else{if(a<16){this.m_locals[a-1]=b}else{this.setWord(b,this.m_vars_start+(a-16)*2)}}},_brancher:function ge_brancher(e){var b=1;var a=this.m_memory[this.m_pc++];var c=a&63;if(a&128){b=0}if(!(a&64)){c=(c<<8)|this.m_memory[this.m_pc++];if(c&8192){c=(~8191)|(c&8191)}}var d=e;if(b){d="if(!("+d+"))"}else{d="if("+d+")"}if(c==0){return d+"{_func_return(0);return;}"}if(c==1){return d+"{_func_return(1);return;}"}c=(this.m_pc+c)-2;return d+"{m_pc="+(c)+";return;}"},_storer:function ge_storer(b){var a=this.m_memory[this.m_pc++];if(b.substring&&b.substring(0,11)=="_func_gosub"){this.m_compilation_running=0;if(b.substring(b.length-4)!=",-1)"){gnusto_error(100,b)}return b.substring(0,b.length-3)+a+")"}else{if(a==0){return"m_gamestack.push("+b+")"}else{if(a<16){return"m_locals["+(a-1)+"]="+b}else{return"setWord("+b+","+(this.m_vars_start+(a-16)*2)+")"}}}gnusto_error(170,"storer")},_generate_gosub:function call_vn(d,c,b){this.m_compilation_running=0;var a=-1;if(b){a=this.m_memory[this.m_pc++]}return"_func_gosub("+this.m_pc_translate_for_routine(d)+",["+c.toString()+"],"+this.m_pc+","+a+")"},_handler_zOut:function ge_handler_zOut(b,a){var c;if(a){c="_func_return(1)"}else{c="m_pc=0x"+this.m_pc.toString(16)}return"if(_zOut("+b+")){"+c+";m_effects=["+GNUSTO_EFFECT_FLAGS_CHANGED+"];return 1}"},_handler_print:function ge_handler_print(c,a){var d=this._zscii_from(this.m_pc,65535,1);var b=d[0];if(c){b=b+c}b=b.quote();this.m_pc=d[1];return this._handler_zOut(b,a)},_log_shift:function ge_log_shift(b,a){if(a&32768){return(b>>>(65536-a))&65535}else{return(b<<a)&65535}},_art_shift:function ge_art_shift(b,a){b=this._unsigned2signed(b);if(a&32768){return(b>>(65536-a))&65535}else{return(b<<a)&65535}},_touch:function ge_touch(a){if(this.m_goldenTrail){this.logger("pc",a.toString(16))}this.m_pc=a},_save_undo:function ge_save_undo(a){this.m_undo.push({m_call_stack:this.m_call_stack.slice(),m_locals:this.m_locals.slice(),m_locals_stack:this.m_locals_stack.slice(),m_param_counts:this.m_param_counts.slice(),m_result_targets:this.m_result_targets.slice(),m_gamestack:this.m_gamestack.slice(),m_gamestack_callbreaks:this.m_gamestack_callbreaks.slice(),m_memory:this.m_memory.slice(0,this.m_stat_start),m_resultvar:this.m_memory[a],m_pc:a+1});return 1},_restore_undo:function ge_restore_undo(){if(this.m_undo.length==0){return 0}var a=this.m_undo.pop();this.m_call_stack=a.m_call_stack;this.m_locals=a.m_locals;this.m_locals_stack=a.m_locals_stack;this.m_param_counts=a.m_param_counts;this.m_result_targets=a.m_result_targets;this.m_gamestack=a.m_gamestack;this.m_gamestack_callbreaks=a.m_gamestack_callbreaks;var b=a.m_memory;this.m_memory=b.concat(this.m_memory.slice(b.length));this._varcode_set(2,a.m_resultvar);this.m_pc=a.m_pc;return 1},_saveable_state:function ge_saveable_state(b){var a={m_memory:this.m_memory.slice(0,this.m_stat_start),m_pc:this.m_pc+b,m_call_stack:this.m_call_stack.slice(),m_locals:this.m_locals.slice(),m_locals_stack:this.m_locals_stack.slice(),m_param_counts:this.m_param_counts.slice(),m_result_targets:this.m_result_targets.slice(),m_gamestack:this.m_gamestack.slice(),m_gamestack_callbreaks:this.m_gamestack_callbreaks.slice()};return a},_verify:function ge_verify(){var c=0;var b=(this.m_original_memory[28]<<8|this.m_original_memory[29]);for(var a=64;a<this.m_original_memory.length;a++){c+=this.m_original_memory[a]}return(c&65535)==b},m_local_game_file:0,m_memory:[],m_handlers:0,m_jit:[],m_goldenTrail:0,m_copperTrail:0,m_compilation_running:0,m_gamestack:0,m_gamestack_callbreaks:[],m_himem:0,m_pc:0,m_dict_start:0,m_objs_start:0,m_vars_start:0,m_stat_start:0,m_abbr_start:0,m_hext_start:0,m_alpha_start:0,m_zalphabet:[],m_string_start:0,m_routine_start:0,m_unicode_start:0,m_custom_unicode_charcount:0,m_separator_count:0,m_separators:[],m_version:0,m_call_stack:[],m_locals:[],m_locals_stack:0,m_param_counts:0,m_result_targets:[],m_rebound:0,m_rebound_args:[],m_output_to_console:0,m_streamthrees:[],m_output_to_script:0,m_single_step:0,m_debug_mode:0,m_parser_debugging:0,m_value_asserts:0,m_breakpoints:{},m_console_buffer:"",m_transcript_buffer:"",m_effects:[],m_answers:[],m_random_state:0,m_random_use_seed:0,m_random_use_sequence:0,m_random_sequence_max:0,m_printing_header_bits:0,m_leftovers:"",m_pc_translate_for_routine:pc_translate_v45,m_pc_translate_for_string:pc_translate_v45,m_undo:[],m_state_to_save:0,m_quetzal_image:0,m_original_memory:[],m_object_tree_start:0,m_property_list_addr_start:0,m_object_size:14,m_interrupt_information:[],op_parchment_data:{}};