1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 }