Subversion Repositories Kolibri OS

Rev

Rev 2275 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; 10.06.2010 staper@inbox.ru
  2.  
  3. ;Œ £¨ç¥áª¨© ª¢ ¤à â - íâ® ­ ¡®à â ª¨å 楫ëå ç¨á¥«, çâ® ¨å á㬬ë
  4. ;¢ áâப å, á⮫¡æ å (०¥ ¢ ¤¨ £®­ «ïå) à ¢­ë.
  5.  
  6. ;à¨¬¥à:
  7.  
  8. ; 16 3  2  13
  9. ; 5  10 11 8
  10. ; 9  6  7  12
  11. ; 4  15 14 1
  12.  
  13. use32
  14. org     0x0
  15.  db     'MENUET01'
  16.  dd     0x1, START, I_END, (D_END+100) and not 3,  (D_END+100) and not 3, 0, 0
  17.  
  18. ;–¢¥â :
  19. Bckgrd_clr      equ 0xffffff    ;ä®­
  20. Brdr_line_clr   equ 0xb0b0b0    ;«¨­¨¨ ¯® £à ­¨æ ¬
  21. Inter_line_clr  equ 0xb0b0b0    ;¢­ãâ७­¨¥ «¨­¨¨
  22. Square_clr      equ 0xdddddd    ;梥⠪ãàá®à 
  23. Fix_nmb_clr     equ 0x83459     ;áâ â¨ç­®¥ §­ ç¥­¨¥
  24. Chg_nmb_clr     equ 0;x008d8d   ;¯¥à¥¬¥­­®¥ §­ ç¥­¨¥
  25. Text_clr        equ 0x000000    ;⥪áâ
  26. Message_clr     equ 0x0000ff    ;á®®¡é¥­¨ï
  27.  
  28. max_dif equ 10
  29. min_dif equ 2
  30. len_kub equ 30  ;¤«¨­  áâ®à®­ë ª¢ ¤à â¨ª 
  31. beg_x   equ 40  ;ª®®à¤¨­ â  • «¥¢®£® ¢¥àå­¥£® 㣫 
  32. beg_y   equ 50  ;ª®®à¤¨­ â  Y «¥¢®£® ¢¥àå­¥£® 㣫 
  33. sym_x equ 20
  34. sym_y equ 20
  35. win_x equ 400   ;è¨à¨­  ®ª­ 
  36. win_y equ 400   ;¢ëá®â  ®ª­ 
  37.  
  38.  
  39. DEBUG equ 0
  40.  
  41. macro dbg_dec num
  42. {pushad
  43. newline
  44. debug_print_dec num
  45. popad
  46. }
  47.  
  48. include '../../../macros.inc'
  49. ;include 'debug.inc'
  50. include 'editbox_ex.mac'
  51. include 'lang.inc'
  52.  
  53.  
  54. START:
  55.         ;mcall  40,7
  56.  
  57. redraw_all:
  58.         mcall   12,1
  59.         mcall   48,4
  60.         add     eax,100*65536+win_x
  61.         mov     ecx,eax
  62.         mcall   0,100*65536+win_y,,(0x34000000+Bckgrd_clr),,title
  63.         movzx   eax,[Difficult]
  64.         mov     ebx,len_kub
  65.         xor     edx,edx
  66.         mul     ebx
  67.         add     eax,beg_x*65536+beg_x
  68.         xchg    eax,ebx
  69.         mcall   38,,beg_y*65536+beg_y,Brdr_line_clr
  70.         mov     edx,Inter_line_clr
  71.         movzx   esi,[Difficult]
  72.         dec     esi
  73.   @@:   add     ecx,len_kub*65536+len_kub
  74.         mcall
  75.         dec     esi
  76.         jnz     @b
  77.         add     ecx,len_kub*65536+len_kub
  78.         mcall   ,,,Brdr_line_clr
  79.  
  80.         movzx   eax,[Difficult]
  81.         mov     ecx,len_kub
  82.         xor     edx,edx
  83.         mul     ecx
  84.         add     eax,(beg_y+1)*65536+beg_y-1
  85.         xchg    eax,ecx
  86.         mov     ebx,beg_x*65536+beg_x
  87.         mcall   38,,,Brdr_line_clr
  88.         mov     edx,Inter_line_clr
  89.         movzx   esi,[Difficult]
  90.         dec     esi
  91.  
  92.   @@:   add     ebx,len_kub*65536+len_kub
  93.         mcall
  94.         dec     esi
  95.         jnz     @b
  96.         add     ebx,len_kub*65536+len_kub
  97.         mcall   ,,,Brdr_line_clr
  98.  
  99.         mcall   8,<4,78>,<4,13>,2,0xbbbbbb
  100.         mcall   4,<8,7>,(0x80000000+Text_clr),txt.clear
  101.         mcall   ,<105,7>,,txt.dif
  102.  
  103.  
  104.         call    show_level
  105.  
  106.         push    dword Map;esi;  mov     esi,Map
  107.         mcall   12,2
  108. draw_pole:
  109.         if DEBUG
  110.         call    SysMsgBoardNum  ;show esp
  111.         endf
  112.  
  113.         movzx   eax,[Y]
  114.         dec     al
  115.         movzx   ebx,[Difficult]
  116.         mul     bl
  117.         mov     bl,[X]
  118.         add     al,bl
  119.         pop     esi     ;       mov     esi,Map
  120.         push    eax     ;ªãàá®à稪
  121.         movzx   eax,[Difficult]
  122.         mov     ebx,eax
  123.         mul     eax
  124.         sub     eax,ebx
  125.         mov     edi,eax
  126.         pop     eax
  127.         push    eax
  128. ;       mov     edi,81-9
  129.         movzx   ebp,[Difficult]
  130.         mov     ebx,beg_x*65536+beg_x+sym_x
  131.         mov     ecx,beg_y*65536+beg_y+sym_y
  132.         call    out_numbers
  133.         pop     eax
  134.         call    out_sum
  135.  
  136. still:
  137.         mcall   10
  138.  
  139.         dec     al
  140.         jz      redraw_all
  141.         dec     al
  142.         jz      key
  143.         dec     al
  144.         jnz     still
  145. ;button:
  146.         mcall   17
  147.         cmp     ah,1
  148.         jne     @f
  149.         mcall   -1
  150. .clear:
  151. @@:     mov     ecx,max_dif*max_dif
  152.         mov     esi,Map
  153. @@:     mov     byte [esi+ecx-1],0
  154.         loop    @b
  155.         jmp     redraw_all
  156.  
  157. key:
  158.         mcall   2
  159.  
  160. .43:    cmp     ah,43           ;+
  161.         jne     .45
  162.         cmp     [Difficult],max_dif
  163.         je      still
  164.         inc     [Difficult]
  165.         jmp     redraw_all
  166.         jmp     still
  167. .45:                            ;-
  168.         cmp     ah,45
  169.         jne     .99
  170.         cmp     [Difficult],min_dif
  171.         je      still
  172.         dec     [Difficult]
  173.         movzx   eax, [Difficult]
  174.         cmp     al, [X]
  175.         jae     @f
  176.         mov     [X], al
  177. @@:
  178.         cmp     al, [Y]
  179.         jae     @f
  180.         mov     [Y], al
  181. @@:
  182.         jmp     redraw_all
  183.         jmp     still
  184.  
  185. .99:    cmp     ah,0x58
  186.         je      @f
  187.         cmp     ah,0x78
  188.         jne     .39
  189. @@:     jmp     still.clear
  190.  
  191. .39:    cmp     ah,0x39
  192.         ja      .110
  193.         cmp     ah,0x30
  194.         jb      still
  195.         sub     ah,0x30
  196.         mov     cl,ah
  197.  
  198.         movzx   eax,[Y]
  199.         dec     al
  200.         mov     ebx,max_dif;[Difficult]
  201.         mul     bl
  202.         mov     bl,[X]
  203.         dec     bl
  204.         add     al,bl
  205.  
  206.         mov     esi,Map
  207.         bt      [flags],9
  208.         jnc     @f
  209.         mov     bl,[esi+eax]
  210.         push    eax
  211.         mov     ax,10
  212.         xor     dl,dl
  213.         mul     bl
  214.         add     cl,al
  215.         pop     eax
  216.         mov     [esi+eax],cl
  217.         btr     [flags],9
  218.         jmp     .onedraw
  219.    @@:  mov     [esi+eax],cl
  220.         bts     [flags],9
  221.         jmp     .onedraw
  222.  
  223.  
  224. .110:   cmp     ah,110          ;n
  225.         jne     .176
  226. .new_game:
  227.         jmp     redraw_all
  228.  
  229. .176:   cmp     ah,176 ;ªãàá®àë
  230.         jne     .177
  231.         call    draw_one_symbol
  232.         dec     [X]
  233.         cmp     [X],1
  234.         jge     @f
  235.         push    eax
  236.         movzx   eax,[Difficult]
  237.         mov     [X],al
  238.         pop     eax
  239. @@:     btr     [flags],9
  240.         jmp     .onedraw
  241. .177:   cmp     ah,177
  242.         jne     .178
  243.         call    draw_one_symbol
  244.         inc     [Y]
  245.         push    eax
  246.         movzx   eax,[Difficult]
  247.         cmp     [Y],al
  248.         jbe     @f
  249.         mov     [Y],1
  250. @@:     pop     eax
  251.         btr     [flags],9
  252.         jmp     .onedraw
  253. .178:   cmp     ah,178
  254.         jne     .179
  255.         call    draw_one_symbol
  256.         dec     [Y]
  257.         cmp     [Y],1
  258.         jge     @f
  259.         push    eax
  260.         movzx   eax,[Difficult]
  261.         mov     [Y],al
  262.         pop     eax
  263. @@:     btr     [flags],9
  264.         jmp     .onedraw
  265. .179:   cmp     ah,179
  266.         jne     still
  267.         call    draw_one_symbol
  268.         inc     [X]
  269.         push    eax
  270.         movzx   eax,[Difficult]
  271.         cmp     [X],al
  272.         jbe     @f
  273.         mov     [X],1
  274. @@:     btr     [flags],9
  275.         pop     eax
  276. .onedraw:
  277.         bts     [flags],4
  278.         call    draw_one_symbol
  279.         call    out_one_sum
  280.         jmp     still ;.todraw
  281.  
  282. show_level:
  283.         movzx   ecx,[Difficult]
  284.         mcall   47,0x80020000,,<205,5>,(0x50000000+Text_clr),Bckgrd_clr
  285. ret
  286.  
  287.  
  288. draw_one_symbol:
  289.         movzx   eax,[X]
  290.         mov     ebx,len_kub*65536+len_kub
  291.         mul     ebx
  292.         xchg    eax,ebx
  293.         add     ebx,(beg_x*65536+beg_y-len_kub*65536+len_kub)
  294.         movzx   eax,[Y]
  295.         mov     ecx,len_kub*65536+len_kub
  296.         mul     ecx
  297.         xchg    eax,ecx
  298.         add     ecx,(beg_y*65536+beg_y+sym_y-len_kub*65536+len_kub)
  299.         movzx   eax,[Y]
  300.         dec     al
  301.         push    ebx
  302.         movzx   ebx,[Difficult]
  303.         mul     bl
  304.         mov     bl,[X]
  305.         add     al,bl
  306.         dec     al
  307.         pop     ebx
  308.         mov     esi,Map
  309.         add     esi,eax
  310.         push    dword 0 ;­¥ ªãàá®à
  311.         bt      [flags],4
  312.         jnc     @f
  313.         mov     dword [esp],1 ;ªãàá®à
  314.         btr     [flags],4
  315. @@:     mov     edi,0
  316.         mov     ebp,1
  317.         call    out_numbers
  318.         pop     eax
  319. ret
  320.  
  321.  
  322. out_numbers:
  323.         push    ebx ecx esi
  324.         shr     ebx,16
  325.         inc     bx
  326.         shl     ebx,16
  327.         add     ebx,len_kub-1
  328.         shr     ecx,16
  329.         inc     cx
  330.         shl     ecx,16
  331.         add     ecx,len_kub-1
  332.         mov     edx,Bckgrd_clr
  333.         push    ebp
  334.         dec     dword [esp+4*5]
  335.         jnz     @f
  336.         mov     edx,Square_clr
  337. @@:     mcall   13
  338.         pop     ebp
  339.         pop     esi
  340.  
  341.         push    ebx edx
  342.         mov     eax,esi
  343.         sub     eax,Map-1
  344.         xor     edx,edx
  345.         movzx   ebx,[Difficult]
  346.         div     ebx
  347.         push    edx
  348.         xor     edx,edx
  349.         mov     ebx,max_dif
  350.         mul     ebx
  351.         pop     edx
  352.         test    edx,edx
  353.         jnz     @f
  354.         movzx   edx,[Difficult]
  355.         sub     eax,max_dif
  356. @@:     add     eax,edx
  357.         mov     al,[eax+Map-1]
  358.         pop     edx ebx
  359.         test    al,al
  360.  
  361. ;       cmp     byte [esi],0
  362.         jnz     .changeable_number
  363.         jmp     .null
  364. .end:
  365.         inc     esi
  366.         dec     ebp
  367.         jnz     out_numbers
  368.         test    edi,edi
  369.         jz      @f
  370.         push    ebx edx
  371.         movzx   eax,[Difficult]
  372.         sub     edi,eax
  373.         mov     ebp,eax
  374.         mov     ebx,len_kub*65536
  375.         xor     edx,edx
  376.         mul     ebx
  377.         push    eax
  378.         movzx   eax,[Difficult]
  379.         mov     ebx,len_kub
  380.         mul     ebx
  381.         pop     ebx
  382.         add     eax,ebx
  383.         pop     edx
  384.         pop     ebx
  385.         sub     ebx,eax
  386. ;       add     ebx,-9*24*65536-9*24
  387.         add     ecx,len_kub*65536+len_kub
  388.         jmp     out_numbers
  389.   @@:
  390. ret
  391.  
  392.  
  393. .null:
  394.         pop     ecx ebx
  395.         add     ebx,len_kub*65536+len_kub
  396.         jmp     .end
  397. .changeable_number:
  398.         push    esi
  399.         shr     ebx,16
  400.         shr     ecx,16
  401.         mov     dx,bx
  402.         shl     edx,16
  403.         mov     dx,cx
  404.         add     edx,8*65536+4
  405.  
  406.         push    ebx edx
  407.         mov     eax,esi
  408.         sub     eax,Map-1
  409.         xor     edx,edx
  410.         movzx   ebx,[Difficult]
  411.         div     ebx
  412.         push    edx
  413.         xor     edx,edx
  414.         mov     ebx,max_dif
  415.         mul     ebx
  416.         pop     edx
  417.         test    edx,edx
  418.         jnz     @f
  419.         movzx   edx,[Difficult]
  420.         sub     eax,max_dif
  421. @@:     add     eax,edx
  422.         pop     edx ebx
  423.        
  424.         movzx   ebx,byte [eax+Map-1];[esi]
  425.  
  426.  
  427.         push    esi ebp edi edx
  428.         sub     edx,2*65536-3
  429.         push    edx
  430.         xchg    eax,ebx
  431.         mov     ebx,10
  432.         xor     edx,edx
  433.         div     ebx
  434.         mov     ebx,edx
  435.         pop     edx
  436.        
  437.         push    ebx
  438.  
  439.         test    eax,eax
  440.         jz      .only_first_num
  441.  
  442. ;       bt      [flags],9
  443. ;       jc      .only_first_num
  444.  
  445.         xchg    eax,ebx
  446.  
  447.         shl     bx,4
  448.         add     ebx,FONT
  449.         mov     ecx,8*65536+16
  450.  
  451.         mov     edi,Pltr.ch
  452.         cmp     dword [esp+4*9],0
  453.         jne     @f
  454.         mov     edi,Pltr.chk
  455. @@:     mov     esi,1
  456.         mov     ebp,0
  457.         mcall   65
  458.  
  459. .only_first_num:
  460.         pop     ebx
  461.         shl     bl,4
  462.  
  463.         add     ebx,FONT
  464.         mov     ecx,8*65536+16
  465.         add     edx,8*65536
  466.         mov     edi,Pltr.ch
  467.         cmp     dword [esp+4*8],0
  468.         jne     @f
  469.         mov     edi,Pltr.chk
  470. @@:     mov     esi,1
  471.         mov     ebp,0
  472.         mcall   65
  473.         pop     edx edi ebp esi
  474.         pop     esi ecx ebx
  475.         add     ebx,len_kub*65536+len_kub
  476.         jmp     .end
  477.  
  478. out_sum:
  479.         movzx   eax,[Difficult]
  480.         push    eax
  481.         mov     esi,Map
  482.         mov     edi,out_sum_buf
  483. .1:     xor     ebx,ebx
  484.         xor     ecx,ecx
  485.         xor     edx,edx
  486. .2:     mov     dl,[ebx+esi]
  487.         add     ecx,edx
  488.         inc     ebx
  489.         cmp     ebx,[esp]
  490.         jne     .2
  491.         mov     word [edi],cx
  492.         add     edi,2
  493.         add     esi,max_dif
  494.         dec     eax
  495.         jnz     .1
  496.  
  497.         push    out_sum_buf
  498.         movzx   eax,[Difficult]
  499.         mov     ebx,len_kub*65536
  500.         xor     edx,edx
  501.         mul     ebx
  502.         add     eax,40*65536
  503.         push    eax
  504.         mov     edx,(beg_x-30)*65536+beg_y+10
  505.         mov     ebx,0x30000
  506.         mov     esi,0x50000000+Fix_nmb_clr
  507.         mov     edi,Bckgrd_clr
  508.  
  509. .3:     mov     ecx,[esp+4]
  510.         mov     cx,[ecx]
  511.         shl     ecx,16
  512.         shr     ecx,16
  513.         mcall   47
  514.         push    edx
  515.         add     edx,[esp+4]
  516.         mcall  
  517.         pop     edx
  518.         add     edx,len_kub
  519.         add     dword [esp+4],2
  520.         dec     dword [esp+8]
  521.         jnz     .3
  522.         pop     eax
  523.         pop     eax
  524.         pop     eax
  525.  
  526.  
  527.         movzx   eax,[Difficult]
  528.         push    eax
  529.         mov     esi,Map
  530.         mov     edi,out_sum_buf
  531.         xor     ebx,ebx
  532. .4:     xor     ecx,ecx
  533.         xor     edx,edx
  534.         mov     ebx,[esp]
  535. .5:     mov     dl,[esi]
  536.         add     ecx,edx
  537.         add     esi,max_dif
  538.         dec     ebx
  539.         jnz     .5
  540.         mov     word [edi],cx
  541.         add     edi,2
  542.         push    eax
  543.         mov     eax,max_dif
  544.         xor     edx,edx
  545.         mul     dword [esp+4]
  546.         dec     eax
  547.         sub     esi,eax
  548.         pop     eax
  549.         dec     eax
  550.         jnz     .4
  551.  
  552.         push    out_sum_buf
  553.         movzx   eax,[Difficult]
  554.         mov     ebx,len_kub
  555.         xor     edx,edx
  556.         mul     ebx
  557.         add     eax,35
  558.         push    eax
  559.         mov     edx,(beg_x+5)*65536+beg_y-20
  560.         mov     ebx,0x30000
  561.         mov     esi,0x50000000+Fix_nmb_clr
  562.         mov     edi,Bckgrd_clr
  563.  
  564. .6:     mov     ecx,[esp+4]
  565.         mov     ecx,[ecx]
  566.         shl     ecx,16
  567.         shr     ecx,16
  568.         mcall   47
  569.         push    edx
  570.         add     edx,[esp+4]
  571.         mcall  
  572.         pop     edx
  573.         add     edx,len_kub*65536;[esp]
  574.         add     dword [esp+4],2
  575.         dec     dword [esp+8]
  576.         jnz     .6
  577.         pop     eax
  578.         pop     eax
  579.         pop     eax
  580. ret
  581.  
  582.  
  583.  
  584. out_one_sum:
  585.         movzx   ecx,[Difficult]
  586.         mov     esi,Map
  587.         xor     edx,edx
  588.  
  589.         movzx   eax,[Y]
  590.         dec     al
  591.         mov     ebx,max_dif
  592.         mul     bl
  593.         add     esi,eax
  594. @@:     mov     al,[esi]
  595.         inc     esi
  596.         add     edx,eax
  597.         loop    @b
  598.  
  599.         mov     ecx,edx
  600.         movzx   eax,[Difficult]
  601.         mov     ebx,len_kub*65536
  602.         xor     edx,edx
  603.         mul     ebx
  604.         add     eax,40*65536
  605.         push    eax
  606.         movzx   eax,[Y]
  607.         dec     eax
  608.         mov     ebx,len_kub
  609.         xor     edx,edx
  610.         mul     ebx
  611.         mov     edx,(beg_x-30)*65536+beg_y+10
  612.         add     edx,eax
  613.         mov     ebx,0x30000
  614.         mov     esi,0x50000000+Fix_nmb_clr
  615.         mov     edi,Bckgrd_clr
  616.  
  617.         mcall   47
  618.         add     edx,[esp]
  619.         mcall  
  620.         pop     eax
  621.  
  622.  
  623.  
  624.  
  625.         movzx   ecx,[Difficult]
  626.         mov     esi,Map
  627.         xor     edx,edx
  628.  
  629.         movzx   eax,[X]
  630.         dec     al
  631.         add     esi,eax
  632. @@:     mov     al,[esi]
  633.         add     esi,max_dif
  634.         add     edx,eax
  635.         loop    @b
  636.  
  637.         mov     ecx,edx
  638.         movzx   eax,[Difficult]
  639.         mov     ebx,len_kub
  640.         xor     edx,edx
  641.         mul     ebx
  642.         add     eax,35
  643.         push    eax
  644.         movzx   eax,[X]
  645.         dec     eax
  646.         mov     ebx,len_kub*65536
  647.         xor     edx,edx
  648.         mul     ebx
  649.         mov     edx,eax
  650.         add     edx,(beg_x+5)*65536+beg_y-20
  651.         mov     ebx,0x30000
  652.         mov     esi,0x50000000+Fix_nmb_clr
  653.         mov     edi,Bckgrd_clr
  654.  
  655.         mcall   47
  656.         add     edx,[esp]
  657.         mcall  
  658.  
  659.         pop     edx
  660.  
  661. ret
  662.  
  663.  
  664.  
  665.  
  666. if DEBUG
  667. SysMsgBoardNum: ;warning: destroys eax,ebx,ecx,esi
  668.         mov     ebx,esp
  669.         mov     ecx,8
  670.         mov     esi,(number_to_out+1)
  671. .1:
  672.         mov     eax,ebx
  673.         and     eax,0xF
  674.         add     al,'0'
  675.         cmp     al,(10+'0')
  676.         jb      @f
  677.         add     al,('A'-'0'-10)
  678. @@:
  679.         mov     [esi+ecx],al
  680.         shr     ebx,4
  681.         loop    .1
  682.         dec     esi
  683.         mcall   71,1,number_to_out
  684. ret
  685.  
  686. number_to_out   db '0x00000000',13,10,0
  687. endf
  688.  
  689.  
  690.  
  691.  
  692.  
  693. if lang eq ru
  694. title db 'Œ £¨ç¥áª¨© ª¢ ¤à â',0
  695. txt:
  696. .dif db "‘«®¦­®áâì (+/-):",0
  697. .clear db 'Žç¨áâ¨âì (x)',0
  698. else
  699. title db 'Magical square',0
  700. txt:
  701. .dif db "Difficult (+/-)",0
  702. .clear db 'Clear (x)',0
  703. endf
  704.  
  705.  
  706.  
  707.  
  708. align 4
  709. ; «¨âàë:
  710. Pltr:
  711. .ch dd Bckgrd_clr,Chg_nmb_clr
  712. .chk dd Square_clr,Chg_nmb_clr
  713. .fx dd Bckgrd_clr,Fix_nmb_clr
  714. .fxk dd Square_clr,Fix_nmb_clr
  715.  
  716. FONT file "MSquare.fnt"
  717.  
  718. X db 1
  719. Y db 1
  720.  
  721. Difficult db 3
  722.  
  723. I_END:
  724. align 16
  725. Map     rb max_dif*max_dif
  726. out_sum_buf rw max_dif
  727.  
  728. flags rw 1
  729.  
  730. D_END:
  731. ;¡¨â 0: á¬. ¯¥à¥¤ draw_pole
  732. ;2: ¢ draw_pole ¨ key
  733. ;4: in draw_one_symbol
  734. ;9: ¢¢¥¤ñ­  ¯¥à¢ ï æ¨äà  ç¨á« 
  735.