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
;    TERMINAL
4
;
5
;    Compile with FASM for Menuet
6
;
7
 
8
use32
331 heavyiron 9
 org	0x0
10
 db	'MENUET01'    ; header
11
 dd	0x01	      ; header version
12
 dd	START	      ; entry point
13
 dd	I_END	      ; image size
14
 dd	I_END+0x10000 ; required memory
15
 dd	I_END+0x10000 ; esp
16
 dd	0x0 , 0x0     ; I_Param , I_Path
31 halyavin 17
 
18
 
19
include 'lang.inc'
20
include 'macros.inc'
21
 
331 heavyiron 22
START:				; start of execution
31 halyavin 23
 
24
    ; Clear the screen memory
25
    mov     eax, '    '
26
    mov     edi,text
27
    mov     ecx,80*30 /4
28
    cld
29
    rep     stosd
30
 
31
 
32
    call draw_window
33
 
34
 
35
still:
36
    ; check connection status
37
    mov  eax,53
38
    mov  ebx,6
39
    mov  ecx,[socket]
40
    int  0x40
41
 
42
    mov     ebx, [socket_status]
43
    mov     [socket_status], eax
44
 
45
    cmp     eax, ebx
331 heavyiron 46
    je	    waitev
31 halyavin 47
 
48
    call    draw_window
49
 
50
waitev:
331 heavyiron 51
    mov  eax,23 		; wait here for event
31 halyavin 52
    mov  ebx,20
53
    int  0x40
54
 
331 heavyiron 55
    cmp  eax,1			; redraw request ?
56
    je	 red
57
    cmp  eax,2			; key in buffer ?
58
    je	 key
59
    cmp  eax,3			; button in buffer ?
60
    je	 button
31 halyavin 61
 
62
    ; any data from the socket?
63
 
64
    mov     eax, 53
65
    mov     ebx, 2
66
    mov     ecx, [socket]
67
    int     0x40
68
    cmp     eax, 0
69
    jne      read_input
70
 
71
    jmp  still
72
 
73
 
74
read_input:
75
 
76
    push ecx
77
    mov     eax, 53
78
    mov     ebx, 3
79
    mov     ecx, [socket]
80
    int     0x40
81
    pop  ecx
82
 
83
    call    handle_data
84
 
85
    push    ecx
86
    mov     eax, 53
87
    mov     ebx, 2
88
    mov     ecx, [socket]
89
    int     0x40
90
    pop     ecx
91
    cmp     eax, 0
92
 
93
 
94
    jne   read_input
95
    call draw_text
96
    jmp  still
97
 
98
 
99
 
100
handle_data:
101
    ; Telnet servers will want to negotiate options about our terminal window
102
    ; just reject them all.
103
    ; Telnet options start with the byte 0xff and are 3 bytes long.
104
 
105
    mov     al, [telnetstate]
106
    cmp     al, 0
331 heavyiron 107
    je	    state0
31 halyavin 108
    cmp     al, 1
331 heavyiron 109
    je	    state1
31 halyavin 110
    cmp     al, 2
331 heavyiron 111
    je	    state2
31 halyavin 112
    jmp     hd001
113
 
114
state0:
115
    cmp     bl, 255
116
    jne     hd001
117
    mov     al, 1
118
    mov     [telnetstate], al
119
    ret
120
 
121
state1:
122
    mov     al, 2
123
    mov     [telnetstate], al
124
    ret
125
 
126
state2:
127
    mov     al, 0
128
    mov     [telnetstate], al
129
    mov     [telnetrep+2], bl
130
 
131
    mov     edx, 3
132
    mov     eax,53
133
    mov     ebx,7
134
    mov     ecx,[socket]
135
    mov     esi, telnetrep
136
    int     0x40
137
    ret
138
 
139
hd001:
331 heavyiron 140
    cmp  bl,13				; BEGINNING OF LINE
31 halyavin 141
    jne  nobol
142
    mov  ecx,[pos]
143
    add  ecx,1
144
  boll1:
