Subversion Repositories Kolibri OS

Rev

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

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