anchor.diff:  ;
   
   : key-available? ( -- true|false )
  -   multi-key 0 <> IF 
  +   multi-key 0 <> IF
         true \ multi scan code key was pressed... so key is available
         EXIT \ done
      THEN
  -   kbd-scan 0 = IF \ if no kbd-scan code is currently available 
  -      int-get-report \ check for one using int-get-report 
  +   kbd-scan 0 = IF \ if no kbd-scan code is currently available
  +      int-get-report \ check for one using int-get-report
      THEN
      kbd-scan 0 <> \ if a kbd-scan is available, report true, else false
   ;
   
  -: usb-kread ( -- char|false )                            \ usb key read for control transfer
  -    multi-key 0 <> if                                    \ if multi scan code key is pressed
  -	multi-key ff and                                 \ read one byte from buffer
  -	multi-key 8 rshift to multi-key                  \ move to next byte 
  -    else                                                 \ normal key check
  -    \ check for new scan code only, if kbd-scan is not set, e.g.
  -    \ by a previous call to key-available?
  -   kbd-scan 0 = IF
  -	\ if interrupt transfer
  -	int-get-report                                   \ read report (interrupt transfer)
  -	\ else control transfer
  -	\ ctl-get-report                                 \ read report (control transfer)
  -	\ end of interrupt/control switch
  -   THEN
  - 	kbd-scan 0 <> if                                 \ scan code exist?
  -	    begin kbd-scan ff and dup 00 = while         \ get a last scancode in report buffer
  -		    kbd-scan 8 rshift to kbd-scan        \ This algorithm is wrong --> must be fixed!
  -		    drop                                 \ KBD doesn't set scancode in pressed order!!!
  -	    repeat
  -	    dup key-old <> if                            \ if the scancode is new
  -	    	dup to key-old                           \ save current scan code
  -	    	get-ukbd-char                            \ translate scan code --> char
  -	    	milliseconds fa + to expire-ms           \ set typematic delay 250ms
  -	    else                                         \ scan code is not changed
  -	    	milliseconds expire-ms > if              \ if timer is expired ... should be considered timer carry over
  -	    	    get-ukbd-char                        \ translate scan code --> char
  -	    	    milliseconds 21 + to expire-ms       \ set typematic rate 30cps
  -	    	else                                     \ timer is not expired 
  -	    	    drop false                           \ do nothing
  -	    	then
  -	    then
  -       kbd-scan 8 rshift to kbd-scan \ handled scan-code
  - 	else
  -	    0 to key-old                                 \ clear privious key
  -	    false                                        \ no scan code --> return false
  - 	then
  -    then
  +: usb-kread ( -- char|false )                     \ usb key read for control transfer
  +   multi-key 0 <> if                              \ if multi scan code key is pressed
  +      multi-key ff and                            \ read one byte from buffer
  +      multi-key 8 rshift to multi-key             \ move to next byte
  +   else                                           \ normal key check
  +      \ check for new scan code only, if kbd-scan is not set, e.g.
  +      \ by a previous call to key-available?
  +      kbd-scan 0 = IF
  +         \ if interrupt transfer
  +         int-get-report                           \ read report (interrupt transfer)
  +         \ else control transfer
  +         \ ctl-get-report                         \ read report (control transfer)
  +         \ end of interrupt/control switch
  +      THEN
  +      kbd-scan 0 <> if                            \ scan code exist?
  +         begin kbd-scan ff and dup 00 = while     \ get a last scancode in report buffer
  +            kbd-scan 8 rshift to kbd-scan         \ This algorithm is wrong --> must be fixed!
  +            drop                                  \ KBD doesn't set scancode in pressed order!!!
  +         repeat
  +         dup key-old <> if                        \ if the scancode is new
  +            dup to key-old                        \ save current scan code
  +            get-ukbd-char                         \ translate scan code --> char
  +            milliseconds fa + to expire-ms        \ set typematic delay 250ms
  +         else                                     \ scan code is not changed
  +            milliseconds expire-ms > if           \ if timer is expired ... should be considered timer carry over
  +               get-ukbd-char                      \ translate scan code --> char
  +               milliseconds 21 + to expire-ms     \ set typematic rate 30cps
  +            else                                  \ timer is not expired
  +               drop false                         \ do nothing
  +            then
  +         then
  +         kbd-scan 8 rshift to kbd-scan            \ handled scan-code
  +      else
  +         0 to key-old                             \ clear privious key
  +         false                                    \ no scan code --> return false
  +      then
  +   then
   ;
   
   
  
positive.code: : control-cls-set-report ( reportvalue FuncAddr -- TRUE|FALSE )
    to temp1
    to temp2
    2109000200000100 kbd-buf kb>setup-packet ! 
    temp2 kbd-buf kb>data l!-le  
    1 kbd-buf kb>data 1 kbd-buf kb>setup-packet
    DEFAULT-CONTROL-MPS temp1 controlxfer  
  ;
  
  : control-cls-get-report ( data-buffer data-len MPS FuncAddr -- TRUE|FALSE )
    to temp1
    to temp2
    to temp3
    a101000100000000 kbd-buf kb>setup-packet ! 
    temp3 kbd-buf kb>setup-packet 6 + w!-le  
    0 swap temp3 kbd-buf kb>setup-packet
    temp2 temp1 controlxfer  
  ;
  
  : int-get-report ( -- )                                     \ get report for interrupt transfer
     0 2 int-in-toggle kbd-buf kb>report 8 mps-int-in
     kbd-addr int-in-ep 7 lshift or rw-endpoint               \ get report 
     swap to int-in-toggle IF
        kbd-buf kb>report @
        ff00000000000000 and 38 rshift to kbd-shift           \ store shift status
        kbd-buf kb>report @
        0000ffffffffffff and to kbd-scan                      \ store scan codes
     ELSE
        0 to kbd-shift                                        \ clear shift status 
        0 to kbd-scan                                         \ clear scan code buffer
     THEN
  ;
  
  : ctl-get-report ( -- )                                     \ get report for control transfer      
     kbd-buf kb>report 8 8 kbd-addr
     control-cls-get-report IF                                \ get report 
        kbd-buf kb>report @
        ff00000000000000 and 38 rshift to kbd-shift           \ store shift status
        kbd-buf kb>report @
        0000ffffffffffff and to kbd-scan                      \ store scan codes 
     ELSE
        0 to kbd-shift                                        \ clear shift status 
        0 to kbd-scan                                         \ clear scan code buffer
     THEN
  ;
  
  : set-led ( led -- ) 
    dup to led-state  
    kbd-addr control-cls-set-report drop
  ;
  
  
negative.code: 		     38 of [char] ? endof
  		     dup of ret endof              \ other keys are no change
  		 endcase
  		 to ret                            \ overwrite new char
  	     then
  	 then
       then
       led-state NumLk and 0 <> if                   \ if NumLk is on
         scancode
         case                                        \ translate scan code --> char
  	 59 of [char] 1 endof
  	 5a of [char] 2 endof
  