; Hlavicka - predelat!!!

; Draw_main_menu_options - number, number2, data,
; Is_on_actual_page - T-bit
; Calc_line - data	; Podle cisla radku vypocita, na ktere strance se dana
  ; volba ma zobrazit
; Draw_main_menu_line	; Oddelovaci cara v hlavnim menu

; Enter_to_submenu - number
  ; Enter_to_submenu_past
  ; is_selected_menu_*

; Do_submenu_algorithms
; In_submenu_confirm
; In_submenu_confirm_is_*

; Show_* (main nemu options)
; Show_small_help

; In_submenu_pressed_up
; In_submenu_pressed_down

; In_submenu_pressed_up_III
; In_submenu_pressed_down_III

; In_main_menu_pressed_up
; In_main_menu_pressed_down


; In_submenu_confirm_change_number
; In_submenu_confirm_change_number_III

; Show_selected_menu_is_*

; Show_settings_saved
; Show_Statistics_data - --||-- (to same, kvuli vykreslovacim algoritmum)

; Show_graphics_from_flash



Draw_main_menu_options:
  ; Vykresli moznosti v hlavnim menu

	LDS number,main_menu_selected_option_I_SRAM	; do "number" si
  ; nahrajeme inforamci o tom, ktera polozka je v menu vybrana
  ; number - polozka


Draw_Trig_mode_test:
  ; Nejdrive si zkontrolujeme, jestli je "Trig_mode" na aktualni strance
	LDI number2,Trig_mode	; do "number2" si ulozime cislo, ktere
  ; reprezentuje "Trig_mode". "Trig_mode" je vlastne cislo, ktere je
  ; definovane v main_uc.asm
	RCALL Is_on_actual_page	; tento podprogram nam zjisti, jestli je
  ; dana funkce na aktualni strane, nebo ne
	BRTS Draw_Num_of_sampl_test	; pokud neni na aktualni strane, pak
  ; nema smysl se toto volbou dale zabyvat -> kontrola dalsi volby

  ; Takze pokud se dostaneme sem, tak musime zjistit, na jaky radek se ma
  ; tato moznost vykreslit. Resp. vykrslit se muze na radek 0~7, ale cislo
  ; poradi muze byt treba 10, coz znamena 1. strana (cisluje se od nuly),
  ; 3. radek. A prave tuto praci za nas udela nasledujici podprogram
	RCALL Calc_line	; Cislo vypocteneho radku je ulozeno v "data"

	CALL select_line_both	; vybereme radek

  ; zbyva zjistit, jestli neni aktualni moznost vybrana
;	CLT	; defaultni je cerne pismo...T na "0" -> "normalni" pismena.
  ; Pokud nastavime T bit do "1" -> bila pismena, cerne pozadi
	CPI number,Trig_mode
	BRNE Draw_Trig_mode	; pokud ne, skok na "Draw_Trig_mode"
  ; Pokud je dana moznost vybrana, pak ji zvyraznime
	SET	; Nastavime barvu pisma na inverzni a pokracuje se dal
Draw_Trig_mode:
	LDI ZH,HIGH(2*MM_Trigger_mode)
	LDI ZL,LOW(2*MM_Trigger_mode)
	LDI data,0	; tim si nastavime, ze chceme vykreslovat od 0.px
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_Num_of_sampl_test:
	LDI number2,Num_of_sampl
	RCALL Is_on_actual_page
	BRTS Draw_Waiting_int_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,Num_of_sampl
	BRNE Draw_Num_of_sampl
	SET
Draw_Num_of_sampl:
	LDI ZH,HIGH(2*MM_Number_of_samples)
	LDI ZL,LOW(2*MM_Number_of_samples)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_Waiting_int_test:
	LDI number2,Waiting_int
	RCALL Is_on_actual_page
	BRTS Draw_Show_stats_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,Waiting_int
	BRNE Draw_Waiting_int
	SET
Draw_Waiting_int:
	LDI ZH,HIGH(2*MM_Waiting_interval)
	LDI ZL,LOW(2*MM_Waiting_interval)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_Show_stats_test:
	LDI number2,Show_stats
	RCALL Is_on_actual_page
	BRTS Draw_Animations_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,Show_stats
	BRNE Draw_Show_stats
	SET
Draw_Show_stats:
	LDI ZH,HIGH(2*MM_Show_Statistics)
	LDI ZL,LOW(2*MM_Show_Statistics)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_Animations_test:
	LDI number2,Animations
	RCALL Is_on_actual_page
	BRTS Draw_About_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,Animations
	BRNE Draw_Animations
	SET
Draw_Animations:
	LDI ZH,HIGH(2*MM_Animations)
	LDI ZL,LOW(2*MM_Animations)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_About_test:
	LDI number2,About
	RCALL Is_on_actual_page
	BRTS Draw_Draw_method_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,About
	BRNE Draw_About
	SET
Draw_About:
	LDI ZH,HIGH(2*MM_About)
	LDI ZL,LOW(2*MM_About)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_Draw_method_test:
	LDI number2,Draw_method
	RCALL Is_on_actual_page
	BRTS Draw_Help_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,Draw_method
	BRNE Draw_Draw_method
	SET
Draw_Draw_method:
	LDI ZH,HIGH(2*MM_Draw_method)
	LDI ZL,LOW(2*MM_Draw_method)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_Help_test:
	LDI number2,Help
	RCALL Is_on_actual_page
	BRTS Draw_VAR_mode_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,Help
	BRNE Draw_Help
	SET
Draw_Help:
	LDI ZH,HIGH(2*MM_Help)
	LDI ZL,LOW(2*MM_Help)
	LDI data,0
	CALL write_text_from_DB
; *-----------------------------------------*
Draw_VAR_mode_test:
	LDI number2,VAR_mode
	RCALL Is_on_actual_page
	BRTS Draw_something_else_test
	RCALL Calc_line
	CALL select_line_both
	CPI number,VAR_mode
	BRNE Draw_VAR_mode
	SET
Draw_VAR_mode:
	LDI ZH,HIGH(2*MM_VAR_mode)
	LDI ZL,LOW(2*MM_VAR_mode)
	LDI data,0
	CALL write_text_from_DB


Draw_something_else_test:


	CLT	; nastavime barvu pisma zase na normalni
  ; Je to zde proto, ze kdyz se zvoli posledni moznost, T-bit se nastavi
  ; do "1" a pak uz se nenastavi na "0"

    ; Vykreslime delici caru
	RCALL Draw_main_menu_line
Draw_small_help:
    ; A zobrazime zakladni napovedu, pro BFU :)
	LDI ZH,HIGH(2*MM_small_help_1)
	LDI ZL,LOW(2*MM_small_help_1)
	LDI data,0
	CALL select_line_both	; Vybereme horni radek
	STS Samples_begin_SRAM,data
	; A nyni nastavime X souradnici
	LDI data,67
	CALL write_text_from_DB

	SET	; nastavi se barva pisma na bile
	LDI ZH,HIGH(2*Symbol_arrow_up)
	LDI ZL,LOW(2*Symbol_arrow_up)
	CALL write_text_from_DB
	CLT	; nastvi se barva pisma na cerne

  ; 1 px mezera
	PUSH data
	CLR data
	CALL write_right
	POP data
	INC data

	LDI ZH,HIGH(2*MM_small_help_2)
	LDI ZL,LOW(2*MM_small_help_2)
	CALL write_text_from_DB

	SET	; nastavi se barva pisma na bile
	LDI ZH,HIGH(2*Symbol_arrow_down)
	LDI ZL,LOW(2*Symbol_arrow_down)
	CALL write_text_from_DB
	CLT

  ; 1 px mezera
	PUSH data
	CLR data
	CALL write_right
	POP data
	INC data

	LDI ZH,HIGH(2*MM_small_help_3)
	LDI ZL,LOW(2*MM_small_help_3)
	CALL write_text_from_DB

        LDI data,1
        CALL select_line_both
  ;      STS Samples_begin_SRAM,data

        LDI data,65
	LDI ZH,HIGH(2*MM_small_help_4)
	LDI ZL,LOW(2*MM_small_help_4)
	CALL write_text_from_DB

        LDI data,3
        CALL select_line_both
  ;      STS Samples_begin_SRAM,data
        LDI data,67
	CLT
	LDI ZH,HIGH(2*MM_small_help_5)
	LDI ZL,LOW(2*MM_small_help_5)
	CALL write_text_from_DB

	SET
	LDI ZH,HIGH(2*MM_small_help_6)
	LDI ZL,LOW(2*MM_small_help_6)
	CALL write_text_from_DB

	CLT
	LDI ZH,HIGH(2*MM_small_help_7)
	LDI ZL,LOW(2*MM_small_help_7)
	CALL write_text_from_DB

	SET
	LDI ZH,HIGH(2*Symbol_arrow_right)
	LDI ZL,LOW(2*Symbol_arrow_right)
	CALL write_text_from_DB

        LDI data,4
        CALL select_line_both
 ;       STS Samples_begin_SRAM,data
	CLT
        LDI data,65
	LDI ZH,HIGH(2*MM_small_help_8)
	LDI ZL,LOW(2*MM_small_help_8)
	CALL write_text_from_DB


        LDI data,6
        CALL select_line_both
;        STS Samples_begin_SRAM,data

        LDI data,67
	LDI ZH,HIGH(2*MM_small_help_9)
	LDI ZL,LOW(2*MM_small_help_9)
	CALL write_text_from_DB

	SET
	LDI ZH,HIGH(2*Big_X)
	LDI ZL,LOW(2*Big_X)
	CALL write_text_from_DB

	CLT
	LDI ZH,HIGH(2*MM_small_help_10)
	LDI ZL,LOW(2*MM_small_help_10)
	CALL write_text_from_DB

	SET
	LDI ZH,HIGH(2*Symbol_arrow_left)
	LDI ZL,LOW(2*Symbol_arrow_left)
	CALL write_text_from_DB

  ; 1 px mezera
	PUSH data
	CLR data
	CALL write_right
	POP data
	INC data

	CLT
	LDI ZH,HIGH(2*MM_small_help_11)
	LDI ZL,LOW(2*MM_small_help_11)
	CALL write_text_from_DB

        LDI data,7
        CALL select_line_both
;        STS Samples_begin_SRAM,data

        LDI data,65
	LDI ZH,HIGH(2*MM_small_help_12)
	LDI ZL,LOW(2*MM_small_help_12)
	CALL write_text_from_DB

	RET
; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*
Is_on_actual_page:
  ; zjisti, jestli je dany objekt (number2) na aktualni strane (vypoctene
  ; podle number)
	SET	; nastavime T bit na "1". Pozdeji bude slouzit pro vyhodnoceni

Test_page_0:	; < 0 ; 7 >
	CPI number,8	; porovname aktualni vybrany radek s 8
  ; (nejprve si zjistime, jak se aktualni strana a pak se zjistuje, zda je
  ; objekt na dane strance -CLT, nebo neni -SET)
	BRSH Test_page_1	; pokud je stejny, nebo vetsi -> skok na
  ; "Test_page_1"

  ; Takze pokud se dostaneme sem, pak je jasne, ze musime zobrazovat prvni
  ; stranu (vyse je pouzita 0, protoze se cisluje od nuly). Takze uz zbyva
  ; zjistit, zda je dany objekt (number2) v mezich < 0 ; 7 >
	CPI number2,8	; kontrola, zda je vetsi, nebo rovno nez 8
	BRSH Test_page_fail	; pokud ano, skok na navesti (neni na dane
  ; strance)
	CLT	; pokud ne, vycistime T bit -> pak se bude vyhodnocovat
	RET


