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
;;   NNTP CLIENT v 0.1
4
;;
5
;;   (C) Ville Turjanmaa
6
;;
7
 
8
version equ '0.1'
9
 
10
include "lang.inc"
485 heavyiron 11
include "..\..\..\macros.inc"
31 halyavin 12
 
13
  use32
14
  org    0x0
15
 
16
  db     'MENUET01'              ; 8 byte id
17
  dd     0x01                    ; header version
18
  dd     START                   ; start of code
19
  dd     I_END                   ; size of image
20
  dd     0x80000                 ; memory for app
21
  dd     0x80000                 ; esp
22
  dd     0x0 , 0x0               ; I_Param , I_Icon
23
 
24
 
25
connect_state  db  0,0,'Disconnected'
26
               db  1,3,'Trying..    '
27
               db  4,4,'Connected   '
28
               db  5,9,'Closing..   '
29
 
30
prev_state     dd  -1
31
 
32
space          dd  0x0
33
 
34
text_start     dd  0x0
35
 
36
text_current   dd  0x0
37
 
38
status     dd  0x0
39
 
40
server_ip  db  192,168,0,96
41
 
42
socket     dd  0x0
43
 
44
xpos       dd  0x0
45
ypos       dd  0x0
46
 
47
;;
48
 
49
group      db  'GROUP alt.test',13,10
50
           db  '                              '
51
 
52
grouplen   dd  16
53
 
54
stat       db  'STAT                          '
55
 
56
statlen    dd  0x0
57
 
58
article    db  'ARTICLE',13,10
59
articlelen:
60
 
61
;;
62
 
63
quit       db  'QUIT',13,10
64
quitlen:
65
 
66
xwait      dd  0x0
67
ywait      dd  0x0
68
 
69
article_n  dd  0x0
70
article_l  dd  0x0
71
 
72
article_start dd 0x0
73
article_last dd 0x0
74
article_all  dd 0x0
75
 
76
article_fetch dd 0x0
77
 
78
xpost      dd  0x0
79
 
80
edisave    dd  0x0
81
 
82
 
83
connection_status:
84
 
85
    pusha
86
 
87
    mov  eax,53
88
    mov  ebx,6
89
    mov  ecx,[socket]
485 heavyiron 90
    mcall
31 halyavin 91
 
92
    cmp  eax,[prev_state]
93
    je   no_cos
94
 
95
    mov  [prev_state],eax
96
 
97
    mov  eax,13
98
    mov  ebx,435*65536+12*6
99
    mov  ecx,42*65536+10
100
    mov  edx,0xffffff
485 heavyiron 101
    mcall
31 halyavin 102
 
103
    mov  ecx,-14
104
    mov  eax,[prev_state]
105
 
106
  next_test:
107
 
108
    add  ecx,14
109
 
110
    cmp  ecx,14*4
111
    je   no_cos
112
 
113
    cmp  al,[connect_state+ecx+0]
114
    jb   next_test
115
    cmp  al,[connect_state+ecx+1]
116
    jg   next_test
117
 
118
    mov  edx,ecx
119
    add  edx,2
120
    add  edx,connect_state
121
 
122
    mov  eax,4
123
    mov  ebx,435*65536+42
124
    mov  ecx,0x000000
125
    mov  esi,12
485 heavyiron 126
    mcall
31 halyavin 127
 
128
  no_cos:
129
 
130
    popa
131
 
132
    ret
133
 
134
 
135
 
136
text_input:
137
 
138
    pusha
139
    mov  ecx,25
140
    mov  eax,32
141
    cld
142
    rep  stosb
143
    popa
144
 
145
    mov  [edisave],edi
146
 
147
  ti0:
148
 
149
    mov  [edi],byte ' '
150
    call draw_entries
151
 
152
    mov  eax,10
485 heavyiron 153
    mcall
31 halyavin 154
 
155
    cmp  eax,2
156
    jne  no_more_text
157
 
158
    mov  eax,2
485 heavyiron 159
    mcall
31 halyavin 160
 
161
    cmp   ah,8