145
    sub  ecx,1
146
    mov  eax,ecx
147
    xor  edx,edx
148
    mov  ebx,80
149
    div  ebx
150
    cmp  edx,0
151
    jne  boll1
152
    mov  [pos],ecx
153
    jmp  newdata
154
  nobol:
155
 
331 heavyiron 156
    cmp  bl,10				  ; LINE DOWN
31 halyavin 157
    jne  nolf
158
   addx1:
159
    add  [pos],dword 1
160
    mov  eax,[pos]
161
    xor  edx,edx
162
    mov  ecx,80
163
    div  ecx
164
    cmp  edx,0
165
    jnz  addx1
166
    mov  eax,[pos]
167
    jmp  cm1
168
  nolf:
169
 
331 heavyiron 170
    cmp  bl,8				 ; BACKSPACE
31 halyavin 171
    jne  nobasp
172
    mov  eax,[pos]
173
    dec  eax
174
    mov  [pos],eax
175
    mov  [eax+text],byte 32
176
    mov  [eax+text+60*80],byte 0
177
    jmp  newdata
178
   nobasp:
179
 
331 heavyiron 180
    cmp  bl,15				 ; CHARACTER
31 halyavin 181
    jbe  newdata
182
    mov  eax,[pos]
183
    mov  [eax+text],bl
184
    mov  eax,[pos]
185
    add  eax,1
186
  cm1:
187
    mov  ebx,[scroll+4]
188
    imul ebx,80
189
    cmp  eax,ebx
331 heavyiron 190
    jb	 noeaxz
31 halyavin 191
    mov  esi,text+80
192
    mov  edi,text
193
    mov  ecx,ebx
194
    cld
195
    rep  movsb
196
    mov  eax,ebx
197
    sub  eax,80
198
  noeaxz:
199
    mov  [pos],eax
200
  newdata:
201
    ret
202
 
203
 
331 heavyiron 204
  red:				; REDRAW WINDOW
31 halyavin 205
    call draw_window
206
    jmp  still
207
 
331 heavyiron 208
  key:				; KEY
209
    mov  eax,2			; send to modem
31 halyavin 210
    int  0x40
211
 
212
    mov     ebx, [socket_status]
331 heavyiron 213
    cmp     ebx, 4		; connection open?
214
    jne     still		; no, so ignore key
31 halyavin 215
 
216
    shr  eax,8
331 heavyiron 217
    cmp  eax,178		; ARROW KEYS
31 halyavin 218
    jne  noaup
219
    mov  al,'A'
220
    call arrow
221
    jmp  still
222
  noaup:
223
    cmp  eax,177
224
    jne  noadown
225
    mov  al,'B'
226
    call arrow
227
    jmp  still
228
  noadown:
229
    cmp  eax,179
230
    jne  noaright
231
    mov  al,'C'
232
    call arrow
233
    jmp  still
234
  noaright:
235
    cmp  eax,176
236
    jne  noaleft
237
    mov  al,'D'
238
    call arrow
239
    jmp  still
240
  noaleft:
241
  modem_out:
242
 
243
    call    to_modem
244
 
245
    jmp  still
246
 
331 heavyiron 247
  button:			; BUTTON
31 halyavin 248
    mov  eax,17
249
    int  0x40
331 heavyiron 250
    cmp  ah,1			; CLOSE PROGRAM
31 halyavin 251
    jne  noclose
252
 
253
    mov  eax,53
254
    mov  ebx,8
255
    mov  ecx,[socket]
256
    int  0x40
257
 
258
     mov  eax,-1
259
     int  0x40
260
  noclose:
331 heavyiron 261
    cmp     ah, 2		; Set IP
31 halyavin 262
    jne     notip
263
 
264
    mov  [string_x], dword 78
265
    mov  [string_y], dword 276
266
    mov  [string_length], dword 15
267
    call read_string
268
    mov   esi,string-1
269
    mov   edi,ip_address
270
    xor   eax,eax
271
   ip1:
272
    inc   esi
