Subversion Repositories Kolibri OS

Rev

Rev 503 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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