Subversion Repositories Kolibri OS

Rev

Rev 485 | 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
 
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
503 heavyiron 34
	db  '/rd/1/network/chess.bmp',0
180 heavyiron 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,70
31 halyavin 65
    mov  ebx,file_info
485 heavyiron 66
    mcall
180 heavyiron 67
 
31 halyavin 68
    mov  esi,0x4000+22*3+4+24*2
69
    mov  edi,0x10000+18*3
180 heavyiron 70
 
31 halyavin 71
    mov  ebx,0
72
    mov  ecx,0
180 heavyiron 73
 
31 halyavin 74
  newp:
180 heavyiron 75
 
31 halyavin 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
180 heavyiron 83
 
31 halyavin 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
180 heavyiron 90
 
31 halyavin 91
    add  edi,6
92
    add  esi,1
180 heavyiron 93
 
31 halyavin 94
    inc  ebx
95
    cmp  ebx,23
96
    jbe  newp
180 heavyiron 97
 
31 halyavin 98
    sub  edi,12
180 heavyiron 99
 
31 halyavin 100
    mov  ebx,0
180 heavyiron 101
 
31 halyavin 102
    inc  ecx
103
    cmp  ecx,279
180 heavyiron 104
    jb	 newp
105
 
31 halyavin 106
    ; Clear the screen memory
107
    mov     eax, '    '
108
    mov     edi,text
109
    mov     ecx,80*30 /4
110
    cld
111
    rep     stosd
180 heavyiron 112
 
113
 
31 halyavin 114
    call draw_window
180 heavyiron 115
 
31 halyavin 116
still:
180 heavyiron 117
 
31 halyavin 118
    call  check_for_board
180 heavyiron 119
 
31 halyavin 120
    call  board_changed
180 heavyiron 121
 
31 halyavin 122
    call  draw_board
180 heavyiron 123
 
31 halyavin 124
    ; check connection status
125
    mov  eax,53
126
    mov  ebx,6
127
    mov  ecx,[socket]
485 heavyiron 128
    mcall
180 heavyiron 129
 
31 halyavin 130
    mov     ebx, [socket_status]
131
    mov     [socket_status], eax
180 heavyiron 132
 
31 halyavin 133
    cmp     eax, ebx
180 heavyiron 134
    je	    waitev
135
 
31 halyavin 136
    call    display_status
180 heavyiron 137
 
31 halyavin 138
waitev:
180 heavyiron 139
    mov  eax,23 		; wait here for event
31 halyavin 140
    mov  ebx,20
485 heavyiron 141
    mcall
180 heavyiron 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
 
31 halyavin 150
    ; any data from the socket?
180 heavyiron 151
 
31 halyavin 152
    mov     eax, 53
153
    mov     ebx, 2
154
    mov     ecx, [socket]
485 heavyiron 155
    mcall
31 halyavin 156
    cmp     eax, 0
157
    jne      read_input
180 heavyiron 158
 
31 halyavin 159
    jmp  still
180 heavyiron 160
 
161
 
31 halyavin 162
read_input:
180 heavyiron 163
 
31 halyavin 164
    push ecx
165
    mov     eax, 53
166
    mov     ebx, 3
167
    mov     ecx, [socket]
485 heavyiron 168
    mcall
31 halyavin 169
    pop  ecx
180 heavyiron 170
 
31 halyavin 171
    call    handle_data
180 heavyiron 172
 
31 halyavin 173
    push    ecx
174
    mov     eax, 53
175
    mov     ebx, 2
176
    mov     ecx, [socket]
485 heavyiron 177
    mcall
31 halyavin 178
    pop     ecx
179
    cmp     eax, 0
180 heavyiron 180
 
181
 
31 halyavin 182
    jne   read_input
183
    call draw_text
184
    jmp  still
180 heavyiron 185
 
186
 
187
 
31 halyavin 188
check_for_board:
180 heavyiron 189
 
31 halyavin 190
    pusha
180 heavyiron 191
 
31 halyavin 192
     mov  esi,text-80
193
   news:
194
    add  esi,80
195
    cmp  esi,text+80*10
180 heavyiron 196
    je	 board_not_found
31 halyavin 197
    cmp  [esi+12],dword '----'
180 heavyiron 198
    je	 cfb1
31 halyavin 199
    jmp  news
200
   cfb1:
201
    cmp  [esi+16*80+12],dword '----'
