;U_SETUP:
SETTINGS:
	LD	A,CMOS_CELL.ScreenSET
	CALL	READCMS
	AND	high CMOS_CELL.ScreenSET.Mask.ColorStyle
	LD	L,A
	CALL	CSET
	LD	DE,0
	LD	HL,#2050
	LD	A,(NORCLR)
	LD	B,A
        CALL    LP_CLS_WIN


	LD	A,msgStrings.setupBiosVer
	LD	DE,#0100                                                ; ?????
	CALL	POSTLEN
	LD	A,msgStrings.setupBiosVer
	CALL	POSTMSG
	LD	A,msgStrings.setupCopyRight
	LD	DE,#0200
	CALL	POSTLEN
	LD	A,msgStrings.setupCopyRight
	CALL	POSTMSG
	LD	A,msgStrings.setupUtilityVer
	LD	DE,#0500
	CALL	POSTLEN
	LD	A,msgStrings.setupUtilityVer
	CALL	POSTMSG

	CALL	setFRAME.double

	LD	DE,#0402
	LD	BC,#1A4C
	CALL	PBORDER

	CALL	setFRAME.medium

	LD	DE,#0602
	LD	BC,#134C
	CALL	PBORDER			;!FIXIT 

	CALL	setFRAME.single

	LD	DE,#062A
	LD	H,#13
	CALL	TLINEV

	LD	DE,#1906
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE
	LD	A,msgStrings.setupHelpStr1
	CALL	POSTMSG
	LD	DE,#1A06
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE
	LD	A,msgStrings.setupHelpStr2
	CALL	POSTMSG
	LD	DE,#1B06
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE
	LD	A,msgStrings.setupHelpStr3
	CALL	POSTMSG
	LD	DE,#1C06
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE
	LD	A,msgStrings.setupHelpStr4
	CALL	POSTMSG
	LD	BC,SettingsItemsTabsAddrs.max*256
	

 IF NEW_FEATURE

        ; LD      HL,CurrentDateTime
        ; CALL    GETTIME

        ; LD      HL,CurrentDateTime

        ; LD      A,(HL)
        ; AND     #F0        

 ENDIF


STT1:	LD	A,C
	LD	(ITEM),A
	PUSH	BC
	CALL	PTEXT
	POP	BC
	INC	C
	DJNZ	STT1

	LD      a,(ITEM_Restore)
	LD	(ITEM),A
	CALL	PCURSOR

AGAIN:	LD	HL,AGAIN
	PUSH	HL
	CALL	KEY
; CURSOR DOWN
	LD	HL,#5200	
	AND	A
	SBC	HL,DE
	JP	Z,INCITM
; CURSOR UP
	LD	HL,#5800	
	AND	A
	SBC	HL,DE
	JP	Z,DECITM
; CURSOR RIGHT
	LD	HL,#5600	
	AND	A
	SBC	HL,DE
	JP	Z,ADDITM
; CURSOR LEFT
	LD	HL,#5400	
	AND	A
	SBC	HL,DE
	JP	Z,SUBITM
; +
	LD	HL,#5300	
	AND	A
	SBC	HL,DE
	JP	Z,INCVAL
; -
	LD	HL,#5900	
	AND	A
	SBC	HL,DE
	JP	Z,DECVAL
; + or -
	LD	HL,#A400	
	AND	A
	SBC	HL,DE
	JP	Z,INCVAL
	CP	"+"
	JP	Z,INCVAL
	CP	"-"
	JP	Z,DECVAL

 IF NEW_FEATURE        
; ENTER
	LD	HL,#280D	
	AND	A
	SBC	HL,DE
	JP	Z,pressedEnter
 ENDIF

; F2
	LD	HL,#3C00	
	AND	A
	SBC	HL,DE
	JP	Z,SAVEV
; F3
	LD	HL,#3D00	
	AND	A
	SBC	HL,DE
	JP	Z,CCHANGE
; F5
	LD	HL,#3F00	
	AND	A
	SBC	HL,DE
	JP	Z,OLD_VAL
; F7
	LD	HL,#4100	
	AND	A
	SBC	HL,DE
	JP	Z,DEF_VAL
; F10
	LD	HL,#4400	
	AND	A
	SBC	HL,DE
	JP	Z,SAVEXIT
