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

 LUA PASS1
	 -- Проверяем BMP, достаём из него параметры, режем на куски
		bmp_width, bmp_height, bmp_image_size, bmp_image_offset, bmp_colors = Get_bmp8bit_values (sj.get_define("PICTURE_FILE"))

		if  bmp_width	~= 128	then sj.error("Invalid BMP width", bmp_width) end
		if	bmp_height	~= 72	then sj.error("Invalid BMP height", bmp_height) end
		if	bmp_colors	~= 256	then sj.error("Invalid BMP number of colors", bmp_colors) end

		if not File_save(sj.get_define("PICTURE_FILE"), "./Build/Bin/LOGO_PAL.BIN", bmp_image_offset-1024, 1024) then sj.error("Palete save error!") end
		if not File_save(sj.get_define("PICTURE_FILE"), "./Build/Bin/LOGO_DAT.BIN", bmp_image_offset, bmp_image_size) then sj.error("Image data save error!") end
 ENDLUA

 LUA ALLPASS
	 	function make_pic_files (fileName, needPal, needPic)
			local fileNameBMP = "'" .. fileName .. ".bmp" .. "'"
			local fileNamePAL = fileName .. "_PAL.BIN"
			local fileNameDAT = fileName .. "_DAT.BIN"

			local bmp_width, bmp_height, bmp_image_size, bmp_image_offset, bmp_colors = Get_bmp8bit_values (fileNameBMP)

			if needPal == 1 then
				if  bmp_width	~= 128	then sj.error(fileNameBMP .. "Invalid BMP width", bmp_width) end
				if	bmp_height	~= 72	then sj.error(fileNameBMP .. "Invalid BMP height", bmp_height) end
				if	bmp_colors	~= 256	then sj.error(fileNameBMP .. "Invalid BMP number of colors", bmp_colors) end				
				if not File_save(fileNameBMP, fileNamePAL, bmp_image_offset-1024, 1024) then
					sj.error(fileNameBMP .. "Palete save error!")
				end
			end
			if needPic == 1 then
				local correctWidth = ((bmp_width*3)%4)+bmp_width
				if correctWidth > bmp_width then 
					File_save(fileNameBMP, fileNameDAT, bmp_image_offset, bmp_image_size, bmp_width, correctWidth-bmp_width)
				else
					File_save(fileNameBMP, fileNameDAT, bmp_image_offset, bmp_image_size)
				end
			end

			print("Resolution: " .. bmp_width .. "x" .. bmp_height, fileNameDAT)
		end
 ENDLUA

	MODULE MAIN_LOGO
Pallete:
	INCBIN 'Build/Bin/LOGO_PAL.BIN'	
.length		EQU $-Pallete
Raster:
	INCBIN 'Build/Bin/LOGO_DAT.BIN'
.length		EQU $-Raster

 IF Pashalki
; !TODO сделать тут табличку-ссылки на нужную таблицу спрайтов и завязать это на даты


	MACRO _PASHALKI_CODE
		IN A,(SLOT3)
		EX AF,AF'
		LD A,SYS_PAGE
		OUT (SLOT3),A

		ld e,(RebootDate.month)
		SLA e
		xor a
		ld 

		EX AF,AF'
		OUT (SLOT3),A


	ENDM

months_table:
	WORD	days_table.January
	WORD	days_table.February
	WORD	days_table.March
	WORD	days_table.April
	WORD	days_table.May
	WORD	days_table.June
	WORD	days_table.July
	WORD	days_table.August
	WORD	days_table.September
	WORD	days_table.October
	WORD	days_table.November
	WORD	days_table.December

days_table:
.January:	DZ		1,2,3,4,5,6,7	
.February	EQU		0
.March		EQU		0
.April		EQU		0
.May		EQU		0
.June		EQU		0
.July		EQU		0
.August		EQU		0
.September	EQU		0
.October	EQU		0
.November	EQU		0
.December:	DZ		31

NewYear:	INCLUDE	'./src/bios/logo/use/New_Year.inc'
;.March8:	INCLUDE	'./src/bios/logo/use/March_8.inc'
 
 ENDIF

/*

	and a
	ld b,0
	ld hl,months_table
	ld de,months_table+1
	ld a,month
	call FIND_NEXT

	ld hl,days_table
	adc hl,de
	ld ix,hl
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl 
	ld de,days_table+1
	ld a,day
	call FIND_NEXT

	ld hl,sprites_table
	adc hl,de

	call Sprites			; в hl адрес в таблице адресов таблиц спрайтов (SP_Table)


FIND_NEXT:
	ld c,(hl)				; берём длину таблицы BYTE
	inc hl
	CPIR
	jr nz,.nothing
	sbc hl,de
	sla l
	ex de,hl
	ret

days_table:
	WORD	december_days_table
	WORD	january_days_table
	WORD	march_days_table
	WORD	december_days_table
;----------------[Months table]----------------[v]
months_table:
	BYTE	months_table.length-1
.months:
	BYTE	01						; Январь
	BYTE	03						; Март
	BYTE	12						; Декабрь
.length		equ	$-months_table

 ASSERT months_table.length < 14, 	ERROR!!!	"months_table" should be less than 14 bytes!
;----------------------------------------------[^]

;-------------[December days table]------------[v]
december_days_table:
	BYTE	december_days_table.length-1
.months:
	BYTE	31						; Новый год
.length		equ	$-december_days_table

 ASSERT december_days_table.length < 33, 	ERROR!!!	"december_days_table" should be less than 33 bytes!
;----------------------------------------------[^]

;-------------[January days table]-------------[v]
january_days_table:
	BYTE	january_days_table.length-1
.months:
	BYTE	01						; Новый год
	BYTE	02						; Новый год
	BYTE	03						; Новый год
	BYTE	04						; Новый год
	BYTE	05						; Новый год
	BYTE	06						; Новый год
	BYTE	07						; Рождество
.length		equ	$-january_days_table

 ASSERT january_days_table.length < 33, 	ERROR!!!	"january_days_table" should be less than 33 bytes!
;----------------------------------------------[^]

;-------------[March days table]------------[v]
march_days_table:
	BYTE	december_days_table.length-1
.months:
	BYTE	08						; Клара Цеткин и Роза Люксембург
.length		equ	$-december_days_table

 ASSERT december_days_table.length < 33, 	ERROR!!!	"december_days_table" should be less than 33 bytes!
;----------------------------------------------[^]
*/

	ENDMODULE
