Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | 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
9
 
10
                org     0x0
11
 
12
                db      'MENUET00'              ; 8 byte id
13
                dd      38                      ; required os
14
                dd      START                   ; program start
15
                dd      I_END                   ; program image size
16
                dd      0x100000                ; required amount of memory
17
                                                ; esp = 0x7FFF0
18
                dd      0x00000000              ; reserved=no extended header
19
 
20
include 'lang.inc'
21
include 'macros.inc'
22
 
23
 
24
START:                          ; start of execution
25
 
26
    call draw_window
27
 
28
    call set_variables
29
 
30
still:
31
 
32
    mov  eax,23                 ; wait here for event
33
    mov  ebx,20
34
    int  0x40
35
 
36
    cmp  eax,1                  ; redraw request ?
37
    je   red
38
    cmp  eax,2                  ; key in buffer ?
39
    je   key
40
    cmp  eax,3                  ; button in buffer ?
41
    je   button
42
    cmp  eax,16+4
43
    je   read_input
44
 
45
    jmp  still
46
 
47
 
48
read_input:
49
 
50
    push ecx
51
    mov  eax,42
52
    mov  ebx,4
53
    int  0x40
54
    pop  ecx
55
 
56
    cmp  bl,27                          ; ESCAPE COMMAND
57
    jne  no_esc
58
    call esc_command
59
    jmp  newdata
60
  no_esc:
61
 
62
    cmp  bl,13                          ; BEGINNING OF LINE
63
    jne  nobol
64
    mov  ecx,[pos]
65
    add  ecx,1
66
  boll1:
67
    sub  ecx,1
68
    mov  eax,ecx
69
    xor  edx,edx
70
    mov  ebx,80
71
    div  ebx
72
    cmp  edx,0
73
    jne  boll1
74
    mov  [pos],ecx
75
    jmp  newdata
76
  nobol:
77
 
78
    cmp  bl,10                            ; LINE DOWN
79
    jne  nolf
80
   addx1:
81
    add  [pos],dword 1
82
    mov  eax,[pos]
83
    xor  edx,edx
84
    mov  ecx,80
85
    div  ecx
86
    cmp  edx,0
87
    jnz  addx1
88
    mov  eax,[pos]
89
    jmp  cm1
90
  nolf:
91
 
92
    cmp  bl,8                            ; BACKSPACE
93
    jne  nobasp
94
    mov  eax,[pos]
95
    dec  eax
96
    mov  [pos],eax
97
    mov  [eax+text],byte 32
98
    mov  [eax+text+60*80],byte 0
99
    jmp  newdata
100
   nobasp:
101
 
102
    cmp  bl,15                           ; CHARACTER
103
    jbe  newdata
104
    mov  eax,[pos]
105
    call draw_data
106
    mov  eax,[pos]
107
    add  eax,1
108
  cm1:
109
    mov  ebx,[scroll+4]
110
    imul ebx,80
111
    cmp  eax,ebx
112
    jb   noeaxz
113
    mov  esi,text+80
114
    mov  edi,text
115
    mov  ecx,ebx
116
    cld
117
    rep  movsb
118
    mov  esi,text+80+60*80
119
    mov  edi,text+60*80
120
    mov  ecx,ebx
121
    cld
122
    rep  movsb
123
    mov  eax,ebx
124
    sub  eax,80
125
  noeaxz:
126
    mov  [pos],eax
127
  newdata:
128
    mov  eax,11
129
    int  0x40
130
    cmp  eax,16+4
131
    je   read_input
132
    call draw_text
133
    jmp  still
134
 
135
 
136
  red:                          ; REDRAW WINDOW
137
    call draw_window
138
    jmp  still
139
 
140
  key:                          ; KEY
141
    mov  eax,2                  ; send to modem
142
    int  0x40
143
    shr  eax,8
144
    cmp  eax,178                ; ARROW KEYS
145
    jne  noaup
146
    mov  al,'A'
147
    call arrow
148
    jmp  still
149
  noaup:
150
    cmp  eax,177
151
    jne  noadown
152
    mov  al,'B'
153
    call arrow
154
    jmp  still
155
  noadown:
156
    cmp  eax,179
157
    jne  noaright
