TOCLEAN = common.img
TARGETS = pc.img bare.img floppy.img
include ../common.mk

QEMU_FLAGS = -accel kvm -accel tcg \
	-chardev stdio,id=char0 \
	-serial chardev:char0 \
	-rtc base=utc
QEMU_DRVOPTS = format=raw,index=0,if=ide

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

pc.img: common.img
	cp common.img $@
	$(DUSK) -c '"init.fs" "$@" mountImage' -f $(DUSKDIR)/fatcp.fs < init.fs

bare.img: common.img
	cp common.img $@
	$(DUSK) -c '"init.fs" "$@" mountImage' -f $(DUSKDIR)/fatcp.fs < bare.fs

floppy.img: $(DUSK) syncfloppy.fs
	dd if=/dev/zero of=$@ bs=512 count=2880 # 1.44M
	$(DUSK) -n xcomp/i386/pc/mkfat -c '"$@" mountImage dofloppy'
	$(DUSK) -c 'f<< xcomp/i386/pc/deploy.fs "$@" mountImage install'
	$(DUSK) -f syncfloppy.fs
	$(DUSK) -c '"init.fs" "$@" mountImage' -f $(DUSKDIR)/fatcp.fs < floppy.fs

.PHONY: emul
emul: pc.img
	qemu-system-i386 $(QEMU_FLAGS) -drive file=pc.img,$(QEMU_DRVOPTS)

.PHONY: emulbare
emulbare: bare.img
	qemu-system-i386 $(QEMU_FLAGS) -drive file=bare.img,$(QEMU_DRVOPTS)

.PHONY: emulfloppy
emulfloppy: floppy.img
	qemu-system-i386 $(QEMU_FLAGS) -fda floppy.img