; ESC
	LD	HL,#011B	
	AND	A
	SBC	HL,DE
	RET	NZ
	POP	HL
	RET 

OLD_VAL:
	CALL    READING
	JR      RestartSetup
	RET 

DEF_VAL:
	CALL    SETDEF
;---------------------------------------
RestartSetup:	
;setXYpos
	CALL	RESCREEN
;setLang
	CALL	SETLAND
;setVsinc
	CALL OnChangeAction.setVsinc
;setInt - Должна быть последней!!!
	JP OnChangeAction.setInt
;---------------------------------------

SAVEXIT:
	CALL	WRITING
	POP	HL
	RET 

SAVEV:
	CALL	WRITING
	RET 

SUBITM:
	CALL	RCURSOR
	LD	A,(ITEM)
	SUB	17							; !HARDCODE max items in column
	JR	NC,GODITM2
	XOR	A
GODITM2:
	LD	(ITEM),A
	JP	PCURSOR

ADDITM:
	CALL	RCURSOR
	LD	A,(ITEM)
	ADD	A,17							; !HARDCODE max items in column
	CP	SettingsItemsTabsAddrs.max
	JR	C,GODITM
	LD	A,SettingsItemsTabsAddrs.max
	DEC	A
GODITM:
	LD	(ITEM),A
	JP	PCURSOR

INCITM:	CALL	RCURSOR
	LD	A,(ITEM)
	INC	A
	CP	SettingsItemsTabsAddrs.max
	JR	NZ,1F
	XOR	A
1:	LD	(ITEM),A
	JP	PCURSOR

DECITM:
	CALL	RCURSOR
	LD	A,(ITEM)
	OR	A
	JR	NZ,1F
	LD	A,SettingsItemsTabsAddrs.max
1:	DEC	A
	LD	(ITEM),A
	JP	PCURSOR

CCHANGE:
	LD	A,CMOS_CELL.ScreenSET
	CALL	READCMS
	INC	A
	AND	high CMOS_CELL.ScreenSET.Mask.ColorStyle
	LD	L,A
	LD	B,A
	LD	A,CMOS_CELL.ScreenSET
	CALL	WRITCMS
CSET:
	LD	H,0
	LD	DE,STYLES
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,DE
	LD	DE,NORCLR
	LDI 
	LDI 
	LDI 
	LDI 
	CALL	FSCREEN
REFRESH:
	LD	BC,SettingsItemsTabsAddrs.max*256
	LD	A,(ITEM)
	PUSH	AF
STT2:	LD	A,C
	LD	(ITEM),A
	PUSH	BC
	CALL	PTEXT
	POP	BC
	INC	C
	DJNZ	STT2
	POP	AF
	LD	(ITEM),A
	CALL	PCURSOR
	RET 

PTEXT:	call    Get_Item_Address
	JP      PITEM

;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[v]
 IF NEW_FEATURE
; New procedure with IY reg
LocateCursor:
	call    Get_Item_Address
        LD      E,(IY+MenusItem.Column)
	LD	D,(IY+MenusItem.Line)
	ld      a,(IY+MenusItem.Name)
        push    iy
	call    FindStringAddr
	LD	BC,#0100
	XOR	A
	CPIR 
	LD	A,#FF
	SUB	C
	ADD	A,E
	LD	E,A
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE
	pop     iy
	ld      a,(iy+MenusItem.FirstString)
	call    FindStringAddr
	LD	BC,#0100
	XOR	A
	CPIR 
	LD	A,#FF
	SUB	C
	LD	B,A
	ret

 ELSE
LocateCursor:
	call    Get_Item_Address
	LD	E,(HL)
	INC	HL
	LD	D,(HL)
	INC	HL
	ld      a,(hl)
	inc     hl
	push    hl
	call    FindStringAddr
	LD	BC,#0100
	XOR	A
	CPIR 
	LD	A,#FF
	SUB	C
	ADD	A,E
	LD	E,A
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE
	pop     hl
	INC	HL	;SKIP REGISTER
	INC	HL	;SKIP MASK
	INC	HL	;SKIP MAX VALUE
	ld      a,(hl)
	call    FindStringAddr
	LD	BC,#0100
	XOR	A
	CPIR 
	LD	A,#FF
	SUB	C
	LD	B,A
	ret
 ENDIF
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[^]

