;
;         "libr_t45_m.txt"      
;
;---------------------------------------------------
;                xlods
;   /   
;     :
;
;   /    Xh:Xl
;     tmp3 (cnt_pix) = 1-255
;        
; tmp0 = tmp_Gy, tmp1 = tmp_Ry, tmp2 = tmp_By
;      
; Gy_f, Ry_f, By_f    (flags)
;      tmpp0
;       
;   ,   
;
xlods:
    sbrc flags,Gy_f
    st x,tmp0 ; tmp_Gy
    adiw xl,1
    sbrc flags,Ry_f
    st x,tmp1 ; tmp_Ry
    adiw xl,1
    sbrc flags,By_f
    st x,tmp2 ; tmp_By
    adiw xl,1
   dec tmp3
   brne xlods
  ret
;---------------------------------------------------
;             rap
;      
;   
;
;   xlods
;  :
;    Xh:Xl (   )
;    Yh:Yl   
;  
; tmp0 = tmp_Gy, tmp1 = tmp_Ry, tmp2 = tmp_By
;      
;    
; Gy_f, Ry_f, By_f    (flags)
;   / 
;    
; (      
; )
;
rap:
    push yh
    push yl
    dec tmp3 ; cnt_pix=cnt_pix-1
    movw yl,xl
      ld tmp2,y
      ld tmp1,-y
      ld tmp0,-y ; Y= +1
      sbiw yl,1 ; Y= 
loop_rap0:
       ld tmpp0,y
       sbrc flags,By_f
       st x,tmpp0
       sbiw yl,1 ;
       sbiw xl,1 ;  
       ld tmpp0,y
       sbrc flags,Ry_f
       st x,tmpp0
       sbiw yl,1 ;
       sbiw xl,1 ;  
       ld tmpp0,y
       sbrc flags,Gy_f
       st x,tmpp0
       sbiw yl,1 ;
       sbiw xl,1 ;  
     dec tmp3
     brne loop_rap0
      mov tmpp0,tmp2
      sbrc flags,By_f
      st x,tmpp0
      sbiw xl,1 ;  
      mov tmpp0,tmp1
      sbrc flags,Ry_f
      st x,tmpp0
      sbiw xl,1 ;  
      mov tmpp0,tmp0
      sbrc flags,Gy_f
      st x,tmpp0
     pop yl
     pop yh
    ret
;---------------------------------------------------
;            rdaun
;      
;   
;
;   xlods
;  :
;    Xh:Xl (   )
;    Yh:Yl   
;   Bh:Bl  1 (  )
;  
; tmp0 = tmp_Gy, tmp1 = tmp_Ry, tmp2 = tmp_By
;      
;    
; Gy_f, Ry_f, By_f    (flags)
;   / 
;    
; (      
; )
;
rdaun:
    push yh
    push yl
    movw yl,xl
    dec tmp3 ; cnt_pix=cnt_pix-1
    ld tmp0,x+ ; tmp_Gy
    ld tmp1,x+ ; tmp_Ry
    ld tmp2,x+ ; tmp_By
loop_rdaun:
    ld tmpp0,x+
    sbrc flags,Gy_f
    st y,tmpp0
    adiw yl,1
    ld tmpp0,x+
    sbrc flags,Ry_f
    st y,tmpp0
    adiw yl,1
    ld tmpp0,x+
    sbrc flags,By_f
    st y,tmpp0
    adiw yl,1
   dec tmp3
   brne loop_rdaun
    mov tmpp0,tmp0
    sbrc flags,Gy_f
    st y,tmpp0
    adiw yl,1
    mov tmpp0,tmp1
    sbrc flags,Ry_f
    st y,tmpp0
    adiw yl,1
    mov tmpp0,tmp2
    sbrc flags,By_f
    st y,tmpp0
   pop yl
   pop yh
  ret
;---------------------------------------------------
;          max_sys_clk
;     
;       
;
max_sys_clk:
   push tmp0
   push tmp1
   clr tmp1
   ldi tmp0,0x80
   out CLKPR,tmp0
   out CLKPR,tmp1
   pop tmp1
   pop tmp0
  ret
;---------------------------------------------------
;         nom_sys_clk
;   "  "
;  1/ ( )
;   
;
nom_sys_clk:
   push tmp0
   push tmp1
   ldi tmp1,(1<<CLKPS2)
   ldi tmp0,0x80
   out CLKPR,tmp0
   out CLKPR,tmp1
   pop tmp1
   pop tmp0
  ret
;---------------------------------------------------
;           EEPROM_wr
;         
;      
; Xh:Xl (for EEARH:EEARL)
;      tmp0 (for EEDR)
;
EEPROM_wr:
    sbic EECR,EEPE
   rjmp EEPROM_wr
    push tmp0
    clr tmp0
    out EECR,tmp0
    pop tmp0
    out EEARH,Xh
    out EEARL,Xl
    out EEDR,tmp0
    sbi EECR,EEMPE
    sbi EECR,EEPE
eewr_end:
    sbic EECR,EEPE
   rjmp eewr_end
  ret
;---------------------------------------------------
;         EEPROM_rd
;        
;      
; Xh:Xl (for EEARH:EEARL)
;       tmp0
;
EEPROM_rd:
     sbic EECR,EEPE
   rjmp EEPROM_rd
     out EEARH,Xh
     out EEARL,Xl
     sbi EECR,EERE
     in tmp0,EEDR
    ret
;---------------------------------------------------
;