180 heavyiron 202
    je	 cfb2
31 halyavin 203
    jmp  news
204
  cfb2:
205
    cmp  [esi+2*80+12],dword '+---'
206
    jne  news
180 heavyiron 207
 
31 halyavin 208
    cmp  [esi+4*80+12],dword '+---'
209
    jne  news
180 heavyiron 210
 
31 halyavin 211
  board_found:
180 heavyiron 212
 
31 halyavin 213
    mov  edi,chess_board
214
    mov  ecx,80*18
215
    cld
216
    rep  movsb
180 heavyiron 217
 
31 halyavin 218
   board_not_found:
180 heavyiron 219
 
31 halyavin 220
     popa
180 heavyiron 221
 
31 halyavin 222
     ret
180 heavyiron 223
 
224
 
225
yst	dd  150
226
textx	equ 10
227
ysts	equ 410
228
 
229
boardx	dd 45
230
boardy	dd 45
231
 
31 halyavin 232
boardxs dd 44
233
boardys dd 44
180 heavyiron 234
 
235
conx	equ 420
236
cony	equ 118
237
 
238
dconx	equ 420
239
dcony	equ 148
240
 
31 halyavin 241
statusx equ 420
242
statusy equ 178
180 heavyiron 243
 
244
 
31 halyavin 245
drsq:
180 heavyiron 246
 
31 halyavin 247
     push eax ebx
180 heavyiron 248
 
31 halyavin 249
     mov  ecx,ebx
250
     mov  ebx,eax
180 heavyiron 251
 
31 halyavin 252
     mov  eax,ebx
253
     add  eax,ecx
180 heavyiron 254
 
31 halyavin 255
     imul ebx,[boardxs]
256
     add  ebx,[boardx]
257
     shl  ebx,16
258
     imul ecx,[boardys]
259
     add  ecx,[boardy]
260
     shl  ecx,16
180 heavyiron 261
 
31 halyavin 262
     add  ebx,[boardxs]
263
     add  ecx,[boardys]
180 heavyiron 264
 
31 halyavin 265
     mov  edx,[sq_black]
266
     test eax,1
267
     jnz  dbl22
268
     mov  edx,[sq_white]
269
   dbl22:
180 heavyiron 270
 
31 halyavin 271
     mov  eax,13
485 heavyiron 272
     mcall
180 heavyiron 273
 
31 halyavin 274
     pop  ebx eax
180 heavyiron 275
 
31 halyavin 276
     ret
180 heavyiron 277
 
278
 
279
 
31 halyavin 280
draw_pawn:
180 heavyiron 281
 
31 halyavin 282
;    edi,0  ; white / black
283
;    esi,0  ; from position 2  , 20 square
284
;    eax,2  ; board x
285
;    ebx,0  ; board y
180 heavyiron 286
 
31 halyavin 287
     pusha
180 heavyiron 288
 
31 halyavin 289
     call drsq
180 heavyiron 290
 
31 halyavin 291
     cmp  esi,20
292
     jne  no_sqd
180 heavyiron 293
 
31 halyavin 294
     popa
295
     ret
180 heavyiron 296
 
31 halyavin 297
   no_sqd:
180 heavyiron 298
 
31 halyavin 299
     imul eax,[boardxs]
300
     imul ebx,[boardys]
180 heavyiron 301
 
31 halyavin 302
     add  eax,[boardx]
303
     add  ebx,[boardy]
180 heavyiron 304
 
31 halyavin 305
     imul esi,44*45*3
306
     add  esi,0x10000+18*3
180 heavyiron 307
 
31 halyavin 308
     mov  ecx,43
180 heavyiron 309
 
31 halyavin 310
   dp0:
180 heavyiron 311
 
31 halyavin 312
     pusha
180 heavyiron 313
 
31 halyavin 314
     mov  ecx,44
180 heavyiron 315
 
31 halyavin 316
   ldp1:
180 heavyiron 317
 
31 halyavin 318
     pusha
180 heavyiron 319
 
31 halyavin 320
     mov  ecx,ebx
321
     mov  ebx,eax
180 heavyiron 322
 
31 halyavin 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:
485 heavyiron 333
     mcall
31 halyavin 334
   nowp:
180 heavyiron 335
 
31 halyavin 336
     popa
180 heavyiron 337
 
31 halyavin 338
     add  esi,3
339
     add  eax,1