158
    mov  al,'C'
159
    call arrow
160
    jmp  still
161
  noaright:
162
    cmp  eax,176
163
    jne  noaleft
164
    mov  al,'D'
165
    call arrow
166
    jmp  still
167
  noaleft:
168
  modem_out:
169
    mov  ecx,0x3f8
170
    mov  bl,al
171
    mov  eax,43
172
    int  0x40
173
    jmp  still
174
 
175
  button:                       ; BUTTON
176
    mov  eax,17
177
    int  0x40
178
    cmp  ah,1                   ; CLOSE PROGRAM
179
    jne  noclose
180
    mov  eax,45                 ; FREE IRQ
181
    mov  ebx,1
182
    mov  ecx,4
183
    int  0x40
184
    mov  eax,46
185
    mov  ebx,1
186
    mov  ecx,0x3f0
187
    mov  edx,0x3ff
188
    int  0x40
189
     mov  eax,-1
190
     int  0x40
191
  noclose:
192
 
193
    jmp  still
194
 
195
 
196
arrow:
197
 
198
    push eax
199
    mov  al,27
200
    call to_modem
201
    mov  al,'['
202
    call to_modem
203
    pop  eax
204
    call to_modem
205
 
206
    ret
207
 
208
 
209
to_modem:
210
 
211
    pusha
212
 
213
    mov  ecx,0x3f8
214
    mov  ebx,eax
215
    mov  eax,43
216
    int  0x40
217
    mov  eax,5
218
    mov  ebx,5
219
    int  0x40
220
 
221
    popa
222
    ret
223
 
224
 
225
draw_data:
226
 
227
    pusha
228
 
229
    cmp  bl,0xe4   ; Á
230
    jne  noe4
231
    mov  bl,0xc1
232
  noe4:
233
    cmp  bl,0xc4   ; É
234
    jne  noc4
235
    mov  bl,0xc9
236
  noc4:
237
    mov  [eax+text],bl
238
    mov  bl,byte [attribute]
239
    mov  [eax+text+60*80],bl
240
 
241
    popa
242
    ret
243
 
244
 
245
irqtable:
246
 
247
    dd  0x3f8  + 0x01000000  ; read port 0x3f8, byte
248
    dd  0
249
    dd  0
250
    dd  0
251
    dd  0
252
    dd  0
253
    dd  0
254
    dd  0
255
    dd  0
256
    dd  0
257
    dd  0
258
    dd  0
259
    dd  0
260
    dd  0
261
    dd  0
262
    dd  0
263
 
264
 
265
 
266
 
267
set_variables:
268
 
269
    pusha
270
 
271
    mov  eax,46
272
    mov  ebx,0
273
    mov  ecx,0x3f0
274
    mov  edx,0x3ff
275
    int  0x40
276
 
277
    mov  eax,45          ; reserve irq 4
278
    mov  ebx,0
279
    mov  ecx,4
280
    int  0x40
281
 
282
    mov  eax,44
283
    mov  ebx,irqtable
284
    mov  ecx,4
285
    int  0x40
286
 
287
;    jmp  noportint
288
 
289
    mov  cx,0x3f8+3
290
    mov  bl,0x80
291
    mov  eax,43
292
    int  0x40
293
 
294
    mov  cx,0x3f8+1
295
    mov  bl,0
296
    mov  eax,43
297
    int  0x40
298
 
299
    mov  cx,0x3f8+0
300
    mov  bl,0x30 / 16
301
    mov  eax,43
302
    int  0x40
303
 
304
    mov  cx,0x3f8+3
305
    mov  bl,3
306
    mov  eax,43
307
    int  0x40
308
 
309
    mov  cx,0x3f8+4
310
    mov  bl,0xB
311
    mov  eax,43
312
    int  0x40
313
 
314
    mov  cx,0x3f8+1
315
    mov  bl,1
316
    mov  eax,43
317
    int  0x40
318
 
319
  noportint:
320
 
321
     mov  eax,40
322
     mov  ebx,0000000000010000b shl 16 + 111b
323
    int  0x40
324
 
325
    popa
326
 
327
    ret
328
 
329
 
330
 