PCURSOR:
	call    LocateCursor
	LD	A,(CURCLR)
	JP	PRINTA

RCURSOR:
	call    LocateCursor
	LD	A,(NORCLR)
	JP	PRINTA

FSCREEN:
	LD	DE,#0000
	EI 
	HALT 
FSC1:
	PUSH	DE
        CALL    LP_SET_PLACE

	LD	A,(NORCLR)
	LD	E,A
        LD      B,#50
        CALL    LP_PRINT_ATR

	POP	DE
	LD	A,#20
	INC	D
	CP	D
	JR	NZ,FSC1
	RET 

ITEM:           DB #00
ITEM_Restore:   DB #00

NORCLR:	        DB COLORS.CGA.PAPER.BLUE + COLORS.CGA.INC.WHITE
HLTCLR:	        DB COLORS.CGA.PAPER.BLUE + COLORS.CGA.INC.YELLOW
CURCLR:	        DB COLORS.CGA.PAPER.RED + COLORS.CGA.INC.WHITE
WRMCLR:	        DB COLORS.CGA.PAPER.BLUE + COLORS.CGA.INC.WHITE


;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[v]
 IF NEW_FEATURE
; New procedure with IY reg
INCVAL:	call    Get_Item_Address
        ld      A,(IY+MenusItem.Type)
        AND     A
        RET     NZ                                                      ; проверка на тип, дальше если paramLine

	LD      A,(IY+MenusItem.CMOSreg)
	PUSH	AF
	CALL	READCMS
	LD	C,A
        AND     (IY+MenusItem.ValueMask)
        CP      (IY+MenusItem.ValueMax)
	LD	A,C
	JR	Z,OVERI
        LD      B,(IY+MenusItem.ValueMask)
	CALL	ADDVAL
	ADD	A,B
	JR	OVER
OVERI:	XOR     (IY+MenusItem.ValueMax)
OVER:   LD	B,A
	POP	AF
	CALL	WRITCMS
	PUSH    IY
        PUSH    IY
        POP     HL
        CALL    PITEM
	POP     IY
        ld      l,(IY+MenusItem.Action)
        ld      h,(IY+MenusItem.Action+1)
	jp      (hl)

DECVAL:	call Get_Item_Address
        ld      A,(IY+MenusItem.Type)
        AND     A
        RET     NZ                                                      ; проверка на тип, дальше если paramLine

	LD      A,(IY+MenusItem.CMOSreg)
	PUSH	AF
	CALL	READCMS
	LD	C,A
        AND     (IY+MenusItem.ValueMask)
	LD	A,C
	JR	Z,OVERD
	LD      B,(IY+MenusItem.ValueMask)
	CALL	ADDVAL
	SUB	B
	JR	OVER
OVERD:	OR     (IY+MenusItem.ValueMax)
	JR OVER


pressedEnter:
; !TODO New Feature
        ld a,(iy+MenusItem.Type)
        and a
        ret z
        ld l,(iy+MenusItem.Action)
        ld h,(iy+MenusItem.Action+1)
        jp (HL)

 ELSE
INCVAL:	call    Get_Item_Address
	INC	HL
	INC	HL
	INC	HL
	LD	A,(HL)
	INC	HL
	PUSH	AF
	CALL	READCMS
	LD	C,A
	AND	(HL)
	INC	HL
	CP	(HL)
	LD	A,C
	JR	Z,OVERI
	DEC	HL
	LD	B,(HL)
	CALL	ADDVAL
	ADD	A,B
	JR	OVER
OVERI:	XOR	(HL)         
OVER:   LD	B,A
	POP	AF
	CALL	WRITCMS
	CALL	PTEXT
	call    Get_Item_Address
	dec     hl
	ld      a,(hl)
	dec     hl
	ld      l,(hl)
	ld      h,a
	jp      (hl)

DECVAL:	call Get_Item_Address
	INC	HL
	INC	HL
	INC	HL
	LD	A,(HL)
	INC	HL
	PUSH	AF
	CALL	READCMS
	LD	C,A
	AND	(HL)
	LD	A,C
	INC	HL
	JR	Z,OVERD
	DEC	HL
	LD	B,(HL)
	CALL	ADDVAL
	SUB	B
	JR	OVER
OVERD:
	OR	(HL)
	JR OVER

 ENDIF
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[^]