180 heavyiron 340
 
31 halyavin 341
     dec  ecx
342
     jnz  ldp1
180 heavyiron 343
 
31 halyavin 344
     popa
180 heavyiron 345
 
31 halyavin 346
     add  ebx,1
347
     add  esi,3*44
180 heavyiron 348
 
31 halyavin 349
     dec  ecx
350
     jnz  dp0
180 heavyiron 351
 
31 halyavin 352
     popa
180 heavyiron 353
 
31 halyavin 354
     ret
180 heavyiron 355
 
356
 
31 halyavin 357
board_changed:
180 heavyiron 358
 
31 halyavin 359
    pusha
180 heavyiron 360
 
31 halyavin 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
180 heavyiron 367
    jb	 bcl1
368
 
31 halyavin 369
    cmp  eax,[checksum]
180 heavyiron 370
    je	 bcl2
31 halyavin 371
    mov  [changed],1
372
  bcl2:
373
    mov  [checksum],eax
180 heavyiron 374
 
31 halyavin 375
    popa
180 heavyiron 376
 
31 halyavin 377
    ret
180 heavyiron 378
 
379
 
380
 
31 halyavin 381
checksum dd 0
180 heavyiron 382
 
31 halyavin 383
changed db 1
180 heavyiron 384
 
31 halyavin 385
draw_board:
180 heavyiron 386
 
31 halyavin 387
     pusha
180 heavyiron 388
 
31 halyavin 389
     cmp  [changed],1
390
     jne  no_change_in_board
180 heavyiron 391
 
31 halyavin 392
     mov  [changed],0
180 heavyiron 393
 
31 halyavin 394
     mov    eax,0
395
     mov    ebx,0
396
   scan_board:
180 heavyiron 397
 
31 halyavin 398
     push   eax ebx
180 heavyiron 399
 
31 halyavin 400
     mov    esi,ebx
401
     imul   esi,2
402
     imul   esi,80
403
     add    esi,80
180 heavyiron 404
 
31 halyavin 405
     imul   eax,4
406
     add    eax,10
180 heavyiron 407
 
31 halyavin 408
     add    esi,eax
180 heavyiron 409
 
31 halyavin 410
     movzx  edx,word [chess_board+esi]
411
     cmp    dx,[board_old+esi]
412
     je     empty_slot
180 heavyiron 413
 
31 halyavin 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
180 heavyiron 422
 
31 halyavin 423
     jmp    empty_slot
180 heavyiron 424
 
31 halyavin 425
    foundnappula2:
180 heavyiron 426
 
31 halyavin 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
180 heavyiron 436
 
31 halyavin 437
    empty_slot:
180 heavyiron 438
 
31 halyavin 439
     pop  ebx eax
180 heavyiron 440
 
31 halyavin 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
180 heavyiron 448
 
31 halyavin 449
     mov  esi,chess_board
450
     mov  edi,board_old
451
     mov  ecx,80*19
452
     cld
453
     rep  movsb
180 heavyiron 454
 
31 halyavin 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]
485 heavyiron 464
     mcall
180 heavyiron 465
 
466
     mov  eax,4 		   ; numbers at left
31 halyavin 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:
485 heavyiron 476
     mcall
31 halyavin 477
     add  edx,80*2
478
     add  ebx,[boardxs]
479
     cmp  edx,chess_board+80*16
480
     jb   db1
180 heavyiron 481
 
31 halyavin 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]
485 heavyiron 493
     mcall
180 heavyiron 494
 
495
     mov  eax,4 		   ; letters at bottom
31 halyavin 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:
485 heavyiron 507
     mcall
31 halyavin 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
180 heavyiron 514
 
31 halyavin 515
     ; print player times
180 heavyiron 516
 
31 halyavin 517
     mov  edi,74
518
     cmp  [chess_board+80+5],byte '1'
519
     jne  nowww2
520
     mov  edi,371
521
   nowww2:
180 heavyiron 522
 
31 halyavin 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]
485 heavyiron 529
     mcall
180 heavyiron 530
 
31 halyavin 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
485 heavyiron 537
     mcall
180 heavyiron 538
 
31 halyavin 539
     mov  edi,74
540
     cmp  [chess_board+80+5],byte '1'
541
     je   nowww
542
     mov  edi,371
543
   nowww:
180 heavyiron 544
 
31 halyavin 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]
485 heavyiron 551
     mcall
