|
| 1 | +/* Copyright (C) 2022 Lars Brinkhoff <lars@nocrew.org> |
| 2 | +
|
| 3 | + This program is free software: you can redistribute it and/or modify |
| 4 | + it under the terms of the GNU General Public License as published by |
| 5 | + the Free Software Foundation, either version 2 of the License, or |
| 6 | + (at your option) any later version. |
| 7 | +
|
| 8 | + This program is distributed in the hope that it will be useful, |
| 9 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + GNU General Public License for more details. |
| 12 | +
|
| 13 | + You should have received a copy of the GNU General Public License |
| 14 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 15 | + |
| 16 | +#include <stdio.h> |
| 17 | +#include <unistd.h> |
| 18 | +#include <string.h> |
| 19 | + |
| 20 | +#include "dis.h" |
| 21 | +#include "memory.h" |
| 22 | + |
| 23 | +#define FBLOCK 04 /* First block to write on tape. */ |
| 24 | +#define LBLOCK 01077 /* Maximum last block to write. */ |
| 25 | +#define FIRST 010 /* First location to dump-1. */ |
| 26 | + |
| 27 | +#define TAPE_BLOCKS 01102 |
| 28 | +#define BLOCK_WORDS 128 |
| 29 | + |
| 30 | +static word_t image[TAPE_BLOCKS * BLOCK_WORDS]; |
| 31 | +static int verbose; |
| 32 | + |
| 33 | +static word_t * |
| 34 | +get_block (int block) |
| 35 | +{ |
| 36 | + return &image[block * BLOCK_WORDS]; |
| 37 | +} |
| 38 | + |
| 39 | +static void |
| 40 | +write_block (FILE *f, int n, int size) |
| 41 | +{ |
| 42 | + int i; |
| 43 | + word_t *x = get_block (n); |
| 44 | + for (i = 0; i < size; i++) |
| 45 | + write_word (f, *x++); |
| 46 | +} |
| 47 | + |
| 48 | +static void |
| 49 | +load_file (FILE *f, struct pdp10_memory *memory) |
| 50 | +{ |
| 51 | + init_memory (memory); |
| 52 | + input_file_format->read (f, memory, 0); |
| 53 | + rewind_word (f); |
| 54 | +} |
| 55 | + |
| 56 | +static void |
| 57 | +copy_file (char *name) |
| 58 | +{ |
| 59 | + struct pdp10_memory memory; |
| 60 | + word_t word; |
| 61 | + FILE *f; |
| 62 | + int i, end; |
| 63 | + |
| 64 | + f = fopen (name, "rb"); |
| 65 | + if (f == NULL) |
| 66 | + { |
| 67 | + fprintf (stderr, "Error opening file %s.\n", name); |
| 68 | + exit (1); |
| 69 | + } |
| 70 | + |
| 71 | + load_file (f, &memory); |
| 72 | + end = memory.area[memory.areas-1].end; |
| 73 | + if (end > BLOCK_WORDS * ((LBLOCK - FBLOCK) + 1)) |
| 74 | + { |
| 75 | + fprintf (stderr, "Program too large: %o\n", end); |
| 76 | + exit (1); |
| 77 | + } |
| 78 | + |
| 79 | + for (i = FIRST + 1; i < end; i++) |
| 80 | + { |
| 81 | + word = get_word_at (&memory, i); |
| 82 | + if (word == -1) |
| 83 | + word = 0; |
| 84 | + image[BLOCK_WORDS * FBLOCK + i - FIRST - 1] = word; |
| 85 | + } |
| 86 | + |
| 87 | + fclose (f); |
| 88 | +} |
| 89 | + |
| 90 | +static void |
| 91 | +usage (const char *x) |
| 92 | +{ |
| 93 | + fprintf (stderr, "Usage: %s [-v] [-W<word format>] [-F<file format>] <tape> <file>\n", x); |
| 94 | + exit (1); |
| 95 | +} |
| 96 | + |
| 97 | +int |
| 98 | +main (int argc, char **argv) |
| 99 | +{ |
| 100 | + int i; |
| 101 | + FILE *f; |
| 102 | + int opt; |
| 103 | + |
| 104 | + input_file_format = &csave_file_format; |
| 105 | + input_word_format = &aa_word_format; |
| 106 | + output_word_format = &dta_word_format; |
| 107 | + verbose = 0; |
| 108 | + |
| 109 | + output_file = fopen ("/dev/null", "w"); |
| 110 | + |
| 111 | + while ((opt = getopt (argc, argv, "vF:W:")) != -1) |
| 112 | + { |
| 113 | + switch (opt) |
| 114 | + { |
| 115 | + case 'v': |
| 116 | + verbose++; |
| 117 | + break; |
| 118 | + case 'W': |
| 119 | + if (parse_input_word_format (optarg)) |
| 120 | + usage (argv[0]); |
| 121 | + break; |
| 122 | + case 'F': |
| 123 | + if (parse_input_file_format (optarg)) |
| 124 | + usage (argv[0]); |
| 125 | + break; |
| 126 | + default: |
| 127 | + usage (argv[0]); |
| 128 | + break; |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + if (optind + 2 != argc) |
| 133 | + usage (argv[0]); |
| 134 | + |
| 135 | + f = fopen (argv[optind], "wb"); |
| 136 | + if (f == NULL) |
| 137 | + { |
| 138 | + fprintf (stderr, "Error opening tape image file %s\n", argv[optind]); |
| 139 | + exit (1); |
| 140 | + } |
| 141 | + |
| 142 | + memset (image, 0, sizeof image); |
| 143 | + |
| 144 | + copy_file (argv[optind+1]); |
| 145 | + |
| 146 | + for (i = 0; i < TAPE_BLOCKS; i++) |
| 147 | + write_block (f, i, BLOCK_WORDS); |
| 148 | + fclose (f); |
| 149 | + |
| 150 | + return 0; |
| 151 | +} |
0 commit comments