Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
31 halyavin 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                   ;;
3
;;    IRC CLIENT for MenuetOS                        ;;
4
;;                                                   ;;
5
;;    License: GPL / See file COPYING for details    ;;
6
;;    Copyright 2004 (c) Ville Turjanmaa             ;;
7
;;                                                   ;;
8
;;    Compile with FASM for Menuet                   ;;
9
;;                                                   ;;
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
 
556 heavyiron 12
version equ '0.51'
31 halyavin 13
 
485 heavyiron 14
 
15
;__DEBUG__ equ 1
16
;__DEBUG_LEVEL__ equ 1
17
 
31 halyavin 18
use32
19
 
195 heavyiron 20
		org	0x0
31 halyavin 21
 
195 heavyiron 22
		db	'MENUET01'		; 8 byte id
23
		dd	0x01			; required os
24
		dd	START			; program start
25
		dd	I_END			; program image size
26
		dd	0x100000		; required amount of memory
27
		dd	0x100000
28
		dd	0,0
29
 
485 heavyiron 30
include "..\..\..\macros.inc"
31
;include "fdo.inc"
32
include "eth.inc"
33
;include "lang.inc"
31 halyavin 34
 
556 heavyiron 35
irc_server_name db      'kolibrios.org',0                 ; default server name
31 halyavin 36
 
556 heavyiron 37
user_nick	dd	12				  ; length
195 heavyiron 38
		db	'kolibri_user           '	  ; string
31 halyavin 39
 
195 heavyiron 40
user_real_name	dd	14				  ; length
41
		db	'KolibriOS User         '	  ; string
31 halyavin 42
 
43
 
195 heavyiron 44
START:				; start of execution
31 halyavin 45
 
46
    mov  eax,40
47
    mov  ebx,10000111b
485 heavyiron 48
    mcall
31 halyavin 49
 
50
    mov  edi,I_END
51
    mov  ecx,60*120
52
    mov  eax,32
53
    cld
54
    rep  stosb
55
 
56
    mov  eax,[rxs]
57
    imul eax,11
58
    mov  [pos],eax
59
 
60
    mov  ebp,0
61
    mov  edx,I_END
556 heavyiron 62
 
63
redraw: 			; redraw
195 heavyiron 64
    call draw_window		; at first, draw the window
31 halyavin 65
 
66
still:
67
 
68
    inc  [cursor_on_off]
69
 
70
    mov  eax,5
71
    mov  ebx,1
485 heavyiron 72
    mcall
31 halyavin 73
 
195 heavyiron 74
    mov  eax,11 		; wait here for event
485 heavyiron 75
    mcall
31 halyavin 76
 
77
    call print_status
78
 
195 heavyiron 79
    cmp  eax,1			; redraw
80
    je	 redraw
81
    cmp  eax,2			; key
82
    je	 main_window_key
83
    cmp  eax,3			; button
84
    je	 button
31 halyavin 85
 
86
    cmp  [I_END+120*60],byte 1
87
    jne  no_main_update
88
    mov  [I_END+120*60],byte 0
89
    mov  edx,I_END
90
    call draw_channel_text
91
  no_main_update:
92
 
93
    call read_incoming_data
94
 
95
    call send_data_to_server
96
 
97
    test [cursor_on_off],0x3f
98
    jnz  nopri
99
    inc  [blink]
100
    call blink_cursor
101
    call print_channel_list
102
  nopri:
103
 
104
    jmp  still
105
 
195 heavyiron 106
button: 			; button
31 halyavin 107
 
195 heavyiron 108
    mov  eax,17 		; get id
485 heavyiron 109
    mcall
31 halyavin 110
 
195 heavyiron 111
    cmp  ah,1			; close program
31 halyavin 112
    jne  noclose
556 heavyiron 113
    or   eax,-1
485 heavyiron 114
    mcall
31 halyavin 115
  noclose:
116
 
117
    call socket_commands
118
 
119
    jmp  still
120
 
121
 
122
print_status:
123
 
124
    pusha
125
 
126
    mov  eax,53
127
    mov  ebx,6
128
    mov  ecx,[socket]
485 heavyiron 129
    mcall
31 halyavin 130
 
131
    mov  [status],eax
132
 
133
    cmp  [old_status],eax
195 heavyiron 134
    je	 nopr
31 halyavin 135
 
136
    mov  [old_status],eax
137
 
138
    push eax
139
 
140
    mov  eax,13
141
    mov  ebx,450*65536+30
142
    mov  ecx,231*65536+10
143
    mov  edx,0xffffff
485 heavyiron 144
    mcall
31 halyavin 145
 
146
    pop  ecx
147
    mov  eax,47
148
    mov  ebx,2*65536
149
    mov  edx,450*65536+231
150
    mov  esi,0x000000
485 heavyiron 151
    mcall
31 halyavin 152
 
153
  nopr:
154
 
155
    popa
156
 
157
    ret
158
 
159
status dd 0
160
old_status dd 0
161
 
162
 
163
socket_commands:
164
 
195 heavyiron 165
    cmp  ah,22	     ; open socket
31 halyavin 166
    jnz  tst3
167
    mov  eax,3
485 heavyiron 168
    mcall
31 halyavin 169
    mov  ecx,eax
556 heavyiron 170
 
171
pusha
172
    mov     eax,irc_server_name
173
    resolve irc_server_name,dword[irc_server_ip]
174
    ;DEBUGF 1,'%u.%u.%u.%u\n',1[irc_server_ip],1[irc_server_ip+1],1[irc_server_ip+2],1[irc_server_ip+3]
175
popa
176
 
31 halyavin 177
    mov  eax,53
178
    mov  ebx,5
179
    mov  edx,6667
180
    mov  esi,dword [irc_server_ip]
181
    mov  edi,1
485 heavyiron 182
    mcall
31 halyavin 183
    mov  [socket], eax
184
    ret
185
  tst3:
186
 
187
 
195 heavyiron 188
    cmp  ah,23	      ; write userinfo
31 halyavin 189
    jnz  tst4
190
 
191
    mov  eax,53  ; user
192
    mov  ebx,7
193
    mov  ecx,[socket]
194
    mov  edx,string0l-string0
195
    mov  esi,string0
485 heavyiron 196
    mcall
31 halyavin 197
 
198
    mov  eax,53  ;
199
    mov  ebx,7
200
    mov  ecx,[socket]
201
    mov  edx,[user_real_name]
202
    mov  esi,user_real_name+4
485 heavyiron 203
    mcall
31 halyavin 204
 
205
    mov  eax,53  ;
206
    mov  ebx,7
207
    mov  ecx,[socket]
208
    mov  edx,2
209
    mov  esi,line_feed
485 heavyiron 210
    mcall
31 halyavin 211
 
212
 
213
    mov  eax,5
214
    mov  ebx,10
485 heavyiron 215
    mcall
31 halyavin 216
 
217
    mov  eax,53  ; nick
218
    mov  ebx,7
219
    mov  ecx,[socket]
220
    mov  edx,string1l-string1
221
    mov  esi,string1
485 heavyiron 222
    mcall
31 halyavin 223
 
224
    mov  eax,53  ;
225
    mov  ebx,7
226
    mov  ecx,[socket]
227
    mov  edx,[user_nick]
228
    mov  esi,user_nick+4
485 heavyiron 229
    mcall
31 halyavin 230
 
231
    mov  eax,53  ;
232
    mov  ebx,7
233
    mov  ecx,[socket]
234
    mov  edx,2
235
    mov  esi,line_feed
485 heavyiron 236
    mcall
31 halyavin 237
 
238
 
239
    ret
240
 
241
  line_feed:  db  13,10
242
 
243
  tst4:
244
 
245
 
195 heavyiron 246
    cmp  ah,24	   ; close socket
31 halyavin 247
    jnz  no_24
248
    mov  eax,53
249
    mov  ebx,8
250
    mov  ecx,[socket]
485 heavyiron 251
    mcall
31 halyavin 252
    ret
253
  no_24:
254
 
255
 
256
    ret
257
 
258
 
259
main_window_key:
260
 
261
    mov  eax,2
485 heavyiron 262
    mcall
31 halyavin 263
 
264
    shr  eax,8
265
 
266
    cmp  eax,8
267
    jne  no_bks2
268
    cmp  [xpos],0
195 heavyiron 269
    je	 still
31 halyavin 270
    dec  [xpos]
271
    call print_entry
272
    jmp  still
273
   no_bks2:
274
 
275
    cmp  eax,20
276
    jbe  no_character2
277
    mov  ebx,[xpos]
278
    mov  [send_string+ebx],al
279
    inc  [xpos]
280
    cmp  [xpos],80
195 heavyiron 281
    jb	 noxposdec
31 halyavin 282
    mov  [xpos],79
283
  noxposdec:
284
    call print_entry
285
    jmp  still
286
  no_character2:
287
 
288
    cmp  eax,13
289
    jne  no_send
290
    cmp  [xpos],0
195 heavyiron 291
    je	 no_send2
31 halyavin 292
    cmp  [send_string],byte '/'   ; server command
