TOOLPATH = ../tools/
INCPATH  = ../tools/haribote/

MAKE     = $(TOOLPATH)make.exe -r
NASK     = $(TOOLPATH)nask.exe
QEMUFDBIN = ..\tools\qemu\fdimage0.bin
CC1      = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM  = $(TOOLPATH)obj2bim.exe
BIM2HRB  = $(TOOLPATH)bim2hrb.exe
RULEFILE = $(TOOLPATH)haribote/haribote.rul
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
MKFONT   = $(TOOLPATH)makefont.exe
BIN2OBJ  = $(TOOLPATH)bin2obj.exe
COPY     = copy
DEL      = del

# ftHg

default :
	$(MAKE) img

# t@CK

ipl.bin : ipl.nas
	$(NASK) ipl.nas ipl.bin ipl.lst

asmhead.bin : asmhead.nas
	$(NASK) asmhead.nas asmhead.bin asmhead.lst

bootpack.gas : bootpack.c bootpack.h fifo.h
	$(CC1) -o bootpack.gas bootpack.c
bootpack.nas : bootpack.gas 
	$(GAS2NASK) bootpack.gas bootpack.nas
bootpack.obj : bootpack.nas 
	$(NASK) bootpack.nas bootpack.obj bootpack.lst

graphic.gas : graphic.c bootpack.h
	$(CC1) -o graphic.gas graphic.c
graphic.nas : graphic.gas
	$(GAS2NASK) graphic.gas graphic.nas
graphic.obj : graphic.nas
	$(NASK) graphic.nas graphic.obj graphic.lst

fifo.gas : fifo.c fifo.h
	$(CC1) -o fifo.gas fifo.c
fifo.nas : fifo.gas
	$(GAS2NASK) fifo.gas fifo.nas
fifo.obj : fifo.nas
	$(NASK) fifo.nas fifo.obj fifo.lst

int.gas : int.c bootpack.h fifo.h
	$(CC1) -o int.gas int.c
int.nas : int.gas
	$(GAS2NASK) int.gas int.nas
int.obj : int.nas
	$(NASK) int.nas int.obj int.lst

dsctbl.gas : dsctbl.c bootpack.h
	$(CC1) -o dsctbl.gas dsctbl.c
dsctbl.nas : dsctbl.gas
	$(GAS2NASK) dsctbl.gas dsctbl.nas
dsctbl.obj : dsctbl.nas
	$(NASK) dsctbl.nas dsctbl.obj dsctbl.lst

naskfunc.obj : naskfunc.nas
	$(NASK) naskfunc.nas naskfunc.obj naskfunc.lst

bootpack.bim : bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj int.obj fifo.obj
	$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \
		bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj int.obj fifo.obj
# 3MB+64KB=3136KB

bootpack.hrb : bootpack.bim
	$(BIM2HRB) bootpack.bim bootpack.hrb 0

haribote.sys : asmhead.bin bootpack.hrb
	copy /B asmhead.bin+bootpack.hrb haribote.sys

helloos.img : ipl.bin haribote.sys
	$(EDIMG) imgin:$(TOOLPATH)fdimg0at.tek \
		wbinimg src:ipl.bin len:512 from:0 to:0  \
		copy from:haribote.sys to:@: \
		imgout:helloos.img

hankaku.bin : hankaku.txt
	$(MKFONT) hankaku.txt hankaku.bin

hankaku.obj : hankaku.bin
	$(BIN2OBJ) hankaku.bin hankaku.obj _hankaku

# R}h

img :
	$(MAKE) helloos.img

run :
	$(MAKE) img
	$(DEL) $(QEMUFDBIN)
	$(COPY) helloos.img $(QEMUFDBIN)
	$(MAKE) -C $(TOOLPATH)qemu


install :
	$(MAKE) img
	$(IMGTOL) w a: helloos.img

clean :
	-$(DEL) *.bin
	-$(DEL) *.lst
	-$(DEL) *.gas
	-$(DEL) *.obj
	-$(DEL) bootpack.nas
	-$(DEL) bootpack.map
	-$(DEL) bootpack.bim
	-$(DEL) bootpack.hrb
	-$(DEL) haribote.sys

src_only :
	$(MAKE) clean
	-$(DEL) helloos.img
