h# eeee constant zl-mask h# 7777 constant zr-mask h# 9009 constant corners : shift4x4 (s value dx dy -- value' ) 4 mod swap 4 mod swap rot h# ffff and ( dx dy value ) dup 16 << or 4 rot - 4 * >> h# ffff and ( x val/y ) 2dup 4 rot - 0 ?do zl-mask and 1 >> loop -rot swap 0 ?do zr-mask and 1 << loop or ; : swap-corners (s value -- value' ) dup corners or corners xor swap corners and dup 15 << swap dup 15 >> swap dup 9 << swap 9 >> or or or corners and or ;