180 heavyiron 552
 
31 halyavin 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
485 heavyiron 559
     mcall
180 heavyiron 560
 
31 halyavin 561
     ; move #
180 heavyiron 562
 
31 halyavin 563
     mov  eax,13
564
     mov  ebx,conx*65536+120
565
     mov  ecx,200*65536+10
566
     mov  edx,[wcolor]
485 heavyiron 567
     mcall
180 heavyiron 568
 
31 halyavin 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
485 heavyiron 575
     mcall
180 heavyiron 576
 
31 halyavin 577
   no_change_in_board:
180 heavyiron 578
 
31 halyavin 579
     popa
180 heavyiron 580
 
31 halyavin 581
     ret
180 heavyiron 582
 
583
 
31 halyavin 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.
180 heavyiron 588
 
31 halyavin 589
    mov     al, [telnetstate]
590
    cmp     al, 0
180 heavyiron 591
    je	    state0
31 halyavin 592
    cmp     al, 1
180 heavyiron 593
    je	    state1
31 halyavin 594
    cmp     al, 2
180 heavyiron 595
    je	    state2
31 halyavin 596
    jmp     hd001
180 heavyiron 597
 
31 halyavin 598
state0:
599
    cmp     bl, 255
600
    jne     hd001
601
    mov     al, 1
602
    mov     [telnetstate], al
603
    ret
180 heavyiron 604
 
31 halyavin 605
state1:
606
    mov     al, 2
607
    mov     [telnetstate], al
608
    ret
180 heavyiron 609
 
31 halyavin 610
state2:
611
    mov     al, 0
612
    mov     [telnetstate], al
613
    mov     [telnetrep+2], bl
180 heavyiron 614
 
31 halyavin 615
    mov     edx, 3
616
    mov     eax,53
617
    mov     ebx,7
618
    mov     ecx,[socket]
619
    mov     esi, telnetrep
485 heavyiron 620
    mcall
31 halyavin 621
    ret
180 heavyiron 622
 
31 halyavin 623
hd001:
180 heavyiron 624
    cmp  bl,13				; BEGINNING OF LINE
31 halyavin 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
180 heavyiron 637
 
31 halyavin 638
    call check_for_board
180 heavyiron 639
 
31 halyavin 640
    jmp  newdata
641
  nobol:
180 heavyiron 642
 
643
    cmp  bl,10				  ; LINE DOWN
31 halyavin 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:
180 heavyiron 656
 
657
     cmp  bl,9				   ; TAB
31 halyavin 658
     jne  notab
659
    add  [pos],dword 8
660
    jmp  newdata
661
  notab:
180 heavyiron 662
 
663
    cmp  bl,8				 ; BACKSPACE
31 halyavin 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:
180 heavyiron 672
 
673
    cmp  bl,15				 ; CHARACTER
31 halyavin 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
180 heavyiron 683
    jb	 noeaxz
31 halyavin 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
180 heavyiron 695
 
696
 
697
  red:				; REDRAW WINDOW
31 halyavin 698
    call draw_window
699
    jmp  still
180 heavyiron 700
 
701
  key:				; KEY
702
    mov  eax,2			; send to modem
485 heavyiron 703
    mcall
180 heavyiron 704
 
31 halyavin 705
    mov     ebx, [socket_status]
180 heavyiron 706
    cmp     ebx, 4		; connection open?
707
    jne     still		; no, so ignore key
708
 
31 halyavin 709
    shr  eax,8
180 heavyiron 710
    cmp  eax,178		; ARROW KEYS
31 halyavin 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:
180 heavyiron 735
 
31 halyavin 736
    call    to_modem
180 heavyiron 737
 
31 halyavin 738
    jmp  still
180 heavyiron 739
 
740
  button:			; BUTTON
31 halyavin 741
    mov  eax,17
485 heavyiron 742
    mcall
180 heavyiron 743
    cmp  ah,1			; CLOSE PROGRAM
31 halyavin 744
    jne  noclose
180 heavyiron 745
 
31 halyavin 746
    mov  eax,53
747
    mov  ebx,8
748
    mov  ecx,[socket]
485 heavyiron 749
    mcall
180 heavyiron 750
 
31 halyavin 751
     mov  eax,-1
485 heavyiron 752
     mcall
31 halyavin 753
  noclose:
180 heavyiron 754
 
755
    cmp     ah, 4		; connect