Test_page_1:	; < 8 ; 15>
	CPI number,16
	BRSH Test_page_2	; analogicky jako vyse

	CPI number2,16	; porovnani s cislem 16
	BRSH Test_page_fail	; pokud je vetsi, nebo rovno 16, pak neni na
  ; dane strane
  ; Takze jsme si overili, ze je v intervalu < 0 ; 15>
	CPI number2,8
	BRLO Test_page_fail	; pokud bude mensi jak 8, pak je jasne, ze
  ; nemuze byt na aktualni strane

  ; takze pokud se dostaneme sem, tak je objekt na aktualni strane
	CLT
	RET

Test_page_2:	; < 16 ; 23>
	JMP END	; zatim se s touto stanou nepocita -> chyba

Test_page_fail:
  ; Neni co resit
	RET
; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*
Calc_line:
  ;Podle cisla radku vypocita, na ktere strance se dana volba ma zobrazit

  ; jako parametr je cislo ulozene v "number2". Vystup je pak ulozen v "data"

	MOV data,number2	; abychom nemuseli u kazde podminky psat znovu
  ; a znovu. Kod by pak byl zbytecne vetsi a pritom stejne rychly

	CPI number2,8
	BRSH Calc_line_page_1	; test, jestli neni cislo vetsi jak 8. V tom
  ; pripade totiz jiste neni na prvni strane (cislovani je od nuly)
  
  ; takze pokud se dostaneme sem, pak je jasne, ze se jedna o stranu 0. Zbyva
  ; tedy urcit radek, coz je preste ta hodnota, ktera je ulozena v "number2".
  ; A tato hodnota byla vyse presunuta do "data"
	RET

Calc_line_page_1:
  ; analogicka kontrola jako vyse
	CPI number2,16
	BRSH Calc_line_page_2
  ; takze nyni je jiste, ze jde o stranu 1. Opet musime urcit radek. To
  ; dosahneme jednoduchouckou operaci
	SUBI data,8
	RET

Calc_line_page_2:	; taky se nepocita, ze bude vic jak 2 strany
	RJMP Test_page_2

; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*

Draw_main_menu_line:	; Oddelovaci cara v hlavnim menu
;	LDS number,main_menu_selected_option_I_SRAM	; do "number" si
  ; nahrajeme inforamci o tom, ktera polozka je v menu vybrana
  ; Nemusime znovu nahravat, protoze data v teto promenne zustala od minule
	CLR CNT	; CNT bude pocitat radky
	STS main_menu_selected_option_I_SRAM,number	; v "number" bude info
  ; o vybranem radku
Draw_main_menu_line_cycle:
	MOV data,CNT
	CALL select_line_both	; vyber aktualniho radku

  ; Vyber Xovou souradnici
	LDI data,61
	CALL select_X_both

  ; Zapis oddelovaci cary na LCD
	LDI data,0b10101010
	CALL write_left	; predpokladame, ze se leva cast vejde
  ; na levou polovinu displeje

Draw_main_menu_line_cycle_before_test:
	INC CNT		; pokud zapiseme na 7. radek, uz dalsi neni k
  ; dispozici -> kontrola a pripadne vyskoceni z cyklu
	CPI CNT,8
	BRNE Draw_main_menu_line_cycle	; pokud jsme jeste nevykreslili
  ; vsech 8 radku, pak skok na Draw_main_menu_line_cycle a pokracuje se
	
	RET




; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*





Enter_to_submenu:	; po stisknuti "OK", nebo "->" se dostaneme do
  ; pod-menu -> musime zjistit, jake submenu se ma vykreslit

  ; Musime zajistit, aby se provedl refresh po navratu z tohoto menu -> zmena
  ; zalozni promenne na $FF (tolik moznosti snad ani v menu nebude :D )
	LDI tmp,$FF
	STS main_menu_selected_option_I_last_SRAM,tmp

  ; Ale jeste predtim si zjistime, jakou hodnotu mame nahrat do promenne
  ; "main_menu_selected_option_II_SRAM" - aby pri stisku tlacitka byla
  ; zvolena jako defaultni posledni nastavena hodnota

	LDS number,main_menu_selected_option_I_SRAM	; zjistime si zvolene
  ; pod-menu a podle toho se rozhodne, jake promenne si mame pripravit.
  ; U nekterych funkci to muzou byt dve promenne, u nekterych zadne.

  ; Je dobre poskladat si funkce podle cetnosti pouzivani od nejvyce pouzivane
  ; funkce, po nejmene pouzivanou funkci. Jednak to umozni lepsi orientaci
  ; v kodu a jednak se o neco zvysi vykon

Enter_to_submenu_pre_Trig_mode:
	CPI number,Trig_mode	; kontrola, zda neni vybran radek
  ; s "Trig_mode" (Jeho hodnota je opet uz definovana v "main_uC.asm")
	BRNE Enter_to_submenu_pre_Trig_mode_end	; pokud ne, skok na
  ; "Enter_to_submenu_pre_Trig_mode_end"
  ; Pokud je zvolena tato moznost, pak se provedou nasledujici prikazy
	LDS tmp,trigger_mode_SRAM	; stahneme si informaci o aktualnim
  ; trigger modu
	STS main_menu_selected_option_II_SRAM,tmp	; a ulozime ji do
  ; patricne promenne
	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Trig_mode_end:
  ; skokem na konec dosahneme vetsi efektivity kodu, pokud dame casto
  ; pouzivane funkce na zacatek vyhodnocovaciho algoritmu. Proto se odkazujeme
  ; na konec aktualni moznosti a ne na nasledujici, ale z hlediska spusteni
  ; prikazu a poctu cyklu je to jedno a to same
; *-----------------------------------------*
Enter_to_submenu_pre_Num_of_sampl:
  ; a tady test na "Num_of_sampl" radek atd....
	CPI number,Num_of_sampl
	BRNE Enter_to_submenu_pre_Num_of_sampl_end

	LDS tmp,number_of_samples_mode_SRAM	; pocet vzorku - mod
  ; (auto, manual)
	STS main_menu_selected_option_II_SRAM,tmp

	LDS tmp,number_of_samples_SRAM	; pocet vzorku
	STS main_menu_selected_option_III_SRAM,tmp

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Num_of_sampl_end:
; *-----------------------------------------*
Enter_to_submenu_pre_Waiting_int:
	CPI number,Waiting_int
	BRNE Enter_to_submenu_pre_Waiting_int_end

	LDS tmp,waiting_interval_mode_SRAM
	STS main_menu_selected_option_II_SRAM,tmp

	LDS tmp,waiting_interval_buffer_SRAM
	STS main_menu_selected_option_III_SRAM,tmp

	LDS tmp,waiting_interval_keyboard_SRAM
	STS main_menu_selected_option_IV_SRAM,tmp

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Waiting_int_end:
; *-----------------------------------------*
Enter_to_submenu_pre_Show_stats:
	CPI number,Show_stats
	BRNE Enter_to_submenu_pre_Show_stats_end

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Show_stats_end:
; *-----------------------------------------*
Enter_to_submenu_pre_Animations:
	CPI number,Animations
	BRNE Enter_to_submenu_pre_Animations_end

	LDS tmp,animations_mode_SRAM
	STS main_menu_selected_option_II_SRAM,tmp

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Animations_end:
; *-----------------------------------------*
Enter_to_submenu_pre_About:
	CPI number,About
	BRNE Enter_to_submenu_pre_About_end

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_About_end:
; *-----------------------------------------*
Enter_to_submenu_pre_Draw_method:
	CPI number,Draw_method
	BRNE Enter_to_submenu_pre_Draw_method_end

	LDS tmp,draw_mode_SRAM
	STS main_menu_selected_option_II_SRAM,tmp

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Draw_method_end:
; *-----------------------------------------*
Enter_to_submenu_pre_Help:
	CPI number,Help
	BRNE Enter_to_submenu_pre_Help_end

	LDS tmp,help_option_SRAM
	STS main_menu_selected_option_II_SRAM,tmp	; Naposledy zvolena
  ; napoveda (jedna z X v help menu)

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_Help_end:
; *-----------------------------------------*
Enter_to_submenu_pre_VAR_mode:
	CPI number,VAR_mode
	BRNE Enter_to_submenu_pre_VAR_mode_end

	RJMP Enter_to_submenu_past
Enter_to_submenu_pre_VAR_mode_end:
; *-----------------------------------------*

Enter_to_submenu_past:
;	LDS data,main_menu_selected_option_II_last_SRAM
  ; A zjistime, zda je potreba provest refresh
;	CP tmp,data	; porovname. Pokud budou stejne, neni potreba provest
  ; refresh

	CALL Clear_right_half_of_LCD	; "Vycistime" pravou polovinu LCD

	LDS tmp,main_menu_selected_option_I_SRAM	; a musime stejnak
  ; nacist data z SRAM znovu, protoze pri dalsim skoku na
  ; Enter_to_submenu_past se data v temer vsech registrech zmeni -> delalo
  ; by to proste bordel

  ; Opet je dobre seradit funkce podle cetnosti pouzivani. Zvysi se tim mirne
  ; vykon
; *-----------------------------------------*
is_selected_menu_Trigger_mode:
	CPI tmp,Trig_mode	; zjistime jestli neni vybrana "Trig_mode"
  ; moznost
	BRNE is_selected_menu_Trigger_mode_end	; pokud neni vybrana tato
  ; moznost, pak skok na konec teto casti a tam se automaticky pokracuje na
  ; dalsi moznost
	RCALL Show_selected_menu_is_Trigger_mode
	RJMP Do_submenu_algorithms
is_selected_menu_Trigger_mode_end:
; *-----------------------------------------*
is_selected_menu_Num_of_sampl:
	CPI tmp,Num_of_sampl
	BRNE is_selected_menu_Num_of_sampl_end

	RCALL Show_selected_menu_is_Num_of_sampl
	RJMP Do_submenu_algorithms
is_selected_menu_Num_of_sampl_end:
; *-----------------------------------------*
is_selected_menu_Waiting_int:
	CPI tmp,Waiting_int
	BRNE is_selected_menu_Waiting_int_end

	RCALL Show_selected_menu_is_Waiting_int
	RJMP Do_submenu_algorithms
is_selected_menu_Waiting_int_end:
; *-----------------------------------------*
is_selected_menu_Show_stats:
	CPI tmp,Show_stats
	BRNE is_selected_menu_Show_stats_end

	RJMP Show_Statistics_data
is_selected_menu_Show_stats_end:
; *-----------------------------------------*
is_selected_menu_Animations:
	CPI tmp,Animations
	BRNE is_selected_menu_Animations_end

	RCALL Show_selected_menu_is_Animations
	RJMP Do_submenu_algorithms
is_selected_menu_Animations_end:
; *-----------------------------------------*

is_selected_menu_About:
	CPI tmp,About
	BRNE is_selected_menu_About_end

	RJMP Show_selected_menu_is_About_info
is_selected_menu_About_end:
; *-----------------------------------------*
is_selected_menu_Draw_method:
	CPI tmp,Draw_method
	BRNE is_selected_menu_Draw_method_end

	RCALL Show_selected_menu_is_Draw_mode
	RJMP Do_submenu_algorithms
