private static void outchar(string_type st, zword c) { if (st == string_type.VOCABULARY) { decoded[ptrDt++] = c; } else { Buffer.print_char(c); } }
static void decode_text(string_type st, zword addr) { // zword* ptr; long byte_addr; zword c2; zword code; zbyte c, prev_c = 0; int shift_state = 0; int shift_lock = 0; int status = 0; // ptr = NULL; /* makes compilers shut up */ byte_addr = 0; if (resolution == 0) { find_resolution(); } /* Calculate the byte address if necessary */ if (st == string_type.ABBREVIATION) { byte_addr = (long)addr << 1; } else if (st == string_type.HIGH_STRING) { if (main.h_version <= ZMachine.V3) { byte_addr = (long)addr << 1; } else if (main.h_version <= ZMachine.V5) { byte_addr = (long)addr << 2; } else if (main.h_version <= ZMachine.V7) { byte_addr = ((long)addr << 2) + ((long)main.h_strings_offset << 3); } else /* (h_version <= V8) */ { byte_addr = (long)addr << 3; } if (byte_addr >= main.story_size) { Err.runtime_error(ErrorCodes.ERR_ILL_PRINT_ADDR); } } /* Loop until a 16bit word has the highest bit set */ if (st == string_type.VOCABULARY) { ptrDt = 0; } do { int i; /* Fetch the next 16bit word */ if (st == string_type.LOW_STRING || st == string_type.VOCABULARY) { FastMem.LOW_WORD(addr, out code); addr += 2; } else if (st == string_type.HIGH_STRING || st == string_type.ABBREVIATION) { FastMem.HIGH_WORD(byte_addr, out code); byte_addr += 2; } else { FastMem.CODE_WORD(out code); } /* Read its three Z-characters */ for (i = 10; i >= 0; i -= 5) { zword abbr_addr; zword ptr_addr; zword zc; c = (zbyte)((code >> i) & 0x1f); switch (status) { case 0: /* normal operation */ if (shift_state == 2 && c == 6) { status = 2; } else if (main.h_version == ZMachine.V1 && c == 1) { Buffer.new_line(); } else if (main.h_version >= ZMachine.V2 && shift_state == 2 && c == 7) { Buffer.new_line(); } else if (c >= 6) { outchar(st, alphabet(shift_state, c - 6)); } else if (c == 0) { outchar(st, ' '); } else if (main.h_version >= ZMachine.V2 && c == 1) { status = 1; } else if (main.h_version >= ZMachine.V3 && c <= 3) { status = 1; } else { shift_state = (shift_lock + (c & 1) + 1) % 3; if (main.h_version <= ZMachine.V2 && c >= 4) { shift_lock = shift_state; } break; } shift_state = shift_lock; break; case 1: /* abbreviation */ ptr_addr = (zword)(main.h_abbreviations + 64 * (prev_c - 1) + 2 * c); FastMem.LOW_WORD(ptr_addr, out abbr_addr); decode_text(string_type.ABBREVIATION, abbr_addr); status = 0; break; case 2: /* ZSCII character - first part */ status = 3; break; case 3: /* ZSCII character - second part */ zc = (zword)((prev_c << 5) | c); c2 = translate_from_zscii((zbyte)zc); // TODO This doesn't seem right outchar(st, c2); status = 0; break; } prev_c = c; } } while (!((code & 0x8000) > 0)); if (st == string_type.VOCABULARY) { ptrDt = 0; } }/* decode_text */
static void decode_text(string_type st, zword addr) { // zword* ptr; long byte_addr; zword c2; zword code; zbyte c, prev_c = 0; int shift_state = 0; int shift_lock = 0; int status = 0; // ptr = NULL; /* makes compilers shut up */ byte_addr = 0; if (resolution == 0) find_resolution(); /* Calculate the byte address if necessary */ if (st == string_type.ABBREVIATION) byte_addr = (long)addr << 1; else if (st == string_type.HIGH_STRING) { if (main.h_version <= ZMachine.V3) byte_addr = (long)addr << 1; else if (main.h_version <= ZMachine.V5) byte_addr = (long)addr << 2; else if (main.h_version <= ZMachine.V7) byte_addr = ((long)addr << 2) + ((long)main.h_strings_offset << 3); else /* (h_version <= V8) */ byte_addr = (long)addr << 3; if (byte_addr >= main.story_size) Err.runtime_error(ErrorCodes.ERR_ILL_PRINT_ADDR); } /* Loop until a 16bit word has the highest bit set */ if (st == string_type.VOCABULARY) ptrDt = 0; do { int i; /* Fetch the next 16bit word */ if (st == string_type.LOW_STRING || st == string_type.VOCABULARY) { FastMem.LOW_WORD(addr, out code); addr += 2; } else if (st == string_type.HIGH_STRING || st == string_type.ABBREVIATION) { FastMem.HIGH_WORD(byte_addr, out code); byte_addr += 2; } else FastMem.CODE_WORD(out code); /* Read its three Z-characters */ for (i = 10; i >= 0; i -= 5) { zword abbr_addr; zword ptr_addr; zword zc; c = (zbyte)((code >> i) & 0x1f); switch (status) { case 0: /* normal operation */ if (shift_state == 2 && c == 6) status = 2; else if (main.h_version == ZMachine.V1 && c == 1) Buffer.new_line(); else if (main.h_version >= ZMachine.V2 && shift_state == 2 && c == 7) Buffer.new_line(); else if (c >= 6) outchar(st, alphabet(shift_state, c - 6)); else if (c == 0) outchar(st, ' '); else if (main.h_version >= ZMachine.V2 && c == 1) status = 1; else if (main.h_version >= ZMachine.V3 && c <= 3) status = 1; else { shift_state = (shift_lock + (c & 1) + 1) % 3; if (main.h_version <= ZMachine.V2 && c >= 4) shift_lock = shift_state; break; } shift_state = shift_lock; break; case 1: /* abbreviation */ ptr_addr = (zword)(main.h_abbreviations + 64 * (prev_c - 1) + 2 * c); FastMem.LOW_WORD(ptr_addr, out abbr_addr); decode_text(string_type.ABBREVIATION, abbr_addr); status = 0; break; case 2: /* ZSCII character - first part */ status = 3; break; case 3: /* ZSCII character - second part */ zc = (zword)((prev_c << 5) | c); c2 = translate_from_zscii((zbyte)zc); // TODO This doesn't seem right outchar(st, c2); status = 0; break; } prev_c = c; } } while (!((code & 0x8000) > 0)); if (st == string_type.VOCABULARY) ptrDt = 0; }/* decode_text */