162
    jne   no_bg
163
    cmp   edi,[edisave]
164
    je    ti0
165
    dec   edi
166
    jmp   ti0
167
   no_bg:
168
 
169
    cmp  ah,13
170
    je   no_more_text
171
 
172
    mov  [edi],ah
173
    inc  edi
174
 
175
    call draw_entries
176
 
177
    jmp  ti0
178
 
179
  no_more_text:
180
 
181
    mov  [xpost],edi
182
 
183
    ret
184
 
185
 
186
convert_text_to_ip:
187
 
188
    pusha
189
 
190
    mov   edi,server_ip
191
    mov   esi,text+10
192
    mov   eax,0
193
    mov   edx,[xpost]
194
  newsip:
195
    cmp   [esi],byte '.'
196
    je    sipn
197
    cmp   esi,edx
198
    jge   sipn
199
    movzx ebx,byte [esi]
200
    inc   esi
201
    imul  eax,10
202
    sub   ebx,48
203
    add   eax,ebx
204
    jmp   newsip
205
  sipn:
206
    mov   [edi],al
207
    xor   eax,eax
208
    inc   esi
209
    cmp   esi,text+50
210
    jg    sipnn
211
    inc   edi
212
    cmp   edi,server_ip+3
213
    jbe   newsip
214
  sipnn:
215
 
216
    popa
217
 
218
    ret
219
 
220
 
221
send_group:
222
 
223
    mov  eax,53
224
    mov  ebx,7
225
    mov  ecx,[socket]
226
    mov  edx,[grouplen]
227
    mov  esi,group
485 heavyiron 228
    mcall
31 halyavin 229
    mov  [status],3
230
    call clear_text
231
    call save_coordinates
232
 
233
    ret
234
 
235
 
236
convert_number_to_text:
237
 
238
    pusha
239
 
240
    mov  eax,[esi]
241
    mov  ecx,0
242
  newch:
243
    inc  ecx
244
    xor  edx,edx
245
    mov  ebx,10
246
    div  ebx
247
    cmp  eax,0
248
    jne  newch
249
 
250
    add  edi,ecx
251
    dec  edi
252
    mov  [article_l],ecx
253
 
254
    mov  eax,[esi]
255
  newdiv:
256
    xor  edx,edx
257
    mov  ebx,10
258
    div  ebx
259
    add  edx,48
260
    mov  [edi],dl
261
    dec  edi
262
    loop newdiv
263
 
264
    popa
265
 
266
    ret
267
 
268
 
269
convert_text_to_number:
270
 
271
    pusha
272
 
273
    mov   edx,0
274
  newdigit:
275
    movzx eax,byte [esi]
276
    cmp   eax,'0'
277
    jb    cend
278
    cmp   eax,'9'
279
    jg    cend
280
    imul  edx,10
281
    add   edx,eax
282
    sub   edx,48
283
    inc   esi
284
    jmp   newdigit
285
  cend:
286
    mov   [edi],edx
287
    popa
288
 
289
    ret
290
 
291
 
292
clear_text:
293
 
294
    mov  [text_start],0
295
    mov  [xpos],0
296
    mov  [ypos],0
297
    mov  [xwait],0
298
    mov  [ywait],0
299
    mov  edi,nntp_text
300
    mov  ecx,0x50000
301
    mov  eax,32
302
    cld
303
    rep  stosb
304
    ret
305
 
306
 
307
state_machine_write:
308
 
309
 
310
    cmp  [status],2
311
    jne  no_22
312
    call send_group
313
    ret
314
  no_22:
315
 
316
    cmp  [status],4
317
    jne  no_4
318
    mov  eax,53
319
    mov  ebx,7
320
    mov  ecx,[socket]
321
    mov  edx,[statlen] ; -stat
322
    mov  esi,stat
485 heavyiron 323
    mcall
31 halyavin 324
    mov  [status],5
325
    call save_coordinates
326
    ret
327
  no_4:
328
 
329
    cmp  [status],6
330
    jne  no_6
331
    mov  eax,53
332
    mov  ebx,7