is_selected_menu_Draw_method_end:
; *-----------------------------------------*
is_selected_menu_Help:
	CPI tmp,Help
	BRNE is_selected_menu_Help_end

	RCALL Show_selected_menu_is_Help_complete
	RJMP Do_submenu_algorithms
is_selected_menu_Help_end:
; *-----------------------------------------*
is_selected_menu_VAR_mode:
	CPI tmp,VAR_mode
	BRNE is_selected_menu_VAR_mode_end

	RJMP V_mode_pre	; Skoci na tento mod.
	RET	; A pak se vrati :)
is_selected_menu_VAR_mode_end:
; *-----------------------------------------*

;	LDI tmp,1	; kod pro Menu mode
;	STS previous_mode_SRAM,tmp

;	RET
; *-----------------------------------------*
	RET	; pokud nebude vybrana jedina moznost, pak asi pripocist
  ; 1 do promenne "error" a skok zpet


Do_submenu_algorithms:
  ; Tady je opet stare reseni toho, aby LCD "neblikalo"
;	CALL wait_100ms	; Aby na LCD bylo vubec neco videt ;-)

  ; Nove reseni:
	LDS tmp,main_menu_selected_option_II_SRAM
	STS main_menu_selected_option_II_last_SRAM,tmp	; aktualni moznost
  ; jsme ulozili do "main_menu_selected_option_II_last_SRAM"

Do_submenu_algorithms_recive_data_keyboard:
	CALL recive_data_keyboard	; zjistime si, jestli si uzivatel
  ; nechce vybrat nejakou jinou moznost, nez je defaultni
	LDS time1,keyboard_L_SRAM	; stahneme si data do time1

	SBRC time1,plus_time_base	; test na tlacitko "sipka nahoru"
	RCALL In_submenu_pressed_up

	SBRC time1,minus_time_base
	RCALL In_submenu_pressed_down	; test na tlacitko "sipka dolu"


	SBRC time1,OK	; test na OK
	RCALL In_submenu_confirm


	SBRC time1,arrow_right	; nebo sipku vpravo
	RCALL In_submenu_confirm


	SBRC time1,X	; test na tlacitko "zpet"
	RJMP Enter_to_submenu_ending

	SBRC time1,arrow_left
	RJMP Enter_to_submenu_ending

  ; Nove reseni obnovy dat na LCD
	LDS tmp,main_menu_selected_option_II_last_SRAM
	LDS data,main_menu_selected_option_II_SRAM
	CP tmp,data
	BREQ Do_submenu_algorithms_recive_data_keyboard	; pokud se data v
  ; obou pametovych bunkach shoduji -> nacti data z klavesnice znovu

	RJMP Enter_to_submenu_past	; pokud nebylo stisknuto tlacitko
  ; "zpet", pak se znovu vykresli data na LCD (obnovi se)

Enter_to_submenu_ending:	; nutna procedura
	CLR time1	; aby pri stisknuti "X" uzivatel nevyskocil do
  ; posledniho zvoleneho modu, ale jen do hlavniho menu
	RET
; *-----------------------------------------*
In_submenu_confirm:
	LDS number,main_menu_selected_option_I_SRAM	; zjistime si, ktera
  ; z hlavnich nabidek byla aktivni a podle toho se na patricne misto ulozi
  ; dana promenna

In_submenu_confirm_Trig_mode:
	CPI number,Trig_mode
	BRNE In_submenu_confirm_Trig_mode_end	; pokud to nebude "Trig_mode",
  ; pokracuje se na In_submenu_confirm_Trig_mode_end a tam bude nasledovat
  ; dalsi test na dalsi moznost
	RCALL In_submenu_confirm_is_Trig_mode
	RJMP In_submenu_confirm_save_settings
In_submenu_confirm_Trig_mode_end:


In_submenu_confirm_Num_of_sampl:
	CPI number,Num_of_sampl
	BRNE In_submenu_confirm_Num_of_sampl_end
	RCALL In_submenu_confirm_is_Num_of_sampl
In_submenu_confirm_Num_of_sampl_end:


In_submenu_confirm_Waiting_int:
	CPI number,Waiting_int
	BRNE In_submenu_confirm_Waiting_int_end
	RCALL In_submenu_confirm_is_Waiting_int
In_submenu_confirm_Waiting_int_end:


In_submenu_confirm_Draw_method:
	CPI number,Draw_method
	BRNE In_submenu_confirm_Draw_method_end

	RCALL In_submenu_confirm_is_Draw_method
In_submenu_confirm_Draw_method_end:


In_submenu_confirm_Animations:
	CPI number,Animations
	BRNE In_submenu_confirm_Animations_end

	RCALL In_submenu_confirm_is_Animations
  ; Zde vyjimecne nebudeme zobrazovat zpravu: "Settings saved", ale rovnou
  ; se spusti patricna animace. Zde muzeme vyuzit toho, ze po spusteni
  ; "In_submenu_confirm_is_Animations" zustane v registru "tmp" ulozene
  ; uzivatelske nastaveni -> nyni vyuzijeme na zjisteni toho, jaka se
  ; ma spustit animace
	CPI tmp,0	; kontrola na 0 - animace "elements"
	BRNE In_submenu_confirm_Animations_1
	RCALL Anime_elements	; spusti animace a pak
	RJMP In_submenu_confirm_settings_saved_end	; preskocime ukladaci
  ; tabulku
In_submenu_confirm_Animations_1:
	CPI tmp,1
	BRNE In_submenu_confirm_Animations_2
	RCALL Anime_matrix
	RJMP In_submenu_confirm_settings_saved_end	; jako vyse
In_submenu_confirm_Animations_2:	; pripraveno pro dalsi animaci...

In_submenu_confirm_Animations_end:


In_submenu_confirm_Help:
	CPI number,Help
	BRNE In_submenu_confirm_Help_end

	RCALL In_submenu_confirm_is_Help
  ; Help je taky trochu jiny. Neco jako animace vyse. Je to z praktickeho
  ; duvodu. Aby napoveda byla prez celou obrazovku a ne prez pulku
	RJMP In_submenu_confirm_settings_saved_end
In_submenu_confirm_Help_end:

In_submenu_confirm_save_settings:
	RCALL Show_settings_saved	; zobrazime info o tom,ze je nastaveni
  ; ulozeno
In_submenu_confirm_settings_saved_end:

  ; pokud jsme "vylezli" z In_submenu_confirm, pak mame vse nastaveno
  ; a pravdepodobne budeme chtit do hlavni nabidky -> takze za uzivatele
  ; stickneme tlacitko "X"
	SET	; nastavime T bit do "1", a tento bit budeme kopirovat dal
	CLR time1
	BLD time1,X	; a nastavime, ze chceme pryc (do hlavni nabidky)
	RET


; *-----------------------------------------*
In_submenu_confirm_is_Trig_mode:
	LDS tmp,main_menu_selected_option_II_SRAM
	STS trigger_mode_SRAM,tmp	; a ulozime informaci do SRAM
  ; Informace se ihned vyuzije pro buffer

	CALL reset_buffer_and_send_cfg	; Restartuje buffer

	LDI tmp,$FF
	STS buffer_too_busy_SRAM,tmp	; A nastavime zaneprazdnenost bufferu
  ; na "1" (Protoze v dobe, kdy jsme v menu, je buffer zaneprazdnen)

	RET

; *-----------------------------------------*
In_submenu_confirm_is_Num_of_sampl:
	LDS number,main_menu_selected_option_II_SRAM
  ; Musime zjistit, zda byla vybrana moznost "Auto", nebo "Manual" a podle
  ; toho budto ulozit nastaveni, nebo pokracovat dal v programu
	CPI number,0	; test na nastaveni "Auto"
	BRNE In_submenu_confirm_is_Num_of_sampl_manual
  ; Pokud neni nastavena promenna na "Auto" pak musi byt nastavena na manual
  ; a provedou se nasledujici prikazy
	RJMP In_submenu_confirm_is_Num_of_sampl_save
In_submenu_confirm_is_Num_of_sampl_manual:
	LDI tmp,100
	STS min_value_submenu_SRAM,tmp
	LDI tmp,$FF
	STS max_value_submenu_SRAM,tmp

	LDS number,main_menu_selected_option_III_SRAM
	LDS tmp,main_menu_selected_option_II_SRAM
	PUSH tmp
	STS main_menu_selected_option_II_SRAM,number

In_submenu_confirm_is_Num_of_sampl_waiting_for_user_select:
	RCALL In_submenu_confirm_change_number	; meni cislo, podle pozadavku
  ; uzivatele. Akorat ho nevypisuje. Pokud bude v T-bitu "1", pak to znamena,
  ; že chceme ulozit nastaveni
	BRTS In_submenu_confirm_is_Num_of_sampl_save_manual	; pokud je v T-bitu
  ; "1", tak ulozit nastaveni -> skok

  ; A znovu se vykresli informace o aktualnim nastaveni
	LDI data,1	; 2. radek (cislovani od nuly, takze proto 1)
	CALL select_line_both

	CLR data
	CALL X_line_R

	SET	; nastavime barvu pisma
	LDI data,95	; a xova souradnice

	LDI ZH,HIGH(2*Symbol_up_and_down)
	LDI ZL,LOW(2*Symbol_up_and_down)
	CALL write_text_from_DB	; symbol sipka nahoru a dolu

	CALL Show_Dec_number_0_to_255
	CALL wait_50ms

	RJMP In_submenu_confirm_is_Num_of_sampl_waiting_for_user_select

In_submenu_confirm_is_Num_of_sampl_save_manual:
  ; Pokud bylo stisknuto "OK", nebo "->", pak se dostaneme sem
	LDS tmp,main_menu_selected_option_II_SRAM
	STS main_menu_selected_option_III_SRAM,tmp
	STS number_of_samples_SRAM,tmp
	POP tmp	; a obnoveni dat v main_menu_selected_option_II_SRAM
	STS main_menu_selected_option_II_SRAM,tmp
	STS number_of_samples_mode_SRAM,tmp

  ; A obnovime informace o offsetu vzorku
	CALL Calculate_samples_offset

  ; Bufferu posleme aktualni data
	CALL reset_buffer_and_send_cfg

	RET

In_submenu_confirm_is_Num_of_sampl_save:
	LDI tmp,0	; to je vybrany posledni mod - 0 - Auto
	STS number_of_samples_mode_SRAM,tmp

	CALL Show_time_base	; sice nam zobrazi aktualni casovou zakladnu,
  ; ale hlavne podle ni nastavi spravny pocet vzorku sam a automaticky
	LDI data,1
	CALL select_line_both
	CLR data
	CALL X_line_R	; tyto 4 radky zaruci, ze casova zakladna nebude
  ; az zase tolik videt

	RET
; *-----------------------------------------*
In_submenu_confirm_is_Waiting_int:
	LDS number,main_menu_selected_option_II_SRAM
  ; Zjistit, zda vybrana prvni, nebo druha moznost (Buffer/keyb.)

	CPI number,0
	BRNE In_submenu_confirm_is_Waiting_int_keyboard
  ; Pokud byla vybrana prvni moznost, pak se provedou nasledujici prikazy
	RJMP In_submenu_confirm_is_Waiting_int_buffer