331
;   *********************************************
332
;   *******  WINDOW DEFINITIONS AND DRAW ********
333
;   *********************************************
334
 
335
 
336
draw_window:
337
 
338
    pusha
339
 
340
    mov  eax,12
341
    mov  ebx,1
342
    int  0x40
343
 
344
    mov  eax,0                     ; DRAW WINDOW
345
    mov  ebx,100*65536+491
346
    mov  ecx,100*65536+270
347
    mov  edx,[wcolor]
348
    add  edx,0x02000000
349
    mov  esi,0x80557799
350
    mov  edi,0x00557799
351
    int  0x40
352
 
353
    mov  eax,4                     ; WINDOW LABEL
354
    mov  ebx,8*65536+8
355
    mov  ecx,0x00ffffff
356
    mov  edx,labelt
357
    mov  esi,labellen-labelt
358
    int  0x40
359
 
360
    mov  eax,8                     ; CLOSE BUTTON
361
    mov  ebx,(491-19)*65536+12
362
    mov  ecx,5*65536+12
363
    mov  edx,1
364
    mov  esi,0x557799
365
    int  0x40
366
 
367
    xor  eax,eax
368
    mov  edi,text+80*30
369
    mov  ecx,80*30 /4
370
    cld
371
    rep  stosd
372
 
373
    call draw_text
374
 
375
    mov  eax,12
376
    mov  ebx,2
377
    int  0x40
378
 
379
    popa
380
 
381
    ret
382
 
383
 
384
bgc  dd  0x000000
385
     dd  0x000000
386
     dd  0x00ff00
387
     dd  0x0000ff
388
     dd  0x005500
389
     dd  0xff00ff
390
     dd  0x00ffff
391
     dd  0x770077
392
 
393
tc   dd  0xffffff
394
     dd  0xff00ff
395
     dd  0xffffff
396
     dd  0xffffff
397
     dd  0xffffff
398
     dd  0xffffff
399
     dd  0xffffff
400
     dd  0xffffff
401
 
402
 
403
draw_text:
404
 
405
    pusha
406
 
407
    mov  esi,text
408
    mov  eax,0
409
    mov  ebx,0
410
  newletter:
411
    mov  cl,[esi]
412
    mov  dl,[esi+60*80]
413
    cmp  cl,[esi+30*80]
414
    jne  yesletter
415
    cmp  dl,[esi+90*80]
416
    jne  yesletter
417
    jmp  noletter
418
  yesletter:
419
    mov  [esi+30*80],cl
420
    mov  [esi+90*80],dl
421
 
422
    pusha
423
    and  edx,0xff
424
    shl  edx,2
425
    add  edx,bgc
426
    mov  edx,[edx]
427
    mov  ecx,ebx
428
    add  ecx,26
429
    shl  ecx,16
430
    mov  cx,9
431
    mov  ebx,eax
432
    add  ebx,6
433
    shl  ebx,16
434
    mov  bx,6
435
    mov  eax,13
436
    int  0x40
437
    popa
438
 
439
    pusha
440
    and  edx,0xff
441
    shl  edx,2
442
    add  edx,tc
443
    mov  ecx,[edx]
444
    push bx
445
    mov  ebx,eax
446
    add  ebx,6
447
    shl  ebx,16
448
    pop  bx
449
    add  bx,26
450
    mov  eax,4
451
    mov  edx,esi
452
    mov  esi,1
453
    int  0x40
454
    popa
455
 
456
  noletter:
457
 
458
    add  esi,1
459
    add  eax,6
460
    cmp  eax,80*6
461
    jb   newletter
462
    mov  eax,0
463
    add  ebx,10
464
    cmp  ebx,24*10
465
    jb   newletter
466
 
467
    popa
468
    ret
469
 
470
 
471
esc_command:
472
 
473
     mov   eax,32
474
     mov   edi,esccmd
475
     mov   ecx,10
476
     cld
477
     rep   stosb
478
     mov   edi,esccmd
479
   newescc:
480
     mov   eax,42
481
     mov   ebx,4
482
     int   0x40
483
     cmp   ecx,0
484
     je    escok
485
     mov   eax,5
486
     mov   ebx,1
487
     int   0x40
488
     jmp   newescc
489
   escok:
