;
;
;  fbc_util_2.txt
;
;   
;    
;   
;
;
;----------------------------------------
;
; .org smart_vectors+256

;
;----------------------------------------
;    0

;     0
 RD_p0_proc:
  mov a,P0
  ajmp rd_ports

;     0
 WR_p0_proc:
  acall bspi_rxd
  mov P0,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   0
 Wbm1_p0_proc:
  acall bspi_rxd
  orl P0,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   0
 Wbm0_p0_proc:
  acall bspi_rxd
  cpl a
  anl P0,a
  acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;    1

;     1
 RD_p1_proc:
  mov a,P1
  ajmp rd_ports

;     1
 WR_p1_proc:
  acall bspi_rxd
  mov P1,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   1
 Wbm1_p1_proc:
  acall bspi_rxd
  orl P1,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   1
 Wbm0_p1_proc:
  acall bspi_rxd
  cpl a
  anl P1,a
  acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;    2

;     2
 RD_p2_proc:
  mov a,P2
  ajmp rd_ports

;     2
 WR_p2_proc:
  acall bspi_rxd
  mov P2,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   2
 Wbm1_p2_proc:
  acall bspi_rxd
  orl P2,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   2
 Wbm0_p2_proc:
  acall bspi_rxd
  cpl a
  anl P2,a
  acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;    3

;     3
 RD_p3_proc:
  mov a,P3
  orl a,#trd_mask ;   bus_dtr=bus_clc=bus_qt=1
  ajmp rd_ports

;     3
 WR_p3_proc:
  acall bspi_rxd
  orl a,#trd_mask
  mov P3,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   3
 Wbm1_p3_proc:
  acall bspi_rxd
  orl a,#trd_mask
  orl P3,a
  acall smart_qt_slave
  ajmp wait_com

;    
;     
;   3
 Wbm0_p3_proc:
  acall bspi_rxd
  cpl a
  orl a,#trd_mask
  anl P3,a
  acall smart_qt_slave
  ajmp wait_com

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

 rd_ports:
  clr data_key
  acall bspi_txd
 ajmp wait_com ;   
 ;     

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

 inc_p0_proc:
   inc P0
   acall smart_qt_slave
  ajmp wait_com
 inc_p1_proc:
   inc P1
   acall smart_qt_slave
  ajmp wait_com
 inc_p2_proc:
   inc P2
   acall smart_qt_slave
  ajmp wait_com
 inc_p3_proc:
   mov a,P3
   rr a
   rr a
   rr a
   inc a
   rl a
   rl a
   rl a
   orl a,#trd_mask
   mov P3,a
   acall smart_qt_slave
  ajmp wait_com

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

 dec_p0_proc:
   dec P0
   acall smart_qt_slave
  ajmp wait_com
 dec_p1_proc:
   dec P1
   acall smart_qt_slave
  ajmp wait_com
 dec_p2_proc:
   dec P2
   acall smart_qt_slave
  ajmp wait_com
 dec_p3_proc:
   mov a,P3
   rr a
   rr a
   rr a
   dec a
   rl a
   rl a
   rl a
   orl a,#trd_mask
   mov P3,a
   acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;      0

 clr_p0_proc:
   clr a
   mov P0,a
   acall smart_qt_slave
  ajmp wait_com
 clr_p1_proc:
   clr a
   mov P1,a
   acall smart_qt_slave
  ajmp wait_com
 clr_p2_proc:
   clr a
   mov P2,a
   acall smart_qt_slave
  ajmp wait_com
 clr_p3_proc:
   clr a
   orl a,#trd_mask
   mov P3,a
   acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;      0FF

 set_p0_proc:
   mov a,#0xFF
   mov p0,a
   acall smart_qt_slave
  ajmp wait_com
 set_p1_proc:
   mov a,#0xFF
   mov p1,a
   acall smart_qt_slave
  ajmp wait_com
 set_p2_proc:
   mov a,#0xFF
   mov p2,a
   acall smart_qt_slave
  ajmp wait_com
 set_p3_proc:
   mov a,#0xFF
   mov p3,a
   acall smart_qt_slave
  ajmp wait_com

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

 cpl_p0_proc:
   mov a,#0xFF
   xrl p0,a
   acall smart_qt_slave
  ajmp wait_com
 cpl_p1_proc:
   mov a,#0xFF
   xrl p1,a
   acall smart_qt_slave
  ajmp wait_com
 cpl_p2_proc:
   mov a,#0xFF
   xrl p2,a
   acall smart_qt_slave
  ajmp wait_com
 cpl_p3_proc:
   mov a,#0xFF
   xrl p3,a
   orl p3,#trd_mask
   acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;      0xFF

 oll_on:
  mov a,#0xFF
  mov P0,a
  mov P1,a
  mov P2,a
  mov P3,a
  acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;      0x00