In_submenu_confirm_is_Waiting_int_keyboard:
	LDI tmp,min_interval_keyboard	; tato hodnota je ulozena na zacatku
  ; "main_uC" z duvodu prehlednosti konstant
	STS min_value_submenu_SRAM,tmp

	LDI tmp,$FF
	STS max_value_submenu_SRAM,tmp

  ; Stahneme si hodnotu intervalu do number
	LDS number,main_menu_selected_option_IV_SRAM
  ; do "tmp" si ulozime hodnotu, ktera je ulozena
  ; v main_menu_selected_option_II_SRAM
	LDS tmp,main_menu_selected_option_II_SRAM
	PUSH tmp	; a tu si zalohujeme
	STS main_menu_selected_option_II_SRAM,number	; a hodnotu z
  ; main_menu_selected_option_IV_SRAM ulozime do
  ; main_menu_selected_option_II_SRAM, abychom si pak usetrili spoustu prace

In_submenu_confirm_is_Waiting_int_keyboard_waiting_for_user_select:
	RCALL In_submenu_confirm_change_number
	BRTS In_submenu_confirm_is_Waiting_int_save_keyboard

  ; A znovu se vykresli informace o aktualnim nastaveni
	LDI data,1
	CALL select_line_both

	CLR data
	CALL X_line_R

	SET
	LDI data,102

	LDI ZH,HIGH(2*Symbol_up_and_down)
	LDI ZL,LOW(2*Symbol_up_and_down)
	CALL write_text_from_DB
	CALL Show_Dec_number_0_to_255	; zobrazi data ulozena v "units",
  ; "tens" a "hundreds"
	CALL wait_50ms

	RJMP In_submenu_confirm_is_Waiting_int_keyboard_waiting_for_user_select

In_submenu_confirm_is_Waiting_int_save_keyboard:
  ; Pokud bylo stisknuto "OK", nebo "->", pak se dostaneme sem
	LDS tmp,main_menu_selected_option_II_SRAM
	STS main_menu_selected_option_IV_SRAM,tmp
	STS waiting_interval_keyboard_SRAM,tmp
In_submenu_confirm_is_Waiting_int_save:
	POP tmp
	STS main_menu_selected_option_II_SRAM,tmp
	STS waiting_interval_mode_SRAM,tmp
	RET


In_submenu_confirm_is_Waiting_int_buffer:
	LDI tmp,min_interval_buffer	; tato hodnota je definovana na
  ; zacatku "main_uC.asm"
	STS min_value_submenu_SRAM,tmp

	LDI tmp,$FF
	STS max_value_submenu_SRAM,tmp
  ; Stahneme si hodnotu intervalu do number
	LDS number,main_menu_selected_option_III_SRAM
  ; do "tmp" si ulozime hodnotu, ktera je ulozena
  ; v main_menu_selected_option_II_SRAM
	LDS tmp,main_menu_selected_option_II_SRAM
	PUSH tmp	; a tu si zalohujeme
	STS main_menu_selected_option_II_SRAM,number	; a hodnotu z
  ; main_menu_selected_option_III_SRAM ulozime do
  ; main_menu_selected_option_II_SRAM, abychom si pak usetrili spoustu prace
In_submenu_confirm_is_Waiting_int_buffer_waiting_for_user_select:
	RCALL In_submenu_confirm_change_number
	BRTS In_submenu_confirm_is_Waiting_int_save_buffer
  ; A znovu se vykresli informace o aktualnim nastaveni
	LDI data,1
	CALL select_line_both

	CLR data
	CALL X_line_R

	SET
	LDI data,73

	LDI ZH,HIGH(2*Symbol_up_and_down)
	LDI ZL,LOW(2*Symbol_up_and_down)
	CALL write_text_from_DB
	CALL Show_Dec_number_0_to_255
	CALL wait_50ms

	RJMP In_submenu_confirm_is_Waiting_int_buffer_waiting_for_user_select

In_submenu_confirm_is_Waiting_int_save_buffer:
  ; Pokud bylo stisknuto "OK", nebo "->", pak se dostaneme sem
	LDS tmp,main_menu_selected_option_II_SRAM
	STS main_menu_selected_option_III_SRAM,tmp
	STS waiting_interval_buffer_SRAM,tmp

	RJMP In_submenu_confirm_is_Waiting_int_save


; *-----------------------------------------*
In_submenu_confirm_is_Draw_method:
	LDS tmp,main_menu_selected_option_II_SRAM
	STS draw_mode_SRAM,tmp

	RET
; *-----------------------------------------*
In_submenu_confirm_is_Animations:
	LDS tmp,main_menu_selected_option_II_SRAM
	STS animations_mode_SRAM,tmp

	RET
; *-----------------------------------------*
In_submenu_confirm_is_Help:
  ; V teto fazi uzivatel potvrdil jednu z X moznosti. Takze musime zjistit,
  ; o kterou slo a podle toho spustit dany podprogram, ktery uzivateli zobrazi
  ; danou napovedu.

	CLR data
	STS main_menu_selected_option_III_SRAM,data	; nastavime pocatek
  ; napovedy na 0. radek
	STS min_value_submenu_SRAM,data	; Nastavime minimalni hodnotu na 0 ->
  ; -> pro vsechny moznosti stejna

  ; Aktivujeme zalamovani radku
	LDI tmp,1
	STS Auto_break_line_SRAM,tmp


	LDS tmp,main_menu_selected_option_II_SRAM	; do tmp si ulozime
  ; informaci o tom, co si uzivatel vlastne vybral


In_submenu_confirm_is_Help_Osc_mode:
	CPI tmp,0	; test na "Osc. mode"
	BRNE In_submenu_confirm_is_Help_Osc_mode_end

	RJMP Show_Help_Osc_mode	; skok na toto navesti. Na konci podprogramu
  ; je zase skok na "In_submenu_confirm_is_Help_end"
In_submenu_confirm_is_Help_Osc_mode_end:

In_submenu_confirm_is_Help_Trigger_mode:
	CPI tmp,1	; test na "Trig_mode"
	BRNE In_submenu_confirm_is_Help_Trigger_mode_end

	RJMP Show_Help_Trigger_mode
In_submenu_confirm_is_Help_Trigger_mode_end:

In_submenu_confirm_is_Help_Num_of_sam:
	CPI tmp,2	; test na "Num. of sam."
	BRNE In_submenu_confirm_is_Help_Num_of_sam_end

	RJMP Show_Help_Num_of_sam
In_submenu_confirm_is_Help_Num_of_sam_end:

In_submenu_confirm_is_Help_Draw_method:
	CPI tmp,3	; test na "Draw method"
	BRNE In_submenu_confirm_is_Help_Draw_method_end

	RJMP Show_Help_Draw_method
In_submenu_confirm_is_Help_Draw_method_end:

In_submenu_confirm_is_Help_Voltage_mode:
	CPI tmp,4	; test na "Voltage mode"
	BRNE In_submenu_confirm_is_Help_Voltage_mode_end

	RJMP Show_Help_Voltage_mode
In_submenu_confirm_is_Help_Voltage_mode_end:


In_submenu_confirm_is_Help_end:
  ; A posledni nastaveni se ulozi
	CLT
	LDS tmp,main_menu_selected_option_II_SRAM
	STS help_option_SRAM,tmp

	CLR tmp
	STS Auto_break_line_SRAM,tmp	; A vypne se zalamovani radku

	RET
; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*

Show_Help_Osc_mode:
  ; Uzivatel si bude moci listovat v menu (posouvat se nahoru a dolu).
  ; K tomu poslouzi promenna "main_menu_selected_option_III_SRAM"

	CLT
  ; rekneme v jakych mezich se bude moci uzivatel pohybovat
	LDI tmp,20	; proste kolikrat muze uzivatel stisknout tlacitko
  ; "dolu"
	STS max_value_submenu_SRAM,tmp
  ; nemusime nastavovat minimalni hodnotu -> uz jsme ji nastavili, protoze
  ; je pro vsechny podprogramy stejna


Show_Help_Osc_mode_show:
	RCALL Show_Help_small_routine

  ; Do Z si ulozime adresu databaze znaku
	LDI ZH,HIGH(2*HC_OSC)
	LDI ZL,LOW(2*HC_OSC)
	CALL write_text_from_DB	; Zobrazime pozadovany text

	RCALL Help_complete_check_keyboard	; nelze pouzit
  ; "In_submenu_confirm_change_number_III", protoze pri stisku plus_time_base
  ; se hodnota "main_menu_selected_option_III_SRAM" snizit a ne zvysit

  ; Provedeme test na T-bit - pokud byl nastaven -> ukonceni
	BRTC Show_Help_Osc_mode_show	; pokud byl T-bit "cisty"
	RJMP In_submenu_confirm_is_Help_end	; Pokud byl T-bit nastaven
; *-----------------------------------------*
Show_Help_Trigger_mode:
  ; Prakticky to same jako vyse, ale nastavuje se jina adresa a jine promenne
	CLT
	LDI tmp,2
	STS max_value_submenu_SRAM,tmp

Show_Help_Trigger_mode_show:
	RCALL Show_Help_small_routine

	LDI ZH,HIGH(2*HC_Trigger_mode)
	LDI ZL,LOW(2*HC_Trigger_mode)
	CALL write_text_from_DB

	RCALL Help_complete_check_keyboard
	BRTC Show_Help_Trigger_mode_show
	RJMP In_submenu_confirm_is_Help_end
; *-----------------------------------------*
Show_Help_Num_of_sam:
	CLT
	LDI tmp,17
	STS max_value_submenu_SRAM,tmp
Show_Help_Num_of_sam_show:
	RCALL Show_Help_small_routine

	LDI ZH,HIGH(2*HC_Num_of_sam)
	LDI ZL,LOW(2*HC_Num_of_sam)
	CALL write_text_from_DB

	RCALL Help_complete_check_keyboard
	BRTC Show_Help_Num_of_sam_show
	RJMP In_submenu_confirm_is_Help_end
; *-----------------------------------------*
Show_Help_Draw_method:
	CLT
	LDI tmp,0
	STS max_value_submenu_SRAM,tmp
Show_Help_Draw_method_show:
	RCALL Show_Help_small_routine

	LDI ZH,HIGH(2*HC_Draw_method)
	LDI ZL,LOW(2*HC_Draw_method)
	CALL write_text_from_DB

	RCALL Help_complete_check_keyboard
	BRTC Show_Help_Draw_method_show
	RJMP In_submenu_confirm_is_Help_end
; *-----------------------------------------*
Show_Help_Voltage_mode:
	CLT
	LDI tmp,12
	STS max_value_submenu_SRAM,tmp
Show_Help_Voltage_mode_show:
	RCALL Show_Help_small_routine

	LDI ZH,HIGH(2*HC_Voltage_mode)
	LDI ZL,LOW(2*HC_Voltage_mode)
	CALL write_text_from_DB

	RCALL Help_complete_check_keyboard
	BRTC Show_Help_Voltage_mode_show
	RJMP In_submenu_confirm_is_Help_end
; *-----------------------------------------*

; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*
Show_Help_small_routine:
  ; Tato cast kodu je pro vsechny moznosti naprosto stejna -> vyplati se
  ; volat jako podprogram -> jednodussi zmena
	CALL Clear_display	; Smazeme data z LCD. Program si nastavi
  ; ke konci jako aktivni radek nulty (uplne nahore) a nastavi Xovou
  ; souradnici na nula. To same plati tedy i o registru "data"
	STS write_text_from_DB_line_SRAM,data	; Musime opet nastavi na 0.
  ; Je to z toho duvodu, ze "write_text_from_DB" si tuto promennou meni behem
  ; sveho chodu a zpetne vlastne informuje o tom, jaky radek je prave aktivni.

	LDS tmp,main_menu_selected_option_III_SRAM
	STS wr_txt_from_DB_start_line_SRAM,tmp	; A nastavime pocatek
  ; vykreslovani
	RET
