org.zmpp.vmutil
Class ZsciiConverter

java.lang.Object
  extended by org.zmpp.vmutil.ZsciiConverter

public class ZsciiConverter
extends Object

This class provides conversion for the ZSCII character encoding into the Java character system.

Version:
1.0
Author:
Wei-ju Wu

Nested Class Summary
static interface ZsciiConverter.AbbreviationsTable
          This interface defines the abstract access to an abbreviations table in memory, this will be used for decoding if needed.
static class ZsciiConverter.Alphabet
          Defines the possible alphabets here.
 
Field Summary
static String A0CHARS
           
static String A1CHARS
           
static String A2CHARS
           
static byte CHAR_0
           
static byte CHAR_1
           
static byte CHAR_6
           
static byte SHIFT_2
           
static byte SHIFT_3
           
static byte SHIFT_4
           
static byte SHIFT_5
           
 
Constructor Summary
ZsciiConverter(int version, ZsciiConverter.AbbreviationsTable abbreviations)
          Constructor.
 
Method Summary
 String convert(MemoryReadAccess memaccess, int address)
          Performs a ZSCII to Unicode conversion at the specified position of the given memory object.
static char decode(ZsciiConverter.Alphabet alphabet, short zchar)
          Decodes a printable character to a unicode character.
static void decodeZchar(StringBuilder builder, ZsciiConverter.Alphabet alphabet, byte b)
          Decodes the given byte value to the specified buffer using the working alphabet.
 ZsciiConverter.Alphabet getInitialAlphabet()
          Returns the initial alphabet of this converter.
 int getVersion()
          Returns the story file version.
static ZsciiConverter.Alphabet shiftFrom(ZsciiConverter.Alphabet alphabet, byte shiftChar)
          Returns a new alphabet for a given shift character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHAR_0

public static final byte CHAR_0
See Also:
Constant Field Values

CHAR_1

public static final byte CHAR_1
See Also:
Constant Field Values

SHIFT_2

public static final byte SHIFT_2
See Also:
Constant Field Values

SHIFT_3

public static final byte SHIFT_3
See Also:
Constant Field Values

SHIFT_4

public static final byte SHIFT_4
See Also:
Constant Field Values

SHIFT_5

public static final byte SHIFT_5
See Also:
Constant Field Values

CHAR_6

public static final byte CHAR_6
See Also:
Constant Field Values

A0CHARS

public static final String A0CHARS
See Also:
Constant Field Values

A1CHARS

public static final String A1CHARS
See Also:
Constant Field Values

A2CHARS

public static final String A2CHARS
See Also:
Constant Field Values
Constructor Detail

ZsciiConverter

public ZsciiConverter(int version,
                      ZsciiConverter.AbbreviationsTable abbreviations)
Constructor.

Parameters:
version - Story file version
abbreviations - the abbreviations table used for decoding
Method Detail

getInitialAlphabet

public ZsciiConverter.Alphabet getInitialAlphabet()
Returns the initial alphabet of this converter.

Returns:
the initial alphabet

getVersion

public int getVersion()
Returns the story file version.

Returns:
the story file version

convert

public String convert(MemoryReadAccess memaccess,
                      int address)
Performs a ZSCII to Unicode conversion at the specified position of the given memory object.

Parameters:
memaccess - a MemoryReadAccess object
address - the address of a ZSCII string
Returns:
a converted Unicode string

decodeZchar

public static void decodeZchar(StringBuilder builder,
                               ZsciiConverter.Alphabet alphabet,
                               byte b)
Decodes the given byte value to the specified buffer using the working alphabet.

Parameters:
builder - the buffer to print into
alphabet - the working alphabet
b - a z character, needs to be a non-shift character

decode

public static char decode(ZsciiConverter.Alphabet alphabet,
                          short zchar)
Decodes a printable character to a unicode character.

Parameters:
alphabet - the work alphabet
zchar - the ZSCII character to decode
Returns:
the Unicode character

shiftFrom

public static ZsciiConverter.Alphabet shiftFrom(ZsciiConverter.Alphabet alphabet,
                                                byte shiftChar)
Returns a new alphabet for a given shift character. If the character is not a shift character, the old alphabet is returned.

Parameters:
alphabet - the start alphabet
shiftChar - the shift character
Returns:
the shifted alphabet


Copyright © 2005 . All Rights Reserved.