293
    jne  no_send2
294
    mov  [send_to_server],1
295
    jmp  still
296
  no_send2:
297
 
298
    jmp  still
299
 
300
 
301
print_channel_list:
302
 
303
    pusha
304
 
305
    mov  eax,13
306
    mov  ebx,415*65536+6*13
307
    mov  ecx,27*65536+12*10
308
    mov  edx,0xffffff
485 heavyiron 309
    mcall
31 halyavin 310
 
311
    mov  eax,4
312
    mov  ebx,415*65536+27
313
    mov  ecx,[index_list_1]
314
    mov  edx,channel_list+32
315
  newch:
316
    movzx esi,byte [edx+31]
317
    and  esi,0x1f
485 heavyiron 318
    mcall
31 halyavin 319
    add  edx,32
320
    add  ebx,12
321
    cmp  edx,channel_list+32*10
322
    jbe  newch
323
 
324
  no_channel_list:
325
 
326
    popa
327
 
328
    ret
329
 
330
 
331
print_user_list:
332
 
333
    pusha
334
 
335
  newtry:
336
 
337
    mov  edx,ebp
338
    imul edx,120*80
339
    add  edx,120*60+8+I_END
340
    cmp  [edx],byte 1
195 heavyiron 341
    je	 nonp
31 halyavin 342
 
343
    mov  edx,ebp
344
    imul edx,120*80
345
    add  edx,120*70+I_END
346
    mov  edi,edx
347
 
348
    mov  eax,[edx-8]
349
    mov  ebx,[edx-4]
350
    add  ebx,edx
351
    sub  ebx,3
352
    inc  eax
353
    dec  edx
354
  newnss:
355
    inc  edx
356
    dec  eax
195 heavyiron 357
    jz	 startuu
31 halyavin 358
  asdf:
359
    cmp  [edx],word '  '
360
    jne  nodouble
361
    inc  edx
362
  nodouble:
363
    cmp  [edx],byte ' '
195 heavyiron 364
    je	 newnss
31 halyavin 365
    inc  edx
366
    cmp  edx,ebx
367
    jbe  asdf
368
    dec  dword [edi-8]
369
 
370
    popa
371
    ret
372
 
373
  startuu:
374
 
375
    cmp  [edx],byte ' '
376
    jne  startpr
377
    inc  edx
378
  startpr:
379
 
380
    pusha
381
    mov  eax,13
382
    mov  ebx,415*65536+6*13
383
    mov  ecx,27*65536+12*10
384
    mov  edx,0xffffff
485 heavyiron 385
    mcall
31 halyavin 386
    popa
387
 
388
    mov  eax,4
389
    mov  ebx,415*65536+27
390
 
391
    mov  ebp,0
392
  newuser:
393
 
394
    mov  esi,0
395
  newusers:
396
    cmp  [edx+esi],byte ' '
195 heavyiron 397
    je	 do_print
31 halyavin 398
    inc  esi
399
    cmp  esi,20
400
    jbe  newusers
401
  do_print:
402
 
403
    mov  ecx,[index_list_1]
404
    cmp  [edx],byte '@'
405
    jne  no_op
406
    mov  ecx,[index_list_2]
407
  no_op:
408
 
485 heavyiron 409
    mcall
31 halyavin 410
 
411
    inc  ebp
412
    cmp  ebp,10
195 heavyiron 413
    je	 nonp
31 halyavin 414
 
415
    add  ebx,12
416
 
417
    add  edx,esi
418
 
419
    inc  edx
420
    cmp  [edx],byte ' '
421
    jne  newuser
422
    inc  edx
423
    jmp  newuser
424
 
425
  nonp:
426
 
427
    popa
428
 
429
    ret
430
 
431
 
432
start_user_list_at dd 0x0
433
 
434
 
195 heavyiron 435
recode_to_cp1251:
436
	push	esi edx
437
  .loop:
438
	lodsb
439
	cmp	al,0x80
440
	jb	@f
441
	and	eax,0x7F
442
	mov	al,[cp866_table+eax]
443
    @@: mov	[esi-1],al
444
	dec	edx
445
	jnz	.loop
446
	pop	edx esi
447
	ret
31 halyavin 448
 
449
 
450
send_data_to_server:
451
 
452
    pusha
453
 
454
    cmp  [send_to_server],1
455
    jne  sdts_ret
456
 
457
    mov  eax,[xpos]
458
    mov  [send_string+eax+0],byte 13
459
    mov  [send_string+eax+1],byte 10
460
 
461
    mov  eax,[rxs]
462
    imul eax,11
463
    mov  [pos],eax
464
    mov  eax,[send_to_channel]
465
    imul eax,120*80
466
    add  eax,I_END
467
    mov  [text_start],eax
468
 
469
    cmp  [send_string],byte '/'   ; server command
195 heavyiron 470
    je	 server_command
31 halyavin 471
 
472
    mov  bl,13
473
    call print_character
474
    mov  bl,10
475
    call print_character
476
    mov  bl,'<'
477
    call print_character
478
 
479
    mov  esi,user_nick+4
480
    mov  ecx,[user_nick]
481
  newnp:
482
    mov  bl,[esi]
483
    call print_character
484
    inc  esi
485
    loop newnp
486
 
487
    mov  bl,'>'
488
    call print_character
489
    mov  bl,' '
490
    call print_character
491
 
492
    mov  ecx,[xpos]
493
    mov  esi,send_string
494
  newcw:
495
    mov  bl,[esi]
496
    call print_character
497
    inc  esi
498
    loop newcw
499
 
500
    mov  eax,dword [send_to_channel]
501
    shl  eax,5
502
    add  eax,channel_list
503
    mov  esi,eax
504
 
505
    mov  edi,send_string_header+8
506
    movzx ecx,byte [eax+31]
507
    cld
508
    rep  movsb
509
 
510
    mov  [edi],word ' :'
511
 
512
    mov   esi, send_string_header
513
    mov   edx,10
514
    movzx ebx,byte [eax+31]
515
    add   edx,ebx
516
 
517
    mov  eax, 53      ; write channel
518
    mov  ebx, 7
519
    mov  ecx, [socket]
485 heavyiron 520
    mcall
31 halyavin 521
 
522
    mov  esi,send_string
523
    mov  edx,[xpos]
524
    inc  edx
525
 
195 heavyiron 526
	call	recode_to_cp1251
527
 
31 halyavin 528
    mov  eax, 53      ; write message
529
    mov  ebx, 7
530
    mov  ecx, [socket]
485 heavyiron 531
    mcall
31 halyavin 532
 
533
    jmp  send_done
534
 
535
  server_command:
536
 
537
    cmp  [send_string+1],dword 'anic'
538
    jne  no_set_nick
539
 
540
    mov  ecx,[xpos]
541
    sub  ecx,7
542
    mov  [user_nick],ecx
543
 
544
    mov  esi,send_string+7
545
    mov  edi,user_nick+4
546
    cld
547
    rep  movsb
548
 
549
    pusha
550
    mov  edi,text+70*1+15
551
    mov  eax,32
552
    mov  ecx,15
553
    cld
554
    rep  stosb
555
    popa
556
 
557
    mov  esi,user_nick+4
558
    mov  edi,text+70*1+15
559
    mov  ecx,[user_nick]
560
    cld
561
    rep  movsb
562
 
563
    call draw_window
564
 
565
    mov  [xpos],0
566
    mov  [send_to_server],0
567
 
568
    popa
569
    ret
570
 
571
  no_set_nick:
572
 
573
    cmp  [send_string+1],dword 'area'
574
    jne  no_set_real_name
575
 
576
    mov  ecx,[xpos]
577
    sub  ecx,7
578
    mov  [user_real_name],ecx
579
 
580
    mov  esi,send_string+7
581
    mov  edi,user_real_name+4
582
    cld
583
    rep  movsb
584
 
585
    pusha
586
    mov  edi,text+70*0+15
587
    mov  eax,32
588
    mov  ecx,15
589
    cld
590
    rep  stosb
591
    popa
592
 
593
    mov  esi,user_real_name+4
594
    mov  edi,text+70*0+15
595
    mov  ecx,[xpos]
596
    sub  ecx,7
597
    cld
598
    rep  movsb
599
 
600
    call draw_window
601
 
602
    mov  [xpos],0
603
    mov  [send_to_server],0
604
 
605
    popa
606
    ret
607
 
608
  no_set_real_name:
609
 
610
    cmp  [send_string+1],dword 'aser'
611
    jne  no_set_server
612
 
485 heavyiron 613
pusha
614
    mov     eax,send_string
615
    add     eax,[xpos]
616
    mov     dword[eax],0
617
    resolve send_string+7,dword[irc_server_ip]
618
    ;DEBUGF 1,'%u.%u.%u.%u\n',1[irc_server_ip],1[irc_server_ip+1],1[irc_server_ip+2],1[irc_server_ip+3]
619
popa
620
 
31 halyavin 621
    mov  ecx,[xpos]
622
    sub  ecx,7
623
 
624
    pusha
625
    mov  edi,text+70*2+15
626
    mov  eax,32