333
    mov  ecx,[socket]
334
    mov  edx,articlelen-article
335
    mov  esi,article
485 heavyiron 336
    mcall
31 halyavin 337
    mov  [status],7
338
    call save_coordinates
339
    ret
340
  no_6:
341
 
342
 
343
    ret
344
 
345
save_coordinates:
346
 
347
    mov  eax,[xpos]
348
    mov  ebx,[ypos]
349
    mov  [xwait],eax
350
    mov  [ywait],ebx
351
 
352
    ret
353
 
354
 
355
state_machine_read:
356
 
357
    cmp  [status],1
358
    jne  no_1
359
    mov  eax,'200 '
360
    call wait_for_string
361
    ret
362
  no_1:
363
 
364
    cmp  [status],3   ;; responce to group
365
    jne  no_3
366
    mov  eax,'211 '
367
    call wait_for_string
368
    ret
369
  no_3:
370
 
371
    cmp  [status],5   ;; responce to stat
372
    jne  no_5
373
    mov  eax,'223 '
374
    call wait_for_string
375
    ret
376
  no_5:
377
 
378
    ;; after 'article' request - no wait
379
 
380
    cmp  [status],9
381
    jne  no_9
382
    mov  eax,'222 '
383
    call wait_for_string
384
    ret
385
  no_9:
386
 
387
 
388
 
389
    ret
390
 
391
 
392
 
393
wait_for_string:
394
 
395
    mov  ecx,[ywait]
396
    imul ecx,80
397
    add  ecx,[xwait]
398
 
399
    mov  ecx,[nntp_text+ecx]
400
 
401
    cmp  eax,ecx
402
    jne  no_match
403
 
404
    cmp  [status],3
405
    jne  no_stat_ret
406
 
407
    mov  esi,[ywait]
408
    imul esi,80
409
    add  esi,[xwait]
410
 
411
  new32s:
412
    inc  esi
413
    movzx eax,byte [esi+nntp_text]
414
    cmp  eax,47
415
    jge  new32s
416
  new32s2:
417
    inc  esi
418
    movzx eax,byte [esi+nntp_text]
419
    cmp  eax,47
420
    jge  new32s2
421
    inc  esi
422
    add  esi,nntp_text
423
;    mov  [esi-1],byte '.'
424
 
425
    mov  edi,article_n
426
    call convert_text_to_number
427
    mov  eax,[article_n]
428
    mov  [article_start],eax
429
 
430
  new32s3:
431
    inc  esi
432
    movzx eax,byte [esi]
433
    cmp  eax,47
434
    jge  new32s3
435
    inc  esi
436
 
437
    mov  edi,article_last
438
    call convert_text_to_number
439
 
440
    mov  eax,[text_current]
441
    add  [article_n],eax
442
 
443
    mov  esi,article_n
444
    mov  edi,nntp_text+71
445
    call convert_number_to_text
446
 
447
    mov  esi,article_n
448
    mov  edi,stat+5
449
    call convert_number_to_text
450
 
451
    mov  eax,[article_l]
452
    mov  [stat+5+eax],byte 13
453
    mov  [stat+6+eax],byte 10
454
    add  eax,5+2
455
    mov  [statlen],eax
456
 
457
    pusha
458
    mov  edi,text+10+66*2
459
    mov  ecx,25
460
    mov  eax,32
461
    cld
462
    rep  stosb
463
    mov  esi,text_current
464
    mov  edi,text+10+66*2
465
    call convert_number_to_text
466
    mov  eax,32
467
    mov  ecx,20
468
    mov  edi,text+10+66*3
469
    cld
470
    rep  stosb
471
    mov  eax,[article_last]
472
    sub  eax,[article_start]
473
    mov  [article_all],eax
474
    mov  esi,article_all
475
    mov  edi,text+10+66*3
476
    call convert_number_to_text
477
    call draw_entries
478
    popa
479
 
480
    call draw_text
481
 
482
  no_stat_ret:
483
 
484
    inc  [status]
485
 
486
    mov  eax,5
487
    mov  ebx,10
