|
| 1 | +/* Copyright (C) 2021 Lars Brinkhoff <[email protected]> |
| 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 "dis.h" |
| 18 | + |
| 19 | +/* The binary output from CROSS is formatted into blocks, with a |
| 20 | +header of three words describing its type, length, and address. After |
| 21 | +the data bytes comes a filler byte (or checksum, but it's always |
| 22 | +zero). |
| 23 | +
|
| 24 | +An Atari DOS binary file is also formatted into blocks. The file |
| 25 | +begins with two FF bytes, and then each block header has start and end |
| 26 | +address (inclusive). */ |
| 27 | + |
| 28 | +static unsigned char buf[4]; |
| 29 | +static int n = 0; |
| 30 | + |
| 31 | +static void refill (FILE *f) |
| 32 | +{ |
| 33 | + word_t word = get_word (f); |
| 34 | + if (word == -1) |
| 35 | + exit (0); |
| 36 | + |
| 37 | + buf[3] = (word >> 18) & 0377; |
| 38 | + buf[2] = (word >> 26) & 0377; |
| 39 | + buf[1] = (word >> 0) & 0377; |
| 40 | + buf[0] = (word >> 8) & 0377; |
| 41 | + n = 4; |
| 42 | +} |
| 43 | + |
| 44 | +static int get_8 (FILE *f) |
| 45 | +{ |
| 46 | + if (n == 0) |
| 47 | + refill (f); |
| 48 | + |
| 49 | + return buf[--n]; |
| 50 | +} |
| 51 | + |
| 52 | +static int get_16 (FILE *f) |
| 53 | +{ |
| 54 | + int word; |
| 55 | + word = get_8 (f); |
| 56 | + word |= get_8 (f) << 8; |
| 57 | + return word; |
| 58 | +} |
| 59 | + |
| 60 | +static void out_8 (int word) |
| 61 | +{ |
| 62 | + putchar (word & 0xFF); |
| 63 | +} |
| 64 | + |
| 65 | +static void out_16 (int word) |
| 66 | +{ |
| 67 | + out_8 (word & 0xFF); |
| 68 | + out_8 (word >> 8); |
| 69 | +} |
| 70 | + |
| 71 | +static void block (FILE *f) |
| 72 | +{ |
| 73 | + int i, type, length, address; |
| 74 | + |
| 75 | + type = get_16 (f); |
| 76 | + length = get_16 (f); |
| 77 | + address = get_16 (f); |
| 78 | + |
| 79 | + fprintf (stderr, "Type %d, length %d, address %04x\n", |
| 80 | + type, length, address); |
| 81 | + |
| 82 | + out_16 (address); |
| 83 | + out_16 (address + length - 1); |
| 84 | + |
| 85 | + for (i = 0; i < length; i++) |
| 86 | + out_8 (get_8 (f)); |
| 87 | + |
| 88 | + get_8 (f); |
| 89 | +} |
| 90 | + |
| 91 | +int main (void) |
| 92 | +{ |
| 93 | + input_word_format = &its_word_format; |
| 94 | + |
| 95 | + out_16 (0xFFFF); |
| 96 | + |
| 97 | + for (;;) |
| 98 | + block (stdin); |
| 99 | + |
| 100 | + return 0; |
| 101 | +} |
0 commit comments