; B - MASK
ADDVAL:	LD	C,#00
ADDV1:	INC	C
	RRC	B
	JR	NC,ADDV1
	LD	B,#80
ADDV2:	RLC	B
	DEC	C
	JR	NZ,ADDV2
	RET 

;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[v]
 IF NEW_FEATURE
; IY - item's address
; New procedure with IY reg
PITEM:  LD      E,(IY+MenusItem.Column)                                 ; x-coordinate
        LD      D,(IY+MenusItem.Line)                                   ; y-coordinate
	;CALL	ScreenPOS.LOCAT
        CALL    LP_SET_PLACE                                            ; set position of item
        LD      A,(IY+MenusItem.Name)
        CALL    POSTMSG

        PUSH    IY
        LD      BC,MenusItem.FirstString
        ADD     IY,BC
        EX      (SP),IY
        POP     HL                                                      ; тут адрес строки первого параметра

        LD      A,(IY+MenusItem.Type)
        AND     A
        JR      NZ,.printParameter                                      ; если это не строка с изменяемым параметром, то просто печать

        LD      A,(IY+MenusItem.CMOSreg)                                ; address of next parametr
        CALL	READCMS                                                 ; read item`s value from cmos

	LD	B,(IY+MenusItem.ValueMask)                              ; item's value mask
	AND	B
.getParameterNum:
	RRCA 
	RRC	B
	JR	NC,.getParameterNum
	RLCA 
	OR	A
	jr	Z,.printParameter                                       ; первый параметр выводим?

	ld c,a
	xor a
	ld b,a
	add hl,bc                                                       ; находим номер параметра
.printParameter:
	ld a,(hl)
	jp POSTMSG

 ELSE
; !FIXIT вызовы процедур биоса надеются на то, что некоторые регистры не портятся
; HL - item's address
PITEM:	LD	E,(HL)                                                  ; x-coordinate
	INC	HL
	LD	D,(HL)                                                  ; y-coordinate
	INC	HL                                                      ; address of next parametr
	PUSH    HL
        CALL    LP_SET_PLACE                                            ; set position of item
	LD      A,(HL)
	CALL	POSTMSG
	POP     HL
	INC     HL
	LD	A,(HL)                                                  ; address of next parametr
	CALL	READCMS                                                 ; read item`s value from cmos
	INC	HL
	LD	B,(HL)                                                  ; item's value mask
	INC	HL
	INC	HL
	AND	B
.getParameterNum:
	RRCA 
	RRC	B
	JR	NC,.getParameterNum
	RLCA 
	OR	A
	jr	Z,.printParameter                                       ; первый параметр выводим?

	ld c,a
	xor a
	ld b,a
	add hl,bc                                                       ; находим номер параметра
.printParameter:
	ld a,(hl)
	jp POSTMSG
 ENDIF
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[^]

; Не портит HL
G_VALUE:
	PUSH	BC
	LD	A,C
	CALL	READCMS
	POP	BC
	AND	B
.loop:	RRCA 
	RRC	B
	JR	NC,.loop
	RLCA 
	RET 

;!TEST
READCMS:
	LD	D,high CMOSARE
	LD	E,A
	CP	CMOS.USED_MAX_ADDRESS+1
	JR	NC,.error	
	LD	A,(DE)
	RET
.error:	SCF
	RET 

;!TEST
WRITCMS:
	LD	D,high CMOSARE
	LD	E,A
	CP	CMOS.USED_MAX_ADDRESS+1
	JR	NC,.error
	LD	A,B
	LD	(DE),A
	RET
.error:	SCF
	RET 

CHEKSUM:
	LD	BC,DEFVAL.Size*256 + #0E				;!HARDCODE
	LD	H,#DE							;!HARDCODE
.loop:	LD	A,C
	CALL	READCMS
	LD	L,A
	LD	A,H
	SUB	L
	RLCA 
	SUB	L
	LD	H,A
	INC	C
	DJNZ	.loop
	RET 

TCHEKSM:
	CALL	CHEKSUM
	LD	A,#3F							; !HARDCODE CMOS
	CALL	READCMS
	CP	H
	RET 

; TSTCMOS:
; 	LD	C,BIOS.CMOS_TEST
; 	JP_to_BIOS


; RDCMOS:
; 	LD	C,BIOS.CMOS_RD
; 	JP_to_BIOS