273
    cmp   [esi],byte '0'
331 heavyiron 274
    jb	  ip2
31 halyavin 275
    cmp   [esi],byte '9'
331 heavyiron 276
    jg	  ip2
31 halyavin 277
    imul  eax,10
278
    movzx ebx,byte [esi]
279
    sub   ebx,48
280
    add   eax,ebx
281
    jmp   ip1
282
   ip2:
283
    mov   [edi],al
284
    xor   eax,eax
285
    inc   edi
286
    cmp   edi,ip_address+3
287
    jbe   ip1
288
    call draw_window
289
 
290
 
291
    jmp     still
292
 
293
notip:
331 heavyiron 294
    cmp     ah, 3		; set port
31 halyavin 295
    jne     notport
296
 
297
    mov  [string_x], dword 215
298
    mov  [string_y], dword 276
299
    mov  [string_length], dword 4
300
    call read_string
301
    mov   esi,string-1
302
    mov   edi,port
303
    xor   eax,eax
304
   ip11:
305
    inc   esi
306
    cmp   [esi],byte '0'
331 heavyiron 307
    jb	  ip21
31 halyavin 308
    cmp   [esi],byte '9'
331 heavyiron 309
    jg	  ip21
31 halyavin 310
    imul  eax,10
311
    movzx ebx,byte [esi]
312
    sub   ebx,48
313
    add   eax,ebx
314
    jmp   ip11
315
   ip21:
316
    mov   [edi],al
317
    inc   edi
318
    mov   [edi],ah
319
    call draw_window
320
 
321
 
322
    jmp     still
323
 
324
notport:
331 heavyiron 325
    cmp     ah, 4		; connect
31 halyavin 326
    jne     notcon
327
 
328
    mov     eax, [socket_status]
329
    cmp     eax, 4
331 heavyiron 330
    je	   still
31 halyavin 331
    call    connect
332
 
333
    jmp     still
334
 
335
notcon:
331 heavyiron 336
    cmp     ah,5		; disconnect
31 halyavin 337
    jne     notdiscon
338
 
339
    call    disconnect
340
    jmp  still
341
 
331 heavyiron 342
notdiscon:			; Echo Toggle
31 halyavin 343
    cmp     ah, 6
344
    jne     still
345
 
346
    mov     al, [echo]
347
    not     al
348
    mov     [echo], al
349
 
350
    call    draw_window
351
    jmp     still
352
 
353
arrow:
354
 
355
    push eax
356
    mov  al,27
357
    call to_modem
358
    mov  al,'['
359
    call to_modem
360
    pop  eax
361
    call to_modem
362
 
363
    ret
364
 
365
 
366
to_modem:
367
    pusha
368
    push    ax
369
    mov     [tx_buff], al
370
    mov     edx, 1
371
    cmp     al, 13
372
    jne     tm_000
373
    mov     edx, 2
374
tm_000:
375
    mov     eax,53
376
    mov     ebx,7
377
    mov     ecx,[socket]
378
    mov     esi, tx_buff
379
    int  0x40
380
    pop     bx
381
    mov     al, [echo]
382
    cmp     al, 0
331 heavyiron 383
    je	    tm_001
31 halyavin 384
 
385
    push    bx
386
    call    handle_data
387
    pop     bx
388
 
389
    cmp     bl, 13
390
    jne     tm_002
391
 
392
    mov     bl, 10
393
    call    handle_data
394
 
395
tm_002:
396
    call    draw_text
397
 
398
tm_001:
399
    popa
400
    ret
401
 
402
 
403
 
404
disconnect:
405
    mov  eax,53
406
    mov  ebx,8
407
    mov  ecx,[socket]
408
    int  0x40
409
    ret
410
 
411
 
412
 
413
connect:
414
    pusha
415
 
331 heavyiron 416
 mov	 ecx, 1000  ; local port starting at 1000
31 halyavin 417
 
418
getlp:
331 heavyiron 419
 inc	 ecx
31 halyavin 420
 push ecx
