;
;----------------[TO DO]----------------
; 	DEFINE path to rom, exp, build, etc.
;	DEFINE path to including files for rom, exp, loader, etc...
;	...
;---------------------------------------

;=======================================
;	DEFDEVICE SPRINTER, #4000, 256
	DEVICE SPRINTER
;        ENCODING "DOS"
;=======================================

;------------[LUA functions]------------;
 includelua 'Shared_includes/lua/Functions.lua'
;---------------------------------------;

;-----------[Shared Includes]-----------
 INCLUDE 'src/bios/shared/includes.inc'	; Includes
;---------------------------------------


 LUA PASS1
	local date, month, year = Get_date_RU(sj.get_define("__DATE__"))
	BuildDate = "'" .. date .. "." .. month .. "." .. year .. "'"
	sj.insert_define("BUILD_DATE", BuildDate)
 ENDLUA
 LUA ALLPASS
	sj.insert_define("BUILD_DATE", BuildDate)
 ENDLUA


 IF PACKED_MAIN
;------------[MAIN prebuild]------------;
	LUA PASS1
	 -- настраиваем путь до упаковщика
		detected_os = Detect_os()
		print ("OS detected:", detected_os)
		print ()

		if detected_os == "Windows" then
				pack_prog = "src\\bin\\hrust.exe Build\\Bin\\temp\\MAIN.PAK Build\\Bin\\temp\\MAIN.BIN"
			elseif detected_os == "MacOS" then 
				pack_prog = "src/bin/mhmt -hst -zxh Build/Bin/temp/MAIN.BIN Build/Bin/temp/MAIN.PAK"
			elseif detected_os == "Linux" then
				pack_prog = "src/bin/mhmt -hst -zxh Build/Bin/temp/MAIN.BIN Build/Bin/temp/MAIN.PAK"
		end


	 -- компиляция для получения сжатого файла MAIN и холостой проход Set_Pictures.asm
		if (os.execute("sjasmplus -DPREBUILD=1 -Wall --msg=war --nologo --syntax=w --fullpath --lst=Build/Prebuilds.LST SRC/BIOS/ROM/SETUP/MAIN.ASM")) then
				print("--[     MAIN.ASM Prebuild DONE     ]--")
			if (os.execute(pack_prog)) then
				print("--[     Hrusting MAIN.BIN DONE     ]--")
				print(" ")
			else
				print("--[     Hrusting MAIN.BIN ERROR!!!     ]--")
				os.exit(1)
			end	
		else
			print("--[     MAIN.ASM Prebuild ERROR!!!     ]--")
			os.exit(1)
		end
	ENDLUA
;---------------------------------------;
 ENDIF

 IF PACKED_MAIN
;----------[MAIN's referenses]----------;                               Компиляция для получения адресов меток и процедур
	MMU		2 e, 18						; страница 18 в банку 2 и проверка на границы.
	ORG		COMPILE_ADDR.MAIN
	INCLUDE 'src/bios/ROM/SETUP/MAIN.asm'
;---------------------------------------
 ENDIF


;	Building page 8 of Sprinter ROM
;-----------------[EXP]-----------------
	MMU		0 e, 8						; страница 8 в банку 0 и проверка на границы	
	ORG		COMPILE_ADDR.EXP
        DEFINE+ IsInBIOS 1
 	OUTPUT	'Build/Bin/EXP.BIN'
		ShowInfo 'EXP block Start', 0                           ; !!!!! test
		INCLUDE	'src/bios/EXP/EXP.asm'
		ShowInfo 'EXP block End', 0                             ; !!!!! test
	OUTEND	
;---------------------------------------



;	Building page 0 of Sprinter ROM
;-----------------[ROM]-----------------
	MMU		0 e, 0						; страница 0 в банку 0 и проверка на границы.
	ORG		ROM_MAP.ROM
        DEFINE+ IsInBIOS 0
	OUTPUT	'Build/Bin/ROM.BIN'
                ShowInfo 'ROM block Start', 0                           ; !!!!! test
		INCLUDE 'src/bios/ROM/ROM.asm'
                ShowInfo 'ROM block End', 0                             ; !!!!! test
	OUTEND	
        UNDEFINE IsInBIOS
;---------------------------------------
;



;	Building page 12 of Sprinter ROM
;------[Loader with bitstream K30]------
	MMU		0 3, 12						; страницы 12-15 в банки 0-3.
	ORG		ROM_MAP.LOADER
	OUTPUT	'Build/Bin/LOADER_K30.BIN'
		Conf_loader K30
		BLOCK	#10000-$,#FF
	OUTEND	
;---------------------------------------



;	Building page 22 of Sprinter ROM
;------[Loader with bitstream K50]------
	MMU		0 3, 22						; страницы 22-25 в банки 0-3.
	ORG		ROM_MAP.LOADER
	OUTPUT	'Build/Bin/LOADER_K50.BIN'
;!TODO сделать упаковщик битстрима тут на LUA
		Conf_loader K50
		BLOCK	#10000-$,#FF
	OUTEND	
;---------------------------------------
;

;	Building page 1 of Sprinter ROM
;-----------------[LOGO]-----------------
	MMU		1 e, 1						; страница 1 в банку 1 и проверка на границы.
	ORG		ROM_MAP.LOGO
	OUTPUT	'Build/Bin/LOGO.BIN'
		INCLUDE 'src/bios/logo/Set_Pictures.asm'
	OUTEND	
;---------------------------------------
;
	EXPORT	ROM_NUMBER		; !FIXIT part1, part2 для Flasher
	EXPORT	BoardID.start
	EXPORT	BoardID.end
	EXPORT	FN_CRIPT.cnf
	EXPORT	ID_SPRINTER.bitstream_ver
	EXPORT	bitstream_ver_hex
	;EXPORT	ID_Version
	;EXPORT	ID_SPRINTER.BIOS_ver
	;EXPORT	BIOS_ver_hex
	;EXPORT	Disk_subsystem_ver_hex
	EXPORT	EXP_ID.VER	; Версия биоса
	EXPORT	EXP_ID.MOD
	;EXPORT	ROM_ID.VER	; Версия дисковой подсистемы
	;EXPORT	ROM_ID.MOD
	EXPORT	CNF_ID.VER	; Версия конфы
	EXPORT	CNF_ID.MOD
	EXPORT	msgStrings.str_ACEX_MODEL
	EXPORT	msgRusStrings.str_ACEX_MODEL
	; LUA ALLPASS
	; 	print ("DEPACKER", sj.get_label("DEPACKER.PackedMAIN"))
	; 	print ("UnPacker", sj.get_label("UnPacker.PackedMAIN"))
	; ENDLUA