; WRCMOS:
; 	LD	C,BIOS.CMOS_WR
; 	JP_to_BIOS

READING:
	LD	D,CMOS.USED_MIN_ADDRESS
.loop:	PUSH	DE
	CALL    CMOS_RD
        POP	DE
	LD	H,high CMOSARE
	LD	L,D
	LD	(HL),A
	LD	A,CMOS.USED_MAX_ADDRESS+1
	INC	D
	CP	D
	JR	NZ,.loop
	RET 

WRITING:
	CALL	CHEKSUM
	LD	B,H
	LD	A,CMOS.Cell.CheckSum
	CALL	WRITCMS
	LD	D,CMOS.USED_MIN_ADDRESS                                                   ; !HARDCODE CMOS 
.loop:
	LD	H,high CMOSARE
	LD	L,D
	LD	A,(HL)
	PUSH	DE
        CALL    CMOS_WR

	POP	DE
	LD	A,CMOS.USED_MAX_ADDRESS+1
	INC	D
	CP	D
	JR	NZ,.loop
	RET 

SETDEFX:
	LD	A,#FF
	LD	(ERRSUM),A
	CALL	SETDEF
	JP	WRITING

SETDEF:							;!TODO может бахнуть LDIRом? посмотреть
	LD	HL,DEFVAL
	LD	C,DEFVAL.Size
	LD	A,CMOS.USED_MIN_ADDRESS
.loop:
	LD	B,(HL)
	INC	HL
	PUSH	AF
	CALL	WRITCMS
	POP	AF
	INC	A
	DEC	C
	JR	NZ,.loop
;REGISTER #35 -	BASIC SETTING 1
	LD	A,#35			;!HARDCODE cmos
	LD	B,#00
	CALL	WRITCMS
;REGISTER #36 -	BASIC SETTING 2
	LD	A,#36			;!HARDCODE cmos
	LD	B,#00
	CALL	WRITCMS

	CALL	CHEKSUM
	LD	B,H
	LD	A,CMOS.Cell.CheckSum
	CALL	WRITCMS
	RET 

;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[v]
; New procedure with IY reg
        IF NEW_FEATURE
Get_Item_Address:
	 LD	A,(ITEM)
	 LD	L,A
	 LD	H,0
	 LD	DE,SettingsItemsTabsAddrs
	 ADD	HL,HL
	 ADD	HL,DE
	 LD	A,(HL)
	 INC	HL
	 LD	H,(HL)
	 LD	L,A
	 PUSH	HL
	 POP	IY
	 RET

        ELSE     
Get_Item_Address:
	 LD	A,(ITEM)
	 LD	L,A
	 LD	H,0
	 LD	DE,SettingsItemsTabsAddrs
	 ADD	HL,HL
	 ADD	HL,DE
	 LD	A,(HL)
	 INC	HL
	 LD	H,(HL)
	 LD	L,A
	 INC	HL
	 INC	HL
	 RET
        ENDIF
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-[^]
;
 MODULE	OnChangeAction
nothing:
        ret

        ; !TODO New Feature
        ; !TODO замутить что-то типа API для рисования всплывающих окон
        IF NEW_FEATURE
SetTime:
         xor     a
         ld      hl,#050E
         ld      de,#0C20
         ld      ix,memBUFFER.Shared
         CALL    WIN_COPY

	 LD DE,#0C20                                                    ; !HARDCODE
         ld b,5
         DI

.loop:   push bc
         push de
         CALL    LP_SET_PLACE
         ; печать атрибутов
         LD E,COLORS.CGA.INC.RED
         LD      B,#0E
         CALL    LP_PRINT_ATR

         pop de
         inc d
         pop bc
         DJNZ .loop

	 CALL	setFRAME.single
         LD	DE,#0C20        ;yx. y=0..1F, x=0..4F координаты левого верхнего угла
	 LD	BC,#050E        ;yx. длина и высота линии
	 CALL	PBORDER

         CALL KEY
         xor a
         ld hl,#050E
         ld de,#0C20
         ld ix,memBUFFER.Shared
         JP      WIN_RESTORE
        ENDIF

setXYpos:
        JP RESCREEN

setVsinc:
        ld a,CMOS_CELL.ScreenSET
        call READCMS
        and high CMOS_CELL.ScreenSET.Mask.Sinc
        SCF
        jr z,.skip                                              ;320
        SLA A
