Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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