31 halyavin 756
    jne     notcon
180 heavyiron 757
 
31 halyavin 758
    mov     eax, [socket_status]
759
    cmp     eax, 4
180 heavyiron 760
    je	   still
31 halyavin 761
    call    connect
180 heavyiron 762
 
31 halyavin 763
    jmp     still
180 heavyiron 764
 
31 halyavin 765
notcon:
180 heavyiron 766
    cmp     ah,5		; disconnect
31 halyavin 767
    jne     notdiscon
180 heavyiron 768
 
31 halyavin 769
    call    disconnect
770
    jmp  still
180 heavyiron 771
 
31 halyavin 772
 notdiscon:
180 heavyiron 773
 
31 halyavin 774
    jmp     still
180 heavyiron 775
 
31 halyavin 776
arrow:
180 heavyiron 777
 
31 halyavin 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
180 heavyiron 785
 
31 halyavin 786
    ret
180 heavyiron 787
 
788
 
31 halyavin 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
485 heavyiron 802
    mcall
31 halyavin 803
    pop     bx
804
    mov     al, [echo]
805
    cmp     al, 0
180 heavyiron 806
    je	    tm_001
807
 
31 halyavin 808
    push    bx
809
    call    handle_data
810
    pop     bx
180 heavyiron 811
 
31 halyavin 812
    cmp     bl, 13
813
    jne     tm_002
180 heavyiron 814
 
31 halyavin 815
    mov     bl, 10
816
    call    handle_data
180 heavyiron 817
 
31 halyavin 818
tm_002:
819
    call    draw_text
180 heavyiron 820
 
31 halyavin 821
tm_001:
822
    popa
823
    ret
180 heavyiron 824
 
825
 
826
 
31 halyavin 827
disconnect:
828
    mov  eax,53
829
    mov  ebx,8
830
    mov  ecx,[socket]
485 heavyiron 831
    mcall
31 halyavin 832
    ret
180 heavyiron 833
 
834
 
835
 
31 halyavin 836
connect:
837
    pusha
180 heavyiron 838
 
839
 mov	 ecx, 1000  ; local port starting at 1000
840
 
31 halyavin 841
getlp:
180 heavyiron 842
 inc	 ecx
31 halyavin 843
 push ecx
180 heavyiron 844
 mov	 eax, 53
845
 mov	 ebx, 9
485 heavyiron 846
 mcall
180 heavyiron 847
 pop	 ecx
848
 cmp	 eax, 0   ; is this local port in use?
849
 jz  getlp	; yes - so try next
850
 
31 halyavin 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
180 heavyiron 861
    movzx   edx, word [port]	  ; telnet port id
31 halyavin 862
    mov     edi,1      ; active open
485 heavyiron 863
    mcall
31 halyavin 864
    mov     [socket], eax
180 heavyiron 865
 
31 halyavin 866
    popa
180 heavyiron 867
 
31 halyavin 868
    ret
180 heavyiron 869
 
870
 
871
 
31 halyavin 872
;   *********************************************
873
;   *******  WINDOW DEFINITIONS AND DRAW ********
874
;   *********************************************
180 heavyiron 875
 
876
 
31 halyavin 877
draw_window:
180 heavyiron 878
 
31 halyavin 879
    pusha
180 heavyiron 880
 
31 halyavin 881
    mov  eax,12
882
    mov  ebx,1
485 heavyiron 883
    mcall
180 heavyiron 884
 
31 halyavin 885
    mov  eax,14
485 heavyiron 886
    mcall
180 heavyiron 887
 
31 halyavin 888
    mov  ebx,eax
889
    mov  ecx,eax
180 heavyiron 890
 
31 halyavin 891
    shr  ebx,16
892
    and  ebx,0xffff
893
    and  ecx,0xffff
180 heavyiron 894
 
31 halyavin 895
    shr  ebx,1
896
    shr  ecx,1
180 heavyiron 897
 
31 halyavin 898
    sub  ebx,275
899
    sub  ecx,235
180 heavyiron 900
 
31 halyavin 901
    shl  ebx,16
902
    shl  ecx,16
180 heavyiron 903
 
904
    mov  eax,0 		    ; DRAW WINDOW
31 halyavin 905
    mov  bx,550
906
    mov  cx,470
907
    mov  edx,[wcolor]
180 heavyiron 908
    add  edx,0x13000000
