From 09bd535fe29912de796e1df3a41a6bc388fee30b Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 30 Nov 2018 22:31:22 +0000 Subject: [PATCH] raw2dsk: make a raw image into a 40 track Amstrad / Spectrum image --- Kernel/cpu-z80/image.mk | 4 +- Kernel/tools/raw2dsk.c | 92 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Kernel/tools/raw2dsk.c diff --git a/Kernel/cpu-z80/image.mk b/Kernel/cpu-z80/image.mk index f98eb6b1..63a44701 100644 --- a/Kernel/cpu-z80/image.mk +++ b/Kernel/cpu-z80/image.mk @@ -25,6 +25,8 @@ tools/makedck: tools/makedck.c tools/plus3boot: tools/plus3boot.c +tools/raw2dsk: tools/raw2dsk.c + tools/raw2mgt: tools/raw2mgt.c tools/bankld/sdldz80: @@ -40,7 +42,7 @@ tools/trslabel: tools/trslabel.c fuzix.ihx: target $(OBJS) platform-$(TARGET)/fuzix.lnk tools/bankld/sdldz80 $(CROSS_LD) -n -k $(LIBZ80) -f platform-$(TARGET)/fuzix.lnk -fuzix.bin: fuzix.ihx tools/bihx tools/analysemap tools/memhogs tools/binman tools/bintomdv tools/binmunge tools/bin2sna tools/bin2z80 cpm-loader/cpmload.bin tools/flat2z80 tools/makejv3 tools/trslabel tools/visualize tools/raw2mgt tools/cartman tools/makedck tools/plus3boot +fuzix.bin: fuzix.ihx tools/bihx tools/analysemap tools/memhogs tools/binman tools/bintomdv tools/binmunge tools/bin2sna tools/bin2z80 cpm-loader/cpmload.bin tools/flat2z80 tools/makejv3 tools/trslabel tools/visualize tools/raw2dsk tools/raw2mgt tools/cartman tools/makedck tools/plus3boot -cp hogs.txt hogs.txt.old tools/memhogs hogs.txt head -5 hogs.txt diff --git a/Kernel/tools/raw2dsk.c b/Kernel/tools/raw2dsk.c new file mode 100644 index 00000000..dfcf5e7d --- /dev/null +++ b/Kernel/tools/raw2dsk.c @@ -0,0 +1,92 @@ +#include +#include +#include + +/* Turn a raw image into a DSK file + + Our input is raw sector data single sided, our output is a 40 track + spectrum +3 image we hope + + 9 sectors per track MFM, 40 tracks, single side (flippy) + + We want this to work in the +3 with 3" drive - the 80 track and double + side options only came in later add on drives */ + +int main(int argc, char *argv[]) +{ + FILE *in, *out; + static unsigned char buf[512 * 9]; + unsigned char *bp; + int track, sector; + + strcpy(buf, "MV - CPCEMU Disk-File\r\nDisk-Info\r\n"); + buf[0x30] = 40; + buf[0x31] = 1; + buf[0x32] = 0; + buf[0x33] = 13; + + if (argc != 3) { + fprintf(stderr, "%s: source dest.\n", argv[0]); + exit(1); + } + + in = fopen(argv[1], "r"); + if (in == NULL) { + perror(argv[1]); + exit(1); + } + out = fopen(argv[2], "w"); + if (out == NULL) { + perror(argv[2]); + exit(1); + } + + /* Write the header */ + if (fwrite(buf, 256, 1, out) != 1) { + perror(argv[2]); + exit(1); + } + for (track = 0; track < 40; track++) { + /* Generate the track header */ + memset(buf, 0, 512); + strcpy(buf, "Track-Info\r\n"); + buf[0x10] = track; + buf[0x11] = 0; + buf[0x14] = 2; + buf[0x15] = 9; + buf[0x16] = 0x4E; + buf[0x17] = 0xE5; + bp = buf + 0x18; + for (sector = 1; sector < 10; sector++) { + *bp++ = track; + *bp++ = 0; + *bp++ = sector; + *bp++ = 2; + *bp++ = 0; + *bp++ = 0; + *bp++ = 0; + *bp++ = 0; + } + if (fwrite(buf, 256, 1, out) != 1) { + perror(argv[2]); + exit(1); + } + if (fread(buf, 512, 9, in) != 9) { + perror(argv[1]); + exit(1); + } + if (fwrite(buf, 512, 9, out) != 9) { + perror(argv[2]); + exit(1); + } + } + if (fclose(in)) { + perror(argv[1]); + exit(1); + } + if (fclose(out)) { + perror(argv[2]); + exit(1); + } + exit(0); +} -- 2.34.1