Skip to content

Commit da75b51

Browse files
committed
Make it possible to write disassembly to destinations other than stdout.
1 parent 7adc8c1 commit da75b51

16 files changed

+148
-138
lines changed

dis.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ spaces (int n)
293293
int i;
294294

295295
for (i = 0; i < n; i++)
296-
putchar (' ');
296+
fputc (' ', output_file);
297297

298298
return i < 0 ? 0 : i;
299299
}
@@ -383,11 +383,11 @@ dis (struct pdp10_memory *memory, int cpu_model)
383383
while ((word = get_next_word (memory)) != -1)
384384
{
385385
if (word & START_TAPE)
386-
printf ("Logical end of tape.\n");
386+
fprintf (output_file, "Logical end of tape.\n");
387387
else if (word & START_FILE)
388-
printf ("Start of file.\n");
388+
fprintf (output_file, "Start of file.\n");
389389
else if (word & START_RECORD)
390-
printf ("Start of record.\n");
390+
fprintf (output_file, "Start of record.\n");
391391
disassemble_word (memory, word & mask, get_address (memory), cpu_model);
392392
}
393393
}
@@ -407,13 +407,13 @@ print_val (const char *format, int field, int hint)
407407

408408
sym = get_symbol_by_value (field, hint);
409409
if (sym == NULL)
410-
n += printf ("%o", field);
410+
n += fprintf (output_file, "%o", field);
411411
else
412-
n += printf ("%s", sym->name);
412+
n += fprintf (output_file, "%s", sym->name);
413413
}
414414
else
415415
{
416-
n += printf ("%c", *p);
416+
n += fprintf (output_file, "%c", *p);
417417
}
418418
}
419419

@@ -461,14 +461,14 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
461461

462462
sym = get_symbol_by_value (address, HINT_ADDRESS);
463463
if (sym != NULL)
464-
printf ("%s:\n", sym->name);
464+
fprintf (output_file, "%s:\n", sym->name);
465465

466466
if (address == -1)
467-
printf (" ");
467+
fprintf (output_file, " ");
468468
else
469-
printf ("%06o: ", address);
469+
fprintf (output_file, "%06o: ", address);
470470

471-
printf ("%012llo ", word);
471+
fprintf (output_file, "%012llo ", word);
472472

473473
n = 0;
474474

