-
Notifications
You must be signed in to change notification settings - Fork 0
/
rof.c
1364 lines (1180 loc) · 38.4 KB
/
rof.c
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
/* ******************************************************************** *
* rof.c - handles rof files *
* *
* ******************************************************************** *
* *
* Copyright (c) 2017 David Breeding *
* *
* This file is part of osk-disasm. *
* *
* osk-disasm is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* osk-disasm is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* (see the file "COPYING") along with osk-disasm. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
* ******************************************************************** */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "disglobs.h"
#include "userdef.h"
#define ROF_C
#include "rof.h"
#include "proto.h"
#ifdef __STDC__
static void ROFDataLst (struct rof_extrn *mylist, int maxcount, struct asc_data *ascdat, char cclass);
static void get_refs(char *vname, int count, int ref_typ, char *codebuffer);
#else
void ROFDataLst ();
void get_refs();
#endif
char rname[100];
/*int code_begin;*/
extern int CodeEnd,
PrevEnt;
extern char realcmd[],
pseudcmd[];
/* DEBUGGING function */
void
#ifdef __STDC__
reflst (void)
#else
reflst ()
struct asc_data *cl;
#endif
{
struct rof_extrn * meme = refs_code;
while (meme)
{
fprintf (stderr, "%05x : %-20s (%s)\n", meme->Ofst,
meme->Extrn ? meme->EName.nam : meme->EName.lbl->sname, meme->Extrn ? "Extern" : "Local");
meme = meme->ENext;
}
/*if (cl->LNext)
{
reflst (cl->LNext);
}
printf (" >>> %04x %d\n",cl->start,cl->length);
if (cl->RNext)
{
reflst (cl->RNext);
}*/
}
/* **************************************************************** *
* RealPos() - Returns the correct file position. Returns CmdEnt *
* Non-ROF files, CmdEnt Offset by Code Entry Point *
* **************************************************************** */
int
#ifdef __STDC__
RealEnt(void)
#else
RealEnt()
#endif
{
return IsROF ? (CmdEnt + HdrEnd) : CmdEnt;
}
/* ************************************************************************ *
* AddInitLbls() - Add the initialization data to the Labels Ref *
* On entry, the file pointer is positioned to the begin of the *
* initialized data list for this particular vsect. *
* ************************************************************************ */
void
#ifdef __STDC__
AddInitLbls (struct rof_extrn *tbl, int dataSiz, char klas)
#else
AddInitLbls(tbl, dataSiz, klas);
struct rof_extrn *tbl, int dataSiz; char klas;
#endif
{
char *dataBuf,
*ptr;
int c = 1;
register int refVal;
dataBuf = (char *)mem_alloc(dataSiz + 1);
if (fread (dataBuf, dataSiz, 1, ModFP) == -1)
{
fprintf (stderr, "AddInitLbls(): Failed to read in data for Init Data Buffer");
exit (errno);
}
while (tbl)
{
if (!tbl->Extrn)
{
ptr = &(dataBuf[tbl->Ofst]);
switch (REFSIZ(tbl->Type))
{
case 1: /*SIZ_BYTE:*/
refVal = *ptr & 0xff;
--dataSiz;
break;
case 2: /*SIZ_WORD:*/
/*refVal = 0;
refVal = fread_w(ModFP);*/
refVal = bufReadW(&ptr);
dataSiz -= 2;
break;
default:
refVal = bufReadL(&ptr);
/*refVal = fread_l(ModFP);*/
dataSiz -= 4;
}
tbl->EName.lbl = addlbl(tbl->dstClass, refVal, "");
}
tbl = tbl->ENext;
}
}
/* ************************************************** *
* rofhdr() - read and interpret rof header *
* ************************************************** */
void
#ifdef __STDC__
getRofHdr (FILE *progpath)
#else
rofhdr()
FILE *progpath;
#endif
{
int glbl_cnt,
ext_count,
count; /* Generic counter */
int local_count;
char *codeBuf;
IsROF = TRUE; /* Flag that module is an ROF module */
fseek(progpath, 0, SEEK_SET); /* Start all over */
/* get header data */
//ROFHd.sync = (M_ID << 16) | (fread_w(ModFP) & 0xffff);
ROFHd.sync = fread_l(ModFP);
if (ROFHd.sync != 0xdeadface)
{
errexit ("Illegal ROF Module sync bytes");
}
ROFHd.ty_lan = fread_w(ModFP);
ROFHd.att_rev = fread_w (ModFP); /* Attribute/Revision word */
ROFHd.valid = fread_w (ModFP); /* Nonzero if valid */
ROFHd.series = fread_w (ModFP); /* Assembler version used to compile */
fread(ROFHd.rdate, sizeof(ROFHd.rdate), 1, ModFP);
ROFHd.edition = fread_w(ModFP);;
ROFHd.statstorage = fread_l (ModFP); /* Size of static variable storage */
ROFHd.idatsz = fread_l (ModFP); /* Size of initialized data */
ROFHd.codsz = fread_l (ModFP); /* Size of the object code */
ROFHd.stksz = fread_l (ModFP); /* Size of stack required */
ROFHd.code_begin = fread_l (ModFP); /* Offset to entry point of object code */
ROFHd.utrap = fread_l (ModFP); /* Offset to unitialized trap entry point */
ROFHd.remotestatsiz = fread_l (ModFP); /* Size of remote static storage */
ROFHd.remoteidatsiz = fread_l (ModFP); /* Size of remote initialized data */
ROFHd.debugsiz = fread_l (ModFP); /* Size of the debug */
ROFHd.rname = freadString();
/* Set ModData to an unreasonable high number so ListData
* won't do it's thing...
*/
M_Mem = 0x10000;
/*ModData = 0x7fff;*/
/* ************************************************ *
* Get the Global definitions *
* ************************************************ */
count = glbl_cnt = fread_w (progpath);
while (count--)
{
char *name;
LBLDEF *me;
int adrs;
int typ;
name = freadString();
typ = fread_w (progpath);
adrs = fread_l (progpath);
if (me = addlbl(rof_class(typ, REFGLBL), adrs, name))
{
me->global = 1;
}
}
/* Code section... read, or save file position */
HdrEnd = ftell (progpath);
CodeEnd = ROFHd.codsz;
/* Read code into buffer for get_refs() while we're here */
if (fread ((codeBuf = (char *)mem_alloc(ROFHd.codsz + 1)), ROFHd.codsz, 1, ModFP) == -1)
{
fprintf (stderr, "Failed to read code buffer\n");
}
/*idp_begin = code_begin + rofptr->codsz;
indp_begin = idp_begin + rofptr->idpsz;*/
/*if (fseek (progpath, ROFHd.codsz, SEEK_CUR) == -1)
{
fprintf (stderr, "rofhdr(): Seek error on module\n");
exit (errno);
}*/
/* ********************************** *
* Initialized data Section *
* ********************************** */
IDataCount = ROFHd.idatsz;
IDataBegin = ftell(ModFP);
/* ********************************** *
* External References Section *
* ********************************** */
if (fseek (ModFP, IDataBegin + ROFHd.idatsz + ROFHd.remotestatsiz + ROFHd.debugsiz, SEEK_SET) == -1)
{
fprintf (stderr, "rofhdr(): Seek error on module\n");
exit (errno);
}
ext_count = fread_w (ModFP);
while (ext_count--)
{
char *_name;
int refcount;
_name = freadString();
refcount = fread_w (ModFP);
/* Get the individual occurrences for this name */
get_refs (_name, refcount, REFXTRN, NULL);
}
/* *************************** *
* Local variables... *
* *************************** */
local_count = fread_w (ModFP);
get_refs("", local_count, REFLOCAL, codeBuf);
free (codeBuf);
/* Now we need to add labels for these refs */
/* common block variables... */
/* Do this after everything else is done */
/* NOTE: We may need to save current ftell() to restore it after this */
if (fseek(ModFP, IDataBegin, SEEK_SET) == -1)
{
errexit ("RofLoadInitData() : Failed to seek to begin of Init Data");
}
AddInitLbls (refs_idata, ROFHd.idatsz, '_');
AddInitLbls (refs_iremote, ROFHd.idatsz, 'H');
/* Now we're ready to disassemble the code */
/* Position to begin of Code section */
fseek (progpath, HdrEnd, SEEK_SET);
PCPos = 0;
/* rofdis();*/
}
void
#ifdef __STDC__
RofLoadInitData (void)
#else
ROFLoadInitData()
#endif
{
/* ********************************** *
* Initialized data section *
* ********************************** */
/* ********************************** *
* Initialized remote data Section *
* ********************************** */
/* ********************************** *
* Debug Information Section *
* ********************************** */
}
/* ****************************************************** *
* rof_class () - returns the Destination reference for *
* the reference *
* Passed: The Type byte from the reference *
* Returns: The Class Letter for the entry *
* ****************************************************** */
char
#ifdef __STDC__
rof_class (int typ, int refTy)
#else
rof_class (typ)
int typ; int refTy
#endif
{
/* We'll tie up additional classes for data/bss as follows
* D for data
* _ for init data
* G for remote
* H for remote init
*
*/
switch (refTy)
{
case REFGLBL:
switch (typ & 0x100)
{
case 0: /* NOT common */
switch (typ & 0x04) /* Docs are backward? */
{
case 0: /* Data */
switch (typ & 0x01) /* Docs are backward ? */
{
case 0: /* Uninit */
switch (typ & 0x02)
{
case 0:
return 'D';
default:
return 'G';
}
default: /* Init */
switch (typ & 0x02)
{
case 0:
return '_';
default:
return 'H';
}
}
default: /* Code or Equ */
switch (typ & 0x02)
{
case 0: /* NOT remote */
return 'L';
default:
return 'L'; /* FIXME: This is actually 'equ' */
}
}
default: /* common */
switch (typ & 0x20)
{
case 0: /* NOT Remote */
/* These are WRONG! but for now, we'll use them */
return '_';
default:
return 'D';
}
}
break;
case REFXTRN:
case REFLOCAL:
switch (typ & 0x20)
{
case 0: /* NOT remote */
switch (typ & 0x200)
{
case 0: /* data */
return '_';
default: /* remote */
return 'L';
}
default:
switch (typ & 0x200)
{
case 0: /* code */
return 'L';
default: /* debug */
break;
}
return 'L';
}
}
return 'L'; /* Should never get to here, but for safety's sake */
}
/* ************************************************** *
* rof_addlbl() - Adds a label to the nlist tree if *
* applicable *
* Copies rof name to nlist name if *
* different
* Passed: adrs - address of label *
* ref - reference structure *
* ************************************************** */
//void
//#ifdef __STDC__
//rof_addlbl (int adrs, struct rof_extrn *ref)
//#else
//rof_addlbl (adrs, ref)
// int adrs; struct rof_extrn *ref;
//#endif
//{
// LBLDEF *nl;
//
// /* The following may be a kludge. The problem is that Relative
// * external references get added to class C.
// * Hopefully, no external references are needed in the label ref
// * tables. We'll try this to see...
// */
//
// if (ref->Extrn)
// {
// return;
// }
//
// if ((nl = addlbl (adrs, rof_class (ref->Type, 1), NULL)))
// {
// if (strlen (ref->EName))
// {
// if (strcmp (nl->sname, ref->EName))
// {
// strcpy (nl->sname, ref->EName);
// }
// }
// }
//}
/* ************************************************************** *
* get_refs() - get entries for given reference, *
* either external or local. *
* Passed: name (or blank for locals) *
* count - number of entries to process *
* 1 if external, 0 if local *
* ************************************************************** */
static void
#ifdef __STDC__
get_refs(char *vname, int count, int ref_typ, char *code_buf)
#else
get_refs(vname, count, ref_typ)
char *vname; int count; int refType, int ref_typ;
#endif
{
struct rof_extrn *prevRef = NULL;
char myClass;
unsigned int _ty;
int _ofst;
struct rof_extrn *new_ref,
*curRef,
**base = 0;
while (count--)
{
_ty = fread_w (ModFP);
_ofst = fread_l (ModFP);
/* Skip Debug refs */
if (ref_typ == REFLOCAL)
{
if ((_ty & 0x220) == 0x220)
{
continue;
}
}
/* Add to externs table */
switch (myClass = rof_class(_ty, ref_typ))
{
case 'L':
base = &refs_code;
break;
case 'D':
base = &refs_data;
break;
case '_':
base = &refs_idata;
break;
case 'G':
base = &refs_remote;
break;
case 'H':
base = &refs_iremote;
break;
default:
myClass = 'L'; /* Possibly cause erroneous result, but to avoid crash */
base = &refs_code;
}
/*if ((ref_typ == REFLOCAL) && (myClass == 'L'))
{
}
else*/
{
new_ref = (struct rof_extrn *)mem_alloc(sizeof(struct rof_extrn));
memset (new_ref, 0, sizeof(struct rof_extrn));
new_ref->Type = _ty;
new_ref->Ofst = _ofst;
new_ref->Extrn = (ref_typ == REFXTRN);
if (prevRef)
{
prevRef->MyNext = new_ref;
}
/*base = &refs_data;*/ /* For the time being, let's try to just use one list for all refs */
/* If this tree has not yet been initialized, simply set the
* base pointer to this entry (as the first)
*/
if ( ! *base)
{
*base = new_ref;
}
/* If we get here, this particular tree has alreay been started,
* so find where to put the new entry. Note, for starters, let's
* assume that each entry will be unique, that is, this location
* won't be here
*/
else /* We have entries, insert it into the proper place */
{
curRef = *base;
/*extrns = *base;*/ /* Use the global externs pointer */
if (_ofst < curRef->Ofst)
{
new_ref->ENext = curRef;
curRef->EUp = new_ref;
*base = new_ref;
}
else
{
while ((curRef->ENext) && (_ofst > curRef->ENext->Ofst))
{
curRef = curRef->ENext;
}
/*if (curRef->Ofst > _ofst)
{
curRef = curRef->EUp;
}*/
if (curRef->ENext)
{
curRef->ENext->EUp = new_ref;
}
new_ref->ENext = curRef->ENext;
new_ref->EUp = curRef;
curRef->ENext = new_ref;
}
} /* *base != NULL */
prevRef = new_ref;
if (new_ref->Extrn)
{
new_ref->EName.nam = vname;
}
else
{
register int dstVal;
char *pt = &(code_buf[new_ref->Ofst]);
new_ref->dstClass = rof_class(_ty, REFGLBL);
if ((ref_typ == REFLOCAL) && (myClass == 'L'))
{
switch ((new_ref->Type >> 3) & 3)
{
case 1:
dstVal = *pt & 0xff;
break;
case 2:
dstVal = bufReadW(&pt);
break;
default:
dstVal = bufReadL(&pt);
}
new_ref->EName.lbl = addlbl(new_ref->dstClass, dstVal, "");
}
}
} /* end "if (ref_typ == REFXTRN)" */
} /* end "while (count--) */
}
/* ************************************************** *
* find_extrn() - find an external reference *
* Passed : (1) xtrn - starting extrn ref *
* (2) adrs - Address to match *
* ************************************************** */
struct rof_extrn *
#ifdef __STDC__
find_extrn ( struct rof_extrn *xtrn, int adrs)
#else
find_extrn (xtrn, adrs)
struct rof_extrn *xtrn; int adrs;
#endif
{
int found = 0;
if (!xtrn)
{
return 0;
}
while ((adrs < xtrn->Ofst) && (xtrn->ENext))
{
xtrn = xtrn->ENext;
}
return (xtrn->Ofst == adrs ? xtrn : NULL);
}
/* ******************************************************** *
* Returns the size defined in the type *
* ******************************************************** */
int
#ifdef __STDC__
typeFetchSize (int rtype)
#else
typeFetchSize (rtype)
int rtype;
#endif
{
return (rtype >> 3) & 3;
}
/* ************************************************************ *
* rof_lblref() - Process a label reference found in the code. *
* On entry, Pc points to the begin of the reference *
* Passed: pointer to int variable to store value of operand *
* value *
* Returns: pointer to the rof_extern entry, with a label name *
* added, if applicable *
* ************************************************************ */
struct rof_extrn *
#ifdef __STDC__
rof_lblref (CMD_ITMS *ci, int *value)
#else
rof_lblref (ci, value)
CMD_ITMS *ci;
int *value;
#endif
{
struct rof_extrn *thisref;
register char *refFmt;
if ( ! (thisref = find_extrn (refs_code, PCPos)))
{
return 0;
}
/**value = getc (progpath);
++Pc;*/
switch (typeFetchSize(thisref->Type))
{
case SIZ_BYTE:
*value = getc(ModFP);
refFmt = "%c%02x";
++PCPos;
break;
case SIZ_WORD:
*value = getnext_w(ci);
refFmt = "%c%04x";
break;
case SIZ_LONG:
*value = (getnext_w(ci) & 0xffff) << 16;
*value |= getnext_w(ci) & 0xffff;
refFmt = (*value > 0xffff) ? "%c%04x" : "%c%08x";
break;
}
if ((Pass == 2) && (strlen(thisref->EName.nam) == 0))
{
sprintf (thisref->EName.nam, refFmt, thisref->Type, *value);
}
return thisref;
}
/* ******************************************************** *
* rof_find_asc() - Find an ascii data block def *
* Passed : (1) tree - ptr to asc_dat tree *
* (2) entry - Command entry point (usually CmdEnt *
* Returns: tree entry if present, 0 if no match *
* ******************************************************** */
static struct asc_data *
#ifdef __STDC__
rof_find_asc (struct asc_data *tree, int entry)
#else
rof_find_asc (tree, entry)
struct asc_data *tree; int entry;
#endif
{
if (!tree)
{
return 0;
}
while (1)
{
if (entry < tree->start)
{
if (tree->LNext)
{
tree = tree->LNext;
}
else
{
return 0;
}
}
else
{
if (entry > tree->start)
{
if (tree->RNext)
{
tree = tree->RNext;
}
else
{
return 0;
}
}
else
{
return tree;
}
}
}
}
/* ******************************************************** *
* rof_datasize() - returns the end of rof data area *
* Passed: Label Class letter to search *
* Returns: size of this data area *
* If not a data area, returns 0 *
* ******************************************************** */
int
#ifdef __STDC__
rof_datasize (char cclass)
#else
rof_datasize (cclass)
char cclass;
#endif
{
int dsize;
switch (cclass)
{
case 'D':
dsize = ROFHd.statstorage;
break;
case 'H':
dsize = ROFHd.remoteidatsiz;
break;
case 'G':
dsize = ROFHd.remotestatsiz;
break;
case '_':
dsize = ROFHd.idatsz;
break;
default:
dsize = 0;
}
return dsize;
}
/* ******************************************************************** *
* DataDoBlock - Process a block composed of an initialized reference *
* from a data area *
* Passed : (1) struct rof_extrn *mylist - pointer to tree element *
* (2) int datasize - the size of the area to process *
* (3) char class - the label class (D or C) *
* ******************************************************************** */
static char *
#ifdef __STDC__
DataDoBlock (struct rof_extrn **refsList, LBLDEF **lblList, char *iBuf, int blkEnd,
struct asc_data *ascdat, char cclass)
#else
DataDoBlock (refsList, lblList, iBuf, int blkEnd, ascdat, cclass)
struct rof_extrn **refsList; LBLDEF **lblList; char *iBuf; int blkEnd;
struct asc_data *ascdat, char cclass;
#endif
{
/*struct rof_extrn *srch;*/
CMD_ITMS Ci;
char lblString[200];
memset (&Ci, 0, sizeof(CMD_ITMS));
/* Insert Label if applicable */
if ((*lblList)->myaddr == CmdEnt)
{
strcpy (lblString, (*lblList)->sname);
Ci.lblname = lblString;
if ((*lblList)->global)
{
strcat (Ci.lblname, ":");
}
(*lblList) = (*lblList)->Next;
}
while (PCPos < blkEnd)
{
int bump = 2,
my_val;
CmdEnt = PCPos;
/* First check that refsList is not null. If this vsect has no
* references, 'refsList' will be null
*/
if ( *refsList && ((*refsList)->Ofst == CmdEnt) )
{
strcpy (Ci.mnem, "dc.");
switch (((*refsList)->Type >> 3) & 3)
{
case 1: /* SIZ_BYTE */
strcat (Ci.mnem, "b");
my_val = *(iBuf++);
++PCPos;
break;
case 2: /* SIZ_WORD */
strcat (Ci.mnem, "w");
my_val = bufReadW(&iBuf) & 0xffff;
/*iBuf += 2;*/
/*my_val = (*(iBuf++) << 8) | (*(iBuf++) & 0xff);*/
PCPos += 2;
break;
default: /* SIZ_LONG */
strcat (Ci.mnem, "l");
my_val = bufReadL(&iBuf);
/*iBuf += 4;*/
/*my_val = (*(iBuf++) << 24) | ((*(iBuf++) & 0xff) << 16) | ((*(iBuf++) & 0xff) << 8) |
(*(iBuf++) & 0xff);*/
PCPos += 4;
}
if ((*refsList)->Extrn)
{
strcpy(Ci.opcode, (*refsList)->EName.nam);
}
else
{
strcpy (Ci.opcode, (*refsList)->EName.lbl->sname);
}
PrintLine(pseudcmd, &Ci, cclass, CmdEnt, CmdEnt);
CmdEnt = PCPos;
Ci.lblname = NULL;
Ci.opcode[0] = '\0';
Ci.mnem[0] = '\0';
/*switch ((*refsList)->Type)
{
case REFGLBL:
strcpy(Ci.opcode, (*refsList)->EName.nam);
break;
case REFLOCAL:
strcpy (Ci.opcode, (*refsList)->EName.lbl->sname);
break;
default:
strcpy (Ci.opcode, "???");
}*/
}
else /* No reference entry for this area */
{
register int bytCount,
bytSize;
if (bytCount = DoAsciiBlock (&Ci, iBuf, blkEnd, cclass))
{
iBuf += bytCount;
continue;
}
else
{
register char *fmt;
switch ((blkEnd - PCPos) % 4)
{
case 0:
bytSize = 4;
bytCount = (blkEnd - PCPos) >> 2;
strcpy (Ci.mnem, "dc.l");
fmt = "$%08x";
break;
case 2:
bytSize = 2;
strcpy (Ci.mnem, "dc.w");
bytCount = (blkEnd - PCPos) >> 1;
fmt = "$%04x";
break;
default:
bytSize = 1;
strcpy (Ci.mnem, "dc.b");
bytCount = blkEnd - PCPos;
fmt = "$%02x";
}
while (bytCount--)
{
int val = 0;
switch (bytSize)
{
case 1:
val = *(iBuf++) & 0xff;
break;
case 4:
/*for (byteNum = 0; byteNum < 4; byteNum++)
{
val = (val << 8) | (*(iBuf++) & 0xff);
}*/
val = bufReadL(&iBuf);
/*iBuf += 4;*/
break;
/*val = ((*(iBuf++) & 0xff) << 8) | (*(iBuf++) & 0xff);
val <<= 16;*/
/* Fall through to the 'word' function to pick up next two bytes */
default:
val = bufReadW(&iBuf);
/*iBuf +=2;*/
/*val = val | ((*(iBuf++) & 0xff) << 8) | (*(iBuf++) & 0xff);*/