Subversion Repositories Kolibri OS

Rev

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