
include ../Rules.make
include ../options


### Variables ###

# Uncomment this to create a listing file
# LIST= -l boot.lst

ifndef DOS
DATE= `date +"%a %D %T %Z"`
endif


### Build Rules ###

.PHONY: all

## Default target: Build binaries & dosimage (for an emulator)
all: dosboot.bin kernel.bin  dosimage



.PHONY:	rawfloppy dosfloppy bootfloppy clean

rawfloppy: image
	cp $< /dev/fd0
#	dd if=$< of=/dev/fd0 bs=512 conv=sync


# modif. by Paul Sept. 1 1999, was : image: boot.bin modules
image: boot.bin $(KERNEL_DEPS)
# commented out by Paul Sept. 1 	rm $@
# was: cat boot.bin modules >$@
	cat boot.bin >$@
ifndef DOS
	../util/adjboot $@
else
	..\util\adjboot $@
endif
	@ls -l $@

CORE_DEPS =	boot.mac macros.mac init.inc pmode.inc gdt.inc \
	ints.inc memory.inc xcom.asm ../options
DISPLAY_DEPS =	display.inc graph.inc ../fonts/gr8x8.psf
SERIAL_DEPS =	serial.asm serial.mac terminal.asm
IO_DEPS =	ide.inc floppy.asm kbd.inc keymap $(SERIAL_DEPS)
FORTH_DEPS =	forth.inc forth.mac dict.inc words.inc bforth.fo

KERNEL_DEPS = $(CORE_DEPS) $(DISPLAY_DEPS) $(IO_DEPS) $(FORTH_DEPS)


## Disk image (flat binary, no filesystem)
boot.bin: boot.asm $(KERNEL_DEPS)
	$(ASM) -f bin $(LIST) -o $@  $<
#	$(ASM) -f bin $(LIST) -dDATE="\"$(DATE)\"" -dUSER=\"$(USER)\" -o $@  $<
	@ls -l $@

## DOS boot disk image (As R: in /etc/mtools.conf)
dosimage: dosboot.bin kernel.bin
	dd if=dosboot.bin of=dosimage bs=1 conv=notrunc count=3
	dd if=dosboot.bin of=dosimage bs=1 conv=notrunc count=450 skip=62 seek=62
	mcopy -o kernel.bin r:
#	ln -sf dosimage hdimage
#	ln -sf dosimage image

## Small hard disk image w/ bootable Retro partition (S: in /etc/mtools.conf)
hdimage: dosboot.bin kernel.bin
	dd if=dosboot.bin of=hdimage bs=1 conv=notrunc count=3 seek=17920
	dd if=dosboot.bin of=hdimage bs=1 conv=notrunc count=450 \
		skip=62 seek=17982
	mcopy -o kernel.bin s:

## Boot sector to load \KERNEL.BIN from a FAT filesystem
dosboot.bin: dosboot.asm ../options
	$(ASM) -f bin -o $@ -l dosboot.lst $(HDLOAD)  $<

## Kernel image (for DOS boot)
kernel.bin: kernel.asm $(KERNEL_DEPS)
	$(ASM) -f bin -l kernel.lst -o $@  $<

## Make a bootable DOS-format floppy (must already be formatted)
floppy: kernel.bin bootfloppy
	mcopy -o kernel.bin a:

## Install just the boot sector on a DOS-format floppy
bootfloppy: dosboot.bin
	dd if=dosboot.bin of=/dev/fd0 bs=1 conv=notrunc count=3
	dd if=dosboot.bin of=/dev/fd0 bs=1 conv=notrunc count=450 skip=62 seek=62



## Obsolete (maybe not?) stuff
#.PHONY: modules stable beta tests alpha
#modules: stable beta #tests
#	touch $@
#
#	cat bforth.rdf print.rdf ints.rdf page.rdf task.rdf misc.rdf \
#	kbd_$(KBD).rdf kbd.rdf debug.rdf help.rdf floppy.rdf ide.rdf install.rdf \
#	serial.rdf terminal.rdf  forth.rdf ddr2.rdf >$@
#XCOM loader test:
#	cat bforth.rdf print.rdf ints.rdf page.rdf task.rdf misc.rdf kbd_$(KBD).rdf kbd.rdf debug.rdf help.rdf floppy.rdf ide.rdf serial.rdf terminal.rdf  xc_test.rdf xcom.rdf  forth.rdf ddr2.rdf >$@
#
#stable: #debug.rdf ddr2.rdf floppy.rdf help.rdf kbd_$(KBD).rdf kbd.rdf misc.rdf
#
#beta: #page.rdf task.rdf ints.rdf print.rdf forth.rdf bforth.rdf lisp.rdf serial.rdf terminal.rdf xcom.rdf ide.rdf install.rdf
#
#kbd_$(KBD).rdf: ../keymaps/kbd_$(KBD).map


### Rules ###

%.bin: %.asm
	$(ASM)  -f bin  -o $@  $<

%.xc: %.asm
	$(ASM)  -f xcom  -o $@  $<

JUNK= boot.bin modules image *.rdf *.lst *~ .*~ bochs.out hdimage

clean:
	rm -f $(JUNK)