@@ -480,7 +480,7 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
480480
/* If no opcode found and left half is 0, print as symbol. */
481481
sym = get_symbol_by_value (Y (word), HINT_ADDRESS);
482482
if (sym != NULL)
483-
n += printf ("%s", sym->name);
483+
n += fprintf (output_file, "%s", sym->name);
484484
}
485485
}
486486
else if ((cpu_model & PDP10_ITS) && OPCODE (word) == ITS_OPER)
@@ -489,7 +489,7 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
489489
oper = lookup_oper (word, opers, sizeof opers / sizeof opers[0]);
490490
if (oper)
491491
{
492-
n += printf ("%-8s ", oper->name);
492+
n += fprintf (output_file, "%-8s ", oper->name);
493493
if (oper->hint == HINT_CHANNEL || A (word) != 0)
494494
n += print_val ("%o,", A (word), oper->hint);
495495
}
@@ -501,7 +501,7 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
501501
sizeof waits_callis / sizeof waits_callis[0]);
502502
if (calli)
503503
{
504-
n += printf ("%-8s ", calli->name);
504+
n += fprintf (output_file, "%-8s ", calli->name);
505505
if (calli->hint == HINT_CHANNEL || A (word) != 0)
506506
n += print_val ("%o,", A (word), calli->hint);
507507
}
@@ -511,14 +511,14 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
511511
{
512512
int address;
513513

514-
n += printf ("%-8s ", ".call");
514+
n += fprintf (output_file, "%-8s ", ".call");
515515

516516
address = calc_e (memory, word);
517517
if (address == -1 ||
518518
get_word_at (memory, address) != SETZ)
519519
{
520520
if (I (word))
521-
n += printf ("@");
521+
n += fprintf (output_file, "@");
522522
n += print_val ("%o", Y (word), HINT_ADDRESS);
523523
if (X (word))
524524
n += print_val ("(%o)", X (word), HINT_ACCUMULATOR);
@@ -530,31 +530,31 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
530530
word_t w;
531531

532532
n = 0;
533-
printf ("[setz\n");
533+
fprintf (output_file, "[setz\n");
534534
w = get_word_at (memory, address + 1);
535535
sixbit_to_ascii (w, name);
536-
printf (" SIXBIT/%s/\n", name);
536+
fprintf (output_file, " SIXBIT/%s/\n", name);
537537
i = 2;
538538
while (((w = get_word_at (memory, address + i)) & SIGNBIT) == 0)
539539
{
540-
printf (" %012llo\n", w);
540+
fprintf (output_file, " %012llo\n", w);
541541
i++;
542542
}
543-
printf (" %012llo]\n", w);
544-
printf (" ");
543+
fprintf (output_file, " %012llo]\n", w);
544+
fprintf (output_file, " ");
545545
}
546546
}
547547
#endif
548548
else
549549
{
550-
n += printf ("%-8s ", op->name);
550+
n += fprintf (output_file, "%-8s ", op->name);
551551

552552
if (op->type & PDP10_IO)
553553
{
554554
const struct pdp10_device *dev;
555555
dev = lookup_device (DEVICE (word), cpu_model);
556556
if (dev != NULL)
557-
n += printf ("%s, ", dev->name);
557+
n += fprintf (output_file, "%s, ", dev->name);
558558
else
559559
n += print_val ("%o, ", DEVICE (word), HINT_DEVICE);
560560
}
@@ -576,15 +576,15 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
576576
if (E (word) != 0 || !(op->type & PDP10_E_UNUSED))
577577
{
578578
if (I (word))
579-
n += printf ("@");
579+
n += fprintf (output_file, "@");
580580

581581
if (op->addr_hint == HINT_FLOAT && X (word) == 0)
582582
{
583583
const struct symbol *sym = get_symbol_by_value (Y (word), hint);
584584
if (sym == NULL)
585-
n += printf ("(%f)", immediate_float (Y (word)));
585+
n += fprintf (output_file, "(%f)", immediate_float (Y (word)));
586586
else
587-
n += printf ("%s", sym->name);
587+
n += fprintf (output_file, "%s", sym->name);
588588
}
589589
else if (Y (word) != 0 && X (word) != 0)
590590
n += print_val ("%o", Y (word), HINT_OFFSET);
@@ -607,21 +607,21 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
607607
{
608608
int t = instruction_time (word, PDP10_KI10);
609609
if (t > 0)
610-
printf (";%5dns", t);
610+
fprintf (output_file, ";%5dns", t);
611611
else
612612
spaces (8);
613613
}
614614
#endif
615615

616616
#if 1
617617
/* Print word as six SIXBIT characters. */
618-
printf (";\"");
618+
fprintf (output_file, ";\"");
619619
for (i = 0; i < 6; i++)
620620
{
621621
int c = (int)(word >> (6 * (5 - i))) & 077;
622-
putchar (c + ' ');
622+
fputc (c + ' ', output_file);
623623
}
624-
putchar ('"');
624+
fputc ('"', output_file);
625625
#endif
626626

627627
#if 1
@@ -668,51 +668,51 @@ disassemble_word (struct pdp10_memory *memory, word_t word,
668668

669669
if (printable)
670670
{
671-
printf (" \"");
671+
fprintf (output_file, " \"");
672672
for (i = 0; i < 5; i++)
673673
{
674674
switch (ch[i])
675675
{
676676
case '\0':
677-
printf ("\\0");
677+
fprintf (output_file, "\\0");
678678
break;
679679
case '\t':
680-
printf ("\\t");
680+
fprintf (output_file, "\\t");
681681
break;
682682
case '\n':
683-
printf ("\\n");
683+
fprintf (output_file, "\\n");
684684
break;
685685
case '\f':
686-
printf ("\\f");
686+
fprintf (output_file, "\\f");
687687
break;
688688
case '\r':
689-
printf ("\\r");
689+
fprintf (output_file, "\\r");
690690
break;
691691
case '\\':
692-
printf ("\\\\");
692+
fprintf (output_file, "\\\\");
693693
break;
694694
case '\"':
695-
printf ("\\\"");
695+
fprintf (output_file, "\\\"");
696696
break;
697697
default:
698698
if (ch[i] < 040 || ch[i] > 0176)
699-
printf ("\\%03o", ch[i]);
699+
fprintf (output_file, "\\%03o", ch[i]);
700700
else
701-
putchar (ch[i]);
701+
fputc (ch[i], output_file);
702702
break;
703703
}
704704
}
705-
printf ("\"");
705+
fprintf (output_file, "\"");
706706
}
707707
#endif
708708

709709
#if 0
710710
/* Print word as six SQUOZE characters. */
711711
squoze_to_ascii (word, ch);
712-
printf (" \"%s\"", ch);
712+
fprintf (output_file, " \"%s\"", ch);
713713
#endif
714714

715-
printf ("\n");
715+
fprintf (output_file, "\n");
716716
}
717717

718718
void

dis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ typedef long long word_t;
3434
#define JRST_1 (JRST + 1)
3535
#define JUMPA ((word_t)(0324000000000LL))
3636

37-
struct FILE;
3837
struct pdp10_file;
3938
struct pdp10_memory;
4039
extern word_t start_instruction;
40+
extern FILE *output_file;
4141

4242
struct file_format {
4343
const char *name;

dmp-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
static void
2323
read_dmp (FILE *f, struct pdp10_memory *memory, int cpu_model)
2424
{
25-
printf ("DMP format\n");
25+
fprintf (output_file, "DMP format\n");
2626

2727
read_raw_at (f, memory, 074);
2828

dskdmp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ main (int argc, char **argv)
341341
exit (1);
342342
}
343343

344+
output_file = stdout;
345+
344346
f = fopen (argv[1], "rb");
345347

346348
buffer = image;

0 commit comments

Comments
 (0)