; *-----------------------------------------*

  ; Nacte data z klavesnice. Zjisti, jestli je potreba provest nejake zmeny.
  ; Pokud ano, pak je provede a nasteduje RET. Tento kod je vlastne stejny
  ; Pro vsechny "Show_Help_*"
Help_complete_check_keyboard:
  ; Meni hodnotu "main_menu_selected_option_III_SRAM" v mezich definovanych
  ; min_value_submenu_SRAM a max_value_submenu_SRAM. Do "time1" ulozi data
  ; z klavesnice. Pokud bude stisknuto tlacitko "OK", nebo "->" pak se do
  ; T-bitu ulozi "1"
  ; Pracuje s CNT,time1,T-bit
	LDS tmp,main_menu_selected_option_III_SRAM
	STS main_menu_selected_option_III_last_SRAM,tmp	; Zalohujeme si
  ; posledni aktualni nastaveni - pak se bude vyuzivat pro rozhodovani zda se
  ; ma provest refresh na LCD, nebo je to zbytecne
Help_complete_check_keyboard_1:

	CALL recive_data_keyboard	; Nacte data z klavesnice

	LDS time1,keyboard_L_SRAM	; Zpracovana data ulozi do "time1"

	SBRC time1,plus_time_base	; A kontrola pro jednotlive klavesy
	RCALL In_submenu_pressed_down_III

	SBRC time1,minus_time_base
	RCALL In_submenu_pressed_up_III

	SET	; Nastavime T-bit
	SBRC time1,OK	; test na tlacitko "OK"
	RET	; Pokud bylo stisknuto tlacitko "OK", pak nasleduje navrat

	SBRC time1,arrow_left
	RET

	SBRC time1,arrow_right
	RET

	SBRC time1,X
	RET
  ; A pokud se dostaneme sem, pak nasteduje kontrola, zda byla promenna
  ; "main_menu_selected_option_III_SRAM" zmenena. Pokud ano, pak se musi
  ; provest refresh. Pokud ne, pak staci zase zkontrolovat klavesnici
  ; a provest cely proces od pocatku
	LDS time1,main_menu_selected_option_III_SRAM
	LDS tmp,main_menu_selected_option_III_last_SRAM
	CP tmp,time1	; porovnani puvodni a aktualni hodnoty
	BREQ Help_complete_check_keyboard_1	; Pokud nebyla provedena
  ; zadna zmena -> znovu zkontrolovat

  ; V opacnem pripade smazeme T-bit a nasleduje navrat
	CLT
	RET

; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*
In_submenu_pressed_up:
	LDS number2,max_value_submenu_SRAM	; zjistime si max. cislo,
  ; ktere jeste muzeme do main_menu_selected_option_II_SRAM ulozit

	LDS number,main_menu_selected_option_II_SRAM

	CP number,number2	; kontrola, zda nejsme nahodou na maximu
	BREQ In_submenu_pressed_up_no_change	; pokud bychom byli mimo
  ; rozsah, pak uz nebudeme zvysovat cislo a nechame posledni, ktere musi
  ; byt platne prave kvuli teto podmince
	INC number	; v opacnem pripade se zvysi hodnota o 1
	STS main_menu_selected_option_II_SRAM,number	; a zmenu nahrajeme do
  ; SRAM
In_submenu_pressed_up_no_change:
	RET
; *-----------------------------------------*
In_submenu_pressed_down:
	LDS number2,min_value_submenu_SRAM

	LDS number,main_menu_selected_option_II_SRAM

	CP number2,number
	BREQ In_submenu_pressed_down_no_change	; pokud uz bude hodnota v
  ; main_menu_selected_option_II_SRAM rovna minimu, nemuzeme jit niz -> skok
  ; na In_submenu_pressed_down_no_change
	DEC number	; v opacnem pripade se odecte 1
	STS main_menu_selected_option_II_SRAM,number	; a zmena se zapise do
  ; SRAM
In_submenu_pressed_down_no_change:
	RET
; *-----------------------------------------*

In_submenu_pressed_up_III:	; to same jako vyse, ale pracuje s jinou SRAM
  ; to je uzitecne pri vetveni menu
	LDS number2,max_value_submenu_SRAM	; zjistime si max. cislo,
  ; ktere jeste muzeme do main_menu_selected_option_III_SRAM ulozit

	LDS number,main_menu_selected_option_III_SRAM

	CP number,number2	; kontrola, zda nejsme nahodou na maximu
	BREQ In_submenu_pressed_up_no_change_III	; pokud bychom byli
  ; mimo rozsah, pak uz nebudeme zvysovat cislo a nechame posledni, ktere musi
  ; byt platne prave kvuli teto podmince
	INC number	; v opacnem pripade se zvysi hodnota o 1
	STS main_menu_selected_option_III_SRAM,number	; a zmenu nahrajeme do
  ; SRAM
In_submenu_pressed_up_no_change_III:
	RET
; *-----------------------------------------*
In_submenu_pressed_down_III:
	LDS number2,min_value_submenu_SRAM

	LDS number,main_menu_selected_option_III_SRAM

	CP number2,number
	BREQ In_submenu_pressed_down_no_change_III	; pokud uz bude
  ; hodnota v main_menu_selected_option_II_SRAM rovna minimu, nemuzeme jit niz
  ; -> skok na In_submenu_pressed_down_no_change_III
	DEC number	; v opacnem pripade se odecte 1
	STS main_menu_selected_option_III_SRAM,number	; a zmena se zapise do
  ; SRAM
In_submenu_pressed_down_no_change_III:
	RET
; *-----------------------------------------*

; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*
In_main_menu_pressed_up:
  ; Nastavime zvoleny radek o jeden vys a pak zkontrolujeme, zda uz nejsme
  ; nahore
	LDS tmp,main_menu_selected_option_I_SRAM	; staneme si data
  ; z SRAM do "tmp"
	STS main_menu_selected_option_I_last_SRAM,tmp	; a zapiseme posledni
  ; zmenu do prislusne pametove bunky (kvuli refreshi na LCD)
	DEC tmp
  ; Pokud byl puvodni radek 0 a my odecteme 1, tak dostaneme $FF
  ; to je spatne. Nejvyssi radek muze mit hodnotu 0	; Pokud je zde $FF
  ; znamena to, ze neni vybran zadny, ale to bude asi pro debugovani
	CPI tmp,$FF
	BREQ In_main_menu_pressed_up_no_change	; pokud tam bude hodnota 255
  ; -> nechceme zmenu zapsat do SRAM -> skok na
  ; In_main_menu_pressed_up_no_change. V opacnem pripade, ale chceme zapsat
  ; zmenu
	STS main_menu_selected_option_I_SRAM,tmp	; a zmenu nahrajeme
  ; do SRAM	
In_main_menu_pressed_up_no_change:
	RET
; *-----------------------------------------*
In_main_menu_pressed_down:
  ; Nastavime zvoleny radek o jeden niz a pak zkontrolujeme, zda uz nejsme
  ; dole
	LDS tmp,main_menu_selected_option_I_SRAM
	STS main_menu_selected_option_I_last_SRAM,tmp	; a zapiseme posledni
  ; zmenu do prislusne pametove bunky (kvuli refreshi na LCD)
	INC tmp
  ; Nejnizsi radek ma hodnotu "Last_option" - definovano v "main_uC.asm"
	CPI tmp,Last_option
	BREQ In_main_menu_pressed_down_no_change	; pokud tam bude
  ; hodnota "Last_option" -> nechceme zmenu zapsat do SRAM -> skok na
  ; In_main_menu_pressed_up_no_change. V opacnem pripade, ale chceme zapsat
  ; zmenu
	STS main_menu_selected_option_I_SRAM,tmp	; a zmenu nahrajeme
  ; do SRAM	
In_main_menu_pressed_down_no_change:
	RET

; *-----------------------------------------*

In_submenu_confirm_change_number:
  ; Meni hodnotu "main_menu_selected_option_II_SRAM" v mezich definovanych
  ; min_value_submenu_SRAM a max_value_submenu_SRAM. Do "time1" ulozi data
  ; z klavesnice. Pokud bude stisknuto tlacitko "OK", nebo "->" pak se do
  ; T-bitu ulozi "1"
  ; Pracuje s CNT,time1,T-bit
	CALL recive_data_keyboard

	LDS time1,keyboard_L_SRAM

	SBRC time1,plus_time_base
	RCALL In_submenu_pressed_up

	SBRC time1,minus_time_base
	RCALL In_submenu_pressed_down

	CLR CNT
	CLT	; nastavi se T-bit do "0"

	SBRC time1,run_stop
	RJMP In_submenu_confirm_change_number_sub_10

	SBRC time1,menu
	RJMP In_submenu_confirm_change_number_add_10

	SBRC time1,OK
	SET	; pokud bude stisknuto OK, pak si info ulozime do T-bitu

	SBRC time1,arrow_right
	SET

	LDS number,main_menu_selected_option_II_SRAM	; do number si ulozime
  ; pocet vzorku a ty pak vykreslime. nejprve ale musime binarni cislo prevest
  ; na dekadicke (je to kvuli "Num_of_sampl" a "Waiting_int")
	RCALL Bin2Dec_0_to_255
	RET
; *-----------------------------------------*

In_submenu_confirm_change_number_III:
  ; V blede modrem co vyse, ale s jinou SRAM
  ; Meni hodnotu "main_menu_selected_option_III_SRAM" v mezich definovanych
  ; min_value_submenu_SRAM a max_value_submenu_SRAM. Do "time1" ulozi data
  ; z klavesnice. Pokud bude stisknuto tlacitko "OK", nebo "->" pak se do
  ; T-bitu ulozi "1"
  ; Pracuje s CNT,time1,T-bit
	CALL recive_data_keyboard

	LDS time1,keyboard_L_SRAM

	SBRC time1,plus_time_base
	RCALL In_submenu_pressed_up_III

	SBRC time1,minus_time_base
	RCALL In_submenu_pressed_down_III

	CLR CNT
	CLT	; nastavi se T-bit do "0"

;	SBRC time1,run_stop
;	RJMP In_submenu_confirm_change_number_sub_10

;	SBRC time1,menu
;	RJMP In_submenu_confirm_change_number_add_10

	SBRC time1,OK
	SET	; pokud bude stisknuto OK, pak si info ulozime do T-bitu

	SBRC time1,arrow_right
	SET

;	LDS number,main_menu_selected_option_III_SRAM	; do number si ulozime
  ; pocet vzorku a ty pak vykreslime. nejprve ale musime binarni cislo prevest
  ; na dekadicke (je to kvuli "Num_of_sampl" a "Waiting_int")
;	RCALL Bin2Dec_0_to_255
	RET
; *-----------------------------------------*
In_submenu_confirm_change_number_add_10:
	RCALL In_submenu_pressed_up
	INC CNT
	CPI CNT,10
	BRNE In_submenu_confirm_change_number_add_10
	RET
In_submenu_confirm_change_number_sub_10:
	RCALL In_submenu_pressed_down
	INC CNT
	CPI CNT,10
	BRNE In_submenu_confirm_change_number_sub_10
	RET
; *-----------------------------------------*