331 heavyiron 421
 mov	 eax, 53
422
 mov	 ebx, 9
423
 int	 0x40
424
 pop	 ecx
425
 cmp	 eax, 0   ; is this local port in use?
426
 jz  getlp	; yes - so try next
31 halyavin 427
 
428
    mov     eax,53
429
    mov     ebx,5
430
    mov     dl, [ip_address + 3]
431
    shl     edx, 8
432
    mov     dl, [ip_address + 2]
433
    shl     edx, 8
434
    mov     dl, [ip_address + 1]
435
    shl     edx, 8
436
    mov     dl, [ip_address]
437
    mov     esi, edx
331 heavyiron 438
    movzx   edx, word [port]	  ; telnet port id
31 halyavin 439
    mov     edi,1      ; active open
440
    int     0x40
441
    mov     [socket], eax
442
 
443
    popa
444
 
445
    ret
446
 
447
 
448
 
449
;   *********************************************
450
;   *******  WINDOW DEFINITIONS AND DRAW ********
451
;   *********************************************
452
 
453
 
454
draw_window:
455
 
456
    pusha
457
 
458
    mov  eax,12
459
    mov  ebx,1
460
    int  0x40
461
 
331 heavyiron 462
    xor  eax,eax		     ; DRAW WINDOW
31 halyavin 463
    mov  ebx,100*65536+491 + 8 +15
464
    mov  ecx,100*65536+270 + 20     ; 20 for status bar
331 heavyiron 465
    mov  edx,0x13000000
466
    mov  edi,labelt
31 halyavin 467
    int  0x40
468
 
469
    ; draw status bar
470
    mov     eax, 13
471
    mov     ebx, 4*65536+484 + 8 +15
472
    mov     ecx, 270*65536 + 3
473
    mov     edx, 0x00557799
474
    int     0x40
475
 
331 heavyiron 476
    mov  eax,8			   ; BUTTON 2: SET IP
31 halyavin 477
    mov  ebx,4*65536+70
478
    mov  ecx,273*65536+12
479
    mov     esi, 0x00557799
480
    mov  edx,2
481
    int  0x40
482
 
331 heavyiron 483
    mov  eax,4			   ; Button text
31 halyavin 484
    mov  ebx,6*65536+276
485
    mov  ecx,0x00ffffff
486
    mov  edx,setipt
487
    mov  esi,setiplen-setipt
488
    int  0x40
489
 
490
 
331 heavyiron 491
    mov  edi,ip_address 	    ; display IP address
31 halyavin 492
    mov  edx,78*65536+276
493
    mov  esi,0x00ffffff
494
    mov  ebx,3*65536
495
  ipdisplay:
496
    mov  eax,47
497
    movzx ecx,byte [edi]
498
    int  0x40
499
    add  edx,6*4*65536
500
    inc  edi
501
    cmp  edi,ip_address+4
331 heavyiron 502
    jb	 ipdisplay
31 halyavin 503
 
331 heavyiron 504
    mov  eax,8			   ; BUTTON 3: SET PORT
31 halyavin 505
    mov  ebx,173*65536+38
506
    mov  ecx,273*65536+12
507
    mov  edx,3
508
    mov     esi, 0x00557799
509
    int  0x40
510
 
331 heavyiron 511
    mov  eax,4			   ; Button text
31 halyavin 512
    mov  ebx,178*65536+276
513
    mov  ecx,0x00ffffff
514
    mov  edx,setportt
515
    mov  esi,setportlen-setportt
516
    int  0x40
517
 
518
 
331 heavyiron 519
    mov  edx,216*65536+276	     ; display port
31 halyavin 520
    mov  esi,0x00ffffff
521
    mov  ebx,4*65536
522
    mov  eax,47
523
    movzx  ecx,word [port]
524
    int  0x40
525
 
331 heavyiron 526
    mov  eax,8			   ; BUTTON 4: Connect
31 halyavin 527
    mov  ebx,250*65536+50
528
    mov  ecx,273*65536+12
