;
;
;         trd2812_m.txt
;
;            
;        WS2812B
;        
;  16  ( 0,000000062 S)
;
;     WS2812B
;
;Data transfer time( TH+TL=1.25s600ns) 
;  T0H  0 code ,high voltage time  0.4us   150ns 
;  T1H  1 code ,high voltage time  0.8us   150ns 
;  T0L  0 code ,low voltage time   0.85us  150ns 
;  T1L  1 code ,low voltage time   0.45us  150ns 
;  RES  low voltage time  Above 50s
;     = 0
;        
;     
;  G - R - B  
;    
;    
;
;     -   (1!)
; - 4.19 
;
; Data transfer time( TH+TL=1.38s -10ns)
;  T0H  0 code ,high voltage time  0.44us  10ns 
;  T1H  1 code ,high voltage time  0.88us  10ns 
;  T0L  0 code ,low voltage time   0.94us  10ns 
;  T1L  1 code ,low voltage time   0.50us  10ns
;  RES  low voltage time  192,88uS (Above 50s)
;
;      (x60*3) = 2175uS (0.002175)
;    (irq t/c0) = 0.004S (4000uS)
;
;             define datas
; .equ port_out = PORTB ;   ( )
; .equ out_line = 0 ;   
; .equ bufout = SRAM_START ;    
; .equ pixel = 60 ;    /
; .equ bufout_size = (pixel * 3) ;       - !!!


;   -   
;
; .def name = r31 ; ZH  ()
; .def name = r30 ; ZL  ()
; .def name = r29 ; YH  ()
; .def name = r28 ; YL  ()
; .def name = r27 ; XH  ()     bufout
; .def name = r26 ; XL  ()     bufout
; .def name = r25 ;  () BH
; .def name = r24 ;  () BL
; .def name = r23 ;  ()
; .def name = r22 ;  ()
; .def name = r21 ;  ()
; .def name = r20 ;  ()
; .def name = r19 ;  ()
; .def name = r18 ;  ()
; .def tmp1 = r17 ;  ()   
; .def tmp0 = r16 ;  ()   
; .def regn = r15 ;  ()
; .def regn = r14 ;  ()
; .def regn = r11 ;  ()
; .def regn = r10 ;  ()
; .def regn = r9 ;  ()
; .def regn = r8 ;  ()
; .def regn = r7 ;  ()
; .def regn = r6 ;  ()
; .def regn = r5 ;  ()
; .def regn = r4 ;  ()
; .def regn = r3 ;  ()
; .def regn = r2 ;  ()
; .def matr = r1 ;  () r1    !!!
; .def madr = r0 ;  () r0    !!!
;
;-----------------------------------------
;  .macro   ;;    
;     
;     
;    .endmacro
; 
;-----------------------------------------
;
;      
;  .dseg
;  .org bufout
;point0: .byte 3 ; g:r:b
;point1: .byte 3 ; g:r:b
;point2: .byte 3 ; g:r:b
;point3: .byte 3 ; g:r:b
;point4: .byte 3 ; g:r:b
;point5: .byte 3 ; g:r:b
;point6: .byte 3 ; g:r:b
;point7: .byte 3 ; g:r:b
;point8: .byte 3 ; g:r:b
;point9: .byte 3 ; g:r:b
;point10: .byte 3 ; g:r:b
;point11: .byte 3 ; g:r:b
;point12: .byte 3 ; g:r:b
;point13: .byte 3 ; g:r:b
;point14: .byte 3 ; g:r:b
;point15: .byte 3 ; g:r:b
;point16: .byte 3 ; g:r:b
;point17: .byte 3 ; g:r:b
;point18: .byte 3 ; g:r:b
;point19: .byte 3 ; g:r:b
;point20: .byte 3 ; g:r:b
;point21: .byte 3 ; g:r:b
;point22: .byte 3 ; g:r:b
;point23: .byte 3 ; g:r:b
;point24: .byte 3 ; g:r:b
;point25: .byte 3 ; g:r:b
;point26: .byte 3 ; g:r:b
;point27: .byte 3 ; g:r:b
;point28: .byte 3 ; g:r:b
;point29: .byte 3 ; g:r:b
;point30: .byte 3 ; g:r:b
;point31: .byte 3 ; g:r:b
;point32: .byte 3 ; g:r:b
;point33: .byte 3 ; g:r:b
;point34: .byte 3 ; g:r:b
;point35: .byte 3 ; g:r:b
;point36: .byte 3 ; g:r:b
;point37: .byte 3 ; g:r:b
;point38: .byte 3 ; g:r:b
;point39: .byte 3 ; g:r:b
;point40: .byte 3 ; g:r:b
;point41: .byte 3 ; g:r:b
;point42: .byte 3 ; g:r:b
;point43: .byte 3 ; g:r:b
;point44: .byte 3 ; g:r:b
;point45: .byte 3 ; g:r:b
;point46: .byte 3 ; g:r:b
;point47: .byte 3 ; g:r:b
;point48: .byte 3 ; g:r:b
;point49: .byte 3 ; g:r:b
;point50: .byte 3 ; g:r:b
;point51: .byte 3 ; g:r:b
;point52: .byte 3 ; g:r:b
;point53: .byte 3 ; g:r:b
;point54: .byte 3 ; g:r:b
;point55: .byte 3 ; g:r:b
;point56: .byte 3 ; g:r:b
;point57: .byte 3 ; g:r:b
;point58: .byte 3 ; g:r:b
;point59: .byte 3 ; g:r:b
;
;-----------------------------------------

  .cseg
		.org 0x0020 ;   00020 !!!