485 heavyiron 909
    mov  edi,title
910
    mcall
180 heavyiron 911
 
31 halyavin 912
    call display_status
180 heavyiron 913
 
914
    mov  eax,8			   ; BUTTON 4: Connect
31 halyavin 915
    mov  ebx,conx*65536+80
916
    mov  ecx,cony*65536+15
917
     mov  esi,[wbutton]
918
     mov  edx,4
485 heavyiron 919
    mcall
180 heavyiron 920
    mov  eax,4			   ; Button text
31 halyavin 921
    mov  ebx,(conx+4)*65536+cony+4
922
    mov  ecx,0xffffff
923
    mov  edx,cont
924
    mov  esi,conlen-cont
485 heavyiron 925
    mcall
180 heavyiron 926
 
927
 
928
    mov  eax,8			   ; BUTTON 5: disconnect
31 halyavin 929
    mov  ebx,dconx*65536+80
930
    mov  ecx,dcony*65536+15
931
    mov  edx,5
932
     mov  esi,[wbutton]
485 heavyiron 933
     mcall
180 heavyiron 934
    mov  eax,4			   ; Button text
31 halyavin 935
    mov  ebx,(dconx+4)*65536+dcony+4
936
    mov  ecx,0x00ffffff
937
    mov  edx,dist
938
    mov  esi,dislen-dist
485 heavyiron 939
    mcall
180 heavyiron 940
 
941
 
31 halyavin 942
    xor  eax,eax
943
    mov  edi,text+80*30
944
    mov  ecx,80*30 /4
945
    cld
946
    rep  stosd
180 heavyiron 947
 
31 halyavin 948
    call draw_text
180 heavyiron 949
 
31 halyavin 950
    mov  [changed],1
180 heavyiron 951
 
31 halyavin 952
    mov  edi,board_old
953
    mov  ecx,80*19
954
    mov  al,0
955
    cld
956
    rep  stosb
180 heavyiron 957
 
31 halyavin 958
    mov  eax,4
959
    mov  ebx,conx*65536+52
960
    mov  ecx,[tcolor]
961
    mov  edx,quick_start
962
    mov  esi,30
180 heavyiron 963
 
31 halyavin 964
  prqs:
180 heavyiron 965
 
485 heavyiron 966
    mcall
31 halyavin 967
    add  ebx,10
968
    add  edx,30
969
    cmp  [edx],byte 'x'
970
    jne  prqs
180 heavyiron 971
 
31 halyavin 972
    mov  eax,12
973
    mov  ebx,2
485 heavyiron 974
    mcall
180 heavyiron 975
 
31 halyavin 976
    popa
180 heavyiron 977
 
31 halyavin 978
    ret
180 heavyiron 979
 
980
 
31 halyavin 981
display_status:
180 heavyiron 982
 
31 halyavin 983
    pusha
180 heavyiron 984
 
31 halyavin 985
    ; draw status bar
986
    mov  eax, 13
987
    mov  ebx, statusx*65536+80
988
    mov  ecx, statusy*65536 + 16
989
    mov  edx, [wcolor]
485 heavyiron 990
    mcall
180 heavyiron 991
 
992
    mov  esi,contlen-contt	    ; display connected status
31 halyavin 993
    mov  edx, contt
994
    mov  eax, [socket_status]
180 heavyiron 995
    cmp  eax, 4 		 ; 4 is connected
996
    je	 pcon
31 halyavin 997
    mov  esi,discontlen-discontt
998
    mov  edx, discontt
999
  pcon:
180 heavyiron 1000
    mov  eax,4			   ; status text
31 halyavin 1001
    mov  ebx,statusx*65536+statusy+2
1002
     mov  ecx,[tcolor]
485 heavyiron 1003
     mcall
180 heavyiron 1004
 
31 halyavin 1005
    popa
1006
    ret
180 heavyiron 1007
 
1008
 
31 halyavin 1009
nappulat:
180 heavyiron 1010
 
31 halyavin 1011
    dd '*P  ',5
1012
    dd '*K  ',3
1013
    dd '*Q  ',4
1014
    dd '*R  ',0
1015
    dd '*N  ',1
1016
    dd '*B  ',2
180 heavyiron 1017
 
31 halyavin 1018
    dd '    ',20
180 heavyiron 1019
 
31 halyavin 1020
    dd 'P   ',5
1021
    dd 'K   ',3