529
    mov     esi, 0x00557799
530
    mov  edx,4
531
    int     0x40
532
 
331 heavyiron 533
    mov  eax,4			   ; Button text
31 halyavin 534
    mov  ebx,255*65536+276
535
    mov  ecx,0x00ffffff
536
    mov  edx,cont
537
    mov  esi,conlen-cont
538
    int  0x40
539
 
540
 
331 heavyiron 541
    mov  eax,8			   ; BUTTON 5: disconnect
31 halyavin 542
    mov  ebx,303*65536+70
543
    mov  ecx,273*65536+12
544
    mov  edx,5
545
    mov     esi, 0x00557799
546
    int     0x40
547
 
548
 
331 heavyiron 549
    mov  eax,4			   ; Button text
31 halyavin 550
    mov  ebx,307*65536+276
551
    mov  ecx,0x00ffffff
552
    mov  edx,dist
553
    mov  esi,dislen-dist
554
    int  0x40
555
 
556
 
331 heavyiron 557
    mov  esi,contlen-contt	    ; display connected status
31 halyavin 558
    mov     edx, contt
559
    mov     eax, [socket_status]
331 heavyiron 560
    cmp     eax, 4		    ; 4 is connected
561
    je	    pcon
31 halyavin 562
    mov     esi,discontlen-discontt
563
    mov     edx, discontt
564
pcon:
565
 
331 heavyiron 566
    mov  eax,4			   ; status text
31 halyavin 567
    mov  ebx,380*65536+276
568
    mov  ecx,0x00ffffff
569
    int  0x40
570
 
571
 
331 heavyiron 572
    mov  eax,8			   ; BUTTON 6: echo
31 halyavin 573
    mov  ebx,460*65536+50
574
    mov  ecx,273*65536+12
575
    mov  edx,6
576
    mov     esi, 0x00557799
577
    int     0x40
578
 
579
    mov  edx,echot
580
    mov  esi,echolen-echot
581
    mov     al, [echo]
582
    cmp     al, 0
583
    jne     peo
584
    mov  edx,echoot
585
    mov  esi,echoolen-echoot
586
 
587
peo:
331 heavyiron 588
    mov  eax,4			   ; Button text
31 halyavin 589
    mov  ebx,463*65536+276
590
    mov  ecx,0x00ffffff
591
    int  0x40
592
 
593
 
594
    xor  eax,eax
595
    mov  edi,text+80*30
596
    mov  ecx,80*30 /4
597
    cld
598
    rep  stosd
599
 
600
    call draw_text
601
 
602
    mov  eax,12
603
    mov  ebx,2
604
    int  0x40
605
 
606
    popa
607
 
608
    ret
609
 
610
 
611
draw_text:
612
 
613
    pusha
614
 
615
    mov  esi,text
616
    mov  eax,0
617
    mov  ebx,0
618
  newletter:
619
    mov  cl,[esi]
620
    cmp  cl,[esi+30*80]
621
    jne  yesletter
622
    jmp  noletter
623
  yesletter:
624
    mov  [esi+30*80],cl
625
 
626
    ; erase character
627
 
628
    pusha
331 heavyiron 629
    mov     edx, 0		    ; bg colour
31 halyavin 630
    mov     ecx, ebx
631
    add     ecx, 26
632
    shl     ecx, 16
633
    mov     cx, 9
634
    mov     ebx, eax
635
    add     ebx, 6
636
    shl     ebx, 16
637
    mov     bx, 6
638
    mov     eax, 13
639
    int     0x40
640
    popa
641
 
642
    ; draw character
643
 
644
    pusha
645
    mov     ecx, 0x00ffffff
646
    push bx
647
    mov  ebx,eax
648
    add  ebx,6
649
    shl  ebx,16
650
    pop  bx
651
    add  bx,26
652
    mov  eax,4
653
    mov  edx,esi
654
    mov  esi,1
655
    int  0x40
656
    popa
657
 
658
  noletter:
659
 
660
    add  esi,1
