Subversion Repositories Kolibri OS

Rev

Rev 485 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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