490
     mov   [edi],bl
491
     add   edi,1
492
     cmp   edi,esccmd+20
493
     je    dontunderstand
494
     mov   esi,escend
495
   nec:
496
     cmp   bl,[esi]
497
     jz    com_ok
498
     add   esi,1
499
     cmp   [esi],byte 0
500
     je    newescc
501
     jmp   nec
502
   com_ok:
503
 
504
     call  get_numbers
505
 
506
     cmp   bl,'H'                     ; SET CURSOR POSITION
507
     jne   no_cursor_position
508
     cmp   [escnumbers],0
509
     jne   ncp1
510
     mov   [pos],dword 0
511
     jmp   cmd_done
512
    ncp1:
513
     mov    eax,[escnumbers]
514
     dec    eax
515
     imul   eax,80
516
     add    eax,[escnumbers+4]
517
     dec    eax
518
     mov    [pos],eax
519
     jmp    cmd_done
520
   no_cursor_position:
521
 
522
     cmp    bl,'K'                      ; ERASE LINE
523
     jne    no_erase_end_of_line
524
     cmp    [escnumbers],0
525
     jne    no_end_line
526
     mov    ecx,[pos]
527
   eeol:
528
     mov    [ecx+text],byte ' '
529
     mov    [ecx+text+60*80],byte 0
530
     add    ecx,1
531
     xor    edx,edx
532
     mov    eax,ecx
533
     mov    ebx,80
534
     div    ebx
535
     cmp    edx,0
536
     jne    eeol
537
     jmp    cmd_done
538
    no_end_line:
539
     cmp    [escnumbers],1              ; BEGINNING OF LINE
540
     jne    no_beg_line
541
     mov    ecx,[pos]
542
   ebol:
543
     mov    [ecx+text],byte ' '
544
     mov    [ecx+text+60*80],byte 0
545
     sub    ecx,1
546
     xor    edx,edx
547
     mov    eax,ecx
548
     mov    ebx,80
549
     div    ebx
550
     cmp    edx,0
551
     jne    ebol
552
     mov    [pos],ecx
553
     jmp    cmd_done
554
    no_beg_line:
555
   no_erase_end_of_line:
556
 
557
     cmp    bl,'J'                          ; ERASE TO END OF SCREEN
558
     jne    no_erase_to_end_of_screen
559
     cmp    [escnumbers],dword 0
560
     jne    no_erase_to_end_of_screen
561
     mov    ecx,[pos]
562
   eteos:
563
     mov    [ecx+text],byte ' '
564
     mov    [ecx+text+60*80],byte 0
565
     add    ecx,1
566
     cmp    ecx,80*24+1
567
     jb     eteos
568
     jmp    cmd_done
569
   no_erase_to_end_of_screen:
570
 
571
     cmp    bl,'r'                           ; SET SCROLL REGION
572
     jne    no_scroll_region
573
     mov    eax,[escnumbers]
574
     dec    eax
575
     mov    [scroll+0],eax
576
     mov    eax,[escnumbers+4]
577
     mov    [scroll+4],eax
578
     jmp    cmd_done
579
   no_scroll_region:
580
 
581
     cmp    bl,'A'                            ; CURSOR UP
582
     jne    no_cursor_up
583
     mov    eax,[pos]
584
     sub    eax,80
585
     mov    [pos],eax
586
     jmp    cmd_done
587
   no_cursor_up:
588
 
589
     cmp    bl,'C'                            ; CURSOR LEFT
590
     jne    no_cursor_left
591
     mov    eax,[pos]
592
     mov    ebx,[escnumbers]
593
     sub    eax,ebx
594
     mov    [pos],eax
595
     call   cmd_done
596
   no_cursor_left:
597
 
598
     cmp    bl,'m'                           ; CHARACTER ATTRIBUTE
599
     jne    no_char_attribute
600
     mov    eax,[escnumbers]
601
     mov    [attribute],eax
602
     jmp    cmd_done
603
   no_char_attribute:
604
 
605
     cmp    bl,'Z'                            ; TERMINAL TYPE
606
     jne    no_terminal_type
607
     mov    al,27
608
     call   to_modem
609
     mov    al,'?'
610
     call   to_modem
