Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   COMMUNICATING WITH MODEM: PORTS & IRQ
  3. ;
  4. ;   Compile with FASM for Menuet
  5. ;
  6.  
  7. include "lang.inc"
  8. include "macros.inc"
  9.  
  10.   use32
  11.   org    0x0
  12.  
  13.   db     'MENUET01'  ; 8 byte id
  14.   dd     0x01        ; header version
  15.   dd     START       ; start of code
  16.   dd     I_END       ; size of image
  17.   dd     0x1000      ; memory for app
  18.   dd     0x1000      ; esp
  19.   dd     0x0 , 0x0   ; I_Param , I_Icon
  20.  
  21.  
  22. START:                          ; start of execution
  23.  
  24.  
  25.     mov  eax,45                 ; reserve irq 4
  26.     mov  ebx,0
  27.     mov  ecx,4
  28.     int  0x40
  29.  
  30.     mov  eax,46                 ; reserve ports 0x3f8-0x3ff
  31.     mov  ebx,0
  32.     mov  ecx,0x3f8
  33.     mov  edx,0x3ff
  34.     int  0x40
  35.  
  36.     mov  eax,44                 ; read these ports at interrupt/irq 4
  37.     mov  ebx,irqtable
  38.     mov  ecx,4
  39.     int  0x40
  40.  
  41.     mov  eax,40                 ; enable event for interrupt/irq 4
  42.     mov  ebx,10000b shl 16 + 111b
  43.     int  0x40
  44.  
  45.     call program_com1
  46.  
  47.     call draw_window
  48.  
  49. still:
  50.  
  51.     mov  eax,10                 ; wait here for event
  52.     int  0x40
  53.  
  54.     cmp  eax,1                  ; redraw request ?
  55.     je   red
  56.     cmp  eax,2                  ; key in buffer ?
  57.     je   key
  58.     cmp  eax,3                  ; button in buffer ?
  59.     je   button
  60.     cmp  eax,16+4               ; data read by interrupt ?
  61.     je   irq4
  62.  
  63.     jmp  still
  64.  
  65.   red:                          ; redraw
  66.     call draw_window
  67.     jmp  still
  68.  
  69.   key:                          ; key
  70.     mov  eax,2                  ; just read it and ignore
  71.     int  0x40
  72.  
  73.     mov  al,ah
  74.     mov  dx,0x3f8
  75.     out  dx,al
  76.  
  77.     jmp  still
  78.  
  79.   button:                       ; button
  80.     or   eax,-1                 ; close this program
  81.     int  0x40
  82.  
  83.  
  84.   irq4:
  85.  
  86.     mov  eax,42
  87.     mov  ebx,4
  88.     int  0x40
  89.  
  90.     ; eax = number of bytes left
  91.     ; ecx = 0 success, =1 fail
  92.     ; bl  = byte
  93.  
  94.     inc   [pos]
  95.     and   [pos],31
  96.     mov   eax,[pos]
  97.  
  98.     mov   [string+eax], bl
  99.     call  draw_string
  100.  
  101.     jmp  still
  102.  
  103.  
  104. baudrate_9600   equ 12
  105. baudrate_57600  equ  2
  106.  
  107. program_com1:
  108.  
  109.     mov  dx,0x3f8+3
  110.     mov  al,0x80
  111.     out  dx,al
  112.  
  113.     mov  dx,0x3f8+1
  114.     mov  al,0x00
  115.     out  dx,al
  116.  
  117.     mov  dx,0x3f8+0
  118.     mov  al,baudrate_9600
  119.     out  dx,al
  120.  
  121.     mov  dx,0x3f8+3
  122.     mov  al,0x3
  123.     out  dx,al
  124.  
  125.     mov  dx,0x3f8+4
  126.     mov  al,0xb
  127.     out  dx,al
  128.  
  129.     mov  dx,0x3f8+1
  130.     mov  al,0x1
  131.     out  dx,al
  132.  
  133.     ret
  134.  
  135.  
  136.  
  137. ;   *********************************************
  138. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  139. ;   *********************************************
  140.  
  141.  
  142. draw_window:
  143.  
  144.     mov  eax, 48
  145.     mov  ebx, 3
  146.     mov  ecx, sc
  147.     mov  edx, sizeof.system_colors
  148.     int  0x40
  149.  
  150.     mov  eax, 12                   ; function 12:tell os about windowdraw
  151.     mov  ebx, 1                    ; 1, start of draw
  152.     int  0x40
  153.  
  154.                                    ; DRAW WINDOW
  155.     mov  eax, 0                    ; function 0 : define and draw window
  156.     mov  ebx, 100*65536+250        ; [x start] *65536 + [x size]
  157.     mov  ecx, 100*65536+85         ; [y start] *65536 + [y size]
  158.     mov  edx, [sc.work]
  159.     or   edx, 0x03000000           ; color of work area RRGGBB,8->color gl
  160.     int  0x40
  161.  
  162.                                    ; WINDOW LABEL
  163.     mov  eax, 4                    ; function 4 : write text to window
  164.     mov  ebx, 8*65536+8            ; [x start] *65536 + [y start]
  165.     mov  ecx, [sc.grab_text]
  166.     or   ecx, 0x10000000           ; font 1 & color ( 0xF0RRGGBB )
  167.     mov  edx, header               ; pointer to text beginning
  168.     mov  esi, header.len           ; text length
  169.     int  0x40
  170.  
  171.     mov  eax, 4                    ; draw text
  172.     mov  ebx, 20*65536+33
  173.     mov  ecx, [sc.work_text]
  174.     mov  edx, text+4
  175.   .nextstr:
  176.     mov  esi, [edx-4]
  177.     test esi, 0xFF000000
  178.     jnz  .finstr
  179.     int  0x40
  180.     add  edx, esi
  181.     add  edx, 4
  182.     add  ebx, 10
  183.     jmp  .nextstr
  184.   .finstr:
  185.  
  186.     call draw_string
  187.  
  188.     mov  eax,12                    ; function 12:tell os about windowdraw
  189.     mov  ebx,2                     ; 2, end of draw
  190.     int  0x40
  191.  
  192.     ret
  193.  
  194.  
  195. draw_string:
  196.     mov  eax, 4
  197.     mov  ebx, 20*65536+65
  198.     mov  ecx, [sc.work_text]
  199.     mov  edx, string
  200.     mov  esi, 32
  201.     int  0x40
  202. ret
  203.  
  204.  
  205. ; DATA AREA
  206.  
  207.  
  208. if lang eq ru
  209.    text mstr "‚‚Ž„ˆŒ›… ‘ˆŒ‚Ž‹› ……„€ž’‘Ÿ ŒŽ„…Œ“.",\
  210.              "„€›… Ž’ ŒŽ„…Œ€ ‘—ˆ’›‚€ž’‘Ÿ Ž",\
  211.              "…›‚€ˆž IRQ4 ˆ Ž’Ž€†€ž’‘Ÿ ˆ†…."
  212.    header:
  213.         db   'ŒŽ„…Œ € COM1'
  214.     .len = $ - header
  215. else
  216.    text mstr "TYPED CHARACTERS ARE SENT TO MODEM.",\
  217.              "DATA FROM MODEM IS READ BY IRQ4",\
  218.              "INTERRUPT AND DISPLAYED BELOW."
  219.    header:
  220.         db   'MODEM AT COM1'
  221.     .len = $ - header
  222. end if
  223.  
  224. pos  dd  0x0
  225.  
  226. irqtable:
  227.        ; port    ; 1=byte, 2=word
  228.   dd   0x3f8 +0x01000000   ; read byte from port 0x3f8 at interrupt/irq 4
  229.   dd   0x0                 ; no more ports ( max 15 ) to read
  230.  
  231.  
  232. I_END:
  233.  
  234. string rb 32
  235. sc system_colors
  236.