Subversion Repositories Kolibri OS

Rev

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