611
     mov    al,'1'
612
     call   to_modem
613
     mov    al,';'
614
     call   to_modem
615
     mov    al,'0'
616
     call   to_modem
617
     mov    al,'c'
618
     call   to_modem
619
     jmp    cmd_done
620
   no_terminal_type:
621
 
622
   dontunderstand:
623
 
624
   cmd_done:
625
 
626
     ret
627
 
628
 
629
draw_numbers:
630
 
631
     pusha
632
 
633
     mov  eax,13
634
     mov  ebx,250*65536+100
635
     mov  ecx,8*65536+8
636
     mov  edx,0x000000
637
     int  0x40
638
 
639
     mov  eax,[escnumbers]
640
     xor  edx,edx
641
     mov  ebx,10
642
     div  ebx
643
     add  eax,48
644
     add  edx,48
645
     mov  byte [numtext+0],al
646
     mov  byte [numtext+1],dl
647
 
648
     mov  eax,[escnumbers+4]
649
     xor  edx,edx
650
     mov  ebx,10
651
     div  ebx
652
     add  eax,48
653
     add  edx,48
654
     mov  [numtext+3],al
655
     mov  [numtext+4],dl
656
 
657
     mov  eax,4
658
     mov  ebx,250*65536+8
659
     mov  ecx,0xffffff
660
     mov  edx,numtext
661
     mov  esi,10
662
     int  0x40
663
 
664
     popa
665
 
666
     ret
667
 
668
draw_event:
669
 
670
     pusha
671
 
672
     mov  eax,13
673
     mov  ebx,150*65536+100
674
     mov  ecx,8*65536+8
675
     mov  edx,0xffffff
676
     int  0x40
677
 
678
     mov  eax,4
679
     mov  ebx,150*65536+8
680
     mov  ecx,0x000000
681
     mov  edx,esccmd
682
     mov  esi,20
683
     int  0x40
684
 
685
     popa
686
     ret
687
 
688
 
689
get_numbers:
690
 
691
     pusha
692
 
693
     mov   [escnumbers+0],0
694
     mov   [escnumbers+4],0
695
     mov   [escnumbers+8],0
696
     mov   ecx,esccmd
697
     cmp   [ecx+1],byte '0'
698
     jb    gn_over
699
     cmp   [ecx+1],byte '9'
700
     jg    gn_over
701
     mov   edi,escnumbers
702
   gn_new:
703
     add   ecx,1
704
     movzx eax,byte [ecx]
705
     sub   eax,48
706
     add   ecx,1
707
     cmp   [ecx],byte '0'
708
     jb    gnl1
709
     cmp   [ecx],byte '9'
710
     jg    gnl1
711
     mov   ebx,10
712
     xor   edx,edx
713
     mul   ebx
714
     movzx ebx,byte[ecx]
715
     add   eax,ebx
716
     sub   eax,48
717
     add   ecx,1
718
   gnl1:
719
     mov   [edi],eax
720
     add   edi,4
721
     cmp   [ecx],byte ';'
722
     je    gn_new
723
  gn_over:
724
     popa
725
     ret
726
 
727
 
728
 
729
 
730
; DATA AREA
731
 
732
 
733
pos         dd  80*10
734
irc_data    dd  0x0
735
print       db  0x0
736
attribute   dd  0
737
scroll      dd  1
738
            dd  24
739
numtext     db  '                     '
740
esccmd      dd  0,0,0,0,0,0,0,0,0,0,0,0,0
741
escend      db  'ZrhlABCDHfDME=>NmKJgincoyq',0
742
escnumbers  dd  0,0,0,0,0
743
wcolor      dd  0x000000
744
labelt      db  'TERMINAL FOR MODEM IN COM1  0.03'
745
labellen:
746
 
747
text:
748
db '                                                                   '
749
db '             '
750
db '*** A TELNET APPLICATION FOR HAYES COMPATIBLE MODEMS IN COM1       '
751
db '             '
752
db '*** USE HAYES COMMANDS TO CONNECT TO A SERVER                      '
753
db '             '
754
db '*** ATDT (PHONENUMBER)                                             '
755
db '             '
756
db '                                                                   '
757
db '             '
758
 
759
I_END:
760