-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumpobj.java
1510 lines (1309 loc) · 53 KB
/
dumpobj.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import omf.*;
/*
* Created on Feb 23, 2006
* Feb 23, 2006 10:23:14 PM
*/
public class dumpobj
{
private HashMap<Integer, String> fTools;
private HashMap<Integer, String> fProdos;
private HashMap<Integer, String> fGSOS;
private dumpobj()
{
fTools = load_tools();
fGSOS = load_gsos();
fProdos = null;
}
private static void usage()
{
System.out.println("dumpobj v 0.1");
System.out.println("usage: dumpobj [options] file [segments]");
System.out.println("options:");
System.out.println("\t-H dump headers only");
System.out.println("\t-D don't do hexdump");
System.out.println("\t-d disassemble CODE segments");
System.out.println("\t-dd disassemble all segments");
System.out.println("\t-h help");
System.out.println("if [segments] is blank then all segments will be dumped.");
}
/**
* @param args
*/
public static void main(String[] args)
{
boolean fHeaderOnly = false;
boolean fHexDump = true;
GetOpt go = new GetOpt(args, "DHdh");
dumpobj self = null;
int fDisasm = 0;
HashSet<String> fSegments = new HashSet<String>();
int c;
while ((c = go.Next()) != -1)
{
switch (c)
{
case 'H':
fHeaderOnly = true;
break;
case 'D':
fHexDump = false;
break;
case 'd':
fDisasm++;
break;
case 'h':
case '?':
usage();
return;
}
}
args = go.CommandLine();
if (args.length < 1) usage();
else
{
File f = new File(args[0]);
for (int i = 1; i < args.length; i++)
fSegments.add(args[i].toUpperCase());
ArrayList<OMF_Segment> segments = OMF.LoadFile(f);
if (segments == null)
{
System.err.printf("Invalid OMF File: %1$s\n", args[0]);
return;
}
if (fDisasm > 0) self = new dumpobj();
for (Iterator<OMF_Segment> iter = segments.iterator(); iter.hasNext(); )
{
OMF_Segment segment = iter.next();
if ((fSegments.size() > 0)
&& (!fSegments.contains(segment.SegmentName().toUpperCase())))
continue;
dumpheader(segment);
if (!fHeaderOnly)
{
int kind = segment.Kind();
if (fDisasm > 1 || fDisasm == 1 && (kind == OMF.KIND_CODE || kind == OMF.KIND_INIT))
{
self.disasm(segment);
}
else
{
dumpbody(segment, fHexDump);
}
}
}
}
}
static void dumpheader(OMF_Segment seg)
{
// write the header....
System.out.printf("Byte count: $%1$08x\n", seg.ByteCount());
System.out.printf("Reserved space: $%1$08x\n", seg.ReservedSpace());
System.out.printf("Length: $%1$08x\n", seg.Length());
System.out.printf("Label length: $%1$02x\n", seg.LabelLength());
System.out.printf("Number length: $%1$02x\n", seg.NumberLength());
System.out.printf("Version: $%1$02x\n", seg.Version());
System.out.printf("Bank size: $%1$08x\n", seg.BankSize());
System.out.printf("Kind: $%1$04x (%2$s)\n",
seg.Kind() | seg.Attributes(),
kind(seg.Kind(), seg.Attributes()));
System.out.printf("Org: $%1$08x\n", seg.Org());
System.out.printf("Alignment: $%1$08x\n", seg.Alignment());
System.out.printf("Number sex: $%1$02x\n", seg.NumberSex());
System.out.printf("Segment number: $%1$04x\n", seg.SegmentNumber());
System.out.printf("Segment entry: $%1$08x\n", seg.Entry());
System.out.printf("Load name: %1$s\n",
seg.LoadName().replace((char)0x00, ' '));
System.out.printf("Segment name: %1$s\n", seg.SegmentName());
System.out.println();
}
static String kind(int kind, int attr)
{
StringBuffer buff = new StringBuffer();
if (kind < 0 || kind > 0x12)
buff.append("???");
else
buff.append(SegKinds[kind]);
if ((attr & OMF.KIND_BANKREL) != 0)
buff.append(", bank relative");
if ((attr & OMF.KIND_SKIPSEG) != 0)
buff.append(", skip");
if ((attr & OMF.KIND_RELOADSEG) != 0)
buff.append(", reload");
if ((attr & OMF.KIND_ABSBANK) != 0)
buff.append(", absolute");
if ((attr & OMF.KIND_NOSPEC) != 0)
buff.append(", nospec");
if ((attr & OMF.KIND_POSIND) != 0)
buff.append(", posind");
if ((attr & OMF.KIND_PRIVATE) != 0)
buff.append(", private");
if ((attr & OMF.KIND_DYNAMIC) != 0)
buff.append(", dynamic");
else buff.append(", static");
return buff.toString();
}
static void dumpbody(OMF_Segment seg, boolean hexdump)
{
int pc = 0;
for(Iterator<OMF_Opcode> iter = seg.Opcodes(); iter.hasNext(); )
{
int size;
OMF_Opcode op = iter.next();
int opcode = op.Opcode();
String name;
if (opcode == OMF.OMF_EOF) name = "END";
else if (opcode < 0xe0 || opcode > 0xf7) name = "???";
else
{
name = names[opcode - 0xe0];
if (opcode == OMF.OMF_LCONST && !(op instanceof OMF_LConst))
{
opcode = op.CodeSize();
name = "CONST";
}
}
size = op.CodeSize();
System.out.printf("%1$08x: %2$-10s($%3$02x)\t$%4$04x", pc, name, opcode, size);
switch (op.Opcode())
{
case OMF.OMF_LCONST:
if (hexdump) dumphex( ((OMF_Const)op).Data(), op.CodeSize());
break;
case OMF.OMF_ENTRY:
{
OMF_Entry e = (OMF_Entry)op;
System.out.printf("\t$%1$04x $%2$08x %3$s",
e.Segment(), e.Offset(), e.toString());
}
break;
case OMF.OMF_SUPER:
{
OMF_Super s = (OMF_Super)op;
String tname;
int type = s.Type();
if (type == 0) tname = "RELOC2";
else if (type == 1) tname = "RELOC3";
else if (type > 1 && type < 38)
tname = "INTERSEG" + (type - 1);
else tname = "??? (" + type + ")";
System.out.printf("\t%1s", tname);
if (hexdump) dumphex(s.Data(), s.Length() - 1);
}
break;
case OMF.OMF_EXPR:
case OMF.OMF_BKEXPR:
case OMF.OMF_LEXPR:
case OMF.OMF_ZPEXPR:
{
OMF_Expr e = (OMF_Expr)op;
dumpexpr(e.Expression());
}
break;
case OMF.OMF_RELEXPR:
{
OMF_RelExpr e = (OMF_RelExpr)op;
dumpexpr(e.Expression());
}
break;
case OMF.OMF_GEQU:
case OMF.OMF_EQU:
{
OMF_Equ eq = (OMF_Equ)op;
System.out.printf("\t%1$s", eq.toString());
dumpexpr(eq.Expression());
}
break;
case OMF.OMF_GLOBAL:
case OMF.OMF_LOCAL:
System.out.printf("\t%1$s", op.toString());
break;
}
System.out.println();
pc += size;
}
System.out.println();
}
private static void dumphex(byte[] data, int length)
{
int i = 0;
while (i < length)
{
StringBuffer hex = new StringBuffer();
StringBuffer ascii = new StringBuffer();
for(int j = 0; j < 16; j++, i++)
{
if (i == length) break;
byte b = data[i];
hex.append(hexcodes[(b >> 4) & 0x0f]);
hex.append(hexcodes[b & 0x0f]);
hex.append(' ');
// isprint hack
if (b >= 32 && b <= 127) ascii.append((char)b);
else ascii.append('.');
}
System.out.printf("\n %1$-50s%2$s", hex, ascii);
}
}
private static void dumpexpr(ArrayList expr)
{
System.out.print("\t");
for (Iterator iter = expr.iterator(); iter.hasNext(); )
{
Object o = iter.next();
if (o instanceof Integer)
{
int value = ((Integer)o).intValue();
String op;
if (value == 0) return; // end of expression.
if (value > 0x15) op = "?";
else op = mathops[value];
System.out.print(op);
}
else if (o instanceof OMF_Number)
{
OMF_Number n = (OMF_Number)o;
int value = n.Value();
int opcode = n.Opcode();
if (opcode == OMF_Expression.EXPR_REL)
{
System.out.printf("*+$%1$04x", value);
}
else if (opcode == OMF_Expression.EXPR_ABS)
{
System.out.printf("$%1$04x", value);
}
else System.out.print("?");
}
else if (o instanceof OMF_Label)
{
OMF_Label lab = (OMF_Label)o;
// may be weak, label, len, type, or count .. should distinguish them.
System.out.print(lab.toString());
}
else
{
System.out.print("?");
}
System.out.print(' ');
}
}
private static String format_x2(int n, int length)
{
String s = Integer.toHexString(n);
while(s.length() < length)
s = "0" + s;
return s;
}
private static String format_x(int n, int length)
{
return "$" + format_x2(n, length);
}
private static String format_arg(int operand, int size, int mode)
{
switch (mode & 0xfff0)
{
case mRelative:
switch(size)
{
case 1:
if ((operand & 0x80) == 0x80)
return "*-" + format_x(256 - operand, 2);
return "*+" + format_x(2 + operand, 2);
case 2:
if ((operand & 0x8000) == 0x8000)
return "*-" + format_x(65536 - operand, 2);
return "*+" + format_x(3 + operand, 2);
}
return "";
case mBlockMove:
return format_x(operand >> 8,2) + "," + format_x(operand & 0xff, 2);
default:
return format_arg(format_x(operand, size * 2), mode);
}
}
private static String format_arg(String base, int mode)
{
String args = "";
switch(mode & 0xf000)
{
case mImmediate:
args = "#" + base;
break;
case mDP:
case mAbsolute:
case mAbsoluteLong:
args = base;
break;
case mRelative:
args = base;
break;
case mBlockMove:
args = base; //
break;
case mDPIL:
case mAbsoluteIL:
args = "[" + base + "]";
break;
case mDPI:
case mAbsoluteI:
args = "(" + base;
if ((mode & m_S) == m_S)
{
mode &= (~m_S);
args += ",s";
}
if ((mode & m_X) == m_X)
{
mode &= (~m_X);
args += ",x";
}
args += ")";
break;
}
switch(mode & 0x0f00)
{
case m_X:
args += ",x";
break;
case m_Y:
args += ",y";
break;
case m_S:
args += ",s";
}
return args;
}
private void disasm(OMF_Segment seg)
{
int pc = 0;
boolean fX = true;
boolean fM = true;
BitSet branches = new BitSet();
String type;
if (seg.Private())
{
type = seg.Kind() == OMF.KIND_DATA ? "PRIVDATA" : "PRIVATE";
}
else
{
type = seg.Kind() == OMF.KIND_DATA ? "DATA" : "START";
}
System.out.printf("%1$s\t%2$s\t%3$s\n",
seg.SegmentName().trim(), type, seg.LoadName().trim());
if ((seg.Kind() & (~1)) != 0 || (seg.Attributes() & (~OMF.KIND_PRIVATE)) != 0)
{
System.out.printf("\tKIND $%1$04x\n",
seg.Kind() | seg.Attributes());
}
ListIterator<OMF_Opcode> iter = seg.Opcodes();
while(iter.hasNext())
{
OMF_Opcode op = iter.next();
switch(op.Opcode())
{
case OMF.OMF_DS:
print_line(pc, "ds", format_x(op.CodeSize(), 2), "");
pc += op.CodeSize();
break;
case OMF.OMF_EQU:
{
OMF_Equ e = (OMF_Equ)op;
print_line(e.toString(), "equ", format_expr(e.Expression()));
}
break;
case OMF.OMF_GEQU:
{
OMF_Equ e = (OMF_Equ)op;
print_line(e.toString(), "gequ", format_expr(e.Expression()));
}
break;
case OMF.OMF_GLOBAL:
print_line(op.toString(), "entry", "");
break;
case OMF.OMF_LOCAL:
print_line(op.toString(), "anop", "");
break;
case OMF.OMF_ALIGN:
print_line("", "align", format_x( ((OMF_Align)op).Value(), 4));
break;
case OMF.OMF_LCONST:
{
int size = op.CodeSize();
int i = 0;
byte[] data =((OMF_Const)op).Data();
loop: while (i < size)
{
int opcode = data[i] & 0xff;
int mode = modes[opcode];
int argsize = mode & 0x000f;
if (branches.get(pc))
System.out.println();
// adjust operand size if m/x bits apply.
if ( ((mode & m_I) == m_I) && fX)
{
argsize++;
}
if ( ((mode & m_M) == m_M) && fM)
{
argsize++;
}
int arg = 0;
String args = "";
if (i + argsize >= size)
{
// TODO -- check for mvn/mvp, handle as special case.
if (i +1 == size)
{
boolean process = true;
op = iter.next();
if (op.CodeSize() == argsize) switch(op.Opcode())
{
case OMF.OMF_EXPR:
case OMF.OMF_ZPEXPR:
case OMF.OMF_BKEXPR:
case OMF.OMF_LEXPR:
args = format_expr((OMF_Expr)op);
break;
case OMF.OMF_RELEXPR:
args = format_expr((OMF_RelExpr)op);
break;
default :
iter.previous();
process = false;
}
if (process)
{
print_line(pc, to_opcode(opcode), args, format_x2(opcode, 2));
pc += 1 + argsize;
i++;
continue;
}
}
for(;;)
{
print_line(pc, "dc", "i1'" + format_x(opcode,2) + "'", format_x2(opcode, 2));
pc++;
i++;
if (i >= size) break;
opcode = data[i];
}
continue;
}
switch(argsize)
{
case 1:
arg = OMF.Read8(data, i + 1,0);
break;
case 2:
arg = OMF.Read16(data, i + 1,0);
break;
case 3:
arg = OMF.Read24(data, i + 1,0);
break;
}
switch(opcode)
{
case 0x40: // rti
case 0x60: // rts
case 0x6b: // rtl
branches.set(pc +1);
break;
case 0x90: // bxx
case 0xb0:
case 0xf0:
case 0x30:
case 0xd0:
case 0x10:
case 0x80:
case 0x50:
case 0x70:
if (arg < 0x80) branches.set(pc + arg + 2);
else branches.set(pc + 0x100 - arg);
break;
case 0x82: //brl
// TODO -- check for debug names.
if (arg < 0x8000) branches.set(pc + 3 + arg);
else branches.set(pc + 0x10000 - arg);
break;
case 0xc2: // rep
if ((arg & 0x20) == 0x20)
{
System.out.println("\tLONGA ON");
fM = true;
}
if ((arg & 0x10) == 0x10)
{
System.out.println("\tLONGI ON");
fX = true;
}
break;
case 0xe2:
if ((arg & 0x20) == 0x20)
{
System.out.println("\tLONGA OFF");
fM = false;
}
if ((arg & 0x10) == 0x10)
{
System.out.println("\tLONGI OFF");
fX = false;
}
break;
case 0xfb: //xce
if (i > 0)
{
if (data[i-1] == 0x18)
{
// clc/xce --> go to native, but still 8 bit mx registers.
}
else if (data[i-1] == 0x38)
{
//sec/xce --> go emulation
System.out.println("\tLONGA OFF");
System.out.println("\tLONGI OFF");
fM = fX = false;
}
}
break;
case 0xa2: // ldx #
if (fX && fTools != null)
{
// check for 22 00 00 e1
if (size > i + 2 + 4)
{
if (data[i + 3] == 0x22 && OMF.Read24(data, i + 4, 0) == kTOOL_STACK)
{
String s = fTools.get(new Integer(arg));
if (s != null)
{
print_line(pc, s, "", "");
pc += 7;
i += 7;
continue loop;
}
}
}
}
break;
case 0x22: // JSL ... check if GS/OS call...
if (arg == kGSOS_INLINE)
{
// TODO check for 6 bytes or 2 bytes + 1 expression or 0 bytes + 2 expression
if (size > i + 3 + 6)
{
int a,b;
String s = null;
a = OMF.Read16(data, i + 4, 0);
b = OMF.Read32(data, i + 6, 0);
if (fGSOS != null) s = fGSOS.get(a);
if (s == null) s = "_GSOS_" + format_x2(a, 4);
print_line(pc, s, format_x(b, 8),"");
pc += 10;
i += 10;
continue loop;
}
else if (size > i + 3 + 2)
{
}
else if (size == i + 1)
{
}
}
break;
case 0x00: // BRK -- treat long runs of 0s as a DS
if (arg == 0)
{
int j = i + 2 ;
for (; j < size; j++)
{
if (data[j] != 0) break;
}
int dsize = j - i;
if (dsize > 2)
{
print_line(pc, "ds", format_x(dsize, 4),"");
i += dsize;
pc += dsize;
continue loop;
}
}
break;
}
args = format_arg(arg, argsize, mode);
String hexbytes = format_x2(opcode, 2);
switch(argsize)
{
case 3:
hexbytes += " " +format_x2(arg & 0xff ,2);
arg = arg >> 8;
case 2:
hexbytes += " " +format_x2(arg & 0xff ,2);
arg = arg >> 8;
case 1:
hexbytes += " " +format_x2(arg & 0xff ,2);
}
print_line(pc, to_opcode(opcode), args, hexbytes);
pc += 1 + argsize;
i += 1 + argsize;
}
}
break;
}
}
System.out.printf("\tEND\n\n");
}
private static String to_opcode(int opcode)
{
return opcodes.substring(opcode * 3, opcode * 3 + 3);
}
private static String format_expr(OMF_Expr expr)
{
return format_expr(expr.Expression());
}
private static String format_expr(OMF_RelExpr expr)
{
return format_expr(expr.Expression());
}
private static String format_expr(ArrayList expr)
{
// TODO -- support all ops, make sure in correct order of operation.
ArrayList<String> stack = new ArrayList<String>();
int size = expr.size();
int i;
int top = 0;
for (i = 0; i < size; i++)
{
Object o = expr.get(i);
if (o instanceof OMF_Label)
{
stack.add(o.toString());
top++;
continue;
}
else if (o instanceof OMF_Number)
{
int v = ((OMF_Number)o).Value();
if (v < 0)
{
Object o2 = expr.get(i + 1);
if ((o2 instanceof Integer) && ((Integer)o2).intValue() == OMF_Expression.EXPR_SHIFT)
{
stack.add(Integer.toString(v));
top++;
continue;
}
}
stack.add(format_x(v, 4) );
top++;
continue;
}
else if (o instanceof Integer)
{
Integer mathop = (Integer)o;
switch(mathop.intValue())
{
case OMF_Expression.EXPR_ADD:
{
String a,b;
a = stack.remove(--top);
b = stack.remove(--top);
stack.add(b + "+" + a);
top++;
break;
}
case OMF_Expression.EXPR_SUB:
{
String a,b;
a = stack.remove(--top);
b = stack.remove(--top);
stack.add(b + "-" + a);
top++;
break;
}
case OMF_Expression.EXPR_MUL:
{
String a,b;
a = stack.remove(--top);
b = stack.remove(--top);
stack.add(b + "*" + a);
top++;
break;
}
case OMF_Expression.EXPR_SHIFT:
{
String a,b;
a = stack.remove(--top);
b = stack.remove(--top);
stack.add(b + "|" + a);
top++;
break;
}
}
}
}
return stack.get(top - 1);
}
private static void print_line(int pc, String opcode, String operand, String bytes)
{
System.out.printf("\t%1$-4s %2$-30s ; %3$06x: %4$s\n",
opcode, operand, pc, bytes);
}
private static void print_line(String lab, String opcode, String operand)
{
System.out.printf("%1$s\t%2$-4s %3$s\n",
lab, opcode, operand);
}
private static HashMap<Integer, String>load_file(File f)
{
HashMap<Integer, String> map = null;
boolean ok;
try
{
RandomAccessFile raf = new RandomAccessFile(f, "r");
map = new HashMap<Integer, String>();
for(;;)
{
int c;
String line = raf.readLine();
if (line == null) break;
c = line.charAt(0);
if (c == ';') continue;
if (c == '#') continue;
line = line.trim();
if (line.length() == 0) continue;
/*
* xxxx [a-zA-Z0-9]
*
*/
int tn = 0;
ok = true;
int i;
for (i = 0; i < 4; i++)
{
c = line.charAt(i);
switch(c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
tn = tn << 4 | (c - '0');
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
tn = tn << 4 | (c - 'a' + 10);
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
tn = tn << 4 | (c - 'A' + 10);
break;
default: ok = false;
}
if (!ok) break;
}
if (!ok) continue;
for (;;)
{
c = line.charAt(i);
if (c == ' ' || c == '\t') i++;
else break;
}