Subversion Repositories Kolibri OS

Rev

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

  1. use32
  2.     org 0x0
  3.     db  'MENUET01'
  4.     dd  0x01
  5.     dd  _preSTART
  6.     dd  I_END
  7.     dd  0x4000
  8.     dd  0x4000
  9.     dd  0x0,0x0
  10.  
  11. include '..\..\macros.inc'
  12. include 'lang.inc'
  13. include 'draw_window.inc'
  14. include 'ball_operations.inc'
  15. include 'basic_alg.inc'
  16.  
  17. _preSTART:
  18.         mcall   66, 1, 1        ;¯à¨­¨¬ ¥¬ ᪠­-ª®¤ë
  19.         mcall   3                               ;randomize
  20.         ror     eax, 16
  21.         mov     [TC_U_SYSTEM_RANDSEED], eax     ;from PPro "system.inc"
  22.  
  23. new_game:
  24.         ;®¡­ã«¥­¨¥ ¬ âà¨æë
  25.         mov     eax, 0
  26.         mov     ecx, 81 / 4
  27.         mov     edi, lineBall
  28.         rep     stosd
  29.         stosb
  30.  
  31.         mov     [score], 0
  32.         mov     [countAllBall], 0
  33.         mov     [current], 0
  34.         mov     ecx, 5
  35.         @@:
  36.            push ecx
  37.            mov  ebx, 7
  38.            call random
  39.            inc  dl
  40.            call add_new_ball
  41.            pop  ecx
  42.            loop @B
  43.         call generate_new___new_color
  44.  
  45. START:
  46.         draw_window
  47.    still:
  48.         mcall   10
  49.  
  50.         dec     eax
  51.         jz      START   ; ¯¥à¥à¨á®¢ âì ®ª­®
  52.         dec     eax
  53.         jnz     button  ;¥á«¨ ­¥ ª« ¢¨è  - §­ ç¨â ª­®¯ª 
  54.  
  55.    key:                 ; ­ ¦ â¨¥ ª« ¢¨è¨
  56.         mcall   2       ; ¯®«ãç ¥¬ ª®¤ ª« ¢¨è¨
  57.         cmp     ah, 60
  58.         je      new_game
  59.         jmp     still
  60.  
  61.    button:              ; ­ ¦ â¨¥ ª­®¯ª¨
  62.         mcall   17
  63.         shr     eax, 8
  64.         cmp     ax, 1   ; ¥á«¨ ª­®¯ª  ¢ë室 ?
  65.         je      .exit
  66.  
  67.         ;¯à®¢¥à¨¬, ­¥ ¯ãáâ  «¨ ª«¥âª 
  68.         mov     edx, [current]
  69.         test    byte [eax + lineBall - 2], 0x7
  70.         jz      .blank
  71.  
  72.         ;¯à®¢¥à¨¬ ­¥ ¡ë«  «¨ íâ  ª«¥âª  㦥 ¢ë¡à ­ 
  73.         cmp     eax, edx
  74.         je      .double_choice
  75.  
  76.         mov     [current], eax
  77.         call    choice_ball
  78.         call    paint_ball      ;á­ ç «  ¯à®à¨á㥬 ­®¢ë© ¢ë¡à ­­ë© è à¨ª
  79.  
  80.         test    edx, edx        ;cmp [current], 0
  81.         jz      still
  82.         mov     eax, edx
  83.  
  84.    @@:
  85.         call    redraw_cell     ;  㦥 ¯®â®¬ 㡥६ à ¬ªã ®â áâ à®£®
  86.         call    paint_ball
  87.         jmp     still
  88.  
  89.    .double_choice:
  90.         mov     [current], 0
  91.         jmp     @B
  92.  
  93.    .blank:      ;­ ¦ â ï ª­®¯ª  - ¯ãáâ 
  94.         test    edx, edx        ;cmp [current], 0
  95.         jz      still
  96.         mov     [dest], eax     ;ª­®¯ªã ­ §­ ç¥­¨ï -> ¢ [dest]
  97.         mov     eax, edx        ;¯ à ¬¥âà ¢ eax
  98.         call    test_path       ;¢ë§ë¢ ¥¬ ४ãàá¨î test_path
  99.         call    zero_cheked
  100.         jnc     still
  101.  
  102. ;^^^^^^^^^^^^^^^^^ move_ball    proc
  103.         mov     eax, [current]
  104.         mov     cl, byte [eax + lineBall - 2]
  105.         mov     byte [eax + lineBall - 2], 0
  106.         mov     eax, [dest]
  107.         mov     byte [eax + lineBall - 2], cl
  108.  
  109.         mov     eax, [current]
  110.         call    redraw_cell
  111.         mov     eax, [dest]
  112.         call    paint_ball
  113.         mov     [current], 0
  114. ;^^^^^^^^^^^^^^^^^ move_ball    endp
  115.  
  116.         call    find_line
  117.         call    vanish_balls
  118.         call    zero_cheked
  119.  
  120.         cmp     [countVanishBall], 0
  121.         je      new_3_balls
  122.         movzx   eax, [countVanishBall]
  123.         inc     eax
  124.         add     [score], eax
  125.         sub     [countAllBall], al
  126.         call    redraw_score
  127.         jmp     still
  128.  
  129.    .exit:
  130.         mcall   -1      ;¢ë室¨¬
  131.  
  132. new_3_balls:
  133.  
  134.         rept    3 num
  135.         {
  136.            mov  dl, [newColor#num]
  137.            call add_new_ball
  138.            call test_new_ball
  139.            cmp  [countAllBall],81
  140.            je   .record_li
  141.         }
  142.  
  143.         call    generate_new___new_color
  144.         call    paint_new_color
  145.         jmp     still
  146.  
  147.         .record_li:
  148.            mov  eax, [score]
  149.            cmp  eax, [record]
  150.            jbe  still
  151.            mov  [record], eax
  152.            jmp  START
  153.  
  154. zero_cheked:    ;®¡­ã«¥­¨¥ ¬ âà¨æë cheked
  155.         pushfd
  156.         mov     eax, lineBall
  157.         mov     ecx, 81
  158.         @@:
  159.            and  byte [eax], 0x7
  160.            inc  eax
  161.            loop @B
  162.         popfd
  163.         ret
  164.  
  165. random:                 ; edx := random [0..(ebx-1)]
  166.         mov     eax, 134775813
  167.         mul     [TC_U_SYSTEM_RANDSEED]
  168.         inc     eax
  169.         mov     [ TC_U_SYSTEM_RANDSEED], eax
  170.         xor     edx, edx
  171.         div     ebx
  172.         ret
  173.  
  174. generate_new___new_color:
  175.         rept    3 num
  176.         {
  177.            mov  ebx, 7
  178.            call random
  179.            inc  dl
  180.            mov  [newColor#num], dl
  181.         }
  182.         ret
  183.  
  184. add_new_ball:   ;¢ dl - 梥â è à¨ª 
  185.         mov     ebp, edx
  186.         mov     ebx, 81
  187.         sub     bl, [countAllBall]
  188.         call    random
  189.         mov     ecx, edx
  190.         mov     eax, lineBall-1
  191.         inc     ecx
  192.         @@:
  193.            inc  eax
  194.            test byte [eax], 0x7
  195.            jnz  @B
  196.            loop @B
  197.  
  198.         ;⥯¥àì ã ­ á ¢ eax -  ¤à¥á ­ è¥£® è à¨ª 
  199.         mov     edx, ebp
  200.         or      byte [eax], dl
  201.         inc     [countAllBall]
  202.         ret
  203.  
  204. test_new_ball:
  205.         ;¯®«ã稬 ID ª­®¯ª¨
  206.         sub     eax, lineBall-2
  207.         call    paint_ball
  208.  
  209.         call    find_line
  210.         call    vanish_balls
  211.         call    zero_cheked
  212.  
  213.         cmp     [countVanishBall], 0
  214.         je      @F
  215.         movzx   eax, [countVanishBall]
  216.         inc     eax
  217.         add     [score], eax
  218.         sub     [countAllBall], al
  219.         call    redraw_score
  220.         @@:
  221.         ret
  222.  
  223. if lang eq ru
  224.         szTitle  db '–¢¥â­ë¥ «¨­¨¨ v 0.2',0
  225.         szNewGame db 'F2 - ­®¢ ï ¨£à ',0
  226.         szRecord db '¥ª®à¤',0
  227.         szScore  db 'Žçª¨',0
  228. else
  229.         szTitle  db 'Color lines v 0.2',0
  230.         szNewGame db 'F2 - new game',0
  231.         szRecord db 'Record',0
  232.         szScore  db 'Score',0
  233. end if
  234.  
  235.  
  236. blank   = 0xB8C2D3
  237. brown   = 0x804000
  238. red     = 0xff0000
  239. yellow  = 0xffff00
  240. green   = 0x008000
  241. cyan    = 0x00ffff
  242. blue    = 0x0000ff
  243. purple  = 0x800080
  244.  
  245. tableColor      dd blank,brown,red,yellow,green,cyan,blue,purple
  246.  
  247. lineCoord:
  248.                 rept    9 coory:0
  249.                 {
  250.                    rept 9 coorx:0
  251.                    \{
  252.                         dw coorx*256+coory
  253.  
  254.                    \}
  255.                 }
  256.  
  257. record  dd 25
  258.  
  259. lineBall db 81 dup ?
  260. score   dd ?
  261. baseAddr dd ?
  262. current dd ?
  263. dest    dd ?
  264.  
  265. newColor1 db ?
  266. newColor2 db ?
  267. newColor3 db ?
  268.  
  269. countVanishBall db ?
  270. countAllBall    db ?
  271.  
  272. TC_U_SYSTEM_RANDSEED    dd      ?
  273. bitID   dd ?
  274.  
  275. I_END: