Subversion Repositories Kolibri OS

Rev

Rev 1805 | Rev 1825 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; 4.11.2009 staper@inbox.ru
  2.  
  3. ; 2.06.2010 fixed a little bug in check
  4.  
  5. ;based on http://sources.codenet.ru/download/1599/Sudoku.html
  6.  
  7. ; ‚ ¯à ¢®¬ ­¨¦­¥¬ 㣫ã à á¯®« £ ¥âáï á¥à ï ª­®¯ª ,
  8. ;¯à¨ ­ ¦ â¨î ­  ª®â®àãî ®ª­® 㢥«¨ç¨¢ ¥âáï ¢ à §¬¥à¥.
  9.  
  10. ; à®£à ¬¬  ¯à®¢¥àï¥â áâப㠯 à ¬¥â஢; ¯à®áâ® ¯¥à¥¤ ©â¥
  11. ;¯ãâì ª ä ©«ã á § ¤ ç¥©.
  12.  
  13. ; ‘®ç¥â ­¨ï ª« ¢¨è:
  14. ;       n - ᣥ­¥à¨à®¢ âì â ¡«¨æã
  15. ;       c - ¯à®¢¥à¨âì à¥è¥­¨¥
  16. ;       ¯à®¡¥« - ¯®ª § âì à¥è¥­¨¥
  17. ;       +-  - ¨§¬¥­¨âì ã஢¥­ì á«®¦­®áâ¨
  18. ;       t - ¯à¨®áâ ­®¢¨âì/§ ¯ãáâ¨âì ᥪ㭤®¬¥à
  19. ;       i - ¢¢¥á⨠᢮© ¯à¨¬¥à
  20. ;       r - à¥è¨âì
  21. ;       l - § £à㧨âì § ¤ çã ¨§ ä ©« 
  22. ;       s - á®åà ­¨âì § ¤ çã ¢ ä ©«
  23. ;       a - á®åà ­¨âì à¥è¥­¨¥ ¢ ä ©«
  24.  
  25. use32
  26. org     0x0
  27.  db     'MENUET01'
  28.  dd     0x1, START, I_END, (D_END+10000) and not 3,  (D_END+10000) and not 3, buf_cmd_lin, cur_dir_path
  29.  
  30. Difficult db 0  ;á«®¦­®áâì [0..9]
  31. Difficult_array db 80,75,68,59,50,45,40,36,32,25
  32.  
  33. ;–¢¥â :
  34. Bckgrd_clr      equ 0xffffff    ;ä®­
  35. Brdr_line_clr   equ 0x780000    ;«¨­¨¨ ¯® £à ­¨æ ¬
  36. Inter_line_clr  equ 0xb0b0b0    ;¢­ãâ७­¨¥ «¨­¨¨
  37. Square_clr      equ 0xdddddd    ;梥⠪ãàá®à 
  38. Fix_nmb_clr     equ 0x335533;0  ;áâ â¨ç­®¥ §­ ç¥­¨¥
  39. Chg_nmb_clr     equ 0;x008d8d   ;¯¥à¥¬¥­­®¥ §­ ç¥­¨¥
  40. Text_clr        equ 0x000000    ;⥪áâ
  41. Message_clr     equ 0x0000ff    ;á®®¡é¥­¨ï
  42.  
  43. DEBUG equ 0
  44.  
  45. macro dbg_dec num
  46. {pushad
  47. newline
  48. debug_print_dec num
  49. popad
  50. }
  51.  
  52. include '../../../macros.inc'
  53. ;include 'debug.inc'
  54. include 'editbox_ex.mac'
  55. include 'lang.inc'
  56. include 'SudokuSolve.pas'
  57.  
  58.  
  59. START:
  60.         mcall   40,7
  61.         mcall   3
  62.         mov     [rsx1],ax
  63.         ror     eax,16
  64.         mov     [rsx2],ax
  65.         rol     eax,7
  66.         mov     [rsx3],ax
  67.         rol     eax,7
  68.         mov     [rsx4],ax
  69.  
  70. ;       call    LOAD_LIB        ;loading Box_Lib library
  71.  
  72. ; This is the part of the macros for load any library/libraries by <Lrz>
  73. LOAD_LIB:
  74.         mcall   68,19,system_path   ; load of sys directory
  75.         test    eax,eax
  76.         jnz     .end_steep
  77.  
  78.         bts     [flags],7
  79. ;       ret
  80.         jmp     .end
  81.  
  82. .end_steep:
  83.  
  84. ; initialize import
  85.         mov     edx, eax
  86.         mov     esi,myimport
  87. .import_loop:
  88.         lodsd
  89.         test    eax, eax
  90.         jz      .import_done
  91.         push    edx
  92. .import_find:
  93.         mov     ebx, [ds:edx]
  94.         test    ebx, ebx
  95.         jz      .exit   ;import_not_found
  96.         push    eax
  97. .lp:
  98.         mov     cl, [ds:eax]
  99.         cmp     cl, [ds:ebx]
  100.         jnz     .import_find_next
  101.         test    cl, cl
  102.         jz      .import_found
  103.         inc     eax
  104.         inc     ebx
  105.         jmp     .lp
  106. .import_find_next:
  107.         pop     eax
  108.         add     edx, 8
  109.         jmp     .import_find
  110. .import_found:
  111.         pop     eax
  112.         mov     eax, [ds:edx+4]
  113.         mov     [esi-4], eax
  114.         pop     edx
  115.         jmp     .import_loop
  116. .exit:
  117.         add     esp,4
  118.  
  119.         bts     [flags],7
  120. ;ret
  121.         jmp     .end
  122.  
  123. .import_done:
  124.         btr     [flags],7
  125.  
  126. ;®¯à¥¤¥«ï¥¬ ¤«¨­ã áâப¨ á ¯ à ¬¥âà ¬¨
  127.         mov     esi,buf_cmd_lin
  128.         xor     eax,eax
  129. @@:     cmp     byte [esi+eax],0
  130.         je      @f
  131.         inc     eax
  132.         jmp     @b
  133. @@:     mov     dword [edit1.size],eax
  134.         mov     dword [edit1.pos],eax
  135. ;ret
  136. .end:
  137.  
  138.         bt      [flags],7
  139.         jc      @f
  140.         mcall   68,11
  141.         cmp     dword [edit1.pos],0
  142.         je      @f
  143.         call    load_sudoku
  144.         jnc     redraw_all
  145. @@:     jmp     key.new_game
  146.  
  147.  
  148. redraw_all:
  149.         mcall   12,1
  150.         mcall   48,4
  151.         add     eax,100*65536+(24*9+67)
  152.         mov     ecx,eax
  153.         mcall   0,100*65536+(24*9+12),,(0x34000000+Bckgrd_clr),,title
  154.         mcall   38,1*65536+(24*9+1),21*65536+21,Brdr_line_clr
  155.         mov     edx,Inter_line_clr
  156.         mov     edi,3
  157.         mov     esi,3
  158.   @@:   add     ecx,24*65536+24
  159.         mcall
  160.         dec     esi
  161.         jnz     @b
  162.         mov     esi,3
  163.         push    edx
  164.         mcall   ,,,Brdr_line_clr
  165.         pop     edx
  166.         dec     edi
  167.         jnz     @b
  168.         mcall   ,1*65536+1,22*65536+236,Inter_line_clr;0xe7e6a0
  169.         mov     edx,Inter_line_clr
  170.         mov     edi,3
  171.         mov     esi,3
  172.         push    edx
  173.         mcall   ,,,Brdr_line_clr
  174.         pop     edx
  175.  
  176.   @@:   add     ebx,24*65536+24
  177.         mcall
  178.         dec     esi
  179.         jnz     @b
  180.         mov     esi,3
  181.         push    edx
  182.         mcall   ,,,Brdr_line_clr
  183.         pop     edx
  184.         dec     edi
  185.         jnz     @b
  186.  
  187.         mcall   8,<208,8>,<257,8>,2,0xbbbbbb
  188.         mcall   4,<5,5>,(0x80000000+Text_clr),txt.new
  189.         mcall   ,<105,5>,,txt.dif
  190.         mcall   ,<5,258>,,txt.space
  191.         mcall   ,<5,246>,,txt.check
  192.         mcall   ,<129,246>,,txt.time
  193.         mcall   ,<5,285>,,txt.own_map
  194.         mcall   ,<5,296>,,txt.solve
  195.         mcall   ,<90,296>,,txt.load
  196.         mcall   ,<5,306>,,txt.save
  197.         mcall   ,<90,306>,,txt.save_solve
  198.  
  199.         bts     [flags],5
  200.         call    Timer.0
  201.         call    show_level
  202.  
  203.         push    dword Map;esi;  mov     esi,Map
  204.         mcall   12,2
  205. draw_pole:
  206.         if DEBUG
  207.         call    SysMsgBoardNum  ;show esp
  208.         endf
  209.  
  210.         movzx   eax,[Y]
  211.         dec     al
  212.         mov     ebx,9
  213.         mul     bl
  214.         mov     bl,[X]
  215.         add     al,bl
  216.         pop     esi     ;       mov     esi,Map
  217.         push    eax     ;ªãàá®à稪
  218.         mov     edi,81-9
  219.         mov     ebp,9
  220.         mov     ebx,1*65536+21
  221.         mov     ecx,21*65536+41
  222.         call    out_numbers
  223.         pop     eax
  224.         bt      [flags],2
  225.         jc      key.0
  226.  
  227. still:
  228.         mcall   23,10
  229.         test    eax,eax
  230.         jz      Timer
  231.  
  232.         dec     al
  233.         jz      redraw_all
  234.         dec     al
  235.         jz      key
  236.         dec     al
  237.         jnz     still
  238. ;button:
  239.         mcall   17
  240.         cmp     ah,1
  241.         jne     @f
  242.         mcall   -1
  243. @@:     cmp     ah,2
  244.         jne     still
  245.         btc     [flags],9
  246.         mcall   48,4
  247.         add     eax,(24*9+67)
  248.         mov     esi,eax
  249.         bt      [flags],9
  250.         jnc     @f
  251.         add     esi,40
  252. @@:     mcall   67,100,100,(24*9+12),
  253.         jmp     still
  254. key:
  255.         mcall   2
  256.         cmp ah,32               ;¯à®¡¥«
  257. jne     @f
  258.         btc     [flags],3
  259.         jc      .todraw
  260.         push    dword SolveMap
  261.         jmp     draw_pole
  262.         .todraw:
  263.         push    dword Map
  264.         jmp     draw_pole
  265. @@:
  266.         bt      [flags],3
  267.         jnc     @f
  268.         bts     [flags],2
  269.         push    eax
  270.         push    dword Map
  271.         jmp     draw_pole
  272. .0:     pop     eax
  273.         btr     [flags],2
  274.         btr     [flags],3
  275. @@:     cmp     ah,108          ;l
  276.         jne     @f
  277.         bt      [flags],7
  278.         jc      still
  279.         bt      [flags],6
  280.         jc      still
  281.         bts     [flags],8
  282.         call    window_load_save
  283.         jmp     still
  284. @@:     cmp     ah,115          ;s
  285.         jne     @f
  286.         btr     [flags],10
  287. .sresh: bt      [flags],7
  288.         jc      still
  289.         bt      [flags],6
  290.         jc      still
  291.         btr     [flags],8
  292.         call    window_load_save
  293.         jmp     still
  294. @@:     cmp     ah,97           ;a
  295.         jne     @f
  296.         bts     [flags],10
  297.         jmp     .sresh
  298. @@:     cmp     ah,116          ;t
  299.         jne     @f
  300.         btc     [flags],1
  301.         jnc     still
  302.         mcall   26,9
  303.         sub     eax,[Ticks_new]
  304.         push    eax
  305.         mov     eax,[Ticks]
  306.         mov     ebx,100
  307.         mul     ebx
  308.         pop     ecx
  309.         sub     ecx,eax
  310.         add     [Ticks_new],ecx
  311.         jmp     still
  312.  
  313. @@:     cmp     ah,105          ;i
  314.         jne     @f
  315.                 xor     ecx,ecx
  316.                 .105_0:
  317.                 mov     byte [SolveMap+ecx],0
  318.                 mov     byte [Map+ecx],0
  319.                 inc     ecx
  320.                 cmp     ecx,9*9
  321.                 jb      .105_0
  322.                 jmp     .todraw
  323.  
  324. @@:     cmp     ah,114          ;r
  325.         jne     .43
  326.         xor     ecx,ecx
  327.         .114_0:
  328.                 mov     al,[Map+ecx]
  329.                 cmp     al,9
  330.                 jbe     @f
  331.                 sub     al,10
  332.                 @@:
  333.                 mov     [SolveMap+ecx],al
  334.                 inc     ecx
  335.                 cmp     ecx,9*9
  336.                 jb      .114_0
  337.         mov     esi,SolveMap
  338.         call    Solve
  339.         cmp     [_iRet],1
  340.         jne     @f
  341.                 mov     edx,txt.check_yes
  342.                 call    Show_message
  343.                 jmp     still
  344.         @@: ;­¥â à¥è¥­¨©
  345.                 xor     ecx,ecx
  346.                 @@:
  347.                 mov     byte [SolveMap+ecx],0
  348.                 inc     ecx
  349.                 cmp     ecx,9*9
  350.                 jb      @b
  351.                 mov     edx,txt.nosolve
  352.                 call    Show_message
  353.                 jmp     still
  354.  
  355. .43:    cmp     ah,43           ;+
  356.         jne     .45
  357.         cmp     [Difficult],9
  358.         je      still
  359.         inc     [Difficult]
  360.         call    show_level
  361.         jmp     still
  362. .45:                            ;-
  363.         cmp     ah,45
  364.         jne     .99
  365.         cmp     [Difficult],0
  366.         je      still
  367.         dec     [Difficult]
  368.         call    show_level
  369.         jmp     still
  370.  
  371. .99:                            ;Check
  372.         cmp     ah,99
  373.         jne     .39
  374.         bts     [flags],15
  375.         xor     ecx,ecx
  376.         mov     edx,txt.check_no
  377. ; @@:   mov     al,byte [Map+ecx]
  378. ;       cmp     byte [SolveMap+ecx],al
  379. ;       jne     @f
  380. ;       inc     ecx
  381. ;       cmp     ecx,9*9
  382. ;       jb      @b
  383.  @@:    mov     al,byte [Map+ecx]       ;¯¥à¥­®á¨¬ §­ ç¥­¨ï ¢® ¢à¥¬¥­­ë© ¬ áᨢ
  384.         cmp     al,9
  385.         jbe     .991
  386.                 sub     al,10
  387.         .991:
  388.         mov     [TempMap+ecx],al
  389.         inc     ecx
  390.         cmp     ecx,9*9
  391.         jb      @b
  392.         mov     esi,TempMap
  393.         call    CheckSudoku
  394.         jc      @f
  395.         mov     edx,txt.check_yes
  396.  @@:    btr     [flags],15
  397.         call    Show_message
  398.         jmp     .todraw
  399.  
  400. .39:    cmp     ah,0x39
  401.         ja      .110
  402.         cmp     ah,0x30
  403.         jb      still
  404.         sub     ah,0x30
  405.         mov     cl,ah
  406.  
  407.         movzx   eax,[Y]
  408.         dec     al
  409.         mov     ebx,9
  410.         mul     bl
  411.         mov     bl,[X]
  412.         dec     bl
  413.         add     al,bl
  414.         mov     esi,Map
  415.         cmp     byte [esi+eax],9
  416.         jg      still
  417.         mov     [esi+eax],cl
  418.         jmp     .onedraw
  419.  
  420. .110:   cmp     ah,110          ;n
  421.         jne     .176
  422. .new_game:
  423.         call    GeneratePlayBoard
  424.         mov     [Ticks],0
  425.         mcall   26,9
  426.         mov     [Ticks_new],eax
  427.         jmp     redraw_all
  428.  
  429. .176:   cmp     ah,176 ;ªãàá®àë
  430.         jne     .177
  431.         call    draw_one_symbol
  432.         dec     [X]
  433.         cmp     [X],1
  434.         jge     @f
  435.         mov     [X],9
  436. @@:     jmp     .onedraw
  437. .177:   cmp     ah,177
  438.         jne     .178
  439.         call    draw_one_symbol
  440.         inc     [Y]
  441.         cmp     [Y],9
  442.         jbe     @f
  443.         mov     [Y],1
  444. @@:     jmp     .onedraw
  445. .178:   cmp     ah,178
  446.         jne     .179
  447.         call    draw_one_symbol
  448.         dec     [Y]
  449.         cmp     [Y],1
  450.         jge     @f
  451.         mov     [Y],9
  452. @@:     jmp     .onedraw
  453. .179:   cmp     ah,179
  454.         jne     still
  455.         call    draw_one_symbol
  456.         inc     [X]
  457.         cmp     [X],9
  458.         jbe     @f
  459.         mov     [X],1
  460. @@:
  461. .onedraw:
  462.         bts     [flags],4
  463.         call    draw_one_symbol
  464.         jmp     still ;.todraw
  465.  
  466. show_level:
  467.         movzx   ecx,[Difficult]
  468.         mcall   47,0x10000,,<205,5>,(0x50000000+Text_clr),Bckgrd_clr
  469. ret
  470.  
  471. Show_message:
  472.         mcall   4,<5,269>,(0xd0000000+Message_clr),,,Bckgrd_clr
  473. ret
  474.  
  475. Timer:
  476.         bt      [flags],1
  477.         jc      still
  478.         mcall   26,9
  479.         sub     eax,[Ticks_new]
  480.         mov     ebx,100
  481.         xor     edx,edx
  482.         div     ebx
  483.         cmp     eax,[Ticks]
  484.         je      still
  485.         mov     [Ticks],eax
  486. .1:     mov     ebx,60
  487.         xor     edx,edx
  488.         div     ebx
  489.         push    eax
  490.         mov     ecx,edx
  491.         mcall   47,0x00020000,,<206,246>,(0x40000000+Text_clr),Bckgrd_clr
  492.         pop     ecx
  493.         mov     edx,189*65536+246
  494.         mcall
  495.         bt      [flags],5
  496.         jnc     @f
  497.         btr     [flags],5
  498.         ret
  499. @@:     jmp     still
  500. .0:     mov     eax,[Ticks]
  501.         jmp     .1
  502.  
  503. draw_one_symbol:
  504.         movzx   eax,[X]
  505.         mov     ebx,24*65536+24
  506.         mul     ebx
  507.         xchg    eax,ebx
  508.         add     ebx,(1*65536+21-24*65536+24)
  509.         movzx   eax,[Y]
  510.         mov     ecx,24*65536+24
  511.         mul     ecx
  512.         xchg    eax,ecx
  513.         add     ecx,(21*65536+41-24*65536+24)
  514.         movzx   eax,[Y]
  515.         dec     al
  516.         push    ebx
  517.         mov     ebx,9
  518.         mul     bl
  519.         mov     bl,[X]
  520.         add     al,bl
  521.         dec     al
  522.         pop     ebx
  523.         mov     esi,Map
  524.         add     esi,eax
  525.         push    dword 0 ;­¥ ªãàá®à
  526.         bt      [flags],4
  527.         jnc     @f
  528.         mov     dword [esp],1 ;ªãàá®à
  529.         btr     [flags],4
  530. @@:     mov     edi,0
  531.         mov     ebp,1
  532.         call    out_numbers
  533.         pop     eax
  534. ret
  535.  
  536.  
  537. out_numbers:
  538.         push    ebx ecx esi
  539.         shr     ebx,16
  540.         inc     bx
  541.         shl     ebx,16
  542.         add     ebx,23
  543.         shr     ecx,16
  544.         inc     cx
  545.         shl     ecx,16
  546.         add     ecx,23
  547.         mov     edx,Bckgrd_clr
  548.         push    ebp
  549.         dec     dword [esp+4*5]
  550.         jnz     @f
  551.         mov     edx,Square_clr
  552. @@:     mcall   13
  553.         pop     ebp
  554.         pop     esi
  555.  
  556.         cmp     byte [esi],0
  557.         je      .null
  558.         cmp     byte [esi],9
  559.         jbe     .changeable_number
  560.         cmp     byte [esi],19
  561.         jbe     .fixed_number
  562.         jmp     .null
  563. .end:
  564.         inc     esi
  565.         dec     ebp
  566.         jnz     out_numbers
  567.         test    edi,edi
  568.         jz      @f
  569.         sub     edi,9
  570.         mov     ebp,9
  571.         add     ebx,-9*24*65536-9*24
  572.         add     ecx,24*65536+24
  573.         jmp     out_numbers
  574.   @@:
  575. ret
  576.  
  577. .fixed_number:
  578.         push    esi
  579.         shr     ebx,16
  580.         shr     ecx,16
  581.         mov     dx,bx
  582.         shl     edx,16
  583.         mov     dx,cx
  584.         add     edx,8*65536+4
  585.         movzx   ebx,byte [esi]
  586.         sub     ebx,10
  587.         dec     ebx
  588.         shl     ebx,4
  589.         add     ebx,FONT
  590.         mov     ecx,8*65536+16
  591.         push    esi ebp edi
  592.         mov     edi,Pltr.fx
  593.         cmp     dword [esp+4*7],0
  594.         jne     @f
  595.         mov     edi,Pltr.fxk
  596. @@:     mov     esi,1
  597.         mov     ebp,0
  598.         mcall   65
  599.         pop     edi ebp esi
  600. .1:     pop     esi ecx ebx
  601.         add     ebx,24*65536+24
  602.         jmp     .end
  603.  
  604. .null:
  605.         pop     ecx ebx
  606.         add     ebx,24*65536+24
  607.         jmp     .end
  608. .changeable_number:
  609.         push    esi
  610.         shr     ebx,16
  611.         shr     ecx,16
  612.         mov     dx,bx
  613.         shl     edx,16
  614.         mov     dx,cx
  615.         add     edx,8*65536+4
  616.         movzx   ebx,byte [esi]
  617.         dec     ebx
  618.         shl     ebx,4
  619.         add     ebx,FONT
  620.         mov     ecx,8*65536+16
  621.         push    esi ebp edi
  622.         mov     edi,Pltr.ch
  623.         cmp     dword [esp+4*7],0
  624.         jne     @f
  625.         mov     edi,Pltr.chk
  626. @@:     mov     esi,1
  627.         mov     ebp,0
  628.         mcall   65
  629.         pop     edi ebp esi
  630.         jmp     .1
  631.  
  632.  
  633.  
  634. GeneratePlayBoard:
  635. ;i db 0
  636. ;j db 0
  637. ;RandI db 0
  638. ;RandJ db 0
  639. ;iRet db 0
  640. ;//£¥­¥à¨à㥬 à¥è¥­­ãî ¬ âà¨æã
  641. ;m:
  642. ;for i:=0 to 8 do
  643. ;  for j:=0 to 8 do
  644. ;    begin
  645. ;    Map[i,j]:=0;
  646. ;    SolveMap[i,j]:=0;
  647. ;    RealMap[i,j]:=0;
  648. ;    end;
  649.         mov     edi,Map
  650.         mov     esi,SolveMap
  651.         mov     edx,RealMap
  652.         xor     ecx,ecx
  653.         @@:
  654.         mov     byte [edi+ecx],0
  655.         mov     byte [esi+ecx],0
  656.         mov     byte [edx+ecx],0
  657.         inc     ecx
  658.         cmp     ecx,9*9
  659.         jb      @b
  660.  
  661. ;//áâ ¢¨¬ à ­¤®¬­® ­¥áª®«ìª® ç¨á¥« ­  ¯®«¥
  662. ;for i:=1 to 21 do
  663. ;  begin
  664. ;  RandI:=random(9);
  665. ;  RandJ:=random(9);
  666. ;  if SolveMap[RandI,RandJ]=0 then
  667. ;     begin
  668. ;     SolveMap[RandI,RandJ]:=random(9)+1;
  669. ;     if not CheckSudoku(SolveMap) then
  670. ;       begin
  671. ;       SolveMap[RandI,RandJ]:=0;
  672. ;       Continue;
  673. ;       end;
  674. ;     end else Continue;
  675. ;  end;
  676.  
  677.         mov     ecx,21
  678. .1:     mov     eax,9
  679.         call    random
  680.         mov     ebx,eax
  681.         mov     eax,9
  682.         call    random
  683.         mov     ah,9
  684.         mul     ah
  685.         add     eax,ebx ;RandI,RandJ
  686.         cmp     byte [esi+eax],0
  687.         jne     .loop
  688.                 mov     ebx,eax
  689.                 mov     eax,9
  690.                 call    random
  691.                 mov     byte [esi+ebx],al
  692.                 call    CheckSudoku
  693.                 jnc     .loop
  694.                 mov     byte [esi+ebx],0
  695.         .loop:
  696.         loop    .1
  697.  
  698.  
  699. ;//à¥è ¥¬ ‘㤮ªã
  700. ;iRet:=Solve(SolveMap);
  701. ;if iRet<>1 then goto m;
  702. ;i:=1;
  703.  
  704.         mov     esi,SolveMap
  705.         call    Solve
  706.         cmp     [_iRet],1
  707.         jne     GeneratePlayBoard
  708.  
  709.         movzx   ecx,[Difficult]
  710.         movzx   ecx,byte [Difficult_array+ecx]
  711.  
  712. ;case Difficult of
  713. ;1:
  714. ;   while i<=42 do
  715. ;   begin
  716. ;        RandI:=random(9);
  717. ;        RandJ:=random(9);
  718. ;        if RealMap[RandI,RandJ]<>0 then Continue else
  719. ;        RealMap[RandI,RandJ]:=SolveMap[RandI,RandJ];
  720. ;        inc(i);
  721. ;   end;
  722. ;2:
  723. ;   while i<=32 do
  724. ;   begin
  725. ;        RandI:=random(9);
  726. ;        RandJ:=random(9);
  727. ;        if RealMap[RandI,RandJ]<>0 then Continue else
  728. ;        RealMap[RandI,RandJ]:=SolveMap[RandI,RandJ];
  729. ;        inc(i);
  730. ;   end;
  731. ;3:
  732. ;   while i<=25 do
  733. ;   begin
  734. ;        RandI:=random(9);
  735. ;        RandJ:=random(9);
  736. ;        if RealMap[RandI,RandJ]<>0 then Continue else
  737. ;        RealMap[RandI,RandJ]:=SolveMap[RandI,RandJ];
  738. ;        inc(i);
  739. ;   end;
  740. ;end;
  741.  
  742. .2:
  743.         mov     eax,9
  744.         call    random
  745.         mov     ebx,eax
  746.         mov     eax,9
  747.         call    random
  748.         mov     ah,9
  749.         mul     ah
  750.         cmp     al,81
  751.         jb      @f
  752.         dec     al
  753.         @@:
  754.         add     eax,ebx ;RandI,RandJ
  755.         cmp     byte [RealMap+eax],0
  756.         jne     .loop2
  757.                 add     byte [SolveMap+eax],10
  758.                 mov     bl,[SolveMap+eax]
  759.                 mov     byte [RealMap+eax],bl
  760.         .loop2:
  761.         loop    .2
  762.  
  763. ;for i:=0 to 8 do
  764. ;   for j:=0 to 8 do
  765. ;      Map[i,j]:=RealMap[i,j];
  766. ;end;
  767.  
  768.         xor     ecx,ecx
  769. @@:     mov     al,[RealMap+ecx]
  770.         mov     [Map+ecx],al
  771.         inc     ecx
  772.         cmp     ecx,9*9
  773.         jb      @b
  774. ret
  775.  
  776.  
  777.  
  778.  
  779. align 4
  780. rsx1 dw ?;0x4321
  781. rsx2 dw ?;0x1234
  782. rsx3 dw ?;0x62e9
  783. rsx4 dw ?;0x3619
  784. random:         ; ¨§ ASCL
  785.         push ecx ebx esi edx
  786.         mov cx,ax
  787.         mov ax,[rsx1]
  788.         mov bx,[rsx2]
  789.         mov si,ax
  790.         mov di,bx
  791.         mov dl,ah
  792.         mov ah,al
  793.         mov al,bh
  794.         mov bh,bl
  795.         xor bl,bl
  796.         rcr dl,1
  797.         rcr ax,1
  798.         rcr bx,1
  799.         add bx,di
  800.         adc ax,si
  801.         add bx,[rsx3]
  802.         adc ax,[rsx4]
  803.         sub [rsx3],di
  804.         adc [rsx4],si
  805.         mov [rsx1],bx
  806.         mov [rsx2],ax
  807.         xor dx,dx
  808.         cmp ax,0
  809.         je nodiv
  810.         cmp cx,0
  811.         je nodiv
  812.         div cx
  813. nodiv:
  814.         mov ax,dx
  815.         pop edx esi ebx ecx
  816.         and eax,0000ffffh
  817. ret
  818.  
  819.  
  820.  
  821. if DEBUG
  822. SysMsgBoardNum: ;warning: destroys eax,ebx,ecx,esi
  823.         mov     ebx,esp
  824.         mov     ecx,8
  825.         mov     esi,(number_to_out+1)
  826. .1:
  827.         mov     eax,ebx
  828.         and     eax,0xF
  829.         add     al,'0'
  830.         cmp     al,(10+'0')
  831.         jb      @f
  832.         add     al,('A'-'0'-10)
  833. @@:
  834.         mov     [esi+ecx],al
  835.         shr     ebx,4
  836.         loop    .1
  837.         dec     esi
  838.         mcall   71,1,number_to_out
  839. ret
  840.  
  841. number_to_out   db '0x00000000',13,10,0
  842. endf
  843.  
  844.  
  845.  
  846. window_load_save:
  847.         popad
  848.         mcall   51,1,.thread,(threat_stack+32*4)
  849.         pushad
  850.         ret
  851. .thread:
  852.         bts     [flags],6
  853. .red:
  854.         mcall   12,1
  855.         mov     edi,txt.load
  856.         bt      [flags],8
  857.         jc      @f
  858.         mov     edi,txt.save
  859.         bt      [flags],10
  860.         jnc     @f
  861.         mov     edi,txt.save_solve
  862. @@:     mcall   0,50*65536+300,0x70*65536+60,(0x34000000+Bckgrd_clr),,
  863.         mcall   8,<245,43>,<2,14>,100,0xaaaaaa
  864.         mcall   4,<252,5>,(0x80000000+Text_clr),txt.enter
  865.         push    dword edit1
  866.         call    [edit_box_draw]
  867.         mcall   12,2
  868. .still:
  869.         mcall   10
  870.         dec     al
  871.         jz      .red
  872.         dec     al
  873.         jz      .key
  874.         dec     al
  875.         jz      .button
  876.         jmp     .still
  877. .button:
  878.         mcall   17,1
  879.         cmp     ah,1
  880.         jne     @f
  881.   .end: btr     [flags],6
  882.         mcall   -1
  883.   @@:   cmp     ah,100
  884.         jne     .still
  885.         bt      [flags],8
  886.         jc      .ld
  887.   .sv:  call    save_sudoku
  888.         jnc     .end
  889.         jmp     .err
  890.   .ld:  call    load_sudoku
  891.         jnc     .end
  892.   .err: mcall   4,<5,19>,(0x80000000+Text_clr),txt.error
  893.         jmp     .still
  894.  
  895.  
  896. .key:
  897.         mcall   2
  898.         cmp     ah,13
  899.         jne     @f
  900.         bt      [flags],8
  901.         jc      .ld
  902.         jmp     .sv
  903.    @@:  cmp     ah,27
  904.         je      .end
  905.         push    dword edit1
  906.         call    [edit_box_key]
  907.         jmp     .still
  908.  
  909.  
  910. save_sudoku:
  911.         mov     [_size],9*(9+2)
  912.         mcall   68,12,[_size]
  913.         test    eax,eax
  914.         jnz     @f
  915.         stc
  916.         ret
  917.  
  918. @@:     mov     [_buffer],eax
  919.         mov     edx,Map
  920.         bt      [flags],10
  921.         jnc     @f
  922.         mov     edx,SolveMap
  923. @@:     mov     esi,eax;[_buffer]
  924.         mov     ecx,[_size]
  925.         xor     edi,edi
  926.         dec     edi
  927.         mov     ebx,9
  928. .1:     test    ecx,ecx
  929.         jz      .end
  930.         test    ebx,ebx
  931.         jz      .2
  932.         inc     edi
  933.         dec     ebx
  934.         mov     al,[edx+edi]
  935.         test    al,al
  936.         jnz     @f
  937.         mov     byte [esi+edi],0x23
  938.         loop    .1
  939.         jmp     .end
  940. @@:     cmp     al,9
  941.         jbe     @f
  942.         sub     al,10
  943. @@:     add     al,48
  944.         mov     byte [esi+edi],al
  945.         loop    .1
  946.         jmp     .end
  947. .2:     mov     ebx,9
  948.         mov     byte [esi+edi+1],13
  949.         mov     byte [esi+edi+2],10
  950.         add     esi,2
  951.         sub     ecx,2
  952.         jmp     .1
  953.  
  954.  
  955. .end:   mov     [func_70.func_n],2
  956.         push    [_size]
  957.         pop     [func_70.param3]
  958.         push    [_buffer]
  959.         pop     [func_70.param4]
  960.         mov     [func_70.name],buf_cmd_lin
  961.         mcall   70,func_70
  962.         cmp     al,0                    ;á®åà ­ñ­ 㤠筮?
  963.         je      @f
  964.         mcall   68,13,[_buffer]
  965.         stc
  966.         ret
  967. @@:     mcall   68,13,[_buffer]
  968.         clc
  969. ret
  970.  
  971. load_sudoku:
  972.         mov     [func_70.func_n],5
  973.         mov     [func_70.param3],0
  974.         mov     [func_70.param4],bufferfinfo
  975.         mov     [func_70.name],buf_cmd_lin
  976.         mcall   70,func_70
  977.         test    al,al           ;ä ©« ­ ©¤¥­?
  978.         jz      @f
  979.         stc
  980.         ret
  981.   @@:   mov     eax, dword [bufferfinfo+32]     ;ª®¯¨à㥬 à §¬¥à ä ©« 
  982.         cmp     eax,81
  983.         jge     @f
  984.         stc
  985.         ret
  986. @@:     cmp     eax,100
  987.         jb      @f
  988.         stc
  989.         ret
  990.  
  991. _size dd 0
  992. _buffer dd 0
  993.  
  994. @@:     mov     [_size],eax
  995.         mcall   68,12,[_size]
  996.         test    eax,eax
  997.         jnz     @f
  998.         stc
  999.         ret     ;®è¨¡ª  ­  ¢ë¤¥«¥­¨¥ ¡«®ª 
  1000.   @@:
  1001.         mov     [_buffer],eax
  1002.         mov     [func_70.func_n],0
  1003.         mov     [func_70.name],buf_cmd_lin
  1004.         push    dword [_size]
  1005.         pop     dword [func_70.param3]
  1006.         push    dword [_buffer]
  1007.         pop     dword [func_70.param4]
  1008.         mcall   70,func_70
  1009.         test    eax,eax
  1010.         jz      @f
  1011.         stc
  1012.         ret     ;®è¨¡ª  ç⥭¨ï
  1013. @@:
  1014.  
  1015.         mov     edx,Map
  1016.         mov     esi,[_buffer]
  1017.         mov     ecx,[_size]
  1018.         xor     edi,edi
  1019.         dec     edi
  1020. .1:     test    ecx,ecx
  1021.         jz      .end
  1022.         inc     edi
  1023.         mov     al,[esi+edi]
  1024.         cmp     al,0x23
  1025.         jne     @f
  1026.         mov     byte [edx+edi],0
  1027.         loop    .1
  1028.         jmp     .end
  1029. @@:     cmp     al,13
  1030.         jne     @f
  1031.         add     esi,2
  1032.         dec     edi
  1033.         sub     ecx,2
  1034.         jmp     .1
  1035. @@:     sub     al,48
  1036.         mov     byte [edx+edi],al
  1037.         loop    .1
  1038. .end:   mcall   68,13,[_buffer]
  1039.  
  1040.         xor     ecx,ecx
  1041. @@:     mov     byte [SolveMap+ecx],0
  1042.         inc     ecx
  1043.         cmp     ecx,9*9
  1044.         jb      @b
  1045.  
  1046.         mov     [Ticks],0
  1047.         mcall   26,9
  1048.         mov     [Ticks_new],eax
  1049.  
  1050.         clc
  1051. ret
  1052.  
  1053.  
  1054.  
  1055.  
  1056. align 4
  1057. myimport:
  1058. edit_box_draw   dd      aEdit_box_draw
  1059. edit_box_key    dd      aEdit_box_key
  1060. edit_box_mouse  dd      aEdit_box_mouse
  1061. version_ed      dd      aVersion_ed
  1062.                 dd      0
  1063.                 dd      0
  1064. aEdit_box_draw  db 'edit_box',0
  1065. aEdit_box_key   db 'edit_box_key',0
  1066. aEdit_box_mouse db 'edit_box_mouse',0
  1067. aVersion_ed     db 'version_ed',0
  1068.  
  1069. edit1 edit_box 240,2,2,Bckgrd_clr,0x6a9480,0,0xAABBCC,0,4096,buf_cmd_lin,ed_focus,2,0,0
  1070.  
  1071. func_70:
  1072.  .func_n dd ?
  1073.  .param1 dd 0
  1074.  .param2 dd 0
  1075.  .param3 dd ?
  1076.  .param4 dd ?
  1077.  .rezerv db 0
  1078.  .name dd ?
  1079.  
  1080. if lang eq ru
  1081. title db '‘㤮ªã',0
  1082. txt:
  1083. .dif db "‘«®¦­®áâì (+/-):",0
  1084. .new db '®¢ ï (N)',0
  1085. .space db '¥è¥­¨¥ (à®¡¥«)',0
  1086. .check db 'à®¢¥à¨âì (C)',0
  1087. .check_yes db           '¥è¥­¨¥ ­ ©¤¥­®',0
  1088. .check_no = .nosolve
  1089. .time db "‚६ï (T)   :",0
  1090. .own_map db '‚¢¥áâ¨ á¢®î ‘ã¤®ªã ¤«ï à¥è¥­¨ï (I)',0
  1091. .nosolve db             '¥ à¥è¥­®         ',0
  1092. .solve db '¥è¨âì (R)',0
  1093. .save db '‘®åà ­¨âì (S)',0
  1094. .save_solve db '‘®åà ­¨âì à¥è¥­¨¥ (A)',0
  1095. .error db 'Žè¨¡ª ',0
  1096. .load db '‡ £à㧨âì (L)',0
  1097. .enter db 'Enter',0
  1098. else
  1099. title db 'Sudoku',0
  1100. txt:
  1101. .dif db "Difficult (+/-)",0
  1102. .new db 'New (N)',0
  1103. .space db 'Solution (Space)',0
  1104. .check db 'Check (C)',0
  1105. .check_yes db           'Right            ',0
  1106. .check_no db            'Not right        ',0
  1107. .time db " Time (T)   :",0
  1108. .own_map db 'Input your own Sudoku (I)',0
  1109. .nosolve db             'It is not solved',0
  1110. .solve db 'Solve (R)',0
  1111. .save db 'Save (S)',0
  1112. .save_solve db 'Save solution (A)',0
  1113. .error db 'Error';,0
  1114. .load db 'Load (L)',0
  1115. .enter db 'Enter',0
  1116. endf
  1117.  
  1118. system_path db '/sys/lib/'
  1119. boxlib_name db 'box_lib.obj',0
  1120.  
  1121. X db 1
  1122. Y db 1
  1123.  
  1124. Pltr:
  1125. .ch dd Bckgrd_clr,Chg_nmb_clr
  1126. .chk dd Square_clr,Chg_nmb_clr
  1127. .fx dd Bckgrd_clr,Fix_nmb_clr
  1128. .fxk dd Square_clr,Fix_nmb_clr
  1129.  
  1130. align 4
  1131. FONT file "SUDOKU.FNT"
  1132. ; «¨âàë:
  1133.  
  1134.  
  1135. I_END:
  1136. align 16
  1137. Map     rb 9*9
  1138. SolveMap rb 9*9
  1139. RealMap rb 9*9
  1140. TempMap rb 9*9
  1141.  
  1142. cur_dir_path    rb 4096
  1143. buf_cmd_lin     rb 4096
  1144. bufferfinfo     rb 40
  1145. Ticks_new rd 1  ;dd 0
  1146. Ticks rd 1      ;dd 0
  1147. flags rw 1
  1148. threat_stack rd 32      ;: times 32 dd 0
  1149.  
  1150. D_END:
  1151. ;¡¨â 0: á¬. ¯¥à¥¤ draw_pole
  1152. ;1: 1-â ©¬¥à ¢ª«îçñ­
  1153. ;2: ¢ draw_pole ¨ key
  1154. ;3: 1-¯®ª § âì à¥èñ­­ãî ª àâã
  1155. ;4: in draw_one_symbol
  1156. ;5: in Timer
  1157. ;6: 1 ­  íªà ­¥ ®ª­® ‘®åà ­¥­¨ï/‡ £à㧪¨
  1158. ;7: box_lib is not loaded
  1159. ;8: 0 - á®åà ­¨âì 1 - § £à㧨âì
  1160. ;9: 1 - 㢥«¨ç¨âì ¢ëá®âã ®ª­ 
  1161. ;10: 1 - á®åà ­¨âì à¥è¥­¨¥
  1162. ;15 1 - ¯à®¢¥àª  ¯à¨ ­ ¦ â¨¨ ª« ¢¨è¨ ‘ (¤«ï CheckSudoku)