Replace fix-rom script with utils binary
This commit is contained in:
parent
a4697fa666
commit
35593dada1
8
Makefile
8
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
|
||||
|
36
src/utils/fix-rom.c
Normal file
36
src/utils/fix-rom.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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<sbuf.st_size; i++) {
|
||||
s+=fgetc(fd);
|
||||
}
|
||||
|
||||
// Edit last byte so that checksum is 0
|
||||
fseek(fd, -1, SEEK_END);
|
||||
s=fgetc(fd)-s;
|
||||
fseek(fd, -1, SEEK_END);
|
||||
fputc(s, fd);
|
||||
|
||||
fclose(fd);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
setbyte() {
|
||||
printf "\x$3"|dd status=none seek="$2" bs=1 count=1 conv=notrunc of="$1"
|
||||
}
|
||||
|
||||
[ -n "$1" ] || exit 1
|
||||
|
||||
setbyte "$1" 2 $(stat -c "%s" "$1"|awk '{printf("%02x",$1/512)}')
|
||||
|
||||
setbyte "$1" 41 00
|
||||
checksum=$(xxd -p -c 1 "$1"|sed 's/^/0x/'|awk '{s+=$1} END {printf("%02x\n",256-s%256)}')
|
||||
setbyte "$1" 41 "$checksum"
|
Loading…
Reference in New Issue
Block a user