661
    add  eax,6
662
    cmp  eax,80*6
331 heavyiron 663
    jb	 newletter
31 halyavin 664
    mov  eax,0
665
    add  ebx,10
666
    cmp  ebx,24*10
331 heavyiron 667
    jb	 newletter
31 halyavin 668
 
669
    popa
670
    ret
671
 
672
 
673
read_string:
674
 
675
    mov  edi,string
676
    mov  eax,'_'
677
    mov  ecx,[string_length]
678
    inc     ecx
679
    cld
680
    rep  stosb
681
    call print_text
682
 
683
    mov  edi,string
684
  f11:
685
    mov  eax,10
686
    int  0x40
687
    cmp  eax,2
688
    jne  read_done
689
    mov  eax,2
690
    int  0x40
691
    shr  eax,8
692
    cmp  eax,13
331 heavyiron 693
    je	 read_done
31 halyavin 694
    cmp  eax,8
695
    jnz  nobsl
696
    cmp  edi,string
331 heavyiron 697
    jz	 f11
31 halyavin 698
    sub  edi,1
699
    mov  [edi],byte '_'
700
    call print_text
701
    jmp  f11
702
  nobsl:
703
    cmp  eax,dword 31
704
    jbe  f11
705
    cmp  eax,dword 95
331 heavyiron 706
    jb	 keyok
31 halyavin 707
    sub  eax,32
708
  keyok:
709
    mov  [edi],al
710
    call print_text
711
 
712
    inc  edi
713
    mov  esi,string
714
    add  esi,[string_length]
715
    cmp  esi,edi
716
    jnz  f11
717
 
718
  read_done:
719
 
720
    call print_text
721
 
722
    ret
723
 
724
 
725
print_text:
726
 
727
    pusha
728
 
729
    mov  eax,13
730
    mov  ebx,[string_x]
731
    shl  ebx,16
732
    add  ebx,[string_length]
733
    imul bx,6
734
    mov  ecx,[string_y]
735
    shl  ecx,16
736
    mov  cx,8
737
    mov  edx,0x00000000
738
    int  0x40
739
 
740
    mov  eax,4
741
    mov  ebx,[string_x]
742
    shl  ebx,16
743
    add  ebx,[string_y]
744
    mov  ecx,0x00ffffff
745
    mov  edx,string
746
    mov  esi,[string_length]
747
    int  0x40
748
 
749
    popa
750
    ret
751
 
752
 
753
 
754
 
755
; DATA AREA
756
 
331 heavyiron 757
telnetrep	db 0xff,0xfc,0x00
758
telnetstate	db 0
31 halyavin 759
 
760
string_length  dd    16
761
string_x       dd    200
762
string_y       dd    60
763
 
331 heavyiron 764
string	       db    '________________'
31 halyavin 765
 
331 heavyiron 766
tx_buff 	db  0, 10
767
ip_address	db  001,002,003,004
768
port		db  0,0
769
echo		db  0
770
socket		dd  0x0
771
socket_status	dd  0x0
772
pos		dd  80 * 1
773
scroll		dd  1
774
		dd  24
775
wcolor		dd  0x000000
776
labelt		db  'Telnet v0.1',0
777
setipt		db  'IP Address:    .   .   .'
31 halyavin 778
setiplen:
331 heavyiron 779
setportt	db  'Port:'
31 halyavin 780
setportlen:
331 heavyiron 781
cont		db  'Connect'
31 halyavin 782
conlen:
331 heavyiron 783
dist		db  'Disconnect'
31 halyavin 784
dislen:
331 heavyiron 785
contt		db  'Connected'
31 halyavin 786
contlen:
331 heavyiron 787
discontt	db  'Disconnected'
31 halyavin 788
discontlen:
331 heavyiron 789
echot	     db  'Echo On'
31 halyavin 790
echolen:
331 heavyiron 791
echoot	      db  'Echo Off'
31 halyavin 792
echoolen:
793
 
794
 
795
 
796
text:
797
I_END: