From: Alan Cox Date: Tue, 6 Jan 2015 23:06:15 +0000 (+0000) Subject: trslabel: initial quick hack volume labeller for TRS80 volumes X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=0fad2d944f14dde990ea95776abefa3d2269454d;p=FUZIX.git trslabel: initial quick hack volume labeller for TRS80 volumes --- diff --git a/Kernel/tools/trslabel.c b/Kernel/tools/trslabel.c new file mode 100644 index 00000000..6a4f5e79 --- /dev/null +++ b/Kernel/tools/trslabel.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include "../include/diskgeom.h" + +struct minipart_lba p; +unsigned char buf[256]; +FILE *vol; + +int main(int argc, const char *argv[]) { + if (argc != 2) { + fprintf(stderr, "%s: diskimage\n", argv[0]); + exit(1); + } + vol = fopen(argv[1], "r+"); + if (vol == NULL) { + perror(argv[1]); + exit(1); + } + if (fread(buf, 256, 1, vol) != 1) { + fprintf(stderr, "%s: failed to read header.\n", argv[1]); + exit(1); + } + if(buf[0] != 0x56 || buf[1] != 0xCB || buf[2] != 0x10 || buf[4] != 1 || buf[6]) { + fprintf(stderr, "%s: not a Reed 1.0 format hard disc volume.\n", argv[1]); + exit(1); + } + + memset(&p, 0xFF, sizeof(p)); + p.g.magic = MP_SIG_0; + p.g.cyl = buf[28] | (buf[29] << 8); + p.g.head = buf[30]; + printf("Disk is %d cylinders, %d heads\n", p.g.cyl, p.g.head); + p.g.sec = 16; + p.g.precomp = 0; + p.g.land = p.g.cyl + 1; + p.g.seek = 0; + p.g.secsize = 8; + + p.cyl[0] = 0; + p.cyl[1] = p.g.cyl - 32; + p.type[0] = 0x55; + p.type[1] = 0x56; + + /* FIXME: should fill in matching LBA bits */ + + if (fseek(vol, 512 + 384L, SEEK_SET) < 0) { + perror(argv[1]); + exit(1); + } + if(fwrite(&p, 64, 1, vol) != 1) { + fprintf(stderr, "%s: unable to write minipart\n"); + exit(1); + } + fclose(vol); +}