.skip:  ld a,128+7                                              ;312
        jp nc,FN_SYNC
        dec a							;320
.set:   jp FN_SYNC

setLang:
        CALL SETLAND
        ld a,(ITEM)
        ld (ITEM_Restore),a
        pop hl							; delete return adress from stack
        jp SETTINGS	
setInt: ld a,CMOS_CELL.ScreenSET
        call READCMS
        and high CMOS_CELL.ScreenSET.Mask.Int
        jr nz,.skipDefaultInt
        ld a,2							; Pentagon sync - default
        jr .set

.skipDefaultInt:
        SRA A
        SRA A
        SRA A
        SRA A							; byte %00xx0000 --> %000000xx
.set:   CALL    FN_SYNC

        LD	IX,win_descriptor.tab80x32
        LD	HL,#0000
        LD	E,1
        CALL    WIN_OPEN

        ld a,(ITEM)
        ld (ITEM_Restore),a
        pop hl							; delete return adress from stack
        jp SETTINGS	
 ENDMODULE
;
MEMTEST	        EQU     #80
SAVERAM	        EQU     #40
EXTBIOS	        EQU     #20

SDELAY2         EQU     #10
SDELAY1         EQU     #08
SDELAY0         EQU     #00
RUS             EQU     #04
QSTART          EQU     #01

TMAT_ON         EQU     #80
TDL250          EQU     #00
TDL500          EQU     #20
TDL750          EQU     #40
TDL1000         EQU     #60
TRATE6          EQU     #00
TRATE8          EQU     #01
TRATE10         EQU     #02
TRATE12         EQU     #03
TRATE15         EQU     #04
TRATE20         EQU     #05
TRATE24         EQU     #06
TRATE30         EQU     #07
SDFDD1          EQU     #00
SDFDD2          EQU     #01
SDIDE1          EQU     #02
SDIDE2          EQU     #03
SDRAM           EQU     #04
ASDFDD1         EQU     #00
ASDFDD2         EQU     #10
ASDRECOVERY	EQU	#70
ASDIDE1         EQU     #20
ASDIDE2         EQU     #30
ASDRAM          EQU     #40
FD1720          EQU     #00
FD1144          EQU     #01
FD1NONE         EQU     #02
FD2720          EQU     #00
FD2144          EQU     #04
FD2NONE         EQU     #08
HD1AUTO         EQU     #00
HD1STP          EQU     #01
HD1NONE         EQU     #02
HD2AUTO         EQU     #00
HD2STP          EQU     #04
HD2NONE         EQU     #08
TURBOFF         EQU     #06
TURBON          EQU     #07
SPRIN           EQU     #00
SCORP           EQU     #08
PENT            EQU     #10
USER            EQU     #18
BAS128          EQU     #00
BAS48_          EQU     #01
TRD128          EQU     #02
EXPN            EQU     #03
TRD48           EQU     #04
BAS48           EQU     #05
REBOOTM         EQU     #02
HDDWP           EQU     #01

STYLES:
; Color	Style 0
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.WHITE
; Color	Style 1
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.LGREEN
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.LMAGENT
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.WHITE
; Color	Style 2
	DB	COLORS.CGA.PAPER.GREEN   + COLORS.CGA.INC.LCYAN
	DB	COLORS.CGA.PAPER.GREEN   + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.GREEN   + COLORS.CGA.INC.BLACK
; Color	Style 3
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.GREEN   + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.LGREEN
; Color	Style 4
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.BLUE
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.YELLOW
; Color	Style 5
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.BROWN
	DB	COLORS.CGA.PAPER.BROWN   + COLORS.CGA.INC.LGRAY
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.WHITE
; Color	Style 6
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.GREEN
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.GREEN
; Color	Style 7
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.LGRAY
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.BLUE    + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.RED     + COLORS.CGA.INC.WHITE
; Color	Style 8
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.LCYAN
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.LGREEN
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.WHITE
; Color	Style 9
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.GREEN   + COLORS.CGA.INC.BLUE
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.LRED
; Color	Style 10
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.RED
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.WHITE
; Color	Style 11
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.BLUE
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.MAGENTA + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.WHITE
; Color	Style 12
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.LGREEN
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.LCYAN
	DB	COLORS.CGA.PAPER.GREEN   + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.WHITE