Show_selected_menu_is_About_info:
        LDI data,0
        CALL select_line_both
;        STS Samples_begin_SRAM,data	; neni potreba, text nebude pokracovat
  ; na dalsi radek

        LDI data,72	; Xova souradnice
        CLT
	LDI ZH,HIGH(2*SM_About_info_1)
	LDI ZL,LOW(2*SM_About_info_1)
	CALL write_text_from_DB


        LDI data,1
        CALL select_line_both
;        STS Samples_begin_SRAM,data

        LDI data,90
	LDI ZH,HIGH(2*SM_About_info_2)
	LDI ZL,LOW(2*SM_About_info_2)
	CALL write_text_from_DB

        LDI data,2
        CALL select_line_both
;        STS Samples_begin_SRAM,data

        LDI data,65
	LDI ZH,HIGH(2*SM_About_info_3)
	LDI ZL,LOW(2*SM_About_info_3)
	CALL write_text_from_DB


        LDI data,3
        CALL select_line_both
 ;       STS Samples_begin_SRAM,data

  ; Trosku grafiky...
	LDI data,1
	CALL select_X_right

  ; Nastavime adresu, od ktere se budou "tahat" data
	LDI ZH,HIGH(2*About_line_3)
	LDI ZL,LOW(2*About_line_3)
  ; Tim, ze data ulozime na flash a urcity algoritmus k nim bude pristupovat
  ; je setrne na pamet (usetri se nejaky ten bajt). Na druhou stranu o neco
  ; pomalejsi, coz v tomto pripade nevadi
	RCALL Show_graphics_from_flash

        LDI data,77
	LDI ZH,HIGH(2*SM_About_info_4)
	LDI ZL,LOW(2*SM_About_info_4)
	CALL write_text_from_DB

  ; Opet neco pro oci :D
	LDI data,4
	CALL select_line_both
	LDI data,1
	CALL select_X_right
  ; A zase...
	LDI ZH,HIGH(2*About_line_4)
	LDI ZL,LOW(2*About_line_4)

	RCALL Show_graphics_from_flash


	LDI data,5
	CALL select_line_both
	LDI data,1
	CALL select_X_right

	LDI ZH,HIGH(2*About_line_5)
	LDI ZL,LOW(2*About_line_5)

	RCALL Show_graphics_from_flash


	LDI data,6
	CALL select_line_both
	LDI data,1
	CALL select_X_right

	LDI ZH,HIGH(2*About_line_6)
	LDI ZL,LOW(2*About_line_6)

	RCALL Show_graphics_from_flash

  ; A zase neco grafiky plus nudny text
	LDI data,7
	CALL select_line_both

	LDI data,1
	CALL select_X_right

	LDI ZH,HIGH(2*About_line_7)
	LDI ZL,LOW(2*About_line_7)

	RCALL Show_graphics_from_flash

	LDI data,110
	LDI ZH,HIGH(2*SM_About_info_year)
	LDI ZL,LOW(2*SM_About_info_year)
	CALL write_text_from_DB

  ; A pockame, dokud uzivatel nestiskne nejakou klavesu
	CALL Wait_for_any_key

	RET

; *-----------------------------------------*
Show_selected_menu_is_Help_complete:
	LDI tmp,4
	STS max_value_submenu_SRAM,tmp	; do SRAM ulozime informaci o max.
  ; poctu moznosti - bude se to pak hodit u In_submenu_pressed_up
	LDI tmp,0
	STS min_value_submenu_SRAM,tmp	; a zase opak. Pro nejmensi hodnotu
  ; Tady to nema az zase takovy vyznam, ale pro nastaveni, kde jsou konkretni
  ; hodnoty v nejakem rozmezi to smysl ma


  ; Grafika a text...
	CALL Clear_display

	LDI data,0
	CALL select_line_both

	LDI data,0
	CLT

	LDI ZH,HIGH(2*SM_help_complete_1)
	LDI ZL,LOW(2*SM_help_complete_1)
	CALL write_text_from_DB	; In witch topic do

  ; A dokud jsme na tomto radku, tak se vykresli takovy to "i"
	LDI data,20
	CALL select_X_right

	LDI ZH,HIGH(2*Help_complete_I_symbol_high)
	LDI ZL,LOW(2*Help_complete_I_symbol_high)
	RCALL Show_graphics_from_flash

	LDI data,1
	CALL select_line_both

	LDI data,3

	LDI ZH,HIGH(2*SM_help_complete_2)
	LDI ZL,LOW(2*SM_help_complete_2)
	CALL write_text_from_DB ; You need help?


  ; Nyni se dovykresli zbytek
	LDI data,20
	CALL select_X_right

	LDI ZH,HIGH(2*Help_complete_I_symbol_low)
	LDI ZL,LOW(2*Help_complete_I_symbol_low)
	RCALL Show_graphics_from_flash


; *-----------------------------------------*
; |          Nyni se vypisi moznosti        |
; *-----------------------------------------*

	LDS number,main_menu_selected_option_II_SRAM	; zjistime si posledni
  ; zvolenou napovedu (pripade se nacte defaultni hodnota)

	LDI data,2
	CALL select_line_both

	LDI data,10

	CPI number,0
	BRNE menu_Help_submenu_0
	SET
menu_Help_submenu_0:
	LDI ZH,HIGH(2*SM_help_complete_3)
	LDI ZL,LOW(2*SM_help_complete_3)
	CALL write_text_from_DB ; OSC mode 
	CLT

	CPI number,1
	BRNE menu_Help_submenu_1
	SET
menu_Help_submenu_1:
	LDI ZH,HIGH(2*SM_help_complete_4)
	LDI ZL,LOW(2*SM_help_complete_4)
	CALL write_text_from_DB ; Trigger mode 
	CLT

	LDI data,3
	CALL select_line_both

	LDI data,5

	CPI number,2
	BRNE menu_Help_submenu_2
	SET
menu_Help_submenu_2:
	LDI ZH,HIGH(2*SM_help_complete_5)
	LDI ZL,LOW(2*SM_help_complete_5)
	CALL write_text_from_DB ; Num. of sam.
	CLT

	CPI number,3
	BRNE menu_Help_submenu_3
	SET
menu_Help_submenu_3:
	LDI ZH,HIGH(2*SM_help_complete_6)
	LDI ZL,LOW(2*SM_help_complete_6)
	CALL write_text_from_DB ; Draw method
	CLT


	LDI data,4
	CALL select_line_both

	LDI data,30

	CPI number,4
	BRNE menu_Help_submenu_4
	SET
menu_Help_submenu_4:
	LDI ZH,HIGH(2*SM_help_complete_7)
	LDI ZL,LOW(2*SM_help_complete_7)
	CALL write_text_from_DB ; Draw method
	CLT



	RET
; *-----------------------------------------*
Show_selected_menu_is_Trigger_mode:
	LDI tmp,2
	STS max_value_submenu_SRAM,tmp	; do SRAM ulozime informaci o max.
  ; poctu moznosti - bude se to pak hodit u In_submenu_pressed_up
	LDI tmp,0
	STS min_value_submenu_SRAM,tmp	; a zase opak. Pro nejmensi hodnotu
  ; Tady to nema az zase takovy vyznam, ale pro nastaveni, kde jsou konkretni
  ; hodnoty v nejakem rozmezi to smysl ma

	LDI data,0
	CALL select_line_both
	CLT	; nastavime barvu pisma na "normalni"
	LDI data,65

	LDI ZH,HIGH(2*SM_Trigger_mode_1)
	LDI ZL,LOW(2*SM_Trigger_mode_1)
	CALL write_text_from_DB	; HW 
  ; Prvni moznosi se budou tykat HW triggeru. Protoze ale bude vice omezeny,
; tak nebude mit tolik moznosti jako SW trigger, ale zase muze fungovat do
; vyssich frekvenci

	LDS number,main_menu_selected_option_II_SRAM	; stahneme si info
  ; o zvolene polozce v pod-menu

;	CLT	; Uz nemusime znovu nastavovat barvu pisma, nastavili jsme ji
  ; drive
	CPI number,0	; pokud bude zvolena moznost cislo 0, pak se zvyrazni
	BRNE menu_Trigger_mode_submenu_0
	SET	; nastaveni zvyrazneni
menu_Trigger_mode_submenu_0:
	LDI ZH,HIGH(2*Symbol_rising_edge)
	LDI ZL,LOW(2*Symbol_rising_edge)
	CALL write_text_from_DB	; a vykresli se znak nabezne hrany

	CLT
	LDI ZH,HIGH(2*Symbol_space)
	LDI ZL,LOW(2*Symbol_space)
	CALL write_text_from_DB	; pridame mezeru
	CPI number,1
	BRNE menu_Trigger_mode_submenu_1
	SET
menu_Trigger_mode_submenu_1:
	LDI ZH,HIGH(2*Symbol_falling_edge)
	LDI ZL,LOW(2*Symbol_falling_edge)
	CALL write_text_from_DB	; a vykresli se znak nabezne hrany

	CLT
	LDI ZH,HIGH(2*Symbol_space)
	LDI ZL,LOW(2*Symbol_space)
	CALL write_text_from_DB	; pridame mezeru
	CPI number,2
	BRNE menu_Trigger_mode_submenu_2
	SET