627
    mov  ecx,15
628
    cld
629
    rep  stosb
630
    popa
631
 
632
    mov  esi,send_string+7
633
    mov  edi,text+70*2+15
634
    cld
635
    rep  movsb
636
 
637
    call draw_window
638
 
639
    mov  [xpos],0
640
    mov  [send_to_server],0
641
 
642
    popa
643
    ret
644
 
645
   no_set_server:
646
 
647
 
648
 
649
 
650
    cmp  [send_string+1],dword 'quer'
651
    jne  no_query_create
652
 
653
    mov  edi,I_END+120*80
654
    mov  eax,1 ; create channel window - search for empty slot
655
   newse2:
656
    mov  ebx,eax
657
    shl  ebx,5
658
    cmp  dword [channel_list+ebx],dword '    '
195 heavyiron 659
    je	 free_found2
31 halyavin 660
    add  edi,120*80
661
    inc  eax
662
    cmp  eax,[max_windows]
195 heavyiron 663
    jb	 newse2
31 halyavin 664
 
665
  free_found2:
666
 
667
    mov  edx,send_string+7
668
 
669
    mov  ecx,[xpos]
670
    sub  ecx,7
671
    mov  [channel_list+ebx+31],cl
672
 
673
    call create_channel_name
674
 
675
    push edi
676
    push eax
677
    mov  [edi+120*60+8],byte 1 ; query window
678
    mov  eax,32
679
    mov  ecx,120*60
680
    cld
681
    rep  stosb
682
    pop  eax
683
    pop  edi
684
 
685
    ; eax has the free position
686
    mov  [thread_screen],edi
687
    call create_channel_window
688
 
689
    mov  [xpos],0
690
    mov  [send_to_server],0
691
 
692
    popa
693
    ret
694
 
695
  no_query_create:
696
 
697
 
698
    mov  esi, send_string+1
699
    mov  edx, [xpos]
700
    add  edx,1
701
 
702
    mov  eax, 53      ; write server command
703
    mov  ebx, 7
704
    mov  ecx, [socket]
485 heavyiron 705
    mcall
31 halyavin 706
 
707
  send_done:
708
 
709
    mov  [xpos],0
710
    mov  [send_to_server],0
711
 
712
    cmp  [send_string+1],dword 'quit'
713
    jne  no_quit_server
714
    mov  eax,5
715
    mov  ebx,200
485 heavyiron 716
    mcall
31 halyavin 717
 
718
    mov  eax, 53      ; close socket
719
    mov  ebx, 8
720
    mov  ecx, [socket]
485 heavyiron 721
    mcall
31 halyavin 722
 
723
    mov  ecx,[max_windows]
724
    mov  edi,I_END
725
  newclose:
726
    mov  [edi+120*60+4],byte  1
727
    add  edi,120*80
728
    loop newclose
729
 
730
    popa
731
    ret
732
 
733
  no_quit_server:
734
 
735
  sdts_ret:
736
 
737
    popa
738
    ret
739
 
740
 
741
 
742
read_incoming_data:
743
 
744
    pusha
745
 
746
  read_new_byte:
747
 
748
    call read_incoming_byte
749
    cmp  ecx,-1
195 heavyiron 750
    je	 no_data_in_buffer
31 halyavin 751
 
752
    cmp  bl,10
753
    jne  no_start_command
754
    mov  [cmd],1
755
  no_start_command:
756
 
757
    cmp  bl,13
758
    jne  no_end_command
759
    mov  eax,[cmd]
760
    mov  [eax+command-2],byte 0
761
    call analyze_command
762
    mov  edi,command
763
    mov  ecx,250
764
    mov  eax,0
765
    cld
766
    rep  stosb
767
    mov  [cmd],0
768
  no_end_command:
769
 
770
    mov  eax,[cmd]
771
    cmp  eax,512
772
    jge  still
773
 
774
    mov  [eax+command-2],bl
775
    inc  [cmd]
776
 
777
    jmp  read_new_byte
778
 
779
  no_data_in_buffer:
780
 
781
    popa
782
 
783
    ret
784
 
785
 
786
create_channel_name:
787
 
788
    pusha
789
 
790
  search_first_letter:
791
    cmp  [edx],byte ' '
792
    jne  first_letter_found
793
    inc  edx
794
    jmp  search_first_letter
795
  first_letter_found:
796
 
797
    mov  esi,edx
798
    mov  edi,channel_list
799
    add  edi,ebx
800
    mov  ecx,30
801
    xor  eax,eax
802
  newcase:
803
    mov  al,[esi]
804
    cmp  eax,'a'
195 heavyiron 805
    jb	 nocdec
31 halyavin 806
    cmp  eax,'z'
195 heavyiron 807
    jg	 nocdec
31 halyavin 808
    sub  al,97-65
809
  nocdec:
810
    mov  [edi],al
811
    inc  esi
812
    inc  edi
813
    loop newcase
814
 
815
    popa
816
 
817
    ret
818
 
819
 
820
create_channel_window:
821
 
822
    pusha
823
 
824
    mov  [cursor_on_off],0
825
 
826
    mov  [thread_nro],eax
827
 
828
    mov  eax,51
829
    mov  ebx,1
830
    mov  ecx,channel_thread
831
    mov  edx,[thread_stack]
485 heavyiron 832
    mcall
31 halyavin 833
 
834
    mov  eax,5
835
    mov  ebx,10
485 heavyiron 836
    mcall
31 halyavin 837
 
838
    add  [thread_stack],0x4000
839
    add  [thread_screen],120*80
840
 
841
    popa
842
 
843
    ret
844
 
845
 
846
print_entry:
847
 
848
    pusha
849
 
850
    mov  eax,13
851
    mov  ebx,8*65536+6*80
852
    mov  ecx,151*65536+13
853
    mov  edx,0xffffff
485 heavyiron 854
    mcall
31 halyavin 855
 
856
    mov  eax,4
857
    mov  ebx,8*65536+154
858
    mov  ecx,0x000000
859
    mov  edx,send_string
860
    mov  esi,[xpos]
485 heavyiron 861
    mcall
31 halyavin 862
 
863
    popa
864
 
865
    ret
866
 
867
blink dd 0x0
868
 
869
blink_cursor:
870
 
871
    pusha
872
 
873
    mov  eax,9
874
    mov  ebx,0xe0000
875
    mov  ecx,-1
485 heavyiron 876
    mcall
31 halyavin 877
 
878
    mov  edx,[blink]
879
    and  edx,1
880
    sub  edx,1
881
    and  edx,0xffffff
882
;    mov  edx,0
883
 
884
    cmp  ax,word [0xe0000+4]
885
    jne  no_blink
886
 
887
    call print_entry
888
 
889
    mov  ebx,[xpos]
890
    imul ebx,6
891
    add  ebx,8
892
    mov  cx,bx
893
    shl  ebx,16
894
    mov  bx,cx
895
    mov  ecx,151*65536+163
896
    mov  eax,38
485 heavyiron 897
    mcall
31 halyavin 898
 
899
    popa
900
 
901
    ret
902
 
903
  no_blink:
904
 
905
    mov  eax,13
906
    mov  ebx,8*65536+6*60
907
    mov  ecx,151*65536+13
908
    mov  edx,0xffffff
485 heavyiron 909
    mcall
31 halyavin 910
 
911
    popa
912
 
913
    ret
914
 
915
 
916
 
917
 
918
 
919
set_channel:
920
 
921
    pusha
922
 
923
    ; UPPER / LOWER CASE CHECK
924
 
925
    mov  esi,eax
926
    mov  edi,channel_temp
927
    mov  ecx,40
928
    xor  eax,eax
929
  newcase2:
930
    mov  al,[esi]
931
    cmp  eax,'#'
195 heavyiron 932
    jb	 newcase_over2
31 halyavin 933
    cmp  eax,'a'
195 heavyiron 934
    jb	 nocdec2
31 halyavin 935
    cmp  eax,'z'
195 heavyiron 936
    jg	 nocdec2
31 halyavin 937
    sub  al,97-65
938
  nocdec2:
939
    mov  [edi],al
940
    inc  esi
941
    inc  edi
942
    loop newcase2
943
  newcase_over2:
944
    sub  edi,channel_temp
945
    mov  [channel_temp_length],edi
946
 
947
    mov  eax,channel_temp
948
 
949
    mov  [text_start],I_END+120*80
950
    mov  ebx,channel_list+32
951
    mov  eax,[eax]
952
 
953
    mov  edx,[channel_temp_length]
954
 
955
  stcl1:
956
    cmp  dl,[ebx+31]
957
    jne  notfound
958
 
959
    pusha
960
    xor  eax,eax
961
    xor  edx,edx
962
    mov  ecx,0
963
  stc4:
964
    mov  dl,[ebx+ecx]
965
    mov  al,[channel_temp+ecx]
966
    cmp  eax,edx
967
    jne  notfound2
968
    inc  ecx
969
    cmp  ecx,[channel_temp_length]
195 heavyiron 970
    jb	 stc4
31 halyavin 971
    popa
972
 
973
    jmp  found
