Subversion Repositories Kolibri OS

Rev

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