Subversion Repositories Kolibri OS

Rev

Rev 503 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;    CHESS CLIENT for CHESSCLUB.COM (VT)
  3. ;
  4. ;    Compile with FASM for Menuet
  5. ;
  6.  
  7. appname equ 'Chess Client for Chessclub.com '
  8. version equ '0.2'
  9.  
  10. use32
  11.  org    0x0
  12.  db     'MENUET01'    ; header
  13.  dd     0x01          ; header version
  14.  dd     START         ; entry point
  15.  dd     I_END         ; image size
  16.  dd     0x100000      ; required memory
  17.  dd     0x100000      ; esp
  18.  dd     0x0 , 0x0     ; I_Param , I_Path
  19.  
  20. include 'lang.inc'
  21. include '..\..\..\macros.inc'
  22.  
  23. pawn_color:
  24.  
  25.      dd  0x000000
  26.      dd  0x222222
  27.      dd  0x444444
  28.      dd  0xf0f0f0
  29.      dd  0xc0c0c0
  30.      dd  0xa0a0a0
  31.      dd  0xa0a0a0
  32.      dd  0x707070
  33.      dd  0xb0b0b0
  34.      dd  0xc0c0c0
  35.      dd  0xd0d0d0
  36.      dd  0xd8d8d8
  37.      dd  0xe0e0e0
  38.      dd  0xe8e8e8
  39.      dd  0x00ff00
  40.      dd  0xffffff
  41.  
  42.  
  43.  
  44. texts  equ  board_old+80*30
  45.  
  46. text   equ  texts+80*32*4
  47.  
  48.  
  49. START:                          ; start of execution
  50.  
  51.     mov  esi,chess_bmp
  52.     mov  edi,0x10000+18*3
  53.  
  54.     mov  ebx,0
  55.     mov  ecx,0
  56.  
  57.   newp:
  58.  
  59.     xor  eax,eax
  60.     mov  al,[esi]
  61.     and  al,0xf0
  62.     shr  al,4
  63.     shl  eax,2
  64.     mov  eax,[pawn_color+eax]
  65.     mov  [edi+0],eax
  66.  
  67.     xor  eax,eax
  68.     mov  al,[esi]
  69.     and  al,0x0f
  70.     shl  eax,2
  71.     mov  eax,[pawn_color+eax]
  72.     mov  [edi+3],eax
  73.  
  74.     add  edi,6
  75.     add  esi,1
  76.  
  77.     inc  ebx
  78.     cmp  ebx,23
  79.     jbe  newp
  80.  
  81.     sub  edi,12
  82.  
  83.     mov  ebx,0
  84.  
  85.     inc  ecx
  86.     cmp  ecx,279
  87.     jb   newp
  88.  
  89.     ; Clear the screen memory
  90.     mov     eax, '    '
  91.     mov     edi,text
  92.     mov     ecx,80*30 /4
  93.     cld
  94.     rep     stosd
  95.  
  96.  
  97.     call draw_window
  98.  
  99. still:
  100.  
  101.     call  check_for_board
  102.  
  103.     call  board_changed
  104.  
  105.     call  draw_board
  106.  
  107.     ; check connection status
  108.     mov  eax,53
  109.     mov  ebx,6
  110.     mov  ecx,[socket]
  111.     mcall
  112.  
  113.     mov     ebx, [socket_status]
  114.     mov     [socket_status], eax
  115.  
  116.     cmp     eax, ebx
  117.     je      waitev
  118.  
  119.     call    display_status
  120.  
  121. waitev:
  122.     mov  eax,23                 ; wait here for event
  123.     mov  ebx,20
  124.     mcall
  125.  
  126.     cmp  eax,1                  ; redraw request ?
  127.     je   red
  128.     cmp  eax,2                  ; key in buffer ?
  129.     je   key
  130.     cmp  eax,3                  ; button in buffer ?
  131.     je   button
  132.  
  133.     ; any data from the socket?
  134.  
  135.     mov     eax, 53
  136.     mov     ebx, 2
  137.     mov     ecx, [socket]
  138.     mcall
  139.     cmp     eax, 0
  140.     jne      read_input
  141.  
  142.     jmp  still
  143.  
  144.  
  145. read_input:
  146.  
  147.     push ecx
  148.     mov     eax, 53
  149.     mov     ebx, 3
  150.     mov     ecx, [socket]
  151.     mcall
  152.     pop  ecx
  153.  
  154.     call    handle_data
  155.  
  156.     push    ecx
  157.     mov     eax, 53
  158.     mov     ebx, 2
  159.     mov     ecx, [socket]
  160.     mcall
  161.     pop     ecx
  162.     cmp     eax, 0
  163.  
  164.  
  165.     jne   read_input
  166.     call draw_text
  167.     jmp  still
  168.  
  169.  
  170.  
  171. check_for_board:
  172.  
  173.     pusha
  174.  
  175.      mov  esi,text-80
  176.    news:
  177.     add  esi,80
  178.     cmp  esi,text+80*10
  179.     je   board_not_found
  180.     cmp  [esi+12],dword '----'
  181.     je   cfb1
  182.     jmp  news
  183.    cfb1:
  184.     cmp  [esi+16*80+12],dword '----'
  185.     je   cfb2
  186.     jmp  news
  187.   cfb2:
  188.     cmp  [esi+2*80+12],dword '+---'
  189.     jne  news
  190.  
  191.     cmp  [esi+4*80+12],dword '+---'
  192.     jne  news
  193.  
  194.   board_found:
  195.  
  196.     mov  edi,chess_board
  197.     mov  ecx,80*18
  198.     cld
  199.     rep  movsb
  200.  
  201.    board_not_found:
  202.  
  203.      popa
  204.  
  205.      ret
  206.  
  207.  
  208. yst     dd  150
  209. textx   equ 10
  210. ysts    equ 410
  211.  
  212. boardx  dd 45
  213. boardy  dd 45
  214.  
  215. boardxs dd 44
  216. boardys dd 44
  217.  
  218. conx    equ 420
  219. cony    equ 118
  220.  
  221. dconx   equ 420
  222. dcony   equ 148
  223.  
  224. statusx equ 420
  225. statusy equ 178
  226.  
  227.  
  228. drsq:
  229.  
  230.      push eax ebx
  231.  
  232.      mov  ecx,ebx
  233.      mov  ebx,eax
  234.  
  235.      mov  eax,ebx
  236.      add  eax,ecx
  237.  
  238.      imul ebx,[boardxs]
  239.      add  ebx,[boardx]
  240.      shl  ebx,16
  241.      imul ecx,[boardys]
  242.      add  ecx,[boardy]
  243.      shl  ecx,16
  244.  
  245.      add  ebx,[boardxs]
  246.      add  ecx,[boardys]
  247.  
  248.      mov  edx,[sq_black]
  249.      test eax,1
  250.      jnz  dbl22
  251.      mov  edx,[sq_white]
  252.    dbl22:
  253.  
  254.      mov  eax,13
  255.      mcall
  256.  
  257.      pop  ebx eax
  258.  
  259.      ret
  260.  
  261.  
  262.  
  263. draw_pawn:
  264.  
  265. ;    edi,0  ; white / black
  266. ;    esi,0  ; from position 2  , 20 square
  267. ;    eax,2  ; board x
  268. ;    ebx,0  ; board y
  269.  
  270.      pusha
  271.  
  272.      call drsq
  273.  
  274.      cmp  esi,20
  275.      jne  no_sqd
  276.  
  277.      popa
  278.      ret
  279.  
  280.    no_sqd:
  281.  
  282.      imul eax,[boardxs]
  283.      imul ebx,[boardys]
  284.  
  285.      add  eax,[boardx]
  286.      add  ebx,[boardy]
  287.  
  288.      imul esi,44*45*3
  289.      add  esi,0x10000+18*3
  290.  
  291.      mov  ecx,43
  292.  
  293.    dp0:
  294.  
  295.      pusha
  296.  
  297.      mov  ecx,44
  298.  
  299.    ldp1:
  300.  
  301.      pusha
  302.  
  303.      mov  ecx,ebx
  304.      mov  ebx,eax
  305.  
  306.      mov  edx,[esi]
  307.      and  edx,0xffffff
  308.      mov  eax,1
  309.      cmp  edx,0x00ff00
  310.      je   nowp
  311.      cmp  edi,1
  312.      jne  nobl
  313.      shr  edx,1
  314.      and  edx,0x7f7f7f
  315.    nobl:
  316.      mcall
  317.    nowp:
  318.  
  319.      popa
  320.  
  321.      add  esi,3
  322.      add  eax,1
  323.  
  324.      dec  ecx
  325.      jnz  ldp1
  326.  
  327.      popa
  328.  
  329.      add  ebx,1
  330.      add  esi,3*44
  331.  
  332.      dec  ecx
  333.      jnz  dp0
  334.  
  335.      popa
  336.  
  337.      ret
  338.  
  339.  
  340. board_changed:
  341.  
  342.     pusha
  343.  
  344.     mov  eax,0
  345.     mov  esi,chess_board
  346.   bcl1:
  347.     add  eax,[esi]
  348.     add  esi,4
  349.     cmp  esi,chess_board+19*80
  350.     jb   bcl1
  351.  
  352.     cmp  eax,[checksum]
  353.     je   bcl2
  354.     mov  [changed],1
  355.   bcl2:
  356.     mov  [checksum],eax
  357.  
  358.     popa
  359.  
  360.     ret
  361.  
  362.  
  363.  
  364. checksum dd 0
  365.  
  366. changed db 1
  367.  
  368. draw_board:
  369.  
  370.      pusha
  371.  
  372.      cmp  [changed],1
  373.      jne  no_change_in_board
  374.  
  375.      mov  [changed],0
  376.  
  377.      mov    eax,0
  378.      mov    ebx,0
  379.    scan_board:
  380.  
  381.      push   eax ebx
  382.  
  383.      mov    esi,ebx
  384.      imul   esi,2
  385.      imul   esi,80
  386.      add    esi,80
  387.  
  388.      imul   eax,4
  389.      add    eax,10
  390.  
  391.      add    esi,eax
  392.  
  393.      movzx  edx,word [chess_board+esi]
  394.      cmp    dx,[board_old+esi]
  395.      je     empty_slot
  396.  
  397.      mov    ecx,13
  398.    newseek2:
  399.      mov    edi,ecx
  400.      imul   edi,8
  401.      sub    edi,8
  402.      cmp    dx,[edi+nappulat]
  403.      je     foundnappula2
  404.      loop   newseek2
  405.  
  406.      jmp    empty_slot
  407.  
  408.     foundnappula2:
  409.  
  410.      mov   esi,[edi+nappulat+4]
  411.      mov   edi,0
  412.      cmp   dl,'*'
  413.      jne   nnbb
  414.      mov   edi,1
  415.    nnbb:
  416.      mov   eax,[esp+4]
  417.      mov   ebx,[esp]
  418.      call  draw_pawn
  419.  
  420.     empty_slot:
  421.  
  422.      pop  ebx eax
  423.  
  424.      inc  eax
  425.      cmp  eax,8
  426.      jb   scan_board
  427.      mov  eax,0
  428.      inc  ebx
  429.      cmp  ebx,8
  430.      jb   scan_board
  431.  
  432.      mov  esi,chess_board
  433.      mov  edi,board_old
  434.      mov  ecx,80*19
  435.      cld
  436.      rep  movsb
  437.  
  438.      mov  eax,13
  439.      mov  ebx,[boardx]
  440.      sub  ebx,14
  441.      shl  ebx,16
  442.      add  ebx,8
  443.      mov  ecx,[boardy]
  444.      shl  ecx,16
  445.      add  ecx,46*8
  446.      mov  edx,[wcolor]
  447.      mcall
  448.  
  449.      mov  eax,4                    ; numbers at left
  450.      mov  ebx,[boardx]
  451.      sub  ebx,14
  452.      shl  ebx,16
  453.      add  ebx,[boardy]
  454.      add  ebx,18
  455.      mov  ecx,[tcolor]
  456.      mov  edx,chess_board+80+5
  457.      mov  esi,3
  458.     db1:
  459.      mcall
  460.      add  edx,80*2
  461.      add  ebx,[boardxs]
  462.      cmp  edx,chess_board+80*16
  463.      jb   db1
  464.  
  465.      mov  eax,13
  466.      mov  ebx,[boardx]
  467.      shl  ebx,16
  468.      add  ebx,8*46
  469.      mov  ecx,[boardys]
  470.      imul ecx,8
  471.      add  ecx,[boardy]
  472.      add  ecx,8
  473.      shl  ecx,16
  474.      add  ecx,10
  475.      mov  edx,[wcolor]
  476.      mcall
  477.  
  478.      mov  eax,4                    ; letters at bottom
  479.      mov  ebx,[boardx]
  480.      add  ebx,3
  481.      shl  ebx,16
  482.      mov  bx,word [boardys]
  483.      imul bx,8
  484.      add  ebx,[boardy]
  485.      add  ebx,8
  486.      mov  ecx,[tcolor]
  487.      mov  edx,chess_board+80*17+8
  488.      mov  esi,4
  489.    db3:
  490.      mcall
  491.      mov  edi,[boardxs]
  492.      shl  edi,16
  493.      add  ebx,edi
  494.      add  edx,4
  495.      cmp  edx,chess_board+80*17+8+4*8
  496.      jb   db3
  497.  
  498.      ; print player times
  499.  
  500.      mov  edi,74
  501.      cmp  [chess_board+80+5],byte '1'
  502.      jne  nowww2
  503.      mov  edi,371
  504.    nowww2:
  505.  
  506.      mov  eax,13
  507.      mov  ebx,(conx)*65536+100
  508.      mov  ecx,edi
  509.      shl  ecx,16
  510.      add  ecx,10
  511.      mov  edx,[wcolor]
  512.      mcall
  513.  
  514.      mov  eax,4
  515.      mov  ebx,(conx)*65536
  516.      add  ebx,edi
  517.      mov  ecx,[tcolor]
  518.      mov  edx,chess_board+80*7+59-1
  519.      mov  esi,20
  520.      mcall
  521.  
  522.      mov  edi,74
  523.      cmp  [chess_board+80+5],byte '1'
  524.      je   nowww
  525.      mov  edi,371
  526.    nowww:
  527.  
  528.      mov  eax,13
  529.      mov  ebx,(conx)*65536+100
  530.      mov  ecx,edi
  531.      shl  ecx,16
  532.      add  ecx,10
  533.      mov  edx,[wcolor]
  534.      mcall
  535.  
  536.      mov  eax,4
  537.      mov  ebx,(conx)*65536
  538.      add  ebx,edi
  539.      mov  ecx,[tcolor]
  540.      mov  edx,chess_board+80*9+59-1
  541.      mov  esi,20
  542.      mcall
  543.  
  544.      ; move #
  545.  
  546.      mov  eax,13
  547.      mov  ebx,conx*65536+120
  548.      mov  ecx,200*65536+10
  549.      mov  edx,[wcolor]
  550.      mcall
  551.  
  552.      mov  eax,4
  553.      mov  ebx,conx*65536
  554.      add  ebx,200
  555.      mov  ecx,[tcolor]
  556.      mov  edx,chess_board+80*1+46
  557.      mov  esi,30
  558.      mcall
  559.  
  560.    no_change_in_board:
  561.  
  562.      popa
  563.  
  564.      ret
  565.  
  566.  
  567. handle_data:
  568.     ; Telnet servers will want to negotiate options about our terminal window
  569.     ; just reject them all.
  570.     ; Telnet options start with the byte 0xff and are 3 bytes long.
  571.  
  572.     mov     al, [telnetstate]
  573.     cmp     al, 0
  574.     je      state0
  575.     cmp     al, 1
  576.     je      state1
  577.     cmp     al, 2
  578.     je      state2
  579.     jmp     hd001
  580.  
  581. state0:
  582.     cmp     bl, 255
  583.     jne     hd001
  584.     mov     al, 1
  585.     mov     [telnetstate], al
  586.     ret
  587.  
  588. state1:
  589.     mov     al, 2
  590.     mov     [telnetstate], al
  591.     ret
  592.  
  593. state2:
  594.     mov     al, 0
  595.     mov     [telnetstate], al
  596.     mov     [telnetrep+2], bl
  597.  
  598.     mov     edx, 3
  599.     mov     eax,53
  600.     mov     ebx,7
  601.     mov     ecx,[socket]
  602.     mov     esi, telnetrep
  603.     mcall
  604.     ret
  605.  
  606. hd001:
  607.     cmp  bl,13                          ; BEGINNING OF LINE
  608.     jne  nobol
  609.     mov  ecx,[pos]
  610.     add  ecx,1
  611.   boll1:
  612.     sub  ecx,1
  613.     mov  eax,ecx
  614.     xor  edx,edx
  615.     mov  ebx,80
  616.     div  ebx
  617.     cmp  edx,0
  618.     jne  boll1
  619.     mov  [pos],ecx
  620.  
  621.     call check_for_board
  622.  
  623.     jmp  newdata
  624.   nobol:
  625.  
  626.     cmp  bl,10                            ; LINE DOWN
  627.     jne  nolf
  628.    addx1:
  629.     add  [pos],dword 1
  630.     mov  eax,[pos]
  631.     xor  edx,edx
  632.     mov  ecx,80
  633.     div  ecx
  634.     cmp  edx,0
  635.     jnz  addx1
  636.     mov  eax,[pos]
  637.     jmp  cm1
  638.   nolf:
  639.  
  640.      cmp  bl,9                             ; TAB
  641.      jne  notab
  642.     add  [pos],dword 8
  643.     jmp  newdata
  644.   notab:
  645.  
  646.     cmp  bl,8                            ; BACKSPACE
  647.     jne  nobasp
  648.     mov  eax,[pos]
  649.     dec  eax
  650.     mov  [pos],eax
  651.     mov  [eax+text],byte 32
  652.     mov  [eax+text+60*80],byte 0
  653.     jmp  newdata
  654.    nobasp:
  655.  
  656.     cmp  bl,15                           ; CHARACTER
  657.     jbe  newdata
  658.     mov  eax,[pos]
  659.     mov  [eax+text],bl
  660.     mov  eax,[pos]
  661.     add  eax,1
  662.   cm1:
  663.     mov  ebx,[scroll+4]
  664.     imul ebx,80
  665.     cmp  eax,ebx
  666.     jb   noeaxz
  667.     mov  esi,text+80
  668.     mov  edi,text
  669.     mov  ecx,ebx
  670.     cld
  671.     rep  movsb
  672.     mov  eax,ebx
  673.     sub  eax,80
  674.   noeaxz:
  675.     mov  [pos],eax
  676.   newdata:
  677.     ret
  678.  
  679.  
  680.   red:                          ; REDRAW WINDOW
  681.     call draw_window
  682.     jmp  still
  683.  
  684.   key:                          ; KEY
  685.     mov  eax,2                  ; send to modem
  686.     mcall
  687.  
  688.     mov     ebx, [socket_status]
  689.     cmp     ebx, 4              ; connection open?
  690.     jne     still               ; no, so ignore key
  691.  
  692.     shr  eax,8
  693.     cmp  eax,178                ; ARROW KEYS
  694.     jne  noaup
  695.     mov  al,'A'
  696.     call arrow
  697.     jmp  still
  698.   noaup:
  699.     cmp  eax,177
  700.     jne  noadown
  701.     mov  al,'B'
  702.     call arrow
  703.     jmp  still
  704.   noadown:
  705.     cmp  eax,179
  706.     jne  noaright
  707.     mov  al,'C'
  708.     call arrow
  709.     jmp  still
  710.   noaright:
  711.     cmp  eax,176
  712.     jne  noaleft
  713.     mov  al,'D'
  714.     call arrow
  715.     jmp  still
  716.   noaleft:
  717.   modem_out:
  718.  
  719.     call    to_modem
  720.  
  721.     jmp  still
  722.  
  723.   button:                       ; BUTTON
  724.     mov  eax,17
  725.     mcall
  726.     cmp  ah,1                   ; CLOSE PROGRAM
  727.     jne  noclose
  728.  
  729.     mov  eax,53
  730.     mov  ebx,8
  731.     mov  ecx,[socket]
  732.     mcall
  733.  
  734.      mov  eax,-1
  735.      mcall
  736.   noclose:
  737.  
  738.     cmp     ah, 4               ; connect
  739.     jne     notcon
  740.  
  741.     mov     eax, [socket_status]
  742.     cmp     eax, 4
  743.     je     still
  744.     call    connect
  745.  
  746.     jmp     still
  747.  
  748. notcon:
  749.     cmp     ah,5                ; disconnect
  750.     jne     notdiscon
  751.  
  752.     call    disconnect
  753.     jmp  still
  754.  
  755.  notdiscon:
  756.  
  757.     jmp     still
  758.  
  759. arrow:
  760.  
  761.     push eax
  762.     mov  al,27
  763.     call to_modem
  764.     mov  al,'['
  765.     call to_modem
  766.     pop  eax
  767.     call to_modem
  768.  
  769.     ret
  770.  
  771.  
  772. to_modem:
  773.     pusha
  774.     push    ax
  775.     mov     [tx_buff], al
  776.     mov     edx, 1
  777.     cmp     al, 13
  778.     jne     tm_000
  779.     mov     edx, 2
  780. tm_000:
  781.     mov     eax,53
  782.     mov     ebx,7
  783.     mov     ecx,[socket]
  784.     mov     esi, tx_buff
  785.     mcall
  786.     pop     bx
  787.     mov     al, [echo]
  788.     cmp     al, 0
  789.     je      tm_001
  790.  
  791.     push    bx
  792.     call    handle_data
  793.     pop     bx
  794.  
  795.     cmp     bl, 13
  796.     jne     tm_002
  797.  
  798.     mov     bl, 10
  799.     call    handle_data
  800.  
  801. tm_002:
  802.     call    draw_text
  803.  
  804. tm_001:
  805.     popa
  806.     ret
  807.  
  808.  
  809.  
  810. disconnect:
  811.     mov  eax,53
  812.     mov  ebx,8
  813.     mov  ecx,[socket]
  814.     mcall
  815.     ret
  816.  
  817.  
  818.  
  819. connect:
  820.     pusha
  821.  
  822.  mov     ecx, 1000  ; local port starting at 1000
  823.  
  824. getlp:
  825.  inc     ecx
  826.  push ecx
  827.  mov     eax, 53
  828.  mov     ebx, 9
  829.  mcall
  830.  pop     ecx
  831.  cmp     eax, 0   ; is this local port in use?
  832.  jz  getlp      ; yes - so try next
  833.  
  834.     mov     eax,53
  835.     mov     ebx,5
  836.     mov     dl, [ip_address + 3]
  837.     shl     edx, 8
  838.     mov     dl, [ip_address + 2]
  839.     shl     edx, 8
  840.     mov     dl, [ip_address + 1]
  841.     shl     edx, 8
  842.     mov     dl, [ip_address]
  843.     mov     esi, edx
  844.     movzx   edx, word [port]      ; telnet port id
  845.     mov     edi,1      ; active open
  846.     mcall
  847.     mov     [socket], eax
  848.  
  849.     popa
  850.  
  851.     ret
  852.  
  853.  
  854.  
  855. ;   *********************************************
  856. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  857. ;   *********************************************
  858.  
  859.  
  860. draw_window:
  861.  
  862.     pusha
  863.  
  864.     mov  eax,12
  865.     mov  ebx,1
  866.     mcall
  867.  
  868.     mov  eax,14
  869.     mcall
  870.  
  871.     mov  ebx,eax
  872.     mov  ecx,eax
  873.  
  874.     shr  ebx,16
  875.     and  ebx,0xffff
  876.     and  ecx,0xffff
  877.  
  878.     shr  ebx,1
  879.     shr  ecx,1
  880.  
  881.     sub  ebx,275
  882.     sub  ecx,235
  883.  
  884.     shl  ebx,16
  885.     shl  ecx,16
  886.  
  887.     mov  eax,0              ; DRAW WINDOW
  888.     mov  bx,550
  889.     mov  cx,470
  890.     mov  edx,[wcolor]
  891.     add  edx,0x13000000
  892.     mov  edi,title
  893.     mcall
  894.  
  895.     call display_status
  896.  
  897.     mov  eax,8                     ; BUTTON 4: Connect
  898.     mov  ebx,conx*65536+80
  899.     mov  ecx,cony*65536+15
  900.      mov  esi,[wbutton]
  901.      mov  edx,4
  902.     mcall
  903.     mov  eax,4                     ; Button text
  904.     mov  ebx,(conx+4)*65536+cony+4
  905.     mov  ecx,0xffffff
  906.     mov  edx,cont
  907.     mov  esi,conlen-cont
  908.     mcall
  909.  
  910.  
  911.     mov  eax,8                     ; BUTTON 5: disconnect
  912.     mov  ebx,dconx*65536+80
  913.     mov  ecx,dcony*65536+15
  914.     mov  edx,5
  915.      mov  esi,[wbutton]
  916.      mcall
  917.     mov  eax,4                     ; Button text
  918.     mov  ebx,(dconx+4)*65536+dcony+4
  919.     mov  ecx,0x00ffffff
  920.     mov  edx,dist
  921.     mov  esi,dislen-dist
  922.     mcall
  923.  
  924.  
  925.     xor  eax,eax
  926.     mov  edi,text+80*30
  927.     mov  ecx,80*30 /4
  928.     cld
  929.     rep  stosd
  930.  
  931.     call draw_text
  932.  
  933.     mov  [changed],1
  934.  
  935.     mov  edi,board_old
  936.     mov  ecx,80*19
  937.     mov  al,0
  938.     cld
  939.     rep  stosb
  940.  
  941.     mov  eax,4
  942.     mov  ebx,conx*65536+52
  943.     mov  ecx,[tcolor]
  944.     mov  edx,quick_start
  945.     mov  esi,30
  946.  
  947.   prqs:
  948.  
  949.     mcall
  950.     add  ebx,10
  951.     add  edx,30
  952.     cmp  [edx],byte 'x'
  953.     jne  prqs
  954.  
  955.     mov  eax,12
  956.     mov  ebx,2
  957.     mcall
  958.  
  959.     popa
  960.  
  961.     ret
  962.  
  963.  
  964. display_status:
  965.  
  966.     pusha
  967.  
  968.     ; draw status bar
  969.     mov  eax, 13
  970.     mov  ebx, statusx*65536+80
  971.     mov  ecx, statusy*65536 + 16
  972.     mov  edx, [wcolor]
  973.     mcall
  974.  
  975.     mov  esi,contlen-contt          ; display connected status
  976.     mov  edx, contt
  977.     mov  eax, [socket_status]
  978.     cmp  eax, 4                  ; 4 is connected
  979.     je   pcon
  980.     mov  esi,discontlen-discontt
  981.     mov  edx, discontt
  982.   pcon:
  983.     mov  eax,4                     ; status text
  984.     mov  ebx,statusx*65536+statusy+2
  985.      mov  ecx,[tcolor]
  986.      mcall
  987.  
  988.     popa
  989.     ret
  990.  
  991.  
  992. nappulat:
  993.  
  994.     dd '*P  ',5
  995.     dd '*K  ',3
  996.     dd '*Q  ',4
  997.     dd '*R  ',0
  998.     dd '*N  ',1
  999.     dd '*B  ',2
  1000.  
  1001.     dd '    ',20
  1002.  
  1003.     dd 'P   ',5
  1004.     dd 'K   ',3
  1005.     dd 'Q   ',4
  1006.     dd 'R   ',0
  1007.     dd 'N   ',1
  1008.     dd 'B   ',2
  1009.  
  1010.  
  1011. row   dd  0x0
  1012. col   dd  0x0
  1013.  
  1014.  
  1015.  
  1016. draw_text:
  1017.  
  1018.     mov  esi,text+80*24
  1019.     mov  edi,texts+80*3
  1020.  
  1021.   dtl1:
  1022.  
  1023.     cmp  [esi],dword 'logi'
  1024.     je   add_text
  1025.     cmp  [esi],dword 'aics'
  1026.     je   add_text
  1027.     cmp  [esi],dword 'You '
  1028.     je   add_text
  1029.     cmp  [esi],dword 'Your'
  1030.     je   add_text
  1031.     cmp  [esi],dword 'Game'
  1032.     je   add_text
  1033.     cmp  [esi],dword 'Ille'
  1034.     je   add_text
  1035.     cmp  [esi],dword 'No s'
  1036.     je   add_text
  1037.  
  1038.     sub  esi,80
  1039.     cmp  esi,text
  1040.     jge  dtl1
  1041.  
  1042.   dtl2:
  1043.  
  1044.     mov  eax,13
  1045.     mov  ebx,10*65536+532
  1046.     mov  ecx,420*65536+40
  1047.      mov  edx,[wtcom]
  1048.      mcall
  1049.  
  1050.     mov  eax,4
  1051.     mov  ebx,10*65536+420
  1052.      mov  ecx,[wtxt]
  1053.      mov  edx,texts
  1054.     mov  esi,80
  1055.  
  1056.   dtl3:
  1057.  
  1058.     mcall
  1059.     add  edx,80
  1060.     add  ebx,10
  1061.     cmp  edx,texts+4*80
  1062.     jb   dtl3
  1063.  
  1064.     ret
  1065.  
  1066.   add_text:
  1067.  
  1068.     pusha
  1069.  
  1070.     cld
  1071.     mov  ecx,80
  1072.     rep  movsb
  1073.  
  1074.     popa
  1075.  
  1076.  
  1077.     sub  esi,80
  1078.     sub  edi,80
  1079.  
  1080.     cmp  edi,texts
  1081.     jb   dtl2
  1082.  
  1083.     jmp  dtl1
  1084.  
  1085.  
  1086. read_string:
  1087.  
  1088.     mov  edi,string
  1089.     mov  eax,'_'
  1090.     mov  ecx,[string_length]
  1091.     inc     ecx
  1092.     cld
  1093.     rep  stosb
  1094.     call print_text
  1095.  
  1096.     mov  edi,string
  1097.   f11:
  1098.     mov  eax,10
  1099.     mcall
  1100.     cmp  eax,2
  1101.     jne  read_done
  1102.     mov  eax,2
  1103.     mcall
  1104.     shr  eax,8
  1105.     cmp  eax,13
  1106.     je   read_done
  1107.     cmp  eax,8
  1108.     jnz  nobsl
  1109.     cmp  edi,string
  1110.     jz   f11
  1111.     sub  edi,1
  1112.     mov  [edi],byte '_'
  1113.     call print_text
  1114.     jmp  f11
  1115.   nobsl:
  1116.     cmp  eax,dword 31
  1117.     jbe  f11
  1118.     cmp  eax,dword 95
  1119.     jb   keyok
  1120.     sub  eax,32
  1121.   keyok:
  1122.     mov  [edi],al
  1123.     call print_text
  1124.  
  1125.     inc  edi
  1126.     mov  esi,string
  1127.     add  esi,[string_length]
  1128.     cmp  esi,edi
  1129.     jnz  f11
  1130.  
  1131.   read_done:
  1132.  
  1133.     call print_text
  1134.  
  1135.     ret
  1136.  
  1137.  
  1138. print_text:
  1139.  
  1140.     pusha
  1141.  
  1142.     mov  eax,13
  1143.     mov  ebx,[string_x]
  1144.     shl  ebx,16
  1145.     add  ebx,[string_length]
  1146.     imul bx,6
  1147.     mov  ecx,[string_y]
  1148.     shl  ecx,16
  1149.     mov  cx,8
  1150.     mov  edx,[wcolor]
  1151.     mcall
  1152.  
  1153.     mov  eax,4
  1154.     mov  ebx,[string_x]
  1155.     shl  ebx,16
  1156.     add  ebx,[string_y]
  1157.     mov  ecx,[tcolor]
  1158.     mov  edx,string
  1159.     mov  esi,[string_length]
  1160.     mcall
  1161.  
  1162.     popa
  1163.     ret
  1164.  
  1165.  
  1166.  
  1167.  
  1168. ; DATA AREA
  1169.  
  1170. telnetrep       db 0xff,0xfc,0x00
  1171. telnetstate     db 0
  1172.  
  1173. string_length  dd    16
  1174. string_x       dd    200
  1175. string_y       dd    60
  1176.  
  1177. string         db    '________________'
  1178.  
  1179. tx_buff         db  0, 10
  1180. ip_address      db  204,178,125,65
  1181. port            dw  5051 ;  0,0
  1182. echo            db  1
  1183. socket          dd  0x0
  1184. socket_status   dd  0x0
  1185. pos             dd  80 * 22
  1186. scroll          dd  1
  1187.                 dd  24
  1188.  
  1189. wbutton         dd  0x336688
  1190.  
  1191. wtcom           dd  0x336688 ; 0x666666
  1192. wtxt            dd  0xffffff
  1193.  
  1194. wcolor          dd  0xe0e0e0
  1195. tcolor          dd  0x000000
  1196.  
  1197. sq_black        dd  0x336688 ; 666666
  1198. sq_white        dd  0xffffff
  1199.  
  1200. title           db  appname,version,0
  1201.  
  1202. setipt          db  '               .   .   .'
  1203. setiplen:
  1204. setportt        db  '     '
  1205. setportlen:
  1206. cont            db  'Connect'
  1207. conlen:
  1208. dist            db  'Disconnect'
  1209. dislen:
  1210. contt           db  'Connected'
  1211. contlen:
  1212. discontt        db  'Disconnected'
  1213. discontlen:
  1214. echot        db  'Echo On'
  1215. echolen:
  1216. echoot        db  'Echo Off'
  1217. echoolen:
  1218.  
  1219. quick_start:
  1220.  
  1221.     db  '( OPPONENT )                  '
  1222.  
  1223.    times 16  db  '                             1'
  1224.  
  1225.     db  'Quick start:                  '
  1226.     db  '                              '
  1227.     db  '1 Connect                     '
  1228.     db  '2 login: "guest"              '
  1229.     db  '3 aics% "seek 10 0"           '
  1230.     db  '  (for a player)              '
  1231.     db  '  (wait)                      '
  1232.     db  '4 Play eg. "e7e5"             '
  1233.     db  '  or  "d2d4"                  '
  1234.     db  '5 aics% "resign"              '
  1235.     db  '  (quit game)                 '
  1236.     db  '6 Disconnect                  '
  1237.  
  1238.   times 5  db  '                              '
  1239.  
  1240.     db  '( YOU )                       '
  1241.  
  1242.     db  'x'
  1243.  
  1244.  
  1245. chess_board:
  1246.  
  1247.     times  80    db 0
  1248.  
  1249.  db '     8    *R  *N  *B  *Q  *K  *B  *N  *R'
  1250.  db '                                        '
  1251.  
  1252.      times  80  db 0
  1253.  
  1254.  db '     7    *P  *P  *P  *P  *P  *P  *P  *P'
  1255.  db '                                        '
  1256.  
  1257.      times  80  db 0
  1258.  
  1259.  db '     6                                  '
  1260.  db '                                        '
  1261.  
  1262.      times  80  db 0
  1263.  
  1264.  db '     5                                  '
  1265.  db '                                        '
  1266.  
  1267.      times  80  db 0
  1268.  
  1269.  db '     4                                  '
  1270.  db '                                        '
  1271.  
  1272.      times  80  db 0
  1273.  
  1274.  db '     3                                  '
  1275.  db '                                        '
  1276.  
  1277.      times  80  db 0
  1278.  
  1279.  db '     2    P   P   P   P   P   P   P   P '
  1280.  db '                                        '
  1281.  
  1282.     times  80      db 0
  1283.  
  1284.  db '     1    R   N   B   Q   K   B   N   R '
  1285.  db '                                        '
  1286.  
  1287.     times  80      db 0
  1288.  
  1289.  db '          a   b   c   d   e   f   g   h '
  1290.  db '                                        '
  1291.  
  1292.  
  1293.     times  80*20 db 0
  1294.  
  1295. chess_bmp:
  1296.         file    'chess.bmp':22*3+4+24*2
  1297.  
  1298. board_old:
  1299.  
  1300.  
  1301. I_END:
  1302.