;  -   bspi -
;   

 oll_off:
  clr a
  mov P0,a
  mov P1,a
  mov P2,a
  orl a,#trd_mask
  mov P3,a
  acall smart_qt_slave
  ajmp wait_com

;
;----------------------------------------
;     /
;  fb4012

 read_hed:
  mov r4,#11
  mov r5,#1
 tr_simv:
  mov a,r5
  acall rd_simv
  acall bspi_txd
  inc r5
  djnz r4,tr_simv
 ajmp wait_com
;
 rd_simv:
    movc a,@a+PC
  ret
  .db "FB4012 V0.2"

;
;----------------------------------------
;  " "
;   
;   - 
;    
;  ajmp wait_com

 LONG_com:
  acall bspi_rxd ;     
  mov dph,a
  acall bspi_rxd ;     
  mov dpl,a
  clr a
  jmp @a+dptr

;
;----------------------------------------
;
;  " " 8951/52
;    
;    vpph
; 0  vpph=0  1  vpph=1
;    smart_qt
; 

 oll_clear_c512:
  acall bspi_rxd ;    vpph
  rrc a
  mov vpph,C ;    vpph
;
;   Pg_reset  MB4012    1
; Pg_psen   0
;
 acall bloc ;   
  mov linc_port2,#1<<Pfb2_6 ;   Pfb2_6=1:Pfb2_7=0
  mov linc_port3,#low ~Pfb_mask ;   Pfb3_6=Pfb3_7=0
  mov r2,#15
  djnz r2,$ ; time 48
  jnb vpph,novpp
  clr linc_port3.pgf_evpp ;  vpph=1  pgf_evpp=0
 novpp:
  mov r2,#10
  djnz r2,$ ; time 10
  clr linc_port3.pgf_prog ;   pgf_prog
 msek_10:
	setb sys_tik
  mov TL0,#low clear_tm
  mov TH0,#high clear_tm
  setb TR0
  jb sys_tik,$ ; -_-    10mS
  setb linc_port3.pgf_prog
  mov r2,#10
  djnz r2,$ ; time 10
  setb linc_port3.pgf_evpp ;   
	                ;  +12  pgf_evpp=1
  lcall sek_time ;    1 
  acall smart_qt_slave
 ajmp wait_com

;
;----------------------------------------
;
;  " "
;  
; "    "
;     
;    
;     
;     
;   
;  

 rd_sign_c512:
  acall bspi_rxd ;   
  mov bptr_h,a
  acall bspi_rxd ;    
  mov bptr_l,a ;  bptr_h:bptr_l
;
;   Pg_reset  MB4012    1
; Pg_psen   0
;
 acall bloc ;   
 anl bptr_h,#low ~Pfb_mask ;   Pfb2_6=Pfb2_7=0
                    ;    bptr_h
 anl linc_port3,#low ~Pfb_mask ;   Pfb3_6=Pfb3_7=0
                   ; (   Pfb3_6=Pfb3_7=1)
 mov addr_h,bptr_h ;    bptr_h:bptr_l
 mov addr_l,bptr_l ;   addr_h:addr_l(Pf2:Pf1)
 mov r2,#10
  djnz r2,$ ; time 10
 mov temp_o,data_bus ;    data_bus(Pf0)  temp_o
 acall bloc ;    
           ; - linc_port3=linc_port2=0xFF
 clr data_key ;   
 mov a,temp_o
 acall bspi_txd ;   
           ;  temp_o  MB4012
 ajmp wait_com

;
;----------------------------------------
;
; 
; "    "
;     
;    
;     
;    
;   
;  

 rd_byte_c512:
  acall bspi_rxd ;   
  mov bptr_h,a
  acall bspi_rxd ;    
  mov bptr_l,a ;  bptr_h:bptr_l
