fix type mess by using stdint.h types

there was a plethora of uint, uchar, ushort etc macros used,
which caused build issues in a number of cases, for example when
compiling against musl libc.
Why move this ~200 lines?