;
;         "dm_ext_disp.txt"    ,
;               
;
;          
;      
;        ,
;        (hs_ext_disp.txt)
;      
;
;------------------------------------------------------------------------------
;
;     -    -
;     (  )    CLKio 
; 
;         ~62 (0,016S)
;   4    0,004S
;   ,        "" ()
;  0,001S       -
;   (  ) =4
;    (3 ) =3
; - (2) =2
;  (1 ) =1
;    =0     
;           (BLANK)
;      100uS
;    ""    
; " "       
;          
;         
;        (-)
;
;------------------------------------------------------------------------------
;
; .equ dm_lens = 4 ;      
; .equ dm_ttm = 1000 ;      CLKio = 1  
; .equ dm_blank = 90 ;      
; .equ dm_A0 = 3 ;()        A0
; .equ dm_A1 = 4 ;()        A1
; .equ dm_A2 = 5 ;()        A2
; .equ dm_A3 = 6 ;()        A3
; .equ dm_mask = 0b10111111 ;    
; .equ dm_AP = PORTD ;      
; .equ dm_SP = PORTB ;      
; .equ dm_f7 = 7 ;        dm_tmp
; .equ dm_f6 = 6 ;       
;------------------------------------------------------------------------------
;
;  .dseg
; dr_tmpd:  .byte dm_lens ;     
; dr_tmpa:  .byte dm_lens ;     
; dm_bufot: .byte dm_lens ;  
; dm_bufat: .byte dm_lens ;   
; dm_masp:  .byte 1 ;     
; dm_pila:  .byte 1 ;     
; dm_cnts:  .byte 1 ;    
; dm_cntk:  .byte 1 ;   
; dm_cnts:  .byte 1 ;     ( )
; dm_flags: .byte 1 ;   
; dm_fsr:   .byte 1 ;    
; dm_cntb:  .byte 1 ;      
;           -  
; dm_cntwf: .byte 1 ;    
;           -  
;
;
;------------------------------------------------------------------------------
;             
;       4   
;    ( 0)  dm_A3:dm_A2:dm_A1:dm_A0  dm_AP
;   ( 1)    dm_SP
; dm_hs_init:
;     clr al
;     out PORTB,al
;     ser al
;     out DDRB,al
;     out PORTD,al
;     andi al,(1<<dm_A0 | 1<<dm_A1 | 1<<dm_A2 | 1<<dm_A3)
;     out DDRD,al
; --------------------------------------------------------
;   -   
;  /1      OCR1A
;   OCF1A   
;    
; clr al
; out TCCR1A,al
; out TCNT1H,al
; out TCNT1L,al
; ldi al,0x08
; out TCCR1B,al
; ldi al,high(dm_ttm)
; out OCR1AH,al
; ldi al,low(dm_ttm)
; out OCR1AL,al
; in al,TIFR
; cbr al,(1<<OCF1A)
; out TIFR,al
; in al,TIMSK
; sbr al,(1<<OCIE1A)
; out TIMSK,al
; sei
;     
;   
; -------------------------------------------------------
;
 dm_regtym:
    ;   
    push xh
    push xl
    push dl
    push ch
    push cl
    push bh
    push bl
    push ah
    push al
    ldi xh,high(dm_masp)
    ldi xl,low(dm_masp)
    ld dl,X+ ; dl=dm_masp (dm_mask)
    ld ch,X+ ; ch=dm_pila (0)
    ld cl,X+ ; cl=dm_cntt (3)
    ld bh,X+ ; bh=dm_cntk (4)
    ld bl,X+ ; bl=dm_cnts (31)
    ld ah,X+ ; ah=dm_flags (f7=?, f6=0)
    ld al,X ; al=dm_fsr (3)
 ;      
     ldi xh,high(dm_bufot)
     ldi xl,low(dm_bufot)
     add xl,al
     brcc ptd0
     subi xh,(-1) ;       
 ptd0:
     tst ch ; = tst dm_pila
     brne ptd1 ;     
       in al,dm_AP
       ori al,(1<<dm_A0 | 1<<dm_A1 | 1<<dm_A2 | 1<<dm_A3)
       out dm_AP,al ;       
     ldi al,29 ;  100      dm_pila=0
     ;   ptd4 -     >> 100
 ptd2:
     dec al
     brbc SREG_Z,ptd2 ;   ~100
      ld al,X ;    dm_bufot  al
      com al ;   
      out dm_SP,al ;    