974
 
975
  notfound2:
976
    popa
977
 
978
  notfound:
979
    add  [text_start],120*80
980
    add  ebx,32
981
    cmp  ebx,channel_list+19*32
195 heavyiron 982
    jb	 stcl1
31 halyavin 983
 
984
    mov  [text_start],I_END
985
 
986
  found:
987
 
988
    popa
989
 
990
    ret
991
 
992
 
195 heavyiron 993
channel_temp:	      times   100   db	 0
31 halyavin 994
channel_temp_length   dd      0x0
995
 
996
 
997
 
998
print_nick:
999
 
1000
    pusha
1001
 
1002
    mov  eax,command+1
1003
    mov  dl,'!'
1004
    call print_text
1005
 
1006
    popa
1007
    ret
1008
 
1009
 
1010
analyze_command:
1011
 
1012
    pusha
1013
 
1014
    mov  [text_start],I_END
1015
    mov  ecx,[rxs]
1016
    imul ecx,11
1017
    mov  [pos],ecx
1018
 
1019
    mov  bl,13
1020
;  call print_character
1021
    mov  bl,10
1022
;  call print_character
1023
 
1024
    mov  ecx,[cmd]
1025
    sub  ecx,2
1026
    mov  esi,command+0
1027
  newcmdc:
1028
    mov  bl,[esi]
1029
;  call print_character
1030
    inc  esi
1031
    loop newcmdc
1032
 
1033
    mov   edx,I_END
1034
;  call  draw_channel_text
1035
 
1036
    cmp  [cmd],20
1037
    jge  cmd_len_ok
1038
 
1039
    mov  [cmd],0
1040
 
1041
    popa
1042
    ret
1043
 
1044
 
1045
  cmd_len_ok:
1046
 
1047
    cmp  [command],dword 'PING'  ; ping response
1048
    jne  no_ping_responce
1049
 
1050
    call print_command_to_main
1051
 
1052
    mov  [command],dword 'PONG'
1053
 
1054
    call print_command_to_main
1055
 
1056
    mov  eax,4
1057
    mov  ebx,100*65536+3
1058
    mov  ecx,0xffffff
1059
    mov  edx,command
1060
    mov  esi,[cmd]
1061
    mov  [command+esi-1],word '**'
485 heavyiron 1062
;    mcall
31 halyavin 1063
 
1064
    mov  eax,53
1065
    mov  ebx,7
1066
    mov  ecx,[socket]
1067
    mov  edx,[cmd]
1068
    sub  edx,2
1069
    and  edx,255
1070
    mov  esi,command
485 heavyiron 1071
    mcall
31 halyavin 1072
 
1073
    mov  eax,53
1074
    mov  ebx,7
1075
    mov  ecx,[socket]
1076
    mov  edx,2
1077
    mov  esi,linef
485 heavyiron 1078
    mcall
31 halyavin 1079
 
1080
    popa
1081
    ret
1082
 
1083
  linef  db  13,10
1084
 
1085
  no_ping_responce:
1086
 
1087
    mov  eax,[rxs]
1088
    imul eax,11
1089
    mov  [pos],eax
1090
 
1091
    mov  [command],byte '<'
1092
 
1093
    mov  eax,command
1094
    mov  ecx,100
1095
   new_blank:
1096
    cmp  [eax],byte ' '
195 heavyiron 1097
    je	 bl_found
31 halyavin 1098
    inc  eax
1099
    loop new_blank
1100
    mov  eax,50
1101
  bl_found:
1102
 
1103
    inc  eax
1104
    mov  [command_position],eax
1105
 
1106
    mov  esi,eax
1107
    mov  edi,irc_command
1108
    mov  ecx,8
1109
    cld
1110
    rep  movsb
1111
 
1112
 
1113
    cmp  [irc_command],'PRIV'  ; message to channel
1114
    jne  no_privmsg
1115
 
1116
    ; compare nick
1117
 
1118
    mov  eax,[command_position]
1119
    add  eax,8
1120
    call compare_to_nick
1121
    cmp  [cresult],0
1122
    jne  no_query_msg
1123
    mov  eax,command+1
1124
  no_query_msg:
1125
    call set_channel
1126
 
1127
    mov  ecx,100 ; [cmd]
1128
    mov  eax,command+10
1129
  acl3:
1130
    cmp  [eax],byte ':'
195 heavyiron 1131
    je	 acl4
31 halyavin 1132
    inc  eax
1133
    loop acl3
1134
    mov  eax,10
1135
  acl4:
1136
    inc  eax
1137
 
1138
    cmp  [eax+1],dword 'ACTI'
1139
    jne  no_action
1140
    push eax
1141
    mov  eax,action_header_short
1142
    mov  dl,0
1143
    call print_text
1144
    mov  eax,command+1
1145
    mov  dl,'!'
1146
    call print_text
1147
    mov  bl,' '
1148
    call print_character
1149
    pop  eax
1150
    add  eax,8
1151
    mov  dl,0
1152
    call print_text
1153
    popa
1154
    ret
1155
 
1156
  no_action:
1157
 
1158
    push eax
1159
    mov  bl,10
1160
    call print_character
1161
    mov  eax,command
1162
    mov  dl,'!'
1163
    call print_text
1164
    mov  bl,'>'
1165
    call print_character
1166
    mov  bl,' '
1167
    call print_character
1168
    pop  eax
1169
 
1170
    mov  dl,0
1171
    call print_text
1172
 
1173
    popa
1174
    ret
1175
 
1176
  no_privmsg:
1177
 
1178
 
195 heavyiron 1179
    cmp  [irc_command],'PART'	 ; channel leave
31 halyavin 1180
    jne  no_part
1181
 
1182
    ; compare nick
1183
 
1184
    mov  eax,command+1
1185
    call compare_to_nick
1186
    cmp  [cresult],0
1187
    jne  no_close_window
1188
 
1189
    mov  eax,[command_position]
1190
    add  eax,5
1191
    call set_channel
1192
 
1193
    mov  eax,[text_start]
1194
    mov  [eax+120*60+4],byte 1
1195
 
1196
    popa
1197
    ret
1198
 
1199
  no_close_window:
1200
 
1201
    mov  eax,[command_position]
1202
    add  eax,5
1203
    call set_channel
1204
 
1205
    mov  eax,action_header_red
1206
    mov  dl,0
1207
    call print_text
1208
    mov  eax,command+1
1209
    mov  dl,'!'
1210
    mov  cl,' '
1211
    call print_text
1212
    mov  eax,has_left_channel
1213
    mov  dl,0
1214
    call print_text
1215
    mov  eax,[command_position]
1216
    add  eax,5
1217
    mov  dl,' '
1218
    call print_text
1219
 
1220
    popa
1221
    ret
1222
 
1223
  no_part:
1224
 
1225
 
195 heavyiron 1226
    cmp  [irc_command],'JOIN'	 ; channel join
31 halyavin 1227
    jne  no_join
1228
 
1229
    ; compare nick
1230
 
1231
    mov  eax,command+1
1232
    call compare_to_nick
1233
    cmp  [cresult],0
1234
    jne  no_new_window
1235
 
1236
    mov  edi,I_END+120*80
1237
    mov  eax,1 ; create channel window - search for empty slot
1238
   newse:
1239
    mov  ebx,eax
1240
    shl  ebx,5
1241
    cmp  dword [channel_list+ebx],dword '    '
195 heavyiron 1242
    je	 free_found
31 halyavin 1243
    add  edi,120*80
1244
    inc  eax
1245
    cmp  eax,[max_windows]
195 heavyiron 1246
    jb	 newse
31 halyavin 1247
 
1248
  free_found:
1249
 
1250
    mov  edx,[command_position]
1251
    add  edx,6
1252
 
1253
    push eax
1254
    push edx
1255
    mov  ecx,0
1256
   finde:
1257
    inc  ecx
1258
    inc  edx
1259
    movzx eax,byte [edx]
1260
    cmp  eax,'#'
1261
    jge  finde
1262
    mov  [channel_list+ebx+31],cl
1263
    pop  edx
1264
    pop  eax
1265
 
1266
    call create_channel_name
1267
 
1268
    push edi
1269
    push eax
1270
    mov  [edi+120*60+8],byte 0 ; channel window
1271
    mov  eax,32
1272
    mov  ecx,120*60
1273
    cld
1274
    rep  stosb
1275
    pop  eax
1276
    pop  edi
1277
 
1278
    ; eax has the free position
1279
    mov  [thread_screen],edi
1280
    call create_channel_window
1281
 
1282
  no_new_window:
1283
 
1284
    mov  eax,[command_position]
1285
    add  eax,6
1286
    call set_channel
1287
 
1288
    mov  eax,action_header_blue
1289
    mov  dl,0
1290
    call print_text
1291
    mov  eax,command+1
1292
    mov  dl,'!'
1293
    mov  cl,' '
1294
    call print_text
1295
 
1296
    mov  eax,joins_channel
1297
    mov  dl,0
1298
    call print_text
1299
 
1300
    mov  eax,[command_position]
1301
    add  eax,6
