words[]: type FD = { } ; const bool yes = 1 , no = 0 ; const bool true = 1 , false = 0 ; extern { uint8 msbit ( uint16 ) ; uint8 msbit ( uint32 ) ; int sign ( int16 ) ; int sign ( int32 ) ; uint16 abs ( int16 ) ; uint32 abs ( int32 ) ; uint16 swap_bytes ( uint16 ) ; uint32 revert_bytes ( uint32 ) ; uint32 swap_words ( uint32 ) ; uint16 random ( ) ; uint32 mul_wwl ( uint16 , uint16 ) ; void flip ( int8 [ to ] ) = opcode flip ; void rol ( int8 [ to ] ) = opcode rol ; void ror ( int8 [ to ] ) = opcode ror ; void sort ( int8 [ to ] ) = opcode sort ; void rsort ( int8 [ to ] ) = opcode rsort ; void shuffle ( int8 [ to ] ) = opcode shuffle ; void revert ( int8 [ to ] ) = opcode revert ; int8 [ ] join ( int8 [ ] [ ] ¢ , int8 ) = opcode join ; int8 [ ] join ( int8 [ ] [ ] ¢ , int8 [ ] ¢ ) = opcode join ; int8 [ ] [ ] split ( int8 [ ] ¢ , int8 ) = opcode split ; int8 [ ] [ ] split ( int8 [ ] ¢ , int8 [ ] ¢ ) = opcode split ; int8 min ( int8 , int8 ) ; int8 min ( int8 , int8 , int8 ) ; int8 min ( int8 [ to ] ) ; int8 max ( int8 , int8 ) ; int8 max ( int8 , int8 , int8 ) ; int8 max ( int8 [ to ] ) ; uint find ( int8 [ to ] , int8 ) = opcode find ; uint find ( int8 [ to ] , int8 [ ] ¢ ) = opcode find ; uint rfind ( int8 [ to ] , int8 ) = opcode rfind ; uint rfind ( int8 [ to ] , int8 [ ] ¢ ) = opcode rfind ; void shrinktofit ( int8 [ ] & ) ; int8 [ to ] substr ( int8 [ ] ¢ , uint a , uint e ) ; int8 [ to ] midstr ( int8 [ ] ¢ , uint i , uint n ) ; int8 [ to ] leftstr ( int8 [ ] ¢ , uint n ) ; int8 [ to ] rightstr ( int8 [ ] ¢ , uint n ) ; int8 numval ( utf8str ¢ ) ; int8 numval ( ucs1str ¢ ) ; int8 numval ( ucs2str ¢ ) ; void flip ( uint8 [ to ] ) = opcode flip ; void rol ( uint8 [ to ] ) = opcode rol ; void ror ( uint8 [ to ] ) = opcode ror ; void sort ( uint8 [ to ] ) = opcode sort ; void rsort ( uint8 [ to ] ) = opcode rsort ; void shuffle ( uint8 [ to ] ) = opcode shuffle ; void revert ( uint8 [ to ] ) = opcode revert ; uint8 [ ] join ( uint8 [ ] [ ] ¢ , uint8 ) = opcode join ; uint8 [ ] join ( uint8 [ ] [ ] ¢ , uint8 [ ] ¢ ) = opcode join ; uint8 [ ] [ ] split ( uint8 [ ] ¢ , uint8 ) = opcode split ; uint8 [ ] [ ] split ( uint8 [ ] ¢ , uint8 [ ] ¢ ) = opcode split ; uint8 min ( uint8 , uint8 ) ; uint8 min ( uint8 , uint8 , uint8 ) ; uint8 min ( uint8 [ to ] ) ; uint8 max ( uint8 , uint8 ) ; uint8 max ( uint8 , uint8 , uint8 ) ; uint8 max ( uint8 [ to ] ) ; uint find ( uint8 [ to ] , uint8 ) = opcode find ; uint find ( uint8 [ to ] , uint8 [ ] ¢ ) = opcode find ; uint rfind ( uint8 [ to ] , uint8 ) = opcode rfind ; uint rfind ( uint8 [ to ] , uint8 [ ] ¢ ) = opcode rfind ; void shrinktofit ( uint8 [ ] & ) ; uint8 [ to ] substr ( uint8 [ ] ¢ , uint a , uint e ) ; uint8 [ to ] midstr ( uint8 [ ] ¢ , uint i , uint n ) ; uint8 [ to ] leftstr ( uint8 [ ] ¢ , uint n ) ; uint8 [ to ] rightstr ( uint8 [ ] ¢ , uint n ) ; uint8 numval ( utf8str ¢ ) ; uint8 numval ( ucs1str ¢ ) ; uint8 numval ( ucs2str ¢ ) ; void flip ( int16 [ to ] ) = opcode flip ; void rol ( int16 [ to ] ) = opcode rol ; void ror ( int16 [ to ] ) = opcode ror ; void sort ( int16 [ to ] ) = opcode sort ; void rsort ( int16 [ to ] ) = opcode rsort ; void shuffle ( int16 [ to ] ) = opcode shuffle ; void revert ( int16 [ to ] ) = opcode revert ; int16 [ ] join ( int16 [ ] [ ] ¢ , int16 ) = opcode join ; int16 [ ] join ( int16 [ ] [ ] ¢ , int16 [ ] ¢ ) = opcode join ; int16 [ ] [ ] split ( int16 [ ] ¢ , int16 ) = opcode split ; int16 [ ] [ ] split ( int16 [ ] ¢ , int16 [ ] ¢ ) = opcode split ; int16 min ( int16 , int16 ) ; int16 min ( int16 , int16 , int16 ) ; int16 min ( int16 [ to ] ) ; int16 max ( int16 , int16 ) ; int16 max ( int16 , int16 , int16 ) ; int16 max ( int16 [ to ] ) ; uint find ( int16 [ to ] , int16 ) = opcode find ; uint find ( int16 [ to ] , int16 [ ] ¢ ) = opcode find ; uint rfind ( int16 [ to ] , int16 ) = opcode rfind ; uint rfind ( int16 [ to ] , int16 [ ] ¢ ) = opcode rfind ; void shrinktofit ( int16 [ ] & ) ; int16 [ to ] substr ( int16 [ ] ¢ , uint a , uint e ) ; int16 [ to ] midstr ( int16 [ ] ¢ , uint i , uint n ) ; int16 [ to ] leftstr ( int16 [ ] ¢ , uint n ) ; int16 [ to ] rightstr ( int16 [ ] ¢ , uint n ) ; int16 numval ( utf8str ¢ ) ; int16 numval ( ucs1str ¢ ) ; int16 numval ( ucs2str ¢ ) ; void flip ( uint16 [ to ] ) = opcode flip ; void rol ( uint16 [ to ] ) = opcode rol ; void ror ( uint16 [ to ] ) = opcode ror ; void sort ( uint16 [ to ] ) = opcode sort ; void rsort ( uint16 [ to ] ) = opcode rsort ; void shuffle ( uint16 [ to ] ) = opcode shuffle ; void revert ( uint16 [ to ] ) = opcode revert ; uint16 [ ] join ( uint16 [ ] [ ] ¢ , uint16 ) = opcode join ; uint16 [ ] join ( uint16 [ ] [ ] ¢ , uint16 [ ] ¢ ) = opcode join ; uint16 [ ] [ ] split ( uint16 [ ] ¢ , uint16 ) = opcode split ; uint16 [ ] [ ] split ( uint16 [ ] ¢ , uint16 [ ] ¢ ) = opcode split ; uint16 min ( uint16 , uint16 ) ; uint16 min ( uint16 , uint16 , uint16 ) ; uint16 min ( uint16 [ to ] ) ; uint16 max ( uint16 , uint16 ) ; uint16 max ( uint16 , uint16 , uint16 ) ; uint16 max ( uint16 [ to ] ) ; uint find ( uint16 [ to ] , uint16 ) = opcode find ; uint find ( uint16 [ to ] , uint16 [ ] ¢ ) = opcode find ; uint rfind ( uint16 [ to ] , uint16 ) = opcode rfind ; uint rfind ( uint16 [ to ] , uint16 [ ] ¢ ) = opcode rfind ; void shrinktofit ( uint16 [ ] & ) ; uint16 [ to ] substr ( uint16 [ ] ¢ , uint a , uint e ) ; uint16 [ to ] midstr ( uint16 [ ] ¢ , uint i , uint n ) ; uint16 [ to ] leftstr ( uint16 [ ] ¢ , uint n ) ; uint16 [ to ] rightstr ( uint16 [ ] ¢ , uint n ) ; uint16 numval ( utf8str ¢ ) ; uint16 numval ( ucs1str ¢ ) ; uint16 numval ( ucs2str ¢ ) ; void flip ( int32 [ to ] ) = opcode flip ; void rol ( int32 [ to ] ) = opcode rol ; void ror ( int32 [ to ] ) = opcode ror ; void sort ( int32 [ to ] ) = opcode sort ; void rsort ( int32 [ to ] ) = opcode rsort ; void shuffle ( int32 [ to ] ) = opcode shuffle ; void revert ( int32 [ to ] ) = opcode revert ; int32 [ ] join ( int32 [ ] [ ] ¢ , int32 ) = opcode join ; int32 [ ] join ( int32 [ ] [ ] ¢ , int32 [ ] ¢ ) = opcode join ; int32 [ ] [ ] split ( int32 [ ] ¢ , int32 ) = opcode split ; int32 [ ] [ ] split ( int32 [ ] ¢ , int32 [ ] ¢ ) = opcode split ; int32 min ( int32 , int32 ) ; int32 min ( int32 , int32 , int32 ) ; int32 min ( int32 [ to ] ) ; int32 max ( int32 , int32 ) ; int32 max ( int32 , int32 , int32 ) ; int32 max ( int32 [ to ] ) ; uint find ( int32 [ to ] , int32 ) = opcode find ; uint find ( int32 [ to ] , int32 [ ] ¢ ) = opcode find ; uint rfind ( int32 [ to ] , int32 ) = opcode rfind ; uint rfind ( int32 [ to ] , int32 [ ] ¢ ) = opcode rfind ; void shrinktofit ( int32 [ ] & ) ; int32 [ to ] substr ( int32 [ ] ¢ , uint a , uint e ) ; int32 [ to ] midstr ( int32 [ ] ¢ , uint i , uint n ) ; int32 [ to ] leftstr ( int32 [ ] ¢ , uint n ) ; int32 [ to ] rightstr ( int32 [ ] ¢ , uint n ) ; int32 numval ( utf8str ¢ ) ; int32 numval ( ucs1str ¢ ) ; int32 numval ( ucs2str ¢ ) ; void flip ( uint32 [ to ] ) = opcode flip ; void rol ( uint32 [ to ] ) = opcode rol ; void ror ( uint32 [ to ] ) = opcode ror ; void sort ( uint32 [ to ] ) = opcode sort ; void rsort ( uint32 [ to ] ) = opcode rsort ; void shuffle ( uint32 [ to ] ) = opcode shuffle ; void revert ( uint32 [ to ] ) = opcode revert ; uint32 [ ] join ( uint32 [ ] [ ] ¢ , uint32 ) = opcode join ; uint32 [ ] join ( uint32 [ ] [ ] ¢ , uint32 [ ] ¢ ) = opcode join ; uint32 [ ] [ ] split ( uint32 [ ] ¢ , uint32 ) = opcode split ; uint32 [ ] [ ] split ( uint32 [ ] ¢ , uint32 [ ] ¢ ) = opcode split ; uint32 min ( uint32 , uint32 ) ; uint32 min ( uint32 , uint32 , uint32 ) ; uint32 min ( uint32 [ to ] ) ; uint32 max ( uint32 , uint32 ) ; uint32 max ( uint32 , uint32 , uint32 ) ; uint32 max ( uint32 [ to ] ) ; uint find ( uint32 [ to ] , uint32 ) = opcode find ; uint find ( uint32 [ to ] , uint32 [ ] ¢ ) = opcode find ; uint rfind ( uint32 [ to ] , uint32 ) = opcode rfind ; uint rfind ( uint32 [ to ] , uint32 [ ] ¢ ) = opcode rfind ; void shrinktofit ( uint32 [ ] & ) ; uint32 [ to ] substr ( uint32 [ ] ¢ , uint a , uint e ) ; uint32 [ to ] midstr ( uint32 [ ] ¢ , uint i , uint n ) ; uint32 [ to ] leftstr ( uint32 [ ] ¢ , uint n ) ; uint32 [ to ] rightstr ( uint32 [ ] ¢ , uint n ) ; uint32 numval ( utf8str ¢ ) ; uint32 numval ( ucs1str ¢ ) ; uint32 numval ( ucs2str ¢ ) ; void flip ( utf8char [ to ] ) = opcode flip ; void rol ( utf8char [ to ] ) = opcode rol ; void ror ( utf8char [ to ] ) = opcode ror ; void sort ( utf8char [ to ] ) = opcode sort ; void rsort ( utf8char [ to ] ) = opcode rsort ; void shuffle ( utf8char [ to ] ) = opcode shuffle ; void revert ( utf8char [ to ] ) = opcode revert ; utf8char [ ] join ( utf8char [ ] [ ] ¢ , utf8char ) = opcode join ; utf8char [ ] join ( utf8char [ ] [ ] ¢ , utf8char [ ] ¢ ) = opcode join ; utf8char [ ] [ ] split ( utf8char [ ] ¢ , utf8char ) = opcode split ; utf8char [ ] [ ] split ( utf8char [ ] ¢ , utf8char [ ] ¢ ) = opcode split ; utf8char min ( utf8char , utf8char ) ; utf8char min ( utf8char , utf8char , utf8char ) ; utf8char min ( utf8char [ to ] ) ; utf8char max ( utf8char , utf8char ) ; utf8char max ( utf8char , utf8char , utf8char ) ; utf8char max ( utf8char [ to ] ) ; uint find ( utf8char [ to ] , utf8char ) = opcode find ; uint find ( utf8char [ to ] , utf8char [ ] ¢ ) = opcode find ; uint rfind ( utf8char [ to ] , utf8char ) = opcode rfind ; uint rfind ( utf8char [ to ] , utf8char [ ] ¢ ) = opcode rfind ; void shrinktofit ( utf8char [ ] & ) ; utf8char [ to ] substr ( utf8char [ ] ¢ , uint a , uint e ) ; utf8char [ to ] midstr ( utf8char [ ] ¢ , uint i , uint n ) ; utf8char [ to ] leftstr ( utf8char [ ] ¢ , uint n ) ; utf8char [ to ] rightstr ( utf8char [ ] ¢ , uint n ) ; utf8char numval ( utf8str ¢ ) ; utf8char numval ( ucs1str ¢ ) ; utf8char numval ( ucs2str ¢ ) ; void flip ( ucs1char [ to ] ) = opcode flip ; void rol ( ucs1char [ to ] ) = opcode rol ; void ror ( ucs1char [ to ] ) = opcode ror ; void sort ( ucs1char [ to ] ) = opcode sort ; void rsort ( ucs1char [ to ] ) = opcode rsort ; void shuffle ( ucs1char [ to ] ) = opcode shuffle ; void revert ( ucs1char [ to ] ) = opcode revert ; ucs1char [ ] join ( ucs1char [ ] [ ] ¢ , ucs1char ) = opcode join ; ucs1char [ ] join ( ucs1char [ ] [ ] ¢ , ucs1char [ ] ¢ ) = opcode join ; ucs1char [ ] [ ] split ( ucs1char [ ] ¢ , ucs1char ) = opcode split ; ucs1char [ ] [ ] split ( ucs1char [ ] ¢ , ucs1char [ ] ¢ ) = opcode split ; ucs1char min ( ucs1char , ucs1char ) ; ucs1char min ( ucs1char , ucs1char , ucs1char ) ; ucs1char min ( ucs1char [ to ] ) ; ucs1char max ( ucs1char , ucs1char ) ; ucs1char max ( ucs1char , ucs1char , ucs1char ) ; ucs1char max ( ucs1char [ to ] ) ; uint find ( ucs1char [ to ] , ucs1char ) = opcode find ; uint find ( ucs1char [ to ] , ucs1char [ ] ¢ ) = opcode find ; uint rfind ( ucs1char [ to ] , ucs1char ) = opcode rfind ; uint rfind ( ucs1char [ to ] , ucs1char [ ] ¢ ) = opcode rfind ; void shrinktofit ( ucs1char [ ] & ) ; ucs1char [ to ] substr ( ucs1char [ ] ¢ , uint a , uint e ) ; ucs1char [ to ] midstr ( ucs1char [ ] ¢ , uint i , uint n ) ; ucs1char [ to ] leftstr ( ucs1char [ ] ¢ , uint n ) ; ucs1char [ to ] rightstr ( ucs1char [ ] ¢ , uint n ) ; ucs1char numval ( utf8str ¢ ) ; ucs1char numval ( ucs1str ¢ ) ; ucs1char numval ( ucs2str ¢ ) ; void flip ( ucs2char [ to ] ) = opcode flip ; void rol ( ucs2char [ to ] ) = opcode rol ; void ror ( ucs2char [ to ] ) = opcode ror ; void sort ( ucs2char [ to ] ) = opcode sort ; void rsort ( ucs2char [ to ] ) = opcode rsort ; void shuffle ( ucs2char [ to ] ) = opcode shuffle ; void revert ( ucs2char [ to ] ) = opcode revert ; ucs2char [ ] join ( ucs2char [ ] [ ] ¢ , ucs2char ) = opcode join ; ucs2char [ ] join ( ucs2char [ ] [ ] ¢ , ucs2char [ ] ¢ ) = opcode join ; ucs2char [ ] [ ] split ( ucs2char [ ] ¢ , ucs2char ) = opcode split ; ucs2char [ ] [ ] split ( ucs2char [ ] ¢ , ucs2char [ ] ¢ ) = opcode split ; ucs2char min ( ucs2char , ucs2char ) ; ucs2char min ( ucs2char , ucs2char , ucs2char ) ; ucs2char min ( ucs2char [ to ] ) ; ucs2char max ( ucs2char , ucs2char ) ; ucs2char max ( ucs2char , ucs2char , ucs2char ) ; ucs2char max ( ucs2char [ to ] ) ; uint find ( ucs2char [ to ] , ucs2char ) = opcode find ; uint find ( ucs2char [ to ] , ucs2char [ ] ¢ ) = opcode find ; uint rfind ( ucs2char [ to ] , ucs2char ) = opcode rfind ; uint rfind ( ucs2char [ to ] , ucs2char [ ] ¢ ) = opcode rfind ; void shrinktofit ( ucs2char [ ] & ) ; ucs2char [ to ] substr ( ucs2char [ ] ¢ , uint a , uint e ) ; ucs2char [ to ] midstr ( ucs2char [ ] ¢ , uint i , uint n ) ; ucs2char [ to ] leftstr ( ucs2char [ ] ¢ , uint n ) ; ucs2char [ to ] rightstr ( ucs2char [ ] ¢ , uint n ) ; ucs2char numval ( utf8str ¢ ) ; ucs2char numval ( ucs1str ¢ ) ; ucs2char numval ( ucs2str ¢ ) ; bool is_letter ( char ) ; bool is_bin_digit ( char ) ; bool is_dec_digit ( char ) ; bool is_hex_digit ( char ) ; uint digit_value ( char ) ; } ; float64 round ( float64 ) ; float64 floor ( float64 ) ; float64 ceil ( float64 ) ; float64 integ ( float64 ) ; float64 fract ( float64 ) ; int sign ( float64 ) ; float64 abs ( float64 ) ; float64 min ( float64 , float64 ) ; float64 max ( float64 , float64 ) ; float64 min ( float64 , float64 , float64 ) ; float64 max ( float64 , float64 , float64 ) ; float64 random ( ) ; float64 random ( float64 ) ; float64 sin ( float64 ) ; float64 cos ( float64 ) ; float64 tan ( float64 ) ; float64 asin ( float64 ) ; float64 acos ( float64 ) ; float64 atan ( float64 ) ; float64 sinh ( float64 ) ; float64 cosh ( float64 ) ; float64 tanh ( float64 ) ; float64 exp10 ( float64 ) ; float64 log10 ( float64 ) ; float64 exp2 ( float64 ) ; float64 log2 ( float64 ) ; float64 expe ( float64 ) ; float64 loge ( float64 ) ; float64 exp ( float64 , float64 ) ; float64 log ( float64 , float64 ) ; float64 pow ( float64 , int ) ; float64 sqrt ( float64 ) ; str numstr ( float64 ) ; float64 numval ( str ¢ ) ; float64 min ( float64 [ ] ¢ ) ; float64 min ( float64 [ to ] ) ; float64 max ( float64 [ ] ¢ ) ; float64 max ( float64 [ to ] ) ; scope ucs2str { ucs2char [ ] spacestr ( uint ) ucs2char [ ] spacestr ( uint , ucs2char ) ucs2char [ ] charstr ( uint ) ucs2char hexchar ( uint ) ucs2char [ ] hexstr ( uint8 ) ucs2char [ ] hexstr ( uint16 ) ucs2char [ ] hexstr ( uint32 ) ucs2char [ ] hexstr ( uint , uint digits ) ucs2char [ ] hexstr ( ulong , uint digits ) ucs2char [ ] binstr ( uint8 ) ucs2char [ ] binstr ( uint16 ) ucs2char [ ] binstr ( uint32 ) ucs2char [ ] binstr ( uint , uint digits ) ucs2char [ ] binstr ( ulong , uint digits ) ucs2char [ ] binstr ( uint , ucs2char [ ] ¢ o , ucs2char [ ] ¢ l ) ucs2char [ ] binstr ( ulong , ucs2char [ ] ¢ o , ucs2char [ ] ¢ l ) ucs2char [ ] numstr ( int ) ucs2char [ ] numstr ( uint ) ucs2char [ ] numstr ( long ) ucs2char [ ] numstr ( ulong ) ucs2char [ ] toupper ( ucs2char [ ] ¢ ) ucs2char [ ] tolower ( ucs2char [ ] ¢ ) ucs2char [ ] escape ( ucs2char [ ] ¢ , ucs2char leftquote ) ucs2char [ ] unescape ( ucs2char [ ] ¢ ) ucs2char [ ] urlencode ( ucs2char [ ] ¢ ) ucs2char [ ] urldecode ( ucs2char [ ] ¢ ) ucs2char [ ] entab ( ucs2char [ ] ¢ , uint tabwidth ) ucs2char [ ] detab ( ucs2char [ ] ¢ , uint tabwidth ) ucs2char [ ] toupper ( ucs2char [ to ] ) ucs2char [ ] tolower ( ucs2char [ to ] ) ucs2char [ ] escape ( ucs2char [ to ] , ucs2char leftquote ) ucs2char [ ] unescape ( ucs2char [ to ] ) ucs2char [ ] urlencode ( ucs2char [ to ] ) ucs2char [ ] urldecode ( ucs2char [ to ] ) ucs2char [ ] entab ( ucs2char [ to ] , uint tabwidth ) ucs2char [ ] detab ( ucs2char [ to ] , uint tabwidth ) ucs1str toucs1 ( ucs2char [ ] ¢ ) ucs2str toucs2 ( ucs2char [ ] ¢ ) utf8str toutf8 ( ucs2char [ ] ¢ ) ucs1str toucs1 ( ucs2char [ to ] ) ucs2str toucs2 ( ucs2char [ to ] ) utf8str toutf8 ( ucs2char [ to ] ) ucs2char [ ] min ( ucs2char [ ] , ucs2char [ ] ) ucs2char [ ] min ( ucs2char [ ] , ucs2char [ ] ¢ ) ucs2char [ ] min ( ucs2char [ ] ¢ , ucs2char [ ] ) ucs2char [ ] ¢ min ( ucs2char [ ] ¢ , ucs2char [ ] ¢ ) ucs2char [ ] ¢ min ( ucs2char [ ] [ ] ¢ ) ucs2char [ ] ¢ min ( ucs2char [ ] [ to ] ) ucs2char [ ] max ( ucs2char [ ] , ucs2char [ ] ) ucs2char [ ] max ( ucs2char [ ] , ucs2char [ ] ¢ ) ucs2char [ ] max ( ucs2char [ ] ¢ , ucs2char [ ] ) ucs2char [ ] ¢ max ( ucs2char [ ] ¢ , ucs2char [ ] ¢ ) ucs2char [ ] ¢ max ( ucs2char [ ] [ ] ¢ ) ucs2char [ ] ¢ max ( ucs2char [ ] [ to ] ) void flip ( ucs2char [ ] [ to ] ) void rol ( ucs2char [ ] [ to ] ) void ror ( ucs2char [ ] [ to ] ) void sort ( ucs2char [ ] [ to ] ) void rsort ( ucs2char [ ] [ to ] ) void shuffle ( ucs2char [ ] [ to ] ) void revert ( ucs2char [ ] [ to ] ) } scope ucs1str { ucs1char [ ] spacestr ( uint ) ucs1char [ ] spacestr ( uint , ucs1char ) ucs1char [ ] charstr ( uint ) ucs1char hexchar ( uint ) ucs1char [ ] hexstr ( uint8 ) ucs1char [ ] hexstr ( uint16 ) ucs1char [ ] hexstr ( uint32 ) ucs1char [ ] hexstr ( uint , uint digits ) ucs1char [ ] hexstr ( ulong , uint digits ) ucs1char [ ] binstr ( uint8 ) ucs1char [ ] binstr ( uint16 ) ucs1char [ ] binstr ( uint32 ) ucs1char [ ] binstr ( uint , uint digits ) ucs1char [ ] binstr ( ulong , uint digits ) ucs1char [ ] binstr ( uint , ucs1char [ ] ¢ o , ucs1char [ ] ¢ l ) ucs1char [ ] binstr ( ulong , ucs1char [ ] ¢ o , ucs1char [ ] ¢ l ) ucs1char [ ] numstr ( int ) ucs1char [ ] numstr ( uint ) ucs1char [ ] numstr ( long ) ucs1char [ ] numstr ( ulong ) ucs1char [ ] toupper ( ucs1char [ ] ¢ ) ucs1char [ ] tolower ( ucs1char [ ] ¢ ) ucs1char [ ] escape ( ucs1char [ ] ¢ , ucs1char leftquote ) ucs1char [ ] unescape ( ucs1char [ ] ¢ ) ucs1char [ ] urlencode ( ucs1char [ ] ¢ ) ucs1char [ ] urldecode ( ucs1char [ ] ¢ ) ucs1char [ ] entab ( ucs1char [ ] ¢ , uint tabwidth ) ucs1char [ ] detab ( ucs1char [ ] ¢ , uint tabwidth ) ucs1char [ ] toupper ( ucs1char [ to ] ) ucs1char [ ] tolower ( ucs1char [ to ] ) ucs1char [ ] escape ( ucs1char [ to ] , ucs1char leftquote ) ucs1char [ ] unescape ( ucs1char [ to ] ) ucs1char [ ] urlencode ( ucs1char [ to ] ) ucs1char [ ] urldecode ( ucs1char [ to ] ) ucs1char [ ] entab ( ucs1char [ to ] , uint tabwidth ) ucs1char [ ] detab ( ucs1char [ to ] , uint tabwidth ) ucs1str toucs1 ( ucs1char [ ] ¢ ) ucs2str toucs2 ( ucs1char [ ] ¢ ) utf8str toutf8 ( ucs1char [ ] ¢ ) ucs1str toucs1 ( ucs1char [ to ] ) ucs2str toucs2 ( ucs1char [ to ] ) utf8str toutf8 ( ucs1char [ to ] ) ucs1char [ ] min ( ucs1char [ ] , ucs1char [ ] ) ucs1char [ ] min ( ucs1char [ ] , ucs1char [ ] ¢ ) ucs1char [ ] min ( ucs1char [ ] ¢ , ucs1char [ ] ) ucs1char [ ] ¢ min ( ucs1char [ ] ¢ , ucs1char [ ] ¢ ) ucs1char [ ] ¢ min ( ucs1char [ ] [ ] ¢ ) ucs1char [ ] ¢ min ( ucs1char [ ] [ to ] ) ucs1char [ ] max ( ucs1char [ ] , ucs1char [ ] ) ucs1char [ ] max ( ucs1char [ ] , ucs1char [ ] ¢ ) ucs1char [ ] max ( ucs1char [ ] ¢ , ucs1char [ ] ) ucs1char [ ] ¢ max ( ucs1char [ ] ¢ , ucs1char [ ] ¢ ) ucs1char [ ] ¢ max ( ucs1char [ ] [ ] ¢ ) ucs1char [ ] ¢ max ( ucs1char [ ] [ to ] ) void flip ( ucs1char [ ] [ to ] ) void rol ( ucs1char [ ] [ to ] ) void ror ( ucs1char [ ] [ to ] ) void sort ( ucs1char [ ] [ to ] ) void rsort ( ucs1char [ ] [ to ] ) void shuffle ( ucs1char [ ] [ to ] ) void revert ( ucs1char [ ] [ to ] ) } scope utf8str { utf8char [ ] spacestr ( uint ) utf8char [ ] spacestr ( uint , utf8char ) utf8char [ ] charstr ( uint ) char hexchar ( uint ) utf8char [ ] hexstr ( uint8 ) utf8char [ ] hexstr ( uint16 ) utf8char [ ] hexstr ( uint32 ) utf8char [ ] hexstr ( uint , uint digits ) utf8char [ ] hexstr ( ulong , uint digits ) utf8char [ ] binstr ( uint8 ) utf8char [ ] binstr ( uint16 ) utf8char [ ] binstr ( uint32 ) utf8char [ ] binstr ( uint , uint digits ) utf8char [ ] binstr ( ulong , uint digits ) utf8char [ ] binstr ( uint , utf8char [ ] ¢ o , utf8char [ ] ¢ l ) utf8char [ ] binstr ( ulong , utf8char [ ] ¢ o , utf8char [ ] ¢ l ) utf8char [ ] numstr ( int ) utf8char [ ] numstr ( uint ) utf8char [ ] numstr ( long ) utf8char [ ] numstr ( ulong ) utf8char [ ] toupper ( utf8char [ ] ¢ ) utf8char [ ] tolower ( utf8char [ ] ¢ ) utf8char [ ] escape ( utf8char [ ] ¢ , char leftquote ) utf8char [ ] unescape ( utf8char [ ] ¢ ) utf8char [ ] urlencode ( utf8char [ ] ¢ ) utf8char [ ] urldecode ( utf8char [ ] ¢ ) utf8char [ ] entab ( utf8char [ ] ¢ , uint tabwidth ) utf8char [ ] detab ( utf8char [ ] ¢ , uint tabwidth ) utf8char [ ] toupper ( utf8char [ to ] ) utf8char [ ] tolower ( utf8char [ to ] ) utf8char [ ] escape ( utf8char [ to ] , char leftquote ) utf8char [ ] unescape ( utf8char [ to ] ) utf8char [ ] urlencode ( utf8char [ to ] ) utf8char [ ] urldecode ( utf8char [ to ] ) utf8char [ ] entab ( utf8char [ to ] , uint tabwidth ) utf8char [ ] detab ( utf8char [ to ] , uint tabwidth ) ucs1str toucs1 ( utf8char [ ] ¢ ) ucs2str toucs2 ( utf8char [ ] ¢ ) utf8str toutf8 ( utf8char [ ] ¢ ) ucs1str toucs1 ( utf8char [ to ] ) ucs2str toucs2 ( utf8char [ to ] ) utf8str toutf8 ( utf8char [ to ] ) utf8char [ ] min ( utf8char [ ] , utf8char [ ] ) utf8char [ ] min ( utf8char [ ] , utf8char [ ] ¢ ) utf8char [ ] min ( utf8char [ ] ¢ , utf8char [ ] ) utf8char [ ] ¢ min ( utf8char [ ] ¢ , utf8char [ ] ¢ ) utf8char [ ] ¢ min ( utf8char [ ] [ ] ¢ ) utf8char [ ] ¢ min ( utf8char [ ] [ to ] ) utf8char [ ] max ( utf8char [ ] , utf8char [ ] ) utf8char [ ] max ( utf8char [ ] , utf8char [ ] ¢ ) utf8char [ ] max ( utf8char [ ] ¢ , utf8char [ ] ) utf8char [ ] ¢ max ( utf8char [ ] ¢ , utf8char [ ] ¢ ) utf8char [ ] ¢ max ( utf8char [ ] [ ] ¢ ) utf8char [ ] ¢ max ( utf8char [ ] [ to ] ) void flip ( utf8char [ ] [ to ] ) void rol ( utf8char [ ] [ to ] ) void ror ( utf8char [ ] [ to ] ) void sort ( utf8char [ ] [ to ] ) void rsort ( utf8char [ ] [ to ] ) void shuffle ( utf8char [ ] [ to ] ) void revert ( utf8char [ ] [ to ] ) } ucs1char [ ] spacestr ( uint ) ucs1char [ ] spacestr ( uint , ucs1char ) ucs1char [ ] charstr ( uint ) ucs1char hexchar ( uint ) ucs1char [ ] hexstr ( uint8 ) ucs1char [ ] hexstr ( uint16 ) ucs1char [ ] hexstr ( uint32 ) ucs1char [ ] hexstr ( uint , uint digits ) ucs1char [ ] hexstr ( ulong , uint digits ) ucs1char [ ] binstr ( uint8 ) ucs1char [ ] binstr ( uint16 ) ucs1char [ ] binstr ( uint32 ) ucs1char [ ] binstr ( uint , uint digits ) ucs1char [ ] binstr ( ulong , uint digits ) ucs1char [ ] binstr ( uint , ucs1char [ ] ¢ o , ucs1char [ ] ¢ l ) ucs1char [ ] binstr ( ulong , ucs1char [ ] ¢ o , ucs1char [ ] ¢ l ) ucs1char [ ] numstr ( int ) ucs1char [ ] numstr ( uint ) ucs1char [ ] numstr ( long ) ucs1char [ ] numstr ( ulong ) ucs1char [ ] toupper ( ucs1char [ ] ¢ ) ucs1char [ ] tolower ( ucs1char [ ] ¢ ) ucs1char [ ] escape ( ucs1char [ ] ¢ , ucs1char leftquote ) ucs1char [ ] unescape ( ucs1char [ ] ¢ ) ucs1char [ ] urlencode ( ucs1char [ ] ¢ ) ucs1char [ ] urldecode ( ucs1char [ ] ¢ ) ucs1char [ ] entab ( ucs1char [ ] ¢ , uint tabwidth ) ucs1char [ ] detab ( ucs1char [ ] ¢ , uint tabwidth ) ucs1char [ ] toupper ( ucs1char [ to ] ) ucs1char [ ] tolower ( ucs1char [ to ] ) ucs1char [ ] escape ( ucs1char [ to ] , ucs1char leftquote ) ucs1char [ ] unescape ( ucs1char [ to ] ) ucs1char [ ] urlencode ( ucs1char [ to ] ) ucs1char [ ] urldecode ( ucs1char [ to ] ) ucs1char [ ] entab ( ucs1char [ to ] , uint tabwidth ) ucs1char [ ] detab ( ucs1char [ to ] , uint tabwidth ) ucs1str toucs1 ( ucs1char [ ] ¢ ) ucs2str toucs2 ( ucs1char [ ] ¢ ) utf8str toutf8 ( ucs1char [ ] ¢ ) ucs1str toucs1 ( ucs1char [ to ] ) ucs2str toucs2 ( ucs1char [ to ] ) utf8str toutf8 ( ucs1char [ to ] ) ucs1char [ ] min ( ucs1char [ ] , ucs1char [ ] ) ucs1char [ ] min ( ucs1char [ ] , ucs1char [ ] ¢ ) ucs1char [ ] min ( ucs1char [ ] ¢ , ucs1char [ ] ) ucs1char [ ] ¢ min ( ucs1char [ ] ¢ , ucs1char [ ] ¢ ) ucs1char [ ] ¢ min ( ucs1char [ ] [ ] ¢ ) ucs1char [ ] ¢ min ( ucs1char [ ] [ to ] ) ucs1char [ ] max ( ucs1char [ ] , ucs1char [ ] ) ucs1char [ ] max ( ucs1char [ ] , ucs1char [ ] ¢ ) ucs1char [ ] max ( ucs1char [ ] ¢ , ucs1char [ ] ) ucs1char [ ] ¢ max ( ucs1char [ ] ¢ , ucs1char [ ] ¢ ) ucs1char [ ] ¢ max ( ucs1char [ ] [ ] ¢ ) ucs1char [ ] ¢ max ( ucs1char [ ] [ to ] ) void flip ( ucs1char [ ] [ to ] ) void rol ( ucs1char [ ] [ to ] ) void ror ( ucs1char [ ] [ to ] ) void sort ( ucs1char [ ] [ to ] ) void rsort ( ucs1char [ ] [ to ] ) void shuffle ( ucs1char [ ] [ to ] ) void revert ( ucs1char [ ] [ to ] ) enum { tm_utc = 0 , tm_localtime = 1 , tm_time = 2 , tm_date = 4 , tm_timezone = 8 , tm_sec = 16 , tm_msec = 32 } extern { float now ( ) ; str timestr ( float seconds , uint flags ) ; float timeval ( str ¢ , uint flags ) ; } enum uint8 { c_reset = 0 , c_speed = 1 , c_hwhsk = 2 , c_swhsk = 3 , c_flushin = 4 , c_availin = 4 , c_flushout = 5 , c_availout = 5 , c_clk_hsk = 6 , c_log2blocksize = 7 , c_totalblocks_lo = 8 , c_totalblocks_hi = 9 , c_reserved2 = 10 } ; enum uint8 OSErr = { ok = 0 , parameter_error = 1 , function_not_supported = 1 , io_error = 2 , device_not_responding = 3 , file_error , filesystem_invalid , device_not_found , directory_not_found , file_not_found , not_a_directory , is_a_directory , file_already_open_for_writing , file_already_open , file_exists , file_not_writable , end_of_file , disk_full , directory_corrupted , filesystem_corrupted } ; extern { OSErr errno ; OSErr error ( ) ; void clear_error ( ) ; void set_error ( OSErr ) ; bool yes_with_error ( OSErr ) ; void * null_with_error ( OSErr ) ; } enum uint8 NodeType = { t_endmarker = 0 , t_file = 1 , t_dir = 2 , t_ser = 3 , t_block = 4 , m_erased = 128 } ; scope NodeType { NodeType operator | ( NodeType , NodeType ) = opcode operator | ; NodeType operator & ( NodeType , NodeType ) = opcode operator & ; } type FD_Handlers = { uint ( FD ¢ , uint8 fu ) getctl ; void ( FD ¢ , uint8 fu , uint ) setctl ; uint ( FD ¢ ) avail_in ; uint ( FD ¢ ) avail_out ; char ( FD ¢ ) getc ; void ( FD ¢ , char ) putc ; bool ( FD ¢ , uint8 [ to ] ) read ; bool ( FD ¢ , uint8 [ to ] ) write ; bool ( FD ¢ , uint32 , uint8 [ ] ¢ ) read_block ; bool ( FD ¢ , uint32 , uint8 [ ] ¢ ) write_block ; void ( FD ¢ ) kill ; ulong ( FD ¢ ) getfpos ; bool ( FD ¢ , ulong fpos ) setfpos ; } extern { uint no_avail_in ( FD ¢ ) uint no_avail_out ( FD ¢ ) = no_avail_in ; char no_getc ( FD ¢ ) = no_avail_in ; void no_putc ( FD ¢ , char ) ulong no_getfpos ( FD ¢ ) bool no_setfpos ( FD ¢ , ulong ) bool no_read ( FD ¢ , uint8 [ to ] ) bool no_write ( FD ¢ , uint8 [ to ] ) = no_read ; bool no_read_block ( FD ¢ , uint32 , uint8 [ ] ¢ ) bool no_write_block ( FD ¢ , uint32 , uint8 [ ] ¢ ) = no_read_block ; } type FD = { FD_Handlers ¢ handlers ; NodeType nodetype ; str name ; } extern { uint avail_in ( ) ; uint avail_out ( ) ; const uint delimiters = 1 << 0 + 1 << 4 + 1 << 10 + 1 << 12 + 1 << 13 ; char getc ( ) ; void putc ( char c ) ; str gets ( uint delimiters ) ; void puts ( str ¢ ) ; void puts ( str ) ; void putnum ( uint ) ; void putnum ( int ) ; bool read ( uint8 [ to ] ) ; bool write ( uint8 [ to ] ) ; } scope FD { extern { void init ( FD ¢ , NodeType , str ¢ name , FD_Handlers ¢ ) ; void kill ( FD ¢ ) ; FD kill ( FD ) ; uint getctl ( FD ¢ , uint8 fu ) void setctl ( FD ¢ , uint8 fu , uint n ) uint avail_in ( FD ¢ ) ; uint avail_out ( FD ¢ ) ; char getc ( FD ¢ ) ; void putc ( FD ¢ , char c ) ; str gets ( FD ¢ , uint delimiters ) ; void puts ( FD ¢ , str ¢ ) ; void puts ( FD ¢ , str ) ; void putnum ( FD ¢ , uint ) ; void putnum ( FD ¢ , int ) ; bool read ( FD ¢ , uint8 [ to ] ) bool write ( FD ¢ , uint8 [ to ] ) bool read_block ( FD ¢ , uint32 blk , uint8 [ ] ¢ ) ; bool write_block ( FD ¢ , uint32 blk , uint8 [ ] ¢ ) ; ulong getfpos ( FD ¢ ) bool setfpos ( FD ¢ , ulong fpos ) bool is_dir ( FD ¢ ) ; bool is_file ( FD ¢ ) ; } } extern const { bool option_a5 = true ; uint8 bSIO_SELECT = 1 ; uint8 bIDE_SELECT = 2 ; uint8 mSIO_SELECT = 255 - 1 << bSIO_SELECT ; uint8 mIDE_SELECT = 255 - 2 << bSIO_SELECT ; } ; type FD = { } ; type BlockDevice = { } ; type IdeBlockDevice = { } ; type I2cBlockDevice = { } ; type SerialDevice = { } ; type Range = { } ; type File = { } ; type FD_Handlers = { } ; extern { uint8 k1_irpt_mask ; uint8 sysflags ; uint32 systemtime ; uint16 period ; uint32 timestamp ; uint16 tsmsec ; char * romdate ; char * romtime ; FD [ ] devs ; File [ ] fds ; FD stdin ; FD stdout ; SerialDevice sio1A ; SerialDevice sio1B ; IdeBlockDevice ide2A ; IdeBlockDevice ide2B ; I2cBlockDevice sio1rom ; I2cBlockDevice ide2rom ; OSErr errno ; void di ( ) void ei ( ) ; void ei_all ( ) ; void select ( uint8 ) uint8 in ( uint8 ) void out ( uint8 , uint8 ) void wait ( ) void memcpy ( void * z , void * q , uint cnt ) void memset ( void * z , uint c , uint cnt ) void memclr ( void * z , uint cnt ) void set_red_led ( ) ; void set_yellow_led ( ) ; void set_both_leds ( ) ; void clear_both_leds ( ) ; OSErr lock_eeprom ( ) ; OSErr unlock_eeprom ( ) ; void write_eeprom ( void * q , void * z , uint16 cnt ) ; void download_firmware ( ) ; void abort ( ) = opcode abort ; void panic ( uint8 blinkcode ) ; void assert1 ( bool ) ; void assert0 ( bool ) ; uint mem_get_free ( ) ; uint mem_get_free_total ( ) ; void download_firmware ( ) ; uint8 fd_function_not_supported ( ) ; void sio_init_channel ( SerialDevice ¢ , str ¢ name , uint8 devselbit , uint8 ch ) ; void ide_init_blockdevice ( BlockDevice ¢ ) ; void i2c_init_blockdevice ( BlockDevice ¢ ) ; } ; extern const { uint8 mSIO_SELECT ; uint8 k1_wr_data ; uint8 k1_rd_data ; char xon = 17 ; char xoff = 19 ; uint8 baud_9600 = 9600 / 2400 ; uint8 baud_57k6 = 57600 / 2400 ; } ; type SerialDevice = FD + { bool hw_handshake ; uint8 sw_handshake ; uint8 clk_handshake ; uint8 device ; uint8 channel ; uint8 baudrate ; uint8 sreg ; uint8 rxreg ; uint8 txreg ; uint8 ibuwi ; uint8 iburi ; uint8 obuwi ; uint8 oburi ; char [ ] ibu ; char [ ] obu ; } ; extern SerialDevice new ( uint8 ch , str ¢ name ) ; extern SerialDevice sio1A ; extern SerialDevice sio1B ; extern uint8 imr_value ; extern uint8 opcr_value ; scope SerialDevice { extern const uint8 obusz = 64 , ibusz = 64 , obumask = obusz - 1 , ibumask = ibusz - 1 , mSWHSK_ENABLED = 1 , mXOFF_RECEIVED = 2 , mXOFF_SENT = 4 , bSWHSK_ENABLED = 0 , bXOFF_RECEIVED = 1 , bXOFF_SENT = 2 ; extern { void reset ( SerialDevice ¢ , bool tx , bool rx ) ; void set_baudrate ( SerialDevice ¢ , uint8 baudrate ) ; void set_sw_handshake ( SerialDevice ¢ , bool f ) ; void set_hw_handshake ( SerialDevice ¢ , bool f ) ; void set_clock_handshake ( SerialDevice ¢ , uint8 f ) ; SerialDevice kill ( SerialDevice ) = FD FD . kill ( FD ) ; void setctl ( SerialDevice ¢ , uint8 fu , uint n ) ; uint getctl ( SerialDevice ¢ , uint8 fu ) ; uint avail_in ( SerialDevice ¢ ) ; uint avail_out ( SerialDevice ¢ ) ; char getc ( SerialDevice ¢ ) ; void putc ( SerialDevice ¢ , char c ) ; void puts ( SerialDevice ¢ , str ¢ ) ; void puts ( SerialDevice ¢ , str ) ; bool read ( SerialDevice ¢ , uint8 [ ] ¢ bu , uint a , uint e ) ; bool write ( SerialDevice ¢ , uint8 [ ] ¢ bu , uint a , uint e ) ; bool read ( SerialDevice ¢ , uint8 [ to ] ) = bool read ( SerialDevice ¢ , uint8 [ ] ¢ , uint , uint ) ; bool write ( SerialDevice ¢ , uint8 [ to ] ) = bool write ( SerialDevice ¢ , uint8 [ ] ¢ , uint , uint ) ; } } extern const uint8 MR0A = 0 , MR1A = 0 , MR2A = 0 , SRA = 1 , UNUSED1 , RXA = 3 , IPCR = 4 , ISR = 5 , CUR = 6 , CLR = 7 , MR0B = 8 , MR1B = 8 , MR2B = 8 , SRB = 9 , UNUSED2 , RXB = 11 , GPR = 12 , IPR = 13 , STCR = 14 , SPCR = 15 , MR0A = 0 , CSRA = 1 , CRA = 2 , TXA = 3 , ACR = 4 , IMR = 5 , CTPU = 6 , CTPL = 7 , MR0B = 8 , CSRB = 9 , CRB = 10 , TXB = 11 , GPR = 12 , OPCR = 13 , SOPR = 14 , ROPR = 15 , mSR_RX_ready = 1 , mSR_RX_full = 2 , mSR_TX_ready = 4 , mSR_TX_empty = 8 , mSR_RX_overrun = 16 , mSR_RX_parity = 32 , mSR_RX_framing = 64 , mSR_RX_break = 128 , bSR_RX_ready = 0 , bSR_TX_ready = 2 , bSR_TX_empty = 3 , mIMR_TXA_ready = 1 , mIMR_RXA_ready = 2 , mIMR_RXA_break = 4 , mIMR_CT_ready = 8 , mIMR_TXB_ready = 16 , mIMR_RXB_ready = 32 , mIMR_RXB_break = 64 , mIMR_IP_changed = 128 , mOPR_RTSA = 1 , mOPR_RTSB = 2 , mOPR_CLKA = 4 , mOPR_CLKB = 8 , mOPR_CTLA = 16 , mOPR_CTLB = 32 , mOPR_INVA = 64 , mOPR_INVB = 128 , OPCR_value = 0 << 0 + 0 << 2 + 0 << 4 , SOPR_value = mOPR_RTSA + mOPR_RTSB + mOPR_CLKA + mOPR_CLKB + mOPR_CTLA + mOPR_CTLB + mOPR_INVA + mOPR_INVB , ROPR_value = 0 , IMR_value = ! mIMR_TXA_ready + ! mIMR_RXA_ready + ! mIMR_RXA_break + mIMR_CT_ready + ! mIMR_TXB_ready + ! mIMR_RXB_ready + ! mIMR_RXB_break + ! mIMR_IP_changed , ACR_value = 0 + 7 << 4 + 0 << 7 , MR0_value = 0 << 0 + 0 << 1 + 0 << 2 + 0 << 3 + 2 << 4 + 0 << 6 + 1 << 7 , MR1_value = 3 << 0 + 0 << 2 + 2 << 3 + 0 << 5 + 1 << 6 + 0 << 7 , MR2_value = 7 << 0 + 0 << 4 + 0 << 5 + 0 << 6 ; uint16 [ 16 ] uart_values_for_baudrate = ( uint16 [ ] ) { ( MR0_value + 0 ) * 256 + ( 6 ) * 17 , ( MR0_value + 0 ) * 256 + ( 8 ) * 17 , ( MR0_value + 0 ) * 256 + ( 9 ) * 17 , ( MR0_value + 0 ) * 256 + ( 11 ) * 17 , ( MR0_value + 4 ) * 256 + ( 3 ) * 17 , ( MR0_value + 0 ) * 256 + ( 12 ) * 17 , ( MR0_value + 0 ) * 256 + ( 9 ) * 17 , ( MR0_value + 0 ) * 256 + ( 9 ) * 17 , ( MR0_value + 0 ) * 256 + ( 0 ) * 17 , ( MR0_value + 1 ) * 256 + ( 5 ) * 17 , ( MR0_value + 1 ) * 256 + ( 6 ) * 17 , ( MR0_value + 1 ) * 256 + ( 8 ) * 17 , ( MR0_value + 1 ) * 256 + ( 9 ) * 17 , ( MR0_value + 1 ) * 256 + ( 11 ) * 17 , ( MR0_value + 4 ) * 256 + ( 6 ) * 17 , ( MR0_value + 1 ) * 256 + ( 12 ) * 17 } ; uint8 imr_value = IMR_value ; uint8 opcr_value = OPCR_value ; FD_Handlers new_sio_handlers ( ) = asm { # assert FD_Handlers . getctl == 0 # assert FD_Handlers . setctl == 2 # assert FD_Handlers . avail_in == 4 # assert FD_Handlers . avail_out == 6 # assert FD_Handlers . getc == 8 # assert FD_Handlers . putc == 10 # assert FD_Handlers . read == 12 # assert FD_Handlers . write == 14 # assert FD_Handlers . read_block == 16 # assert FD_Handlers . write_block == 18 # assert FD_Handlers . kill == 20 # assert FD_Handlers . getfpos == 22 # assert FD_Handlers . setfpos == 24 p_enter dw ISTR dw 26 dw SerialDevice . getctl__12SerialDeviceC_5uint8_6uint16 dw SerialDevice . setctl__12SerialDeviceC_5uint8_6uint16_ dw SerialDevice . avail_in__12SerialDeviceC_6uint16 dw SerialDevice . avail_out__12SerialDeviceC_6uint16 dw SerialDevice . getc__12SerialDeviceC_8ucs1char dw SerialDevice . putc__12SerialDeviceC_8ucs1char_ dw SerialDevice . read__12SerialDeviceC_5uint8AEC_6uint16_6uint16_4bool dw SerialDevice . write__12SerialDeviceC_5uint8AEC_6uint16_6uint16_4bool dw no_read_block__2FDC_6uint32_5uint8AEC_4bool dw no_read_block__2FDC_6uint32_5uint8AEC_4bool ; write_block dw FD . kill__2FDC_ dw no_getfpos__2FDC_6uint32 dw no_setfpos__2FDC_6uint32_4bool dw RETURN } FD_Handlers sio_handlers = new_sio_handlers ( ) ; SerialDevice new ( uint8 ch , str ¢ name ) { SerialDevice this = alloc SerialDevice ( ) ; FD . init ( this , t_ser , name , sio_handlers ) ; this . device := mSIO_SELECT ; this . baudrate := 9600 / 2400 ; this . channel := ch ; uint ch3 = ch << 3 ; this . sreg := ch3 + SRA + k1_rd_data ; this . rxreg := ch3 + RXA + k1_rd_data ; this . txreg := ch3 + TXA + k1_wr_data ; this . ibu = alloc char [ SerialDevice . ibusz ] ( ) ; this . obu = alloc char [ SerialDevice . obusz ] ( ) ; return this ; } scope SerialDevice { void set_baudrate ( SerialDevice ¢ this , uint8 baudrate ) { uint8 chx8 = this . channel << 3 ; uint8 i = msbit ( baudrate ) ; bool t = i && baudrate >> ( i - 1 ) & 1 ; uint v = uart_values_for_baudrate [ t << 3 + i ] ; this . baudrate = t ? 3 << ( i - 1 ) : i < 6 ? 1 << i : baud_9600 ; uint8 csr_mask = 0 ; if ( this . clk_handshake ) { if ( this . clk_handshake & 1 ) csr_mask |= 15 ; if ( this . clk_handshake & 2 ) csr_mask |= 240 ; } out ( chx8 + CRA , 176 ) ; out ( chx8 + MR0A , v . hi ) ; out ( chx8 + CSRA , v . lo | csr_mask ) ; } void set_sw_handshake ( SerialDevice ¢ this , bool f ) { if ( this . sw_handshake & 1 != f ) { this . sw_handshake = f ; } } void set_hw_handshake ( SerialDevice ¢ this , bool f ) { uint chx8 = this . channel << 3 ; if ( this . hw_handshake != f ) { this . hw_handshake = f ; out ( chx8 + CRA , 16 ) ; out ( chx8 + MR1A , MR1_value + f << 7 ) ; out ( chx8 + MR2A , MR2_value + f << 4 ) ; } } void set_clock_handshake ( SerialDevice ¢ this , uint8 flags ) { uint8 ch = this . channel ; uint8 chx2 = ch << 1 ; if ( this . clk_handshake != flags ) { this . clk_handshake = flags ; if ( flags & 3 ) opcr_value |= 3 << chx2 ; else opcr_value &= ~ ( 3 << chx2 ) ; out ( OPCR , opcr_value ) ; out ( SOPR , ( 1 << 0 + 1 << 2 + 1 << 6 ) << ch ) ; if ( flags & 4 ) out ( ROPR , ( 65 << ch ) ) ; this . set_baudrate ( this . baudrate ) ; } } void reset ( SerialDevice ¢ this , bool tx , bool rx ) { uint8 CR = CRA + this . channel << 3 ; if ( rx ) { out ( CR , 32 ) ; this . sw_handshake &= ~ mXOFF_SENT ; this . ibuwi = this . iburi ; } if ( tx ) { out ( CR , 48 ) ; this . sw_handshake &= ~ mXOFF_RECEIVED this . oburi = this . obuwi ; } out ( CR , 64 ) ; out ( CR , 1 << 0 + 1 << 2 ) ; } void setctl ( SerialDevice ¢ channel , uint8 fu , uint value ) { if ( fu == c_flushout ) { uint8 n = 50 ; do { while channel . oburi != channel . obuwi && n -- ; wait ( ) ; } } select ( mSIO_SELECT ) ; switch ( fu ) { case c_clk_hsk : channel . set_clock_handshake ( value ) ; break ; case c_reset : channel . reset ( yes , yes ) ; break ; case c_speed : channel . set_baudrate ( value / 24 ) ; break ; case c_hwhsk : channel . set_hw_handshake ( value != 0 ) ; break ; case c_swhsk : channel . set_sw_handshake ( value != 0 ) ; break ; case c_flushin : channel . reset ( no , yes ) ; break ; case c_flushout : channel . reset ( yes , no ) ; break ; } ei ( ) ; } uint getctl ( SerialDevice ¢ channel , uint8 fu ) { switch ( fu ) { case c_speed : return channel . baudrate * 24 ; case c_hwhsk : return channel . hw_handshake ; case c_swhsk : return channel . sw_handshake ; case c_clk_hsk : return channel . clk_handshake ; case c_availin : return channel . avail_in ( ) ; case c_availout : return channel . avail_out ( ) ; default : return 0 ; } } uint avail_in ( SerialDevice ¢ channel ) = asm { # assert SerialDevice . iburi == SerialDevice . ibuwi + 1 # assert SerialDevice . oburi == SerialDevice . obuwi + 1 deref_handle_de ; de -> channel data ld hl , SerialDevice . ibuwi add hl , de ; hl -> ibuwi ld a , ( hl ) ; a = ibuwi inc hl ; hl -> iburi sub a , ( hl ) ; a = ibuwi - iburi jp ld_de_a_next } uint avail_out ( SerialDevice ¢ channel ) = asm { deref_handle_de ; de -> channel data ld a , SerialDevice . obusz ; a = const obusz ld hl , SerialDevice . obuwi add hl , de ; hl -> obuwi sub a , ( hl ) ; a = obusz - obuwi inc hl ; hl -> oburi add a , ( hl ) ; a = obusz - obuwi + iburi = obusz - ( obuwi - oburi ) jp ld_de_a_next } char getc ( SerialDevice ¢ channel ) { do { until channel . avail_in ( ) ; wait ( ) ; } char c = channel . ibu [ channel . iburi & ibumask ] ; channel . iburi ++ ; return c ; } void putc ( SerialDevice ¢ channel , char c ) { do { until channel . avail_out ( ) ; wait ( ) ; } channel . obu [ channel . obuwi & obumask ] = c ; channel . obuwi ++ ; } void puts ( SerialDevice ¢ fd , str ¢ s ) { ( void ) fd . write ( s [ to ] ) ; } void puts ( SerialDevice ¢ fd , str s ) { ( void ) fd . write ( s [ to ] ) ; } bool read ( SerialDevice ¢ channel , uint8 [ ] ¢ bu , uint a , uint e ) { do { uint8 i = channel . iburi & ibumask ; uint8 m = ibusz - i ; uint8 n = min ( e - a , channel . avail_in ( ) ) ; if ( m < n ) { memcpy ( & bu [ a ] , & channel . ibu [ i ] , m ) ; memcpy ( & bu [ a + m ] , & channel . ibu [ 0 ] , n - m ) ; } else memcpy ( & bu [ a ] , & channel . ibu [ i ] , n ) ; channel . iburi += n ; a += n ; while a < e ; wait ( ) ; } return no ; } bool write ( SerialDevice ¢ channel , uint8 [ ] ¢ bu , uint a , uint e ) { do { uint8 i = channel . obuwi & obumask ; uint8 m = obusz - i ; uint8 n = min ( e - a , channel . avail_out ( ) ) ; if ( m < n ) { memcpy ( & channel . obu [ i ] , & bu [ a ] , m ) ; memcpy ( & channel . obu [ 0 ] , & bu [ a + m ] , n - m ) ; } else memcpy ( & channel . obu [ i ] , & bu [ a ] , n ) ; channel . obuwi += n ; a += n ; while a < e ; wait ( ) ; } return no ; } } ""