1022
    dd 'Q   ',4
1023
    dd 'R   ',0
1024
    dd 'N   ',1
1025
    dd 'B   ',2
180 heavyiron 1026
 
1027
 
31 halyavin 1028
row   dd  0x0
1029
col   dd  0x0
180 heavyiron 1030
 
1031
 
1032
 
31 halyavin 1033
draw_text:
180 heavyiron 1034
 
31 halyavin 1035
    mov  esi,text+80*24
1036
    mov  edi,texts+80*3
180 heavyiron 1037
 
31 halyavin 1038
  dtl1:
180 heavyiron 1039
 
31 halyavin 1040
    cmp  [esi],dword 'logi'
180 heavyiron 1041
    je	 add_text
31 halyavin 1042
    cmp  [esi],dword 'aics'
180 heavyiron 1043
    je	 add_text
31 halyavin 1044
    cmp  [esi],dword 'You '
180 heavyiron 1045
    je	 add_text
31 halyavin 1046
    cmp  [esi],dword 'Your'
180 heavyiron 1047
    je	 add_text
31 halyavin 1048
    cmp  [esi],dword 'Game'
180 heavyiron 1049
    je	 add_text
31 halyavin 1050
    cmp  [esi],dword 'Ille'
180 heavyiron 1051
    je	 add_text
31 halyavin 1052
    cmp  [esi],dword 'No s'
180 heavyiron 1053
    je	 add_text
1054
 
31 halyavin 1055
    sub  esi,80
1056
    cmp  esi,text
1057
    jge  dtl1
180 heavyiron 1058
 
31 halyavin 1059
  dtl2:
180 heavyiron 1060
 
31 halyavin 1061
    mov  eax,13
1062
    mov  ebx,10*65536+532
1063
    mov  ecx,420*65536+40
1064
     mov  edx,[wtcom]
485 heavyiron 1065
     mcall
180 heavyiron 1066
 
31 halyavin 1067
    mov  eax,4
1068
    mov  ebx,10*65536+420
1069
     mov  ecx,[wtxt]
1070
     mov  edx,texts
1071
    mov  esi,80
180 heavyiron 1072
 
31 halyavin 1073
  dtl3:
180 heavyiron 1074
 
485 heavyiron 1075
    mcall
31 halyavin 1076
    add  edx,80
1077
    add  ebx,10
1078
    cmp  edx,texts+4*80
180 heavyiron 1079
    jb	 dtl3
1080
 
31 halyavin 1081
    ret
180 heavyiron 1082
 
31 halyavin 1083
  add_text:
180 heavyiron 1084
 
31 halyavin 1085
    pusha
180 heavyiron 1086
 
31 halyavin 1087
    cld
1088
    mov  ecx,80
1089
    rep  movsb
180 heavyiron 1090
 
31 halyavin 1091
    popa
180 heavyiron 1092
 
1093
 
31 halyavin 1094
    sub  esi,80
1095
    sub  edi,80
180 heavyiron 1096
 
31 halyavin 1097
    cmp  edi,texts
180 heavyiron 1098
    jb	 dtl2
1099
 
31 halyavin 1100
    jmp  dtl1
180 heavyiron 1101
 
1102
 
31 halyavin 1103
read_string:
180 heavyiron 1104
 
31 halyavin 1105
    mov  edi,string
1106
    mov  eax,'_'
1107
    mov  ecx,[string_length]
1108
    inc     ecx
1109
    cld
1110
    rep  stosb
1111
    call print_text
180 heavyiron 1112
 
31 halyavin 1113
    mov  edi,string
1114
  f11:
1115
    mov  eax,10
485 heavyiron 1116
    mcall
31 halyavin 1117
    cmp  eax,2
1118
    jne  read_done
1119
    mov  eax,2
485 heavyiron 1120
    mcall
31 halyavin 1121
    shr  eax,8
1122
    cmp  eax,13
180 heavyiron 1123
    je	 read_done
31 halyavin 1124
    cmp  eax,8
1125
    jnz  nobsl
1126
    cmp  edi,string
180 heavyiron 1127
    jz	 f11
31 halyavin 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
180 heavyiron 1136
    jb	 keyok
31 halyavin 1137
    sub  eax,32
1138
  keyok:
1139
    mov  [edi],al
1140
    call print_text
180 heavyiron 1141
 
31 halyavin 1142
    inc  edi
1143
    mov  esi,string