;
;   Pg_reset  MB4012    1
; Pg_psen   0
;
 acall bloc ;   
 anl bptr_h,#low ~Pfb_mask ;   Pfb2_6=Pfb2_7=0
             ;    bptr_h
;  acall bloc 3=0xFF (  Pfb3_6=Pfb3_7=1)
 mov addr_h,bptr_h ;    bptr_h:bptr_l
 mov addr_l,bptr_l ;   addr_h:addr_l(Pf2:Pf1)
 mov r2,#10
  djnz r2,$ ; time 10
 mov temp_o,data_bus ;    data_bus(Pf0)  temp_o
 acall bloc ;    
           ; - linc_port3=linc_port2=0xFF
 clr data_key ;   
 mov a,temp_o
 acall bspi_txd ;   
           ;  temp_o  MB4012
 ajmp wait_com

;
;----------------------------------------
;
;  " " ( )
;     
;    
;     
;    
;      
;   vpph (0  vpph=0  1  vpph=1)
;       pgf_prog
;    time_wr
;   
;      
; 

 wr_byte_c512:
  acall bspi_rxd ;   
  mov bptr_h,a
  acall bspi_rxd ;    
  mov bptr_l,a ;  bptr_h:bptr_l
  acall bspi_rxd ;   
  mov temp_i,a ; temp_i(  )
  acall bspi_rxd ;    vpph
  rrc a ; 0  vpph=0  1  vpph=1
  mov vpph,C ;    vpph
  acall bspi_rxd ;  
  mov time_wr,a ;    pgf_prog
;
;   Pg_reset  MB4012    1
; Pg_psen   0
;
  acall bloc ;   
  anl bptr_h,#low ~Pfb_mask ;   Pfb2_6=0:Pfb2_7=1
  orl bptr_h,#1<<Pfb2_7 ;    bptr_h
;  acall bloc 3=0xFF (  Pfb3_6=Pfb3_7=1)
  mov addr_h,bptr_h ;    bptr_h:bptr_l
  mov addr_l,bptr_l ;   addr_h:addr_l(Pf2:Pf1)
  mov r2,#10
   djnz r2,$ ; time 10
  mov data_bus,temp_i ;    temp_i  data_bus(Pf0)
  mov r2,#15
  djnz r2,$ ; time 48
  jnb vpph,novpp2
  clr linc_port3.pgf_evpp ;  vpph=1  pgf_evpp=0
 novpp2:
  mov r2,#10
  djnz r2,$ ; time 10
  clr linc_port3.pgf_prog ;   pgf_prog
  mov r2,time_wr
	 djnz r2,$ ; -_-    time_wr uS
  setb linc_port3.pgf_prog
 while_busyl:
  jb linc_port3.pgf_busy,while_busyl ;  pgf_busy = 0
  mov data_bus,#0xFF ;  0   
 while_busyh:
  jnb linc_port3.pgf_busy,while_busyh ;  pgf_busy = 1
	 ; (  0  1 uS
   ;   pgf_prog,   1 
   ;     2mS)
  setb linc_port3.pgf_evpp ;   
	                ;  +12  pgf_evpp=1
   mov r2,#10
  djnz r2,$ ; time 10
  clr linc_port2.Pfb2_7 ;    Pfb2_6=Pfb2_7=0
   mov r2,#15
  djnz r2,$ ; time 48
  mov temp_o,data_bus;    temp_o
 acall bloc ;   
 clr data_key ;   
 mov a,temp_o
 acall bspi_txd ;   
           ;  temp_o  MB4012
 ajmp wait_com

;
;----------------------------------------
;
;    1 
  mov tik_cnt,#sec_ps2 ;   
	          ;  
 sek_time:
	setb sys_tik
  mov TL0,#low sec_paus
  mov TH0,#high sec_paus
  setb TR0
  jb sys_tik,$
  djnz tik_cnt,sek_time ;   1 
 ret
;
;----------------------------------------
;
 bloc:
  mov a,#0xFF
  mov p0,a
  mov p1,a
  mov p2,a
  mov p3,a
  nop
  nop
  nop
 ret
;
;----------------------------------------
;

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