words[]: const bool yes = 1 , no = 0 ; const bool true = 1 , false = 0 ; 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 set_error ( OSErr ) ; void clear_error ( ) ; } extern { bool is_letter ( char ) ; bool is_bin_digit ( char ) ; bool is_dec_digit ( char ) ; bool is_hex_digit ( char ) ; uint8 digit_value ( char ) ; uint8 msbit ( uint16 ) ; uint8 msbit ( uint32 ) ; uint8 count1bits ( uint16 ) ; uint8 count1bits ( uint32 ) ; bool is1bit ( uint16 ) ; 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 ( ) ; uint8 random ( ) ; bool random ( ) ; uint16 random ( uint16 N ) ; uint32 random ( uint32 ) ; uint32 mul_wwl ( uint16 , uint16 ) ; void revert ( int8 [ to ] ) = opcode revert ; void rol ( int8 [ to ] ) = opcode rol ; void ror ( int8 [ to ] ) = opcode ror ; void sort ( int8 [ to ] ) ; void rsort ( int8 [ to ] ) ; 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 ( ucs1str ¢ ) ; void revert ( uint8 [ to ] ) = opcode revert ; void rol ( uint8 [ to ] ) = opcode rol ; void ror ( uint8 [ to ] ) = opcode ror ; void sort ( uint8 [ to ] ) ; void rsort ( uint8 [ to ] ) ; 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 ( ucs1str ¢ ) ; void revert ( int16 [ to ] ) = opcode revert ; void rol ( int16 [ to ] ) = opcode rol ; void ror ( int16 [ to ] ) = opcode ror ; void sort ( int16 [ to ] ) ; void rsort ( int16 [ to ] ) ; 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 ( ucs1str ¢ ) ; void revert ( uint16 [ to ] ) = opcode revert ; void rol ( uint16 [ to ] ) = opcode rol ; void ror ( uint16 [ to ] ) = opcode ror ; void sort ( uint16 [ to ] ) ; void rsort ( uint16 [ to ] ) ; 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 ( ucs1str ¢ ) ; void revert ( int32 [ to ] ) = opcode revert ; void rol ( int32 [ to ] ) = opcode rol ; void ror ( int32 [ to ] ) = opcode ror ; void sort ( int32 [ to ] ) ; void rsort ( int32 [ to ] ) ; 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 ( ucs1str ¢ ) ; void revert ( uint32 [ to ] ) = opcode revert ; void rol ( uint32 [ to ] ) = opcode rol ; void ror ( uint32 [ to ] ) = opcode ror ; void sort ( uint32 [ to ] ) ; void rsort ( uint32 [ to ] ) ; 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 ( ucs1str ¢ ) ; void revert ( ucs1char [ to ] ) = opcode revert ; void rol ( ucs1char [ to ] ) = opcode rol ; void ror ( ucs1char [ to ] ) = opcode ror ; void sort ( ucs1char [ to ] ) ; void rsort ( ucs1char [ to ] ) ; 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 ( ucs1str ¢ ) ; } ; 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 ] ) extern { uint8 sysflags ; uint32 systemtime ; char * romdate ; char * romtime ; void di ( ) void ei ( ) ; uint8 in ( uint16 ) ; void out ( uint16 , uint8 ) ; void wait ( ) void abort ( ) = opcode abort ; void panic ( uint8 errorcode ) ; void assert1 ( bool ) ; void assert0 ( bool ) ; void memcpy ( void * z , void * q , uint cnt ) void memset ( void * z , uint c , uint cnt ) void memclr ( void * z , uint cnt ) char getc ( ) ; char waitc ( ) ; bool getc_avail ( ) ; void print ( char ) ; void print ( int ) ; void print ( uint ) ; void print ( char * ) ; void print ( str ¢ ) ; void print ( str ) ; void locate ( uint xy ) ; void setattr ( uint8 ) ; void draw ( uint x1 , uint y1 , uint x2 , uint y2 ) ; void draw ( uint xy1 , uint xy2 ) ; void draw_digit ( uint xy , uint digit ) ; void plot ( uint x , uint y ) ; void clear_background ( ) ; void clear_board ( uint xy ) ; void set_attr_c ( uint xy , uint wh , uint attr ) ; void set_attr_p ( uint xy , uint wh , uint attr ) ; void board_reset_attr ( uint xy ) ; uint8 * get_cellset ( uint idx ) ; uint8 * get_rowset ( uint row ) ; uint8 * get_colset ( uint col ) ; uint8 * get_blkset ( uint row , uint col ) ; uint16 random ( uint16 ) ; uint16 random ( ) ; uint8 random ( ) ; bool random ( ) ; uint8 count1bits ( uint16 ) ; bool is1bit ( uint16 ) ; const uint8 * cboards ; const uint8 * level1_cdata ; const uint8 * level2_cdata ; const uint8 * level3_cdata ; const uint8 * level4_cdata ; const uint num_boards ; uint mouse_xy ; uint8 mouse_x ; uint8 mouse_y ; uint8 mouse_buttons ; const uint GSDATA_size ; const uint SLOW_CDATA_size ; const uint SLOW_DATA_size ; const uint SLOW_CODE_size ; const uint VCODE_size ; const uint VMCORE_size ; const uint CODE_size ; const uint CONST_size ; const uint DATA_size ; const uint STACKS_size ; const uint HEAP_size ; const uint GSINIT_size ; const uint ZX7_size ; const uint tape_size ; const uint uncompressed_data_size ; uint16 heap ; uint16 heap_start ; uint16 heap_end ; uint16 handles_start ; uint16 free_handle ; const uint16 * rndseed16 ; } extern void SHOW_MOUSE ( ) ; void show_mouse ( ) = void SHOW_MOUSE ( ) ; extern void HIDE_MOUSE ( ) ; void hide_mouse ( ) = void HIDE_MOUSE ( ) ; const char c_eot = 0 ; const char c_home = 1 ; const char c_cls = 2 ; const char c_locate = 3 ; const char c_setcol = 4 ; const char c_setrow = 5 ; const char c_setattr = 6 ; const char c_setpen = 7 ; const char c_setpaper = 8 ; const char c_clrcols = 9 ; const char c_tab = 10 ; const char c_newline = 13 ; const char c_inverse = 14 ; const char c_narrow = 16 ; const char c_bold = 18 ; const char c_flash = 22 ; const char c_bright = 24 ; const char c_clreol = 26 ; ; print ( c_home ) ; print ( 13 ) ; print ( "\rtape size = " ) ; print ( tape_size ) ; print ( "\rslow cdata size = " ) ; print ( uncompressed_data_size ) ; print ( "\rslow data size = " ) ; print ( SLOW_DATA_size ) ; print ( "\rslow code size = " ) ; print ( SLOW_CODE_size ) ; print ( "\rVcode size = " ) ; print ( VCODE_size ) ; print ( "\rVM core size = " ) ; print ( VMCORE_size ) ; print ( "\rcode size = " ) ; print ( CODE_size ) ; print ( "\rconst size = " ) ; print ( CONST_size ) ; print ( "\rdata size = " ) ; print ( GSDATA_size + DATA_size ) ; print ( "\rstacks size = " ) ; print ( STACKS_size ) ; print ( "\rheap size = " ) ; print ( HEAP_size ) ; print ( "\rinit code size = " ) ; print ( GSINIT_size ) ; print ( "\rZX7 size = " ) ; print ( ZX7_size ) ; assert ( count1bits ( 61680 ) == 8 ) ; assert ( count1bits ( 85 ) == 4 ) ; assert ( count1bits ( 511 ) == 9 ) ; assert ( count1bits ( 0 ) == 0 ) ; assert ( msbit ( 2 - 1 ) + 1 == 1 ) ; assert ( msbit ( 3 - 1 ) + 1 == 2 ) ; assert ( msbit ( 4 - 1 ) + 1 == 2 ) ; assert ( msbit ( 5 - 1 ) + 1 == 3 ) ; assert ( msbit ( 6 - 1 ) + 1 == 3 ) ; assert ( msbit ( 7 - 1 ) + 1 == 3 ) ; assert ( msbit ( 8 - 1 ) + 1 == 3 ) ; extern char [ ] [ ] boards ; const uint compressed_board_size = 81 ; type MenuItem = { uint8 x , w ; str text ; void ( uint ) fu ; } MenuItem [ ] menu_items ; const uint8 attr_mbar = 7 + 0 * 8 ; const uint8 attr_mbar_hover = 7 + 0 * 8 + 64 ; const uint8 attr_mbar_click = 7 + 3 * 8 + 64 ; type Button = { uint xy , wh ; str text ; void ( uint ) fu ; bool on ; bool disabled ; uint8 cookie ; } Button [ ] buttons ; Button ¢ button_pencil ; Button ¢ button_pen ; const uint8 attr_button = 0 + 7 * 8 + 64 ; const uint8 attr_button_disabled = 7 + 1 * 8 + 64 ; const uint8 attr_button_hover = 0 + 6 * 8 + 64 ; const uint8 attr_button_click = 0 + 4 * 8 + 64 ; const uint8 attr_button_on = 0 + 6 * 8 + 64 ; extern const char charcode_left_arrow ; extern const char charcode_right_arrow ; type Cell = uint16 ; Cell [ ] board ; const uint m_number = 15 ; const uint m_presetcell = 16 ; const uint m_hilitedcell = 32 ; const uint m_wrongcell = 64 ; const uint m_pencil = 65408 ; const uint8 attr_cell_error = 0 + 2 * 8 + 64 ; const uint8 attr_cell_hilite = 0 + 6 * 8 + 64 ; const uint board_xy = 780 ; const uint board_wh = 4626 ; const uint numpad_xy = 770 ; const uint numpad_wh = 4616 ; uint8 level ; bool game_on ; uint8 current_number ; void select_pencil ( uint ) ; void select_pen ( uint ) ; void select_number ( uint ) ; MenuItem new ( uint x , uint w , str text , void ( uint ) fu ) { MenuItem this = alloc MenuItem ( ) ; this . x = x ; this . w = w ; this . text = text ; this . fu = fu ; setattr ( attr_mbar ) ; locate ( x ) ; print ( c_clrcols ) ; print ( ( char ) w ) ; print ( text ) ; return this ; } scope Button { void draw ( Button ¢ this ) { this . on = no ; this . disabled = yes ; uint xy = this . xy ; uint wh = this . wh ; if ( wh . hi == 1 ) { xy . lo <<= 3 ; locate ( xy ) ; setattr ( attr_button_disabled ) ; print ( this . text ) ; xy . hi <<= 3 ; } else { set_attr_c ( xy , wh , attr_button_disabled ) ; draw_digit ( xy , this . text [ 0 ] ) ; xy <<= 3 ; } wh <<= 3 ; uint w = wh . lo ; uint h = wh . hi << 8 ; draw ( xy - 256 , xy + w - 257 ) ; draw ( xy + h , xy + wh - 1 ) ; draw ( xy - 1 , xy + h - 257 ) ; draw ( xy + w , xy + wh - 256 ) ; } void disable ( Button ¢ this ) { this . disabled = yes ; set_attr_c ( this . xy , this . wh , attr_button_disabled ) ; } void enable ( Button ¢ this ) { this . disabled = no ; set_attr_c ( this . xy , this . wh , this . on ? attr_button_on : attr_button ) ; } void enable ( Button ¢ this , bool f ) { if ( f ) this . enable ( ) ; else this . disable ( ) ; } void select ( Button ¢ this , bool f ) { this . on = f ; this . enable ( ) ; } } Button new ( uint xy , uint wh , str text , void ( uint ) fu , uint cookie ) { Button this = alloc Button ( ) ; this . xy = xy ; this . wh = wh ; this . text = text ; this . fu = fu ; this . cookie = cookie ; return this ; } bool isinbox ( uint pos , uint xy , uint wh ) { return pos . lo >= xy . lo && pos . hi >= xy . hi && pos . lo < xy . lo + wh . lo && pos . hi < xy . hi + wh . hi ; } void track_mouse_while_button_down ( uint xy , uint wh ) { wait ( ) ; do { wait ( ) ; while mouse_buttons && isinbox ( mouse_xy , xy , wh ) ; } } void track_mouse_while_button_up ( uint xy , uint wh ) { do { wait ( ) ; while ! mouse_buttons && isinbox ( mouse_xy , xy , wh ) ; if ( getc_avail ( ) ) return ; } } void set_cell_attr ( uint idx , uint attr ) { uint xy = board_xy + ( idx / 9 ) << 9 + ( idx % 9 ) << 1 ; set_attr_c ( xy , 514 , attr ) ; } void draw_cross ( ) { draw ( board_xy << 3 + 48 , board_xy << 3 + 36656 ) ; draw ( board_xy << 3 + 96 , board_xy << 3 + 36704 ) ; draw ( board_xy << 3 + 12032 , board_xy << 3 + 12175 ) ; draw ( board_xy << 3 + 24320 , board_xy << 3 + 24463 ) ; } void check_board ( ) { board_reset_attr ( board_xy ) ; if ( current_number ) { uint i = 81 ; do { while i -- ; if ( board [ i ] & 15 == current_number ) set_cell_attr ( i , attr_cell_hilite ) ; } } uint sli = 27 ; do { while sli -- ; uint8 * set = get_cellset ( sli ) ; uint mask = 0 ; uint emask = 0 ; uint8 * p = set + 9 ; do { while -- p >= set ; uint c = board [ * p ] ; if ( c & 15 == 0 ) next ; uint m = 1 << ( c & 15 ) ; if ( mask & m ) emask |= m ; else mask |= m ; } if ( ! emask ) next ; p = set + 9 ; do { while -- p >= set ; uint c = board [ * p ] ; if ( c & 15 == 0 ) next ; uint m = 1 << ( c & 15 ) ; if ( emask & m ) set_cell_attr ( * p , attr_cell_error ) ; } } } void set_cell ( uint idx , uint value ) { board [ idx ] = value ; uint x = idx % 9 ; uint y = idx / 9 ; hide_mouse ( ) ; draw_digit ( board_xy + x << 1 + y << 9 , value ) ; if ( x == 3 ) draw ( board_xy << 3 + 48 , board_xy << 3 + 36656 ) ; else if ( x == 6 ) draw ( board_xy << 3 + 96 , board_xy << 3 + 36704 ) ; if ( y == 2 ) draw ( board_xy << 3 + 12032 , board_xy << 3 + 12175 ) ; else if ( y == 5 ) draw ( board_xy << 3 + 24320 , board_xy << 3 + 24463 ) ; show_mouse ( ) ; } void clear_pencil_in_set ( uint mask , uint8 * set ) { uint i = 9 ; do { while i -- ; uint j = * set ++ ; if ( board [ j ] & mask ) set_cell ( j , board [ j ] ^ mask ) ; } } void track_mouse ( ) { show_mouse ( ) ; do { while mouse_buttons ; wait ( ) ; } * rndseed16 += mouse_xy ; if ( mouse_y < 8 ) { uint8 i = menu_items . count ( ) ; do { while i -- ; MenuItem ¢ m = menu_items [ i ] ; uint xy = m . x , wh = m . w + 2048 ; if ( isinbox ( mouse_xy , xy , wh ) ) { set_attr_p ( xy , wh , attr_mbar_hover ) ; track_mouse_while_button_up ( xy , wh ) ; if ( mouse_buttons ) { set_attr_p ( xy , wh , attr_mbar_click ) ; track_mouse_while_button_down ( xy , wh ) ; if ( ! mouse_buttons ) m . fu ( 0 ) ; } set_attr_p ( xy , wh , attr_mbar ) ; exit ; } } } elif ( isinbox ( mouse_xy , numpad_xy << 3 , numpad_wh << 3 ) ) { uint8 i = buttons . count ( ) ; do { while i -- ; Button ¢ b = buttons [ i ] ; uint xy = b . xy << 3 , wh = b . wh << 3 ; if ( isinbox ( mouse_xy , xy , wh ) ) { if ( b . disabled ) exit ; set_attr_p ( xy , wh , attr_button_hover ) ; track_mouse_while_button_up ( xy , wh ) ; if ( mouse_buttons ) { set_attr_p ( xy , wh , attr_button_click ) ; track_mouse_while_button_down ( xy , wh ) ; if ( ! mouse_buttons ) b . fu ( b . cookie ) ; } set_attr_p ( xy , wh , b . on ? attr_button_on : attr_button ) ; exit ; } } } elif ( game_on && current_number && isinbox ( mouse_xy , board_xy << 3 , board_wh << 3 ) ) { track_mouse_while_button_up ( board_xy << 3 , 4626 << 3 ) ; if ( mouse_buttons ) { uint x = ( mouse_x >> 3 - board_xy . lo ) >> 1 ; uint y = ( mouse_y >> 3 - board_xy . hi ) >> 1 ; uint idx = y * 9 + x ; uint mask = 64 << current_number ; if ( button_pen . on ) { if ( board [ idx ] & m_presetcell ) return ; if ( board [ idx ] == current_number ) { set_cell ( idx , 0 ) ; } else { set_cell ( idx , current_number ) ; clear_pencil_in_set ( mask , get_colset ( x ) ) ; clear_pencil_in_set ( mask , get_rowset ( y ) ) ; clear_pencil_in_set ( mask , get_blkset ( y / 3 , x / 3 ) ) ; } check_board ( ) ; } else { if ( board [ idx ] & m_number ) return ; set_cell ( idx , board [ idx ] ^ mask ) ; } } } } void clear_mbar ( ) { draw ( 0 , 8 , 255 , 8 ) ; setattr ( 7 + 0 * 8 + 64 ) ; print ( c_home ) ; print ( c_clreol ) ; locate ( 256 - ( 4 * 5 + 1 + 4 * 2 ) - 2 ) ; print ( "00:00" ) ; } void draw_board ( ) { uint xy = board_xy ; uint8 i = 0 ; do { do { uint8 c = board [ i ++ ] ; if ( c & 15 ) draw_digit ( xy , c ) ; xy . lo += 2 ; while i % 9 ; } xy . lo -= 18 ; xy . hi += 2 ; while i < 81 ; } draw_cross ( ) ; } void select_joystick ( ) { } void select_pen ( uint ) { button_pen . on = yes ; button_pencil . on = no ; set_attr_c ( button_pen . xy , button_pen . wh , attr_button_on ) ; set_attr_c ( button_pencil . xy , button_pencil . wh , attr_button ) ; } void select_pencil ( uint ) { button_pencil . on = yes ; button_pen . on = no ; set_attr_c ( button_pencil . xy , button_pencil . wh , attr_button_on ) ; set_attr_c ( button_pen . xy , button_pen . wh , attr_button ) ; } void select_number ( uint z ) { Button ¢ b = buttons [ z - 1 ] ; bool f = ! b . on ; if ( current_number ) { Button ¢ b = buttons [ current_number - 1 ] ; b . on = no ; current_number = 0 ; set_attr_c ( b . xy , 514 , attr_button ) ; } if ( f ) { b . on = f ; current_number = z ; set_attr_c ( b . xy , 514 , attr_button_on ) ; } check_board ( ) ; if ( ! button_pen . on && ! button_pencil . on ) select_pen ( 0 ) ; } void undo ( uint ) { } void redo ( uint ) { } void set_level ( uint n ) { Button ¢ b = buttons [ 14 + level ] ; b . on = no ; set_attr_c ( b . xy , b . wh , attr_button ) ; level = n ; b = buttons [ 14 + level ] ; b . on = yes ; set_attr_c ( b . xy , b . wh , attr_button_on ) ; } void start_game ( uint ) { game_on = yes ; } extern const int8 * sintab ; void pause ( uint ) { uint8 x = 0 ; do { plot ( x , 96 - * ( sintab + x ) ) ; while ++ x ; } } void abort ( uint ) { game_on = no ; } void save ( uint ) { } void load ( uint ) { } void mogrify_board ( ) { char [ ] xch = " 123456789??????" ; uint i = 9 ; do { swap ( xch [ i ] , xch [ 1 + random ( i ) ] ) ; while -- i ; } i = 81 ; do { while i -- ; uint & c = board [ i ] ; if ( c & 15 ) c = ( c & 65520 ) | ( xch [ c & 15 ] & 15 ) ; } } enum { NOSYM_IMAGE = 0 , NOSYM_RANDOM = 1 , VSYM_HFIXED = 2 , VSYM_HRANDOM = 3 , HSYM_VFIXED = 4 , HSYM_VRANDOM = 5 , XSYM = 6 , XSYM_BLKSYM = 7 } ; uint8 [ ] get_related ( uint idx ) { assert ( idx < 81 ) ; uint8 [ ] list = alloc uint8 [ ] ( 20 ) ; uint8 col = idx % 9 ; uint8 row = idx / 9 ; uint8 * p = & list [ 0 ] ; uint8 i = 8 ; do { while i -- ; * p ++ = ( i == row ? 8 : i ) * 9 + col ; * p ++ = row * 9 + ( i == col ? 8 : i ) ; } int8 row0 = row - row % 3 ; int8 col0 = col - col % 3 ; int8 r = row0 + 3 ; do { while -- r >= row0 ; if ( r == row ) next ; int8 c = col0 + 3 ; do { while -- c >= col0 ; if ( c == col ) next ; assert ( r * 9 + c != idx ) ; * p ++ = r * 9 + c ; } } return list ; } void clear_board ( ) { uint8 i = 0 ; do { board [ i ] = 511 ; while ++ i < 9 * 9 ; } } void _set ( uint idx , uint symbol ) { assert ( idx < 81 ) ; assert ( is1bit ( symbol ) ) ; assert ( symbol & board [ idx ] ) ; board [ idx ] = symbol ; uint8 [ ] related = get_related ( idx ) ; uint8 i = 20 ; do { uint8 j = related [ -- i ] ; assert ( j < 81 ) ; Cell & c = board [ j ] ; if ( c & symbol ) { assert ( c != symbol ) ; c -= symbol ; if ( is1bit ( c ) ) { _set ( j , c ) ; } } while i ; } } void newBoard ( uint8 * qdata ) { uint8 qbyte ; uint8 qmask = 0 ; clear_board ( ) ; uint8 i = 9 ; do { while ( i -- ) ; _set ( i , 1 << i ) ; } uint8 bi = 8 ; do { while ++ bi < 81 ; Cell z = board [ bi ] ; uint8 n = count1bits ( z ) ; if ( n == 1 ) next ; assert ( n > 1 && n <= 8 ) ; n = msbit ( n - 1 ) + 1 ; uint8 i = 0 ; do { while ( n -- ) if ( qmask == 0 ) { qbyte = * qdata ++ ; qmask = 128 ; } i <<= 1 ; if ( qbyte & qmask ) { i ++ ; } qmask >>= 1 ; } Cell q = 1 ; do { do { until z & q ; q <<= 1 ; assert ( q ) ; } while i -- ; q <<= 1 ; } _set ( bi , q ) ; } } void swap_cols ( uint a , uint b ) { if ( a == b ) { print ( "[]" ) ; return ; } print ( "[sc" ) ; do { swap ( board [ a ] , board [ b ] ) ; a += 9 ; b += 9 ; while a < 81 ; } print ( "]" ) ; } void swap_rows ( uint a , uint b ) { if ( a == b ) { print ( "[]" ) ; return ; } print ( "[sr" ) ; a *= 9 ; b *= 9 ; Cell [ ] z = alloc Cell [ ] ( 9 ) ; memcpy ( & z [ 0 ] , & board [ a ] , 9 * sizeof ( Cell ) ) ; memcpy ( & board [ a ] , & board [ b ] , 9 * sizeof ( Cell ) ) ; memcpy ( & board [ b ] , & z [ 0 ] , 9 * sizeof ( Cell ) ) ; print ( "]" ) ; } void mirror_h ( ) { print ( "[mh" ) ; uint8 r = 81 ; do { while r ; r -= 9 ; revert ( board [ r to r + 9 ] ) ; } print ( "]" ) ; } void mirror_v ( ) { print ( "[mv" ) ; uint8 a = 0 , b = 8 ; do { while a < b ; swap_rows ( a ++ , b -- ) ; } print ( "]" ) ; } void mirror_h_blk ( uint i ) { print ( "[mhb" ) ; i *= 3 ; swap_cols ( i , i + 2 ) ; print ( "]" ) ; } void mirror_v_blk ( uint i ) { print ( "[mvb" ) ; i *= 27 ; swap_rows ( i , i + 18 ) ; print ( "]" ) ; } void transpose_board ( ) { print ( "[xb" ) ; uint8 i = 9 ; do { while i -- ; uint8 j = i ; do { while j -- ; swap ( board [ i * 9 + j ] , board [ i + j * 9 ] ) ; } } print ( "]" ) ; } void shuffle_h ( ) { print ( "[sh" ) ; uint a = 9 ; do { swap_cols ( random ( a ) , -- a ) ; while a ; } print ( "]" ) ; } void shuffle_v ( ) { print ( "[sv" ) ; uint a = 9 ; do { swap_rows ( random ( a ) , -- a ) ; while a ; } print ( "]" ) ; } extern void main ( ) ; void main ( ) { print ( "\r\rPress key --> " ) ; ( void ) waitc ( ) ; board := alloc uint [ ] ( 81 ) ; buttons := alloc Button [ ] ( 19 ) ; menu_items := alloc MenuItem [ ] ( 6 ) ; uint xy = numpad_xy ; buttons [ 14 ] := new Button ( xy , 259 , "Easy" , set_level , 0 ) ; buttons [ 15 ] := new Button ( xy + 4 , 260 , "Normal" , set_level , 1 ) ; xy . hi += 2 ; buttons [ 16 ] := new Button ( xy , 259 , "Hard" , set_level , 2 ) ; buttons [ 17 ] := new Button ( xy + 4 , 260 , "Expert" , set_level , 3 ) ; xy . hi += 2 ; buttons [ 18 ] := new Button ( xy , 264 , "Start Game" , start_game , 1 ) ; xy . hi += 2 ; buttons [ 0 ] := new Button ( xy , 514 , "1" , select_number , 1 ) ; buttons [ 1 ] := new Button ( xy + 3 , 514 , "2" , select_number , 2 ) ; buttons [ 2 ] := new Button ( xy + 6 , 514 , "3" , select_number , 3 ) ; xy . hi += 3 ; buttons [ 3 ] := new Button ( xy , 514 , "4" , select_number , 4 ) ; buttons [ 4 ] := new Button ( xy + 3 , 514 , "5" , select_number , 5 ) ; buttons [ 5 ] := new Button ( xy + 6 , 514 , "6" , select_number , 6 ) ; xy . hi += 3 ; buttons [ 6 ] := new Button ( xy , 514 , "7" , select_number , 7 ) ; buttons [ 7 ] := new Button ( xy + 3 , 514 , "8" , select_number , 8 ) ; buttons [ 8 ] := new Button ( xy + 6 , 514 , "9" , select_number , 9 ) ; xy . hi += 3 ; buttons [ 9 ] := new Button ( xy , 259 , "Pen" , select_pen , 1 ) ; button_pen = buttons [ 9 ] ; buttons [ 10 ] := new Button ( xy + 4 , 260 , "Pencil" , select_pencil , 1 ) ; button_pencil = buttons [ 10 ] ; xy . hi += 2 ; buttons [ 11 ] := new Button ( xy , 257 , charstr ( charcode_left_arrow ) , undo , 1 ) ; buttons [ 12 ] := new Button ( xy + 2 , 257 , charstr ( charcode_right_arrow ) , redo , 1 ) ; buttons [ 13 ] := new Button ( xy + 4 , 260 , "Pause" , pause , 1 ) ; clear_background ( ) ; uint8 i = buttons . count ( ) ; do { while i -- ; buttons [ i ] . draw ( ) ; } select_joystick ( ) ; do { clear_mbar ( ) ; menu_items [ 0 ] = new MenuItem ( 0 , 28 , "Save" , save ) ; menu_items [ 1 ] = new MenuItem ( 4 * 8 + 2 , 29 , "Load" , load ) ; clear_board ( board_xy ) ; draw_cross ( ) ; i = buttons . count ( ) ; do { while i -- ; buttons [ i ] . enable ( i >= 14 ) ; } set_level ( level ) ; do { while ( ! game_on ) ; track_mouse ( ) ; } hide_mouse ( ) ; current_number = 0 ; clear_mbar ( ) ; menu_items [ 0 ] := new MenuItem ( 0 , 28 , "Save" , save ) ; menu_items [ 1 ] := new MenuItem ( 4 * 8 + 2 , 29 , "Load" , load ) ; menu_items [ 2 ] := new MenuItem ( 8 * 8 + 2 , 29 , "Undo" , undo ) ; menu_items [ 3 ] := new MenuItem ( 12 * 8 + 2 , 29 , "Redo" , redo ) ; menu_items [ 4 ] := new MenuItem ( 16 * 8 + 2 , 37 , "Pause" , pause ) ; menu_items [ 5 ] := new MenuItem ( 21 * 8 + 3 , 36 , "Abort" , abort ) ; setattr ( 7 + 1 * 8 ) ; locate ( 5376 ) ; print ( c_clreol ) ; locate ( 5632 ) ; print ( c_clreol ) ; locate ( 5888 ) ; print ( c_clreol ) ; locate ( 5376 ) ; uint brdidx = random ( num_boards ) * 10 ; uint8 * cboard = cboards + brdidx ; newBoard ( cboard ) ; uint8 * pp = level4_cdata ; uint8 bits = * ( cboard + 9 ) ; uint8 byte = bits ; uint8 mask = 1 ; switch ( level ) { case 0 : byte >>= 3 ; pp = level1_cdata ; break ; case 1 : byte >>= 2 ; pp = level2_cdata ; break ; case 2 : byte >>= 1 ; pp = level3_cdata ; break ; } uint8 [ 9 ] syms = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; shuffle ( syms ) ; pp += brdidx ; uint8 i = 0 ; do { if ( ! mask ) { byte = * pp ++ ; mask = 128 ; } assert ( is1bit ( board [ i ] ) ) ; board [ i ] = byte & mask ? syms [ msbit ( board [ i ] ) ] + m_presetcell : 0 ; mask >>= 1 ; while ++ i < 81 ; } if ( 0 ) switch ( bits >> 5 ) { case 1 : shuffle_h ( ) ; shuffle_v ( ) ; if ( random bool ( ) ) transpose_board ( ) ; break ; case 3 : shuffle_h ( ) ; case 2 : if ( random bool ( ) ) mirror_v ( ) ; break ; case 5 : shuffle_v ( ) ; case 4 : if ( random bool ( ) ) mirror_h ( ) ; break ; case 7 : i = 3 ; do { while i -- ; if ( random bool ( ) ) mirror_h_blk ( i ) ; if ( random bool ( ) ) mirror_v_blk ( i ) ; } if ( random bool ( ) ) transpose_board ( ) ; case 6 : if ( random bool ( ) ) mirror_h ( ) ; if ( random bool ( ) ) mirror_v ( ) ; break ; } draw_board ( ) ; i = buttons . count ( ) ; do { while i -- ; buttons [ i ] . on = no ; buttons [ i ] . enable ( i <= 13 ) ; } select_pen ( 0 ) ; do { while ( game_on ) ; track_mouse ( ) ; char c = getc ( ) ; if ( c >= 49 && c <= 57 ) select_number ( c - 48 ) ; else if ( c == 112 ) if ( button_pen . on ) select_pencil ( 0 ) ; else select_pen ( 0 ) ; } hide_mouse ( ) ; } } ""