Subversion Repositories Kolibri OS

Rev

Rev 551 | Go to most recent revision | 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.         push    48
  262.         pop     eax
  263.         push    3
  264.         pop     ebx
  265.         mov     ecx, color_table
  266.         push    4*10
  267.         pop     edx
  268.         int     0x40    ; get color table
  269.         push    12
  270.         pop     eax
  271.         push    1
  272.         pop     ebx
  273.         int     0x40    ; start redraw
  274.         push    ebx
  275.         xor     eax, eax
  276.         mov     ebx, 100*65536 + WindowWidth
  277.         mov     ecx, 100*65536 + WindowHeight
  278.         add     ecx, [SkinHeight]
  279.         mov     edx, 4C0C0C0h
  280.         int     0x40    ; define window
  281.         mov     al, 71
  282.         pop     ebx
  283.         mov     ecx, caption
  284.         int     0x40    ; set caption
  285.         call    draw_aux
  286.         call    draw_field
  287.         push    12
  288.         pop     eax
  289.         push    2
  290.         pop     ebx
  291.         int     0x40
  292.         ret
  293.  
  294. caption db      'Memory Blocks L&V Edition',0
  295.  
  296. generate:
  297. ; generate random field
  298.         xor     edi, edi
  299. .loop:
  300.         call    random
  301.         cmp     [field_items+edx], 0
  302.         jnz     .loop
  303.         mov     eax, edi
  304.         shr     eax, 1
  305.         inc     eax
  306.         mov     [field_items+edx], al
  307.         inc     edi
  308.         cmp     edi, FieldWidth*FieldHeight
  309.         jb      .loop
  310.         ret
  311.  
  312. draw_field_item:
  313. ; in: eax=field item
  314. ; out: nothing
  315. ; destroys: eax,ebx,ecx,edx,esi
  316.         mov     esi, eax
  317.         lea     edx, [eax+0x80000000+100]
  318.         push    8
  319.         pop     eax
  320.         int     0x40    ; delete old button
  321.         mov     ebx, [xstart+esi*4]
  322.         shl     ebx, 16
  323.         mov     bl, ButtonWidth
  324.         mov     ecx, [ystart+esi*4]
  325.         add     ecx, [SkinHeight]
  326.         shl     ecx, 16
  327.         mov     cl, ButtonHeight
  328.         lea     edx, [esi+0x40000000+100]
  329.         int     0x40    ; define new button
  330.         ror     ecx, 16
  331.         sub     ecx, [SkinHeight]
  332.         ror     ecx, 16
  333.         mov     al, [field_status+esi]
  334.         dec     eax
  335.         js      draw_closed_item
  336.         jz      draw_current_item
  337. draw_opened_item:
  338.         mov     edx, 0x94AECE
  339.         call    draw_frame
  340.         mov     edx, 0xEFEBEF
  341.         add     ebx, 0xFFFF
  342.         add     ecx, 0xFFFF
  343.         mov     al, 13
  344.         int     0x40
  345.         jmp     draw_item_image
  346. draw_current_item:
  347.         push    ebx ecx
  348.         mov     edx, 0x94AECE
  349.         call    draw_frame
  350.         pop     ecx ebx
  351.         add     ebx, 10000h
  352.         add     ecx, 10000h
  353.         push    ebx ecx
  354.         mov     bl, ButtonWidth-2
  355.         mov     cl, ButtonHeight-2
  356.         mov     edx, 0x94DB00
  357.         call    draw_frame
  358.         pop     ecx ebx
  359.         add     ebx, 10000h
  360.         add     ecx, 10000h
  361.         mov     bl, ButtonWidth-4
  362.         mov     cl, ButtonHeight-4
  363.         mov     edx, 0x94DB00
  364.         call    draw_frame
  365.         add     ebx, 10000h
  366.         add     ecx, 10000h
  367.         mov     bl, ButtonWidth-5
  368.         mov     cl, ButtonHeight-5
  369.         mov     edx, 0xEFEBEF
  370.         int     0x40
  371. draw_item_image:
  372. ;       push    7
  373. ;       pop     eax
  374. ;       movzx   ebx, [field_items+esi]
  375. ;       dec     ebx
  376. ;       imul    ebx, ImageWidth*ImageHeight*3
  377. ;       add     ebx, images
  378. ;       mov     ecx, ImageWidth*10000h+ImageHeight
  379. ;       mov     edx, [xstart+esi*4]
  380. ;       shl     edx, 16
  381. ;       add     edx, [ystart+esi*4]
  382. ;       add     edx, 3*10001h
  383. ;       add     edx, [SkinHeight]
  384. ;       int     0x40
  385.         push    65
  386.         pop     eax
  387.         movzx   ebx, [field_items+esi]
  388.         dec     ebx
  389.         imul    ebx, ImageWidth*ImageHeight
  390.         add     ebx, images
  391.         mov     ecx, ImageWidth*10000h+ImageHeight
  392.         mov     edx, [xstart+esi*4]
  393.         shl     edx, 16
  394.         add     edx, [ystart+esi*4]
  395.         add     edx, 3*10001h
  396.         add     edx, [SkinHeight]
  397.         push    8
  398.         pop     esi
  399.         mov     edi, palette
  400.         xor     ebp, ebp
  401.         int     0x40
  402.         ret
  403. draw_closed_item:
  404.         mov     edx, 0x94AECE
  405.         call    draw_frame
  406.         push    38
  407.         pop     eax
  408.         shr     ebx, 16
  409.         inc     ebx
  410.         imul    ebx, 0x10001
  411.         push    ebx
  412.         add     ebx, ButtonWidth-2
  413.         shr     ecx, 16
  414.         inc     ecx
  415.         imul    ecx, 0x10001
  416.         mov     edx, 0xFFFFFF
  417.         int     0x40
  418.         pop     ebx
  419.         push    ecx
  420.         add     ecx, ButtonHeight-3
  421.         int     0x40
  422.         pop     ecx
  423.         push    ebx ecx
  424.         add     ebx, ButtonWidth-2
  425.         shr     ecx, 16
  426.         add     ecx, ButtonHeight-2
  427.         imul    ecx, 0x10001
  428.         mov     edx, 0xDEDEDE
  429.         int     0x40
  430.         pop     ecx
  431.         push    ecx
  432.         movzx   ebx, bx
  433.         imul    ebx, 0x10001
  434.         add     ecx, 10000h+ButtonHeight-3
  435.         int     0x40
  436.         pop     ecx ebx
  437.         add     ebx, 10000h
  438.         mov     bx, ButtonWidth-3
  439.         add     ecx, 10000h
  440.         mov     cx, ButtonHeight-3
  441.         mov     al, 13
  442.         mov     edx, 0xBDC7D6
  443.         int     0x40
  444.         ret
  445.  
  446. draw_field:
  447.         xor     ebx, ebx
  448.         xor     ecx, ecx
  449.         mov     edi, xstart
  450. .loop:
  451.         mov     eax, ebx
  452.         imul    eax, SpaceWidth
  453.         add     eax, 9
  454.         stosd
  455.         mov     eax, ecx
  456.         imul    eax, SpaceHeight
  457.         add     eax, 4
  458.         mov     [edi+ystart-xstart-4], eax
  459.         lea     eax, [edi-xstart-4]
  460.         shr     eax, 2
  461.         push    ebx ecx edi
  462.         call    draw_field_item
  463.         pop     edi ecx ebx
  464.         inc     ecx
  465.         cmp     ecx, FieldHeight
  466.         jb      .loop
  467.         xor     ecx, ecx
  468.         inc     ebx
  469.         cmp     ebx, FieldWidth
  470.         jb      .loop
  471.         ret
  472.  
  473. draw_aux:
  474.         push    13
  475.         pop     eax
  476.         mov     ebx, 5*65536 + 425
  477.         mov     ecx, [SkinHeight]
  478.         shl     ecx, 16
  479.         add     ecx, 256*65536 + 1
  480.         mov     edx, 0xFFFFFF
  481.         int     0x40
  482.         add     ecx, 1*65536 + 29
  483.         mov     edx, [color_table+5*4]
  484.         int     0x40
  485.         push    8
  486.         pop     eax
  487.         mov     ebx, 14*65536 + 107
  488.         add     ecx, 3*65536 - 7
  489.         push    5
  490.         pop     edx
  491.         mov     esi, [color_table+6*4]
  492.         int     0x40
  493.         push    4
  494.         pop     eax
  495.         mov     ebx, 27*65536 + 268
  496.         add     ebx, [SkinHeight]
  497.         mov     ecx, [color_table+7*4]
  498.         or      ecx, 0x80000000
  499.         mov     edx, aNewGame_ru
  500.         cmp     [CurLanguage], 0
  501.         jz      @f
  502.         mov     edx, aNewGame_en
  503. @@:
  504.         int     0x40
  505.         mov     ebx, 155*65536 + 268
  506.         add     ebx, [SkinHeight]
  507.         mov     ecx, [color_table+8*4]
  508.         or      ecx, 0x80000000
  509.         mov     edx, aCount_ru
  510.         cmp     [CurLanguage], 0
  511.         jz      @f
  512.         mov     edx, aCount_en
  513. @@:
  514.         int     0x40
  515.         call    draw_count
  516.         mov     al, 13
  517.         mov     ecx, [SkinHeight]
  518.         shl     ecx, 16
  519.         mov     ebx, 405*65536 + 2
  520.         add     ecx, 265*65536 + 2
  521.         mov     edx, 0xBDCBDE
  522.         int     0x40
  523.         mov     ebx, 403*65536 + 6
  524.         add     ecx, (270*65536 + 6) - (265*65536 + 2)
  525.         int     0x40
  526.         mov     ebx, 411*65536 + 6
  527.         add     ecx, (275*65536 + 6) - (270*65536 + 6)
  528.         int     0x40
  529.         mov     ebx, 412*65536 + 9
  530.         add     ecx, (262*65536 + 8) - (275*65536 + 6)
  531.         mov     edx, 0xD6D7CE
  532.         int     0x40
  533.         ret
  534.  
  535. draw_count:
  536.         mov     edi, string_for_number+15
  537.         mov     eax, [count]
  538.         push    10
  539.         pop     ecx
  540. @@:
  541.         xor     edx, edx
  542.         div     ecx
  543.         dec     edi
  544.         add     dl, '0'
  545.         mov     [edi], dl
  546.         test    eax, eax
  547.         jnz     @b
  548.         mov     al, 4
  549.         mov     ebx, [SkinHeight]
  550.         add     ebx, 195*65536 + 268
  551.         mov     ecx, [color_table+8*4]
  552.         or      ecx, 0xC0000000
  553.         mov     edx, edi
  554.         mov     edi, [color_table+5*4]
  555.         int     0x40
  556.         ret
  557.  
  558. random:
  559. ; in: nothing
  560. ; out: edx = random value in [0..FieldWidth*FieldHeight-1]
  561. ; destroys: eax,ecx,edx
  562.         rdtsc
  563.         xor     edx, eax
  564.         not     edx
  565.         mov     eax, [RandSeed]
  566.         ror     eax, 3
  567.         xor     eax, 0DEADBEEFh
  568.         add     eax, edx
  569.         mov     [RandSeed], eax
  570.         add     eax, edx
  571.         xor     edx, edx
  572.         push    FieldWidth*FieldHeight
  573.         pop     ecx
  574.         div     ecx
  575.         ret
  576.  
  577. i_end:
  578.  
  579. SkinHeight      dd      ?
  580. color_table     rd      10
  581. RandSeed        dd      ?
  582. FirstClick      dd      ?
  583. SecondClick     dd      ?
  584. string_for_number       rb      16
  585. xstart          rd      60
  586. ystart          rd      60
  587.  
  588. align 1000h
  589. stk     rb      1000h
  590. mem:
  591.