From 35593dada1201e3e53147b13d3d29909cb76a322 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 9 Nov 2019 11:02:27 +0000 Subject: [PATCH] Replace fix-rom script with utils binary --- Makefile | 8 +++++--- src/utils/fix-rom.c | 36 ++++++++++++++++++++++++++++++++++++ utils/fix-rom.sh | 13 ------------- 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 src/utils/fix-rom.c delete mode 100755 utils/fix-rom.sh diff --git a/Makefile b/Makefile index 552b87b..50b3bb2 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ default: fdimage.img # Host utils utils/%: src/utils/%.c + mkdir -p utils $(CC) -o $@ $< # Boot sectors @@ -46,8 +47,8 @@ boot/%.bs: boot/%.asm $(NASM) $(NASM_ARGS) -DFLOPPY=$(FLOPPY) -o $@ $< # BIOS option roms -rom/%.rom: rom/%.asm - $(NASM) $(NASM_ARGS) -o $@ $< && utils/fix-rom.sh $@ +rom/%.rom: rom/%.asm utils/fix-rom + $(NASM) $(NASM_ARGS) -o $@ $< && utils/fix-rom $@ # Regular COM programs com/%.com: com/%.asm @@ -70,7 +71,8 @@ hdimage.img: boot/mbr.bs fdimage.img clean: find -name '*.lst' -delete - rm -f $$(cat .gitignore) boot/*.bs com/*.com rom/*.rom utils/emul + rm -f $$(cat .gitignore) boot/*.bs com/*.com rom/*.rom utils/* + rmdir utils qemu-floppy: fdimage.img $(ROMS) $(QEMU) $(QEMU_ARGS) -boot a -fda fdimage.img diff --git a/src/utils/fix-rom.c b/src/utils/fix-rom.c new file mode 100644 index 0000000..05cfc83 --- /dev/null +++ b/src/utils/fix-rom.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include + +struct stat sbuf; + +int main(int argc, char** argv) { + FILE* fd = fopen(argv[1], "r+"); + fstat(fileno(fd), &sbuf); + if (sbuf.st_size & 0x1F) { + fprintf(stderr, "Filesize is not a multiple of 512 bytes\n"); + exit(1); + } + + // Fill out filesize flag + fseek(fd, 2, SEEK_SET); + fputc(sbuf.st_size >> 9, fd); + + // Calculate checksum + fseek(fd, 0, SEEK_SET); + off_t i; + uint8_t s; + for (i=0; i