1144
    add  esi,[string_length]
1145
    cmp  esi,edi
1146
    jnz  f11
180 heavyiron 1147
 
31 halyavin 1148
  read_done:
180 heavyiron 1149
 
31 halyavin 1150
    call print_text
180 heavyiron 1151
 
31 halyavin 1152
    ret
180 heavyiron 1153
 
1154
 
31 halyavin 1155
print_text:
180 heavyiron 1156
 
31 halyavin 1157
    pusha
180 heavyiron 1158
 
31 halyavin 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]
485 heavyiron 1168
    mcall
180 heavyiron 1169
 
31 halyavin 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]
485 heavyiron 1177
    mcall
180 heavyiron 1178
 
31 halyavin 1179
    popa
1180
    ret
180 heavyiron 1181
 
1182
 
1183
 
1184
 
31 halyavin 1185
; DATA AREA
180 heavyiron 1186
 
1187
telnetrep	db 0xff,0xfc,0x00
1188
telnetstate	db 0
1189
 
31 halyavin 1190
string_length  dd    16
1191
string_x       dd    200
1192
string_y       dd    60
180 heavyiron 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
 
485 heavyiron 1217
title		db  appname,version,0
180 heavyiron 1218
 
1219
setipt		db  '               .   .   .'
31 halyavin 1220
setiplen:
180 heavyiron 1221
setportt	db  '     '
31 halyavin 1222
setportlen:
180 heavyiron 1223
cont		db  'Connect'
31 halyavin 1224
conlen:
180 heavyiron 1225
dist		db  'Disconnect'
31 halyavin 1226
dislen:
180 heavyiron 1227
contt		db  'Connected'
31 halyavin 1228
contlen:
180 heavyiron 1229
discontt	db  'Disconnected'
31 halyavin 1230
discontlen:
180 heavyiron 1231
echot	     db  'Echo On'
31 halyavin 1232
echolen:
180 heavyiron 1233
echoot	      db  'Echo Off'
31 halyavin 1234
echoolen:
180 heavyiron 1235
 
31 halyavin 1236
quick_start:
180 heavyiron 1237
 
1238
    db	'( OPPONENT )                  '
1239
 
31 halyavin 1240
   times 16  db  '                             1'
180 heavyiron 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
 
31 halyavin 1255
  times 5  db  '                              '
180 heavyiron 1256
 
1257
    db	'( YOU )                       '
1258
 
1259
    db	'x'
1260
 
1261
 
31 halyavin 1262
chess_board:
180 heavyiron 1263
 
1264
    times  80	 db 0
1265
 
31 halyavin 1266
 db '     8    *R  *N  *B  *Q  *K  *B  *N  *R'
1267
 db '                                        '
180 heavyiron 1268
 
1269
     times  80	db 0
1270
 
31 halyavin 1271
 db '     7    *P  *P  *P  *P  *P  *P  *P  *P'
1272
 db '                                        '
180 heavyiron 1273
 
1274
     times  80	db 0
1275
 
31 halyavin 1276
 db '     6                                  '
1277
 db '                                        '
180 heavyiron 1278
 
1279
     times  80	db 0
1280
 
31 halyavin 1281
 db '     5                                  '
1282
 db '                                        '
180 heavyiron 1283
 
1284
     times  80	db 0
1285
 
31 halyavin 1286
 db '     4                                  '
1287
 db '                                        '
180 heavyiron 1288
 
1289
     times  80	db 0
1290
 
31 halyavin 1291
 db '     3                                  '
1292
 db '                                        '
180 heavyiron 1293
 
1294
     times  80	db 0
1295
 
31 halyavin 1296
 db '     2    P   P   P   P   P   P   P   P '
1297
 db '                                        '
180 heavyiron 1298
 
1299
    times  80	   db 0
1300
 
31 halyavin 1301
 db '     1    R   N   B   Q   K   B   N   R '
1302
 db '                                        '
180 heavyiron 1303
 
1304
    times  80	   db 0
1305
 
31 halyavin 1306
 db '          a   b   c   d   e   f   g   h '
1307
 db '                                        '
180 heavyiron 1308
 
1309
 
31 halyavin 1310
    times  80*20 db 0
180 heavyiron 1311
 
31 halyavin 1312
board_old:
180 heavyiron 1313
 
1314
 
31 halyavin 1315
I_END:
180 heavyiron 1316