slot0:
     ; 6/14 (6-4=2     CBI)
    cbi port_out,out_line ; 2 
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    ret ; 4 
    .org (slot0+16)
slot1:
    nop ; 13/7 (13-4=9)
    nop
    nop
    nop
    nop
    nop
    nop
    cbi port_out,out_line ; 2 
    nop
    nop
    ret ; 4 
    .org 0x0060
xslot0:
    ; 6/14 (6-5=1     CBI    1 nop)
    cbi port_out,out_line ; 2 
    cbr zl,(1<<6) ;   1 
    nop
    nop
    nop
    nop
    nop
    nop ; -2   ld tmp0,x+
    dec tmp1 ; 1 
    brbs SREG_Z,ends_trd ; 1    ( )
    rjmp trasstt ; 2 
    .org (xslot0+16)
xslot1:
    nop ; 13/7 (13-5=8)
    cbr zl,(1<<6) ;   1 
    nop
    nop
    nop
    nop
    nop
    cbi port_out,out_line ; 2 
           ; -2   ld tmp0,x+
		dec tmp1 ; 1 
    brbs SREG_Z,ends_trd ; 1    ( )
    rjmp trasstt ; 2 
;
ends_trd:
      pop tmp0
      pop tmp1
      pop xl
      pop xh
			pop zl
			pop zh ;     
   ret
;-----------------------------------------
;
; :
;  out_line   
;   out_line =0
;     RAMEND
;   (bufout:bufout_size)  
;     
;
mass_trm:
     push zh
     push zl
     push xh
     push xl
     push tmp1
     push tmp0 ;     
res_line:
     ldi tmp0,2
     ser tmp1
     cbi port_out,out_line
res_time:
     dec tmp1
     brne res_time
     dec tmp0
     brne res_time ; =>50uS time out
     ldi xh,high (bufout)
     ldi xl,low (bufout) ;    
        ;  
     ldi tmp1,bufout_size
     ldiw z,slot0 ;     
;-----------------------------------------
trasstt:
    ld tmp0,x+ ; 2 
slot_0:
      sbi port_out,out_line ; 2     3 
			bst tmp0,7 ; 1 
			bld zl,4 ; 1 
			icall ; 3  = 4   out_line=1
;----------------
slot_1:
      sbi port_out,out_line
      bst tmp0,6 ; 1 
			bld zl,4 ; 1 
			icall ; 3 
;----------------
slot_2:
      sbi port_out,out_line
      bst tmp0,5 ; 1 
			bld zl,4 ; 1 
			icall ; 3 
;----------------
slot_3:
      sbi port_out,out_line
      bst tmp0,4 ; 1 
			bld zl,4 ; 1 
			icall ; 3 
;----------------
slot_4:
      sbi port_out,out_line
      bst tmp0,3 ; 1 
			bld zl,4 ; 1 
			icall ; 3 
;----------------
slot_5:
      sbi port_out,out_line
      bst tmp0,2 ; 1 
			bld zl,4 ; 1 
			icall ; 3 
;----------------
slot_6:
      sbi port_out,out_line
      bst tmp0,1 ; 1 
			bld zl,4 ; 1 
			icall ; 3 
;----------------
slot_7:
      sbi port_out,out_line
      sbr zl,(1<<6) ;     
                  ; 1 
      bst tmp0,0 ; 1 
			bld zl,4 ; 1 
			ijmp ; 3 
;----------------