-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedirect.java
127 lines (108 loc) · 3.2 KB
/
makedirect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import omf.OMF_Eof;
import omf.OMF_Segment;
import omf.OMF;
/*
* Created on Dec 7, 2006
* Dec 7, 2006 7:29:03 PM
*/
/*
* makedirect [-o outfile] [-n name] [-p size]
*
* create a direct page segment
* -o outfile: name of file (direct.o is default)
* -n name: segment name (STACKMIN is default)
* -p size: size of segment (required)
*
*/
public class makedirect
{
private static void usage()
{
System.out.println("makedirect v 0.1");
System.out.println("Create a direct page/stack segment.");
System.out.println("usage: makedirect [options]");
System.out.println("options:");
//System.out.println("\t-n name segment name [STACKMIN]");
System.out.println("\t-o objfile object file name [direct.o]");
System.out.println("\t-p size size of segment (required)");
System.out.println("\t-h help");
}
private static int ParseInt(String s)
{
int c;
if (s == null || s.length() == 0) return 0;
int base = 10;
c = s.charAt(0);
if (c == '$')
{
s = s.substring(1);
base = 16;
}
else if (c == '0'
&& s.length() > 2
&& s.charAt(1) == 'x')
{
s = s.substring(2);
base = 16;
}
return Integer.parseInt(s, base);
}
public static void main(String[] args)
{
GetOpt go = new GetOpt(args, "o:p:h");
//String fSegname = "STACKMIN";
String fOutfile = "direct.o";
int fSize = -1;
int c;
while ((c = go.Next()) != -1)
{
switch(c)
{
/*
case 'n':
fSegname = go.Argument();
break;
*/
case 'o':
fOutfile = go.Argument();
break;
case 'p':
fSize = makedirect.ParseInt(go.Argument());
break;
case 'h':
case '?':
usage();
return;
}
}
if (fSize == 0)
{
usage();
return;
}
if (fSize < 0x0100 || fSize > 0xffff)
{
System.err.println("makedirect: size is out of range. Must be $100--$ffff.");
}
OMF_Segment s = new OMF_Segment();
s.SetSegmentName("~Direct");
s.SetLoadName("~Direct");
s.SetReservedSpace(fSize);
s.SetKind(OMF.KIND_DP);
s.SetAttributes(OMF.KIND_PRIVATE);
s.SetSegmentNumber(1);
s.AddOpcode(new OMF_Eof());
try
{
FileOutputStream fout = new FileOutputStream(fOutfile);
s.Save(fout);
}
catch (FileNotFoundException e)
{
System.err.println("makedirect: unable to open file "
+ fOutfile + ".");
}
}
}