1302
    mov  dl,0
1303
    call print_text
1304
 
1305
    popa
1306
    ret
1307
 
1308
  no_join:
1309
 
1310
 
195 heavyiron 1311
    cmp  [irc_command],'NICK'	   ; nick change
31 halyavin 1312
    jne  no_nick_change
1313
 
1314
    mov  [text_start],I_END
1315
    add  [text_start],120*80
1316
 
1317
 new_all_channels3:
1318
 
1319
    mov  eax,action_header_short
1320
    mov  dl,0
1321
    call print_text
1322
    mov  eax,command+1
1323
    mov  dl,'!'
1324
    call print_text
1325
    mov  eax,is_now_known_as
1326
    mov  dl,0
1327
    call print_text
1328
    mov  eax,[command_position]
1329
    add  eax,6
1330
    mov  dl,0
1331
    call print_text
1332
 
1333
    add  [text_start],120*80
1334
    cmp  [text_start],I_END+120*80*20
195 heavyiron 1335
    jb	 new_all_channels3
31 halyavin 1336
 
1337
    popa
1338
    ret
1339
 
1340
  no_nick_change:
1341
 
1342
 
195 heavyiron 1343
     cmp  [irc_command],'KICK'	    ; kick
31 halyavin 1344
     jne  no_kick
1345
 
1346
    mov  [text_start],I_END
1347
    add  [text_start],120*80
1348
 
1349
    mov  eax,[command_position]
1350
    add  eax,5
1351
    call set_channel
1352
 
1353
; new_all_channels4:
1354
 
1355
    mov  eax,action_header_short
1356
    mov  dl,0
1357
    call print_text
1358
    mov  eax,command+1
1359
    mov  dl,'!'
1360
    call print_text
1361
     mov  eax,kicked
1362
     mov  dl,0
1363
    call print_text
1364
    mov  eax,[command_position]
1365
    add  eax,5
1366
    mov  dl,0
1367
    call print_text
1368
 
1369
;    add  [text_start],120*80
1370
;    cmp  [text_start],I_END+120*80*20
1371
;    jb   new_all_channels4
1372
 
1373
    popa
1374
    ret
1375
 
1376
  no_kick:
1377
 
1378
 
1379
 
1380
 
195 heavyiron 1381
    cmp  [irc_command],'QUIT'	 ; irc quit
31 halyavin 1382
    jne  no_quit
1383
 
1384
    mov  [text_start],I_END
1385
    add  [text_start],120*80
1386
 
1387
 new_all_channels2:
1388
 
1389
    mov  eax,action_header_red
1390
    mov  dl,0
1391
    call print_text
1392
    mov  eax,command+1
1393
    mov  dl,'!'
1394
    call print_text
1395
    mov  eax,has_quit_irc
1396
    mov  dl,0
1397
    call print_text
1398
 
1399
    add  [text_start],120*80
1400
    cmp  [text_start],I_END+120*80*20
195 heavyiron 1401
    jb	 new_all_channels2
31 halyavin 1402
 
1403
    popa
1404
    ret
1405
 
1406
  no_quit:
1407
 
1408
 
1409
    cmp  [irc_command],dword 'MODE'  ; channel mode change
1410
    jne  no_mode
1411
 
1412
    mov  [text_start],I_END
1413
    add  [text_start],120*80
1414
 
1415
    mov  eax,[command_position]
1416
    add  eax,5
1417
    call set_channel
1418
 
1419
 new_all_channels:
1420
 
1421
    mov  eax,action_header_short
1422
    mov  dl,0
1423
    call print_text
1424
 
1425
    call print_nick
1426
 
1427
    mov  eax,sets_mode
1428
    mov  dl,0
1429
    call print_text
1430
 
1431
    mov  eax,[command_position]
1432
    add  eax,5
1433
    mov  dl,0
1434
    call print_text
1435
 
1436
;    add  [text_start],120*80
1437
;    cmp  [text_start],I_END+120*80*20
1438
;    jb   new_all_channels
1439
 
1440
    popa
1441
    ret
1442
 
1443
  no_mode:
1444
 
1445
 
1446
    cmp  [irc_command],dword '353 '  ; channel user names
1447
    jne  no_user_list
1448
 
1449
    mov  eax,[command_position]
1450
   finde2:
1451
    inc  eax
1452
    cmp  [eax],byte '#'
1453
    jne  finde2
1454
    call set_channel
1455
 
1456
   finde3:
1457
    inc  eax
1458
    cmp  [eax],byte ':'
1459
    jne  finde3
1460
 
1461
    pusha
1462
    cmp  [user_list_pos],0
1463
    jne  no_clear_user_list
1464
    mov  edi,[text_start]
1465
    add  edi,120*70
1466
    mov  [edi-8],dword 0
1467
    mov  [edi-4],dword 0
1468
    mov  eax,32
1469
    mov  ecx,1200
1470
    cld
1471
    rep  stosb
1472
  no_clear_user_list:
1473
    popa
1474
 
1475
    push eax
1476
 
1477
    mov  esi,eax
1478
    inc  esi
1479
    mov  edi,[text_start]
1480
    add  edi,120*70
1481
    add  edi,[user_list_pos]
1482
    mov  edx,edi
1483
    mov  ecx,command
1484
    add  ecx,[cmd]
1485
    sub  ecx,[esp]
1486
    sub  ecx,3
1487
    and  ecx,0xfff
1488
    cld
1489
    rep  movsb
1490
 
1491
    pop  eax
1492
    mov  ebx,command
1493
    add  ebx,[cmd]
1494
    sub  ebx,eax
1495
    sub  ebx,2
1496
    mov  [edx+ebx-1],dword '    '
1497
 
1498
    add  [user_list_pos],ebx
1499
 
1500
    mov  eax,[user_list_pos]
1501
    mov  ebx,[text_start]
1502
    add  ebx,120*70
1503
    mov  [ebx-4],eax
1504
 
1505
    popa
1506
    ret
1507
 
1508
  user_list_pos dd 0x0
1509
 
1510
  no_user_list:
1511
 
1512
 
1513
    cmp  [irc_command],dword '366 '  ; channel user names end
1514
    jne  no_user_list_end
1515
 
1516
    mov  [user_list_pos],0
1517
 
1518
    popa
1519
    ret
1520
 
1521
  no_user_list_end:
1522
 
1523
    mov  [command],byte '-'
1524
    call print_command_to_main
1525
 
1526
    popa
1527
 
1528
    ret
1529
 
1530
 
1531
cresult db 0
1532
 
1533
compare_to_nick:
1534
 
1535
; input  : eax = start of compare
1536
; output : [cresult] = 0 if match, [cresult]=1 if no match
1537
 
1538
 
1539
    pusha
1540
 
1541
    mov  esi,eax
1542
    mov  edi,0
1543
 
1544
  new_nick_compare:
1545
 
1546
    mov  bl,byte [esi]
1547
    mov  cl,byte [user_nick+4+edi]
1548
 
1549
    cmp  bl,cl
1550
    jne  nonickm
1551
 
1552
    add  esi,1
1553
    add  edi,1
1554
 
1555
    cmp  edi,[user_nick]
195 heavyiron 1556
    jb	 new_nick_compare
31 halyavin 1557
 
1558
    movzx eax,byte [esi]
1559
    cmp  eax,40
1560
    jge  nonickm
1561
 
1562
    popa
1563
    mov  [cresult],0
1564
    ret
1565
 
1566
  nonickm:
1567
 
1568
    popa
1569
    mov  [cresult],1
1570
    ret
1571
 
1572
 
1573
 
1574
 
1575
 
1576
print_command_to_main:
1577
 
1578
    pusha
1579
 
1580
    mov  [text_start],I_END
1581
    mov  ecx,[rxs]
1582
    imul ecx,11
1583
    mov  [pos],ecx
1584
 
1585
    mov  bl,13
1586
    call print_character
1587
    mov  bl,10
1588
    call print_character
1589
 
1590
    mov  ecx,[cmd]
1591
    sub  ecx,2
1592
    mov  esi,command
1593
   newcmdc2:
1594
    mov  bl,[esi]
1595
    call print_character
1596
    inc  esi
1597
    loop newcmdc2
1598
 
1599
    mov   edx,I_END
1600
    call  draw_channel_text
1601
 
1602
    popa
1603
 
1604
    ret
1605
 
1606
 
1607
 
1608
 
1609
print_text:
1610
 
1611
    pusha
1612
 
1613
    mov  ecx,command-2
1614
    add  ecx,[cmd]
1615
 
1616
  ptr2:
1617
    mov  bl,[eax]
1618
    cmp  bl,dl
195 heavyiron 1619
    je	 ptr_ret
31 halyavin 1620
    cmp  bl,0
195 heavyiron 1621
    je	 ptr_ret
31 halyavin 1622
    call print_character
1623
    inc  eax
1624
    cmp  eax,ecx
1625
    jbe  ptr2
1626
 
1627
  ptr_ret:
1628
 
1629
    mov  eax,[text_start]
1630
    mov  [eax+120*60],byte 1
1631
 
1632
    popa
