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