485 heavyiron 488
    mcall
31 halyavin 489
 
490
    call check_for_incoming_data
491
 
492
  no_match:
493
 
494
    ret
495
 
496
 
497
 
498
START:                          ; start of execution
499
 
500
     mov  eax,40
501
     mov  ebx,10000111b
485 heavyiron 502
     mcall
31 halyavin 503
 
504
     call clear_text
505
 
506
     call draw_window
507
 
508
still:
509
 
510
    call state_machine_write
511
    call state_machine_read
512
 
513
    mov  eax,23                 ; wait here for event
514
    mov  ebx,5
485 heavyiron 515
    mcall
31 halyavin 516
 
517
    cmp  eax,1                  ; redraw request ?
518
    je   red
519
    cmp  eax,2                  ; key in buffer ?
520
    je   key
521
    cmp  eax,3                  ; button in buffer ?
522
    je   button
523
 
524
    call check_for_incoming_data
525
 
526
    call connection_status
527
 
528
    jmp  still
529
 
530
  red:                          ; redraw
531
    call draw_window
532
    jmp  still
533
 
534
  key:                          ; key
535
    mov  eax,2                  ; just read it and ignore
485 heavyiron 536
    mcall
31 halyavin 537
 
538
    cmp  ah,' '
539
    jne  no_space
540
    mov  eax,[space]
541
    dec  eax
542
    add  [text_start],eax
543
    call draw_text
544
    jmp  still
545
  no_space:
546
 
547
    cmp  ah,177
548
    jne  no_plus
549
    inc  [text_start]
550
    call draw_text
551
    jmp  still
552
  no_plus:
553
 
554
    cmp  ah,178
555
    jne  no_minus
556
    cmp  [text_start],0
557
    je   no_minus
558
    dec  [text_start]
559
    call draw_text
560
    jmp  still
561
  no_minus:
562
 
563
    cmp  ah,179
564
    jne  no_next
565
    inc  [text_current]
566
    call send_group
567
    jmp  still
568
  no_next:
569
 
570
    cmp  ah,176
571
    jne  no_prev
572
    cmp  [text_current],0
573
    je   still
574
    dec  [text_current]
575
    call send_group
576
    jmp  still
577
  no_prev:
578
 
579
    jmp  still
580
 
581
 
582
  button:                       ; button
583
    mov  eax,17                 ; get id
485 heavyiron 584
    mcall
31 halyavin 585
 
586
    shr  eax,8
587
 
588
    cmp  eax,11
589
    jne  no_11
590
    mov  edi,text+10
591
    call text_input
592
    call convert_text_to_ip
593
    jmp  still
594
   no_11:
595
 
596
    cmp  eax,12
597
    jne  no_12
598
    mov  edi,text+66+10
599
    call text_input
600
    mov  esi,text+66+10
601
    mov  edi,group+6
602
    mov  ecx,[xpost]
603
    sub  ecx,text+66+10
604
    mov  eax,ecx
605
    cld
606
    rep  movsb
607
    mov  [group+6+eax],byte 13
608
    mov  [group+7+eax],byte 10
609
    add  eax,6+2
610
    mov  [grouplen],eax
611
    mov  [text_current],0
612
    jmp  still
613
   no_12:
614
 
615
    cmp  eax,13
616
    jne  no_13
617
    mov  edi,text+10+66*2
618
    call text_input
619
    mov  esi,text+10+66*2
620
    mov  edi,text_current
621
    call convert_text_to_number
622
    call send_group
623
    jmp  still
624
   no_13:
625
 
626
 
627
    cmp  eax,14
628
    jne  no_start
629
    call clear_text
630
    mov  eax,3
485 heavyiron 631
    mcall
31 halyavin 632
    mov  ecx,eax
633
    mov  eax,53
634
    mov  ebx,5
635
    mov  edx,119
636
    mov  esi,dword [server_ip]
637
    mov  edi,1
485 heavyiron 638
    mcall
31 halyavin 639
    mov  [socket],eax
640
    mov  [status],1
641
    jmp  still
642
  no_start:
643
 