1633
    ret
1634
 
1635
 
195 heavyiron 1636
cp1251_table:
1637
  db '?','?','?','?','?','?','?','?' , '?','?','?','?','?','?','?','?' ; 8
556 heavyiron 1638
  db '?','?','?','?','?',$F9,'?','?' , '?','?','?','?','?','?','?','?' ; 9
1639
  db '?',$F6,$F7,'?',$FD,'?','?','?' , $F0,'?',$F2,'?','?','?','?',$F4 ; A
1640
  db $F8,'?','?','?','?','?','?',$FA , $F1,$FC,$F3,'?','?','?','?',$F5 ; B
195 heavyiron 1641
  db $80,$81,$82,$83,$84,$85,$86,$87 , $88,$89,$8A,$8B,$8C,$8D,$8E,$8F ; C
1642
  db $90,$91,$92,$93,$94,$95,$96,$97 , $98,$99,$9A,$9B,$9C,$9D,$9E,$9F ; D
1643
  db $A0,$A1,$A2,$A3,$A4,$A5,$A6,$A7 , $A8,$A9,$AA,$AB,$AC,$AD,$AE,$AF ; E
1644
  db $E0,$E1,$E2,$E3,$E4,$E5,$E6,$E7 , $E8,$E9,$EA,$EB,$EC,$ED,$EE,$EF ; F
556 heavyiron 1645
 
485 heavyiron 1646
;    0   1   2   3   4   5   6   7     8   9   A   B   C   D   E   F
31 halyavin 1647
 
195 heavyiron 1648
cp866_table:
1649
  db $C0,$C1,$C2,$C3,$C4,$C5,$C6,$C7 , $C8,$C9,$CA,$CB,$CC,$CD,$CE,$CF ; 8
1650
  db $D0,$D1,$D2,$D3,$D4,$D5,$D6,$D7 , $D8,$D9,$DA,$DB,$DC,$DD,$DE,$DF ; 9
1651
  db $E0,$E1,$E2,$E3,$E4,$E5,$E6,$E7 , $E8,$E9,$EA,$EB,$EC,$ED,$EE,$EF ; A
1652
  db '?','?','?','?','?','?','?','?' , '?','?','?','?','?','?','?','?' ; B
1653
  db '?','?','?','?','?','?','?','?' , '?','?','?','?','?','?','?','?' ; C
1654
  db '?','?','?','?','?','?','?','?' , '?','?','?','?','?','?','?','?' ; D
1655
  db $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7 , $F8,$F9,$FA,$FB,$FC,$FD,$FE,$FF ; E
556 heavyiron 1656
  db $A8,$B8,$AA,$BA,$AF,$BF,$A1,$A2 , $B0,$95,$B7,'?',$B9,$A4,'?','?' ; F
1657
 
485 heavyiron 1658
;    0   1   2   3   4   5   6   7     8   9   A   B   C   D   E   F
195 heavyiron 1659
 
31 halyavin 1660
print_character:
1661
 
1662
    pusha
1663
 
195 heavyiron 1664
    cmp  bl,13	   ; line beginning
31 halyavin 1665
    jne  nobol
1666
    mov  ecx,[pos]
1667
    add  ecx,1
1668
  boll1:
1669
    sub  ecx,1
1670
    mov  eax,ecx
1671
    xor  edx,edx
1672
    mov  ebx,[rxs]
1673
    div  ebx
1674
    cmp  edx,0
1675
    jne  boll1
1676
    mov  [pos],ecx
1677
    jmp  newdata
1678
  nobol:
1679
 
195 heavyiron 1680
    cmp  bl,10	   ; line down
31 halyavin 1681
    jne  nolf
1682
   addx1:
1683
    add  [pos],dword 1
1684
    mov  eax,[pos]
1685
    xor  edx,edx
1686
    mov  ecx,[rxs]
1687
    div  ecx
1688
    cmp  edx,0
1689
    jnz  addx1
1690
    mov  eax,[pos]
1691
    jmp  cm1
1692
  nolf:
1693
  no_lf_ret:
1694
 
1695
 
195 heavyiron 1696
    cmp  bl,15	  ; character
31 halyavin 1697
    jbe  newdata
1698
 
1699
    mov  eax,[irc_data]
1700
    shl  eax,8
1701
    mov  al,bl
1702
    mov  [irc_data],eax
1703
 
1704
    mov  eax,[pos]
1705
    call draw_data
1706
 
1707
    mov  eax,[pos]
1708
    add  eax,1
1709
  cm1:
1710
    mov  ebx,[scroll+4]
1711
    imul ebx,[rxs]
1712
    cmp  eax,ebx
195 heavyiron 1713
    jb	 noeaxz
31 halyavin 1714
 
1715
    mov  esi,[text_start]
1716
    add  esi,[rxs]
1717
 
1718
    mov  edi,[text_start]
1719
    mov  ecx,ebx
1720
    cld
1721
    rep  movsb
1722
 
1723
    mov  esi,[text_start]
1724
    mov  ecx,[rxs]
1725
    imul ecx,61
1726
    add  esi,ecx
1727
 
1728
    mov  edi,[text_start]
1729
    mov  ecx,[rxs]
1730
    imul ecx,60
1731
    add  edi,ecx
1732
    mov  ecx,ebx
1733
    cld
1734
    rep  movsb
1735
 
1736
    mov  eax,ebx
1737
    sub  eax,[rxs]
1738
  noeaxz:
1739
    mov  [pos],eax
1740
 
1741
  newdata:
1742
 
1743
    mov  eax,[text_start]
1744
    mov  [eax+120*60],byte 1
1745
 
1746
    popa
1747
    ret
1748
 
1749
 
1750
 
1751
draw_data:
1752
 
1753
    pusha
1754
 
1755
    and  ebx,0xff
1756
    add  eax,[text_start]
1757
    mov  [eax],bl
1758
 
1759
    popa
1760
    ret
1761
 
1762
 
1763
read_incoming_byte:
1764
 
1765
    mov  eax, 53
1766
    mov  ebx, 2
1767
    mov  ecx, [socket]
485 heavyiron 1768
    mcall
31 halyavin 1769
 
1770
    mov  ecx,-1
1771
 
1772
    cmp  eax,0
195 heavyiron 1773
    je	 no_more_data
31 halyavin 1774
 
1775
    mov  eax, 53
1776
    mov  ebx, 3
1777
    mov  ecx, [socket]
485 heavyiron 1778
    mcall
31 halyavin 1779
 
195 heavyiron 1780
	cmp	bl,0x80
1781
	jb	@f
1782
	and	ebx,0x7F
1783
	mov	bl,[cp1251_table+ebx]
1784
    @@:
1785
 
31 halyavin 1786
    mov  ecx,0
1787
 
1788
  no_more_data:
1789
 
1790
    ret
1791
 
1792
 
1793
 
1794
draw_window:
1795
 
1796
    pusha
1797
 
1798
    mov  eax,12
1799
    mov  ebx,1
485 heavyiron 1800
    mcall
31 halyavin 1801
 
1802
    mov  [old_status],300
1803
 
485 heavyiron 1804
    xor  eax,eax		   ; draw window
31 halyavin 1805
    mov  ebx,5*65536+499
1806
    mov  ecx,5*65536+345
1807
    mov  edx,[wcolor]
551 spraid 1808
    add  edx,0x14ffffff
485 heavyiron 1809
    mov  edi,title
1810
    mcall
31 halyavin 1811
 
195 heavyiron 1812
    mov  eax,8			   ; button: open socket
31 halyavin 1813
    mov  ebx,43*65536+22
1814
    mov  ecx,229*65536+10
1815
    mov  edx,22
1816
    mov  esi,[main_button]
485 heavyiron 1817
    mcall
31 halyavin 1818
 
485 heavyiron 1819
    ;mov  eax,8			   ; button: send userinfo
31 halyavin 1820
    mov  ebx,180*65536+22
1821
    mov  ecx,229*65536+10
1822
    mov  edx,23
485 heavyiron 1823
    mcall
31 halyavin 1824
 
485 heavyiron 1825
    ;mov  eax,8			   ; button: close socket
31 halyavin 1826
    mov  ebx,317*65536+22
1827
    mov  ecx,229*65536+10
1828
    mov  edx,24
485 heavyiron 1829
    mcall
31 halyavin 1830
 
195 heavyiron 1831
    mov  eax,38 		   ; line
31 halyavin 1832
    mov  ebx,5*65536+494
1833
    mov  ecx,148*65536+148
1834
    mov  edx,[main_line]
485 heavyiron 1835
    mcall
31 halyavin 1836
    add  ecx,1*65536+1
1837
 
195 heavyiron 1838
    mov  eax,38 		   ; line
31 halyavin 1839
    mov  ebx,5*65536+494
1840
    mov  ecx,166*65536+166
485 heavyiron 1841
    mcall
31 halyavin 1842
    add  ecx,1*65536+1
1843
 
195 heavyiron 1844
    mov  eax,38 		   ; line
31 halyavin 1845
    mov  ebx,410*65536+410
1846
    mov  ecx,22*65536+148
