TARGET = pcbios.img
TARGETS = $(TARGET) bios13.img
include ../common.mk
QEMU_FLAGS = -accel kvm -accel tcg -rtc base=utc

$(TARGET): $(DUSK) init.fs
	dd if=/dev/zero of=$@ bs=512 count=16384 # 8M
	$(DUSK) -c '"$@" mountImage f<< xcomp/i386/pc/mkfat.fs'
	$(DUSK) -c 'f<< xcomp/i386/pc/deploy.fs "$@" mountImage install'
	$(DUSK) -c '"$@"' -f $(DUSKDIR)/syncfs.fs
	$(DUSK) -c '"init.fs" "$@" mountImage' -f $(DUSKDIR)/fatcp.fs < init.fs

.PHONY: emul
emul: $(TARGET)
	qemu-system-i386 $(QEMU_FLAGS) \
		-drive file=$(TARGET),format=raw,index=0,if=ide

bios13.img: $(DUSK) $(FS)/xcomp/i386/pc/bios13.fs
	$(DUSK) -e -c "f<< xcomp/i386/pc/bios13.fs org 512 stdio write" > $@
	# This script is not portable
	./bios13gen.sh >> $@ || echo "bios13gen.sh failed. incomplete image, but it's going to somewhat work"

.PHONY: bios13run
bios13run: bios13.img
	# change "if" to "floppy" to if needed
	qemu-system-i386 -drive file=bios13.img,format=raw,index=0,if=ide
