Subversion Repositories Kolibri OS

Rev

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