View Javadoc

1   /*
2    * $Id: Main.java,v 1.3 2005/11/03 19:04:59 weiju Exp $
3    * 
4    * Created on 10.10.2005
5    * Copyright 2005 by Wei-ju Wu
6    *
7    * This file is part of The Z-machine Preservation Project (ZMPP).
8    *
9    * ZMPP is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation; either version 2 of the License, or
12   * (at your option) any later version.
13   *
14   * ZMPP is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with ZMPP; if not, write to the Free Software
21   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22   */
23  package org.zmpp.debug;
24  
25  import java.io.File;
26  import java.io.IOException;
27  import java.io.RandomAccessFile;
28  
29  import javax.swing.JFrame;
30  
31  import org.zmpp.base.DefaultMemoryAccess;
32  import org.zmpp.base.MemoryAccess;
33  import org.zmpp.vm.Abbreviations;
34  import org.zmpp.vm.DefaultStoryFileHeader;
35  import org.zmpp.vm.Machine3;
36  import org.zmpp.vm.OutputStream;
37  import org.zmpp.vm.StoryFileHeader;
38  import org.zmpp.vmutil.ZsciiConverter;
39  import org.zmpp.vmutil.ZsciiString;
40  
41  /***
42   * This class is for integration testing only.
43   * 
44   * @author Wei-ju Wu
45   * @version 1.0
46   */
47  public class Main {
48  
49    static class MyOutputStream implements OutputStream {
50      
51      private boolean enabled;
52      
53      public MyOutputStream() {
54        
55        enabled = true;
56      }
57      
58      public void setEnabled(boolean flag) {
59        
60        this.enabled = flag;
61      }
62      
63      public boolean isEnabled() {
64        
65        return enabled;
66      }
67      
68      public void newline() {
69        
70        System.out.println();
71      }
72      
73      public void print(String str) {
74        
75        System.out.print(str);
76      }
77    }
78    
79    /***
80     * @param args
81     */
82    public static void main(String[] args) {
83  
84      if (args.length == 0) {
85        
86        System.out.println("usage: java org.zmpp.vm.Main <storyfile>");
87      }
88      try {
89        File storyfile = new File(args[0]);
90        RandomAccessFile file = new RandomAccessFile(storyfile, "r");
91        int fileSize = (int) file.length();
92        byte[] buffer = new byte[fileSize];    
93        file.read(buffer);
94        file.close();
95        MemoryAccess memaccess = new DefaultMemoryAccess(buffer);
96        StoryFileHeader fileheader = new DefaultStoryFileHeader(memaccess);
97        Abbreviations abbreviations = new Abbreviations(memaccess,
98          fileheader.getAbbreviationsAddress());
99        ZsciiConverter converter = new ZsciiConverter(3, abbreviations);
100       ZsciiString.setZsciiConverter(converter);      
101       Machine3 machineState = new Machine3();
102       machineState.initialize(memaccess, fileheader);
103       machineState.setOutputStream(1, new MyOutputStream());
104       
105       JFrame frame = new TestFrame(machineState);
106       frame.pack();
107       frame.setVisible(true);
108       
109       
110     } catch (IOException ex) {
111       
112       ex.printStackTrace();
113     }
114   }
115 
116 }