From: Alan Cox Date: Wed, 10 Oct 2018 21:16:55 +0000 (+0100) Subject: chmem: remove dead comment X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c381938c6ab7ca5abb795dfd722cd06957f96403;p=FUZIX.git chmem: remove dead comment --- diff --git a/Applications/util/chmem.c b/Applications/util/chmem.c new file mode 100644 index 00000000..915a96b7 --- /dev/null +++ b/Applications/util/chmem.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + int v; + FILE *fp; + unsigned char buf[10]; + unsigned short top; + uint8_t be; + + if (argc != 2 && argc != 3) { + fprintf(stderr, "%s [executable] {size}\n", argv[0]); + exit(1); + } + if (argc == 2) + fp = fopen(argv[1], "r"); + else + fp = fopen(argv[1], "r+"); + if (fp == NULL) { + perror(argv[1]); + exit(1); + } + if (fread(buf, 10, 1, fp) != 1) { + fprintf(stderr, "%s: too short ?\n", argv[0]); + exit(1); + } + if (buf[3] != 'F' || buf[4] != 'Z'|| buf[5] != 'X' || + buf[6] != '1') { + fprintf(stderr, "%s: not a Fuzix binary format.\n", argv[1]); + exit(1); + } + if (buf[3] == 0x7E || buf[3] == 0x20) + be = 1; /* 6809 */ + else if (buf[3] == 0x4C || buf[3] == 0x38) + be = 0; /* 6502 */ + else if (buf[3] == 0xC3 || buf[3] == 0x18) + be = 0; /* Z80 */ + else { + fprintf(stderr, "%s: unknown Fuzix binary type.\n", argv[1]); + exit(1); + } + if (argc == 2) { + if (be) + top = buf[9] | (buf[8] << 8); + else + top = buf[8] | (buf[9] << 8); + if (top) + printf("Fuzix binary set at %d bytes.\n", top); + else + printf("Fuzix binary, set to allocate all available.\n"); + exit(0); + } + + if (sscanf(argv[2], "%d", &v) != 1 || v < 0 || v > 65536) { + fprintf(stderr, "%s: invalid chmem value '%s'.\n", argv[0], argv[2]); + exit(1); + } + if (be) { + buf[8] = v >> 8; + buf[9] = v & 0xFF; + } else { + buf[8] = v & 0xFF; + buf[9] = v >> 8; + } + rewind(fp); + if(fwrite(buf, 10, 1, fp) != 1) { + fprintf(stderr, "%s: write error.\n", argv[0]); + exit(1); + } + fclose(fp); + exit(0); +}