Subversion Repositories Kolibri OS

Rev

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

  1. use32
  2.         db      'MENUET01'
  3.         dd      1
  4.         dd      start
  5.         dd      i_end
  6.         dd      mem
  7.         dd      mem
  8.         dd      0
  9.         dd      0
  10.  
  11. ; field size in items
  12. FieldWidth = 10
  13. FieldHeight = 6
  14.  
  15. ; size of one picture in pixels
  16. ImageWidth = 32
  17. ImageHeight = 32
  18.  
  19. ; size of one button in pixels
  20. ButtonWidth = ImageWidth + 6
  21. ButtonHeight = ImageHeight + 6
  22.  
  23. SpaceWidth = ButtonWidth + 4
  24. SpaceHeight = ButtonHeight + 4
  25.  
  26. ; size of window in pixels
  27. WindowWidth = 434
  28. WindowHeight = 291      ; excluding skin height
  29.  
  30. if FieldWidth*FieldHeight mod 2
  31. error field size must be an even number!
  32. end if
  33.  
  34. draw_frame:
  35. ; in: ebx=[xstart]*65536+[xsize],ecx=[ystart]*65536+[ysize],edx=color
  36. ;       ystart is relative to SkinHeight
  37. ; out: nothing
  38. ; destroys: eax,ecx
  39.         push    13
  40.         pop     eax
  41.         ror     ecx, 16
  42.         add     ecx, [SkinHeight]
  43.         push    ecx
  44.         shl     ecx, 16
  45.         inc     ecx
  46.         int     0x40    ; ebx=[xstart]*65536+[xsize], ecx=[ystart]*65536+1
  47.         ror     ecx, 16
  48.         add     cx, [esp+2]
  49.         ror     ecx, 16
  50.         int     0x40    ; ebx=[xstart]*65536+[xsize], ecx=([ystart]+[ysize])*65536+1
  51.         pop     ecx
  52.         ror     ecx, 16
  53.         push    ebx
  54.         mov     bx, 1
  55.         int     0x40    ; ebx=[xstart]*65536+1, ecx=[ystart]*65536+[ysize]
  56.         ror     ebx, 16
  57.         add     bx, [esp]
  58.         ror     ebx, 16
  59.         inc     ecx
  60.         int     0x40    ; ebx=([xstart]+[xsize])*65536+1, ecx=[ystart]*65536+([ysize]+1)
  61.         dec     ecx
  62.         pop     ebx
  63.         ret
  64.  
  65. draw_button:
  66. ; in: ebx=[xstart]*65536+[xsize],ecx=[ystart]*65536+[ysize],edx=button color,esi=id
  67. ;       ystart is relative to SkinHeight
  68. ; out: nothing
  69. ; destroys: eax
  70.         push    edx
  71.         mov     edx, 0x94AECE
  72.         call    draw_frame
  73.         mov     edx, 0xFFFFFF
  74.         push    ebx
  75.         add     ebx, 0xFFFF
  76.         push    ecx
  77.         add     ecx, 0x10000
  78.         mov     cx, 1
  79.         int     0x40    ; ebx=([xstart]+1)*65536+([xsize]-1), ecx=([ystart]+1)*65536+1
  80.         pop     ecx
  81.         mov     edx, 0xC0C0C0
  82.         dec     ebx
  83.         push    ecx
  84.         shr     ecx, 16
  85.         add     ecx, [esp]
  86.         dec     ecx
  87.         shl     ecx, 16
  88.         inc     ecx
  89.         int     0x40    ; ebx=([xstart]+1)*65536+([xsize]-2), ecx=([ystart]+[ysize]-1)*65536+1
  90.         pop     ecx
  91.         mov     edx, 0xFFFFFF
  92.         push    ecx
  93.         add     ecx, 0xFFFF
  94.         push    ebx
  95.         mov     bx, 1
  96.         int     0x40    ; ebx=([xstart]+1)*65536+1, ecx=([ystart]+1)*65536+([ysize]-1)
  97.         pop     ebx
  98.         push    ebx
  99.         shr     ebx, 16
  100.         add     ebx, [esp]
  101.         shl     ebx, 16
  102.         inc     ebx
  103.         mov     edx, 0xC0C0C0
  104.         add     ecx, 0xFFFF
  105.         int     0x40    ; ebx=([xstart]+[xsize]-1)*65536+1, ecx=([ystart]+2)*65536+([ysize]-2)
  106.         pop     ebx
  107.         pop     ecx
  108.         pop     ebx
  109.         pop     edx
  110.         push    ebx ecx
  111.         add     ebx, 20000h - 3
  112.         add     ecx, 20000h - 3
  113.         int     0x40
  114.         pop     ecx ebx
  115.         push    edx
  116.         mov     edx, esi
  117.         or      edx, 0x80000000
  118.         mov     al, 8
  119.         int     0x40
  120.         mov     edx, esi
  121.         or      edx, 0x40000000
  122.         int     0x40
  123.         pop     edx
  124.         ret
  125.  
  126. ;digits_ptr     dd      0
  127. ;digits_str     rb      11
  128.  
  129. ;images:
  130. ;       file    'mblocks.raw'
  131. images:
  132.         file    'mblocksi.raw'
  133. palette:
  134.         file    'mblocksp.raw'
  135.  
  136. aNewGame_ru     db      '®¢ ï ¨£à (F2)',0
  137. aCount_ru       db      ' ‘ç¥â:',0
  138. aRu             db      'RU',0
  139. aNewGame_en     db      'New  game (F2)',0
  140. aCount_en       db      'Count:',0
  141. aEn             db      'EN',0
  142.  
  143. CurLanguage     db      0       ; 0=russian, 1=english
  144.  
  145. field_status    rb      60      ; status of field elements: 0=closed, 1=temporarily opened, 2=permanently opened
  146. field_items     rb      60      ; items in field
  147.  
  148. count           dd      0
  149.  
  150. start:
  151.         push    26
  152.         pop     eax
  153.         push    5
  154.         pop     ebx
  155.         int     0x40
  156.         cmp     eax, 4
  157.         setnz   [CurLanguage]
  158.         call    generate
  159. ; get skin height
  160.         push    48
  161.         pop     eax
  162.         push    4
  163.         pop     ebx
  164.         int     0x40
  165.         mov     [SkinHeight], eax
  166. ; no previous click
  167.         mov     eax, 0xBAD
  168.         mov     [FirstClick], eax
  169.         mov     [SecondClick], eax
  170. ; draw window
  171. redraw:
  172.         call    draw_window
  173. ; events loop
  174. evloop:
  175.         push    10
  176.         pop     eax
  177.         int     0x40
  178.         dec     eax
  179.         jz      redraw
  180.         dec     eax
  181.         jz      key
  182.         mov     al, 17
  183.         int     0x40
  184.         shr     eax, 8
  185. ;       cmp     eax, 6
  186. ;       jz      set_lang
  187.         cmp     eax, 5
  188.         jz      new_game
  189.         cmp     eax, 1
  190.         jnz     field_pressed
  191.         push    -1
  192.         pop     eax
  193.         int     0x40
  194. key:
  195.         mov     al, 2
  196.         int     0x40
  197.         cmp     ah, '3'         ; F2?
  198.         jnz     evloop
  199. new_game:
  200.         mov     edi, field_status
  201.         mov     ecx, FieldWidth*FieldHeight/2
  202.         xor     eax, eax
  203.         rep     stosd
  204.         mov     [count], eax
  205.         mov     eax, 0xBAD
  206.         mov     [FirstClick], eax
  207.         mov     [SecondClick], eax
  208.         call    generate
  209.         call    draw_field
  210. @@:
  211.         call    draw_aux
  212.         jmp     evloop
  213. ;set_lang:
  214. ;       xor     [CurLanguage], 1
  215. ;       jmp     @b
  216. field_pressed:
  217.         sub     eax, 100
  218.         cmp     [field_status+eax], 0
  219.         jnz     cont
  220.         mov     ebx, [FirstClick]
  221.         mov     ecx, [SecondClick]
  222.         cmp     ebx, 0xBAD
  223.         jz      first_click
  224.         cmp     ecx, 0xBAD
  225.         jz      second_click
  226.         mov     dl, [field_items+ecx]
  227.         cmp     [field_items+ebx], dl
  228.         jnz     dont_match
  229.         mov     [field_status+ebx], 2
  230.         mov     [field_status+ecx], 2
  231.         jmp     @f
  232. dont_match:
  233.         mov     [field_status+ebx], 0
  234.         mov     [field_status+ecx], 0
  235. @@:
  236.         push    eax ecx
  237.         mov     eax, ebx
  238.         call    draw_field_item
  239.         pop     eax
  240.         call    draw_field_item
  241.         mov     [SecondClick], 0xBAD
  242.         pop     eax
  243.         mov     [FirstClick], eax
  244.         jmp     @f
  245. second_click:
  246.         cmp     [FirstClick], eax
  247.         jz      cont
  248.         mov     [SecondClick], eax
  249. @@:
  250.         mov     [field_status+eax], 1
  251.         call    draw_field_item
  252.         inc     [count]
  253. cont:
  254.         call    draw_count
  255.         jmp     evloop
  256. first_click:
  257.         mov     [FirstClick], eax
  258.         jmp     @b
  259.  
  260. draw_window:
  261.         mov eax, 48
  262.         mov ebx, 3
  263.         mov ecx, color_table
  264.         mov edx, 40
  265.         int     0x40    ; get color table
  266.  
  267.         mov eax, 12
  268.         mov ebx, 1
  269.         int     0x40    ; start redraw
  270.        
  271.         xor     eax, eax
  272.         mov     ebx, 100*65536 + WindowWidth
  273.         mov     ecx, 100*65536 + WindowHeight
  274.         add     ecx, [SkinHeight]
  275.         mov     edx, 0x14C0C0C0
  276.         mov     edi, caption
  277.         int     0x40
  278.        
  279.         call    draw_aux
  280.         call    draw_field
  281.        
  282.         mov eax, 12
  283.         mov ebx, 2
  284.         int     0x40    ; end redraw
  285.        
  286.         ret
  287.  
  288. caption db      'Memory Blocks L&V Edition',0
  289.  
  290. generate:
  291. ; generate random field
  292.         xor     edi, edi
  293. .loop:
  294.         call    random
  295.         cmp     [field_items+edx], 0
  296.         jnz     .loop
  297.         mov     eax, edi
  298.         shr     eax, 1
  299.         inc     eax
  300.         mov     [field_items+edx], al
  301.         inc     edi
  302.         cmp     edi, FieldWidth*FieldHeight
  303.         jb      .loop
  304.         ret
  305.  
  306. draw_field_item:
  307. ; in: eax=field item
  308. ; out: nothing
  309. ; destroys: eax,ebx,ecx,edx,esi
  310.         mov     esi, eax
  311.         lea     edx, [eax+0x80000000+100]
  312.         push    8
  313.         pop     eax
  314.         int     0x40    ; delete old button
  315.         mov     ebx, [xstart+esi*4]
  316.         shl     ebx, 16
  317.         mov     bl, ButtonWidth
  318.         mov     ecx, [ystart+esi*4]
  319.         add     ecx, [SkinHeight]
  320.         shl     ecx, 16
  321.         mov     cl, ButtonHeight
  322.         lea     edx, [esi+0x40000000+100]
  323.         int     0x40    ; define new button
  324.         ror     ecx, 16
  325.         sub     ecx, [SkinHeight]
  326.         ror     ecx, 16
  327.         mov     al, [field_status+esi]
  328.         dec     eax
  329.         js      draw_closed_item
  330.         jz      draw_current_item
  331. draw_opened_item:
  332.         mov     edx, 0x94AECE
  333.         call    draw_frame
  334.         mov     edx, 0xEFEBEF
  335.         add     ebx, 0xFFFF
  336.         add     ecx, 0xFFFF
  337.         mov     al, 13
  338.         int     0x40
  339.         jmp     draw_item_image
  340. draw_current_item:
  341.         push    ebx ecx
  342.         mov     edx, 0x94AECE
  343.         call    draw_frame
  344.         pop     ecx ebx
  345.         add     ebx, 10000h
  346.         add     ecx, 10000h
  347.         push    ebx ecx
  348.         mov     bl, ButtonWidth-2
  349.         mov     cl, ButtonHeight-2
  350.         mov     edx, 0x94DB00
  351.         call    draw_frame
  352.         pop     ecx ebx
  353.         add     ebx, 10000h
  354.         add     ecx, 10000h
  355.         mov     bl, ButtonWidth-4
  356.         mov     cl, ButtonHeight-4
  357.         mov     edx, 0x94DB00
  358.         call    draw_frame
  359.         add     ebx, 10000h
  360.         add     ecx, 10000h
  361.         mov     bl, ButtonWidth-5
  362.         mov     cl, ButtonHeight-5
  363.         mov     edx, 0xEFEBEF
  364.         int     0x40
  365. draw_item_image:
  366. ;       push    7
  367. ;       pop     eax
  368. ;       movzx   ebx, [field_items+esi]
  369. ;       dec     ebx
  370. ;       imul    ebx, ImageWidth*ImageHeight*3
  371. ;       add     ebx, images
  372. ;       mov     ecx, ImageWidth*10000h+ImageHeight
  373. ;       mov     edx, [xstart+esi*4]
  374. ;       shl     edx, 16
  375. ;       add     edx, [ystart+esi*4]
  376. ;       add     edx, 3*10001h
  377. ;       add     edx, [SkinHeight]
  378. ;       int     0x40
  379.         push    65
  380.         pop     eax
  381.         movzx   ebx, [field_items+esi]
  382.         dec     ebx
  383.         imul    ebx, ImageWidth*ImageHeight
  384.         add     ebx, images
  385.         mov     ecx, ImageWidth*10000h+ImageHeight
  386.         mov     edx, [xstart+esi*4]
  387.         shl     edx, 16
  388.         add     edx, [ystart+esi*4]
  389.         add     edx, 3*10001h
  390.         add     edx, [SkinHeight]
  391.         push    8
  392.         pop     esi
  393.         mov     edi, palette
  394.         xor     ebp, ebp
  395.         int     0x40
  396.         ret
  397. draw_closed_item:
  398.         mov     edx, 0x94AECE
  399.         call    draw_frame
  400.         push    38
  401.         pop     eax
  402.         shr     ebx, 16
  403.         inc     ebx
  404.         imul    ebx, 0x10001
  405.         push    ebx
  406.         add     ebx, ButtonWidth-2
  407.         shr     ecx, 16
  408.         inc     ecx
  409.         imul    ecx, 0x10001
  410.         mov     edx, 0xFFFFFF
  411.         int     0x40
  412.         pop     ebx
  413.         push    ecx
  414.         add     ecx, ButtonHeight-3
  415.         int     0x40
  416.         pop     ecx
  417.         push    ebx ecx
  418.         add     ebx, ButtonWidth-2
  419.         shr     ecx, 16
  420.         add     ecx, ButtonHeight-2
  421.         imul    ecx, 0x10001
  422.         mov     edx, 0xDEDEDE
  423.         int     0x40
  424.         pop     ecx
  425.         push    ecx
  426.         movzx   ebx, bx
  427.         imul    ebx, 0x10001
  428.         add     ecx, 10000h+ButtonHeight-3
  429.         int     0x40
  430.         pop     ecx ebx
  431.         add     ebx, 10000h
  432.         mov     bx, ButtonWidth-3
  433.         add     ecx, 10000h
  434.         mov     cx, ButtonHeight-3
  435.         mov     al, 13
  436.         mov     edx, 0xBDC7D6
  437.         int     0x40
  438.         ret
  439.  
  440. draw_field:
  441.         xor     ebx, ebx
  442.         xor     ecx, ecx
  443.         mov     edi, xstart
  444. .loop:
  445.         mov     eax, ebx
  446.         imul    eax, SpaceWidth
  447.         add     eax, 9
  448.         stosd
  449.         mov     eax, ecx
  450.         imul    eax, SpaceHeight
  451.         add     eax, 4
  452.         mov     [edi+ystart-xstart-4], eax
  453.         lea     eax, [edi-xstart-4]
  454.         shr     eax, 2
  455.         push    ebx ecx edi
  456.         call    draw_field_item
  457.         pop     edi ecx ebx
  458.         inc     ecx
  459.         cmp     ecx, FieldHeight
  460.         jb      .loop
  461.         xor     ecx, ecx
  462.         inc     ebx
  463.         cmp     ebx, FieldWidth
  464.         jb      .loop
  465.         ret
  466.  
  467. draw_aux:
  468.         push    13
  469.         pop     eax
  470.         mov     ebx, 5*65536 + 425
  471.         mov     ecx, [SkinHeight]
  472.         shl     ecx, 16
  473.         add     ecx, 256*65536 + 1
  474.         mov     edx, 0xFFFFFF
  475.         int     0x40
  476.         add     ecx, 1*65536 + 29
  477.         mov     edx, [color_table+5*4]
  478.         int     0x40
  479.         push    8
  480.         pop     eax
  481.         mov     ebx, 14*65536 + 107
  482.         add     ecx, 3*65536 - 7
  483.         push    5
  484.         pop     edx
  485.         mov     esi, [color_table+6*4]
  486.         int     0x40
  487.         push    4
  488.         pop     eax
  489.         mov     ebx, 27*65536 + 268
  490.         add     ebx, [SkinHeight]
  491.         mov     ecx, [color_table+7*4]
  492.         or      ecx, 0x80000000
  493.         mov     edx, aNewGame_ru
  494.         cmp     [CurLanguage], 0
  495.         jz      @f
  496.         mov     edx, aNewGame_en
  497. @@:
  498.         int     0x40
  499.         mov     ebx, 155*65536 + 268
  500.         add     ebx, [SkinHeight]
  501.         mov     ecx, [color_table+8*4]
  502.         or      ecx, 0x80000000
  503.         mov     edx, aCount_ru
  504.         cmp     [CurLanguage], 0
  505.         jz      @f
  506.         mov     edx, aCount_en
  507. @@:
  508.         int     0x40
  509.         call    draw_count
  510.         mov     al, 13
  511.         mov     ecx, [SkinHeight]
  512.         shl     ecx, 16
  513.         mov     ebx, 405*65536 + 2
  514.         add     ecx, 265*65536 + 2
  515.         mov     edx, 0xBDCBDE
  516.         int     0x40
  517.         mov     ebx, 403*65536 + 6
  518.         add     ecx, (270*65536 + 6) - (265*65536 + 2)
  519.         int     0x40
  520.         mov     ebx, 411*65536 + 6
  521.         add     ecx, (275*65536 + 6) - (270*65536 + 6)
  522.         int     0x40
  523.         mov     ebx, 412*65536 + 9
  524.         add     ecx, (262*65536 + 8) - (275*65536 + 6)
  525.         mov     edx, 0xD6D7CE
  526.         int     0x40
  527.         ret
  528.  
  529. draw_count:
  530.         mov     edi, string_for_number+15
  531.         mov     eax, [count]
  532.         push    10
  533.         pop     ecx
  534. @@:
  535.         xor     edx, edx
  536.         div     ecx
  537.         dec     edi
  538.         add     dl, '0'
  539.         mov     [edi], dl
  540.         test    eax, eax
  541.         jnz     @b
  542.         mov     al, 4
  543.         mov     ebx, [SkinHeight]
  544.         add     ebx, 195*65536 + 268
  545.         mov     ecx, [color_table+8*4]
  546.         or      ecx, 0xC0000000
  547.         mov     edx, edi
  548.         mov     edi, [color_table+5*4]
  549.         int     0x40
  550.         ret
  551.  
  552. random:
  553. ; in: nothing
  554. ; out: edx = random value in [0..FieldWidth*FieldHeight-1]
  555. ; destroys: eax,ecx,edx
  556.         rdtsc
  557.         xor     edx, eax
  558.         not     edx
  559.         mov     eax, [RandSeed]
  560.         ror     eax, 3
  561.         xor     eax, 0DEADBEEFh
  562.         add     eax, edx
  563.         mov     [RandSeed], eax
  564.         add     eax, edx
  565.         xor     edx, edx
  566.         push    FieldWidth*FieldHeight
  567.         pop     ecx
  568.         div     ecx
  569.         ret
  570.  
  571. i_end:
  572.  
  573. SkinHeight      dd      ?
  574. color_table     rd      10
  575. RandSeed        dd      ?
  576. FirstClick      dd      ?
  577. SecondClick     dd      ?
  578. string_for_number       rb      16
  579. xstart          rd      60
  580. ystart          rd      60
  581.  
  582. align 1000h
  583. stk     rb      1000h
  584. mem:
  585.