Subversion Repositories Kolibri OS

Rev

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