; Color	Style 13
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.LGREEN
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.LCYAN
	DB	COLORS.CGA.PAPER.CYAN    + COLORS.CGA.INC.YELLOW
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.YELLOW
; Color	Style 14 (Mono)
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.LGRAY
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.WHITE
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.BLACK
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.LGRAY
; Color	Style 15
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.LMAGENT
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.LGREEN
	DB	COLORS.CGA.PAPER.LGRAY   + COLORS.CGA.INC.RED
	DB	COLORS.CGA.PAPER.BLACK   + COLORS.CGA.INC.RED

DEFVAL: DB	SAVERAM+EXTBIOS+SDELAY1					;X0E - OPTIONS
	DB	TDL250+TRATE30						;X0F - KEYBOARD
	DB	SDIDE1+ASDRECOVERY					;X10 - SYSTEM DISKS
	DB	FD1720+FD2720+HD1AUTO+HD2AUTO				;X11 - FDD & Primary HDD's
	DB	0							;X12 - CYLINDERS LOW MASTER
	DB	0							;X13 - CYLINDERS HIGH MASTER
	DB	0							;X14 - HEADS MASTER
	DB	0							;X15 - SECTORS MASTER
	DB	0							;X16 - CYLINDERS LOW SLAVE
	DB	0							;X17 - CYLINDERS HIGH SLAVE
	DB	0							;X18 - HEADS SLAVE
	DB	0							;X19 - SECTORS SLAVE
	DB	0							;X1A - Int conf, Screen sync, COLOR STYLE
	DB	TURBON+SPRIN						;X1B - HARDARE CONF
	DB	BAS128							;X1C - RESET MODE
	DB	REBOOTM							;X1D - REBOOT
	DB	0							;X1E - TRDOS
	DB	#77							;X1F - SCREEN POSITION
	DB	HD1AUTO+HD2AUTO						;X20 - Secondary HDD's
.Size	EQU	$-DEFVAL


;!FIXIT расписать тут ячейки кмоса и это смещение меткой привязать вместо #0E в SETDEF
        _mInfoALIGN 256,0						; выравнивание на адрес #XX00
CMOSARE:
	DS	14
	;
	DB	SAVERAM+EXTBIOS						;X0E - OPTIONS
	DB	TDL250+TRATE30						;X0F - KEYBOARD
	DB	SDIDE1+ASDFDD2						;X10 - SYSTEM DISKS
	DB	FD1720+FD2720+HD1AUTO+HD2AUTO				;X11 - FDD & HDD
	DB	0							;X12 - CYLINDERS LOW MASTER
	DB	0							;X13 - CYLINDERS HIGH MASTER
	DB	0							;X14 - HEADS MASTER
	DB	0							;X15 - SECTORS MASTER
	DB	0							;X16 - CYLINDERS LOW SLAVE
	DB	0							;X17 - CYLINDERS HIGH SLAVE
	DB	0							;X18 - HEADS SLAVE
	DB	0							;X19 - SECTORS SLAVE
	DB	0							;X1A - Int conf, Screen sync, COLOR STYLE
	DB	TURBON+SPRIN						;X1B - HARDARE CONF
	DB	BAS128							;X1C - RESET MODE
	DB	REBOOTM							;X1D - REBOOT MSG, HDD W/P
	DB	%0000'0000						;X1E - TRDOS
	DB	%0111'0111						;X1F - SCREEN POSITION
	DB	HD1AUTO+HD2AUTO						;X20 - Secondary HDD's
	DB	%0000'0000						;X21
	DB	%0000'0000						;X22
	DB	%0000'0000						;X23
	DB	%0000'0000						;X24
	DB	%0000'0000						;X25
	DB	%0000'0000						;X26
	DB	%0000'0000						;X27
	DB	%0000'0000						;X28
	DB	%0000'0000						;X29
	DB	%0000'0000						;X2A
	DB	%0000'0000						;X2B
	DB	%0000'0000						;X2C
	DB	%0000'0000						;X2D
	DB	%0000'0000						;X2E
	DB	%0000'0000						;X2F
	DB	%0000'0000						;X30
	DB	%0000'0000						;X31
	DB	#20							;X32 - CENTURY
	DB	%0000'0000						;X33
	DB	%0000'0000						;X34
	DB	%0000'0000						;X35
	DB	%0000'0000						;X36
	DB	%0000'0000						;X37
	DB	%0000'0000						;X38
	DB	%0000'0000						;X39
	DB	%0000'0000						;X3A
	DB	%0000'0000						;X3B
	DB	%0000'0000						;X3C
	DB	%0000'0000						;X3D
	DB	%0000'0000						;X3E
	DB	%0000'0000						;X3F - CHECKSUM
 BLOCK   #100 - low $                                                   ; добивка CMOSARE до размера в 256 байтов
