;
;        mb_main.txt
;      
; KOTUINO mode 2     aspgm1
;
;----------------------------------------------
 master_ptr:
  WAITT 250
  LLPRINT str0 ;  
 wait_fl0:
  Rx_BYTE filtre0 ;     
  sjmp wait_fl0
 go_fl0:

  LLPRINT str2 ;    
 LDA_String read_hed
  mov dptr,#m_str1
  mov r4,#11
 loop0:
  lcall bspi_rxd
  movx @dptr,a
  inc dptr
  djnz r4,loop0
  LLPRINT m_str0 ;   
   WAITT 150

;-------------------------
  LLPRINT str3 ;  / Vpp (+12V)
 wait_fl1:
  Rx_BYTE filtre1 ;     
  sjmp wait_fl1
 go_fl1:
;-------------------------
;       
point_proc0:
  acall bloc_fb ;      0xFF
;-------------------------
;       
;   "/"
  LLPRINT str5
  LLPRINT str0
 wait_fl2:
  Rx_BYTE filtre2 ;     
  sjmp wait_fl2 ;       
 go_fl2: ;    ! !

;-------------------------
;   ( -)
;   
; read_sign0: ;     0
  mov PCL_fb_buf,#sign0_addrl ;    
  mov PCH_fb_buf,#0 ;    
  LONG_cmd sign_reader
  mov sign0_buf,a ;    
; read_sign1: ;     1
  mov PCL_fb_buf,#sign1_addrl ;    
   LONG_cmd sign_reader
  mov sign1_buf,a ;    
; read_sign2: ;     2
  mov PCL_fb_buf,#sign2_addrl ;    
   LONG_cmd sign_reader
  mov sign2_buf,a ;    

;-------------------------
;   
 LLPRINT str6
  mov a,sign0_buf
  lcall txx_ascii
 LLPRINT str7
  mov a,sign1_buf
  lcall txx_ascii
 LLPRINT str8
  mov a,sign2_buf
  lcall txx_ascii

;      
;     
;    
  mov a,#atmel_id
  cjne a,sign0_buf,error_m
  mov a,#type51
  cjne a,sign1_buf,test52
  sjmp set_at51
 test52:
  mov a,#type52
  cjne a,sign1_buf,error_m
  mov flash_size,#low flash_size_52 ; flash_size_52
  mov flash_size+1,#high flash_size_52
  mov dptr,#str10_a
  mov a,#'2'
  movx @dptr,a
 test_vpph:
  mov a,#vpp_12v
  cjne a,sign2_buf,test_vppl
  mov dptr,#str10_b
  mov a,#'1'
  movx @dptr,a
  inc dptr
  mov a,#'2'
  movx @dptr,a
  setb vpph ;  vpph = 1 (Vpp=12V)
  sjmp test_ok1
 test_vppl:
  mov a,#vpp_5v
  cjne a,sign2_buf,error_m
  mov dptr,#str10_b
  mov a,#'0'
  movx @dptr,a
  inc dptr
  mov a,#'5'
  movx @dptr,a
  clr vpph ;  vpph = 0 (Vpp=5V)
 test_ok1:
  LLPRINT str10 ;  
      ;      
;
;      :
;  vpph " "
;  flash_size     
;
  WAITT 150
  sjmp point_proc1 ;   point_proc1

 set_at51:
  mov flash_size,#low flash_size_51 ; flash_size_51
  mov flash_size+1,#high flash_size_51
  mov dptr,#str10_a
  mov a,#'1'
  movx @dptr,a
 sjmp test_vpph ;    Vpp

 error_m:
  LLPRINT str9 ;    
  WAITT 150
  ajmp point_proc0


 point_proc1:
;-------------------------
;       0xFF
  lcall blanc
;-------------------------
;
;0 - return to installing the microcontroller(point_proc0)
;1 - load *.hex file (go_fl4)
;2 - load blanc damp (point_proc3+dump_size=flash_size)
;
LLPRINT str15
 wait_fl4:
  Rx_BYTE filtre4 ;     
  sjmp wait_fl4 ;       
 go_fl4: ;    ! !
;-------------------------
  LLPRINT str11 ;     
      ;   
      ;     
      ;    !
      ;   !
  WAITT 50
  PCALL_LDFile echo_rst ;   
      ;   kotios
      ;    

;-------------------------
;     
;    dump_size
 point_proc2:
  lcall dumper
  mov dump_size,#0 ; 
  inc r1 ;    
  mov dump_size+1,r1 ;   256 

;---------------------------------
;
 point_proc3:
  mov dptr,#str17a
  mov a,dump_size+1
  dec a
  lcall binascii
  mov a,R5
  movx @dptr,a
  inc dptr
  mov a,r4
  movx @dptr,a
  LLPRINT str17 ;    
  ;    

;-------------------------
;
;   ,
;  "" ,
;       
;    
; 0 -    point_proc0
; 1 -   (  point_proc3)
; 2 -    (  point_proc3)
; 3 -        (  point_proc3)
;
  LLPRINT str12
 wait_fl3:
  Rx_BYTE filtre3 ;     
  sjmp wait_fl3
 go_fl3:
;-------------------------
;








;-------------------------






; LONG_cmd dumper

TEST_STOP
;