Subversion Repositories Kolibri OS

Rev

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