644
    cmp  eax,15
645
    jne  no_end
646
    mov  eax,53
647
    mov  ebx,7
648
    mov  ecx,[socket]
649
    mov  edx,quitlen-quit
650
    mov  esi,quit
485 heavyiron 651
    mcall
31 halyavin 652
    mov  eax,5
653
    mov  ebx,10
485 heavyiron 654
    mcall
31 halyavin 655
    call check_for_incoming_data
656
    mov  eax,53
657
    mov  ebx,8
658
    mov  ecx,[socket]
485 heavyiron 659
    mcall
31 halyavin 660
    mov  eax,5
661
    mov  ebx,5
485 heavyiron 662
    mcall
31 halyavin 663
    mov  eax,53
664
    mov  ebx,8
665
    mov  ecx,[socket]
485 heavyiron 666
    mcall
31 halyavin 667
    mov  [status],0
668
    jmp  still
669
  no_end:
670
 
671
    cmp  eax,1                   ; button id=1 ?
672
    jne  noclose
673
    mov  eax,-1                 ; close this program
485 heavyiron 674
    mcall
31 halyavin 675
  noclose:
676
 
677
    jmp  still
678
 
679
 
680
check_for_incoming_data:
681
 
682
    cmp  [status],0
683
    jne  go_on
684
    ret
685
  go_on:
686
 
687
    mov  eax,53
688
    mov  ebx,2
689
    mov  ecx,[socket]
485 heavyiron 690
    mcall
31 halyavin 691
 
692
    cmp  eax,0
693
    je   ch_ret
694
 
695
    mov  eax,53
696
    mov  ebx,3
697
    mov  ecx,[socket]
485 heavyiron 698
    mcall
31 halyavin 699
 
700
    and  ebx,0xff
701
 
702
    cmp  ebx,13
703
    jb   no_print
704
 
705
    cmp  bl,13
706
    jne  char
707
    mov  [xpos],0
708
    inc  [ypos]
709
    jmp  no_print
710
  char:
711
 
712
    cmp  ebx,128
713
    jbe  char_ok
714
    mov  ebx,'?'
715
  char_ok:
716
 
717
    mov  ecx,[ypos]
718
    imul ecx,80
719
    add  ecx,[xpos]
720
    mov  [nntp_text+ecx],bl
721
    cmp  [xpos],78
722
    jg   noxinc
723
    inc  [xpos]
724
  noxinc:
725
 
726
  no_print:
727
 
728
    mov  eax,53
729
    mov  ebx,2
730
    mov  ecx,[socket]
485 heavyiron 731
    mcall
31 halyavin 732
 
733
    cmp  eax,0
734
    jne  check_for_incoming_data
735
 
736
    call draw_text
737
 
738
  ch_ret:
739
 
740
    ret
741
 
742
 
743
 
744
;   *********************************************
745
;   *******  WINDOW DEFINITIONS AND DRAW ********
746
;   *********************************************
747
 
748
 
749
draw_window:
750
 
751
    pusha
752
 
753
    mov  [prev_state],-1
754
 
755
    mov  eax,12                    ; function 12:tell os about windowdraw
756
    mov  ebx,1                     ; 1, start of draw
485 heavyiron 757
    mcall
31 halyavin 758
 
759
                                   ; DRAW WINDOW
760
    mov  eax,0                     ; function 0 : define and draw window
761
    mov  ebx,100*65536+520         ; [x start] *65536 + [x size]
762
    mov  ecx,5*65536+470           ; [y start] *65536 + [y size]
485 heavyiron 763
    mov  edx,0x13ffffff            ; color of work area RRGGBB,8->color gl
764
    mov  edi,title                 ; WINDOW LABEL
765
    mcall
31 halyavin 766
 
767
    mov  eax,38
768
    mov  ebx,5*65536+515
769
    mov  ecx,101*65536+101
770
    mov  edx,0x99bbff
485 heavyiron 771
    mcall
31 halyavin 772
    mov  ecx,102*65536+102
773
    mov  edx,0x3366aa
485 heavyiron 774
    mcall