menu_Trigger_mode_submenu_2:
	LDI ZH,HIGH(2*Big_C)
	LDI ZL,LOW(2*Big_C)
	CALL write_text_from_DB	; C
  ; bude znacit Continuous time base - tzn. neustale se
  ; obnovuje, nezavisle na triggeru. Vhodne pro pomale deje (zacne se
  ; vzorkovat ihned

	CLT

	RET
; *-----------------------------------------*
Show_selected_menu_is_Num_of_sampl:
	LDI tmp,1
	STS max_value_submenu_SRAM,tmp

	LDI tmp,0
	STS min_value_submenu_SRAM,tmp

	LDS number,main_menu_selected_option_III_SRAM	; do number si ulozime
  ; pocet vzorku a ty pak vykreslime. nejprve ale musime binarni cislo prevest
  ; na dekadicke
	CALL Bin2Dec_0_to_255

	LDS number,main_menu_selected_option_II_SRAM	; a zjistime, jaka
  ; byla vybrana moznost

	LDI data,0
	CALL select_line_both
	LDI data,65

	CLT
	CPI number,0
	BRNE menu_Num_of_sampl_submenu_1
	SET
menu_Num_of_sampl_submenu_1:
	LDI ZH,HIGH(2*SM_Num_of_sampl_1)
	LDI ZL,LOW(2*SM_Num_of_sampl_1)
	CALL write_text_from_DB	; Auto

	CLT
	LDI tmp,4
	ADD data,tmp	; a posuneme se v Xove souradnici o 4px
  ; (je to rychlejsi, a efektivnejsi nez mezera)

	CPI number,1
	BRNE menu_Num_of_sampl_submenu_2
  ; V pripade, ze je zvolena moznost "Manual", pak se zobrazi aktualni
  ; nastavena hodnota
	PUSH data	; zaloha registru data
	LDI data,1	; 2. radek (cislovani od nuly, takze proto 1)
	CALL select_line_both
	LDI data,95	; a xova souradnice

	LDI ZH,HIGH(2*Symbol_up_and_down)
	LDI ZL,LOW(2*Symbol_up_and_down)
	CALL write_text_from_DB	; up & down
	CALL Show_Dec_number_0_to_255
  ; a pokracujeme tam kde jsme posledne skoncili
	LDI data,0
	CALL select_line_both
	POP data	; a obnoveni registru data
	SET

menu_Num_of_sampl_submenu_2:
	LDI ZH,HIGH(2*SM_Num_of_sampl_2)
	LDI ZL,LOW(2*SM_Num_of_sampl_2)
	CALL write_text_from_DB	; Manual

	RET
; *-----------------------------------------*
Show_selected_menu_is_Waiting_int:
	LDI tmp,1
	STS max_value_submenu_SRAM,tmp

	LDI tmp,0
	STS min_value_submenu_SRAM,tmp

  ; Zjistime si, jeslti je vybrana prvni, nebo druha moznost
	LDS number,main_menu_selected_option_II_SRAM

	LDI data,0
	CALL select_line_both
	LDI data,65

	CLT
	CPI number,0
	BRNE menu_Waiting_int_submenu_1
  ; V pripade, ze je zvolena 1. moznost, pak se zobrazi data
	PUSH data	; zaloha Xove souradnice
	LDS number,waiting_interval_buffer_SRAM
	CALL Bin2Dec_0_to_255	; prevod cisla do dekadicke soustavy

	LDI data,1
	CALL select_line_both
	LDI data,73

	LDI ZH,HIGH(2*Symbol_up_and_down)
	LDI ZL,LOW(2*Symbol_up_and_down)
	CALL write_text_from_DB	; up & down
	CALL Show_Dec_number_0_to_255

	LDI data,0
	CALL select_line_both
	POP data
	
	SET
menu_Waiting_int_submenu_1:
	LDI ZH,HIGH(2*SM_Waiting_int_1)
	LDI ZL,LOW(2*SM_Waiting_int_1)
	CALL write_text_from_DB	; Buffer


	CLT
	LDI tmp,4
	ADD data,tmp	; a posuneme se v Xove souradnici o 4px
  ; (je to rychlejsi, a efektivnejsi nez mezera)

	CPI number,1
	BRNE menu_Waiting_int_submenu_2
  ; V pripade ze je zvolena tato moznost....
	PUSH data
	LDS number,waiting_interval_keyboard_SRAM
	CALL Bin2Dec_0_to_255

	LDI data,1
	CALL select_line_both
	LDI data,102

	LDI ZH,HIGH(2*Symbol_up_and_down)
	LDI ZL,LOW(2*Symbol_up_and_down)
	CALL write_text_from_DB	; up & down
	CALL Show_Dec_number_0_to_255

	LDI data,0
	CALL select_line_both
	POP data

	SET
menu_Waiting_int_submenu_2:
	LDI ZH,HIGH(2*SM_Waiting_int_2)
	LDI ZL,LOW(2*SM_Waiting_int_2)
	CALL write_text_from_DB	; keyb.

	RET
; *-----------------------------------------*
Show_selected_menu_is_Draw_mode:
  ; V podstate podle vzoru "Show_selected_menu_is_Trigger_mode"
  ; Zase budou nejake moznosti a uzivatel si vybere tu "nejlepsi"
	LDI tmp,1
	STS max_value_submenu_SRAM,tmp	; max. hodnota z vyberu

	LDI tmp,0
	STS min_value_submenu_SRAM,tmp	; min hodnota

	LDI data,0
	CALL select_line_both	; vyber radku
	CLT
	LDI data,65	; Xova souradnice na LCD

	LDS number,main_menu_selected_option_II_SRAM	; zjistime si, jake
  ; nastaveni bylo pouzito posledne, pripadne se nacte defaultni nastaveni
  ; 0 - points (body)
  ; 1 - vector (vektorove)
	CPI number,0	; kontrola, zda neni vybrane bodove vykreslovani
	BRNE menu_Draw_mode_submenu_0
	SET	; pokud ano, pak se zvyrazni
menu_Draw_mode_submenu_0:
	LDI ZH,HIGH(2*SM_Draw_mode_1)
	LDI ZL,LOW(2*SM_Draw_mode_1)
	CALL write_text_from_DB	; Points

	CLT

	LDI tmp,4
	ADD data,tmp	; a posuneme se v Xove souradnici o 4px
  ; (je to rychlejsi, a efektivnejsi nez mezera)
	CPI number,1	; to same jako vyse, ale pro vektorove vykreslovani
	BRNE menu_Draw_mode_submenu_1
	SET
menu_Draw_mode_submenu_1:
	LDI ZH,HIGH(2*SM_Draw_mode_2)
	LDI ZL,LOW(2*SM_Draw_mode_2)
	CALL write_text_from_DB	; Vector

	CLT	; a nastavime barvu pisma na defaultni
  ; Plus vykreslime jeste nejaky maly popis, at se vyuzije LCD
	LDI data,2
	CALL select_line_both	; radek

	LDI data,70	; Xova souradnice

	LDI ZH,HIGH(2*SM_Draw_mode_3)
	LDI ZL,LOW(2*SM_Draw_mode_3)
	CALL write_text_from_DB	; Point draw is

	LDI data,3	; dalsi radek
	CALL select_line_both
	LDI data,65

	LDI ZH,HIGH(2*SM_Draw_mode_4)
	LDI ZL,LOW(2*SM_Draw_mode_4)
	CALL write_text_from_DB	; faster,but not


	LDI data,4
	CALL select_line_both
	LDI data,65

	LDI ZH,HIGH(2*SM_Draw_mode_5)
	LDI ZL,LOW(2*SM_Draw_mode_5)
	CALL write_text_from_DB	; so good

	LDI data,5
	CALL select_line_both
	LDI data,64

	LDI ZH,HIGH(2*SM_Draw_mode_6)
	LDI ZL,LOW(2*SM_Draw_mode_6)
	CALL write_text_from_DB	; looking.

	RET
; *-----------------------------------------*
Show_selected_menu_is_Animations:
	LDI tmp,1
	STS max_value_submenu_SRAM,tmp

	LDI tmp,0
	STS min_value_submenu_SRAM,tmp

	LDI data,0
	CALL select_line_both	; nastavime radek
	CLT
	LDI data,65	; nastavime Xovou souradnici

	LDS number,main_menu_selected_option_II_SRAM	; DWN info o vybrane
  ; polozce

	CPI number,0
	BRNE menu_Animations_submenu_0
	SET
menu_Animations_submenu_0:
	LDI ZH,HIGH(2*SM_Animations_1)
	LDI ZL,LOW(2*SM_Animations_1)
	CALL write_text_from_DB	; Elements

	LDI data,1
	CALL select_line_both
	CLT
	LDI data,65

	CPI number,1
	BRNE menu_Animations_submenu_1
	SET
menu_Animations_submenu_1:
	LDI ZH,HIGH(2*SM_Animations_2)
	LDI ZL,LOW(2*SM_Animations_2)
	CALL write_text_from_DB	; Matrix

	CLT

	RET
; *-----------------------------------------*
Show_settings_saved:
	CLT
	LDI number,33	; do CNT si ulozime pocatecni Xovou souradnici

	LDI data,3
	CALL select_line_both	; vybereme radek

	MOV data,number	; zvolime Xovou souradnici
	LDI ZH,HIGH(2*Settings_saved)
	LDI ZL,LOW(2*Settings_saved)
	CALL write_text_from_DB	; |Settings saved|

  ; A jeste vykreslime ramecek
	MOV number2,data	; a jeste si ulozime informaci o tom, jak
  ; je dlouhy text

	LDI data,2
	CALL select_line_both

	MOV data,number
	CALL select_X_left
	LDI data,0b11110000
	CALL write_left
	MOV CNT,number
	LDI data,0b00010000
Show_settings_saved_top_L:
	CALL write_left
	INC CNT
	CPI CNT,63
	BRNE Show_settings_saved_top_L

	SUBI number2,68	; musime odecist 64, protoze zapisujeme do prave
  ; poloviny (adresa muze byt v rozsahu 0~63 - tj. 64 adres) a posunout se
  ; o "4" zpet (o 3 kvuli dekoraci a o 1 kvuli posloupnosti prikazu INC CNT
  ; a CP CNT,number2)
	CLR CNT
	MOV data,CNT
	CALL select_X_right
	LDI data,0b00010000
Show_settings_saved_top_R:
	CALL write_right
	INC CNT
	CP CNT,number2
	BRNE Show_settings_saved_top_R

	LDI data,0b00100000
	CALL write_right
	LDI data,0b01000000
	CALL write_right
	LDI data,0b10000000
	CALL write_right


	LDI data,4
	CALL select_line_both

	MOV data,number
	CALL select_X_left
	LDI data,0b00000001
	CALL write_left
	LDI data,0b00000010
	CALL write_left
	LDI data,0b00000100
	CALL write_left
	MOV CNT,number
	LDI data,0b00001000
Show_settings_saved_bottom_L:
	CALL write_left
	INC CNT
	CPI CNT,61	; uz 3 body mame vykreslene, do CNT jsme je ale
  ; nepricetli, protoze by to byla zbytecna ztrata cyklu
	BRNE Show_settings_saved_bottom_L

	LDI tmp,2
	ADD number2,tmp	; tady zase chceme vykreslit az na konec -> musime
  ; ty zase neco pricist
	CLR CNT
	MOV data,CNT
	CALL select_X_right
	LDI data,0b00001000
Show_settings_saved_bottom_R:
	CALL write_right
	INC CNT
	CP CNT,number2
	BRNE Show_settings_saved_bottom_R

	LDI data,0b00001111
	CALL write_right

	CALL wait_500ms	; aby nedoslo k problemum, kdyz uzivatel
  ; podrzi delsi dobu tlacitko (aby se "neodklikla" informativni tabulka)
Show_settings_saved_still_w8:
  ; A pockame na uzivatele az stiskne nejakou klavesu
	CALL recive_data_keyboard
	LDS number,keyboard_L_SRAM
	CPI number,0
	BRNE Show_settings_saved_exit	; pokud bude v pameti ulozeno
  ; jakekoli cislo, pak skok na Show_settings_saved_exit. Pokud ne, pak se
  ; bude testovat na dalsich 8 klaves
	LDS number,keyboard_H_SRAM
	CPI number,0
	BRNE Show_settings_saved_exit	; pokud ani zde nebyla stisknuta
  ; nejaka klavesa, pak se znovu nactou data z klavesnice a znovu se testuje
	RJMP Show_settings_saved_still_w8

Show_settings_saved_exit:
	RET
; *-----------------------------------------*

; *-----------------------------------------*
; |                                         |
; *-----------------------------------------*
Show_Statistics_data:
	LDI data,0
	CALL select_line_both

	CLR data
	CALL X_line_R	; smaze jeden radek (vyse zvoleny). Je to proto, ze
  ; kdyz se zmeni informace o chybe, tak na LCD zustanou i stara data. A to je
  ; nezadouci -> musi se vse smazat a znovu vykreslit

	LDI data,65	; X pozice
	CLT	; barva pisma

	LDI ZH,HIGH(2*SM_Statistics_data_1)
	LDI ZL,LOW(2*SM_Statistics_data_1)
	CALL write_text_from_DB	; Keyb. err:

	LDS number,start_bit_errors_SRAM
	CPI number,250	; pokud bude chyb 250 (dal se nepocita), pak se
  ; zobrazi misto konkretniho udaje "Crit."
	BRNE keyboard_error_normal	; pokud nedosahl pocet chyb 250, pak
  ; se zobrazi pocet chyb
	LDI ZH,HIGH(2*SM_Statistics_data_2)
	LDI ZL,LOW(2*SM_Statistics_data_2)
	CALL write_text_from_DB	; Crit.

	RJMP keyboard_error_normal_end
keyboard_error_normal:
	CALL Bin2Dec_0_to_255	; prevod
	CALL Show_Dec_number_0_to_255_without_zeros	; a zobrazeni
keyboard_error_normal_end:


  ; Pocet chyb (varovani) pri komunikaci s bufferem
  ; (kdyz se neshoduje pocet vzorku v bufferu s poctem vzorku v "main_uC")
	LDI data,1
	CALL select_line_both

;	CLR data	; neni potreba mazat. Tato informace se nemeni, kdyz
  ; jsme v menu
;	CALL X_line_R

	LDI data,65
;	CLT	; barva pisma

	LDI ZH,HIGH(2*SM_Statistics_data_3)
	LDI ZL,LOW(2*SM_Statistics_data_3)
	CALL write_text_from_DB	; Num.of samp.


	LDI data,2
	CALL select_line_both

;	CLR data
;	CALL X_line_R

	LDI data,70
;	CLT

	LDI ZH,HIGH(2*SM_Statistics_data_4)
	LDI ZL,LOW(2*SM_Statistics_data_4)
	CALL write_text_from_DB	; not match:

;	CLR data
;	CALL X_line_R

	LDI data,3	; zvolime radek
	CALL select_line_both

	LDI data,75	; a Xovou souradnici
  ; Nemusime mazat. Informace se muze zmenit jen pri komunikaci s bufferem
  ; a ta v hlavnim menu neprobiha

  ; Vypocet...
	LDS number,Num_of_sampl_error_2_SRAM
	CPI number,$99	; kontrola, zda jsme nedosahli hodnoty 99xx
	BREQ Show_Statistics_data_Test_for_critical

Show_Statistics_data_not_Critical:
;	LDI data,75
;	CLT

  ; Nejprve tisice a stovky. Proto jsme nacetli "Num_of_sampl_error_2" jako
  ; prvni
	CALL Show_tens_and_units_without_zeros_all	; vezme data
  ; z "number" a zobrazi je jako desitky a jednotky (resp. v tomto pripade
  ; se pracuje s registry "tens" a "units", ktere nyni predstavuji tisice
  ; a stovky
	LDS number,Num_of_sampl_error_1_SRAM
	CALL Show_tens_and_units_without_zero


  ; Ted si vypiseme posledni adresu, ktera je pouzivana SRAM
	LDI data,4
	CALL select_line_both

	LDI data,65

	LDI ZH,HIGH(2*SM_Statistics_data_5)
	LDI ZL,LOW(2*SM_Statistics_data_5)
	CALL write_text_from_DB	; SRAM used:

	LDI data,5
	CALL select_line_both
	LDI data,75

  ; nejprve vypiseme horni bity
	LDI number,HIGH(last_adress_SRAM)	; do number si ulozime hornich
  ; 8 bitu z hodnoty "last_adress_SRAM"
	CALL Packed_BCD2DEC	; prevedeme si cislo na tisice a stovky, resp.
  ; na horni a dolni 4 bity (ty se ulozi do registru "units" a "tens")
	CALL Show_tens_and_units_without_zeros_all	; a zobrazime tisice
  ; a stovky sestnackove soustavy
	LDI number,LOW(last_adress_SRAM)	; to same jako vyse, ale pro
  ; desitky a stovky v sestnackove soustave
	CALL Packed_BCD2DEC
	CALL Show_tens_and_units	; (nepredpokladam, ze by se pouzila
  ; adresa mensi jak $09)

	LDI ZH,HIGH(2*SM_Statistics_data_6)
	LDI ZL,LOW(2*SM_Statistics_data_6)
	CALL write_text_from_DB	;  HEX

Show_Statistics_data_keyboard_check:
	CALL wait_50ms	; aby to bylo vubec citelne. X_line_R totiz smaze
  ; data na LCD a jejich opetovne zobrazeni fyzicky chvilku trva

	CALL recive_data_keyboard	; nacteni informace o stisklych
  ; tlacitkach
	CLR time1	; jeste si musime nastavit, ze az "vylezeme"
  ; z podprogramu, tak ze nebylo stiskle zadne tlacitko (kontroluji se data
  ; prave v registru "time1"

	LDS data,keyboard_L_SRAM

	SBRC data,X	; test na tlacitko "X"
	RET

	SBRC data,arrow_left	; test na tlacitko "<--"
	RET

	RJMP Show_Statistics_data



Show_Statistics_data_Test_for_critical:
	LDS tmp,Num_of_sampl_error_1_SRAM
	CPI tmp,$99
	BREQ Show_Statistics_data_Critical
	RJMP Show_Statistics_data_not_Critical

Show_Statistics_data_Critical:
	LDI data,95
	CLT
	LDI ZH,HIGH(2*SM_Statistics_data_7)
	LDI ZL,LOW(2*SM_Statistics_data_7)
	CALL write_text_from_DB	; Critical

	RJMP Show_Statistics_data_keyboard_check


; *-----------------------------------------*

; *-----------------------------------------*

; *-----------------------------------------*

; *-----------------------------------------*

; *-----------------------------------------*

; *-----------------------------------------*

; *-----------------------------------------*
; *-----------------------------------------*
; |    Grafika - databaze a vykreslovani    |
; *-----------------------------------------*
Show_graphics_from_flash:
  ; Vykresli binarni data na LCD. Bude pokracovat tak dlouho, dokud nenajde
  ; kombinaci $FF,$FA,00
	LPM data,Z+	; stahneme si data z flash pameti
	CPI data,$FF	; kontrola, zda nejsme na konci. Kod je $FF, $FA
	BREQ Show_graphics_from_flash_end_1
Show_graphics_from_flash_OK:
	CALL write_right	; zapiseme data z databaze
	RJMP Show_graphics_from_flash

Show_graphics_from_flash_end_1:
	LPM data,Z+	; a nacteme dalsi data
	CPI data,$FA	; kontrola s kodem
	BRNE Show_graphics_from_flash_end_2
  ; A jeste kontrola na nulovy bit (posledni)
	LPM data,Z+
	CPI data,$00
	BRNE Show_graphics_from_flash_end_3

	RET	; pokud se dostaneme na konec -> navrat z podprogramu

Show_graphics_from_flash_end_3:
	SBIW ZL,1
Show_graphics_from_flash_end_2:
  ; pokud nebyla nasledujici data shodna, pak jde o data, ktera se maji
  ; normalne zobrazit na LCD
	SBIW ZL,2	; musime se v pameti vratit o 2
	LPM data,Z	; a nacist tedy puvodni data
	RJMP Show_graphics_from_flash_OK	; zbyva uz jen vykresleni
; *-----------------------------------------*
About_line_3:
.DB 0b00100010,0b00100010,0b01000010,0b10000100,0b00001000,0b00010000,0b10100000,0b01000000,0b10000000,$FF,$FA,0

About_line_4:
  ; data musime rozdelit na vice .DB (kompilator mi vyhlasil valku, kdyz bylo na jendom radku vice nez 255 zanku) A take musi byt vzdy pocet cisel
  ; v databazi sudy, jinak se na konec prida "zero byte", ktery je v tomto
  ; pripade mezera navic, coz je nechtenne

  ; Instrukce jsou vlastne 16. bitove. A kdyz na flash ukladame nejaka data,
  ; tak je ukladame po 8. bitech. Problem nastava, kdyz ulozime lichy pocet.
  ; Kompilator si s tim poradi tak, ze do teto "mezery" vlozi $00. Coz je
  ; v tomto pripade vice nez nezadouci. Sice bych mohl data zapsat v hexadec.
  ; soustave, ale to uz by nebylo uz vubec prehledne a navic by se u zapisu
  ; muselo o neco vic premyslet

.DB 0b00010000,0b10010000,0b01010000,0b01010000,0b01010001,0b01010010,0b01010100,0b01010101,0b01010100,0b01010100,0b10010010,0b00100010,0b00100010,0b00100111,0b01110101,0b00000101,0b01110111,0b00100010,0b00111110,0,0,0,0,0b10100000,0b01100000,0b11111000
.DB 0b01100100,0b10100010,0b00000001,0b00000001,0b10001001,0b00010111,0b00001001,0b10000001,0b11100001,0b10100111,0b00100100,0b10100100,0b10100100,0b10101110,0b10100000,0b10101110,0b10100100,0b10111100,0b10000000,0b10000100,0b10011010,0b10100100
.DB 0b10100000,0b10100000,0b10100000,0b10010000,0b01001000,0b01001000,0b01001000,0b01010100,0b01001000,0b01000000,0b01000000,0b01000000,0b01000000,0b01000000,0b01000000,$FF,$FA,0



About_line_5:
.DB 0b01001001,0b10101001,0b01001000,0b00001000,0b11110000,0b01000010,0b01001101,0b01010010,0b01010000,0b01010010,0b01010101,0b01010010,0b01010000,0b01001000,0b01000100,0b01011000,0b01010000,0b01001000,0b01000100,0b01011000,0b01010000,0b01001000
.DB 0b01000100,0b01011001,0b10010001,0b00011111,0b01000001,0b10100001,0b01000000,0b00000001,0b00111110,0b01000001,0b10000000,0b00100111,0b01011100,0b00100111,0b10000000,0b01111111,0b00000000,0b11111110,0b00000010,0b11111010,0b00001010,0b00001010
.DB 0b01001010,0b10101010,0b01001010,0b01001010,0b01001010,0b01001010,0b10001010,0b00001010,0b11111010,0b00001001,0b00100101,0b01010101,0b00100101,0b00100101,0b00100101,0b00100101,0b00100101,0b00100101,0b00100101,$FF,$FA,0



About_line_6:
.DB 0b01000010,0b01011110,0b01010000,0b01010101,0b01011101,0b01000101,0b00100000,0b00011100,0b00000010,0b00000010,0b00000111,0b00000101,0b00000101,0b11010111,0b10110010,0b11111110,0b10110010,0b11010111,0b00000101,0b00000101,0b00000111,0b00000010
.DB 0b00100010,0b01011100,0b00100000,0b00000001,0b00000010,0b10000101,0b01001010,0b10010100,0b10010100,0b10010100,0b11010100,0b01010101,0b01010101,0b11010101,0b10010100,0b10010010,0b01001001,0b00100100,0b00010010,0b00001001,0b01000100,0b10100010
.DB 0b01000010,0b01000010,0b01000010,0b01000101,0b01000010,0b01000000,0b00100011,0b00010100,0b00010100,0b00010101,0b00010101,0b00010101,0b00010101,0b00010101,0b00010101,0b00010101,0b00010101,0b00010101,0b00010101,$FF,$FA,0

About_line_7:
.DB 0b00010010,0b00010010,0b00010010,0b00010111,0b00010101,0b00010101,0b00010111,0b00010010,0b00010010,0b00010111,0b00010000,0b00010111,0b00010010,0b00010010,0b00001010,0b00100111,0b01010000,0b00100000,0b00100000,0b00100010,0b00111101,0b00100010
.DB 0b00100000,0b01110010,0b01010101,0b01010010,0b01110010,0b00100100,0b00111001,0b00100000,0b01110000,0b01010000,0b01010001,0b01110001,0b00100001,0b00100001,0b00100000,0b01010000,0b00100000,$FF,$FA,0