;DONT MOVE !!! ADDRESS


; !TODO всё правильно?
;REGISTER #0E
; %1000'0000 - MEMORY TEST
; %0100'0000 - SAVE RAM DISKS
; %0010'0000 - UPDATE BIOS
; %0001'1000 - START DELAY
; %0000'0100 - LANGUAGE
; %0000'0010 - NOT USED
; %0000'0001 - QUICK START
;REGISTER #0F
; %1000'0000 - TYPEMATIC	ON/OFF
; %0110'0000 - TYPEMATIC	DELAY 00-250, 01-500, 10-750, 11-1000
; %0001'1111 - TYPEMATIC	RATE
;		0-6, 1-8, 2-10,	3-12, 4-15, 5-20, 6-24,	7-30
;REGISTER #10
; %0000'0111 - SYSTEM DISK
; %0111'0000 - ALT SYSTEM DISK
;REGISTER #11
; %0000'0011 - FDD FIRST	  720 /	1.44  /	NONE
; %0000'1100 - FDD SECOND
; %0011'0000 - IDE Primary MASTER AUTO /	SETUP /	DISABLED
; %1100'0000 - IDE Primary SLAVE		-----//------
;REGISTER #12 -	CYLINDERS (MASTER)
;REGISTER #14 -	HEADS	  (MASTER)
;REGISTER #15 -	SECTORS	  (MASTER)
;REGISTER #16 -	CYLINDERS (SLAVE)
;REGISTER #18 -	HEADS	  (SLAVE)
;REGISTER #19 -	SECTORS	  (SLAVE)
;REGISTER #1A
; %0000'1111 - COLOR STYLE
; %0011'0000 - Frame Int (Default/Pentagon/Scorpion/Original)
; %1100'0000 - Screen V-Sinc (Default/312 lines 50 HZ/320 Lines 49 Hz)
;REGISTER #1B -	HARDWARE CONFIGURATION
; %0000'0001 - TURBO MODE (D0..D3 - 6 OR	7)
; %0000'0010 - TURBO EXCHANGE ON/OFF - 1
; %0000'0100 - PORT EXCHANGE ON/OFF - 1
; %0001'1000 - COMPUTER
;		0-SPRINTER
;		1-SPECTRUM 256
;		2-PENTAGON 128
;		3-OTHER
; %1110'0000 - RESERVED
;REGISTER #1C -	RESET MODE
;		0-RESET	128 Basic
;		1-RESET	48 Basic & 128 mem
;		2-RESET	TR-DOS & 128 mem
;		3-RESET	EXPANSION (Disabled)
;		4-RESET	TR-DOS & 48 mem
;		5-RESET	48 Basic
;REGISTER #1D
; %0000'0010 - Reboot message
; %0000'0001 - HDD Write	protect
;REGISTER #1E
; %0000'0011 - TR DOS A:	Default	 / FDD / HDD / RMD
; %0000'1100 - TR DOS B:	Default	 / FDD / HDD / RMD
; %0011'0000 - TR DOS C:	Default	 / FDD / HDD / RMD
; %1100'0000 - TR DOS D:	Default	 / FDD / HDD / RMD
;REGISTER #1F           ;R06
; %1111'0000 - X-Screen position
; %0000'1111 - Y-Screen position
;REGISTER #20
; %0011'0000 - IDE Secondary MASTER AUTO /	SETUP /	DISABLED
; %1100'0000 - IDE Secondary SLAVE		-----//------
; .
; .
;REGISTER #37 -	CYLINDERS (MASTER)
;REGISTER #39 -	HEADS	  (MASTER)
;REGISTER #3A -	SECTORS	  (MASTER)
;REGISTER #3B -	CYLINDERS (SLAVE)
;REGISTER #3D -	HEADS	  (SLAVE)
;REGISTER #3E -	SECTORS	  (SLAVE)