;--------------
         ; (  =     )
         ;         ( )
;--------------
 ptd1:
     adiw xl,dm_lens ;      xh:xl (max +63)
             ;      
     ld al,X
     cpse al,ch ;     dm_bufat(  0-4)
             ;    (ch=dm_pila)
     rjmp ptd3
     sbr ah,(1<<dm_f6) ;   dm_f6=1
     in al,dm_AP
     ori al,(1<<dm_A0 | 1<<dm_A1 | 1<<dm_A2 | 1<<dm_A3)
     out dm_AP,al ;       ch=dm_pila  0  4
 ptd3:
     sbrc ah,dm_f6 ;  ,  dm_f6=0
     rjmp ptd4 ;        
      in al,dm_AP
      and al,dl
      out dm_AP,al ;  
 ptd4:
      inc ch ; ch=dm_pila = (ch=dm_pila)+1
      dec cl ; cl=dm_cntt = (cl=dm_cntt)-1
      breq ptd5
     rjmp retirss ;      
 ptd5:     ;   
     ld al,X
     cpse al,ch ;     dm_bufat(  0-4)
             ;    (ch=dm_pila)
     rjmp ptd10
      in al,dm_AP
      ori al,(1<<dm_A0 | 1<<dm_A1 | 1<<dm_A2 | 1<<dm_A3)
      out dm_AP,al ;       ch=dm_pila = 4
 ptd10:
     asr dl ;     
     clr ch ; ch=dm_pila = 0
     ldi cl,3 ; cl=dm_cntt = 3
      cbr ah,(1<<dm_f6) ; ah=dm_flags.dm_f6=0   
     dec bh ; bh=dm_cntk = (bh=dm_cntk)-1
     breq ptd6 ;   
      lds al,dm_fsr
      dec al
      sts dm_fsr,al ;      
    rjmp retirss ;     
;  4     
;     dm_pila=0    
 ptd6:    ;   
    sbrs ah,dm_f7 ;    F7
    rjmp ptd7
    push yh
    push yl
    ldi xh,high(dm_bufot-1)
    ldi xl,low(dm_bufot-1)
    ldi yh,high(dr_tmpd-1)
    ldi yl,low(dr_tmpd-1)
    ldi al,(dm_lens*2)
 ptd8:
     ld ch,Y+
     st X+,ch
     dec al
     breq ptd9
     rjmp ptd8
 ptd9:
    pop yl
    pop yh
    cbr ah,(1<<dm_f7) ; dm_f7=0
 ptd7:
   ;   ch=dm_pila = 0, cl=dm_cntt = 3, dm_f6=0
   ldi dl,dm_mask ; dl=dm_masp = dm_mask
   ldi bh,4 ; bh=dm_cntk = 4
   ldi al,3 ;   ( -1)
   sts dm_fsr,al ;      
;--------------
;        " "
;--------------
;   
;-------------------------------------------------------------------------
 retirss:
    ldi al,low(retirs)
    push al
    ldi al,high(retirs)
    push al
    reti
 retirs:
      ldi xh,high(dm_masp)
      ldi xl,low(dm_masp)
    st X+,dl ; dm_masp=dl
    st X+,ch ; dm_pila=ch
    st X+,cl ; dm_cntt=cl
    st X+,bh ; dm_cntk=bh
    st X+,bl ; dm_cnts=bl
    st X+,ah ; dm_flags=ah
    pop al
    pop ah
    pop bl
    pop bh
    pop cl
    pop ch
    pop dl
    pop xl
    pop xh
  ret
;