Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;10.11.2009 staper@inbox.ru
  2.  
  3. use32
  4. org     0x0
  5. db      'MENUET01'
  6. dd      0x1, START, I_END, (I_END+600) and not 3, (I_END+600) and not 3, 0x0, 0x0
  7.  
  8. remote_ip db 010,010,010,002
  9. server_port dd 0x9876
  10. client_port dd 0x6789
  11. socknum dd ?
  12.  
  13. DEBUG equ 1
  14.  
  15. include 'macros.inc'
  16. include 'lang.inc'
  17. include 'debug.inc'
  18.  
  19. macro dbg_dec num
  20. {pushad
  21. newline
  22. debug_print_dec num
  23. popad}
  24.  
  25. OP_SOC equ 0 ; UDP only
  26. CL_SOC equ 1
  27. WR_SOC equ 4
  28.  
  29. macro free_socket {
  30. mcall 53,1,[socknum]
  31.  if CL_SOC no equ 1
  32.  mcall 53,CL_SOC,[socknum]
  33.  endf
  34. btr [flags],11
  35. btr [flags],12}
  36.  
  37.  
  38. START:
  39.         mcall   40,10100111b ;á¥âì,¬ëèì
  40.         mcall   3
  41.         mov     [rsx1],ax
  42.         shr     eax,16
  43.         mov     [rsx2],ax
  44.         call    redraw_all
  45.         jmp     draw_pole
  46.  
  47. redraw_all:
  48.         mcall   12,1
  49.         mcall   0,100*65536+432,100*65536+280,0x34FFFFFF,,title
  50.         mcall   38,1*65536+421,27*65536+27,0x00b0b0b0
  51.         mov     edi,10
  52.   @@:   add     ecx,20*65536+20
  53.         mcall
  54.         dec     edi
  55.         jnz     @b
  56.         mcall   ,1*65536+1,27*65536+226,;000000
  57.         mov     edi,21
  58.   @@:   add     ebx,20*65536+20
  59.         mcall
  60.         dec     edi
  61.         jnz     @b
  62.         mcall   13,202*65536+19,27*65536+202,0xFFFFFF
  63.         mcall   4,40*65536+12,0x80000000,text_user
  64.         mcall   ,350*65536+12,,text_cpu
  65.  
  66.         mcall   8,120*65536+70,7*65536+15,3,0xFFFFFF    ;auto_fill
  67.         mcall   ,230*65536+70,,2,                       ;new_game
  68.         mov     ecx,234*65536+15
  69.         bt      [flags],11
  70.         jc      @f
  71.         mcall   ,2*65536+70,,4,                         ;listen
  72. @@:     bt      [flags],12
  73.         jc      @f
  74.         mcall   ,74*65536+70,,5,                        ;connect
  75. @@:     mcall   ,146*65536+70,,6,                       ;disconnect
  76.         mcall   4,135*65536+12,0x80000000,but_new
  77.         mcall   ,240*65536+12,,but_auto
  78.         mcall   ,15*65536+240,,but_lis_con
  79.  
  80.         mcall   12,2
  81. ret
  82.  
  83. draw_pole:
  84.         if DEBUG
  85.         call    SysMsgBoardNum  ;show esp
  86.         endf
  87.  
  88.         mov     esi,table1
  89.         mov     edi,90
  90.         mov     ebp,10
  91.         mov     ebx,1*65536+21
  92.         mov     ecx,27*65536+47
  93.         call    draw_bots
  94.  
  95.         mov     esi,table2
  96.         mov     edi,90
  97.         mov     ebp,10
  98.         mov     ebx,221*65536+241
  99.         mov     ecx,27*65536+47
  100.         call    draw_bots
  101.         cmp     [loc_kill],10
  102.         jne     @f
  103.         mcall   4,69*65536+12,0x80ff0000,text_win
  104.         bts     [flags],5
  105.   @@:   cmp     [rem_kill],10
  106.         jne     @f
  107.         mcall   4,372*65536+12,0x80ff0000,text_win
  108.         bts     [flags],5
  109.   @@:
  110.         cmp     [number_bots],10
  111.         jne     still
  112.         bts     [flags],0
  113. still:
  114.         mcall   23,10
  115.         test    eax,eax
  116.         jz      listen
  117. ;        mcall   10
  118.  
  119.         cmp     eax,6
  120.         je      mouse
  121. ;        cmp     eax,8
  122. ;        je      still
  123.         dec     eax
  124.         jnz     @f
  125.         call    redraw_all
  126.         jmp     draw_pole
  127. @@:     dec     eax
  128.         jz      key
  129.         dec     eax
  130.         jz      button
  131.         jmp     still
  132.  
  133. listen:
  134.         mcall   53,2,[socknum]
  135.         test    eax,eax
  136.         jz      still
  137.         xor     edx,edx
  138.         call    check_header
  139.         jc      still
  140.         mcall   53,2,[socknum]
  141.         test    eax,eax
  142.         jz      still
  143.         mcall   53,3,[socknum]
  144.         push    ebx
  145.         mcall   53,2,[socknum]
  146.         pop     ebx
  147. if DEBUG
  148. debug_print_dec eax
  149. push eax
  150. movzx eax,bl
  151. debug_print_dec eax
  152. pop eax
  153. endf
  154.         cmp     bl,1    ;¯®«ã祭® á®®¡é¥­¨¥ ®â á¥à¢¥à  á à ­¤®¬­ë¬ ç¨á«®¬
  155.         je      .get_first
  156.         cmp     bl,2    ;á¥à¢¥à ¯®«ã稫 ®â¢¥â, ®¯à¥¤¥«ïî騩 ¯®à冷ª 室 
  157.         je      .set_first
  158.         cmp     bl,3    ;®â¬¥­  ᮥ¤¨­¥­¨ï
  159.         je      .close_connect
  160.         cmp     bl,4    ;£¥­¥à æ¨ï ­®¢®© ¨£àë, ®ç¨á⪠ ª àâ
  161.         je      .new_game
  162.         cmp     bl,5    ;®ª®­ç ­¨¥ ¨£àë (¢ë¨£àëè ®¯¯®­¥­â )
  163.         je      .end_game
  164.         cmp     bl,6    ;poluchena koordinata ataki
  165.         je      .get_koord
  166.         cmp     bl,7    ;v otvet posyla'utsya ismen'ennue elementy v table2, max 12 byte = zagolovok 3 bytes + kol-vo elementov + el-ty (max 4*2 bytes)
  167.         je      .get_elem
  168. .free_cash:
  169.         call    check_header.free
  170.         jmp     still
  171. .get_first:
  172. ;       cmp     eax,2
  173. ;       jne     .free_cash
  174.         mcall   53,2,[socknum]
  175. @@:     mcall   53,3,[socknum]
  176.         mov     dl,bl
  177.         shl     edx,8
  178.         mcall   53,2,[socknum]
  179.         test    eax,eax
  180.         jnz     @b
  181.         shr     edx,8
  182.         cmp     dx,[who_first]
  183.         jge     @f
  184.         mov     word [message+2],0x0002 ;I'm first
  185.         mcall   53,WR_SOC,[socknum],4,message
  186.         inc     eax
  187.         jz      button.error
  188.         bts     [flags],13      ;moi hod
  189.         jmp     still
  190. @@:     mov     word [message+2],0x0102 ;He is first
  191.         mcall   53,WR_SOC,[socknum],4,message
  192.         inc     eax
  193.         jz      button.error
  194.         btr     [flags],13
  195.         jmp     still
  196. .set_first:
  197. ;       cmp     eax,1
  198. ;       jne     .free_cash
  199.         mcall   53,2,[socknum]
  200. @@:     mcall   53,3,[socknum]
  201.         dec     bl
  202.         jz      @f
  203.         btr     [flags],13
  204.         jmp     still
  205. @@:     bts     [flags],13
  206.         jmp     still
  207. .close_connect:
  208.         free_socket
  209.         jmp     still
  210. .new_game:
  211.         mov     esi,table2
  212.         mov     ecx,100/4
  213.    @@:  mov     dword [esi],0
  214.         add     esi,4
  215.         loop    @b
  216.         jmp     still
  217. .end_game:
  218.         mov     [rem_kill],10
  219.         bts     [flags],13
  220.         call    redraw_all
  221.         jmp     draw_pole
  222. .buf dw 0xffff
  223. .get_koord:
  224. ;        cmp     eax,1
  225. ;        jne     .free_cash
  226.         mcall   53,2,[socknum]
  227. ;       test    eax,eax
  228. ;       jz      still
  229.         mcall   53,3,[socknum]
  230.         movzx   eax,bl
  231.         cmp     ax,[.buf]
  232.         je      still
  233.         mov     [.buf],ax
  234.         mov     esi,table1
  235.         mov     edi,table1
  236.         mov     bl, byte [edi+eax]
  237.         add     bl,2
  238.         mov     ecx,table1
  239.         call    if_bot_killed
  240.  
  241.         movzx   edx, byte [message+3]
  242.         mov     byte [message+3+1+edx*2],al
  243.         mov     byte [message+3+1+edx*2+1],bl
  244.         inc     byte [message+3]
  245.  
  246.         mov     [table1+eax],bl
  247.         push    ebx
  248.         mov     byte [message+2],7
  249.         mov     edi,5
  250.    .@u: movzx   edx,byte [message+3]
  251.         lea     edx,[edx*2+4]
  252.         mcall   53,WR_SOC,[socknum],,message
  253.         mcall   5,10
  254.         dec     edi
  255.         jnz     .@u
  256.         inc     eax
  257.         jz      button.error
  258.         pop     ebx
  259.         bts     [flags],13      ;ostavliaem hod za soboi
  260.         cmp     bl,3
  261.         jb      @f
  262.         btr     [flags],13      ;peredaem hod
  263.         cmp     bl,4
  264.         jne     @f
  265.         inc     [rem_kill]
  266.         cmp     [rem_kill],10
  267.         jne     draw_pole
  268.         call    redraw_all
  269. @@:     jmp     draw_pole
  270. .buf2 dw 0xffff
  271. .get_elem:
  272.         mcall   53,2,[socknum]
  273. ;       test    eax,eax
  274. ;       jz      still
  275.         mcall   53,3,[socknum]
  276.         movzx   edi,bl          ;chislo elementov
  277.         test    edi,edi
  278.         jz      .free_cash
  279. @@:     mcall   53,2,[socknum]
  280.         mcall   53,3,[socknum]
  281.         movzx   eax,bl
  282.         push    eax
  283.         mcall   53,2,[socknum]
  284.         mcall   53,3,[socknum]
  285.         pop     eax
  286.         cmp     bl,byte [.buf2+1]       ;¯à®¢¥àª  ­  ¯®¢â®à­ë© ¯ ª¥â
  287.         jne     @f
  288.         cmp     al,byte [.buf2]
  289.         je      .free_cash
  290. @@:     mov     byte [.buf2],al
  291.         mov     byte [.buf2+1],bl
  292.         jmp     .00
  293. @@:     mcall   53,3,[socknum]
  294.         movzx   eax,bl
  295.         push    eax
  296.         mcall   53,2,[socknum]
  297.         mcall   53,3,[socknum]
  298.         pop     eax
  299. .00     mov     [table2+eax],bl
  300.         dec     edi
  301.         jz      @f
  302.         mcall   53,2,[socknum]
  303.         test    eax,eax
  304.         jnz     @b
  305. @@:     call    check_header.free
  306.         cmp     byte [.buf2+1],2
  307.         jbe     @f
  308.         bts     [flags],13
  309.         cmp     byte [.buf2+1],4
  310.         jb      draw_pole
  311.         inc     [loc_kill]
  312.         cmp     [loc_kill],10
  313.         jb      draw_pole
  314.         call    redraw_all
  315.         jmp     draw_pole
  316. @@:     btr     [flags],13
  317.         jmp     draw_pole
  318.  
  319.  
  320.  
  321.  
  322. check_header:
  323.         mov     esi,2
  324. @@:     mcall   53,3,[socknum]
  325.         mov     dl,bl
  326.         dec     esi
  327.         jz      @f
  328.         shl     edx,8
  329.         mcall   53,2,[socknum]
  330.         test    eax,eax
  331.         jnz     @b
  332. @@:     xchg    dh,dl
  333.         cmp     dx, word [message]
  334.         jne     .free
  335. if DEBUG
  336. newline
  337. debug_print 'XO packet:'
  338. endf
  339.         clc
  340.         ret
  341. .free:
  342. @@:     mcall   53,3,[socknum]
  343.         mcall   53,2,[socknum]
  344.         test    eax,eax
  345.         jnz     @b
  346. if DEBUG
  347. newline
  348. debug_print 'packet cleared'
  349. endf
  350.         stc
  351. ret
  352.  
  353.  
  354.  
  355.  
  356. key:
  357.         mcall   2
  358.         jmp     still
  359.  
  360. close_prog:
  361.         free_socket     ;-1 ®è¨¡ª 
  362.         mcall   -1
  363.  
  364. button:
  365.         mcall   17
  366.         dec     ah
  367.         jz      close_prog
  368.  
  369.         dec     ah
  370.         jnz      @f
  371.         mov     ecx,(344)/4
  372.         mov     esi,table1
  373.    .@0: mov     dword [esi],0
  374.         add     esi,4
  375.         loop    .@0
  376.         mov     word [listen.buf],0xffff
  377.         mov     word [listen.buf2],0xffff
  378. ;        mov     [flags],1100b   ;auto fill
  379.         btr     [flags],0
  380.         btr     [flags],2
  381.         bts     [flags],3
  382.         mov     [number_bots],0
  383.         call    set_bots
  384.         bts     [flags],0
  385.   .a0:  btr     [flags],5
  386.         bt      [flags],12
  387.         jc      .a1
  388.         bt      [flags],11
  389.         jnc     .a2
  390.   .a1:  mov     byte [message+3],4
  391. ;        mcall   53,WR_SOC,[sicknum],3,message
  392.   .a2:  call    redraw_all
  393.         jmp     draw_pole
  394.   @@:   dec     ah              ;new game
  395.         jnz      @f
  396. .new_game:
  397.         mov     ecx,(344)/4
  398.         mov     esi,table1
  399.    .@1: mov     dword [esi],0
  400.         add     esi,4
  401.         loop    .@1
  402.         mov     word [listen.buf],0xffff
  403.         mov     word [listen.buf2],0xffff
  404.         mov     [number_bots],0
  405. ;        mov     [flags],1100b
  406.         btr     [flags],0
  407.         btr     [flags],2
  408.         btr     [flags],3
  409.         jmp     .a0
  410.  
  411.   @@:   dec     ah
  412.         jnz      @f
  413.         bt      [flags],11
  414.         jc      still
  415.         bt      [flags],12
  416.         jc      still
  417.         mcall   53,OP_SOC,[client_port],[server_port],<dword [remote_ip]>    ;listen
  418. if DEBUG
  419. push eax
  420. dbg_dec eax
  421. debug_print ':socket:listen...'
  422. pop eax
  423. endf
  424.         mov     [socknum],eax   ;-1 ®è¨¡ª 
  425.         inc     eax
  426.         jz      .error
  427.         bts     [flags],11
  428.         xor     eax,eax
  429.         or      ax,-1
  430.         call    random
  431.         mov     [who_first],ax          ;progi soediniaias' sveria'ut eto znachenie, u kogo bol'she, tot nachinaet pervyi
  432.         bts     [flags],14
  433.         call    redraw_all
  434.         jmp     draw_pole
  435.  
  436.   @@:   dec     ah
  437.         jnz      @f
  438.         bt      [flags],11
  439.         jc      still
  440.         bt      [flags],12
  441.         jc      still
  442.         mcall   53,OP_SOC,[server_port],[client_port],<dword [remote_ip]>    ;connect
  443. if DEBUG
  444. push eax
  445. dbg_dec eax
  446. debug_print ':socket:connect...'
  447. pop eax
  448. endf
  449.         mov     [socknum],eax   ;-1 ®è¨¡ª 
  450.         inc     eax
  451.         jz      .error
  452.         bts     [flags],12
  453.         xor     eax,eax
  454.         or      ax,-1
  455.         call    random
  456.         mov     esi,message+2
  457.         mov     byte [esi],1
  458.         mov     [esi+1],ax
  459.         mcall   53,WR_SOC,[socknum],5,message ;-1 ®è¨¡ª 
  460.         inc     eax
  461.         jz      .error
  462.         bts     [flags],14
  463.         call    redraw_all
  464.         jmp     draw_pole
  465.  
  466.   @@:   free_socket     ;-1 ®è¨¡ª       ;disconnect
  467.         call    redraw_all
  468.         jmp     draw_pole
  469.  
  470. .error:
  471. if DEBUG
  472. debug_print 'error on open/sent'
  473. endf
  474.         jmp     still
  475.  
  476. draw_bots:
  477.         cmp     byte [esi],1
  478.         je      .one
  479.         cmp     byte [esi],2
  480.         je      .two
  481.         cmp     byte [esi],3
  482.         je      .three
  483.         cmp     byte [esi],4
  484.         jne     .null
  485.         bts     [flags],4
  486.         jmp     .three
  487.  
  488. .end:
  489.         inc     esi
  490.         dec     ebp
  491.         jnz     draw_bots
  492.         test    edi,edi
  493.         jz      @f
  494.         sub     edi,10
  495.         mov     ebp,10
  496.         add     ebx,-200*65536-200
  497.         add     ecx,20*65536+20
  498.         jmp     draw_bots
  499.   @@:
  500. ret
  501.  
  502. .one:
  503.         push    ebx ecx
  504.         call    .0
  505.         mov     edx,0x00aa66
  506.         mcall   13
  507.         pop     ecx ebx
  508. .null:
  509.         add     ebx,20*65536+20
  510.         jmp     .end
  511. .two:
  512.         push    ebx ecx
  513.         add     ebx,8*65536-6
  514.         add     ecx,12*65536-12
  515.         mcall   38,,,0x508cec
  516.         add     ecx,-6*65536+6
  517.         mcall
  518.         pop     ecx ebx
  519.         jmp     .null
  520. .three:
  521.         push    ebx ecx
  522.         call    .0
  523.         mov     edx,0x00FF0000
  524.         bt      [flags],4
  525.         jnc     @f
  526.         mov     edx,0x00555555
  527.         btr     [flags],4
  528.   @@:   mcall   13
  529.         pop     ecx ebx
  530.         xor     edx,edx
  531.         mcall   38
  532.         add     ecx,20*65536-20
  533.         mcall
  534.         add     ecx,-20*65536+20
  535.         jmp     .null
  536.  
  537. .0:
  538.         shr     ebx,16
  539.         inc     bx
  540.         shl     ebx,16
  541.         add     ebx,19
  542.         shr     ecx,16
  543.         inc     cx
  544.         shl     ecx,16
  545.         add     ecx,19
  546. ret
  547.  
  548. mouse:
  549.         bt      [flags],5
  550.         jc      still
  551.         mcall   37,2
  552.         test    eax,eax
  553.         jz      still
  554.         cmp     al,2
  555.         jg      still
  556.         ;1 - «¥¢ ï ª­®¯ª , 2 - ¯à ¢ ï
  557.         dec     al
  558.         jnz     .mouse_1
  559.         btr     [flags],1
  560.         jmp     @f
  561.   .mouse_1:
  562.         bts     [flags],1
  563.   @@:
  564.         mcall   37,1
  565.         mov     dx,ax
  566.         shr     eax,16
  567.         cmp     dx,27
  568.         jbe     still
  569.         cmp     dx,227
  570.         jge     still
  571.         cmp     ax,1
  572.         jbe     still
  573.         cmp     ax,201
  574.         jge     second_pole
  575.                         ;¯¥à¢®¥ ¯®«¥
  576.         bt      [flags],0
  577.         jc      still
  578.         sub     ax,1
  579.         push    dx
  580.         xor     edx,edx
  581.         mov     cx,20
  582.         div     cx
  583.         pop     dx
  584.         mov     [oX],al
  585.         push    ax
  586.         sub     dx,27
  587.         mov     ax,dx
  588.         xor     dx,dx
  589.         div     cx
  590.         mov     [oY],al
  591.         xor     dx,dx
  592.         mov     cx,10
  593.         mul     cx
  594.         pop     dx
  595.         add     ax,dx
  596.         cmp     ax,100
  597.         jg      still
  598.  
  599. set_bot:
  600.         mov     esi,table1
  601.         bt      [flags],2
  602.         jnc     @f
  603.         mov     esi,table2
  604.   @@:   mov     edi,esi
  605.         add     edi,100
  606.         cmp     [number_bots],6
  607.         jnb     .1paluba
  608.         cmp     [number_bots],3
  609.         jnb     .2paluba
  610.         cmp     [number_bots],0
  611.         je      .4paluba
  612.         jmp     .3paluba
  613.  
  614. .4paluba:
  615.         bt      [flags],1       ;ç¥âëàñ寠«ã¡­ë©
  616.         jnc     @f
  617.         cmp     [oX],6
  618.         jg      _still
  619.         jmp     .41
  620.   @@:   cmp     [oY],6
  621.         jg      _still
  622.   .41:  inc     [number_bots]
  623.         mov     [edi],al
  624.         bt      [flags],1
  625.         jc      @f
  626.         add     al,10
  627.         mov     [edi+1],al
  628.         add     al,10
  629.         mov     [edi+2],al
  630.         add     al,10
  631.         mov     [edi+3],al
  632.         jmp     init_table
  633.   @@:   inc     al
  634.         mov     [edi+1],al
  635.         inc     al
  636.         mov     [edi+2],al
  637.         inc     al
  638.         mov     [edi+3],al
  639.         jmp     init_table
  640.  
  641.  
  642. .3paluba:                               ;âàñ寠«ã¡­ë©
  643.         bt      [flags],1
  644.         jnc     @f
  645.         cmp     [oX],7
  646.         jg      _still
  647.         jmp     .31
  648.   @@:   cmp     [oY],7
  649.         jg      _still
  650.   .31:
  651.         call    find_near
  652.  
  653.         bt      [flags],1
  654.         jc      @f
  655.         add     al,10
  656.         call    find_near
  657.         add     al,10
  658.         call    find_near
  659.         sub     al,20
  660.         jmp     .32
  661.   @@:   inc     al
  662.         call    find_near
  663.         inc     al
  664.         call    find_near
  665.         sub     al,2
  666.   .32:
  667.         inc     [number_bots]
  668.         mov     ecx,4
  669.         mov     dl,[number_bots]
  670.         sub     dl,2
  671.         jz      @f
  672.         add     ecx,3
  673.   @@:
  674.         mov     [edi+ecx],al
  675.         bt      [flags],1
  676.         jc      @f
  677.         add     al,10
  678.         mov     [edi+ecx+1],al
  679.         add     al,10
  680.         mov     [edi+ecx+2],al
  681. jmp     init_table
  682.   @@:   inc     al
  683.         mov     [edi+ecx+1],al
  684.         inc     al
  685.         mov     [edi+ecx+2],al
  686. jmp     init_table
  687.  
  688.  
  689.  
  690. .2paluba:                               ;¤¢ã寠«ã¡­ë©
  691.         bt      [flags],1
  692.         jnc     @f
  693.         cmp     [oX],8
  694.         jg      _still
  695.         jmp     .21
  696.   @@:   cmp     [oY],8
  697.         jg      _still
  698.   .21:
  699.         call    find_near
  700.         bt      [flags],1
  701.         jc      @f
  702.         add     al,10
  703.         call    find_near
  704.         sub     al,10
  705.         jmp     .22
  706.   @@:   inc     al
  707.         call    find_near
  708.         dec     al
  709.   .22:
  710.         inc     [number_bots]
  711.         mov     ecx,8
  712.         mov     dl,[number_bots]
  713.         sub     dl,4
  714.         jz      @f
  715.         add     ecx,2
  716.         dec     dl
  717.         jz      @f
  718.         add     ecx,2
  719.   @@:   add     ecx,2
  720.         mov     [edi+ecx],al
  721.         bt      [flags],1
  722.         jc      @f
  723.         add     al,10
  724.         mov     [edi+ecx+1],al
  725. jmp     init_table
  726.   @@:   inc     al
  727.         mov     [edi+ecx+1],al
  728. jmp     init_table
  729.  
  730.  
  731. .1paluba:                               ;®¤­®¯ «ã¡­ë©
  732.         call    find_near
  733.         inc     [number_bots]
  734.         xor     edx,edx
  735.         movzx   ecx,[number_bots]
  736.         add     ecx,9
  737.         mov     [edi+ecx],al
  738. jmp     init_table
  739.  
  740. find_near:
  741.         push    ax
  742.         call    f_near  ;0
  743.  
  744.         cmp     al,10
  745.         jb      @f
  746.         sub     al,10   ;-10
  747.         call    f_near
  748.  
  749. @@:     cmp     al,11
  750.         jb      @f
  751.  
  752.         xor     edx,edx
  753.         mov     ecx,10
  754.         div     cx
  755.         mov     ax,[esp]
  756.         cmp     dx,0
  757.         je      @f
  758.  
  759.         sub     al,11   ;-11
  760.         call    f_near
  761.  
  762. @@:     cmp     al,9
  763.         jb      @f
  764.  
  765.         xor     edx,edx
  766.         mov     ecx,10
  767.         div     cx
  768.         mov     ax,[esp]
  769.         cmp     dx,9
  770.         je      @f
  771.  
  772.         sub     al,9    ;-9
  773.         call    f_near
  774.  
  775. @@:     cmp     al,1
  776.         jb      @f
  777.  
  778.         xor     edx,edx
  779.         mov     ecx,10
  780.         div     cx
  781.         mov     ax,[esp]
  782.         cmp     dx,0
  783.         je      @f
  784.  
  785.         dec     al      ;-1
  786.         call    f_near
  787.  
  788. @@:     cmp     al,99
  789.         jg      @f
  790.  
  791.         xor     edx,edx
  792.         mov     ecx,10
  793.         div     cx
  794.         mov     ax,[esp]
  795.         cmp     dx,9
  796.         je      @f
  797.  
  798.         inc     al      ;+1
  799.         call    f_near
  800.  
  801. @@:     cmp     al,90
  802.         jge     @f
  803.         add     al,10   ;+10
  804.         call    f_near
  805.  
  806. @@:     cmp     al,91
  807.         jge     @f
  808.  
  809.         xor     edx,edx
  810.         mov     ecx,10
  811.         div     cx
  812.         mov     ax,[esp]
  813.         cmp     dx,0
  814.         je      @f
  815.  
  816.         add     al,9    ;+9
  817.         call    f_near
  818.  
  819. @@:     cmp     al,89
  820.         jge     @f
  821.  
  822.         xor     edx,edx
  823.         mov     ecx,10
  824.         div     cx
  825.         mov     ax,[esp]
  826.         cmp     dx,9
  827.         je      @f
  828.         add     al,11   ;+11
  829.         call    f_near
  830.  
  831. @@:     pop     ax
  832.         clc
  833. ret
  834.  
  835. f_near:
  836. movzx   edx, byte [smeshenie]
  837.   @@:   cmp     al,[edi+edx]
  838.         je      .end
  839.         dec     dl
  840.         jnz     @b
  841.         cmp     al,[edi]
  842.         je      .end
  843.         mov     ax,[esp+4]
  844.         ret
  845.   .end: add     esp,10
  846.         jmp     _still
  847.  
  848.  
  849.  
  850. init_table:
  851. ;       xor     eax,eax
  852.         movzx   ecx, byte [number_bots]
  853.         mov     edx,3
  854.         dec     cl
  855.         jz      .i_t
  856.  
  857.         mov     al,2
  858. .2:     add     dl,3
  859.         dec     cl
  860.         jz      .i_t
  861.         dec     al
  862.         jnz     .2
  863.  
  864.         mov     al,3
  865. .3:     add     dl,2
  866.         dec     cl
  867.         jz      .i_t
  868.         dec     al
  869.         jnz     .3
  870.  
  871.         mov     al,4
  872. .4:     inc     dl
  873.         dec     cl
  874.         jz      .i_t
  875.         dec     al
  876.         jnz     .4
  877.  
  878. .i_t:   mov     [smeshenie],dl
  879. @@:     movzx   eax, byte [edi+edx]
  880.         mov     byte [esi+eax],1
  881.         dec     dl
  882.         jnz     @b
  883.         movzx   eax, byte [edi]
  884.         mov     byte [esi+eax],1
  885.         bt      [flags],3
  886.         jc      set_bots
  887. ;       mcall   12,1
  888.         jmp     draw_pole
  889.  
  890.  
  891. second_pole:
  892.         bt      [flags],0
  893.         jnc     still
  894.         bt      [flags],13
  895.         jnc     still
  896.         cmp     ax,221
  897.         jbe     still
  898.         cmp     ax,421
  899.         jge     still
  900.                         ;¢â®à®¥ ¯®«¥
  901.         sub     ax,221
  902.         push    dx
  903.         xor     edx,edx
  904.         mov     cx,20
  905.         div     cx
  906.         pop     dx
  907.         push    ax
  908.         sub     dx,27
  909.         mov     ax,dx
  910.         xor     dx,dx
  911.         div     cx
  912.         xor     dx,dx
  913.         mov     cx,10
  914.         mul     cx
  915.         pop     dx
  916.         add     ax,dx
  917.         cmp     ax,100
  918.         jg      still
  919.  
  920. ;       mov     edi,table1      ;nashe pole
  921.         mov     esi,table2      ;opponent
  922.         cmp     byte [esi+eax],2
  923.         jge     still
  924.         add     byte [esi+eax],2
  925.         mov     byte [message+3],al
  926.         mov     byte [message+2],6
  927.         mov     edi,5
  928. @@:     mcall   5,10
  929.         mcall   53,WR_SOC,[socknum],4,message
  930.         dec     edi
  931.         jnz     @b
  932.         jmp     draw_pole
  933.  
  934.  
  935.  
  936. if_bot_killed:
  937.         mov     byte [message+3],0
  938.  
  939.         push    ebx
  940.         add     edi,100
  941.         mov     ebx,19
  942.   @@:   cmp     al,[edi+ebx]
  943.         je      @f
  944.         dec     ebx
  945.         jnz     @b
  946.         cmp     al,[edi+ebx]
  947.         jne     .end
  948.   @@:
  949.         cmp     ebx,16
  950.         jnb     .end_i
  951.  
  952.   @@:   cmp     bl,10
  953.         jb      .2
  954.         btc     bx,0
  955.         mov     bl, [edi+ebx]
  956.         cmp     byte [ecx+ebx],3
  957.         jne     .end
  958.  
  959.         inc     byte [ecx+ebx]
  960.  
  961.         movzx   edx, byte [message+3]
  962.         mov     byte [message+3+1+edx*2],bl
  963.         mov     bl,[ecx+ebx]
  964.         mov     byte [message+3+1+edx*2+1],bl
  965.         inc     byte [message+3]
  966.  
  967.         jmp     .end_i
  968.  
  969.   .2:   cmp     bl,4
  970.         jb      .3
  971.         add     edi,4
  972.         cmp     bl,7
  973.         jb      .3
  974.         add     edi,3
  975.   .3:   movzx   edx, byte [edi]
  976.         cmp     dl,al
  977.         je      @f
  978.         cmp     byte [ecx+edx],3
  979.         jne     .end
  980.   @@:   mov     dl,[edi+1]
  981.         cmp     dl,al
  982.         je      @f
  983.         cmp     byte [ecx+edx],3
  984.         jne     .end
  985.   @@:   mov     dl,[edi+2]
  986.         cmp     dl,al
  987.         je      @f
  988.         cmp     byte [ecx+edx],3
  989.         jne     .end
  990.  
  991.   @@:   cmp     bl,4
  992.         jnb     @f
  993.         mov     dl,[edi+3]
  994.         cmp     dl,al
  995.         je      @f
  996.         cmp     byte [ecx+edx],3
  997.         jne     .end
  998.  
  999.  
  1000.   @@:   mov     dl,[edi]
  1001.         cmp     dl,al
  1002.         je      @f
  1003.  
  1004.         inc     byte [ecx+edx]
  1005.  
  1006.         push    edx ebx
  1007.         movzx   ebx, byte [message+3]
  1008.         mov     byte [message+3+1+ebx*2],dl
  1009.         mov     dl,[ecx+edx]
  1010.         mov     byte [message+3+1+ebx*2+1],dl
  1011.         inc     byte [message+3]
  1012.         pop     ebx edx
  1013.  
  1014.  
  1015.   @@:   mov     dl,[edi+1]
  1016.         cmp     dl,al
  1017.         je      @f
  1018.  
  1019.         inc     byte [ecx+edx]
  1020.  
  1021.         push    edx ebx
  1022.         movzx   ebx, byte [message+3]
  1023.         mov     byte [message+3+1+ebx*2],dl
  1024.         mov     dl,[ecx+edx]
  1025.         mov     byte [message+3+1+ebx*2+1],dl
  1026.         inc     byte [message+3]
  1027.         pop     ebx edx
  1028.  
  1029.   @@:   mov     dl,[edi+2]
  1030.  
  1031.         cmp     bl,4
  1032.         jnb     .9
  1033.         cmp     dl,al
  1034.         je      @f
  1035.  
  1036.         inc     byte [ecx+edx]
  1037.  
  1038.         push    edx ebx
  1039.         movzx   ebx, byte [message+3]
  1040.         mov     byte [message+3+1+ebx*2],dl
  1041.         mov     dl,[ecx+edx]
  1042.         mov     byte [message+3+1+ebx*2+1],dl
  1043.         inc     byte [message+3]
  1044.         pop     ebx edx
  1045.  
  1046.   @@:   mov     dl,[edi+3]
  1047.   .9:   cmp     dl,al
  1048.         je      .end_i
  1049.  
  1050.         inc     byte [ecx+edx]
  1051.  
  1052.         push    edx ebx
  1053.         movzx   ebx, byte [message+3]
  1054.         mov     byte [message+3+1+ebx*2],dl
  1055.         mov     dl,[ecx+edx]
  1056.         mov     byte [message+3+1+ebx*2+1],dl
  1057.         inc     byte [message+3]
  1058.         pop     ebx edx
  1059.  
  1060.   .end_i:
  1061.         pop     ebx
  1062.         inc     ebx
  1063. ;       inc     [rem_kill]
  1064.         ret
  1065.   .end: pop     ebx
  1066. ret
  1067.  
  1068.  
  1069.  
  1070.  
  1071. _still:
  1072.         bt      [flags],3
  1073.         jnc     still
  1074.  
  1075. set_bots:
  1076.         cmp     [number_bots],10
  1077.         jne     @f
  1078.         ret
  1079.   @@:   xor     edx,edx
  1080.         mov     ecx,10
  1081.         cmp     [number_bots],6
  1082.         jb      @f
  1083.         push    dword 10
  1084.         jmp     .1
  1085.   @@:   cmp     [number_bots],3
  1086.         jb      @f
  1087.         push    dword 9
  1088.         jmp     .1
  1089.   @@:   cmp     [number_bots],2
  1090.         jb      @f
  1091.         push    dword 8
  1092.         jmp     .1
  1093.   @@:   push    dword 7
  1094.   .1:
  1095.         mov     eax,[esp]
  1096.         call    random
  1097.         mov     [oX],al
  1098.         mul     cl
  1099.         mov     cl,al
  1100.         mov     eax,[esp]
  1101.         call    random
  1102.         mov     [oY],al
  1103.         add     cl,al
  1104.  
  1105.         cmp     cl,100
  1106.         jge     .1
  1107.  
  1108.         add     esp,4
  1109.         mov     eax,2
  1110.         call    random
  1111.         cmp     al,1
  1112.         jne     @f
  1113.         bts     [flags],1
  1114.         mov     al,cl
  1115.         jmp     set_bot
  1116.   @@:   btr     [flags],1
  1117.         mov     al,cl
  1118.         jmp     set_bot
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124. align 4
  1125. rsx1 dw ?;0x4321
  1126. rsx2 dw ?;0x1234
  1127. random:         ; ¨§ ASCL
  1128.         push ecx edx esi
  1129.         mov cx,ax
  1130.         mov ax,[rsx1]
  1131.         mov bx,[rsx2]
  1132.         mov si,ax
  1133.         mov di,bx
  1134.         mov dl,ah
  1135.         mov ah,al
  1136.         mov al,bh
  1137.         mov bh,bl
  1138.         xor bl,bl
  1139.         rcr dl,1
  1140.         rcr ax,1
  1141.         rcr bx,1
  1142.         add bx,di
  1143.         adc ax,si
  1144.         add bx,0x62e9
  1145.         adc ax,0x3619
  1146.         mov [rsx1],bx
  1147.         mov [rsx2],ax
  1148.         xor dx,dx
  1149.         cmp ax,0
  1150.         je nodiv
  1151.         cmp cx,0
  1152.         je nodiv
  1153.         div cx
  1154. nodiv:
  1155.         mov ax,dx
  1156.         pop esi edx ecx
  1157.         and eax,0000ffffh
  1158. ret
  1159.  
  1160.  
  1161. if DEBUG
  1162. SysMsgBoardNum: ;warning: destroys eax,ebx,ecx,esi
  1163.         mov     ebx,esp
  1164.         mov     ecx,8
  1165.         mov     esi,(number_to_out+1)
  1166. .1:
  1167.         mov     eax,ebx
  1168.         and     eax,0xF
  1169.         cmp     al,10
  1170.         sbb     al,69h
  1171.         das
  1172.         mov     [esi+ecx],al
  1173.         shr     ebx,4
  1174.         loop    .1
  1175.         dec     esi
  1176.         mcall   71,1,number_to_out
  1177. ret
  1178.  
  1179. number_to_out   db '0x00000000',13,10,0
  1180. endf
  1181.  
  1182.  
  1183.  
  1184.  
  1185. text_cpu db 'CPU',0
  1186. text_user db 'USER',0
  1187. but_lis_con db 'Listen     Connect     Disconnect',0
  1188. if lang eq ru
  1189. title db 'Œ®à᪮© ¡®© 0.4',0
  1190. but_auto db ' ááâ ¢¨âì',0
  1191. but_new db '®¢ ï',0
  1192. text_win db '‚먣ࠫ!',0
  1193. else
  1194. title db 'Sea war 0.4',0
  1195. but_auto db 'Auto fill',0
  1196. but_new db 'New',0
  1197. text_win db 'Won!',0
  1198. endf
  1199.  
  1200. who_first dw 0
  1201.  
  1202. message db 'XO1234567890'
  1203.  
  1204. I_END:
  1205. ; t1,t3,t5: 0-­¥¯®¬¥ç¥­­ ï ª«¥â®çª , 1-§ ­ïâ ï, 2-"¯à®¬ å", 3-"£®à¨â", 4-"¯®â®¯«¥­"
  1206. ; t2,t4: â ¡«¨æë à á¯®«®¦¥­¨ï í«¥¬¥­â®¢, 1 í«¥¬¥­â ¯® 4 ª«¥âª¨, 2x3, 3x2, 4x1
  1207. align 16
  1208. table1  rb 100  ;«¥¢®¥ ¯®«¥, local
  1209. table3  rb 20
  1210. table2  rb 100  ;¯à ¢®¥, remote
  1211. table4  rb 20
  1212. rb 100
  1213. rem_kill rb 1   ;remote
  1214. loc_kill rb 1   ;local
  1215. p_pov   rb 1
  1216. smeshenie rb 1
  1217. number_bots rb 1
  1218. oX rb 1
  1219. oY rb 1
  1220. tbl_ranen rb 4
  1221.  
  1222. flags rw 1
  1223. ;flags2 rw 1
  1224. ;¡¨â 0: 0/1 - § ¯®«­¥­¨¥ â ¡«¨æ /¨£à 
  1225. ;1: ­ ¦ â  «¥¢ ï ª­®¯ª  ¬ëè¨ (¢¥à⨪ «ì) /¯à ¢ ï (£®à¨§®­â «ì)
  1226. ;2: § ¯®«­ï¥âáï «¥¢®¥ ¯®«¥ /¯à ¢®¥
  1227. ;3: àãç­®¥ § ¯®«­¥­¨¥ / ¢â®§ ¯®«­¥­¨¥
  1228. ;4: ¢ .three - ¯®â®¯«¥­­ë© ª®à ¡«ì
  1229. ;5: ¨£à  ®ª®­ç¥­ 
  1230. ;11: ogidat' server
  1231. ;12: server gdet otveta
  1232. ;13; 1 - ¬®© 室, 0 - ®¯¯®­¥­â