This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dismain.c
1181 lines (1014 loc) · 29.7 KB
/
dismain.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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* dismain.c - The main disassembler routine. This handles a single *
* pass for the disassembler routine. For each command, it passes *
* off the job of disassembling that command. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define _MAIN_ /* We will define all variables in one header file, then
define them extern from all other files */
#include <ctype.h>
#include "disglobs.h"
#include "textdef.h"
#include "modtypes.h"
#include <string.h>
#include "proto.h"
int error;
void reflst();
#ifdef _WIN32
# define strcasecmp _stricmp
#endif
#ifdef _OSK
# define strcasecmp strcmp
#endif
/* Some variables that are only used in one or two modules */
int LblFilz; /* Count of Label files specified */
char *LblFNam[MAX_LBFIL]; /* Pointers to the path names for the files */
static int HdrLen;
int CodeEnd;
extern struct databndaries *dbounds;
extern char realcmd[], pseudcmd[];
#ifdef __STDC__
extern void printXtraBytes (char *);
#else
extern void printXtraBytes ();
#endif
static int get_asmcmd(
#ifdef __STDC__
void
#endif
);
/*
* list_print() - Handle printouts of lines of code. Prints to the listing
* and prints to asm code file if specified
*/
static void
#ifdef __STDC__
list_print (CMD_ITMS *ci, short ent, char *lblnam)
#else
list_print (ci, ent, lblnam)
CMD_ITMS *ci;
int ent;
char *lblnam;
#endif
{
register char *ListFmt = "%05x %04x %10.10s %s %s\n";
register char *CmntFmt = "%05x %04x %10.10s %s %s %s\n";
char *lb;
lb = (lblnam ? lblnam : lblstr('L', CmdEnt));
/* When ready, need to provide for option whether to print or not */
if (ci->comment)
{
printf(CmntFmt, ent & 0xffff, ci->cmd_wrd, lb,
ci->mnem, ci->opcode, ci->comment);
}
else
{
printf(ListFmt, ent & 0xffff, ci->cmd_wrd, lb,
ci->mnem, ci->opcode);
}
/* Provide for printing to asm src listing */
}
static char *DrvrJmps[] = {
"Init", "Read", "Write", "GetStat", "SetStat", "Term", "Except", NULL
};
static char *FmanJmps[] = {"Open", "Create", "Makdir", "Chgdir", "Delete", "Seek",
"Read", "Write", "Readln", "Writeln", "Getstat", "Setstat", "Close", NULL};
/* ***********************
* get_drvr_jmps()
* Read the Driver initialization table and set up
* label names.
*/
static void
#ifdef __STDC__
get_drvr_jmps(int mty)
#else
get_drvr_jmps(mty)
int mty;
#endif
{
register char **pt;
register int jmpdst;
int jmpbegin = ftell (ModFP);
char boundstr[50];
if (mty == MT_DEVDRVR)
{
pt = DrvrJmps;
}
else
{
pt = FmanJmps;
}
while (*pt)
{
jmpdst = fread_w(ModFP);
if (jmpdst)
{
addlbl ('L', jmpdst, *pt);
sprintf (boundstr, "L W L %x-%x", jmpbegin, ftell(ModFP) - 1);
}
else
{
sprintf (boundstr, "L W & %x-%x", jmpbegin, ftell(ModFP) - 1);
}
setupbounds (boundstr);
jmpbegin = ftell(ModFP);
++pt;
}
}
/* ****************************************************** *
* Get the module header. We will do this only in Pass 1 *
* ****************************************************** */
static int
get_modhead()
{
/* Get standard (common to all modules) header fields */
M_ID = fread_w(ModFP) & 0xffff;
switch (M_ID)
{
case 0x4afc:
M_SysRev = fread_w(ModFP);
M_Size = fread_l( ModFP);
M_Owner = fread_l(ModFP);
M_Name = fread_l(ModFP);
M_Accs = fread_w(ModFP);
M_Type = fread_b(ModFP);
M_Lang = fread_b(ModFP);
M_Attr = fread_b(ModFP);
M_Revs = fread_b(ModFP);
M_Edit = fread_w(ModFP);
M_Usage = fread_l(ModFP);
M_Symbol = fread_l(ModFP);
/* We have 14 bytes that are not used */
if (fseek(ModFP, 14, SEEK_CUR) != 0)
{
errexit("Cannot Seek to file location");
}
M_Parity = fread_w(ModFP);
/* Now get any further Mod-type specific headers */
switch (M_Type)
{
case MT_PROGRAM:
case MT_SYSTEM:
case MT_TRAPLIB:
case MT_FILEMAN:
case MT_DEVDRVR:
M_Exec = fread_l(ModFP);
/* Add label for Exception Handler, if applicable */
/* Only for specific Module Types??? */
if (M_Except = fread_l(ModFP))
{
addlbl('L', M_Except, "");
}
/* Add btext */
/* applicable for only specific Moule Types??? */
addlbl ('L', 0, "btext");
HdrEnd = ftell(ModFP); /* We'll keep changing it if necessary */
if ((M_Type != MT_SYSTEM) && (M_Type != MT_FILEMAN))
{
M_Mem = fread_l(ModFP);
if (M_Type != MT_DEVDRVR)
{
M_Stack = fread_l(ModFP);
M_IData = fread_l(ModFP);
M_IRefs = fread_l( ModFP);
if (M_Type == MT_TRAPLIB)
{
M_Init = fread_l(ModFP);
M_Term = fread_l(ModFP);
}
}
HdrEnd = ftell(ModFP); /* The final change.. */
}
if ((M_Type == MT_DEVDRVR) || (M_Type == MT_FILEMAN))
{
fseek (ModFP, M_Exec, SEEK_SET);
get_drvr_jmps (M_Type);
}
if (M_IData)
{
fseek (ModFP, M_IData, SEEK_SET);
IDataBegin = fread_l (ModFP);
IDataCount = fread_l (ModFP);
/* Insure we have an entry for the first Initialized Data */
addlbl ('D', IDataBegin, "");
CodeEnd = M_IData;
}
else
{
/* This may be incorrect */
CodeEnd = M_Size - 3;
}
}
fseek (ModFP, 0, SEEK_END);
if (ftell(ModFP) < M_Size)
{
errexit ("\n*** ERROR! File size < Module Size... Aborting...! ***\n");
}
break;
case 0xdead:
getRofHdr(ModFP);
/*errexit("Disassembly of ROF files is not yet implemented.");*/
break;
default:
errexit("Unknown module type");
}
return 0;
}
/*
* modnam_find() - search a modna struct for the desired value
* Returns: On Success: Pointer to the desired value
* On Failure: NULL
*/
struct modnam *
#ifdef __STDC__
modnam_find (struct modnam *pt, int desired)
#else
modnam_find (pt, desired)
struct modnam *pt;
int desired;
#endif
{
while ((pt->val) && (pt->val != desired))
{
++pt;
}
return (pt->val ? pt : NULL);
}
/* ******************************************************************** *
* RdLblFile() - Reads a label file and stores label values into label *
* tree if value (or address) is present in tree *
* Path to file has already been opened and is stored in "inpath" *
* ******************************************************************** */
static void
#ifdef __STDC__
RdLblFile (FILE *inpath)
#else
RdLblFile (inpath)
FILE *inpath;
#endif
{
char labelname[30],
clas,
eq[10],
strval[15],
*lbegin;
int address;
LBLDEF *nl;
while ( ! feof (inpath))
{
char rdbuf[81];
fgets (rdbuf, 80, inpath);
if ( ! (lbegin = skipblank (rdbuf)) || (*lbegin == '*'))
{
continue;
}
if (sscanf (rdbuf, "%s %s %s %c", labelname, eq, strval, &clas) == 4)
{
#ifdef _OSK
register int c;
#endif
clas = toupper (clas);
#ifdef _OSK
for (c = 0; c < 3; c++)
{
eq[c] = _tolower(eq[c]);
}
#endif
if ( ! strcasecmp (eq, "equ"))
{
/* Store address in proper place */
if (strval[0] == '$') /* if represented in hex */
{
sscanf (&strval[1], "%x", &address);
}
else
{
address = atoi (strval);
}
nl = findlbl (clas, address);
if (nl)
{
strncpy (nl->sname, labelname, sizeof(nl->sname) - 1);
nl->sname[sizeof(nl->sname)] = '\0';
nl->stdname = 1;
}
}
}
}
}
/* ******************************************************** *
* GetLabels() - Set up all label definitions *
* Reads in all default label files and then reads *
* any files specified by the '-s' option. *
* ******************************************************** */
static void
GetLabels () /* Read the labelfiles */
{
register int x;
/* First, get built-in ascii definitions. Later, if desired,
* they can be redefined */
/*for (x = 0; x < 33; x++)
{
if ((nl = FindLbl (ListRoot ('^'), x)))
{
strcpy (nl->sname, CtrlCod[x]);
}
}
if ((nl = FindLbl (ListRoot ('^'), 0x7f)))
{
strcpy (nl->sname, "del");
}*/
/* Next read in the Standard systems names file */
/*if ((OSType == OS_9) || (OSType == OS_Moto))
{
tmpnam = build_path ("sysnames");
if ( ! (inpath = fopen (tmpnam, "rb")))
fprintf (stderr, "Error in opening Sysnames file..%s\n",
filename);
else
{
RdLblFile ();
fclose (inpath);
}
}*/
/* Now read in label files specified on the command line */
for (x = 0; x < LblFilz; x++)
{
register FILE *inpath;
if ((inpath = build_path (LblFNam[x], BINREAD)))
{
RdLblFile (inpath);
fclose (inpath);
}
else
{
fprintf (stderr, "ERROR! cannot open Label File %s for read\n",
LblFNam[x]);
}
}
}
/*
* dopass() - Do a complete single pass through the module.
* The first pass establishes the addresses of necessary labels
* On the second pass, the desired label names have been inserted
* and printing of the listing and writing of the source file is
* done, if either or both is desired.
*/
int
#ifdef __STDC__
dopass(int argc,char **argv,int mypass)
#else
dopass(argc,argv,mypass)
int argc;
char **argv;
int mypass;
#endif
{
int sval = 0;
int lval = 0;
int wval = 0;
if (Pass == 1)
{
if (!(ModFP = fopen(ModFile, BINREAD)))
{
errexit("Cannot open Module file for read");
}
PCPos = 0;
get_modhead();
PCPos = ftell(ModFP);
/*process_label(&Instruction, 'L', M_Exec);*/
addlbl ('L', M_Exec, NULL);
/* Set Default Addressing Modes according to Module Type */
switch (M_Type)
{
case MT_PROGRAM:
strcpy(DfltLbls, "&&&&&&D&&&&L");
break;
case MT_DEVDRVR:
/* Init/Term:
(a1)=Device Dscr
Read/Write,Get/SetStat:
(a1)=Path Dscr, (a5)=Caller's Register Stack
All:
(a1)=Path Dscr
(a2)=Static Storage, (a4)=Process Dscr, (a6)=System Globals
(a1) & (a5) default to Read/Write, etc. For Init/Term, specify
AModes for these with Boundary Defs*/
strcpy (DfltLbls, "&ZD&PG&&&&&L");
break;
}
GetIRefs();
do_cmd_file();
setROFPass();
}
else /* Do Pass 2 Setup */
{
/*parsetree ('A');*/
GetLabels();
/* We do this here so that we can rename labels
* to proper names defined in the ROF file
*/
if (IsROF)
{
setROFPass();
RofLoadInitData();
}
WrtEquates (1);
WrtEquates (0);
/*showem();*/
CmdEnt = 0;
if (IsROF)
{
ROFPsect(&ROFHd);
ROFDataPrint();
}
else
{
PrintPsect();
OS9DataPrint();
}
}
/* NOTE: This is just a temporary kludge The begin _SHOULD_ be
the first byte past the end of the header, but until
we get bounds working, we'll do this. */
if (fseek(ModFP, HdrEnd, SEEK_SET) != 0)
{
errexit("FIle Seek Error");
}
if (IsROF)
{
PCPos = 0;
}
else
{
PCPos = HdrEnd;
}
while (PCPos < CodeEnd)
{
struct databndaries *bp;
memset(&Instruction, 0, sizeof(Instruction));
CmdEnt = PCPos;
/* NOTE: The 6809 version did an "if" and it apparently worked,
* but we had to do this to get it to work with consecutive bounds.
*/
while (bp = ClasHere (dbounds, PCPos))
{
NsrtBnds (bp);
CmdEnt = PCPos;
}
if (get_asmcmd())
{
if (Pass == 2)
{
/*PrintComment('L', CmdEnt, PCPos);*/
Instruction.comment = get_apcomment ('L', CmdEnt);
/*list_print (&Instruction, CmdEnt, NULL);*/
PrintLine (pseudcmd, &Instruction, 'L', CmdEnt, PCPos);
if (PrintAllCode && Instruction.wcount)
{
int count = Instruction.wcount;
char codbuf[50];
int wpos = 0;
/*printf("%6s", "");*/
codbuf[0] = '\0';
while (count)
{
char tmpcod[10];
sprintf (tmpcod, "%04x ", (unsigned short)Instruction.code[wpos++]);
strcat (codbuf, tmpcod);
--count;
// if (count > 1)
// {
// PrintAllCodLine(Instruction.code[wpos],
// Instruction.code[wpos + 1]);
// count -= 2;
// wpos += 2;
// }
// else
// {
// PrintAllCodL1(Instruction.code[wpos]);
// --count;
// ++wpos;
// }
/*printf("%04x ", Instruction.code[count] & 0xffff);*/
}
printXtraBytes (codbuf);
}
}
}
else
{
if (Pass == 2)
{
strcpy (Instruction.mnem, "dc.w");
sprintf (Instruction.opcode, "$%x",
Instruction.cmd_wrd & 0xffff);
PrintLine (pseudcmd, &Instruction, 'L', CmdEnt, PCPos);
CmdEnt = PCPos;
/*list_print (&Instruction, CmdEnt, NULL);*/
}
}
}
if (Pass == 2)
{
WrtEnds();
}
/*reflst();*/
return 0;
}
extern struct rof_extrn *refs_code;
int showem()
{
char c = '_';
struct rof_extrn *rf = refs_code;
LBLCLAS *l = labelclass(c);
if (!rf)
fprintf(stderr, "No Code refs found!\n");
while (rf)
{
fprintf (stderr, "%04x: -> (%03x '%c') \"%-14s\" (%s)\n", rf->Ofst, rf->Type,
rf->dstClass ? rf->dstClass : ' ', rf->Extrn ? rf->EName.nam : rf->EName.lbl->sname,
rf->Extrn ? "Extern" : "Local");
rf = rf->ENext;
}
return 0;
}
static CMD_ITMS *
#ifdef __STDC__
initcmditems (CMD_ITMS *ci)
#else
initcmditems (ci)
CMD_ITMS *ci;
#endif
{
ci->mnem[0] = 0;
ci->wcount = 0;
ci->opcode[0] ='\0';
ci->comment = NULL;
return ci;
}
/*
* noimplemented() - A dummy function which simply returns NULL for instructions
* that do not yet have handler functions
*/
int
#ifdef __STDC__
notimplemented(CMD_ITMS *ci, int tblno, OPSTRUCTURE *op)
#else
notimplemented (ci, tblno, op)
CMD_ITMS *ci;
int tblno;
OPSTRUCTURE *op;
#endif
{
return 0;
}
/*extern OPSTRUCTURE *instr00,*instr01,*instr04,*instr05,*instr06,
*instr07,*instr08,*instr09,*instr11,*instr12,*instr13,*instr14;*/
OPSTRUCTURE *opmains[] =
{
instr00,
instr01,
instr02, /* Repeat 3 times for 3 move sizes */
instr03,
instr04,
instr05,
instr06,
instr07,
instr08,
instr09,
NULL, /* No instr 010 */
instr11,
instr12,
instr13,
instr14,
NULL
};
static int
get_asmcmd()
{
/*extern OPSTRUCTURE syntax1[];
extern COPROCSTRUCTURE syntax2[];*/
register OPSTRUCTURE *optbl;
int opword;
int j;
int size;
size = 0;
Instruction.wcount = 0;
opword = getnext_w (&Instruction);
/* Make adjustments for this being the command word */
Instruction.cmd_wrd = Instruction.code[0] & 0xffff;
Instruction.wcount = 0; /* Set it back again */
/* This may be temporary. Opword %1111xxxxxxxxxxxx is available
* for 68030-68040 CPU's, but we are not yet making this available
*/
if ((opword & 0xf000) == 0xf000)
return 0;
if (!(optbl = opmains[(opword >> 12) & 0x0f]))
{
return 0;
}
for (j = 0; j <= MAXINST; j++)
{
OPSTRUCTURE *curop = &optbl[j];
error = FALSE;
if (!(curop->name))
break;
curop = tablematch (opword, curop);
/* The table must be organized such that the "cpulvl" field
* is sorted in ascending order. Therefore, if a "cpulvl"
* higher than "cpu" is encountered we can abort the search.
*/
if (curop->cpulvl > cpu)
{
return 0;
}
if (!error)
{
if (curop->opfunc(&Instruction, curop->id, curop))
{
return 1;
}
else
{
if (ftell(ModFP) != RealEnt() + 2)
{
fseek(ModFP, RealEnt() + 2, SEEK_SET);
PCPos = CmdEnt + 2;
initcmditems(&Instruction);
}
}
}
}
#if (DEVICE==68040 || COPROCESSOR==TRUE)
for (h = 3; h <= MAXCOPROCINST; h++)
{
error = FALSE;
j = fpmatch (start);
if (!error)
{
size = disassembleattempt (start, j);
if (size != 0)
break;
}
}
#endif
/* if (size == 0)
{
printf ("\n%c%8x", HEXDEL, start);
printf (" %4X\t\t DC.W", get16 (start));
printf (" \t\t? ");
return (2);
}
else
return (size);*/
return 0;
}
/* ******************************************************************** *
* MovBytes() - Reads data for Data Boundary range from input file and *
* places it onto the print buffer (and does any applicable *
* printing if in pass 2). *
* ******************************************************************** */
void
#ifdef __STDC__
MovBytes (struct databndaries *db)
#else
MovBytes (db)
struct databndaries *db;
#endif
{
CMD_ITMS Ci;
char tmps[20];
unsigned int valu;
int bmask;
#ifdef _OSK
static
#endif
char *xFmt[3] = {"$%02x", "$%04x", "$%08x"};
char xtrabytes[50];
int cCount = 0,
maxLst;
char *xtrafmt;
CmdEnt = PCPos;
/* This may be temporary, and we may set PBytSiz
* to the appropriate value */
*xtrabytes = '\0';
strcpy (Ci.mnem, "dc");
Ci.opcode[0] = '\0';
Ci.lblname = "";
Ci.comment = NULL;
Ci.cmd_wrd = 0;
PBytSiz = db->b_siz;
if (PBytSiz < 4)
{
xtrafmt = "%02x";
}
else
{
xtrafmt = "%04x";
}
switch (PBytSiz)
{
case 1:
strcat (Ci.mnem, ".b");
maxLst = 4;
bmask = 0xff;
break;
case 2:
strcat (Ci.mnem, ".w");
maxLst = 2;
bmask = 0xffff;
break;
case 4:
strcat (Ci.mnem, ".l");
maxLst = 1;
bmask = 0xffff;
break;
}
while (PCPos <= db->b_hi)
{
/* Init dest buffer to null string for LblCalc concatenation */
tmps[0] = '\0';
switch (PBytSiz)
{
case 1:
valu = fread_b(ModFP);
break;
case 2:
valu = fread_w (ModFP);
break;
case 4:
valu = fread_l (ModFP);
break;
}
PCPos += db->b_siz;
++cCount;
/*process_label (&Ci, AMode, valu);*/
LblCalc (tmps, valu, AMode, PCPos - db->b_siz);
if (Pass == 2)
{
char tmpval[10];
if (cCount == 0)
{
Ci.cmd_wrd = valu & bmask;
}
else if (cCount < maxLst)
{
Ci.cmd_wrd = ((Ci.cmd_wrd << (PBytSiz * 8)) | (valu & bmask));
}
else
{
sprintf (tmpval, xtrafmt, valu & bmask);
strcat (xtrabytes, tmpval);
}
++cCount;
if (strlen(Ci.opcode))
{
strcat (Ci.opcode, ",");
}
strcat (Ci.opcode, tmps);
/* If length of operand string is max, print a line */
if ( (strlen (Ci.opcode) > 22) || findlbl ('L', PCPos))
{
PrintLine(pseudcmd, &Ci, 'L', CmdEnt, PCPos);
if (strlen(xtrabytes))
{
printXtraBytes (xtrabytes);
}
Ci.opcode[0] = '\0';
Ci.cmd_wrd = 0;
Ci.lblname = NULL;
CmdEnt = PCPos/* _ PBytSiz*/;
cCount = 0;
}
}
/*PCPos += PBytSiz;*/
}
/* Loop finished.. print any unprinted data */
if ((Pass == 2) && strlen (Ci.opcode))
{
PrintLine (pseudcmd, &Ci, 'L', CmdEnt, PCPos);
if (strlen(xtrabytes))
{
printXtraBytes (xtrabytes);
}
}
}
/* ******************************************
* MovAsc() - Move nb byes fordcb" statement
*/
void
#ifdef __STDC__
MovASC (int nb, char aclass)
#else
MovASC (nb, aclass)
int nb;
char aclass;
#endif
{
char oper_tmp[30];
CMD_ITMS Ci;
int cCount = 0;
strcpy (Ci.mnem, "dc.b"); /* Default mnemonic to "fcc" */
CmdEnt = PCPos;
*oper_tmp = '\0';
Ci.cmd_wrd = 0;
Ci.comment = NULL;
Ci.lblname = "";
while (nb--)
{
register int x;
char c[6];
if ((strlen (oper_tmp) > 24) ||
(strlen (oper_tmp) && findlbl (aclass, PCPos)))
/*(strlen (oper_tmp) && findlbl (ListRoot (aclass), PCPos + 1)))*/
{
sprintf (Ci.opcode, "\"%s\"", oper_tmp);
PrintLine (pseudcmd, &Ci, 'L', CmdEnt, PCPos);
oper_tmp[0] = '\0';
CmdEnt = PCPos;
Ci.lblname = "";
Ci.cmd_wrd = 0;
Ci.wcount = 0;
cCount = 0;
}
x = fgetc (ModFP);