31 halyavin 775
 
776
 
777
    mov  eax,8
778
    mov  ebx,238*65536+8
779
    mov  ecx,30*65536+8
780
    mov  edx,11
781
    mov  esi,0x88aadd
485 heavyiron 782
    mcall
31 halyavin 783
    mov  ecx,41*65536+8
784
    mov  edx,12
485 heavyiron 785
    mcall
31 halyavin 786
    mov  ecx,52*65536+8
787
    mov  edx,13
485 heavyiron 788
    mcall
31 halyavin 789
 
790
    mov  ebx,265*65536+75
791
    mov  ecx,39*65536+13
792
    mov  edx,14
485 heavyiron 793
    mcall
31 halyavin 794
    mov  ebx,351*65536+75
795
    mov  edx,15
485 heavyiron 796
    mcall
31 halyavin 797
 
798
    call draw_entries
799
 
800
    call draw_text
801
 
802
    mov  eax,12                    ; function 12:tell os about windowdraw
803
    mov  ebx,2                     ; 2, end of draw
485 heavyiron 804
    mcall
31 halyavin 805
 
806
    popa
807
 
808
    ret
809
 
810
 
811
draw_entries:
812
 
813
    pusha
814
 
815
    mov  eax,13
816
    mov  ebx,30*65536+200
817
    mov  ecx,30*65536+44
818
    mov  edx,0xffffff
485 heavyiron 819
    mcall
31 halyavin 820
 
485 heavyiron 821
    mov  eax,4
31 halyavin 822
    mov  ebx,30*65536+31           ; draw info text with function 4
823
    mov  ecx,0x000000
824
    mov  edx,text
825
    mov  esi,66
826
    mov  edi,6
827
  newline2:
485 heavyiron 828
    mcall
31 halyavin 829
    add  ebx,11
830
    add  edx,66
831
    dec  edi
832
    jnz  newline2
833
 
834
    popa
835
 
836
    ret
837
 
838
 
839
draw_text:
840
 
841
    pusha
842
 
843
    mov  eax,9
844
    mov  ebx,0x70000
845
    mov  ecx,-1
485 heavyiron 846
    mcall
31 halyavin 847
 
848
    mov  eax,[0x70000+46]
849
    cmp  eax,150
850
    jbe  dtret
851
 
852
    sub  eax,111
853
    mov  ebx,10
854
    xor  edx,edx
855
    div  ebx
856
    mov  edi,eax
857
    dec  edi
858
 
859
    mov  [space],edi
485 heavyiron 860
    mov  eax,4
31 halyavin 861
    mov  ebx,20*65536+111           ; draw info text with function 4
862
    mov  ecx,0x000000
863
    mov  edx,[text_start]
864
    imul edx,80
865
    add  edx,nntp_text
866
    mov  esi,80
485 heavyiron 867
 
868
 newline:
31 halyavin 869
    pusha
870
    mov  ecx,ebx
871
    shl  ecx,16
872
    mov  eax,13
873
    mov  ebx,20*65536+80*6
874
    mov  cx,10
875
    mov  edx,0xffffff
485 heavyiron 876
    mcall
31 halyavin 877
    popa
878
 
485 heavyiron 879
    mcall
31 halyavin 880
    add  ebx,10
881
    add  edx,80
882
    dec  edi
883
    jnz  newline
884
 
885
  dtret:
886
 
887
    popa
888
 
889
    ret
890
 
891
 
892
; DATA AREA
893
 
894
text:
895
 db 'NNTP IP : 192.168.0.96             <                              '
896
 db 'Group   : alt.test                 <      Connect      Disconnect '
897
 db 'Article : 0                        <                              '
898
 db 'Art.max : ?                                                       '
899
 db '                                                                  '
900
 db 'Arrow left/rigth: fetch prev/next - Arrow up/down & space: scroll '
901
 
902
textl:
903
 
904
 
485 heavyiron 905
title    db   'NNTP client v',version,0
31 halyavin 906
 
907
nntp_text:
908
 
909
     db 'a'
910
 
911
I_END:   ;;;