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