Rev 4462 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4462 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2014. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; terminal for KolibriOS ;; |
||
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org ;; |
||
9 | ;; ;; |
||
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
11 | ;; Version 2, June 1991 ;; |
||
12 | ;; ;; |
||
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
14 | |||
15 | format binary as "" |
||
16 | |||
17 | use32 |
||
18 | org 0x0 |
||
19 | |||
20 | db 'MENUET01' |
||
21 | dd 0x1 |
||
22 | dd START |
||
23 | dd I_END |
||
24 | dd IM_END+0x1000 |
||
25 | dd IM_END+0x1000 |
||
26 | dd 0, 0 |
||
27 | |||
28 | include '../../proc32.inc' |
||
29 | include '../../macros.inc' |
||
30 | include '../../dll.inc' |
||
31 | include '../../develop/libraries/box_lib/trunk/box_lib.mac' |
||
32 | |||
33 | |||
34 | START: |
||
35 | |||
36 | mcall 68, 11 |
||
37 | |||
38 | stdcall dll.Load, @IMPORT |
||
39 | or eax, eax |
||
40 | jnz exit |
||
41 | |||
42 | mcall 40, EVM_MOUSE + EVM_MOUSE_FILTER + EVM_REDRAW + EVM_BUTTON + EVM_KEY |
||
43 | |||
44 | invoke init_checkbox, ch1 |
||
45 | |||
46 | red_win: |
||
47 | call draw_window |
||
48 | |||
49 | mainloop: |
||
50 | mcall 10 |
||
51 | |||
52 | dec eax |
||
53 | jz red_win |
||
54 | |||
55 | dec eax |
||
56 | jz key |
||
57 | |||
58 | dec eax |
||
59 | jz button |
||
60 | |||
61 | invoke edit_box_mouse, edit1 |
||
62 | invoke edit_box_mouse, edit2 |
||
63 | invoke edit_box_mouse, edit3 |
||
64 | invoke edit_box_mouse, edit4 |
||
65 | |||
66 | invoke option_box_mouse, Option_boxs1 |
||
67 | invoke option_box_mouse, Option_boxs2 |
||
68 | |||
69 | invoke check_box_mouse, ch1 |
||
70 | |||
71 | jmp mainloop |
||
72 | |||
73 | button: |
||
74 | mcall 17 |
||
75 | |||
76 | cmp ah, 0x10 ; connect button |
||
77 | je open_connection |
||
78 | |||
79 | test ah , ah |
||
80 | jz mainloop |
||
81 | exit: |
||
82 | mcall -1 |
||
83 | |||
84 | key: |
||
85 | mcall 2 |
||
86 | |||
87 | cmp ah, 13 ; enter key |
||
88 | je open_connection |
||
89 | |||
90 | invoke edit_box_key, edit1 |
||
91 | invoke edit_box_key, edit2 |
||
92 | invoke edit_box_key, edit3 |
||
93 | invoke edit_box_key, edit4 |
||
94 | |||
95 | jmp mainloop |
||
96 | |||
97 | |||
98 | |||
99 | draw_window: |
||
100 | ; get system colors |
||
101 | mcall 48, 3, sc, 40 |
||
102 | |||
103 | mcall 12,1 |
||
104 | mov edx, [sc.work] |
||
105 | or edx, 0x34000000 |
||
106 | xor esi, esi |
||
107 | mov edi, str_title |
||
7548 | leency | 108 | mcall 0, 50 shl 16 + 415, 30 shl 16 + 195 |
4462 | hidnplayr | 109 | |
7548 | leency | 110 | mov ebx, 5 shl 16 + 12 |
111 | mov ecx, 0x90000000 |
||
4462 | hidnplayr | 112 | or ecx, [sc.work_text] |
113 | mov edx, str_port |
||
114 | mcall 4 |
||
7548 | leency | 115 | add ebx, 25 |
4462 | hidnplayr | 116 | mov edx, str_speed |
117 | mcall |
||
7548 | leency | 118 | add ebx, 25 |
4462 | hidnplayr | 119 | mov edx, str_data |
120 | mcall |
||
7548 | leency | 121 | add ebx, 25 |
4462 | hidnplayr | 122 | mov edx, str_stop |
123 | mcall |
||
124 | |||
7548 | leency | 125 | mov ebx, 195 shl 16 + 12 |
4462 | hidnplayr | 126 | mov edx, str_parity |
127 | mcall |
||
7548 | leency | 128 | mov ebx, 280 shl 16 + 12 |
4462 | hidnplayr | 129 | mov edx, str_flow |
130 | mcall |
||
131 | |||
7548 | leency | 132 | edit_boxes_set_sys_color edit1,editboxes_end,sc |
4462 | hidnplayr | 133 | invoke edit_box_draw, edit1 |
134 | invoke edit_box_draw, edit2 |
||
135 | invoke edit_box_draw, edit3 |
||
136 | invoke edit_box_draw, edit4 |
||
137 | |||
7548 | leency | 138 | option_boxes_set_sys_color sc, Option_boxs1 |
139 | option_boxes_set_sys_color sc, Option_boxs2 |
||
4462 | hidnplayr | 140 | invoke option_box_draw, Option_boxs1 |
141 | invoke option_box_draw, Option_boxs2 |
||
142 | |||
7548 | leency | 143 | check_boxes_set_sys_color2 ch1,ch1_end,sc ;set color |
4462 | hidnplayr | 144 | invoke check_box_draw, ch1 |
145 | |||
146 | mov esi, [sc.work_button] |
||
7548 | leency | 147 | mcall 8, 280 shl 16 + 100, 115 shl 16 + 22, 0x10 |
4462 | hidnplayr | 148 | |
7548 | leency | 149 | mov ecx, 0x90000000 |
4462 | hidnplayr | 150 | or ecx, [sc.work_button_text] |
7548 | leency | 151 | mcall 4, 315 shl 16 + 119, , str_open |
4462 | hidnplayr | 152 | |
153 | |||
154 | mov edx, [sc.work_graph] |
||
7548 | leency | 155 | mcall 38, 0 shl 16 + 405, 145 shl 16 + 145 |
4462 | hidnplayr | 156 | |
7548 | leency | 157 | mov ecx, 0x90000000 |
4462 | hidnplayr | 158 | or ecx, [sc.work_text] |
7548 | leency | 159 | mcall 4, 5 shl 16 + 150, , [errormsg] |
4462 | hidnplayr | 160 | |
161 | mcall 12, 2 |
||
162 | ret |
||
163 | |||
164 | |||
165 | open_connection: |
||
166 | |||
167 | mov [errormsg], err_none ; clear previous error message |
||
168 | |||
169 | ; Read the serial port name, and convert it to a port number |
||
170 | cmp byte[ed_port+4], 0 |
||
171 | jne .port_error |
||
172 | mov eax, dword[ed_port] |
||
173 | or eax, 0x20202020 ; convert to lowercase |
||
174 | cmp eax, 'com1' |
||
175 | je .com1 |
||
176 | cmp eax, 'com2' |
||
177 | je .com2 |
||
178 | cmp eax, 'com3' |
||
179 | je .com3 |
||
180 | cmp eax, 'com4' |
||
181 | je .com4 |
||
182 | .port_error: |
||
183 | mov [errormsg], err_port |
||
184 | jmp red_win |
||
185 | |||
186 | .com1: |
||
187 | mov [port], 0x3f8 |
||
188 | jmp .port_ok |
||
189 | .com2: |
||
190 | mov [port], 0x2f8 |
||
191 | jmp .port_ok |
||
192 | .com3: |
||
193 | mov [port], 0x3e8 |
||
194 | jmp .port_ok |
||
195 | .com4: |
||
196 | mov [port], 0x2e8 |
||
197 | .port_ok: |
||
198 | |||
199 | ; reserve the com port so we can work with it |
||
200 | xor ebx, ebx |
||
201 | movzx ecx, [port] |
||
202 | mov edx, ecx |
||
203 | add edx, 7 |
||
204 | mcall 46 |
||
205 | test eax, eax |
||
206 | jz .port_reserved |
||
207 | mov [errormsg], err_reserve |
||
208 | jmp red_win |
||
209 | .port_reserved: |
||
210 | |||
211 | ; disable com interrupts |
||
212 | ; (We cannot receive them on the application level :( ) |
||
213 | mov dx, [port] |
||
214 | inc dx |
||
215 | mov al, 0 |
||
216 | out dx, al |
||
217 | |||
218 | ; Set speed: |
||
219 | ; Convert the ascii decimal number that user entered |
||
220 | ; So we can do some math with it |
||
221 | mov esi, ed_speed |
||
222 | xor eax, eax |
||
223 | xor ebx, ebx |
||
224 | .convert_loop: |
||
225 | lodsb |
||
226 | test al, al |
||
227 | jz .convert_done |
||
228 | sub al, '0' |
||
229 | jb .invalid_speed |
||
230 | cmp al, 9 |
||
231 | ja .invalid_speed |
||
232 | lea ebx, [ebx + 4*ebx] |
||
233 | shl ebx, 1 |
||
234 | add ebx, eax |
||
235 | jmp .convert_loop |
||
236 | .invalid_speed: |
||
237 | call free_port |
||
238 | mov [errormsg], err_speed |
||
239 | jmp red_win |
||
240 | .convert_done: |
||
241 | test ebx, ebx |
||
242 | jz .invalid_speed |
||
243 | |||
244 | ; We now have the speed setting in ebx |
||
245 | ; calculate the divisor latch value as 115200/ebx |
||
246 | xor edx, edx |
||
247 | mov eax, 115200 |
||
248 | div ebx |
||
249 | test edx, edx |
||
250 | jnz .invalid_speed |
||
251 | cmp eax, 0xffff |
||
252 | ja .invalid_speed |
||
253 | mov bx, ax |
||
254 | |||
255 | ; enable Divisor latch |
||
256 | mov dx, [port] |
||
257 | add dx, 3 |
||
258 | mov al, 1 shl 7 ; dlab bit |
||
259 | out dx, al |
||
260 | |||
261 | ; Set divisor latch value |
||
262 | mov dx, [port] |
||
263 | mov al, bl |
||
264 | out dx, al |
||
265 | inc dx |
||
266 | mov al, bh |
||
267 | out dx, al |
||
268 | |||
269 | ; Check the parity type |
||
270 | xor bl, bl |
||
271 | cmp [option_group1], op1 ; none |
||
272 | je .parity_ok |
||
273 | |||
274 | mov bl, 001b shl 3 |
||
275 | cmp [option_group1], op2 ; odd |
||
276 | je .parity_ok |
||
277 | |||
278 | mov bl, 011b shl 3 |
||
279 | cmp [option_group1], op3 ; even |
||
280 | je .parity_ok |
||
281 | |||
282 | mov bl, 101b shl 3 |
||
283 | cmp [option_group1], op4 ; mark |
||
284 | je .parity_ok |
||
285 | |||
286 | mov bl, 111b shl 3 |
||
287 | cmp [option_group1], op5 ; space |
||
288 | je .parity_ok |
||
289 | jmp exit2 ; something went terribly wrong |
||
290 | .parity_ok: |
||
291 | |||
292 | ; Check number of stop bits |
||
293 | cmp [ed_stop], '1' |
||
294 | je .stop_ok |
||
295 | cmp [ed_stop], '2' |
||
296 | jne .invalid_stop |
||
297 | or bl, 1 shl 2 ; number of stop bits |
||
298 | jmp .stop_ok |
||
299 | .invalid_stop: |
||
300 | call free_port |
||
301 | mov [errormsg], err_stopbits |
||
302 | jmp red_win |
||
303 | .stop_ok: |
||
304 | |||
305 | ; Check number of data bits |
||
306 | mov al, [ed_data] |
||
307 | cmp al, '8' |
||
308 | ja .invalid_data |
||
309 | sub al, '5' |
||
310 | jae .data_ok |
||
311 | .invalid_data: |
||
312 | call free_port |
||
313 | mov [errormsg], err_databits |
||
314 | jmp red_win |
||
315 | .data_ok: |
||
316 | or al, bl |
||
317 | ; Program data bits, stop bits and parity in the UART |
||
318 | mov dx, [port] |
||
319 | add dx, 3 ; Line Control Register |
||
320 | out dx, al |
||
321 | |||
322 | ; clear + enable fifo (64 bytes), 1 byte trigger level |
||
323 | mov dx, [port] |
||
324 | inc dx |
||
325 | inc dx |
||
326 | mov al, 0x7 + 1 shl 5 |
||
327 | out dx, al |
||
328 | |||
329 | ; flow control |
||
330 | mov dx, [port] |
||
331 | add dx, 4 |
||
332 | mov al, 0xb |
||
333 | out dx, al |
||
334 | |||
335 | ; Hide our GUI window and open the console |
||
336 | mcall 40, 0 ; disable all events |
||
337 | mcall 67, 0, 0, 0, 0 ; hide window |
||
338 | mcall 12, 1 |
||
339 | mcall 12, 2 |
||
340 | |||
341 | invoke con_start, 1 |
||
342 | invoke con_init, 80, 25, 80, 25, str_title |
||
343 | |||
344 | console_loop: |
||
345 | mcall 5, 1 ; wait 10 ms |
||
346 | |||
347 | invoke con_get_flags |
||
348 | test eax, 0x200 ; con window closed? |
||
349 | jnz exit2 |
||
350 | |||
351 | .tx_loop: |
||
352 | invoke con_kbhit |
||
353 | test eax, eax ; did user press a key? |
||
354 | jz .rx_loop |
||
355 | |||
356 | invoke con_getch2 ; get the pressed key from buffer |
||
357 | mov dx, [port] |
||
358 | out dx, al |
||
359 | |||
360 | test [ch1.flags], ch_flag_en ; does user want us to echo locally? |
||
361 | je .tx_loop |
||
362 | |||
363 | and eax, 0xff |
||
364 | push eax |
||
365 | invoke con_write_asciiz, esp ; print the character |
||
366 | pop eax |
||
367 | jmp .tx_loop |
||
368 | |||
369 | .rx_loop: |
||
370 | mov dx, [port] |
||
371 | add dx, 5 ; Line status register |
||
372 | in al, dx |
||
373 | test al, 1 ; Data ready? |
||
374 | jz console_loop |
||
375 | |||
376 | mov dx, [port] ; Read character from buffer |
||
377 | in al, dx |
||
378 | |||
379 | and eax, 0xff |
||
380 | push eax |
||
381 | invoke con_write_asciiz, esp ; print the character |
||
382 | pop eax |
||
383 | |||
384 | jmp .rx_loop |
||
385 | |||
386 | |||
387 | exit2: |
||
388 | |||
389 | call free_port |
||
390 | mcall -1 ; exit |
||
391 | |||
392 | free_port: |
||
393 | |||
394 | xor ebx, ebx |
||
395 | inc ebx |
||
396 | movzx ecx, [port] |
||
397 | mov edx, ecx |
||
398 | add edx, 7 |
||
399 | mcall 46 |
||
400 | |||
401 | ret |
||
402 | |||
403 | ;------------------------- |
||
404 | ; DATA |
||
405 | |||
406 | align 16 |
||
407 | @IMPORT: |
||
408 | |||
409 | library box_lib, 'box_lib.obj',\ |
||
410 | console, 'console.obj' |
||
411 | |||
412 | import box_lib,\ |
||
413 | edit_box_draw, 'edit_box',\ |
||
414 | edit_box_key, 'edit_box_key',\ |
||
415 | edit_box_mouse, 'edit_box_mouse',\ |
||
416 | init_checkbox, 'init_checkbox2',\ |
||
417 | check_box_draw, 'check_box_draw2',\ |
||
418 | check_box_mouse, 'check_box_mouse2',\ |
||
419 | option_box_draw, 'option_box_draw',\ |
||
420 | option_box_mouse, 'option_box_mouse' |
||
421 | |||
422 | import console,\ |
||
423 | con_start, 'START',\ |
||
424 | con_init, 'con_init',\ |
||
425 | con_exit, 'con_exit',\ |
||
426 | con_getch2, 'con_getch2',\ |
||
427 | con_write_asciiz, 'con_write_asciiz',\ |
||
428 | con_get_flags, 'con_get_flags',\ |
||
429 | con_kbhit, 'con_kbhit' |
||
430 | |||
7548 | leency | 431 | edit1 edit_box 60, 112, 10, 0xffffff, 0x6f9480, 0, 0, 0x10000000, 8, ed_port, mouse_dd, ed_focus, 4, 4 |
432 | edit2 edit_box 60, 112, 35, 0xffffff, 0x6a9480, 0, 0, 0x10000000, 7, ed_speed, mouse_dd, ed_figure_only, 4, 4 |
||
433 | edit3 edit_box 60, 112, 60, 0xffffff, 0x6a9480, 0, 0, 0x10000000, 1, ed_data, mouse_dd, ed_figure_only, 1, 1 |
||
434 | edit4 edit_box 60, 112, 85, 0xffffff, 0x6a9480, 0, 0, 0x10000000, 1, ed_stop, mouse_dd, ed_figure_only, 1, 1 |
||
435 | editboxes_end: |
||
4462 | hidnplayr | 436 | |
437 | ed_port db "COM1",0,0,0,0,0,0 |
||
438 | ed_speed db "9600",0,0,0 |
||
439 | ed_data db "8",0 |
||
440 | ed_stop db "1",0 |
||
441 | |||
442 | option_group1 dd op1 |
||
7548 | leency | 443 | op1 option_box option_group1, 195, 30, 6, 12, 0xffffff, 0, 0, str_none, 4 |
444 | op2 option_box option_group1, 195, 47, 6, 12, 0xffffff, 0, 0, str_odd, 3 |
||
445 | op3 option_box option_group1, 195, 64, 6, 12, 0xffffff, 0, 0, str_even, 4 |
||
446 | op4 option_box option_group1, 195, 81, 6, 12, 0xffffff, 0, 0, str_mark, 4 |
||
447 | op5 option_box option_group1, 195, 98, 6, 12, 0xffffff, 0, 0, str_space, 5 |
||
4462 | hidnplayr | 448 | |
449 | option_group2 dd op6 |
||
7548 | leency | 450 | op6 option_box option_group2, 280, 30, 6, 12, 0xffffff, 0, 0, str_none, 4 |
4462 | hidnplayr | 451 | ;op7 option_box option_group2, 270, 44, 6, 12, 0xffffff, 0, 0, str_xon, 8, 10b |
452 | ;op8 option_box option_group2, 270, 61, 6, 12, 0xffffff, 0, 0, str_rts, 7, 1b |
||
453 | ;op9 option_box option_group2, 270, 78, 6, 12, 0xffffff, 0, 0, str_dsr, 7 |
||
454 | |||
7548 | leency | 455 | ch1 check_box2 5 shl 16 + 12, 119 shl 16 + 12, 5, 0xffffff, 0x000000, 0, str_echo, ch_flag_middle |
456 | ch1_end: |
||
4462 | hidnplayr | 457 | |
458 | Option_boxs1 dd op1, op2, op3, op4, op5, 0 |
||
459 | Option_boxs2 dd op6, 0 ;op7, op8, op9, 0 |
||
460 | |||
461 | str_title db 'Terminal', 0 |
||
462 | str_port db 'Serial port:', 0 |
||
463 | str_speed db 'Speed (baud):', 0 |
||
464 | str_data db 'Data bits:', 0 |
||
465 | str_parity db 'Parity:', 0 |
||
466 | str_flow db 'Flow control:', 0 |
||
467 | str_stop db 'Stop bits:', 0 |
||
468 | |||
469 | str_open db 'Open', 0 |
||
470 | |||
471 | str_none db 'None' |
||
472 | str_odd db 'Odd' |
||
473 | str_even db 'Even' |
||
474 | str_mark db 'Mark' |
||
475 | str_space db 'Space' |
||
476 | ;str_xon db 'XON/XOFF' |
||
477 | ;str_rts db 'RTS/CTS' |
||
478 | ;str_dsr db 'DSR/DTR' |
||
479 | |||
480 | str_echo db 'Local echo', 0 |
||
481 | |||
482 | errormsg dd err_none |
||
483 | err_none db 0 |
||
484 | err_port db 'Invalid serial port.', 0 |
||
485 | err_reserve db 'The port is already in use.', 0 |
||
486 | err_speed db 'Incorrect speed setting.', 0 |
||
487 | err_stopbits db 'Invalid number of stop bits. Must be 1 or 2.', 0 |
||
488 | err_databits db 'Invalid number of data bits. Must be between 5 and 8.', 0 |
||
489 | |||
490 | I_END: |
||
491 | |||
492 | mouse_dd dd ? |
||
493 | echo db ? |
||
494 | port dw ? |
||
495 | sc system_colors |
||
496 | |||
497 | IM_END: |