Rev 205 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 205 | Rev 485 | ||
---|---|---|---|
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 for Menuet |
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 | int 0x40 |
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 | int 0x40 |
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 | int 0x40 |
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 | int 0x40 |
43 | mcall |
44 | 44 | ||
45 | call program_com1 |
45 | call program_com1 |
- | 46 | ||
- | 47 | mov eax, 48 |
|
- | 48 | mov ebx, 3 |
|
- | 49 | mov ecx, sc |
|
- | 50 | mov edx, sizeof.system_colors |
|
- | 51 | mcall |
|
- | 52 | ||
46 | 53 | red: |
|
47 | call draw_window |
54 | call draw_window |
48 | 55 | ||
49 | still: |
56 | still: |
50 | 57 | ||
51 | mov eax,10 ; wait here for event |
58 | mov eax,10 ; wait here for event |
52 | int 0x40 |
59 | mcall |
53 | 60 | ||
54 | cmp eax,1 ; redraw request ? |
61 | cmp eax,1 ; redraw request ? |
55 | je red |
62 | je red |
56 | cmp eax,2 ; key in buffer ? |
63 | cmp eax,2 ; key in buffer ? |
57 | je key |
64 | je key |
58 | cmp eax,3 ; button in buffer ? |
65 | cmp eax,3 ; button in buffer ? |
59 | je button |
66 | je button |
60 | cmp eax,16+4 ; data read by interrupt ? |
67 | cmp eax,16+4 ; data read by interrupt ? |
61 | je irq4 |
68 | je irq4 |
62 | 69 | ||
63 | jmp still |
70 | jmp still |
64 | - | ||
65 | red: ; redraw |
- | |
66 | call draw_window |
- | |
67 | jmp still |
- | |
68 | 71 | ||
69 | key: ; key |
72 | key: ; key |
70 | mov eax,2 ; just read it and ignore |
73 | mov eax,2 ; just read it and ignore |
71 | int 0x40 |
74 | mcall |
72 | 75 | ||
73 | mov al,ah |
76 | mov al,ah |
74 | mov dx,0x3f8 |
77 | mov dx,0x3f8 |
75 | out dx,al |
78 | out dx,al |
76 | 79 | ||
77 | jmp still |
80 | jmp still |
78 | 81 | ||
79 | button: ; button |
82 | button: ; button |
80 | or eax,-1 ; close this program |
83 | or eax,-1 ; close this program |
81 | int 0x40 |
84 | mcall |
82 | 85 | ||
83 | 86 | ||
84 | irq4: |
87 | irq4: |
85 | 88 | ||
86 | mov eax,42 |
89 | mov eax,42 |
87 | mov ebx,4 |
90 | mov ebx,4 |
88 | int 0x40 |
91 | mcall |
89 | 92 | ||
90 | ; eax = number of bytes left |
93 | ; eax = number of bytes left |
91 | ; ecx = 0 success, =1 fail |
94 | ; ecx = 0 success, =1 fail |
92 | ; bl = byte |
95 | ; bl = byte |
93 | 96 | ||
94 | inc [pos] |
97 | inc [pos] |
95 | and [pos],31 |
98 | and [pos],31 |
96 | mov eax,[pos] |
99 | mov eax,[pos] |
97 | 100 | ||
98 | mov [string+eax], bl |
101 | mov [string+eax], bl |
99 | call draw_string |
102 | call draw_string |
100 | 103 | ||
101 | jmp still |
104 | jmp still |
102 | 105 | ||
103 | 106 | ||
104 | baudrate_9600 equ 12 |
107 | baudrate_9600 equ 12 |
105 | baudrate_57600 equ 2 |
108 | baudrate_57600 equ 2 |
106 | 109 | ||
107 | program_com1: |
110 | program_com1: |
108 | 111 | ||
109 | mov dx,0x3f8+3 |
112 | mov dx,0x3f8+3 |
110 | mov al,0x80 |
113 | mov al,0x80 |
111 | out dx,al |
114 | out dx,al |
112 | 115 | ||
113 | mov dx,0x3f8+1 |
116 | mov dx,0x3f8+1 |
114 | mov al,0x00 |
117 | mov al,0x00 |
115 | out dx,al |
118 | out dx,al |
116 | 119 | ||
117 | mov dx,0x3f8+0 |
120 | mov dx,0x3f8+0 |
118 | mov al,baudrate_9600 |
121 | mov al,baudrate_9600 |
119 | out dx,al |
122 | out dx,al |
120 | 123 | ||
121 | mov dx,0x3f8+3 |
124 | mov dx,0x3f8+3 |
122 | mov al,0x3 |
125 | mov al,0x3 |
123 | out dx,al |
126 | out dx,al |
124 | 127 | ||
125 | mov dx,0x3f8+4 |
128 | mov dx,0x3f8+4 |
126 | mov al,0xb |
129 | mov al,0xb |
127 | out dx,al |
130 | out dx,al |
128 | 131 | ||
129 | mov dx,0x3f8+1 |
132 | mov dx,0x3f8+1 |
130 | mov al,0x1 |
133 | mov al,0x1 |
131 | out dx,al |
134 | out dx,al |
132 | 135 | ||
133 | ret |
136 | ret |
134 | 137 | ||
135 | 138 | ||
136 | 139 | ||
137 | ; ********************************************* |
140 | ; ********************************************* |
138 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
141 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
139 | ; ********************************************* |
142 | ; ********************************************* |
140 | 143 | ||
141 | 144 | ||
142 | draw_window: |
145 | 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 | 146 | ||
150 | mov eax, 12 ; function 12:tell os about windowdraw |
147 | mov eax, 12 ; function 12:tell os about windowdraw |
151 | mov ebx, 1 ; 1, start of draw |
148 | mov ebx, 1 ; 1, start of draw |
152 | int 0x40 |
149 | mcall |
153 | 150 | ||
154 | ; DRAW WINDOW |
151 | ; DRAW WINDOW |
155 | mov eax, 0 ; function 0 : define and draw window |
152 | mov eax, 0 ; function 0 : define and draw window |
156 | mov ebx, 100*65536+250 ; [x start] *65536 + [x size] |
153 | mov ebx, 100*65536+250 ; [x start] *65536 + [x size] |
157 | mov ecx, 100*65536+85 ; [y start] *65536 + [y size] |
154 | mov ecx, 100*65536+85 ; [y start] *65536 + [y size] |
158 | mov edx, [sc.work] |
155 | mov edx, [sc.work] |
159 | or edx, 0x03000000 ; color of work area RRGGBB,8->color gl |
156 | or edx, 0x03000000 ; color of work area RRGGBB,8->color gl |
160 | int 0x40 |
157 | mcall |
161 | 158 | ||
162 | ; WINDOW LABEL |
159 | ; WINDOW LABEL |
163 | mov eax, 4 ; function 4 : write text to window |
160 | mov eax, 4 ; function 4 : write text to window |
164 | mov ebx, 8*65536+8 ; [x start] *65536 + [y start] |
161 | mov ebx, 8*65536+8 ; [x start] *65536 + [y start] |
165 | mov ecx, [sc.grab_text] |
162 | mov ecx, [sc.grab_text] |
166 | or ecx, 0x10000000 ; font 1 & color ( 0xF0RRGGBB ) |
163 | or ecx, 0x10000000 ; font 1 & color ( 0xF0RRGGBB ) |
167 | mov edx, header ; pointer to text beginning |
164 | mov edx, title ; pointer to text beginning |
168 | mov esi, header.len ; text length |
165 | mov esi, title.len ; text length |
169 | int 0x40 |
166 | mcall |
170 | 167 | ||
171 | mov eax, 4 ; draw text |
168 | mov eax, 4 ; draw text |
172 | mov ebx, 20*65536+33 |
169 | mov ebx, 20*65536+33 |
173 | mov ecx, [sc.work_text] |
170 | mov ecx, [sc.work_text] |
174 | mov edx, text+4 |
171 | mov edx, text+4 |
175 | .nextstr: |
172 | .nextstr: |
176 | mov esi, [edx-4] |
173 | mov esi, [edx-4] |
177 | test esi, 0xFF000000 |
174 | test esi, 0xFF000000 |
178 | jnz .finstr |
175 | jnz .finstr |
179 | int 0x40 |
176 | mcall |
180 | add edx, esi |
177 | add edx, esi |
181 | add edx, 4 |
178 | add edx, 4 |
182 | add ebx, 10 |
179 | add ebx, 10 |
183 | jmp .nextstr |
180 | jmp .nextstr |
184 | .finstr: |
181 | .finstr: |
185 | 182 | ||
186 | call draw_string |
183 | call draw_string |
187 | 184 | ||
188 | mov eax,12 ; function 12:tell os about windowdraw |
185 | mov eax,12 ; function 12:tell os about windowdraw |
189 | mov ebx,2 ; 2, end of draw |
186 | mov ebx,2 ; 2, end of draw |
190 | int 0x40 |
187 | mcall |
191 | 188 | ||
192 | ret |
189 | ret |
193 | 190 | ||
194 | 191 | ||
195 | draw_string: |
192 | draw_string: |
196 | mov eax, 4 |
193 | mov eax, 4 |
197 | mov ebx, 20*65536+65 |
194 | mov ebx, 20*65536+65 |
198 | mov ecx, [sc.work_text] |
195 | mov ecx, [sc.work_text] |
199 | mov edx, string |
196 | mov edx, string |
200 | mov esi, 32 |
197 | mov esi, 32 |
201 | int 0x40 |
198 | mcall |
202 | ret |
199 | ret |
203 | 200 | ||
204 | 201 | ||
205 | ; DATA AREA |
202 | ; DATA AREA |
206 | 203 | ||
207 | 204 | ||
208 | if lang eq ru |
205 | if lang eq ru |
209 | text mstr " .",\ |
206 | text mstr " .",\ |
210 | " ",\ |
207 | " ",\ |
211 | " IRQ4 ." |
208 | " IRQ4 ." |
212 | header: |
209 | title: |
213 | db ' COM1' |
210 | db ' COM1' |
214 | .len = $ - header |
211 | .len = $ - title |
215 | else |
212 | else |
216 | text mstr "TYPED CHARACTERS ARE SENT TO MODEM.",\ |
213 | text mstr "TYPED CHARACTERS ARE SENT TO MODEM.",\ |
217 | "DATA FROM MODEM IS READ BY IRQ4",\ |
214 | "DATA FROM MODEM IS READ BY IRQ4",\ |
218 | "INTERRUPT AND DISPLAYED BELOW." |
215 | "INTERRUPT AND DISPLAYED BELOW." |
219 | header: |
216 | title: |
220 | db 'MODEM AT COM1' |
217 | db 'MODEM AT COM1' |
221 | .len = $ - header |
218 | .len = $ - title |
222 | end if |
219 | end if |
223 | 220 | ||
224 | pos dd 0x0 |
221 | pos dd 0x0 |
225 | 222 | ||
226 | irqtable: |
223 | irqtable: |
227 | ; port ; 1=byte, 2=word |
224 | ; port ; 1=byte, 2=word |
228 | 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 |
229 | dd 0x0 ; no more ports ( max 15 ) to read |
226 | dd 0x0 ; no more ports ( max 15 ) to read |
230 | 227 | ||
231 | 228 | ||
232 | I_END: |
229 | I_END: |
233 | 230 | ||
234 | string rb 32 |
231 | string rb 32 |
235 | sc system_colors |
232 | sc system_colors |