485 heavyiron 1847
    mcall
31 halyavin 1848
    add  ebx,1*65536+1
1849
 
195 heavyiron 1850
    mov  ebx,25*65536+183	   ; info text
31 halyavin 1851
    mov  ecx,0x000000
1852
    mov  edx,text
1853
    mov  esi,70
1854
  newline:
1855
    mov  eax,4
485 heavyiron 1856
    mcall
31 halyavin 1857
    add  ebx,12
1858
    add  edx,70
1859
    cmp  [edx],byte 'x'
1860
    jne  newline
1861
 
195 heavyiron 1862
    mov  edx,I_END		  ; text from server
31 halyavin 1863
    call draw_channel_text
1864
 
1865
    mov  eax,12
1866
    mov  ebx,2
485 heavyiron 1867
    mcall
31 halyavin 1868
 
1869
    popa
1870
 
1871
    ret
1872
 
1873
main_line    dd 0x000000
1874
main_button  dd 0x6565cc
1875
 
1876
 
1877
text:
1878
 
195 heavyiron 1879
db '   Real name : KolibriOS User  - change with eg /areal Jill User      '
556 heavyiron 1880
db '   Nick      : kolibri_user    - change with eg /anick Jill           '
485 heavyiron 1881
db '   Server    : kolibrios.org   - change with eg /aserv irc.by         '
31 halyavin 1882
db '                                                                      '
1883
db '        1) Open socket         2) Send userinfo       Close socket    '
1884
db '                                                                      '
1885
db '   Commands after established connection:                             '
1886
db '                                                                      '
195 heavyiron 1887
db '   /join #ChannelName         - eg /join #general                     '
1888
db '   /part #ChannelName         - eg /part #windows                     '
31 halyavin 1889
db '   /query Nickname            - eg /query Mary                        '
1890
db '   /quit                      - Quit server and Close socket          '
195 heavyiron 1891
db 'x' ; <- END MARKER, DONT DELETE
31 halyavin 1892
 
1893
 
1894
 
1895
 
1896
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1897
;
1898
;                        CHANNEL THREADS
1899
;
1900
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1901
 
1902
 
1903
 
1904
channel_thread:
1905
 
1906
    mov   ebp,[thread_nro]
1907
    mov   eax,ebp
1908
    shl   eax,14
1909
    add   eax,0x80000
1910
    mov   esp,eax
1911
 
195 heavyiron 1912
    mov   edi,ebp	 ; clear thread memory
31 halyavin 1913
    imul  edi,120*80
1914
    add   edi,I_END
1915
    mov   ecx,120*80
1916
    mov   eax,32
1917
    cld
1918
;    rep   stosb
1919
 
1920
    mov   edx,[thread_screen]
1921
 
1922
    call  thread_draw_window
1923
 
1924
  w_t:
1925
 
1926
    mov  esi,ebp
1927
    imul esi,120*80
1928
    add  esi,I_END
1929
    cmp  [esi+120*60+4],byte 1
1930
    jne  no_channel_leave
1931
    mov  [esi+120*60+4],byte 0
1932
    mov  edi,ebp
1933
    shl  edi,5
1934
    mov  dword [channel_list+edi],dword '    '
1935
    mov  byte  [channel_list+edi+31],byte 1
1936
    mov  eax,-1
485 heavyiron 1937
    mcall
31 halyavin 1938
  no_channel_leave:
1939
 
1940
    call  check_mouse
1941
 
1942
    mov   eax,23
1943
    mov   ebx,1
485 heavyiron 1944
    mcall
31 halyavin 1945
 
1946
    cmp   eax,1
1947
    jne   no_draw_window
1948
    call  thread_draw_window
1949
    call  draw_channel_text
1950
    call  print_user_list
1951
  no_draw_window:
1952
 
1953
    cmp   eax,2
195 heavyiron 1954
    je	  thread_key
31 halyavin 1955
 
1956
    cmp   eax,3
1957
    jne   no_end
1958
    mov   eax,17
485 heavyiron 1959
    mcall
31 halyavin 1960
    mov   eax,ebp
1961
    imul  eax,120*80
1962
    add   eax,I_END
1963
    cmp   [eax+120*60+8],byte 0 ; channel window
195 heavyiron 1964
    je	  not_close
31 halyavin 1965
    mov   eax,ebp
1966
    shl   eax,5
1967
    add   eax,channel_list
1968
    mov   [eax],dword '    '
1969
    mov   [eax+31],byte 1
1970
    mov   eax,-1
485 heavyiron 1971
    mcall
31 halyavin 1972
  not_close:
1973
    mov   [text_start],eax
1974
    mov   eax,nocl
1975
  newcc:
1976
    mov   bl,[eax]
1977
    call  print_character
1978
    inc   eax
1979
    cmp   [eax],byte 0
1980
    jne   newcc
1981
    call  draw_channel_text
1982
    jmp   w_t
1983
   nocl:   db  13,10,'To exit channel, use PART or QUIT command.',0
1984
   no_end:
1985
 
1986
    cmp   [edx+120*60],byte 1
1987
    jne   no_update
1988
    mov   [edx+120*60],byte 0
1989
    call  draw_channel_text
1990
  no_update:
1991
 
1992
    test [cursor_on_off],0x3f
1993
    jnz   nopri2
1994
 
1995
    call  blink_cursor
1996
    call  print_user_list
1997
 
1998
  nopri2:
1999
 
2000
    jmp   w_t
2001
 
2002
 
2003
 
2004
check_mouse:
2005
 
2006
    pusha
2007
 
2008
    mov  eax,37
2009
    mov  ebx,1
485 heavyiron 2010
    mcall
31 halyavin 2011
 
2012
    mov  ebx,eax
2013
    shr  eax,16
2014
    and  ebx,0xffff
2015
 
2016
    cmp  eax,420
195 heavyiron 2017
    jb	 no_mouse
31 halyavin 2018
    cmp  eax,494
195 heavyiron 2019
    jg	 no_mouse
31 halyavin 2020
 
2021
    cmp  ebx,145
195 heavyiron 2022
    jg	 no_mouse
31 halyavin 2023
    cmp  ebx,23
195 heavyiron 2024
    jb	 no_mouse
31 halyavin 2025
 
2026
 
2027
    cmp  ebx,100
195 heavyiron 2028
    jb	 no_plus
31 halyavin 2029
    mov  eax,ebp
2030
    imul eax,120*80
2031
    add  eax,120*70+I_END
2032
    inc  dword [eax-8]
2033
    call print_user_list
2034
    mov  eax,5
2035
    mov  ebx,8
485 heavyiron 2036
    mcall
31 halyavin 2037
    jmp  no_mouse
2038
  no_plus:
2039
 
2040
    cmp  ebx,80
195 heavyiron 2041
    jg	 no_mouse
31 halyavin 2042
    mov  eax,ebp
2043
    imul eax,120*80
2044
    add  eax,120*70+I_END
2045
    cmp  dword [eax-8],dword 0
195 heavyiron 2046
    je	 no_mouse
31 halyavin 2047
    dec  dword [eax-8]
2048
    call print_user_list
2049
    mov  eax,5
2050
    mov  ebx,8
485 heavyiron 2051
    mcall
31 halyavin 2052
 
2053
  no_minus:
2054
 
2055
  no_mouse:
2056
 
2057
    popa
2058
 
2059
    ret
2060
 
2061
 
2062
 
2063
 
2064
thread_key:
2065
 
2066
    mov  eax,2
485 heavyiron 2067
    mcall
31 halyavin 2068
 
2069
    shr  eax,8
2070
 
2071
    cmp  eax,8
2072
    jne  no_bks
2073
    cmp  [xpos],0
195 heavyiron 2074
    je	 w_t
31 halyavin 2075
    dec  [xpos]
2076
    call print_entry
2077
    jmp  w_t
2078
   no_bks:
2079
 
2080
    cmp  eax,20
2081
    jbe  no_character
2082
    mov  ebx,[xpos]
2083
    mov  [send_string+ebx],al
2084
    inc  [xpos]
2085
    cmp  [xpos],80
195 heavyiron 2086
    jb	 xpok
31 halyavin 2087
    mov  [xpos],79
2088
  xpok:
2089
    call print_entry
2090
    jmp  w_t
2091
  no_character:
2092
 
2093
    cmp  eax,13
2094
    jne  no_send
2095
    cmp  [xpos],0
195 heavyiron 2096
    je	 no_send
31 halyavin 2097
    mov  dword [send_to_channel],ebp
2098
    mov  [send_to_server],1
2099
  wait_for_sending:
2100
    mov  eax,5
2101
    mov  ebx,1
485 heavyiron 2102
    mcall
31 halyavin 2103
    cmp  [send_to_server],1
195 heavyiron 2104
    je	 wait_for_sending
31 halyavin 2105
    call draw_channel_text
2106
    call print_entry
2107
    jmp  w_t
2108
  no_send:
2109
 
2110
    jmp  w_t
2111
 
2112
 
2113
 
2114
 
2115
 
2116
 
2117
draw_channel_text:
2118
 
2119
    pusha
2120
 
2121
    mov   eax,4
2122
    mov   ebx,10*65536+26
2123
    mov   ecx,12
2124
    mov   esi,[rxs]
2125
  dct:
2126
    pusha
2127
    mov   cx,bx
2128
    shl   ecx,16
2129
    mov   cx,9
2130
    mov   eax,13
2131
    mov   ebx,10*65536
2132
    mov   bx,word [rxs]
2133
    imul  bx,6
2134
    mov   edx,0xffffff
485 heavyiron 2135
    mcall
31 halyavin 2136
    popa
2137
    push  ecx
2138
    mov   eax,4
2139
    mov   ecx,0
2140
    cmp   [edx],word '* '
2141
    jne   no_red
2142
    mov   ecx,0x0000ff
2143
   no_red:
2144
    cmp   [edx],word '**'
2145
    jne   no_light_blue
2146
    cmp   [edx+2],byte '*'
2147
    jne   no_light_blue
2148
    mov   ecx,0x0000ff
2149
  no_light_blue:
2150
    cmp   [edx],byte '#'
2151
    jne   no_blue
2152
    mov   ecx,0x0000ff
2153
  no_blue:
485 heavyiron 2154
    mcall
31 halyavin 2155
    add   edx,[rxs]
2156
    add   ebx,10
2157
    pop   ecx
2158
    loop  dct
2159
 
2160
    popa
2161
    ret
2162
 
2163
 
2164
 
2165
 
2166
 
2167
thread_draw_window:
2168
 
2169
    pusha
2170
 
2171
    mov  eax,12
2172
    mov  ebx,1
485 heavyiron 2173
    mcall
31 halyavin 2174
 
195 heavyiron 2175
    mov  ebx,ebp		   ; draw window
31 halyavin 2176
    shl  ebx,16+4
556 heavyiron 2177
    xor  eax,eax
31 halyavin 2178
    mov  ecx,ebx
2179
    mov  bx,499
2180
    mov  cx,170
2181
 
2182
    mov  edx,[wcolor]
2183
    add  edx,0x03ffffff
2184
    mov  esi,0x80555599
2185
    mov  edi,0x00ffffff
2186
 
485 heavyiron 2187
    mcall
31 halyavin 2188
 
195 heavyiron 2189
    mov  eax,ebp		   ; label
31 halyavin 2190
    add  eax,48
2191
    mov  [labelc+14],al
2192
    mov  eax,ebp
2193
    shl  eax,5
2194
    add  eax,channel_list
2195
    mov  esi,eax
2196
    mov  edi,labelc+17
2197
    movzx ecx,byte [eax+31]
2198
    cld
2199
    rep   movsb
2200
 
195 heavyiron 2201
    mov  esi,17 		   ; print label
31 halyavin 2202
    movzx ebx,byte [eax+31]
2203
    add  esi,ebx
2204
    mov  eax,4
2205
    mov  ebx,9*65536+8
2206
    mov  ecx,0x00ffffff
2207
    mov  edx,labelc
485 heavyiron 2208
    mcall
31 halyavin 2209
 
195 heavyiron 2210
    mov  eax,38 		   ; line
31 halyavin 2211
    mov  ebx,5*65536+494
2212
    mov  ecx,148*65536+148
2213
    mov  edx,[channel_line_sun]
485 heavyiron 2214
    mcall
31 halyavin 2215
    add  ecx,1*65536+1
2216
    mov  edx,[channel_line_shadow]
485 heavyiron 2217
    mcall
31 halyavin 2218
 
2219
 
485 heavyiron 2220
    ;mov  eax,38 		   ; line
31 halyavin 2221
    mov  ebx,410*65536+410
2222
    mov  ecx,22*65536+148
2223
    mov  edx,[channel_line_sun]
485 heavyiron 2224
    mcall
31 halyavin 2225
    add  ebx,1*65536+1
2226
    mov  edx,[channel_line_shadow]
485 heavyiron 2227
    mcall
31 halyavin 2228
 
2229
    mov  eax,12
2230
    mov  ebx,2
485 heavyiron 2231
    mcall
31 halyavin 2232
 
2233
    popa
2234
 
2235
    ret
2236
 
2237
 
2238
; DATA AREA
2239
 
195 heavyiron 2240
socket	dd  0x0
31 halyavin 2241
 
2242
bgc  dd  0x000000
2243
     dd  0x000000
2244
     dd  0x00ff00
2245
     dd  0x0000ff
2246
     dd  0x005500
2247
     dd  0xff00ff
2248
     dd  0x00ffff
2249
     dd  0x770077
2250
 
2251
tc   dd  0xffffff
2252
     dd  0xff00ff
2253
     dd  0xffffff
2254
     dd  0xffffff
2255
     dd  0xffffff
2256
     dd  0xffffff
2257
     dd  0xffffff
2258
     dd  0xffffff
2259
 
2260
channel_line_sun    dd 0x9999ff
2261
channel_line_shadow dd 0x666699
2262
 
2263
cursor_on_off  dd  0x0
2264
 
2265
max_windows    dd  20
2266
 
2267
thread_stack   dd  0x9fff0
2268
thread_nro     dd 1
2269
thread_screen  dd I_END+120*80*1
2270
 
195 heavyiron 2271
action_header_blue  db	10,'*** ',0
2272
action_header_red   db	10,'*** ',0
31 halyavin 2273
 
195 heavyiron 2274
action_header_short db	10,'* ',0
31 halyavin 2275
 
195 heavyiron 2276
has_left_channel db  ' has left ',0
2277
joins_channel	 db  ' has joined ',0
31 halyavin 2278
is_now_known_as  db  ' is now known as ',0
195 heavyiron 2279
has_quit_irc	 db  ' has quit IRC',0
2280
sets_mode	 db  ' sets mode ',0
2281
kicked		 db  ' kicked from ',0
31 halyavin 2282
 
195 heavyiron 2283
index_list_1	 dd  0x0000bb
2284
index_list_2	 dd  0x0000ff
31 halyavin 2285
 
195 heavyiron 2286
posx		 dd  0x0
2287
incoming_pos	 dd  0x0
31 halyavin 2288
incoming_string: times 128 db 0
2289
 
195 heavyiron 2290
pos	     dd  0x0
31 halyavin 2291
 
2292
text_start   dd  I_END
2293
irc_data     dd  0x0
195 heavyiron 2294
print	     db  0x0
2295
cmd	     dd  0x0
2296
rxs	     dd  66
31 halyavin 2297
 
195 heavyiron 2298
res:	     db  0,0
31 halyavin 2299
command:     times  600  db 0x0
2300
 
195 heavyiron 2301
nick	     dd  0,0,0
31 halyavin 2302
irc_command  dd  0,0
2303
 
2304
command_position  dd 0x0
195 heavyiron 2305
counter 	  dd  0
2306
send_to_server	  db 0
31 halyavin 2307
 
195 heavyiron 2308
channel_list:	  times 32*20 db 32
31 halyavin 2309
send_to_channel   dd 0x0
2310
 
2311
send_string_header:  db     'privmsg #eax :'
195 heavyiron 2312
		     times  100  db  0x0
31 halyavin 2313
 
195 heavyiron 2314
send_string:	     times  100  db  0x0
2315
xpos	     dd  0
31 halyavin 2316
 
2317
string0:     db  'USER guest ser1 ser2 :'
2318
string0l:
2319
string1:     db  'nick '
2320
string1l:
2321
 
195 heavyiron 2322
attribute   dd	0
2323
scroll	    dd	1
2324
	    dd	12
31 halyavin 2325
 
195 heavyiron 2326
numtext     db	'                     '
31 halyavin 2327
 
195 heavyiron 2328
wcolor	    dd	0x000000
31 halyavin 2329
 
195 heavyiron 2330
labelc	    db	'AIRC - WINDOW X: #xxx                 '
485 heavyiron 2331
title	    db	'IRC client ',version,0
31 halyavin 2332
 
485 heavyiron 2333
;include_debug_strings  ; ALWAYS present in data section
2334
 
556 heavyiron 2335
irc_server_ip db ?  ; bufer for server_IP
2336
 
485 heavyiron 2337
dnsMsg:  rb 512     ; buffer used by DNS client
2338
 
2339
 
31 halyavin 2340
;;
2341
;;   Channel data at I_END
2342
;;
2343
;;   120*80 * channel window (1+)
2344
;;
2345
;;      At         Size
2346
;;
2347
;;      00      ,  120*60   window text 120 characters per row
2348
;;  120*60      ,  1        text is updated
2349
;;  120*60+4    ,  1        close yourself
2350
;;  120*60+8    ,  1        0 = channel window  :  1 = private chat
2351
;;  120*61      ,  256      channel name
2352
;;  120*61+254  ,  254      channel entry text from user
2353
;;  120*61+255  ,  1        length of entry text
2354
;;  120*69+248  ,  4        display names from n:th name
2355
;;  120*69+252  ,  4        length of names string
2356
;;  120*70      ,  1200     names separated with space
2357
;;
556 heavyiron 2358
I_END: